From patchwork Wed Feb 7 14:55:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 13548630 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4F8C6C4828F for ; Wed, 7 Feb 2024 14:56:19 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.677723.1054524 (Exim 4.92) (envelope-from ) id 1rXjLP-0006wJ-My; Wed, 07 Feb 2024 14:56:11 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 677723.1054524; Wed, 07 Feb 2024 14:56:11 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rXjLP-0006w6-Gn; Wed, 07 Feb 2024 14:56:11 +0000 Received: by outflank-mailman (input) for mailman id 677723; Wed, 07 Feb 2024 14:56:10 +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 1rXjLO-0006gr-ES for xen-devel@lists.xenproject.org; Wed, 07 Feb 2024 14:56:10 +0000 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [2a00:1450:4864:20::632]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 07532507-c5c9-11ee-8a49-1f161083a0e0; Wed, 07 Feb 2024 15:56:09 +0100 (CET) Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-a30f7c9574eso100317366b.0 for ; Wed, 07 Feb 2024 06:56:09 -0800 (PST) Received: from localhost ([213.195.118.74]) by smtp.gmail.com with ESMTPSA id y13-20020a170906070d00b00a386a32a9d9sm834614ejb.194.2024.02.07.06.56.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 06:56:08 -0800 (PST) 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: 07532507-c5c9-11ee-8a49-1f161083a0e0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1707317768; x=1707922568; 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=VvhvJ0mk4ckYFEcAiyKPBpKqoDXebryxKX/EJIJcbn4=; b=g6B46dlfp7q0nunTllR8NB5f4f3IRonaTzlX53W1RlNhcEIWLz90iDqNiMpBJMqNgQ S1NC4U6I9d0nmcVIHR5U3fE13l1ff/p+sv+q8FkgtAc6dOXaovzTjTQM7MRXTSk0rfvE iIFLzs5U4vHcVK1NsdIHF7Nhr8GbOPh6WFXSc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707317768; x=1707922568; 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=VvhvJ0mk4ckYFEcAiyKPBpKqoDXebryxKX/EJIJcbn4=; b=qNHXlDGViVIHBNMFpfNtvHiRsr4T/ia41xI7GyXmIGasd1S6kUgp+y+ZFICbXi4IbL 2BTsGbKJMu9UD7fm9h2tGmN33MPPgD+6rVR/5+E28AyqIX035h/gdvd1RNxttGkefNVb 44I3zjU+8yDCgDowFGuzefL4BpP/ZUffhOO48DBFwz4ApOkKjBueJJo2KLwup4xU46u/ g9N8zAuG1tx3kvxLhFlY2eQWFgTtDUAJIHIZxMJ/v3FHrXL9KhtfQaCHF+DbRCu33iO8 Q4xE5gUBkWBCX5tA91OwpQHjsz9ZiQNNGkhRaEnHb6l2IpyNuux5B7rDuVs2tq+lLEt4 dB2w== X-Gm-Message-State: AOJu0YwkxDK+Z6liLxr2KKaQqxZEM0iZ6DommNGqhvz+dikyCI3FErVH IV8s5TmgYtmLtKc0XEw+2nWA25lo5ATni5HQ8s+BaoHEIxxtNi3hxPVuZ2ZMYc9vtydv4FBC9kP + X-Google-Smtp-Source: AGHT+IEf//jnO6+wwgVwFq/WbrfkwQt0EVuxuJU/7OLvjKJPip3WS7InnQyd8gBn9YlqnI5vxEk4Nw== X-Received: by 2002:a17:906:cc1:b0:a38:5c3c:9d1e with SMTP id l1-20020a1709060cc100b00a385c3c9d1emr1744877ejh.18.1707317768593; Wed, 07 Feb 2024 06:56:08 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCXtnfQ4fJ1r4TYx1lFl0J8JNHk10d6cWkSfoq5n/yZRh5p5FxCnDmCFAljj8VyeWsf1vl9b16Ni+7hOCHfm/OaCfd/2bDdIpCQ+3V7O+jfokzkfiST9xH5EBMQJh3/mtrtR4PC0tXSJ/9VQzFrIg8e+BDzDEoVUbXXo6CFax+lo7fwEgCXwmOSpOMkHD2tIaTU8uSwQvg/V0vI7REPXfqnIX6WCoZmKZ0CUzfDx3nN56R6Br1EJU3WByChBz7um5utykJgmp0PqzD4r5WI/Nis9yyh/8ymQkgLQiThHwDBqKthf+cpgh6zNTwGv1shcC6SJx3dKft3Y63g49diiN2ZR05QOFfZCwn3pqQEdtIo78ydvw50BUmLlJDw0rWsn+tgTZt4gZEf08HetDF9UhjMZS7rOT38bQIq9mzHHRE2BN4ARc6kXqKmUZ+NFQqMIhvq5aZ1keLiDIbbpfmuYqgG+nrI= From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Shawn Anastasio , Alistair Francis , Bob Eshleman , Connor Davis Subject: [PATCH v6 1/3] xen: introduce Kconfig function alignment option Date: Wed, 7 Feb 2024 15:55:45 +0100 Message-ID: <20240207145547.89689-2-roger.pau@citrix.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240207145547.89689-1-roger.pau@citrix.com> References: <20240207145547.89689-1-roger.pau@citrix.com> MIME-Version: 1.0 And use it to replace CODE_ALIGN in assembly. This allows to generalize the way the code alignment gets set across all architectures. No functional change intended. Signed-off-by: Roger Pau Monné Reviewed-by: Jan Beulich Reviewed-by: Michal Orzel Acked-by: Shawn Anastasio --- Changes since v5: - New in this version. --- xen/Kconfig | 17 +++++++++++++++++ xen/arch/arm/Kconfig | 1 + xen/arch/arm/include/asm/config.h | 3 +-- xen/arch/ppc/Kconfig | 1 + xen/arch/ppc/include/asm/config.h | 3 --- xen/arch/riscv/Kconfig | 1 + xen/arch/riscv/include/asm/config.h | 1 - xen/arch/x86/Kconfig | 1 + xen/arch/x86/include/asm/config.h | 3 +-- xen/include/xen/linkage.h | 5 +++-- 10 files changed, 26 insertions(+), 10 deletions(-) diff --git a/xen/Kconfig b/xen/Kconfig index 134e6e68ad84..1e1b041fd52f 100644 --- a/xen/Kconfig +++ b/xen/Kconfig @@ -37,6 +37,23 @@ config CC_HAS_VISIBILITY_ATTRIBUTE config CC_SPLIT_SECTIONS bool +# Set code alignment. +# +# Allow setting on a boolean basis, and then convert such selection to an +# integer for the build system and code to consume more easily. +config FUNCTION_ALIGNMENT_4B + bool +config FUNCTION_ALIGNMENT_8B + bool +config FUNCTION_ALIGNMENT_16B + bool +config FUNCTION_ALIGNMENT + int + default 16 if FUNCTION_ALIGNMENT_16B + default 8 if FUNCTION_ALIGNMENT_8B + default 4 if FUNCTION_ALIGNMENT_4B + default 0 + source "arch/$(SRCARCH)/Kconfig" config DEFCONFIG_LIST diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig index 50e9bfae1ac8..80fb5b14f04e 100644 --- a/xen/arch/arm/Kconfig +++ b/xen/arch/arm/Kconfig @@ -16,6 +16,7 @@ config ARM select HAS_PASSTHROUGH select HAS_UBSAN select IOMMU_FORCE_PT_SHARE + select FUNCTION_ALIGNMENT_4B config ARCH_DEFCONFIG string diff --git a/xen/arch/arm/include/asm/config.h b/xen/arch/arm/include/asm/config.h index 3b6d829197a4..a2e22b659d53 100644 --- a/xen/arch/arm/include/asm/config.h +++ b/xen/arch/arm/include/asm/config.h @@ -53,8 +53,7 @@ /* Linkage for ARM */ #ifdef __ASSEMBLY__ -#define CODE_ALIGN 4 -#define ALIGN .balign CODE_ALIGN +#define ALIGN .balign CONFIG_FUNCTION_ALIGNMENT #define ENTRY(name) \ .globl name; \ ALIGN; \ diff --git a/xen/arch/ppc/Kconfig b/xen/arch/ppc/Kconfig index ab116ffb2a70..6b3b2bb95f56 100644 --- a/xen/arch/ppc/Kconfig +++ b/xen/arch/ppc/Kconfig @@ -1,6 +1,7 @@ config PPC def_bool y select HAS_DEVICE_TREE + select FUNCTION_ALIGNMENT_4B config PPC64 def_bool y diff --git a/xen/arch/ppc/include/asm/config.h b/xen/arch/ppc/include/asm/config.h index e5d201e16c50..e0a0abfeb408 100644 --- a/xen/arch/ppc/include/asm/config.h +++ b/xen/arch/ppc/include/asm/config.h @@ -31,9 +31,6 @@ #define INVALID_VCPU_ID MAX_VIRT_CPUS /* Linkage for PPC */ -#ifdef __ASSEMBLY__ -#define CODE_ALIGN 4 -#endif #define XEN_VIRT_START _AC(0xc000000000000000, UL) diff --git a/xen/arch/riscv/Kconfig b/xen/arch/riscv/Kconfig index f382b36f6c82..b4b354a7786e 100644 --- a/xen/arch/riscv/Kconfig +++ b/xen/arch/riscv/Kconfig @@ -1,5 +1,6 @@ config RISCV def_bool y + select FUNCTION_ALIGNMENT_16B config RISCV_64 def_bool y diff --git a/xen/arch/riscv/include/asm/config.h b/xen/arch/riscv/include/asm/config.h index a80cdd4f857c..99ea5635208b 100644 --- a/xen/arch/riscv/include/asm/config.h +++ b/xen/arch/riscv/include/asm/config.h @@ -69,7 +69,6 @@ /* Linkage for RISCV */ #ifdef __ASSEMBLY__ -#define CODE_ALIGN 16 #define CODE_FILL /* empty */ #endif diff --git a/xen/arch/x86/Kconfig b/xen/arch/x86/Kconfig index 1acdffc51c22..3dd8f18b46ef 100644 --- a/xen/arch/x86/Kconfig +++ b/xen/arch/x86/Kconfig @@ -29,6 +29,7 @@ config X86 select HAS_UBSAN select HAS_VPCI if HVM select NEEDS_LIBELF + select FUNCTION_ALIGNMENT_16B config ARCH_DEFCONFIG string diff --git a/xen/arch/x86/include/asm/config.h b/xen/arch/x86/include/asm/config.h index 660246d1dae5..ab7288cb3682 100644 --- a/xen/arch/x86/include/asm/config.h +++ b/xen/arch/x86/include/asm/config.h @@ -43,9 +43,8 @@ /* Linkage for x86 */ #ifdef __ASSEMBLY__ -#define CODE_ALIGN 16 #define CODE_FILL 0x90 -#define ALIGN .align CODE_ALIGN, CODE_FILL +#define ALIGN .align CONFIG_FUNCTION_ALIGNMENT, CODE_FILL #define ENTRY(name) \ ALIGN; \ GLOBAL(name) diff --git a/xen/include/xen/linkage.h b/xen/include/xen/linkage.h index 0997e16810b2..770ae49963b8 100644 --- a/xen/include/xen/linkage.h +++ b/xen/include/xen/linkage.h @@ -41,9 +41,10 @@ */ #define count_args_exp(args...) count_args(args) #if count_args_exp(CODE_FILL) -# define DO_CODE_ALIGN(align...) LASTARG(CODE_ALIGN, ## align), CODE_FILL +# define DO_CODE_ALIGN(align...) LASTARG(CONFIG_FUNCTION_ALIGNMENT, ## align), \ + CODE_FILL #else -# define DO_CODE_ALIGN(align...) LASTARG(CODE_ALIGN, ## align) +# define DO_CODE_ALIGN(align...) LASTARG(CONFIG_FUNCTION_ALIGNMENT, ## align) #endif #define FUNC(name, align...) \ From patchwork Wed Feb 7 14:55:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 13548631 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5C1ACC4828D for ; Wed, 7 Feb 2024 14:56:20 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.677724.1054533 (Exim 4.92) (envelope-from ) id 1rXjLQ-0007C4-RN; Wed, 07 Feb 2024 14:56:12 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 677724.1054533; Wed, 07 Feb 2024 14:56:12 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rXjLQ-0007Bx-OX; Wed, 07 Feb 2024 14:56:12 +0000 Received: by outflank-mailman (input) for mailman id 677724; Wed, 07 Feb 2024 14:56:11 +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 1rXjLP-0006gr-EA for xen-devel@lists.xenproject.org; Wed, 07 Feb 2024 14:56:11 +0000 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [2a00:1450:4864:20::62a]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 08055efc-c5c9-11ee-8a49-1f161083a0e0; Wed, 07 Feb 2024 15:56:11 +0100 (CET) Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-a271a28aeb4so94407466b.2 for ; Wed, 07 Feb 2024 06:56:11 -0800 (PST) Received: from localhost ([213.195.118.74]) by smtp.gmail.com with ESMTPSA id l16-20020a170906415000b00a3551f727d1sm830912ejk.68.2024.02.07.06.56.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 06:56:09 -0800 (PST) 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: 08055efc-c5c9-11ee-8a49-1f161083a0e0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1707317770; x=1707922570; 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=akzbcc4EuKcp9VAzRO87Fc+0Red8uqWWSH8LHiM9Mf0=; b=LrE13oNnVGeF2t8ZuvKIRL/aM/6H+SDnBqPHYRVcwsUjCX+aGkGxbf7DRDLWgM3P1A FnM9omA+Kcd+dNFrnmokH0r93wTq8HDZY4JM22Zp1RNIyrxLdgeuFk2MkQIctbTXpPrH ra/7xCxG9EV/yAtitpZ0LA9IF7cjLFuVaYg2I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707317770; x=1707922570; 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=akzbcc4EuKcp9VAzRO87Fc+0Red8uqWWSH8LHiM9Mf0=; b=iYgNg7Jl6ttsYGAnol9eiTrdhP3fNKJj4bNfu8/FbBfLwv1lKQLZVYd/H8UEJglkCC yV51pVbU/Mxi24U1rQCR0Z02IH0cztjs4Sz+wesV5tp6I5kmWhhRAhau3KedXMZgymM9 Y1ir6EXq8SqOCTaJWsJmqCIKp8QWPtOMkQgVZelp4EWE0tQP2uNSyQ4sxABh0IT04rbu CSkdWR5WFrx71coqX2KrPJuAJpkcYNgqw7lA6qg7OZwjkIx/PU0H5WnLF4318Mp6nWGT 13eWCnyUda8rECXzmCtTi8di23XTn8exAfXXhEI9WbLx+bPl0W3tM24L8Scs6SH9hB7W q6nw== X-Gm-Message-State: AOJu0YwFMLrFCQ47Ln/xumNFCxsOERy3e85DaoTaK5gvscw4w+4azjQ9 BoW94xL1CJR5aF20QQU3SHpin721BOm2/LVJkaM1umGivth6+R/nJvDGBHSv1ftFUHREPhKBVgA B X-Google-Smtp-Source: AGHT+IF8t8/nmL4BjDrYilxRzo93JsRzkWnYIJ8/PI+xuH0RzNl3UwwXRYn8sWqNsbYCRRDf0zCEIw== X-Received: by 2002:a17:906:69d6:b0:a38:970a:75df with SMTP id g22-20020a17090669d600b00a38970a75dfmr649647ejs.15.1707317769901; Wed, 07 Feb 2024 06:56:09 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCUgtHNKg/CEiKIRnL5cmUT1iguKf8bV8fxszMgMhEi6x7dMwAsGFPeRh3psns0y2/JQiVz17gW6BoXCO22hyvH7+RGiZJeZkajNtS7qt47yb/wQnFgWzumfwPbBGnD5wQ9KCQXmDrgAogtwnUCSPC4ZHLSWlazXgJ3LP9CIUr+hEBrCx2cLHdpVWQp5/MFilRrbQzaxQEOMq0wd9q6VeOMCq0sMB6BDRBZpTw== From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu Subject: [PATCH v6 2/3] xen: use explicit function alignment if supported by compiler Date: Wed, 7 Feb 2024 15:55:46 +0100 Message-ID: <20240207145547.89689-3-roger.pau@citrix.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240207145547.89689-1-roger.pau@citrix.com> References: <20240207145547.89689-1-roger.pau@citrix.com> MIME-Version: 1.0 Introduce a new Kconfig check for whether the compiler supports -falign-functions and if supported use it to align functions to the per-arch selected value, just like it's done for assembly ENTRY() and FUNC() symbols. Note that it's possible for the compiler to end up using a higher function alignment regardless of the passed value. Different compilers handle the option differently, as clang will ignore -falign-functions value if it's smaller than the one that would be set by the optimization level, while gcc seems to always honor the function alignment passed in -falign-functions. Signed-off-by: Roger Pau Monné --- Changes since v5: - New in this version. --- xen/Kconfig | 5 +++++ xen/Makefile | 1 + 2 files changed, 6 insertions(+) diff --git a/xen/Kconfig b/xen/Kconfig index 1e1b041fd52f..040cba1b4b73 100644 --- a/xen/Kconfig +++ b/xen/Kconfig @@ -41,6 +41,11 @@ config CC_SPLIT_SECTIONS # # Allow setting on a boolean basis, and then convert such selection to an # integer for the build system and code to consume more easily. +# +# Requires clang >= 7.0.0 +config CC_HAS_FUNCTION_ALIGNMENT + def_bool $(cc-option,-falign-functions) + config FUNCTION_ALIGNMENT_4B bool config FUNCTION_ALIGNMENT_8B diff --git a/xen/Makefile b/xen/Makefile index 21832d640225..7c8249ab3a33 100644 --- a/xen/Makefile +++ b/xen/Makefile @@ -390,6 +390,7 @@ CFLAGS += -fomit-frame-pointer endif CFLAGS-$(CONFIG_CC_SPLIT_SECTIONS) += -ffunction-sections -fdata-sections +CFLAGS-$(CONFIG_CC_HAS_FUNCTION_ALIGNMENT) += -falign-functions=$(CONFIG_FUNCTION_ALIGNMENT) CFLAGS += -nostdinc -fno-builtin -fno-common CFLAGS += -Werror -Wredundant-decls -Wwrite-strings -Wno-pointer-arith From patchwork Wed Feb 7 14:55:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 13548632 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D571CC4829B for ; Wed, 7 Feb 2024 14:56:21 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.677725.1054542 (Exim 4.92) (envelope-from ) id 1rXjLS-0007S2-32; Wed, 07 Feb 2024 14:56:14 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 677725.1054542; Wed, 07 Feb 2024 14:56:14 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rXjLR-0007RU-Vd; Wed, 07 Feb 2024 14:56:13 +0000 Received: by outflank-mailman (input) for mailman id 677725; Wed, 07 Feb 2024 14:56:13 +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 1rXjLQ-0006gr-VN for xen-devel@lists.xenproject.org; Wed, 07 Feb 2024 14:56:12 +0000 Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [2a00:1450:4864:20::12e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 08e3c0cd-c5c9-11ee-8a49-1f161083a0e0; Wed, 07 Feb 2024 15:56:12 +0100 (CET) Received: by mail-lf1-x12e.google.com with SMTP id 2adb3069b0e04-511531f03f6so895010e87.0 for ; Wed, 07 Feb 2024 06:56:12 -0800 (PST) Received: from localhost ([213.195.118.74]) by smtp.gmail.com with ESMTPSA id tb21-20020a1709078b9500b00a380a1ee2b0sm840342ejc.25.2024.02.07.06.56.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 06:56:10 -0800 (PST) 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: 08e3c0cd-c5c9-11ee-8a49-1f161083a0e0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1707317771; x=1707922571; 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=2ed76aC18yY98YVZXZt7AsqWqpjS5eaKS4tBHEoatpQ=; b=ffgy3MgAIwcB4+vvmMZL30pvZFqJ2ua4eoco8+OCeuirQid7bs9n4JkBX+p67QxzIi yKvKM2BDgOAYPLP2j+CQA48J0qRjoZXFeJ0ZSZ9NIG5fPlBbqxkhxadXDGe7cRviqbVd Tc+rLC06Fz1E516rLfOAY3EkTY7VWnhdEr3dc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707317771; x=1707922571; 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=2ed76aC18yY98YVZXZt7AsqWqpjS5eaKS4tBHEoatpQ=; b=gqkeeJqiYkIO8bldNb2bSrb/Z0H8Y1wTwOtYk0/6D/4f8H5YMh8tj8zUCjFTucqpEm gmiOE3pwJfHPN4xo1jV2XG6lZLfBWkuW7f7nqw5bhPqkHnrp70OWvx9odoiN/6+bNFba pT/RaxPELe5IYK8e9XORp0HCsx31vEy64niHmwAlA1MykJuxoUhb2RAOJlfq+tI6s4Nn Ls7zjj7cKyUNipDKY74gNZtIeLrVKxmT12UFC+IDBqJS4QFy9dyu2dk4AVr37SXJIA1p b2q3EraLA0jzcscxUCiAsPprbBvrsFwxNvhGUxW8LItJWNBxU5cof4rFzrmFN8Yod0q+ /AOQ== X-Gm-Message-State: AOJu0YyHovjPoU62jeVyUrQZk8amfhdlIXTlXVGClBg75yq9ZsJDZNCI 1RsYSyBkirGB3aa1zVoiDiAwSXqmtKq79zGjAISKHUd3CE+ZIML9XYbwyEyjAX/IeMvguJ2TlNq j X-Google-Smtp-Source: AGHT+IFjeD8qDT4xiVr2PUwhzlFFk5FQqMJQTzmBOSuqXkY85fRKeoE9V31qv2BMZZ3sUhl7/cnDgQ== X-Received: by 2002:a05:6512:64:b0:511:32cc:1c4c with SMTP id i4-20020a056512006400b0051132cc1c4cmr4090745lfo.40.1707317771143; Wed, 07 Feb 2024 06:56:11 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWZDc68kXxHbMNCiBjGEn/a0QM3LIn8rfYvRUQUi478C0UQqxSFN/K6AnPu1utTjEZmyXBs3qYeNFZSI7mn0fqdTkFnxCYLLJYmgFbSbdFQl0ic0LQoaALVUDGoWngQPjWDi+vKi019BuUPLzADdEX3+5oyjBA3pwz3/jqOTaKUq/tQjAdxY9WM+vLvrDtGvXPtDYc4XLRciPOXtNqEzcYVEcirEx5ueeXM+VMEcxha4hhp7TQfVuHoH2OcHGO9D9zGMdDWTb1EpuwXe4CFR5YxlbZrDTt4zOjr4XYXsY/99oH7YjUgI9Vi40MJyk3eZm2wcHJOTR81mGIbajLbX0iY02r5Pk3vxwB4dvW6CUegfJISvC4QMt3cetooXA1/Qn+5ns6RQH3fpZQnLik5g7llzi4ve2vMqAteT56qVl4JoOyr94FjXjy30YTh56Hoe60wp/wbBUkxNwF8DNs7ohgW4JT3iteWCChBm288x8oPy3ea/+skvN7auSrTHns+FDOtH8OmFXenfIAqT/es0zW/xEESneQ= From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Konrad Rzeszutek Wilk , Ross Lagerwall , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Andrew Cooper , George Dunlap , Jan Beulich , Wei Liu , Shawn Anastasio , Alistair Francis , Bob Eshleman , Connor Davis Subject: [PATCH v6 3/3] xen/livepatch: align functions to ensure minimal distance between entry points Date: Wed, 7 Feb 2024 15:55:47 +0100 Message-ID: <20240207145547.89689-4-roger.pau@citrix.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240207145547.89689-1-roger.pau@citrix.com> References: <20240207145547.89689-1-roger.pau@citrix.com> MIME-Version: 1.0 The minimal function size requirements for an x86 livepatch are either 5 bytes (for jmp) or 9 bytes (for endbr + jmp), and always 4 bytes on Arm. Ensure that distance between functions entry points is always at least of the minimal required size for livepatch instruction replacement to be successful. Add an additional align directive to the linker scripts, in order to ensure that the next section placed after the .text.* (per-function sections) is also aligned to the required boundary, so that the distance of the last function entry point with the next symbol is also of minimal size. Note that livepatch-build-tools will take into account each per-function section alignment in order to decide whether there's enough padding. Signed-off-by: Roger Pau Monné Reviewed-by: Jan Beulich --- Changes since v5: - Split chunks into pre-patches to make review easier. Changes since v4: - Split from the rest of the livepatch testing series. - Reword and expand a bit the commit message. - Add a comment about falign-functions clang version requirement. Changes since v3: - Test for compiler option with -falign-functions. - Make FUNCTION_ALIGNMENT depend on CC_HAS_FUNCTION_ALIGNMENT. - Set 16byte function alignment for x86 release builds. Changes since v2: - Add Arm side. - Align end of section in the linker script to ensure enough padding for the last function. - Expand commit message and subject. - Rework Kconfig options. - Check that the compiler supports the option. Changes since v1: - New in this version. --- xen/arch/arm/livepatch.c | 2 ++ xen/arch/arm/xen.lds.S | 4 ++++ xen/arch/ppc/xen.lds.S | 4 ++++ xen/arch/riscv/xen.lds.S | 4 ++++ xen/arch/x86/livepatch.c | 4 ++++ xen/arch/x86/xen.lds.S | 4 ++++ xen/common/Kconfig | 5 ++++- 7 files changed, 26 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/livepatch.c b/xen/arch/arm/livepatch.c index bbca1e5a5ed3..aa8ae8c38d28 100644 --- a/xen/arch/arm/livepatch.c +++ b/xen/arch/arm/livepatch.c @@ -68,6 +68,8 @@ void arch_livepatch_revive(void) int arch_livepatch_verify_func(const struct livepatch_func *func) { + BUILD_BUG_ON(ARCH_PATCH_INSN_SIZE > CONFIG_FUNCTION_ALIGNMENT); + /* If NOPing only do up to maximum amount we can put in the ->opaque. */ if ( !func->new_addr && (func->new_size > LIVEPATCH_OPAQUE_SIZE || func->new_size % ARCH_PATCH_INSN_SIZE) ) diff --git a/xen/arch/arm/xen.lds.S b/xen/arch/arm/xen.lds.S index 470c8f22084f..0126a3afae53 100644 --- a/xen/arch/arm/xen.lds.S +++ b/xen/arch/arm/xen.lds.S @@ -46,6 +46,10 @@ SECTIONS #ifdef CONFIG_CC_SPLIT_SECTIONS *(.text.*) #endif +#ifdef CONFIG_LIVEPATCH + /* Ensure enough distance with the next placed section. */ + . = ALIGN(CONFIG_FUNCTION_ALIGNMENT); +#endif *(.fixup) *(.gnu.warning) diff --git a/xen/arch/ppc/xen.lds.S b/xen/arch/ppc/xen.lds.S index 030e1ee37b55..f300c03a666f 100644 --- a/xen/arch/ppc/xen.lds.S +++ b/xen/arch/ppc/xen.lds.S @@ -32,6 +32,10 @@ SECTIONS #ifdef CONFIG_CC_SPLIT_SECTIONS *(.text.*) #endif +#ifdef CONFIG_LIVEPATCH + /* Ensure enough distance with the next placed section. */ + . = ALIGN(CONFIG_FUNCTION_ALIGNMENT); +#endif *(.fixup) *(.gnu.warning) diff --git a/xen/arch/riscv/xen.lds.S b/xen/arch/riscv/xen.lds.S index 8510a87c4d06..1fb9af11c1cc 100644 --- a/xen/arch/riscv/xen.lds.S +++ b/xen/arch/riscv/xen.lds.S @@ -27,6 +27,10 @@ SECTIONS #ifdef CONFIG_CC_SPLIT_SECTIONS *(.text.*) #endif +#ifdef CONFIG_LIVEPATCH + /* Ensure enough distance with the next placed section. */ + . = ALIGN(CONFIG_FUNCTION_ALIGNMENT); +#endif . = ALIGN(IDENT_AREA_SIZE); _ident_start = .; diff --git a/xen/arch/x86/livepatch.c b/xen/arch/x86/livepatch.c index ee539f001b73..b00ad7120da9 100644 --- a/xen/arch/x86/livepatch.c +++ b/xen/arch/x86/livepatch.c @@ -109,6 +109,10 @@ int arch_livepatch_verify_func(const struct livepatch_func *func) */ uint8_t needed = ARCH_PATCH_INSN_SIZE; + BUILD_BUG_ON(ARCH_PATCH_INSN_SIZE + + (IS_ENABLED(CONIFG_XEN_IBT) ? ENDBR64_LEN : 0) > + CONFIG_FUNCTION_ALIGNMENT); + if ( is_endbr64(func->old_addr) || is_endbr64_poison(func->old_addr) ) needed += ENDBR64_LEN; diff --git a/xen/arch/x86/xen.lds.S b/xen/arch/x86/xen.lds.S index 8930e14fc40e..6649bc16dc48 100644 --- a/xen/arch/x86/xen.lds.S +++ b/xen/arch/x86/xen.lds.S @@ -101,6 +101,10 @@ SECTIONS *(.text.*) #endif *(.text.__x86_indirect_thunk_*) +#ifdef CONFIG_LIVEPATCH + /* Ensure enough distance with the next placed section. */ + . = ALIGN(CONFIG_FUNCTION_ALIGNMENT); +#endif *(.fixup) *(.gnu.warning) diff --git a/xen/common/Kconfig b/xen/common/Kconfig index 310ad4229cdf..63fba175c99f 100644 --- a/xen/common/Kconfig +++ b/xen/common/Kconfig @@ -395,8 +395,11 @@ config CRYPTO config LIVEPATCH bool "Live patching support" default X86 - depends on "$(XEN_HAS_BUILD_ID)" = "y" + depends on "$(XEN_HAS_BUILD_ID)" = "y" && CC_HAS_FUNCTION_ALIGNMENT select CC_SPLIT_SECTIONS + select FUNCTION_ALIGNMENT_16B if XEN_IBT + select FUNCTION_ALIGNMENT_8B if X86 + select FUNCTION_ALIGNMENT_4B if ARM ---help--- Allows a running Xen hypervisor to be dynamically patched using binary patches without rebooting. This is primarily used to binarily