Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Yunhui Cui" <cuiyunhui@bytedance.com>
Cc: devicetree@vger.kernel.org, conor+dt@kernel.org, robh@kernel.org
Subject: Re: [PATCH v4 2/3] riscv: track effective hardware PTE A/D updating
Date: Thu, 18 Jun 2026 07:02:14 +0000	[thread overview]
Message-ID: <20260618070215.268ED1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260618064406.14508-3-cuiyunhui@bytedance.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] A hotplugged CPU lacking the Svadu extension is incorrectly allowed to come online when hardware PTE A/D updating is globally enabled but FWFT is not required, leading to silent data corruption.
--

commit e238566a69f2ecd235872518a759dd75d54f71af
Author: Yunhui Cui <cuiyunhui@bytedance.com>

riscv: track effective hardware PTE A/D updating

This commit tracks the runtime state of hardware PTE A/D updating using a
static key. It attempts to enable FWFT for all online harts, falling back
to software A/D if that fails, and ensures hotplugged CPUs match the global
state before coming online.

> diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c
> --- a/arch/riscv/kernel/cpufeature.c
> +++ b/arch/riscv/kernel/cpufeature.c

[ ... ]

> +int riscv_enable_hw_pte_ad_updating(void)
> +{
> +	unsigned int cpu;
> +	int ret;
> +
> +	if (!riscv_has_hw_pte_ad_updating() ||
> +	    !riscv_hw_pte_ad_updating_requires_fwft)
> +		return 0;

[Severity: High]
Does this code allow a hotplugged CPU to come online without the Svadu
extension when hardware A/D updating is globally enabled?

If the boot CPUs have Svadu but lack Svade, the flag
riscv_hw_pte_ad_updating_requires_fwft is set to false and the global
static key riscv_hw_pte_ad_updating is enabled.

When a new CPU is later hotplugged, it calls this function via
smp_callin(). Since riscv_hw_pte_ad_updating_requires_fwft is false, it
returns 0 and bypasses any capability checks for the local CPU.

If the hotplugged CPU does not actually support Svadu (e.g., in an
asymmetric SoC or due to firmware misconfiguration), it successfully
comes online. Because the kernel globally assumes hardware A/D updating
is active, it skips software A/D fault handling.

Could this lead to the hotplugged CPU silently failing to update
accessed/dirty bits, causing data corruption when dirty data is dropped
during reclaim?

> +
> +	cpu = smp_processor_id();
> +	ret = riscv_enable_local_hw_pte_ad_updating();
> +	if (ret)
> +		pr_err("CPU%u failed to enable hardware PTE A/D updating: %d\n",
> +		       cpu, ret);
> +
> +	return ret;
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260618064406.14508-1-cuiyunhui@bytedance.com?part=2

  reply	other threads:[~2026-06-18  7:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-18  6:44 [PATCH v4 0/3] riscv: support effective hardware PTE A/D updates Yunhui Cui
2026-06-18  6:44 ` [PATCH v4 1/3] dt-bindings: riscv: describe Svadu as disabled at boot Yunhui Cui
2026-06-18  6:44 ` [PATCH v4 2/3] riscv: track effective hardware PTE A/D updating Yunhui Cui
2026-06-18  7:02   ` sashiko-bot [this message]
2026-06-18  8:53     ` [External] " yunhui cui
2026-06-18  6:44 ` [PATCH v4 3/3] riscv: preserve A/D and soft-dirty state across PTE updates Yunhui Cui

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=20260618070215.268ED1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=cuiyunhui@bytedance.com \
    --cc=devicetree@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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