From nobody Sun Dec 14 11:32:39 2025 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE61B1F94D for ; Thu, 16 Jan 2025 17:32:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737048754; cv=none; b=t49RbkKQOELHXPSbZyP77eMz4OrfDhTn5dn2U/aJfHgwNFW7CSlPhsxereP8lVa0GJKR3ykA8MSQniu16JFoMV35++IDF3nUqlWzubOd+yj/myJGXVzuPJW3/ZRs2H4XJTmLtc4aWU7rZCNaXcwDoswzDjIKSQf8ljOwPTY/v6o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737048754; c=relaxed/simple; bh=FAwTQDOg1XS6NTjoryxHdzMTFrfzNsl8JlTJA9w2wxY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=u2i8MTRk041EjKQ8mu4k+Zf2DGhMbnyWsYoyo+HBe4f6zfiVqTBbkaShu8i/8q53mzyc0IC9fni/eCKKXy6MKbqmHzHmozias4hS4zT9+1KL0RsYU+l4CI/c/8tUWnoHN9SnlefF8gtNQMeH2XzMuiXvsjVEXC7vZhVuAT6GaWo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=iqesPseA; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="iqesPseA" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1737048750; bh=FAwTQDOg1XS6NTjoryxHdzMTFrfzNsl8JlTJA9w2wxY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=iqesPseA0hRVC1AcimVR5z4LHhZY3JmZX5CZesgHZ2F5CG6m3//n4qe7ZdRD87T27 CCBqrE5wU6uk744V1zmJ7jWQJhMLB2opB7NoPKHw5GjZA/ZJJYNlwKmQb79BB6BYvV bwahi1rVLtx8lv5ZU+uOHVMi/wWQWXL1VzZ+iBt4= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Thu, 16 Jan 2025 18:32:29 +0100 Subject: [PATCH 3/6] sysfs: introduce __SYSFS_FUNCTION_ALTERNATIVE() 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 Message-Id: <20250116-sysfs-const-attr-prep-v1-3-15e72dba4205@weissschuh.net> References: <20250116-sysfs-const-attr-prep-v1-0-15e72dba4205@weissschuh.net> In-Reply-To: <20250116-sysfs-const-attr-prep-v1-0-15e72dba4205@weissschuh.net> To: Greg Kroah-Hartman , "Rafael J. Wysocki" Cc: linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1737048749; l=1400; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=FAwTQDOg1XS6NTjoryxHdzMTFrfzNsl8JlTJA9w2wxY=; b=ME5DBKGbrRXiz/SAVJADDFRH2McbeA6q6cWSaE9KqcA4cpOtdvL6MxcmR2juoqaFfWD3blqgH 5hAZ9pXjX7QClzb8c3p+VFwH8a7QTYFvRee1w006Ovw/Y3Qtj1CjUPO X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= For the constification phase of 'struct attribute' various callback struct members will need to exist in both const and non-const variants. Keeping both members in a union avoids memory and CPU overhead but will be detected and trapped by Control Flow Integrity (CFI). By deciding between a struct and a union depending whether CFI is enabled, most configurations can avoid this overhead. Code using these callbacks will still need to be updated to handle both members explicitly. In the union case the compiler will recognize that testing for one union member is enough and optimize away the code for the other one. Signed-off-by: Thomas Wei=C3=9Fschuh --- include/linux/sysfs.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h index 52d4862bbcef2a6b143710a19801222bf7abc346..46e9261bc35f248a733d27c05c9= 31080b0c58e17 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h @@ -58,6 +58,12 @@ do { \ #define sysfs_attr_init(attr) do {} while (0) #endif =20 +#ifdef CONFIG_CFI_CLANG +#define __SYSFS_FUNCTION_ALTERNATIVE(MEMBERS...) struct { MEMBERS } +#else +#define __SYSFS_FUNCTION_ALTERNATIVE(MEMBERS...) union { MEMBERS } +#endif + /** * struct attribute_group - data structure used to declare an attribute gr= oup. * @name: Optional: Attribute group name --=20 2.48.1