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.web10.4847.1615530434239456035 for ; Thu, 11 Mar 2021 22:27:14 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=lOU3l7DD; 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 12C6APDJ139263; Fri, 12 Mar 2021 06:27:10 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=IyGh2hGyPNEI+2m0OrCnDZEcNOlJaF8tmhqHfhD22sw=; b=lOU3l7DDn0JPVIk5oYrhoES3dHczC9aWNXS2IrUgGDcetNYmbfXp35y4s779HTPRwDxU jxBa14P0KQsbxBt/K1RO7lkFUwwODTEvkNcRbrz/o6IpPrf1t8kVfoJMtKDUe35pHNPf NNfWZJwacDgQ/mVNh4sJ+aBwbV5/EiLitAKhN1HJJGPknEEmbDM5Maz63lTOevK3FRVH gEvwUA44mOewqehfISYcqpuotbd8gWsH/VDLz+ydpGpkSXqcB/ATlRafEz1yMJ4gDtFo lBM1tg1eF4N9sG8WmRH9Ioh5pwEPRs7U3t825fSNJ+g9bNTUUNlMJmMhIGvyI8ohC1HQ 8g== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2130.oracle.com with ESMTP id 373y8c14as-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Mar 2021 06:27:10 +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 12C6PY05079482; Fri, 12 Mar 2021 06:27:09 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam07lp2040.outbound.protection.outlook.com [104.47.56.40]) by userp3030.oracle.com with ESMTP id 374kp243k0-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Mar 2021 06:27:09 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eYKDeq+Lbg9RKU9gXN6rNQHJFIgNorFgkFxkbdFoQKRNT4F55abpc71uvVdUUGPcyhVM514c95LNQG8LJg025MR7unW8ilr4iGGUpJ36DUmPCAVBBcwb+9U/+KowmUIw5qP2DZPBE6OyLg4DVQzs/V+Ku8BiFcZDZvXJhEY4JYwhDz/XqrZE/88NLW9H+7ow0z4x6R/DL7GmXRBhUEKP9WDuKx40y5UegfAulTIO9fR5tDHfgBl2qDk3lo9KV0IOt/n5Ve68ew8mgGt2KkYGgcTKY2WlrjCH15kUWzoVDGSwzFaJEM+/2ys33lrngilbMaew3l+4RhGsL45Kym1/0A== 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=IyGh2hGyPNEI+2m0OrCnDZEcNOlJaF8tmhqHfhD22sw=; b=iCCxKdWB6145wB6qoYqUHg7bbECs5FfVnyrQ8g4nQaBwL9SuiR9zdpAWzLNphnJ6ISZkOEVPww8vBjDbeGu8wOt7nujgAqUbC07qlsZh6OxCvoXzAm57wrmkWf98RqWq6G30l7kyx1Qtx7s6AnYJ0F3q2yf4o3/9wNt+Y9Gdy1eKiNG4gSlTHMpg5oQOEFK0KbiUbIFMsxKBwBWmFym79pqhC/H57z/5+NBzKHHCjGidEfyX8ufeoPW6fQPQBoiopV3C3+qYAZO3v+7D6tKqHJ4h+MXJoJVABcRRwkTX9IOtGPRe1OJ5bfaBdkkUzIkMHZzG1803FJuDkZuW3PyyiA== 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=IyGh2hGyPNEI+2m0OrCnDZEcNOlJaF8tmhqHfhD22sw=; b=TELWb3zUHgvj81HxqLtFSUW/VCp8wLQUpRVI0qwvE0HZlOxIZM5Wi74d8lvXXBua0MORukQ5sGFHdu2yMzZtro+j2RfdEYMOsOsU2okE+IBKGLQjTlkZ5gjKpGC8ZqnzGMgLZz3a0WoYFkN5OC5qBgflDGFWmQiU8gkQe35cqMk= 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 SJ0PR10MB4605.namprd10.prod.outlook.com (2603:10b6:a03:2d9::24) by BYAPR10MB3191.namprd10.prod.outlook.com (2603:10b6:a03:14f::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3890.24; Fri, 12 Mar 2021 06:27:08 +0000 Received: from SJ0PR10MB4605.namprd10.prod.outlook.com ([fe80::a021:790:7ce6:6f16]) by SJ0PR10MB4605.namprd10.prod.outlook.com ([fe80::a021:790:7ce6:6f16%6]) with mapi id 15.20.3912.030; Fri, 12 Mar 2021 06:27:08 +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 v9 02/10] OvmfPkg/CpuHotplugSmm: collect hot-unplug events Date: Thu, 11 Mar 2021 22:26:48 -0800 Message-Id: <20210312062656.2477515-3-ankur.a.arora@oracle.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210312062656.2477515-1-ankur.a.arora@oracle.com> References: <20210312062656.2477515-1-ankur.a.arora@oracle.com> X-Originating-IP: [148.87.23.12] X-ClientProxiedBy: MWHPR02CA0018.namprd02.prod.outlook.com (2603:10b6:300:4b::28) To SJ0PR10MB4605.namprd10.prod.outlook.com (2603:10b6:a03:2d9::24) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from prion.us.oracle.com (148.87.23.12) by MWHPR02CA0018.namprd02.prod.outlook.com (2603:10b6:300:4b::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3912.17 via Frontend Transport; Fri, 12 Mar 2021 06:27:06 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8d8cd79d-535d-4d3f-3777-08d8e51fdc65 X-MS-TrafficTypeDiagnostic: BYAPR10MB3191: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:167; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yKvWDDhGJOHXCfrm6a+SWgIWWoGRTZv02NOgcuBjusXvlBmifokW07Ut1fR/d9tXqmQ+OS457SBrpn/igN7SRK4hAyDTPONYtC/5INrP8YZC1X7lCHzFyyjrnL4YS3pZXJOQTtgNE8BU1ZwhiU/oGUc+7JCvfmjUrt4DtycSayEVhu0TpEbthyC2Zi6FxjXhgnDFBLHv5DibLom1KvWedBEqXMXLEH0C76LaBth4+KaTJ3VngY9GpypKsMqeSgIwjzEGF4+y1563cTC06TWlw3lg1w/ospSGd9wmCQ45FSWZs6eLk+h+EQ3NOTLb9WrDcY0qk4DljN7KVD9zNkyfbg1YK3xDBaoKJgwJuRqi75/BEGqYnf0zsTCARdSxja9G269ifP2eBcWWyBQFFlnwZrC0JBuWP/S/kas0dLSGgCzXUxHCKZDTrBZ9L38Geh69i5yrx6+3YO/kt4P6dv8Uj/8aShzL90k8YRw7bvdQGcv5W9hPSff5JGzgZvwVS3aWK//fZKSH/ofO+oMvwx9HuVq8oRIDWkhH8CIzWvrs0gKGKH45Vi5PsNxrIWNqaPQsKDDLZYT6oqzBsb9f3uOnBr/zRPXU1AyoLSUcLEFS/AA= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR10MB4605.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(346002)(39860400002)(396003)(376002)(366004)(136003)(54906003)(86362001)(4326008)(36756003)(30864003)(478600001)(66556008)(66476007)(66946007)(316002)(83380400001)(5660300002)(2906002)(6916009)(103116003)(966005)(6486002)(26005)(2616005)(956004)(6666004)(186003)(107886003)(7696005)(16526019)(52116002)(1076003)(8936002)(8676002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?lw4kQxzquqFy4GY7Wz1hs8Jp2f+EGM/Dtpsb1iiGJ9PEC2qzGtv0Ez2y/YWp?= =?us-ascii?Q?gXdfuF8T669y1uMj821+57l2S2bwYrr2X7XLmaneHXhRr6XKIuBblX1hmki0?= =?us-ascii?Q?Q9SKL3cPcAr5X7m3vZT8RuLPkzzatt5ws0sqv/f18mWg99pQB9VesXNBogA1?= =?us-ascii?Q?h0vuDKjhvXlxk3syxvMMk6WzszH6HHShmzICOZF6uzoslkLtCAu5g0Doe9jx?= =?us-ascii?Q?9mZAWq4VWTi5ikl7SnMEZ8iqIQUxKdcFyCYwOLL83Plz00BwMyyrYyGrVr5l?= =?us-ascii?Q?Vd8nTrKroFx/1KAihMwIMxVb6F9QK4ZMDAeW6UscKla5c00u/wHmvzDhyIKN?= =?us-ascii?Q?Z/8Yb9PsnQBh0O3z1By5GQJ2xOyblgPJ4s2g1FREYji27zz77XnvN3oDYV+N?= =?us-ascii?Q?Y8ATruKfKmHW8k5HAbymS7DEnO/ZjWtYZCvqCrFUs+O2BJGyP87JUhdQEj5b?= =?us-ascii?Q?JXwHJ4G6U7yuenNnIIPT3cDRSJ7Ps6myT+HK1MuXgCRqz73llf4e2czaux8k?= =?us-ascii?Q?0FXV/adNOTUMn1yH/bmmNfz1J9jRE7YhqXNHw4Y7Btz9kqSh+Y73E2VinLLC?= =?us-ascii?Q?IDzXhXwDVxIn2EDX1Ovs6psL7W1viJARKbPXr/tYM53BapjseXxPzWB98DCF?= =?us-ascii?Q?UrpaKcR3N83jl+n+nqj1Biwa4DIXncfpf2fr2h7nqUp7hTJSbi+mqrVR9H0q?= =?us-ascii?Q?yDDtRG1oCIQqllQwtkXCrJHxHBBRodu03DY2E3YxWNnI4j/kAH4TNRsg+GbK?= =?us-ascii?Q?JoRZjDbdusbT06EA96mUasRpUlu2ccYOBGEsnXBlKEDJRqYKTwgbRHs0xk4i?= =?us-ascii?Q?MCamw/ElAdeLAuprDu8RmtB7MCCmNj7ppjnbXUwTfKCrUo/l2kyIbfHhGFyj?= =?us-ascii?Q?BxhXLKjup3EZPXpRsHxs969CDv8mpBjLJuxBA1AndzXSF3DkzUGnv39S03tN?= =?us-ascii?Q?Es8eXWyh26O/ilTZf5LYDWK8Gj5yG+SykkHEjtDBIayYkZ09xuhJkLd+gRyZ?= =?us-ascii?Q?lNw6dOiwjszccxMFANkBOWWYXJXkZEltgnpnvuqtIwVVQdFhB/jnIvC4sEOs?= =?us-ascii?Q?F58MYH7i6jNByWn5wbzqrAnWzGOaA00C4UKfb6tKxeApBeiFa8v3AuWm7PU0?= =?us-ascii?Q?4LN0L+S/Towuwxa9B2e6r/zbH8pPjdP4yu/tc3WUxq/3rO1SoyEbdMicqj1a?= =?us-ascii?Q?ggfETtJ75W9dDxSi8ydRgabdOJrQToC7hAte5pVsYKR/YTrBliG+n7zitGtM?= =?us-ascii?Q?Wc8W9s9hVJoau7AOkEdA8XdAudzMSEnkaD1zQlrcV6naW1LLTcsIIZnacOYL?= =?us-ascii?Q?aqqK0hV2w1FdgQoH9W2RxWTs?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8d8cd79d-535d-4d3f-3777-08d8e51fdc65 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB4605.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Mar 2021 06:27:07.9184 (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: TCOokEFuHjku8skuLqr2dqmJCXO+Ziodff4RZ2zsTqFQJBO9+J/CvrtRoDq/Nqv+Rhm7EHYoa3ZOzQlBkQ3fJFot+DG5MyAXVmioZMtQ9G0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB3191 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9920 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 suspectscore=0 adultscore=0 phishscore=0 malwarescore=0 mlxscore=0 bulkscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2103120044 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9920 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 clxscore=1015 mlxscore=0 phishscore=0 lowpriorityscore=0 malwarescore=0 suspectscore=0 adultscore=0 mlxlogscore=999 spamscore=0 bulkscore=0 priorityscore=1501 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2103120043 Content-Transfer-Encoding: 8bit Content-Type: text/plain Process fw_remove events in QemuCpuhpCollectApicIds(), and collect APIC IDs and QEMU CPU Selectors for CPUs 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@redhat.com/ 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=3132 Signed-off-by: Ankur Arora --- Notes: Addresses the following comments from v8: (1) Fix commit message to mention that we collect cpu-selectors as well. (2,3,6) s/UnplugSelector/UnplugSelectors/ in CpuHotplug.c, QemuCpuhp.c (4) Fix comment above the declaration of the now renamed mToUnplugSelector. (5) Fix spacing around "||". (7) Fix QemuCpuCollectApicIds() comments to line up descriptions for ToUnplugSelectors and other params. (8) s/ExtendSel/ExtendSels/. (9) Add the (ExtendSels => ExtendIds) assert. (10) Fix the missing CurrentSelector++ bug. OvmfPkg/CpuHotplugSmm/QemuCpuhp.h | 1 + OvmfPkg/Include/IndustryStandard/QemuCpuHotplug.h | 1 + OvmfPkg/CpuHotplugSmm/CpuHotplug.c | 29 +++++-- OvmfPkg/CpuHotplugSmm/QemuCpuhp.c | 101 +++++++++++++++------- 4 files changed, 93 insertions(+), 39 deletions(-) diff --git a/OvmfPkg/CpuHotplugSmm/QemuCpuhp.h b/OvmfPkg/CpuHotplugSmm/QemuCpuhp.h index 8adaa0ad91f0..3e2c2192e1c0 100644 --- a/OvmfPkg/CpuHotplugSmm/QemuCpuhp.h +++ b/OvmfPkg/CpuHotplugSmm/QemuCpuhp.h @@ -55,6 +55,7 @@ QemuCpuhpCollectApicIds ( OUT APIC_ID *PluggedApicIds, OUT UINT32 *PluggedCount, OUT APIC_ID *ToUnplugApicIds, + OUT UINT32 *ToUnplugSelectors, OUT UINT32 *ToUnplugCount ); diff --git a/OvmfPkg/Include/IndustryStandard/QemuCpuHotplug.h b/OvmfPkg/Include/IndustryStandard/QemuCpuHotplug.h index a34a6d3fae61..2ec7a107a64d 100644 --- a/OvmfPkg/Include/IndustryStandard/QemuCpuHotplug.h +++ b/OvmfPkg/Include/IndustryStandard/QemuCpuHotplug.h @@ -34,6 +34,7 @@ #define QEMU_CPUHP_STAT_ENABLED BIT0 #define QEMU_CPUHP_STAT_INSERT BIT1 #define QEMU_CPUHP_STAT_REMOVE BIT2 +#define QEMU_CPUHP_STAT_FW_REMOVE BIT4 #define QEMU_CPUHP_RW_CMD_DATA 0x8 diff --git a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c b/OvmfPkg/CpuHotplugSmm/CpuHotplug.c index bf68fcd42914..ee1497b93140 100644 --- a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c +++ b/OvmfPkg/CpuHotplugSmm/CpuHotplug.c @@ -45,13 +45,16 @@ STATIC CPU_HOT_PLUG_DATA *mCpuHotPlugData; // don't want to allocate SMRAM at OS runtime, and potentially fail (or // fragment the SMRAM map). // -// These arrays provide room for ("possible CPU count" minus one) APIC IDs -// each, as we don't expect every possible CPU to appear, or disappear, in a -// single MMI. The numbers of used (populated) elements in the arrays are +// The first array stores APIC IDs for hot-plug events, the second and the +// third store APIC IDs and QEMU CPU Selectors (both indexed similarly) for +// hot-unplug events. All of these provide room for "possible CPU count" minus +// one elements as we don't expect every possible CPU to appear, or disappear, +// in a single MMI. The numbers of used (populated) elements in the arrays are // determined on every MMI separately. // STATIC APIC_ID *mPluggedApicIds; STATIC APIC_ID *mToUnplugApicIds; +STATIC UINT32 *mToUnplugSelectors; // // Address of the non-SMRAM reserved memory page that contains the Post-SMM Pen // for hot-added CPUs. @@ -289,6 +292,7 @@ CpuHotplugMmi ( mPluggedApicIds, &PluggedCount, mToUnplugApicIds, + mToUnplugSelectors, &ToUnplugCount ); if (EFI_ERROR (Status)) { @@ -333,7 +337,9 @@ CpuHotplugEntry ( ) { EFI_STATUS Status; + UINTN Len; UINTN Size; + UINTN SizeSel; // // This module should only be included when SMM support is required. @@ -387,8 +393,9 @@ CpuHotplugEntry ( // // Allocate the data structures that depend on the possible CPU count. // - if (RETURN_ERROR (SafeUintnSub (mCpuHotPlugData->ArrayLength, 1, &Size)) || - RETURN_ERROR (SafeUintnMult (sizeof (APIC_ID), Size, &Size))) { + if (RETURN_ERROR (SafeUintnSub (mCpuHotPlugData->ArrayLength, 1, &Len)) || + RETURN_ERROR (SafeUintnMult (sizeof (APIC_ID), Len, &Size)) || + RETURN_ERROR (SafeUintnMult (sizeof (UINT32), Len, &SizeSel))) { Status = EFI_ABORTED; DEBUG ((DEBUG_ERROR, "%a: invalid CPU_HOT_PLUG_DATA\n", __FUNCTION__)); goto Fatal; @@ -405,6 +412,12 @@ CpuHotplugEntry ( DEBUG ((DEBUG_ERROR, "%a: MmAllocatePool(): %r\n", __FUNCTION__, Status)); goto ReleasePluggedApicIds; } + Status = gMmst->MmAllocatePool (EfiRuntimeServicesData, SizeSel, + (VOID **)&mToUnplugSelectors); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: MmAllocatePool(): %r\n", __FUNCTION__, Status)); + goto ReleaseToUnplugApicIds; + } // // Allocate the Post-SMM Pen for hot-added CPUs. @@ -412,7 +425,7 @@ CpuHotplugEntry ( Status = SmbaseAllocatePostSmmPen (&mPostSmmPenAddress, SystemTable->BootServices); if (EFI_ERROR (Status)) { - goto ReleaseToUnplugApicIds; + goto ReleaseToUnplugSelectors; } // @@ -472,6 +485,10 @@ ReleasePostSmmPen: SmbaseReleasePostSmmPen (mPostSmmPenAddress, SystemTable->BootServices); mPostSmmPenAddress = 0; +ReleaseToUnplugSelectors: + gMmst->MmFreePool (mToUnplugSelectors); + mToUnplugSelectors = NULL; + ReleaseToUnplugApicIds: gMmst->MmFreePool (mToUnplugApicIds); mToUnplugApicIds = NULL; diff --git a/OvmfPkg/CpuHotplugSmm/QemuCpuhp.c b/OvmfPkg/CpuHotplugSmm/QemuCpuhp.c index 8d4a6693c8d6..8434dd446b96 100644 --- a/OvmfPkg/CpuHotplugSmm/QemuCpuhp.c +++ b/OvmfPkg/CpuHotplugSmm/QemuCpuhp.c @@ -145,27 +145,30 @@ QemuCpuhpWriteCommand ( On error, the contents of the output parameters are undefined. - @param[in] MmCpuIo The EFI_MM_CPU_IO_PROTOCOL instance for - accessing IO Ports. + @param[in] MmCpuIo The EFI_MM_CPU_IO_PROTOCOL instance for + accessing IO Ports. - @param[in] PossibleCpuCount The number of possible CPUs in the system. Must - be positive. + @param[in] PossibleCpuCount The number of possible CPUs in the system. Must + be positive. - @param[in] ApicIdCount The number of elements each one of the - PluggedApicIds and ToUnplugApicIds arrays can - accommodate. Must be positive. + @param[in] ApicIdCount The number of elements each one of the + PluggedApicIds and ToUnplugApicIds arrays can + accommodate. Must be positive. - @param[out] PluggedApicIds The APIC IDs of the CPUs that have been - hot-plugged. + @param[out] PluggedApicIds The APIC IDs of the CPUs that have been + hot-plugged. - @param[out] PluggedCount The number of filled-in APIC IDs in - PluggedApicIds. + @param[out] PluggedCount The number of filled-in APIC IDs in + PluggedApicIds. - @param[out] ToUnplugApicIds The APIC IDs of the CPUs that are about to be - hot-unplugged. + @param[out] ToUnplugApicIds The APIC IDs of the CPUs that are about to be + hot-unplugged. - @param[out] ToUnplugCount The number of filled-in APIC IDs in - ToUnplugApicIds. + @param[out] ToUnplugSelectors The QEMU Selectors of the CPUs that are about + to be hot-unplugged. + + @param[out] ToUnplugCount The number of filled-in APIC IDs in + ToUnplugApicIds. @retval EFI_INVALID_PARAMETER PossibleCpuCount is zero, or ApicIdCount is zero. @@ -187,6 +190,7 @@ QemuCpuhpCollectApicIds ( OUT APIC_ID *PluggedApicIds, OUT UINT32 *PluggedCount, OUT APIC_ID *ToUnplugApicIds, + OUT UINT32 *ToUnplugSelectors, OUT UINT32 *ToUnplugCount ) { @@ -204,6 +208,7 @@ QemuCpuhpCollectApicIds ( UINT32 PendingSelector; UINT8 CpuStatus; APIC_ID *ExtendIds; + UINT32 *ExtendSels; UINT32 *ExtendCount; APIC_ID NewApicId; @@ -245,10 +250,10 @@ QemuCpuhpCollectApicIds ( if ((CpuStatus & QEMU_CPUHP_STAT_INSERT) != 0) { // // The "insert" event guarantees the "enabled" status; plus it excludes - // the "remove" event. + // the "fw_remove" event. // if ((CpuStatus & QEMU_CPUHP_STAT_ENABLED) == 0 || - (CpuStatus & QEMU_CPUHP_STAT_REMOVE) != 0) { + (CpuStatus & QEMU_CPUHP_STAT_FW_REMOVE) != 0) { DEBUG ((DEBUG_ERROR, "%a: CurrentSelector=%u CpuStatus=0x%x: " "inconsistent CPU status\n", __FUNCTION__, CurrentSelector, CpuStatus)); @@ -259,33 +264,63 @@ QemuCpuhpCollectApicIds ( CurrentSelector)); ExtendIds = PluggedApicIds; + ExtendSels = NULL; ExtendCount = PluggedCount; - } else if ((CpuStatus & QEMU_CPUHP_STAT_REMOVE) != 0) { - DEBUG ((DEBUG_VERBOSE, "%a: CurrentSelector=%u: remove\n", __FUNCTION__, - CurrentSelector)); + } else if ((CpuStatus & QEMU_CPUHP_STAT_FW_REMOVE) != 0) { + // + // "fw_remove" event guarantees "enabled". + // + if ((CpuStatus & QEMU_CPUHP_STAT_ENABLED) == 0) { + DEBUG ((DEBUG_ERROR, "%a: CurrentSelector=%u CpuStatus=0x%x: " + "inconsistent CPU status\n", __FUNCTION__, CurrentSelector, + CpuStatus)); + return EFI_PROTOCOL_ERROR; + } + + DEBUG ((DEBUG_VERBOSE, "%a: CurrentSelector=%u: fw_remove\n", + __FUNCTION__, CurrentSelector)); ExtendIds = ToUnplugApicIds; + ExtendSels = ToUnplugSelectors; ExtendCount = ToUnplugCount; + } else if ((CpuStatus & QEMU_CPUHP_STAT_REMOVE) != 0) { + // + // Let the OSPM deal with the "remove" event. + // + DEBUG ((DEBUG_VERBOSE, "%a: CurrentSelector=%u: remove (ignored)\n", + __FUNCTION__, CurrentSelector)); + + ExtendIds = NULL; + ExtendSels = NULL; + ExtendCount = NULL; } else { DEBUG ((DEBUG_VERBOSE, "%a: CurrentSelector=%u: no event\n", __FUNCTION__, CurrentSelector)); break; } - // - // Save the APIC ID of the CPU with the pending event, to the corresponding - // APIC ID array. - // - if (*ExtendCount == ApicIdCount) { - DEBUG ((DEBUG_ERROR, "%a: APIC ID array too small\n", __FUNCTION__)); - return EFI_BUFFER_TOO_SMALL; - } - QemuCpuhpWriteCommand (MmCpuIo, QEMU_CPUHP_CMD_GET_ARCH_ID); - NewApicId = QemuCpuhpReadCommandData (MmCpuIo); - DEBUG ((DEBUG_VERBOSE, "%a: ApicId=" FMT_APIC_ID "\n", __FUNCTION__, - NewApicId)); - ExtendIds[(*ExtendCount)++] = NewApicId; + ASSERT ((ExtendIds == NULL) == (ExtendCount == NULL)); + ASSERT ((ExtendSels == NULL) || (ExtendIds != NULL)); + if (ExtendIds != NULL) { + // + // Save the APIC ID of the CPU with the pending event, to the + // corresponding APIC ID array. + // For unplug events, also save the CurrentSelector. + // + if (*ExtendCount == ApicIdCount) { + DEBUG ((DEBUG_ERROR, "%a: APIC ID array too small\n", __FUNCTION__)); + return EFI_BUFFER_TOO_SMALL; + } + QemuCpuhpWriteCommand (MmCpuIo, QEMU_CPUHP_CMD_GET_ARCH_ID); + NewApicId = QemuCpuhpReadCommandData (MmCpuIo); + DEBUG ((DEBUG_VERBOSE, "%a: ApicId=" FMT_APIC_ID "\n", __FUNCTION__, + NewApicId)); + if (ExtendSels != NULL) { + ExtendSels[(*ExtendCount)] = CurrentSelector; + } + ExtendIds[(*ExtendCount)++] = NewApicId; + } // // We've processed the CPU with (known) pending events, but we must never // clear events. Therefore we need to advance past this CPU manually; -- 2.9.3