mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Naveen N Rao <naveen@kernel.org>
To: x86@kernel.org
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>,  Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	 "H. Peter Anvin" <hpa@zytor.com>,
	linux-kernel@vger.kernel.org, Nikunj A Dadhania <nikunj@amd.com>,
	 Manali Shukla <manali.shukla@amd.com>,
	Bharata B Rao <bharata@amd.com>
Subject: Re: [PATCH 4/5] x86/apic: Introduce a variable to track the number of EILVT registers
Date: Wed, 8 Apr 2026 15:54:57 +0530	[thread overview]
Message-ID: <adYkgzSK1LgR5y8t@blrnaveerao1> (raw)
In-Reply-To: <6184174999bdd316b421aa2fd346276011b6900b.1775019269.git.naveen@kernel.org>

On Wed, Apr 01, 2026 at 10:26:35AM +0530, Naveen N Rao (AMD) wrote:
> Future AMD processors will be increasing the number of EILVT registers.
> Rather than hardcoding the maximum EILVT register count and using that
> everywhere, introduce a variable to track the EILVT register count.
> 
> The number of EILVT registers is exposed through the extended APIC
> Feature Register (APIC_EFEAT) bits 23:16. Use this to initialize the
> count and fall back to the current default (APIC_EILVT_NR_AMD_10H) if
> the count is not available.
> 
> Export the new variable for KVM since it needs this for supporting
> extended APIC register space on AMD.
> 
> Signed-off-by: Naveen N Rao (AMD) <naveen@kernel.org>
> Tested-by: Manali Shukla <manali.shukla@amd.com>
> ---
> http://lore.kernel.org/r/20260204074452.55453-3-manali.shukla@amd.com as 
> a related series adding support for KVM and needing access to the EILVT 
> register count.
> 

...

>  
> +static __init void init_eilvt(void)
> +{
> +	if (cpu_feature_enabled(X86_FEATURE_EXTAPIC))
> +		apic_eilvt_count = APIC_EFEAT_XLC(apic_read(APIC_EFEAT));
> +
> +	if (!apic_eilvt_count)
> +		apic_eilvt_count = APIC_EILVT_NR_AMD_10H;
> +}
> +
>  /*
>   * Program the next event, relative to now
>   */
> @@ -1644,6 +1655,9 @@ static void setup_local_APIC(void)
>  	if (!cpu)
>  		cmci_recheck();
>  #endif
> +
> +	if (!apic_eilvt_count)
> +		init_eilvt();
>  }

Kernel Test Robot (lkp@intel.com) reported that we will now be calling 
into an __init function from a non-init function. So, I'm thinking I 
should move this into apic_bsp_setup() instead:

diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
index 748e09c5b322..fc8be361e51a 100644
--- a/arch/x86/kernel/apic/apic.c
+++ b/arch/x86/kernel/apic/apic.c
@@ -1655,9 +1655,6 @@ static void setup_local_APIC(void)
        if (!cpu)
                cmci_recheck();
 #endif
-
-       if (!apic_eilvt_count)
-               init_eilvt();
 }

 static void end_local_APIC_setup(void)
@@ -2357,6 +2354,7 @@ static void __init apic_bsp_setup(bool upmode)
        if (upmode)
                apic_bsp_up_setup();
        setup_local_APIC();
+       init_eilvt();

        enable_IO_APIC();
        end_local_APIC_setup();


Since that is now only called on the BSP, we can also ensure that
apic_eilvt_count is only set on AMD processors (avoids having to 
allocate memory for eilvt_offsets otherwise):

diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
index ada963d90659..ca29be202d81 100644
--- a/arch/x86/kernel/apic/apic.c
+++ b/arch/x86/kernel/apic/apic.c
@@ -416,10 +416,10 @@ static __init void init_eilvt(void)
        if (cpu_feature_enabled(X86_FEATURE_EXTAPIC))
                apic_eilvt_count = APIC_EFEAT_XLC(apic_read(APIC_EFEAT));
 
-       if (!apic_eilvt_count)
+       if (!apic_eilvt_count && boot_cpu_data.x86_vendor == X86_VENDOR_AMD)
                apic_eilvt_count = APIC_EILVT_NR_AMD_10H;
 
-       if (!eilvt_offsets)
+       if (apic_eilvt_count)
                eilvt_offsets = kzalloc_objs(atomic_t, apic_eilvt_count);
 }
 

Thoughts?


- Naveen


  reply	other threads:[~2026-04-08 10:28 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-01  4:56 [PATCH 0/5] Support additional AMD " Naveen N Rao (AMD)
2026-04-01  4:56 ` [PATCH 1/5] x86/apic: Drop AMD Extended Interrupt LVT macros Naveen N Rao (AMD)
2026-04-03 23:06   ` [tip: x86/cleanups] " tip-bot2 for Naveen N Rao (AMD)
2026-04-01  4:56 ` [PATCH 2/5] x86/apic: Drop unused AMD EILVT macros Naveen N Rao (AMD)
2026-04-01  4:56 ` [PATCH 3/5] perf/amd/ibs: Limit the max EILVT register count for AMD family 0x10 Naveen N Rao (AMD)
2026-04-01  4:56 ` [PATCH 4/5] x86/apic: Introduce a variable to track the number of EILVT registers Naveen N Rao (AMD)
2026-04-08 10:24   ` Naveen N Rao [this message]
2026-04-01  4:56 ` [PATCH 5/5] x86/apic: Drop APIC_EILVT_NR_MAX and switch to using apic_eilvt_count Naveen N Rao (AMD)

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=adYkgzSK1LgR5y8t@blrnaveerao1 \
    --to=naveen@kernel.org \
    --cc=bharata@amd.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=manali.shukla@amd.com \
    --cc=mingo@redhat.com \
    --cc=nikunj@amd.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /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

all inboxes | Powered by JetHome®