From patchwork Tue Nov 26 17:21:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uros Bizjak X-Patchwork-Id: 13886255 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 6A7C5D65531 for ; Tue, 26 Nov 2024 17:23:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F2E5A6B0083; Tue, 26 Nov 2024 12:23:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EB79F6B0088; Tue, 26 Nov 2024 12:23:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D315B6B008C; Tue, 26 Nov 2024 12:23:56 -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 AAD966B0083 for ; Tue, 26 Nov 2024 12:23:56 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 5DA0E1A0EE2 for ; Tue, 26 Nov 2024 17:23:56 +0000 (UTC) X-FDA: 82828918662.08.168739A Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) by imf30.hostedemail.com (Postfix) with ESMTP id 9736F80003 for ; Tue, 26 Nov 2024 17:23:45 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Sz4tMUnQ; spf=pass (imf30.hostedemail.com: domain of ubizjak@gmail.com designates 209.85.218.52 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=1732641832; 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=2Erh3kDkyyLqMgBRTpctsP9hRptfdoHadkYL68Kj+DE=; b=Td4sQ3jYF/ERrW4eQAQ7/XTR5DpivU26hfFyvtDHnjnHHyZP8woBkzpHJ4n4Oca+GoVRm7 oC/aRoglBC3yscDY5+kBZknXDMZ5DbERIFvFxA6+Lgau5f0sKyTYIXYMUXUrVRtCkUfXlW DUZ2vI1vwQBDbswL97I8EAQQPgMNop4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732641832; a=rsa-sha256; cv=none; b=JfizXMwkrUW+EEVg5ivTaQpm84bvgCHxZUTdhYkCipLPQV9QBaq1PbkWYeTNJJAKslulQh fq5R+wi1Vt/riiP9C2H08yEUrA9WcGfbxRmAuwZZwtDvQSetMWahp7qw68RtFPeapAcbVX MQEli1mzOGOOaX2gck0+xYjkbv1tw+o= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Sz4tMUnQ; spf=pass (imf30.hostedemail.com: domain of ubizjak@gmail.com designates 209.85.218.52 as permitted sender) smtp.mailfrom=ubizjak@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-aa52a5641f8so562374966b.3 for ; Tue, 26 Nov 2024 09:23:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732641833; x=1733246633; 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=2Erh3kDkyyLqMgBRTpctsP9hRptfdoHadkYL68Kj+DE=; b=Sz4tMUnQWpubMjOkvAiIe1YrRJA1H3wUQpiS8UJ4cx9+N4DQojIQAx7RDZYV7BD4F0 0gSZ8pQreapf21DkPE865FXCD1n0anLPyiFZi4zlzdpJYVvffpYNZCEoHfOJTQYpqTIl IILp1DGIG2DDp/0vO9MOQk0MG7THIOb9F/i2/XXh0+jk4aGq/8UHTkgMR8VJBmQyhffK QPZckeIsjjdpmituYGKp9oNXDG4aqryyjWn0AkFhM2Xg/6yPF8AT6ODZSWeoinMIpg66 TuaRjYQfzHTuzY2vKLlibhEbzzaiODZR9Nmy4UBRB/6SVT2N8KTss44Ydye8SJqctF8x UdUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732641833; x=1733246633; 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=2Erh3kDkyyLqMgBRTpctsP9hRptfdoHadkYL68Kj+DE=; b=mK7Hw/tlKazxwYh01Urx7NKbnIYPPumTP1FAqAosDSsZP6MK2OOD7bH02XneQy+8bd Rf9MmkGkrL68+1ScHiI/EK4Kv3pHuyyQHrV/tELP3gKk4OXXhRx2DmS3RqKvdAA8P2I7 VZt9qBrX4yW00TuHb4kefOpV+VDKtcuNOPc3KjmKG0J1T3zoz4cn+zR1pBjn0cb2LMTB oBfYNSF4VujnPr/kUZxY2dGp89nIOyrn9tJuJeNuVJr8UvxvVpBV7cV/yoH423DItWNC fZa59qS+1LeETTf29izv2Ed95Md/r4TQ0plxAdxS0yLmB6WcT08zHRqilD10ThRavTEw rcOA== X-Forwarded-Encrypted: i=1; AJvYcCX1qdImBlMpeHpGpOoOcxZNPXPSDD1nTzHCx8d9eRrrW4ECmuE4igGL/A6whW//gxKGGuQ2fO67rA==@kvack.org X-Gm-Message-State: AOJu0YwZDmqXiLR4uCLg6D8LPnTKHRHJlhiBwq9Ax+yCkOQCD8A5O9xp f18jfLo59/Pl1jnZFVxTHWamMgw6YNlyOiiNu9aTYYvomQmJG4xw X-Gm-Gg: ASbGncsbdGgNgDp5mguSJ95aHKFSx/DyyuErSr2FuM38ccnjNYIAiOgBqzUs3WxF3R8 Dp+5ldqghrplwB7MKEX+v9GdnOHZFSYfC1h7pEJcxWSFlIC3ICe5XpFahMLt+0cXS0L9cIO6jcQ BB+FvrogLW7dEK9s431WNuieNLd6X/+kBpEXaK+KLc3ZglVHU5ZWIlJlsRe3VfXwn0TVUa21zWG 7gi1BAT3eRrNs5BPjDDG8FeDPEz+lmEkLTBpmNPUz81YQkXHgkerBKeEic= X-Google-Smtp-Source: AGHT+IECV1SfPk75kkOO3nyGfh6AJfPnfs9z/0KCVg6p2LbUtu1npUxOUG5Li3TZL6yCbXfXk+iKng== X-Received: by 2002:a17:906:314f:b0:aa4:9ab1:196c with SMTP id a640c23a62f3a-aa50990b24emr1417865366b.9.1732641832663; Tue, 26 Nov 2024 09:23:52 -0800 (PST) Received: from localhost.localdomain ([46.248.82.114]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa534232086sm473832866b.42.2024.11.26.09.23.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Nov 2024 09:23:52 -0800 (PST) From: Uros Bizjak To: x86@kernel.org, linux-sparse@vger.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 , Andy Lutomirski , Ingo Molnar , Luc Van Oostenryck , Nadav Amit , Brian Gerst , "H . Peter Anvin" , Peter Zijlstra Subject: [PATCH 0/6] Enable strict percpu address space checks Date: Tue, 26 Nov 2024 18:21:17 +0100 Message-ID: <20241126172332.112212-1-ubizjak@gmail.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 X-Rspamd-Server: rspam10 X-Stat-Signature: ctuj13rsz4ph6pi5pon7degyw15ieyy8 X-Rspamd-Queue-Id: 9736F80003 X-Rspam-User: X-HE-Tag: 1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zubUgWWNyDNL5QrRKRw7inbW+xzEAzf5V9FIXfJaG6IXtJnMWxMcAVHn6yyF3P6OeTBSfSCczmSaqcvQJKReX5Q8x2MkJ5cuC7DOMsp7XaazdFXaDCZXHxM/1B+Ad+x6JB5sgPznhlTM4yweSFYPU5MecHzXZRB29wSBSHzNlPPgB516ojMiNQgIvfglpfwk6YwzrG+cAaWyyYqa4TwhE+JhQ9a8ZtNIOi7F7SMzujKmhFd8BGe84z1+EiPeev+hArAIO5dj3GYGCKHf9Ek7jayJ1+NqP1oNuVpsa9VYdBVPMitSFBK3B7tHIEkypBuOZ3XiFUL6RdigFb+cZnblwvEhgLMVjQXdH1QhrtqoCrANFkVBqhfWurhjaJiZMFqiypLNHz1mm2AHiebb4sCy9tcnQ4YmYiGECCIWypCKvb5lZV8QmRpvO5hdsUZs68/QLlZyjvxkb40swk+CesfkgbiDyPqj0kvjSwk0O/2JQ8X6NfOTk5S9+vYi+zj8vKCagzzRUP/NkZIzVoBg0pGPcBarDjA6K4+FZr7Ko/Qemi2KZV5p4W5Szuv+tGhiOPCxPpjMtQZEGT4HgMa2TDh+f1iPBCDnJePEh2k82ikyUnfx8XD0Nr6OBIEO1M/ZCxUpHQ30g75a72vUzjUnNkaqTyw== 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: This patchset enables 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. Cc: Thomas Gleixner Cc: Dennis Zhou Cc: Tejun Heo Cc: Christoph Lameter Cc: Linus Torvalds Cc: Andy Lutomirski Cc: Ingo Molnar Cc: Luc Van Oostenryck Cc: Nadav Amit Cc: Brian Gerst 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 | 34 +++++++++++++++++++--------- arch/x86/kernel/kgdb.c | 2 +- fs/bcachefs/util.h | 2 +- include/asm-generic/percpu.h | 41 +++++++++++++++++++++++----------- include/linux/compiler.h | 13 +++++++++++ include/linux/compiler_types.h | 2 +- include/linux/part_stat.h | 2 +- include/linux/percpu-defs.h | 6 ++--- include/net/snmp.h | 5 ++--- init/Kconfig | 3 +++ kernel/locking/percpu-rwsem.c | 2 +- net/mpls/internal.h | 4 ++-- 12 files changed, 80 insertions(+), 36 deletions(-)