Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jiangtian Feng" <jiangtianfeng@linux.alibaba.com>,
	catalin.marinas@arm.com, will@kernel.org,
	akpm@linux-foundation.org, rafael@kernel.org
Cc: mark.rutland@arm.com, james.morse@arm.com, robin.murphy@arm.com,
	nikumbh.adi@gmail.com, tony.luck@intel.com, guohanjun@huawei.com,
	mchehab@kernel.org, lenb@kernel.org, xueshuai@linux.alibaba.com,
	tongtiangen@huawei.com, tianruidong@linux.alibaba.com,
	tongweilin@linux.alibaba.com, baolin.wang@linux.alibaba.com,
	ashok.raj@oss.qualcomm.com, jonathan.cameron@oss.qualcomm.com,
	david@kernel.org, liam@infradead.org, vbabka@kernel.org,
	rppt@kernel.org, mhocko@suse.com, ljs@kernel.org,
	surenb@google.com, shivankg@amd.com, wangkefeng.wang@huawei.com,
	xiangzao@linux.alibaba.com, ying.huang@linux.alibaba.com,
	linmiaohe@huawei.com, nao.horiguchi@gmail.com, ziy@nvidia.com,
	tujinjiang@huawei.com, mgorman@techsingularity.net,
	kaitao.cheng@linux.dev, chengkaitao@kylinos.cn,
	muchun.song@linux.dev, nico.pache@linux.dev,
	ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org,
	lance.yang@linux.dev, usama.arif@linux.dev, kas@kernel.org,
	kees@kernel.org, andreyknvl@gmail.com, dvyukov@google.com,
	gli@kvack.org, der@google.com, ryabinin.a.a@gmail.com,
	vincenzo.frascino@arm.com, tglx@kernel.org, mingo@redhat.com,
	bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com,
	maddy@linux.ibm.com, mpe@ellerman.id.au, npiggin@gmail.com,
	chleroy@kernel.org, ritesh.list@gmail.com, sshegde@linux.ibm.com,
	aneesh.kumar@kernel.org, naveen.n.rao@linux.ibm.com,
	linux-mm@kvack.org, kasan-dev@googlegroups.com, x86@kernel.org
Subject: Re: [PATCH v16 2/9] ACPI: APEI: GHES: use exception context to gate SIGBUS on poison consumption
Date: Sun, 06 Dec 2026 01:26:16 +0000	[thread overview]
Message-ID: <sashiko-outbox-252029@kernel.org> (raw)
In-Reply-To: <20261205012435.1406255-3-jiangtianfeng@linux.alibaba.com>

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] ACPI: APEI: GHES_CTX_KERNEL defers SEA poisoning to async
  workqueue
- [Medium] ACPI: APEI: GHES: cached kernel SEA returns 0 without queuing
  work
- [Low] ACPI: APEI: commit message mismatches enum ghes_exec_ctx and
  reachability
- [Low] ACPI: APEI: GHES_CTX() double-evaluates, fails on NULL, lacks
  ptrace.h
--

commit 9312338f2bc24ddbc1ea6e4a8f429c087d02ab9f
Author: Ruidong Tian <tianruidong@linux.alibaba.com>

ACPI: APEI: GHES: use exception context to gate SIGBUS on poison consumption

This commit introduces an execution context enum and plumbs it from
apei_claim_sea() through GHES NMI-like spooling into memory failure
handling, so kernel-mode synchronous external aborts can avoid setting
MF_ACTION_REQUIRED or force-killing the current task with SIGBUS.

> Up to now ghes_handle_memory_failure() unconditionally promoted any
> synchronous recoverable memory error to MF_ACTION_REQUIRED, which
> ends up SIGBUS on current -- regardless of whether the poison was
> consumed from user space or from inside the kernel on the task's
> behalf. That kills tasks that should instead have seen a plain
> syscall error.

[ ... ]

> Introduce:
>
>     enum context { ... };
>
> and plumb the value all the way down to the queued estatus node:
>
>  * Add an 'enum context context' field to struct ghes_estatus_node
>    and record it in ghes_in_nmi_queue_one_entry().
>  * Extend ghes_notify_sea() and the internal
>    ghes_in_nmi_spool_from_list() with an enum context parameter.

[Severity: Low]
This isn't a bug, but the commit message refers to enum context three
times while the patch actually defines enum ghes_exec_ctx, and it omits
the new GHES_CTX() macro.

Also, at this commit do_sea() still checks user_mode(regs) before calling
apei_claim_sea(regs), so GHES_CTX_KERNEL is not yet reachable.  Describing
this as preparatory work rather than a currently reachable bug would match
the tree state.

> diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
> index 5d888c82efeaa..eb4466aa87f25 100644
> --- a/drivers/acpi/apei/ghes.c
> +++ b/drivers/acpi/apei/ghes.c
> @@ -543,7 +543,7 @@ static bool ghes_handle_memory_failure(struct acpi_hest_generic_data *gdata,
>  	    (gdata->flags & CPER_SEC_ERROR_THRESHOLD_EXCEEDED))
>  		flags = MF_SOFT_OFFLINE;
>  	if (sev == GHES_SEV_RECOVERABLE && sec_sev == GHES_SEV_RECOVERABLE)
> -		flags = sync ? MF_ACTION_REQUIRED : 0;
> +		flags = sync && context != GHES_CTX_KERNEL ? MF_ACTION_REQUIRED : 0;
>  
>  	if (flags != -1)
>  		return ghes_do_memory_failure(mem_err->physical_addr, flags);
> @@ -552,10 +552,10 @@ static bool ghes_handle_memory_failure(struct acpi_hest_generic_data *gdata,
>  }
>  
>  static bool ghes_handle_arm_hw_error(struct acpi_hest_generic_data *gdata,
> -				     int sev, bool sync)
> +				     int sev, bool sync, enum ghes_exec_ctx context)
>  {
>  	struct cper_sec_proc_arm *err = acpi_hest_get_payload(gdata);
> -	int flags = sync ? MF_ACTION_REQUIRED : 0;
> +	int flags = sync && context != GHES_CTX_KERNEL ? MF_ACTION_REQUIRED : 0;

[Severity: Medium]
Does clearing MF_ACTION_REQUIRED for GHES_CTX_KERNEL inadvertently defer
page poisoning to the asynchronous workqueue?

ghes_do_memory_failure() only queues synchronous TWA_RESUME task_work when
flags == MF_ACTION_REQUIRED && current->mm, so passing flags = 0 falls
through to memory_failure_queue(pfn, 0).  When a kernel copy helper such as
copy_from_user() recovers via its extable fixup and returns -EFAULT, the
task can return to userspace before the kworker runs, while the poisoned
page is still mapped and unpoisoned.

In that window, the task can munmap() or exit and return the poisoned page
to the allocator for another task or the kernel to consume, or re-access it
and hit the 10-second ghes_estatus_cached() entry just added by
ghes_proc_in_irq().  Gating task_work_add() on sync && current->mm while
gating the SIGBUS delivery in memory_failure_cb() on MF_ACTION_REQUIRED
would keep poisoning synchronous before returning to userspace while still
suppressing SIGBUS for GHES_CTX_KERNEL.

[ ... ]

> @@ -1452,11 +1456,10 @@ static int ghes_in_nmi_queue_one_entry(struct ghes *ghes,
>  	/* This error has been reported before, don't process it again. */
>  	if (ghes_estatus_cached(estatus)) {
>  		/*
> -		 * Return failure on duplicate SEA entries so that the
> -		 * subsequent SEA handler invocation sends a SIGBUS signal to
> -		 * the task to prevent it from re-entering the handler loop.
> +		 * Kernel copies must still reach their fixup; retain duplicate
> +		 * SEA anti-storm handling for user and KVM/NA paths.
>  		 */
> -		if (is_hest_sync_notify(ghes))
> +		if (is_hest_sync_notify(ghes) && context != GHES_CTX_KERNEL)
>  			rc = -ECANCELED;
>  		goto no_work;
>  	}
> @@ -1473,14 +1476,15 @@ static int ghes_in_nmi_queue_one_entry(struct ghes *ghes,
>  }
>  
>  static int __maybe_unused ghes_in_nmi_spool_from_list(struct list_head *rcu_list,
> -			       enum fixed_addresses fixmap_idx)
> +			       enum fixed_addresses fixmap_idx,
> +			       enum ghes_exec_ctx context)
>  {
>  	int ret = -ENOENT;
>  	struct ghes *ghes;
>  
>  	rcu_read_lock();
>  	list_for_each_entry_rcu(ghes, rcu_list, list) {
> -		if (!ghes_in_nmi_queue_one_entry(ghes, fixmap_idx))
> +		if (!ghes_in_nmi_queue_one_entry(ghes, fixmap_idx, context))
>  			ret = 0;
>  	}
>  	rcu_read_unlock();

[Severity: Medium]
Can returning 0 from the cached no_work path break duplicate kernel SEA
recovery when IRQs are disabled?

For a cached GHES_CTX_KERNEL record, ghes_in_nmi_queue_one_entry() frees
estatus_node without adding it to ghes_estatus_llist, yet returns 0.
ghes_in_nmi_spool_from_list() then treats that 0 as queued work, calls
irq_work_queue(&ghes_proc_irq_work) on an empty list, and returns 0 to
apei_claim_sea().

If the duplicate SEA hits an IRQ-disabled kernel copy such as
__copy_from_user_inatomic() in unwind_user_frame() during a perf PMU IRQ,
apei_claim_sea() assumes queued work could not run, logs "APEI work queued
but not completed", and returns -EINPROGRESS.  With commit "arm64: enable
recover from synchronous external abort in kernel context",
do_apei_claim_sea() then skips fixup_exception_me() and do_sea() falls
through to arm64_notify_die(), turning a recoverable duplicate copy into a
fatal exception.  Even with IRQs enabled, it still triggers a spurious
irq_work_queue() and irq_work_run().

Distinguishing "claimed, already cached" from "claimed, work queued" across
ghes_in_nmi_queue_one_entry(), ghes_in_nmi_spool_from_list(), and
ghes_notify_sea() would avoid both the empty irq_work and the false
-EINPROGRESS.

> diff --git a/include/acpi/ghes.h b/include/acpi/ghes.h
> index 7acf209061ea7..2cd97f7002140 100644
> --- a/include/acpi/ghes.h
> +++ b/include/acpi/ghes.h
> @@ -33,10 +33,21 @@ struct ghes {
>  	void __iomem *error_status_vaddr;
>  };
>  
> +enum ghes_exec_ctx {
> +	GHES_CTX_NA = -1,
> +	GHES_CTX_KERNEL = 0,
> +	GHES_CTX_USER = 1
> +};
> +
> +#define GHES_CTX(regs)	((regs) ? (user_mode(regs) ? GHES_CTX_USER \
> +						   : GHES_CTX_KERNEL) \
> +				: GHES_CTX_NA)

[Severity: Low]
Should GHES_CTX() be a static inline helper instead of a macro?

As written, it evaluates regs twice when non-NULL, fails to compile if a
caller passes literal NULL because user_mode(NULL) dereferences void *, and
relies on callers transitively including ptrace.h for user_mode().  A
static inline helper taking const struct pt_regs *regs (with ptrace.h
included, or kept local to arch/arm64/kernel/acpi.c) avoids all three.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261205012435.1406255-1-jiangtianfeng@linux.alibaba.com?part=2


  reply	other threads:[~2026-12-06  1:26 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-05  1:24 [PATCH v16 0/9] arm64: add ARCH_HAS_COPY_MC support Jiangtian Feng
2026-12-05  1:24 ` [PATCH v16 1/9] uaccess: add generic fallback version of copy_mc_to_user() Jiangtian Feng
2026-12-06  1:26   ` sashiko-bot
2026-12-05  1:24 ` [PATCH v16 2/9] ACPI: APEI: GHES: use exception context to gate SIGBUS on poison consumption Jiangtian Feng
2026-12-06  1:26   ` sashiko-bot [this message]
2026-12-05  1:24 ` [PATCH v16 3/9] arm64: extable: merge UACCESS_ERR_ZERO and KACCESS_ERR_ZERO into ACCESS_ERR_ZERO Jiangtian Feng
2026-12-06  1:26   ` sashiko-bot
2026-12-05  1:24 ` [PATCH v16 4/9] arm64: enable recover from synchronous external abort in kernel context Jiangtian Feng
2026-12-06  1:26   ` sashiko-bot
2026-12-05  1:24 ` [PATCH v16 5/9] mm/hwpoison: return -EFAULT when copy fail in copy_mc_[user]_highpage() Jiangtian Feng
2026-12-05  1:24 ` [PATCH v16 6/9] arm64: support copy_mc_[user]_highpage() Jiangtian Feng
2026-12-06  1:26   ` sashiko-bot
2026-12-05  1:24 ` [PATCH v16 7/9] arm64: introduce copy_mc_to_kernel() implementation Jiangtian Feng
2026-12-06  1:26   ` sashiko-bot
2026-12-05  1:24 ` [PATCH v16 8/9] lib/test: memcpy_kunit: add copy_page() and copy_mc_page() tests Jiangtian Feng
2026-12-06  1:26   ` sashiko-bot
2026-12-05  1:24 ` [PATCH v16 9/9] lib/tests: memcpy_kunit: add memcpy_mc() and memcpy_mc_large() test Jiangtian Feng
2026-12-06  1:26   ` sashiko-bot

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=sashiko-outbox-252029@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=andreyknvl@gmail.com \
    --cc=aneesh.kumar@kernel.org \
    --cc=ashok.raj@oss.qualcomm.com \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=bp@alien8.de \
    --cc=catalin.marinas@arm.com \
    --cc=chengkaitao@kylinos.cn \
    --cc=chleroy@kernel.org \
    --cc=dave.hansen@linux.intel.com \
    --cc=david@kernel.org \
    --cc=der@google.com \
    --cc=dev.jain@arm.com \
    --cc=dvyukov@google.com \
    --cc=gli@kvack.org \
    --cc=guohanjun@huawei.com \
    --cc=hpa@zytor.com \
    --cc=james.morse@arm.com \
    --cc=jiangtianfeng@linux.alibaba.com \
    --cc=jonathan.cameron@oss.qualcomm.com \
    --cc=kaitao.cheng@linux.dev \
    --cc=kas@kernel.org \
    --cc=kasan-dev@googlegroups.com \
    --cc=kees@kernel.org \
    --cc=lance.yang@linux.dev \
    --cc=lenb@kernel.org \
    --cc=liam@infradead.org \
    --cc=linmiaohe@huawei.com \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=maddy@linux.ibm.com \
    --cc=mark.rutland@arm.com \
    --cc=mchehab@kernel.org \
    --cc=mgorman@techsingularity.net \
    --cc=mhocko@suse.com \
    --cc=mingo@redhat.com \
    --cc=mpe@ellerman.id.au \
    --cc=muchun.song@linux.dev \
    --cc=nao.horiguchi@gmail.com \
    --cc=naveen.n.rao@linux.ibm.com \
    --cc=nico.pache@linux.dev \
    --cc=nikumbh.adi@gmail.com \
    --cc=npiggin@gmail.com \
    --cc=rafael@kernel.org \
    --cc=ritesh.list@gmail.com \
    --cc=robin.murphy@arm.com \
    --cc=rppt@kernel.org \
    --cc=ryabinin.a.a@gmail.com \
    --cc=ryan.roberts@arm.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=shivankg@amd.com \
    --cc=sshegde@linux.ibm.com \
    --cc=surenb@google.com \
    --cc=tglx@kernel.org \
    --cc=tianruidong@linux.alibaba.com \
    --cc=tongtiangen@huawei.com \
    --cc=tongweilin@linux.alibaba.com \
    --cc=tony.luck@intel.com \
    --cc=tujinjiang@huawei.com \
    --cc=usama.arif@linux.dev \
    --cc=vbabka@kernel.org \
    --cc=vincenzo.frascino@arm.com \
    --cc=wangkefeng.wang@huawei.com \
    --cc=will@kernel.org \
    --cc=x86@kernel.org \
    --cc=xiangzao@linux.alibaba.com \
    --cc=xueshuai@linux.alibaba.com \
    --cc=ying.huang@linux.alibaba.com \
    --cc=ziy@nvidia.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