Received: by 2002:ac0:a874:0:0:0:0:0 with SMTP id c49csp316644ima; Fri, 15 Mar 2019 03:33:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqwnsePQUr++zk4Hmlz0ixQO0BkXeGMz84fN51XOZIWD3+4YyUxQlXb6XpDwVsf6AW5vV2Zz X-Received: by 2002:a62:1b92:: with SMTP id b140mr3310814pfb.159.1552646016153; Fri, 15 Mar 2019 03:33:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552646016; cv=none; d=google.com; s=arc-20160816; b=qXAxZ1ivCIafYb4zlOSHBZPREhY0ChsH+rqvko9tq+IrekDzATp8dTlAzJMDLyimea MGEyHIPai34hEN7u0JQACklT/Gme6DFn2fipzVy3FuivwOAw7QHPNmzuuYf5rIv8CVed HERJpINNwiCxg/yiGGo6QFkS/LxanRsQcYtB+6F1aGWqH4le89//M8NPidbtczWtD/18 QS0QZAoPn/isfH3QZqG97goumYWRG6ny4uc8b5M3qDS5sMkurYpE5brDargltFRTImfv NxUYnnaa93GVbObiQJYa02VXGkRIYOEpAt9d/t6iPYXJ6EPfg2/8ZSxbi/0EkwiFRFSk VUbw== 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=gZ/V7q0xhHaWcL+zUAogrPKMadaTk2dis1LJ1iph4Tw=; b=EF7HC8Mu0BmcYFliSnmMtN8tz2VBVMCeYue9kRd92eO3tgKBBZ2ZlUD010YJSTGRKA lHRX8zciFvgu2MPECEv8Sron3efEfnxl1QwiqPhEUmJK2NUD1TwGratL3lrbnvi4hDHz v31emxF5rIgD7cJE7nZC7RRBFAi4U6rd6q8/MTV5O9dT1zoo//8J/V8n9xjV4rYdpODX dugQKXQIMTy9w9EAdTKXAVlLb7o2N+Bh9c6qT9XWXhznMmTovTO+I/kZ76GgPOi2dmdv QooSsgynFVMxYCFxO2bmJE+KYERmUgP9959DZ432/ODt2UT3m9vkWGRMTOdmM8F6KdX5 E8wQ== 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 bj1si1414890plb.15.2019.03.15.03.33.20; Fri, 15 Mar 2019 03:33:36 -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 S1728853AbfCOKce (ORCPT + 99 others); Fri, 15 Mar 2019 06:32:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:5684 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728676AbfCOKce (ORCPT ); Fri, 15 Mar 2019 06:32:34 -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 D11D630842A0; Fri, 15 Mar 2019 10:32:33 +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 953665C21F; Fri, 15 Mar 2019 10:32:19 +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 1/3] kexec: Do not map the kexec area as decrypted when SEV is active Date: Fri, 15 Mar 2019 18:32:01 +0800 Message-Id: <20190315103203.13128-2-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.40]); Fri, 15 Mar 2019 10:32:33 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently, the arch_kexec_post_{alloc,free}_pages unconditionally maps the kexec area as decrypted. This works fine when SME is active. Because in SME, the first kernel is loaded in decrypted area by the BIOS, so the second kernel must be also loaded into the decrypted memory. When SEV is active, the first kernel is loaded into the encrypted area, so the second kernel must be also loaded into the encrypted memory. Lets make sure that arch_kexec_post_{alloc,free}_pages does not clear the memory encryption mask from the kexec area when SEV is active. Co-developed-by: Brijesh Singh Signed-off-by: Brijesh Singh Signed-off-by: Lianbo Jiang --- arch/x86/kernel/machine_kexec_64.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/machine_kexec_64.c b/arch/x86/kernel/machine_kexec_64.c index ceba408ea982..bcebf4993da4 100644 --- a/arch/x86/kernel/machine_kexec_64.c +++ b/arch/x86/kernel/machine_kexec_64.c @@ -566,7 +566,10 @@ int arch_kexec_post_alloc_pages(void *vaddr, unsigned int pages, gfp_t gfp) * not encrypted because when we boot to the new kernel the * pages won't be accessed encrypted (initially). */ - return set_memory_decrypted((unsigned long)vaddr, pages); + if (sme_active()) + return set_memory_decrypted((unsigned long)vaddr, pages); + + return 0; } void arch_kexec_pre_free_pages(void *vaddr, unsigned int pages) @@ -575,5 +578,6 @@ void arch_kexec_pre_free_pages(void *vaddr, unsigned int pages) * If SME is active we need to reset the pages back to being * an encrypted mapping before freeing them. */ - set_memory_encrypted((unsigned long)vaddr, pages); + if (sme_active()) + set_memory_encrypted((unsigned long)vaddr, pages); } -- 2.17.1