From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from userp2130.oracle.com (userp2130.oracle.com [156.151.31.86]) by mx.groups.io with SMTP id smtpd.web12.6144.1613725506144600680 for ; Fri, 19 Feb 2021 01:05:06 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=ABzPfWjw; spf=pass (domain: oracle.com, ip: 156.151.31.86, mailfrom: ankur.a.arora@oracle.com) Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 11J952fx093498; Fri, 19 Feb 2021 09:05:02 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=ABzPfWjwYQTpiOAj/Cgz+uOvX8zui8n4a7aOzKeGvLWJWhM8yVB5P+riEoI2DKR/VVXU sZvViU34jNnxi5MsG2RhFQ9mCWMab6aeor8oEjhEmRETFf1I9zMtfuhunVfZU2g22SEO PO8zqm8oIYfCMO12zXVbKskL/hsMKZI/7xXo4YW1eswv9jnHjWKTwaa8wNwUcWhxuJvg eMUbvh0Zo8L3VncpLa78ILK0dzdsRbTOu9DDxamGzH0kb88tyGZxLt4Y04mhDkxOt8y0 iTg2wlTgUIctZlbw8kuuBXQ7y5xA07CxZZQxO8yx/QhDyTiOtMFPgO5nCqgm7Qnn1ljd iA== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2130.oracle.com with ESMTP id 36p66r8rdt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Feb 2021 09:05:02 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 11J8uJSF131491; Fri, 19 Feb 2021 09:05:01 GMT Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2177.outbound.protection.outlook.com [104.47.55.177]) by aserp3020.oracle.com with ESMTP id 36prp2pa12-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Feb 2021 09:05:01 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lpOMPKX0vBjLJ3Pl4iW1WexB0Rjv9zT343TY0ZnNarHEAz+4lYNScN/33AtYbQFH0Fb6iiYQlPDPMu3e9u2Dqmk7i2eee+l3SohUn9xHzefLuSZ6i2wD2RhMX7KbgDcBIZ0g1+AO20wK+oPugIXMNAwkm7EiN7xKhbeWgTB37XDEQJbPGnjWudgIgw3AD1nQhsa40ykSj1WP48XptR0gXQE9kECFzhqI0m0hdPxYNJNZLHbAbWxz+YDoKArKDdSlt5qAgjRk5oA4oNEWiUV8nYo4MfmqABojjsF6iYvlm+jbqkACEVkxLHS5qBctkkkF15UiHVTC9760r+m1zHZ/HA== 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=Of9fup8BsWxD7w/NjhT3EDh9PW56H2cHaS6eTG6EHLCtoyi3h5XguGMLhAykyav8bhLWLIyOSiIRs7gW5lwZ9DwLP5mp+1JeLoXWgxxoLkG/TP6twJwRdLfrSvDjX3nMMEcZdLyi+YLnearcEz3A4GfIvOniwMEAcgoZKUwE8RWYxY+j0FaZ7PWiXpUMa0hVp7clq/CUBB1W6uKDHsZT+lfxnCxyZFEAX7k40DuBgQ9mTB0qtn68YPumFHvYa2yd5/2E1wUGhAQgCWWCfTYG+S6afL/2i4pjzVsdmBNGqgcXhSbk6FoI7pbq8bJ4Id399v8adwtCdI/T9nGuy0j93A== 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=YsPTKmBCCtmODaIW4uh0cZ3KMZcHxfgmB2UfW5H442WBbPeJmriEfZ0ML52pT5sTyYa2Lm7zgfSRN0KVq9fAHGe7ZlBx3sC+jnHw3RqqezvyIZY54V1WiHV3uhFOGyMlHLMEoJnvM+3VZaxJFAaiXTa+LFbyQc40Kh+F9q5cPiw= 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 BYAPR10MB3605.namprd10.prod.outlook.com (2603:10b6:a03:129::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3846.27; Fri, 19 Feb 2021 09:04:58 +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.029; Fri, 19 Feb 2021 09:04:58 +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 v7 04/10] OvmfPkg/CpuHotplugSmm: introduce UnplugCpus() Date: Fri, 19 Feb 2021 01:04:38 -0800 Message-Id: <20210219090444.1332380-5-ankur.a.arora@oracle.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210219090444.1332380-1-ankur.a.arora@oracle.com> References: <20210219090444.1332380-1-ankur.a.arora@oracle.com> X-Originating-IP: [148.87.23.5] X-ClientProxiedBy: MWHPR13CA0004.namprd13.prod.outlook.com (2603:10b6:300:16::14) 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.5) by MWHPR13CA0004.namprd13.prod.outlook.com (2603:10b6:300:16::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3890.8 via Frontend Transport; Fri, 19 Feb 2021 09:04:57 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a0bb102f-2608-405c-5544-08d8d4b56eac X-MS-TrafficTypeDiagnostic: BYAPR10MB3605: 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: rEuZ/QS5C+KDLBR7w8W97OTqsll67iMMFkZVUoBWbteSaFKifdva28uxW6fGvQb76V8lfNoutX0uQYmp1Mqe6C08mq1MqURU/owwZA75K8tE3FRMoJBsp+Gqytbag9tXZEGavH4Rybh1wUfV875z4zguGV0hM7kNCquLVEVP1sDVqaPZMoK/tCCAgQLWmlPWiOAYOYO/CrQU7G672uFkqTW5rKMtW0/JQXOZ3coWp60fHp/5TuZDxaImwYI0rA8Zisqu6j7G0f+Tp/I2QSvNVZQBQzL6DoNOukY6358IPManWOH8TCkwvXsCClzrkFN70v0OzljE72Qnr5Jp/BcHi/ziEkn2W2jTM1kY2Vv9vKaK83uIQKiIJHlYZJ14x4ybotDpXw9cACEe0j1BA3e1A60Yz+yWdHvxLVMWKAuP6Vn+GbEDK75+RaEOKXzQ9fjA/v9vrlDjgPHCHGF+ilevlokSaBm7+7OVo1YQPID/J+AeGK4eMrrOiDwQU3z/IYW0x0sG9oFqvlrANmRwrXbEg3Mo8QD6CQCvSxNY0d4LV/+Fv/vpOWIYK0giWLlNsdL2fiXeAwdSw149f22VjAaVHd/OEJ+jtBaHsGoBUTSztWk= 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:(366004)(376002)(39860400002)(346002)(396003)(136003)(83380400001)(7696005)(66946007)(2616005)(66556008)(6486002)(36756003)(86362001)(316002)(6666004)(54906003)(966005)(8676002)(66476007)(52116002)(478600001)(956004)(4326008)(5660300002)(6916009)(8936002)(2906002)(107886003)(1076003)(186003)(103116003)(26005)(16526019);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?sZY1v2xFOC1bk+H21LV0YWFR3U5BJWS5aFLIk7QOORdG3YBGSA42sFqo8yda?= =?us-ascii?Q?lEzkHjEQlwv3E6sK8NmXw63NxntQRnIm7HKl7WSmDeZWqtpENcXUZUSGHODn?= =?us-ascii?Q?x0R/RxPf9ZBIgta61plg4pIZvLP8+ju2eAzd8kpDkbZYJiTfeefXT4kRTsKy?= =?us-ascii?Q?EcMN+WnwR9h/P+38V1ItkYXvNRELqi6vPC9pTkB6OSuxxuvw7xkpJZ8cxjf0?= =?us-ascii?Q?k9UDdBfyr+uCzaKFZpuoMd7g2nvrHDUREIEKlQhX4kOTRUC6xfxH+0GpdEwB?= =?us-ascii?Q?WoBN/bWUbIGrxuswVhSPN6+QZzdMdu1KJFykAiyRw3xrT3VYko7mEPcQMHtJ?= =?us-ascii?Q?dBkPYl5zlzu3fCrE4SMM6GqQqdSneeplmeoBJHJ5HV4NE97nH/RY/iVW2JS4?= =?us-ascii?Q?WAE7Up9ImHRo0N94T938Xg4heZYX4kNON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-ascii?Q?BVuixpy6kQErVog8sBJPeJvA?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: a0bb102f-2608-405c-5544-08d8d4b56eac X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB4605.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Feb 2021 09:04:58.5943 (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: kAn1JVcEdPeXhMR94wcjNylE+a32wwAiruKiK6sG2ZyyLyB6vO0gQISwnB26dUuiBcnU2xIuN0pN74keYnm3tlgQpc/pv00RFQe1bJ9rNik= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB3605 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9899 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 mlxlogscore=999 bulkscore=0 suspectscore=0 spamscore=0 malwarescore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2102190070 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9899 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 lowpriorityscore=0 suspectscore=0 impostorscore=0 priorityscore=1501 clxscore=1015 spamscore=0 mlxscore=0 phishscore=0 malwarescore=0 bulkscore=0 adultscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2102190071 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