From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lj1-f171.google.com (mail-lj1-f171.google.com [209.85.208.171]) (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 6C51E33343F for ; Wed, 21 Jan 2026 16:17:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=209.85.208.171 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769012229; cv=pass; b=FZzfVtmHOg1wHGOt4WCWxgDeo1yex3SbzRKL0HECuaYpN3aM1wHA8GuztM3ANAPYlsw1q4U2B5zUEq1a5Dc26scXG08EacAZRF6a2DDUdqunX3Rgwcw6MUO7JHukSuqCc9ydaJ8KsbblIVrkIsOHcRBEs+wccDY+HXw/UIs2Kqo= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769012229; c=relaxed/simple; bh=EnezYMjJBEeoERtCgdJJWB5tHj0Gc2U6tbov+6t2DzY=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=MwA438g/L6Fed3WeC7UAGOe+pl+b4VbNsYd2NmdxBA71swcSvQ1WFDlocyXrablpjJuZ1/3QF2MAifT/1YVbbrczg1sZ0ob4T8aTMFuUzoJRC7xTJCjwGEQVOH9L7kfwKe3UET1ckJrqaEmre74VUfX0zbmQcVV5lOM60Jbl8r4= ARC-Authentication-Results:i=2; 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=VmkndfLi; arc=pass smtp.client-ip=209.85.208.171 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="VmkndfLi" Received: by mail-lj1-f171.google.com with SMTP id 38308e7fff4ca-38304020185so113811fa.2 for ; Wed, 21 Jan 2026 08:17:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1769012225; cv=none; d=google.com; s=arc-20240605; b=dfPnABWWaqrDItD7H0Fz/RfbKJ/sCAIFtltA+d7p0Jmzy+FasNMBaOT5P5iz49wj0K i2r731rjV/am+DalN16Mud5ZMXuU1MOBovS+K/xbeVwIOiBYpWcymq3BZ7VmH4dV3Ks4 7SuF/Phhx527N37Zt7CltxQjclgoixR3JrOYYR3ETefz76EI0cHzGaJkK8AKXWNHfqkG m5P83swqd5OJMuw9x9c80ZfRerX8GfL+Qg8+P5nCERGKqQt0MDnfvP1lg2hfTwARXEVX NZQ3Ee0t83hfbairRqWm3p+chSY0YFc/XIkVyROiNFVzk1vqr1GfPagBqP+JzcgLEoRs 7Vjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=IbUyMSwkS2THpK+duEm5DQP8Ica4Rv0xGOmFUVH8VYw=; fh=8A9m/el7oZ1Km+QPZlHxHZcu+7xdpYmnMfj9mXo7q9w=; b=Wk/IrUaxiBGXeeTYt1vBhq1VR/6SSjB0B/BIDzkvXgpumUtDTceb5lbyC5gGAxGn8Y ++YkMPZTtSAyhfTYXgNDJbKG2i6HIhpQ050RH9Y1MBkevbdr9rTZkNtf0wHbqDp99zlj +75BgFAUHNQRYeD+piP18rtzzrROQ/4VL/tDAwR4XrtMW7jWCD0xXVgnlHLZS1c1iKmO tC8RCWDm0i6GaYnkr+fL6z9EsbzHNLUiHvvpZH1zvPZAs3JGIBC9AyRGRVX0yOGyCgOe Zjre3CzSx3ZxzSBULw7TCUABSn8/B3SLktfDkSkLqP+0RVuYPpeirYVAPd0azLGq4zmB ZT5g==; darn=vger.kernel.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769012225; x=1769617025; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=IbUyMSwkS2THpK+duEm5DQP8Ica4Rv0xGOmFUVH8VYw=; b=VmkndfLiTaZatAUpl2rQRxZIQlsJR5S1Lr2BUpQ07+/q9lpk4gQzyRLorKngDAOG35 XbUwZLhtBuH3yLBqI7wNzQ9eR07sO2PrqwMMv2GkJPZ83XvPQiepxNVGU7b7Z5Kk1/Su gzOEqyZ861IVj+mEqkLVBfFoQzuSjmMzT1iQxUYUDX3i9xVFB73dhrEGvXZ2XkIlHOpU 8XnGg+3BHZXrCXeuFFXSvGMiTfP4AhbhOBYZogJ/2k1t4qwc92ka1Vov33oLqqiMHvcU 6jlGfEJXKAO8VqdAoOTj8Y7zIA9NvZDk4N6+JHr1ZAczMgoGOy8ssMwQdCyNSY0sKHHZ tPPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769012225; x=1769617025; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=IbUyMSwkS2THpK+duEm5DQP8Ica4Rv0xGOmFUVH8VYw=; b=Pwhu1NBOisfv07Rssk5DyoF03xgeB0YbEH1F8wL5OFuPq6PYvr31+o6IzFZ8fB+m7b gYZjrwcNQW6Lxqgg0k8aFnWd1M2AbwhmZxNgONB8yr0AUuqtHRruHrFnAU2MAbuRRqcE EDDm1eo3AOwThWY2FZLzKY23E1h0WDqqlKkqH0tx3pUtOA06po8tWNzLRgLaiRQwb1Hu V34cntRJG5iMoTLyp7o1lGSigWWCA4827gGa9B6zT1dh8IJ4gnLihYrVSy4bhEquwKMF FEob69KGWK6Z3aOVytp3BgZoMHY+Ea13EDoSb5DNQqu2VFRJnxJdPjuCxXFYFB+A/3Te lKqA== X-Forwarded-Encrypted: i=1; AJvYcCU4zbEv/bzxA78xEFWE9hqFCm8K1+oQmDz5cOzCdPE7muwZHUfgGvw43qETc2F5GQWUt0c84YN/AdkhQXo=@vger.kernel.org X-Gm-Message-State: AOJu0YzSm47PDidrJo/3/GF0mYGBKGTR26u6sokGTjtOiW+2pzOByJPr V0UsKvqDl4otQTPGst5AYgjiw1E9YqOpGBSr5jWM4nUHFdShtIwlsD6snjvjsKCj3ho5q0C5ck7 UMaN55FWP20oIxV1JBuP4EG3J0L3RAzI= X-Gm-Gg: AZuq6aJLid+919dyFdqyDMa0nv6CQH7kJ2zMUbQBK5tndIFX8n1PiLBkJIpNnCBw5qu TWHdHNpnDubfbvJp9YzYcEzlOqYkiZzpKpZgEEvE+51ph+o9fxobVOLJnLQTca6S8BHK3++NrQh aS1vki7g5Hk7k36ylKDeljrnmdDi2CyAUNEQjgltxKvAelE+vXtVisbgv6X60QlmVG+kairkv0u oOccVg76M62DsrH1w1haLrIfiO9y3lGtdHlXKMg+VDmqbk47ruhiJ3vobKbksM4UA4n0TAM50xk UKcAmCxUXjExymoex+pFWz447UBvZTGl0DFlZg== X-Received: by 2002:a2e:bd83:0:b0:383:1d89:8cfa with SMTP id 38308e7fff4ca-383842dea57mr57965331fa.31.1769012224890; Wed, 21 Jan 2026 08:17:04 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20260105090422.6243-1-ubizjak@gmail.com> <176891088183.510.8607818928752445249.tip-bot2@tip-bot2> <3A54B6DC-2462-41DA-8C34-D38CCD2A9A2B@zytor.com> <20260121140857.3544d19e@pumpkin> In-Reply-To: <20260121140857.3544d19e@pumpkin> From: Uros Bizjak Date: Wed, 21 Jan 2026 17:16:53 +0100 X-Gm-Features: AZwV_Qhs7yi0l7pxnfI94c0waWp_pCDndezu9sEMh7Hqq6ONJq2d6NMeoqqZtqk Message-ID: Subject: Re: [tip: x86/cleanups] x86/segment: Use MOVL when reading segment registers To: David Laight Cc: Brian Gerst , "H. Peter Anvin" , linux-kernel@vger.kernel.org, tip-bot2 for Uros Bizjak , linux-tip-commits@vger.kernel.org, "Borislav Petkov (AMD)" , Michael Kelley , x86@kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Jan 21, 2026 at 5:06=E2=80=AFPM David Laight wrote: > > On Wed, 21 Jan 2026 06:49:16 -0500 > Brian Gerst wrote: > > > On Wed, Jan 21, 2026 at 2:29=E2=80=AFAM H. Peter Anvin = wrote: > > > > > > On January 20, 2026 4:08:01 AM PST, tip-bot2 for Uros Bizjak wrote: > > > >The following commit has been merged into the x86/cleanups branch of= tip: > > > > > > > >Commit-ID: 53ed3d91a141f5c8b3bce45b0004fbbfefe77956 > > > >Gitweb: https://git.kernel.org/tip/53ed3d91a141f5c8b3bce45b00= 04fbbfefe77956 > > > >Author: Uros Bizjak > > > >AuthorDate: Mon, 05 Jan 2026 10:02:32 +01:00 > > > >Committer: Borislav Petkov (AMD) > > > >CommitterDate: Tue, 20 Jan 2026 12:34:58 +01:00 > > > > > > > >x86/segment: Use MOVL when reading segment registers > > > > > > > >Use MOVL when reading segment registers to avoid 0x66 operand-size o= verride > > > >insn prefix. The segment value is always 16-bit and gets zero-extend= ed to the > > > >full 32-bit size. > > > > > > > >Example: > > > > > > > > 4e4: 66 8c c0 mov %es,%ax > > > > 4e7: 66 89 83 80 0b 00 00 mov %ax,0xb80(%rbx) > > > > > > > > 4e4: 8c c0 mov %es,%eax > > > > 4e6: 66 89 83 80 0b 00 00 mov %ax,0xb80(%rbx) > > > > > > > >Also, use the %k0 modifier which generates the SImode (signed intege= r) > > > >register name for the target register. > > > > > > > > [ bp: Extend and clarify commit message. ] > > > > > > > >Signed-off-by: Uros Bizjak > > > >Signed-off-by: Borislav Petkov (AMD) > > > >Reviewed-by: H. Peter Anvin (Intel) > > > >Tested-by: Michael Kelley > > > >Link: https://patch.msgid.link/20260105090422.6243-1-ubizjak@gmail.c= om > > > >--- > > > > arch/x86/include/asm/segment.h | 2 +- > > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > > >diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/s= egment.h > > > >index f59ae71..9f5be2b 100644 > > > >--- a/arch/x86/include/asm/segment.h > > > >+++ b/arch/x86/include/asm/segment.h > > > >@@ -348,7 +348,7 @@ static inline void __loadsegment_fs(unsigned sho= rt value) > > > > * Save a segment register away: > > > > */ > > > > #define savesegment(seg, value) \ > > > >- asm("mov %%" #seg ",%0":"=3Dr" (value) : : "memory") > > > >+ asm("movl %%" #seg ",%k0" : "=3Dr" (value) : : "memory") > > > > > > > > #endif /* !__ASSEMBLER__ */ > > > > #endif /* __KERNEL__ */ > > > > > > > > > > Incidentally, why aren't we using =3Drm here? Segment moves support m= emory operands. > > > > You would have to be really careful to only use short (16-bit) > > variables, because it will not zero-extend with a memory operand. > > > > It would be much safer to have something that returned the value > of the segment register (zero extended to 32 bits). movl from %seg to 32-bit register (as proposed in the patch) zero-extends the value all the way to word size (64-bits on x86_64). The proposed solution also handles memory operands, so: --cut here-- unsigned int m; void foo(void) { asm("mov %%gs,%k0" : "=3Dr"(m)); } --cut here-- compiles to optimal code: 0000000000000000 : 0: 8c e8 mov %gs,%eax 2: 89 05 00 00 00 00 mov %eax,0x0(%rip) # 8 4: R_X86_64_PC32 m-0x4 8: c3 ret Uros.