From nobody Sat Feb 7 16:39:27 2026 Received: from mail-ed1-f44.google.com (mail-ed1-f44.google.com [209.85.208.44]) (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 BE19E20C029 for ; Tue, 23 Dec 2025 20:20:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766521251; cv=none; b=M+hOU5xKtU73GfkD2p/hU9m8Wx+hZ/hnBvnfdqtXoaXE9gqRUmhPYkYmdz14NqXmZfY8L03NUlX0BUDA8jfPiqMkFmFB3Uczb1BV5x5J0RiTRl65RwCu1ee0c3oSfYMUfh246mF+E59udz+ZZHLC2vCoY0YoncOh6GdbnCOtKrQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766521251; c=relaxed/simple; bh=LlyjlclXGN692O2SWEY8ay9uEe4c6AvrD+APt6+mDlw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=l4+eMc9t2ZybC6gUmag5Tean3+t7AGRGTUwIbQ6vqIkMPAIsd/gXQnZTgT8vg7KSZd4jfE07YrFjiMh4dTUTqTQGpJCKkvBVu65GiOg8pBVcYafaL+VzFcFe4r0rm8XVsAu4ycH7ptlhgT1PjXlvfQoR0iYFXswWNjzTpVziEfA= 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=mBzDseei; arc=none smtp.client-ip=209.85.208.44 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="mBzDseei" Received: by mail-ed1-f44.google.com with SMTP id 4fb4d7f45d1cf-64b92abe63aso7585523a12.0 for ; Tue, 23 Dec 2025 12:20:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766521248; x=1767126048; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8t2IfrlBya6NzOo6SZSiTUH90/X3W1rsvlXvoEG82FU=; b=mBzDseeiCluj4WAL9r6QDrkKDIWRdzSA5eysO02qmxulEy+sZzxYKTOIUb2lKLNZDi ItLN9C5g39X+nGLsWu5Q95kcov+CFw0l+ztdaYwF51Ldl4lnXCm3ksem6DvuKElUxSZt HOINPIzs+b852G4raf3Y/IqyW3u4GvQNs17nO5eYGk65dvRNmyN6JoeRd3VZ2pwh36Ua NS+BhhyGuYHDRfonB1E58uqeBL2j/qp8nmwDDcHEyP7fmDevBMWOjE1YloeG6nowd7km lacsOYC3encjWnXB+FN+d2YQ9z+7RwLH6rHvLKOOQJmE0+pdKK+8Hja9g8ungVG7EvsF XVuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766521248; x=1767126048; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=8t2IfrlBya6NzOo6SZSiTUH90/X3W1rsvlXvoEG82FU=; b=eGzCgqhAl/TzEMLX0USM7tyfjsILK2j4X7XMrNwdyt9uDZzIlinKvYbplxhj/23la7 r//vmSPrY/vHdsTCH7QllgYX6rVm9JibzJZGhdoXnjk+grt8VLiZGJX0d0nnWUAPBeHu jXDfFFmGzG5W44soxGRXqGYRlxIv2lUJblu7UgiLi8cmJNXr+TdimCSKlHnPRM6phk8o On7nvrN1Obwrys96sMtkpsiov3C7pLyh5RRfkswyBdEINWjUWEkGqACBEW0F/Cj0bVTT dzOzEWxhNhzTOLTxzthr5buPQeG+sq4gt8RX1VegLcr7HEIFBfnOfOfvoAZ3/BSQAukV S2Eg== X-Forwarded-Encrypted: i=1; AJvYcCXicjK16lE8BT0kVoKCkCho2vRWfv9qqUPKwUv5yv3E0bQuv6GdyUnWYJPCpz4MCW+DYy7rDNuBLhF4440=@vger.kernel.org X-Gm-Message-State: AOJu0Ywj2+MiJV3IuGzV+8GlzxwUA1FKEX9SFMH954CdbYqLh2ZZVwBz EvoqjKBfqqMRQZbSslPmkUkE4Nu5TtSfs2mP+Q92gtmcb9SP25rkhA/v X-Gm-Gg: AY/fxX5S7PG1CHfjBVDVrdr/NqJFg/0Yh+avQxieBd9RrgmzwPad8YxKUsEnDiFeVpe 9bwsp8FwAeRB76prPhJbuxZoBhpNgTbLgdLwIW39j92xYal6gMUyYvDZ1y224Ejy1QhZQScTey3 L4fC6CUKoSNsuHiovAjERB+iO95iY29rA85DHCzKbXhT+m/oCrW02QokRmrXOAxPM1ad8ZZaG/F Wr4RP94klJwncBQRSjmIkjHKt59iOtUsHMlC6zD0HXH8oKay2v5e+uYk9U5mKNlZXWr0Dtv+d14 jeJlWOciF5m4vPebhrM2IsHeTAjbbnDPw4EWYBz2znMebRq4E6dPWRWXFduZVa09wmH0EKOmd2Z m8/uTsIjILSd89LTGwzgXv2Orv36zDMTNoLRj/2AUXgXk3hvjaEOT795rYvzX3A9WWHGcp9e7kZ cynasYfdSO4BiJ2XBQkgTkauRvYw23kbG21JRhMZzx+EQ= X-Google-Smtp-Source: AGHT+IERetNfHsRXNnmsuixwV63EZ9aUKbNhPYULrI+e6CG2A/WjJrZfzbnUT2ZksmfOEyavTT51iQ== X-Received: by 2002:a05:6402:2787:b0:64d:1fcf:3eda with SMTP id 4fb4d7f45d1cf-64d1fcf41d4mr9844158a12.22.1766521247825; Tue, 23 Dec 2025 12:20:47 -0800 (PST) Received: from fedora ([46.248.82.114]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-64b91599844sm14707177a12.25.2025.12.23.12.20.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Dec 2025 12:20:46 -0800 (PST) From: Uros Bizjak To: x86@kernel.org, linux-kernel@vger.kernel.org Cc: Uros Bizjak , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" Subject: [PATCH 1/3] x86/boot: replace FS/GS inline asm with segment-qualified accesses Date: Tue, 23 Dec 2025 21:18:56 +0100 Message-ID: <20251223202038.91200-2-ubizjak@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251223202038.91200-1-ubizjak@gmail.com> References: <20251223202038.91200-1-ubizjak@gmail.com> 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 GCC treats absolute addresses smaller than min-pagesize param (defaulting to 4kB) as assumed results of pointer arithmetics from NULL. The following code, when compiled with -O2 -Warray-bounds (included in -Wall): int foo (void) { return *(int *)0x123; } will emit a rather cryptic warning: warning: array subscript 0 is outside array bounds of =E2=80=98int[0]=E2=80= =99 [-Warray-bounds=3D] 1 | int foo (void) { return *(int *)0x123; } | ^~~~~~~~~~~~~ cc1: note: source object is likely at address zero Currently, the warning is supressed by the GCC specific RELOC_HIDE() macro that obfuscates arithmetic on a variable address so that GCC doesn't recognize the original var, and make assumptions about it. The GCC specific RELOC_HIDE() macro was introduced to work around certain ppc64 specific compiler bug in pre-4.1 GCC. This bug was fixed long ago, and replacing GCC specific macro with a generic one triggers the above warning in vga_recalc_vertical(). To solve the issue, replace open-coded inline assembly used for FS/GS memory accesses in arch/x86/boot/boot.h with segment-qualified pointer dereferences. The compiler allows pointer arithmetic from NULL in __seg_fs and __seg_gs named address spaces. Using __seg_fs and __seg_gs also simplifies the code, improves readability, and allows the compiler to reason better about the memory accesses. Explicit "memory" clobbers are also added to FS/GS segment register updates and repe cmpsb helpers to prevent incorrect reordering. No functional changes intended. Signed-off-by: Uros Bizjak Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: "H. Peter Anvin" --- arch/x86/boot/boot.h | 58 ++++++++++++++------------------------------ 1 file changed, 18 insertions(+), 40 deletions(-) diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h index 8e3eab34dff4..6f39048f0481 100644 --- a/arch/x86/boot/boot.h +++ b/arch/x86/boot/boot.h @@ -53,7 +53,7 @@ static inline u16 ds(void) =20 static inline void set_fs(u16 seg) { - asm volatile("movw %0,%%fs" : : "rm" (seg)); + asm volatile("movw %0,%%fs" : : "rm" (seg) : "memory"); } static inline u16 fs(void) { @@ -64,7 +64,7 @@ static inline u16 fs(void) =20 static inline void set_gs(u16 seg) { - asm volatile("movw %0,%%gs" : : "rm" (seg)); + asm volatile("movw %0,%%gs" : : "rm" (seg) : "memory"); } static inline u16 gs(void) { @@ -77,78 +77,54 @@ typedef unsigned int addr_t; =20 static inline u8 rdfs8(addr_t addr) { - u8 *ptr =3D (u8 *)absolute_pointer(addr); - u8 v; - asm volatile("movb %%fs:%1,%0" : "=3Dq" (v) : "m" (*ptr)); - return v; + return *(__seg_fs u8 *)(__force addr_t)absolute_pointer(addr); } static inline u16 rdfs16(addr_t addr) { - u16 *ptr =3D (u16 *)absolute_pointer(addr); - u16 v; - asm volatile("movw %%fs:%1,%0" : "=3Dr" (v) : "m" (*ptr)); - return v; + return *(__seg_fs u16 *)(__force addr_t)absolute_pointer(addr); } static inline u32 rdfs32(addr_t addr) { - u32 *ptr =3D (u32 *)absolute_pointer(addr); - u32 v; - asm volatile("movl %%fs:%1,%0" : "=3Dr" (v) : "m" (*ptr)); - return v; + return *(__seg_fs u32 *)(__force addr_t)absolute_pointer(addr); } =20 static inline void wrfs8(u8 v, addr_t addr) { - u8 *ptr =3D (u8 *)absolute_pointer(addr); - asm volatile("movb %1,%%fs:%0" : "+m" (*ptr) : "qi" (v)); + *(__seg_fs u8 *)(__force addr_t)absolute_pointer(addr) =3D v; } static inline void wrfs16(u16 v, addr_t addr) { - u16 *ptr =3D (u16 *)absolute_pointer(addr); - asm volatile("movw %1,%%fs:%0" : "+m" (*ptr) : "ri" (v)); + *(__seg_fs u16 *)(__force addr_t)absolute_pointer(addr) =3D v; } static inline void wrfs32(u32 v, addr_t addr) { - u32 *ptr =3D (u32 *)absolute_pointer(addr); - asm volatile("movl %1,%%fs:%0" : "+m" (*ptr) : "ri" (v)); + *(__seg_fs u32 *)(__force addr_t)absolute_pointer(addr) =3D v; } =20 static inline u8 rdgs8(addr_t addr) { - u8 *ptr =3D (u8 *)absolute_pointer(addr); - u8 v; - asm volatile("movb %%gs:%1,%0" : "=3Dq" (v) : "m" (*ptr)); - return v; + return *(__seg_gs u8 *)(__force addr_t)absolute_pointer(addr); } static inline u16 rdgs16(addr_t addr) { - u16 *ptr =3D (u16 *)absolute_pointer(addr); - u16 v; - asm volatile("movw %%gs:%1,%0" : "=3Dr" (v) : "m" (*ptr)); - return v; + return *(__seg_gs u16 *)(__force addr_t)absolute_pointer(addr); } static inline u32 rdgs32(addr_t addr) { - u32 *ptr =3D (u32 *)absolute_pointer(addr); - u32 v; - asm volatile("movl %%gs:%1,%0" : "=3Dr" (v) : "m" (*ptr)); - return v; + return *(__seg_gs u32 *)(__force addr_t)absolute_pointer(addr); } =20 static inline void wrgs8(u8 v, addr_t addr) { - u8 *ptr =3D (u8 *)absolute_pointer(addr); - asm volatile("movb %1,%%gs:%0" : "+m" (*ptr) : "qi" (v)); + *(__seg_gs u8 *)(__force addr_t)absolute_pointer(addr) =3D v; } static inline void wrgs16(u16 v, addr_t addr) { - u16 *ptr =3D (u16 *)absolute_pointer(addr); - asm volatile("movw %1,%%gs:%0" : "+m" (*ptr) : "ri" (v)); + *(__seg_gs u16 *)(__force addr_t)absolute_pointer(addr) =3D v; } static inline void wrgs32(u32 v, addr_t addr) { - u32 *ptr =3D (u32 *)absolute_pointer(addr); - asm volatile("movl %1,%%gs:%0" : "+m" (*ptr) : "ri" (v)); + *(__seg_gs u32 *)(__force addr_t)absolute_pointer(addr) =3D v; } =20 /* Note: these only return true/false, not a signed return value! */ @@ -156,14 +132,16 @@ static inline bool memcmp_fs(const void *s1, addr_t s= 2, size_t len) { bool diff; asm volatile("fs repe cmpsb" - : "=3D@ccnz" (diff), "+D" (s1), "+S" (s2), "+c" (len)); + : "=3D@ccnz" (diff), "+D" (s1), "+S" (s2), "+c" (len) + : : "memory"); return diff; } static inline bool memcmp_gs(const void *s1, addr_t s2, size_t len) { bool diff; asm volatile("gs repe cmpsb" - : "=3D@ccnz" (diff), "+D" (s1), "+S" (s2), "+c" (len)); + : "=3D@ccnz" (diff), "+D" (s1), "+S" (s2), "+c" (len) + : : "memory"); return diff; } =20 --=20 2.52.0 From nobody Sat Feb 7 16:39:27 2026 Received: from mail-ed1-f67.google.com (mail-ed1-f67.google.com [209.85.208.67]) (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 947E634D3BE for ; Tue, 23 Dec 2025 20:20:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.67 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766521254; cv=none; b=bhP2m0sO8JE5lVRWqzxoMHDKat17aGcxd1KpTuBBkKSDXx3EV4ie/D26Nokk25JaWTb8HBkoBJxeoPcO1BTm3d3M+WRxaL9afKT0xqve/Vjl6kd/uFHFFfkMQNG5xfXE6N3FqK8t+YcK3Mw/XR0VeDnY9GzZk0xDEzuAsEud9Tk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766521254; c=relaxed/simple; bh=ms1zZeiQfEjd3f4G2q7OYjPMPVH6vxabg3pLiE8b8uM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZxDaBiuq850xfWZ7UAAVz0TzfdioivYj7EiXkpMK2mhjIavR8EeyaHcXoJFDmtHo29zK9VtpQIRFo4pg6zW0zzd1FMRAy+pFhPSTEhFoquvPrBUGXQ5lVecdKyu2XRtworKX5sKOMBVnI+H5FONKG4/kXfKV6C2pRVj7bHJWtR8= 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=jkNu26KJ; arc=none smtp.client-ip=209.85.208.67 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="jkNu26KJ" Received: by mail-ed1-f67.google.com with SMTP id 4fb4d7f45d1cf-64b61f82b5fso7020605a12.0 for ; Tue, 23 Dec 2025 12:20:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766521250; x=1767126050; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=na9YxYYO7P8v4DQcfqJUIioved/R6y06CaLpOWA32xk=; b=jkNu26KJfXxUuvcZDt9WDtFWLpiptZH0hjRToK0QPFjJ9/P0+xY/1Vj2tKmKhf0hTK 6wV4ZOrvZ9DE/NdTE/rBlZRUedk8ukiyCLju2i9FTHJ4bIHReCnEdujLawlEWjyJot1o L4VaBv+w5pZwF7J9WudkIBwAbcMKLelHZKADMHjmALXQa6ynKVBvYQycngiPPWP1q30H ar97rzefcffbdRlkWgySup3/gDga19CG8VHC680Kx2swENCgujgURPIwh+Z1fv/uui5L HOFBltFChDjpiBHd8athsyowj0//Unp/h/HOCxZTy1pNRvwVQBQxBfKIHLOdcZzN4zPN DwsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766521250; x=1767126050; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=na9YxYYO7P8v4DQcfqJUIioved/R6y06CaLpOWA32xk=; b=N/ow7I3fMGD07Avd6kVKcBPtHGwoOSRzwJeE04hN1COLy7BPjwxnOEYrSP43ACAs/N Q8yRbev/cNxekmdozhjhlwc+eFhzTYr1np45zRDy3KldGUt7jLIIWeo1OedoC7shPwxk l3Hbq4sYUUsc/TkOun4RNvEznKL0sE7ah12nnuwcOCSqc75a5arGpoTfV4kXBveOEn+E BEQsmiHhC9ms5E6hUUgXfx9lNl7h1qN8dNvdGaNpKqx7Yg9L4npRudz95t1fuM7ioq9t m60baw4TsmlgRtYxj1T8n8fBjYYT6QGYUpkYEAVZgiWV2/8ZW8ItV1lXhB44MZjBX0bm 7PCg== X-Forwarded-Encrypted: i=1; AJvYcCXSJT3ovDsPyPVy0q6zghdnFneUYOT9351QhaKHALHIo82SVh3/x1zllEfzZBRuEhXuXNCWta7J5/wlHaQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxPgylrDJD9BbS+1sO/4Q477QAWqyC8e5blX8WkwmFmaLYNSGRB G4y+VfKPXbaizfIX/Bs/mI9wNo43Qu7aJq4423/HG7As2AB2+afDW6Ef X-Gm-Gg: AY/fxX4Jm/FHkEean+MWN51foy5jPX7Z2AiYk/DRanki1Ac9YGO04HMIBshlni7IVxH wF3v5ojKYofck5dZ9xgAU/hOg4YF+g+fll8O5IohlR0kkHNf0sTkBrJEIOEnwahbiHKi+Z142s4 8XuWeH+zSgn2ZChI5IaHqVyMT90wKJterADGcCmdtJoV23GgJQ1DZUlhNc6kTFsT0h/q0o70Sw/ 8ipGZthaQGvMhe5giYOHFjouDh4XIHU1mNaB2VTR1621oapY4Pfe+gXi52L1SLjJtumv7Nuk02b OardeXg30onDZen5UbVFPMJ5FeGMdaE06qFYusnTwAWc0MhvTer46Zk0XjHLH9TNBFo1v+CN+FZ IiavvcBdKQwZ23+8au+cLo2n+WhxwpPqaWsdtD00aaTh0VIj6xn4hOQ6EX3ppZ9oKOo5It6sBt/ IH3RY+yIodtxBE+dFiFutRGL0h69Dr1NR0LRV7X2pTGUgBACj6sKM6DQ== X-Google-Smtp-Source: AGHT+IEHHthUaSRWAxw10vJbbtOB2NNqYykQoeuSuWcza8ElwBqfBfecJqUti/qYyZ0k+9X4qoKS5w== X-Received: by 2002:a17:907:94cf:b0:b7d:1a23:81a0 with SMTP id a640c23a62f3a-b8037297276mr1426200466b.63.1766521249655; Tue, 23 Dec 2025 12:20:49 -0800 (PST) Received: from fedora ([46.248.82.114]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-64b91599844sm14707177a12.25.2025.12.23.12.20.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Dec 2025 12:20:48 -0800 (PST) From: Uros Bizjak To: x86@kernel.org, linux-kernel@vger.kernel.org Cc: Uros Bizjak , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" Subject: [PATCH 2/3] x86/boot: disable GCC min-pagesize assumption in boot code Date: Tue, 23 Dec 2025 21:18:57 +0100 Message-ID: <20251223202038.91200-3-ubizjak@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251223202038.91200-1-ubizjak@gmail.com> References: <20251223202038.91200-1-ubizjak@gmail.com> 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 GCC treats absolute addresses smaller than min-pagesize param (defaulting to 4kB) as assumed results of pointer arithmetics from NULL. The following code, when compiled with -O2 -Warray-bounds (included in -Wall): int foo (void) { return *(int *)0x123; } will emit a rather cryptic warning: warning: array subscript 0 is outside array bounds of =E2=80=98int[0]=E2=80= =99 [-Warray-bounds=3D] 1 | int foo (void) { return *(int *)0x123; } | ^~~~~~~~~~~~~ cc1: note: source object is likely at address zero Currently, the warning is supressed by the GCC specific RELOC_HIDE() macro that obfuscates arithmetic on a variable address so that GCC doesn't recognize the original var, and make assumptions about it. The GCC specific RELOC_HIDE() macro was introduced to work around certain ppc64 specific compiler bug in pre-4.1 GCC. This bug was fixed long ago, and replacing GCC specific macro with a generic one triggers the above warning in copy_boot_params(). The early boot environment does not guarantee any minimum page size, so explicitly setting the minimum page size to zero by adding --param=3Dmin-pagesize=3D0 to the compiler flags when building the x86 boot code with GCC inhibits warnings for addresses below 4kB. The option is guarded by CONFIG_CC_IS_GCC since it is GCC-specific. No functional changes intended. Signed-off-by: Uros Bizjak Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: "H. Peter Anvin" --- arch/x86/boot/Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile index 3f9fb3698d66..372e67d2a855 100644 --- a/arch/x86/boot/Makefile +++ b/arch/x86/boot/Makefile @@ -55,6 +55,9 @@ KBUILD_CFLAGS :=3D $(REALMODE_CFLAGS) -D_SETUP KBUILD_AFLAGS :=3D $(KBUILD_CFLAGS) -D__ASSEMBLY__ KBUILD_CFLAGS +=3D -fno-asynchronous-unwind-tables KBUILD_CFLAGS +=3D $(CONFIG_CC_IMPLICIT_FALLTHROUGH) +ifdef CONFIG_CC_IS_GCC +KBUILD_CFLAGS +=3D $(call cc-option,--param=3Dmin-pagesize=3D0) +endif =20 $(obj)/bzImage: asflags-y :=3D $(SVGA_MODE) =20 --=20 2.52.0 From nobody Sat Feb 7 16:39:27 2026 Received: from mail-ed1-f52.google.com (mail-ed1-f52.google.com [209.85.208.52]) (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 CFB7B34F49B for ; Tue, 23 Dec 2025 20:20:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766521256; cv=none; b=WQr9RvSJx3Jv0GtARdco3+cigXryA+6ke8qEBUnNrzX7oCxIkCh7MAoG76i37wycDDjD72tfTwhwAEavVNA89W5vbQ4+wepTFopTTClmpagqCIEk8b42Vr7aUPbSp6OLGAqbLPzntlq+jNf4N3XLiymSRzCXk6BLlIbh8wukQYQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766521256; c=relaxed/simple; bh=Fap4dzvqS7aEWoYiTrUtxE9+Mc6X0pvPwNckvkCiCSM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Hx2gcoeRTVhK7r+b6bwvFqQ0LGutkzzmCa6EP+f0+wFC2TuZVOCmAA3/6ZdNb85HPD7Cye+A1FJP5ejy1Kv9u8uKHSrQuIaCbk2W7jKm6AgscJLuauQI96irq+2OspXGEYotIKzeWgvK0SnptSXWSw/V2OOWVsc3r2C2pU7qNcA= 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=eI7tg6om; arc=none smtp.client-ip=209.85.208.52 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="eI7tg6om" Received: by mail-ed1-f52.google.com with SMTP id 4fb4d7f45d1cf-64d2c50f0d6so4214881a12.3 for ; Tue, 23 Dec 2025 12:20:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766521252; x=1767126052; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=QRGzBsOiCH2SoWHbAYqLbD7CkoVm8aBS7G/P/WUjHt4=; b=eI7tg6omN5WLkbFNK7AHjXJoJdv300QeOLQCet2wJ9m/2OeyXHYYw86llhVFaIsSsN UBmiOof72u4vbDx7viLxgQvBWW0I+kk31AM3GMd5wvhXM8nnwK61W1vGxbuurlzGEK+Z kLr7KboNp0uNHbDIRMn9fHxscvK9bweBYu5GKd1gwgqZZOT8leFPop0PNBuTEEloaU5q 0K/EDin7Km0u+PptLDLk/VZe+DKNjVde9wyCt2/fTF5qChptu0f0uxkX7QVBaRI6/sBr lvCkYxwOewRnxHawBkyM//Z+OfTN7QZK8TKD1j7FCvr/jiwdA1nk3/I+JQa3aRDpQYIT Y3Rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766521252; x=1767126052; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=QRGzBsOiCH2SoWHbAYqLbD7CkoVm8aBS7G/P/WUjHt4=; b=d0tMpbwXRJcwBPDdGGFqsWabTNWzvECdBDH0WdC9RXT7FJdjXL1Cadi6wOdPfLN0Z3 MpPn2i/Dj/0qqL9x81muxUflAc54DWnOPphacx2dGdgCOgxD4pYyE2Jvx6JNMPRnufhF kE3W7yPI3LgAyn91IgMUNJaZLtegZroTnPPoaiwDCZvrFoGSRlT1kNdQcrEIHxbvesld pN6q9wbPU4F3oSySpVdiG+AXQCZiKoWB0Ot+Z1Wmzxw80hIWc4QwkWB0Ji69/jVpBUh6 xBkV+j//MMJfa7YZ1uRkR+Z86ZFEtst4+M3Ybba7lvtOZrMJTjtHdmmTg0+V6Matk3lb 2Wyg== X-Forwarded-Encrypted: i=1; AJvYcCXjyyJBJcWK/mXfWeRl3drKStEMZvgiXiOznRnV3HFHX1dEA5PjfGLXUetI3zjOCdhHVgXxxswgEqxThDE=@vger.kernel.org X-Gm-Message-State: AOJu0YwfnfscZXbY9oDS/nUdh8UySt0V4gkZC+HNNKPjhVWUYPGdQlIj SZO4fhScZ2vFVOGh75+85pxnAr496y3uYMN+sqP/FQeHPUJcookozmG7 X-Gm-Gg: AY/fxX7YGmL9iLQznXSDenhWVQQWizibRdqn/eeACQzmvb9FVBOIVLI9DDBd2klJ00j nZ6JKhXP70sVG6yjKbQjQuISH31+YCiK23VgLYnoLTLzv72u20vqozywk7uugpF6xW5ypRG/Zft 44N9+WaJ6BwvKpovyOWCsPomDgu/8ouMuEdkdKnB8JdqeD/kKEwoOrTpciCEBDSNzJcPN3bqaiY igs/EMEJFzE7Wi6e2/Jl5jOKaHLV2MEmvbgZlawcdHcbRsYAFG+L+9CvHkUeK1IRyhX+e6jFQMx GrSCUIkIbx/2RRGKkIEKgLRFNFxRUOHsAdADAA8id3hM0jZtcIzegJFG18T/qpTMZ/8A8ITPJuw qwls0iHJMd5rkpp/N7U1yiBf0Wmc3t8kjQ1uO8STXAyeAWuO2k/LG5hlGIX3GPZ8nFdLgd1MqjB TwjinpyTCrLiOQjF2KFhP6GVe48FxbZFRqk3D/O9BzKp8= X-Google-Smtp-Source: AGHT+IETyWd+uT3WCjL/DyttBZRJAT99br/qspYA0txF59SLkKiZWJb7hHjhjTN3fmgqw5g/71IorA== X-Received: by 2002:a05:6402:2685:b0:64b:5c4e:e695 with SMTP id 4fb4d7f45d1cf-64b8edbb83cmr12564298a12.29.1766521251541; Tue, 23 Dec 2025 12:20:51 -0800 (PST) Received: from fedora ([46.248.82.114]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-64b91599844sm14707177a12.25.2025.12.23.12.20.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Dec 2025 12:20:50 -0800 (PST) From: Uros Bizjak To: x86@kernel.org, linux-kernel@vger.kernel.org Cc: Uros Bizjak , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Linus Torvalds Subject: [PATCH 3/3] compiler-gcc: Remove obsolete RELOC_HIDE() macro Date: Tue, 23 Dec 2025 21:18:58 +0100 Message-ID: <20251223202038.91200-4-ubizjak@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251223202038.91200-1-ubizjak@gmail.com> References: <20251223202038.91200-1-ubizjak@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Remove the RELOC_HIDE() macro from include/linux/compiler-gcc.h. The GCC specific macro was historically used to workaround very old compiler bugs (including pre-4.1 ppc64 GCC). These compilers are long obsolete. The generic RELOC_HIDE() macro should be used instead. The removal of the GCC specific macro results in the following code size reduction: text data bss dec hex filename 28526453 4823511 737108 34087072 20820a0 vmlinux-old.o 28520945 4823463 737108 34081516 2080aec vmlinux-new.o ./bloat-o-meter vmlinux-old.o vmlinux-new.o add/remove: 4/14 grow/shrink: 189/674 up/down: 4433/-7865 (-3432) ... Total: Before=3D24103512, After=3D24100080, chg -0.01% Signed-off-by: Uros Bizjak Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: "H. Peter Anvin" Cc: Linus Torvalds --- include/linux/compiler-gcc.h | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h index 5de824a0b3d7..081e658754b9 100644 --- a/include/linux/compiler-gcc.h +++ b/include/linux/compiler-gcc.h @@ -10,31 +10,6 @@ + __GNUC_MINOR__ * 100 \ + __GNUC_PATCHLEVEL__) =20 -/* - * This macro obfuscates arithmetic on a variable address so that gcc - * shouldn't recognize the original var, and make assumptions about it. - * - * This is needed because the C standard makes it undefined to do - * pointer arithmetic on "objects" outside their boundaries and the - * gcc optimizers assume this is the case. In particular they - * assume such arithmetic does not wrap. - * - * A miscompilation has been observed because of this on PPC. - * To work around it we hide the relationship of the pointer and the object - * using this macro. - * - * Versions of the ppc64 compiler before 4.1 had a bug where use of - * RELOC_HIDE could trash r30. The bug can be worked around by changing - * the inline assembly constraint from =3Dg to =3Dr, in this particular - * case either is valid. - */ -#define RELOC_HIDE(ptr, off) \ -({ \ - unsigned long __ptr; \ - __asm__ ("" : "=3Dr"(__ptr) : "0"(ptr)); \ - (typeof(ptr)) (__ptr + (off)); \ -}) - #if defined(LATENT_ENTROPY_PLUGIN) && !defined(__CHECKER__) #define __latent_entropy __attribute__((latent_entropy)) #endif --=20 2.52.0