Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: Steven Sistare <steven.sistare@oracle.com>
Cc: "Tian, Kevin" <kevin.tian@intel.com>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	Cornelia Huck <cohuck@redhat.com>,
	Jason Gunthorpe <jgg@nvidia.com>
Subject: Re: [PATCH V6 2/7] vfio/type1: prevent underflow of locked_vm via exec()
Date: Tue, 20 Dec 2022 14:59:20 -0700	[thread overview]
Message-ID: <20221220145920.6669de59.alex.williamson@redhat.com> (raw)
In-Reply-To: <f2af6106-7898-b96c-000e-92e84190ee54@oracle.com>

On Tue, 20 Dec 2022 10:01:21 -0500
Steven Sistare <steven.sistare@oracle.com> wrote:

> On 12/19/2022 2:48 AM, Tian, Kevin wrote:
> >> From: Steve Sistare <steven.sistare@oracle.com>
> >> Sent: Saturday, December 17, 2022 2:51 AM
> >> @@ -1664,15 +1666,7 @@ static int vfio_dma_do_map(struct vfio_iommu
> >> *iommu,
> >>  	 * against the locked memory limit and we need to be able to do both
> >>  	 * outside of this call path as pinning can be asynchronous via the
> >>  	 * external interfaces for mdev devices.  RLIMIT_MEMLOCK requires
> >> a
> >> -	 * task_struct and VM locked pages requires an mm_struct, however
> >> -	 * holding an indefinite mm reference is not recommended,
> >> therefore we
> >> -	 * only hold a reference to a task.  We could hold a reference to
> >> -	 * current, however QEMU uses this call path through vCPU threads,
> >> -	 * which can be killed resulting in a NULL mm and failure in the
> >> unmap
> >> -	 * path when called via a different thread.  Avoid this problem by
> >> -	 * using the group_leader as threads within the same group require
> >> -	 * both CLONE_THREAD and CLONE_VM and will therefore use the
> >> same
> >> -	 * mm_struct.
> >> +	 * task_struct and VM locked pages requires an mm_struct.  
> > 
> > IMHO the rationale why choosing group_leader still applies...  
> 
> I don't see why it still applies.  With the new code, we may save a reference 
> to current or current->group_leader, without error.  "NULL mm and failure in the 
> unmap path" will not happen with mmgrab.  task->signal->rlimit is shared, so it 
> does not matter which task we use, or whether the task is dead, as long as 
> one of the tasks lives, which is guaranteed by the mmget_not_zero() guard.  Am
> I missing something?
> 
> I kept current->group_leader for ease of debugging, so that all dma's are owned 
> by the same task.

That much at least would be a good comment to add since the above
removes all justification for why we're storing group_leader as the
task rather than current.  Ex:

	QEMU typically calls this path through vCPU threads, which can
	terminate due to vCPU hotplug, therefore historically we've used
	group_leader for task tracking.  With the addition of grabbing
	the mm for the life of the DMA tracking structure, this is not
	so much a concern, but we continue to use group_leader for
	debug'ability, ie. all DMA tracking is owned by the same task.

Given the upcoming holidays and reviewers starting to disappear, I
suggest we take this up as a fixes series for v6.2 after the new year.
The remainder of the vfio next branch for v6.2 has already been merged.
Thanks,

Alex


  reply	other threads:[~2022-12-20 22:00 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-16 18:50 [PATCH V6 0/7] fixes for virtual address update Steve Sistare
2022-12-16 18:50 ` [PATCH V6 1/7] vfio/type1: exclude mdevs from VFIO_UPDATE_VADDR Steve Sistare
2022-12-16 18:50 ` [PATCH V6 2/7] vfio/type1: prevent underflow of locked_vm via exec() Steve Sistare
2022-12-19  7:48   ` Tian, Kevin
2022-12-20 15:01     ` Steven Sistare
2022-12-20 21:59       ` Alex Williamson [this message]
2022-12-20 22:06         ` Steven Sistare
2022-12-16 18:50 ` [PATCH V6 3/7] vfio/type1: track locked_vm per dma Steve Sistare
2022-12-19  7:51   ` Tian, Kevin
2022-12-16 18:50 ` [PATCH V6 4/7] vfio/type1: restore locked_vm Steve Sistare
2022-12-19  7:54   ` Tian, Kevin
2022-12-16 18:50 ` [PATCH V6 5/7] vfio/type1: revert "block on invalid vaddr" Steve Sistare
2022-12-19  7:54   ` Tian, Kevin
2022-12-16 18:50 ` [PATCH V6 6/7] vfio/type1: revert "implement notify callback" Steve Sistare
2022-12-19  7:55   ` Tian, Kevin
2022-12-16 18:50 ` [PATCH V6 7/7] vfio: revert "iommu driver " Steve Sistare
2022-12-19  7:55   ` Tian, Kevin
2022-12-19 18:42 ` [PATCH V6 0/7] fixes for virtual address update Steven Sistare
2022-12-19 20:55   ` Alex Williamson

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=20221220145920.6669de59.alex.williamson@redhat.com \
    --to=alex.williamson@redhat.com \
    --cc=cohuck@redhat.com \
    --cc=jgg@nvidia.com \
    --cc=kevin.tian@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=steven.sistare@oracle.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