From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=52.42.203.116 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795977187; b=vBG4QbbkOrDqG6AWXlBKzm0Sl/zaFAn0XtX1EcmtwYDb1m2gvnN6XWmYcgwR3m6fmQW3 JWwR8NPnQOf+JinNRpFkd1bpabd93GgKbUne1w+ykAOfC9nGuR9kBV0IsSKtXcCvJIODS CrOH+2JkRPrvm+zeXZejNZ9J30PYVGRLnbATpkhShn6PvBvz990JYBqj9fRkjkjSv/esD ZnxFCJ7BqFGfEzuZ2ZqJyY+KSCGtxQzCNjOBYSYghw2smfxXT5dp2BGFlNS9st8SwynS1 WXK/HzEJ6qkvRsMsrMCWn7hQTS/1I9JLShKu4bdDEgw9aTUnYJOHHUp2n5VzgJX9h3A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795977187; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:Received:Received:X-Farcaster-Flow-ID:Received:Received: From:To:CC:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding:Content-Type:X-Originating-IP: X-ClientProxiedBy; bh=UVjGlFjUY6ZQIbzE4AWGQ0rW1+s+FAnF3V5bb/c2kz8=; b=cXVfpHeDbzgNEqWk3X34JYbDLFKf8ShsPJ4aBC32d94VGA0NG/rL2LjNGs9RyfJnwFWU iPaIR69b2bA1Lz/z8uW0//ZBAZ5cIHW1/bfQQc9g14HBAhCfHYpKtusXZ3JQQLhgmYSY0 a9LDr7K2Shqv8sPhdGl0FHY+6PJQvqSMFO1eollZMno7+Y+/MRxKze9jKDFxjpLjLrpgj DZ63QfsiFEw3TTC3/CutJ6PX53GIMt0Cpu9TUftq3GCYVj8rEwtO7Ts35VfLhQjb/OGn5 yfmOKml9YjrvEi9nozOCI1+KC6Ro51vW/a2eWEUwZTj9ORzFtTt7sBDquZQT4xAIzow== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=amazon.com; spf=pass smtp.mailfrom=amazon.de; dkim=pass header.d=amazon.com header.i=@amazon.com header.a=rsa-sha256 header.s=amazoncorp2 header.b=ZZGycnAl; arc=none smtp.remote-ip=52.42.203.116 Received: from pdx-out-008.esa.us-west-2.outbound.mail-perimeter.amazon.com (pdx-out-008.esa.us-west-2.outbound.mail-perimeter.amazon.com [52.42.203.116]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F9E0606A32C; Sun, 29 Nov 2026 18:33:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6F9E0606A32C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=amazon.com header.i=@amazon.com header.a=rsa-sha256 header.s=amazoncorp2 header.b=ZZGycnAl DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazoncorp2; t=1795977187; x=1827513187; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UVjGlFjUY6ZQIbzE4AWGQ0rW1+s+FAnF3V5bb/c2kz8=; b=ZZGycnAlENfeTAB/lkEEEIXGni92HvkbwPIbW8KPO4J0yCAfX9FooFoq tWYpyINlNR8cHRp7ZpEpBzalW8BroeO8RcjR9vvtoTLVYka4xa3ARS5W/ fPBPydZtsJtEa9CP5yQB89T0nPFqMR1/iN8AJrIWRJfnlOw8sbw/56N3r qaMmhQNfOUrzyB90BXiIcZbZkvY4Zl9I81tL0OvLtBp6XjpmusMRf2qPr hJu2qVNx3wU2isfaB5/oYQcrWDHIxUHyP1DHk3WpmikVbJ0+QjnIYre/H QweUMKTmmgdyoBpDS8F1FQC2pLsJVVFkQjwzWbEFBqgXP8VeDVFytudYH Q==; X-CSE-ConnectionGUID: ylu3/mAAR6+7vBrdw2obMQ== X-CSE-MsgGUID: O3675knIQlGWqsp8dgMDEg== X-IronPort-AV: E=Sophos;i="6.27,241,1787011200"; d="scan'208";a="35441298" Received: from ip-10-5-9-48.us-west-2.compute.internal (HELO smtpout.naws.us-west-2.prod.farcaster.email.amazon.dev) ([10.5.9.48]) by internal-pdx-out-008.esa.us-west-2.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Nov 2026 18:33:04 +0000 Received: from EX19MTAUWC002.ant.amazon.com [205.251.233.111:28600] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.27.231:2525] with esmtp (Farcaster) id fff8b27d-3970-43d0-891d-ef7de2fbc42b; Sun, 29 Nov 2026 18:33:04 +0000 (UTC) X-Farcaster-Flow-ID: fff8b27d-3970-43d0-891d-ef7de2fbc42b Received: from EX19D001UWA001.ant.amazon.com (10.13.138.214) by EX19MTAUWC002.ant.amazon.com (10.250.64.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.57; Sun, 29 Nov 2026 18:33:03 +0000 Received: from ip-10-253-83-51.amazon.com (172.19.99.218) by EX19D001UWA001.ant.amazon.com (10.13.138.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.57; Sun, 29 Nov 2026 18:33:00 +0000 From: Alexander Graf To: Greg Kroah-Hartman , Arnd Bergmann CC: The AWS Nitro Enclaves Team , , Paolo Bonzini , "Stefano Garzarella" , Stefan Hajnoczi , Marek Szyprowski , Robin Murphy , Andrew Morton , "David Hildenbrand" , Mike Rapoport , "Jonathan Corbet" , Shuah Khan , "Randy Dunlap" , , , , , , , , , Subject: [PATCH v2 19/23] nitro_enclaves: Build the boot-time CPU pool once the CPUs are online Date: Sun, 29 Nov 2026 18:21:48 +0000 Message-ID: X-Mailer: git-send-email 2.47.1 In-Reply-To: References: X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: EX19D031UWC002.ant.amazon.com (10.13.139.212) To EX19D001UWA001.ant.amazon.com (10.13.138.214) An admin who passes nitro_enclaves.ne_cpus= to a kernel with the driver built in gets no CPU pool, and this not very informative error message: Booting kernel: `2-5' invalid for parameter `nitro_enclaves.ne_cpus' The parameter setter runs from parse_args() in start_kernel(), before the page allocator and the secondary CPUs are up. Building a pool needs both. Keep a value that arrives while system_state is SYSTEM_BOOTING in ne_cpus, note its parameter in ne_cpus_kp, and build the pool from it in ne_init(), which runs once both are up. The pool building moves into ne_replace_cpu_pool() for that. That way a valid list on the command line gets its pool, and an invalid one reports why. A list that ne_init() rejects is cleared out of ne_cpus, so the parameter does not keep naming a pool that was never built. Fixes: ff8a4d3e3a99 ("nitro_enclaves: Add logic for setting an enclave vCPU") Signed-off-by: Alexander Graf --- v1 -> v2: - Clear ne_cpus when ne_init() rejects the boot-time list (Sashiko) drivers/virt/nitro_enclaves/ne_misc_dev.c | 67 +++++++++++++++++++++-- 1 file changed, 62 insertions(+), 5 deletions(-) diff --git a/drivers/virt/nitro_enclaves/ne_misc_dev.c b/drivers/virt/nitro_enclaves/ne_misc_dev.c index 232bdc651f833..ed7af30f69afa 100644 --- a/drivers/virt/nitro_enclaves/ne_misc_dev.c +++ b/drivers/virt/nitro_enclaves/ne_misc_dev.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -104,6 +105,13 @@ module_param_cb(ne_cpus, &ne_cpu_pool_ops, &ne_cpus_arg, 0644); /* https://www.kernel.org/doc/html/latest/admin-guide/kernel-parameters.html#cpu-lists */ MODULE_PARM_DESC(ne_cpus, " - CPU pool used for Nitro Enclaves"); +/* + * The parameter a value from the kernel command line is kept in until ne_init() + * builds its pool. Nothing else writes ne_cpus, so it is set whenever ne_cpus + * holds a value, and no sysfs write can reach the setter before ne_init() runs. + */ +static const struct kernel_param *ne_cpus_kp; + /** * struct ne_cpu_pool - CPU pool used for Nitro Enclaves. * @avail_threads_per_core: Available full CPU cores to be dedicated to @@ -450,7 +458,7 @@ static void ne_snapshot_cpu_pool(struct cpumask *cpu_pool) } /** - * ne_set_kernel_param() - Set the NE CPU pool value via the NE kernel parameter. + * ne_replace_cpu_pool() - Replace the NE CPU pool with the one a CPU list names. * @val: NE CPU pool string value. * @kp : NE kernel parameter associated with the NE CPU pool. * @@ -459,7 +467,7 @@ static void ne_snapshot_cpu_pool(struct cpumask *cpu_pool) * * 0 on success. * * Negative return value on failure. */ -static int ne_set_kernel_param(const char *val, const struct kernel_param *kp) +static int ne_replace_cpu_pool(const char *val, const struct kernel_param *kp) { char error_val[] = ""; cpumask_var_t cpu_pool; @@ -469,9 +477,6 @@ static int ne_set_kernel_param(const char *val, const struct kernel_param *kp) unsigned int nr_cores = 0; int rc = -EINVAL; - if (!capable(CAP_SYS_ADMIN)) - return -EPERM; - if (!zalloc_cpumask_var(&cpu_pool, GFP_KERNEL)) return -ENOMEM; @@ -593,6 +598,39 @@ static int ne_set_kernel_param(const char *val, const struct kernel_param *kp) return rc; } +/** + * ne_set_kernel_param() - Set the NE CPU pool value via the NE kernel parameter. + * @val: NE CPU pool string value. + * @kp : NE kernel parameter associated with the NE CPU pool. + * + * Context: Process context. + * Return: + * * 0 on success. + * * Negative return value on failure. + */ +static int ne_set_kernel_param(const char *val, const struct kernel_param *kp) +{ + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; + + /* + * A value on the kernel command line reaches this from the parse_args() + * call in start_kernel(), which runs before mm_core_init() has brought + * up the allocator a cpumask comes from and long before smp_init() has + * brought online the CPUs a pool is built out of. Keep the value and + * leave the pool to ne_init(), which runs from do_basic_setup() with + * both of those behind it. A value from modprobe or from sysfs arrives + * with the system already up and is applied here. + */ + if (system_state == SYSTEM_BOOTING) { + ne_cpus_kp = kp; + + return param_set_copystring(val, kp); + } + + return ne_replace_cpu_pool(val, kp); +} + /** * ne_free_kernel_param() - Tear down the NE CPU pool when the module goes away. * @arg: The NE kernel parameter argument, unused. @@ -2005,8 +2043,27 @@ static long ne_ioctl(struct file *file, unsigned int cmd, unsigned long arg) static int __init ne_init(void) { + static char cpu_list[NE_CPUS_SIZE] __initdata; int rc; + /* + * Build the pool of a CPU list that came from the kernel command line, + * which the setter only kept. The value is taken out of the parameter + * string first, because building the pool writes that string. A list + * the build rejects is taken out of the parameter too, so ne_cpus does + * not name a pool that was never built. + */ + if (ne_cpus_kp && ne_cpus[0]) { + memcpy(cpu_list, ne_cpus, sizeof(cpu_list)); + + if (ne_replace_cpu_pool(cpu_list, ne_cpus_kp) < 0) { + param_set_copystring("", ne_cpus_kp); + + pr_err("%s: No CPU pool from nitro_enclaves.ne_cpus=%s\n", + ne_misc_dev.name, cpu_list); + } + } + rc = pci_register_driver(&ne_pci_driver); if (rc < 0) ne_teardown_cpu_pool(); -- 2.47.1