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.web12.1017.1610696867527439848 for ; Thu, 14 Jan 2021 23:47:47 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=WolTtg8/; 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 10F7hmoT185461; Fri, 15 Jan 2021 07:47:44 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=WolTtg8/s7TBmwPRlg2EyuRz/P+BGqnOf/IkUW+ee7GPp592+P7nUwQi2y9dnCJLaQWX 8CGA0zcAl64MHD8ihbugEgScgrAz1GmAy3RWcKSiWEyrvkVBpuM+9CrwS1xxZtDswLdS CudDWyJaRulhPFEs6bL/RyJEHmBpFoCixKwGL3JiAKQBKnhVazq7cL0gsv6wm2CS0M1L jdVH4kuyY4IQuwhftgFzMGWbRxyyytBg2Otshn/R/TqmZUdC1dkQLYm7Wevfu/MRi4bv eGaNDFvz7hewf2XL1wZKmgCgIitKULDfTHAmXFpATDa/qFRX09uyQAQ+aXsZwHqPuvce yA== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2130.oracle.com with ESMTP id 360kg23rja-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 15 Jan 2021 07:47:44 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 10F7eJcT043493; Fri, 15 Jan 2021 07:45:44 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3030.oracle.com with ESMTP id 360kf33v05-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 15 Jan 2021 07:45:43 +0000 Received: from abhmp0019.oracle.com (abhmp0019.oracle.com [141.146.116.25]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 10F7jgeG013337; Fri, 15 Jan 2021 07:45:42 GMT Received: from localhost.localdomain (/70.36.60.91) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 14 Jan 2021 23:45:41 -0800 From: "Ankur Arora" To: devel@edk2.groups.io Cc: imammedo@redhat.com, lersek@redhat.com, Ankur Arora , Jordan Justen , Ard Biesheuvel , Boris Ostrovsky , Aaron Young Subject: [PATCH v3 02/10] OvmfPkg/CpuHotplugSmm: collect hot-unplug events Date: Thu, 14 Jan 2021 23:45:25 -0800 Message-Id: <20210115074533.277448-3-ankur.a.arora@oracle.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20210115074533.277448-1-ankur.a.arora@oracle.com> References: <20210115074533.277448-1-ankur.a.arora@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9864 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 malwarescore=0 suspectscore=0 adultscore=0 spamscore=0 mlxlogscore=999 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101150044 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9864 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 suspectscore=0 clxscore=1015 impostorscore=0 spamscore=0 priorityscore=1501 mlxscore=0 phishscore=0 mlxlogscore=999 bulkscore=0 adultscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101150044 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