Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1155310rwd; Thu, 18 May 2023 08:35:31 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7nXSpi1Wb54CRgBHd+au48voAMopFvwxLMAR7skM02cWOvmUAwDmatIASWM4mlYnDmrvpP X-Received: by 2002:a17:90a:5a0a:b0:253:3975:7a37 with SMTP id b10-20020a17090a5a0a00b0025339757a37mr3227933pjd.9.1684424131535; Thu, 18 May 2023 08:35:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1684424131; cv=pass; d=google.com; s=arc-20160816; b=eb/CZr+eWQFdj560v0fsR4EZafVyt1z4uRrqYWrOajWG1WDesQXKAe5UpRjT+dzkBZ R1ZeW7YAouuL1KQll/NVmhRC4duw05sWW6WACBCaoOzTDqr62AJ4lZUugIdqDFJoSoyM Z7fK3UQowffqpDD6MCpsgWwy8fB3Ajk4NYJiz3V5V92kYAbFt4+EkOWcei/hl4Cd+rUo WgFiCNrmGXkkSNlGmLT1dHiTXbub0R6nSM9QCFDx1ZXHEC7d04us0ditsYmaWRrY2G/Y GSt0n01kOzisgaoqNuyrvS7MYTiB5JILBxCUWC40Ehl0vCslPSt1CsPlPrnWPySvD8Xg 5dGQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from :dkim-signature; bh=Y7IaCsmwMXghF0Wa0lt8/SC0QjzVqzUsAbk94IPtFqM=; b=m3FisSbl++Bf672fPnxmCACK3h/QPbnB+a1ijGA3yAwMrHaeELiXg8QDvjsZ0S5fiF f3K4OFrL1crf8z9Oo366uDRMiu0CoeZDjcEJ9N2BDF0I8tL7yYWb9mGPPvoPYUzzfj6Z wK1WyRJstAcGNjAotZrRq5dMW4Y9O2a1R+ySdNQSIg09dp1VbfJ34gyoWRGy/D7lMto7 QtcHMvYWZQl12+mT6JuAjFuSVL4cppZsUIqxjEN0WXaIEsollFjT4vRtDSw8EpS+B63q PK3yxclah4r659+VD7tCYZFQ6qnSr/HoCuZ2HlKTgqtcPGXved0xIQKdNPeZMjST3deM jb6g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=c85vjnhD; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w11-20020a17090abc0b00b00253728ab2b6si434274pjr.163.2023.05.18.08.35.08; Thu, 18 May 2023 08:35:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=c85vjnhD; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231604AbjERPOn (ORCPT + 99 others); Thu, 18 May 2023 11:14:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231410AbjERPOl (ORCPT ); Thu, 18 May 2023 11:14:41 -0400 Received: from BN3PR00CU001.outbound.protection.outlook.com (mail-eastus2azon11020025.outbound.protection.outlook.com [52.101.56.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 323DB119; Thu, 18 May 2023 08:14:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GL/PoL+KDHaMXvnyGM3wmnW65W5AJy85o82+JtFeuEOvKJkoy7cRYHvntv0jTEiBvIoTcOLCPjENTfa+yQEz8g0wfaNhi4j4oYbgvTdO7ASGxCzkcqzCM1yHcWMu8f76JxAQvietpnIk8AJCM3UFnq3YzwittEDF/DwEIw4OqaKAPZR2t66S+pc6Nbhl+ppw3l1idpNNPZ43LVFWUQHkM0Df3J+/Enuwbv8G9T8yyDFwjyK6yeIxjgo57rOtRWo+rsXYnh8zjgv4qBgzzKxOXHiE37oujbr7be3sCggjWAZGxYoZKL426no6chegpO8m4AJQHqVKfjZ6hoqDdXmF5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Y7IaCsmwMXghF0Wa0lt8/SC0QjzVqzUsAbk94IPtFqM=; b=YmTDhuNSWk5xxcNt5OoykzhEZiy4gbsPU/0ZIefaIzSjoPeG0ARYM08rZyLf4/sNR0CL09ddCiRqIhlfOzkp83lunwTxh1pC/M5DVt9JH4JlVS0dk/h5Y9TWdtfUd/CSriN7zmiacQkioHt+lRdMIHtK21rY0fv+tfy+ceQRoRBjsIe+izRpj6kEWudHwd/iCmyLOjl2jWKYE3SPjswt4+GkxIqK75xZZw+1G9uWpFLeS6eztM1oypSZtcXnEb/V7hKdDHrkqtjyd7CZGwQ336qxsTlGFl11VDTnJgnbQtsna19m/UZ4A1ifvOxz6HLcxTmNDFz6wOTBxJ26tRfn7w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Y7IaCsmwMXghF0Wa0lt8/SC0QjzVqzUsAbk94IPtFqM=; b=c85vjnhDUirjQj87bOgpD2Zw2zq0iKXTtie+6lz8jlAL5I4IFFY5+i6Y3ddYq+zZ5438rnIfh7NPnm0EtXLN5z+H7W1dz0m1aGFaqHARWN8d2XhqLvQsEVL1oYTSD0ozwLByndVJYObDCehOce0Yjj3c8TlHd+lqqkrCj4VevjQ= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; Received: from DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) by SN7PR21MB3827.namprd21.prod.outlook.com (2603:10b6:806:29a::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.6; Thu, 18 May 2023 15:14:36 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::b7e9:4da1:3c23:35f]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::b7e9:4da1:3c23:35f%6]) with mapi id 15.20.6433.006; Thu, 18 May 2023 15:14:36 +0000 From: Michael Kelley To: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, vkuznets@redhat.com, decui@microsoft.com Cc: mikelley@microsoft.com, stable@vger.kernel.org Subject: [PATCH v2 1/1] Drivers: hv: vmbus: Fix vmbus_wait_for_unload() to scan present CPUs Date: Thu, 18 May 2023 08:13:52 -0700 Message-Id: <1684422832-38476-1-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 Content-Type: text/plain X-ClientProxiedBy: CY5PR15CA0198.namprd15.prod.outlook.com (2603:10b6:930:82::14) To DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR21MB1370:EE_|SN7PR21MB3827:EE_ X-MS-Office365-Filtering-Correlation-Id: ff34140c-6c2f-4a6f-f03b-08db57b2944a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: r1im+lOj89g077grve6MqxlmAAec5oH2j/M0HwOynh1zCrkweNQesjXkquPOtfAIzfAM3HWDOWYkQQbU2cwPr+5NT3m6BR3+jpoYsinkh3Pbop/TWeA4acpFLFsh/3D+Bm9XcuSHhZa98xaV9jmOEU9CFYkExlsZk69h8XQKgKsC86pEtP80o7GLecPrKMBRfks3Iv28L98aSW5Zaqp9BL6Q3vYZJT0Mm6wF3zJ5+EDJe5crPlcj6F1nOpOS1uOOLOQwSm/yNE7FIyjGm/51S2ix7fhUmHnXi0LtiePApD/15ZLb7s3LvacCPCL4zD+93Wt3W+VCNekwvyjSK0EHdRHaXfjtGPoj41LwqfDvAZNNwko/w4mC1FhPOsdqloBlY9zuU3cbu78f4Aq+8KfNL9ppoxmjrs8pmP0nSMAzkIym+96o1dJnqyZfvdFc+LwAJajJbCWkZB5xGOOpeZZw2pAzh4u0rJHthJMoZ35AYQv6QsD32hJsUSR3lK4Em28w44aE6yR7t+xtBEEgMdleg6JFMG0anol+taTCvmmHP52axVhN/gzM/sYc/tbSCuWNkN3h90vDcAYSWNU6UkkmaNgPsI1X4dmdmujGSesLxTjB+0imI/RxJrGP4FyglM0dExTqqIFD2vlmUiR1znW8VWyD70mcweJg5sWkIn8ihJc= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR21MB1370.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(136003)(346002)(376002)(39860400002)(396003)(366004)(451199021)(52116002)(6666004)(6486002)(41300700001)(36756003)(38350700002)(38100700002)(6512007)(6506007)(26005)(5660300002)(2616005)(83380400001)(186003)(2906002)(86362001)(8676002)(8936002)(82960400001)(82950400001)(66556008)(66476007)(66946007)(6636002)(4326008)(10290500003)(478600001)(316002)(786003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?pu+227EXLe8mSPYmEc3gRbDAlw6fP/v7S2R8QamQIFhECx3etOu++6Vv573r?= =?us-ascii?Q?qs+5oRAa4ieC9GWYB/umd6ri1kJRp2Zd1qWIoZZu2IQYFasjS0QmT5WKhoYH?= =?us-ascii?Q?j/yQ5eYCFhGpHUDmBn3sc7kzSLTNaSzdBzbhxMS5FJICHC34P/rvQ2MEtMRD?= =?us-ascii?Q?gYEoaVPv/EuRO3Zu4jNn1cBPKMy4T1kUGAEDtcxRJV8SMEUknx0IwgiAfuG+?= =?us-ascii?Q?jzMfAtcdqXVIqlbdy6xCvess1zZ477nGx6JByW4tZYxX7nYhBvldRjvAWjYH?= =?us-ascii?Q?Q/ZNULWoWZiZw17xKMgL63W6mDiFc/gMM4GvqFfRJhwIN6q4ZKa29JkKs76q?= =?us-ascii?Q?ERswLjX267TlB0LvB8k92KHsh7Sd/N6WaMKyLbPIG56qZ5uysxZ0Rl6TMcx4?= =?us-ascii?Q?RhilFpcQRccyZxG4PueDQsjPZ0X6mqenPh715Jkw0KMZKYvZaWg61z2ywQxA?= =?us-ascii?Q?JK067X3bZzKoc+0Lmc5uJg+xNWk0ENdVNbsFfgpU7yKwsYaL6R5/SsctbYec?= =?us-ascii?Q?1SJB2L8O4V8tK1fiI5UpxsmunS3GKk31Or7F6ryOJeku7bjlNQ9bGRtEeQmx?= =?us-ascii?Q?Kyu91hMkz5fJBzxiHhrEQTtB94ojbc5fOPE4tvQeZM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8FozFV3M3CSw5yr9Pz6IDGmmrxKdMHfPQ1g7KWw14VyqfPB8M?= =?us-ascii?Q?rQU5s/zN4hU/s63E7KkqQ7o4Ti1CHg0DGNiuHoZW?= X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: ff34140c-6c2f-4a6f-f03b-08db57b2944a X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 May 2023 15:14:31.7294 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 5KP7kBU77bIytZYGzvmNFB/GRCR7d58ZQFarx31cIu4U+ugFRaFGCfif5vmloeo2VMFdbe3HwA690vKNOOGSew== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR21MB3827 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org vmbus_wait_for_unload() may be called in the panic path after other CPUs are stopped. vmbus_wait_for_unload() currently loops through online CPUs looking for the UNLOAD response message. But the values of CONFIG_KEXEC_CORE and crash_kexec_post_notifiers affect the path used to stop the other CPUs, and in one of the paths the stopped CPUs are removed from cpu_online_mask. This removal happens in both x86/x64 and arm64 architectures. In such a case, vmbus_wait_for_unload() only checks the panic'ing CPU, and misses the UNLOAD response message except when the panic'ing CPU is CPU 0. vmbus_wait_for_unload() eventually times out, but only after waiting 100 seconds. Fix this by looping through *present* CPUs in vmbus_wait_for_unload(). The cpu_present_mask is not modified by stopping the other CPUs in the panic path, nor should it be. Also, in a CoCo VM the synic_message_page is not allocated in hv_synic_alloc(), but is set and cleared in hv_synic_enable_regs() and hv_synic_disable_regs() such that it is set only when the CPU is online. If not all present CPUs are online when vmbus_wait_for_unload() is called, the synic_message_page might be NULL. Add a check for this. Fixes: cd95aad55793 ("Drivers: hv: vmbus: handle various crash scenarios") Cc: stable@vger.kernel.org Reported-by: John Starks Signed-off-by: Michael Kelley Reviewed-by: Vitaly Kuznetsov --- Changes in v2: * Added a comment and updated commit messages to describe scenario where synic_message_page might be NULL * Added Cc: stable@vger.kernel.org drivers/hv/channel_mgmt.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c index 007f26d..2f4d09c 100644 --- a/drivers/hv/channel_mgmt.c +++ b/drivers/hv/channel_mgmt.c @@ -829,11 +829,22 @@ static void vmbus_wait_for_unload(void) if (completion_done(&vmbus_connection.unload_event)) goto completed; - for_each_online_cpu(cpu) { + for_each_present_cpu(cpu) { struct hv_per_cpu_context *hv_cpu = per_cpu_ptr(hv_context.cpu_context, cpu); + /* + * In a CoCo VM the synic_message_page is not allocated + * in hv_synic_alloc(). Instead it is set/cleared in + * hv_synic_enable_regs() and hv_synic_disable_regs() + * such that it is set only when the CPU is online. If + * not all present CPUs are online, the message page + * might be NULL, so skip such CPUs. + */ page_addr = hv_cpu->synic_message_page; + if (!page_addr) + continue; + msg = (struct hv_message *)page_addr + VMBUS_MESSAGE_SINT; @@ -867,11 +878,14 @@ static void vmbus_wait_for_unload(void) * maybe-pending messages on all CPUs to be able to receive new * messages after we reconnect. */ - for_each_online_cpu(cpu) { + for_each_present_cpu(cpu) { struct hv_per_cpu_context *hv_cpu = per_cpu_ptr(hv_context.cpu_context, cpu); page_addr = hv_cpu->synic_message_page; + if (!page_addr) + continue; + msg = (struct hv_message *)page_addr + VMBUS_MESSAGE_SINT; msg->header.message_type = HVMSG_NONE; } -- 1.8.3.1