[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] xen/x86: Change stub page freeing to fix smt=0
- To: Roger Pau Monné <roger.pau@xxxxxxxxxx>
- From: Jason Andryuk <jason.andryuk@xxxxxxx>
- Date: Mon, 1 Jun 2026 17:07:52 -0400
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=citrix.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0)
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=hG9W2e5jgQUBQAJLZL/4kduVWRVloyFkEdOR1JN+kME=; b=Dm8h2x44fkE1yec6fyoSNsaNsVdN3bj+4oct9YzoGNG8Y0pBn5j0OJJ0FAfxa/6t5wi7Xj0g3zjPKDD72y2MffA0PCjvORGaHtfm/ut8SEWn6jQsQt+wvj/WnZ8nHyNXrt3wAUHLw7GuP5tT1HKLUmtS4Non4IrKL3YON32XcytZa4kYWvmEkGje02j5Cj7O02oWgVWCUUJRDHsk3fW8ssy9oFXh+07XsNZgYE2oUgNqkhQqb0kWQUF9R5Uhy/oMz2z8e9qQxSegjNCInq/D1NR7mgb2TgClaUDDmytJjlDf/kENtvYTgBFUkwDvs+S/c4aBl3fr+T5tGll2SIj8Sw==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=BoRnRn2X83y487A3gNon78krqexsPBJyAb5cm4x/OYyY7Ti/i71x1ypRoG+ky2TXOLB5XJPyfxniD8TKO1CHZ+HDip6Ayp5vRlyrE+NSxLBDVqFx2Fj4DoN33v3jtKiV7QQwCu7L7GnceVYkR9b7NJHN88xJvhb8viTqqMH43Yi6iWBN3I7sDR2WyWwA1+MPCeOpdujSd13L6mGgVH71JzHsZlQ5B1Pr55GGRR5+jYhG2ilXaFsxo3z9QsCR6koWgU7CdFyzr7zMhgmtPH8X6mazgOwOMpi7T6CTz8NugYHcBnK8P07ZDdhSLf7aayQkdSKloL51dFxrmboDynKWEA==
- Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=amd.com header.i="@amd.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
- Cc: <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Teddy Astie <teddy.astie@xxxxxxxxxx>
- Delivery-date: Mon, 01 Jun 2026 21:08:18 +0000
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
On 2026-06-01 13:00, Roger Pau Monné wrote:
On Tue, May 26, 2026 at 04:31:14PM -0400, Jason Andryuk wrote:
A single stubs page is initialized with 0xcc and re-used, with multiple
CPUs each using a portion of the shared page. In cpu_smpboot_free(),
each stubs area is checked against 0xcc. When all are set to 0xcc, the
page is freed.
Booting a system with smt=0, CPU0 is initially setup, allocating the
stubs page and initializing to 0xcc. When more CPUs are brought up,
CPU1 is initialized and then immediately brough offline as it is the
sibling of CPU0. Since the page was initially memset with 0xcc,
cpu_smpboot_free() finds all stubs as 0xcc and frees the page.
However, the page is still assigned to CPU0 and continues to be assigned
to other CPUs.
Meanwhile the page can be reallocated, which can lead to misbehavior.
The particular instance was the stubs page re-used as a page table which
later faulted when the entry was all 0xcc.
Change to initializing the page as 0xd6/STUB_BUF_FREE, and initializing
individual stubs as 0xcc/STUB_BUF_USED. 0xd6 now indicates unused, and
0xcc indicates used/assigned. When freeing a CPU, the stub is set to
0xd6, and the page is freed if all stubs are 0xd6. Initializing with
STUB_BUF_FREE lets cpu_smpboot_free() a page that was only ever
partially used.
0xd6/UDB is a 1 byte invalid opcode, which is similar to the existing
use of 0xcc. 0xd6 is used to identify bug frames, but the stub addr
(e.g. 0xffff82d07fffe000) fails the is_active_kernel_text() check. It
should be okay to use here.
Fixes: 7a66ac8d1633 ("x86: move syscall trampolines off the stack")
Signed-off-by: Jason Andryuk <jason.andryuk@xxxxxxx>
---
It would be nice to use get_page()/put_page() to let count_info handle
reference counting, but they require an owning domain.
The listed Fixes introduced the use of 0xcc, but the smt commit may have
made it more problematic.
Fixes: d8f974f1a646 ("x86: command line option to avoid use of secondary
hyper-threads")
Speaking with Andrew, we believe it might be easier to simply forego
the freeing of the page, possibly something like:
diff --git a/xen/arch/x86/smpboot.c b/xen/arch/x86/smpboot.c
index ff05955bae40..62c6cbf4b561 100644
--- a/xen/arch/x86/smpboot.c
+++ b/xen/arch/x86/smpboot.c
@@ -990,19 +990,12 @@ static void cpu_smpboot_free(unsigned int cpu, bool
remove)
{
mfn_t mfn = _mfn(per_cpu(stubs.mfn, cpu));
unsigned char *stub_page = map_domain_page(mfn);
- unsigned int i;
memset(stub_page + STUB_BUF_CPU_OFFS(cpu), 0xcc, STUB_BUF_SIZE);
- for ( i = 0; i < STUBS_PER_PAGE; ++i )
- if ( stub_page[i * STUB_BUF_SIZE] != 0xcc )
- break;
unmap_domain_page(stub_page);
destroy_xen_mappings(per_cpu(stubs.addr, cpu) & PAGE_MASK,
(per_cpu(stubs.addr, cpu) | ~PAGE_MASK) + 1);
per_cpu(stubs.addr, cpu) = 0;
- per_cpu(stubs.mfn, cpu) = 0;
- if ( i == STUBS_PER_PAGE )
- free_domheap_page(mfn_to_page(mfn));
}
if ( IS_ENABLED(CONFIG_PV32) )
(there might be further cleanup possible if the page is not freed, the
above chunk is untested).
It's a single page shared between 32 CPUs, and offlining 32 adjacent
CPUs seems very unlikely. IMO the extra complexity of having to deal
with the freeing overshadows the very small memory gain we get from
it.
Hi Roger,
Yes, I made and tested the same change locally last week. Well, I retained:
per_cpu(stubs.mfn, cpu) = 0;
Maybe it would be good to save the mfn in case the CPU returns? But I
thought per-cpu vars are cleared, so it wouldn't be available anyway?
Also, I was waiting to see if anyone chimed in with other ideas.
Thanks,
Jason
|