From: Jason Gunthorpe <jgg@nvidia.com>
To: Steven Sistare <steven.sistare@oracle.com>
Cc: kvm@vger.kernel.org, Alex Williamson <alex.williamson@redhat.com>,
Cornelia Huck <cohuck@redhat.com>,
Kevin Tian <kevin.tian@intel.com>
Subject: Re: [PATCH V7 3/7] vfio/type1: track locked_vm per dma
Date: Mon, 9 Jan 2023 20:31:15 -0400 [thread overview]
Message-ID: <Y7yx0517LE7qDEP/@nvidia.com> (raw)
In-Reply-To: <1d5fd387-3e4d-77a5-dc6d-04cc4c9ed3cb@oracle.com>
On Mon, Jan 09, 2023 at 04:24:03PM -0500, Steven Sistare wrote:
> On 1/3/2023 1:13 PM, Steven Sistare wrote:
> > On 1/3/2023 10:21 AM, Jason Gunthorpe wrote:
> >> On Tue, Dec 20, 2022 at 12:39:21PM -0800, Steve Sistare wrote:
> >>> Track locked_vm per dma struct, and create a new subroutine, both for use
> >>> in a subsequent patch. No functional change.
> >>>
> >>> Fixes: c3cbab24db38 ("vfio/type1: implement interfaces to update vaddr")
> >>> Cc: stable@vger.kernel.org
> >>> Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
> >>> Reviewed-by: Kevin Tian <kevin.tian@intel.com>
> >>> ---
> >>> drivers/vfio/vfio_iommu_type1.c | 20 +++++++++++++++-----
> >>> 1 file changed, 15 insertions(+), 5 deletions(-)
> >>>
> >>> diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
> >>> index 71f980b..588d690 100644
> >>> --- a/drivers/vfio/vfio_iommu_type1.c
> >>> +++ b/drivers/vfio/vfio_iommu_type1.c
> >>> @@ -101,6 +101,7 @@ struct vfio_dma {
> >>> struct rb_root pfn_list; /* Ex-user pinned pfn list */
> >>> unsigned long *bitmap;
> >>> struct mm_struct *mm;
> >>> + long locked_vm;
> >>
> >> Why is it long? Can it be negative?
> >
> > The existing code uses both long and uint64_t for page counts, and I picked one.
> > I'll use size_t instead to match vfio_dma size.
> >
> >>> };
> >>>
> >>> struct vfio_batch {
> >>> @@ -413,22 +414,21 @@ static int vfio_iova_put_vfio_pfn(struct vfio_dma *dma, struct vfio_pfn *vpfn)
> >>> return ret;
> >>> }
> >>>
> >>> -static int vfio_lock_acct(struct vfio_dma *dma, long npage, bool async)
> >>> +static int mm_lock_acct(struct task_struct *task, struct mm_struct *mm,
> >>> + bool lock_cap, long npage, bool async)
> >>> {
> >>
> >> Now async is even more confusing, the caller really should have a
> >> valid handle on the mm before using it as an argument like this.
> >
> > The caller holds a grab reference on mm, and mm_lock_acct does mmget_not_zero to
> > validate the mm. IMO this is a close analog of the original vfio_lock_acct code
> > where the caller holds a get reference on task, and does get_task_mm to validate
> > the mm.
> >
> > However, I can hoist the mmget_not_zero from mm_lock_acct to its callsites in
> > vfio_lock_acct and vfio_change_dma_owner.
>
> Yielding:
>
> static int mm_lock_acct(struct task_struct *task, struct mm_struct *mm,
> bool lock_cap, long npage)
> {
> int ret = mmap_write_lock_killable(mm);
>
> if (!ret) {
Please don't write in the 'single return' style, that is not kernel
code.
'success oriented flow' means you have early returns and goto error so
a straight line read of the function tells what success looks like
Jason
next prev parent reply other threads:[~2023-01-10 0:32 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-20 20:39 [PATCH V7 0/7] fixes for virtual address update Steve Sistare
2022-12-20 20:39 ` [PATCH V7 1/7] vfio/type1: exclude mdevs from VFIO_UPDATE_VADDR Steve Sistare
2022-12-20 20:39 ` [PATCH V7 2/7] vfio/type1: prevent underflow of locked_vm via exec() Steve Sistare
2023-01-03 15:20 ` Jason Gunthorpe
2023-01-03 18:12 ` Steven Sistare
2023-01-03 19:20 ` Jason Gunthorpe
2023-01-06 15:14 ` Steven Sistare
2023-01-09 13:52 ` Jason Gunthorpe
2023-01-09 15:54 ` Steven Sistare
2023-01-09 21:16 ` Steven Sistare
2023-01-10 15:02 ` Jason Gunthorpe
2022-12-20 20:39 ` [PATCH V7 3/7] vfio/type1: track locked_vm per dma Steve Sistare
2023-01-03 15:21 ` Jason Gunthorpe
2023-01-03 18:13 ` Steven Sistare
2023-01-09 21:24 ` Steven Sistare
2023-01-10 0:31 ` Jason Gunthorpe [this message]
2022-12-20 20:39 ` [PATCH V7 4/7] vfio/type1: restore locked_vm Steve Sistare
2023-01-03 15:22 ` Jason Gunthorpe
2023-01-03 18:12 ` Steven Sistare
2022-12-20 20:39 ` [PATCH V7 5/7] vfio/type1: revert "block on invalid vaddr" Steve Sistare
2022-12-20 20:39 ` [PATCH V7 6/7] vfio/type1: revert "implement notify callback" Steve Sistare
2022-12-20 20:39 ` [PATCH V7 7/7] vfio: revert "iommu driver " Steve Sistare
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=Y7yx0517LE7qDEP/@nvidia.com \
--to=jgg@nvidia.com \
--cc=alex.williamson@redhat.com \
--cc=cohuck@redhat.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