Received: by 2002:a25:b323:0:0:0:0:0 with SMTP id l35csp940678ybj; Fri, 20 Sep 2019 02:28:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqwUNudaBrxWfHgGeHNSf/4F5MvU9u+WCQVLI0hMOSLh3iOCkDZfsF7yTlvuLaTXlhc3aYSE X-Received: by 2002:a50:a557:: with SMTP id z23mr20168192edb.99.1568971700345; Fri, 20 Sep 2019 02:28:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568971700; cv=none; d=google.com; s=arc-20160816; b=doURE3llsLq/Frw5Tl56ITtbmTy/zg/j9eppSepFJyds1Gv3D40HWdKpsnXfvP8Chw FSgrujmBKT4RbWhH7VmE3RXFfciPcO2cjC7OyfWcdeAegBXrlH+uId7dgvm0q5ztT9j8 AS18vwmVEEze1Fkq/uqzn4N8rPwwSBNLmz24pTsGbJI17Weer6CtjnZR1hT0LtPLMHQi FXA+pTciFMhP7E30eTAQPBVsnbk7f1fIUTJA7u4IRtiGUnoEetgGdGWh3i7LpWMp/3C+ YQXlPTOE13w5ogX/MYNbv6BoAfq52A038XdbCjhPzQhdRRJC749v0IDYYHEs2yzVXCLd SNwQ== 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=P71Y2p13oNtNDdVHC8SqZ7R5oL653QW4XfH4vLCL8jY=; b=J0qJtWn12eTupDlGkwgpD31jIjFoJevdx7LfbJA0b3b3lxijRNiUdp1A+vgC6OdgH4 +2wm6VX7Lu56rnVHhBCZhy0jJ3E7xRe09bwENt3Q9eI7sY8E8VqGsm5qCrBpX5JgDWwG JnOcoSaWbCxL/VR+PFh8Qcq6yJnW7DCprPLNWR43SAf7K5RchupWZ5FEE2Y+hXPKnPM0 bzdk5w/uPOpEJypIHoLtn4toCOa0cFfKeuIVspjd4mpJhgSESZX79ME52NyDNNBNMRFd UolUXksth9qXr4Tv0fEhIZkQct807MAlWRAtUTJgQu8TyUlmJEv4Gv/PwqsGPuZKb3ZB Sf6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=IF9BKjRO; 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 n2si701351ejy.35.2019.09.20.02.27.57; Fri, 20 Sep 2019 02:28:20 -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=IF9BKjRO; 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 S2393555AbfISWLR (ORCPT + 99 others); Thu, 19 Sep 2019 18:11:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:49834 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2393539AbfISWLN (ORCPT ); Thu, 19 Sep 2019 18:11:13 -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 166AF218AF; Thu, 19 Sep 2019 22:11:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1568931071; bh=Zqd5/E63vnr/mwIYahJPTQHIhkHsBfJp65brYETECCo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IF9BKjROGgu8k6CDVh5+wAJm7iJc0fyPWfYgQZ/PDnViSZTCB7BGWEWyzoO95IcPP j+geUez3Th4WK58ner7DSnCwP9nbW8mpFDDJzTSZTZaNz8X2hTi2K3oMGg4JBW9J8K 4Prcd6sC44kfs9jP1ihg8sDCn8KoQygyOmR/L0Aw= 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 5.2 118/124] iommu/amd: Flush old domains in kdump kernel Date: Fri, 20 Sep 2019 00:03:26 +0200 Message-Id: <20190919214823.471987280@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190919214819.198419517@linuxfoundation.org> References: <20190919214819.198419517@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 dce1d8d2e8a44..b265062edf6c8 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -1143,6 +1143,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; @@ -1863,6 +1874,7 @@ static void set_dte_entry(u16 devid, struct protection_domain *domain, { 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); @@ -1912,8 +1924,20 @@ static void set_dte_entry(u16 devid, struct protection_domain *domain, 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