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.web08.2230.1610049450451219305 for ; Thu, 07 Jan 2021 11:57:30 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=CeyvnCl/; 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 107JtQ5n013632; Thu, 7 Jan 2021 19:57:27 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=+wVCSFUq7HGMY+oxD+QAKSWCqrbLZBzJIie9pmjZH18=; b=CeyvnCl/r8bE0NA2ADT4HdFtli6s8tRWr2EEAFr2tvFwVvevyg9mXBb6Jq3jSAIniGtN AR5Z7kOIE0L4aR5KX5ptWSLPEn/jnPeRLo2wCbEukkbIzf98cc5vaS//iVeg6SVNufK4 lIyC8obgCW8EFxTziBOqlVTIFdB+93XHShY6YcIH54GBghq02h/NUVCX7zoZx5rZ1pna Q+K6m+0CKGQZPpskYszvVgh+tz/I4tLuGPA2vvTAcS4G2AfZUXMRErLrNT/bQQG7v8Nw HTOVbL96+oxEqvZXVXzGAP+6YBVnbG7HTCTwX3XeZ0dJeqOTnnWFmh6xhhskwmF/BTXT 2w== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2120.oracle.com with ESMTP id 35wepme2tp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 07 Jan 2021 19:57:27 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 107JacP9136060; Thu, 7 Jan 2021 19:55:26 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3020.oracle.com with ESMTP id 35w3qu6cqy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Jan 2021 19:55:26 +0000 Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 107JtPpI021867; Thu, 7 Jan 2021 19:55:25 GMT Received: from localhost.localdomain (/70.36.60.91) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 07 Jan 2021 11:55:24 -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 v2 02/10] OvmfPkg/CpuHotplugSmm: handle Hot-unplug events Date: Thu, 7 Jan 2021 11:55:07 -0800 Message-Id: <20210107195515.106158-3-ankur.a.arora@oracle.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20210107195515.106158-1-ankur.a.arora@oracle.com> References: <20210107195515.106158-1-ankur.a.arora@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9857 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 malwarescore=0 mlxscore=0 spamscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101070114 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9857 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 bulkscore=0 spamscore=0 impostorscore=0 phishscore=0 lowpriorityscore=0 suspectscore=0 priorityscore=1501 mlxscore=0 malwarescore=0 clxscore=1015 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101070115 Content-Transfer-Encoding: quoted-printable Process fw_remove events in QemuCpuhpCollectApicIds() and collect corresponding APIC IDs for CPUs that are being hot-unplugged. Additionally we now ignore CPUs which have only 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@redhat= .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..2dd783ebf42e 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 //=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 //=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) {=0D 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) {=0D + //=0D + // "fw_remove" event guarantees "enabled".=0D + //=0D + if ((CpuStatus & QEMU_CPUHP_STAT_ENABLED) =3D=3D 0) {=0D + DEBUG ((DEBUG_ERROR, "%a: CurrentSelector=3D%u CpuStatus=3D0x%x: "= =0D + "inconsistent CPU status\n", __FUNCTION__, CurrentSelector,=0D + CpuStatus));=0D + return EFI_PROTOCOL_ERROR;=0D + }=0D +=0D + DEBUG ((DEBUG_VERBOSE, "%a: CurrentSelector=3D%u: fw_remove\n", __FU= NCTION__,=0D CurrentSelector));=0D =0D ExtendIds =3D ToUnplugApicIds;=0D ExtendCount =3D ToUnplugCount;=0D + } else if ((CpuStatus & QEMU_CPUHP_STAT_REMOVE) !=3D 0) {=0D + //=0D + // Let the OSPM deal with the "remove" event.=0D + //=0D + DEBUG ((DEBUG_INFO, "%a: CurrentSelector=3D%u: remove (ignored)\n", = __FUNCTION__,=0D + CurrentSelector));=0D +=0D + CurrentSelector++;=0D + continue;=0D } 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);=0D DEBUG ((DEBUG_VERBOSE, "%a: ApicId=3D" FMT_APIC_ID "\n", __FUNCTION__,= =0D - NewApicId));=0D - ExtendIds[(*ExtendCount)++] =3D NewApicId;=0D + OpApicId, ExtendCount));=0D + ExtendIds[(*ExtendCount)++] =3D OpApicId;=0D =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..692e3072598c 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=0D +#define QEMU_CPUHP_STAT_FW_REMOVE BIT4=0D =0D #define QEMU_CPUHP_RW_CMD_DATA 0x8=0D =0D --=20 2.9.3