From: Peter Xu <peterx@redhat.com>
To: "Liu, Yi L" <yi.l.liu@intel.com>
Cc: "qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
"Lan, Tianyu" <tianyu.lan@intel.com>,
"Michael S . Tsirkin" <mst@redhat.com>,
Jason Wang <jasowang@redhat.com>,
Marcel Apfelbaum <marcel@redhat.com>,
David Gibson <david@gibson.dropbear.id.au>
Subject: Re: [Qemu-devel] [PATCH v2 7/7] intel_iommu: support passthrough (PT)
Date: Thu, 20 Apr 2017 11:07:14 +0800 [thread overview]
Message-ID: <20170420030714.GB26087@pxdev.xzpeter.org> (raw)
In-Reply-To: <A2975661238FB949B60364EF0F2C257439054CF5@shsmsx102.ccr.corp.intel.com>
On Wed, Apr 19, 2017 at 07:13:47AM +0000, Liu, Yi L wrote:
> Peter,
>
> Besides the gPA->hPA mapping, pt mode enabling requires some sanity check on
> s->pt_supported. See comments inline.
>
> > -----Original Message-----
> > From: Qemu-devel [mailto:qemu-devel-bounces+yi.l.liu=intel.com@nongnu.org] On
> > Behalf Of Peter Xu
> > Sent: Monday, April 17, 2017 7:32 PM
> > To: qemu-devel@nongnu.org
> > Cc: Lan, Tianyu <tianyu.lan@intel.com>; Michael S . Tsirkin <mst@redhat.com>;
> > Jason Wang <jasowang@redhat.com>; peterx@redhat.com; Marcel Apfelbaum
> > <marcel@redhat.com>; David Gibson <david@gibson.dropbear.id.au>
> > Subject: [Qemu-devel] [PATCH v2 7/7] intel_iommu: support passthrough (PT)
> >
> > Signed-off-by: Peter Xu <peterx@redhat.com>
> > ---
> > hw/i386/intel_iommu.c | 109 +++++++++++++++++++++++++++++++++--------
> > hw/i386/intel_iommu_internal.h | 1 +
> > hw/i386/trace-events | 1 +
> > hw/i386/x86-iommu.c | 1 +
> > include/hw/i386/x86-iommu.h | 1 +
> > 5 files changed, 93 insertions(+), 20 deletions(-)
> >
> > diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index
> > 05ae631..deb2007 100644
> > --- a/hw/i386/intel_iommu.c
> > +++ b/hw/i386/intel_iommu.c
> > @@ -872,7 +872,7 @@ static int vtd_dev_to_context_entry(IntelIOMMUState *s,
> > uint8_t bus_num,
> > } else {
> > switch (vtd_ce_get_type(ce)) {
> > case VTD_CONTEXT_TT_MULTI_LEVEL:
> > - /* fall through */
> > + case VTD_CONTEXT_TT_PASS_THROUGH:
>
> Passthru type is a reserved type if ecap.PT=0, so add a check here. If s->pt_supported
> is false, report this translation type as unsupported and report an invalid context
> programming to guest.
>
> > case VTD_CONTEXT_TT_DEV_IOTLB:
> > break;
> > default:
> > @@ -883,6 +883,73 @@ static int vtd_dev_to_context_entry(IntelIOMMUState *s,
> > uint8_t bus_num,
> > return 0;
> > }
> >
> > +/* Fetch translation type for specific device. Returns <0 if error
> > + * happens, otherwise return the shifted type to check against
> > + * VTD_CONTEXT_TT_*. */
> > +static int vtd_dev_get_trans_type(VTDAddressSpace *as) {
> > + IntelIOMMUState *s;
> > + VTDContextEntry ce;
> > + int ret;
> > +
> > + s = as->iommu_state;
> > +
> > + ret = vtd_dev_to_context_entry(s, pci_bus_num(as->bus),
> > + as->devfn, &ce);
> > + if (ret) {
> > + return ret;
> > + }
> > +
> > + return vtd_ce_get_type(&ce);
> > +}
> > +
> > +static bool vtd_dev_pt_enabled(VTDAddressSpace *as) {
> > + int ret;
> > +
> > + assert(as);
> > +
> > + ret = vtd_dev_get_trans_type(as);
> > + if (ret < 0) {
> > + /*
> > + * Possibly failed to parse the context entry for some reason
> > + * (e.g., during init, or any guest configuration errors on
> > + * context entries). We should assume PT not enabled for
> > + * safety.
> > + */
> > + return false;
> > + }
> > +
> > + return ret == VTD_CONTEXT_TT_PASS_THROUGH; }
> > +
> > +static void vtd_switch_address_space(VTDAddressSpace *as) {
> > + bool use_iommu;
> > +
> > + assert(as);
> > +
> > + use_iommu = as->iommu_state->dmar_enabled;
> > + if (use_iommu) {
>
> if s->pt_supported is false, no need to check the context.TT, even
> context.TT=pt, then it should be an invalid context programming.
Agree with you on both comments. Thanks. :-)
--
Peter Xu
next prev parent reply other threads:[~2017-04-20 3:07 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-17 11:32 [Qemu-devel] [PATCH v2 0/7] VT-d: PT (passthrough) mode support and misc fixes Peter Xu
2017-04-17 11:32 ` [Qemu-devel] [PATCH v2 1/7] memory: tune last param of iommu_ops.translate() Peter Xu
2017-04-18 4:07 ` David Gibson
2017-04-17 11:32 ` [Qemu-devel] [PATCH v2 2/7] memory: remove the last param in memory_region_iommu_replay() Peter Xu
2017-04-18 4:08 ` David Gibson
2017-04-17 11:32 ` [Qemu-devel] [PATCH v2 3/7] x86-iommu: use DeviceClass properties Peter Xu
2017-04-17 11:32 ` [Qemu-devel] [PATCH v2 4/7] intel_iommu: renaming context entry helpers Peter Xu
2017-04-17 11:32 ` [Qemu-devel] [PATCH v2 5/7] intel_iommu: provide vtd_ce_get_type() Peter Xu
2017-04-17 11:32 ` [Qemu-devel] [PATCH v2 6/7] intel_iommu: use IOMMU_ACCESS_FLAG() Peter Xu
2017-04-17 11:32 ` [Qemu-devel] [PATCH v2 7/7] intel_iommu: support passthrough (PT) Peter Xu
2017-04-18 4:30 ` Liu, Yi L
2017-04-18 4:54 ` Peter Xu
2017-04-18 6:02 ` Liu, Yi L
2017-04-18 7:27 ` Peter Xu
2017-04-18 9:04 ` Liu, Yi L
2017-04-19 7:27 ` Lan Tianyu
2017-04-20 3:04 ` Peter Xu
2017-04-20 4:55 ` Liu, Yi L
2017-04-20 5:40 ` Peter Xu
2017-04-20 6:36 ` Liu, Yi L
2017-04-20 7:04 ` Peter Xu
2017-04-20 7:10 ` Lan Tianyu
2017-04-20 6:51 ` Lan, Tianyu
2017-04-20 7:00 ` Peter Xu
2017-04-19 7:13 ` Liu, Yi L
2017-04-20 3:07 ` Peter Xu [this message]
2017-04-18 10:29 ` [Qemu-devel] [PATCH v2 0/7] VT-d: PT (passthrough) mode support and misc fixes Paolo Bonzini
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=20170420030714.GB26087@pxdev.xzpeter.org \
--to=peterx@redhat.com \
--cc=david@gibson.dropbear.id.au \
--cc=jasowang@redhat.com \
--cc=marcel@redhat.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=tianyu.lan@intel.com \
--cc=yi.l.liu@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.