From nobody Fri Oct 31 09:15:27 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=1747926044; cv=none; d=zohomail.com; s=zohoarc; b=EHu6KtG17FOxCa77sBBcwIEUbBBUAZBCjHZnLlI2YMzEPVvRbV1rNXvw9FfV0dZmtaTx+GrZ7COBmqhewJqo3nOTgPME+pYBUZ2nznLlOkRqWoMt+I30p8nR/9h+6UlhMNj38OJFDTV8ikdkfM9S7XS6xvW+Y1LHyK3qY8O3Dfc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1747926044; 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:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ljRP4y1r3tEpwonUwcR95PojX/tUgMS8XUn01iePeGU=; b=SUWT5CyjqUaPaTUNNGrnV+c0txDZtdbpwVOCjSNA3y+2rJo2d6432ZoGAsKBg1b+9XAyhrvmkNiVJ0yUrEwlh+Wp6GNJy2pE9ncXtwQBYTEpXrKGHGo/C9ChDxMOpZcwdsbqg7jTOE+5HtaMqIgpmTx4zVGfNiYtB6C5y8sPHfk= 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 1747926043996791.8515155280463; Thu, 22 May 2025 08:00:43 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.994167.1377208 (Exim 4.92) (envelope-from ) id 1uI7PE-0003t9-Ea; Thu, 22 May 2025 15:00:24 +0000 Received: by outflank-mailman (output) from mailman id 994167.1377208; Thu, 22 May 2025 15:00:24 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uI7PE-0003rz-BN; Thu, 22 May 2025 15:00:24 +0000 Received: by outflank-mailman (input) for mailman id 994167; Thu, 22 May 2025 15:00:22 +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 1uI7PC-0003kR-H3 for xen-devel@lists.xenproject.org; Thu, 22 May 2025 15:00:22 +0000 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [2a00:1450:4864:20::52c]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 7ba248ee-371d-11f0-a2fb-13f23c93f187; Thu, 22 May 2025 17:00:21 +0200 (CEST) Received: by mail-ed1-x52c.google.com with SMTP id 4fb4d7f45d1cf-5f3f04b5dbcso12271962a12.1 for ; Thu, 22 May 2025 08:00:21 -0700 (PDT) Received: from localhost.localdomain (host-92-26-98-202.as13285.net. [92.26.98.202]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-6005ac32a7fsm10550119a12.56.2025.05.22.08.00.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 May 2025 08:00:20 -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: 7ba248ee-371d-11f0-a2fb-13f23c93f187 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1747926021; x=1748530821; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ljRP4y1r3tEpwonUwcR95PojX/tUgMS8XUn01iePeGU=; b=qFzqVxcz/TBe1GR0f3imECCEGXt8ucop/9QAXy1s60al7tItVAoL8eXEBwrhXr4SGZ i1QzKF661PYgswjsyEzI2vv2RBPO57qGlXtnSs+RhuQy1tDqyavAPv0uWbg3BrGhzBmN f5jvKbr1DWcFFzjEH/umAiBtPqjnhjm+uWdak= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747926021; x=1748530821; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ljRP4y1r3tEpwonUwcR95PojX/tUgMS8XUn01iePeGU=; b=GKaGDYVktCkEf8jdvHXTg7629u2pNDIUaaRBxBFJoMllo2zVyJz8qwmRUkR+BWBk57 1fLGDdS7VYruKDTDJNTdbOoRLsFw9CgG8QEqWVV4jqNPkd8mrGv/9kUjs7E7VWSVvWeO oPkISRULr6iFJkFKb0+gdGq2grOqxPRRf4xHcla+gNIANexmNGBM2d/ygYayKzPcA3Rf eHCITLMTuDbb+PBfGbvM3dG3q6+g85hG81dRPluaWKn5XLYIicUkmIykRGSyiLrf/sCF 5V6c9tEJhyJgZHxXRuOH+Ioi7wfdvrQI8jTAkjbfbFW7n8MHZrjKiQik+qqQ0LPcrvFb QvgQ== X-Gm-Message-State: AOJu0YwTpESXE5v72dT7f0Pa/ogufRk3H9/0B9I4sTWUfXWjsiDn/rg7 vL/FWZRgArjkp1dXQRLCQbJAx86vzlX+mZBKo5IuzIWMY/dshTQTsa4HUVkUdQmBZFSASDs11hT 8jCHa X-Gm-Gg: ASbGncs6T/wECEm+yFtc/w7lb0kMZ2lYugVcx+4PeitvIkWv4UZHLLYzMgo5cFoVb+N jJzLfrHvTn0Syx18RWs7miX8O2WuhEj+umFmmUpb00A3Yfp8+pCHFlQlFLvtey50xsZtHe3t37A zPBiyWkKDZGm9tvz+QmlWFS/DkuVsQQVbye9OlmulcPWteXkSO1IF+QE2wbphqn2IE6FNRQyLAX HCD0dSbKXMFUwouiwSNoh+eibIBOxWVaUpvbdFLaptfEdDQqwKDEvI453Jeejdydo0NEb4VtGy+ /xu5F83T62qVXYNu8gVjnFXOJkuH9HjY7AoW9b+XSu56gU8WO7XWkwuqPG+kZn9vNubbxUJYCwp Z4USqRsS35D6vwko/npp3ovU7 X-Google-Smtp-Source: AGHT+IEmxj6rPzsElnxUfYxYT7ERgKr+r2Hy5iHlkty1zrydVqmvddsQiDbNWydC/aVOLZzOLCtaxQ== X-Received: by 2002:a05:6402:358f:b0:602:2d06:6b19 with SMTP id 4fb4d7f45d1cf-6022d066f47mr6642878a12.1.1747926020894; Thu, 22 May 2025 08:00:20 -0700 (PDT) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH 1/3] x86/alternatives: Factor out access to ideal_nops[] Date: Thu, 22 May 2025 16:00:13 +0100 Message-Id: <20250522150015.555492-2-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250522150015.555492-1-andrew.cooper3@citrix.com> References: <20250522150015.555492-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: 1747926045069116600 ... in order to rework the calculation. No functional change. Signed-off-by: Andrew Cooper Acked-by: Jan Beulich --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 --- xen/arch/x86/alternative.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/alternative.c b/xen/arch/x86/alternative.c index ecc56964bd9c..cc2d0c89aca3 100644 --- a/xen/arch/x86/alternative.c +++ b/xen/arch/x86/alternative.c @@ -86,6 +86,11 @@ static bool init_or_livepatch_read_mostly toolchain_nops= _are_ideal; # define toolchain_nops_are_ideal false #endif =20 +static const unsigned char *get_ideal_nops(unsigned int noplen) +{ + return ideal_nops[noplen]; +} + static void __init arch_init_ideal_nops(void) { switch ( boot_cpu_data.x86_vendor ) @@ -116,7 +121,7 @@ static void __init arch_init_ideal_nops(void) } =20 #ifdef HAVE_AS_NOPS_DIRECTIVE - if ( memcmp(ideal_nops[ASM_NOP_MAX], toolchain_nops, ASM_NOP_MAX) =3D= =3D 0 ) + if ( memcmp(get_ideal_nops(ASM_NOP_MAX), toolchain_nops, ASM_NOP_MAX) = =3D=3D 0 ) toolchain_nops_are_ideal =3D true; #endif } @@ -127,9 +132,11 @@ void init_or_livepatch add_nops(void *insns, unsigned = int len) while ( len > 0 ) { unsigned int noplen =3D len; + if ( noplen > ASM_NOP_MAX ) noplen =3D ASM_NOP_MAX; - memcpy(insns, ideal_nops[noplen], noplen); + + memcpy(insns, get_ideal_nops(noplen), noplen); insns +=3D noplen; len -=3D noplen; } --=20 2.39.5 From nobody Fri Oct 31 09:15:27 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=1747926045; cv=none; d=zohomail.com; s=zohoarc; b=LgLOhdTXd7ZaHsn2DA0eMlcYJIEtdiRCdqmdoXi7JOGgLvt3EdQGF17bP+c4fLI+cp0uSUJSPZzpz0f27kjSA9fpGr5KQxSDxBuYH7X5Z7tFmKxL+LOtZIwEIrGL6Yj0E/h9bwEbo09U4UrThvodNml0dIb2j/kmm6udrQed6JI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1747926045; 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:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=3Ul/tNZRZ1TlH45ain/OMZmy2A/UotZfS6GWeE2NRSQ=; b=TfxAyHutfj1P7DtWXqHmXkP36o/AURhexXywvE2CYZI6DDkzQI9TZHFKVXV0khSUf967Jp1Wb/nVk//g6qg2VUPxkJ5ORT5kTW8MC5kDlT1FNOY5Y8pV29ZuMTrk+VXZKUyavESqpajbOcz4X4xUvMWp4+wvAdbAm2TwjIyVcKU= 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 174792604522771.90053110769873; Thu, 22 May 2025 08:00:45 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.994168.1377225 (Exim 4.92) (envelope-from ) id 1uI7PF-0004IV-OO; Thu, 22 May 2025 15:00:25 +0000 Received: by outflank-mailman (output) from mailman id 994168.1377225; Thu, 22 May 2025 15:00:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uI7PF-0004H5-KD; Thu, 22 May 2025 15:00:25 +0000 Received: by outflank-mailman (input) for mailman id 994168; Thu, 22 May 2025 15:00:24 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uI7PE-0003qi-A4 for xen-devel@lists.xenproject.org; Thu, 22 May 2025 15:00:24 +0000 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [2a00:1450:4864:20::52b]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 7c4769fb-371d-11f0-b892-0df219b8e170; Thu, 22 May 2025 17:00:22 +0200 (CEST) Received: by mail-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-601a6e2e93cso1078856a12.1 for ; Thu, 22 May 2025 08:00:22 -0700 (PDT) Received: from localhost.localdomain (host-92-26-98-202.as13285.net. [92.26.98.202]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-6005ac32a7fsm10550119a12.56.2025.05.22.08.00.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 May 2025 08:00:21 -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: 7c4769fb-371d-11f0-b892-0df219b8e170 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1747926022; x=1748530822; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3Ul/tNZRZ1TlH45ain/OMZmy2A/UotZfS6GWeE2NRSQ=; b=qy2JAXsno9K7JStIq8vmmLp9fL6Yrq8IJSeSjDLqSt4wjW1gWm6oTmW5SxCuj/jyrH O7FN1N7pXdf/lGsdBzdn+yHVYe+658tL+yjM9qXQ6iAySeo6PpVJZMYvP9GdjKCyUbsG eyw0DLeo6cEJTPsVcHIpHfDquxtOOHPB/xsuU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747926022; x=1748530822; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3Ul/tNZRZ1TlH45ain/OMZmy2A/UotZfS6GWeE2NRSQ=; b=Ohb2G6bDafR2nqpzwdHrjabZ06OFdHBi2wEv4VH4bmCnS8NKvN6Ya9zalEfHBtbIeG a5DlxC1zAK+K+QRB8hON2MDWu9cTecveIhR/FRs3awVCGiwSjdjRmlUrKHu2a0xbJUz9 75ZzUsLynP4PLHEVCCDmZm0AKQ4OxeKj/9Jf1GsQCwVikvxKBYvd6/GU3YOcRJ+Tpe7P UhYt1GmCHXf4ec+RB6cPVoeY/hyUBAYlgy/cMStOAcVV6qdLcwvfHivrqA4G/TPhhX76 0hrfl/e6Mki2U9n5DFuPKVnVQaOFsJ4euXgQZlNtwKTUsDO6zb2r5i++VL/PGtCf3HKP o+YQ== X-Gm-Message-State: AOJu0Yz2P0ZCxmRThUyMDjIB1fIorKSO3CHVvgN7oN7FRsBCiPcYubYM WdQsqyUoyvFK0siepVp3e88KMMBuk/AeM8j3i7pz5xQtvRZhsfbtg26FTTaX97oLMjOJ4A3ua/0 F/Zb6 X-Gm-Gg: ASbGncuD/3BlD4r/EIYAsLT/J0xEteYsdn5gs7xo/2cYTmW3ZBo0I+917ZjQvbAgZLB LVF3VucMK4VbQeJ4Kt4A5xBA7CfuN1+uJION92WJ8+1RoUNKvLGlaR0U5WBQJtZ9tauLvQ+dKkQ X/EV5WMKG69HpIXlFhOKEP/IxH9kf5JdQ5uY+z7Cae1BhsN9ftFJYzINAn/pexEymAU9iM3nEDj WvMaknhE6HcQqCBmvtnEqlKNAC1LjsLB5cZrsX9UHNyXmXaUPjseWdyxHnZIFryafqr/7XrFeWG zIdcKiflCssQuaYetB3A3p91AfQ8kH4gTphrI+lczX/4PwTtKdgZh3H7/yZ8ped4/ya0PxRPSMO GFSpuBLzYeSrXvlYcWnkt2V3aZgsQFyAwlxo= X-Google-Smtp-Source: AGHT+IFASlcGlaKb1Z2UunBUZ54ibZHHQNVikl7rpE8jSvm4IynpdunZ+amUYf3dZh7NQwzlRJx06g== X-Received: by 2002:a05:6402:2105:b0:602:d98:5d83 with SMTP id 4fb4d7f45d1cf-6020d9860bamr9635108a12.5.1747926021934; Thu, 22 May 2025 08:00:21 -0700 (PDT) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH 2/3] x86/alternatives: Rework get_ideal_nops() Date: Thu, 22 May 2025 16:00:14 +0100 Message-Id: <20250522150015.555492-3-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250522150015.555492-1-andrew.cooper3@citrix.com> References: <20250522150015.555492-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: 1747926047252116600 The {k8,p6}_nops[] arrays are both 80-byte structures indexing 45-byte structures. Furthermore, perhaps unusually for C, the source layout is an obvious hint about the trangular nature of the structure. Therefore, we can replace the pointer chase with some simple arithmatic. No functional change. Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 The implemenation of get_ideal_nops() changes from: mov 0x19bc41(%rip),%rax # mov %edi,%edi mov (%rax,%rdi,8),%rax jmp <__x86_return_thunk> to: lea -0x1(%rdi),%eax imul %edi,%eax shr %eax add 0x67fc1(%rip),%rax # jmp <__x86_return_thunk> The imul has a latency of 3 cycles on all CPUs back to the K8 and Nehalem. It's better than an extra deference on all CPUs, even the older ones. --- xen/arch/x86/alternative.c | 40 ++++++++++++-------------------------- 1 file changed, 12 insertions(+), 28 deletions(-) diff --git a/xen/arch/x86/alternative.c b/xen/arch/x86/alternative.c index cc2d0c89aca3..ff7d83c0ddbd 100644 --- a/xen/arch/x86/alternative.c +++ b/xen/arch/x86/alternative.c @@ -20,7 +20,7 @@ #define MAX_PATCH_LEN (255-1) =20 #ifdef K8_NOP1 -static const unsigned char k8nops[] init_or_livepatch_const =3D { +static const unsigned char k8_nops[] init_or_livepatch_const =3D { K8_NOP1, K8_NOP2, K8_NOP3, @@ -31,22 +31,10 @@ static const unsigned char k8nops[] init_or_livepatch_c= onst =3D { K8_NOP8, K8_NOP9, }; -static const unsigned char * const k8_nops[ASM_NOP_MAX+1] init_or_livepatc= h_constrel =3D { - NULL, - k8nops, - k8nops + 1, - k8nops + 1 + 2, - k8nops + 1 + 2 + 3, - k8nops + 1 + 2 + 3 + 4, - k8nops + 1 + 2 + 3 + 4 + 5, - k8nops + 1 + 2 + 3 + 4 + 5 + 6, - k8nops + 1 + 2 + 3 + 4 + 5 + 6 + 7, - k8nops + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8, -}; #endif =20 #ifdef P6_NOP1 -static const unsigned char p6nops[] init_or_livepatch_const =3D { +static const unsigned char p6_nops[] init_or_livepatch_const =3D { P6_NOP1, P6_NOP2, P6_NOP3, @@ -57,21 +45,9 @@ static const unsigned char p6nops[] init_or_livepatch_co= nst =3D { P6_NOP8, P6_NOP9, }; -static const unsigned char * const p6_nops[ASM_NOP_MAX+1] init_or_livepatc= h_constrel =3D { - NULL, - p6nops, - p6nops + 1, - p6nops + 1 + 2, - p6nops + 1 + 2 + 3, - p6nops + 1 + 2 + 3 + 4, - p6nops + 1 + 2 + 3 + 4 + 5, - p6nops + 1 + 2 + 3 + 4 + 5 + 6, - p6nops + 1 + 2 + 3 + 4 + 5 + 6 + 7, - p6nops + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8, -}; #endif =20 -static const unsigned char * const *ideal_nops init_or_livepatch_data =3D = p6_nops; +static const unsigned char *ideal_nops init_or_livepatch_data =3D p6_nops; =20 #ifdef HAVE_AS_NOPS_DIRECTIVE =20 @@ -86,9 +62,17 @@ static bool init_or_livepatch_read_mostly toolchain_nops= _are_ideal; # define toolchain_nops_are_ideal false #endif =20 +/* + * Both k8_nops[] and p6_nops[] are flattened triangular data structures, + * making the offsets easy to calculate. + * + * To get the start of NOP $N, we want to calculate T($N - 1) + */ static const unsigned char *get_ideal_nops(unsigned int noplen) { - return ideal_nops[noplen]; + unsigned int offset =3D ((noplen - 1) * noplen) / 2; + + return &ideal_nops[offset]; } =20 static void __init arch_init_ideal_nops(void) --=20 2.39.5 From nobody Fri Oct 31 09:15:27 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=1747926040; cv=none; d=zohomail.com; s=zohoarc; b=WALX/7UG2TUV6EAVIccvbTaF1u+/zJlzM1KyvpRW8y1fw4uf3sWFj1RZAjcDTHfHSz4UQ0sjfsIXQVEghu9WrAXBJZwcgufe7b0EpSYQutXPYh0gR6aQ5JiIFUSTYaMoRNsxGhctgeirhUI22xGJX/3Nu2Jw1zE29XkgSC9iC/Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1747926040; 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:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Lr3f4QVXBQIDCvAtm/J7FXqG+fuDtkqVk40mCLaFjM8=; b=PCB7ryUJd3zOZx5slSyTG272z1lRHdojjSXai+nevoB1fNbPYInRUZUpRtG2PW2ZAX8DBNMtCUKiWHo9POPVvHKbh3Oesw1D3O7UhD7EYi2Snldd9x4tF7/CCdpVzw7DC/Nexgk3T/DXPZFKYn/iOypq7+SIAZDinIvCfKmXD38= 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 174792604092454.6343147089932; Thu, 22 May 2025 08:00:40 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.994169.1377230 (Exim 4.92) (envelope-from ) id 1uI7PG-0004Kg-0O; Thu, 22 May 2025 15:00:26 +0000 Received: by outflank-mailman (output) from mailman id 994169.1377230; Thu, 22 May 2025 15:00:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uI7PF-0004KC-RT; Thu, 22 May 2025 15:00:25 +0000 Received: by outflank-mailman (input) for mailman id 994169; Thu, 22 May 2025 15:00:24 +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 1uI7PE-0003kR-B6 for xen-devel@lists.xenproject.org; Thu, 22 May 2025 15:00:24 +0000 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [2a00:1450:4864:20::534]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 7cf75ed1-371d-11f0-a2fb-13f23c93f187; Thu, 22 May 2025 17:00:24 +0200 (CEST) Received: by mail-ed1-x534.google.com with SMTP id 4fb4d7f45d1cf-601f278369bso9150926a12.1 for ; Thu, 22 May 2025 08:00:24 -0700 (PDT) Received: from localhost.localdomain (host-92-26-98-202.as13285.net. [92.26.98.202]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-6005ac32a7fsm10550119a12.56.2025.05.22.08.00.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 May 2025 08:00:22 -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: 7cf75ed1-371d-11f0-a2fb-13f23c93f187 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1747926023; x=1748530823; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Lr3f4QVXBQIDCvAtm/J7FXqG+fuDtkqVk40mCLaFjM8=; b=rXjMiK9JnMJRdG4PnhsWg2h4PlT+CAz96h165SNajgQoZNEin7atLn6c/iWpVjpTsi Wv962se85Z+3GjDberiNeUkE9LoYBJ0BaeE+yyUCjs6hBH5luQ9SMJEwqsC/BRkTzvsg k5Z6enxHV6YgqDl9Dtuaqyx6GAMtJtQETr04k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747926023; x=1748530823; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Lr3f4QVXBQIDCvAtm/J7FXqG+fuDtkqVk40mCLaFjM8=; b=IAflsfANmTnaLivvIBKFLpXUjWqcqIAnmWoeYOB8daT0wpnxO+1DlA/s7nHyY6z3+f 9Hj5ctAlqJla8CPY04sC4B9Bj4iKfy/ejr+csO+mukAn5+MFN89pacWs/qoUrcei9UoC hgRIsl2f3vU4A35JNtpD4OGtcqffB9RT01YzjqUj7PoG8dZVZ85s6+/zPsuTiTgFZYRu Q/J0c+Ox+5LySfZDSI9YrnEvGTHmRDj2RmV0RdzYUik9LxPRQY6SoCbDMXe5NkoExNli nXRRV7X6Vtwv3+TSnivLSRP69AY3NAwSpkKzit+Q5KvWV9sf0oS04cFYIc7DKd2BQSVm q1vw== X-Gm-Message-State: AOJu0YwGuMX2wPBcgZrIhwkWrOW5V9hJd5D/UkFUy6tMEnH3/BBbc4cI 0HmLKUxmECNToJaKG2weg+DgcePIj+xMYbvxreIa/gG3jd+m2q9ELEF3GhBMaZhO/4XJ3E6vgiZ ABEgs X-Gm-Gg: ASbGncuclKk9nRqynWHj8RCsTd+nvINalFWzDkYTgd+f9XYVsrLYzhwA5unCTP0bURh V3r/p3lfZ8fK/z/Q5hdx55HD41eF8c671Eu0aDSqpqfbHeYM1rcOQc1x6q3fOkwBDkBwoRkK4fC pHHFXG6RapxSW369miThBx7OWFQ6rU66fPM78A3bfRfX16qo8nMaPjZ+Zit1GCRNYBlDnRXA85P qxWKLez+VlWtxPlX71n/008Q61hpKxh86NxTGksfYzO8fQ/dUkXL2IlCSS4i72j6rVxFDaJZdsm zOA6bxFRz+rcmjXjjORP3bY8Z+7WHKtr9T/7TVl2uKLCmrnIm68JIuu9oBuCsd1F8MubbxOwzXZ V5vpVaqg6eemavYXw1cthqX+l X-Google-Smtp-Source: AGHT+IGwN3+4ZGB1CCik2Dp+hZVMQfvh8ozffLpfJ+B7Xqh8901rhiCpfdZYsF8r17CSvH0+QTy0rw== X-Received: by 2002:a05:6402:50cc:b0:601:9dc3:2795 with SMTP id 4fb4d7f45d1cf-6019dc32e17mr18470941a12.7.1747926023055; Thu, 22 May 2025 08:00:23 -0700 (PDT) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH 3/3] x86/alternatives: Introduce init_or_livepatch_ro_after_init Date: Thu, 22 May 2025 16:00:15 +0100 Message-Id: <20250522150015.555492-4-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250522150015.555492-1-andrew.cooper3@citrix.com> References: <20250522150015.555492-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: 1747926042933116600 ... and use it for ideal_nops and toolchain_nops_are_ideal; both of which a= re invariant after arch_init_ideal_nops() has run. No functional change. Signed-off-by: Andrew Cooper Acked-by: Jan Beulich --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 --- xen/arch/x86/alternative.c | 4 ++-- xen/include/xen/livepatch.h | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/alternative.c b/xen/arch/x86/alternative.c index ff7d83c0ddbd..058a8b22d41f 100644 --- a/xen/arch/x86/alternative.c +++ b/xen/arch/x86/alternative.c @@ -47,7 +47,7 @@ static const unsigned char p6_nops[] init_or_livepatch_co= nst =3D { }; #endif =20 -static const unsigned char *ideal_nops init_or_livepatch_data =3D p6_nops; +static const unsigned char *ideal_nops init_or_livepatch_ro_after_init =3D= p6_nops; =20 #ifdef HAVE_AS_NOPS_DIRECTIVE =20 @@ -56,7 +56,7 @@ asm ( ".pushsection .init.rodata, \"a\", @progbits\n\t" "toolchain_nops: .nops " __stringify(ASM_NOP_MAX) "\n\t" ".popsection\n\t"); extern char toolchain_nops[ASM_NOP_MAX]; -static bool init_or_livepatch_read_mostly toolchain_nops_are_ideal; +static bool init_or_livepatch_ro_after_init toolchain_nops_are_ideal; =20 #else # define toolchain_nops_are_ideal false diff --git a/xen/include/xen/livepatch.h b/xen/include/xen/livepatch.h index d074a5bebecc..62f8db2b55b4 100644 --- a/xen/include/xen/livepatch.h +++ b/xen/include/xen/livepatch.h @@ -29,6 +29,7 @@ struct xen_sysctl_livepatch_op; #define init_or_livepatch_constrel #define init_or_livepatch_data #define init_or_livepatch_read_mostly __read_mostly +#define init_or_livepatch_ro_after_init __ro_after_init #define init_or_livepatch =20 /* Convenience define for printk. */ @@ -153,6 +154,7 @@ void revert_payload_tail(struct payload *data); #define init_or_livepatch_constrel __initconstrel #define init_or_livepatch_data __initdata #define init_or_livepatch_read_mostly __initdata +#define init_or_livepatch_ro_after_init __initdata #define init_or_livepatch __init =20 static inline int livepatch_op(struct xen_sysctl_livepatch_op *op) --=20 2.39.5