From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.groups.io with SMTP id smtpd.web12.28715.1612149193570115191 for ; Sun, 31 Jan 2021 19:13:13 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=SwPT/FE0; spf=pass (domain: redhat.com, ip: 216.205.24.124, mailfrom: lersek@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612149192; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2ScU+b1KdontSf8BbZyDzKSw/YzBj0kP46MB3FW2h+8=; b=SwPT/FE0Iw41ig1Q0sR2MksuvLsLxhXZhSPTybjjc2KFdTvHPWbRlJ2BpAqIR951YPZPfj cyU43Gzpl7A1JMYgOIOx24dqdtRuMlOjZZYvkovqJOXxfmccaXD4FYBsu2/nS8ypQmD8qv gwrGX1SSdrrC3cGxSEOATRcuuPV8E7s= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-353-vYVx-Y2uMcOh4dPIKbV4eQ-1; Sun, 31 Jan 2021 22:13:07 -0500 X-MC-Unique: vYVx-Y2uMcOh4dPIKbV4eQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5F047800D55; Mon, 1 Feb 2021 03:13:06 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-112-16.ams2.redhat.com [10.36.112.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 898606E53E; Mon, 1 Feb 2021 03:13:04 +0000 (UTC) Subject: Re: [PATCH v6 4/9] OvmfPkg/CpuHotplugSmm: introduce UnplugCpus() To: Ankur Arora , devel@edk2.groups.io Cc: imammedo@redhat.com, boris.ostrovsky@oracle.com, Jordan Justen , Ard Biesheuvel , Aaron Young References: <20210129005950.467638-1-ankur.a.arora@oracle.com> <20210129005950.467638-5-ankur.a.arora@oracle.com> From: "Laszlo Ersek" Message-ID: <06503fdc-a609-455d-2269-38491e8a9408@redhat.com> Date: Mon, 1 Feb 2021 04:13:03 +0100 MIME-Version: 1.0 In-Reply-To: <20210129005950.467638-5-ankur.a.arora@oracle.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=lersek@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit On 01/29/21 01:59, Ankur Arora wrote: > Introduce UnplugCpus() which maps each APIC ID being unplugged > onto the hardware ID of the processor and informs PiSmmCpuDxeSmm > of removal by calling EFI_SMM_CPU_SERVICE_PROTOCOL.RemoveProcessor(). > > With this change we handle the first phase of unplug where we collect > the CPUs that need to be unplugged and mark them for removal in SMM > data structures. > > 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 > --- > OvmfPkg/CpuHotplugSmm/CpuHotplug.c | 84 ++++++++++++++++++++++++++++++++++++++ > 1 file changed, 84 insertions(+) > > diff --git a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c b/OvmfPkg/CpuHotplugSmm/CpuHotplug.c > index 05b1f8cb63a6..70d69f6ed65b 100644 > --- a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c > +++ b/OvmfPkg/CpuHotplugSmm/CpuHotplug.c > @@ -188,6 +188,88 @@ RevokeNewSlot: > } > > /** > + Process to be hot-unplugged CPUs, per QemuCpuhpCollectApicIds(). > + > + 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. > + > + @param[in] ToUnplugApicIds The APIC IDs of the CPUs that are about to be > + hot-unplugged. > + > + @param[in] ToUnplugCount The number of filled-in APIC IDs in > + ToUnplugApicIds. > + > + @retval EFI_SUCCESS Known APIC IDs have been removed from SMM data > + structures. > + > + @return Error codes propagated from > + mMmCpuService->RemoveProcessor(). > + (1) Please drop this empty line (just before the '**/'). > +**/ > +STATIC > +EFI_STATUS > +UnplugCpus ( > + IN APIC_ID *ToUnplugApicIds, > + IN UINT32 ToUnplugCount > + ) > +{ > + EFI_STATUS Status; > + UINT32 ToUnplugIdx; > + UINTN ProcessorNum; > + > + ToUnplugIdx = 0; > + while (ToUnplugIdx < ToUnplugCount) { > + APIC_ID RemoveApicId; > + > + RemoveApicId = ToUnplugApicIds[ToUnplugIdx]; > + > + // > + // mCpuHotPlugData->ApicId maps ProcessorNum -> ApicId. Use it to find > + // the ProcessorNum for the APIC ID to be removed. > + // > + for (ProcessorNum = 0; > + ProcessorNum < mCpuHotPlugData->ArrayLength; > + ProcessorNum++) { > + if (mCpuHotPlugData->ApicId[ProcessorNum] == RemoveApicId) { > + break; > + } > + } > + > + // > + // Ignore the unplug if APIC ID not found > + // > + if (ProcessorNum == mCpuHotPlugData->ArrayLength) { > + DEBUG ((DEBUG_INFO, "%a: did not find APIC ID " FMT_APIC_ID > + " to unplug\n", __FUNCTION__, RemoveApicId)); (2) Please use DEBUG_VERBOSE here. (I agree that we should have *one* DEBUG_INFO message that relates to the removal of an individual processor; however, I think we should emit that message when we finally signal QEMU to eject the processor.) (3) Please un-indent ("outdent"?) the second line by two spaces. > + ToUnplugIdx++; > + continue; > + } > + > + // > + // Mark ProcessorNum for removal from SMM data structures > + // > + Status = mMmCpuService->RemoveProcessor (mMmCpuService, ProcessorNum); > + (4) It would be more idiomatic to remove this empty line (between Status assignment and check). > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "%a: RemoveProcessor(" FMT_APIC_ID "): %r\n", > + __FUNCTION__, RemoveApicId, Status)); > + goto Fatal; (5) Please just "return Status" here, and drop the "Fatal" label. > + } > + > + ToUnplugIdx++; > + } > + > + // > + // We've removed this set of APIC IDs from SMM data structures. > + // > + return EFI_SUCCESS; > + > +Fatal: > + return Status; > +} > + > +/** > CPU Hotplug MMI handler function. > > This is a root MMI handler. > @@ -303,6 +385,8 @@ CpuHotplugMmi ( > > if (PluggedCount > 0) { > Status = ProcessHotAddedCpus (mPluggedApicIds, PluggedCount); > + } else if (ToUnplugCount > 0) { > + Status = UnplugCpus (mToUnplugApicIds, ToUnplugCount); > } > > if (EFI_ERROR(Status)) { > (6) Hmm... What's the reason for the exclusivity? Why is the following not better: if (PluggedCount > 0) { Status = ProcessHotAddedCpus (mPluggedApicIds, PluggedCount); if (EFI_ERROR (Status)) { goto Fatal; } } if (ToUnplugCount > 0) { Status = UnplugCpus (mToUnplugApicIds, ToUnplugCount); if (EFI_ERROR (Status)) { goto Fatal; } } QemuCpuhpCollectApicIds() intentionally populates both arrays in a single go. As I suggested earlier: https://lists.gnu.org/archive/html/qemu-devel/2020-11/msg06711.html msgid: > [...] please handle plugs first, for which unused slots in > mCpuHotPlugData.ApicId will be populated, and *then* handle removals > (in the same invocation of CpuHotplugMmi()). Did that turn out as unviable (the "same invocation of CpuHotplugMmi()" part)? (7) As a side note, addressing point (6) above would allow you to address my point (13) from the v5 patch#1 thread, too; i.e., nesting the Status check under (PluggedCount > 0). Thanks! Laszlo