From nobody Fri Oct 3 15:34:23 2025 Received: from mail-wr1-f73.google.com (mail-wr1-f73.google.com [209.85.221.73]) (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 BAE0A1DDF7 for ; Thu, 28 Aug 2025 12:28:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756384089; cv=none; b=Nm9jvGRGm03rvktvJS+MukN9xmbq2LuQG0I+69xFI/rldnGuPivCfZ8HKxXKbUL+MpCUVvBh+V2SW+xQhZW1qdg+nbol+JMlbyrDLaUe64dIkFOWMLPQvUu0NtFPFZwPcp+pcSQEp8r4+iRTkL03xSi1hkUprCSMeqrA0HlabcM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756384089; c=relaxed/simple; bh=GBInbJAJRj5ONLa1gt+nD49xcbsKA8ganwjzvi5pg4c=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=j7XNpa4pc8+6B0pKL62Ehutze6pFCys4SmmoTvPXjfxEUHe7eyk0sSkQzdMS2oj/CW4uwd9tHwTzbyDB3fcNI0DMivaLQtrz3YdH1o5H0QPQ+0v4dupssNNagKIsW8cfF/XLXRZ8QGnVwuenv7uQRUBeUwXpgZ6vleGdBvVTJYE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jackmanb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=TaFMVa6q; arc=none smtp.client-ip=209.85.221.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jackmanb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="TaFMVa6q" Received: by mail-wr1-f73.google.com with SMTP id ffacd0b85a97d-3c584459d02so627173f8f.0 for ; Thu, 28 Aug 2025 05:28:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1756384086; x=1756988886; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=NT5ndZiyJJqWCgiYx08dUhX4e7n0TWvqf6AS15EwVrA=; b=TaFMVa6qC3s0EPnSfEx/WJyzKAquVDgPozdbA4YkCNTad4TpgnnmM+4fJ3AHS/22Z6 0jpGFDXCY1crd+rrPzs8FiVK6aXo1cSR2fq1iAuo5OJ3K5qjY9iUVx3/G5T/CpgYKGCu oXKiCRxuQVZOy36b+U2VB+YVYGq5LE8GdjEl++OKo1ZuoTbnDErbK3UyP+sZYL0SYawB PmFR609Fff3w9jBGms+yf/29meuBKyzxuCPJA7p8lDPx/ubRXc0xdnrys0D40eq9xH/s uKjaavi4AT/acd85ztoBu+3PlY7ZklbuowtEiQ6i18XmH66KJSvqxWrqm+9bbdAsDxZs rpwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756384086; x=1756988886; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=NT5ndZiyJJqWCgiYx08dUhX4e7n0TWvqf6AS15EwVrA=; b=b39MsUmqTnpeXKT3Rc2Qc4KnQ5hZmaATyR+KA567BlXQuiYOuSTJUhnJNOOqjBslAm PSgtcKLW1g28/AOdO2BFkXlJ84dW4U4MhDVFpDhNO9GyWQ54XCmmhOOC11ygCs1P3+OM C/CpTa5xnKQKnnwrKRR/YrM68PoDXhlaQxyXTZRupJfVPW99XQvm33sjfMY0b1y3pDsi PGenK4iT480UhHl+5VSwaGFgNMfJzGBGIV/BQVod1bS//UBXWPixk8VwqqvgPtpK12L2 0BGxS66903dBlPilY4RhGCMusCEMYGrPfrI+vbGNVa+MZMCmvwnWNehwhnWzAWqTcNo9 K/kw== X-Gm-Message-State: AOJu0YwFLL4antSJg9Q2fAcmz2DSugNJp9qmvsbkGaY/5+oSWbtiSz8a noOco0gB1OzSKRyM4QEABKF0iQpl+jnfwYU+Jb50/wLQA4caYB/kRp8kz1xiTnxGJC2gZFNJtC8 pB+h3fTKx4501OA== X-Google-Smtp-Source: AGHT+IGJWI0ZFUz+7Oag9wdtFaUSV6+VfGrApOEbus6AYfztggP4vFm0mvCRRgVub8dgHHObAbgpSPShD8KaaQ== X-Received: from wmbel18.prod.google.com ([2002:a05:600c:3e12:b0:45b:732e:5a16]) (user=jackmanb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6000:1881:b0:3c9:24f5:470c with SMTP id ffacd0b85a97d-3c924f54bfemr12451964f8f.42.1756384086018; Thu, 28 Aug 2025 05:28:06 -0700 (PDT) Date: Thu, 28 Aug 2025 12:27:58 +0000 In-Reply-To: <20250828-b4-vma-no-atomic-h-v2-0-02d146a58ed2@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250828-b4-vma-no-atomic-h-v2-0-02d146a58ed2@google.com> X-Mailer: b4 0.14.2 Message-ID: <20250828-b4-vma-no-atomic-h-v2-1-02d146a58ed2@google.com> Subject: [PATCH v2 1/4] tools/include: Implement a couple of atomic_t ops From: Brendan Jackman To: "Liam R. Howlett" , Andrew Morton , Lorenzo Stoakes , Vlastimil Babka , Jann Horn , Pedro Falcato Cc: linux-kernel@vger.kernel.org, maple-tree@lists.infradead.org, linux-mm@kvack.org, Brendan Jackman Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The VMA tests need an operation equivalent to atomic_inc_unless_negative() to implement a fake mapping_map_writable(). Adding it will enable them to switch to the shared atomic headers and simplify that fake implementation. In order to add that, also add atomic_try_cmpxchg() which can be used to implement it. This is copied from Documentation/atomic_t.txt. Then, implement atomic_inc_unless_negative() itself based on the raw_atomic_dec_unless_positive() in include/linux/atomic/atomic-arch-fallback.h. There's no present need for a highly-optimised version of this (nor any reason to think this implementation is sub-optimal on x86) so just implement this with generic C, no x86-specifics. Signed-off-by: Brendan Jackman Reviewed-by: Pedro Falcato --- tools/include/linux/atomic.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tools/include/linux/atomic.h b/tools/include/linux/atomic.h index 01907b33537e04c5e860dd2cd61a61dfab6ea8f1..50c66ba9ada58cf05125e2e2472= 734bf3b0f8595 100644 --- a/tools/include/linux/atomic.h +++ b/tools/include/linux/atomic.h @@ -12,4 +12,26 @@ void atomic_long_set(atomic_long_t *v, long i); #define atomic_cmpxchg_release atomic_cmpxchg #endif /* atomic_cmpxchg_relaxed */ =20 +static inline bool atomic_try_cmpxchg(atomic_t *ptr, int *oldp, int new) +{ + int ret, old =3D *oldp; + + ret =3D atomic_cmpxchg(ptr, old, new); + if (ret !=3D old) + *oldp =3D ret; + return ret =3D=3D old; +} + +static inline bool atomic_inc_unless_negative(atomic_t *v) +{ + int c =3D atomic_read(v); + + do { + if (unlikely(c < 0)) + return false; + } while (!atomic_try_cmpxchg(v, &c, c + 1)); + + return true; +} + #endif /* __TOOLS_LINUX_ATOMIC_H */ --=20 2.50.1 From nobody Fri Oct 3 15:34:23 2025 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) (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 91C2130F547 for ; Thu, 28 Aug 2025 12:28:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756384090; cv=none; b=VIc3aZY0ruA4VjyxblWeGt7CEe91agTAkMSoum6ln2DZ/gcxPFYWzVtHaYTQK4id6s01qQLT5JjW0JHsDoShmwdTLEjA+SbjwdCddETs79E1A/4ZPTN/6+gB6tSrDRsQi1/nQiuBevOe6BsYjrLYOLpk/RT4IlyzT44MGQ1BMz4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756384090; c=relaxed/simple; bh=EmboPdxeD9U1RTTfc6lvCHB2Qk6VER1hrEBN1mp8C/0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=I4wI4kTYk4Yj7elsE+NtmmrKiYsA4eVDQA8zaplH74J1McOJezqUQa50O/+ORw2p44pfUoUMqyhwXwf9CLCUcb52mEe17cMKXtM7mgVKV7mGxYO1yc98n+eYQHGCSV7siSP9SfuLxsAIh8qoUEQTB5AVYqN6Fr10yrbiXsbErWU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jackmanb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=G1CR3y5G; arc=none smtp.client-ip=209.85.128.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jackmanb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="G1CR3y5G" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-45a1b0c5377so4554625e9.3 for ; Thu, 28 Aug 2025 05:28:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1756384087; x=1756988887; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=qm9V93bDt4mzncYEvbMk2UnVnKCadpO9FtS3vTNJKSc=; b=G1CR3y5GIyvjJPXQoCPNpN/zZUMrjlSSn9E7na6aU2wTEH5AXKIibvrHGyXXzbrUNV 7jYcVVQ/8e1k7bUgegfOuL4q6binATc8pbstwW31Z4KiGKOaMT/wY0ECp/LndNwXW5HK r+ZBPtz4S9rx60IKR+eauDkqmIDxWvClDrN68cmPyZsiJjlILezkIm/Yp1bt5NEzoRsD UTsG65VH+WmTIKCT0RJOUDy4sC2XMNCiQE6I4zXirAgtrcSKCaV5imHyvcl2k2o3YleL JsSwgIucNlyE9jxC0wMg0wpwp5rjFUzNPP5SNo20WETRX/HoSQe005UYmsmNO8mrJ4Tx z/Hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756384087; x=1756988887; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=qm9V93bDt4mzncYEvbMk2UnVnKCadpO9FtS3vTNJKSc=; b=WyTo7XXs/eXsVTRY3Qhhiq3/syCDuez7hh5kRnJQbZo2hpPjcEIr17tF0k1LBjESxq 3VSxSAQj0HMUZLuQ43aTHWuIm1r3+iZynA/e9dF+zePKan0/EsEBYkeXf6+UikuDdkNt i0M9VAWesbccM8YMse2T13Is2tji6mQJiP61xeebAU4xzTgKTrGM++wlIUREmSdPrGZU wxPQjYuQYpqNIx8lgduJtVh/lhFz/G4NQlY7oy0hvd9fKJo2mKa20uAEvzfg8Wyy8q4+ WS4S12IaniV4SsYvD4ZYtBmajrBikA601TjJ1EOUK/AYJT8XBphP+TolfKb6uy646jpX wetg== X-Gm-Message-State: AOJu0YxfNXOCUGtJPNXJJBxLUelpA3/oTzjTMIXAZtRXnmYBCj13/5IL 1QQdxRl5U9jZwBeXjglUiEKZGf3YEvvJJR+k392pik+XKNyYKivEzmBpT/jOq8p7YeXz7VOz6iU Q6Tnmua4zBSPYCQ== X-Google-Smtp-Source: AGHT+IHX4/WrNzbX/FYn6VIRfFQuxMO4r/uZ6gK2OY/lKgZ1ymFGCjrrA2HbF5ORNJdD5g5bjBWjoWc/vSleOQ== X-Received: from wmte19.prod.google.com ([2002:a05:600c:8b33:b0:45b:73cf:2862]) (user=jackmanb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:1f95:b0:453:78f:fa9f with SMTP id 5b1f17b1804b1-45b5179cfa5mr199709225e9.11.1756384087019; Thu, 28 Aug 2025 05:28:07 -0700 (PDT) Date: Thu, 28 Aug 2025 12:27:59 +0000 In-Reply-To: <20250828-b4-vma-no-atomic-h-v2-0-02d146a58ed2@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250828-b4-vma-no-atomic-h-v2-0-02d146a58ed2@google.com> X-Mailer: b4 0.14.2 Message-ID: <20250828-b4-vma-no-atomic-h-v2-2-02d146a58ed2@google.com> Subject: [PATCH v2 2/4] tools: testing: Allow importing arch headers in shared.mk From: Brendan Jackman To: "Liam R. Howlett" , Andrew Morton , Lorenzo Stoakes , Vlastimil Babka , Jann Horn , Pedro Falcato Cc: linux-kernel@vger.kernel.org, maple-tree@lists.infradead.org, linux-mm@kvack.org, Brendan Jackman Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable There is an arch/ tree under tools. This contains some useful stuff, to make that available, add it to the -I flags. This requires $(SRCARCH), which is provided by Makefile.arch, so include that.. There still aren't that many headers so also just smush all of them into SHARED_DEPS instead of starting to do any header dependency hocus pocus. Reviewed-by: Lorenzo Stoakes Reviewed-by: Liam R. Howlett Acked-by: Pedro Falcato Signed-off-by: Brendan Jackman --- tools/testing/shared/shared.mk | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/testing/shared/shared.mk b/tools/testing/shared/shared.mk index 923ee2492256b693c5cf16cc014d9d2410be5457..937aaa7623320da1085a8e0f43f= 6a728ddd3ab1c 100644 --- a/tools/testing/shared/shared.mk +++ b/tools/testing/shared/shared.mk @@ -1,6 +1,8 @@ # SPDX-License-Identifier: GPL-2.0 +include ../../scripts/Makefile.arch =20 -CFLAGS +=3D -I../shared -I. -I../../include -I../../../lib -g -Og -Wall \ +CFLAGS +=3D -I../shared -I. -I../../include -I../../arch/$(SRCARCH)/includ= e \ + -I../../../lib -g -Og -Wall \ -D_LGPL_SOURCE -fsanitize=3Daddress -fsanitize=3Dundefined LDFLAGS +=3D -fsanitize=3Daddress -fsanitize=3Dundefined LDLIBS +=3D -lpthread -lurcu @@ -11,6 +13,7 @@ SHARED_DEPS =3D Makefile ../shared/shared.mk ../shared/*.= h generated/map-shift.h \ generated/bit-length.h generated/autoconf.h \ ../../include/linux/*.h \ ../../include/asm/*.h \ + ../../arch/$(SRCARCH)/include/asm/*.h \ ../../../include/linux/xarray.h \ ../../../include/linux/maple_tree.h \ ../../../include/linux/radix-tree.h \ --=20 2.50.1 From nobody Fri Oct 3 15:34:23 2025 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) (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 E036F30F81F for ; Thu, 28 Aug 2025 12:28:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756384091; cv=none; b=GXuZIqvkCaLPr1Za2RKJswBajKoP99mMfaViPBxnZD6er9Ft+E4eG7T2tLzFEMHnmARNSfxM86caOwT/ngrrNYTKNEdReXNwN/GPFVETufDklWD4OMGuI6RvfeJ3C6qbmhGHzIBWK/kx0k9qRRC0jBrirrtPFj8Fy/ubrH/SndA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756384091; c=relaxed/simple; bh=vQkMd7Qf2k97SxOL52I26gjziGPAAlEoamanWdcsTro=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=E6oUzGCVRImprGJ+V5HQdsv04Ei4IYN2CEBOM+tsXydUIdNY6PJ1v40Tl/rcq6SOwRneRybO8byYEXOrtZz1Qa9OMebEni/ta8fyHH8ZLRPPgy7MCyawR9QgcLICf36k7CBhoFLOcktULt9W3IoUUVO79G8rsO00eYH5JO5I2/U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jackmanb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=EElO/fW7; arc=none smtp.client-ip=209.85.128.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jackmanb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="EElO/fW7" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-45a1b0511b3so5624775e9.1 for ; Thu, 28 Aug 2025 05:28:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1756384088; x=1756988888; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=/6dT2kIzhUObfcC4J3vqd7faAhyAUusYo8WMwaL7OG0=; b=EElO/fW7nJ9YMS2sfKjZs3SZTn36+jeozx3WnFPOsNbfJ3tMJL7iNOWJ545EDNQgrs bSvOUZF3339ystO4txowJFAXWpEBKHs2eDYAlKwcQBrQ7OWf0O/yqKOSudapYlT9qdId vguUEIzq8i7n7+Nl3EIHjJSyv2flE4iBjlhX3ng525jhHBzgXyAc0si6cbt9kvg8pQiF tqIJSYzTEepraqWkqxW+sy04VURrAbT+icOVI6N7H7IhggtAh7d+xinXkxcjCRDyxz4U Kt83SrniIrBIm3YnghdLTxQgZ6K2w7Qd63ROARf8OkJbFIJnINecqLph8cbiKOnNl+1e nsMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756384088; x=1756988888; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/6dT2kIzhUObfcC4J3vqd7faAhyAUusYo8WMwaL7OG0=; b=hn1DGWhssmJthkYQ7oJ6xPb3sgjne44KWa0ka1tSEFijNrCvCALK3jShrZErIxxt8S tCPyNbhDU7R6RmRERd/2Cz6Zx5bJWrIYr1T7M24pCT2/0ENeoT0nUjQYlQXZt0cPPWcy ImAHJmCd67rFuXqCh/VcGQRDsm6Nx2/4ln6GOatDMrlMTj8k3z3GCMylxcIQCTKVVk8b aiGT81fWyyRl2GXn0WZnhILtRirhbQMGPMw1m5Rt3PNQTf91x6pj3WxlW2w2ARe+vtxR 7y96crtE/U0b0vs8G5lZGpk6D5v+nUzC1HU5ciF28wgGcovRRSWIbcQhBNthFG43gpbq 1daw== X-Gm-Message-State: AOJu0Yy0qxEhtDg3ZB2pBm2aBXd0Y6glFVfTAv807qQm3jGxkgrnJ5kD zoU8eNfl9fjbDOOVeEFdF1VaUC9CHkn+dsGxNpSJ/979NftAwxnYdP/bFw0tY2mcUqJdPXb5h/I cjqTERmMSuvyzpQ== X-Google-Smtp-Source: AGHT+IHKlzslKK7RObgYwxB2Fi8fBbrlynksOPFwGRWJ5LPhLhzhqfjYPPoqRNKcPdh8DdvfOT2SAEyk1oi/WQ== X-Received: from wmbay6.prod.google.com ([2002:a05:600c:1e06:b0:459:e01c:3d6d]) (user=jackmanb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:3b15:b0:458:c059:7db1 with SMTP id 5b1f17b1804b1-45b517d4580mr224468945e9.30.1756384088185; Thu, 28 Aug 2025 05:28:08 -0700 (PDT) Date: Thu, 28 Aug 2025 12:28:00 +0000 In-Reply-To: <20250828-b4-vma-no-atomic-h-v2-0-02d146a58ed2@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250828-b4-vma-no-atomic-h-v2-0-02d146a58ed2@google.com> X-Mailer: b4 0.14.2 Message-ID: <20250828-b4-vma-no-atomic-h-v2-3-02d146a58ed2@google.com> Subject: [PATCH v2 3/4] tools: testing: Support EXTRA_CFLAGS in shared.mk From: Brendan Jackman To: "Liam R. Howlett" , Andrew Morton , Lorenzo Stoakes , Vlastimil Babka , Jann Horn , Pedro Falcato Cc: linux-kernel@vger.kernel.org, maple-tree@lists.infradead.org, linux-mm@kvack.org, Brendan Jackman Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable This allows the user to set cflags when building tests that use this shared build infrastructure. For example, it enables building with -Werror so that patch-check scripts will fail: make -C tools/testing/vma -j EXTRA_CFLAGS=3D-Werror Reviewed-by: Lorenzo Stoakes Reviewed-by: Liam R. Howlett Acked-by: Pedro Falcato Signed-off-by: Brendan Jackman --- tools/testing/shared/shared.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/testing/shared/shared.mk b/tools/testing/shared/shared.mk index 937aaa7623320da1085a8e0f43f6a728ddd3ab1c..5bcdf26c8a9d51ab2cbd264f2f8= a7445d7c036e3 100644 --- a/tools/testing/shared/shared.mk +++ b/tools/testing/shared/shared.mk @@ -4,6 +4,7 @@ include ../../scripts/Makefile.arch CFLAGS +=3D -I../shared -I. -I../../include -I../../arch/$(SRCARCH)/includ= e \ -I../../../lib -g -Og -Wall \ -D_LGPL_SOURCE -fsanitize=3Daddress -fsanitize=3Dundefined +CFLAGS +=3D $(EXTRA_CFLAGS) LDFLAGS +=3D -fsanitize=3Daddress -fsanitize=3Dundefined LDLIBS +=3D -lpthread -lurcu LIBS :=3D slab.o find_bit.o bitmap.o hweight.o vsprintf.o --=20 2.50.1 From nobody Fri Oct 3 15:34:23 2025 Received: from mail-ej1-f74.google.com (mail-ej1-f74.google.com [209.85.218.74]) (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 20BA730F7F5 for ; Thu, 28 Aug 2025 12:28:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756384092; cv=none; b=CaFHm1vwc6At6r6hniygKR0YFiTgs46O3LAuirvMi/c7JbLvls/J4untEzZK6JdvHZj+zgshfcghWWsMN58GstwhzVN+6NTgXWVaQIALRWp1fxn0HPoK35oq3UgfMj1eu/CgwxJVObs15sQZ2XAXwH4QgT2RGTrmW39ULpTwe1E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756384092; c=relaxed/simple; bh=DpUor3KEsPz2OnQ+Y4omnUce5SVbQSwW5xNxUaGt4Xg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=mLU5DSxo10Zi3TW1Wr9lLsxsFVxXG+Esk3+SMBQ3nZ3oUkPlEPbwhLA1Ue87+iRcXzTyZOnW2j6svJCCLCYs2trHTsUu5ywmkviIQ7w1hwNJoWklGyanu+DTs5Yxkxj1ZL1JrMGRZnuB+PeMenbPPCRLpB1fyYfU3UCUtHETRhg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jackmanb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=eZ+Rhb9B; arc=none smtp.client-ip=209.85.218.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jackmanb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="eZ+Rhb9B" Received: by mail-ej1-f74.google.com with SMTP id a640c23a62f3a-afcb72a8816so74948066b.0 for ; Thu, 28 Aug 2025 05:28:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1756384089; x=1756988889; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=l7cTx8YnEK6PXjAxYIM2TxKBSe00LYvnBB3H2O1o/mY=; b=eZ+Rhb9B5cuYJ8wD5DXbrnu/Q2qfwRimVpZBB8XMccc+kfx1ixAyLgJb5n5naKSVuk BE8N58vEVDK1rYPvYUjMgpzv4l4HJRS3bNq2hag0RGQwMJRDv+fEaqnEbJfNJWQx9UV1 VkI+9g8rQb1L4UzpvxpxpeasP7dzGPoEqqVlLeG4q818ikCXvmM+uUAGmTg4L7psN9/8 eberFN8txNYacSdAKCG+iBSnRShRr5i4ksf3fjn3xDJiy4tuD72sBRu4KXP5jHLktwjQ yTzSLgieWE7Pguip/KKj1vpR5D/Z48Suk5Fp5OCpWLb180BHrSu6s8NB2eYiqDUQME6t 4xCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756384089; x=1756988889; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=l7cTx8YnEK6PXjAxYIM2TxKBSe00LYvnBB3H2O1o/mY=; b=Pjf1/lBHGhMkb2iDLr1UoyiphlWxSw9EZo/t+NsH+f+I47srAjOnlz1sspi9xWVoGb wdysRmERle/KFVtuwAF09E8T+j6xspNweOManSXiy+FDv/KBpzYLIgAIlmuQBqTi937+ SncAZQj65ANcUYOrfic8QQkGNhX8bbwz8m65BKsscY5bXm/HiDDwD1B56ivgBzVszi1e nbRZS/dTCaiIw9G7c9tJVF2i3Ymm4zZRULKuABZcwO3kBqz/egJehoXkjvzaSZeo7YwK T+gfEWlqJqlqsHbk6sbmVbaCQOS+jrLWL090vqMXlqPLXanFIY29rhYaUMMbd9/8ZC5f zlKw== X-Gm-Message-State: AOJu0YzhHgjBtZ5Avm+4nfL6fZXTX8wfAA7lNb4ihaGFb1XtWad+ne0P ykKskE9Rjn632SvRjTZVzMwLVr4TpZdwwZgn42mdGaY+9NTfIAJWFEkPhCC/zSpg0XDaYzWNZik w4/o5aULMwjVoxw== X-Google-Smtp-Source: AGHT+IEjpL3mL9YVYzvlFjpNuB2q7yGo5muV6qRmjgMsPd3KcbfmlJV+kvknHo72hH9YYv52hL3iJ2LhDTES2w== X-Received: from ejcvj16.prod.google.com ([2002:a17:907:d490:b0:afe:af3c:d8b]) (user=jackmanb job=prod-delivery.src-stubby-dispatcher) by 2002:a17:907:7e9c:b0:af9:8c1f:b290 with SMTP id a640c23a62f3a-afe28f6a866mr1820910266b.29.1756384089249; Thu, 28 Aug 2025 05:28:09 -0700 (PDT) Date: Thu, 28 Aug 2025 12:28:01 +0000 In-Reply-To: <20250828-b4-vma-no-atomic-h-v2-0-02d146a58ed2@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250828-b4-vma-no-atomic-h-v2-0-02d146a58ed2@google.com> X-Mailer: b4 0.14.2 Message-ID: <20250828-b4-vma-no-atomic-h-v2-4-02d146a58ed2@google.com> Subject: [PATCH v2 4/4] tools: testing: Use existing atomic.h for vma/maple tests From: Brendan Jackman To: "Liam R. Howlett" , Andrew Morton , Lorenzo Stoakes , Vlastimil Babka , Jann Horn , Pedro Falcato Cc: linux-kernel@vger.kernel.org, maple-tree@lists.infradead.org, linux-mm@kvack.org, Brendan Jackman Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The shared userspace logic used for unit-testing maple tree and VMA code currently has its own replacements for atomics helpers. This is not needed as the necessary APIs already have userspace implementations in the tools tree. Switching over to that allows deleting a bit of code. Note that the implementation is different; while the version being deleted here is implemented using liburcu, the existing version in tools uses either x86 asm or compiler builtins. It's assumed that both are equally likely to be correct. The tools tree's version of atomic_t is a struct type while the version being deleted was just a typedef of an integer. This means it's no longer valid to call __sync_bool_compare_and_swap() directly on it. One option would be to just peek into the struct and call it on the field, but it seems a little cleaner to just use the corresponding atomic.h API whic has been added recently. Now the fake mapping_map_writable() is copied from the real one. Reviewed-by: Lorenzo Stoakes Signed-off-by: Brendan Jackman --- tools/testing/shared/linux/maple_tree.h | 6 ++---- tools/testing/vma/linux/atomic.h | 17 ----------------- tools/testing/vma/vma_internal.h | 12 +++--------- 3 files changed, 5 insertions(+), 30 deletions(-) diff --git a/tools/testing/shared/linux/maple_tree.h b/tools/testing/shared= /linux/maple_tree.h index f67d47d32857cee296c2784da57825c9a31cd340..7d0fadef0f11624dbb110ad351a= abdc79a19dcd2 100644 --- a/tools/testing/shared/linux/maple_tree.h +++ b/tools/testing/shared/linux/maple_tree.h @@ -1,7 +1,5 @@ /* SPDX-License-Identifier: GPL-2.0+ */ -#define atomic_t int32_t -#define atomic_inc(x) uatomic_inc(x) -#define atomic_read(x) uatomic_read(x) -#define atomic_set(x, y) uatomic_set(x, y) +#include + #define U8_MAX UCHAR_MAX #include "../../../../include/linux/maple_tree.h" diff --git a/tools/testing/vma/linux/atomic.h b/tools/testing/vma/linux/ato= mic.h deleted file mode 100644 index 788c597c4fdea7392307de93ff4459453b96179b..000000000000000000000000000= 0000000000000 --- a/tools/testing/vma/linux/atomic.h +++ /dev/null @@ -1,17 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ - -#ifndef _LINUX_ATOMIC_H -#define _LINUX_ATOMIC_H - -#define atomic_t int32_t -#define atomic_inc(x) uatomic_inc(x) -#define atomic_read(x) uatomic_read(x) -#define atomic_set(x, y) uatomic_set(x, y) -#define U8_MAX UCHAR_MAX - -#ifndef atomic_cmpxchg_relaxed -#define atomic_cmpxchg_relaxed uatomic_cmpxchg -#define atomic_cmpxchg_release uatomic_cmpxchg -#endif /* atomic_cmpxchg_relaxed */ - -#endif /* _LINUX_ATOMIC_H */ diff --git a/tools/testing/vma/vma_internal.h b/tools/testing/vma/vma_inter= nal.h index f13354bf0a1e3839327da7927c4a7da1530a1693..437d2a1013be418c6d3e77534fa= 19b0ee1518c9b 100644 --- a/tools/testing/vma/vma_internal.h +++ b/tools/testing/vma/vma_internal.h @@ -21,6 +21,7 @@ =20 #include =20 +#include #include #include #include @@ -1398,15 +1399,8 @@ static inline bool map_deny_write_exec(unsigned long= old, unsigned long new) =20 static inline int mapping_map_writable(struct address_space *mapping) { - int c =3D atomic_read(&mapping->i_mmap_writable); - - /* Derived from the raw_atomic_inc_unless_negative() implementation. */ - do { - if (c < 0) - return -EPERM; - } while (!__sync_bool_compare_and_swap(&mapping->i_mmap_writable, c, c+1)= ); - - return 0; + return atomic_inc_unless_negative(&mapping->i_mmap_writable) ? + 0 : -EPERM; } =20 static inline unsigned long move_page_tables(struct pagetable_move_control= *pmc) --=20 2.50.1