From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 52F403A9D84 for ; Thu, 19 Mar 2026 10:20:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773915634; cv=none; b=YAWXyXbsLH6IVaT+Y5SrgKh/ef1B4tFrEQV+FL2Es+YCMA0gXbcp1Qrd9TBBeTY2NjSmADtF0mmy5na0Npn9pmY7ASolF7XX4Nv6fxlat55lUVwumrkmieJ6dQoHIJCmR90fxJ4Vi67YXmXDKD5C2E08IgVzVQkY/hMltkSacHQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773915634; c=relaxed/simple; bh=++fcf6S/XK0D11pTdmgYtr7l3b7FuFwrXEdr5gNWnEY=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mk4SzCrrqS8VYXbFNNQZVkM8q+zU9F4Ythk+quhpEk5Mtkepo2E5MzTTTezlaOBZMSo+jRp8ej/TezDF0Q7emWAL9CuX+bizq3d9WVXr7JsOfMYXNznR9mJr9074VfdZjwRA1nCnekeeVmqqF4/siCTjJ7Feau+9533rpfx7O0c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ao70TAOW; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ao70TAOW" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-486fb14227cso5500045e9.3 for ; Thu, 19 Mar 2026 03:20:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773915627; x=1774520427; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=er86Qb4lQzAU+b2qgRF3WCMVavCR5Nk0ABnuQReaSbs=; b=ao70TAOWQup8JDpHZi4+LWvBenoXu9UeuIEl9PebFW9flfEZiI9YnILJOxDTpkNabw 7dTCBu2cFvdj6NuihybtPv1jn9uOfotD3kbjD+qkoxMUGd2J+RH6dgwjikPBZPSpkITg qXJlzK6jpeDxGF2CDxhufdUivCWeohDR0v04VlpyeO3q1zVxYp/m8LgRGAJOXrI40nd4 538jeEkuq8/4u96zufH6RFKE9orabRzORNC3JYgBKUSMWnMpdQPeEnxxnflNF0SZv/z6 oZrGUlHKM5aMxod1JDvYSbwHt5dP47Vj0x8E26W/kWIBYDD+vq9wPo1xq69zSyZaxvTQ 8GOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773915627; x=1774520427; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=er86Qb4lQzAU+b2qgRF3WCMVavCR5Nk0ABnuQReaSbs=; b=kl3/zvaaoppyPvXZQioj9EaWM/bywxVIHVon+vtUQRrlPUTSkCwyhH808wxP1zrLno Q6n/crKoVwnuAvrQpKK5GdWigBivyvqNe/racZwAeuk1GyYvP5hbhdHUbI2UJg/uxpzh zhXBXWnkI7jh8MYbgAknmKIHg2l/ax0HVG9hHIaACQ/H04T7A/Ks6ogdgVq3xjK0/8Vp rbX2GX1tIfsOuA38MCeLtJXM7aNAP/sWdB+b/NPkayjUoDPYlNakJ4ffJV17Qoc8cBiW 2JtGeAznV9z87Ch9JHVe2JrSp6XddLopfXVRoN3RDVpaPIY0LwkoT+302fxukl+KlaK9 0dsQ== X-Forwarded-Encrypted: i=1; AJvYcCWhZX9avMO2JklxHF+8cXl9SmrifdQuOTqHU0Im1r2Mj7OmNWk1Kv7X2RhU7+4qf7LugVeZdC7CCorg5xU=@vger.kernel.org X-Gm-Message-State: AOJu0YyGORlQilyP8NfBepV3UlfeTiAXQTYzPwju6/eqIfp8zZFsMydn eFCMlhQ8D+nSvqoiRf7lohuXGp5GDgSpr6y34ANpeleOfftWbkS3FdCK X-Gm-Gg: ATEYQzwVHBM0fbvwgjjW+sDB6NOgLuoYBDllO/NKRm/xZIEqDuuBGqh1cutX6h3njnI Du/FUMraze+kyNzRH3eL3kFcx04gF38n0+jIry6o7GS+mo6FVWlZIo0/705bbegSCAoQN4xCkvY 5jPv1GdX8Doj+XP3s5P9Q8uoZicIebC0cT3E2g8b425cQfjSLZns3R6r2mi4EQ8u7pj/YG0PVKs E9CkZifIIRBg26krwa7EIZiLV4omNbV0qgJClmAPLkuJJ2vRvogA4lKMxC/i4r9WvAzFHK7IEyc XHHV44UYhwgbXJPsLeNFjrAtBO0PI6fmzjDH9gvi1A5dOvnba1o/V2qeE9fJCr7nQEf0fosuuub TUeGbC0qoaiGi/ibK1F00kqhbIhwJq2cCzTRfN79jZurUiBDBGouHjtsaMDlfUUrMY+y62GecaH jvDwQ7kuyW+UCKKQyvBlgX2iKdKGyriFkiZhPMx9woT3Bdho657Pg5DDwV6f0PwA2z X-Received: by 2002:a05:600c:8b0a:b0:479:1b0f:dfff with SMTP id 5b1f17b1804b1-486f44221f2mr110416825e9.10.1773915626819; Thu, 19 Mar 2026 03:20:26 -0700 (PDT) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-486f8c4aa85sm45536275e9.12.2026.03.19.03.20.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Mar 2026 03:20:26 -0700 (PDT) Date: Thu, 19 Mar 2026 10:20:25 +0000 From: David Laight To: Uros Bizjak Cc: x86@kernel.org, linux-kernel@vger.kernel.org, "Peter Zijlstra (Intel)" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" Subject: Re: [PATCH] x86/asm: Switch clflush alternatives to use %a address operand modifier Message-ID: <20260319102025.213b68aa@pumpkin> In-Reply-To: References: <20260318090831.501191-1-ubizjak@gmail.com> <20260318150315.6cff1844@pumpkin> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Wed, 18 Mar 2026 16:45:28 +0100 Uros Bizjak wrote: > On Wed, Mar 18, 2026 at 4:03=E2=80=AFPM David Laight > wrote: > > > > On Wed, 18 Mar 2026 10:08:11 +0100 > > Uros Bizjak wrote: > > =20 > > > The inline asm used with alternative_input() specifies the address > > > operand for clflush with the "a" input operand constraint and > > > explicit "(%[addr])" dereference: > > > > > > "clflush (%[addr])", [addr] "a" (addr) > > > > > > This forces the pointer into %rax and manually encodes the memory > > > operand in the template. Instead, use the %a address operand > > > modifier and relax the constraint from "a" to "r": > > > > > > "clflush %a[addr]", [addr] "r" (addr) > > > > > > This lets the compiler choose the register while generating the > > > correct addressing mode. =20 > > > > Aren't these two independent changes? =20 >=20 > I was hoping I can put a trivial "a" -> "r" change under the "also > ..." change. OTOH, let's change the summary to "x86/asm: Improve > clflush alternatives assembly", that will also handle your proposed > addition of "memory" clobber. >=20 > > %a saves you having to know how to write the memory reference for the > > architecture - so is the same as (%[addr]) (assuming att syntax). > > I think the assembler handles the one 'odd' case of (%rbp). =20 >=20 > Yes, it does, and also fixes another 'odd' case of (%r13). >=20 > > Was there ever a reason for using "a" rather than "r" - it seems an > > unusual choice. =20 >=20 > Probably just an oversight due to a follow-up __monitor() that wants > its operand in %rax. Actually gcc can be quite bad are reverse tracking register requirements. So forcing 'addr' into %rax for the cflush might actually remove a register move before the monitor. Indeed, were it to pick a different register there will always be a extra register move. If the value is in a different register (eg from a function call) then you'll move the register move instruction - but there'll still be one. So I suspect this change can never improve the code. David >=20 > > I also think there should be a "memory" clobber - but it probably > > makes no difference for these two cases. =20 >=20 > Hm, I think this is a good proposal. The pointer in the register is > invisible to the compiler memory tracker, so the compiler is free to > schedule (potentially related!) memory access around clflush. The > clobber doesn't make a difference in this particular case, but should > be there nevertheless as a memory read/write barrier. >=20 > Thanks, > Uros. >=20