From nobody Wed May 22 00:47:38 2024 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=1707317786; cv=none; d=zohomail.com; s=zohoarc; b=R1nxNZy4ZCO3yZzFAKGdKJEHRGuv7TbQe4VgxUmuxg4bEbxxx/BRJhqOx1orffMLgnHWxt+CGHHT1HIST4FIdPwd2ma+swwnszFW5MO6VqEoZPD0ie/cykhfkMcBloWflMlbyh2picAYar+ZusphgMaB7tO2FuM2/3Qg5hZ/hjg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1707317786; 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=VvhvJ0mk4ckYFEcAiyKPBpKqoDXebryxKX/EJIJcbn4=; b=CR6vnkpnDvou3u+xkXqjfJsOTqpl+JL1UNs187JGXtLWvUXS516/SnKPyEdSs+Gs3ERbQzHFy3TiYTxB5wC0C2gpYta3j6okER5z5hgVO38HRExxGmyrfCXeiORhCPmYrLGJuTGGQP3eFBCLl4ptPI3LJRe+JQh+Mn8VP661EtI= 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 1707317786717161.2838818891006; Wed, 7 Feb 2024 06:56:26 -0800 (PST) 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 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-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: 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1707317788493100002 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=C3=A9 Acked-by: Shawn Anastasio Reviewed-by: Jan Beulich Reviewed-by: Michal Orzel --- 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 =20 +# 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" =20 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 =20 config ARCH_DEFCONFIG string diff --git a/xen/arch/arm/include/asm/config.h b/xen/arch/arm/include/asm/c= onfig.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 @@ =20 /* 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 =20 config PPC64 def_bool y diff --git a/xen/arch/ppc/include/asm/config.h b/xen/arch/ppc/include/asm/c= onfig.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 =20 /* Linkage for PPC */ -#ifdef __ASSEMBLY__ -#define CODE_ALIGN 4 -#endif =20 #define XEN_VIRT_START _AC(0xc000000000000000, UL) =20 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 =20 config RISCV_64 def_bool y diff --git a/xen/arch/riscv/include/asm/config.h b/xen/arch/riscv/include/a= sm/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 @@ =20 /* Linkage for RISCV */ #ifdef __ASSEMBLY__ -#define CODE_ALIGN 16 #define CODE_FILL /* empty */ #endif =20 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 =20 config ARCH_DEFCONFIG string diff --git a/xen/arch/x86/include/asm/config.h b/xen/arch/x86/include/asm/c= onfig.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 @@ =20 /* 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, ## ali= gn), \ + CODE_FILL #else -# define DO_CODE_ALIGN(align...) LASTARG(CODE_ALIGN, ## align) +# define DO_CODE_ALIGN(align...) LASTARG(CONFIG_FUNCTION_ALIGNMENT, ## ali= gn) #endif =20 #define FUNC(name, align...) \ --=20 2.43.0 From nobody Wed May 22 00:47:38 2024 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=1707317786; cv=none; d=zohomail.com; s=zohoarc; b=Alb8C2krIOTmvVY7thdiEii1xrW7Cw0v4BUPK+P5c6tjQ5/h6H1wMAAnDXEXx0kiQ+B1ANTOv9xg34dlD7u+/nguUqkn1wQfHonNNtOzJwMj8heCUK7W5l8lnqKbKYGOyFj0JO5WpO9feX5cs3Cb3Q0/a8ghOVzhfRSSFYCueGU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1707317786; 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=akzbcc4EuKcp9VAzRO87Fc+0Red8uqWWSH8LHiM9Mf0=; b=hRtJ9u1kK7y/SZxbD+vQvTKkYwJjplWjJ6/FAG7UMlQXAkyqCIaQoMxvmIZieyxSGKr4jtrRB0LIEKcCYjraCXRKesx9qb2xPAfA/xW+SKPn9zb8kJdPgJxGC6ls04sh5kD/9JKAufCmoK0ylgGv1XOIA6RUx/k1rPFORhVHCEw= 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 1707317786193618.3385556816959; Wed, 7 Feb 2024 06:56:26 -0800 (PST) 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 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-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: 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1707317788477100001 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=C3=A9 --- 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 >=3D 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 +=3D -fomit-frame-pointer endif =20 CFLAGS-$(CONFIG_CC_SPLIT_SECTIONS) +=3D -ffunction-sections -fdata-sections +CFLAGS-$(CONFIG_CC_HAS_FUNCTION_ALIGNMENT) +=3D -falign-functions=3D$(CONF= IG_FUNCTION_ALIGNMENT) =20 CFLAGS +=3D -nostdinc -fno-builtin -fno-common CFLAGS +=3D -Werror -Wredundant-decls -Wwrite-strings -Wno-pointer-arith --=20 2.43.0 From nobody Wed May 22 00:47:38 2024 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=1707317791; cv=none; d=zohomail.com; s=zohoarc; b=dLacPHZr0dIuobv9r37518dGi64GQ+YALZdkfXfoMqF0j5y4RQ3af1uuis/Ilfk5WR3M7A+xdqd5pWEAEMfIvC39Ueq15Z0xIXETD73LP+cfFf7mV/k9Znu32+0tbNpasZvvH2fscL07Ah7TshndyjQf8FDQTEk0JDHvHV/vsHU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1707317791; 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=2ed76aC18yY98YVZXZt7AsqWqpjS5eaKS4tBHEoatpQ=; b=If4WwsN11uCgYge31fey7fEaRbRIBM17Z5ZmdeC50nLVfKALZPR05q1D0OLMvYnc2oO9CwiA5ZmvMBjcOFx819xkGZO478QI4pY1yIM0/6hLuDYYaVgUVcmpHYNezNnPa3K0J3ga5ORq7XfDPSt9c5CiVwnZJMguqy21MjAetBQ= 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 1707317791601430.13765256446095; Wed, 7 Feb 2024 06:56:31 -0800 (PST) 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 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-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: 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1707317792431100001 The minimal function size requirements for an x86 livepatch are either 5 by= tes (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=C3=A9 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 t= he 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) =20 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. */ + . =3D ALIGN(CONFIG_FUNCTION_ALIGNMENT); +#endif =20 *(.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. */ + . =3D ALIGN(CONFIG_FUNCTION_ALIGNMENT); +#endif =20 *(.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. */ + . =3D ALIGN(CONFIG_FUNCTION_ALIGNMENT); +#endif =20 . =3D ALIGN(IDENT_AREA_SIZE); _ident_start =3D .; 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 =3D ARCH_PATCH_INSN_SIZE; =20 + 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_add= r) ) needed +=3D ENDBR64_LEN; =20 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. */ + . =3D ALIGN(CONFIG_FUNCTION_ALIGNMENT); +#endif =20 *(.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)" =3D "y" + depends on "$(XEN_HAS_BUILD_ID)" =3D "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 --=20 2.43.0