From patchwork Mon Aug 5 18:39:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uros Bizjak X-Patchwork-Id: 13753970 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 F13E7C3DA4A for ; Mon, 5 Aug 2024 18:40:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1A2326B0095; Mon, 5 Aug 2024 14:40:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0B44E6B0098; Mon, 5 Aug 2024 14:40:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D12686B0099; Mon, 5 Aug 2024 14:40:40 -0400 (EDT) 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 A8D656B0095 for ; Mon, 5 Aug 2024 14:40:40 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 4DD0D80437 for ; Mon, 5 Aug 2024 18:40:40 +0000 (UTC) X-FDA: 82419057840.19.F9A093F Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) by imf26.hostedemail.com (Postfix) with ESMTP id 60EAF140003 for ; Mon, 5 Aug 2024 18:40:38 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=IDjdspM0; spf=pass (imf26.hostedemail.com: domain of ubizjak@gmail.com designates 209.85.208.42 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=1722883177; 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=NvmD+ez0KqmrlVq3MNB02uXxyKID9fWAsFipmCLltBQ=; b=T+swfzbu2scD2gdLDsD7pi7bXuZdEIGWQfROfig55bLFqpWPd1Y6WnIBdfGcSFvGv9+EGt 9oDh8cCE+hEl3lUWYqrKxM9P8NX4KjvCl9mBLEeSxyC60qbTr9cJm65YZY2KZE33LHNA9P srgASXCtylbTmncHinp8QHPEjdA1BPg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722883177; a=rsa-sha256; cv=none; b=RdrOuzzjp44nKeTjFx5g8LTc+6W5cLLYwjrq1Kt6ujdhDkiQkqopOISGUjc29KRmDtKizh JrJKLqNFywz88kZhAOnjvONiZdZGFLM7USEYckN4IME5a89YiJ0DZ8PWEUAEDORcIlqnq1 4F0uXl1v/J2P1W3aOKfIuGgdcVJ8DUU= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=IDjdspM0; spf=pass (imf26.hostedemail.com: domain of ubizjak@gmail.com designates 209.85.208.42 as permitted sender) smtp.mailfrom=ubizjak@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-ed1-f42.google.com with SMTP id 4fb4d7f45d1cf-5af6a1afa63so12141626a12.0 for ; Mon, 05 Aug 2024 11:40:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722883236; x=1723488036; 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=NvmD+ez0KqmrlVq3MNB02uXxyKID9fWAsFipmCLltBQ=; b=IDjdspM07ccUO/YVKP7wBA4SwxCRf6WQjAjSIBHfckXgByy8J6AVvcYKbwLkfo+MPQ 4xhecVQpsN+KKSLLimfYPogZJSiuWpnFyRuG+3PCr/0Cx/wNyoIteVPf8++xB/GYF+4Z +fPNRBGSH8ysOagpGFKkeqQX7Pl3zsRzX2G4xVubqTnH6yApMFykxGoP/ABBDGyB+Ppu JsWblRBAUY4Kk/Bl9N80g4zzw6kogmV831Qum7wqF3gzbEsUek4RyhA0yoQbeE6M4NSq hzzIXDKb+vSmdT2qrdnlBhDlbgBwhx/k8Fs+5A1Jc7Iv5eMXtANbVWDY3+7EL4zQ5BD1 RJDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722883236; x=1723488036; 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=NvmD+ez0KqmrlVq3MNB02uXxyKID9fWAsFipmCLltBQ=; b=JSJRu1G/YipCYo5mIQjSRKRHkswbGhJGcKUWnx9QwQWYysMlJqys55OVkWvduhr42L vthD9GTSPsj23kwpxuEoQzE8awWrv6p4VWsGyXSn7x9RwfISsvROPIU5EvyBIXMki8HD 5i8k1xdOasmvGxLfBmYDEebF2id+eBz9TaqjI2/ELG/Y4oVYIc3LtLPzBVKjk2MmDZB8 /sB668hPZrS7DWd72cTeWgBE6VPiGgzYk+al7HEYSPGd+lzxGRM/8MLwuD5iRyDemjBK UGKBbjd49UjVaraHHjx4M5ncn3td1Xp/cECE+2jwBDnklHiP0NGQAHCsrdjM5hRRAF0b i6TQ== X-Gm-Message-State: AOJu0Yxr0cxhYkg7Y5jLzT5P5OeNikfX1WjkxgsBp6QG0U/gFcoC42e/ p0EUhsKwSFPDSEWI9jILnnmSHZ1rfQrE8sg1WCHGNPhA7r9Y8UK+bWNMDRjY X-Google-Smtp-Source: AGHT+IGT8P8MH8PUrIhAbGQwOI91FhpuTTEeBpD91PRfdIvScb2atdeUvkPb95VBGym8haoLNMyXMg== X-Received: by 2002:a17:907:c00f:b0:a7d:e956:ad51 with SMTP id a640c23a62f3a-a7de956af6dmr465965066b.21.1722883236392; Mon, 05 Aug 2024 11:40:36 -0700 (PDT) Received: from localhost.localdomain (93-103-32-68.dynamic.t-2.net. [93.103.32.68]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a7dc9c12ad3sm478517266b.88.2024.08.05.11.40.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Aug 2024 11:40:35 -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 2/3] percpu: Assorted fixes found by strict percpu address space checks Date: Mon, 5 Aug 2024 20:39:00 +0200 Message-ID: <20240805184012.358023-3-ubizjak@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240805184012.358023-1-ubizjak@gmail.com> References: <20240805184012.358023-1-ubizjak@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 60EAF140003 X-Stat-Signature: yr1yehu79yujaxq73qk15f4pmzm9yy4i X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1722883238-136315 X-HE-Meta: U2FsdGVkX18fSGL/04HEPT8ITUhhX1gWAGDesDXxWsVhCY7q647q9e4955y6Sp6ZO5U7JyqsuRkDJuM5+BsUfbNstbo+4IF1JA9Bv0W1+p/DVbAUAr+4ILh3uyufPn46ZebIIX1PQgUpACicxrZx86u0Uw/AFEJ4Q041xyo74gUGA3X1Cst7fyzMUAIdo3vugT18lsVAEtaor0ceR3DlE40Iio09EGHUaj5GsZPnlHCgKKP8ksDMCa/mNbiV5A6YunyM4k6+C2lRk7FLep/8/ZgpWQsjsJPZyW3VJm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6n1DKGMWauUSxnhfWakF81UUr1fszJ4yzFEjpKmZN8pS0TM3VGbeMlrrCmfRZNYn6m1cOSvabaicaOE1lvnsHCp/7DuW+nJOBEyWqRVfmbZn6sbrl9wZMxeqN/0TL3Ns4+rGDdupK67qoyQnwPCskz4yLU5mPtp+Z4ur5pY5D7Xhl4C9BVmvGdKVvZmOI5YViCh3auMr90ffW4RaIQYAJhMLPXFvHOqk+t6T8ySEzuVpnskWRr6JMCJvqO+6qXbGpNb+/v/oZtTplyLFMlazYWwyejKnCjvkZLVYK3A9Zo402Q1ZgD4hr/Ixz8reO4OLrt5TbxagoiuQmMjwjQWJPWRFIAClriu6Uas2mx7c= 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);