From nobody Mon Nov 23 22:28:33 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=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1794229704; cv=none; d=zohomail.com; s=zohoarc; b=U7AvOvJd30vvzmHwKE5zBTd1FNJgoiVK948nDkfQAL4eqZdM130mN3t24ZHgv0H+FE9zZsBtt+JJDZ5o2qOTYZF436bP1gixBicvGNT7AhxF2xROu2QWdk94lDGwNXueg0Fp4T+vZlTyPjdEtmmu9xjPstJKLwv0RuGwZh0x01Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794229704; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=SecZZq9fuPHvRmh1WvuUmmfIbPjJb6Pt5XQ5H/cNAmk=; b=CAUlsuC9B+DQwxrlgmL9weKO9jPlKgKAvlQ0SzhOPHGxBsDe2DAcP5YabNyKf2Aq87dwIlsp/4HBlz5/PXj0nyYpY39mBPB0+fuAVdtEyHERdSP7mXWe2ASZhJK3WemvqGdmCYBp+HcYAOTPSNP7N8+8IWTNrx0sle9Xkg/sIzc= 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=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1794229704731860.2450413950259; Mon, 9 Nov 2026 05:08:24 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1480033.1683962 (Exim 4.92) (envelope-from ) id 1xQP6U-0008Sb-4Q; Mon, 09 Nov 2026 13:08:06 +0000 Received: by outflank-mailman (output) from mailman id 1480033.1683962; Mon, 09 Nov 2026 13:08: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 1xQP6U-0008SS-18; Mon, 09 Nov 2026 13:08:06 +0000 Received: by outflank-mailman (input) for mailman id 1480033; Mon, 09 Nov 2026 13:08:05 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) id 1xQP6T-0008SC-4G for xen-devel@lists.xenproject.org; Mon, 09 Nov 2026 13:08:05 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1xQP6S-003xok-H9 for xen-devel@lists.xenproject.org; Mon, 09 Nov 2026 14:08:04 +0100 Received: from [10.42.69.8] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6af1c5a5-8faa-0a2a0a5109dd-0a2a4508a774-34 for ; Mon, 09 Nov 2026 14:08:04 +0100 Received: from [209.85.221.45] (helo=mail-wr1-f45.google.com) by tlsNG-c1860d.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6af1c5b4-f659-0a2a45080019-d155dd2db196-3 for ; Mon, 09 Nov 2026 14:08:04 +0100 Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-492fcbfaa87so541100f8f.3 for ; Mon, 09 Nov 2026 05:08:04 -0800 (PST) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-49597d0a775sm10792976f8f.55.2026.11.09.05.08.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 09 Nov 2026 05:08:03 -0800 (PST) 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=suse.com header.i="@suse.com" header.h="Content-Transfer-Encoding:Content-Type:In-Reply-To:Autocrypt:Content-Language:References:Cc:To:From:Subject:User-Agent:MIME-Version:Date:Message-ID" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1794229684; x=1794834484; darn=lists.xenproject.org; h=content-transfer-encoding:content-type:in-reply-to:autocrypt :content-language:references:cc:to:from:subject:user-agent :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to:content-type; bh=SecZZq9fuPHvRmh1WvuUmmfIbPjJb6Pt5XQ5H/cNAmk=; b=Jm7fTvFZ4Io7lDN5PpEzx90t0ttaA4JPFy0dFKNiUZDItlXOOUvfPU28BLmXTdB7H/ m4Z08ZhSSe/xva6Fp/cgwIYR/Bb2Ya7pArnIYMfpxHU8tl7EHh+a9cy6Y083ZGx50RII gDo9gymRnDRMop6KtLKdNkgWJ2hXfyxhGc5RLKF3ilhAXSldYTqyZXPq7pVUQG5gikwu nZDfI5db7FkSYgdk0vmn50Wa3dx6R8YJUWQ5jhhN/UvKrLf49/9a3Q9aNuH7PJkSPTNA +4Zacr96tAyfzx8J1yKyHyBzNFfMrYyBSW3qjMhE7eqeGoTzZ8XfuyUoIERzwOIbTFwq rBVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794229684; x=1794834484; h=content-transfer-encoding:content-type:in-reply-to:autocrypt :content-language:references:cc:to:from:subject:user-agent :mime-version:date:message-id:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to:content-type; bh=SecZZq9fuPHvRmh1WvuUmmfIbPjJb6Pt5XQ5H/cNAmk=; b=E11B6I8Me8MPDlqAp44Tjv8QZLBScLp5gon3Lq/PahXwCF4swl+J9jAcRKvaW+HZNt /wWEiPgd4hoa1QM/ZEhOnGSHhEF7XXxbDmTy3QchqUdmfCYtzP18E5oxBm47Zegj70C/ Wl1YAWmGmKSnoe/9Z0Vlpmj2Ix82TVRmVD3LG5tYi/OcnWu6ZSorJCGcltrN1Uq9JS+v 5AFwIHTx6XXD01htwROLTB7X75AdoVjGGfYIxEvnrLjyn6Vt3FJZgznkBuJXo9QenKzk D0uRbT5Apl5wQhFWOX96R63iXPWY/2upcqyLp1yWiOnu8mUDVxTZLrzCcpDWAfYxOlWe RWpg== X-Gm-Message-State: APuU4Z9sktpYHNrq6oybyfSij2t5Tw0Z+8V3/0UsFtScG6MqqUaLBIUE YzPk1x+aSAOCcaJp+3zP26+Qe/4nOF0ReH52741TrcOjl7OcbewNzornoQXjf5SX1MGgfl6vUP/ i6MRXNQ== X-Gm-Gg: AYBFou126YBvBNxQSingCfOiZy9s9x9UzhfXuY6w+OMMpILj5HmD5qajvbCWzzK3yeV aZCQgKx/saC+coa5G2FRpn5LTxDuO4ostze3EgBtoRoZms1wAhuSoNGjJ6VjsLtdOV1GPSt1ifZ b0uizO9YhmqfnLL7RLIO0l8gDSpE5dxOmYsvot0aNHKkSiWZSrLIFIC0QJYI7RB0PuQf9WeaRmq L9NYooPpIcsRfmqp02VvfGb4mJPAmr7+r8CFDNysE+3dk6EJzmHsNUrDo52/gdnxeWeZpjrfC5u +vNwVZBGqzt+EWxA8zP8LqqllCVpQWhEcIQOEnj8Wb+CxJWLwb3s/4x9XQkBQBaeTk8kOX0AOmg fuSaFtTEfDb3qd4+AkTw7A3Ti+QWwrzgXO++o2mII5vlcX+IvZmX1aLb+Ybj8478li8xxBenTnk 9poefaMRJri4mXbF3rjD+zEh0Ntrq1GuaNNAHTGLcOarQFTwoYFQiwJMZieVod11IWR1raMvC+b 0psbgp3JJ9e4awtd6DJknpi70XRekqZcDkBY2uhsdYLw3cIRYY8kYWhy8BOTICWTju+chdbx5cS kWXztGGJiLttu39ZhAtjtseD5w73zj1i6NG4nHvkaycsy7E91Rbm2AexuHAwFVpHb0qJNkEfU/J nBA== X-Received: by 2002:a05:6000:25ea:b0:490:2d81:ccbb with SMTP id ffacd0b85a97d-49584e3dccbmr7579686f8f.52.1794229683646; Mon, 09 Nov 2026 05:08:03 -0800 (PST) Message-ID: <2b348885-fb2d-420f-8f71-81e3a9c836af@suse.com> Date: Mon, 9 Nov 2026 14:08:03 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v5 1/4] x86: record SSP at non-guest entry points From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , Teddy Astie , =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= References: Content-Language: en-US Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-c1860d/1794229684-CE74387B-49275601/10/78276251493 X-purgate-type: spam X-purgate-size: 2764 X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1794229706449158500 Content-Type: text/plain; charset="utf-8" We will want to use that value for call trace generation, and likely also to eliminate the somewhat fragile shadow stack searching done in fixup_exception_return(). For those purposes, guest-only entry points do not need to record that value. To keep the saving code simple, record our own SSP that corresponds to an exception frame, pointing to the top of the shadow stack counterpart of what the CPU has saved on the regular stack. Consuming code can then work its way from there. In SAVE_ALL / RESTORE_ALL simply drop the use of UREGS_r15. We want the full size in all cases, so what exactly the top-of-stack field is going to be (whose UREGS_* is 0 anyway) doesn't matter this much there. This way we don't need to distinguish between XEN_SHSTK=3Dy and XEN_SHSTK=3Dn. Signed-off-by: Jan Beulich --- v5: Drop ssp parameter of PUSH_AND_CLEAR_GPRS again. v4: Re-base. v3: Put new field at the front of struct cpu_user_regs. v2: Add comment ahead of SAVE_ALL. Add comma between its parameters. Re-base. --- a/xen/arch/x86/include/asm/asm_defns.h +++ b/xen/arch/x86/include/asm/asm_defns.h @@ -259,12 +259,19 @@ static always_inline void stac(void) xor %r14d, %r14d push %r15 xor %r15d, %r15d +#ifdef CONFIG_XEN_SHSTK + rdsspq %rcx + push %rcx +#endif .endm =20 /* * POP GPRs from a UREGS_* frame on the stack. Does not modify flags. */ .macro POP_GPRS skip_rax=3D0 +#ifdef CONFIG_XEN_SHSTK + pop %rcx +#endif pop %r15 pop %r14 pop %r13 --- a/xen/arch/x86/include/asm/cpu-user-regs.h +++ b/xen/arch/x86/include/asm/cpu-user-regs.h @@ -11,6 +11,15 @@ */ struct cpu_user_regs { +#ifdef CONFIG_XEN_SHSTK + /* + * This points _at_ the corresponding shadow stack frame; it is _not_ = the + * outer context's SSP. That, if the outer context has CET-SS enabled, + * is stored in the top slot of the pointed to shadow stack. + */ + uint64_t entry_ssp; +#endif + union { uint64_t r15; uint32_t r15d; uint16_t r15w; uint8_t r15b= ; }; union { uint64_t r14; uint32_t r14d; uint16_t r14w; uint8_t r14b= ; }; union { uint64_t r13; uint32_t r13d; uint16_t r13w; uint8_t r13b= ; }; --- a/xen/arch/x86/x86_64/asm-offsets.c +++ b/xen/arch/x86/x86_64/asm-offsets.c @@ -57,6 +57,9 @@ void __dummy__(void) OFFSET(UREGS_eflags, struct cpu_user_regs, rflags); OFFSET(UREGS_rsp, struct cpu_user_regs, rsp); OFFSET(UREGS_ss, struct cpu_user_regs, ss); +#ifdef CONFIG_XEN_SHSTK + OFFSET(UREGS_entry_ssp, struct cpu_user_regs, entry_ssp); +#endif DEFINE(UREGS_kernel_sizeof, sizeof(struct cpu_user_regs)); BLANK(); From nobody Mon Nov 23 22:28:33 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=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1794229721; cv=none; d=zohomail.com; s=zohoarc; b=X+5Qovb1vD+SlRplVIdmqobe8DdBBTvpbA6+h6dDhBazV/7xCUARVAkAKx9WTYafJBNh4tNrB+5erP2nwhJ8+UfNUXt89RZ8CvHYI3W7b14iihhG9NEfAwqWoqOKAk5J33cRB83+VdEg7bHGn3XGLc1sUGRjtWHgiXk0OHNGAB4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794229721; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=MgcXWj5vqnP+4zvYUktX5k7TuUXNjhHYEeS80l/cLOs=; b=WZzOBvoqHlRXPofL0kzIueZ7FqC+8WWC0jof/NXIj9Jp5nOXj3czqaraphlDs0t53+/vUX8giCl0QKUKByxPI5btCyTaeg1LG9g/uDDOmLNCSMlSkH/wlS9mOfNVge0zGF1hvVLV2Uf0EtchcALPrX2me9wbfG9Kl+B3jMYx1so= 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=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1794229721365523.169652903555; Mon, 9 Nov 2026 05:08:41 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1480039.1683972 (Exim 4.92) (envelope-from ) id 1xQP6t-0000Wy-BZ; Mon, 09 Nov 2026 13:08:31 +0000 Received: by outflank-mailman (output) from mailman id 1480039.1683972; Mon, 09 Nov 2026 13:08:31 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xQP6t-0000Wq-7k; Mon, 09 Nov 2026 13:08:31 +0000 Received: by outflank-mailman (input) for mailman id 1480039; Mon, 09 Nov 2026 13:08:29 +0000 Received: from mx.expurgate.net ([194.145.224.10]) by lists.xenproject.org with esmtp (Exim 4.92) id 1xQP6r-0000U6-KW for xen-devel@lists.xenproject.org; Mon, 09 Nov 2026 13:08:29 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1xQP6r-007emB-19 for xen-devel@lists.xenproject.org; Mon, 09 Nov 2026 14:08:29 +0100 Received: from [10.42.69.7] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6af1c5bf-bab6-0a2a0a5309dd-0a2a4507d41c-34 for ; Mon, 09 Nov 2026 14:08:28 +0100 Received: from [209.85.128.51] (helo=mail-wm1-f51.google.com) by tlsNG-ef75cf.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6af1c5cb-b4ea-0a2a45070019-d1558033e434-3 for ; Mon, 09 Nov 2026 14:08:28 +0100 Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-4a35a60499eso6289365e9.0 for ; Mon, 09 Nov 2026 05:08:28 -0800 (PST) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4b76cbdb9cdsm194886635e9.1.2026.11.09.05.08.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 09 Nov 2026 05:08:26 -0800 (PST) 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=suse.com header.i="@suse.com" header.h="Content-Transfer-Encoding:Content-Type:In-Reply-To:Autocrypt:Content-Language:References:Cc:To:From:Subject:User-Agent:MIME-Version:Date:Message-ID" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1794229707; x=1794834507; darn=lists.xenproject.org; h=content-transfer-encoding:content-type:in-reply-to:autocrypt :content-language:references:cc:to:from:subject:user-agent :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to:content-type; bh=MgcXWj5vqnP+4zvYUktX5k7TuUXNjhHYEeS80l/cLOs=; b=GatG4V6Oyrx0EZ4NbrFbsYKBtSKWu+Mm93yja4qQMqyHRdeSFsbfZy9x+JX7EvfgUp GL8OWjdLwXVjT55Cul886OOxiAz+gWAhwbS1tvVQ1sEfRydpO7WLlncyILGiIjReFoSG fBjZtBM4TL2cd6CE1K12AI6VznE1uoUyrNGBxCWgD/rBA0LM/gdTItF72JCtXNheDqfO DYiD9T7jp4vL1ilWvOXLTGyvcL3QhkSD5X1QpdlFpCIlDD+uVzqdZZHiH1ak6qTZXpAf g263JMqIOSViZ+v3b01JgycSQdA1vQoLv39GAMaZIwGfMMY24tXWF6+Fra3PkxfjPq3u O7bA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794229707; x=1794834507; h=content-transfer-encoding:content-type:in-reply-to:autocrypt :content-language:references:cc:to:from:subject:user-agent :mime-version:date:message-id:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to:content-type; bh=MgcXWj5vqnP+4zvYUktX5k7TuUXNjhHYEeS80l/cLOs=; b=BHYn70eCB3i+7d6Kbn+Z1RfogoKmQMP06Z1WLNHPdow0KYZE3OMsgqyTEGKTy5Sd8f FvcQp6UywAnjNvipMhEaAkQ1X9IXsSV+s7h5qAN2aRT58uGZnF0SLufdifkG5BAMede/ dRpUupTASW1HIM3OCLPUplnxK8/9AWlPlV3MOWyHixUBv7eBBx4q9njFC287gSFpUF6N zITLdG9nLxUGjYY9+WOz9ZJnbDeh9I1eoh+QuWTPqGR4JZ56TYa/TZrWeGs0np4vayzN I6/KpyNJrwk/bkLVddb8Kiy+2kZfiocfHKwW9tRK9Ys2qpHnZa0ZAAiq9IWVyfOdU56R RThQ== X-Gm-Message-State: APuU4Z9K8WdoBfIsI4jJc8Bz0a5Lga39FdjN7IboXwqIFlKik8sl9X/6 0RtUwla3L+3dRdtIiVymPph8Oq4VcH4o4swnukWbw9RgGJ6zOwDK7m3jDPJYu5HcTQxJ0nIn+0n xpsGUqQ== X-Gm-Gg: AYBFou1/kxtIHLAr/aRxYxkhYugvs9dAHf5OWCSidHmLXYYmYLTirBymnofHH2C1RbA /E8v0rN1335MqnSySlF6QyBpgtW4CdHEILU3/ZzoUydtYJyr+v8fR1baMB2MFuX/mUts0QB3ytZ KTQZ9DcKZRFntzEmDMGfx12lHqFe0LLitr0u+u0fY0vg1GH4jIfB8g0ny5UiT/cc2l92DYU1K1Q bGl4ba9UnpEWiKLkMQE/JmoOPhUZ1JdNzjmW60TvJ9TegGeAinjxGgNwAC3qDcAMNMh5KAd1L9w yZwSflrRs1DJrN+IGS186VDWh9hWJWFqVBuSaKJWAY3mdnBtCDzLm/aQRed2hIAQwwrDmEkmorh gWXPXSY2towM5FFU0kpg6tZUjH0W3y06Lh1Gc7H1lMhZhGH6Osb5k0kFSO/zsSXoPo6Xa6ApRo1 u+xkcqtYPk1zVPGD0S+X5UtR2fig80z22DkrckzkPMCTrULHLJNTvS0nkFLQqndUqU/CFnNJUxj NX4SE7oFmM9l5zjbZXjJc9ijEUTVvD7e5PB9EBNels9rOcdV5XcnW3CWLvVKfYxjVQYg85pRtQx C7C9S0eCfTJYC6aFdzKjtV1SKplkotSI90W5RL+2yZ+SxJEsqS+E2vAPihiMKgT6RgvbaLIfjMQ Q+gJGIee5xeeyPEg= X-Received: by 2002:a05:600c:1906:b0:4af:79ee:f660 with SMTP id 5b1f17b1804b1-4b963c8153cmr71863165e9.31.1794229707510; Mon, 09 Nov 2026 05:08:27 -0800 (PST) Message-ID: Date: Mon, 9 Nov 2026 14:08:26 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v5 2/4] x86/traps: use entry_ssp in fixup_exception_return() From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , Teddy Astie , =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= References: Content-Language: en-US Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-ef75cf/1794229708-358C1AE4-2863B18D/10/78276251493 X-purgate-type: spam X-purgate-size: 5932 X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1794229722752158500 Content-Type: text/plain; charset="utf-8" With the value recorded on entry there's no need anymore to go hunt for the respective exception frame on the shadow stack. By deriving "ptr" from that field (without any offset), it then ends up pointing one slot lower than before. Therefore all array indexes need incrementing, nicely doing away with all the negative ones. Signed-off-by: Jan Beulich Reviewed-by: Andrew Cooper --- Indentation of the prior inner (but not innermost) if()'s body is deliberately left untouched, to aid review. It'll be adjusted in a separate follow-on patch. --- v3: Relax the first BUG_ON(). v2: IS_ENABLED() -> #ifdef. Re-base. --- a/xen/arch/x86/traps.c +++ b/xen/arch/x86/traps.c @@ -690,19 +690,6 @@ unsigned long get_stack_trace_bottom(uns } } =20 -static unsigned long get_shstk_bottom(unsigned long sp) -{ - /* SAF-11-safe */ - switch ( get_stack_page(sp) ) - { -#ifdef CONFIG_XEN_SHSTK - case 0: return ROUNDUP(sp, IST_SHSTK_SIZE) - sizeof(unsigned long); - case 5: return ROUNDUP(sp, PAGE_SIZE) - sizeof(unsigned long); -#endif - default: return sp - sizeof(unsigned long); - } -} - unsigned long get_stack_dump_bottom(unsigned long sp) { switch ( get_stack_page(sp) ) @@ -1187,26 +1174,29 @@ void asmlinkage noreturn do_unhandled_tr static void fixup_exception_return(struct cpu_user_regs *regs, unsigned long fixup, unsigned long stub= _ra) { - if ( IS_ENABLED(CONFIG_XEN_SHSTK) ) +#ifdef CONFIG_XEN_SHSTK { - unsigned long ssp, *ptr, *base; + unsigned long ssp =3D rdssp(); =20 - if ( (ssp =3D rdssp()) =3D=3D SSP_NO_SHSTK ) - goto shstk_done; + if ( ssp !=3D SSP_NO_SHSTK ) + { + unsigned long *ptr =3D _p(regs->entry_ssp); + unsigned long primary_shstk =3D + (ssp & ~(STACK_SIZE - 1)) + + (PRIMARY_SHSTK_SLOT + 1) * PAGE_SIZE - 8; =20 - ptr =3D _p(ssp); - base =3D _p(get_shstk_bottom(ssp)); + BUG_ON((regs->entry_ssp ^ primary_shstk) >> + (PAGE_SHIFT + STACK_ORDER)); =20 - for ( ; ptr < base; ++ptr ) - { /* - * Search for %rip. The shstk currently looks like this: + * The shstk currently looks like this: * * tok [Supervisor token, =3D=3D &tok | BUSY, only with FRE= D inactive] * ... [Pointed to by SSP for most exceptions, empty in IST= cases] * %cs [=3D=3D regs->cs] * %rip [=3D=3D regs->rip] - * SSP [Likely points to 3 slots higher, above %cs] + * SSP [Pointed to by entry_ssp; Likely points to 3 slots + * higher, above %cs] * ... [call tree to this function, likely 2/3 slots] * * and we want to overwrite %rip with fixup. There are two @@ -1219,13 +1209,10 @@ static void fixup_exception_return(struc * * Check for both regs->rip and regs->cs matching. */ - if ( ptr[0] =3D=3D regs->rip && ptr[1] =3D=3D regs->cs ) - { - unsigned long primary_shstk =3D - (ssp & ~(STACK_SIZE - 1)) + - (PRIMARY_SHSTK_SLOT + 1) * PAGE_SIZE - 8; + BUG_ON(ptr[1] !=3D regs->rip || ptr[2] !=3D regs->cs); =20 - wrss(fixup, ptr); + { + wrss(fixup, &ptr[1]); =20 if ( !stub_ra ) goto shstk_done; @@ -1242,7 +1229,7 @@ static void fixup_exception_return(struc * - if we're on an IST stack, we need to increment the * original SSP. */ - BUG_ON((ptr[-1] ^ primary_shstk) >> PAGE_SHIFT); + BUG_ON((ptr[0] ^ primary_shstk) >> PAGE_SHIFT); =20 if ( (ssp ^ primary_shstk) >> PAGE_SHIFT ) { @@ -1251,39 +1238,30 @@ static void fixup_exception_return(struc * addresses actually match. Then increment the inter= rupted * context's SSP. */ - BUG_ON(stub_ra !=3D *(unsigned long*)ptr[-1]); - wrss(ptr[-1] + 8, &ptr[-1]); + BUG_ON(stub_ra !=3D *(unsigned long*)ptr[0]); + wrss(ptr[0] + 8, &ptr[0]); goto shstk_done; } =20 /* Make sure the two return addresses actually match. */ - BUG_ON(stub_ra !=3D ptr[2]); + BUG_ON(stub_ra !=3D ptr[3]); =20 /* Move exception frame, updating SSP there. */ - wrss(ptr[1], &ptr[2]); /* %cs */ - wrss(ptr[0], &ptr[1]); /* %rip */ - wrss(ptr[-1] + 8, &ptr[0]); /* SSP */ + wrss(ptr[2], &ptr[3]); /* %cs */ + wrss(ptr[1], &ptr[2]); /* %rip */ + wrss(ptr[0] + 8, &ptr[1]); /* SSP */ =20 /* Move all newer entries. */ - while ( --ptr !=3D _p(ssp) ) - wrss(ptr[-1], &ptr[0]); + while ( ptr-- !=3D _p(ssp) ) + wrss(ptr[0], &ptr[1]); =20 /* Finally account for our own stack having shifted up. */ asm volatile ( "incsspd %0" :: "r" (2) ); - - goto shstk_done; } } - - /* - * We failed to locate and fix up the shadow IRET frame. This cou= ld - * be due to shadow stack corruption, or bad logic above. We cann= ot - * continue executing the interrupted context. - */ - BUG(); - } shstk_done: +#endif /* CONFIG_XEN_SHSTK */ =20 /* Fixup the regular stack. */ regs->rip =3D fixup; From nobody Mon Nov 23 22:28:33 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=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1794229748; cv=none; d=zohomail.com; s=zohoarc; b=YtBHYCCAsgDXttcnne1NQLu7M6XGB5lVHnzl4jKzdLspiGtmo8IJSoL8XowJ+FgIwk7DMoS3Refb3nOdiaw+Hu4cfP8V4MSdYCgQF4fXUW86MLCPWZ1VgI6gNbbF7MR5oXGrMZ30006GMYk9bJxduSnij93zEGaZDIBVgyz5hY8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794229748; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=kWNN+CSvpz5vv5zgWaxbE6Boj6ISxZgPbPxn4bWn+ns=; b=l6jzjeiXoxYXa+FOqPGkdyBcDKvzwt6gffTbn+wbHtduS0AFQv8Jl245mwmFHzZxChZrvDgjObHMNMCVmpuW5apUgZ4RFH4297UtS75Ntc6HWB2T6ZDi1mNcfdFyjO7v14WITsNIaC1+EdVWlFQuHV901DH749wVFWs7K0IPqBQ= 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=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 179422974894159.27281915810863; Mon, 9 Nov 2026 05:09:08 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1480044.1683979 (Exim 4.92) (envelope-from ) id 1xQP7D-0000xx-Hr; Mon, 09 Nov 2026 13:08:51 +0000 Received: by outflank-mailman (output) from mailman id 1480044.1683979; Mon, 09 Nov 2026 13:08:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xQP7D-0000xq-EQ; Mon, 09 Nov 2026 13:08:51 +0000 Received: by outflank-mailman (input) for mailman id 1480044; Mon, 09 Nov 2026 13:08:50 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) id 1xQP7C-0000xR-1I for xen-devel@lists.xenproject.org; Mon, 09 Nov 2026 13:08:50 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1xQP7B-003y5h-EM for xen-devel@lists.xenproject.org; Mon, 09 Nov 2026 14:08:49 +0100 Received: from [10.42.69.2] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6af1c5d4-8faa-0a2a0a5109dd-0a2a4502d7fe-40 for ; Mon, 09 Nov 2026 14:08:49 +0100 Received: from [209.85.221.44] (helo=mail-wr1-f44.google.com) by tlsNG-720697.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6af1c5e1-6ca4-0a2a45020019-d155dd2cf077-3 for ; Mon, 09 Nov 2026 14:08:49 +0100 Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-491971ac844so820372f8f.2 for ; Mon, 09 Nov 2026 05:08:49 -0800 (PST) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4b90ee249d3sm144512205e9.7.2026.11.09.05.08.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 09 Nov 2026 05:08:48 -0800 (PST) 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=suse.com header.i="@suse.com" header.h="Content-Transfer-Encoding:Content-Type:In-Reply-To:Autocrypt:Content-Language:References:Cc:To:From:Subject:User-Agent:MIME-Version:Date:Message-ID" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1794229729; x=1794834529; darn=lists.xenproject.org; h=content-transfer-encoding:content-type:in-reply-to:autocrypt :content-language:references:cc:to:from:subject:user-agent :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to:content-type; bh=kWNN+CSvpz5vv5zgWaxbE6Boj6ISxZgPbPxn4bWn+ns=; b=FPGv6Z+w/YU0ez+XvH0IYpRbcDVkfvWsuW2KWHh8kNkiNU/3pYwbM8Ah+ZXzc46vwX oj3g+Dd3is1paSufOp3QDIavH25lQ+Oe2tMIjqF306plaWzUoHxrhtReiIfhHlTJEFVN lDrGwiHFKXm1WGtigeq0eq6AbZoXS5TsPs/J+9MiIaAyDzOZ6u+4XfjbmnPxUXlxWkjE 6B3oYUZIKgxQ803ixCl4mMCnzNdG9HG1b6SO+JCooAxGTgSlVGXyzdUaQXWuHlzlh3Ch sicIW5/9Dm9bPyINHEcmgUl0s3n+vHG4npUHFM9/pxdRwrDHoDVbIy7o2BxFTaCOrxZy zw1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794229729; x=1794834529; h=content-transfer-encoding:content-type:in-reply-to:autocrypt :content-language:references:cc:to:from:subject:user-agent :mime-version:date:message-id:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to:content-type; bh=kWNN+CSvpz5vv5zgWaxbE6Boj6ISxZgPbPxn4bWn+ns=; b=YUUs2VNLtSCWQFNMrRDfP4NUAIXO/hQUg10AFmbw0ENz9T95khCTa01d7f8nlGoKlj DWuoAIIt6AGSt/tBEzLkxI7mMuVO0NO1g/WP74qWIl+WpK0I5T5JcC8iWJb1aQ/4H/Kd 9JBAxwqEXZMzjNdzTuZA3TRU5SJ0nPONA1s/bRjCbPgLqiXAz5/mCLwvgdGPFf6f9GVQ 8KAEspOiZpiC/j/DhCljFpULeoYPm7kSCyH5QcBoINsMdrrX04Cklad0gMb645mAW05Z QTbXy1ay+UDwz3HO7I1vM4NVLHjnPJUtQLjPU8MwRsdcMWwqhBgm15b8dVVZbZBeWjVb i+uQ== X-Gm-Message-State: APuU4Z+o1fF4H/zXGvsuKKrPDmavA1fWgjiR/bGwFZ3S9NGDjtTpaiNN RhQ05RhhroV+QWcVh7xizXaeyxRerzy1IE4FDL8j1VZrItj12gnnABIIMPnxzjlkzu43sa53jLU vskEAtA== X-Gm-Gg: AYBFou2AKUk4dWZvgJ8tPJg7JJquFT6YAobRREe45p4EzrwQ0x70uH+a42fjc8IZtIH Bs6Ehy9ylzGYYpk9s9GXBxRgbU6XhzH94sUey+Qjx+aJvQg/+1rBa20JJ9a0K4oGdLqF4+cR4De D8ss2dyMfppoJ5UATzyWGXj8TREDUfMmWHrRYEVoTH7U5UCtC2BG5hS54jDHTfPy3dl4ewXDMoY UH6fMSF5LFZd5vaG/dJ9O0ettk1O60sCNw5kSDnYu3qjU+kriNVlkvxzKkWa6/MJCFLYPwyjRAz 4PQFktbpA4FZqEpwtY1sL02CT6mtahZFEYJL7w4H2TzGN4bS1B/Aaa8QV6V3e63Hgbg9yr0FhD1 n7qjQgs8AiOfOIjR5nNUAOYsviSgk10g/mmoRMITmrwW2iI34Rk6DNKIPrWCklITZmV0tuftBrw n1B8zMCFcD/vCHAenL17Ogb67+1E+B5bal6VCJfldBv+RvD39O474MnfEAxuMeo5czoKfXn9cjI 3iVlsV9LEoedPkmnWunpyT7g+QSwzVpLrhT375ZrutvEG1ztBDQwMR+u2gdOw3AfTjNPiedyLkx LtLtN7f8SNuEKFMeCVnPezPsSEesx4H7Vzp0xfMnPtuCe+Jfb44MGW2xrHJCeLrKTwqIWt+JAKC xY8HbTrLbYf3uK+k3 X-Received: by 2002:a05:600c:1c02:b0:4a2:74f:46c1 with SMTP id 5b1f17b1804b1-4b9633cee71mr91387225e9.8.1794229728618; Mon, 09 Nov 2026 05:08:48 -0800 (PST) Message-ID: <6df9553e-af02-4c82-80c8-5b34dd7e919e@suse.com> Date: Mon, 9 Nov 2026 14:08:47 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v5 3/4] x86/traps: reduce indentation in fixup_exception_return() From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , Teddy Astie , =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= References: Content-Language: en-US Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-720697/1794229729-F32B12AC-3877A60C/10/78276251493 X-purgate-type: spam X-purgate-size: 7461 X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1794229751120158500 Content-Type: text/plain; charset="utf-8" The earlier "x86/traps: use entry_ssp in fixup_exception_return()" left unnecessary scopes and hence unnecessarily deep indentation. While that was intentional (to improve readabilirty of the diff), rectify this now. Signed-off-by: Jan Beulich Acked-by: Andrew Cooper --- v4: New. --- a/xen/arch/x86/traps.c +++ b/xen/arch/x86/traps.c @@ -1175,90 +1175,86 @@ static void fixup_exception_return(struc unsigned long fixup, unsigned long stub= _ra) { #ifdef CONFIG_XEN_SHSTK + unsigned long ssp =3D rdssp(); + + if ( ssp !=3D SSP_NO_SHSTK ) { - unsigned long ssp =3D rdssp(); + unsigned long *ptr =3D _p(regs->entry_ssp); + unsigned long primary_shstk =3D + (ssp & ~(STACK_SIZE - 1)) + + (PRIMARY_SHSTK_SLOT + 1) * PAGE_SIZE - 8; + + BUG_ON((regs->entry_ssp ^ primary_shstk) >> + (PAGE_SHIFT + STACK_ORDER)); + + /* + * The shstk currently looks like this: + * + * tok [Supervisor token, =3D=3D &tok | BUSY, only with FRED in= active] + * ... [Pointed to by SSP for most exceptions, empty in IST cas= es] + * %cs [=3D=3D regs->cs] + * %rip [=3D=3D regs->rip] + * SSP [Pointed to by entry_ssp; Likely points to 3 slots + * higher, above %cs] + * ... [call tree to this function, likely 2/3 slots] + * + * and we want to overwrite %rip with fixup. There are two + * complications: + * 1) We cant depend on SSP values, because they won't differ by + * 3 slots if the exception is taken on an IST stack. + * 2) There are synthetic (unrealistic but not impossible) + * scenarios where %rip can end up in the call tree to this + * function, so we can't check against regs->rip alone. + * + * Check for both regs->rip and regs->cs matching. + */ + BUG_ON(ptr[1] !=3D regs->rip || ptr[2] !=3D regs->cs); + + wrss(fixup, &ptr[1]); + + if ( !stub_ra ) + goto shstk_done; + + /* + * Stub recovery ought to happen only when the outer context + * was on the main shadow stack. We need to also "pop" the + * stub's return address from the interrupted context's shadow + * stack. That is, + * - if we're still on the main stack, we need to move the + * entire stack (up to and including the exception frame) + * up by one slot, incrementing the original SSP in the + * exception frame, + * - if we're on an IST stack, we need to increment the + * original SSP. + */ + BUG_ON((ptr[0] ^ primary_shstk) >> PAGE_SHIFT); =20 - if ( ssp !=3D SSP_NO_SHSTK ) + if ( (ssp ^ primary_shstk) >> PAGE_SHIFT ) { - unsigned long *ptr =3D _p(regs->entry_ssp); - unsigned long primary_shstk =3D - (ssp & ~(STACK_SIZE - 1)) + - (PRIMARY_SHSTK_SLOT + 1) * PAGE_SIZE - 8; - - BUG_ON((regs->entry_ssp ^ primary_shstk) >> - (PAGE_SHIFT + STACK_ORDER)); - /* - * The shstk currently looks like this: - * - * tok [Supervisor token, =3D=3D &tok | BUSY, only with FRE= D inactive] - * ... [Pointed to by SSP for most exceptions, empty in IST= cases] - * %cs [=3D=3D regs->cs] - * %rip [=3D=3D regs->rip] - * SSP [Pointed to by entry_ssp; Likely points to 3 slots - * higher, above %cs] - * ... [call tree to this function, likely 2/3 slots] - * - * and we want to overwrite %rip with fixup. There are two - * complications: - * 1) We cant depend on SSP values, because they won't diffe= r by - * 3 slots if the exception is taken on an IST stack. - * 2) There are synthetic (unrealistic but not impossible) - * scenarios where %rip can end up in the call tree to th= is - * function, so we can't check against regs->rip alone. - * - * Check for both regs->rip and regs->cs matching. + * We're on an IST stack. First make sure the two return + * addresses actually match. Then increment the interrupted + * context's SSP. */ - BUG_ON(ptr[1] !=3D regs->rip || ptr[2] !=3D regs->cs); + BUG_ON(stub_ra !=3D *(unsigned long*)ptr[0]); + wrss(ptr[0] + 8, &ptr[0]); + goto shstk_done; + } =20 - { - wrss(fixup, &ptr[1]); + /* Make sure the two return addresses actually match. */ + BUG_ON(stub_ra !=3D ptr[3]); =20 - if ( !stub_ra ) - goto shstk_done; + /* Move exception frame, updating SSP there. */ + wrss(ptr[2], &ptr[3]); /* %cs */ + wrss(ptr[1], &ptr[2]); /* %rip */ + wrss(ptr[0] + 8, &ptr[1]); /* SSP */ + + /* Move all newer entries. */ + while ( ptr-- !=3D _p(ssp) ) + wrss(ptr[0], &ptr[1]); =20 - /* - * Stub recovery ought to happen only when the outer conte= xt - * was on the main shadow stack. We need to also "pop" the - * stub's return address from the interrupted context's sh= adow - * stack. That is, - * - if we're still on the main stack, we need to move the - * entire stack (up to and including the exception frame) - * up by one slot, incrementing the original SSP in the - * exception frame, - * - if we're on an IST stack, we need to increment the - * original SSP. - */ - BUG_ON((ptr[0] ^ primary_shstk) >> PAGE_SHIFT); - - if ( (ssp ^ primary_shstk) >> PAGE_SHIFT ) - { - /* - * We're on an IST stack. First make sure the two ret= urn - * addresses actually match. Then increment the inter= rupted - * context's SSP. - */ - BUG_ON(stub_ra !=3D *(unsigned long*)ptr[0]); - wrss(ptr[0] + 8, &ptr[0]); - goto shstk_done; - } - - /* Make sure the two return addresses actually match. */ - BUG_ON(stub_ra !=3D ptr[3]); - - /* Move exception frame, updating SSP there. */ - wrss(ptr[2], &ptr[3]); /* %cs */ - wrss(ptr[1], &ptr[2]); /* %rip */ - wrss(ptr[0] + 8, &ptr[1]); /* SSP */ - - /* Move all newer entries. */ - while ( ptr-- !=3D _p(ssp) ) - wrss(ptr[0], &ptr[1]); - - /* Finally account for our own stack having shifted up. */ - asm volatile ( "incsspd %0" :: "r" (2) ); - } - } + /* Finally account for our own stack having shifted up. */ + asm volatile ( "incsspd %0" :: "r" (2) ); } shstk_done: #endif /* CONFIG_XEN_SHSTK */ From nobody Mon Nov 23 22:28:33 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=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1794229771; cv=none; d=zohomail.com; s=zohoarc; b=aUZZd9gSjT51Uh2LunleXgSM7QuORMjUkfbl2UJ0ENzFUt+9TGYU0ZtvcPZLW2Q1vlKKVugjY6Qgep6wUCMnmRmipbxP6A8PDi6DH+4Sta38HSlMfrgBRQ3Vm1oVvwuK97fybhv8GdpkodBDbgbSRrJtf23AojWNLwHwCIjNE/w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794229771; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=y40rikzKdW41I0gcKC+jqL54qXX/dn+hAUR30HB1xyE=; b=JbZQD60sA9kLL1klPVU6hZdslMp9gXUupfriyDvSNp3cIbqI3DcrJ4x1dA8LNgE4AaFxo8b3LUDDvXELrQtbgxajgR5ZL9mFCRcPwLGZrQYIAhdHoRPyGFgYDUp2Wc/279Uw2Fx3ezLMF7r1H6keZYKuTJYJTaO5f5UjoOOeqNQ= 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=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1794229771107487.0583863896909; Mon, 9 Nov 2026 05:09:31 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1480052.1683988 (Exim 4.92) (envelope-from ) id 1xQP7c-0001YT-Sr; Mon, 09 Nov 2026 13:09:16 +0000 Received: by outflank-mailman (output) from mailman id 1480052.1683988; Mon, 09 Nov 2026 13:09:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xQP7c-0001YM-QI; Mon, 09 Nov 2026 13:09:16 +0000 Received: by outflank-mailman (input) for mailman id 1480052; Mon, 09 Nov 2026 13:09:14 +0000 Received: from mx.expurgate.net ([194.145.224.10]) by lists.xenproject.org with esmtp (Exim 4.92) id 1xQP7a-0001WD-Me for xen-devel@lists.xenproject.org; Mon, 09 Nov 2026 13:09:14 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1xQP7a-00E8fp-3I for xen-devel@lists.xenproject.org; Mon, 09 Nov 2026 14:09:14 +0100 Received: from [10.42.69.3] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6af1c5f4-bab6-0a2a0a5309dd-0a2a4503c872-14 for ; Mon, 09 Nov 2026 14:09:14 +0100 Received: from [209.85.128.44] (helo=mail-wm1-f44.google.com) by tlsNG-33051d.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6af1c5f6-fae8-0a2a45030019-d155802cd8e5-3 for ; Mon, 09 Nov 2026 14:09:10 +0100 Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-4a210470b49so5993505e9.2 for ; Mon, 09 Nov 2026 05:09:10 -0800 (PST) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4b7e6eca30asm238392435e9.7.2026.11.09.05.09.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 09 Nov 2026 05:09:09 -0800 (PST) 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=suse.com header.i="@suse.com" header.h="Content-Transfer-Encoding:Content-Type:In-Reply-To:Autocrypt:Content-Language:References:Cc:To:From:Subject:User-Agent:MIME-Version:Date:Message-ID" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1794229750; x=1794834550; darn=lists.xenproject.org; h=content-transfer-encoding:content-type:in-reply-to:autocrypt :content-language:references:cc:to:from:subject:user-agent :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to:content-type; bh=y40rikzKdW41I0gcKC+jqL54qXX/dn+hAUR30HB1xyE=; b=DKRhCHqXXdSJKro64NcOClKf7cHrgS1RLh2F6LViifY9AWlJVi/02FLdF49OW0F+SV KjljLrgcs2ibtFJ8/zwO/UEFG/kOaEii0gJGldmviHd85Z/8p+Aqh63JQFLYgwBkOsxa OWJLzgbU0G8dB9YfhP+iQ+bqutbtaZThBMiiK/y6y12ogKA+c71r0LBaypoWTxp2AkdG Tkrk5sA3MnByRbEzLpNNpK/IcetRRlm0HIQeXuTDc8lbe2U4tgn3Z/uf4nb0fx6m4LpM 6E13/E01ZoFqpM2qEpb6yRMYLnMFNFVJ/wffch1S/+CIohX1yEb2NItZMLeTCJl4qL2B yVRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794229750; x=1794834550; h=content-transfer-encoding:content-type:in-reply-to:autocrypt :content-language:references:cc:to:from:subject:user-agent :mime-version:date:message-id:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to:content-type; bh=y40rikzKdW41I0gcKC+jqL54qXX/dn+hAUR30HB1xyE=; b=anhNirGYwI64mWmOV02UrTzg2ZX7zJG6cQqCR0H/lzgXPg/nlZDPHYrgHWNAgNQN8t TScpFBjnlPmIhaLGDa1c1M2NGPPTOA7VI/SLeq72KbqWAa9CRhKRqWnp4UDBOvUGZ1SN K16gZ1D5Q60xFqrFm3cm5VKlOD2NmiBHl7A68f7rgMdTOPTgLMdeOmsgAu2GWaQy/ucV EcZYkLmoGH/0i2gB/0Hfj+r+ZFc+kGWp4akfLgFS9pHSyVzw8PNMX9TMe/Nc/WGwh0h9 spWFRKTvtA36974ermMRwMZEvqMb3v5L252tSGjzVMobxCdt461hiP8oIEgwEGV4nY4f tcFg== X-Gm-Message-State: APuU4Z8kQIiYKyolgnV/k32IuMlJss6rZphwFRO9r8vR6nFKkvZEcdsL pXapVgus8mDIRMwqpJ8Q2NZ9xTsxarn7GD0jB22a2Ngk15TM57jeEFARDFlXcl39ZZfJ5dOwjKv +5LuKCA== X-Gm-Gg: AYBFou0k8KpcmdMmjzJj5KQuWQW39vfDGV1qZ2TQPdg4GA5V0cn+D5YP+v755JmvZLm QHXP2sDaC/bHHVLJ8PzOHc3Qn3/kWyB9voG6t+ojzXUkM74psUvhOe7c/v23gn9bPRBiaznZU/n xFHqytOsPfUgYeytD+JZzMBlXisbt7UdFJ+aUbUQcaBQiI4f5PiYiiU5w3BxQoUtdchHQ+WxRPF mRGbOZc0aI4MVHfrHCPya7+t71+JiCfiT09a61HJ0/meWl8XJTv1rmws9sZ9ERlT6sNee3ALv/5 8rJcVB88X8VDIaWRxCCxS6jqUP+UK/s1xO3sdF4IM9X/czDR1Zo/3UG7RK77HJHn8HAmgPL3mhI wDXzmJH9mkPYdQatP0lW5WRJtJGcPtBvFf911C5oP9fa6jnWHletP/Va7RH9TDiDN+3l11lhBk3 S/5qNfL7QrCmlw5nUb4qVhWxzF8lSeMd76pcMuYnYeSTPc1cPt5Jcx0vCu9YtjPBGtJxwNQTixO yOS3c4fA4q3nhjUEzjk62a6GUAH/yR72zc9dPMNQNnYJNBsaOZh1HYQcUACH0qjUX8F3oGiHOp+ d8HNRIkns96/pynka02V0HSX+C2fCFIXSCFU5uTp7mmj5aTZHfskosl5ZtkABwv9woXg++WQPQZ DYrD0aGRtHMuAWr4= X-Received: by 2002:a05:600c:3148:b0:4b7:dc0:89c with SMTP id 5b1f17b1804b1-4b963c88bd6mr79037015e9.32.1794229749743; Mon, 09 Nov 2026 05:09:09 -0800 (PST) Message-ID: Date: Mon, 9 Nov 2026 14:09:07 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v5 4/4] x86: prefer shadow stack for producing call traces From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , Teddy Astie , =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= References: Content-Language: en-US Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-33051d/1794229750-760FE4E9-3413C342/10/78276251493 X-purgate-type: spam X-purgate-size: 4605 X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1794229773491158500 Content-Type: text/plain; charset="utf-8" Shadow stacks contain little more than return addresses, and they in particular allow precise call traces also with FRAME_POINTER=3Dn: (XEN) Xen call trace: (XEN) [] R extable.c#search_one_extable+0x70/0x73 (XEN) [] C search_exception_table+0xc2/0x177 (XEN) [] C traps.c#extable_fixup.isra.0+0x18/0x6c (XEN) [] C do_invalid_op+0xab/0x106 (XEN) [] C x86_64/entry.S#handle_exception_saved+0x88/= 0xf4 (XEN) [] E ffff82d07fffe044 (XEN) [] C stub_selftest+0xd0/0x168 (XEN) [] C setup.c#init_done+0x116/0x15a as opposed to this counterpart (earlier during the same boot, before CET is enabled): (XEN) Xen call trace: (XEN) [] R extable.c#search_one_extable+0x70/0x73 (XEN) [] S search_exception_table+0xc2/0x177 (XEN) [] S traps.c#extable_fixup.isra.0+0x18/0x6c (XEN) [] S do_invalid_op+0xab/0x106 (XEN) [] S x86_64/entry.S#handle_exception_saved+0x88/= 0xf4 (XEN) [] S stub_selftest+0xd0/0x168 (XEN) [] S do_initcalls+0x29/0x38 (XEN) [] S __start_xen+0x1c72/0x2235 (XEN) [] S __high_start+0xb7/0xc0 (note the entirely missing entry for the stub itself [1]; sadly there are no stray entries there). [1] Arguably we could teach FRAME_POINTER=3Dn traces to recognize stubs as well. But not FRAME_POINTER=3Dy ones. In fact, what's missing there isn't the stub itself, but (of course) its immediate caller. Signed-off-by: Jan Beulich --- While the 'E' for exception frames is probably okay, I'm not overly happy with the 'C' (for CET). I would have preferred 'S' (for shadow), but we use that character already. As an alternative to suppressing output for the top level exception frame, adding the new code ahead of the 'R' output line (and then also ahead of the stack top read) could be considered. Quite likely a number of other uses of is_active_kernel_text() also want amending with in_stub(). --- v3: Correct "link to other shadow stack" check. Don't log a line for the (impossible) PV case. Add example stack trace to description. v2: IS_ENABLED() -> #ifdef. Re-base. --- a/xen/arch/x86/traps.c +++ b/xen/arch/x86/traps.c @@ -48,6 +48,7 @@ #include #include #include +#include #include #include #include @@ -705,6 +706,13 @@ unsigned long get_stack_dump_bottom(unsi } } =20 +#ifdef CONFIG_XEN_SHSTK +static bool in_stub(unsigned long addr) +{ + return !((this_cpu(stubs.addr) ^ addr) >> STUB_BUF_SHIFT); +} +#endif + #if !defined(CONFIG_FRAME_POINTER) =20 /* @@ -797,6 +805,49 @@ static void show_trace(const struct cpu_ !is_active_kernel_text(tos) ) printk(" [<%p>] R %pS\n", _p(regs->rip), _p(regs->rip)); =20 +#ifdef CONFIG_XEN_SHSTK + if ( rdssp() !=3D SSP_NO_SHSTK ) + { + const unsigned long *ptr =3D _p(regs->entry_ssp); + unsigned int n; + + for ( n =3D 0; (unsigned long)ptr & (PAGE_SIZE - sizeof(*ptr)); ++= n ) + { + unsigned long val =3D *ptr; + + if ( is_active_kernel_text(val) || in_stub(val) ) + { + /* Normal return address entry. */ + printk(" [<%p>] C %pS\n", _p(val), _p(val)); + ++ptr; + } + else if ( !((val ^ (unsigned long)ptr) >> + (PAGE_SHIFT + STACK_ORDER)) ) + { + if ( val & (sizeof(val) - 1) ) + { + /* Most likely a supervisor token. */ + break; + } + + /* + * Ought to be a hypervisor interruption frame. But don't + * (re)log the current frame's %rip. + */ + if ( n || ptr[1] !=3D regs->rip ) + printk(" [<%p>] E %pS\n", _p(ptr[1]), _p(ptr[1])); + ptr =3D _p(val); + } + else /* Bogus. */ + break; + } + + /* Fall back to legacy stack trace if nothing was logged at all. */ + if ( n ) + return; + } +#endif /* CONFIG_XEN_SHSTK */ + if ( fault ) { printk(" [Fault on access]\n");