From: Ben-Ami Yassour Subject: RE: [PATCH] KVM: PCIPT: VT-d: fix context mapping Date: Thu, 19 Jun 2008 15:28:44 +0300 Message-ID: <1213878524.7454.4.camel@lnx-benami> References: <1213729526-10410-1-git-send-email-benami@il.ibm.com> <1213729526-10410-2-git-send-email-benami@il.ibm.com> <1213729526-10410-3-git-send-email-benami@il.ibm.com> <1213729526-10410-4-git-send-email-benami@il.ibm.com> <1213729526-10410-5-git-send-email-benami@il.ibm.com> <08DF4D958216244799FC84F3514D70F00180ECFD@pdsmsx415.ccr.corp.intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: amit.shah@qumranet.com, Muli Ben-Yehuda , raharper@us.ibm.com, kvm@vger.kernel.org To: "Han, Weidong" Return-path: Received: from mtagate6.uk.ibm.com ([195.212.29.139]:55700 "EHLO mtagate6.uk.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755525AbYFSM3k (ORCPT ); Thu, 19 Jun 2008 08:29:40 -0400 Received: from d06nrmr1407.portsmouth.uk.ibm.com (d06nrmr1407.portsmouth.uk.ibm.com [9.149.38.185]) by mtagate6.uk.ibm.com (8.13.8/8.13.8) with ESMTP id m5JCSk7o672948 for ; Thu, 19 Jun 2008 12:28:46 GMT Received: from d06av01.portsmouth.uk.ibm.com (d06av01.portsmouth.uk.ibm.com [9.149.37.212]) by d06nrmr1407.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v9.0) with ESMTP id m5JCSkfh2490392 for ; Thu, 19 Jun 2008 13:28:46 +0100 Received: from d06av01.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av01.portsmouth.uk.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id m5JCSji7026654 for ; Thu, 19 Jun 2008 13:28:46 +0100 In-Reply-To: <08DF4D958216244799FC84F3514D70F00180ECFD@pdsmsx415.ccr.corp.intel.com> Sender: kvm-owner@vger.kernel.org List-ID: On Thu, 2008-06-19 at 16:59 +0800, Han, Weidong wrote: > benami@il.ibm.com wrote: > > From: Ben-Ami Yassour > >=20 > > When changing the VT-d context mapping, according to the spec, it i= s > > required=20 > > to first set the context to not present, flush and only then apply = the > > new context. > >=20 > > Signed-off-by: Ben-Ami Yassour > > --- > > drivers/pci/intel-iommu.c | 17 +++++++++++++++++ > > 1 files changed, 17 insertions(+), 0 deletions(-) > >=20 > > diff --git a/drivers/pci/intel-iommu.c b/drivers/pci/intel-iommu.c > > index 930874f..dcdfa97 100644 > > --- a/drivers/pci/intel-iommu.c > > +++ b/drivers/pci/intel-iommu.c > > @@ -56,6 +56,7 @@ > >=20 > >=20 > > static void flush_unmaps_timeout(unsigned long data); > > +static void detach_domain_for_dev(struct dmar_domain *domain, u8 > > bus, u8 devfn);=20 > >=20 > > DEFINE_TIMER(unmap_timer, flush_unmaps_timeout, 0, 0); > >=20 > > @@ -1264,7 +1265,23 @@ static int domain_context_mapping_one(struct > > dmar_domain *domain, if (!context) > > return -ENOMEM; > > spin_lock_irqsave(&iommu->lock, flags); > > + > > + if (context_present(*context) && > > + (context_domain_id(*context) =3D=3D domain->id) && > > + (context_address_width(*context) =3D=3D domain->agaw) && > > + (context_address_root(*context) =3D=3D > virt_to_phys(domain->pgd)) && > > + (context_translation_type(*context) =3D=3D > CONTEXT_TT_MULTI_LEVEL) > > && + (!context_fault_disable(*context))) { > > + spin_unlock_irqrestore(&iommu->lock, flags); > > + return 0; > > + } >=20 > Only need to check context_present(*context) according to VT-d spec, > which says "software must not modify fields other than the Present (P= ) > field of currently present root-entries or context-entries." >=20 > Randy (Weidong) The logic here is that, if no change is made to the context then just return ok (0). Otherwise, according to the spec, we need to first invalidate the context, flush it, and only then apply the changes to th= e context. The other option is to make sure that before every call to this functio= n the context is invalidated, but disabling it inside the function seems safer. =EF=BB=BFdo you agree with that? Regards, Ben >=20 > > + > > + spin_unlock_irqrestore(&iommu->lock, flags); > > + > > + detach_domain_for_dev(domain, bus, devfn); > >=20 > > + spin_lock_irqsave(&iommu->lock, flags); > > + > > context_clear_entry(*context); > > context_set_domain_id(*context, domain->id); > > context_set_address_width(*context, domain->agaw);