From nobody Thu Nov 14 23:00:04 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+72711+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+72711+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 1615530446615338.80352554807814; Thu, 11 Mar 2021 22:27:26 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id FyF5YY1788612x0v3rRKEqlJ; Thu, 11 Mar 2021 22:27:26 -0800 X-Received: from aserp2120.oracle.com (aserp2120.oracle.com [141.146.126.78]) by mx.groups.io with SMTP id smtpd.web11.4908.1615530441279466488 for ; Thu, 11 Mar 2021 22:27:21 -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 12C68vva167464; Fri, 12 Mar 2021 06:27:18 GMT X-Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2120.oracle.com with ESMTP id 3741pmryaa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Mar 2021 06:27:17 +0000 X-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 12C6P9bu055196; Fri, 12 Mar 2021 06:27:17 GMT X-Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2109.outbound.protection.outlook.com [104.47.55.109]) by userp3020.oracle.com with ESMTP id 374kgw3bs0-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Mar 2021 06:27:16 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iB58DLIb+Ix0pwmRJ6czeMWRwNekk/iNhQYk/6yJwYf/86WcsrvHsyLwPv+G3cCIM0gEhAtVxXIA2JG3Oxuz4vD/n5lCv7Db2IqA+oTi45KCgoqa0Z+BEV+JTb8/GYq9TRev4AOL9eBQXHVOkyKA4U/OJRnFNix6/SWTzuN9vL/VGP31Y6OkZfmlFNzpyBgJlXuU8SJfnUyVES5KbKDIUbPw02MpB0c4Y3zqBxVbrZh7NvkV4laDtrR8Y/MhxfPlSFJvP/Vr/1TSBe7ATk/QpA5qodNp+7q6Ac2pAWJ/nRJfKI06DwIzNQp6/kT8I4FxrewpZ939hxUiG7imR9ScZg== 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=SVBy6Dr1CxfbqFJQ//fGo3VS5yVWlGZUKq15HXAWjk0=; b=PH/+9fpTgOuSnhyOKTZtxtclCvOyOAtozhvhpcNxedhLvQYAd47o5xuidy4TOP/Z2qgfLoxS9CNuiSSVmeLB2j7/UyxQbNVuHT7Hwp3FOxPmbwlzx9JACw+hL2XOe4/9+wKFDx6HkVw0KrxK6k4AVuJzOQ6JTrHo0CvY5L3AWZ3WLquGWaC8VAvxpQLa3BNAarsIKdm2bOFsgjGu++5eB9nUwLaGUlO6FvXbXKPG96kuh5g6NbNZCk331Bd3yHV21QppbS2FZba2kR4IQN4GVz2x8ZT/phshGhIVS/fPx6VHZJfjtQk+2vYtRWRh3OkjYPTxzHqc8gnQbTCAnsUUrw== 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 SJ0PR10MB4605.namprd10.prod.outlook.com (2603:10b6:a03:2d9::24) by SJ0PR10MB4544.namprd10.prod.outlook.com (2603:10b6:a03:2ad::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3933.31; Fri, 12 Mar 2021 06:27:15 +0000 X-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:15 +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 v9 08/10] OvmfPkg/CpuHotplugSmm: add EjectCpu() Date: Thu, 11 Mar 2021 22:26:54 -0800 Message-Id: <20210312062656.2477515-9-ankur.a.arora@oracle.com> 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 X-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:14 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 61f1457d-da2e-4664-94a5-08d8e51fe0c9 X-MS-TrafficTypeDiagnostic: SJ0PR10MB4544: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBCl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fBwvfFlCxN31dPOM1P3?= =?us-ascii?Q?w+FEKc76ioNLjsYi4on9JpPDMUt7lKQemFWv12NxDFWWKqGV/5fXzyuk+Teq?= =?us-ascii?Q?dWUToyzD3SP+SxcL0tc9Z4lXW/oyiVrYFzqwCRd6MwS3h5IxrXZ6/M9u/ga1?= =?us-ascii?Q?MWEL00U8hdRjn6Ri6yyuIhEB1YMlLTlyunBqDYZ50merA38JaK16PcjvjcS4?= =?us-ascii?Q?Tatadnta34+5gtW4sKHlc/3K?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 61f1457d-da2e-4664-94a5-08d8e51fe0c9 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:15.2661 (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: 8iq/lJaeIEVssGcLz0hV9lfW7s7NNrtWLE/Pt7k5/sRxBbNvGzeaPpa1FCoXxBz1HadQtvlf4OdXWSQUu/J8wrIptjLkODymZw6zBZ1WgRY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4544 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: rRabuutQdNXbP2K62HLOtVyRx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1615530446; bh=CDDRmfpAiMKnveEsH2kWsS0FOPXmx/sEQ49ii1VZCBk=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=FwQerlCG69Amg9GqTC+T0oMAZI5iUItpoR1L28uYhmXiSXaVPoKlRqijPGDvCGunFs0 zHAxRevLixQu+FISsCTXx9XsQp2T77au6vJzTsNUAs5+8B3xDCOl2VFSdwPGpDOz6getF 35ZLIkhHE1KGdu9EHuaet0KEGp2Dm+AHQDQ= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Add EjectCpu(), which handles the CPU ejection, and provides a holding area for said CPUs. It is called via SmmCpuFeaturesRendezvousExit(), at the tail end of the SMI handling. Also UnplugCpus() now stashes QEMU Selectors of CPUs which need to be ejected in CPU_HOT_EJECT_DATA.QemuSelectorMap. This is used by EjectCpu() to identify CPUs marked for ejection. 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 Reviewed-by: Laszlo Ersek --- Notes: Addresses the following comments from v8: =20 (1) Fixup the coment about UnplugCpus() to reference stashing QEMU Cpu Selectors instead of APIC IDs. (2) s/ToUnplugSelector/ToUnplugSelectors/ (3) Use plural for APIC ID in comment describing retval EFI_ALREADY_STA= RTED. (4) Fixup indentation in check against CPU_EJECT_QEMU_SELECTOR_INVALID. (5) Clarify comment: - // never match more than one APIC ID and by transitivity, more than= one - // QemuSelector in a single invocation of UnplugCpus(). + // never match more than one APIC ID -- nor, by transitivity, desig= nate + // more than one QemuSelector -- in a single invocation of UnplugCp= us(). (6a) Remove unnecessary UINT64 cast for mCpuHotEjectData->QemuSelectorM= ap[ProcessorNum]. (6b) Switch from 0x%Lx -> %Lu for QemuSelectorMap[ProcessorNum]. (6c) Switch from 0x%Lx -> %u for QemuSelector (7) Switch to "return EFI_ALREADY_STARTED". (8a) Replace "QemuSelector 0x%Lx" with "QemuSelector %u". (8b) Replace the mCpuHotEjectData->QemuSelectorMap[ProcessorNum] argume= nt with just QemuSelector in DEBUG call. (9) Clarify comment and make the language complementary to that in patc= h-7 Explicitly mention release memory fence. OvmfPkg/CpuHotplugSmm/CpuHotplugSmm.inf | 2 + OvmfPkg/CpuHotplugSmm/CpuHotplug.c | 154 ++++++++++++++++++++++++++++= ++-- 2 files changed, 148 insertions(+), 8 deletions(-) diff --git a/OvmfPkg/CpuHotplugSmm/CpuHotplugSmm.inf b/OvmfPkg/CpuHotplugSm= m/CpuHotplugSmm.inf index 04322b0d7855..ebcc7e2ac63a 100644 --- a/OvmfPkg/CpuHotplugSmm/CpuHotplugSmm.inf +++ b/OvmfPkg/CpuHotplugSmm/CpuHotplugSmm.inf @@ -40,6 +40,7 @@ [Packages] [LibraryClasses] BaseLib BaseMemoryLib + CpuLib DebugLib LocalApicLib MmServicesTableLib @@ -54,6 +55,7 @@ [Protocols] =20 [Pcd] gUefiCpuPkgTokenSpaceGuid.PcdCpuHotPlugDataAddress ## CON= SUMES + gUefiOvmfPkgTokenSpaceGuid.PcdCpuHotEjectDataAddress ## CON= SUMES gUefiOvmfPkgTokenSpaceGuid.PcdQ35SmramAtDefaultSmbase ## CON= SUMES =20 [FeaturePcd] diff --git a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c b/OvmfPkg/CpuHotplugSmm/Cpu= Hotplug.c index 59f000eb7886..2eeb4567a262 100644 --- a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c +++ b/OvmfPkg/CpuHotplugSmm/CpuHotplug.c @@ -10,10 +10,12 @@ #include // ICH9_APM_CNT #include // QEMU_CPUHP_CMD_GET_PENDING #include // CpuDeadLoop() +#include // CpuSleep() #include // ASSERT() #include // gMmst #include // PcdGetBool() #include // SafeUintnSub() +#include // CPU_HOT_EJECT_DATA #include // EFI_MM_CPU_IO_PROTOCOL #include // EFI_SMM_CPU_SERVICE_PROTOC= OL #include // EFI_STATUS @@ -32,11 +34,12 @@ STATIC EFI_MM_CPU_IO_PROTOCOL *mMmCpuIo; // STATIC EFI_SMM_CPU_SERVICE_PROTOCOL *mMmCpuService; // -// This structure is a communication side-channel between the +// These structures serve as communication side-channels between the // EFI_SMM_CPU_SERVICE_PROTOCOL consumer (i.e., this driver) and provider // (i.e., PiSmmCpuDxeSmm). // STATIC CPU_HOT_PLUG_DATA *mCpuHotPlugData; +STATIC CPU_HOT_EJECT_DATA *mCpuHotEjectData; // // SMRAM arrays for fetching the APIC IDs of processors with pending event= s (of // known event types), for the time of just one MMI. @@ -190,18 +193,71 @@ RevokeNewSlot: } =20 /** + CPU Hot-eject handler, called from SmmCpuFeaturesRendezvousExit() + on each CPU at exit from SMM. + + If, the executing CPU is not being ejected, nothing to be done. + If, the executing CPU is being ejected, wait in a halted loop + until ejected. + + @param[in] ProcessorNum ProcessorNum denotes the CPU exiting SMM, + and will be used as an index into + CPU_HOT_EJECT_DATA->QemuSelectorMap. It is + identical to the processor handle number in + EFI_SMM_CPU_SERVICE_PROTOCOL. +**/ +VOID +EFIAPI +EjectCpu ( + IN UINTN ProcessorNum + ) +{ + UINT64 QemuSelector; + + QemuSelector =3D mCpuHotEjectData->QemuSelectorMap[ProcessorNum]; + if (QemuSelector =3D=3D CPU_EJECT_QEMU_SELECTOR_INVALID) { + return; + } + + // + // APs being unplugged get here from SmmCpuFeaturesRendezvousExit() + // after having been cleared to exit the SMI and so have no SMM + // processing remaining. + // + // Keep them penned here until the BSP tells QEMU to eject them. + // + for (;;) { + DisableInterrupts (); + CpuSleep (); + } +} + +/** Process to be hot-unplugged CPUs, per QemuCpuhpCollectApicIds(). =20 For each such CPU, report the CPU to PiSmmCpuDxeSmm via - EFI_SMM_CPU_SERVICE_PROTOCOL. If the to be hot-unplugged CPU is - unknown, skip it silently. + EFI_SMM_CPU_SERVICE_PROTOCOL and stash the QEMU Cpu Selectors for later + ejection. If the to be hot-unplugged CPU is unknown, skip it silently. + + Additonally, if we do stash any Cpu Selectors, also install a CPU eject + handler which would handle the ejection. =20 @param[in] ToUnplugApicIds The APIC IDs of the CPUs that are about to= be hot-unplugged. =20 + @param[in] ToUnplugSelectors The QEMU Selectors of the CPUs that are ab= out to + be hot-unplugged. + @param[in] ToUnplugCount The number of filled-in APIC IDs in ToUnplugApicIds. =20 + @retval EFI_ALREADY_STARTED For the ProcessorNum that + EFI_SMM_CPU_SERVICE_PROTOCOL had assigned = to + one of the APIC IDs in ToUnplugApicIds, + mCpuHotEjectData->QemuSelectorMap already = has + the QemuSelector value stashed. (This shou= ld + never happen.) + @retval EFI_SUCCESS Known APIC IDs have been removed from SMM = data structures. =20 @@ -212,23 +268,36 @@ STATIC EFI_STATUS UnplugCpus ( IN APIC_ID *ToUnplugApicIds, + IN UINT32 *ToUnplugSelectors, IN UINT32 ToUnplugCount ) { EFI_STATUS Status; UINT32 ToUnplugIdx; + UINT32 EjectCount; UINTN ProcessorNum; =20 ToUnplugIdx =3D 0; + EjectCount =3D 0; while (ToUnplugIdx < ToUnplugCount) { APIC_ID RemoveApicId; + UINT32 QemuSelector; =20 RemoveApicId =3D ToUnplugApicIds[ToUnplugIdx]; + QemuSelector =3D ToUnplugSelectors[ToUnplugIdx]; =20 // - // mCpuHotPlugData->ApicId maps ProcessorNum -> ApicId. Use it to find - // the ProcessorNum for the APIC ID to be removed. + // mCpuHotPlugData->ApicId maps ProcessorNum -> ApicId. Use RemoveApic= Id + // to find the corresponding ProcessorNum for the CPU to be removed. // + // With this we can establish a 3 way mapping: + // APIC_ID -- ProcessorNum -- QemuSelector + // + // We stash the ProcessorNum -> QemuSelector mapping so it can later be + // used for CPU hot-eject in SmmCpuFeaturesRendezvousExit() context (w= here + // we only have ProcessorNum available.) + // + for (ProcessorNum =3D 0; ProcessorNum < mCpuHotPlugData->ArrayLength; ProcessorNum++) { @@ -257,11 +326,62 @@ UnplugCpus ( return Status; } =20 + if (mCpuHotEjectData->QemuSelectorMap[ProcessorNum] !=3D + CPU_EJECT_QEMU_SELECTOR_INVALID) { + // + // mCpuHotEjectData->QemuSelectorMap[ProcessorNum] is set to + // CPU_EJECT_QEMU_SELECTOR_INVALID when mCpuHotEjectData->QemuSelect= orMap + // is allocated, and once the subject processsor is ejected. + // + // Additionally, mMmCpuService->RemoveProcessor(ProcessorNum) invali= dates + // mCpuHotPlugData->ApicId[ProcessorNum], so a given ProcessorNum can + // never match more than one APIC ID -- nor, by transitivity, design= ate + // more than one QemuSelector -- in a single invocation of UnplugCpu= s(). + // + DEBUG ((DEBUG_ERROR, "%a: ProcessorNum %Lu maps to QemuSelector %Lu,= " + "cannot also map to %u\n", __FUNCTION__, (UINT64)ProcessorNum, + mCpuHotEjectData->QemuSelectorMap[ProcessorNum], QemuSelector)); + + return EFI_ALREADY_STARTED; + } + + // + // Stash the QemuSelector so we can do the actual ejection later. + // + mCpuHotEjectData->QemuSelectorMap[ProcessorNum] =3D (UINT64)QemuSelect= or; + + DEBUG ((DEBUG_INFO, "%a: Started hot-unplug on ProcessorNum %Lu, APIC = ID " + FMT_APIC_ID ", QemuSelector %u\n", __FUNCTION__, (UINT64)ProcessorNu= m, + RemoveApicId, QemuSelector)); + + EjectCount++; ToUnplugIdx++; } =20 + if (EjectCount !=3D 0) { + // + // We have processors to be ejected; install the handler. + // + mCpuHotEjectData->Handler =3D EjectCpu; + + // + // The BSP and APs load mCpuHotEjectData->Handler, and + // mCpuHotEjectData->QemuSelectorMap[] in SmmCpuFeaturesRendezvousExit= () + // and EjectCpu(). + // + // The comment in SmmCpuFeaturesRendezvousExit() details how we use + // the AllCpusInSync control-dependency to ensure that any loads are + // ordered-after the stores above. + // + // Ensure that the stores above are ordered-before the AllCpusInSync s= tore + // by using a MemoryFence() with release semantics. + // + MemoryFence (); + } + // - // We've removed this set of APIC IDs from SMM data structures. + // We've removed this set of APIC IDs from SMM data structures and + // have installed an ejection handler if needed. // return EFI_SUCCESS; } @@ -389,7 +509,7 @@ CpuHotplugMmi ( } =20 if (ToUnplugCount > 0) { - Status =3D UnplugCpus (mToUnplugApicIds, ToUnplugCount); + Status =3D UnplugCpus (mToUnplugApicIds, mToUnplugSelectors, ToUnplugC= ount); if (EFI_ERROR (Status)) { goto Fatal; } @@ -460,9 +580,14 @@ CpuHotplugEntry ( =20 // // Our DEPEX on EFI_SMM_CPU_SERVICE_PROTOCOL guarantees that PiSmmCpuDxe= Smm - // has pointed PcdCpuHotPlugDataAddress to CPU_HOT_PLUG_DATA in SMRAM. + // has pointed: + // - PcdCpuHotPlugDataAddress to CPU_HOT_PLUG_DATA in SMRAM, + // - PcdCpuHotEjectDataAddress to CPU_HOT_EJECT_DATA in SMRAM, if the + // possible CPU count is greater than 1. // mCpuHotPlugData =3D (VOID *)(UINTN)PcdGet64 (PcdCpuHotPlugDataAddress); + mCpuHotEjectData =3D (VOID *)(UINTN)PcdGet64 (PcdCpuHotEjectDataAddress); + if (mCpuHotPlugData =3D=3D NULL) { Status =3D EFI_NOT_FOUND; DEBUG ((DEBUG_ERROR, "%a: CPU_HOT_PLUG_DATA: %r\n", __FUNCTION__, Stat= us)); @@ -474,6 +599,19 @@ CpuHotplugEntry ( if (mCpuHotPlugData->ArrayLength =3D=3D 1) { return EFI_UNSUPPORTED; } + + if (mCpuHotEjectData =3D=3D NULL) { + Status =3D EFI_NOT_FOUND; + } else if (mCpuHotPlugData->ArrayLength !=3D mCpuHotEjectData->ArrayLeng= th) { + Status =3D EFI_INVALID_PARAMETER; + } else { + Status =3D EFI_SUCCESS; + } + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: CPU_HOT_EJECT_DATA: %r\n", __FUNCTION__, Sta= tus)); + goto Fatal; + } + // // Allocate the data structures that depend on the possible CPU count. // --=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 (#72711): https://edk2.groups.io/g/devel/message/72711 Mute This Topic: https://groups.io/mt/81273611/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-