From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from aserp2130.oracle.com (aserp2130.oracle.com [141.146.126.79]) by mx.groups.io with SMTP id smtpd.web09.8844.1611643506063631436 for ; Mon, 25 Jan 2021 22:45:06 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=TnQbXZjg; spf=pass (domain: oracle.com, ip: 141.146.126.79, mailfrom: ankur.a.arora@oracle.com) Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 10Q6Z9xQ058326; Tue, 26 Jan 2021 06:45:01 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=L1gPodx8KoROTcPRXS118SD00ecs41MWalErPdya0ZY=; b=TnQbXZjg7JfJck63pE0u7lAqcMGnlVelWM+mkraSyHcIpfnkawWvKTy6EgEyrQ5AD6Rv cyUi/L0u0VTIV9qchwdWh+xY28YTPomnsEiRgY2DlHmELo0BTO72yVAkp9ltl/bz32jN VbVhiL5R9yyLAlsyeja8Cs9vZl1+Gt5cNh82J0qkN4aU4AbM72gNAhHJBrXX5yAbsDy3 v6XikEN5pygSusrp76NhkRHUSPTGTuxHj6r18QJlLN/OiABgygnOs/dy8Zl3j1qTZx+S 6x27AF8dthFQ6/cbOz5FcHtBrfKTVh/Y0SysrhMZa9cBxKPujnYJ76LiJHeUY3LifNmV TA== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2130.oracle.com with ESMTP id 3689aagu16-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 26 Jan 2021 06:45:01 +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 10Q6a689097113; Tue, 26 Jan 2021 06:45:00 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2177.outbound.protection.outlook.com [104.47.59.177]) by userp3030.oracle.com with ESMTP id 368wqw1qcn-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 26 Jan 2021 06:45:00 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iAmESYs36oaizAZTXCxENgYyZTMc7RtQ6SF8d232z8yr5MQ6zQz4lRKGISPXetp/k5c8gcftW32ddBVNyTA6sDR89z094HQNa+Ih5z0UEQ7wZSqaLiEZbz270VFE1Atj5HZlbTYF/zrtS2iL2vs6PNFoU8LWizrYgzNPXS/3+66xBaNf95dmrJfpXKtp+YNzZtyOFqhgfsV6ZK4HMq+3tjV3ud1IdKOvufxfZLNmIAwFYgO84SRNE+vyvCuzsGD5VXp0c7VDAgV0baAeNemjOi/mcPszO4X/LsGXpVv0QV3uLDQwBPR1xREKrcJyTZdX3MrMO4LHGTpr338+FJy5Xg== 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=L1gPodx8KoROTcPRXS118SD00ecs41MWalErPdya0ZY=; b=T8J5/cM1v7Od4euBX/WcAyabzmRQ7ST9opNWclXSl4UfxCYMnowg1MPiOBXrx4FrQXwvWq2XiXr+BO2Xjc/PPCRKZ2DVMXirPn5gbkUCDxuIccMslCCh+OpiTpkndm++C4ZQZ6dRj3QwthoTkSgJPrhJIMJhwN0qUWvFv1UGspI3cAoDqmpytdPY9f6miQI8xpLotjx7Vq2Kw9d+wnIgrkbqKjW/KaxoBkUznaf0/PNr4DevCNkdIAi2n40dPCEw0yhFtT0LLAiZTKFWYx5zWbC5x6i0ii3a5YEKCfiXq3e1rUmZAB2yHRrHaNurMDYn7LNwQCQVtTDP/JgkrUf8nw== 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=L1gPodx8KoROTcPRXS118SD00ecs41MWalErPdya0ZY=; b=WlqdNpuHBpJo1Q1SR3nlAn7FVVrIUYm/2mP2y1XLDAJjlbqGpSkbs4GRgihWYT72RCbtBfxUVENhfS8io4rtjKJXCdCcPyCOQOQG21OoWoJhqoA+bC/axk2EJQg0yN3fu0Wch/iConI34e23MM2ccWKnhlxOnnkbrHrI+SG/RpI= 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 CY4PR10MB1718.namprd10.prod.outlook.com (2603:10b6:910:9::17) by CY4PR1001MB2184.namprd10.prod.outlook.com (2603:10b6:910:45::37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.14; Tue, 26 Jan 2021 06:44:59 +0000 Received: from CY4PR10MB1718.namprd10.prod.outlook.com ([fe80::39dc:6ba7:9397:cb6]) by CY4PR10MB1718.namprd10.prod.outlook.com ([fe80::39dc:6ba7:9397:cb6%6]) with mapi id 15.20.3784.019; Tue, 26 Jan 2021 06:44:59 +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 v5 8/9] OvmfPkg/CpuHotplugSmm: add worker to do CPU ejection Date: Mon, 25 Jan 2021 22:44:39 -0800 Message-Id: <20210126064440.299596-9-ankur.a.arora@oracle.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210126064440.299596-1-ankur.a.arora@oracle.com> References: <20210126064440.299596-1-ankur.a.arora@oracle.com> X-Originating-IP: [70.36.60.91] X-ClientProxiedBy: MWHPR18CA0061.namprd18.prod.outlook.com (2603:10b6:300:39::23) To CY4PR10MB1718.namprd10.prod.outlook.com (2603:10b6:910:9::17) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (70.36.60.91) by MWHPR18CA0061.namprd18.prod.outlook.com (2603:10b6:300:39::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.12 via Frontend Transport; Tue, 26 Jan 2021 06:44:55 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8e282034-7316-467a-747d-08d8c1c5e452 X-MS-TrafficTypeDiagnostic: CY4PR1001MB2184: 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: wzIKhLbUKKROs7SL2KXIcHwWPUlQ58FClqVwr9FSVaIcBGH4YtS0cCzqICKKQq1VQ2ee+l8XUHL1nulHPp48x+Ylk9UIdC6TlgfGUGYc4HOIDGGrW99OlThrwsefmeXimyHzSt72m5YT7bbcm5+qDw4y+uhodfd8SIhD3xSSAE3PSTDH24ywNkzgTfmJ0t4E7ecqyhVpuicTnNZuqYgZQSIH4KOsWl3sKKvdvu3kZgSPTQosMA1can0tuq6GgP1kRX8DH5K0yV41E8k2zt+8iUZqPDPvWER8SF3UGQP8Bt36OMw5qLs3WbVGIeEWcU6e875xXD9TKnkk10TE82l4lSrg5hkizkxkhoSph9sasjzXqPprHrvVM/FrJ6r7ISPsUjMTDC6zmiH4LHBH/YMaBYnJPurKTnblmpYYO847I3jfvGrrawtLV4cNZPMKgex44UMCpIOc08HQESsJtwuj9rhOpexOlSkSqgcBh539n18K80cVmph0/2I5QE4byQxu3PpwfC0aguNiKczP0ggjqg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CY4PR10MB1718.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(366004)(396003)(39860400002)(376002)(346002)(136003)(69590400011)(6916009)(2616005)(4326008)(6512007)(52116002)(956004)(66556008)(6486002)(36756003)(186003)(6506007)(26005)(66476007)(6666004)(478600001)(8676002)(8936002)(83380400001)(966005)(1076003)(2906002)(86362001)(5660300002)(66946007)(103116003)(316002)(54906003)(16526019)(107886003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?u9s+y5TE87QrK/omzEb5BIImq//eiEGhPFJuqLJWkfW3CirV80XJ+oap6Yer?= =?us-ascii?Q?DP6Z/FP9iJeIHdU36lQgQKzZafFSzF4F3YQCvPrFwOdXeTCynU125NHjSRix?= =?us-ascii?Q?vX5Cf1g7WvfdXV7ke8FvfNUXX11cBb6B2K3gWljZbdpRUfAiO89//RQEbM1g?= =?us-ascii?Q?/36LE6ecOA3rkztBrKL5qULgS5yNfVp5fDV7eibZ9S0qCBGjzedGumKiyl1b?= =?us-ascii?Q?uukdq78MUR4XhsUXhffniXqhlHAsgjIuUXiBMn/hifBMzL3Nzulan3JJkgMu?= =?us-ascii?Q?MruQmBKdlSmMQudxUCDTSZ7K2zP00wshxtnARpH+p2J5bKT+KUnjK/k68DoH?= =?us-ascii?Q?q39OyT9NED8YPfLhMh4stLLdcVHS2ayPbcKNMQ1YYcHgJw4F2c6mAeSBulkW?= =?us-ascii?Q?Vhb3ARPFqcEmt6EfjbXejWZefTmPbZTQ8K3SQsI+gssskUAofnEHtg8afEFA?= =?us-ascii?Q?4dOOIbren760nLkqfS7UAAAyTvhYseQbIOgCgbC9cyanC8INmnayuZDiLj7e?= =?us-ascii?Q?ppTdyVbaEu4zaUsKznFARcqZo/jBsliuOt5HH06IDfNEeu71OkDJJX5xYYc7?= =?us-ascii?Q?E/P0xVtoFXqKwan61om9WB1Kqoznxu268R8k/T1IKZVmDdTTZGOpSaoCOoRx?= =?us-ascii?Q?nLsxKyfvLb88CvWyiH8aT9QDri1VvbDmkOurl3z5UIEe50AtO41XZHSt9nSX?= =?us-ascii?Q?bZNFS9Hwbu7+JNPQUMgwZRnFl0xJc9m9FcJhe2uRsYXJGGhi/5j+dIbYVI/X?= =?us-ascii?Q?u+DxYRtjzE68POoThTqbbke5zJ8H7G0yDkFrHqmblw161KenvDV2tGlGTZa3?= =?us-ascii?Q?XClrIpQLeXI27aqvoRG8c5tr64ZuaxPRz4D3pcLf3L58aZwycTcjea0P3e8l?= =?us-ascii?Q?8/xlof/hVdKUfIslCtluFPgM21+vYMUo91tJivdyHkKEc/kV8MSKTJwXceXV?= =?us-ascii?Q?1CZTo559OWV1giXqzZtnGeEghvG5TzCQuPZ/06pEbJDXvMg88yaCHJp/GZ3R?= =?us-ascii?Q?aKj8Ptry5wopaOfQ+iW58HJD6quDCjFbc/IYamhgtRV+soOVdEafr7vBTiXG?= =?us-ascii?Q?y1l90h9E?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8e282034-7316-467a-747d-08d8c1c5e452 X-MS-Exchange-CrossTenant-AuthSource: CY4PR10MB1718.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2021 06:44:55.9860 (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: XrVcoYnP3JGB7/Kg853XSidEq4XZuP9ibtOxOcLHqqsZKHfo2dBQoPh5CB69UV5nTVpwjYj2LrcjwStYlJGZgzHqK3Aj8dZ8IMngJGW2eBI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR1001MB2184 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9875 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 spamscore=0 phishscore=0 adultscore=0 mlxlogscore=999 malwarescore=0 suspectscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101260035 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9875 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 adultscore=0 lowpriorityscore=0 mlxlogscore=999 clxscore=1015 phishscore=0 bulkscore=0 spamscore=0 priorityscore=1501 mlxscore=0 suspectscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101260035 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain Designate a worker CPU (we use the one executing the root MMI handler), which will do the actual ejection via QEMU in CpuEject(). CpuEject(), on the worker CPU, ejects each marked CPU by first selecting its APIC ID and then sending the QEMU "eject" command. QEMU in-turn signals the remote VCPU thread which context-switches it out of the SMI. CpuEject(), on the CPU being ejected, spins around in its holding area until this final context-switch. This does mean that there is some CPU state that would ordinarily be restored (in SmiRendezvous() and in SmiEntry.nasm::CommonHandler), but will not be anymore. This unrestored state includes FPU state, CET enable, stuffing of RSB and the final RSM. Since the CPU state is destroyed by QEMU, this should be okay. 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=3D3132 Signed-off-by: Ankur Arora --- OvmfPkg/CpuHotplugSmm/CpuHotplug.c | 73 ++++++++++++++++++++++++++++++++++= ---- 1 file changed, 67 insertions(+), 6 deletions(-) diff --git a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c b/OvmfPkg/CpuHotplugSmm/Cpu= Hotplug.c index 99e6845a12d9..d4e27d641dc5 100644 --- a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c +++ b/OvmfPkg/CpuHotplugSmm/CpuHotplug.c @@ -186,10 +186,13 @@ Fatal: /**=0D CPU Hot-eject handler function.=0D =0D - If the executing CPU is not being ejected: NOP.=0D + If the executing CPU is neither a worker, nor being ejected: NOP.=0D If the executing CPU is being ejected: wait in a CpuDeadLoop()=0D until ejected.=0D =0D + If the executing CPU is a worker CPU: set QEMU Cpu status to eject=0D + for CPUs being ejected.=0D +=0D @param[in] ProcessorNum Index of executing CPU.=0D **/=0D VOID=0D @@ -209,6 +212,56 @@ CpuEject( return;=0D }=0D =0D + if (ApicId =3D=3D CPU_EJECT_WORKER) {=0D + UINT32 CpuIndex;=0D +=0D + for (CpuIndex =3D 0; CpuIndex < mCpuHotEjectData->ArrayLength; CpuInde= x++) {=0D + UINT64 RemoveApicId;=0D +=0D + RemoveApicId =3D mCpuHotEjectData->ApicIdMap[CpuIndex];=0D +=0D + if ((RemoveApicId !=3D CPU_EJECT_INVALID &&=0D + RemoveApicId !=3D CPU_EJECT_WORKER)) {=0D + //=0D + // This to-be-ejected-CPU has already received the BSP's SMI exit= =0D + // signal and, will execute SmmCpuFeaturesSmiRendezvousExit()=0D + // followed by this callback or is already waiting in the=0D + // CpuDeadLoop() below.=0D + //=0D + // Tell QEMU to context-switch it out.=0D + //=0D + QemuCpuhpWriteCpuSelector (mMmCpuIo, (APIC_ID) RemoveApicId);=0D + QemuCpuhpWriteCpuStatus (mMmCpuIo, QEMU_CPUHP_STAT_EJECTED);=0D +=0D + //=0D + // Compiler barrier to ensure the next store isn't reordered=0D + //=0D + MemoryFence();=0D +=0D + //=0D + // Clear the eject status for CpuIndex to ensure that an invalid=0D + // SMI later does not end up trying to eject it or a newly=0D + // hotplugged CpuIndex does not go into the dead loop.=0D + //=0D + mCpuHotEjectData->ApicIdMap[CpuIndex] =3D CPU_EJECT_INVALID;=0D +=0D + DEBUG ((DEBUG_INFO, "%a: Unplugged CPU %u -> " FMT_APIC_ID "\n",=0D + __FUNCTION__, CpuIndex, RemoveApicId));=0D + }=0D + }=0D +=0D + //=0D + // Clear our own worker status.=0D + //=0D + mCpuHotEjectData->ApicIdMap[ProcessorNum] =3D CPU_EJECT_INVALID;=0D +=0D + //=0D + // We are done until the next hot-unplug; clear the handler.=0D + //=0D + mCpuHotEjectData->Handler =3D NULL;=0D + return;=0D + }=0D +=0D //=0D // CPU(s) being unplugged get here from SmmCpuFeaturesSmiRendezvousExit(= )=0D // after having been cleared to exit the SMI by the monarch and thus hav= e=0D @@ -306,6 +359,19 @@ UnplugCpus( }=0D =0D if (EjectCount !=3D 0) {=0D + UINTN Worker;=0D +=0D + Status =3D mMmCpuService->WhoAmI(mMmCpuService, &Worker);=0D + ASSERT_EFI_ERROR(Status);=0D + //=0D + // UnplugCpus() is called via the root MMI handler and thus we are=0D + // executing in the BSP context.=0D + //=0D + // Mark ourselves as the worker CPU.=0D + //=0D + ASSERT (mCpuHotEjectData->ApicIdMap[Worker] =3D=3D CPU_EJECT_INVALID);= =0D + mCpuHotEjectData->ApicIdMap[Worker] =3D CPU_EJECT_WORKER;=0D +=0D //=0D // We have processors to be ejected; install the handler.=0D //=0D @@ -429,11 +495,6 @@ CpuHotplugMmi ( if (EFI_ERROR (Status)) {=0D goto Fatal;=0D }=0D - if (ToUnplugCount > 0) {=0D - DEBUG ((DEBUG_ERROR, "%a: hot-unplug is not supported yet\n",=0D - __FUNCTION__));=0D - goto Fatal;=0D - }=0D =0D if (PluggedCount > 0) {=0D Status =3D PlugCpus(mPluggedApicIds, PluggedCount);=0D --=20 2.9.3