From: Alistair Popple <apopple@nvidia.com>
To: "Yu, Fenghua" <fenghua.yu@intel.com>
Cc: Lorenzo Stoakes <lstoakes@gmail.com>,
Vinod Koul <vkoul@kernel.org>,
"Jiang, Dave" <dave.jiang@intel.com>,
"dmaengine@vger.kernel.org" <dmaengine@vger.kernel.org>,
"Zhu, Tony" <tony.zhu@intel.com>,
Andrew Morton <akpm@linux-foundation.org>,
"linux-mm@kvack.org" <linux-mm@kvack.org>,
Christoph Hellwig <hch@infradead.org>,
"Shankar, Ravi V" <ravi.v.shankar@intel.com>
Subject: Re: [PATCH 09/17] mm: export access_remote_vm() symbol
Date: Wed, 04 Jan 2023 17:12:31 +1100 [thread overview]
Message-ID: <87tu16rdea.fsf@nvidia.com> (raw)
In-Reply-To: <IA1PR11MB609745A8BE83313FAB0236C29BF59@IA1PR11MB6097.namprd11.prod.outlook.com>
"Yu, Fenghua" <fenghua.yu@intel.com> writes:
> Hi, Lorenzo,
>
>> Hey Fenghua :)
>>
>> > access_remote_vm(mm) directly call __access_remote_vm(mm).
>> > access_process_vm(tsk) calls mm=get_task_mm() then
>> __access_remote_vm(mm).
>> >
>> > So instead of access_remote_vm(mm), it's access_process_vm(tsk) that
>> > holds a reference count on the mm, right?
>>
>> Indeed!
>>
>> >
>> > > >
>> > > > Is there a reason you can't use access_process_vm() which is
>> > > > exported and additionally handles the refrencing?
>> >
>> > IDXD interrupt handler starts a work which needs to access remote vm.
>> > The remote mm is found by PASID which is saved in device event log.
>> >
>> > In the work, it's hard to get the remote mm from a task because
>> > mm->owner could be NULL but the mm is still existing.
>>
>> That makes sense, however I do feel nervous about exporting something that
>> that relies on this reference.
>>
>> The issue is ensuring that the mm can't be taken from underneath you, the only
>> user of access_remote_vm(), procfs, does a careful dance using get_task_mm()
>> and
>> mm_access() to ensure this can't happen, if _sometimes_ the remote mm might
>> have an owner and _sometimes_ not it feels like any exported function needs to
>> be equally careful?
I think the point is the remote mm should be valid as long as the PASID
is valid because it doesn't make sense to have a PASID without
associated memory map. iommu_sva_find() does mmget_not_zero() to ensure
that.
Obviously something must still be holding a mmgrab() though. That should
happen as part of the PASID allocation done by iommu_sva_bind_device().
>> I definitely don't feel as if simply exporting this is a safe option, and you would in
>> that case need a new function that handles different scenarios of mm
>> ownership/not.
Note this isn't that different from get_user_pages_remote().
>> I may be missing something here and I will wait for others to chime in but I think
>> we would definitely need something more than simply exporting this.
>
> I may define and export a new wrapper access_remote_vm_ref() which will hold
> mm's reference count before accessing it:
> int access_remote_vm_ref(mm)
> {
> int ret;
>
> if (mm == &init_mm)
> return 0;
>
> mmget(mm);
> ret = access_remote_vm(mm);
> mmput(mm);
>
> return ret;
> }
> EXPORT_SYMBOL_GPL(access_remote_vm_ref);
>
> IDXD or any driver calls this and holds mm reference count while accesses the mm.
> This is useful for caller to directly access mm even if mm's owner could be NULL.
I'm not sure that helps much. A driver would still need to hold a
mm_count to ensure the struct_mm itself can't go away anyway so it may
as well do the mmget() IMHO (although it really should be
mmget_not_zero()).
In any case though iommu_sva_find() already takes care of doing
mmget_not_zero(). I wonder if it makes more sense to define a wrapper
(eg. iommu_access_pasid) that takes a PASID and does the mm
lookup/access_vm/mmput?
> Do you think this is sufficient to take care of the mm reference and is a good way to go?
>
> Thanks.
>
> -Fenghua
next prev parent reply other threads:[~2023-01-04 7:02 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20230103163505.1569356-1-fenghua.yu@intel.com>
2023-01-03 16:34 ` Fenghua Yu
2023-01-03 17:45 ` Lorenzo Stoakes
2023-01-03 17:50 ` Lorenzo Stoakes
2023-01-03 19:20 ` Yu, Fenghua
2023-01-03 20:13 ` Lorenzo Stoakes
2023-01-04 5:06 ` Yu, Fenghua
2023-01-04 6:12 ` Alistair Popple [this message]
2023-01-04 19:00 ` Yu, Fenghua
2023-01-04 20:00 ` Lorenzo Stoakes
2023-01-04 19:56 ` Lorenzo Stoakes
2023-01-04 21:05 ` Lorenzo Stoakes
2023-01-04 23:57 ` Alistair Popple
2023-01-05 3:08 ` Yu, Fenghua
2023-01-05 3:22 ` Alistair Popple
2023-01-05 20:58 ` Yu, Fenghua
2023-01-05 21:04 ` Lorenzo Stoakes
2023-01-05 7:26 ` Lorenzo Stoakes
2023-01-08 17:36 ` Christoph Hellwig
2023-03-01 23:39 ` Fenghua Yu
[not found] <20230103162920.1569002-1-fenghua.yu@intel.com>
2023-01-03 16:29 ` Fenghua Yu
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=87tu16rdea.fsf@nvidia.com \
--to=apopple@nvidia.com \
--cc=akpm@linux-foundation.org \
--cc=dave.jiang@intel.com \
--cc=dmaengine@vger.kernel.org \
--cc=fenghua.yu@intel.com \
--cc=hch@infradead.org \
--cc=linux-mm@kvack.org \
--cc=lstoakes@gmail.com \
--cc=ravi.v.shankar@intel.com \
--cc=tony.zhu@intel.com \
--cc=vkoul@kernel.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