From nobody Mon Nov 23 22:39:50 2026 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=1792425641; cv=none; d=zohomail.com; s=zohoarc; b=LC+seyDUz3yZGDMXJKflbjuyQq1kZtCyWerdEIu0x68DTM9iH3NKn25Nmtw48YmzO/G1O67nj1XNu9wjFBvKmBGNE4Zof/fcNZO0ucOMpyhvb/KUNl+v5AtN/KUPSaI/ppin/9RlNwkZW/B6eFWDq/tSJ5lY3dnqY+CXpEeRX6M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792425641; 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=rXku0uSS7cetVaB1RhHYmZ4LzWZiZ0jJSJfMyr9JCAQ=; b=WEDkDOWeccFUv3UgrRpFmfgCnqDOmQDas6iHVQMlz9+qh4JkSvQaczE0XIx6xATFkumwKbV1VwPvr+iiJQbuPhxgSzxtdzPy09Qu7+y+/7aCVJBbkDFams9lGbuioCRlNXPvdZdfTtbEf5PlFnF9MiSNpO9tqAD95b91N9DKs/Q= 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 1792425641467383.21537519743003; Mon, 19 Oct 2026 09:00:41 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1454547.1668103 (Exim 4.92) (envelope-from ) id 1xIpmQ-0004zU-DI; Mon, 19 Oct 2026 16:00:06 +0000 Received: by outflank-mailman (output) from mailman id 1454547.1668103; Mon, 19 Oct 2026 16:00:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xIpmQ-0004z1-AU; Mon, 19 Oct 2026 16:00:06 +0000 Received: by outflank-mailman (input) for mailman id 1454547; Mon, 19 Oct 2026 16:00:04 +0000 Received: from mx.expurgate.net ([194.145.224.10]) by lists.xenproject.org with esmtp (Exim 4.92) id 1xIpmO-0004YH-C4 for xen-devel@lists.xenproject.org; Mon, 19 Oct 2026 16:00:04 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1xIpmN-0024ZI-Dd for xen-devel@lists.xenproject.org; Mon, 19 Oct 2026 18:00:03 +0200 Received: from [10.42.69.1] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6ad63e68-8faa-0a2a0a5109dd-0a2a450190a6-44 for ; Mon, 19 Oct 2026 18:00:03 +0200 Received: from [209.85.128.47] (helo=mail-wm1-f47.google.com) by tlsNG-d62444.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6ad63e83-5984-0a2a45010019-d155802fece8-3 for ; Mon, 19 Oct 2026 18:00:03 +0200 Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-4a1cef0439aso25018485e9.0 for ; Mon, 19 Oct 2026 09:00:03 -0700 (PDT) Received: from localhost.localdomain (host-78-146-248-75.as13285.net. [78.146.248.75]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48dfd4e28bcsm24218617f8f.23.2026.10.19.09.00.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Oct 2026 09:00:01 -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" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=google header.d=citrix.com header.i="@citrix.com" header.h="Content-Transfer-Encoding:Content-Type:MIME-Version:Message-Id:Date:Subject:Cc:To:From" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1792425603; x=1793030403; darn=lists.xenproject.org; h=content-transfer-encoding:content-type:mime-version:message-id:date :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to :content-type; bh=rXku0uSS7cetVaB1RhHYmZ4LzWZiZ0jJSJfMyr9JCAQ=; b=o0exFcdZDl889rR3yyiY+YHUvmt9oIgWbp3PRkXS5jmKwZ2xepLX3fpLgq5UpZ+ANv 4JywiOu0A5DGZcH9WzGsyUddrBpbU63bKvF8T277rziBNhYESAJgxqe3pU42CzC0qkmE mkxSMaTbLuxuOQsYVZo2QXhip3eZM7W/rv5aA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792425603; x=1793030403; h=content-transfer-encoding:content-type:mime-version:message-id:date :subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to:content-type; bh=rXku0uSS7cetVaB1RhHYmZ4LzWZiZ0jJSJfMyr9JCAQ=; b=xYrBUTa3LjQYYbG82kMtm4u9B9oYfq4F9M2kXunuvst3WkVAwBOYfBNP60QdFkB/3X 8J7/qBJ7a5GI3kmafhCe9JGPLtcDdxzIzdCkx0AAMpz6AwSfMCOtdN5BIiOgDywELev0 wXVgt96mKYgMAnV6q6cRkA5OdPHxY1PfJvh42W9hpliemYTCsFJIjiwMVKEkb5iVXnnu hPqHe7LHkpX4YrsSfCQdOf9qZLyi1XiHOEZVm2YbbD/PH9lus/VGi/uJ9ZWgOVX/gz9q FSX0fKI5JxlSOxhTeOT2an8j5lBKf9AwBvC0MI4JwYmqJP4MVkEcf2Yq69gB1vZ6DlNL UgNw== X-Gm-Message-State: AFq9FYJ1CwQtByMV5CFHam/fJshO+l4pK165wjEMd4YCXmZ4C3Xv/xm1 UuoshjijEXXjUQHb+lx5/UmLcw5Zc4/MfWjUvlHx1J8GIS/EbSbSbE0a8Do21rAYyzLaC7VFqlI u3qsb X-Gm-Gg: AYBFou2JvlLpM+Ervhj8OXuyMxlfJxs2b/5Ux1ADDenXZr2XxusBofqQUyiWLpVQ9ZM J5bSTsCwpS5TQlMV/+95VqyTWA9rqMUswC7WmQQe7xv00bCVmLh/ICwI0oTFFm4e5n5TnP4z+S4 +TO4naptRkS5L05nSn5Rv/8aSi5r7X96lzGQ7Z/hJGo6uKIfE351Hv/QdYELXpU8tbzYOxt7cJs Sy0OJWcYLlJRwiBCeCa9jEyATUdvYZZcfhfBE6Meq5lbtUNLeUx015Z07jFMR4Cs9YkYaJA2iTt jpTOaIwENodAZ6ca14VCit8nVLuZGZUlj34HOdrtpK/IeX/SJNHVrxsvSsv2f+D/7zgU/dl8h5A U9RpfXVNuuUUOSg7c4w36ziaxgdVNzK1LYVwYZSlij2QCwThfwCS5ngY4LKN/5d4p5vu53hssOC qPHFrGwgx5HFh1qxV6X4UnPi1OIGmNoiofB5wuOhbftLABbmhg2GsdopF6TiXGO1xsh1XBmN/Cb hvaVWxPmFF+5hnNNZss4q5jN79BSeiGU5IYis6qrn224bzJ X-Received: by 2002:a05:600c:3b13:b0:4a0:2150:55fb with SMTP id 5b1f17b1804b1-4a1d75ad08amr206887475e9.4.1792425602167; Mon, 19 Oct 2026 09:00:02 -0700 (PDT) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Jan Beulich , Teddy Astie Subject: [PATCH] x86/shstk: Fix possible crash while enabling Shadow Stacks Date: Mon, 19 Oct 2026 16:59:59 +0100 Message-Id: <20261019155959.883789-1-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.39.5 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-d62444/1792425603-1FC69757-A7A6712D/10/78276251493 X-purgate-type: spam X-purgate-size: 3785 X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1792425644864158500 Between writing MSR_S_CET.SHSTK_EN and establishing SSP using RSTORSSP or SETSSBSY, there must not be any CALL or RET instructions. Building Xen with -fno-early-inlining causes wrmsr() to become out-of-line, and thus suffers #DF during boot. Make the MSR and shstk helpers always_inline. They ought to have been this way all along. Reported-by: Roger Pau Monn=C3=A9 Signed-off-by: Andrew Cooper Reviewed-by: Roger Pau Monn=C3=A9 Reviewed-by: Teddy Astie reported-by tag also. --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Teddy Astie No change in the compiled binary at -O2, except for the line numbers embedd= ed into *_param() names. With -fno-early-inlining, the resulting delta is: add/remove: 8/9 grow/shrink: 13/50 up/down: 360/-736 (-376) --- xen/arch/x86/include/asm/msr.h | 8 ++++---- xen/arch/x86/include/asm/shstk.h | 4 ++-- xen/arch/x86/setup.c | 5 +++++ 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/xen/arch/x86/include/asm/msr.h b/xen/arch/x86/include/asm/msr.h index 1377d156f4e1..d5cec5509faa 100644 --- a/xen/arch/x86/include/asm/msr.h +++ b/xen/arch/x86/include/asm/msr.h @@ -47,7 +47,7 @@ static always_inline uint64_t rdmsr(unsigned int msr) val =3D a__ | ((u64)b__<<32); \ } while(0) =20 -static inline void wrmsr(unsigned int msr, uint64_t val) +static always_inline void wrmsr(unsigned int msr, uint64_t val) { uint32_t lo =3D val, hi =3D val >> 32; =20 @@ -56,7 +56,7 @@ static inline void wrmsr(unsigned int msr, uint64_t val) #define wrmsrl(msr, val) wrmsr(msr, val) =20 /* Non-serialising WRMSR, when available. Falls back to a serialising WRM= SR. */ -static inline void wrmsrns(uint32_t msr, uint64_t val) +static always_inline void wrmsrns(uint32_t msr, uint64_t val) { uint32_t lo =3D val, hi =3D val >> 32; =20 @@ -72,7 +72,7 @@ static inline void wrmsrns(uint32_t msr, uint64_t val) } =20 /* rdmsr with exception handling */ -static inline int rdmsr_safe(unsigned int msr, uint64_t *val) +static always_inline int rdmsr_safe(unsigned int msr, uint64_t *val) { uint64_t lo, hi; =20 @@ -113,7 +113,7 @@ static inline int rdmsr_safe(unsigned int msr, uint64_t= *val) } =20 /* wrmsr with exception handling */ -static inline int wrmsr_safe(unsigned int msr, uint64_t val) +static always_inline int wrmsr_safe(unsigned int msr, uint64_t val) { uint32_t lo =3D val, hi =3D val >> 32; =20 diff --git a/xen/arch/x86/include/asm/shstk.h b/xen/arch/x86/include/asm/sh= stk.h index 9160fe9f0e99..22bbbb2faf37 100644 --- a/xen/arch/x86/include/asm/shstk.h +++ b/xen/arch/x86/include/asm/shstk.h @@ -15,7 +15,7 @@ */ #define SSP_NO_SHSTK 1 =20 -static inline unsigned long rdssp(void) +static always_inline unsigned long rdssp(void) { unsigned long ssp; =20 @@ -24,7 +24,7 @@ static inline unsigned long rdssp(void) return ssp; } =20 -static inline void wrss(unsigned long val, unsigned long *ptr) +static always_inline void wrss(unsigned long val, unsigned long *ptr) { asm ( "wrssq %[val], %[ptr]" : [ptr] "=3Dm" (*ptr) diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index fef3c2dd4423..446cd8127693 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -915,6 +915,11 @@ static void __init noreturn reinit_bsp_stack(void) */ local_irq_disable(); =20 + /* + * There must be no CALL or RET instructions between writing + * MSR_S_CET.SHSTK_EN and establishing SSP with RSTORSSP or SETSSB= SY + * below. All helpers must be forced inline. + */ wrmsrl(MSR_S_CET, xen_msr_s_cet_value()); =20 /* base-commit: 7e020a4dd6ed30eb6c91a9abe2767034e2bb270a --=20 2.39.5