From nobody Thu Nov 14 17:06:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+70876+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+70876+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=fail(p=none dis=none) header.from=oracle.com Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1611882127587305.14983033577926; Thu, 28 Jan 2021 17:02:07 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id ntWnYY1788612xggl8k2MIFa; Thu, 28 Jan 2021 17:02:07 -0800 X-Received: from aserp2120.oracle.com (aserp2120.oracle.com [141.146.126.78]) by mx.groups.io with SMTP id smtpd.web09.3211.1611882126714735838 for ; Thu, 28 Jan 2021 17:02:06 -0800 X-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 10T0gDlp065042; Fri, 29 Jan 2021 01:02:04 GMT X-Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2120.oracle.com with ESMTP id 368brkxsbf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 29 Jan 2021 01:02:03 +0000 X-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 10T0eGVF081743; Fri, 29 Jan 2021 01:00:03 GMT X-Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2172.outbound.protection.outlook.com [104.47.56.172]) by userp3030.oracle.com with ESMTP id 368wr13e5c-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 29 Jan 2021 01:00:02 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iBpJyE2cQ731ZWCWY29AyFPQJnKR3YDc6iknz1qA6sXolGUzSaeeEQGWSFerVyb7Fic+WhYYZFrNzYUKjwGsysbC55i2lLgerUSxPjrVnq41aI+L5u4v+cT3buYRX1eV5tTclwoFPRWdXKC75rXgDW+m7DxMXEAx6oF1Xdt8Djcv88Ui8ZVRvhyVtNDnqGkJqv6e2U3CRDXP6OptcIKtsotDqWZSAdr1y4T5bw+WxIU4GHMedv0biRl73kXHiIJB8H+GAqH+PyhgIYd10oz9Pwbf3saDpU38zFsO5OKpCuG0GkpQ4sZr4VPwpimn1LCddZKQyDLN0PKAc1PPHLiELg== 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=Guq00U15YcGAAy1mDO2Rk+JcBjl0zhlnNSefjcd/tks=; b=aQP6JBBhJi0AMX+g6JVJ1KyU+FHA7l/FDbGfQHBUNcQWfiK8x6sMloosLDKVZMwUJgOD5u9rbWsqbKzWOe/dX8ni7TOJ1KiU3aN0paScJz5roQYghB64NhZeCkbeu72xy/pvQDJKHktAZXA3U3fD6hV4v8Bl1ElTaKKlcRPA1TT2gDJwz28eLlnoqKy+oS5hTiHrbc+sP7lu+RihmzuaeEM7lbN+f1Cub16RzTQYaPl6HJnyOGM31hBm2uh60/3O51CfL/gxmKo8qMA5ZmXmB4PHeHfhjPMkwqG5SbKwoHWJsN4mHv19xw1tiGfoOemKfhDi2rPctFr973pHEf4EIA== 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 X-Received: from CY4PR10MB1718.namprd10.prod.outlook.com (2603:10b6:910:9::17) by CY4PR1001MB2246.namprd10.prod.outlook.com (2603:10b6:910:41::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.16; Fri, 29 Jan 2021 01:00:00 +0000 X-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.3805.019; Fri, 29 Jan 2021 01:00:00 +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: [edk2-devel] [PATCH v6 2/9] OvmfPkg/CpuHotplugSmm: collect hot-unplug events Date: Thu, 28 Jan 2021 16:59:43 -0800 Message-Id: <20210129005950.467638-3-ankur.a.arora@oracle.com> In-Reply-To: <20210129005950.467638-1-ankur.a.arora@oracle.com> References: <20210129005950.467638-1-ankur.a.arora@oracle.com> X-Originating-IP: [148.87.23.8] X-ClientProxiedBy: MWHPR1401CA0022.namprd14.prod.outlook.com (2603:10b6:301:4b::32) To CY4PR10MB1718.namprd10.prod.outlook.com (2603:10b6:910:9::17) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from prion.us.oracle.com (148.87.23.8) by MWHPR1401CA0022.namprd14.prod.outlook.com (2603:10b6:301:4b::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3805.17 via Frontend Transport; Fri, 29 Jan 2021 00:59:59 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 147cf1a0-c8a9-41b0-dfef-08d8c3f1340f X-MS-TrafficTypeDiagnostic: CY4PR1001MB2246: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 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xyUZiNLKrtED8BISM7D5F/nJ3?= =?us-ascii?Q?XPrEayXfSWWpkkH4g/WStQDnCMHQlZSc5e/cvLAmhOwwSQsV4yiyeO6jcwk5?= =?us-ascii?Q?aZcNqnzFrW0g8k3TCJVunLovJvqiXl4/uzGm1AsJiyXrW7C4OK7LC88omMyk?= =?us-ascii?Q?XE4ksF1705hnVQxTUFK9m1YC6p7iOTA7rxNfX/a9n4As2i27PCDfdhY8lur1?= =?us-ascii?Q?gB7Z+osUqQmK+IX9GrcbL6QJV/Pssi8pONbNOHlU4ceGeI4+UR+dSGu1J/nC?= =?us-ascii?Q?0u8TZKP/UmbmSpKVULpqrngDluKPyl+6sRibNspSBsKqJpGFa2Ek3ducqq9T?= =?us-ascii?Q?5PSD7kRPN4g1zWNNI0bOho3wjRi6oktH0YPzKoyko7wcJ4CBg5BGlglyfEdu?= =?us-ascii?Q?0GOR1dMIMm9i7LCUGyvu8L7FVl1jFECeArxunHNDe3s+42jry3Di5euvv05N?= =?us-ascii?Q?nFb2rl/1LBsUHIOs3r5Aq3RLa3iDnuD8ASXcCqtWxbofHQzblwq942y2whiD?= =?us-ascii?Q?U37IzeZNSYkEZdRtYkAKQquAe9qTSAjSCC9V7idlapJXWimeTxYIqkZxay7e?= =?us-ascii?Q?zpSN+87VNOsHPV9fO+Uz43FWgUK+w62NuXqV+y2WTkYXwb1X1JQ2v+gusf5k?= =?us-ascii?Q?OQs6MyBa9uXc/uabhWgSoB+9cRfXglnZHibsAe438cP4yErP8ZEYiEEdXN1z?= =?us-ascii?Q?2XLYkpThh1N5ZMmUgbdQPwOh4+geppfPJZtubMeLGFDWp9th0zf/t0TbP/Up?= =?us-ascii?Q?4R2k6NsC?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 147cf1a0-c8a9-41b0-dfef-08d8c3f1340f X-MS-Exchange-CrossTenant-AuthSource: CY4PR10MB1718.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jan 2021 01:00:00.4583 (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: F7Ek/8iKEJY/Fxlze3OKy/feHWWIYLc8gXn26CmzTf8Q3HQWGyOUslCiQlt8D8VCymoE861X/NbThs626TCGpuAkbVC9jg9pKz6tjGBsCEo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR1001MB2246 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ankur.a.arora@oracle.com X-Gm-Message-State: LbIs4DPnnmvSn2n1JQlezhj8x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1611882127; bh=iINmjKMImoXOMlIxmoLGWarJzfwRYKPzvFbvGHmCoPk=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=HM31M1/QlBrihiDh+EeNQ9EqAVwFQbUPprij7RY7s7DdtiO/GWKRKTqmD0Kpo8PR4d0 BXiTm/k+1MluZ5RFC6Ytz+XE8I3xhN6E4o+NlfvHCvCU2+83f73EVdECmseJppTVJsU9t eg8WEZ0ZjBp8z2Sn0gpt4P1/kddA4sEsqBE= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" 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 --- Notes: I'm treating events (insert=3D1, fw_remove=3D1) below as invalid (return EFI_PROTOCOL_ERROR, which ends up as an assert), but I'm not sure that is correct: =20 if ((CpuStatus & QEMU_CPUHP_STAT_INSERT) !=3D 0) { // // The "insert" event guarantees the "enabled" status; plus it e= xcludes - // the "remove" event. + // the "fw_remove" event. // if ((CpuStatus & QEMU_CPUHP_STAT_ENABLED) =3D=3D 0 || - (CpuStatus & QEMU_CPUHP_STAT_REMOVE) !=3D 0) { + (CpuStatus & QEMU_CPUHP_STAT_FW_REMOVE) !=3D 0) { DEBUG ((DEBUG_ERROR, "%a: CurrentSelector=3D%u CpuStatus=3D0x%= x: " "inconsistent CPU status\n", __FUNCTION__, CurrentSelector, CpuStatus)); =20 QEMU's handling in cpu_hotplug_rd() can return both of these: =20 cpu_hotplug_rd() { ... case ACPI_CPU_FLAGS_OFFSET_RW: /* pack and return is_* fields */ val |=3D cdev->cpu ? 1 : 0; val |=3D cdev->is_inserting ? 2 : 0; val |=3D cdev->is_removing ? 4 : 0; val |=3D cdev->fw_remove ? 16 : 0; ... } and I don't see any code that treats is_inserting and is_removing as exclusive. One specific case where this looks it might be a problem is if the user unplugs a CPU and right after that plugs it. =20 As part of the unplug handling, the ACPI AML would, in the scan loop, asynchronously trigger the notify, which would do the OS unplug, set "fw_remove" and then call the SMI_CMD. =20 The subsequent plug could then come and set the "insert" bit. =20 Assuming what I'm describing could happen, I'm not sure what's the right handling: QEMU could treat these bits as exclusive and then OVMF could justifiably treat it as a protocol error? OvmfPkg/Include/IndustryStandard/QemuCpuHotplug.h | 2 ++ OvmfPkg/CpuHotplugSmm/QemuCpuhp.c | 29 +++++++++++++++++++= ---- 2 files changed, 26 insertions(+), 5 deletions(-) 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 #define QEMU_CPUHP_STAT_INSERT BIT1 #define QEMU_CPUHP_STAT_REMOVE BIT2 +#define QEMU_CPUHP_STAT_EJECTED BIT3 +#define QEMU_CPUHP_STAT_FW_REMOVE BIT4 =20 #define QEMU_CPUHP_RW_CMD_DATA 0x8 =20 diff --git a/OvmfPkg/CpuHotplugSmm/QemuCpuhp.c b/OvmfPkg/CpuHotplugSmm/Qemu= Cpuhp.c index 8d4a6693c8d6..f871e50c377b 100644 --- a/OvmfPkg/CpuHotplugSmm/QemuCpuhp.c +++ b/OvmfPkg/CpuHotplugSmm/QemuCpuhp.c @@ -245,10 +245,10 @@ QemuCpuhpCollectApicIds ( if ((CpuStatus & QEMU_CPUHP_STAT_INSERT) !=3D 0) { // // The "insert" event guarantees the "enabled" status; plus it exclu= des - // the "remove" event. + // the "fw_remove" event. // if ((CpuStatus & QEMU_CPUHP_STAT_ENABLED) =3D=3D 0 || - (CpuStatus & QEMU_CPUHP_STAT_REMOVE) !=3D 0) { + (CpuStatus & QEMU_CPUHP_STAT_FW_REMOVE) !=3D 0) { DEBUG ((DEBUG_ERROR, "%a: CurrentSelector=3D%u CpuStatus=3D0x%x: " "inconsistent CPU status\n", __FUNCTION__, CurrentSelector, CpuStatus)); @@ -260,12 +260,31 @@ QemuCpuhpCollectApicIds ( =20 ExtendIds =3D PluggedApicIds; ExtendCount =3D PluggedCount; - } else if ((CpuStatus & QEMU_CPUHP_STAT_REMOVE) !=3D 0) { - DEBUG ((DEBUG_VERBOSE, "%a: CurrentSelector=3D%u: remove\n", __FUNCT= ION__, - CurrentSelector)); + } 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", + __FUNCTION__, CurrentSelector)); =20 ExtendIds =3D ToUnplugApicIds; ExtendCount =3D ToUnplugCount; + } 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 { DEBUG ((DEBUG_VERBOSE, "%a: CurrentSelector=3D%u: no event\n", __FUNCTION__, CurrentSelector)); --=20 2.9.3 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#70876): https://edk2.groups.io/g/devel/message/70876 Mute This Topic: https://groups.io/mt/80199952/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-