From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751506AbdH3PsM (ORCPT ); Wed, 30 Aug 2017 11:48:12 -0400 Received: from mga03.intel.com ([134.134.136.65]:34290 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751375AbdH3PsL (ORCPT ); Wed, 30 Aug 2017 11:48:11 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,449,1498546800"; d="scan'208";a="129973222" Date: Wed, 30 Aug 2017 08:50:25 -0700 From: Jacob Pan To: Filippo Sironi via iommu Cc: linux-kernel@vger.kernel.org, Filippo Sironi , David Woodhouse , David Woodhouse , jacob.jun.pan@linux.intel.com Subject: Re: [PATCH] intel-iommu: Don't be too aggressive when clearing one context entry Message-ID: <20170830085025.7027c9f8@jacob-builder> In-Reply-To: <1503929789-26698-1-git-send-email-sironi@amazon.de> References: <1503929789-26698-1-git-send-email-sironi@amazon.de> Organization: OTC X-Mailer: Claws Mail 3.13.2 (GTK+ 2.24.30; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 28 Aug 2017 16:16:29 +0200 Filippo Sironi via iommu wrote: > Previously, we were invalidating context cache and IOTLB globally when > clearing one context entry. This is a tad too aggressive. > Invalidate the context cache and IOTLB for the interested device only. > > Signed-off-by: Filippo Sironi > Cc: David Woodhouse > Cc: David Woodhouse > Cc: Joerg Roedel > Cc: iommu@lists.linux-foundation.org > Cc: linux-kernel@vger.kernel.org > --- > drivers/iommu/intel-iommu.c | 25 ++++++++++++++++++++++--- > 1 file changed, 22 insertions(+), 3 deletions(-) > > diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c > index 3e8636f1220e..4bf3e59b0929 100644 > --- a/drivers/iommu/intel-iommu.c > +++ b/drivers/iommu/intel-iommu.c > @@ -2351,13 +2351,32 @@ static inline int domain_pfn_mapping(struct > dmar_domain *domain, unsigned long i > static void domain_context_clear_one(struct intel_iommu *iommu, u8 > bus, u8 devfn) { > + unsigned long flags; > + struct context_entry *context; > + u16 did_old; > + > if (!iommu) > return; > > + spin_lock_irqsave(&iommu->lock, flags); > + context = iommu_context_addr(iommu, bus, devfn, 0); > + if (!context) { > + spin_unlock_irqrestore(&iommu->lock, flags); > + return; > + } perhaps check with device_context_mapped()? > + did_old = context_domain_id(context); > + spin_unlock_irqrestore(&iommu->lock, flags); > clear_context_table(iommu, bus, devfn); > - iommu->flush.flush_context(iommu, 0, 0, 0, > - DMA_CCMD_GLOBAL_INVL); > - iommu->flush.flush_iotlb(iommu, 0, 0, 0, > DMA_TLB_GLOBAL_FLUSH); > + iommu->flush.flush_context(iommu, > + did_old, > + (((u16)bus) << 8) | devfn, > + DMA_CCMD_MASK_NOBIT, > + DMA_CCMD_DEVICE_INVL); > + iommu->flush.flush_iotlb(iommu, > + did_old, > + 0, > + 0, > + DMA_TLB_DSI_FLUSH); > } > > static inline void unlink_domain_info(struct device_domain_info > *info) [Jacob Pan]