From patchwork Sun Dec 8 20:45:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uros Bizjak X-Patchwork-Id: 13898660 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 43558E77173 for ; Sun, 8 Dec 2024 20:47:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9CE9E6B0388; Sun, 8 Dec 2024 15:47:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 97D0C6B0389; Sun, 8 Dec 2024 15:47:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 845406B038A; Sun, 8 Dec 2024 15:47:26 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 66D746B0388 for ; Sun, 8 Dec 2024 15:47:26 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id D62DBADFE5 for ; Sun, 8 Dec 2024 20:47:25 +0000 (UTC) X-FDA: 82872976368.08.ADB8EBE Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) by imf24.hostedemail.com (Postfix) with ESMTP id 841DC180004 for ; Sun, 8 Dec 2024 20:47:21 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=JO6Kdx7J; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf24.hostedemail.com: domain of ubizjak@gmail.com designates 209.85.128.41 as permitted sender) smtp.mailfrom=ubizjak@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733690825; a=rsa-sha256; cv=none; b=L4LqPsjuA2Jh7OBqOARtKuog8Ix/O3tGOsji1EbhgoOC0lxBmQxtXXUEsZQqAddwQCQhV+ LaByo3HpOJ5tcfcn1xdWd+hDsNhS8RzLeGv0mvHg6kXKWpqS4VJ3BnYxQuhzgNqZuCfnHW ZZr34kj7YSBMoJ/PJa9hm/I/wZLUUY4= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=JO6Kdx7J; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf24.hostedemail.com: domain of ubizjak@gmail.com designates 209.85.128.41 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=1733690825; 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=uydVfRix40VtM5XGFg4FP+2BbqHhhGYzjwg/+qRitoA=; b=Fds4B3RILp1NML5W0l8JfJetq0dxuHw7NeBqTdmUZquNXFYCLUnZv8Iib4Lzl1LeBb4R8u oYMi6ih1O3cgIA/uABRZsjSLMhgD6v2PSCV7SscK6ZntPM4FoGWA6qSycxpD02c/7E7iP+ T+nKF/e2zedKlcTmUhJBI94zrsJC6zE= Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-434f09d18e2so11222625e9.0 for ; Sun, 08 Dec 2024 12:47:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733690842; x=1734295642; 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=uydVfRix40VtM5XGFg4FP+2BbqHhhGYzjwg/+qRitoA=; b=JO6Kdx7JdvT8IAJ7rAzqiJ+ZOr9yrVzNmHzcpWY1i0rydZ4F5r9hvnxwneWxUi5QBU 3q1DZAZ8p4evGkauGRm9iuZBKsrkx/UJ5gyxJiIDfJ4lQKN+QaikMx8PaZmz1mqsEsOB juzicGZDX5YNYt3slJXULDv/x4PBT9UsgTdZfOWUZKHr9B1/oYftnHSmVCMHzJ8zrq8u Sszb0KrGpWQQahj+vp8mBgklNRraciFE+TEX1xZ17kC/j2dZ7DIX5W706OKGPWeThwn0 Qk3hdfXcEXBFeNAGRb1B5mJP518P9tnhYsKRQEvedopgGQyzIjdfBlOUM4iJOYCgh297 zagw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733690842; x=1734295642; 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=uydVfRix40VtM5XGFg4FP+2BbqHhhGYzjwg/+qRitoA=; b=UZQekQBBtmBdvOiSgQlSnYItNCwwn6Q2uMRBwlBOYMDRx6y610sfNkiXsm14pnxmff SQKxMggK+2M1IHgNe9fRDaGWYizlnat9lqSk29wmOhhf3eHHnA+sja3gJfFBcg8Nssl3 VTRq65Ac6rzOfFzAhzYNzwH8BG65ZO9i++gD043Qs/FIDNwtiy8fCUmsGq3zgzfkk3cC 40RCJKcfg1j/pQJ7X0UXLtb3Ub5MS/KJh7KwjfdHzUrU+yKYljSZP4rK4UsxNohGIV01 XKMFLWKHbmMus4dDiSrIzg8z9vB17UFcxixBolFtj0I0TExsD4SMYb24zbFGhka8dPou xc9g== X-Forwarded-Encrypted: i=1; AJvYcCUB1/WQWoODc89OMImGJoKAsldBSK8n6EhHwvkBlFFOg+RBJtxMNbZcrgJyDybsfqVPAQ5xay7zpw==@kvack.org X-Gm-Message-State: AOJu0YwkJ+8/Ob2VPIEaHdWn0ed7405Na2cJBdeVJbT73Y2iN8HHaKwM YHXwEOFR3D8G08Hq8Ows4s3zLEvieMyTnTzoRTCSvU9HusMEkYRD2ZaxcNoL X-Gm-Gg: ASbGncsL2So7U2OtAx6y2ANPK8umvBoWLiSUETiNeCEA0C8XrAS1C/5pnQlLuti9/wc NohVXu1HDC9pEB1EFZ7MsuHwuXpmUF+zzbqK8JBRCdTE1RoZEFC3RSgjmituWD3EwQFVW89NZ2R KZVwDWSeLvRJxmWMWX1ONTJ0XG2dQTnXPycVGR04wRzRerfc40+Vsjk2tIJ9JyZ/0YWZ55ROXkx mpPJlTUY6/edzv3zaijNNJODWC5APcGJD40/MWUMrtlVLOlUleTXQzkNYw= X-Google-Smtp-Source: AGHT+IHFzU3im506LwOrHouMZuWAgeUYsws5o5LtVKTrGik4PmUi+r8oEAGSFnNWQi82Ax6AF2zxOw== X-Received: by 2002:a05:600c:1909:b0:434:f586:753c with SMTP id 5b1f17b1804b1-434f5867ecemr15873445e9.7.1733690842202; Sun, 08 Dec 2024 12:47:22 -0800 (PST) Received: from localhost.localdomain ([46.248.82.114]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3861f59cc6fsm10874975f8f.34.2024.12.08.12.47.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Dec 2024 12:47:21 -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 , Dan Carpenter , "H . Peter Anvin" , Peter Zijlstra Subject: [PATCH v3 0/6] Enable strict percpu address space checks Date: Sun, 8 Dec 2024 21:45:15 +0100 Message-ID: <20241208204708.3742696-1-ubizjak@gmail.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 841DC180004 X-Stat-Signature: k5f1f1ke5hko3hptum9qggrfr86k16df X-Rspam-User: X-HE-Tag: 1733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YQbyo/zOTZJ5EUnr49tnr6M7vIm4tH9HxdtlzXwMNRSD8tTg7gGBrr8gJ2Fnmks4wyqCUeACXxife7wzrwgOyoVcAM3qSbmGS2Ns3ZiaIDPy/HGXRgikQRJXEZY9bPkVSM4QmGAnEHFptiE35Z6moX6J2Zygqt66xP5RbtlSKKcVTyh/sMBp1r7oPN0kOJ84YIAXgz/a8NNYNi9vFaoQJYf7WTJbTeyyWS7x8WLRRPSCyDR97xsiO3PNSj0ysDiZEa1meGki7o7ZMsoqICsf1fCLPR0tVPv+yJtf2/8l9akZ1MgLsg3THPDoo3yj80aJK6Gzy43Ni6wM1hVgkv4JLBSoyp7ohLnoyKXTv5w1QXKkN4bvLqzZfc500ByfTANtQfMkCFTc+lY3Tz42D6SoCn2S6D1H91/iOd/89hzSjDd4P/YFSmaNv2S3na53W1X5gG387LBHCi779q4duPWZQ7EfYei1Ukm+6N9qoLMyqDCKcVVaJJ8QF+ceGXIawsOtcfEGKO095wTVAJO+Bt3mC7//dweMONqQ9rL6ce7Y2FOslY3ZExs2xZ2RrnRwbkWWW5u1v0Q0Jp3t3joQkGKClTOxFiqq9pCNj0RHrlkg0WC8BG5XWfAADKov6WI8e9H3Edoo46+joDi0zez/nQ6ngYPiV62MygsabcH7z4UiUN+140zEbwy0VinQ0Y2WSzLrP3xmtpfFmvegvLRlHCTw== 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. 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: 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 | 38 ++++++++++++++++++++++++--------- arch/x86/kernel/kgdb.c | 2 +- fs/bcachefs/util.h | 2 +- include/asm-generic/percpu.h | 39 ++++++++++++++++++++++------------ 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, 82 insertions(+), 36 deletions(-) Acked-by: Dennis Zhou