Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933736AbcLACOg (ORCPT ); Wed, 30 Nov 2016 21:14:36 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57194 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753741AbcLACOe (ORCPT ); Wed, 30 Nov 2016 21:14:34 -0500 Reply-To: xlpang@redhat.com Subject: Re: [PATCH] iommu/vt-d: Flush old iotlb for kdump when the device gets context mapped References: <1479286950-21885-1-git-send-email-xlpang@redhat.com> <582C232F.6080205@redhat.com> <582D1A40.409@redhat.com> <20161129143547.GG2078@8bytes.org> <583E8A9B.7070906@redhat.com> <20161130090327.GA4192@x1> <20161130095334.GB4192@x1> <20161130102334.GC4192@x1> <20161130142642.GJ2078@8bytes.org> To: Joerg Roedel , Baoquan He Cc: xlpang@redhat.com, Don Brace , Myron Stowe , kexec@lists.infradead.org, LKML , iommu@lists.linux-foundation.org, Myron Stowe , Dave Young , David Woodhouse From: Xunlei Pang Message-ID: <583F87D1.6030402@redhat.com> Date: Thu, 1 Dec 2016 10:15:45 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: <20161130142642.GJ2078@8bytes.org> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 01 Dec 2016 02:14:34 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1975 Lines: 47 On 11/30/2016 at 10:26 PM, Joerg Roedel wrote: > On Wed, Nov 30, 2016 at 06:23:34PM +0800, Baoquan He wrote: >> OK, talked with Xunlei. The old cache could be entry with present bit >> set. > -EPARSE > > Anyway, what I was trying to say is, that the IOMMU TLB is tagged with > domain-ids, and that there is also a context-cache which maps device-ids > to domain-ids. > > If we update the context entry then we need to flush only the context > entry, as it will point to a new domain-id then and future IOTLB lookups > in the IOMMU will be using the new domain-id and do not match the old > entries. Hi Joerg, Thanks for the explanation, and we still need to flush context cache using old domain-id, right? How about the following update? index 3965e73..624eac9 100644 --- a/drivers/iommu/intel-iommu.c +++ b/drivers/iommu/intel-iommu.c @@ -2024,6 +2024,25 @@ static int domain_context_mapping_one(struct dmar_domain *domain, if (context_present(context)) goto out_unlock; + /* + * For kdump cases, old valid entries may be cached due to the + * in-flight DMA and copied pgtable, but there is no unmapping + * behaviour for them, thus we need an explicit cache flush for + * the newly-mapped device. For kdump, at this point, the device + * is supposed to finish reset at its driver probe stage, so no + * in-flight DMA will exist, and we don't need to worry anymore + * hereafter. + */ + if (context_copied(context)) { + u16 did_old = context_domain_id(context); + + if (did_old >= 0 && did_old < cap_ndoms(iommu->cap)) + iommu->flush.flush_context(iommu, did_old, + (((u16)bus) << 8) | devfn, + DMA_CCMD_MASK_NOBIT, + DMA_CCMD_DEVICE_INVL); + } + pgd = domain->pgd;