From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3D56C4167B for ; Mon, 4 Dec 2023 21:03:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233754AbjLDVDZ (ORCPT ); Mon, 4 Dec 2023 16:03:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231171AbjLDVDY (ORCPT ); Mon, 4 Dec 2023 16:03:24 -0500 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FD4BAA for ; Mon, 4 Dec 2023 13:03:30 -0800 (PST) Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-3333074512bso2029080f8f.1 for ; Mon, 04 Dec 2023 13:03:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701723809; x=1702328609; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=U/WOpD6r5y0Ok3tYpWvI/WXVRtBKW+2PA57aZ1Qk9dM=; b=eISlS4nc6Ls4YF409KOga3qngwtTYbPNvk0NJEi1wGAqFij9pH90cnR3jMyVFTkCO7 VUtgDM7rOhOsmH64zJMoABAwH1iPEfoQj4DW0SCmZrNPcNV6OeymamR9gwcq7WcSSAL5 I5KzHpMd51JIkV9eDEmqLt7Za6y6tmyGKOBtaVM5vYhZvl5XL227ohhgf4sSVJ7muEzS jQwFqX6rljtDhK3pyrJQAUhsSeeCjCe9dFSBNiWNvPu/2jthyfC/aF1maKecUHgV8HKe mpk+eDAXQAmcuNsjDCm/LqctfZgIwkb8/us6311B81QLCTG7Zs8tLdeb0lGhheH5bC/v wsrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701723809; x=1702328609; 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=U/WOpD6r5y0Ok3tYpWvI/WXVRtBKW+2PA57aZ1Qk9dM=; b=Obhv0MYqwnKgBwjP7YMOcHKat0AFFiEgHOLF+fRrYHxD24vTSueF64V0efQ5Q2vcKf LBWUyYPDrXlqKdCxsNynqjFA4D9hbBD99ja7f6TPIhUIUmlLrlOxFvyXVXsjSKnsRcoX Ak5QJcO/1xZkMTUgLjDGpNfS9re6OeCICGVtFtPq3IqbuvhP7ZZr5WhEKYIeVfJAYYY2 FeQ5fyUy6nF8kaexTZ4FmgA0BiYxeH4gKopJGQLYfNqKbrlRT1nBHsZ3m0+iW8/KR5WS bgXqmuurBZXuO2hP/7TNcZ870zTNfSDhXl3qcfyfCB8INh6UBX7GVRSnP8PR6bDP/yTl 3TJg== X-Gm-Message-State: AOJu0YxSLcORU2OArH3/Io2r/auL6A2Krck//9l4F0mkTAUAK74UZK0M N6XkslwwP2vXrR3VrtUkNNhS94tFPNWpGgvE X-Google-Smtp-Source: AGHT+IFpNzTBjUKSQO/vP55D8BC/OsIV+NGib9MAOI5fywwZE//8VYDwFEAC3RiLpk4AIT9KfrLPYA== X-Received: by 2002:a05:600c:19d2:b0:40b:5e4a:235e with SMTP id u18-20020a05600c19d200b0040b5e4a235emr3218429wmq.96.1701723808650; Mon, 04 Dec 2023 13:03:28 -0800 (PST) Received: from localhost.localdomain ([46.248.82.114]) by smtp.gmail.com with ESMTPSA id b18-20020a05600c4e1200b0040c08567bbfsm7414815wmq.17.2023.12.04.13.03.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 13:03:28 -0800 (PST) From: Uros Bizjak To: x86@kernel.org, linux-kernel@vger.kernel.org Cc: Uros Bizjak , Andy Lutomirski , Brian Gerst , Denys Vlasenko , Ingo Molnar , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Thomas Gleixner , Josh Poimboeuf Subject: [PATCH -tip v3 1/3] x86/percpu: Fix "const_pcpu_hot" version generation failure Date: Mon, 4 Dec 2023 22:02:29 +0100 Message-ID: <20231204210320.114429-1-ubizjak@gmail.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Version generation for "const_pcpu_hot" symbol failed because genksyms doesn't know the __seg_gs keyword. Revert commit 4604c052b84d "x86/percpu: Declare const_pcpu_hot as extern const variable" and use this_cpu_read_const instead to avoid "sparse: dereference of noderef expression" warning when reading const_pcpu_hot. Cc: Andy Lutomirski Cc: Brian Gerst Cc: Denys Vlasenko Cc: Ingo Molnar Cc: H. Peter Anvin Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Josh Poimboeuf Signed-off-by: Uros Bizjak --- v2: Use BUILD_BUG() instead of BUG(). --- arch/x86/include/asm/current.h | 5 +++-- arch/x86/include/asm/percpu.h | 7 +++++++ arch/x86/include/asm/processor.h | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/asm/current.h b/arch/x86/include/asm/current.h index 9fbd7cb2dc86..c8c5674d69f6 100644 --- a/arch/x86/include/asm/current.h +++ b/arch/x86/include/asm/current.h @@ -37,12 +37,13 @@ static_assert(sizeof(struct pcpu_hot) == 64); DECLARE_PER_CPU_ALIGNED(struct pcpu_hot, pcpu_hot); /* const-qualified alias to pcpu_hot, aliased by linker. */ -extern const struct pcpu_hot __percpu_seg_override const_pcpu_hot; +DECLARE_PER_CPU_ALIGNED(const struct pcpu_hot __percpu_seg_override, + const_pcpu_hot); static __always_inline struct task_struct *get_current(void) { if (IS_ENABLED(CONFIG_USE_X86_SEG_SUPPORT)) - return const_pcpu_hot.current_task; + return this_cpu_read_const(const_pcpu_hot.current_task); return this_cpu_read_stable(pcpu_hot.current_task); } diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h index 0f12b2004b94..3859abad19ec 100644 --- a/arch/x86/include/asm/percpu.h +++ b/arch/x86/include/asm/percpu.h @@ -28,6 +28,7 @@ #else /* ...!ASSEMBLY */ +#include #include #include @@ -462,6 +463,7 @@ do { \ #define this_cpu_write_8(pcp, val) __raw_cpu_write(volatile, pcp, val) #endif +#define this_cpu_read_const(pcp) __raw_cpu_read(, pcp) #else /* CONFIG_USE_X86_SEG_SUPPORT */ #define raw_cpu_read_1(pcp) percpu_from_op(1, , "mov", pcp) @@ -486,6 +488,11 @@ do { \ #define this_cpu_write_8(pcp, val) percpu_to_op(8, volatile, "mov", (pcp), val) #endif +/* + * The generic per-cpu infrastrucutre is not suitable for + * reading const-qualified variables. + */ +#define this_cpu_read_const(pcp) ({ BUILD_BUG(); (typeof(pcp))0; }) #endif /* CONFIG_USE_X86_SEG_SUPPORT */ #define raw_cpu_add_1(pcp, val) percpu_add_op(1, , (pcp), val) diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h index 061aa86b4662..1188e8bf76a2 100644 --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -534,7 +534,7 @@ static __always_inline unsigned long current_top_of_stack(void) * entry trampoline. */ if (IS_ENABLED(CONFIG_USE_X86_SEG_SUPPORT)) - return const_pcpu_hot.top_of_stack; + return this_cpu_read_const(const_pcpu_hot.top_of_stack); return this_cpu_read_stable(pcpu_hot.top_of_stack); } -- 2.42.0