Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp2780488img; Sun, 24 Mar 2019 18:59:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqydH/ofBz/C828Q1plcwh6CdC7dlXUo+09RsRueQ4EyHtp11aiT5vTiacewaPkQBeOxMqYo X-Received: by 2002:a63:d854:: with SMTP id k20mr21165487pgj.107.1553479163030; Sun, 24 Mar 2019 18:59:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553479163; cv=none; d=google.com; s=arc-20160816; b=n4oaW4SZEzH2UdhWIkwtNX7g/4Rwwf35ZW/lekIoDpAAX4pEtbH9UCfHBM0R+Srf2M 93JFjbjHRTheOc2HXHveh1f/yn9J6kGgQopkgRhgP7qiKyw3LdDgdMDfiQuHbEpGv0Ou owXWpZvb/GceCd9faHGUVp5GY3AQ6ussQF0sWIKliGebv5VJRmmRbwE/eKX7yucso673 zXaHwWpq6ose/6GcV3RAxFHFgs6ALPw/jLSimv2R2bbNdQfiY5fbMmatu9gHqasS9ohW h71tw7U6nBFAADhNN65st+x8440+z3mdytZsV14f1WcCg5hzsVQnhGjQSZAbNUM+006Z rN1w== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=UjeDzlpNH2obTIi6S6hVmqZ+dpwbmA0KKs8AXlHVgVA=; b=ImRlJ5DIgVsLRe2Zb2HHjJnkrmYsRmmjrtP7S316Q5wqRPZpQsTB/TY0GxRMARlwfa iYuVUv9xdixo+PlAyEFSkAxEgBxlunF5tYZrXZeeaVBEgB822dRCz7rd3UFlvYylKMze Wpc+8XfktZG2fhhbvF73ha+ExebCzpxIWgs75L8gXBP3XiuJ8cNy9yFns7BVYU5MiIly CoZJ0BFJF/9ZmP5+gi3bL4Rwgak5W+AwJeXs4gODihA1lOsOHXqMGcjKc/zYfwnGRXRH 3ew/Ke/GK4SKMdVCBSyF2QcNPQFVswSkWaYvJzyE/CoJAOVDCvM1YpvLWjNkKPi29IFn nYsw== 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 f3si12976615plf.300.2019.03.24.18.59.07; Sun, 24 Mar 2019 18:59: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; 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 S1729263AbfCYB6b (ORCPT + 99 others); Sun, 24 Mar 2019 21:58:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39316 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729231AbfCYB6b (ORCPT ); Sun, 24 Mar 2019 21:58:31 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 408F13084295; Mon, 25 Mar 2019 01:58:30 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-53.pek2.redhat.com [10.72.12.53]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B0E4710018F9; Mon, 25 Mar 2019 01:58:15 +0000 (UTC) Subject: Re: [PATCH 1/3] kexec: Do not map the kexec area as decrypted when SEV is active To: Borislav Petkov Cc: linux-kernel@vger.kernel.org, kexec@lists.infradead.org, tglx@linutronix.de, mingo@redhat.com, x86@kernel.org, hpa@zytor.com, akpm@linux-foundation.org, dyoung@redhat.com, brijesh.singh@amd.com, thomas.lendacky@amd.com, bhe@redhat.com References: <20190315103203.13128-1-lijiang@redhat.com> <20190315103203.13128-2-lijiang@redhat.com> <20190324150034.GH23289@zn.tnic> From: lijiang Message-ID: <7b115829-40d9-e55e-dee3-ec8e4766971f@redhat.com> Date: Mon, 25 Mar 2019 09:58:07 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20190324150034.GH23289@zn.tnic> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Mon, 25 Mar 2019 01:58:30 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 在 2019年03月24日 23:00, Borislav Petkov 写道: >> Subject: Re: [PATCH 1/3] kexec: Do not map the kexec area as decrypted when SEV is active > > The tip tree preferred format for patch subject prefixes is > 'subsys/component:', e.g. 'x86/apic:', 'x86/mm/fault:', 'sched/fair:', > 'genirq/core:'. Please do not use file names or complete file paths as > prefix. 'git log path/to/file' should give you a reasonable hint in most > cases. Fine, thanks for your advice. > > On Fri, Mar 15, 2019 at 06:32:01PM +0800, Lianbo Jiang wrote: >> Currently, the arch_kexec_post_{alloc,free}_pages unconditionally > > Please end function names with parentheses. Ok, i will improve them next post. > >> 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. > > Hold on, wait a minute! > > Why do we even need this? As usual, you guys never explain what the big > picture is. So you mention SEV, which sounds to me like you want to be > able to kexec the SEV *guest*. Yes? Yes. Just like the physical machines support kdump, the virtual machines also need kdump. When a virtual machine panic, we also need to dump its memory for analysis. > > First of all, why? For the SEV virtual machine, the memory is also encrypted. When SEV is enabled, the first kernel is loaded into the encrypted area. Unlike the SME, the first kernel is loaded into the decrypted area. Because of this difference between SME and SEV, we need to properly map the kexec memory area in order to correctly access it. > > Then, if so... > >> 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); > > ... then this looks yucky. Because, you're adding an sme_active() check here > but then __set_memory_enc_dec() checks For the SEV virtual machine, it maps the kexec memroy area as encrypted, so, no need to invoke this function to change anything. > > if (!mem_encrypt_active()) > > and heads will spin from all the checking of memory encryption aspects. > > So this would need a rework so that there are no multiple confusing > checks. About the three functions, here i copied their comment from the arch/x86/mm/mem_encrypt.c Please refer to it. /* * SME and SEV are very similar but they are not the same, so there are * times that the kernel will need to distinguish between SME and SEV. The * sme_active() and sev_active() functions are used for this. When a * distinction isn't needed, the mem_encrypt_active() function can be used. * Thanks. Lianbo > > Thx. >