From nobody Fri Dec 19 02:51:21 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1747402430; cv=none; d=zohomail.com; s=zohoarc; b=iVDWLA6jLF9YreGhaXnWx2ltZGGrnkXoPkjWvEirYFN2ZuORcE6KhoRNdIvyBuGqSyQJjVB6IlgPF+EmG/4NF7zMtiiqPc7ng+FyLBEV7/MiBjXldrZ5mAHaA+JC1Sv2eM2M9O837d5xLyhbzsU3/7P2N7IrZjim2nKH28kQZXE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1747402430; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=+563COaD5Tzxy42DVJiIP27O5Q90TLkJxpGFzPREXj4=; b=MMf4jOQywphZ54YA6T7tv+Vo51KldtS5VPkfTU2Eop7tFvveKwjhvCQjqLj8h+1ZbI/90qCLTMza0IOAaGJp9GumjfyX1MjT45mzFld0ZKhrUv3NykcfqxzGtOxhlUuEwjC1NqzDukhMxHvnR3mL+sF+GzV+6OPfZCxQYGbkqd0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1747402430904132.52729789259502; Fri, 16 May 2025 06:33:50 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.987176.1372598 (Exim 4.92) (envelope-from ) id 1uFvBs-0000DK-Sn; Fri, 16 May 2025 13:33:32 +0000 Received: by outflank-mailman (output) from mailman id 987176.1372598; Fri, 16 May 2025 13:33:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uFvBs-0000DD-Pv; Fri, 16 May 2025 13:33:32 +0000 Received: by outflank-mailman (input) for mailman id 987176; Fri, 16 May 2025 13:33:31 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uFvBr-0000D2-6K for xen-devel@lists.xenproject.org; Fri, 16 May 2025 13:33:31 +0000 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [2a00:1450:4864:20::42a]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 5ab047b2-325a-11f0-9eb6-5ba50f476ded; Fri, 16 May 2025 15:33:30 +0200 (CEST) Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-3a361b8a66cso384097f8f.2 for ; Fri, 16 May 2025 06:33:30 -0700 (PDT) Received: from andrew-laptop.. ([46.149.103.13]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a35ca88990sm2919757f8f.68.2025.05.16.06.33.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 May 2025 06:33:28 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 5ab047b2-325a-11f0-9eb6-5ba50f476ded DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1747402409; x=1748007209; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=+563COaD5Tzxy42DVJiIP27O5Q90TLkJxpGFzPREXj4=; b=Bg0glXHKqiNNJ/6YKjniaGyx6j2IuPpd6YOTS9q5ImcffaTvCl9wScAvh+sU80u8b7 O8kHMgzTZnbvXYw4/CPuDdF2xFlLZy/6v18GQcVohSRRcL/YA9pN4KWe9S9URiHiWa8A p62+SLQmRmint5E671YZVLWtBRsf3XANthPmw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747402409; x=1748007209; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+563COaD5Tzxy42DVJiIP27O5Q90TLkJxpGFzPREXj4=; b=gbproIwZMWrx3+MmprzzEDxw4hPNboKojzJuj9Rf8l/0giDbDo+sAtmtWzn5u1lkNA mxOeUMi25Mqc9QM1YDUkdgjK5L+vWHg0jMdCxPH6SxHIpFOG5T3wBU/pqHTNT8kSET5v Pcuh4DhX+lMnAJEzpJbOWwi/goZeaRKIGAyIFrNUxgXGdKGKDyMePE11H38kzVMDJiyp Dy2Cum6mjgLIdsT1XNgCYwmXvWsnEwhHaClAmQ/B2A0RZ4PBF0Yj0/0p05sfPR7K6QG+ WSBv8mgntoDlEOzIhdLx1WLm2+KRNVeVOEAcpFT2j4qRsLiqydADr9nZ0si9vFDwBr5g PQQA== X-Gm-Message-State: AOJu0YwkLBjYREcnzwndRNRPH809o3XHkbm8YpKFPIxGdDMtl+I8awgr I5MSOuqgvYhfoQYuMfWEaJPb+kntdNEF1iZBgc86jxlVkeZzmEIuhHXErFgnEQNTf3JdF0UlZ2R Ldlek X-Gm-Gg: ASbGncsMySx/kJvgOGiffgfpSP0qM0Ip7BnK6bONQktriHnrQbuTKbPNvV4RsnF6RGn rqZ6zErhXkcZ/yaKgmHTGfvsO/mYgYUu7HWW6GGh1CT9m6Gb3DUCfBoD6t3j/jYu1z4+BC6mbvl WOvRwEiZNTZHcCWeHAzrQUjvPv3HPSnERNjELe/F1Gli0BM/SmHbe92/Js58rs9DEJm/MeZt4GU 0/PTKxHQWWI+N5D/ce/7rkAHqorKC8fvDi809CmrcaE11IH4qpMnD5OeSexmmfZqda23u/1CIGJ 6X5ll+LXYkfczNvRgxSugiK/1CwtIcJ1qM3Bol1A9MjEer2lO/11Fomzt/c3lbU= X-Google-Smtp-Source: AGHT+IGBZcA/D0toS/bzcF2SEeqek/9hmi29cajL7lU/dxawRyQdg/bLnBswuTorEq6YmiJwR4jRmQ== X-Received: by 2002:a5d:64ee:0:b0:3a0:8495:cb75 with SMTP id ffacd0b85a97d-3a35c834f85mr3921790f8f.9.1747402409082; Fri, 16 May 2025 06:33:29 -0700 (PDT) From: Andrew Cooper To: xen-devel@lists.xenproject.org Cc: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH] x86/stubs: Consolidate the stubs infrastructure in asm/stubs.h Date: Fri, 16 May 2025 14:33:26 +0100 Message-Id: <20250516133326.49587-1-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1747402432518116600 Very few files need the stubs. Move the infrastructure out of processor.h and config.h into a new stubs.h, and adjust the includes accordingly. Make the per-cpu struct stubs be read mostly; they're unmodified during the uptime of the CPU, and move them into smpboot.c seeing as that's where they're allocated and freed. No functional change. Signed-off-by: Andrew Cooper Acked-by: Jan Beulich --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 This is from one of my several failed attempts to deal with the stubs more nicely in XSA-469. Still, getting the infrastructure out of processor.h is a good cleanup. The FRED series is probably going to result in getting rid of x86_64/traps.c, given that most of the content gets dropped. --- xen/arch/x86/alternative.c | 1 + xen/arch/x86/extable.c | 8 +++--- xen/arch/x86/hvm/vmx/vmx.c | 1 + xen/arch/x86/include/asm/config.h | 5 ---- xen/arch/x86/include/asm/processor.h | 11 --------- xen/arch/x86/include/asm/stubs.h | 37 ++++++++++++++++++++++++++++ xen/arch/x86/pv/emul-priv-op.c | 1 + xen/arch/x86/setup.c | 1 + xen/arch/x86/smpboot.c | 3 +++ xen/arch/x86/x86_64/traps.c | 3 +-- xen/arch/x86/x86_emulate/private.h | 2 ++ 11 files changed, 52 insertions(+), 21 deletions(-) create mode 100644 xen/arch/x86/include/asm/stubs.h diff --git a/xen/arch/x86/alternative.c b/xen/arch/x86/alternative.c index ecc56964bd9c..d4fe56b3dae8 100644 --- a/xen/arch/x86/alternative.c +++ b/xen/arch/x86/alternative.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include diff --git a/xen/arch/x86/extable.c b/xen/arch/x86/extable.c index 1572efa69a00..8b78c75d3374 100644 --- a/xen/arch/x86/extable.c +++ b/xen/arch/x86/extable.c @@ -1,16 +1,18 @@ =20 +#include #include #include +#include #include #include #include #include -#include -#include #include -#include #include =20 +#include +#include + #define EX_FIELD(ptr, field) ((unsigned long)&(ptr)->field + (ptr)->field) =20 static inline unsigned long ex_addr(const struct exception_table_entry *x) diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index 827db6bdd807..c2262c584822 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -48,6 +48,7 @@ #include #include #include +#include #include =20 static bool __initdata opt_force_ept; diff --git a/xen/arch/x86/include/asm/config.h b/xen/arch/x86/include/asm/c= onfig.h index f0123a7de983..3553bf89dc97 100644 --- a/xen/arch/x86/include/asm/config.h +++ b/xen/arch/x86/include/asm/config.h @@ -49,11 +49,6 @@ /* Primary shadow stack is slot 5 of 8, immediately under the primary stac= k. */ #define PRIMARY_SHSTK_SLOT 5 =20 -/* Total size of syscall and emulation stubs. */ -#define STUB_BUF_SHIFT (L1_CACHE_SHIFT > 7 ? L1_CACHE_SHIFT : 7) -#define STUB_BUF_SIZE (1 << STUB_BUF_SHIFT) -#define STUBS_PER_PAGE (PAGE_SIZE / STUB_BUF_SIZE) - /* Return value for zero-size _xmalloc(), distinguished from NULL. */ #define ZERO_BLOCK_PTR ((void *)0xBAD0BAD0BAD0BAD0UL) =20 diff --git a/xen/arch/x86/include/asm/processor.h b/xen/arch/x86/include/as= m/processor.h index eacd425c5350..1820e04a32f9 100644 --- a/xen/arch/x86/include/asm/processor.h +++ b/xen/arch/x86/include/asm/processor.h @@ -424,17 +424,6 @@ static inline void enable_nmis(void) =20 void nocall sysenter_entry(void); =20 -struct stubs { - union { - void(*func)(void); - unsigned long addr; - }; - unsigned long mfn; -}; - -DECLARE_PER_CPU(struct stubs, stubs); -unsigned long alloc_stub_page(unsigned int cpu, unsigned long *mfn); - static inline uint8_t get_cpu_family(uint32_t raw, uint8_t *model, uint8_t *stepping) { diff --git a/xen/arch/x86/include/asm/stubs.h b/xen/arch/x86/include/asm/st= ubs.h new file mode 100644 index 000000000000..a520928e9a50 --- /dev/null +++ b/xen/arch/x86/include/asm/stubs.h @@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef X86_ASM_STUBS_H +#define X86_ASM_STUBS_H + +/* + * Xen has several per-cpu executable stubs which are written dynamically. + * These are: + * + * - The SYSCALL entry stubs, LSTAR and CSTAR. These are written on boot,= and + * are responsible for moving back onto Xen's stack. + * + * - The emulation stub. This is used to replay an instruction or sequence + * which trapped for emulation. + * + * The stubs have an executable alias in l2_xenmap[] (i.e. within 1G of the + * rest of .text), and are written via map_domain_page(). + */ + +#include + +/* Total size of syscall and emulation stubs. */ +#define STUB_BUF_SHIFT (L1_CACHE_SHIFT > 7 ? L1_CACHE_SHIFT : 7) +#define STUB_BUF_SIZE (1 << STUB_BUF_SHIFT) +#define STUBS_PER_PAGE (PAGE_SIZE / STUB_BUF_SIZE) + +struct stubs { + union { + void (*func)(void); + unsigned long addr; + }; + unsigned long mfn; +}; + +DECLARE_PER_CPU(struct stubs, stubs); +unsigned long alloc_stub_page(unsigned int cpu, unsigned long *mfn); + +#endif /* X86_ASM_STUBS_H */ diff --git a/xen/arch/x86/pv/emul-priv-op.c b/xen/arch/x86/pv/emul-priv-op.c index 295d847ea24c..4da3f379ef3e 100644 --- a/xen/arch/x86/pv/emul-priv-op.c +++ b/xen/arch/x86/pv/emul-priv-op.c @@ -21,6 +21,7 @@ #include #include #include +#include =20 #include =20 diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 25189541244d..1f5cb67bd0ee 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -55,6 +55,7 @@ #include #include #include +#include #include #include #include diff --git a/xen/arch/x86/smpboot.c b/xen/arch/x86/smpboot.c index 0189d6c332a4..41fe67d43c94 100644 --- a/xen/arch/x86/smpboot.c +++ b/xen/arch/x86/smpboot.c @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -57,6 +58,8 @@ static cpumask_t scratch_cpu0mask; DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, send_ipi_cpumask); static cpumask_t send_ipi_cpu0mask; =20 +DEFINE_PER_CPU_READ_MOSTLY(struct stubs, stubs); + cpumask_t cpu_online_map __read_mostly; EXPORT_SYMBOL(cpu_online_map); =20 diff --git a/xen/arch/x86/x86_64/traps.c b/xen/arch/x86/x86_64/traps.c index ac0fafd72d31..b10bd0becafb 100644 --- a/xen/arch/x86/x86_64/traps.c +++ b/xen/arch/x86/x86_64/traps.c @@ -21,6 +21,7 @@ #include #include #include +#include #include =20 =20 @@ -330,8 +331,6 @@ static unsigned int write_stub_trampoline( return ROUNDUP(p - stub, 16); } =20 -DEFINE_PER_CPU(struct stubs, stubs); - void nocall lstar_enter(void); void nocall cstar_enter(void); =20 diff --git a/xen/arch/x86/x86_emulate/private.h b/xen/arch/x86/x86_emulate/= private.h index 30be59547032..c4138afe1db5 100644 --- a/xen/arch/x86/x86_emulate/private.h +++ b/xen/arch/x86/x86_emulate/private.h @@ -10,8 +10,10 @@ =20 # include # include + # include # include +# include # include # include =20 --=20 2.34.1