From: Peter Xu <peterx@redhat.com>
To: Eugenio Perez Martin <eperezma@redhat.com>
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
"Aleksandar Rikalo" <aleksandar.rikalo@syrmia.com>,
"Yan Zhao" <yan.y.zhao@intel.com>,
"Eduardo Habkost" <ehabkost@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
"Jason Wang" <jasowang@redhat.com>,
"Juan Quintela" <quintela@redhat.com>,
"Hervé Poussineau" <hpoussin@reactos.org>,
qemu-level <qemu-devel@nongnu.org>,
"Eric Auger" <eric.auger@redhat.com>,
qemu-arm@nongnu.org, qemu-ppc@nongnu.org,
"Avi Kivity" <avi@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"David Gibson" <david@gibson.dropbear.id.au>,
"Richard Henderson" <rth@twiddle.net>
Subject: Re: [PATCH 5/5] memory: Skip bad range assertion if notifier is DEVIOTLB_UNMAP type
Date: Mon, 28 Sep 2020 13:48:57 -0400 [thread overview]
Message-ID: <20200928174857.GC59869@xz-x1> (raw)
In-Reply-To: <CAJaqyWfwGP7_Ex=NhG_po+A1BkN3OCV=+3Vwi8uhLJ_e4UA5NQ@mail.gmail.com>
On Mon, Sep 28, 2020 at 11:05:01AM +0200, Eugenio Perez Martin wrote:
> On Fri, Sep 4, 2020 at 6:34 AM Jason Wang <jasowang@redhat.com> wrote:
> >
> >
> > On 2020/9/4 上午12:14, Eugenio Pérez wrote:
> > > Device IOTLB invalidations can unmap arbitrary ranges, eiter outside of
> > > the memory region or even [0, ~0ULL] for all the space. The assertion
> > > could be hit by a guest, and rhel7 guest effectively hit it.
> > >
> > > Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
> > > Reviewed-by: Peter Xu <peterx@redhat.com>
> > > Reviewed-by: Juan Quintela <quintela@redhat.com>
> > > ---
> > > softmmu/memory.c | 13 +++++++++++--
> > > 1 file changed, 11 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/softmmu/memory.c b/softmmu/memory.c
> > > index 8694fc7cf7..e723fcbaa1 100644
> > > --- a/softmmu/memory.c
> > > +++ b/softmmu/memory.c
> > > @@ -1895,6 +1895,7 @@ void memory_region_notify_iommu_one(IOMMUNotifier *notifier,
> > > {
> > > IOMMUTLBEntry *entry = &event->entry;
> > > hwaddr entry_end = entry->iova + entry->addr_mask;
> > > + IOMMUTLBEntry tmp = *entry;
> > >
> > > if (event->type == IOMMU_NOTIFIER_UNMAP) {
> > > assert(entry->perm == IOMMU_NONE);
> > > @@ -1908,10 +1909,18 @@ void memory_region_notify_iommu_one(IOMMUNotifier *notifier,
> > > return;
> > > }
> > >
> > > - assert(entry->iova >= notifier->start && entry_end <= notifier->end);
> > > + if (notifier->notifier_flags & IOMMU_NOTIFIER_DEVIOTLB_UNMAP) {
> > > + /* Crop (iova, addr_mask) to range */
> > > + tmp.iova = MAX(tmp.iova, notifier->start);
> > > + tmp.addr_mask = MIN(entry_end, notifier->end) - tmp.iova;
> > > + /* Confirm no underflow */
> > > + assert(MIN(entry_end, notifier->end) >= tmp.iova);
> >
> >
> > It's still not clear to me why we need such assert. Consider
> > notifier->end is the possible IOVA range but not possible device IOTLB
> > invalidation range (e.g it allows [0, ULLONG_MAX]).
> >
> > Thanks
> >
>
> As far as I understood the device should admit that out of bounds
> notifications in that case,
> and the assert just makes sure that there was no underflow in
> tmp.addr_mask, i.e., that something
> very wrong that should never happen in production happened.
>
> Peter, would you mind to confirm/correct it?
I think Jason is right - since we have checked at the entry that the two
regions cross over each other:
/*
* Skip the notification if the notification does not overlap
* with registered range.
*/
if (notifier->start > entry_end || notifier->end < entry->iova) {
return;
}
Then I don't see how this assertion can fail any more.
But imho not a big problem either, and it shouldn't hurt to even keep the
assertion of above isn't that straightforward.
>
> Is there anything else needed to pull this patch?
I didn't post a pull for this only because I shouldn't :) - the plan was that
all vt-d patches will still go via Michael's tree, iiuc. Though at least to me
I think this series is acceptable for merging.
Though it would always be good too if Jason would still like to review it.
Jason, what's your opinion?
Thanks,
--
Peter Xu
next prev parent reply other threads:[~2020-09-28 18:02 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-25 19:16 [RFC 0/1] memory: Delete assertion in memory_region_unregister_iommu_notifier Eugenio Pérez
2020-06-25 19:16 ` [RFC 1/1] " Eugenio Pérez
2020-06-25 19:29 ` [RFC 0/1] " no-reply
2020-08-26 14:36 ` [RFC v6 00/13] " Eugenio Pérez
2020-08-26 14:36 ` [RFC v6 01/13] memory: Rename memory_region_notify_one to memory_region_notify_iommu_one Eugenio Pérez
2020-08-26 14:36 ` [RFC v6 02/13] memory: Add IOMMUTLBNotificationType to IOMMUTLBEntry Eugenio Pérez
2020-08-26 15:42 ` Peter Xu
2020-08-27 6:11 ` Eugenio Perez Martin
2020-08-26 14:36 ` [RFC v6 03/13] hw/alpha/typhoon: Mark all IOMMUTLBEntry as IOMMU_IOTLB_NONE type Eugenio Pérez
2020-08-26 15:50 ` Peter Xu
2020-08-26 14:36 ` [RFC v6 04/13] amd_iommu: " Eugenio Pérez
2020-08-26 14:36 ` [RFC v6 05/13] hw/arm/smmu: Fill IOMMUTLBEntry notifier type Eugenio Pérez
2020-08-26 14:36 ` [RFC v6 06/13] dma/rc4030: Mark all IOMMUTLBEntry as IOMMU_IOTLB_NONE type Eugenio Pérez
2020-08-26 14:36 ` [RFC v6 07/13] intel_iommu: Mark IOMMUTLBEntry of page notification as IOMMU_IOTLB_UNMAP type Eugenio Pérez
2020-08-26 14:36 ` [RFC v6 08/13] virtio-iommu: Mark virtio_iommu_translate IOTLB as IOMMU_IOTLB_NONE type Eugenio Pérez
2020-08-26 14:36 ` [RFC v6 09/13] intel_iommu: Set IOMMUTLBEntry type in vtd_page_walk_level Eugenio Pérez
2020-08-26 14:36 ` [RFC v6 10/13] memory: Notify IOMMU IOTLB based on entry type, not permissions Eugenio Pérez
2020-08-26 14:36 ` [RFC v6 11/13] memory: Add IOMMU_DEVIOTLB_UNMAP IOMMUTLBNotificationType Eugenio Pérez
2020-08-26 14:36 ` [RFC v6 12/13] intel_iommu: Do not notify regular iotlb to device-iotlb notifiers Eugenio Pérez
2020-08-26 16:51 ` 罗勇刚(Yonggang Luo)
2020-08-27 6:56 ` Eugenio Perez Martin
2020-08-26 14:36 ` [RFC v6 13/13] memory: Skip bad range assertion if notifier is DEVIOTLB type Eugenio Pérez
2020-08-26 15:00 ` [RFC v6 00/13] memory: Delete assertion in memory_region_unregister_iommu_notifier Eugenio Perez Martin
2020-08-26 15:54 ` Peter Xu
2020-08-27 6:53 ` Eugenio Perez Martin
2020-09-03 16:14 ` [PATCH 0/5] memory: Skip " Eugenio Pérez
2020-09-03 16:14 ` [PATCH 1/5] memory: Rename memory_region_notify_one to memory_region_notify_iommu_one Eugenio Pérez
2020-09-03 16:14 ` [PATCH 2/5] memory: Add IOMMUTLBEvent Eugenio Pérez
2020-09-03 16:14 ` [PATCH 3/5] memory: Add IOMMU_NOTIFIER_DEVIOTLB_UNMAP IOMMUTLBNotificationType Eugenio Pérez
2020-09-03 16:14 ` [PATCH 4/5] intel_iommu: Skip page walking on device iotlb invalidations Eugenio Pérez
2020-09-04 18:32 ` Peter Xu
2020-09-03 16:14 ` [PATCH 5/5] memory: Skip bad range assertion if notifier is DEVIOTLB_UNMAP type Eugenio Pérez
2020-09-04 4:34 ` Jason Wang
2020-09-28 9:05 ` Eugenio Perez Martin
2020-09-28 17:48 ` Peter Xu [this message]
2020-10-03 17:38 ` Michael S. Tsirkin
2020-10-05 6:32 ` Eugenio Perez Martin
2020-10-15 7:50 ` Jason Wang
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=20200928174857.GC59869@xz-x1 \
--to=peterx@redhat.com \
--cc=aleksandar.rikalo@syrmia.com \
--cc=avi@redhat.com \
--cc=david@gibson.dropbear.id.au \
--cc=ehabkost@redhat.com \
--cc=eperezma@redhat.com \
--cc=eric.auger@redhat.com \
--cc=hpoussin@reactos.org \
--cc=jasowang@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=quintela@redhat.com \
--cc=rth@twiddle.net \
--cc=yan.y.zhao@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).