From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=35.162.73.231 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795977048; b=VHl6EmH3Nkm3o1YsKuQX00C7/pDJjEzr2P4SdRMBSK4f7TnGTPzhrPM7dBz405EaRYFB 3O7h1H+3fUopBpd3jyA1/sodpNysgY5rWdNCgY9BzPxq74XXRVkdDBgBpCWwOWlvGP0au +cnoBQEkncOcxAdcgWcHJOFTCToKV6yfUPbT7VnRyPEZdjPR0ZTU5HEMxNMVndCHImUrR ZBwg2kc0pyX5RQs2QT/HjzPrKQ08K5z65+hVmy/HVExGSu0zwOE2NkpAFtPHpWnSDJvGc uP7MdOyWP7QHvc4vIYvTk2I33TEdXN6T48wbFbTcjpIE70xkOqGQ3qNMPBINpa2C2ug== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795977048; 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=34GqbRKvvWrglokp4MY5ziNNagU9fbplUFx8UTok7UU=; b=tdtBm5lp845GcdPlad/2uwXxjzX4aHpb6Wzc4iE75gxZziY73WKvOkBD01/2mQ716ZST 8ykbvd6B6Gnsc7SQaeY10YitlNsLAhTUhsfQ1LqOgnDVhUvGccIIRxf3LVn3hmEEYS/B3 rUn4EeVokx06Ropudu8JxsP3paaoChyGa9ACT25tY7bVwsfluxOhIamwmNQsPPd7DtpfK RxAGDXzNlCY77Pv0gkc7G5GX95ikrA/OnhbG0TZu3+wCXgogm5pnwFBtx+/ZfXoaTdJoB Yym2hkRRIgi78wDqhdZ+Dn5tzUzsjxPIjl4yz0KoLkrMvtiSVu/otyS3pcWNcsA2AZw== 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=TJaaJ9cJ; arc=none smtp.remote-ip=35.162.73.231 Received: from pdx-out-012.esa.us-west-2.outbound.mail-perimeter.amazon.com (pdx-out-012.esa.us-west-2.outbound.mail-perimeter.amazon.com [35.162.73.231]) (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 88DF6606A31C; Sun, 29 Nov 2026 18:30:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 88DF6606A31C 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=TJaaJ9cJ DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazoncorp2; t=1795977047; x=1827513047; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=34GqbRKvvWrglokp4MY5ziNNagU9fbplUFx8UTok7UU=; b=TJaaJ9cJnYd0R5XGllne1owXkcE90IwFXX00bwHBsaoWvkk/iQr7UbGW M6lLrVsJTe5/HDmFLFVlbXFH6tRKea7+0xiPZn4gIiB4X6EMRUQ0fgC2g OonzrQVvp8MhiqHLPFISA9N5ZPqfj16GBwr40rsqGb9ZdAxjPJY94qaPv 2uZP3hj6GP78xq8tDV1HY4zIWp8kwBfGh5KEGz+X8417p1D1XCAmaX0/A 8pLRpVSiyhGbSCLo95pyfGuxDj2zRqewJ8fxMd7QyhWgbSEm9Ysxkl+RN vi1pgZb6bta0FLxbXHN3cca8A4CiPY+YaV+XurzKTfb2Y15w1qv9MHNL0 w==; X-CSE-ConnectionGUID: xRTER0D5SI65QVED2hFrNQ== X-CSE-MsgGUID: bvOttq5aSOOoU2ZC50vJnA== X-IronPort-AV: E=Sophos;i="6.27,241,1787011200"; d="scan'208";a="35245748" Received: from ip-10-5-0-115.us-west-2.compute.internal (HELO smtpout.naws.us-west-2.prod.farcaster.email.amazon.dev) ([10.5.0.115]) by internal-pdx-out-012.esa.us-west-2.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Nov 2026 18:30:44 +0000 Received: from EX19MTAUWC001.ant.amazon.com [205.251.233.53:27890] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.27.231:2525] with esmtp (Farcaster) id adfad67f-2f24-4090-884e-7ddd4cc28bb9; Sun, 29 Nov 2026 18:30:44 +0000 (UTC) X-Farcaster-Flow-ID: adfad67f-2f24-4090-884e-7ddd4cc28bb9 Received: from EX19D001UWA001.ant.amazon.com (10.13.138.214) by EX19MTAUWC001.ant.amazon.com (10.250.64.174) 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:30:44 +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:30:40 +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 15/23] nitro_enclaves: Put the CPU pool back when the new CPU list is refused Date: Sun, 29 Nov 2026 18:21:44 +0000 Message-ID: <20e6783e5edd915016f478dcfaef48fafe80c992.1795965038.git.graf@amazon.com> 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: EX19D031UWA003.ant.amazon.com (10.13.139.47) To EX19D001UWA001.ant.amazon.com (10.13.138.214) An admin who writes a CPU list that the driver refuses, for example one that names CPU 0, leaves out a sibling or spans two NUMA nodes, loses the pool that was there. The checks need every CPU of the list online and a CPU the pool holds is offline, so they can only run after the old pool is torn down. Snapshot the CPUs of the pool before the teardown, and set the pool up again from the snapshot when the new list is refused. Where that fails as well, clear ne_cpus so that it does not name a pool that is gone. Fixes: ff8a4d3e3a99 ("nitro_enclaves: Add logic for setting an enclave vCPU") Signed-off-by: Alexander Graf --- drivers/virt/nitro_enclaves/ne_misc_dev.c | 43 +++++++++++++++++++---- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/drivers/virt/nitro_enclaves/ne_misc_dev.c b/drivers/virt/nitro_enclaves/ne_misc_dev.c index 6efd55cfb6cb6..f4a531e705917 100644 --- a/drivers/virt/nitro_enclaves/ne_misc_dev.c +++ b/drivers/virt/nitro_enclaves/ne_misc_dev.c @@ -427,6 +427,24 @@ static void ne_teardown_cpu_pool(void) ne_free_core_slots(threads_per_core, nr_cores); } +/** + * ne_snapshot_cpu_pool() - Copy out the CPUs the NE CPU pool holds. + * @cpu_pool: CPU mask to fill in with the CPUs from the NE CPU pool. + * + * Context: Process context. + */ +static void ne_snapshot_cpu_pool(struct cpumask *cpu_pool) +{ + unsigned int i = 0; + + mutex_lock(&ne_cpu_pool.mutex); + + for (i = 0; i < ne_cpu_pool.nr_parent_vm_cores; i++) + cpumask_or(cpu_pool, cpu_pool, ne_cpu_pool.avail_threads_per_core[i]); + + mutex_unlock(&ne_cpu_pool.mutex); +} + /** * ne_set_kernel_param() - Set the NE CPU pool value via the NE kernel parameter. * @val: NE CPU pool string value. @@ -441,6 +459,7 @@ static int ne_set_kernel_param(const char *val, const struct kernel_param *kp) { char error_val[] = ""; cpumask_var_t cpu_pool; + cpumask_var_t old_pool; struct ne_pci_dev *ne_pci_dev = NULL; cpumask_var_t *threads_per_core = NULL; unsigned int nr_cores = 0; @@ -452,9 +471,15 @@ static int ne_set_kernel_param(const char *val, const struct kernel_param *kp) if (!zalloc_cpumask_var(&cpu_pool, GFP_KERNEL)) return -ENOMEM; + if (!zalloc_cpumask_var(&old_pool, GFP_KERNEL)) { + free_cpumask_var(cpu_pool); + + return -ENOMEM; + } + rc = down_read_killable(&ne_devs.lock); if (rc) - goto free_cpumask; + goto free_cpumasks; ne_pci_dev = ne_devs.ne_pci_dev; @@ -512,6 +537,8 @@ static int ne_set_kernel_param(const char *val, const struct kernel_param *kp) * device_hotplug_lock, which ACPI hotplug holds around the probe and * remove callbacks, and those take ne_devs.lock. */ + ne_snapshot_cpu_pool(old_pool); + ne_detach_cpu_pool(&threads_per_core, &nr_cores); if (ne_pci_dev) @@ -529,9 +556,10 @@ static int ne_set_kernel_param(const char *val, const struct kernel_param *kp) if (rc < 0) { pr_err("%s: Error in setup CPU pool [rc=%d]\n", ne_misc_dev.name, rc); - param_set_copystring(error_val, kp); + if (cpumask_empty(old_pool) || ne_setup_cpu_pool(old_pool) < 0) + param_set_copystring(error_val, kp); - goto free_cpumask; + goto free_cpumasks; } rc = param_set_copystring(val, kp); @@ -540,10 +568,11 @@ static int ne_set_kernel_param(const char *val, const struct kernel_param *kp) ne_teardown_cpu_pool(); - param_set_copystring(error_val, kp); + if (cpumask_empty(old_pool) || ne_setup_cpu_pool(old_pool) < 0) + param_set_copystring(error_val, kp); } - goto free_cpumask; + goto free_cpumasks; unlock: if (ne_pci_dev) @@ -552,7 +581,9 @@ static int ne_set_kernel_param(const char *val, const struct kernel_param *kp) unlock_devs: up_read(&ne_devs.lock); -free_cpumask: +free_cpumasks: + free_cpumask_var(old_pool); + free_cpumask_var(cpu_pool); return rc; -- 2.47.1