From patchwork Thu Dec 5 15:40:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uros Bizjak X-Patchwork-Id: 13895606 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 9CA6BE7716C for ; Thu, 5 Dec 2024 15:43:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2CF0B6B0166; Thu, 5 Dec 2024 10:43:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 256D56B016A; Thu, 5 Dec 2024 10:43:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 083676B0176; Thu, 5 Dec 2024 10:43:02 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id D70BC6B0166 for ; Thu, 5 Dec 2024 10:43:01 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 22F49A16FC for ; Thu, 5 Dec 2024 15:43:00 +0000 (UTC) X-FDA: 82861323510.02.77D1506 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) by imf05.hostedemail.com (Postfix) with ESMTP id 2FF4710000D for ; Thu, 5 Dec 2024 15:42:27 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="N/XpizXm"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf05.hostedemail.com: domain of ubizjak@gmail.com designates 209.85.221.53 as permitted sender) smtp.mailfrom=ubizjak@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733413371; a=rsa-sha256; cv=none; b=J7a4KgP3Y7NA/Zy4Pafd0ROM7qqYJj2w9EK3heUAVaYooGEolcbFaqoV27tbRxuo+MHnul JxClDcHculMmSQpPUM1dwfY9Vk8G1SIz0ZlItaRq0d8G4fI8KTFOLAmDJ9YCfZot8/hRyx MB8v1GWOPndA8TvjwE1g+w2gLaEmELY= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="N/XpizXm"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf05.hostedemail.com: domain of ubizjak@gmail.com designates 209.85.221.53 as permitted sender) smtp.mailfrom=ubizjak@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733413371; 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=Qm0xTA7w0trmMS63onZN9A8A0KVvItfxjJ4yazAcGOA=; b=s5zVNaoh1W5WKIMCCkKruWUWq8Llns2aGHq0jQap5iE5Z9XVmlCx1bcts5GCO6Dw97eInT MQnpQ24rzNc8hPDKNgKh865xNYvfhG2xZQAyCTISjOwvVYPLb3VZ4/zGBPEMcYKVIwVEp5 KLxRILOoRylPm9blwexl7Cn+CWImy5A= Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-385e1fcb0e1so574230f8f.2 for ; Thu, 05 Dec 2024 07:42:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733413377; x=1734018177; 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=Qm0xTA7w0trmMS63onZN9A8A0KVvItfxjJ4yazAcGOA=; b=N/XpizXmhQaBJHALsvNdjtfUBkSV7399kiytvuMbvfMHlqC5VwkUUFFV3c5qbftCD5 +8CTUbtXZpsgRSwYi0LX17xcfU8Ue9mYX/zhQ4Z9jzBxQeTH9wsWTPTbH/G4fDw1aoew bMzXrr7GQnoJQR7OAPJH3ZDfy1+a8uxtWPuxehGZ4mdk07Tq/D7t0HQmAkmj/3LQ7a8L 11mdB2M15W0oG8IRRITQ0J2eTFxFa+g0JNmjPoaerx5EfoPjhPUbFICjsa5NZu7NanCn VspuKKRMDMY+YOCk1jDm+HUyVjBkFbPXZyvGBhwQLbCukj3tQkisAwAlJRBH0csficC6 N8ZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733413377; x=1734018177; 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=Qm0xTA7w0trmMS63onZN9A8A0KVvItfxjJ4yazAcGOA=; b=W71Whe5Lne1Mbo2K0Oh7phBUx0L4K8+Ou5HAKtjHP8jYVRjz0qMPaa+cvAw1wYmIml i0OClvqSLxh9HUQCHDK38T9cw+TfUER0qnCZD1XYdnXLYT8qFow2GTXxRmCRNeyrrTud AUgvbd0oKMwHFv4UwchMSPRfJ/lCA+nUhXI4pa5P8/wUAehiwct2B5jXTcvC6lBU8iFo +tVLuzoHoaiI3sXRzVluhBmncrloxjQMDPaZFfqzkEQNsiQvblkR++9ralm6IgrOjoDT AGfswPvp8QFIBb1Eq/ChH3bwFLtZjwXUvcTjQUbF8JGXTIAytBVeLAzMfa8Yko2rsas8 l01g== X-Forwarded-Encrypted: i=1; AJvYcCUBejBr84UB6SeUba8P0aMQ3fIXzACsOmiyayLciKPBnOOBlypk0g6yKdJ/1N6vA/bmtLUZBpqSaw==@kvack.org X-Gm-Message-State: AOJu0Yw9ACzRbpwasVuZWLvxXSm41BbvFh0O6MEhffzpRCDkJHtjSXvL z13NwJQmfiC8SgOdio57WpSRHiMxT9FSPQda96GOoGjJzoKk1d90 X-Gm-Gg: ASbGncsR5Aj+O/CnOoRxyw2/+H2+AnC4yP+iFLpKT1ecNN6EVE8gw2CwErm8sglj6kY xZQB3DnyJoYPVnyoTgdH/XsP08rErCOCBExGqQ8TCSLKuL2fiI9bjI8znesOL6KdAP57/8rb3j0 QEr2bUStyWKclPM+YgWMfc+GcP0H7eQnzLt69Sw/Z4Ht3SXUulhgWbU3PjigHeusCXrMZsjmafj FfLtjSgRrGSuRy11cYkKf445c6fMQpH9vRj9QkKZ03zm+z0rxIPAQ5FNIE= X-Google-Smtp-Source: AGHT+IE1FZ5JkMJKChb9COrcHR93yKEZdHzkg3M98KstBiKvfHSE5uSF5BeN4exQl35vdPQhMGDNYw== X-Received: by 2002:a5d:588b:0:b0:385:f114:15d6 with SMTP id ffacd0b85a97d-38607ac1ad6mr7179392f8f.13.1733413376413; Thu, 05 Dec 2024 07:42:56 -0800 (PST) Received: from localhost.localdomain ([46.248.82.114]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-434da11387dsm27020185e9.30.2024.12.05.07.42.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Dec 2024 07:42:56 -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 , Andy Lutomirski , Ingo Molnar , Nadav Amit , Brian Gerst , "H . Peter Anvin" , Peter Zijlstra Subject: [PATCH v2 0/6] Enable strict percpu address space checks Date: Thu, 5 Dec 2024 16:40:50 +0100 Message-ID: <20241205154247.43444-1-ubizjak@gmail.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 2FF4710000D X-Stat-Signature: femstwxfo7bedudhydotwbhrggwwusq1 X-HE-Tag: 1733413347-392751 X-HE-Meta: U2FsdGVkX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06AVPGOdV1IQiyIIp/1XDNel8wzkyryI2FxWHbfbikeOU4R4T1rd2Rp4JegNeDX0FW37xPSSdmDEIblFK9vpCwO5fZnq8Y2CVQ2QB/H6HGbQzZKJHNwkdstgr5yLVv9+mVnspwjxT3ys8u9sffvKHZ9IjcvDqKb0fF5M5CIK2Cq+0Q3H6iDsBH/V+iNWlyDw6NfPsA1HxnH1SNVCG6KRd8RjlItJRnQ0wfOMUA4f2z3tS8eg1WhJBgjCCUe3Feep6tmSKntY2aZQd1o0BA3GipvUdiwL8+l0Q081+jKmMRb3inNEXOuxUOidTQGb0XyIow73z+gT+l/TiDMSgUyG8f0rwHDQ0ddvDb0O3gFVorBg9CqzuN6dHk+2sirtaSr2csU6TARxZSQwAc877bBacMktSeTYtAdLUngsNx2dXQXJsJ9ZG6sUyalM3ACl7Ypv4uCLaANcY2G12PHuk26cHonXlzSs3Vvd8IDUx2nWtaN+rPvLnXtLK/krd6Su32ijhTwz8+3ROLjDE+spHZS+X5YDn2mkcTq71SoPMKpU7vyo1YaH8fD5IABDP8pZ6kEiJwXPvvVZ0Q3LPdDqf2P1fyKW2PmzBWm31VH/sI0/c48O2i5wUGxTjD2Kph/Ig70w== 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. v2: - Add comment to remove test for __CHECKER__ once sparse learns about __typeof_unqual__. - Add Acked-by: tags. Cc: Thomas Gleixner Cc: Dennis Zhou Cc: Tejun Heo Cc: Christoph Lameter Cc: Linus Torvalds Cc: Andy Lutomirski Cc: Ingo Molnar 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 | 38 ++++++++++++++++++++++--------- 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, 84 insertions(+), 36 deletions(-)