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 9D23AC54798 for ; Fri, 23 Feb 2024 12:24:55 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.684847.1065021 (Exim 4.92) (envelope-from ) id 1rdUba-0005jW-Be; Fri, 23 Feb 2024 12:24:42 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 684847.1065021; Fri, 23 Feb 2024 12:24:42 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rdUba-0005jP-8t; Fri, 23 Feb 2024 12:24:42 +0000 Received: by outflank-mailman (input) for mailman id 684847; Fri, 23 Feb 2024 12:24:40 +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 1rdUbY-0005jD-OI for xen-devel@lists.xenproject.org; Fri, 23 Feb 2024 12:24:40 +0000 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [2a00:1450:4864:20::52f]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 831c6e53-d246-11ee-98f5-efadbce2ee36; Fri, 23 Feb 2024 13:24:38 +0100 (CET) Received: by mail-ed1-x52f.google.com with SMTP id 4fb4d7f45d1cf-5643ae47cd3so891108a12.3 for ; Fri, 23 Feb 2024 04:24:38 -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 q29-20020a50cc9d000000b00563a3ff30basm6806208edi.59.2024.02.23.04.24.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 23 Feb 2024 04:24:37 -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: 831c6e53-d246-11ee-98f5-efadbce2ee36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1708691078; x=1709295878; 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=B4I9sZOXJcqzreICLCN3hytYAXvuabcNleeaVNRUsbI=; b=bHDZMfdUkxgkX4TffbTVl573m4sYD7zU2ifIsrqIvziOs6sS7/ZMeuMTZxMrH/VdUr 63Vq5Qj8boBl5+8ERUTXQ611mbEftLGs4/2SGfpHGhuijFbCQ+EfFiUKPnvGZAhLN1O0 A7vF76lKnvZMgsztkDMY4MiO5lTdESVLYdrvCrZUC9iXUOCb/Eo5VM/xPrWkS53IMFV9 nf5G4r5uEfx4JiSQzi6sugJx0F7+z5idz+og6dcZJefc+8/2qyn32J1QilAOpPYwAOQS v7QsSC1AvWheouzr4COLq+0J+xvpTN67natc6pV5D3tvEHv/oW//gi20HiGOJRr2Xrve p+yQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708691078; x=1709295878; 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=B4I9sZOXJcqzreICLCN3hytYAXvuabcNleeaVNRUsbI=; b=iD2c64L4wEBMtOcu4Eiygq7YKgsxdzCwZ2iwO2ptgotrQ8tOmbLxcYnd9hTlABEvEK 9MCvH3c0X52KTvDbJHCIJmyTCnvAa7Yx/w5cjhHTLxOBuRbHkspNE5mvJOW/F7fUqIn7 sVItN9tjevtbJZdth1K7Vd7isq5IwPWC6mhr1nhEFY3h/2Y1hrb1N2aUylBN1cAFtDY+ I2hiPW64AmkIc7RusFFkfQOe5ZIQZeHS0y8OCnUq1tzGiHS4L9iF87jgUuOEpxpgLjcJ g9dw2xlCzN1538+RnQCnrEdyDAC/MblUlpOfhET/x7Uvs255HQ8W+WKneze9CMnUazYM qKuA== X-Forwarded-Encrypted: i=1; AJvYcCV+fSEizMW8k/HV1c1ATSW5EaaVSnk3S7oPMsyaFka48LPFOwrDEHHqdoIetgT3N9Fof0LrZFQkDlb12956qxPdIBe43m3C2VOraUSjPNU= X-Gm-Message-State: AOJu0YxCLj8j6Wn7HamnNQ3G/1dnKmCqWQZNo5kXj8gfZzttruOv19Sk ivkQF+dHzu9iJuQsPtEmWamgU9g6r+rrp6yEy6VznkbM/iuDLN4UcG4MIuVx0g== X-Google-Smtp-Source: AGHT+IEqiazWVbPH8vIlUohZwm2+g5dBndk+3IyGp9Ma66OsdTPaK0lu7KlAqN/37lZg0rHIEsxJ2w== X-Received: by 2002:a05:6402:254c:b0:565:7114:ef37 with SMTP id l12-20020a056402254c00b005657114ef37mr1438498edb.12.1708691078043; Fri, 23 Feb 2024 04:24:38 -0800 (PST) Message-ID: Date: Fri, 23 Feb 2024 13:24:36 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] x86/altcall: use an union as register type for function parameters Content-Language: en-US To: =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= Cc: Andrew Cooper , Wei Liu , Matthew Grooms , xen-devel@lists.xenproject.org References: <20240222164455.67248-1-roger.pau@citrix.com> From: Jan Beulich Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/D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bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 23.02.2024 13:18, Roger Pau Monné wrote: > On Fri, Feb 23, 2024 at 11:43:14AM +0100, Jan Beulich wrote: >> On 23.02.2024 10:19, Roger Pau Monné wrote: >>> On Thu, Feb 22, 2024 at 05:55:00PM +0100, Jan Beulich wrote: >>>> On 22.02.2024 17:44, Roger Pau Monne wrote: >>>>> --- a/xen/arch/x86/include/asm/alternative.h >>>>> +++ b/xen/arch/x86/include/asm/alternative.h >>>>> @@ -167,9 +167,25 @@ extern void alternative_branches(void); >>>>> #define ALT_CALL_arg5 "r8" >>>>> #define ALT_CALL_arg6 "r9" >>>>> >>>>> +#ifdef CONFIG_CC_IS_CLANG >>>>> +/* >>>>> + * Use an union with an unsigned long in order to prevent clang from skipping a >>>>> + * possible truncation of the value. By using the union any truncation is >>>>> + * carried before the call instruction. >>>>> + * https://github.com/llvm/llvm-project/issues/82598 >>>>> + */ >>>> >>>> I think it needs saying that this is relying on compiler behavior not >>>> mandated by the standard, thus explaining why it's restricted to >>>> Clang (down the road we may even want to restrict to old versions, >>>> assuming they fix the issue at some point). Plus also giving future >>>> readers a clear understanding that if something breaks with this, it's >>>> not really a surprise. >>> >>> What about: >>> >>> Use a union with an unsigned long in order to prevent clang from >>> skipping a possible truncation of the value. By using the union any >>> truncation is carried before the call instruction. >> >> ..., in turn covering for ABI-non-compliance in that the necessary >> clipping / extension of the value is supposed to be carried out in >> the callee. >> >>> Note this >>> behavior is not mandated by the standard, and hence could stop being >>> a viable workaround, or worse, could cause a different set of >>> code-generation issues in future clang versions. >>> >>> This has been reported upstream at: >>> https://github.com/llvm/llvm-project/issues/82598 >>> >>>> Aiui this bug is only a special case of the other, much older one, so >>>> referencing that one here too would seem advisable. >>> >>> My report has been resolved as a duplicate of: >>> >>> https://github.com/llvm/llvm-project/issues/43573 >>> >>> FWIW, I think for the context the link is used in (altcall) my bug >>> report is more representative, and readers can always follow the trail >>> into the other inter-related bugs. >> >> While true, the comment extension suggested above goes beyond that >> territory, and there the other bug is quite relevant directly. After all >> what your change does is papering over a knock-on effect of them not >> following the ABI. And that simply because it is pretty hard to see how >> we could work around the ABI non-conformance itself (which btw could >> bite us if we had any affected C function called from assembly). >> >> 43537 looks to be a newer instance of 12579; funny they didn't close >> that as a duplicate then, too. > > So would you be OK with the following: Yes, ... > Use a union with an unsigned long in order to prevent clang from > skipping a possible truncation of the value. By using the union any > truncation is carried before the call instruction, in turn covering > for ABI-non-compliance in that the necessary clipping / extension of > the value is supposed to be carried out in the callee. > > Note this behavior is not mandated by the standard, and hence could > stop being a viable workaround, or worse, could cause a different set > of code-generation issues in future clang versions. > > This has been reported upstream at: > https://github.com/llvm/llvm-project/issues/12579 ... yet perhaps still list your new bug report here as well. Jan