Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp2024526lqb; Mon, 27 May 2024 05:41:14 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXSJtQYO5ZN8XbT8GzjWfxIo+r+UXAoip0HaUKrJX8J5mS6H0jI/AjuCtW/ZIwzoJkaCODXe36ClnPcFrzUcIki2BuIBWsWO/5mKm+jcw== X-Google-Smtp-Source: AGHT+IGgPpCqwJvfN92AZYWzbglsTvJ4pkv+tnqCzIuK0z8nHObzwzXy4fkVFrBcFg2quwL+GM+u X-Received: by 2002:a05:6358:c123:b0:196:c46b:de62 with SMTP id e5c5f4694b2df-197e5212dbamr924289955d.18.1716813673922; Mon, 27 May 2024 05:41:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716813673; cv=pass; d=google.com; s=arc-20160816; b=Jy0xCfk2kR/6qgwRmqTJDyYBYLH1NQ/zuOaQNNpzB0NWk9KfeQ0g9Kjmx2TpJ7yU1G 45deytRWtud2Y+IqCTv9VSjJ5/JAo0WsO2vW0JC+CF9boKvi7jy4wm59N5IrFVPEQ5oC UMBarqYxfTVxkc41I94EP+SvFTbxVntTJp1Q4ChWC1KEcRsP+Q9IwkrTm+/XRVr8pDF1 fHyrmgHvhFpMvdbL6VLfNzyvKCUz3LHo/1ttrI162DDQv40IJcIGKmYC5ZnIMXAHh9vZ irmwbA+2Qlx47yNInk0le2kp30ATB+/SnD+GR1LVF/x1Bd83eKj57YoZdNK7Mtk20PMr 9QgQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=+KQ1XXPKYiyM2BBxP7vDHilnO6xgA3d3JBHZpfRVIW8=; fh=yOXSm0E/8tOfmRnhk0JfE6MKLQieMwDr2DHng9Fw+Y4=; b=ToqOvNXHZ9I3p3N8gM/JJc3/UOB57OiWCEvSszOPDv2UEpRdXl/yglNUtRjnZ+uAkC +QU05gXMfTqTX696d2s9qryGD4NYW/zqTWEIpPrS+q57ZGxiRLRviqhntw8Qn1Q7kBQx lqbdbc/IfBLQt7T8md4nuuRTtKXe1D439f3dyKlZODxeQMg5tPT8UNr2HNWueMdknMAn f84/nTvA6VpUcx7oZpr2t5g6zY+DFAuGpdbWZQVtb6MKvqYyTAwHWANJ2k4mi3VtytKs jAT2/0Ozc9GIA/A8HOCqvSh76Iggb9wXw19cfj2al4Dg0zgnZ2KMgBDaHqSSOA38+NnX b2rQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@alien8.de header.s=alien8 header.b=MDuMiMvO; arc=pass (i=1 spf=pass spfdomain=alien8.de dkim=pass dkdomain=alien8.de dmarc=pass fromdomain=alien8.de); spf=pass (google.com: domain of linux-kernel+bounces-190589-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190589-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-6822bbcbac8si6252585a12.901.2024.05.27.05.41.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 05:41:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-190589-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@alien8.de header.s=alien8 header.b=MDuMiMvO; arc=pass (i=1 spf=pass spfdomain=alien8.de dkim=pass dkdomain=alien8.de dmarc=pass fromdomain=alien8.de); spf=pass (google.com: domain of linux-kernel+bounces-190589-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190589-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 7FF12B23657 for ; Mon, 27 May 2024 12:33:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 52BF415E5B1; Mon, 27 May 2024 12:33:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (4096-bit key) header.d=alien8.de header.i=@alien8.de header.b="MDuMiMvO" Received: from mail.alien8.de (mail.alien8.de [65.109.113.108]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A472213B2A4 for ; Mon, 27 May 2024 12:33:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=65.109.113.108 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716813232; cv=none; b=MNGjM7txr4WWEqpKyW8yXxRMzmOXJmfdZQ9bCFCYcZK5Si3oxQJgaiMzQaJkP1KDuCMzg+WqJTBxADso/eUOjHZqJZ1wOrfsIoJIO0cO8pg/8BbFNHAVwgILTopXhlIu2t2o0Mzi5EF54AjLd5VIOGTS/foKxht+mdLCUWWV9HQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716813232; c=relaxed/simple; bh=0POJpo4op/4WKtBiRoOk3agZ6RzBzkKKvc//+TM5oeU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=G2MXN1ao0OHonFqo36cwhoUDrD7+LkpWQzFVTzrjhRWjhes5FpM7c+YLaPDR2UAb4VmHsHC5zNOQlrVzRO0Cm//gHwy2xmJUtP6jSaKpt1/mq+U3c2PUuDXqqPu19h5EaeUsmaclwMkgcF3M1/aQRVWoGMO5/h/gxPc/FVAzHQc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=alien8.de; spf=pass smtp.mailfrom=alien8.de; dkim=pass (4096-bit key) header.d=alien8.de header.i=@alien8.de header.b=MDuMiMvO; arc=none smtp.client-ip=65.109.113.108 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=alien8.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=alien8.de Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.alien8.de (SuperMail on ZX Spectrum 128k) with ESMTP id 74A3B40E02A9; Mon, 27 May 2024 12:33:47 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at mail.alien8.de Authentication-Results: mail.alien8.de (amavisd-new); dkim=pass (4096-bit key) header.d=alien8.de Received: from mail.alien8.de ([127.0.0.1]) by localhost (mail.alien8.de [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id V4U4EjJu8wWB; Mon, 27 May 2024 12:33:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=alien8; t=1716813224; bh=+KQ1XXPKYiyM2BBxP7vDHilnO6xgA3d3JBHZpfRVIW8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=MDuMiMvOnVl/o/XhDMvbOYg3o/XU5nS45zcZIu2GSiQvmybJVGnSqNbAFYSxButLQ TU9EyUl57PnV3M/VbRpumxQ0PCa3PRnMbdTnjacqvtWdbdRSLWI3sb5dUzwqSNkIcO XuKhmSFjvh5q76HZQmNLySdgNY995WBjukkw3DZTz2yqaZVztk0ms4sE9mrDG7xoZl ELfn5bkcv+fAS4LJGJ829D7tAu9QY4txE+KNAJOubqRxTOW8Q/x32p8OAUIHjlnkpC ZgPdd3ESyksr++z8T791SxoaxsjTTe0+BLVO04zqBlzMn5QbXDQp4CRTOKszNg7+lT XAB/4P6u+7nd88NrKqdQmM7Ia9I40RtoHDfO/XUUr8IfXStnyyV/69I0BmnAvcaSz7 FfHunVX2ZgPkuy8kQDoi2jgzfk5bD8QlCS4Wk73VzLlvravgbGP2S8TR9YoZyjGwY3 wj3kwEgS3bAMCP19c/lqGCUXB+stXu1eHjXeRAjLCil/LCuL7AsqU0LNy1qRVZgZlE 4WuXX/MU8xBfiMKqQ22vmhi4+nViNrL/u9mNmPKSE4UAm78qSzBTe3kw73u4AUDISD 1xXvmldfFWufIhU8JgwUZLdEIf1USAstLpdco2YP8ScIPYRFslw3aFUy4FFrL6nRjC LW9xkVjajInrdwHHrIg7nmtk= Received: from zn.tnic (p5de8ee85.dip0.t-ipconnect.de [93.232.238.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-256) server-digest SHA256) (No client certificate requested) by mail.alien8.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 2194E40E016A; Mon, 27 May 2024 12:33:30 +0000 (UTC) Date: Mon, 27 May 2024 14:33:24 +0200 From: Borislav Petkov To: Tom Lendacky Cc: linux-kernel@vger.kernel.org, x86@kernel.org, linux-coco@lists.linux.dev, svsm-devel@coconut-svsm.dev, Thomas Gleixner , Ingo Molnar , Dave Hansen , "H. Peter Anvin" , Andy Lutomirski , Peter Zijlstra , Dan Williams , Michael Roth , Ashish Kalra Subject: Re: [PATCH v4 07/15] x86/sev: Use the SVSM to create a vCPU when not in VMPL0 Message-ID: <20240527123304.GBZlR9gBzBIjqEKKo6@fat_crate.local> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: On Wed, Apr 24, 2024 at 10:58:03AM -0500, Tom Lendacky wrote: > -static int snp_set_vmsa(void *va, bool vmsa) > +static int base_snp_set_vmsa(void *va, bool vmsa) s/base_/__/ The svsm_-prefixed ones are already a good enough distinction... > { > u64 attrs; > > @@ -1013,6 +1013,40 @@ static int snp_set_vmsa(void *va, bool vmsa) > return rmpadjust((unsigned long)va, RMP_PG_SIZE_4K, attrs); > } > > +static int svsm_snp_set_vmsa(void *va, void *caa, int apic_id, bool vmsa) ^^^^^^^^^^^ bool create_vmsa or so, to denote what this arg means. > +{ > + struct svsm_call call = {}; > + unsigned long flags; > + int ret; > + > + local_irq_save(flags); > + > + call.caa = this_cpu_read(svsm_caa); > + call.rcx = __pa(va); > + > + if (vmsa) { > + /* Protocol 0, Call ID 2 */ > + call.rax = SVSM_CORE_CALL(SVSM_CORE_CREATE_VCPU); > + call.rdx = __pa(caa); > + call.r8 = apic_id; > + } else { > + /* Protocol 0, Call ID 3 */ > + call.rax = SVSM_CORE_CALL(SVSM_CORE_DELETE_VCPU); > + } > + > + ret = svsm_protocol(&call); > + > + local_irq_restore(flags); > + > + return ret; > +} > + > +static int snp_set_vmsa(void *va, void *caa, int apic_id, bool vmsa) > +{ > + return vmpl ? svsm_snp_set_vmsa(va, caa, apic_id, vmsa) > + : base_snp_set_vmsa(va, vmsa); Why do you even need helpers if you're not going to use them somewhere else? Just put the whole logic inside snp_set_vmsa(). > +} > + > #define __ATTR_BASE (SVM_SELECTOR_P_MASK | SVM_SELECTOR_S_MASK) > #define INIT_CS_ATTRIBS (__ATTR_BASE | SVM_SELECTOR_READ_MASK | SVM_SELECTOR_CODE_MASK) > #define INIT_DS_ATTRIBS (__ATTR_BASE | SVM_SELECTOR_WRITE_MASK) > @@ -1044,11 +1078,11 @@ static void *snp_alloc_vmsa_page(int cpu) > return page_address(p + 1); > } > > -static void snp_cleanup_vmsa(struct sev_es_save_area *vmsa) > +static void snp_cleanup_vmsa(struct sev_es_save_area *vmsa, int apic_id) > { > int err; > > - err = snp_set_vmsa(vmsa, false); > + err = snp_set_vmsa(vmsa, NULL, apic_id, false); > if (err) > pr_err("clear VMSA page failed (%u), leaking page\n", err); > else > @@ -1059,6 +1093,7 @@ static int wakeup_cpu_via_vmgexit(u32 apic_id, unsigned long start_ip) > { > struct sev_es_save_area *cur_vmsa, *vmsa; > struct ghcb_state state; > + struct svsm_ca *caa; > unsigned long flags; > struct ghcb *ghcb; > u8 sipi_vector; > @@ -1105,6 +1140,12 @@ static int wakeup_cpu_via_vmgexit(u32 apic_id, unsigned long start_ip) > if (!vmsa) > return -ENOMEM; > > + /* > + * If an SVSM is present, then the SVSM CAA per-CPU variable will > + * have a value, otherwise it will be NULL. > + */ /* If an SVSM is present, the SVSM per-CPU CAA will be !NULL. */ Shorter. -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette