From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.groups.io with SMTP id smtpd.web09.34483.1613997570910281429 for ; Mon, 22 Feb 2021 04:39:31 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=iIGwSDx0; spf=pass (domain: redhat.com, ip: 63.128.21.124, mailfrom: lersek@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613997570; 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=6hqVOhsBcK/aobPgFBFrBTVeD3QaLxw/lcuLwX2C4WY=; b=iIGwSDx0h6NRNhz0O9ugsKBLYmJqIZE619Yft0eVdq96X2fvDV00RSCkS2H4cRyebs+0MX 4mZt9Cn7fC6yP2ZTG9eTy0qloB77r21+xEvBYsQKC2FvhnWLjKVoMXXZbQ1w4IL6Lnl1Mc JcIatg7DTf1Esld26UhZlv7U6gwIzC8= 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-204-E9OLU6iBNqmRCepeqDu62w-1; Mon, 22 Feb 2021 07:39:27 -0500 X-MC-Unique: E9OLU6iBNqmRCepeqDu62w-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4DC27192AB7A; Mon, 22 Feb 2021 12:39:26 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-113-67.ams2.redhat.com [10.36.113.67]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7AC3310016F6; Mon, 22 Feb 2021 12:39:24 +0000 (UTC) Subject: Re: [edk2-devel] [PATCH v8 04/10] OvmfPkg/CpuHotplugSmm: introduce UnplugCpus() To: devel@edk2.groups.io, ankur.a.arora@oracle.com Cc: imammedo@redhat.com, boris.ostrovsky@oracle.com, Jordan Justen , Ard Biesheuvel , Aaron Young References: <20210222071928.1401820-1-ankur.a.arora@oracle.com> <20210222071928.1401820-5-ankur.a.arora@oracle.com> From: "Laszlo Ersek" Message-ID: <0cbe2d8d-573c-9c14-8edc-5763ba02f264@redhat.com> Date: Mon, 22 Feb 2021 13:39:23 +0100 MIME-Version: 1.0 In-Reply-To: <20210222071928.1401820-5-ankur.a.arora@oracle.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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 02/22/21 08:19, 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 > --- > > Notes: > Addresses these review comments from v6: > (1) Drop the empty line in the comment block around UnplugCpus(). > (2) Make the "did not find APIC ID" DEBUG_VERBOSE instead of DEBUG_INFO. > (3) Un-Indented ("Outdented") the line following the comment "Ignore the > unplug if APIC ID. > (4) Remove the empty line between Status assignment and check. > (5) Drop the "goto Fatal" logic and just return Status directly. > (6) Handle both Plugging and Unplugging of CPUs in one go. > (7) Also nest the EFI_STATUS check. > > OvmfPkg/CpuHotplugSmm/CpuHotplug.c | 84 ++++++++++++++++++++++++++++++++++++++ > 1 file changed, 84 insertions(+) > > diff --git a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c b/OvmfPkg/CpuHotplugSmm/CpuHotplug.c > index 3192bfea1f15..f07b5072749a 100644 > --- a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c > +++ b/OvmfPkg/CpuHotplugSmm/CpuHotplug.c > @@ -188,6 +188,83 @@ 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(). > +**/ > +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_VERBOSE, "%a: did not find APIC ID " FMT_APIC_ID > + " to unplug\n", __FUNCTION__, RemoveApicId)); > + ToUnplugIdx++; > + continue; > + } > + > + // > + // Mark ProcessorNum for removal from SMM data structures > + // > + Status = mMmCpuService->RemoveProcessor (mMmCpuService, ProcessorNum); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "%a: RemoveProcessor(" FMT_APIC_ID "): %r\n", > + __FUNCTION__, RemoveApicId, Status)); > + return Status; > + } > + > + ToUnplugIdx++; > + } > + > + // > + // We've removed this set of APIC IDs from SMM data structures. > + // > + return EFI_SUCCESS; > +} > + > +/** > CPU Hotplug MMI handler function. > > This is a root MMI handler. > @@ -309,6 +386,13 @@ CpuHotplugMmi ( > } > } > > + if (ToUnplugCount > 0) { > + Status = UnplugCpus (mToUnplugApicIds, ToUnplugCount); > + if (EFI_ERROR (Status)) { > + goto Fatal; > + } > + } > + > // > // We've handled this MMI. > // > Reviewed-by: Laszlo Ersek