Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Jinjie Ruan <ruanjinjie@huawei.com>
To: Will Deacon <will@kernel.org>
Cc: <catalin.marinas@arm.com>, <tsbogend@alpha.franken.de>,
	<tglx@kernel.org>, <mingo@redhat.com>, <bp@alien8.de>,
	<dave.hansen@linux.intel.com>, <hpa@zytor.com>,
	<peterz@infradead.org>, <kees@kernel.org>, <nathan@kernel.org>,
	<linusw@kernel.org>, <ojeda@kernel.org>, <david.kaplan@amd.com>,
	<lukas.bulwahn@redhat.com>, <ryan.roberts@arm.com>,
	<maz@kernel.org>, <timothy.hayes@arm.com>,
	<lpieralisi@kernel.org>, <thuth@redhat.com>,
	<menglong8.dong@gmail.com>, <oupton@kernel.org>,
	<yeoreum.yun@arm.com>, <miko.lenczewski@arm.com>,
	<broonie@kernel.org>, <kevin.brodsky@arm.com>,
	<james.clark@linaro.org>, <yangyicong@hisilicon.com>,
	<tabba@google.com>, <osandov@fb.com>, <arnd@arndb.de>,
	<anshuman.khandual@arm.com>, <david@kernel.org>,
	<akpm@linux-foundation.org>, <ljs@kernel.org>, <dev.jain@arm.com>,
	<yang@os.amperecomputing.com>, <chaitanyas.prakash@arm.com>,
	<kprateek.nayak@amd.com>, <chenl311@chinatelecom.cn>,
	<sshegde@linux.ibm.com>, <thorsten.blum@linux.dev>,
	<chang.seok.bae@intel.com>, <tim.c.chen@linux.intel.com>,
	<x86@kernel.org>, <linux-kernel@vger.kernel.org>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-mips@vger.kernel.org>
Subject: Re: [PATCH v3 09/12] arm64: cpufeature: Ensure atomic updates to system_cpucaps bitmap
Date: Wed, 8 Jul 2026 18:01:04 +0800	[thread overview]
Message-ID: <3501828e-7dd4-4587-b29a-71eabcc05ab8@huawei.com> (raw)
In-Reply-To: <akvooksAvkmG971U@willie-the-truck>



On 7/7/2026 1:40 AM, Will Deacon wrote:
> On Wed, Jun 24, 2026 at 05:25:34PM +0800, Jinjie Ruan wrote:
>> Parallel CPU bringup allows multiple secondary CPUs to concurrently
>> execute update_cpu_capabilities() during early boot.
>>
>> The current non-atomic __set_bit() and __clear_bit() helpers perform
>> unserialized updates on the shared global bitmap, risking data races
>> and feature flag erasure.
>>
>> Upgrade these operations to set_bit() and clear_bit() to ensure all
>> concurrent modifications are properly serialized via arm64 atomics.
>>
>> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
>> ---
>>  arch/arm64/kernel/cpufeature.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c
>> index be75e60d56ca..a1a13f3e01ed 100644
>> --- a/arch/arm64/kernel/cpufeature.c
>> +++ b/arch/arm64/kernel/cpufeature.c
>> @@ -3548,7 +3548,7 @@ static void update_cpu_capabilities(u16 scope_mask)
>>  
>>  		if (!caps->matches(caps, cpucap_default_scope(caps))) {
>>  			if (match_all)
>> -				__clear_bit(caps->capability, system_cpucaps);
>> +				clear_bit(caps->capability, system_cpucaps);
>>  			continue;
>>  		}
>>  
>> @@ -3559,7 +3559,7 @@ static void update_cpu_capabilities(u16 scope_mask)
>>  		if (!match_all && caps->desc && !caps->cpus)
>>  			pr_info("detected: %s\n", caps->desc);
>>  
>> -		__set_bit(caps->capability, system_cpucaps);
>> +		set_bit(caps->capability, system_cpucaps);
>>  
>>  		if (boot_cpu && (caps->type & SCOPE_BOOT_CPU))
>>  			set_bit(caps->capability, boot_cpucaps);
> 
> I don't think this is sufficient. Even if we use atomic updates for the
> low-level bits, the logic here which tries to avoid re-probing features
> that have already been detected isn't going to work correctly if it's
> running concurrently with itself.
> 
> I think the best bet is probably to move update_cpu_capabilities() out
> of check_local_cpu_capabilities() and call it after cpuhp_ap_sync_alive()
> when the system capabilities are not yet finalised. WDYT? That means
> we'd have something akin to setup_boot_cpu_features() for the secondary
> CPUs.

This approach most thoroughly avoids concurrency issues, as after
cpuhp_ap_sync_alive(), the secondary CPUs are woken up serially by the
boot CPU.

It also eliminates the problem of boot CPUs being stuck in deadlock wait
for the secondary CPUs, because update_cpu_capabilities() does not call
cpu_die_early() or cpu_panic_kernel().

Is it similar to the following code?

diff --git a/arch/arm64/include/asm/cpufeature.h
b/arch/arm64/include/asm/cpufeature.h
index 6c95227032b0..33185527aea9 100644
--- a/arch/arm64/include/asm/cpufeature.h
+++ b/arch/arm64/include/asm/cpufeature.h
@@ -651,6 +651,7 @@ void __init setup_system_features(void);
 void __init setup_user_features(void);

 void check_local_cpu_capabilities(void);
+void setup_secondary_cpu_capabilities(void);

 u64 read_sanitised_ftr_reg(u32 id);
 u64 __read_sysreg_by_encoding(u32 sys_id);
diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c
index e3110a572bc8..4d106d90adb0 100644
--- a/arch/arm64/kernel/cpufeature.c
+++ b/arch/arm64/kernel/cpufeature.c
@@ -3859,6 +3859,12 @@ void check_local_cpu_capabilities(void)
         */
        check_early_cpu_features();

+       if (system_capabilities_finalized())
+               verify_local_cpu_capabilities();
+}
+
+void setup_secondary_cpu_capabilities(void)
+{
        /*
         * If we haven't finalised the system capabilities, this CPU gets
         * a chance to update the errata work arounds and local features.
@@ -3867,8 +3873,6 @@ void check_local_cpu_capabilities(void)
         */
        if (!system_capabilities_finalized())
                update_cpu_capabilities(SCOPE_LOCAL_CPU);
-       else
-               verify_local_cpu_capabilities();
 }

 bool this_cpu_has_cap(unsigned int n)
diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c
index fd824b96ab19..7d4c369fa090 100644
--- a/arch/arm64/kernel/smp.c
+++ b/arch/arm64/kernel/smp.c
@@ -243,6 +243,7 @@ asmlinkage notrace void secondary_start_kernel(void)
         * we made it into the kernel. We're still not 'online'.
         */
        cpuhp_ap_sync_alive();
+       setup_secondary_cpu_capabilities();

        update_cpu_features(cpu);
        store_cpu_topology(cpu);


> 
> Will



  parent reply	other threads:[~2026-07-08 10:01 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-24  9:25 [PATCH v3 00/12] arm64: Add HOTPLUG_PARALLEL support for secondary CPUs Jinjie Ruan
2026-06-24  9:25 ` [PATCH v3 01/12] cpu/hotplug: Introduce CONFIG_HOTPLUG_PARALLEL_SMT Jinjie Ruan
2026-06-24  9:25 ` [PATCH v3 02/12] cpu/hotplug: Propagate bring-up status to arch_cpuhp_cleanup_kick_cpu() Jinjie Ruan
2026-06-24  9:25 ` [PATCH v3 03/12] arm64: smp: Tidy up smp_prepare_cpus() Jinjie Ruan
2026-06-24  9:25 ` [PATCH v3 04/12] arm64: smp: Tidy up cpuinfo init and cpufeature updates Jinjie Ruan
2026-06-24  9:25 ` [PATCH v3 05/12] arm64: smp: Defer RCU registration during secondary CPU bringup Jinjie Ruan
2026-07-06 17:39   ` Will Deacon
2026-07-07  3:02     ` Jinjie Ruan
2026-07-07 10:27       ` Will Deacon
2026-07-08  9:13         ` Jinjie Ruan
2026-06-24  9:25 ` [PATCH v3 06/12] arm64: smp: Use generic HOTPLUG_SPLIT_STARTUP machinery for CPU onlining Jinjie Ruan
2026-06-24  9:25 ` [PATCH v3 07/12] arm64: cpu_ops: Make 'cpu_operations' pointer global instead of per-cpu Jinjie Ruan
2026-06-24  9:25 ` [PATCH v3 08/12] arm64: cpu_ops: Introduce get_secondary_cpu_ops() Jinjie Ruan
2026-06-24  9:25 ` [PATCH v3 09/12] arm64: cpufeature: Ensure atomic updates to system_cpucaps bitmap Jinjie Ruan
2026-07-06 17:40   ` Will Deacon
2026-07-07  3:24     ` Jinjie Ruan
2026-07-08 10:01     ` Jinjie Ruan [this message]
2026-06-24  9:25 ` [PATCH v3 10/12] arm64: smp: Pass CPU ID to update_cpu_boot_status() Jinjie Ruan
2026-06-24  9:25 ` [PATCH v3 11/12] arm64: smp: Rework early boot data into per-CPU arrays Jinjie Ruan
2026-06-24  9:25 ` [PATCH v3 12/12] arm64: Add HOTPLUG_PARALLEL support for secondary CPUs Jinjie Ruan
2026-07-07  4:00   ` Jinjie Ruan
2026-07-07 10:30     ` Will Deacon
2026-06-24 12:16 ` [PATCH v3 00/12] " Will Deacon
2026-06-24 14:59   ` Borislav Petkov
2026-06-25  1:34   ` Jinjie Ruan
2026-07-06 17:39     ` Will Deacon
2026-07-07  8:14       ` Jinjie Ruan
2026-07-07 10:37         ` Will Deacon
2026-07-08  9:36           ` Jinjie Ruan
2026-06-29  4:04 ` Shrikanth Hegde

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=3501828e-7dd4-4587-b29a-71eabcc05ab8@huawei.com \
    --to=ruanjinjie@huawei.com \
    --cc=akpm@linux-foundation.org \
    --cc=anshuman.khandual@arm.com \
    --cc=arnd@arndb.de \
    --cc=bp@alien8.de \
    --cc=broonie@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=chaitanyas.prakash@arm.com \
    --cc=chang.seok.bae@intel.com \
    --cc=chenl311@chinatelecom.cn \
    --cc=dave.hansen@linux.intel.com \
    --cc=david.kaplan@amd.com \
    --cc=david@kernel.org \
    --cc=dev.jain@arm.com \
    --cc=hpa@zytor.com \
    --cc=james.clark@linaro.org \
    --cc=kees@kernel.org \
    --cc=kevin.brodsky@arm.com \
    --cc=kprateek.nayak@amd.com \
    --cc=linusw@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=ljs@kernel.org \
    --cc=lpieralisi@kernel.org \
    --cc=lukas.bulwahn@redhat.com \
    --cc=maz@kernel.org \
    --cc=menglong8.dong@gmail.com \
    --cc=miko.lenczewski@arm.com \
    --cc=mingo@redhat.com \
    --cc=nathan@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=osandov@fb.com \
    --cc=oupton@kernel.org \
    --cc=peterz@infradead.org \
    --cc=ryan.roberts@arm.com \
    --cc=sshegde@linux.ibm.com \
    --cc=tabba@google.com \
    --cc=tglx@kernel.org \
    --cc=thorsten.blum@linux.dev \
    --cc=thuth@redhat.com \
    --cc=tim.c.chen@linux.intel.com \
    --cc=timothy.hayes@arm.com \
    --cc=tsbogend@alpha.franken.de \
    --cc=will@kernel.org \
    --cc=x86@kernel.org \
    --cc=yang@os.amperecomputing.com \
    --cc=yangyicong@hisilicon.com \
    --cc=yeoreum.yun@arm.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