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.web11.30105.1610951708771631244 for ; Sun, 17 Jan 2021 22:35:08 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=FYUeV4It; 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 10I6Y78X093263; Mon, 18 Jan 2021 06:35:05 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 : mime-version : content-transfer-encoding; s=corp-2020-01-29; bh=e3Ti4CtUs1Cl6NkjPGCnu+c17u/xyEcLp/6bAXjYh70=; b=FYUeV4ItfUDFkQd86bq+XakzuNn/HmG9eJ7WTLEmUEHlpzS3w5hrcZYrwt/bH6Eo8C0E O1Vwl2WwbWc5zkIVcwogG+M8KV8RwROgHxP44aMZwhHsfX8+hIYlZkFDk0rXkO8dGDIR NJEw2JIEDQXVJVpT1btdCaBZXt22D0VmC8PqFpaJpdTRhxKu1YM/n/0YxLJ4tja8QSWA uKqaUhPrviWBxVwWLdSLGYUVve84LF+ZOvBHtCdLx1QBkn3HdjHq0wIrIKXj6pQYKlZR pMHlEH1DyogaotV77l5ccrowEYjHoSG4rX3bOc2w+UGDm5pLotM6GBqhLWbB+oNJBMF9 zw== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2120.oracle.com with ESMTP id 363r3kkm58-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 18 Jan 2021 06:35:04 +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 10I6VMo1051575; Mon, 18 Jan 2021 06:35:04 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3030.oracle.com with ESMTP id 364a2uj8nj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 18 Jan 2021 06:35:04 +0000 Received: from abhmp0016.oracle.com (abhmp0016.oracle.com [141.146.116.22]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 10I6Z2eF001643; Mon, 18 Jan 2021 06:35:02 GMT Received: from prion.us.oracle.com (/10.159.226.191) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sun, 17 Jan 2021 22:35:02 -0800 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 v4 2/9] OvmfPkg/CpuHotplugSmm: collect hot-unplug events Date: Sun, 17 Jan 2021 22:34:50 -0800 Message-Id: <20210118063457.358581-3-ankur.a.arora@oracle.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20210118063457.358581-1-ankur.a.arora@oracle.com> References: <20210118063457.358581-1-ankur.a.arora@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9867 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxscore=0 suspectscore=0 phishscore=0 mlxlogscore=999 bulkscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101180038 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9867 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 priorityscore=1501 mlxscore=0 malwarescore=0 phishscore=0 suspectscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101180038 Content-Transfer-Encoding: quoted-printable Process fw_remove events in QemuCpuhpCollectApicIds() and collect corresponding APIC IDs for CPUs that are being hot-unplugged. In addition, we now ignore CPUs which only have remove set. These CPUs haven't been processed by OSPM yet. This is based on the QEMU hot-unplug protocol documented here: https://lore.kernel.org/qemu-devel/20201204170939.1815522-3-imammedo@redh= at.com/ Also define QEMU_CPUHP_STAT_EJECTED while we are at it. 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/QemuCpuhp.c | 35 +++++++++++++++++--= ---- OvmfPkg/Include/IndustryStandard/QemuCpuHotplug.h | 2 ++ 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/OvmfPkg/CpuHotplugSmm/QemuCpuhp.c b/OvmfPkg/CpuHotplugSmm/Qemu= Cpuhp.c index 8d4a6693c8d6..16ecf8cc433e 100644 --- a/OvmfPkg/CpuHotplugSmm/QemuCpuhp.c +++ b/OvmfPkg/CpuHotplugSmm/QemuCpuhp.c @@ -205,7 +205,7 @@ QemuCpuhpCollectApicIds ( UINT8 CpuStatus;=0D APIC_ID *ExtendIds;=0D UINT32 *ExtendCount;=0D - APIC_ID NewApicId;=0D + APIC_ID OpApicId; =0D //=0D // Write CurrentSelector (which is valid) to the CPU selector register= .=0D @@ -245,10 +245,10 @@ QemuCpuhpCollectApicIds ( if ((CpuStatus & QEMU_CPUHP_STAT_INSERT) !=3D 0) {=0D //=0D // The "insert" event guarantees the "enabled" status; plus it exclu= des=0D - // the "remove" event.=0D + // the "fw_remove" event. //=0D if ((CpuStatus & QEMU_CPUHP_STAT_ENABLED) =3D=3D 0 ||=0D - (CpuStatus & QEMU_CPUHP_STAT_REMOVE) !=3D 0) {=0D + (CpuStatus & QEMU_CPUHP_STAT_FW_REMOVE) !=3D 0) { DEBUG ((DEBUG_ERROR, "%a: CurrentSelector=3D%u CpuStatus=3D0x%x: "= =0D "inconsistent CPU status\n", __FUNCTION__, CurrentSelector,=0D CpuStatus));=0D @@ -260,12 +260,31 @@ QemuCpuhpCollectApicIds ( =0D ExtendIds =3D PluggedApicIds;=0D ExtendCount =3D PluggedCount;=0D - } else if ((CpuStatus & QEMU_CPUHP_STAT_REMOVE) !=3D 0) {=0D - DEBUG ((DEBUG_VERBOSE, "%a: CurrentSelector=3D%u: remove\n", __FUNCT= ION__,=0D + } else if ((CpuStatus & QEMU_CPUHP_STAT_FW_REMOVE) !=3D 0) { + // + // "fw_remove" event guarantees "enabled". + // + if ((CpuStatus & QEMU_CPUHP_STAT_ENABLED) =3D=3D 0) { + DEBUG ((DEBUG_ERROR, "%a: CurrentSelector=3D%u CpuStatus=3D0x%x: " + "inconsistent CPU status\n", __FUNCTION__, CurrentSelector, + CpuStatus)); + return EFI_PROTOCOL_ERROR; + } + + DEBUG ((DEBUG_VERBOSE, "%a: CurrentSelector=3D%u: fw_remove\n", __FU= NCTION__, CurrentSelector));=0D =0D ExtendIds =3D ToUnplugApicIds;=0D ExtendCount =3D ToUnplugCount;=0D + } else if ((CpuStatus & QEMU_CPUHP_STAT_REMOVE) !=3D 0) { + // + // Let the OSPM deal with the "remove" event. + // + DEBUG ((DEBUG_INFO, "%a: CurrentSelector=3D%u: remove (ignored)\n", = __FUNCTION__, + CurrentSelector)); + + CurrentSelector++; + continue; } else {=0D DEBUG ((DEBUG_VERBOSE, "%a: CurrentSelector=3D%u: no event\n",=0D __FUNCTION__, CurrentSelector));=0D @@ -281,10 +300,10 @@ QemuCpuhpCollectApicIds ( return EFI_BUFFER_TOO_SMALL;=0D }=0D QemuCpuhpWriteCommand (MmCpuIo, QEMU_CPUHP_CMD_GET_ARCH_ID);=0D - NewApicId =3D QemuCpuhpReadCommandData (MmCpuIo);=0D + OpApicId =3D QemuCpuhpReadCommandData (MmCpuIo); DEBUG ((DEBUG_VERBOSE, "%a: ApicId=3D" FMT_APIC_ID "\n", __FUNCTION__,= =0D - NewApicId));=0D - ExtendIds[(*ExtendCount)++] =3D NewApicId;=0D + OpApicId, ExtendCount)); + ExtendIds[(*ExtendCount)++] =3D OpApicId; =0D //=0D // We've processed the CPU with (known) pending events, but we must ne= ver=0D diff --git a/OvmfPkg/Include/IndustryStandard/QemuCpuHotplug.h b/OvmfPkg/In= clude/IndustryStandard/QemuCpuHotplug.h index a34a6d3fae61..bcae60f77ba6 100644 --- a/OvmfPkg/Include/IndustryStandard/QemuCpuHotplug.h +++ b/OvmfPkg/Include/IndustryStandard/QemuCpuHotplug.h @@ -34,6 +34,8 @@ #define QEMU_CPUHP_STAT_ENABLED BIT0=0D #define QEMU_CPUHP_STAT_INSERT BIT1=0D #define QEMU_CPUHP_STAT_REMOVE BIT2=0D +#define QEMU_CPUHP_STAT_EJECTED BIT3 +#define QEMU_CPUHP_STAT_FW_REMOVE BIT4 =0D #define QEMU_CPUHP_RW_CMD_DATA 0x8=0D =0D --=20 2.9.3