From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from aserp2120.oracle.com (aserp2120.oracle.com [141.146.126.78]) by mx.groups.io with SMTP id smtpd.web12.31930.1613978389308722014 for ; Sun, 21 Feb 2021 23:19:49 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=oDH7cG9P; spf=pass (domain: oracle.com, ip: 141.146.126.78, mailfrom: ankur.a.arora@oracle.com) Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 11M7Dv4f131242; Mon, 22 Feb 2021 07:19:46 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2020-01-29; bh=b2bE66bX2QhqReGUL5sLF1Eh2kfjXO969oJmWd9P7zo=; b=oDH7cG9PU+iHmmwzuEeRvv9wew1E9IR3CpTxLuJoQi3Tkerfpp9hkvdAe/EkK2jWRU55 vMZEmx6h3hE+7pIRWIpaJLfTuXIbzcyt5Uk9IX2VspoyYMwQERowl/coqAV9u8agZzX1 WbIkux9E3kf/JH1GHwylZWp4hAL/yrM4ms/L0Pe0mrcB29t0Rw+9oxS5dIc/qIyFEIuc pVY96fIl/44rcxlw0+sK6nHY3RN0DXngMQ4w9gJHTitnpRuf2ZhQs5DHhUFWXQPAGXik EX8rbySCrGEHynvsV4WoaQEjf4R1yIFp5LOB3KRRVly5QDPt08JDOnercEkPZdlWaYBJ wA== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2120.oracle.com with ESMTP id 36ttcm2kea-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 22 Feb 2021 07:19:46 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 11M7GNIN155898; Mon, 22 Feb 2021 07:19:45 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2176.outbound.protection.outlook.com [104.47.59.176]) by userp3030.oracle.com with ESMTP id 36ucbvqk4f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 22 Feb 2021 07:19:45 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UpZWeUaddvqwPQwqAh8/3HSOjIXrvi7rNf7Op9GELZLaJT7/stj2oJFNz+IR2phqY8KbpPEG46/Ye0whhaKg/bpU+fuz8dQzgSVELIXZ5I6TYNLxfRbbGMVF7ssplqqds1x6iBq/CQXf2pML78H+sskfSzPizmEYc/7/7rLteE9gvKtdxFUK6Qs/ziJmCnPXNXjaoj/e1Bw2boxyMIwhraXHxBE9HifLV2MBeoU//W5R+Z3kf+vD7cCZEFhYcf+BQrXCGqKmOsAq6sYotUBt3xWJw1uxR/tBtIVlD9NCHKhS0rk/ioUccOouovs/FnOUeCL0aIm3AB0d50MHHtrDug== 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-SenderADCheck; bh=b2bE66bX2QhqReGUL5sLF1Eh2kfjXO969oJmWd9P7zo=; b=LzATsUXOtO2tyolujm5gPjZRml3oRtgFkccyRTcCjt4t29sv+Ve19KhkxF4YLW7JJKwEW/T+kMpCS2QE+aKhca246/4+taZHr//3+GEsySZrOPLzKwVg7C12auyq1B4dMM6RWQmwneT4BzyL+18T5/fLU+3p5U56ZZDYwMIjyEJy8A7C8TZcRGi0Ek8KCO5z7XIhEmUNpQS9qLEM2badWAeuuWfoB/ky7aEY+PmexCxvX/oKvVq478SniU62AWU4Vh0CZPtWqngw9H9iTo4VCwRmM2XRPHdU2l4s8kyTM9uNWtEmmFQtd7nN+MCi90D64YvzJhs9KvUUMVuWePaqNw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=b2bE66bX2QhqReGUL5sLF1Eh2kfjXO969oJmWd9P7zo=; b=oGs6winFO2qZ4SbMqGIFbjKVB9XlbDWTNKPVkPeCGWwK73bqxjLnQQf/OD29DZ19xeAHSi+5K+4NBa8ijKo5Gg14wXJeUKumSv7/e8AgKT4JwP7F9zUr2SHNADkYpHWJEAyiYJ8MbaekXsLAAzPE+NPYb71BF3M5ZrHADZ4yCkQ= Authentication-Results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=oracle.com; Received: from SJ0PR10MB4605.namprd10.prod.outlook.com (2603:10b6:a03:2d9::24) by BYAPR10MB3191.namprd10.prod.outlook.com (2603:10b6:a03:14f::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3868.29; Mon, 22 Feb 2021 07:19:42 +0000 Received: from SJ0PR10MB4605.namprd10.prod.outlook.com ([fe80::a021:790:7ce6:6f16]) by SJ0PR10MB4605.namprd10.prod.outlook.com ([fe80::a021:790:7ce6:6f16%6]) with mapi id 15.20.3868.033; Mon, 22 Feb 2021 07:19:42 +0000 From: "Ankur Arora" To: devel@edk2.groups.io Cc: lersek@redhat.com, imammedo@redhat.com, boris.ostrovsky@oracle.com, Ankur Arora , Jordan Justen , Ard Biesheuvel , Aaron Young Subject: [PATCH v8 04/10] OvmfPkg/CpuHotplugSmm: introduce UnplugCpus() Date: Sun, 21 Feb 2021 23:19:22 -0800 Message-Id: <20210222071928.1401820-5-ankur.a.arora@oracle.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210222071928.1401820-1-ankur.a.arora@oracle.com> References: <20210222071928.1401820-1-ankur.a.arora@oracle.com> X-Originating-IP: [148.87.23.11] X-ClientProxiedBy: MWHPR17CA0065.namprd17.prod.outlook.com (2603:10b6:300:93::27) To SJ0PR10MB4605.namprd10.prod.outlook.com (2603:10b6:a03:2d9::24) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from prion.us.oracle.com (148.87.23.11) by MWHPR17CA0065.namprd17.prod.outlook.com (2603:10b6:300:93::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3868.27 via Frontend Transport; Mon, 22 Feb 2021 07:19:41 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 888238dc-774e-47e8-ee49-08d8d7023938 X-MS-TrafficTypeDiagnostic: BYAPR10MB3191: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AWyXuwAM18boZsK2QanQc5MNypd1UCYZV8GLGqLzXrRjCVduCrDgVVOP+cWTw/+CNl+RJPUwXOuckiQcZFGnBhn7fdYGzCKEjfLz8shceHxSYw0DQTq8Fq3bZUPkM9krk2vWZxATwObMUEnQEKzU7QdpiPNZwkpVIZhWUMP5BSZHPbyrehcm3ygb6U/3UT0DF5EasXy2TPrqfKAA3yWdz3Phy+Jqpv9ATPA7mCvDa+jXzEyDd8hTcrGMgoUQ9EGII+aqw/6B9qY74jYzB5fuzmoXKtQHOWZnCErIbYJIH0lhN3OzX4lCWNRtjRjb18I/9n2uzYO4U+Fbro+rXvt944eUtgYKZFm7m5RLN8h14lS+zVS5PJG/wGyVhX+ayt1osIlFhmZi6Ez0u1ISIlLJK8NzCOP+rftsTlCL48mJXb/zbZmuSMJe9G1XRlsPVJE73uY+SIj758fgxV9BhyL8zEOa88SfbV52HtcJui5/LdDHqyWF9L85kj8WDTKgD2UgT7skB5cWYPMN8SccxZs5E6ZHo794nNtgOZoeJFaQKboVe+oCP9y+DBgVHDHe6XvGrVQHvoEA0vDWMuUzYFKsjm4mvBYQTLlvhlZCPmSbVUU= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR10MB4605.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(39860400002)(136003)(346002)(376002)(396003)(366004)(2906002)(8936002)(54906003)(316002)(83380400001)(478600001)(86362001)(8676002)(6916009)(6486002)(2616005)(186003)(16526019)(956004)(26005)(107886003)(5660300002)(7696005)(52116002)(66946007)(6666004)(66476007)(66556008)(36756003)(1076003)(4326008)(966005)(103116003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?Q6FNKt/NoWNUv6wE7yDj8Bt3IfsjCPJEXRl5nUJFy8CGsOHM9Jqxga0dsKns?= =?us-ascii?Q?PPYPyWqaMZJJyYMG/BSxnWgB9Xcg+sTEYQ2SGZFp18O7v4q/EXJHEEP+t11N?= =?us-ascii?Q?GMje3wXQaN50SvGkINX/BOVpBWPebGPM9U9v/QbFGfbeRvrk4gwqFCiRusxo?= =?us-ascii?Q?ufWBmdsXgRtaQ/1S9RcBloAKuMcocQn1SaJU0wIpkxa+ihevbROfUoE4lQ75?= =?us-ascii?Q?sH2TKVJAJXj3zVp/zbvV+H9oljvl8ZzgIxbaNBsKSGGFZskfT5n5sv0rfGvr?= =?us-ascii?Q?ngLWQ74VbhLnrNLO2eM2FERoZ4l43lecByFGN+Fxpn0F4zXoKxRgmDt7FXys?= =?us-ascii?Q?EUfVX07rGutno4r3xVE7DY8NTy2GKqb3BC6/M6KqPDxiO7QBqu7bHiscrR1b?= =?us-ascii?Q?eO8AayR4YHA4zLtBc3/6uisFVecwjf730ypVDN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jmFvHibTp1hqaNJSvzY?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 888238dc-774e-47e8-ee49-08d8d7023938 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB4605.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Feb 2021 07:19:42.4675 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: HOxMZ44QpF6MnZmO+yml46uC1qz/ddSrzWhpoEgb9GUAl0K2wbTJR8jK6AQKPLcjnxE5AfBQBe5nYX1ukDiwTOUsni0Ykc2Lu7gVJeOUT6U= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB3191 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9902 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 phishscore=0 spamscore=0 suspectscore=0 bulkscore=0 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2102220064 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9902 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 lowpriorityscore=0 spamscore=0 mlxscore=0 bulkscore=0 clxscore=1015 priorityscore=1501 malwarescore=0 impostorscore=0 suspectscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2102220064 Content-Transfer-Encoding: 8bit Content-Type: text/plain Introduce UnplugCpus() which maps each APIC ID being unplugged onto the hardware ID of the processor and informs PiSmmCpuDxeSmm of removal by calling EFI_SMM_CPU_SERVICE_PROTOCOL.RemoveProcessor(). With this change we handle the first phase of unplug where we collect the CPUs that need to be unplugged and mark them for removal in SMM data structures. Cc: Laszlo Ersek Cc: Jordan Justen Cc: Ard Biesheuvel Cc: Igor Mammedov Cc: Boris Ostrovsky Cc: Aaron Young Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3132 Signed-off-by: Ankur Arora --- Notes: Addresses these review comments from v6: (1) Drop the empty line in the comment block around UnplugCpus(). (2) Make the "did not find APIC ID" DEBUG_VERBOSE instead of DEBUG_INFO. (3) Un-Indented ("Outdented") the line following the comment "Ignore the unplug if APIC ID. (4) Remove the empty line between Status assignment and check. (5) Drop the "goto Fatal" logic and just return Status directly. (6) Handle both Plugging and Unplugging of CPUs in one go. (7) Also nest the EFI_STATUS check. OvmfPkg/CpuHotplugSmm/CpuHotplug.c | 84 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c b/OvmfPkg/CpuHotplugSmm/CpuHotplug.c index 3192bfea1f15..f07b5072749a 100644 --- a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c +++ b/OvmfPkg/CpuHotplugSmm/CpuHotplug.c @@ -188,6 +188,83 @@ RevokeNewSlot: } /** + Process to be hot-unplugged CPUs, per QemuCpuhpCollectApicIds(). + + For each such CPU, report the CPU to PiSmmCpuDxeSmm via + EFI_SMM_CPU_SERVICE_PROTOCOL. If the to be hot-unplugged CPU is + unknown, skip it silently. + + @param[in] ToUnplugApicIds The APIC IDs of the CPUs that are about to be + hot-unplugged. + + @param[in] ToUnplugCount The number of filled-in APIC IDs in + ToUnplugApicIds. + + @retval EFI_SUCCESS Known APIC IDs have been removed from SMM data + structures. + + @return Error codes propagated from + mMmCpuService->RemoveProcessor(). +**/ +STATIC +EFI_STATUS +UnplugCpus ( + IN APIC_ID *ToUnplugApicIds, + IN UINT32 ToUnplugCount + ) +{ + EFI_STATUS Status; + UINT32 ToUnplugIdx; + UINTN ProcessorNum; + + ToUnplugIdx = 0; + while (ToUnplugIdx < ToUnplugCount) { + APIC_ID RemoveApicId; + + RemoveApicId = ToUnplugApicIds[ToUnplugIdx]; + + // + // mCpuHotPlugData->ApicId maps ProcessorNum -> ApicId. Use it to find + // the ProcessorNum for the APIC ID to be removed. + // + for (ProcessorNum = 0; + ProcessorNum < mCpuHotPlugData->ArrayLength; + ProcessorNum++) { + if (mCpuHotPlugData->ApicId[ProcessorNum] == RemoveApicId) { + break; + } + } + + // + // Ignore the unplug if APIC ID not found + // + if (ProcessorNum == mCpuHotPlugData->ArrayLength) { + DEBUG ((DEBUG_VERBOSE, "%a: did not find APIC ID " FMT_APIC_ID + " to unplug\n", __FUNCTION__, RemoveApicId)); + ToUnplugIdx++; + continue; + } + + // + // Mark ProcessorNum for removal from SMM data structures + // + Status = mMmCpuService->RemoveProcessor (mMmCpuService, ProcessorNum); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: RemoveProcessor(" FMT_APIC_ID "): %r\n", + __FUNCTION__, RemoveApicId, Status)); + return Status; + } + + ToUnplugIdx++; + } + + // + // We've removed this set of APIC IDs from SMM data structures. + // + return EFI_SUCCESS; +} + +/** CPU Hotplug MMI handler function. This is a root MMI handler. @@ -309,6 +386,13 @@ CpuHotplugMmi ( } } + if (ToUnplugCount > 0) { + Status = UnplugCpus (mToUnplugApicIds, ToUnplugCount); + if (EFI_ERROR (Status)) { + goto Fatal; + } + } + // // We've handled this MMI. // -- 2.9.3