From patchwork Mon Aug 12 11:57:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uros Bizjak X-Patchwork-Id: 13760450 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 16E9BC3DA7F for ; Mon, 12 Aug 2024 12:00:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8A1FB6B008A; Mon, 12 Aug 2024 08:00:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 852136B008C; Mon, 12 Aug 2024 08:00:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 719836B0092; Mon, 12 Aug 2024 08:00:03 -0400 (EDT) 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 533B66B008A for ; Mon, 12 Aug 2024 08:00:03 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id A3C871A1D7B for ; Mon, 12 Aug 2024 12:00:02 +0000 (UTC) X-FDA: 82443449844.28.F654B49 Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) by imf01.hostedemail.com (Postfix) with ESMTP id D7DFE40014 for ; Mon, 12 Aug 2024 11:59:59 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=jPhSdbCc; spf=pass (imf01.hostedemail.com: domain of ubizjak@gmail.com designates 209.85.208.49 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=1723463907; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=oRKx9dZX3QjMkF5miIckcLbQZtgikNx/maL4/UrUqR8=; b=e3vVz/b+5oTorOFWm3tWqwebYU6mjeOvMwhu9sCa2MVHF4OE75SiCTIq2veBW22Pbv2ZVP SFNmt7urWFtNGfKoBPnI7Q+sl8nuH6yAPa6t5jfUuL6kjV2eYJ2yYo8JBFea3kDMSCEcYM Ld4yoWtHEpHPAitrUM849fbeGETT4iQ= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=jPhSdbCc; spf=pass (imf01.hostedemail.com: domain of ubizjak@gmail.com designates 209.85.208.49 as permitted sender) smtp.mailfrom=ubizjak@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723463907; a=rsa-sha256; cv=none; b=xUzKuBxm+I06gDapiq4LlC1WkWOB7PEA/WIgF6hzuaBs6/xwrYQC3wiRIVjqHmPInFXRJK 8Gqzeaj8OTOWSjLnGFCDmKQMoUhsSF1sNvi/j/V6v2I250vzwgLJpbiBtHtlREH4XxI2Ab gf99sR2GusQS4wsbrL8B/mKwEFJJqbI= Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-5af51684d52so4641139a12.1 for ; Mon, 12 Aug 2024 04:59:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723463998; x=1724068798; 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=oRKx9dZX3QjMkF5miIckcLbQZtgikNx/maL4/UrUqR8=; b=jPhSdbCcbnXJFluprWuXcFTY9kYBNcr9PrLsVRDnYAQJB/IVRdohOh870hM1EV8RIh kiHNzOShuC7dVQGsH3QschzOwU1JmuE6lWqrS56oKunCMoWZMeFy2udmdOTXqz6ReQwM QkvhnSdYpbKS5rK94vAdgU2lvbZ2vLeAAOp2nmfnSw6dEyIQc+R2zlIFcJnM70dbm26m XFLm7CfbJ/V8M5H/HKOh6z6SsVTcUqeXFZlkWvI/bGCSajM9CcQ3jwPTAwMGyZVA8Q0d CLHNFxBG3Cdho2Ylg/S1JQ2O6CP+FdLIptij3I29CgkZyHst5YASYHmvjAF3DC2uXX+J zzyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723463998; x=1724068798; 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=oRKx9dZX3QjMkF5miIckcLbQZtgikNx/maL4/UrUqR8=; b=cIqkKHgoUGlQFLgrNflAVgd8IBRvbPlZdcWDwTtS7UR5aMGnw6qXrXElCPnBIxKv+P Hn+eExfOJTbXz5B3hG1xmt4ooAk1xSrN4mgx2C33cts52dmO/LqDqRnNVHf/CTZ0DBd5 tOlF4K0WxPh9THdzl0/eOlLY+MGeDfKkLHfBaM9iH6JHIaHTXhevp3wth3Y+wnQUUZMw Lmr1k9G3NeFjXHdDUsHma5lNGP2fDAtQChc8fRopD7sDKX2WAP20Dmif4iYDsCN8Hhk2 kZ1hLJ6xyWBGJRP79jIiNC5AqEfWsi+audrwk6sYSNAB+nmTGdaobuTx4ehAemT9rdki nWKg== X-Gm-Message-State: AOJu0Yxn8crItw77rek6HFYkBEUjGVNN796icSbuaoN5+sq6ClpZNwwh VK5zhotGzF70amTiPgardLfZaI9aG77Fsg9pSW+ORimIOINE3ZlaiFTOK0C9UTU= X-Google-Smtp-Source: AGHT+IHgH1TDpiQShSgpot1VvJxvHAYo32/du5ZSHtZ10/tza/HQdHkI7tdD0Hqt2qPFzIpMIKDXEw== X-Received: by 2002:a05:6402:5ca:b0:5a2:abcb:c4d1 with SMTP id 4fb4d7f45d1cf-5bd44c77743mr9130a12.34.1723463997238; Mon, 12 Aug 2024 04:59:57 -0700 (PDT) Received: from fedora.iskraemeco.si ([193.77.86.250]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5bd1a5e04aesm2055970a12.76.2024.08.12.04.59.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Aug 2024 04:59:56 -0700 (PDT) From: Uros Bizjak To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Uros Bizjak , Dennis Zhou , Tejun Heo , Christoph Lameter , Andy Lutomirski , Ingo Molnar , Nadav Amit , Brian Gerst , Denys Vlasenko , "H. Peter Anvin" , Linus Torvalds , Peter Zijlstra , Thomas Gleixner , Borislav Petkov , Luc Van Oostenryck Subject: [RFC PATCH v2 0/4] Enable strict percpu address space checks Date: Mon, 12 Aug 2024 13:57:34 +0200 Message-ID: <20240812115945.484051-1-ubizjak@gmail.com> X-Mailer: git-send-email 2.46.0 MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: D7DFE40014 X-Stat-Signature: zgrbb6gaiqquboykkpb88wudzajhy4ff X-Rspam-User: X-HE-Tag: 1723463999-338180 X-HE-Meta: U2FsdGVkX1+lEqfVkI4eTtxhUC7lskDIwXVofTzhFwZ2UeG+WkloVrbBB+4HuW5PfK0dScwjkLyFQ9IutnR7PoXcP2TUKoRNZKIa4BnLtHVf3TIBaRuDVo3is7ANwQFCiiGgqpjkCMtQCvsnf9rZqNhorvDRqnAkdUG/l6I+3TpqfCRdHOaaB9uhT9jtAArrz4O9WBouB6eNWChFJNZvmCsurA7JiNGL+Ueb4PW5nXD1DR4ha3V5IQ+2UpnOEz+UKFW8koHojozgoZ61b7mhyJ2+qO2ow1vxMmsYiPRn7A010qMyOKx+J3RHXPwRG3mtQY92xaDldSWd4rUDFFf+umI9LAmka7XX3AlmK2DPm9MPy62YUYgeN4V2lUcbIET5ZHjuK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um7WUWwznAzqiluWX/SO+/bfUey7TK5BHnA9RIN8aNAtK1jbhz6LeADUTVAVTO2caotUTZNMC5USNzlNAXObS9mKLHZS8iwRIi07PtGt6peIYvLOqhW5jA8fDWgZdVYAwQYYTNeWZ46PWGGctKu7Q8N7ocP8K5fq+lUbTSLpTaltZeMpvJ26bQxP2cbcVJxgUKPmEcFyKzX7J0mMrH6JBjz7+bpQ8EwicNlnwWYkx5JBzhBCg4Hq/38Uqn7v1LUCdbSTXMcgOnLw6L2uDqzVuKrh21lw9DsPpW1XVicCT50o0XknkanyeIHtMSg== 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 sparse doesn't know anything about __typeof_unqual__() operator, so the usage of __typeof_unqual__() breaks sparse checking. Cc: Dennis Zhou Cc: Tejun Heo Cc: Christoph Lameter Cc: Andy Lutomirski Cc: Ingo Molnar Cc: Nadav Amit Cc: Brian Gerst Cc: Denys Vlasenko Cc: H. Peter Anvin Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Borislav Petkov Cc: Luc Van Oostenryck Uros Bizjak (4): percpu: Define pcpu_typeof() percpu: Assorted fixes found by strict percpu address space checks 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 | 53 ++++++++++++++++++++++++---------- arch/x86/kernel/head64.c | 3 +- drivers/base/devres.c | 2 +- fs/aio.c | 2 +- include/asm-generic/percpu.h | 41 +++++++++++++++++--------- include/linux/cleanup.h | 4 +-- include/linux/compiler_types.h | 2 +- include/linux/part_stat.h | 2 +- include/linux/percpu-defs.h | 39 ++++++++++++++++++++----- include/linux/prandom.h | 1 + init/Kconfig | 3 ++ kernel/events/hw_breakpoint.c | 4 +-- kernel/locking/percpu-rwsem.c | 2 +- kernel/workqueue.c | 2 +- lib/percpu_counter.c | 2 +- net/core/dev.c | 2 +- 16 files changed, 115 insertions(+), 49 deletions(-)