All of lore.kernel.org
 help / color / mirror / Atom feed
From: JunYoung Lee <ljyoung04@gmail.com>
To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org,
	namhyung@kernel.org
Cc: mark.rutland@arm.com, alexander.shishkin@linux.intel.com,
	jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com,
	james.clark@linaro.org, linux-perf-users@vger.kernel.org,
	linux-kernel@vger.kernel.org, JunYoung Lee <ljyoung04@gmail.com>,
	stable@vger.kernel.org
Subject: [PATCH v2 2/2] perf/core: Don't loop forever on a bad pmd in perf_get_pgtable_size()
Date: Wed,  2 Dec 2026 20:59:02 +0900	[thread overview]
Message-ID: <20261202115902.586760-3-ljyoung04@gmail.com> (raw)
In-Reply-To: <20261202115902.586760-1-ljyoung04@gmail.com>

perf_get_pgtable_size() hands pte_offset_map() a copy of the pmd. For a
bad pmd, such as an x86-64 espfix entry, pte_offset_map() fails and only
clears the copy, so the walk reads the same entry again and retries
forever with interrupts disabled. A PERF_SAMPLE_CODE_PAGE_SIZE sample
with an IP in the espfix area hangs the CPU this way.

Return 0 for a bad pmd instead.

Fixes: a92cbb82c8d3 ("perf/core: allow pte_offset_map() to fail")
Cc: stable@vger.kernel.org
Signed-off-by: JunYoung Lee <ljyoung04@gmail.com>
---
Changes in v2:
- Split out of v1 into its own patch (Peter).

Tested on 693c2e04e3f1 (kernelCTF LTS config, KVM guest, AMD host) with
a root exclude_kernel=0 breakpoint event probing the 128 espfix slots:
- With 1/2 only: the probe of the populated slot never returns, the
  console fills with "bad pmd" messages and the guest stops answering.
- With 1/2 and 2/2: all probes return with code_page_size=0 and no
  "bad pmd" message appears.

 kernel/events/core.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 4c7f173d7..dbede0eab 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -8710,6 +8710,14 @@ static u64 perf_get_pgtable_size(struct mm_struct *mm, unsigned long addr)
 	if (pmd_leaf(pmd))
 		return pmd_leaf_size(pmd);
 
+	/*
+	 * pte_offset_map() fails on a bad pmd and only clears our local
+	 * copy, so retrying would read the same entry again and loop
+	 * forever with interrupts disabled.
+	 */
+	if (pmd_bad(pmd))
+		return 0;
+
 	ptep = pte_offset_map(&pmd, addr);
 	if (!ptep)
 		goto again;

-- 
2.56.1

  parent reply	other threads:[~2026-12-02 11:59 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 11:59 [PATCH v2 0/2] perf/core: Fix kernel page size leak and espfix hang JunYoung Lee
2026-12-02 11:59 ` [PATCH v2 1/2] perf/core: Don't report a kernel IP for exclude_kernel events JunYoung Lee
2026-12-02 12:16   ` sashiko-bot
2026-12-02 11:59 ` JunYoung Lee [this message]
2026-12-02 12:16 ` [PATCH v2 0/2] perf/core: Fix kernel page size leak and espfix hang 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=20261202115902.586760-3-ljyoung04@gmail.com \
    --to=ljyoung04@gmail.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=irogers@google.com \
    --cc=james.clark@linaro.org \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=stable@vger.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.