public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "luofengwc at qq dot com" <sourceware-bugzilla@sourceware.org>
To: glibc-bugs@sourceware.org
Subject: [Bug libc/31492] New: ARM ldp instruction trigger bus error when kernel open option CONFIG_IO_STRICT_DEVMEM
Date: Fri, 15 Mar 2024 07:51:03 +0000	[thread overview]
Message-ID: <bug-31492-131@http.sourceware.org/bugzilla/> (raw)

https://sourceware.org/bugzilla/show_bug.cgi?id=31492

            Bug ID: 31492
           Summary: ARM ldp instruction trigger bus error when kernel open
                    option CONFIG_IO_STRICT_DEVMEM
           Product: glibc
           Version: 2.34
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: libc
          Assignee: unassigned at sourceware dot org
          Reporter: luofengwc at qq dot com
                CC: drepper.fsp at gmail dot com
  Target Milestone: ---

Hi, everyone, I encountered a runtime problem with bus errror caused by the ldp
instruction(ARM instruction).
On an aarch architecture Linux machine, when I turned on the option kernel
option CONFIG_IO_STRICT_DEVMEM, mapped the memory of /dev/mem using mmap, and
used the ldp instruction to read the data, a bus error occurred, but ldr and
ldrp ran normally.

Why do i think this problem is related to glibc because the ldp command is also
used in memcpy. when use memcpy to copy /dev/mem data, alos has bus error;

check kernel CONFIG_IO_STRICT_DEVMEM optoins
```
zcat /proc/config.gz | grep CONFIG_IO_STRICT_DEVMEM
CONFIG_IO_STRICT_DEVMEM=y
```
code example: demo.c

```
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>

typedef char u8;

int main() {
        off_t base = 9654697984;
        void *p;
        int fd;
        int len = 724;

        struct stat statbuf;
        off_t mmoffset;
        void *mmp;

        if ((fd = open("/dev/mem", O_RDONLY)) == -1)
        {
                printf("%d\n",__LINE__);
                return NULL;
        }

        if ((p = malloc(len)) == NULL)
        {
                printf("%d\n",__LINE__);
                return NULL;
        }

        if (fstat(fd, &statbuf) == -1)
        {
                printf("%d\n",__LINE__);
                return NULL;
        }


        mmoffset = base % sysconf(_SC_PAGESIZE);

        printf("0");
        mmp = mmap(NULL, mmoffset + len, PROT_READ, MAP_SHARED, fd, base -
mmoffset);
        if (mmp == MAP_FAILED)
                return 0;

        long output;

        __asm__(
                "ldrb w0, [x0]"
                : "=r" (output)
                : "r" (mmp+mmoffset)
        );

        __asm__(
                "ldr x0, [x0]"
                : "=r" (output)
                : "r" (mmp+mmoffset)
        );
        // ldp trigger bus error
        __asm__(
                "ldp x0, x1, [x0]"
                : "=r" (output)         
                : "r" (mmp+mmoffset)
        );


        if (munmap(mmp, mmoffset + len) == -1)
        {
                return NULL;
        }

        printf("\noutput = %ld\n",output);

  return 0;
}
```
compile command with none optimization

```
gcc -O0 demo.c  -g
```

-- 
You are receiving this mail because:
You are on the CC list for the bug.

             reply	other threads:[~2024-03-15  7:51 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-15  7:51 luofengwc at qq dot com [this message]
2024-03-15  8:09 ` [Bug libc/31492] " luofengwc at qq dot com
2024-03-15  9:51 ` fweimer at redhat dot com
2024-03-17  2:02 ` luofengwc at qq dot com
2024-03-19 11:56 ` adhemerval.zanella at linaro dot org
2024-03-20  8:47 ` luofengwc at qq dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-31492-131@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=glibc-bugs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).