Received: by 2002:ac0:a874:0:0:0:0:0 with SMTP id c49csp316817ima; Fri, 15 Mar 2019 03:33:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqwOtQF/dB1sYT/kHGR0pt3lUdXKK1UZrWoN2EHELpqizY8QetKti6uGdQJd55OD9fNTMvly X-Received: by 2002:a17:902:b493:: with SMTP id y19mr3528784plr.9.1552646030160; Fri, 15 Mar 2019 03:33:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552646030; cv=none; d=google.com; s=arc-20160816; b=E+fL5FSdJkVp6PUc8T7hpN9F0UYovPx1lCytqv8CYoPg7FhQ36jt/qiv1HL/WHPtM5 YBP4/44eKJnivLXxczDjPQu4ZFy/K/96QqVSzOZN3uJG34Xk26KiG5/xQtz47/8EFBLL x2jDp3GaVHgg/sMu4suIar1UU6flHRw5yJRJIiUCac4wkvnHjDqER82cyLSN/YLycScv l5XjDTKp90wBXaWwskdOdNXyqZQG08zH2e0kKXEDu/NGjRDqytmoLmhhG9hqaPktIX1g AZFz3yxLiyGNsBqh6mzbyhMvfaEluywI2hk0QRKpyNnGG/jKvtPI+dET9CFyJ9fRDKUM eAJw== 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; bh=NANYKgKUuhq9JiW0CN3f8bT5ooLuItWBTbE+eL/yjUk=; b=yHx5yBQka8FW9CNHryVK1Ol5WTvxDxGlzu2gR3J7BDyUWZn/wUtkLMfWOlNSyMdIDR rOX9W/svlkSd8Vmfc4KZr9EnYSnupRbwtc7ayOUCEvFGXNt35dvDz9wW8kXZFafhGJxH mKQw+Geok8OpSCG8nmrRAJTnHnZLZuPzMIExtawzWHaLz8CjXzcZY4kKkE4Nle+rLqvS 8DB4/RktTquNSgsNoDAEI8WDjFTbtFoRjYjRLIbIIPAw/aqxL+2ccBoy6h1hxj/vhgLp 1qHZOGpJzhNH8ItJSVkPp9UTLEW6si/beXgGzE3aD0O5kNDWdTMk7CIH7889/TICRGrX T9Bw== 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 o17si1476877pll.344.2019.03.15.03.33.35; Fri, 15 Mar 2019 03:33:50 -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 S1728876AbfCOKcq (ORCPT + 99 others); Fri, 15 Mar 2019 06:32:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50726 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728676AbfCOKcq (ORCPT ); Fri, 15 Mar 2019 06:32:46 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CBA2AE8B18; Fri, 15 Mar 2019 10:32:45 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-12-223.pek2.redhat.com [10.72.12.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0B9555C642; Fri, 15 Mar 2019 10:32:34 +0000 (UTC) From: Lianbo Jiang To: linux-kernel@vger.kernel.org Cc: kexec@lists.infradead.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, x86@kernel.org, hpa@zytor.com, akpm@linux-foundation.org, dyoung@redhat.com, brijesh.singh@amd.com, thomas.lendacky@amd.com, bhe@redhat.com Subject: [PATCH 2/3] kexec: Set the C-bit in the identity map page table when SEV is active Date: Fri, 15 Mar 2019 18:32:02 +0800 Message-Id: <20190315103203.13128-3-lijiang@redhat.com> In-Reply-To: <20190315103203.13128-1-lijiang@redhat.com> References: <20190315103203.13128-1-lijiang@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 15 Mar 2019 10:32:45 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When SEV is active, the second kernel image is loaded into the encrypted memory. Lets make sure that when kexec builds the identity mapping page table it adds the memory encryption mask(C-bit). Co-developed-by: Brijesh Singh Signed-off-by: Brijesh Singh Signed-off-by: Lianbo Jiang --- arch/x86/kernel/machine_kexec_64.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/machine_kexec_64.c b/arch/x86/kernel/machine_kexec_64.c index bcebf4993da4..8c58d1864500 100644 --- a/arch/x86/kernel/machine_kexec_64.c +++ b/arch/x86/kernel/machine_kexec_64.c @@ -56,6 +56,7 @@ static int init_transition_pgtable(struct kimage *image, pgd_t *pgd) pte_t *pte; unsigned long vaddr, paddr; int result = -ENOMEM; + pgprot_t prot = PAGE_KERNEL_EXEC_NOENC; vaddr = (unsigned long)relocate_kernel; paddr = __pa(page_address(image->control_code_page)+PAGE_SIZE); @@ -92,7 +93,11 @@ static int init_transition_pgtable(struct kimage *image, pgd_t *pgd) set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE)); } pte = pte_offset_kernel(pmd, vaddr); - set_pte(pte, pfn_pte(paddr >> PAGE_SHIFT, PAGE_KERNEL_EXEC_NOENC)); + + if (sev_active()) + prot = PAGE_KERNEL_EXEC; + + set_pte(pte, pfn_pte(paddr >> PAGE_SHIFT, prot)); return 0; err: return result; @@ -129,6 +134,11 @@ static int init_pgtable(struct kimage *image, unsigned long start_pgtable) level4p = (pgd_t *)__va(start_pgtable); clear_page(level4p); + if (sev_active()) { + info.page_flag |= _PAGE_ENC; + info.kernpg_flag = _KERNPG_TABLE; + } + if (direct_gbpages) info.direct_gbpages = true; -- 2.17.1