Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp350677lqe; Sat, 6 Apr 2024 04:08:19 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW57uWnQP9eMi/gaBmx/WwT7oKKR0erl7oxKo85S+fY633mZcqIrH6AUlywflO662DEfzgEZBeYH+N4F7mL5OHfutbvR1lmWm98NWrslQ== X-Google-Smtp-Source: AGHT+IF9Z+fgb7rFVBrPZwzSJ133KMv+FIatf8EYaJk2RSOOzVc0+hy7eIbDVI97iBpkR8s4pLdb X-Received: by 2002:a17:90a:7106:b0:2a2:47a2:9bba with SMTP id h6-20020a17090a710600b002a247a29bbamr3546421pjk.3.1712401699516; Sat, 06 Apr 2024 04:08:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712401699; cv=pass; d=google.com; s=arc-20160816; b=uZhPHR1NMrOKii8zGf4J+hJatZ/AKjvpwmCWb1tJXwntfrV55K0iN+bPwzsPE9T87i lMhJVmGppFLa4Qn/dkgBLpTQCmOAB+r+zEkc1kjeEDDkF4XXTLTnOt8GWjmMTo9fkdZJ MHYc/QSuwGNV5THXiG4f3doYR+DI83K8gPNSgUx+vdJCEtbT921w4htKKRldM+Y7aVaE /SusbgRsVQgNMlJeYefEnxt+5uyBrZ8W9RLPKusxDZy+v2Mp84BQ22xAhY06YxPSJf7H UIZLD0UtslmTfnf6rj68y5KwDrtFhuN7kBJHosLhc+BtN14x3RVXQqzqYaFrqafw6wuz Qbqg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:precedence:robot-unsubscribe:robot-id :message-id:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:in-reply-to:cc:subject:to:reply-to:sender :from:dkim-signature:dkim-signature:date; bh=s83HeeqehO4rlHoAz788hUzh9Pm7jM/NKUzLWyUOxU4=; fh=aMuEctUrpEjcm7+Z6FW9dcyBzbyQClfa+XesJRjdIVw=; b=IfJau+k2lK7b/UCySbqroL8BwGF5qJh6tpO9dpXP9kV/k5wO0Bq7qlKNNdI1hb+0eH moY5VrYucAeftm0q/EJVzIpec6nR/gMWD4CUJBdM6ZrduUW5tYbxhGKyYKPvIOUIZZlk V8pdp6fIgnkfmcwYqrz+D9UC5gxwmIoks7AY12sGZW+TdrzGC73wDT6A6Oe08lGKmvcw VM3hb8PnpjqwRQnFaVe7caYR6GycvhCh9XHDTq24XQ254MJA9kb87Mvi3Y1/sprninBT sdPRtJl6rdIB4e8OSV7zITKNQl8jvZ6aHCn4t6MwXsvjcn7ghcmSb9b1oqZOK4pxvM0b QMAQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=dJdH2x52; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-133898-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-133898-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id nr19-20020a17090b241300b002a2b221886csi2973638pjb.66.2024.04.06.04.08.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Apr 2024 04:08:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-133898-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=dJdH2x52; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-133898-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-133898-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 70549B21ABA for ; Sat, 6 Apr 2024 11:08:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7E53C2C856; Sat, 6 Apr 2024 11:08:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="dJdH2x52"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="r279CCgR" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D7D2124219; Sat, 6 Apr 2024 11:07:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712401681; cv=none; b=hxy1nX3uMJutNTnjUwxK8ho+pFTiWUomVdgiEYKPtT/8ysZskITeD5h5TnQUKlWkjUc8dGCVYfVunOjQSiztv/S37v9UWeqhdnS4GLh+GCgnGxP9zgQlGlQ84iK8SRlWXDwQ29ccJIZWT/JqjuF79Ox6z+Jx7A4qXuLVstq5aXA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712401681; c=relaxed/simple; bh=EtAvrxwb3wNLzH5Et72bsbOizcpLgTpxxUcMAYME1C0=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=F+nnPn3soKCadKmAKZ5yfYxx5+LpKpcEDyWerR7sZMIDdWWrLoRCEmu43Dlgz+PYjvrg6lNm5IgyL0vRgD/KNyoIRhC81k/vuGMyLlL4AP2jLBQ46FAodfd6IBvE2ZbDQSB+yezSvZCCLXkCMDRkdLxVQ8m9maQQEm3vgEOM85E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=dJdH2x52; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=r279CCgR; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Date: Sat, 06 Apr 2024 11:07:57 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1712401678; h=from:from:sender:sender:reply-to: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:in-reply-to:references:references; bh=s83HeeqehO4rlHoAz788hUzh9Pm7jM/NKUzLWyUOxU4=; b=dJdH2x52mdo+jUO0jUITsY0LdowAIdVw/uUsCiQT4YBvJI36DrTo/dwBnv01GRzb3vVmd9 +U8Vvq7FA7yqlH9lsLnw2oEh71rCXeonbOitO6/+VJlgrALzQ0xI/K1+chdbxhyFiXWDz3 Ok+dX4yS2b0nfXoAq0N63PjaALX8FEEwIVm6NjbHr1/8iVTj14lbinMCgmf5SO6ZQxD32Z Pwyh+pdl6STNIMygEHud0n5a5URZy/uwSySVtjqxO+PNtbSCxkqnyOn3kaGW2wZ3ky3Jn1 zq5zkhxQuLzv0/mFeE6AJQg4bSjoI+n77WQyLglriCsEz+MCvGupyFz4VN5JEA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1712401678; h=from:from:sender:sender:reply-to: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:in-reply-to:references:references; bh=s83HeeqehO4rlHoAz788hUzh9Pm7jM/NKUzLWyUOxU4=; b=r279CCgRzlsJp/y5bMeOdAiWfiPHi9wiplQ81H2iSzpAqaeckf8BSwf9g5ClRG2wFUb78U x1haHgRNFX2PGJBg== From: "tip-bot2 for Uros Bizjak" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/percpu] x86/percpu: Rewrite x86_this_cpu_test_bit() and friends as macros Cc: Uros Bizjak , Ingo Molnar , Linus Torvalds , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20240404094218.448963-2-ubizjak@gmail.com> References: <20240404094218.448963-2-ubizjak@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <171240167712.10875.8346272529060813426.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit The following commit has been merged into the x86/percpu branch of tip: Commit-ID: a3f8a3a2cf0b7b3ccb51ee60d51c0b5435c7135a Gitweb: https://git.kernel.org/tip/a3f8a3a2cf0b7b3ccb51ee60d51c0b5435c7135a Author: Uros Bizjak AuthorDate: Thu, 04 Apr 2024 11:42:02 +02:00 Committer: Ingo Molnar CommitterDate: Sat, 06 Apr 2024 12:42:17 +02:00 x86/percpu: Rewrite x86_this_cpu_test_bit() and friends as macros Rewrite the whole family of x86_this_cpu_test_bit() functions as macros, so standard __my_cpu_var() and raw_cpu_read() macros can be used on percpu variables. This approach considerably simplifies implementation of functions and also introduces standard checks on accessed percpu variables. No functional changes intended. Signed-off-by: Uros Bizjak Signed-off-by: Ingo Molnar Cc: Linus Torvalds Link: https://lore.kernel.org/r/20240404094218.448963-2-ubizjak@gmail.com --- arch/um/include/asm/cpufeature.h | 3 +-- arch/x86/include/asm/cpufeature.h | 3 +-- arch/x86/include/asm/percpu.h | 54 ++++++++++++------------------ 3 files changed, 25 insertions(+), 35 deletions(-) diff --git a/arch/um/include/asm/cpufeature.h b/arch/um/include/asm/cpufeature.h index 66fe06d..1eb8b83 100644 --- a/arch/um/include/asm/cpufeature.h +++ b/arch/um/include/asm/cpufeature.h @@ -38,8 +38,7 @@ extern const char * const x86_bug_flags[NBUGINTS*32]; #define this_cpu_has(bit) \ (__builtin_constant_p(bit) && REQUIRED_MASK_BIT_SET(bit) ? 1 : \ - x86_this_cpu_test_bit(bit, \ - (unsigned long __percpu *)&cpu_info.x86_capability)) + x86_this_cpu_test_bit(bit, cpu_info.x86_capability)) /* * This macro is for detection of features which need kernel diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h index 42157dd..cd4c02d 100644 --- a/arch/x86/include/asm/cpufeature.h +++ b/arch/x86/include/asm/cpufeature.h @@ -127,8 +127,7 @@ extern const char * const x86_bug_flags[NBUGINTS*32]; #define this_cpu_has(bit) \ (__builtin_constant_p(bit) && REQUIRED_MASK_BIT_SET(bit) ? 1 : \ - x86_this_cpu_test_bit(bit, \ - (unsigned long __percpu *)&cpu_info.x86_capability)) + x86_this_cpu_test_bit(bit, cpu_info.x86_capability)) /* * This macro is for detection of features which need kernel diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h index cbfbbe8..d6ff0db 100644 --- a/arch/x86/include/asm/percpu.h +++ b/arch/x86/include/asm/percpu.h @@ -96,7 +96,7 @@ #endif /* CONFIG_SMP */ #define __my_cpu_type(var) typeof(var) __percpu_seg_override -#define __my_cpu_ptr(ptr) (__my_cpu_type(*ptr)*)(__force uintptr_t)(ptr) +#define __my_cpu_ptr(ptr) (__my_cpu_type(*(ptr))*)(__force uintptr_t)(ptr) #define __my_cpu_var(var) (*__my_cpu_ptr(&(var))) #define __percpu_arg(x) __percpu_prefix "%" #x #define __force_percpu_arg(x) __force_percpu_prefix "%" #x @@ -568,37 +568,29 @@ do { \ #define this_cpu_read_stable_8(pcp) ({ BUILD_BUG(); (typeof(pcp))0; }) #endif -static __always_inline bool x86_this_cpu_constant_test_bit(unsigned int nr, - const unsigned long __percpu *addr) -{ - unsigned long __percpu *a = - (unsigned long __percpu *)addr + nr / BITS_PER_LONG; +#define x86_this_cpu_constant_test_bit(_nr, _var) \ +({ \ + unsigned long __percpu *addr__ = \ + (unsigned long __percpu *)&(_var) + ((_nr) / BITS_PER_LONG); \ + !!((1UL << ((_nr) % BITS_PER_LONG)) & raw_cpu_read(*addr__)); \ +}) -#ifdef CONFIG_X86_64 - return ((1UL << (nr % BITS_PER_LONG)) & raw_cpu_read_8(*a)) != 0; -#else - return ((1UL << (nr % BITS_PER_LONG)) & raw_cpu_read_4(*a)) != 0; -#endif -} - -static inline bool x86_this_cpu_variable_test_bit(int nr, - const unsigned long __percpu *addr) -{ - bool oldbit; - - asm volatile("btl %[nr], " __percpu_arg([var]) - CC_SET(c) - : CC_OUT(c) (oldbit) - : [var] "m" (*__my_cpu_ptr((unsigned long __percpu *)(addr))), - [nr] "Ir" (nr)); - - return oldbit; -} - -#define x86_this_cpu_test_bit(nr, addr) \ - (__builtin_constant_p((nr)) \ - ? x86_this_cpu_constant_test_bit((nr), (addr)) \ - : x86_this_cpu_variable_test_bit((nr), (addr))) +#define x86_this_cpu_variable_test_bit(_nr, _var) \ +({ \ + bool oldbit; \ + \ + asm volatile("btl %[nr], " __percpu_arg([var]) \ + CC_SET(c) \ + : CC_OUT(c) (oldbit) \ + : [var] "m" (__my_cpu_var(_var)), \ + [nr] "rI" (_nr)); \ + oldbit; \ +}) + +#define x86_this_cpu_test_bit(_nr, _var) \ + (__builtin_constant_p(_nr) \ + ? x86_this_cpu_constant_test_bit(_nr, _var) \ + : x86_this_cpu_variable_test_bit(_nr, _var)) #include