From patchwork Mon Aug 12 11:57:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uros Bizjak X-Patchwork-Id: 13760451 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 743A5C52D7F for ; Mon, 12 Aug 2024 12:00:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 184ED6B0098; Mon, 12 Aug 2024 08:00:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 10BB26B009A; Mon, 12 Aug 2024 08:00:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EBAFA6B0098; Mon, 12 Aug 2024 08:00:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id CA5A46B008C for ; Mon, 12 Aug 2024 08:00:03 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 75808A8A1B for ; Mon, 12 Aug 2024 12:00:03 +0000 (UTC) X-FDA: 82443449886.16.794D22B Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) by imf23.hostedemail.com (Postfix) with ESMTP id 91264140033 for ; Mon, 12 Aug 2024 12:00:01 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=jfmgsZgA; spf=pass (imf23.hostedemail.com: domain of ubizjak@gmail.com designates 209.85.218.41 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=1723463933; 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:in-reply-to:references:references:dkim-signature; bh=efqfVk4wKUu5y2Eyqs3KUsdZhsPQcKGa1y+niD5IcF0=; b=wCPTf1l+B/YsK1vOBSItnOuksOqfqsH6orgMUDyq/lhRl8DB1s+G8TdjhTpFf5aIj0RMfp DPnjbXS6iTS9RaHVf4R28MwWt5sS91vC/3gt6a13alT648vcOP7cWIZaO+C3p11T4eCU78 s3GNmxDDNjtmXEugtxq5TEOPgyzq9Xc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723463933; a=rsa-sha256; cv=none; b=t5ZfWtdosUtRmGYAPm5p4AFbBv54zNw4rGYSwbCpAugTf/Xl44E1V3A9AIgJBRW30K2WBN m02i/sTwMPnARw+1NGpthrlUaRUu2fx8LZDGu0zEDECgBsDyHvrvaCwyJq8srZ1MBfhSgn nBEkJmnMjsJ6hQINdo12ZE/Z5QhCNN4= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=jfmgsZgA; spf=pass (imf23.hostedemail.com: domain of ubizjak@gmail.com designates 209.85.218.41 as permitted sender) smtp.mailfrom=ubizjak@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-a7d638a1f27so145922566b.2 for ; Mon, 12 Aug 2024 05:00:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723463999; x=1724068799; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=efqfVk4wKUu5y2Eyqs3KUsdZhsPQcKGa1y+niD5IcF0=; b=jfmgsZgARIXY3RuWcMO7oJLlRlYvcLYEx1i0yeHP5J8Z/s3V4rRM8vK1NLnS5B3+b8 wQnHgbHwifBpJtzZhuFFPVAj7QUJqAPPuMKOcfpOpvcQa/KWfd+dz4eJ9ZKbx++w6nVI mvCHsWObKw+PJ/Si0ZGEIIKgFFfvPENsrZfaycVjTQGEZzB4skvbeUJHhRmOUuB9BOv+ 5YvX/Pgddw3DpuP7nPqOIkClpGF5SDpDbvuAgmynlMt+P+FZSvxY1xSkxSIfi4C+1nAC ar/7lAzz6NwSeugApiNmJinCqRPFutZTH1141p0u6LDg5bXJHmgsjqjHgXBLyZXvkxaD 9drg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723463999; x=1724068799; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=efqfVk4wKUu5y2Eyqs3KUsdZhsPQcKGa1y+niD5IcF0=; b=rqy6ZI/BtOoRhzov9trd72VK3TuwkT42pXArUVQzBAof9rVAoZFUnJCCFyY1r+xHi9 v0A08aZ9GfUrtdhARk52+jkyvsmSwbD+FfMqvBFCSM0HkcPWsPNhpBn7ifAwHLZTPzs2 UfPkRiz+eoirXXlVuu8bExYrMh9oCJh3+BCOH95G0G4CVZELdZ6Tfm/kShkLkhZrFJPs OQb6UAGyIh2gBoKktxxv6948OpUA32O+ZxFplfxWmb/WBw4C2xehswWvzvoCuMnro7Jy SkRFGFbGn5c8YNGL0yPglh2GU0QbuWZ3d7ohrfOns3lQNvD6whP+b74rxCnOAmzUO3gH p52w== X-Gm-Message-State: AOJu0Yy86PcZcI8DQ0qlqbEv5/eN95BDp9LaeJ+4HzO8PB5UVE1bDq+k i+Gu9Lt24rfp/ZcvLnO1QD2NQrq3XvoUcYR+KgIne/ugZCBAzgmbzVieR+fgHw4= X-Google-Smtp-Source: AGHT+IGiz6BT46LDWsI4Kfhh8bbjUUZbNV/Nqu7ImfCdRuAQ78vk+RWaGtts3dHDU6gbsnhG/C8MMg== X-Received: by 2002:a05:6402:2347:b0:57d:669:caf2 with SMTP id 4fb4d7f45d1cf-5bd44c66b08mr14452a12.25.1723463999358; Mon, 12 Aug 2024 04:59:59 -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.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Aug 2024 04:59:58 -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 2/4] percpu: Assorted fixes found by strict percpu address space checks Date: Mon, 12 Aug 2024 13:57:36 +0200 Message-ID: <20240812115945.484051-3-ubizjak@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240812115945.484051-1-ubizjak@gmail.com> References: <20240812115945.484051-1-ubizjak@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 91264140033 X-Stat-Signature: 53qqry68cegqkj4fdy5i3w1jnkzx54hi X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1723464001-934196 X-HE-Meta: U2FsdGVkX18iA74+WGbVZjt0b6NjpNdlflehhOG6D2Wt43TMiWZSgKsM1LkBeZObqAhm0AIRCKdkbsMc79r/peb0cXknN/wBtRozplq8hAU/YKguBndnay+vtXEG5G32UCcBMdRm+ju8M72upOsGcIHCISSLU2/75qQkIP/+W9KKrSVT4rWSFtgZq1P72Ku7cOm9zDf2UHNcRSI6sPRKdUTHfBuHF0XLhZRpOsh17DXyYfuG4HPXFNtWL35BjpoqzrgOFbbgsaQXOkmJEeqosNqMdjWr3UFHTHa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2PD1P/PZB8h7YA+AkUI00yTnFTngAVq6xZkdoDdZdZ3tT8G7P6D4GcLVD2wJZ2QH0yMH68j6vEYQcpgWWRBT0n947fB7OSLz4TCkYeu7FAlZB6n4+XAldPgvH2IBkbiuAqD28ggEifPkQKFilI3lo8zzlwNfF09XNVH83+yKQ1IocZb3LhpmVaxeukZX1CMnXOhNShrmB5u7Px/FA6yvQbPLZFTjCSj1uIlr2UJa8yICbXEIRhbJiTBsoA48c4I0i9rDU46mKri5ZmQp07hwMy90qgwJ7AxjHCyohY6T3gJ35Yz94WzpfyTcf9tyQdfoPCnHqVfcA8KCy6kr9DahAkd5lRYCVov9zIfwNB2gVeAy/m05TuCETd9V52a0c= 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: Assorted fixes to prevent defconfig build failures when strict percpu address space checks will be enabled. These show effeciveness of strict percpu address space checks. Signed-off-by: Uros Bizjak 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 --- arch/x86/kernel/head64.c | 3 ++- drivers/base/devres.c | 2 +- fs/aio.c | 2 +- include/linux/cleanup.h | 4 ++-- include/linux/prandom.h | 1 + kernel/events/hw_breakpoint.c | 4 ++-- kernel/workqueue.c | 2 +- lib/percpu_counter.c | 2 +- net/core/dev.c | 2 +- 9 files changed, 12 insertions(+), 10 deletions(-) diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c index a817ed0724d1..f5d6ad351cc4 100644 --- a/arch/x86/kernel/head64.c +++ b/arch/x86/kernel/head64.c @@ -560,9 +560,10 @@ void early_setup_idt(void) void __head startup_64_setup_gdt_idt(void) { void *handler = NULL; + struct desc_struct *gdt = (struct desc_struct *)(uintptr_t)init_per_cpu_var(gdt_page.gdt); struct desc_ptr startup_gdt_descr = { - .address = (unsigned long)&RIP_REL_REF(init_per_cpu_var(gdt_page.gdt)), + .address = (unsigned long)&RIP_REL_REF(*gdt), .size = GDT_SIZE - 1, }; diff --git a/drivers/base/devres.c b/drivers/base/devres.c index a2ce0ead06a6..894f5a1e6d18 100644 --- a/drivers/base/devres.c +++ b/drivers/base/devres.c @@ -1231,6 +1231,6 @@ void devm_free_percpu(struct device *dev, void __percpu *pdata) * devm_free_pages() does. */ WARN_ON(devres_release(dev, devm_percpu_release, devm_percpu_match, - (__force void *)pdata)); + (__force void *)(uintptr_t)pdata)); } EXPORT_SYMBOL_GPL(devm_free_percpu); diff --git a/fs/aio.c b/fs/aio.c index 6066f64967b3..e8920178b50f 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -100,7 +100,7 @@ struct kioctx { unsigned long user_id; - struct __percpu kioctx_cpu *cpu; + struct kioctx_cpu __percpu *cpu; /* * For percpu reqs_available, number of slots we move to/from global diff --git a/include/linux/cleanup.h b/include/linux/cleanup.h index d9e613803df1..f7e1158cbacf 100644 --- a/include/linux/cleanup.h +++ b/include/linux/cleanup.h @@ -154,7 +154,7 @@ static inline class_##_name##_t class_##_name##ext##_constructor(_init_args) \ #define DEFINE_GUARD(_name, _type, _lock, _unlock) \ DEFINE_CLASS(_name, _type, if (_T) { _unlock; }, ({ _lock; _T; }), _type _T); \ static inline void * class_##_name##_lock_ptr(class_##_name##_t *_T) \ - { return *_T; } + { return (void *)(uintptr_t)*_T; } #define DEFINE_GUARD_COND(_name, _ext, _condlock) \ EXTEND_CLASS(_name, _ext, \ @@ -211,7 +211,7 @@ static inline void class_##_name##_destructor(class_##_name##_t *_T) \ \ static inline void *class_##_name##_lock_ptr(class_##_name##_t *_T) \ { \ - return _T->lock; \ + return (void *)(uintptr_t)_T->lock; \ } diff --git a/include/linux/prandom.h b/include/linux/prandom.h index f7f1e5251c67..f2ed5b72b3d6 100644 --- a/include/linux/prandom.h +++ b/include/linux/prandom.h @@ -10,6 +10,7 @@ #include #include +#include #include struct rnd_state { diff --git a/kernel/events/hw_breakpoint.c b/kernel/events/hw_breakpoint.c index 6c2cb4e4f48d..d82fe78f0658 100644 --- a/kernel/events/hw_breakpoint.c +++ b/kernel/events/hw_breakpoint.c @@ -849,7 +849,7 @@ register_wide_hw_breakpoint(struct perf_event_attr *attr, cpu_events = alloc_percpu(typeof(*cpu_events)); if (!cpu_events) - return (void __percpu __force *)ERR_PTR(-ENOMEM); + return (void __percpu __force *)(uintptr_t)ERR_PTR(-ENOMEM); cpus_read_lock(); for_each_online_cpu(cpu) { @@ -868,7 +868,7 @@ register_wide_hw_breakpoint(struct perf_event_attr *attr, return cpu_events; unregister_wide_hw_breakpoint(cpu_events); - return (void __percpu __force *)ERR_PTR(err); + return (void __percpu __force *)(uintptr_t)ERR_PTR(err); } EXPORT_SYMBOL_GPL(register_wide_hw_breakpoint); diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 1745ca788ede..32729a2e93af 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -377,7 +377,7 @@ struct workqueue_struct { /* hot fields used during command issue, aligned to cacheline */ unsigned int flags ____cacheline_aligned; /* WQ: WQ_* flags */ - struct pool_workqueue __percpu __rcu **cpu_pwq; /* I: per-cpu pwqs */ + struct pool_workqueue __rcu * __percpu *cpu_pwq; /* I: per-cpu pwqs */ struct wq_node_nr_active *node_nr_active[]; /* I: per-node nr_active */ }; diff --git a/lib/percpu_counter.c b/lib/percpu_counter.c index 51bc5246986d..3d0613ac7e73 100644 --- a/lib/percpu_counter.c +++ b/lib/percpu_counter.c @@ -209,7 +209,7 @@ int __percpu_counter_init_many(struct percpu_counter *fbc, s64 amount, INIT_LIST_HEAD(&fbc[i].list); #endif fbc[i].count = amount; - fbc[i].counters = (void *)counters + (i * counter_size); + fbc[i].counters = (void __percpu *)counters + (i * counter_size); debug_percpu_counter_activate(&fbc[i]); } diff --git a/net/core/dev.c b/net/core/dev.c index 751d9b70e6ad..5cad88cf029c 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -10860,7 +10860,7 @@ noinline void netdev_core_stats_inc(struct net_device *dev, u32 offset) return; } - field = (__force unsigned long __percpu *)((__force void *)p + offset); + field = (unsigned long __percpu *)(void __percpu *)(p + offset); this_cpu_inc(*field); } EXPORT_SYMBOL_GPL(netdev_core_stats_inc);