From nobody Tue Feb 10 02:43:23 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=1637944706; cv=none; d=zohomail.com; s=zohoarc; b=LOQCBlCzx38fOBDNYzhAHvMpwLPboZkixjUy1Ss6nLO3Z7dFgbv7U7PUFH2lglXRnzEtmVfWn13vHnpbGDbZhR9IBIv1U4zJ2wRozuSFNB7U4XLLjekaawBLX5Ups9tYZLbuMA/4kIwSvFQZke+HUebyFdtJSuH0oalG1NUEDWA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637944706; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=5Gqyz1tDmnPBMtAUwHhjOuY4AMpFNXal6eVIKQVu4is=; b=FPrTd+9TWr+to6OBULXePL2RsIIBbR3V+P1lAgeuBqXc1IubMWstm93cIoSSaRxt3gkUlRJ3XFmMEiObYZC70Yh6FpFxtwyEI+HrloEf+l3B6e3wdI9hNgSrQ2WsAi//aeUjbIDrKsaKm5Wg0OTVp862vh5UKmEtf6TpJ9/132s= 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 163794470618821.89974505097564; Fri, 26 Nov 2021 08:38:26 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.233242.404595 (Exim 4.92) (envelope-from ) id 1mqeEe-00017C-QJ; Fri, 26 Nov 2021 16:38:04 +0000 Received: by outflank-mailman (output) from mailman id 233242.404595; Fri, 26 Nov 2021 16:38:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mqeEe-000175-Mw; Fri, 26 Nov 2021 16:38:04 +0000 Received: by outflank-mailman (input) for mailman id 233242; Fri, 26 Nov 2021 16:38:03 +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 1mqeEd-00016T-H3 for xen-devel@lists.xenproject.org; Fri, 26 Nov 2021 16:38:03 +0000 Received: from esa6.hc3370-68.iphmx.com (esa6.hc3370-68.iphmx.com [216.71.155.175]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 3798379d-4ed7-11ec-9787-a32c541c8605; Fri, 26 Nov 2021 17:38:01 +0100 (CET) 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: 3798379d-4ed7-11ec-9787-a32c541c8605 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1637944681; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3/NSMBOP/JTQOyrzYRs/g6kXzLCntN/islndZqobP2A=; b=fHTEOc5bsGQR/2ghLjq12c9Ysde2RrWLIZD+PvjpMSdd8tx1ldQALi7m UR7CrSZ4ZcabtZAh+quoUhNypWg9b4yyzMYCqgeqF8VtOJT3Jt1DMu8Vo U7LUwInHWF0X9mxKNHsT+5Nw8xvZWoB8Bir3YU7WErPPJM1ryuKDSWa8E g=; Authentication-Results: esa6.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: gP0vgzTaE3WaM/cuUgl+CufkQG5kFJBtOQLSYtnjRVimZhPkhfI9r1CKRblfJ2Siwlzp7lk5Pi uqGf2I9Q/Lq+iQQ2Uk4JVQ766DJBFeeTnMip0FCo15yLXhcIwIAtjOn2Nmsc/Rr0FwrONfa+lX iLd2/OLLlvJXCv7r+Sup18zbPu0co4BlOBa+TZByHDLAQ3cqP02PrPNDChlCDsQyN8VPhxePNk QOQD4slsyMrzV9YqNr1WCXBZUB3wle+kWHg1CpiBhqf1yMu6Iq2KXQ6EKzJmlSXhgWKQcag1rT yqUbewEqur95krDwC/c94Y4o X-SBRS: 5.1 X-MesageID: 58647550 X-Ironport-Server: esa6.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-Data: A9a23:CDflPq3zkrkNgO6zh/bD5R52kn2cJEfYwER7XKvMYLTBsI5bpzQGz TYfC2vVbKyDMWfzfd8kYNzl8R5TuMXWztY1TgU5pC1hF35El5HIVI+TRqvS04J+DSFhoGZPt Zh2hgzodZhsJpPkS5PE3oHJ9RGQ74nRLlbHILOCan8ZqTNMEn970Es6wbBh2OaEvPDia++zk YKqyyHgEAfNNw5cagr4PIra9XuDFNyr0N8plgRWicJj5TcypFFMZH4rHomjLmOQf2VhNrXSq 9Avbl2O1jixEx8FUrtJm1tgG6EAaua60QOm0hK6V0U+6/TrS+NbPqsTbZIhhUlrZzqhg+8t2 NUUmr6KaiQ3OIz2we4NWSJgHHQrVUFG0OevzXmXtMWSywvNcmf2wuUoB0YzVWEa0r8pWycUr 6VecW1TKEDY7w616OvTpu1Er8IvNsT0eqgYvWlt12rxBvc6W5HTBa7N4Le02R9t1p4SQquDP 6L1bxIxQyzfQyVkFm4KS7cDmb+4gmikbjRx/Qf9Sa0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2f9WTua6YgqjBIokLtp133Aq2lEZdPRUGvb3qy nIpoVj6faUskd2ZJhOo7C90cW7LU80sKQFhLX5Xo3SOzUO2lHYT72KhLGKq1aLdhEWtNQtsZ uIG5IOcOEYZmIasS+V2maF+q4bsbu6zJw= X-IronPort-AV: E=Sophos;i="5.87,266,1631592000"; d="scan'208";a="58647550" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu Subject: [PATCH v1.1 60/65] x86/emul: Update emulation stubs to be CET-IBT compatible Date: Fri, 26 Nov 2021 16:37:14 +0000 Message-ID: <20211126163714.28870-1-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20211126123446.32324-1-andrew.cooper3@citrix.com> References: <20211126123446.32324-1-andrew.cooper3@citrix.com> 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: 1637944707264100001 All indirect branches need to land on an endbr64 instruction. For stub_selftests(), use endbr64 unconditionally for simplicity. For iopo= rt and instruction emulation, add endbr64 conditionally. Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Wei Liu v2: * Update to use endbr helpers --- xen/arch/x86/extable.c | 14 +++++++++----- xen/arch/x86/pv/emul-priv-op.c | 7 +++++++ xen/arch/x86/x86_emulate.c | 13 +++++++++++-- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/xen/arch/x86/extable.c b/xen/arch/x86/extable.c index 4aa1ab4b2a45..25c6fda00d28 100644 --- a/xen/arch/x86/extable.c +++ b/xen/arch/x86/extable.c @@ -129,19 +129,23 @@ search_exception_table(const struct cpu_user_regs *re= gs) static int __init cf_check stub_selftest(void) { static const struct { - uint8_t opc[4]; + uint8_t opc[8]; uint64_t rax; union stub_exception_token res; } tests[] __initconst =3D { - { .opc =3D { 0x0f, 0xb9, 0xc3, 0xc3 }, /* ud1 */ + { .opc =3D { 0xf3, 0x0f, 0x1e, 0xfa, /* endbr64 */ + 0x0f, 0xb9, 0xc3, 0xc3 }, /* ud1 */ .res.fields.trapnr =3D TRAP_invalid_op }, - { .opc =3D { 0x90, 0x02, 0x00, 0xc3 }, /* nop; add (%rax),%al */ + { .opc =3D { 0xf3, 0x0f, 0x1e, 0xfa, /* endbr64 */ + 0x90, 0x02, 0x00, 0xc3 }, /* nop; add (%rax),%al */ .rax =3D 0x0123456789abcdef, .res.fields.trapnr =3D TRAP_gp_fault }, - { .opc =3D { 0x02, 0x04, 0x04, 0xc3 }, /* add (%rsp,%rax),%al */ + { .opc =3D { 0xf3, 0x0f, 0x1e, 0xfa, /* endbr64 */ + 0x02, 0x04, 0x04, 0xc3 }, /* add (%rsp,%rax),%al */ .rax =3D 0xfedcba9876543210, .res.fields.trapnr =3D TRAP_stack_error }, - { .opc =3D { 0xcc, 0xc3, 0xc3, 0xc3 }, /* int3 */ + { .opc =3D { 0xf3, 0x0f, 0x1e, 0xfa, /* endbr64 */ + 0xcc, 0xc3, 0xc3, 0xc3 }, /* int3 */ .res.fields.trapnr =3D TRAP_int3 }, }; unsigned long addr =3D this_cpu(stubs.addr) + STUB_BUF_SIZE / 2; diff --git a/xen/arch/x86/pv/emul-priv-op.c b/xen/arch/x86/pv/emul-priv-op.c index 808ff1873352..e35cb4b8669d 100644 --- a/xen/arch/x86/pv/emul-priv-op.c +++ b/xen/arch/x86/pv/emul-priv-op.c @@ -26,6 +26,7 @@ =20 #include #include +#include #include #include #include @@ -111,6 +112,12 @@ static io_emul_stub_t *io_emul_stub_setup(struct priv_= op_ctxt *ctxt, u8 opcode, =20 p =3D ctxt->io_emul_stub; =20 + if ( cpu_has_xen_ibt ) + { + place_endbr64(p); + p +=3D 4; + } + APPEND_BUFF(prologue); APPEND_CALL(load_guest_gprs); =20 diff --git a/xen/arch/x86/x86_emulate.c b/xen/arch/x86/x86_emulate.c index 60191a94dc18..720740f29b84 100644 --- a/xen/arch/x86/x86_emulate.c +++ b/xen/arch/x86/x86_emulate.c @@ -17,6 +17,7 @@ #include #include /* cpu_has_amd_erratum() */ #include +#include =20 /* Avoid namespace pollution. */ #undef cmpxchg @@ -29,11 +30,19 @@ cpu_has_amd_erratum(¤t_cpu_data, AMD_ERRATUM_##nr) =20 #define get_stub(stb) ({ \ + void *ptr; \ BUILD_BUG_ON(STUB_BUF_SIZE / 2 < MAX_INST_LEN + 1); \ ASSERT(!(stb).ptr); \ (stb).addr =3D this_cpu(stubs.addr) + STUB_BUF_SIZE / 2; \ - memset(((stb).ptr =3D map_domain_page(_mfn(this_cpu(stubs.mfn)))) + \ - ((stb).addr & ~PAGE_MASK), 0xcc, STUB_BUF_SIZE / 2); \ + (stb).ptr =3D map_domain_page(_mfn(this_cpu(stubs.mfn))) + \ + ((stb).addr & ~PAGE_MASK); \ + ptr =3D memset((stb).ptr, 0xcc, STUB_BUF_SIZE / 2); \ + if ( cpu_has_xen_ibt ) \ + { \ + place_endbr64(ptr); \ + ptr +=3D 4; \ + } \ + ptr; \ }) #define put_stub(stb) ({ \ if ( (stb).ptr ) \ --=20 2.11.0