From nobody Mon Sep 16 18:56:17 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=1721727126; cv=none; d=zohomail.com; s=zohoarc; b=kbFRcLvlObt62JB30GrSfx7MFGPL9nEfv7LbwdE8hkbmlNOaOOVh1LO74/tssKOeb23qCnI5sKSyUGGkRAx42KoOW2jPRHNnBn3zTu4g+/TlQMYXDqFwbp9M+Tc5EZqiBbfy/e24JDeWSAwvlzRHRnnGmfGeubuY3KxbVhiJK+E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1721727126; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=4p5EBajcnF2PBWFGM7P90104CDoSF78S5SKBKjL4e/Y=; b=GtU/W4gU8CtW52YvhfuZNhp1xM2uWsOnjaE0F3jPR/Yj7ym7MqcajhS+lKNmp8vGcCjuxOU8GqB6t/qYCjtJPhEg8EDXS6NgXiUPf6JZQwNXp0qtdG+XwI3rA/D5/XY5d8D+rR2YSY6CEPhUoNy3WomX0JjmMixm7b2QkB+F3FE= 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 1721727126601352.2527146096372; Tue, 23 Jul 2024 02:32:06 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.762893.1173120 (Exim 4.92) (envelope-from ) id 1sWBs6-0005y3-2N; Tue, 23 Jul 2024 09:31:50 +0000 Received: by outflank-mailman (output) from mailman id 762893.1173120; Tue, 23 Jul 2024 09:31:50 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sWBs5-0005xw-Vr; Tue, 23 Jul 2024 09:31:49 +0000 Received: by outflank-mailman (input) for mailman id 762893; Tue, 23 Jul 2024 09:31:48 +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 1sWBs4-0005xq-IK for xen-devel@lists.xenproject.org; Tue, 23 Jul 2024 09:31:48 +0000 Received: from mail-lj1-x233.google.com (mail-lj1-x233.google.com [2a00:1450:4864:20::233]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 62012341-48d6-11ef-bbfe-fd08da9f4363; Tue, 23 Jul 2024 11:31:47 +0200 (CEST) Received: by mail-lj1-x233.google.com with SMTP id 38308e7fff4ca-2ef2d7d8854so22634941fa.0 for ; Tue, 23 Jul 2024 02:31:47 -0700 (PDT) Received: from localhost ([213.195.124.163]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-427d6906a96sm168073485e9.22.2024.07.23.02.31.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jul 2024 02:31:46 -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: 62012341-48d6-11ef-bbfe-fd08da9f4363 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1721727107; x=1722331907; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=4p5EBajcnF2PBWFGM7P90104CDoSF78S5SKBKjL4e/Y=; b=Px2VoIjBIiErERU+l+1A9M8P1zeEqostM0d7WZMyjzTGmnt12yyevBUQCDCTqFAfGe XNfQjSPetoLXVnCGa1Qx0U1VYvnnmU4xL9jv5p2RY8qjBjdzSNPE8OEXVJ6IdxH8DNfm Cl115pM/3AwBrXsC/ITqvndHFPzhzAK1TnOSU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721727107; x=1722331907; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=4p5EBajcnF2PBWFGM7P90104CDoSF78S5SKBKjL4e/Y=; b=DA6t35KkC+8q7lRboyQRWdg4c4HsgcHZEaXmDcfqSREH3x+jD04fjbyFU4OzBnrA1x K2y7Cu1xOiKUmfjR/UQuaFVURNBRv2FPIwraaSVRy92Ua/iKOiL+k+rmoS1HfwTCMooW 0oVtBfvaFsMa2+ryWQJUxE3QMxN4HtDtpiHYQLbKYBa6fAgUumvsVKBPNp5Tp5I9aptl ldQMxvVxZxBIujE7XsRmsV/5FnM7ObogABEXdfOTfA+PrbyuM+h31Qr+JcvTWpmmbKIp fMtuGx7Oukp8pqIEIfYn0G045agt8LDxuSsv1YUoyu8vg2UX3Jcq/ibwYq9Ns/0TcKpe 9knA== X-Gm-Message-State: AOJu0YwVfJVMeDckRSLELqnowhuZFObSmuRJNNyRv9fEsN/SdN8uRDC1 l3EoPI1jxky2iLhdB5tYz9gQXNn5hb0VDiphHxWQzT7onF6aRi9U2IRQpKuzOZbRvXD1PyB6Efu B X-Google-Smtp-Source: AGHT+IE1pyooqsY8trGVubUq4gK4A3xLfKdqvT96Y8tKgrPiFsTVxiOCI/mJeYESNEAImuc7Km7BXA== X-Received: by 2002:a2e:9f16:0:b0:2ee:80b2:1e99 with SMTP id 38308e7fff4ca-2f01ead8f10mr16221501fa.44.1721727106436; Tue, 23 Jul 2024 02:31:46 -0700 (PDT) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Jan Beulich , Andrew Cooper , Oleksii Kurochko Subject: [PATCH for-4.19] x86/altcall: fix clang code-gen when using altcall in loop constructs Date: Tue, 23 Jul 2024 11:31:17 +0200 Message-ID: <20240723093117.99487-1-roger.pau@citrix.com> X-Mailer: git-send-email 2.45.2 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: 1721727127015116600 Yet another clang code generation issue when using altcalls. The issue this time is with using loop constructs around alternative_{,v}ca= ll instances using parameter types smaller than the register size. Given the following example code: static void bar(bool b) { unsigned int i; for ( i =3D 0; i < 10; i++ ) { int ret_; register union { bool e; unsigned long r; } di asm("rdi") =3D { .e =3D b }; register unsigned long si asm("rsi"); register unsigned long dx asm("rdx"); register unsigned long cx asm("rcx"); register unsigned long r8 asm("r8"); register unsigned long r9 asm("r9"); register unsigned long r10 asm("r10"); register unsigned long r11 asm("r11"); asm volatile ( "call %c[addr]" : "+r" (di), "=3Dr" (si), "=3Dr" (dx), "=3Dr" (cx), "=3Dr" (r8), "=3Dr" (r9), "=3Dr" (r10), "=3Dr" (r11), "=3Da" (ret_) : [addr] "i" (&(func)), "g" (func) : "memory" ); } } See: https://godbolt.org/z/qvxMGd84q Clang will generate machine code that only resets the low 8 bits of %rdi between loop calls, leaving the rest of the register possibly containing garbage from the use of %rdi inside the called function. Note also that cl= ang doesn't truncate the input parameters at the callee, thus breaking the psAB= I. Fix this by turning the `e` element in the anonymous union into an array th= at consumes the same space as an unsigned long, as this forces clang to reset = the whole %rdi register instead of just the low 8 bits. Fixes: 2ce562b2a413 ('x86/altcall: use a union as register type for functio= n parameters on clang') Suggested-by: Jan Beulich Signed-off-by: Roger Pau Monn=C3=A9 Reviewed-by: Jan Beulich --- Adding Oleksii as to whether this could be considered for 4.19: it's strict= ly limited to clang builds, plus will need to be backported anyway. --- xen/arch/x86/include/asm/alternative.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/include/asm/alternative.h b/xen/arch/x86/include/= asm/alternative.h index 0d3697f1de49..e63b45927643 100644 --- a/xen/arch/x86/include/asm/alternative.h +++ b/xen/arch/x86/include/asm/alternative.h @@ -185,10 +185,10 @@ extern void alternative_branches(void); */ #define ALT_CALL_ARG(arg, n) \ register union { \ - typeof(arg) e; \ + typeof(arg) e[sizeof(long) / sizeof(arg)]; \ unsigned long r; \ } a ## n ## _ asm ( ALT_CALL_arg ## n ) =3D { \ - .e =3D ({ BUILD_BUG_ON(sizeof(arg) > sizeof(void *)); (arg); }) \ + .e[0] =3D ({ BUILD_BUG_ON(sizeof(arg) > sizeof(void *)); (arg); })\ } #else #define ALT_CALL_ARG(arg, n) \ --=20 2.45.2