From patchwork Wed Feb 9 08:02:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 12739746 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 lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 50E0EC433EF for ; Wed, 9 Feb 2022 08:02:50 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.268816.462752 (Exim 4.92) (envelope-from ) id 1nHhvk-0001gP-O6; Wed, 09 Feb 2022 08:02:24 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 268816.462752; Wed, 09 Feb 2022 08:02:24 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nHhvk-0001gI-L4; Wed, 09 Feb 2022 08:02:24 +0000 Received: by outflank-mailman (input) for mailman id 268816; Wed, 09 Feb 2022 08:02:24 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nHhvj-0001gC-Nh for xen-devel@lists.xenproject.org; Wed, 09 Feb 2022 08:02:24 +0000 Received: from galois.linutronix.de (galois.linutronix.de [193.142.43.55]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 9bde2105-897e-11ec-8f75-fffcc8bd4f1a; Wed, 09 Feb 2022 09:02:22 +0100 (CET) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 9bde2105-897e-11ec-8f75-fffcc8bd4f1a From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1644393741; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FtIrm50qhttDnvw+t6HEGKMbZATCUZOMdzvBi9MSe90=; b=M+XiBZLvnS4bNyf917WB109HyC2w29CJUrl4+O3s0DgpsdEx7qd9LvVurUJCNhRS15Nnsu cRSfB+3pzT1O13psRd1f1F9RUn9biTeEoiOyQmgimdTbr/vjqZy4deWCmwndr0QD2ufJ+o Sqd0tsdtLPAXbSLtB6Ji4LmVP+iCKv0Wi8A/f7QNPsiv7QL9eRdaHboT0vES0Rkm5q3nVj SpwQ1re3o986jPQhDh5fxadxCmGBF1Vzc3lThDa3bMhOehonLIvbh9MLuv6ROwY5VULVZR 2E4X2eG/cFMezVii0GULTAbaf5XfnGRONCEx1DX7F1mYfNUvbSlZMPFwSeGCFA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1644393741; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FtIrm50qhttDnvw+t6HEGKMbZATCUZOMdzvBi9MSe90=; b=+3CvOrEeIA0hMtHDBMPRo5y999b5GRmR5FqI8tJFmUGxGgnh38jpNfHNPILyt8qyLKUD1R 20dt3aOcmPlVKbDQ== To: linux-kernel@vger.kernel.org, x86@kernel.org, xen-devel@lists.xenproject.org Cc: Thomas Gleixner , Longpeng , Gonglei , Peter Zijlstra , Ingo Molnar , Valentin Schneider , Juergen Gross , Stefano Stabellini , Ingo Molnar , Borislav Petkov , Dave Hansen , "H . Peter Anvin" , Boris Ostrovsky , Sebastian Andrzej Siewior Subject: [PATCH REPOST v2 1/2] x86/xen: Allow to retry if cpu_initialize_context() failed. Date: Wed, 9 Feb 2022 09:02:13 +0100 Message-Id: <20220209080214.1439408-2-bigeasy@linutronix.de> In-Reply-To: <20220209080214.1439408-1-bigeasy@linutronix.de> References: <20220209080214.1439408-1-bigeasy@linutronix.de> MIME-Version: 1.0 From: Boris Ostrovsky If memory allocation in cpu_initialize_context() fails then it will bring up the VCPU and leave with the corresponding CPU bit set in xen_cpu_initialized_map. The following (presumably successful) CPU bring up will BUG in xen_pv_cpu_up() because nothing for that VCPU would be initialized. Clear the CPU bits, that were set in cpu_initialize_context() in case the memory allocation fails. [ bigeasy: Creating a patch from Boris' email. ] Signed-off-by: Boris Ostrovsky Signed-off-by: Sebastian Andrzej Siewior Link: https://lore.kernel.org/r/20211206152034.2150770-2-bigeasy@linutronix.de --- arch/x86/xen/smp_pv.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/arch/x86/xen/smp_pv.c b/arch/x86/xen/smp_pv.c index 4a6019238ee7d..57c3f9332ec94 100644 --- a/arch/x86/xen/smp_pv.c +++ b/arch/x86/xen/smp_pv.c @@ -260,8 +260,11 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle) return 0; ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL); - if (ctxt == NULL) + if (ctxt == NULL) { + cpumask_clear_cpu(cpu, xen_cpu_initialized_map); + cpumask_clear_cpu(cpu, cpu_callout_mask); return -ENOMEM; + } gdt = get_cpu_gdt_rw(cpu); From patchwork Wed Feb 9 08:02:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 12739747 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 lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EA3B7C433F5 for ; Wed, 9 Feb 2022 08:02:50 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.268818.462774 (Exim 4.92) (envelope-from ) id 1nHhvo-0002Ce-95; Wed, 09 Feb 2022 08:02:28 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 268818.462774; Wed, 09 Feb 2022 08:02:28 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nHhvo-0002CX-4z; Wed, 09 Feb 2022 08:02:28 +0000 Received: by outflank-mailman (input) for mailman id 268818; Wed, 09 Feb 2022 08:02:26 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nHhvm-0001r0-HO for xen-devel@lists.xenproject.org; Wed, 09 Feb 2022 08:02:26 +0000 Received: from galois.linutronix.de (galois.linutronix.de [193.142.43.55]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 9c59a9de-897e-11ec-8eb8-a37418f5ba1a; Wed, 09 Feb 2022 09:02:24 +0100 (CET) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 9c59a9de-897e-11ec-8eb8-a37418f5ba1a From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1644393742; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mGICh+XWg4zl0BiLYSOzGN+Dsvh3xZ6pQjRuhNeu4t0=; b=ExUJbo84qFWHQkDAcAAStNINkRabfk8iqlakMkfpAmeUEtkbAySRTYSeSJDPzjC8ESDJjs swNFfrhhlAGeF0NLs/r64Eyk+1Td6b9zKYMN3ok5zwYOgcaOAP1qkPPo1oL2jV2sNsdI5+ LiSOvtHlUYOZK+mDwdteqLAhgWjyasTaXK64aUt9UGdT8Z5UiiLBZU6owgmiZqsUOgXuLM fEDKOzNGXSw1XwOn+qC53DI8miXoiqN0FrfwxuqRL9vsRDzdbnbAHm6QPh7QLy1Brvz86x AowW/70fENFFaxAkvAaZcbDSXsWmL22tSd1WGdhaLdOKNblqDvfFYeWtRQhi+w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1644393742; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mGICh+XWg4zl0BiLYSOzGN+Dsvh3xZ6pQjRuhNeu4t0=; b=g1B138BAtPqSmJQ3szFTc93wehmOLL8GH6VVKCoGPE7yBHuAp4eaCSW9kuMmWr95Ow20Gr zuRl08iV0JPH6NDg== To: linux-kernel@vger.kernel.org, x86@kernel.org, xen-devel@lists.xenproject.org Cc: Thomas Gleixner , Longpeng , Gonglei , Peter Zijlstra , Ingo Molnar , Valentin Schneider , Juergen Gross , Stefano Stabellini , Ingo Molnar , Borislav Petkov , Dave Hansen , "H . Peter Anvin" , Sebastian Andrzej Siewior , Dongli Zhang , Henry Wang Subject: [PATCH REPOST v2 2/2] cpu/hotplug: Allow the CPU in CPU_UP_PREPARE state to be brought up again. Date: Wed, 9 Feb 2022 09:02:14 +0100 Message-Id: <20220209080214.1439408-3-bigeasy@linutronix.de> In-Reply-To: <20220209080214.1439408-1-bigeasy@linutronix.de> References: <20220209080214.1439408-1-bigeasy@linutronix.de> MIME-Version: 1.0 From: "Longpeng(Mike)" A CPU will not show up in virtualized environment which includes an Enclave. The VM splits its resources into a primary VM and a Enclave VM. While the Enclave is active, the hypervisor will ignore all requests to bring up a CPU and this CPU will remain in CPU_UP_PREPARE state. The kernel will wait up to ten seconds for CPU to show up (do_boot_cpu()) and then rollback the hotplug state back to CPUHP_OFFLINE leaving the CPU state in CPU_UP_PREPARE. The CPU state is set back to CPUHP_TEARDOWN_CPU during the CPU_POST_DEAD stage. After the Enclave VM terminates, the primary VM can bring up the CPU again. Allow to bring up the CPU if it is in the CPU_UP_PREPARE state. [bigeasy: Rewrite commit description.] Signed-off-by: Longpeng(Mike) Signed-off-by: Sebastian Andrzej Siewior Link: https://lore.kernel.org/r/20210901051143.2752-1-longpeng2@huawei.com Reviewed-by: Valentin Schneider Tested-by: Dongli Zhang Reviewed-by: Henry Wang Link: https://lore.kernel.org/r/20211122154714.xaoxok3fpk5bgznz@linutronix.de Link: https://lore.kernel.org/r/20211206152034.2150770-3-bigeasy@linutronix.de --- kernel/smpboot.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/kernel/smpboot.c b/kernel/smpboot.c index f6bc0bc8a2aab..b9f54544e7499 100644 --- a/kernel/smpboot.c +++ b/kernel/smpboot.c @@ -392,6 +392,13 @@ int cpu_check_up_prepare(int cpu) */ return -EAGAIN; + case CPU_UP_PREPARE: + /* + * Timeout while waiting for the CPU to show up. Allow to try + * again later. + */ + return 0; + default: /* Should not happen. Famous last words. */