Received: by 2002:a25:b323:0:0:0:0:0 with SMTP id l35csp349369ybj; Thu, 19 Sep 2019 15:31:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqwsgc4Paf+a99pghwTHHFZEvCjWqK0yr9jDxGFPCOggR8+Yd1tBhrx+w1/dBCea8wQCuPMw X-Received: by 2002:a17:906:1c03:: with SMTP id k3mr16187415ejg.32.1568932283120; Thu, 19 Sep 2019 15:31:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568932283; cv=none; d=google.com; s=arc-20160816; b=TE9YjFcBo8KXg/Oc0s2AGm3JvjPGcCSZpdqlys89yHiet5NVhd+2wVFEz5+5SzazdA 7OADPAk0RgUPlE2IhvBxLQFCJjsWVFGFgzcO0GKsTZjChlxKCwXA4KDeSm887lZUX8F2 tf/cfdOZM5AlQDfTogrTpgmNyfxhQOdiQAoAG407sGk8tbQys7MMASXpLf+M0/UaTt2E pZ7MHIRQLD1285hj2WtJuKA71u/BIwPkpjA+VhH9lKAoT8X7YMR18U3MWc3+0XqrWFU1 sAaC8XhRlWZ7LaldPPEtMTnvNDD3rnCi7BliPlx5l6hY8eIfH0hH4+7dqjFONJ4TQJQL xkxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=jXKtWIfX0jthlz5rq0YupFY+gMpUqhC2s+8zSIZ5diY=; b=akDp5bbjOos/9McEu9YSsujOySGmVT4Cmh+oIWa8+h80p/nRmiqIu30KKMu+w8CZAi FdfOPbFx8I2JZSJNmTwCOPeM00hgQFE0vQ/1j6DxX+LwFaF/Jl5SLe+DIHZNhGanRV5m sauN5LffzMMek0N8hBPtFprLa25lfMFr0oJpKvn5frHXszDfXcixpV2Fq3hndARrX2jh 7yfJ8rW4zpEOg5Mh5BinnbDRbExIXVu4d+aqdGgo4J0xfGag4sSv9ufs1f7mdnlNmnUx zi9MlPBtkr9s1J8gqCzGFMN3Cs9qN31PUL52W9yWUnlu5Th2j/vLPWaGvzLxReVD/eAw 3CYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=iAQ+8fB+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b20si2596567ejk.38.2019.09.19.15.30.59; Thu, 19 Sep 2019 15:31:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=iAQ+8fB+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406502AbfISWRj (ORCPT + 99 others); Thu, 19 Sep 2019 18:17:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:58804 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2406488AbfISWRg (ORCPT ); Thu, 19 Sep 2019 18:17:36 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CEE3B20678; Thu, 19 Sep 2019 22:17:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1568931455; bh=wOfno92071SM8Zoy2bQQhGzk30UPTtn44awh7U17Mu0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iAQ+8fB+fNFDqiCVnoqrmiFHFYB/EXIiioGmv+QBR3SnwyIneFB1Sy4sDBCZAR5KV czZqi1wm6ZCfapuv8KNZyfq9i9IMHQd3i5nKLoULyKG1tR1YNMr+GGBusWa4HZU4pL 1gJJtTZdJ5oSV8imIY7MK52I6IfNJtROkuGX2Exk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Stuart Hayes , Joerg Roedel , Sasha Levin Subject: [PATCH 4.14 52/59] iommu/amd: Flush old domains in kdump kernel Date: Fri, 20 Sep 2019 00:04:07 +0200 Message-Id: <20190919214808.023865468@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190919214755.852282682@linuxfoundation.org> References: <20190919214755.852282682@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Stuart Hayes [ Upstream commit 36b7200f67dfe75b416b5281ed4ace9927b513bc ] When devices are attached to the amd_iommu in a kdump kernel, the old device table entries (DTEs), which were copied from the crashed kernel, will be overwritten with a new domain number. When the new DTE is written, the IOMMU is told to flush the DTE from its internal cache--but it is not told to flush the translation cache entries for the old domain number. Without this patch, AMD systems using the tg3 network driver fail when kdump tries to save the vmcore to a network system, showing network timeouts and (sometimes) IOMMU errors in the kernel log. This patch will flush IOMMU translation cache entries for the old domain when a DTE gets overwritten with a new domain number. Signed-off-by: Stuart Hayes Fixes: 3ac3e5ee5ed5 ('iommu/amd: Copy old trans table from old kernel') Signed-off-by: Joerg Roedel Signed-off-by: Sasha Levin --- drivers/iommu/amd_iommu.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c index 684f7cdd814b6..822c85226a29f 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -1150,6 +1150,17 @@ static void amd_iommu_flush_tlb_all(struct amd_iommu *iommu) iommu_completion_wait(iommu); } +static void amd_iommu_flush_tlb_domid(struct amd_iommu *iommu, u32 dom_id) +{ + struct iommu_cmd cmd; + + build_inv_iommu_pages(&cmd, 0, CMD_INV_IOMMU_ALL_PAGES_ADDRESS, + dom_id, 1); + iommu_queue_command(iommu, &cmd); + + iommu_completion_wait(iommu); +} + static void amd_iommu_flush_all(struct amd_iommu *iommu) { struct iommu_cmd cmd; @@ -1835,6 +1846,7 @@ static void set_dte_entry(u16 devid, struct protection_domain *domain, bool ats) { u64 pte_root = 0; u64 flags = 0; + u32 old_domid; if (domain->mode != PAGE_MODE_NONE) pte_root = iommu_virt_to_phys(domain->pt_root); @@ -1877,8 +1889,20 @@ static void set_dte_entry(u16 devid, struct protection_domain *domain, bool ats) flags &= ~DEV_DOMID_MASK; flags |= domain->id; + old_domid = amd_iommu_dev_table[devid].data[1] & DEV_DOMID_MASK; amd_iommu_dev_table[devid].data[1] = flags; amd_iommu_dev_table[devid].data[0] = pte_root; + + /* + * A kdump kernel might be replacing a domain ID that was copied from + * the previous kernel--if so, it needs to flush the translation cache + * entries for the old domain ID that is being overwritten + */ + if (old_domid) { + struct amd_iommu *iommu = amd_iommu_rlookup_table[devid]; + + amd_iommu_flush_tlb_domid(iommu, old_domid); + } } static void clear_dte_entry(u16 devid) -- 2.20.1