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 C3FD4C4725D for ; Mon, 22 Jan 2024 11:22:02 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.669780.1042190 (Exim 4.92) (envelope-from ) id 1rRsNG-0003jv-D8; Mon, 22 Jan 2024 11:21:54 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 669780.1042190; Mon, 22 Jan 2024 11:21:54 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rRsNG-0003jo-AL; Mon, 22 Jan 2024 11:21:54 +0000 Received: by outflank-mailman (input) for mailman id 669780; Mon, 22 Jan 2024 11:21:53 +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 1rRsNF-0003jg-IK for xen-devel@lists.xenproject.org; Mon, 22 Jan 2024 11:21:53 +0000 Received: from mail-lj1-x236.google.com (mail-lj1-x236.google.com [2a00:1450:4864:20::236]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 712cbdcf-b918-11ee-98f2-6d05b1d4d9a1; Mon, 22 Jan 2024 12:21:52 +0100 (CET) Received: by mail-lj1-x236.google.com with SMTP id 38308e7fff4ca-2cdb50d8982so32589751fa.2 for ; Mon, 22 Jan 2024 03:21:52 -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 m1-20020a056e021c2100b00362772f67a1sm1044137ilh.20.2024.01.22.03.21.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 22 Jan 2024 03:21:51 -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: 712cbdcf-b918-11ee-98f2-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1705922512; x=1706527312; darn=lists.xenproject.org; h=content-transfer-encoding:in-reply-to:autocrypt:from:references:cc :to:content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=kHBGqnsb4oN+WzK3qGlJoxKuVtHXhfOeG4UuXN/xmGA=; b=cqLeImj12OI/ckjVJWAZohQFxJ6pH0tGhnmG2Ah+EagCXhml859qBB+YlbA4hOSUMz FgcAyclGDYJUPzxpQpYbyj9oSs3KRMdMj78hX20wGQzsSu0WLvuese7MIYv0GolyQfEK +dlVoYyrHFLL4Lk1/WrgtgAxIECG173ZK20s3FazTBvOTL/md9iiX3ho/tZmaec5foLk pYkXhYEWm/NGlE6IY9b3vPf8tGnS1VjKivw7vAO9vlCmwpB8SjgFiOh8bBothdN5dgTy /ge4mApP+9Hg2S6Wty/W6hOY1xqwtkMr5J9wELaHGFclDg4AlXVqurA8DznmZFtfE2Fs sBUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705922512; x=1706527312; h=content-transfer-encoding:in-reply-to:autocrypt:from:references:cc :to:content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=kHBGqnsb4oN+WzK3qGlJoxKuVtHXhfOeG4UuXN/xmGA=; b=jQSGY/RkDTQ6JlXHa6wck9eO35xEiduSY774BU4pbNlv9X6qtOPcOf2PsnQAY6jNzv a+EsDCUwjZTOyQNErhk3lpfvsNqvYo2JHEqKCkOeJjqJmZPuQ7QZKiNKbin1qIqQQAkD hLB2FfplrhZGZ2Ovfkm4iSte/2ZzKE878zYYqB+s45s7o/xtd4YbhGu4kXEDEJwU/1FH 6qGPzAJ9u3j8vcxLb5cpJiISq87ZFDmROAFzln7qAbzsbjzYYQM3NDo8n0lYikuYgZBy UvcosIidRJ7NbPat1mEmw2s9V4FoBKAq5/1qSVES5RFAtIN9vNy8I919KYtafJTDqtkk eeBA== X-Gm-Message-State: AOJu0YyjcJxMZxvgyRq3hoMsW183xtdwHP36SBij1BjqMn2I25lOS3ts KZIRRu9rn2Ic+eTXCZwW7WDEwCbBZ+eIGkGkrUdH3A/4C8Qrd96y+o/JLUf7og== X-Google-Smtp-Source: AGHT+IHOPdIU/Y1MpiffzGMWgDWgAIy2JnWSHTyOiORPgyjGeXgHq3D2t4V1Gr1u35MP2QKX74EdpA== X-Received: by 2002:a2e:b0f4:0:b0:2cc:603f:5cd7 with SMTP id h20-20020a2eb0f4000000b002cc603f5cd7mr1608848ljl.6.1705922511950; Mon, 22 Jan 2024 03:21:51 -0800 (PST) Message-ID: <013210fd-6ea3-4719-afcd-1da97d9cd17f@suse.com> Date: Mon, 22 Jan 2024 12:21:47 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v5] x86/livepatch: align functions to ensure minimal distance between entry points Content-Language: en-US To: Roger Pau Monne Cc: Andrew Cooper , George Dunlap , Julien Grall , Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , Ross Lagerwall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , xen-devel@lists.xenproject.org References: <20240122110244.14091-1-roger.pau@citrix.com> From: Jan Beulich Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQ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V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: <20240122110244.14091-1-roger.pau@citrix.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 22.01.2024 12:02, Roger Pau Monne wrote: > 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 script, 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 it's possible for the compiler to end up using a higher function > alignment regardless of the passed value, so this change just make sure that > the minimum required for livepatch to work is present. 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. > In order to cope with this behavior and avoid that setting -falign-functions > results in an alignment inferior to what the optimization level would have > selected force x86 release builds to use a function alignment of 16 bytes. Nit: A comma after "selected" may help readability. > --- a/xen/Kconfig > +++ b/xen/Kconfig > @@ -37,6 +37,27 @@ config CC_HAS_VISIBILITY_ATTRIBUTE > config CC_SPLIT_SECTIONS > bool > > +# Set function 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. > +# > +# Requires clang >= 7.0.0 > +config CC_HAS_FUNCTION_ALIGNMENT > + def_bool $(cc-option,-falign-functions) Nit: Maybe better have a blank line here? > +config FUNCTION_ALIGNMENT_4B > + bool > +config FUNCTION_ALIGNMENT_8B > + bool > +config FUNCTION_ALIGNMENT_16B > + bool > +config FUNCTION_ALIGNMENT > + int > + depends on CC_HAS_FUNCTION_ALIGNMENT > + default 16 if FUNCTION_ALIGNMENT_16B > + default 8 if FUNCTION_ALIGNMENT_8B > + default 4 if FUNCTION_ALIGNMENT_4B > + > source "arch/$(SRCARCH)/Kconfig" > > config DEFCONFIG_LIST >[...] > --- a/xen/arch/x86/xen.lds.S > +++ b/xen/arch/x86/xen.lds.S > @@ -99,6 +99,10 @@ SECTIONS > *(.text) > #ifdef CONFIG_CC_SPLIT_SECTIONS > *(.text.*) > +#endif > +#ifdef CONFIG_FUNCTION_ALIGNMENT > + /* Ensure enough distance with the next placed section. */ > + . = ALIGN(CONFIG_FUNCTION_ALIGNMENT); > #endif > *(.text.__x86_indirect_thunk_*) I continue to fail to see how an alignment directive can guarantee minimum distance. In the worst case such a directive inserts nothing at all. IOW at the very least there's a non-spelled-out assumption here about the last item in the earlier section having suitable alignment and thus, if small in size, being suitably padded. Personally I don't think merely spelling out such a requirement would help - it would end up being a trap for someone to fall into. I'm further curious why .text.__x86_indirect_thunk_* is left past the inserted alignment. While pretty unlikely, isn't it in principle possible for the thunks there to also need patching? Aren't we instead requiring then that assembly functions (and thunks) all be suitably aligned as well? Jan