Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp3453176img; Mon, 25 Mar 2019 10:34:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqyTetnuTrUtchT2HA9j6UV4LXeGDG60MKft6S90eeV56Q/oEugLjB/2EPlP4wEdLm92PSpn X-Received: by 2002:a17:902:a612:: with SMTP id u18mr26127180plq.145.1553535295169; Mon, 25 Mar 2019 10:34:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553535295; cv=none; d=google.com; s=arc-20160816; b=iCRpBq4uo5JnBXDkw86HDFpE96YE8To1onbXRyhQyNmHgtTZel1aWoIn/mkUquLlhR wVOQGS1n06biKIaVTrf7/9HPgtBIoh/4uOLSJg+CmGMrgeHlEUzcz8iQUKeE6Jlx2LFy I9UAsaNZizK2Pjg8u0LCBWo2G7zkmPi2IKYsQixRucxqZ9HO7oUIcROuN2xyk87l4IQ6 uN0scRsPsfvXIOvU64zbBsvi0tGoBAUa85UTHf0/bNZ82QKaA/nQqkLXp09OARYY3WBr vWmQuN8kplTzGM3SZ8ywr30XYYNrMYTK8JwElAEMRuMQmTgf6wIkeWxwQYjRS39omgum 3iPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=fba9IzIQTZT23NikFz22dQO0PjauBkWFCObbQk9HoB8=; b=YNQlq8WkX+Q153XS71rBIt3LOAmBp9gaiVxOtQGph/QZJydq/uLxQX8NwmIwMmSATp vv1aoFaMRH4yo1z9nhFUNgwxl9tbdt74MjocndcfebT4jj5cp5gTk9t9Aw7vSsXUM4IO gKKNeCYiQMPulJ1iKUTLRquO+r9LusYOhkZ+/HtVA7OhXra76k3clGVop3nFy/0GN5wD maCqvFB42hqqE/5Z7C0Du8WrhTVPAHhyc2YVxPAa6bVrZmxROvJKuj8OaaAh9bRnwoWh vLLV6EvHltIB39mRg50qFvFEXmpeE1ChJ0z6iSHH5Rpgp5afYKPjaZS4hmc+fxAqLHlR moeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=YFUDar3o; 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=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b9si13322056pfd.228.2019.03.25.10.34.40; Mon, 25 Mar 2019 10:34:55 -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=@alien8.de header.s=dkim header.b=YFUDar3o; 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=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729932AbfCYRci (ORCPT + 99 others); Mon, 25 Mar 2019 13:32:38 -0400 Received: from mail.skyhub.de ([5.9.137.197]:38464 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729714AbfCYRci (ORCPT ); Mon, 25 Mar 2019 13:32:38 -0400 Received: from zn.tnic (p200300EC2F098000329C23FFFEA6A903.dip0.t-ipconnect.de [IPv6:2003:ec:2f09:8000:329c:23ff:fea6:a903]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 9FFF71EC0513; Mon, 25 Mar 2019 18:32:36 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1553535156; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=fba9IzIQTZT23NikFz22dQO0PjauBkWFCObbQk9HoB8=; b=YFUDar3oobJYrA/YCHuJL41EvqAfkuDWJwUHSKmKCBB+Me5W062tdJwTo70cpe5TcBHyaq rz889huK840mQlCPvCThc9RZltyfQ8rdlbVoJDeDX8chZVvdHjguKmPTtvgODYuDkNAE9h auZth8C9GIq/3VRdg811IWe0oWpalYc= Date: Mon, 25 Mar 2019 18:32:39 +0100 From: Borislav Petkov To: "Singh, Brijesh" , "Lendacky, Thomas" Cc: lijiang , "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" , "bhe@redhat.com" Subject: Re: [PATCH 1/3] kexec: Do not map the kexec area as decrypted when SEV is active Message-ID: <20190325173239.GO12016@zn.tnic> References: <20190315103203.13128-1-lijiang@redhat.com> <20190315103203.13128-2-lijiang@redhat.com> <20190324150034.GH23289@zn.tnic> <7b115829-40d9-e55e-dee3-ec8e4766971f@redhat.com> <20190325063742.GA12016@zn.tnic> <652b9166-f06e-c210-3c3f-c9e80a97db18@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <652b9166-f06e-c210-3c3f-c9e80a97db18@amd.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 25, 2019 at 05:17:55PM +0000, Singh, Brijesh wrote: > By default all the memory regions are mapped encrypted. The > set_memory_{encrypt,decrypt}() is a generic function which can be > called explicitly to clear/set the encryption mask from the existing > memory mapping. The mem_encrypt_active() returns true if either SEV or > SME is active. So the __set_memory_enc_dec() uses the > memory_encrypt_active() check to ensure that the function is no-op when > SME/SEV are not active. > > Currently, the arch_kexec_post_alloc_pages() unconditionally clear the > encryption mask from the kexec area. In case of SEV, we should not clear > the encryption mask. Brijesh, I know all that. Please read what I said here at the end: https://lkml.kernel.org/r/20190324150034.GH23289@zn.tnic With this change, the code looks like this: + if (sme_active()) + return set_memory_decrypted((unsigned long)vaddr, pages); now in __set_memory_enc_dec via set_memory_decrypted(): /* Nothing to do if memory encryption is not active */ if (!mem_encrypt_active()) return 0; so you have: if (sme_active()) ... if (!mem_encrypt_active()) now maybe this is all clear to you and Tom but I betcha others will get confused. Probably something like "well, what should be active now, SME, SEV or memory encryption in general"? I hope you're catching my drift. So if you want to *not* decrypt memory in the SEV case, then doing something like this should make it a bit more clear: if (sev_active()) return; return set_memory_decrypted((unsigned long)vaddr, pages); along with a comment *why* we're checking here. But actually, I'd prefer if you had separate wrappers which are called for SME and for SEV. I'll let Tom chime in too. -- Regards/Gruss, Boris. Good mailing practices for 400: avoid top-posting and trim the reply.