From: John Hubbard <jhubbard@nvidia.com>
To: Matt Sickler <Matt.Sickler@daktronics.com>,
Bharath Vedartham <linux.bhar@gmail.com>,
"ira.weiny@intel.com" <ira.weiny@intel.com>,
"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
"jglisse@redhat.com" <jglisse@redhat.com>
Cc: "devel@driverdev.osuosl.org" <devel@driverdev.osuosl.org>,
"linux-mm@kvack.org" <linux-mm@kvack.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] staging: kpc2000: Convert put_page() to put_user_page*()
Date: Mon, 15 Jul 2019 15:01:43 -0700 [thread overview]
Message-ID: <82441723-f30e-5811-ab1c-dd9a4993d7df@nvidia.com> (raw)
In-Reply-To: <SN6PR02MB4016687B605E3D97D699956EEECF0@SN6PR02MB4016.namprd02.prod.outlook.com>
On 7/15/19 2:47 PM, Matt Sickler wrote:
> It looks like Outlook is going to absolutely trash this email. Hopefully it comes through okay.
>
...
>>
>> Because this is a common pattern, and because the code here doesn't likely
>> need to set page dirty before the dma_unmap_sg call, I think the following
>> would be better (it's untested), instead of the above diff hunk:
>>
>> diff --git a/drivers/staging/kpc2000/kpc_dma/fileops.c
>> b/drivers/staging/kpc2000/kpc_dma/fileops.c
>> index 48ca88bc6b0b..d486f9866449 100644
>> --- a/drivers/staging/kpc2000/kpc_dma/fileops.c
>> +++ b/drivers/staging/kpc2000/kpc_dma/fileops.c
>> @@ -211,16 +211,13 @@ void transfer_complete_cb(struct aio_cb_data
>> *acd, size_t xfr_count, u32 flags)
>> BUG_ON(acd->ldev == NULL);
>> BUG_ON(acd->ldev->pldev == NULL);
>>
>> - for (i = 0 ; i < acd->page_count ; i++) {
>> - if (!PageReserved(acd->user_pages[i])) {
>> - set_page_dirty(acd->user_pages[i]);
>> - }
>> - }
>> -
>> dma_unmap_sg(&acd->ldev->pldev->dev, acd->sgt.sgl, acd->sgt.nents, acd->ldev->dir);
>>
>> for (i = 0 ; i < acd->page_count ; i++) {
>> - put_page(acd->user_pages[i]);
>> + if (!PageReserved(acd->user_pages[i])) {
>> + put_user_pages_dirty(&acd->user_pages[i], 1);
>> + else
>> + put_user_page(acd->user_pages[i]);
>> }
>>
>> sg_free_table(&acd->sgt);
>
> I don't think I ever really knew the right way to do this.
>
> The changes Bharath suggested look okay to me. I'm not sure about the check for PageReserved(), though. At first glance it appears to be equivalent to what was there before, but maybe I should learn what that Reserved page flag really means.
> From [1], the only comment that seems applicable is
> * - MMIO/DMA pages. Some architectures don't allow to ioremap pages that are
> * not marked PG_reserved (as they might be in use by somebody else who does
> * not respect the caching strategy).
>
> These pages should be coming from anonymous (RAM, not file backed) memory in userspace. Sometimes it comes from hugepage backed memory, though I don't think that makes a difference. I should note that transfer_complete_cb handles both RAM to device and device to RAM DMAs, if that matters.
>
> [1] https://elixir.bootlin.com/linux/v5.2/source/include/linux/page-flags.h#L17
>
I agree: the PageReserved check looks unnecessary here, from my outside-the-kpc_2000-team
perspective, anyway. Assuming that your analysis above is correct, you could collapse that
whole think into just:
@@ -211,17 +209,8 @@ void transfer_complete_cb(struct aio_cb_data *acd, size_t xfr_count, u32 flags)
BUG_ON(acd->ldev == NULL);
BUG_ON(acd->ldev->pldev == NULL);
- for (i = 0 ; i < acd->page_count ; i++) {
- if (!PageReserved(acd->user_pages[i])) {
- set_page_dirty(acd->user_pages[i]);
- }
- }
-
dma_unmap_sg(&acd->ldev->pldev->dev, acd->sgt.sgl, acd->sgt.nents, acd->ldev->dir);
-
- for (i = 0 ; i < acd->page_count ; i++) {
- put_page(acd->user_pages[i]);
- }
+ put_user_pages_dirty(&acd->user_pages[i], acd->page_count);
sg_free_table(&acd->sgt);
(Also, Matt, I failed to Cc: you on a semi-related cleanup that I just sent out for this
driver, as long as I have your attention:
https://lore.kernel.org/r/20190715212123.432-1-jhubbard@nvidia.com
)
thanks,
--
John Hubbard
NVIDIA
next prev parent reply other threads:[~2019-07-15 22:01 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-15 19:52 Bharath Vedartham
2019-07-15 20:14 ` John Hubbard
2019-07-15 20:52 ` Bharath Vedartham
2019-07-15 21:47 ` Matt Sickler
2019-07-15 22:01 ` John Hubbard [this message]
2019-07-15 22:04 ` John Hubbard
2019-07-16 10:28 ` Bharath Vedartham
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=82441723-f30e-5811-ab1c-dd9a4993d7df@nvidia.com \
--to=jhubbard@nvidia.com \
--cc=Matt.Sickler@daktronics.com \
--cc=devel@driverdev.osuosl.org \
--cc=gregkh@linuxfoundation.org \
--cc=ira.weiny@intel.com \
--cc=jglisse@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux.bhar@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