kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
From: Sadanand Warrier <sadanandwarrier@gmail.com>
To: Cengiz Can <cengiz@kernel.wtf>
Cc: kernelnewbies@kernelnewbies.org
Subject: Re: get_user_pages and pinning
Date: Sun, 3 Jan 2021 12:54:39 -0500	[thread overview]
Message-ID: <CADJuq2zQ2M+7Sig4FFkR2fro8vraQ6naoog6y5aN-afyurcb0g@mail.gmail.com> (raw)
In-Reply-To: <5C603B48-1AA6-4692-B484-564E08D63E7E@kernel.wtf>

Cengiz

> I don't have an answer to your question because your sentences are too long and I couldn't understand the thing you are asking.
 A clearer picture below.
1) There is a user program that allocates memory using malloc. It does
not initialize the memory.
2) It uses an ioctl to pass a pointer to different areas of this
allocated memory to a driver controlling a device.
3) The device is supposed to fill the buffer that this pointer points
to with requested data.
4) The driver pins the pages that the pointer points to in memory
using get_user_pages.
5) The driver gets the physical (bus) address of this buffer using
kernel apis such as dma_map_sg and queues up the DMA.
6) Inspecting the bus address returned by kernel apis shows that the
same address is returned for different locations in the buffer.
7) So the DMA fails (rather the device sends the data but it is over
writing the same location)
8) It looks like the memory isn't actually allocated by malloc. Not a surprise.
9) It will ideally allocate memory when a write to the memory location occurs.
10) But the write is happening not from user space but by DMA from a device.

So the question is what should happen if the memory isn't actually
allocated. Should get_user_pages check?
It doesn't seem to be doing so.  Can it?

S

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

  reply	other threads:[~2021-01-03 17:55 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-02 12:39 get_user_pages and pinning Sadanand Warrier
2021-01-02 13:08 ` Cengiz Can
2021-01-03 17:54   ` Sadanand Warrier [this message]
2021-01-03 18:26     ` Rik van Riel
2021-01-03 18:54       ` Sadanand Warrier
2021-01-02 13:20 ` Greg KH
2021-01-02 15:11   ` Sadanand Warrier
2021-01-03 17:58 Sadanand Warrier

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=CADJuq2zQ2M+7Sig4FFkR2fro8vraQ6naoog6y5aN-afyurcb0g@mail.gmail.com \
    --to=sadanandwarrier@gmail.com \
    --cc=cengiz@kernel.wtf \
    --cc=kernelnewbies@kernelnewbies.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 NNTP newsgroup(s).