From nobody Fri Jan 2 15:31:51 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B8A65CD691F for ; Tue, 10 Oct 2023 10:20:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230210AbjJJKUB (ORCPT ); Tue, 10 Oct 2023 06:20:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229516AbjJJKT6 (ORCPT ); Tue, 10 Oct 2023 06:19:58 -0400 Received: from 18.mo581.mail-out.ovh.net (18.mo581.mail-out.ovh.net [188.165.56.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E819C97 for ; Tue, 10 Oct 2023 03:19:54 -0700 (PDT) Received: from director8.ghost.mail-out.ovh.net (unknown [10.109.143.249]) by mo581.mail-out.ovh.net (Postfix) with ESMTP id 7A09E28549 for ; Tue, 10 Oct 2023 10:03:11 +0000 (UTC) Received: from ghost-submission-6684bf9d7b-dnnmd (unknown [10.110.208.237]) by director8.ghost.mail-out.ovh.net (Postfix) with ESMTPS id CCBC51FE50; Tue, 10 Oct 2023 10:03:08 +0000 (UTC) Received: from foxhound.fi ([37.59.142.105]) by ghost-submission-6684bf9d7b-dnnmd with ESMTPSA id iJQ8KlwhJWUQWgAArvdK0g (envelope-from ); Tue, 10 Oct 2023 10:03:08 +0000 Authentication-Results: garm.ovh; auth=pass (GARM-105G0061679898a-46f3-4f1d-875a-19332c22c92d, 0BECE3FDD040DFF140D1580490AC4D25886584D9) smtp.auth=jose.pekkarinen@foxhound.fi X-OVh-ClientIp: 91.157.111.220 From: =?UTF-8?q?Jos=C3=A9=20Pekkarinen?= To: seanjc@google.com, pbonzini@redhat.com, skhan@linuxfoundation.org Cc: =?UTF-8?q?Jos=C3=A9=20Pekkarinen?= , tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org Subject: [PATCH] kvm/sev: make SEV/SEV-ES asids configurable Date: Tue, 10 Oct 2023 13:04:39 +0300 Message-ID: <20231010100441.30950-1-jose.pekkarinen@foxhound.fi> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Ovh-Tracer-Id: 2404640727859308198 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvkedrheehgddvvdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemucehtddtnecunecujfgurhephffvvefufffkofggtgfgsehtkeertdertdejnecuhfhrohhmpeflohhsrocurfgvkhhkrghrihhnvghnuceojhhoshgvrdhpvghkkhgrrhhinhgvnhesfhhogihhohhunhgurdhfiheqnecuggftrfgrthhtvghrnhepfedtleeuteeitedvtedtteeuieevudejfeffvdetfeekleehhfelleefteetjeejnecukfhppeduvdejrddtrddtrddupdeluddrudehjedrudduuddrvddvtddpfeejrdehledrudegvddruddtheenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduvdejrddtrddtrddupdhmrghilhhfrhhomhepoehjohhsvgdrphgvkhhkrghrihhnvghnsehfohighhhouhhnugdrfhhiqedpnhgspghrtghpthhtohepuddprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdpoffvtefjohhsthepmhhoheekuddpmhhouggvpehsmhhtphhouhht Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There are bioses that doesn't allow to configure the number of asids allocated for SEV/SEV-ES, for those cases, the default behaviour allocates all the asids for SEV, leaving no room for SEV-ES to have some fun. If the user request SEV-ES to be enabled, it will find the kernel just run out of resources and ignored user request. This following patch will address this issue by making the number of asids for SEV/SEV-ES configurable over kernel module parameters. Signed-off-by: Jos=C3=A9 Pekkarinen --- arch/x86/kvm/svm/sev.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 07756b7348ae..68a63b42d16a 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -51,9 +51,18 @@ static bool sev_enabled =3D true; module_param_named(sev, sev_enabled, bool, 0444); =20 +/* nr of asids requested for SEV */ +static unsigned int requested_sev_asids; +module_param_named(sev_asids, requested_sev_asids, uint, 0444); + /* enable/disable SEV-ES support */ static bool sev_es_enabled =3D true; module_param_named(sev_es, sev_es_enabled, bool, 0444); + +/* nr of asids requested for SEV-ES */ +static unsigned int requested_sev_es_asids; +module_param_named(sev_es_asids, requested_sev_asids, uint, 0444); + #else #define sev_enabled false #define sev_es_enabled false @@ -2194,6 +2203,11 @@ void __init sev_hardware_setup(void) if (!max_sev_asid) goto out; =20 + if (requested_sev_asids + requested_sev_es_asids > max_sev_asid) { + pr_info("SEV asids requested more than available: %u ASIDs\n", max_sev_a= sid); + goto out; + } + /* Minimum ASID value that should be used for SEV guest */ min_sev_asid =3D edx; sev_me_mask =3D 1UL << (ebx & 0x3f); @@ -2215,7 +2229,8 @@ void __init sev_hardware_setup(void) goto out; } =20 - sev_asid_count =3D max_sev_asid - min_sev_asid + 1; + sev_asid_count =3D (requested_sev_asids) ? max_sev_asid - min_sev_asid + = 1 : + requested_sev_asids; WARN_ON_ONCE(misc_cg_set_capacity(MISC_CG_RES_SEV, sev_asid_count)); sev_supported =3D true; =20 @@ -2237,10 +2252,11 @@ void __init sev_hardware_setup(void) goto out; =20 /* Has the system been allocated ASIDs for SEV-ES? */ - if (min_sev_asid =3D=3D 1) + if (max_sev_asid - sev_asid_count <=3D 1) goto out; =20 - sev_es_asid_count =3D min_sev_asid - 1; + sev_es_asid_count =3D (requested_sev_es_asids) ? min_sev_asid - 1 : + requested_sev_es_asids; WARN_ON_ONCE(misc_cg_set_capacity(MISC_CG_RES_SEV_ES, sev_es_asid_count)); sev_es_supported =3D true; =20 @@ -2248,11 +2264,13 @@ void __init sev_hardware_setup(void) if (boot_cpu_has(X86_FEATURE_SEV)) pr_info("SEV %s (ASIDs %u - %u)\n", sev_supported ? "enabled" : "disabled", - min_sev_asid, max_sev_asid); + min_sev_asid, sev_asid_count); if (boot_cpu_has(X86_FEATURE_SEV_ES)) pr_info("SEV-ES %s (ASIDs %u - %u)\n", sev_es_supported ? "enabled" : "disabled", - min_sev_asid > 1 ? 1 : 0, min_sev_asid - 1); + sev_asid_count, + (requested_sev_es_asids) ? 0 : + sev_asid_count + sev_es_asid_count); =20 sev_enabled =3D sev_supported; sev_es_enabled =3D sev_es_supported; --=20 2.41.0