Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp28282rdg; Tue, 10 Oct 2023 03:20:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH38rB9ABhsJ5BbH4eswOg/CUvQELhHsP55OyCz2JuEp0dI3HOvKwBK3BTuaZUgJCU8JZfC X-Received: by 2002:a17:902:d486:b0:1c9:97b7:b3cc with SMTP id c6-20020a170902d48600b001c997b7b3ccmr4346605plg.47.1696933228135; Tue, 10 Oct 2023 03:20:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696933228; cv=none; d=google.com; s=arc-20160816; b=vein4m/XDlQpJzJkMDqSYZ1Dgu8S1zXTbpfoyeS08m9rUUO/25k8SGWw3NO9xshKZd c0En/ctcSru9t511/ewfyrDIlyHDcjDDtj0Yu7wmdQL9aKy3yxIebEX+X0w9h3WAeUuz UJIaSGRfgNai+ksJyzyQXjMgZ9fjZVFvwNAeerxHxD5dCHAzjcjNk/AHOiay+rAX/tu2 oHgLKMNVcMKyeo4kPAaxaJYDkIpQyddIVbeC+WFGx1jDalIt1aVUHEDm2kdY3qR2loT8 Mn62+Ox7UfagkbybnOG5i3uhzxz74bv0I8sf6i1Au7ipqn41xdCfB5Y4wXJ6DlIhSIOg bU+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=lAPtjVU4q8q8kYfriyvZSBvkmujCV2l4vKOMrRpfduE=; fh=g/oAorp3D6UsRmd1L7iAr7vd4b1bKLrnwD0FCn0DGaA=; b=mClr2aKD/cfpveC/xmwBsS7pH4EXHKggjhkrj7nWoLTbW0Pg6ee02KqtLDpYonka1Y a0vqA4GlOWJk9U0B/dsaDACLwpGV0DSZ/Ikykbth2he9zWrGE0Ot1F8/jZhDc6vsxr8g we0efvwHb9slLpCwR1tL/mOPFlyCgnFubb5T1BEu/br9lY75olaGJY2ybXPdH7z3rApk xtOuZeeaBdFF4gPaPZ6+Z4g3jRHA5O3qB03Q29WJoGZc6Hx8OLVfjmqbPtZnE3V1MoDQ d1haPzA/eaCi8/cbBYRjpuQ2YqNlreSmvzBcg1aPpzIifHc1AdQd1YlIksrep6eWoWjQ dzVw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id kh8-20020a170903064800b001c42d60b9e6si1015954plb.112.2023.10.10.03.20.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 03:20:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id D5227802F6AF; Tue, 10 Oct 2023 03:20:20 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229898AbjJJKUA (ORCPT + 99 others); Tue, 10 Oct 2023 06:20:00 -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: 8bit X-Ovh-Tracer-Id: 2404640727859308198 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvkedrheehgddvvdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemucehtddtnecunecujfgurhephffvvefufffkofggtgfgsehtkeertdertdejnecuhfhrohhmpeflohhsrocurfgvkhhkrghrihhnvghnuceojhhoshgvrdhpvghkkhgrrhhinhgvnhesfhhogihhohhunhgurdhfiheqnecuggftrfgrthhtvghrnhepfedtleeuteeitedvtedtteeuieevudejfeffvdetfeekleehhfelleefteetjeejnecukfhppeduvdejrddtrddtrddupdeluddrudehjedrudduuddrvddvtddpfeejrdehledrudegvddruddtheenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduvdejrddtrddtrddupdhmrghilhhfrhhomhepoehjohhsvgdrphgvkhhkrghrihhnvghnsehfohighhhouhhnugdrfhhiqedpnhgspghrtghpthhtohepuddprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdpoffvtefjohhsthepmhhoheekuddpmhhouggvpehsmhhtphhouhht X-Spam-Status: No, score=2.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Tue, 10 Oct 2023 03:20:21 -0700 (PDT) X-Spam-Level: ** 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é 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 = true; module_param_named(sev, sev_enabled, bool, 0444); +/* 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 = 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; + if (requested_sev_asids + requested_sev_es_asids > max_sev_asid) { + pr_info("SEV asids requested more than available: %u ASIDs\n", max_sev_asid); + goto out; + } + /* Minimum ASID value that should be used for SEV guest */ min_sev_asid = edx; sev_me_mask = 1UL << (ebx & 0x3f); @@ -2215,7 +2229,8 @@ void __init sev_hardware_setup(void) goto out; } - sev_asid_count = max_sev_asid - min_sev_asid + 1; + sev_asid_count = (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 = true; @@ -2237,10 +2252,11 @@ void __init sev_hardware_setup(void) goto out; /* Has the system been allocated ASIDs for SEV-ES? */ - if (min_sev_asid == 1) + if (max_sev_asid - sev_asid_count <= 1) goto out; - sev_es_asid_count = min_sev_asid - 1; + sev_es_asid_count = (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 = true; @@ -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); sev_enabled = sev_supported; sev_es_enabled = sev_es_supported; -- 2.41.0