Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp328259imm; Fri, 31 Aug 2018 01:22:33 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZTPYxqcd7eP3bwSgIxGVlPYZCYSozc1AVM9gl8xmsVMU+iM5TG2x9QF7FjXOpZuRxLDBxO X-Received: by 2002:a63:3587:: with SMTP id c129-v6mr13333864pga.290.1535703753385; Fri, 31 Aug 2018 01:22:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535703753; cv=none; d=google.com; s=arc-20160816; b=toDv1PU9bZtJw/zbis7sQF9Jkos4Z/KS2uNNoUx6GauzRnqAhb9+RQpfsq0xi86HK9 OTMlTKaX0UQQzsHR58Irs1myRknu026Mb1/Rqdgkac7Z9EqXr/8Fxb+2XzWMB8buW2PU Jp5b7G+KccKvCzH+waZqRAJMmRzDMR28AV/142RJsFQt1+PLOI4sQ+ie7cJKoenwKv/8 47BxODiR+gwacY51pt8xorXnChd/G8XWY05xv8x2XqBOstQKnTWCJ8uyM3s0IBnpMT47 WvGuj/8IdVioSrhVswz+gX2mMEyWPdBRwAOuYFX1VgZ+PEOZctTmgD9BI8SUR60aLIe4 0rGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=Vez20QTKv8aLL9SnxBll09TdDW8S83k4zVAwQLJF07w=; b=riJTHWRGd9btnt+fmogzQXiog7s3Kvr9SX1Mopmvl41zjV37dy7Y8Aoo03SYeKsLCe B+vdpL2L8mqAxgz4B4nnbUgPqH9nUCGyDFrfXC9GZ4342ts/aR4UO75gp5w4a5mzJltZ qW32xJlqzMUejWvsRSzi7kkk4S9Pz/Tx2fkeQA54z9q14nqLt4mmkHNPYONFiYB+KmK7 r8qU3l5lWA/FbHfBhHRNc8XxGmuqv5ZHqwYhkeDCUPCcJPulEM085AWCv7HtUdpcnvod Cu75JWNPjDU0mln61IoyBJHUE0VxhRGdrhwGHMmA7ddeN5KHbL9LK3H3dg32suL/AaeT SlJQ== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b20-v6si8515489pls.78.2018.08.31.01.22.18; Fri, 31 Aug 2018 01:22:33 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727785AbeHaM0p (ORCPT + 99 others); Fri, 31 Aug 2018 08:26:45 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:51122 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727229AbeHaM0o (ORCPT ); Fri, 31 Aug 2018 08:26:44 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AF9EC818F020; Fri, 31 Aug 2018 08:20:26 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-12-30.pek2.redhat.com [10.72.12.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9FCF510D18E0; Fri, 31 Aug 2018 08:20:15 +0000 (UTC) From: Lianbo Jiang To: linux-kernel@vger.kernel.org Cc: mingo@redhat.com, tglx@linutronix.de, hpa@zytor.com, ebiederm@xmission.com, joro@8bytes.org, thomas.lendacky@amd.com, dyoung@redhat.com, kexec@lists.infradead.org, iommu@lists.linux-foundation.org, bhe@redhat.com Subject: [PATCH 4/5 V6] iommu/amd_iommu: remap the device table of IOMMU with the memory encryption mask for kdump Date: Fri, 31 Aug 2018 16:19:29 +0800 Message-Id: <20180831081930.31561-5-lijiang@redhat.com> In-Reply-To: <20180831081930.31561-1-lijiang@redhat.com> References: <20180831081930.31561-1-lijiang@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 31 Aug 2018 08:20:26 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 31 Aug 2018 08:20:26 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'lijiang@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In kdump kernel, it will copy the device table of IOMMU from the old device table, which is encrypted when SME is enabled in the first kernel. So we have to remap the old device table with the memory encryption mask. Signed-off-by: Lianbo Jiang --- drivers/iommu/amd_iommu_init.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c index 84b3e4445d46..3931c7de7c69 100644 --- a/drivers/iommu/amd_iommu_init.c +++ b/drivers/iommu/amd_iommu_init.c @@ -902,12 +902,22 @@ static bool copy_device_table(void) } } - old_devtb_phys = entry & PAGE_MASK; + /* + * When SME is enabled in the first kernel, the entry includes the + * memory encryption mask(sme_me_mask), we must remove the memory + * encryption mask to obtain the true physical address in kdump kernel. + */ + old_devtb_phys = __sme_clr(entry) & PAGE_MASK; + if (old_devtb_phys >= 0x100000000ULL) { pr_err("The address of old device table is above 4G, not trustworthy!\n"); return false; } - old_devtb = memremap(old_devtb_phys, dev_table_size, MEMREMAP_WB); + old_devtb = (sme_active() && is_kdump_kernel()) + ? (__force void *)ioremap_encrypted(old_devtb_phys, + dev_table_size) + : memremap(old_devtb_phys, dev_table_size, MEMREMAP_WB); + if (!old_devtb) return false; -- 2.17.1