From patchwork Mon Jan 27 16:05:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uros Bizjak X-Patchwork-Id: 13951588 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2D616C02188 for ; Mon, 27 Jan 2025 16:07:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9EDF32800D1; Mon, 27 Jan 2025 11:07:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 99E1A6B015C; Mon, 27 Jan 2025 11:07:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 83F262800D1; Mon, 27 Jan 2025 11:07:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 60E696B015B for ; Mon, 27 Jan 2025 11:07:24 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 1D2F7120301 for ; Mon, 27 Jan 2025 16:07:24 +0000 (UTC) X-FDA: 83053711608.26.AE39816 Received: from mail-ed1-f44.google.com (mail-ed1-f44.google.com [209.85.208.44]) by imf07.hostedemail.com (Postfix) with ESMTP id 21B0B40002 for ; Mon, 27 Jan 2025 16:07:21 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=J+YzhF3a; spf=pass (imf07.hostedemail.com: domain of ubizjak@gmail.com designates 209.85.208.44 as permitted sender) smtp.mailfrom=ubizjak@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1737994042; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=WT5eWH6rZrIJLgUZzxnI1r9howrcT7ENhSKc9wgIf9U=; b=oy+t10GJQpc51rEohhPhjW+T+42KnL4rQmkF3OyNugwhbK0iE+r7goqgs1JtH/fG6Ppqzn MmcQuwXjF8mBCInUfsyKEDUHSRyk6xVCZIuuQYxMfUE6SquDyBd3PDOn3VuuYWoARtCQlH BuhFTrU9gmxIb405O+84/3eSVUr5bqg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737994042; a=rsa-sha256; cv=none; b=0fFv1aAGS9m35ouWhS0i3fOIg+JGtGBamJEdDeZdzb7+1HDF85XrNuUgYPD86bdn+rr87p DXzrCuXYTFFn5X4uJFTl6ZsLEPCbIC8QqRRvnJHiEKgKnLYMzOqj/4grMFy7Wrby+HGgss dSrvUH7jQejZQ3LDrMj9jmYrlxXZSXE= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=J+YzhF3a; spf=pass (imf07.hostedemail.com: domain of ubizjak@gmail.com designates 209.85.208.44 as permitted sender) smtp.mailfrom=ubizjak@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-ed1-f44.google.com with SMTP id 4fb4d7f45d1cf-5d3e6274015so8688004a12.0 for ; Mon, 27 Jan 2025 08:07:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737994040; x=1738598840; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=WT5eWH6rZrIJLgUZzxnI1r9howrcT7ENhSKc9wgIf9U=; b=J+YzhF3aVD5/EjIB2xuYEpIycmVV16iOhqZu+k5O7hL0XnQJjHM9OIpF1jnujXo4b4 2PWYgEJTZADul/HWhW6loj04jLR9dwzR5T8y1Bmoe8jUvjiX2GDx/rp0xyJTXh/izQux PoHNrCrIrKwE3s5C5AQC6eiBNaZvfodOhBLdHnx9uS/IA1GBbk3PRTEgfsS84g9hJ5bR pVF2IjgbCq8pAHKlyubjMZga0CKJjT2MlvewQAXzkpH+TGlTR3xBKwTqd2VJGNs7y4JM s8y96FX+k52B3KDHkU97WRGe2opFapwTKsBq1ZC3hAsXs7sEPs6u8ZzGGcup/RHhDCm1 fovA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737994040; x=1738598840; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=WT5eWH6rZrIJLgUZzxnI1r9howrcT7ENhSKc9wgIf9U=; b=LbkLtNm7k0yf1dygTKkbLJtEsABCW8vgWem3G+AwpMfPNbTAPd7v1e7OVh3YRwYOzY Gfs08GBnGBnJsjm4kMW4hPmLVTxW0Q70g2Mqu1tY57NXueGtuBSVV5bjRu1qjqTutSXq 5TDT0o2bvdqKOST+aYuBxd2HPTPWUrmKPskft/QaBqbLU5ELgZLz7qX6qItnrGKXXSIz Vbcga9Wd5EAQNJCb250OksAhyDv3Fsma4s1EfVhmPClYGyU2EbVnganOFmvk5LIxCY/q wtigw3qog8674iduHjfriiKdjEy2NSgAERzoaz/1lTPMppcr7HRaIiDs235vT5hCm7df 88eA== X-Forwarded-Encrypted: i=1; AJvYcCXw6ZYio4cQDXDRr72TQkELKQxvLsYRr/HTzGaH1MIfVvxptCyXEwRlZL+CR5ZCb5ldWX51CZFt8w==@kvack.org X-Gm-Message-State: AOJu0YyFp463mYcR/oxs95QfXV4ienmih9JLkZZewCF3cnS7WzrXc+9m 6q/b0DbWx+wMuL4F/VI6g7Vl/Rj/Ng0PSbGwp3bgpIQuysB3GfW6 X-Gm-Gg: ASbGnctlpZzEvEsgCwiFuXF+IeUtJxsabA1HIpceksv9vauFzuhJlAPY1lKaq6QCb9c ZDHFLMIbdZbkKaAsxbydgPy8x2BshB2PEPB1b09t3TS8RfcA30faOSU55/GOE83IGui2c0BSFoM S22v7p/Xv2fptbwpCr3tzHOEdFIwNCrPp1HK2SABhJcmksRh8B0kB4klgQ4p40+AAEtH+yuwfmv H87tFrNnE2VBgbahEvdaEGTcViUG/NDgzCejULbY/y2g4PcCAG49rZuAJhYqz/n8u0XFJLqvT/H fVywVYShQypMxw== X-Google-Smtp-Source: AGHT+IFuULEp0GQymnkX/TKA35qIg1LycjVhC3Ts9VWHQc6Q18z1cFu8eW/Z/NP2jJeLUu8LFdZJ8A== X-Received: by 2002:a17:907:940b:b0:aac:619:7ed8 with SMTP id a640c23a62f3a-ab38b1e651bmr3499843866b.7.1737994040271; Mon, 27 Jan 2025 08:07:20 -0800 (PST) Received: from localhost.localdomain ([46.248.82.114]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab675e8b01asm592643866b.84.2025.01.27.08.07.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jan 2025 08:07:19 -0800 (PST) From: Uros Bizjak To: x86@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-bcachefs@vger.kernel.org, linux-arch@vger.kernel.org, netdev@vger.kernel.org Cc: Uros Bizjak , Thomas Gleixner , Dennis Zhou , Tejun Heo , Christoph Lameter , Linus Torvalds , Andrew Morton , Andy Lutomirski , Ingo Molnar , Nadav Amit , Brian Gerst , Dan Carpenter , "H . Peter Anvin" , Peter Zijlstra Subject: [PATCH v4 0/6] Enable strict percpu address space checks Date: Mon, 27 Jan 2025 17:05:04 +0100 Message-ID: <20250127160709.80604-1-ubizjak@gmail.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 X-Stat-Signature: jwri4m6pk431utxk944s89ge4tkg1n9i X-Rspam-User: X-Rspamd-Queue-Id: 21B0B40002 X-Rspamd-Server: rspam03 X-HE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Zs8KO8xG8MDAa6xxT7IpdCTJ9Mh1X97NnYw5+7dPxTFeOYGWpJDIzN5fyw+VB8M/qp6e4XajLonRpUAxVZcajL8SDq4wp7dtqxegG3lIoS44dnQeDZ1OlpzvYCFMiguGQzQAKswY0wmgHTm0cVQhcqNlLkeZCVdaBkZCjHorfnoILESTCWVJ0LoQBRmumohU1fTs3G7IKCAm+kFwX0il/4gSR2IZWk0YmTL8VSypqW3+zmmVhMOrqGfoSDz15VWv5LoE7FtSWFk6nZX0m3tqg+66aPAXWQujxmQu7aCaIR2uTXGbxz55s34AdRhtwjkYaNCdP5wc7da57V1POY+NMyggVgg/uvcuCT+XUylE93oD16E/6o1TXKqDURQnY6Fbs4kodfUYNLOjcEVo4HUDEwWSUE/RZi2B4EUu94SEr+7LoAB4d4w6v6WsPFsdTgv4eBGoNTXD2tiK3+fqeyREiuoV5OsOPjgvUlYpXEmr6WpeIjKJWYpDYzOII+oa9OTRn/mJWZCmnlDoRs/XDF5b+LTu++wh77QaTYn0Gx8nIf6iJYMjWlNL6yBwwLG3EX95kncjZVeJss1Ou/S6Ujhq8CTzGjephSs2wcvpb9dlkXZvt00Qh1TJhUcIDtT1AWwrjk72ZXonSkrniKyG5QRNrhP/g+9oy1c7cSiuHnN5ISds9oRbRr8fYVHcz4E2FUYYlID/YHVA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Enable strict percpu address space checks via x86 named address space qualifiers. Percpu variables are declared in __seg_gs/__seg_fs named AS and kept named AS qualified until they are dereferenced via percpu accessor. This approach enables various compiler checks for cross-namespace variable assignments. Please note that current version of sparse doesn't know anything about __typeof_unqual__() operator. Avoid the usage of __typeof_unqual__() when sparse checking is active to prevent sparse errors with unknowing keyword. The proposed patch by Dan Carpenter to implement __typeof_unqual__() handling in sparse is located at: https://lore.kernel.org/lkml/5b8d0dee-8fb6-45af-ba6c-7f74aff9a4b8@stanley.mountain/ v2: - Add comment to remove test for __CHECKER__ once sparse learns about __typeof_unqual__. - Add Acked-by: tags. v3: - Rename __per_cpu_qual to __percpu_qual. - Add more Acked-by: tags. v4: - Do not auto-detect compiler support for __typeof_unqual__() Cc: Thomas Gleixner Cc: Dennis Zhou Cc: Tejun Heo Cc: Christoph Lameter Cc: Linus Torvalds Cc: Andrew Morton Cc: Andy Lutomirski Cc: Ingo Molnar Cc: Nadav Amit Cc: Brian Gerst Cc: Dan Carpenter Cc: H. Peter Anvin Cc: Peter Zijlstra Uros Bizjak (6): x86/kgdb: Use IS_ERR_PCPU() macro compiler.h: Introduce TYPEOF_UNQUAL() macro percpu: Use TYPEOF_UNQUAL() in variable declarations percpu: Use TYPEOF_UNQUAL() in *_cpu_ptr() accessors percpu: Repurpose __percpu tag as a named address space qualifier percpu/x86: Enable strict percpu checks via named AS qualifiers arch/x86/include/asm/percpu.h | 33 +++++++++++++++++++--------- arch/x86/kernel/kgdb.c | 2 +- fs/bcachefs/util.h | 2 +- include/asm-generic/percpu.h | 39 ++++++++++++++++++++++------------ include/linux/compiler-clang.h | 8 +++++++ include/linux/compiler-gcc.h | 8 +++++++ include/linux/compiler.h | 20 +++++++++++++++++ include/linux/compiler_types.h | 2 +- include/linux/part_stat.h | 2 +- include/linux/percpu-defs.h | 6 +++--- include/net/snmp.h | 5 ++--- kernel/locking/percpu-rwsem.c | 2 +- net/mpls/internal.h | 4 ++-- 13 files changed, 97 insertions(+), 36 deletions(-)