qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Xu <peterx@redhat.com>
To: Jason Gunthorpe <jgg@nvidia.com>
Cc: Yi Liu <yi.l.liu@intel.com>,
	Zhenzhong Duan <zhenzhong.duan@intel.com>,
	qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com,
	pbonzini@redhat.com, richard.henderson@linaro.org,
	eduardo@habkost.net, marcel.apfelbaum@gmail.com,
	alex.williamson@redhat.com, clg@redhat.com, david@redhat.com,
	philmd@linaro.org, kwankhede@nvidia.com, cjia@nvidia.com,
	chao.p.peng@intel.com
Subject: Re: [PATCH v3 5/5] intel_iommu: Optimize out some unnecessary UNMAP calls
Date: Thu, 8 Jun 2023 15:53:23 -0400	[thread overview]
Message-ID: <ZIIxs9kXQyULglIJ@x1n> (raw)
In-Reply-To: <ZIIBhmoT7H2/q0lb@nvidia.com>

On Thu, Jun 08, 2023 at 01:27:50PM -0300, Jason Gunthorpe wrote:
> On Thu, Jun 08, 2023 at 11:40:55AM -0400, Peter Xu wrote:
> 
> > > But if there is the proper locks to prevent a map/unmap race, then
> > > there should also be the proper locks to check that there is no map in
> > > the first place and avoid the kernel call..
> > 
> > The problem is IIRC guest iommu driver can do smart things like batching
> > invalidations, it means when QEMU gets it from the guest OS it may already
> > not matching one mapped objects.
> 
> qemu has to fix it. The kernel API is object based, not paged
> based. You cannot unmap partions of a prior mapping.
> 
> I assume for this kind of emulation it is doing 4k objects because
> it has no idea what size of mapping the client will use?

MAP is fine, before notify() to VFIO or anything, qemu scans the pgtable
and handles it in page size or huge page size, so it can be >4K but always
guest iommu pgsize aligned.

I think we rely on guest behaving right, so it should also always operate
on that size minimum when mapped huge.  It shouldn't violate the
"per-object" protocol of iommufd.

IIUC the same to vfio type1v2 from that aspect.

It's more about UNMAP batching, but I assume iommufd is fine if it's fine
with holes inside for that case.  The only difference of "not exist" of
-ENOENT seems to be just same as before as long as QEMU treats it as 0 like
before.

Though that does look slightly special, because the whole empty UNMAP
region can be seen as a hole too; not sure when that -ENOENT will be useful
if qemu should always bypass it anyway.  Indeed not a problem to qemu.

> 
> > We can definitely lookup every single object and explicitly unmap, but it
> > loses partial of the point of batching that guest OS does.  
> 
> You don't need every single object, but it would be faster to check
> where things are mapped and then call the kernel correctly instead of
> trying to iterate with the unmapped reults.

Maybe yes.  If so, It'll be great if Zhenzhong could just attach some proof
on that, meanwhile drop the "iommufd UNMAP warnings" section in the commit
message.

Thanks,

-- 
Peter Xu



  reply	other threads:[~2023-06-08 19:53 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-08  9:52 [PATCH v3 0/5] Optimize UNMAP call and bug fix Zhenzhong Duan
2023-06-08  9:52 ` [PATCH v3 1/5] util: Add iova_tree_foreach_range_data Zhenzhong Duan
2023-06-08  9:52 ` [PATCH v3 2/5] intel_iommu: Fix a potential issue in VFIO dirty page sync Zhenzhong Duan
2023-06-08 13:42   ` Peter Xu
2023-06-08  9:52 ` [PATCH v3 3/5] intel_iommu: Fix flag check in replay Zhenzhong Duan
2023-06-08 13:43   ` Peter Xu
2023-06-08  9:52 ` [PATCH v3 4/5] intel_iommu: Fix address space unmap Zhenzhong Duan
2023-06-08 13:48   ` Peter Xu
2023-06-09  3:31     ` Duan, Zhenzhong
2023-06-09 13:36       ` Peter Xu
2023-06-13  2:32         ` Duan, Zhenzhong
2023-06-08  9:52 ` [PATCH v3 5/5] intel_iommu: Optimize out some unnecessary UNMAP calls Zhenzhong Duan
2023-06-08 14:05   ` Peter Xu
2023-06-08 14:11     ` Jason Gunthorpe
2023-06-08 15:40       ` Peter Xu
2023-06-08 16:27         ` Jason Gunthorpe
2023-06-08 19:53           ` Peter Xu [this message]
2023-06-09  1:00             ` Jason Gunthorpe
2023-06-09  5:49             ` Duan, Zhenzhong
2023-06-09 21:26               ` Peter Xu
2023-06-13  2:37                 ` Duan, Zhenzhong
2023-06-14  9:47                 ` Duan, Zhenzhong
2023-06-09  4:03         ` Duan, Zhenzhong
2023-06-09  3:41     ` Duan, Zhenzhong
2023-06-08 20:34   ` Peter Xu
2023-06-09  4:01     ` Duan, Zhenzhong
2023-06-14  9:38       ` Duan, Zhenzhong
2023-06-14 12:51         ` Peter Xu
2023-06-08 15:53 ` [PATCH v3 0/5] Optimize UNMAP call and bug fix Peter Xu
2023-06-09  3:32   ` Duan, Zhenzhong

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=ZIIxs9kXQyULglIJ@x1n \
    --to=peterx@redhat.com \
    --cc=alex.williamson@redhat.com \
    --cc=chao.p.peng@intel.com \
    --cc=cjia@nvidia.com \
    --cc=clg@redhat.com \
    --cc=david@redhat.com \
    --cc=eduardo@habkost.net \
    --cc=jasowang@redhat.com \
    --cc=jgg@nvidia.com \
    --cc=kwankhede@nvidia.com \
    --cc=marcel.apfelbaum@gmail.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=yi.l.liu@intel.com \
    --cc=zhenzhong.duan@intel.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;
as well as URLs for NNTP newsgroup(s).