From nobody Mon Dec 1 23:33:17 2025 Received: from out-172.mta0.migadu.com (out-172.mta0.migadu.com [91.218.175.172]) (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 06EEB306B06 for ; Wed, 26 Nov 2025 02:06:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764122772; cv=none; b=jlvUaP4H0YG/qyh+2uNDahhS6zh1XaMACh2WZoiV3CZD9Ft2i0LuSTLg0CSxPJ/nkivMMZN9TZkQfqA0MBiia1CZWKqels9B+1soqSF/yjLQzeh1I5VH+8VTzOqNatv93KYqSp9DKu3lSKvsDEclccK03Sh37T/RRF6nL0FvukI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764122772; c=relaxed/simple; bh=rEyAIeGKVONa+XHzkCV5F1EaJnH0f6VY3VSLc1lOy2c=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rS/Soj7Q4IKWp2H9JOGnSPv5ixshd+8IAkJbYTGmjdqEIAciYPyqe8pIUvSNnicUjg/urI5XnnpCR5E+M51kjnTBAIQlzZAL8d0M14cGik0kmsf/sz20AEe4soq4yR0ssUKFAGCSfOCANOsntAugJ9+SkoD/Vg1DtO6IeQjwy/c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=aw/JY6Xu; arc=none smtp.client-ip=91.218.175.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="aw/JY6Xu" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1764122765; h=from:from: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=IJFLj/4Ro5hIBW4b227wdO+x5xyFcMjEZgEKTjn36EA=; b=aw/JY6XuyM96NQznYWKGpdEhO876LnDF9JU+uEO51o0n2/TJTjYwcAOAcFTtbJvyKwwPv/ neiPp6T9ZXRa4Ap4ZKPrPNd5iRiW5w+ZQYAxGU1HQc3sWjoS6fjg9NlxCOFncCj0tGZHIt CdaQqElAia/8ijVpB6/49NFpIzpOBRE= From: George Guo Date: Wed, 26 Nov 2025 10:05:50 +0800 Subject: [PATCH v3 1/2] LoongArch: Add 128-bit atomic cmpxchg support 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 Message-Id: <20251126-2-v3-1-851b5a516801@linux.dev> References: <20251126-2-v3-0-851b5a516801@linux.dev> In-Reply-To: <20251126-2-v3-0-851b5a516801@linux.dev> To: Huacai Chen , WANG Xuerui Cc: loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, George Guo , George Guo X-Developer-Signature: v=1; a=ed25519-sha256; t=1764122759; l=2732; i=dongtai.guo@linux.dev; s=20251103; h=from:subject:message-id; bh=rSX+//mu5dp/V6lO1NUdtEvY0gguP3s+oE7pcxBAUaM=; b=BMl69L9PQMW4xCJlyEGUwZn6+W5o/yZb86FeXsXiRpYonPVvNgjRoID2zy6qMu0K9s1ebjCkw Xz9SQOaHfuBBZEgo/lPbuVylNkykrpmwOQ1EU81jkySfS7rfAIXuJR0 X-Developer-Key: i=dongtai.guo@linux.dev; a=ed25519; pk=yHUJPGx/kAXutP/NSHpj7hWW0KQNlv3w9H6ju4qUoTM= X-Migadu-Flow: FLOW_OUT From: George Guo Implement 128-bit atomic compare-and-exchange using LoongArch's LL.D/SC.Q instructions. At the same time, fix BPF scheduler test failures (scx_central scx_qmap) caused by kmalloc_nolock_noprof returning NULL due to missing 128-bit atomics. The NULL returns led to -ENOMEM errors during scheduler initialization, causing test cases to fail. Verified by testing with the scx_qmap scheduler (located in tools/sched_ext/). Building with `make` and running ./tools/sched_ext/build/bin/scx_qmap. Signed-off-by: George Guo --- arch/loongarch/include/asm/cmpxchg.h | 47 ++++++++++++++++++++++++++++++++= ++++ 1 file changed, 47 insertions(+) diff --git a/arch/loongarch/include/asm/cmpxchg.h b/arch/loongarch/include/= asm/cmpxchg.h index 979fde61bba8a42cb4f019f13ded2a3119d4aaf4..88553ae63e178ebff16ebbc2e01= b0e23831b0918 100644 --- a/arch/loongarch/include/asm/cmpxchg.h +++ b/arch/loongarch/include/asm/cmpxchg.h @@ -111,6 +111,44 @@ __arch_xchg(volatile void *ptr, unsigned long x, int s= ize) __ret; \ }) =20 +union __u128_halves { + u128 full; + struct { + u64 low; + u64 high; + }; +}; + +#define __cmpxchg128_asm(ptr, old, new) \ +({ \ + union __u128_halves __old, __new, __ret; \ + volatile u64 *__ptr =3D (volatile u64 *)(ptr); \ + \ + __old.full =3D (old); \ + __new.full =3D (new); \ + \ + __asm__ __volatile__( \ + "1: ll.d %0, %3 # 128-bit cmpxchg low \n" \ + __WEAK_LLSC_MB \ + " ld.d %1, %4 # 128-bit cmpxchg high \n" \ + " bne %0, %z5, 2f \n" \ + " bne %1, %z6, 2f \n" \ + " move $t0, %z7 \n" \ + " move $t1, %z8 \n" \ + " sc.q $t0, $t1, %2 \n" \ + " beqz $t0, 1b \n" \ + "2: \n" \ + __WEAK_LLSC_MB \ + : "=3D&r" (__ret.low), "=3D&r" (__ret.high) \ + : "r" (__ptr), \ + "ZC" (__ptr[0]), "m" (__ptr[1]), \ + "Jr" (__old.low), "Jr" (__old.high), \ + "Jr" (__new.low), "Jr" (__new.high) \ + : "t0", "t1", "memory"); \ + \ + __ret.full; \ +}) + static inline unsigned int __cmpxchg_small(volatile void *ptr, unsigned in= t old, unsigned int new, unsigned int size) { @@ -198,6 +236,15 @@ __cmpxchg(volatile void *ptr, unsigned long old, unsig= ned long new, unsigned int __res; \ }) =20 +/* cmpxchg128 */ +#define system_has_cmpxchg128() 1 + +#define arch_cmpxchg128(ptr, o, n) \ +({ \ + BUILD_BUG_ON(sizeof(*(ptr)) !=3D 16); \ + __cmpxchg128_asm(ptr, o, n); \ +}) + #ifdef CONFIG_64BIT #define arch_cmpxchg64_local(ptr, o, n) \ ({ \ --=20 2.48.1 From nobody Mon Dec 1 23:33:17 2025 Received: from out-170.mta0.migadu.com (out-170.mta0.migadu.com [91.218.175.170]) (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 D79E730B50D for ; Wed, 26 Nov 2025 02:06:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764122773; cv=none; b=JBxptOhCUDnQ1NnOXHF/GKeb8y1lMfLROgY6Ok68ySh2EmYGly2m/Z3lWavbCH7KJc0DyexqvKgyiMNzmHEnlwzcbok0FpetYsP9GGpyP40SnGV30QYSJ/aXqE/IIZ6UKmGXmLCSNYBTFzoOSz7RBwLHbf4rLfx9dQD5+M5NJGw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764122773; c=relaxed/simple; bh=8TifsbTNXqYIYqD9lXrhIsElmC4Aa87KXjt2KqkZcjI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KIqjQPiNslc+2++tEZUstKP4PoHsXUX1jdf5YA2Z1RVPpiu0EjHd3D52zD0niCGHT6GX7J4ihk8gTGRFDuE3AK6+Aof3pHlJ8RD/LcHvC7Pf+6kW/oSiUvzdbLAguHts8zt4CJd0ljF6NwFwsEpRUzZWdxAp9+adIhCbuVY9Xlk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=VC7tQSx2; arc=none smtp.client-ip=91.218.175.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="VC7tQSx2" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1764122767; h=from:from: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=qd6hbMJvs0YabNz3CCTWdf/jCMHxiJ1lcDXBCRGzJYI=; b=VC7tQSx2GWvoQl5CDS+jqGUm/3Y15uXxTw3eoZVwbPB53Df1zLs0yFoWXLP4RmQ5saoyx4 kXq5QssRG0UNdygsN898jAgzD7rcQaUPII91vOLPTW0yFqrkXfu4o8Li3glhcfKl+CVeR9 nVr9cC1er/puluA+u1/osRfI3JBwY2c= From: George Guo Date: Wed, 26 Nov 2025 10:05:51 +0800 Subject: [PATCH v3 2/2] LoongArch: Enable 128-bit atomics cmpxchg support 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 Message-Id: <20251126-2-v3-2-851b5a516801@linux.dev> References: <20251126-2-v3-0-851b5a516801@linux.dev> In-Reply-To: <20251126-2-v3-0-851b5a516801@linux.dev> To: Huacai Chen , WANG Xuerui Cc: loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, George Guo , George Guo X-Developer-Signature: v=1; a=ed25519-sha256; t=1764122759; l=1046; i=dongtai.guo@linux.dev; s=20251103; h=from:subject:message-id; bh=jJgZhwA4ooo3Ax4Z4naKB2Lj5KNiYF1TJyBIlsCbAQU=; b=EyzwY+EjUXHL5YSCwu7+wb0RxiIJz3LVNu5NtKXY13cQQzJ5Ii99mr4WisRxWmXW01LlPFxoZ 9qKcKOKjfKhBYDvaPnNUCFFpNDWh5MwhILDx1VpIcqmWv92y3J67zIo X-Developer-Key: i=dongtai.guo@linux.dev; a=ed25519; pk=yHUJPGx/kAXutP/NSHpj7hWW0KQNlv3w9H6ju4qUoTM= X-Migadu-Flow: FLOW_OUT From: George Guo Add select HAVE_CMPXCHG_DOUBLE and select HAVE_ALIGNED_STRUCT_PAGE in Kconf= ig to enable 128-bit atomic cmpxchg support on LoongArch. Signed-off-by: George Guo --- arch/loongarch/Kconfig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig index 5b1116733d881bc2b1b43fb93f20367add4dbc54..6fb2c253969f9ddece547892042= 3d7326c3ec046 100644 --- a/arch/loongarch/Kconfig +++ b/arch/loongarch/Kconfig @@ -114,6 +114,7 @@ config LOONGARCH select GENERIC_TIME_VSYSCALL select GPIOLIB select HAS_IOPORT + select HAVE_ALIGNED_STRUCT_PAGE select HAVE_ARCH_AUDITSYSCALL select HAVE_ARCH_JUMP_LABEL select HAVE_ARCH_JUMP_LABEL_RELATIVE @@ -140,6 +141,7 @@ config LOONGARCH select HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALLS select HAVE_DYNAMIC_FTRACE_WITH_REGS select HAVE_EBPF_JIT + select HAVE_CMPXCHG_DOUBLE select HAVE_EFFICIENT_UNALIGNED_ACCESS if !ARCH_STRICT_ALIGN select HAVE_EXIT_THREAD select HAVE_GENERIC_TIF_BITS --=20 2.48.1