From nobody Fri Dec 19 11:50:01 2025 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B795D2E401 for ; Mon, 8 Dec 2025 03:50:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765165824; cv=none; b=qn+8jUG3rPlEHWQT7oiThjbgdd+BVxlkVt7mYUqgYU0A7zQvuy/FjTBisCFX7VC0O0djxWVFKJuCDhMrm0jW12QqO+7oJ7eBFm+f3YsqURdxrRS9tWt4NLi5aqIOCTAZICMqUKVtG/P+wD8R6eU+3QJWlVZRF8ZHmqrfZdQ6ZPc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765165824; c=relaxed/simple; bh=dxxUXPsKpc+ktrYr3NX238Ynrv7KxxIKYL2RCz+WmHQ=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qxplL9kjuQ+iGOlx1T1dt9Mq9QLG6YKNNrtGIlLsLlu7jpI/ZKWbWWBCXfovzEP8sp/hbg674RWO7fLXpEjt2fWy35TG+y5RDrbuslD//ubRgfEw7hR5T60KSeQUmwlvyGD3J2PrHY8iQkNq83fxv0yAHg093LEKeQdrMtalYD4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=ZHthHD4D; arc=none smtp.client-ip=209.85.214.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="ZHthHD4D" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-297dc3e299bso33571895ad.1 for ; Sun, 07 Dec 2025 19:50:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1765165822; x=1765770622; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=HQt8uoJWMBYj/YlVtM/kz+RuiqvE92xrlYMKIfu5C3o=; b=ZHthHD4DE1td+M3Tx7PdLn+/MTLFkJYU/CPsFFQSvVe2lCKCIR/biM9xk68XvVvBcZ 3B7O7qAlq2fGDnD6c9lwtI7DQgmLC4HDtvI1GVSE0EeTrVaROpCHgJmR1PcS9E/tXMqH vDCZV6g4G+8sHFGP+yFtkqSsa4mDmcsf41/YXwwEXI2K6J+ItAzhV+gi/b659YUqilTT mw+kY5RJQn0M5WQ5BwG3S1+btDnMoRssdbEVT1LfDXp3lEzuJwrQeLU/9Wdx6ho0fpS+ DM6aEcX6TfYpZO1qA4lHl7M1MHf/iod++B/Qcaq+eDCKQVS7kngUFiK90s1sIOr98uUR MiwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765165822; x=1765770622; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=HQt8uoJWMBYj/YlVtM/kz+RuiqvE92xrlYMKIfu5C3o=; b=AEumZULFnRRgyXVHWc0s5wJJ3v+PJhhB+gwzIpEGPxMLEm6uZtgNET8Rhvh0UTVKSs npV1VrrdO6lKgVn6iacHYWrVX8WniCqskCoXYEL8li65/fYtRde/TSlmGXM7A2hc/Q+5 9v2BWdfPm84w1FrZc131Fbl0TD060BQfB3mPl6jslHrfz667tLjfno6pdZNPTlJB7576 DCIpxWnJjpPmHJgH/haQpJ2z7dA76p7m6WDKV7IpqH454+BBkmFvBH/8DB32rhKAEk1N dlmnYiJmCGGkCqhHUAZL1baxcolUYYTPLGHiB/GTjdWe0mb7rzZDKmB1L0vzX7shg02u uhxQ== X-Forwarded-Encrypted: i=1; AJvYcCVFmBHWxz2E0U/roefLcKwUudmb0PgtzprhQ4/5j1rovsgnfI5dhbilcbxax4PjQPj5gUKYH3Qxqqsk2bo=@vger.kernel.org X-Gm-Message-State: AOJu0Yx8ORny2uqhCR0nP8tKke0ZZcUwSDWPu6uq6f1dh3VutPghXmcM lY9s3HDTh8RPPccuxn3GygzDYhlG1ak65Z0oRic7jaHdYwoC2ncEHEfdkVghAFywmrM= X-Gm-Gg: ASbGncurRU+hOFKt9GYBypYlwNZ78xKAkeLA9lbO0KqzfAVLShjyQXqBPYSKoy+zBOg jlcwJiBCvBAUuf62//+Ak1cY6hCrk0HKVoCiJ76UlcPJYe5n1lbDXYN4+qL7/At24+TFcNXD4gE xLB0tt4Ew/ev4WTn2+WpONshD6OCv1Pvh80X2v62mmGNqUUvUJ2IU7LcittCIJjKQwpZWhIqwCq iOCQxAd8NOl4OtqXKp2xLIK7Xvvhm/IHaGzdCF52eEGteZfGtSsmU6OPwDiuKAQf5viV/E2nAcW kD6EXZp6GZbucvAuL4cx225b7pdDBTcPzPmdnnGcYc3CkFPLKsAkX0N6CKtSrqdUHKpM3i4M/0C pFZ/8PuTM4DI2aI3l9oIQlsi5wT+SFBhIpu9/+8utKBbq4Bctz5JjnVUxkfhtJ1Bc1ZzrFFIVW3 REdsTRCm+60GnzXiFzP/GdMGmvg9Ww4Wb91djdzQwrLPjh X-Google-Smtp-Source: AGHT+IG6fRjq+lmQBsuqNIpVk2L76QYaDW/Ee1RxLF8vMbBYaZ5Umod8j+UA/guL3/HnA5D4KRUWHA== X-Received: by 2002:a17:903:2cb:b0:296:3f23:b910 with SMTP id d9443c01a7336-29df579eb0cmr58912355ad.9.1765165821912; Sun, 07 Dec 2025 19:50:21 -0800 (PST) Received: from L6YN4KR4K9.bytedance.net ([139.177.225.240]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29daeae6d96sm108871275ad.102.2025.12.07.19.50.08 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 07 Dec 2025 19:50:21 -0800 (PST) From: Yunhui Cui To: aou@eecs.berkeley.edu, alex@ghiti.fr, andii@kernel.org, andybnac@gmail.com, apatel@ventanamicro.com, ast@kernel.org, ben.dooks@codethink.co.uk, bjorn@kernel.org, bpf@vger.kernel.org, charlie@rivosinc.com, cl@gentwo.org, conor.dooley@microchip.com, cuiyunhui@bytedance.com, cyrilbur@tenstorrent.com, daniel@iogearbox.net, debug@rivosinc.com, dennis@kernel.org, eddyz87@gmail.com, haoluo@google.com, john.fastabend@gmail.com, jolsa@kernel.org, kpsingh@kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-riscv@lists.infradead.org, linux@rasmusvillemoes.dk, martin.lau@linux.dev, palmer@dabbelt.com, pjw@kernel.org, puranjay@kernel.org, pulehui@huawei.com, ruanjinjie@huawei.com, rkrcmar@ventanamicro.com, samuel.holland@sifive.com, sdf@fomichev.me, song@kernel.org, tglx@linutronix.de, tj@kernel.org, thuth@redhat.com, yonghong.song@linux.dev, yury.norov@gmail.com, zong.li@sifive.com Subject: [PATCH v2 1/3] riscv: remove irqflags.h inclusion in asm/bitops.h Date: Mon, 8 Dec 2025 11:49:42 +0800 Message-Id: <20251208034944.73113-2-cuiyunhui@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20251208034944.73113-1-cuiyunhui@bytedance.com> References: <20251208034944.73113-1-cuiyunhui@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The arch/riscv/include/asm/bitops.h does not functionally require including /linux/irqflags.h. Additionally, adding arch/riscv/include/asm/percpu.h causes a circular inclusion: kernel/bounds.c ->include/linux/log2.h ->include/linux/bitops.h ->arch/riscv/include/asm/bitops.h ->include/linux/irqflags.h ->include/linux/find.h ->return val ? __ffs(val) : size; ->arch/riscv/include/asm/bitops.h The compilation log is as follows: CC kernel/bounds.s In file included from ./include/linux/bitmap.h:11, from ./include/linux/cpumask.h:12, from ./arch/riscv/include/asm/processor.h:55, from ./arch/riscv/include/asm/thread_info.h:42, from ./include/linux/thread_info.h:60, from ./include/asm-generic/preempt.h:5, from ./arch/riscv/include/generated/asm/preempt.h:1, from ./include/linux/preempt.h:79, from ./arch/riscv/include/asm/percpu.h:8, from ./include/linux/irqflags.h:19, from ./arch/riscv/include/asm/bitops.h:14, from ./include/linux/bitops.h:68, from ./include/linux/log2.h:12, from kernel/bounds.c:13: ./include/linux/find.h: In function 'find_next_bit': ./include/linux/find.h:66:30: error: implicit declaration of function '__ff= s' [-Wimplicit-function-declaration] 66 | return val ? __ffs(val) : size; | ^~~~~ Signed-off-by: Yunhui Cui --- arch/riscv/include/asm/bitops.h | 1 - 1 file changed, 1 deletion(-) diff --git a/arch/riscv/include/asm/bitops.h b/arch/riscv/include/asm/bitop= s.h index 238092125c118..3c1a15be54d80 100644 --- a/arch/riscv/include/asm/bitops.h +++ b/arch/riscv/include/asm/bitops.h @@ -11,7 +11,6 @@ #endif /* _LINUX_BITOPS_H */ =20 #include -#include #include #include =20 --=20 2.39.5 From nobody Fri Dec 19 11:50:01 2025 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B6989231827 for ; Mon, 8 Dec 2025 03:50:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765165839; cv=none; b=Bb0JY+slwo3NOlEWnGuEz/fNQDqwqJlkzqi4mrxg07bhubENounfbsyFW8j/lGufYZQsWpR8VH5TrRgWHhOI7Z/1MlwclAMnaoGuK8ZWtgq17/tWMOvuirIjObpfrHvD/lXeHoq2MsTvRO8qosC/xabAvaWdEgJ5Axr2eN6qsgk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765165839; c=relaxed/simple; bh=2S8VdCVOVRMhLF5pnwGHAuQCvqrTtPFg5LvAxtmaqpI=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=uPAOG+oOOGgtuELcjtGze0TzJRX5dOkwQre/bW6S+oNbooz5hhwBHuoceavsjpVEWsuK9GsF3/sL5cl88L4IUoNUCBrxUXWO21n9Am6uOYOIsUaP4YkXIoRtPKyUegDcDHupNLri+caZ7Gu/yDhHA3aAd8p42oB1Us5WTz7LRZc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=GP8K/Okx; arc=none smtp.client-ip=209.85.214.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="GP8K/Okx" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-298145fe27eso62188795ad.1 for ; Sun, 07 Dec 2025 19:50:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1765165837; x=1765770637; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=TcDdbeyUjaIQvBTZiz9kFlENYKGodkKBU6I+HMWpHSE=; b=GP8K/Okx3N6vWGjppOI88KOBfYqSf1V3UlBtdJyfMuLh6eCaxTpXLaeKksSm9IT+m9 mPATWk1BPUJf2RRQc852zyuDovq70mTuhO8g4yweZrrcJw+ghoUrW39yplewOhObnw9f YQ/6k1/oDauYfGqQoQu5iThvfmOUk2MvBCS83WttHro/v/mF8ZWf6MXZe03q29bP1qbk RuOM5THrG+41098kgwOsAFb21jcyRUOWQao9XhZcmlWaZS2zQ2dPR7coaM7HR/DBl+RQ mbaQThjElI5UfHfexoh3JRVep5N9OMZlYYgv7+6mqysmh9aHrtZV5EUkWrDocBHYGbVK 3RQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765165837; x=1765770637; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=TcDdbeyUjaIQvBTZiz9kFlENYKGodkKBU6I+HMWpHSE=; b=mlTIJFroEEsiKPCr65QCyXA9mVzhII8RKDwf1wJiVsrGNbuVYIfk9Zu8BVRDD65sBg J2dtWYsPxeK1La/YDdkem0AmOm8Y7XgeFq9etoHKx3AUhuuLhd7RmZvPPYgr/AoUg1SA h/Ivt0eANQxALTo3FIXpfwuDTYHn8E1bU/E1suid34Vd2XKanbbRqKCUt2TKaQ9Mj1k8 /EOFDtXyCYbKhqlMmMbNadD8mMr05JnCiOifdfBT0ZlW6JyQXi8D5ua3QVIxwZljRdCz XRdCugBH43JHyFcT/FQGlHzE9QS3SLfXyYa9TZbH/5EW0LtYzoYiTl+VpOa5sXwcCOVJ zfxw== X-Forwarded-Encrypted: i=1; AJvYcCVxIKsJZMPuc84dmOXGAFx/ybjqdrYqQug1ALReY1cjHRor+7C84ty8Nnj2NgzWB1AWP0THpFMH3hJRou8=@vger.kernel.org X-Gm-Message-State: AOJu0Yw4Cax5b0OPoV47D7XN/4BFFHzVw3TLKqzUQH9MVeuW4NQIZIYI MHkI9LBwwCjl0/t5QmncLHxGldSvEj9X/sCrlpeJ+C4K0ynCg+MEhbg9O3CXQpvmCw4= X-Gm-Gg: ASbGncuRKIixLVL+c3aCCwlGFDNzmQN53s12R7LAmc98hXX1FKAAkGBcC2XMsy55gqZ 327TicmuH1Gg4cqEK5n9KXpQARM4Brz4QRlnsDt2vDKGTO1hs8jrYJ8N4EKU8cnL7me6WRMAYpa 4dw/oWhJzi62tGBFJOUzo293zu2PoS1qNZ8nSGBBD9WiHNZbJyszzxvmj96+i5q0i0UIyQxt5gX ZYgJgEbb8sbq3+HvwZ1TL9ceunMpxoDrXx53p6fNP1FR8Pl5SgjPZqqtTcSQUAtv9whsveEIGG8 K03Tkpi5sQZIXAgnUU/mtZNzwku9bvb7QSQEUmp8blc+O5h+rnKIQ2cjOIxnw/4Z7KFBayVQv+y 7xzPo+d+3uz4TYPCqMhHIa5fUVeL4B1FzG368uZRH4fj1PlYaAaqBcCLx0ElP4c9Ek5l82Rr7sx BXHZ02kKRAqu+UOmnm0r6asovcBlJlmNFWf7kx/k9IgzTs X-Google-Smtp-Source: AGHT+IEsyS70YjfqcY6uDUzuCw0QsSiDGBq56vWCrB/xumiB1z4Fux5bNgh47wXnVIwNcfKaN47/fA== X-Received: by 2002:a17:902:cf0f:b0:297:c4b0:8d53 with SMTP id d9443c01a7336-29df5e1b2femr51595245ad.54.1765165836888; Sun, 07 Dec 2025 19:50:36 -0800 (PST) Received: from L6YN4KR4K9.bytedance.net ([139.177.225.240]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29daeae6d96sm108871275ad.102.2025.12.07.19.50.22 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 07 Dec 2025 19:50:36 -0800 (PST) From: Yunhui Cui To: aou@eecs.berkeley.edu, alex@ghiti.fr, andii@kernel.org, andybnac@gmail.com, apatel@ventanamicro.com, ast@kernel.org, ben.dooks@codethink.co.uk, bjorn@kernel.org, bpf@vger.kernel.org, charlie@rivosinc.com, cl@gentwo.org, conor.dooley@microchip.com, cuiyunhui@bytedance.com, cyrilbur@tenstorrent.com, daniel@iogearbox.net, debug@rivosinc.com, dennis@kernel.org, eddyz87@gmail.com, haoluo@google.com, john.fastabend@gmail.com, jolsa@kernel.org, kpsingh@kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-riscv@lists.infradead.org, linux@rasmusvillemoes.dk, martin.lau@linux.dev, palmer@dabbelt.com, pjw@kernel.org, puranjay@kernel.org, pulehui@huawei.com, ruanjinjie@huawei.com, rkrcmar@ventanamicro.com, samuel.holland@sifive.com, sdf@fomichev.me, song@kernel.org, tglx@linutronix.de, tj@kernel.org, thuth@redhat.com, yonghong.song@linux.dev, yury.norov@gmail.com, zong.li@sifive.com Subject: [PATCH v2 2/3] riscv: introduce percpu.h into include/asm Date: Mon, 8 Dec 2025 11:49:43 +0800 Message-Id: <20251208034944.73113-3-cuiyunhui@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20251208034944.73113-1-cuiyunhui@bytedance.com> References: <20251208034944.73113-1-cuiyunhui@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Current percpu operations rely on generic implementations, where raw_local_irq_save() introduces substantial overhead. Optimization is achieved through atomic operations and preemption disabling. Currently, since RISC-V does not support lr/sc.b/h, when ZABHA is not supported, lr/sc.w needs to be used instead, which requires some additional mask operations. Signed-off-by: Yunhui Cui --- arch/riscv/include/asm/percpu.h | 238 ++++++++++++++++++++++++++++++++ 1 file changed, 238 insertions(+) create mode 100644 arch/riscv/include/asm/percpu.h diff --git a/arch/riscv/include/asm/percpu.h b/arch/riscv/include/asm/percp= u.h new file mode 100644 index 0000000000000..b173729926126 --- /dev/null +++ b/arch/riscv/include/asm/percpu.h @@ -0,0 +1,238 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#ifndef __ASM_PERCPU_H +#define __ASM_PERCPU_H + +#include + +#include +#include +#include + +#define PERCPU_RW_OPS(sz) \ +static inline unsigned long __percpu_read_##sz(void *ptr) \ +{ \ + return READ_ONCE(*(u##sz *)ptr); \ +} \ + \ +static inline void __percpu_write_##sz(void *ptr, unsigned long val) \ +{ \ + WRITE_ONCE(*(u##sz *)ptr, (u##sz)val); \ +} + +PERCPU_RW_OPS(8) +PERCPU_RW_OPS(16) +PERCPU_RW_OPS(32) +PERCPU_RW_OPS(64) + +#define __PERCPU_AMO_OP_CASE(sfx, name, sz, amo_insn) \ +static inline void \ +__percpu_##name##_amo_case_##sz(void *ptr, unsigned long val) \ +{ \ + asm volatile ( \ + "amo" #amo_insn #sfx " zero, %[val], %[ptr]" \ + : [ptr] "+A" (*(u##sz *)ptr) \ + : [val] "r" ((u##sz)(val)) \ + : "memory"); \ +} + +#define PERCPU_OP(name, amo_insn) \ + __PERCPU_AMO_OP_CASE(.w, name, 32, amo_insn) \ + __PERCPU_AMO_OP_CASE(.d, name, 64, amo_insn) + +PERCPU_OP(add, add) +PERCPU_OP(andnot, and) +PERCPU_OP(or, or) + +/* + * Currently, only this_cpu_add_return_xxx() requires a return value, + * and the PERCPU_RET_OP() does not account for other operations. + */ +#define __PERCPU_AMO_RET_OP_CASE(sfx, name, sz, amo_insn) \ +static inline u##sz \ +__percpu_##name##_return_amo_case_##sz(void *ptr, unsigned long val) \ +{ \ + register u##sz ret; \ + \ + asm volatile ( \ + "amo" #amo_insn #sfx " %[ret], %[val], %[ptr]" \ + : [ptr] "+A" (*(u##sz *)ptr), [ret] "=3Dr" (ret) \ + : [val] "r" ((u##sz)(val)) \ + : "memory"); \ + \ + return ret + val; \ +} + +#define PERCPU_RET_OP(name, amo_insn) \ + __PERCPU_AMO_RET_OP_CASE(.w, name, 32, amo_insn) \ + __PERCPU_AMO_RET_OP_CASE(.d, name, 64, amo_insn) + +PERCPU_RET_OP(add, add) + +#define PERCPU_8_16_GET_SHIFT(ptr) (((unsigned long)(ptr) & 0x3) * BITS_PE= R_BYTE) +#define PERCPU_8_16_GET_MASK(sz) GENMASK((sz)-1, 0) +#define PERCPU_8_16_GET_PTR32(ptr) ((u32 *)((unsigned long)(ptr) & ~0x3)) + +#define PERCPU_8_16_OP(name, amo_insn, sz, sfx, val_type, new_val_expr, as= m_op) \ +static inline void __percpu_##name##_amo_case_##sz(void *ptr, unsigned lon= g val) \ +{ \ + if (IS_ENABLED(CONFIG_RISCV_ISA_ZABHA) && \ + riscv_has_extension_unlikely(RISCV_ISA_EXT_ZABHA)) { \ + asm volatile ("amo" #amo_insn #sfx " zero, %[val], %[ptr]" \ + : [ptr] "+A"(*(val_type *)ptr) \ + : [val] "r"((val_type)(new_val_expr)) \ + : "memory"); \ + } else { \ + u32 *ptr32 =3D PERCPU_8_16_GET_PTR32(ptr); \ + const unsigned long shift =3D PERCPU_8_16_GET_SHIFT(ptr); \ + const u32 mask =3D PERCPU_8_16_GET_MASK(sz) << shift; \ + const val_type val_trunc =3D (val_type)(new_val_expr); \ + u32 retx, rc; \ + val_type new_val_type; \ + \ + asm volatile ( \ + "0: lr.w %0, %2\n" \ + "and %3, %0, %4\n" \ + "srl %3, %3, %5\n" \ + #asm_op " %3, %3, %6\n" \ + "sll %3, %3, %5\n" \ + "and %1, %0, %7\n" \ + "or %1, %1, %3\n" \ + "sc.w %1, %1, %2\n" \ + "bnez %1, 0b\n" \ + : "=3D&r"(retx), "=3D&r"(rc), "+A"(*ptr32), "=3D&r"(new_val_type) \ + : "r"(mask), "r"(shift), "r"(val_trunc), "r"(~mask) \ + : "memory"); \ + } \ +} + +#define PERCPU_OP_8_16(op_name, op, expr, final_op) \ + PERCPU_8_16_OP(op_name, op, 8, .b, u8, expr, final_op); \ + PERCPU_8_16_OP(op_name, op, 16, .h, u16, expr, final_op) + +PERCPU_OP_8_16(add, add, val, add) +PERCPU_OP_8_16(andnot, and, ~val, and) +PERCPU_OP_8_16(or, or, val, or) + +#define PERCPU_8_16_RET_OP(name, amo_insn, sz, sfx, val_type, new_val_expr= ) \ +static inline val_type __percpu_##name##_return_amo_case_##sz(void *ptr, u= nsigned long val) \ +{ \ + if (IS_ENABLED(CONFIG_RISCV_ISA_ZABHA) && \ + riscv_has_extension_unlikely(RISCV_ISA_EXT_ZABHA)) { \ + register val_type ret; \ + asm volatile ("amo" #amo_insn #sfx " %[ret], %[val], %[ptr]" \ + : [ptr] "+A"(*(val_type *)ptr), [ret] "=3Dr"(ret) \ + : [val] "r"((val_type)(new_val_expr)) \ + : "memory"); \ + return ret + (val_type)(new_val_expr); \ + } else { \ + u32 *ptr32 =3D PERCPU_8_16_GET_PTR32(ptr); \ + const unsigned long shift =3D PERCPU_8_16_GET_SHIFT(ptr); \ + const u32 mask =3D (PERCPU_8_16_GET_MASK(sz) << shift); \ + const u32 inv_mask =3D ~mask; \ + const val_type val_trunc =3D (val_type)(new_val_expr); \ + u32 old, new, tmp; \ + \ + asm volatile ( \ + "0: lr.w %0, %3\n" \ + "and %1, %0, %4\n" \ + "srl %1, %1, %5\n" \ + "add %1, %1, %6\n" \ + "and %1, %1, %7\n" \ + "sll %1, %1, %5\n" \ + "and %2, %0, %8\n" \ + "or %2, %2, %1\n" \ + "sc.w %2, %2, %3\n" \ + "bnez %2, 0b\n" \ + : "=3Dr"(old), "=3Dr"(tmp), "=3D&r"(new), "+A"(*ptr32) \ + : "r"(mask), "r"(shift), "r"(val_trunc), "r"(PERCPU_8_16_GET_MASK(sz)),= \ + "r"(inv_mask) \ + : "memory"); \ + return (val_type)(tmp); \ + } \ +} + +PERCPU_8_16_RET_OP(add, add, 8, .b, u8, val) +PERCPU_8_16_RET_OP(add, add, 16, .h, u16, val) + +#define _pcp_protect(op, pcp, ...) \ +({ \ + preempt_disable_notrace(); \ + op(raw_cpu_ptr(&(pcp)), __VA_ARGS__); \ + preempt_enable_notrace(); \ +}) + +#define _pcp_protect_return(op, pcp, args...) \ +({ \ + typeof(pcp) __retval; \ + preempt_disable_notrace(); \ + __retval =3D (typeof(pcp))op(raw_cpu_ptr(&(pcp)), ##args); \ + preempt_enable_notrace(); \ + __retval; \ +}) + +#define this_cpu_read_1(pcp) _pcp_protect_return(__percpu_read_8, pcp) +#define this_cpu_read_2(pcp) _pcp_protect_return(__percpu_read_16, pcp) +#define this_cpu_read_4(pcp) _pcp_protect_return(__percpu_read_32, pcp) +#define this_cpu_read_8(pcp) _pcp_protect_return(__percpu_read_64, pcp) + +#define this_cpu_write_1(pcp, val) _pcp_protect(__percpu_write_8, pcp, (un= signed long)val) +#define this_cpu_write_2(pcp, val) _pcp_protect(__percpu_write_16, pcp, (u= nsigned long)val) +#define this_cpu_write_4(pcp, val) _pcp_protect(__percpu_write_32, pcp, (u= nsigned long)val) +#define this_cpu_write_8(pcp, val) _pcp_protect(__percpu_write_64, pcp, (u= nsigned long)val) + +#define this_cpu_add_1(pcp, val) _pcp_protect(__percpu_add_amo_case_8, pcp= , val) +#define this_cpu_add_2(pcp, val) _pcp_protect(__percpu_add_amo_case_16, pc= p, val) +#define this_cpu_add_4(pcp, val) _pcp_protect(__percpu_add_amo_case_32, pc= p, val) +#define this_cpu_add_8(pcp, val) _pcp_protect(__percpu_add_amo_case_64, pc= p, val) + +#define this_cpu_add_return_1(pcp, val) \ +_pcp_protect_return(__percpu_add_return_amo_case_8, pcp, val) + +#define this_cpu_add_return_2(pcp, val) \ +_pcp_protect_return(__percpu_add_return_amo_case_16, pcp, val) + +#define this_cpu_add_return_4(pcp, val) \ +_pcp_protect_return(__percpu_add_return_amo_case_32, pcp, val) + +#define this_cpu_add_return_8(pcp, val) \ +_pcp_protect_return(__percpu_add_return_amo_case_64, pcp, val) + +#define this_cpu_and_1(pcp, val) _pcp_protect(__percpu_andnot_amo_case_8, = pcp, ~val) +#define this_cpu_and_2(pcp, val) _pcp_protect(__percpu_andnot_amo_case_16,= pcp, ~val) +#define this_cpu_and_4(pcp, val) _pcp_protect(__percpu_andnot_amo_case_32,= pcp, ~val) +#define this_cpu_and_8(pcp, val) _pcp_protect(__percpu_andnot_amo_case_64,= pcp, ~val) + +#define this_cpu_or_1(pcp, val) _pcp_protect(__percpu_or_amo_case_8, pcp, = val) +#define this_cpu_or_2(pcp, val) _pcp_protect(__percpu_or_amo_case_16, pcp,= val) +#define this_cpu_or_4(pcp, val) _pcp_protect(__percpu_or_amo_case_32, pcp,= val) +#define this_cpu_or_8(pcp, val) _pcp_protect(__percpu_or_amo_case_64, pcp,= val) + +#define this_cpu_xchg_1(pcp, val) _pcp_protect_return(xchg_relaxed, pcp, v= al) +#define this_cpu_xchg_2(pcp, val) _pcp_protect_return(xchg_relaxed, pcp, v= al) +#define this_cpu_xchg_4(pcp, val) _pcp_protect_return(xchg_relaxed, pcp, v= al) +#define this_cpu_xchg_8(pcp, val) _pcp_protect_return(xchg_relaxed, pcp, v= al) + +#define this_cpu_cmpxchg_1(pcp, o, n) _pcp_protect_return(cmpxchg_relaxed,= pcp, o, n) +#define this_cpu_cmpxchg_2(pcp, o, n) _pcp_protect_return(cmpxchg_relaxed,= pcp, o, n) +#define this_cpu_cmpxchg_4(pcp, o, n) _pcp_protect_return(cmpxchg_relaxed,= pcp, o, n) +#define this_cpu_cmpxchg_8(pcp, o, n) _pcp_protect_return(cmpxchg_relaxed,= pcp, o, n) + +#define this_cpu_cmpxchg64(pcp, o, n) this_cpu_cmpxchg_8(pcp, o, n) + +#define this_cpu_cmpxchg128(pcp, o, n) \ +({ \ + u128 old__, new__, ret__; \ + typeof(pcp) *ptr__; \ + old__ =3D o; \ + new__ =3D n; \ + preempt_disable_notrace(); \ + ptr__ =3D raw_cpu_ptr(&(pcp)); \ + ret__ =3D cmpxchg128_local(ptr__, old__, new__); \ + preempt_enable_notrace(); \ + ret__; \ +}) + +#include + +#endif /* __ASM_PERCPU_H */ --=20 2.39.5 From nobody Fri Dec 19 11:50:01 2025 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6186624DFF3 for ; Mon, 8 Dec 2025 03:50:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765165854; cv=none; b=H2wm+7srRV96WcurMdj4xHG8sFMWaBbBxaW0p4FtkOB9+f57LLiHvWcmHTBOUqh9D9ONEKjJ/cSGUo6g6nPKA4lWcDR35eUq+nOymCzZ4zo/K4kzDkcTM6Q6H7QLwEPhW4Gy8T2Pn4p1L06nOSNovVP5H80BGuhdkZlQrBYrZjk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765165854; c=relaxed/simple; bh=s7J1/EJglygUlRcA2CA2RR3zp0EAzyaKlV4J61HRDG8=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=ajsKueCkk7ZQWHeiXzZ7BalQhD879/EMX8SeE4inR6RFe3VM3v/tHscW/+IwSv46dePJ32d+6exEtvajUktx2fT/dTQXcWWdYGKttAru4nG4MBZbXjo4SckfgOgIIXlEvnoNyi69T/GWgnhOnujomPVx9HDG9fUDObeF+1zBf0E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=JveqQe+4; arc=none smtp.client-ip=209.85.214.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="JveqQe+4" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-29d7b019e0eso44960435ad.2 for ; Sun, 07 Dec 2025 19:50:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1765165853; x=1765770653; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=xFr5RgkhvM6EE5Q/RHn3oG8Xllt/H7Gtrl4Nvhbq1ik=; b=JveqQe+4vnnBF9/JE6TGDJebpcfTVkSFSusxozXzEEzKIXzeB2X78bi0GfmBgnSmOn kBhLioroZZxLg6+rUzN8vLL03Bpmx3qmpTYXrL9C1XgetXZXYwOBY1ohjM++0F/8tR8r 6SCGxW2lUeQF5YeyD0SKVSzUv50/+G8hfz5ZYCHTLlwLckrceok7uKXIZkv0E0yMaNir mcGlY0G86dLqRyD3ufuD0EwW3lkG3JyQ/Tmc/JaDqlr38E1XnZV+jz0CEy5/gTNJsypN XugjFk59HHasR44Zft1w14sI1vkhiwcRYcdBCs8B9zcY5Kcu7FCfJYmuZ36E0Mdl30YD MZFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765165853; x=1765770653; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=xFr5RgkhvM6EE5Q/RHn3oG8Xllt/H7Gtrl4Nvhbq1ik=; b=AmK8eQS3rIQEdTmdOgez7Sp67PfQaaPHZ+ZoMrC9u9d5c3JBRyQXbdKRMPaZLERqpZ ax8CqtrY2zTTV/LFwtvtm+MiRuX0HWekW3gO8cIdQ2PxQvFoHm5uakzeQwhmYjrT1Kpv SXClrSVc6lTLxzcgWWKN3a42pc3aGHLY3dJdXel9LCvjx9pzhGSvI+9kmNh8Bs7pp4iv MzPrx/RUbxG+XYW2UVi0zRDJSzYxelkQlnuUAKEeYHrDut8CccUJX2j+X9PpQVP0O3cg 9gFDCWZnGAQ9siLpOUkWzA1NYUP8tna2BGFVwuTYXieBkWh6D5Tpk37wrcmqNJbt8Hmw NFwQ== X-Forwarded-Encrypted: i=1; AJvYcCXKqwAD3Hw2dhXZaiJlOxNz/3rk2L02kZ2VPhMb7VarzMcYrvUI3jVzUPQxhSZOfxV+Qb2egnP2GOmy7Go=@vger.kernel.org X-Gm-Message-State: AOJu0Ywnt3EEDTB4E4fAsy6Jv3u4byCm55H7w0a1EVKDlE+u62NxSrcu ODL+zyNnIMJSQRKfw6vxykgOC0IKujPstQXb6gSHW+wFmR5cBwgRc721tRbeKCD7FIo= X-Gm-Gg: ASbGncu1yeyXl5+dlUa5UTXmrmigu2hOiMnHZ053IF8JpzKZvImnE8ivLqglplhbPI6 zAwUSgj7ESrojgXXtpqbqomcm1TaZFqj5YmMXRK+gtgyNkd9OfZ2VV4hPygKL3lNodhxmPci2c6 wxlR+RGGIjoUo8VxiJMzMkuZJVS1lAKplYF71g1vUnWFW0AakpYFmoPG+P3BpnSEK+LtQ0Ili/Y qU9XV0n05nOogj5YfAiGckq9j9deglpKdCaiuU7cid1MOFR6Tw2xaYrkTothmmFB3L7vjyz0nw0 BIJjhUPDyEZnwdoG2iX9FYA+J2Uph6XMjPZ2Y9IVd7AFQYTFuDXEJI+LcYDPJ9GGGp21kDf710c ypnprGL57XfxROLo0+jDxu/N33pTBw2H4zbKy4UrC2it04Spqo0t+z4JkoDfGAsFokqN7rlXYEX H8DZmwRHZ7Me91mcW71sOUrhb302Gm1pDWJKIHeXsIdFkm X-Google-Smtp-Source: AGHT+IGvReM+D+IE845FajcK0U2ifqJXm74OcYy9I6WIlw3gQeLkhNJjnOwLKfKhujYanWqb2gK1OA== X-Received: by 2002:a17:903:15ce:b0:299:dea1:e791 with SMTP id d9443c01a7336-29df56772d0mr53566285ad.12.1765165852442; Sun, 07 Dec 2025 19:50:52 -0800 (PST) Received: from L6YN4KR4K9.bytedance.net ([139.177.225.240]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29daeae6d96sm108871275ad.102.2025.12.07.19.50.37 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 07 Dec 2025 19:50:52 -0800 (PST) From: Yunhui Cui To: aou@eecs.berkeley.edu, alex@ghiti.fr, andii@kernel.org, andybnac@gmail.com, apatel@ventanamicro.com, ast@kernel.org, ben.dooks@codethink.co.uk, bjorn@kernel.org, bpf@vger.kernel.org, charlie@rivosinc.com, cl@gentwo.org, conor.dooley@microchip.com, cuiyunhui@bytedance.com, cyrilbur@tenstorrent.com, daniel@iogearbox.net, debug@rivosinc.com, dennis@kernel.org, eddyz87@gmail.com, haoluo@google.com, john.fastabend@gmail.com, jolsa@kernel.org, kpsingh@kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-riscv@lists.infradead.org, linux@rasmusvillemoes.dk, martin.lau@linux.dev, palmer@dabbelt.com, pjw@kernel.org, puranjay@kernel.org, pulehui@huawei.com, ruanjinjie@huawei.com, rkrcmar@ventanamicro.com, samuel.holland@sifive.com, sdf@fomichev.me, song@kernel.org, tglx@linutronix.de, tj@kernel.org, thuth@redhat.com, yonghong.song@linux.dev, yury.norov@gmail.com, zong.li@sifive.com Subject: [PATCH v2 3/3] riscv: store percpu offset into thread_info Date: Mon, 8 Dec 2025 11:49:44 +0800 Message-Id: <20251208034944.73113-4-cuiyunhui@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20251208034944.73113-1-cuiyunhui@bytedance.com> References: <20251208034944.73113-1-cuiyunhui@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Originally we planned to add a register for the percpu offset, which would speed up percpu variable R/W and reduce access instructions. After discussion [1], it=E2=80=99s now stored in thread_info. [1] https://lists.riscv.org/g/tech-privileged/topic/risc_v_tech_arch_review= /113437553?page=3D2 Signed-off-by: Yunhui Cui --- arch/riscv/include/asm/asm.h | 6 +----- arch/riscv/include/asm/percpu.h | 4 ++++ arch/riscv/include/asm/switch_to.h | 8 ++++++++ arch/riscv/include/asm/thread_info.h | 5 +++-- arch/riscv/kernel/asm-offsets.c | 1 + arch/riscv/kernel/smpboot.c | 7 +++++++ arch/riscv/net/bpf_jit_comp64.c | 9 +-------- 7 files changed, 25 insertions(+), 15 deletions(-) diff --git a/arch/riscv/include/asm/asm.h b/arch/riscv/include/asm/asm.h index e9e8ba83e632f..137a49488325e 100644 --- a/arch/riscv/include/asm/asm.h +++ b/arch/riscv/include/asm/asm.h @@ -91,11 +91,7 @@ =20 #ifdef CONFIG_SMP .macro asm_per_cpu dst sym tmp - lw \tmp, TASK_TI_CPU_NUM(tp) - slli \tmp, \tmp, RISCV_LGPTR - la \dst, __per_cpu_offset - add \dst, \dst, \tmp - REG_L \tmp, 0(\dst) + REG_L \tmp, TASK_TI_PCPU_OFFSET(tp) la \dst, \sym add \dst, \dst, \tmp .endm diff --git a/arch/riscv/include/asm/percpu.h b/arch/riscv/include/asm/percp= u.h index b173729926126..18e282dded626 100644 --- a/arch/riscv/include/asm/percpu.h +++ b/arch/riscv/include/asm/percpu.h @@ -7,7 +7,9 @@ =20 #include #include +#include #include +#include =20 #define PERCPU_RW_OPS(sz) \ static inline unsigned long __percpu_read_##sz(void *ptr) \ @@ -233,6 +235,8 @@ _pcp_protect_return(__percpu_add_return_amo_case_64, pc= p, val) ret__; \ }) =20 +#define __my_cpu_offset (((struct thread_info *)current)->pcpu_offset) + #include =20 #endif /* __ASM_PERCPU_H */ diff --git a/arch/riscv/include/asm/switch_to.h b/arch/riscv/include/asm/sw= itch_to.h index 0e71eb82f920c..733b6cd306e40 100644 --- a/arch/riscv/include/asm/switch_to.h +++ b/arch/riscv/include/asm/switch_to.h @@ -88,6 +88,13 @@ static inline void __switch_to_envcfg(struct task_struct= *next) :: "r" (next->thread.envcfg) : "memory"); } =20 +static inline void __switch_to_pcpu_offset(struct task_struct *next) +{ +#ifdef CONFIG_SMP + next->thread_info.pcpu_offset =3D __my_cpu_offset; +#endif +} + extern struct task_struct *__switch_to(struct task_struct *, struct task_struct *); =20 @@ -122,6 +129,7 @@ do { \ if (switch_to_should_flush_icache(__next)) \ local_flush_icache_all(); \ __switch_to_envcfg(__next); \ + __switch_to_pcpu_offset(__next); \ ((last) =3D __switch_to(__prev, __next)); \ } while (0) =20 diff --git a/arch/riscv/include/asm/thread_info.h b/arch/riscv/include/asm/= thread_info.h index 36918c9200c92..8d7d43cc9c405 100644 --- a/arch/riscv/include/asm/thread_info.h +++ b/arch/riscv/include/asm/thread_info.h @@ -52,7 +52,8 @@ */ struct thread_info { unsigned long flags; /* low level flags */ - int preempt_count; /* 0=3D>preemptible, <0=3D>BUG */ + int preempt_count; /* 0=3D>preemptible, <0=3D>BUG */ + int cpu; /* * These stack pointers are overwritten on every system call or * exception. SP is also saved to the stack it can be recovered when @@ -60,8 +61,8 @@ struct thread_info { */ long kernel_sp; /* Kernel stack pointer */ long user_sp; /* User stack pointer */ - int cpu; unsigned long syscall_work; /* SYSCALL_WORK_ flags */ + unsigned long pcpu_offset; #ifdef CONFIG_SHADOW_CALL_STACK void *scs_base; void *scs_sp; diff --git a/arch/riscv/kernel/asm-offsets.c b/arch/riscv/kernel/asm-offset= s.c index af827448a609e..fbf53b66b0e06 100644 --- a/arch/riscv/kernel/asm-offsets.c +++ b/arch/riscv/kernel/asm-offsets.c @@ -38,6 +38,7 @@ void asm_offsets(void) OFFSET(TASK_THREAD_SUM, task_struct, thread.sum); =20 OFFSET(TASK_TI_CPU, task_struct, thread_info.cpu); + OFFSET(TASK_TI_PCPU_OFFSET, task_struct, thread_info.pcpu_offset); OFFSET(TASK_TI_PREEMPT_COUNT, task_struct, thread_info.preempt_count); OFFSET(TASK_TI_KERNEL_SP, task_struct, thread_info.kernel_sp); OFFSET(TASK_TI_USER_SP, task_struct, thread_info.user_sp); diff --git a/arch/riscv/kernel/smpboot.c b/arch/riscv/kernel/smpboot.c index d85916a3660c3..9e95c068b966b 100644 --- a/arch/riscv/kernel/smpboot.c +++ b/arch/riscv/kernel/smpboot.c @@ -209,6 +209,11 @@ int __cpu_up(unsigned int cpu, struct task_struct *tid= le) } #endif =20 +void __init smp_prepare_boot_cpu(void) +{ + __my_cpu_offset =3D per_cpu_offset(smp_processor_id()); +} + void __init smp_cpus_done(unsigned int max_cpus) { } @@ -234,6 +239,8 @@ asmlinkage __visible void smp_callin(void) mmgrab(mm); current->active_mm =3D mm; =20 + __my_cpu_offset =3D per_cpu_offset(smp_processor_id()); + #ifdef CONFIG_HOTPLUG_PARALLEL cpuhp_ap_sync_alive(); #endif diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp6= 4.c index 5f9457e910e87..4a492a6a1cc1e 100644 --- a/arch/riscv/net/bpf_jit_comp64.c +++ b/arch/riscv/net/bpf_jit_comp64.c @@ -1345,15 +1345,8 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, s= truct rv_jit_context *ctx, if (rd !=3D rs) emit_mv(rd, rs, ctx); #ifdef CONFIG_SMP - /* Load current CPU number in T1 */ - emit_lw(RV_REG_T1, offsetof(struct thread_info, cpu), + emit_lw(RV_REG_T1, offsetof(struct thread_info, pcpu_offset), RV_REG_TP, ctx); - /* Load address of __per_cpu_offset array in T2 */ - emit_addr(RV_REG_T2, (u64)&__per_cpu_offset, extra_pass, ctx); - /* Get address of __per_cpu_offset[cpu] in T1 */ - emit_sh3add(RV_REG_T1, RV_REG_T1, RV_REG_T2, ctx); - /* Load __per_cpu_offset[cpu] in T1 */ - emit_ld(RV_REG_T1, 0, RV_REG_T1, ctx); /* Add the offset to Rd */ emit_add(rd, rd, RV_REG_T1, ctx); #endif --=20 2.39.5