From nobody Wed Dec 17 08:56:37 2025 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 5F3A62E092A for ; Thu, 16 Oct 2025 20:51:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760647903; cv=none; b=THNjI4bfampLDw5eaizDFavv+ik7XLXxbCsJhFV3KeUCQskgJcNTRdRB8YDydiLf/1WC1XYzxGI9JdKXpBXCZQgAoUQmfOTD/KBgJ9WdVYE96H/1yvm3VYqRKoXe0uJKwY4UQ/ExnON2I2k79D3InL+yIThKKygd82Zvx8n/wwM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760647903; c=relaxed/simple; bh=dliEiqiTMvqs0IcfBNZb5LeQ61wchQuC1RPqs6mcWkQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=jahZNJr6juA4+hUqRwp0Y/+29zfLhy/I/ZOp/iwGPS1wyWnOTPLnPDmMwKVhoIMbtuXTd8oJW7LfjJJaQfztt8FGo+Or17svHpXd8MbEd2PPVawfVkaKkCOJX7EUFVyOcq7Jl+YdG0oUXncgkhAOiRhbVpPvLGk3B3y3F536Az0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=gTg5bc8a; arc=none smtp.client-ip=209.85.216.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="gTg5bc8a" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-32ee157b9c9so1099135a91.2 for ; Thu, 16 Oct 2025 13:51:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1760647902; x=1761252702; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=oxkK/QQ7vt0zUL78WAYEZhyuB+OQo5aAup2L7Jq9TRw=; b=gTg5bc8aLGe/5TST+JAJ0W7CaxulbaqtS7Hql4i4OvwEM+Gle8G+c3Wuf2PTzS3slp ASyYfsdxmOkakRRVQIKCf0n9tty1VEPehXCk7DYV9nzkzjoho+6NPm4nDllTGyW8k/Ga JarDtqeWtNjTKEc7+Pqtw2ycDoaHCoIfP3M23N43FMeJkEepsUj/72US2f1YjPK5JN7T XX/ATGgB33/CQIKkfe1Qp9UVdJYWCg5k+yttP1QKY0DF/qwYonqnMOgZ2qYOkhVnTN1u 4UCGCLkm/9IBD/mtodLkfCj+rca+FvdNCYvv6t2bapM5x5kFytW28xs/ipcviMmNs7PI YoJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760647902; x=1761252702; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=oxkK/QQ7vt0zUL78WAYEZhyuB+OQo5aAup2L7Jq9TRw=; b=wHl2DYob1pbVSgth7ePoyYLfAcozUkkNjbUxlGgG5Cg27RskTpcJ24M0aF5lR2CGix pRj+RCSAfCvPFah/L9e0I7TiPRrQcAHiQwzJRUebCsr2Hm7wJIu70Ov14pp3MqP/UzRW GZpKFLyLRMIuwY7fKUqqEPx5nAPQCtMwhnkIXHk4Vmo7tKRfIriV9vUateGTQXDb0LG4 z3bqDKFtlc7bEYXDovFcZpN1Ihtbr3s08WwZnTYY+taBwMpfcS9CkYpuFViFPkcIeBSP hGiVBVvMbuRZrE8TxulSDCk3FrZDb/6Gi8KHw31H2XQ2ch5NSckK38MtuR1VlK6j6VIZ ytZQ== X-Forwarded-Encrypted: i=1; AJvYcCXjbyCDuBbqBeS6sEZJGxdSFahI1yvfa437kkfxcNSCd+3I05pEWuA5/QLrejQbOnPkbNoX2nbpHnfS55Q=@vger.kernel.org X-Gm-Message-State: AOJu0Yy8frEqn2NYeoUEKaooh3szFXP3ou+JWKfoCyEohfWbHpIZnZWj Tz6Y4HJb8rBuV1bqbVCw1duTonbIqX/U6pj+3sGTSTI5DIBrU3bfkgefrnVIQZ42LF146gZ7hso hSku+9cXhVA== X-Google-Smtp-Source: AGHT+IHX6jzTaUBGdzq/jMSrKjZ3i8b5Eknbvm6Eiw9NU7XO1EnAB15c1MZGsKcSU2etha5Z+4McyObiisOy X-Received: from pjboh7.prod.google.com ([2002:a17:90b:3a47:b0:332:8246:26ae]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90a:e70d:b0:330:9c0b:5494 with SMTP id 98e67ed59e1d1-33bcf8e94f2mr1274322a91.22.1760647901813; Thu, 16 Oct 2025 13:51:41 -0700 (PDT) Date: Thu, 16 Oct 2025 13:51:23 -0700 In-Reply-To: <20251016205126.2882625-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251016205126.2882625-1-irogers@google.com> X-Mailer: git-send-email 2.51.0.858.gf9c4a03a3a-goog Message-ID: <20251016205126.2882625-2-irogers@google.com> Subject: [PATCH v5 1/4] parisc: Inline a type punning version of get_unaligned_le32 From: Ian Rogers To: "James E.J. Bottomley" , Helge Deller , Andy Lutomirski , Thomas Gleixner , Vincenzo Frascino , Ian Rogers , Arnaldo Carvalho de Melo , linux-parisc@vger.kernel.org, linux-kernel@vger.kernel.org, Eric Biggers , Al Viro , Christophe Leroy , "Jason A. Donenfeld" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Reading the byte/char output_len with get_unaligned_le32 can trigger compiler warnings due to the size read. Avoid these warnings by using type punning. This avoids issues when switching get_unaligned_t to __builtin_memcpy. Signed-off-by: Ian Rogers --- arch/parisc/boot/compressed/misc.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/arch/parisc/boot/compressed/misc.c b/arch/parisc/boot/compress= ed/misc.c index 9c83bd06ef15..111f267230a1 100644 --- a/arch/parisc/boot/compressed/misc.c +++ b/arch/parisc/boot/compressed/misc.c @@ -278,6 +278,19 @@ static void parse_elf(void *output) free(phdrs); } =20 +/* + * The regular get_unaligned_le32 uses __builtin_memcpy which can trigger + * warnings when reading a byte/char output_len as an integer, as the size= of a + * char is less than that of an integer. Use type punning and the packed + * attribute, which requires -fno-strict-aliasing, to work around the prob= lem. + */ +static u32 punned_get_unaligned_le32(const void *p) +{ + const struct { __le32 x; } __packed * __get_pptr =3D p; + + return le32_to_cpu(__get_pptr->x); +} + asmlinkage unsigned long __visible decompress_kernel(unsigned int started_= wide, unsigned int command_line, const unsigned int rd_start, @@ -309,7 +322,7 @@ asmlinkage unsigned long __visible decompress_kernel(un= signed int started_wide, * leave 2 MB for the stack. */ vmlinux_addr =3D (unsigned long) &_ebss + 2*1024*1024; - vmlinux_len =3D get_unaligned_le32(&output_len); + vmlinux_len =3D punned_get_unaligned_le32(&output_len); output =3D (char *) vmlinux_addr; =20 /* --=20 2.51.0.858.gf9c4a03a3a-goog From nobody Wed Dec 17 08:56:37 2025 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (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 A0D032E22AB for ; Thu, 16 Oct 2025 20:51:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760647906; cv=none; b=Bh0XJWiuBCpqSgBicQ3MEMTnVBK3UyeqzINYHuAbunvlV5E82WTYRM97ycPiApvLXVcvKr10uHZQHmzrC4eg/ZabxIkCRK6Ehc3dYZn3hOHyF/cdGCWoDSvri8fcAwJnrW3kGVZfqMHvrPXMsuhcw3omOav9rRiX2qvzOUlx6UA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760647906; c=relaxed/simple; bh=nVrSvzPztuXGClDcdMqXs9xM3Seb6JCG22hS9qvNjdA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=Qlryeu8mGjRd1BDTALXuN/aD0Y07NT/uaKpHFZb1a2QwQaHROE5IsGfC3MkT1c+8bpGcPe4gG7XAsA0r7MXn8Q+xLIEtuB5mPXD56rqxCa0FBG8etG5aG+5Ht4PCdqyKwzkCNG5fkP2M55kl3BQFKjKawGXen9A3l+MoppsFLbU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=YgAgpFsr; arc=none smtp.client-ip=209.85.214.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="YgAgpFsr" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-27ee41e062cso17333775ad.1 for ; Thu, 16 Oct 2025 13:51:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1760647904; x=1761252704; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=BAIMGYoqbISny2vRErUw0qxGyMwV616xJj8ghqmGSR0=; b=YgAgpFsr7DuYTEPj1mC2sURger/hsf+DwRhYAci96wvFfCM/eDp31lTwSYdlSmbVZv 8JYtZylr/du8IH6rU9Ek9etUZMTlzeaHVFqRC3HII/sHcksXVaWQCk2MIyik2ZHJ5K1t z1RoazTT6M4C6qFrrs0lvso/3LrmRkSE9HAk7q2L0CQvye4RPF66wqsom9bGEYlQtxkD XFJGZlgtDxXCLIuMBTcL7u2W+pF29SpPUOfcp9vkTbM0oCvySonVNjq0CQIxclCq5UKQ 2Jb3cXdBfam5HXeDyn7jNXS4xTFVtyKiJyXW5YqOELpQ1hB6bgtOwxx9BniCU3ApgI65 uvOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760647904; x=1761252704; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=BAIMGYoqbISny2vRErUw0qxGyMwV616xJj8ghqmGSR0=; b=HDN2gwNozEkPAwJ38c9xrNgOf9QJOhjSR55DJ8qbkr6dKqdGrI80HgpkJ8X+eppPjr DKOjlTVM98Thzwe+g2phRnz+wSuqTvXZzXUQvFzFFcJ20h4am+0xjm/3nSYVtQrJ3kql H6BU9AhGydHRFg3YUQQHR4mrqvVw37hWhjempM/mltk/hw42z37Mootjm2UrGNghL9bM X45ETWHwmI0l22AfDMsQgJCM65pc4gkZrtdOLYSmUbJH27hb47p2mm1Oos3Vnk9yYEFy NmulD1HGUGcZhpGrHnNiQMMGH9Um3jfRr3c3yxA4tGJGJX8k4Bb+e/59zbMDS3btlX9B qOyw== X-Forwarded-Encrypted: i=1; AJvYcCVVMHHuYP2aqY6BTe1Kdk9zqixE0d4clMXMKgXK2B20jr+GybXejjz3QXof1rTH7Qx6+SaMjoSrAnaZsU8=@vger.kernel.org X-Gm-Message-State: AOJu0YxvRdBV1t+KeQlT+smwCzmaMdHhl6GV9JvqPAcdipB/zD3nDZHg xE4yYNZvxcHZkRCZKsoLN1loryzLk3JCKAobp0nVYe5RfqMZsE6i/S4gWxgHRsMT6KuX7X5AMve BMJUFh4OM9A== X-Google-Smtp-Source: AGHT+IG5RzQebXrGDbWsNPzFtRR2+5yK+xcRDPhguIs/MdSqdZRddPVVMtrRDsP/hpqzUccoN4arVYWrJvpY X-Received: from plko5.prod.google.com ([2002:a17:902:6b05:b0:25c:22e5:1a27]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:2b06:b0:272:f9c3:31fb with SMTP id d9443c01a7336-290cba4dbb5mr14771145ad.58.1760647903824; Thu, 16 Oct 2025 13:51:43 -0700 (PDT) Date: Thu, 16 Oct 2025 13:51:24 -0700 In-Reply-To: <20251016205126.2882625-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251016205126.2882625-1-irogers@google.com> X-Mailer: git-send-email 2.51.0.858.gf9c4a03a3a-goog Message-ID: <20251016205126.2882625-3-irogers@google.com> Subject: [PATCH v5 2/4] vdso: Switch get/put unaligned from packed struct to memcpy From: Ian Rogers To: "James E.J. Bottomley" , Helge Deller , Andy Lutomirski , Thomas Gleixner , Vincenzo Frascino , Ian Rogers , Arnaldo Carvalho de Melo , linux-parisc@vger.kernel.org, linux-kernel@vger.kernel.org, Eric Biggers , Al Viro , Christophe Leroy , "Jason A. Donenfeld" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Type punning is necessary for get/put unaligned but the use of a packed struct violates strict aliasing rules, requiring -fno-strict-aliasing to be passed to the C compiler. Switch to using memcpy so that -fno-strict-aliasing isn't necessary. Signed-off-by: Ian Rogers --- include/vdso/unaligned.h | 41 ++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/include/vdso/unaligned.h b/include/vdso/unaligned.h index ff0c06b6513e..9076483c9fbb 100644 --- a/include/vdso/unaligned.h +++ b/include/vdso/unaligned.h @@ -2,14 +2,43 @@ #ifndef __VDSO_UNALIGNED_H #define __VDSO_UNALIGNED_H =20 -#define __get_unaligned_t(type, ptr) ({ \ - const struct { type x; } __packed * __get_pptr =3D (typeof(__get_pptr))(p= tr); \ - __get_pptr->x; \ +#include + +/** + * __get_unaligned_t - read an unaligned value from memory. + * @type: the type to load from the pointer. + * @ptr: the pointer to load from. + * + * Use memcpy to affect an unaligned type sized load avoiding undefined be= havior + * from approaches like type punning that require -fno-strict-aliasing in = order + * to be correct. As type may be const, use __unqual_scalar_typeof to map = to a + * non-const type - you can't memcpy into a const type. The + * __get_unaligned_ctrl_type gives __unqual_scalar_typeof its required + * expression rather than type, a pointer is used to avoid warnings about = mixing + * the use of 0 and NULL. The void* cast silences ubsan warnings. + */ +#define __get_unaligned_t(type, ptr) ({ \ + type *__get_unaligned_ctrl_type __always_unused =3D NULL; \ + __unqual_scalar_typeof(*__get_unaligned_ctrl_type) __get_unaligned_val; \ + __builtin_memcpy(&__get_unaligned_val, (void *)(ptr), \ + sizeof(__get_unaligned_val)); \ + __get_unaligned_val; \ }) =20 -#define __put_unaligned_t(type, val, ptr) do { \ - struct { type x; } __packed * __put_pptr =3D (typeof(__put_pptr))(ptr); \ - __put_pptr->x =3D (val); \ +/** + * __put_unaligned_t - write an unaligned value to memory. + * @type: the type of the value to store. + * @val: the value to store. + * @ptr: the pointer to store to. + * + * Use memcpy to affect an unaligned type sized store avoiding undefined + * behavior from approaches like type punning that require -fno-strict-ali= asing + * in order to be correct. The void* cast silences ubsan warnings. + */ +#define __put_unaligned_t(type, val, ptr) do { \ + type __put_unaligned_val =3D (val); \ + __builtin_memcpy((void *)(ptr), &__put_unaligned_val, \ + sizeof(__put_unaligned_val)); \ } while (0) =20 #endif /* __VDSO_UNALIGNED_H */ --=20 2.51.0.858.gf9c4a03a3a-goog From nobody Wed Dec 17 08:56:37 2025 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (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 397BE2E3B1C for ; Thu, 16 Oct 2025 20:51:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760647907; cv=none; b=oVqw65Qt//2CBdGZd+7udo+E3ehf0R8UzQ1X2oBZBddK4plmgZX5lL3Qj06c46gedhaZCRK4XD4JHVyUYLF/NPHG4qbzmrl2DmPWKmvoV4jmohyFFfVCAce9jrvR00U28CiHFfTfUJq6a/rbEtxZJso8b97IeaOzvEvPZ9p9vPw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760647907; c=relaxed/simple; bh=UvfqvuNzNaKuTenaXI68Nt5jBlIoumMb2oUSP1fRCMU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=KkuNxes5uaOaSJg+2nkq7xtwSXikd7+Hs2l07hYPW/Vdqf6LFP6DnZ7rcf5UB+2mSy7GVCsxJaJpfJFFTNEE1dkgfDWck9pWAHkJD+nyKFqu7TIVx3tSY478NSgypD9+SHqt/ve4Ltn/wlKTSDZNYQKIWGgBNJYJSALJiZODHEA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=QGGWIWh+; arc=none smtp.client-ip=209.85.210.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="QGGWIWh+" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-77f64c5cf62so994643b3a.2 for ; Thu, 16 Oct 2025 13:51:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1760647905; x=1761252705; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=Op/cgLXnfaBM2beLrTOCrg+8NoqMY5HOv5BplNGP7NA=; b=QGGWIWh+pnserlzUrxPH4BA+m7NV4XzFYkbMzNIguxIBTuEC/tRd98BjX9PCWc/Om6 HV+6qTn0ePEULdSZbenN2jrWAVNrfO8STKHC1zYhGONz/topHXlF1ZL8sJPawIUUinF8 U7J+pSaWyOqglKc9VWDoZF+BRqVpbNVJ7QLQSRBTnOareu5SaM9cVmsnWuhnad31xj/j SFoqC09DvrgydNg+GlvzqX2S7uAOmGv6GerOqu3aHSDNwZXEH0ZcS+M2lgca3QAeZuju Hs9UrjLZLBplEFRbtv7CN9oWDwXcw0swWBVk27OiCfuGFNU4sxxzetxcnw2MVURyJ34t aNFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760647905; x=1761252705; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Op/cgLXnfaBM2beLrTOCrg+8NoqMY5HOv5BplNGP7NA=; b=pXEm74jj4N+miU29s3quufCMR9TG7glaAuAX/VHH69LxRFT6p8a7tObBnAbH5lFBAw JSewovxIprvCR94LcXtjDPanx1fiCLcetR5AdaESzLGehxXPox1cUGMxM6lWMTvMYgx5 F6+OeGFod6Zhv6Xdc/Ica0M4G6VoZc/RlwVZwSfXQVUz4LZvMKI+Xa3PyrT+EpYVKPKw WseVxjLbCHUvczXVwO/PO90czxVpUr5pbSUFAaVNttZUNCZ3UbLgdLVPtRgguYSnNSpT mx5cKGMdcZRBPhRdpwG1gZxpXgeoOZyephfgauDISapOaJvUnMBxeuXJ0EubSRDkmbQF NbHA== X-Forwarded-Encrypted: i=1; AJvYcCV5+ihA+D7eukRMiXesi4emsX8UWL15chpd07TIizxROlDcXYt0nkMbhPF28m9pfsPOSP1tOsDUtiE8OfM=@vger.kernel.org X-Gm-Message-State: AOJu0YwbKHDV5/XSfIDYSoMOXjo3Jqkn/moThRD+YzRBeCfq+CVM4k8l l9u3FFW2qPFSlVkw02/qzqcE7xdWMen+CCKwJiWzx2XF+E82okRtrp+2HKsnmIpyajV8cpLg7Pu O7Za1RD7wCA== X-Google-Smtp-Source: AGHT+IGUbpSBAQlWWqITv9bif+XWoD3GdrHFfDFRJdD4RE9Dd+y5C2qTC2uRnG+u/NrbClKTgiG4ImAur+pN X-Received: from pgip24.prod.google.com ([2002:a63:c158:0:b0:b54:fd1f:ef57]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:72a4:b0:334:974b:6e0f with SMTP id adf61e73a8af0-334a86256c3mr1836298637.40.1760647905615; Thu, 16 Oct 2025 13:51:45 -0700 (PDT) Date: Thu, 16 Oct 2025 13:51:25 -0700 In-Reply-To: <20251016205126.2882625-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251016205126.2882625-1-irogers@google.com> X-Mailer: git-send-email 2.51.0.858.gf9c4a03a3a-goog Message-ID: <20251016205126.2882625-4-irogers@google.com> Subject: [PATCH v5 3/4] tools headers: Update the linux/unaligned.h copy with the kernel sources From: Ian Rogers To: "James E.J. Bottomley" , Helge Deller , Andy Lutomirski , Thomas Gleixner , Vincenzo Frascino , Ian Rogers , Arnaldo Carvalho de Melo , linux-parisc@vger.kernel.org, linux-kernel@vger.kernel.org, Eric Biggers , Al Viro , Christophe Leroy , "Jason A. Donenfeld" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" To pick up the changes in: vdso: Switch get/put unaligned from packed struct to memcpy As the code is dependent on __unqual_scalar_typeof, update the tools version of compiler_types.h to include this. Signed-off-by: Ian Rogers --- tools/include/linux/compiler_types.h | 22 +++++++++++++++ tools/include/vdso/unaligned.h | 41 ++++++++++++++++++++++++---- 2 files changed, 57 insertions(+), 6 deletions(-) diff --git a/tools/include/linux/compiler_types.h b/tools/include/linux/com= piler_types.h index d09f9dc172a4..890982283a5e 100644 --- a/tools/include/linux/compiler_types.h +++ b/tools/include/linux/compiler_types.h @@ -40,4 +40,26 @@ #define asm_goto_output(x...) asm goto(x) #endif =20 +/* + * __unqual_scalar_typeof(x) - Declare an unqualified scalar type, leaving + * non-scalar types unchanged. + */ +/* + * Prefer C11 _Generic for better compile-times and simpler code. Note: 'c= har' + * is not type-compatible with 'signed char', and we define a separate cas= e. + */ +#define __scalar_type_to_expr_cases(type) \ + unsigned type: (unsigned type)0, \ + signed type: (signed type)0 + +#define __unqual_scalar_typeof(x) typeof( \ + _Generic((x), \ + char: (char)0, \ + __scalar_type_to_expr_cases(char), \ + __scalar_type_to_expr_cases(short), \ + __scalar_type_to_expr_cases(int), \ + __scalar_type_to_expr_cases(long), \ + __scalar_type_to_expr_cases(long long), \ + default: (x))) + #endif /* __LINUX_COMPILER_TYPES_H */ diff --git a/tools/include/vdso/unaligned.h b/tools/include/vdso/unaligned.h index ff0c06b6513e..9076483c9fbb 100644 --- a/tools/include/vdso/unaligned.h +++ b/tools/include/vdso/unaligned.h @@ -2,14 +2,43 @@ #ifndef __VDSO_UNALIGNED_H #define __VDSO_UNALIGNED_H =20 -#define __get_unaligned_t(type, ptr) ({ \ - const struct { type x; } __packed * __get_pptr =3D (typeof(__get_pptr))(p= tr); \ - __get_pptr->x; \ +#include + +/** + * __get_unaligned_t - read an unaligned value from memory. + * @type: the type to load from the pointer. + * @ptr: the pointer to load from. + * + * Use memcpy to affect an unaligned type sized load avoiding undefined be= havior + * from approaches like type punning that require -fno-strict-aliasing in = order + * to be correct. As type may be const, use __unqual_scalar_typeof to map = to a + * non-const type - you can't memcpy into a const type. The + * __get_unaligned_ctrl_type gives __unqual_scalar_typeof its required + * expression rather than type, a pointer is used to avoid warnings about = mixing + * the use of 0 and NULL. The void* cast silences ubsan warnings. + */ +#define __get_unaligned_t(type, ptr) ({ \ + type *__get_unaligned_ctrl_type __always_unused =3D NULL; \ + __unqual_scalar_typeof(*__get_unaligned_ctrl_type) __get_unaligned_val; \ + __builtin_memcpy(&__get_unaligned_val, (void *)(ptr), \ + sizeof(__get_unaligned_val)); \ + __get_unaligned_val; \ }) =20 -#define __put_unaligned_t(type, val, ptr) do { \ - struct { type x; } __packed * __put_pptr =3D (typeof(__put_pptr))(ptr); \ - __put_pptr->x =3D (val); \ +/** + * __put_unaligned_t - write an unaligned value to memory. + * @type: the type of the value to store. + * @val: the value to store. + * @ptr: the pointer to store to. + * + * Use memcpy to affect an unaligned type sized store avoiding undefined + * behavior from approaches like type punning that require -fno-strict-ali= asing + * in order to be correct. The void* cast silences ubsan warnings. + */ +#define __put_unaligned_t(type, val, ptr) do { \ + type __put_unaligned_val =3D (val); \ + __builtin_memcpy((void *)(ptr), &__put_unaligned_val, \ + sizeof(__put_unaligned_val)); \ } while (0) =20 #endif /* __VDSO_UNALIGNED_H */ --=20 2.51.0.858.gf9c4a03a3a-goog From nobody Wed Dec 17 08:56:37 2025 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 D5BDE2E5418 for ; Thu, 16 Oct 2025 20:51:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760647909; cv=none; b=D4P4DWd3n9/HHapG6FOUHBkSCgj/XxtYPOXH3XKKbOm8Po4e7UuQFm8tFzFsc8+ThWCYGScHshAr2f1sHIhYz3lbNsfiDMsfck7mleVf7KxAB7T7bui8W4TKc5gu+8Cl9dBQBjdjkJAMweJtMAzUE1Hqctg6HAhQQbbqYKqmX3Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760647909; c=relaxed/simple; bh=ELYvw7ZAYoD/qvF4+0zHGfAH8XjqxESr5Bk1ckhjTsY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=uFwfidZFXk9yUE7qrP0kZK5o4WR+GJ+7i+EMoMhxQ6iPGhPiMB83COowCIwi+Lfu4ADGGLrDuboH82JUqWzFkchPE+B2A8rhcfBgF/o109hfFZCaNQI0XL5SSMj79V8kznrwngOn/OgXxKPsmxuOJ9u9nTwGCLUmf9Tt697dk08= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=N3WCvZeI; arc=none smtp.client-ip=209.85.216.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="N3WCvZeI" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-3324538ceb0so2085737a91.1 for ; Thu, 16 Oct 2025 13:51:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1760647907; x=1761252707; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=3x/uHpEqiK/yR3zaxN8TiBftfzYVsJOeZiUqjKGmJC0=; b=N3WCvZeI7EjTOuhJpjZvzWZZ30mN5zRw76kcX7/Yge0X9/dF7Jpq7aUV5a3BJFyIF4 XJatFbqas28+a7LSvQQC2RqDLR94r6tAzN8aSd1rityTHYjYhO4OCGKWtuqBFXmgNQLC JeTkuBITC5ey8FUbxKw9/TdtZS2hkzulB/QRP66/L2f9Gdr8UJ8PZJqrleyd8GrlhKEe 2OAOrafEp1XwxnNjbdj+YnvZyHiEZ0oAMBr+wgjhp5cpiOZPxCGVqHDepJijLdXJm7nD 6m3HTnP+jgAu3GPXjfZzsFeoanvCqEj17Tt0eSa8x7xz1SYUR+bneo9tJzTmUYJuEGku oBuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760647907; x=1761252707; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=3x/uHpEqiK/yR3zaxN8TiBftfzYVsJOeZiUqjKGmJC0=; b=G39fXAbfpO9kogDq5K3QgAdGWQp8DD2cuAc3XjGOrxy6+ZcGA0gO+YOUdGTUuZl88B x2kY24PeA7ToutikiycSBSDhrHJMeH4Fa1bv+9mStPrbMVMzOLbhDzviUfBTFnExDQaX fatYL/81au4BZCMpxEqcyQn5l0jEijNazPcGQNFvwm1jTu+4INB1jCtTfPLuFaavXwDL MLALk+fdrroiZwK4fzPpbHyuq48xDeM+4UFQZhSC4vJbuLveGKO0A6hUkYQs6VjJO2O1 urKT26dgYPLevfueX2j2jI71+UivCVOWkqmaL4Q5eSn8Qm88xl7mEaojfheTTsoSUoP7 DoXQ== X-Forwarded-Encrypted: i=1; AJvYcCXl6PtFonJbl7ax4pD3vlo6n/BAQFkINQUWIpXcGN3ZmJHwFb1Vads9+kDztKEtTQ2Al4ccLc4qp03LpzI=@vger.kernel.org X-Gm-Message-State: AOJu0YyRQaAptsb8YZRL6wuEra/sIrZ3oYgbkrvGY+0L0hs7oBsV0IDF ap2dKWsJBALh+OPB7FQ7AZiR1rTOTDEDzgLYgRkNZWc6uPUC1tlwz9dsq/qOwLEA2exeqPDi3Mz 4C0tzejO6UQ== X-Google-Smtp-Source: AGHT+IHfet3YXaizTDWcf4cES9vB97PcTVbDuttutuWSnMKXiMdllyjCZASSKesyfzsvND89p+bwGI5ALSmM X-Received: from pjbft18.prod.google.com ([2002:a17:90b:f92:b0:33b:dbe2:7682]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:2b4b:b0:335:28ee:eebe with SMTP id 98e67ed59e1d1-33bcf908bc8mr1187370a91.30.1760647907329; Thu, 16 Oct 2025 13:51:47 -0700 (PDT) Date: Thu, 16 Oct 2025 13:51:26 -0700 In-Reply-To: <20251016205126.2882625-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251016205126.2882625-1-irogers@google.com> X-Mailer: git-send-email 2.51.0.858.gf9c4a03a3a-goog Message-ID: <20251016205126.2882625-5-irogers@google.com> Subject: [PATCH v5 4/4] tools headers: Remove unneeded ignoring of warnings in unaligned.h From: Ian Rogers To: "James E.J. Bottomley" , Helge Deller , Andy Lutomirski , Thomas Gleixner , Vincenzo Frascino , Ian Rogers , Arnaldo Carvalho de Melo , linux-parisc@vger.kernel.org, linux-kernel@vger.kernel.org, Eric Biggers , Al Viro , Christophe Leroy , "Jason A. Donenfeld" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Now the get/put unaligned use memcpy the -Wpacked and -Wattributes warnings don't need disabling. Signed-off-by: Ian Rogers --- tools/include/linux/unaligned.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tools/include/linux/unaligned.h b/tools/include/linux/unaligne= d.h index 395a4464fe73..d51ddafed138 100644 --- a/tools/include/linux/unaligned.h +++ b/tools/include/linux/unaligned.h @@ -6,9 +6,6 @@ * This is the most generic implementation of unaligned accesses * and should work almost anywhere. */ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wpacked" -#pragma GCC diagnostic ignored "-Wattributes" #include =20 #define get_unaligned(ptr) __get_unaligned_t(typeof(*(ptr)), (ptr)) @@ -143,6 +140,5 @@ static inline u64 get_unaligned_be48(const void *p) { return __get_unaligned_be48(p); } -#pragma GCC diagnostic pop =20 #endif /* __LINUX_UNALIGNED_H */ --=20 2.51.0.858.gf9c4a03a3a-goog