Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp345442pxb; Thu, 25 Feb 2021 04:16:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJzQnG8spNdGtT921UQw5/vFGG8Tw6wsRpIiZQP+4be1EkG/uTMHHQCN23VBUQ335x3SYNzD X-Received: by 2002:a17:906:12d2:: with SMTP id l18mr2320777ejb.308.1614255378038; Thu, 25 Feb 2021 04:16:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614255378; cv=none; d=google.com; s=arc-20160816; b=lMbK2zGL3COxlMyMI9PwhjTKiKuDyEPQlcmDrNUxOjhJaaMzslpyBFvQOYPv9ZMGOD /46adnsdSk1dacqn8LsAI9Qp5PkTYmu8glFrYTSusA4RiuCWlTsgfASUkNSEsORagGNa GOlCHYwJ57ZF9qybY4tKK98I8zQnJ/CxWcV6gW9cUjRI/KdqRitDJMb4qvP08nOx4xqq sR32y0Vrv6I9Ez1SlWKsJuwYIUG+KXkWaKSt81q7vgH5nuVVFM1oRnaY12YbJn94H4PW N0vK9YTSyStnBMB3vcQQKaP8//Xwu9nI/ZHcbnszdAGURCHh1l0owCNUWlFCPo1NjTbt qieQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=uowjjR43yhHROzZrr8+GTPAe1G0Z7p+VXIsXmHZT/DI=; b=n8N9GwMEhfn/hL2TSo4CYK3EJvghFBTZ9vb/o3q6KsXSGzEK8oUytNf6f5TZ1kYNM/ 7y7x8GfoNwvgRQM2Lz+LLy+Z+DFUGQzKixtwkL1/NLWnP0AZcN6QQv4T9yUEvgx1bYf2 5hu1A59EChmFTvQFeCu5UnAnBEmkThQ4UV15xXwHhmifYLvJEf0pO0uFz20WSQb+G07u ANxWg6xNtEhA4Ve7zKZoJaEhv2LCYprLkEFDheT/UqCxzlZQvTHG3JIalIDeU8CD3N9f LNrjVQ111Nwa6XAQRtLz1PTfbZBDGRI4mUZZU5pUyxwgUlHIIbJqp5D4bD8E4GU35vBA Kb8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=C7l6RDM9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id a20si3662749edj.257.2021.02.25.04.15.53; Thu, 25 Feb 2021 04:16:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=C7l6RDM9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S231591AbhBYMNx (ORCPT + 99 others); Thu, 25 Feb 2021 07:13:53 -0500 Received: from mail.skyhub.de ([5.9.137.197]:43328 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229571AbhBYMNv (ORCPT ); Thu, 25 Feb 2021 07:13:51 -0500 Received: from zn.tnic (p200300ec2f03dc0059e4821217d1e808.dip0.t-ipconnect.de [IPv6:2003:ec:2f03:dc00:59e4:8212:17d1:e808]) (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 AD79C1EC052A; Thu, 25 Feb 2021 13:13:09 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1614255189; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uowjjR43yhHROzZrr8+GTPAe1G0Z7p+VXIsXmHZT/DI=; b=C7l6RDM9UJMC40fLu4YLfez5BF6dXTtgOjtsFeZ/yBsJes9E+fS6f7NKObR7VNz8+enqge oZxlN/KVgnpBzKfk8dFfgDpWPFElVwVzwKnICt6v34WSqLKFNRlg3fvdIsUv7gp7wsl9Lr BQe/61MPSqaoFWiR09QP9VR+WflWms8= Date: Thu, 25 Feb 2021 13:13:08 +0100 From: Borislav Petkov To: Joerg Roedel Cc: x86@kernel.org, Joerg Roedel , hpa@zytor.com, Andy Lutomirski , Dave Hansen , Peter Zijlstra , Jiri Slaby , Dan Williams , Tom Lendacky , Juergen Gross , Kees Cook , David Rientjes , Cfir Cohen , Erdem Aktas , Masami Hiramatsu , Mike Stunes , Sean Christopherson , Martin Radev , Arvind Sankar , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: Re: [PATCH 4/7] x86/boot/compressed/64: Add 32-bit boot #VC handler Message-ID: <20210225121308.GB380@zn.tnic> References: <20210210102135.30667-1-joro@8bytes.org> <20210210102135.30667-5-joro@8bytes.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20210210102135.30667-5-joro@8bytes.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 10, 2021 at 11:21:32AM +0100, Joerg Roedel wrote: > From: Joerg Roedel > > Add a #VC exception handler which is used when the kernel still executes > in protected mode. This boot-path already uses CPUID, which will cause #VC > exceptions in an SEV-ES guest. > > Signed-off-by: Joerg Roedel > --- > arch/x86/boot/compressed/head_64.S | 6 ++ > arch/x86/boot/compressed/mem_encrypt.S | 77 +++++++++++++++++++++++++- > 2 files changed, 82 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S > index 8deeec78cdb4..eadaa0a082b8 100644 > --- a/arch/x86/boot/compressed/head_64.S > +++ b/arch/x86/boot/compressed/head_64.S > @@ -34,6 +34,7 @@ > #include > #include > #include > +#include > #include "pgtable.h" > > /* > @@ -856,6 +857,11 @@ SYM_FUNC_START(startup32_set_idt_entry) > SYM_FUNC_END(startup32_set_idt_entry) > > SYM_FUNC_START(startup32_load_idt) > + /* #VC handler */ > + leal rva(startup32_vc_handler)(%ebp), %eax > + movl $X86_TRAP_VC, %edx > + call startup32_set_idt_entry > + > /* Load IDT */ > leal rva(boot32_idt)(%ebp), %eax > movl %eax, rva(boot32_idt_desc+2)(%ebp) > diff --git a/arch/x86/boot/compressed/mem_encrypt.S b/arch/x86/boot/compressed/mem_encrypt.S > index aa561795efd1..350ecb56c7e4 100644 > --- a/arch/x86/boot/compressed/mem_encrypt.S > +++ b/arch/x86/boot/compressed/mem_encrypt.S > @@ -67,10 +67,85 @@ SYM_FUNC_START(get_sev_encryption_bit) > ret > SYM_FUNC_END(get_sev_encryption_bit) > > +/* > + * Emit code to request an CPUID register from the Hypervisor using > + * the MSR-based protocol. > + * > + * fn: The register containing the CPUID function > + * reg: Register requested > + * 1 = EAX > + * 2 = EBX > + * 3 = ECX > + * 4 = EDX > + * > + * Result is in EDX. Jumps to .Lfail on error > + */ > +.macro SEV_ES_REQ_CPUID fn:req reg:req I'm wondering - instead of replicating this 4 times, can this be a function which you CALL? You do have a stack so you should be able to. > + /* Request CPUID[%ebx].EAX */ > + movl $\reg, %eax > + shll $30, %eax > + orl $0x00000004, %eax > + movl \fn, %edx > + movl $MSR_AMD64_SEV_ES_GHCB, %ecx > + wrmsr > + rep; vmmcall > + rdmsr > + /* Check response code */ Before you do that, I guess you wanna check: GHCBData[29:12] – Reserved, must be zero in the HV response. Thx. -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette