Virtuozzo QEMU development (svt-core@virtuozzo.com)
 help / color / mirror / Atom feed
From: "Denis V. Lunev" <den@openvz.org>
To: svt-core@virtuozzo.com
Cc: andrey.drobyshev@virtuozzo.com, "Denis V. Lunev" <den@openvz.org>
Subject: [PATCH 1/2] UefiCpuPkg: add SendStartupIpi to LocalApicLib #VSTOR-146639
Date: Mon, 21 Sep 2026 17:44:05 +0200	[thread overview]
Message-ID: <20260921154406.1628753-2-den@openvz.org> (raw)
In-Reply-To: <20260921154406.1628753-1-den@openvz.org>

From: Denis V. Lunev <den@openvz.org>

The library can send a Start-up IPI to all processors excluding self,
or an INIT-SIPI-SIPI sequence to one processor, but it cannot send a
bare Start-up IPI to one processor. SendInitSipiSipi builds that ICR
inline instead.

Export it, and build SendInitSipiSipi on top of it. A caller that has
to poke a single AP now has a way to do so without an INIT, which
would reset an AP that had already started.

No functional change.

Signed-off-by: Denis V. Lunev <den@openvz.org>
Cc: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
---
 UefiCpuPkg/Include/Library/LocalApicLib.h     | 19 +++++++++++
 .../Library/BaseXApicLib/BaseXApicLib.c       | 32 ++++++++++++++++---
 .../BaseXApicX2ApicLib/BaseXApicX2ApicLib.c   | 32 ++++++++++++++++---
 3 files changed, 73 insertions(+), 10 deletions(-)

diff --git a/UefiCpuPkg/Include/Library/LocalApicLib.h b/UefiCpuPkg/Include/Library/LocalApicLib.h
index d7c2ad3f70..6c55ed75cc 100644
--- a/UefiCpuPkg/Include/Library/LocalApicLib.h
+++ b/UefiCpuPkg/Include/Library/LocalApicLib.h
@@ -200,6 +200,25 @@ SendStartupIpiAllExcludingSelf (
   IN UINT32  StartupRoutine
   );
 
+/**
+  Send a Start-up IPI to a specified target processor.
+
+  This function returns after the IPI has been accepted by the target processor.
+
+  if StartupRoutine >= 1M, then ASSERT.
+  if StartupRoutine is not multiple of 4K, then ASSERT.
+
+  @param  ApicId          Specify the local APIC ID of the target processor.
+  @param  StartupRoutine  Points to a start-up routine which is below 1M physical
+                          address and 4K aligned.
+**/
+VOID
+EFIAPI
+SendStartupIpi (
+  IN UINT32  ApicId,
+  IN UINT32  StartupRoutine
+  );
+
 /**
   Send an INIT-Start-up-Start-up IPI sequence to a specified target processor.
 
diff --git a/UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.c b/UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.c
index 9767e3b48e..2f2d31333a 100644
--- a/UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.c
+++ b/UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.c
@@ -525,7 +525,7 @@ SendStartupIpiAllExcludingSelf (
 }
 
 /**
-  Send an INIT-Start-up-Start-up IPI sequence to a specified target processor.
+  Send a Start-up IPI to a specified target processor.
 
   This function returns after the IPI has been accepted by the target processor.
 
@@ -538,7 +538,7 @@ SendStartupIpiAllExcludingSelf (
 **/
 VOID
 EFIAPI
-SendInitSipiSipi (
+SendStartupIpi (
   IN UINT32  ApicId,
   IN UINT32  StartupRoutine
   )
@@ -548,16 +548,38 @@ SendInitSipiSipi (
   ASSERT (StartupRoutine < 0x100000);
   ASSERT ((StartupRoutine & 0xfff) == 0);
 
-  SendInitIpi (ApicId);
-  MicroSecondDelay (PcdGet32 (PcdCpuInitIpiDelayInMicroSeconds));
   IcrLow.Uint32            = 0;
   IcrLow.Bits.Vector       = (StartupRoutine >> 12);
   IcrLow.Bits.DeliveryMode = LOCAL_APIC_DELIVERY_MODE_STARTUP;
   IcrLow.Bits.Level        = 1;
   SendIpi (IcrLow.Uint32, ApicId);
+}
+
+/**
+  Send an INIT-Start-up-Start-up IPI sequence to a specified target processor.
+
+  This function returns after the IPI has been accepted by the target processor.
+
+  if StartupRoutine >= 1M, then ASSERT.
+  if StartupRoutine is not multiple of 4K, then ASSERT.
+
+  @param  ApicId          Specify the local APIC ID of the target processor.
+  @param  StartupRoutine  Points to a start-up routine which is below 1M physical
+                          address and 4K aligned.
+**/
+VOID
+EFIAPI
+SendInitSipiSipi (
+  IN UINT32  ApicId,
+  IN UINT32  StartupRoutine
+  )
+{
+  SendInitIpi (ApicId);
+  MicroSecondDelay (PcdGet32 (PcdCpuInitIpiDelayInMicroSeconds));
+  SendStartupIpi (ApicId, StartupRoutine);
   if (!StandardSignatureIsAuthenticAMD ()) {
     MicroSecondDelay (200);
-    SendIpi (IcrLow.Uint32, ApicId);
+    SendStartupIpi (ApicId, StartupRoutine);
   }
 }
 
diff --git a/UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.c b/UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.c
index 7fa997c882..d4db452a80 100644
--- a/UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.c
+++ b/UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.c
@@ -764,7 +764,7 @@ SendStartupIpiAllExcludingSelf (
 }
 
 /**
-  Send an INIT-Start-up-Start-up IPI sequence to a specified target processor.
+  Send a Start-up IPI to a specified target processor.
 
   This function returns after the IPI has been accepted by the target processor.
 
@@ -777,7 +777,7 @@ SendStartupIpiAllExcludingSelf (
 **/
 VOID
 EFIAPI
-SendInitSipiSipi (
+SendStartupIpi (
   IN UINT32  ApicId,
   IN UINT32  StartupRoutine
   )
@@ -787,16 +787,38 @@ SendInitSipiSipi (
   ASSERT (StartupRoutine < 0x100000);
   ASSERT ((StartupRoutine & 0xfff) == 0);
 
-  SendInitIpi (ApicId);
-  MicroSecondDelay (PcdGet32 (PcdCpuInitIpiDelayInMicroSeconds));
   IcrLow.Uint32            = 0;
   IcrLow.Bits.Vector       = (StartupRoutine >> 12);
   IcrLow.Bits.DeliveryMode = LOCAL_APIC_DELIVERY_MODE_STARTUP;
   IcrLow.Bits.Level        = 1;
   SendIpi (IcrLow.Uint32, ApicId);
+}
+
+/**
+  Send an INIT-Start-up-Start-up IPI sequence to a specified target processor.
+
+  This function returns after the IPI has been accepted by the target processor.
+
+  if StartupRoutine >= 1M, then ASSERT.
+  if StartupRoutine is not multiple of 4K, then ASSERT.
+
+  @param  ApicId          Specify the local APIC ID of the target processor.
+  @param  StartupRoutine  Points to a start-up routine which is below 1M physical
+                          address and 4K aligned.
+**/
+VOID
+EFIAPI
+SendInitSipiSipi (
+  IN UINT32  ApicId,
+  IN UINT32  StartupRoutine
+  )
+{
+  SendInitIpi (ApicId);
+  MicroSecondDelay (PcdGet32 (PcdCpuInitIpiDelayInMicroSeconds));
+  SendStartupIpi (ApicId, StartupRoutine);
   if (!StandardSignatureIsAuthenticAMD ()) {
     MicroSecondDelay (200);
-    SendIpi (IcrLow.Uint32, ApicId);
+    SendStartupIpi (ApicId, StartupRoutine);
   }
 }
 
-- 
2.53.0


  reply	other threads:[~2026-09-21 15:44 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-21 15:44 [PATCH 0/2] UefiCpuPkg/MpInitLib: recover from a lost Start-up IPI #VSTOR-146639 Denis V. Lunev
2026-09-21 15:44 ` Denis V. Lunev [this message]
2026-09-23 13:30   ` [PATCH 1/2] UefiCpuPkg: add SendStartupIpi to LocalApicLib #VSTOR-146639 Andrey Drobyshev
2026-09-21 15:44 ` [PATCH 2/2] UefiCpuPkg/MpInitLib: resend the Start-up IPI when an AP misses it #VSTOR-146639 Denis V. Lunev
2026-09-23 13:30   ` Andrey Drobyshev
2026-09-23 13:30 ` [PATCH 0/2] UefiCpuPkg/MpInitLib: recover from a lost Start-up IPI #VSTOR-146639 Andrey Drobyshev
2026-09-23 13:30   ` Denis V. Lunev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260921154406.1628753-2-den@openvz.org \
    --to=den@openvz.org \
    --cc=andrey.drobyshev@virtuozzo.com \
    --cc=svt-core@virtuozzo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox