From: Clemens Ladisch <clemens@ladisch.de>
To: Pecker Hu <pecker.hu@gmail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: Need help about how linux to handle translation fault
Date: Fri, 12 Aug 2011 13:27:53 +0200 [thread overview]
Message-ID: <4E450E39.3030404@ladisch.de> (raw)
In-Reply-To: <CAPtRRT9h6yWNB41tfjO9ryx+BppkiTGNWRgNjNTUkwXv-B0eYw@mail.gmail.com>
Pecker Hu wrote:
> ...
> And I send the address of str to kernel space using IOCTL interface.
> ioctl(fd, VM_TEST_GET_VADDR, str);
>
> When I try to use pgd to find the physical address, I don't find it
> .
You must not directly access user space memory from kernel space because
that memory can be moved or swapped out at any time. Use only functions
like copy_from_user() which take appropriate precautions; and don't
forget to check for errors.
Furthermore, the physical address is useless. If you want to access
the memory from a device, you have to use the DMA mapping API because
the CPU's physical address it not necessarily the same address as that
used on the device's bus, and sometimes you have to program an IOMMU
before devices are allowed to access that memory at all.
> So I think string array is located in data cache not in physical
> memory, after I call copy_from_user, kernel will allocate page for it,
> then we can access it, is it right?
As far as any code running on the CPU is concerned, caches are
completely transparent. (This is not always true for devices, but the
DMA mapping API takes care of that.)
Regards,
Clemens
prev parent reply other threads:[~2011-08-12 11:23 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-12 7:37 Need help about how linux to handle translation fault Pecker Hu
2011-08-12 11:27 ` Clemens Ladisch [this message]
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=4E450E39.3030404@ladisch.de \
--to=clemens@ladisch.de \
--cc=linux-kernel@vger.kernel.org \
--cc=pecker.hu@gmail.com \
/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