From nobody Sat Oct 4 06:29:31 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 CDF99322A22 for ; Tue, 19 Aug 2025 10:34:53 +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=1755599695; cv=none; b=ukn6vUm8O0qLk9/9xDoLaxBCw46sWIecinqjJ1ikOdTx0BPLA4bzf56f4tL7Bp/mo1Hj8L1zKIxSODYWCLFGpx5tS+Amd9yZEGc01dtx/FOuKFC2hem2T5GogVQHU22lIzu4miX8KsgOUnIKq1ZDdtFTg9XexQXwAWlbatthX4M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755599695; c=relaxed/simple; bh=7lgTDryzjPL5Xg/gMsVbQOEVBBvts7hg247LEVfqcuA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=F3SwlLANOMqhEU8gbgpOd1tFB+8rSO6a2PRLy31ozEi7l795OsQ5GkyazAQ0npxqFBP+MqCDFjkhTkVoG30br7CroigdTYyw8is/ISrHVbKZVEn6YhUJX7EgoKTcCDMQAtobkDXElRjoyicbnNuMUH+nMWj+npd07rzFAh7qpt4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=v1jb0Lmb; 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--aliceryhl.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="v1jb0Lmb" Received: by mail-ej1-f74.google.com with SMTP id a640c23a62f3a-afcb78d3b3cso413766666b.1 for ; Tue, 19 Aug 2025 03:34:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1755599692; x=1756204492; 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=08JqJr7G1gjWdMKCvvnL7bTDodkNWFyfbH7nQBOCVjE=; b=v1jb0Lmby8zlsQVVBpuNI8ZPtR00i8HV+DNVAIwrzHvXXQZbXt+DQQK3sfWaxgO79f pkFEmR1isqLU1tebvvQ5WFR9w7iLU7zM6UOsMg9x9IkE1QAIfVkw3acy3K8wY9y8NhNR FU199ViLd0b4+GctuH8JL0WG9noY03O1zS+yWyol/UcX1O8iyNyb+K+/QJ04L5T/5k9s CwAGJz4j/7sz9Q3GHYzS3Ufw13tCS0NF1xo2RyX4iNImJj1jwuFrdypa50T662MogybW hF3K+hf5SiNvfMbEQDd0HS4Ee2yjElLdsaiiQllR3BrVGnuz8Zy3iC8VdmVr9XRUOL3g okMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755599692; x=1756204492; 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=08JqJr7G1gjWdMKCvvnL7bTDodkNWFyfbH7nQBOCVjE=; b=b0/xnzPb3FiJ6f36fns8Em5H1QGLM7jI8pyJecic32om/wIK7Civmvm/HLqmkmzCkg BBNVTdZQlISgDjaFoL9OMz0Mqf5/PwPbO8dpEPFJ4RthSN1akJSnekod+qvb/7eNe10G 1hqrqMDZwDJW91GsUK5j+V08YmNjGTV/Y/TWrBc4t1Ivx7A/K1/Ym6ji69dO+fs09pLA lwu1ug9WzN1XjAPSTIniJspsyzu2c7pIiXG/0Dz3Esm788K0qJQTpSgITpG5JOY2pU+q 9TKIX5WyFFM7JgYniE8LT2sCpPS2KMVSud/TgWk7HPaWZanmRH4QCpvGK7MCf+TQVzXN Phag== X-Forwarded-Encrypted: i=1; AJvYcCWMxTCgtA2fSmG88rQTd7MeEafB3vNO2Zw9+5xJTJReaGL0PhT1o5GQY3lomQRXQFRKvRWEuF8fB6bny/I=@vger.kernel.org X-Gm-Message-State: AOJu0YxdxbP0M6aEQNnA9tZ3EqeD3TIDL5CHfhm0OHrwksyxFGp0o0Sc RZHlIkuFlm2Xns+LK2AoredOSlFt+ZbQog26JAiRf5ZD8K0XaPkVk/oAy17OR3iMRE+c6yyzheU xXqka3QRIBSeNBVfEQA== X-Google-Smtp-Source: AGHT+IFSburLeN/bZPFzEEv5PgVznU3wJsVBP4Za2PFk07p+aJbgcziyUbh1qo8zQ4cn+Sc8HH0/fLdWChO+yMs= X-Received: from edf23.prod.google.com ([2002:a05:6402:21d7:b0:619:ac6:aec3]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a17:906:478b:b0:ae3:f299:ba47 with SMTP id a640c23a62f3a-afddcfbe96amr204399666b.32.1755599692268; Tue, 19 Aug 2025 03:34:52 -0700 (PDT) Date: Tue, 19 Aug 2025 10:34:42 +0000 In-Reply-To: <20250819-maple-tree-v2-0-229b48657bab@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250819-maple-tree-v2-0-229b48657bab@google.com> X-Developer-Key: i=aliceryhl@google.com; a=openpgp; fpr=49F6C1FAA74960F43A5B86A1EE7A392FDE96209F X-Developer-Signature: v=1; a=openpgp-sha256; l=1889; i=aliceryhl@google.com; h=from:subject:message-id; bh=7lgTDryzjPL5Xg/gMsVbQOEVBBvts7hg247LEVfqcuA=; b=owEBbQKS/ZANAwAKAQRYvu5YxjlGAcsmYgBopFNJHnIw9YCL5xST5YbjRd/Fzqnm1QmO+dTfa R9nNQweAv6JAjMEAAEKAB0WIQSDkqKUTWQHCvFIvbIEWL7uWMY5RgUCaKRTSQAKCRAEWL7uWMY5 Rps+D/99qMIDJ4FAIG06+w4Pu047hC0WFaEATdHVtqYrnG0o9tOBFTfCf2vmCTWFGrKSDW7Dtrp eryDx27c4f0TvBZK96kS4KmjNAWOnw3rPIbkY6By4WnBvNg5fWrKNNyI3QDZ+igp+xOANglhCwW KNoXBOmawcL+/Mh1TNZjNYjHr2ORd73s4qCl2KwA6fMRT0d/x2hRo5nk+pR7PQycyLa3tFVPGPs wJyhT0wBS9/y5+Gy+DMf2e6PBSq/+83z4WwL56wOLBv6AjEvezT3B7N6lY9GcVwIXVGZjxRsimb CA7uYTZ8Zsh60pNTfARC2FGcVpKsioQPaS2qfXVRfbjQgXy4TuxOxU/wdl8XEtlCl3hgOP2MVVy P2wgzi76vgMmK4xp7OdzS41dyaFHOIfRnRfFSJgFt0VtxWffccMpRfHyRhSfJXai7eKddUqZhL0 6Tgb3ip7bQDBqVLn2KrXGrWXDVmKGUjP0Tyvhip8Q7O5NMwCqNQ26gZdlhF2/gw0ZQlWipcN7b8 oLvmfvoYyk9iN7KbRPb0cTzn4QxYcNPy7kGAo03XDAHqioDNg6N3hDi/fDTtEw909c1Rq+SfMOI f7GZxUIiRK/bVeCKDjgqR6ds9j18xtrinjh1lJbIQtpNmDELQ/BqdlnlGGHeH/sM+Ks2B1eV1jD 0RLYklyP7QzszoA== X-Mailer: b4 0.14.2 Message-ID: <20250819-maple-tree-v2-1-229b48657bab@google.com> Subject: [PATCH v2 1/5] maple_tree: remove lockdep_map_p typedef From: Alice Ryhl To: Andrew Morton , "Liam R. Howlett" , Lorenzo Stoakes , Miguel Ojeda , Andrew Ballance Cc: Boqun Feng , Gary Guo , "=?utf-8?q?Bj=C3=B6rn_Roy_Baron?=" , Benno Lossin , Andreas Hindborg , Trevor Gross , Danilo Krummrich , linux-kernel@vger.kernel.org, maple-tree@lists.infradead.org, rust-for-linux@vger.kernel.org, linux-mm@kvack.org, Alice Ryhl Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Having the ma_external_lock field exist when CONFIG_LOCKDEP=3Dn isn't used anywhere, so just get rid of it. This also avoids generating a typedef called lockdep_map_p that could overlap with typedefs in other header files. With this change, bindgen will generate better definitions for this union, which makes it nicer to use from Rust. This avoids a cast in the Rust abstractions for the maple tree, ensuring that Rust's type checker will notice at build-time if ma_lock is changed from spinlock_t to something else. Signed-off-by: Alice Ryhl Reviewed-by: Danilo Krummrich --- include/linux/maple_tree.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/linux/maple_tree.h b/include/linux/maple_tree.h index bafe143b1f783202e27b32567fffee4149e8e266..8244679ba1758235e049acbaede= e62aae5c0e226 100644 --- a/include/linux/maple_tree.h +++ b/include/linux/maple_tree.h @@ -194,7 +194,6 @@ enum store_type { #define MAPLE_RESERVED_RANGE 4096 =20 #ifdef CONFIG_LOCKDEP -typedef struct lockdep_map *lockdep_map_p; #define mt_lock_is_held(mt) \ (!(mt)->ma_external_lock || lock_is_held((mt)->ma_external_lock)) =20 @@ -207,7 +206,6 @@ typedef struct lockdep_map *lockdep_map_p; =20 #define mt_on_stack(mt) (mt).ma_external_lock =3D NULL #else -typedef struct { /* nothing */ } lockdep_map_p; #define mt_lock_is_held(mt) 1 #define mt_write_lock_is_held(mt) 1 #define mt_set_external_lock(mt, lock) do { } while (0) @@ -230,8 +228,10 @@ typedef struct { /* nothing */ } lockdep_map_p; */ struct maple_tree { union { - spinlock_t ma_lock; - lockdep_map_p ma_external_lock; + spinlock_t ma_lock; +#ifdef CONFIG_LOCKDEP + struct lockdep_map *ma_external_lock; +#endif }; unsigned int ma_flags; void __rcu *ma_root; --=20 2.51.0.rc1.167.g924127e9c0-goog From nobody Sat Oct 4 06:29:31 2025 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.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 02F32322C75 for ; Tue, 19 Aug 2025 10:34:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755599697; cv=none; b=ZvNVgJcsFPAlce/rcsi2pj+fTPau7XlDoHiwWyCE6B8AVHHlzDpFJ8X4DCu5CzhWdP5nTrcZT84dO6jHzDGkfoAXudhADeYk7/1cincbK/re8hzQ8QsBkvEzepFmjTpR0EDweITGvoqlvBD/IJjYrqu0P7BB79lpimY1nWppBZY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755599697; c=relaxed/simple; bh=MKxYbHHLM/JS9toYpXewsAShbLKnjFbJwKsiTwhjAmo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=cjmkHnatCPyvNg6Z3QRhimYh4nRdGK+yDliIC0cJek3XGttDlK8tepowFTZOw1e73xWLS+6r6fuuQ/ocyvBpqfDZC7ivXavP2F4emXVZx8s6mhmCt6HWwi0jCfpnJ232hi+103HvqN/5aGF+/QbDCjKETXD1+c7DwPNhRPpBhI4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=CnsBVLEc; arc=none smtp.client-ip=209.85.128.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--aliceryhl.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="CnsBVLEc" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-45a1b0d221aso21302515e9.3 for ; Tue, 19 Aug 2025 03:34:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1755599693; x=1756204493; 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=Pfxca/vdoEge9OPiAMRUJ8vrOmkvClzZNcHuu539GzA=; b=CnsBVLEc7OLrXFqXULHcN+Kj3Fiz+kQR6skSVf3nZvSdnR22V7oYFkInkS6luNcAt4 /eUknRAhqyqD09CLjADsQXWTtR/lfDiZ3v/kQucj15u+2ymgIH874XLlXSYJlYmGGrKO +9OP+dTOtm6oWYfQcOcRCleu9Up4XDz4LGSf4rxxqi3wq5BWKquE37hrZYXC5X2UbP94 jSZ8onxUUpCowpN5dGtDhLC7o2rtCjhkNQLqVYSWWW3//RdDk3IZovZcOLSqyXSrjYvs IVL+GCHotLN1rpuO4wLqJtnTAfdGj3bX6oa2F/nVKTxD5ODLgX3T1yaQ+1+NWyFhdLkZ SO8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755599693; x=1756204493; 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=Pfxca/vdoEge9OPiAMRUJ8vrOmkvClzZNcHuu539GzA=; b=DW1afVa89PYNCXa4jGh21+cLJzRzt7hy8VUP4xsOy61RJcQCsDCtULmy+pyhUNpQb0 ca9yqdy0ZNBfbNwx6ICetdEqIQ2w9WNdEXltCweSjfA/SkVxoJXmzvHlOXvdOuYV8a1f xLDKzcqT8C1vCI9qQwQpw3K0jeA82eLmL6oUm4EsLzY3F0KcPPkdXvLMyxTlTNYriSUq Niyq9Ncmy+zrDiM678XIplIIcljVAi5TAEjV9f8BG1QKq+Nb77rtxpOzHmWDKW6cLXX3 +xfcF6BjRBOl38lXKatBqHBjeoK52pNdlToIANj12FzRl+trSe+aXu2nZd+BZ8omd9OG K2nA== X-Forwarded-Encrypted: i=1; AJvYcCVBL1XKGIlhnbtrJNilRUlTGQqAa6OgY9k8TQ0Ygpi8sVK2Ntl8xV/9qjwd7/an0413OrqhFfLUpGIoj1o=@vger.kernel.org X-Gm-Message-State: AOJu0Yzns+lxgmYvXVKT+T3W4WxpMEas7cdxUej3i/3TLmpnIfbWKc37 MC9Qh0lDILDSRswL74eTH+uyJgienJBaBgI2hiFbig0Pj4pHzDfut6NrE/nt3uzNBam0tljSgcy OYEZwuupxNWJZlDHaHg== X-Google-Smtp-Source: AGHT+IE57bom5MOYeyMuvrnfkCdbg5uwjHWFrgxzmpQzVFKeaDq24eHhOQXjlw+2VnC0x+p+7UfkiwxufCL15t8= X-Received: from wmbee6.prod.google.com ([2002:a05:600c:6406:b0:459:dd4e:4446]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:3b89:b0:459:df07:6da4 with SMTP id 5b1f17b1804b1-45b43db53f3mr18052995e9.5.1755599693386; Tue, 19 Aug 2025 03:34:53 -0700 (PDT) Date: Tue, 19 Aug 2025 10:34:43 +0000 In-Reply-To: <20250819-maple-tree-v2-0-229b48657bab@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250819-maple-tree-v2-0-229b48657bab@google.com> X-Developer-Key: i=aliceryhl@google.com; a=openpgp; fpr=49F6C1FAA74960F43A5B86A1EE7A392FDE96209F X-Developer-Signature: v=1; a=openpgp-sha256; l=15522; i=aliceryhl@google.com; h=from:subject:message-id; bh=MKxYbHHLM/JS9toYpXewsAShbLKnjFbJwKsiTwhjAmo=; b=owEBbQKS/ZANAwAKAQRYvu5YxjlGAcsmYgBopFNJW8HjTuKaNTMMaf5soBbGn6cWprflZ3DM3 g4Wxhas46uJAjMEAAEKAB0WIQSDkqKUTWQHCvFIvbIEWL7uWMY5RgUCaKRTSQAKCRAEWL7uWMY5 RgwaEAClw7fEaNGNDJfFzVq5Z1dWBxpmcNKiiURuKUqrV2bQ31x1M6W0d9kkEWBeEr2qOcN4Vcm LEeB8JmUZNrrhPbbRqtauL8i5y8psswkTTQdItN28AXfEBYU1tHsyJDRuGJh1rFls9zNq1V44k6 FxpBlp4jrf5ds2oFAh4VIs5UlP/UHyfOu5zPhVIk/eB4iPuBsw6NdVwtprLmHcIGX5DQKhwSX8Z H+eIYMr44wLWDFgx3otgzrPHQ05IM7OD1ySm+H1NmKMItYqGY+B8VbkRIrA50GgcaHo8QjMZQh0 bC/nW2WK+1Q6SeGVA0A4ztzb5ATiFvdr5OoTMRioLAeTu0aEsa//jJ0ajg/TSn9F2xbPBmfGzP0 qfbisVWAmQfuG1fWAllgDJLHrLa9zmkdN1j76ligL9jUg4fIoUQFahpdA2TWXxu7PUASKgIYW8V VesBOD0uS4QTJ6sSXIxxV717IZiiRqvTabITo5VSZzXJq/NtOzOCX6H4ui5xI1s9uawnl1X60Bk 5KNtDrjOtVNvgPk8WvGXuRU6jxjX5hjIxjdd5BcHYYdsAuB5K7VU3xMxCVpoWrq5wcfgrxdPB/N HJOCjG+0Mu+f1znCZ3qqAIG30Q1HJi8CoCf7lKIt2IS8VDdeXpE4+d9fD9dovPU1ax+2HQmEwsY ZJuwrp86W+2n+QQ== X-Mailer: b4 0.14.2 Message-ID: <20250819-maple-tree-v2-2-229b48657bab@google.com> Subject: [PATCH v2 2/5] rust: maple_tree: add MapleTree From: Alice Ryhl To: Andrew Morton , "Liam R. Howlett" , Lorenzo Stoakes , Miguel Ojeda , Andrew Ballance Cc: Boqun Feng , Gary Guo , "=?utf-8?q?Bj=C3=B6rn_Roy_Baron?=" , Benno Lossin , Andreas Hindborg , Trevor Gross , Danilo Krummrich , linux-kernel@vger.kernel.org, maple-tree@lists.infradead.org, rust-for-linux@vger.kernel.org, linux-mm@kvack.org, Alice Ryhl Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The maple tree will be used in the Tyr driver to allocate and keep track of GPU allocations created internally (i.e. not by userspace). It will likely also be used in the Nova driver eventually. This adds the simplest methods for additional and removal that do not require any special care with respect to concurrency. This implementation is based on the RFC by Andrew but with significant changes to simplify the implementation. Co-developed-by: Andrew Ballance Signed-off-by: Andrew Ballance Signed-off-by: Alice Ryhl --- MAINTAINERS | 2 + include/linux/maple_tree.h | 3 + rust/helpers/helpers.c | 1 + rust/helpers/maple_tree.c | 8 ++ rust/kernel/lib.rs | 1 + rust/kernel/maple_tree.rs | 343 +++++++++++++++++++++++++++++++++++++++++= ++++ 6 files changed, 358 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index fe168477caa45799dfe07de2f54de6d6a1ce0615..26053163fe5aed2fc4b4e39d470= 62c93b873ac13 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -16250,7 +16250,9 @@ L: rust-for-linux@vger.kernel.org S: Maintained W: http://www.linux-mm.org T: git git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm +F: rust/helpers/maple_tree.c F: rust/helpers/mm.c +F: rust/kernel/maple_tree.rs F: rust/kernel/mm.rs F: rust/kernel/mm/ =20 diff --git a/include/linux/maple_tree.h b/include/linux/maple_tree.h index 8244679ba1758235e049acbaedee62aae5c0e226..4af6c5e1a6241e24e3e73b1cc13= 64b8da77b9bf0 100644 --- a/include/linux/maple_tree.h +++ b/include/linux/maple_tree.h @@ -481,6 +481,9 @@ struct ma_wr_state { #define MA_ERROR(err) \ ((struct maple_enode *)(((unsigned long)err << 2) | 2UL)) =20 +/* + * When changing MA_STATE, remember to also change rust/kernel/maple_tree.= rs + */ #define MA_STATE(name, mt, first, end) \ struct ma_state name =3D { \ .tree =3D mt, \ diff --git a/rust/helpers/helpers.c b/rust/helpers/helpers.c index 7cf7fe95e41dd51717050648d6160bebebdf4b26..c5d42e0f7ce6786c1e96f8c0f27= 710959ca3362b 100644 --- a/rust/helpers/helpers.c +++ b/rust/helpers/helpers.c @@ -26,6 +26,7 @@ #include "io.c" #include "jump_label.c" #include "kunit.c" +#include "maple_tree.c" #include "mm.c" #include "mutex.c" #include "of.c" diff --git a/rust/helpers/maple_tree.c b/rust/helpers/maple_tree.c new file mode 100644 index 0000000000000000000000000000000000000000..1dd9ac84a13feed53c0ed5eec68= 05517081d0673 --- /dev/null +++ b/rust/helpers/maple_tree.c @@ -0,0 +1,8 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include + +void rust_helper_mt_init_flags(struct maple_tree *mt, unsigned int flags) +{ + mt_init_flags(mt, flags); +} diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs index ed53169e795c0badf548025a57f946fa18bc73e3..6b0a5689669fa691e366ab3f9d4= 62692c12bd548 100644 --- a/rust/kernel/lib.rs +++ b/rust/kernel/lib.rs @@ -96,6 +96,7 @@ #[cfg(CONFIG_KUNIT)] pub mod kunit; pub mod list; +pub mod maple_tree; pub mod miscdevice; pub mod mm; #[cfg(CONFIG_NET)] diff --git a/rust/kernel/maple_tree.rs b/rust/kernel/maple_tree.rs new file mode 100644 index 0000000000000000000000000000000000000000..ea1bd694213b73108732aecc36d= a95342aeafe04 --- /dev/null +++ b/rust/kernel/maple_tree.rs @@ -0,0 +1,343 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! Maple trees. +//! +//! C header: [`include/linux/maple_tree.h`](srctree/include/linux/maple_t= ree.h) +//! +//! Reference: + +use core::{ + marker::PhantomData, + ops::{Bound, RangeBounds}, + ptr, +}; + +use kernel::{ + alloc::Flags, + error::code::{EEXIST, ENOMEM}, + error::to_result, + prelude::*, + types::{ForeignOwnable, Opaque}, +}; + +/// A maple tree optimized for storing non-overlapping ranges. +/// +/// # Invariants +/// +/// Each range in the maple tree owns an instance of `T`. +#[pin_data(PinnedDrop)] +#[repr(transparent)] +pub struct MapleTree { + #[pin] + tree: Opaque, + _p: PhantomData, +} + +/// A helper type used for navigating a [`MapleTree`]. +/// +/// # Invariants +/// +/// For the duration of `'tree`: +/// +/// * The `ma_state` must reference a valid `MapleTree`. +/// * The `ma_state` has read/write access to the tree. +pub struct MaState<'tree, T: ForeignOwnable> { + state: bindings::ma_state, + _phantom: PhantomData<&'tree mut MapleTree>, +} + +#[inline] +fn to_maple_range(range: impl RangeBounds) -> Option<(usize, usize)= > { + let first =3D match range.start_bound() { + Bound::Included(start) =3D> *start, + Bound::Excluded(start) =3D> start.checked_add(1)?, + Bound::Unbounded =3D> 0, + }; + + let last =3D match range.end_bound() { + Bound::Included(end) =3D> *end, + Bound::Excluded(end) =3D> end.checked_sub(1)?, + Bound::Unbounded =3D> usize::MAX, + }; + + if last < first { + return None; + } + + Some((first, last)) +} + +impl MapleTree { + /// Create a new maple tree. + /// + /// The tree will use the regular implementation with a higher branchi= ng factor. + #[inline] + pub fn new() -> impl PinInit { + pin_init!(MapleTree { + // SAFETY: This initializes a maple tree into a pinned slot. T= he maple tree will be + // destroyed in Drop before the memory location becomes invali= d. + tree <- Opaque::ffi_init(|slot| unsafe { bindings::mt_init_fla= gs(slot, 0) }), + _p: PhantomData, + }) + } + + /// Insert the value at the given index. + /// + /// If the maple tree already contains a range using the given index, = then this call will fail. + /// + /// # Examples + /// + /// ``` + /// use kernel::maple_tree::{MapleTree, InsertErrorKind}; + /// + /// let tree =3D KBox::pin_init(MapleTree::>::new(), GFP_KER= NEL)?; + /// + /// let ten =3D KBox::new(10, GFP_KERNEL)?; + /// let twenty =3D KBox::new(20, GFP_KERNEL)?; + /// let the_answer =3D KBox::new(42, GFP_KERNEL)?; + /// + /// // These calls will succeed. + /// tree.insert(100, ten, GFP_KERNEL)?; + /// tree.insert(101, twenty, GFP_KERNEL)?; + /// + /// // This will fail because the index is already in use. + /// assert_eq!( + /// tree.insert(100, the_answer, GFP_KERNEL).unwrap_err().cause, + /// InsertErrorKind::Occupied, + /// ); + /// # Ok::<_, Error>(()) + /// ``` + #[inline] + pub fn insert(&self, index: usize, value: T, gfp: Flags) -> Result<(),= InsertError> { + self.insert_range(index..=3Dindex, value, gfp) + } + + /// Insert a value to the specified range, failing on overlap. + /// + /// This accepts the usual types of Rust ranges using the `..` and `..= =3D` syntax for exclusive + /// and inclusive ranges respectively. The range must not be empty, an= d must not overlap with + /// any existing range. + /// + /// # Examples + /// + /// ``` + /// use kernel::maple_tree::{MapleTree, InsertErrorKind}; + /// + /// let tree =3D KBox::pin_init(MapleTree::>::new(), GFP_KER= NEL)?; + /// + /// let ten =3D KBox::new(10, GFP_KERNEL)?; + /// let twenty =3D KBox::new(20, GFP_KERNEL)?; + /// let the_answer =3D KBox::new(42, GFP_KERNEL)?; + /// let hundred =3D KBox::new(100, GFP_KERNEL)?; + /// + /// // Insert the value 10 at the indices 100 to 499. + /// tree.insert_range(100..500, ten, GFP_KERNEL)?; + /// + /// // Insert the value 20 at the indices 500 to 1000. + /// tree.insert_range(500..=3D1000, twenty, GFP_KERNEL)?; + /// + /// // This will fail due to overlap with the previous range on index = 1000. + /// assert_eq!( + /// tree.insert_range(1000..1200, the_answer, GFP_KERNEL).unwrap_e= rr().cause, + /// InsertErrorKind::Occupied, + /// ); + /// + /// // When using .. to specify the range, you must be careful to ensu= re that the range is + /// // non-empty. + /// assert_eq!( + /// tree.insert_range(72..72, hundred, GFP_KERNEL).unwrap_err().ca= use, + /// InsertErrorKind::InvalidRequest, + /// ); + /// # Ok::<_, Error>(()) + /// ``` + pub fn insert_range(&self, range: R, value: T, gfp: Flags) -> Resul= t<(), InsertError> + where + R: RangeBounds, + { + let Some((first, last)) =3D to_maple_range(range) else { + return Err(InsertError { + value, + cause: InsertErrorKind::InvalidRequest, + }); + }; + + let ptr =3D T::into_foreign(value); + + // SAFETY: The tree is valid, and we are passing a pointer to an o= wned instance of `T`. + let res =3D to_result(unsafe { + bindings::mtree_insert_range(self.tree.get(), first, last, ptr= , gfp.as_raw()) + }); + + if let Err(err) =3D res { + // SAFETY: As `mtree_insert_range` failed, it is safe to take = back ownership. + let value =3D unsafe { T::from_foreign(ptr) }; + + let cause =3D if err =3D=3D ENOMEM { + InsertErrorKind::AllocError(kernel::alloc::AllocError) + } else if err =3D=3D EEXIST { + InsertErrorKind::Occupied + } else { + InsertErrorKind::InvalidRequest + }; + Err(InsertError { value, cause }) + } else { + Ok(()) + } + } + + /// Erase the range containing the given index. + /// + /// # Examples + /// + /// ``` + /// use kernel::maple_tree::{MapleTree, InsertErrorKind}; + /// + /// let tree =3D KBox::pin_init(MapleTree::>::new(), GFP_KER= NEL)?; + /// + /// let ten =3D KBox::new(10, GFP_KERNEL)?; + /// let twenty =3D KBox::new(20, GFP_KERNEL)?; + /// + /// tree.insert_range(100..500, ten, GFP_KERNEL)?; + /// tree.insert(67, twenty, GFP_KERNEL)?; + /// + /// let twenty =3D tree.erase(67).unwrap(); + /// assert_eq!(*twenty, 20); + /// + /// let ten =3D tree.erase(275).unwrap(); + /// assert_eq!(*ten, 10); + /// + /// // The previous call erased the entire range, not just index 275. + /// assert!(tree.erase(127).is_none()); + /// # Ok::<_, Error>(()) + /// ``` + #[inline] + pub fn erase(&self, index: usize) -> Option { + // SAFETY: `self.tree` contains a valid maple tree. + let ret =3D unsafe { bindings::mtree_erase(self.tree.get(), index)= }; + + // SAFETY: If the pointer is not null, then we took ownership of a= valid instance of `T` + // from the tree. + unsafe { T::try_from_foreign(ret) } + } + + /// Free all `T` instances in this tree. + /// + /// # Safety + /// + /// This frees Rust data referenced by the maple tree without removing= it from the maple tree. + /// The caller must ensure that no reference that remains in the maple= tree is used incorrectly + /// after this call. + unsafe fn free_all_entries(self: Pin<&mut Self>) { + // SAFETY: The caller provides exclusive access to the entire mapl= e tree, so we have + // exclusive access to the entire maple tree despite not holding t= he lock. + let mut ma_state =3D unsafe { MaState::new_raw(self.into_ref().get= _ref(), 0, usize::MAX) }; + + loop { + // This uses the raw accessor because we're destroying pointer= s without removing them + // from the maple tree, which is only valid because this is th= e destructor. + let ptr =3D ma_state.mas_find_raw(usize::MAX); + if ptr.is_null() { + break; + } + // SAFETY: By the type invariants, this pointer references a v= alid value of type `T`. + // By the safety requirements, it is okay to free it without r= emoving it from the maple + // tree. + drop(unsafe { T::from_foreign(ptr) }); + } + } +} + +#[pinned_drop] +impl PinnedDrop for MapleTree { + #[inline] + fn drop(mut self: Pin<&mut Self>) { + // We only iterate the tree if the Rust value have a destructor. + if core::mem::needs_drop::() { + // SAFETY: The tree is valid, and other than the below `mtree_= destroy` call, it will + // not be accessed after this call. + unsafe { self.as_mut().free_all_entries() }; + } + + // SAFETY: The tree is valid, and will not be accessed after this = call. + unsafe { bindings::mtree_destroy(self.tree.get()) }; + } +} + +impl<'tree, T: ForeignOwnable> MaState<'tree, T> { + /// Initialize a new `MaState` with the given tree. + /// + /// # Safety + /// + /// The caller must ensure that this `MaState` has read/write access t= o the maple tree. + #[inline] + unsafe fn new_raw(mt: &'tree MapleTree, first: usize, end: usize) -= > Self { + // INVARIANT: + // * Having a reference ensures that the `MapleTree` is valid f= or `'tree`. + // * The caller ensures that we have read/write access. + Self { + state: bindings::ma_state { + tree: mt.tree.get(), + index: first, + last: end, + node: ptr::null_mut(), + status: bindings::maple_status_ma_start, + min: 0, + max: usize::MAX, + alloc: ptr::null_mut(), + mas_flags: 0, + store_type: bindings::store_type_wr_invalid, + ..Default::default() + }, + _phantom: PhantomData, + } + } + + #[inline] + fn as_raw(&mut self) -> *mut bindings::ma_state { + &raw mut self.state + } + + #[inline] + fn mas_find_raw(&mut self, max: usize) -> *mut c_void { + // SAFETY: By the type invariants, the `ma_state` is active and we= have read/write access + // to the tree. + unsafe { bindings::mas_find(self.as_raw(), max) } + } +} + +/// Error type for failure to insert a new value. +pub struct InsertError { + /// The value that could not be inserted. + pub value: T, + /// The reason for the failure to insert. + pub cause: InsertErrorKind, +} + +/// The reason for the failure to insert. +#[derive(PartialEq, Eq, Copy, Clone)] +pub enum InsertErrorKind { + /// There is already a value in the requested range. + Occupied, + /// Failure to allocate memory. + AllocError(kernel::alloc::AllocError), + /// The insertion request was invalid. + InvalidRequest, +} + +impl From for Error { + #[inline] + fn from(kind: InsertErrorKind) -> Error { + match kind { + InsertErrorKind::Occupied =3D> EEXIST, + InsertErrorKind::AllocError(kernel::alloc::AllocError) =3D> EN= OMEM, + InsertErrorKind::InvalidRequest =3D> EINVAL, + } + } +} + +impl From> for Error { + #[inline] + fn from(insert_err: InsertError) -> Error { + Error::from(insert_err.cause) + } +} --=20 2.51.0.rc1.167.g924127e9c0-goog From nobody Sat Oct 4 06:29:31 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 E6189322C95 for ; Tue, 19 Aug 2025 10:34:55 +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=1755599697; cv=none; b=LTeyN+QDrQKPyjMr7jZNnNeNuvRmTBmt3tU/LY4wuWIFIRdm0G9qN51N/vLJvHQXczB8sRRroPDVKYMKGKWJ/j01Uo+ZqJy+Yz9ZH+RO36HuAmcnuG9qJkRSwDsJF+g5HmoNaD0emM8blOMFOJP/b8Kge3KquqmQCinyELJd99s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755599697; c=relaxed/simple; bh=D/ogmv6je6b+B8kZGRNN3fxoNtbqMSGDfVNELXGyhdA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Wv5lgUqWbF9GGxu/L23TlQafYVdWnJEKfElg+xr9RL97VWmaxPBCY+QtMFZHAmi/KSPEHj5f8EzLdfz9eLH96mN65S4lB/h5a8qY29IsgdrWoBugCI5rbFeElT2d6CMgihEevDhJSjNHNmNdAm5Tqzn3JLmQ31e5iVqCslFvsHY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=evb0KbB2; 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--aliceryhl.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="evb0KbB2" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-45a1b0c5366so23413695e9.3 for ; Tue, 19 Aug 2025 03:34:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1755599694; x=1756204494; 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=BYWHG9rV+2DZ17Wm5m0AvZTyVI+nQsfmKfJhbAh/mlo=; b=evb0KbB2HuO1Z5rqbBTTPpxJQlmrxp7qg5sWrxHGX0pOPLRgcwMmVtWvhjytU8Y2+p CkjcTLyhICsYTW5rf+a1fEdnJU7wl5ij21uy4QeFuy5bf9aPVGmOu/nu5kaUO02spwvW bGskviwLEVDHUL+SMTUDHFbYDkfVJsKP075pedZfJXF5g44fFNHXbJlmSvWfhGnvDEG8 7sXoEDbsenDT8TzeClPUjSrbcvIuE18nRb8tYgUP82s2OkvINlciqdEmqQpak0HidOZl Z+IeEfNJ7zT/0l0nN9asqrCh1z87NqOYdywyqBxrrkaM0MBY+KivXh0uvryKZ68PntUu FMZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755599694; x=1756204494; 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=BYWHG9rV+2DZ17Wm5m0AvZTyVI+nQsfmKfJhbAh/mlo=; b=aTEnJ9Y0wuTDxaYTzEPElG96bqo9BfHPi09mQDV/wUgRkAanAcXTLEQSCqARoMizfR Jef/cZZbx+w8EZbSI9rXb+O9IaDicHPLQEkQlY+gdgX6+fufxu1BKnhDCmGr6inCXfFE El6znjcQ6MnczOfFimRtqBGPM+gKP1XxvDEB8ePQ4rdohpSQCaNYiyNnPgs7/cnMdIgi Ed2piBKnXJ34mbTYa7FBXZ48jH65knqwGVl2X5bmTN7IVl5ZYd8aFux1PpEfRO7JtMAA gjPKvXKYwW/phVA0HsFXew6Wo0KDfR9xnsPjXZEUmWkizWwMTM5QUC0C3YT7Ri69G9Ak MjTw== X-Forwarded-Encrypted: i=1; AJvYcCUlr0eWPeMg9B4XEpzfHCYoh0SfqSrBryHqh68gQD4ASDhmvhOvXOE0VnXZSWqj6MSlgysrGTyCbA7CfRs=@vger.kernel.org X-Gm-Message-State: AOJu0Yw4wsyPINcEXyPovTUytbci7CQZMeSDacBtFJpsEW2wO6KEMAOz woHg96+ZvhPw8cFbDQ2d6u8CdGKCxD7FqhcMczl8KuE6O357vMhnPmFWwImIrixlKKOTZa/dzRz tFrmZc9I1DNjWQTmVXA== X-Google-Smtp-Source: AGHT+IFBgYtRm7CWyI1w4fPitIlOJVfovxFrde4PL+kQ34yH4njzswJ7XwKKVps2PuFHp10ZDY6TrvIKkaD9/sM= X-Received: from wmv20.prod.google.com ([2002:a05:600c:26d4:b0:459:dfcf:15e4]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:198e:b0:458:c045:ee99 with SMTP id 5b1f17b1804b1-45b43e129c9mr13524705e9.28.1755599694398; Tue, 19 Aug 2025 03:34:54 -0700 (PDT) Date: Tue, 19 Aug 2025 10:34:44 +0000 In-Reply-To: <20250819-maple-tree-v2-0-229b48657bab@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250819-maple-tree-v2-0-229b48657bab@google.com> X-Developer-Key: i=aliceryhl@google.com; a=openpgp; fpr=49F6C1FAA74960F43A5B86A1EE7A392FDE96209F X-Developer-Signature: v=1; a=openpgp-sha256; l=6917; i=aliceryhl@google.com; h=from:subject:message-id; bh=D/ogmv6je6b+B8kZGRNN3fxoNtbqMSGDfVNELXGyhdA=; b=owEBbQKS/ZANAwAKAQRYvu5YxjlGAcsmYgBopFNJIFLz4Aprvq7ZI2MNJOKuSzdNGW1/VHJ82 jvD7kmIfDSJAjMEAAEKAB0WIQSDkqKUTWQHCvFIvbIEWL7uWMY5RgUCaKRTSQAKCRAEWL7uWMY5 RniPEACGbhxlrlt8/Clyf5Fw+0UpjFP9dH6UWXSI8fN8qGFSUVA3wY2bBoO27kK94+4bXDfQ/AW epU1uS8pgyulz3OXpZDKIQ0wxfcwwxJykBGini7ha9XfLO9CwNq0m0Mk2jklKruK0O8C9vwqI1S Qb28OmX6lBr6EsXb2frq1JvBY97WxOcOgCekC4uvh+9Q381pwBRh9JteXJ98l1K+Wmn1b8HEHad y1kQF24vmus9anM+eamNnUd8RbMOyTzQAc6fJeS9qeJzPKgYGJT0xq6U2qMT1Q3srofjuB4VKix JBB6sCMRl+JBW51b50qtb4KomwviFQq0MT66jX/1vah1IdH3TXI+oTD6KgtXITB35GjXHJr4rq3 XGO4kqyvnRNzkMNgpBrbF0QZd9dRFZ01c2+xXDVtSWPEbLUrgojpO7QM9+/qaSj2aBJEvrwZb61 GrmZTJ/ayk/tA9yuTt8fNc6IkAz/mTKNMeP2RrHb0Pk1Yjc98aTEIopKJen84AQvD0dR5NuqPJ/ Mlfa0PgHaCIi5/wac0+Ll/ULm4CgZNEUK6qbJVaQOiKrv/m7akBpbA/s2AaU0HJLQhK8U0kcsbM O635DN8aBVluhQjultaKNGfHdOw99rLJnuXfuogdytUIHTP9jANSoicWwtIl0OZvMhdXN+86J8J Kn1zGFMHYK0xA0g== X-Mailer: b4 0.14.2 Message-ID: <20250819-maple-tree-v2-3-229b48657bab@google.com> Subject: [PATCH v2 3/5] rust: maple_tree: add MapleTree::lock() and load() From: Alice Ryhl To: Andrew Morton , "Liam R. Howlett" , Lorenzo Stoakes , Miguel Ojeda , Andrew Ballance Cc: Boqun Feng , Gary Guo , "=?utf-8?q?Bj=C3=B6rn_Roy_Baron?=" , Benno Lossin , Andreas Hindborg , Trevor Gross , Danilo Krummrich , linux-kernel@vger.kernel.org, maple-tree@lists.infradead.org, rust-for-linux@vger.kernel.org, linux-mm@kvack.org, Alice Ryhl Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable To load a value, one must be careful to hold the lock while accessing it. To enable this, we add a lock() method so that you can perform operations on the value before the spinlock is released. This adds a MapleGuard type without using the existing SpinLock type. This ensures that the MapleGuard type is not unnecessarily large, and that it is easy to swap out the type of lock in case the C maple tree is changed to use a different kind of lock. Co-developed-by: Andrew Ballance Signed-off-by: Andrew Ballance Reviewed-by: Andrew Ballance Signed-off-by: Alice Ryhl Reviewed-by: Danilo Krummrich --- rust/kernel/maple_tree.rs | 139 ++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 139 insertions(+) diff --git a/rust/kernel/maple_tree.rs b/rust/kernel/maple_tree.rs index ea1bd694213b73108732aecc36da95342aeafe04..17e4d8586ebad56aee87a97befd= fec5741f147de 100644 --- a/rust/kernel/maple_tree.rs +++ b/rust/kernel/maple_tree.rs @@ -220,6 +220,22 @@ pub fn erase(&self, index: usize) -> Option { unsafe { T::try_from_foreign(ret) } } =20 + /// Lock the internal spinlock. + #[inline] + pub fn lock(&self) -> MapleGuard<'_, T> { + // SAFETY: It's safe to lock the spinlock in a maple tree. + unsafe { bindings::spin_lock(self.ma_lock()) }; + + // INVARIANT: We just took the spinlock. + MapleGuard(self) + } + + #[inline] + fn ma_lock(&self) -> *mut bindings::spinlock_t { + // SAFETY: This pointer offset operation stays in-bounds. + unsafe { &raw mut (*self.tree.get()).__bindgen_anon_1.ma_lock } + } + /// Free all `T` instances in this tree. /// /// # Safety @@ -263,6 +279,91 @@ fn drop(mut self: Pin<&mut Self>) { } } =20 +/// A reference to a [`MapleTree`] that owns the inner lock. +/// +/// # Invariants +/// +/// This guard owns the inner spinlock. +#[must_use =3D "if unused, the lock will be immediately unlocked"] +pub struct MapleGuard<'tree, T: ForeignOwnable>(&'tree MapleTree); + +impl<'tree, T: ForeignOwnable> Drop for MapleGuard<'tree, T> { + #[inline] + fn drop(&mut self) { + // SAFETY: By the type invariants, we hold this spinlock. + unsafe { bindings::spin_unlock(self.0.ma_lock()) }; + } +} + +impl<'tree, T: ForeignOwnable> MapleGuard<'tree, T> { + /// Create a [`MaState`] protected by this lock guard. + pub fn ma_state(&mut self, first: usize, end: usize) -> MaState<'_, T>= { + // SAFETY: The `MaState` borrows this `MapleGuard`, so it can also= borrow the `MapleGuard`s + // read/write permissions to the maple tree. + unsafe { MaState::new_raw(self.0, first, end) } + } + + /// Load the value at the given index. + /// + /// # Examples + /// + /// Read the value while holding the spinlock. + /// + /// ``` + /// use kernel::maple_tree::{MapleTree, InsertErrorKind}; + /// + /// let tree =3D KBox::pin_init(MapleTree::>::new(), GFP_KER= NEL)?; + /// + /// let ten =3D KBox::new(10, GFP_KERNEL)?; + /// let twenty =3D KBox::new(20, GFP_KERNEL)?; + /// tree.insert(100, ten, GFP_KERNEL)?; + /// tree.insert(200, twenty, GFP_KERNEL)?; + /// + /// let mut lock =3D tree.lock(); + /// assert_eq!(lock.load(100), Some(&mut 10)); + /// assert_eq!(lock.load(200), Some(&mut 20)); + /// assert_eq!(lock.load(300), None); + /// # Ok::<_, Error>(()) + /// ``` + /// + /// Increment refcount while holding spinlock and read afterwards. + /// + /// ``` + /// use kernel::maple_tree::{MapleTree, InsertErrorKind}; + /// use kernel::sync::Arc; + /// + /// let tree =3D KBox::pin_init(MapleTree::>::new(), GFP_KERN= EL)?; + /// + /// let ten =3D Arc::new(10, GFP_KERNEL)?; + /// let twenty =3D Arc::new(20, GFP_KERNEL)?; + /// tree.insert(100, ten, GFP_KERNEL)?; + /// tree.insert(200, twenty, GFP_KERNEL)?; + /// + /// // Briefly take the lock to increment the refcount. + /// let value =3D Arc::from(tree.lock().load(100).unwrap()); + /// + /// // At this point, another thread might remove the value. + /// tree.erase(100); + /// + /// // But we can still access it because we took a refcount. + /// assert_eq!(*value, 10); + /// # Ok::<_, Error>(()) + /// ``` + #[inline] + pub fn load(&mut self, index: usize) -> Option> { + // SAFETY: `self.tree` contains a valid maple tree. + let ret =3D unsafe { bindings::mtree_load(self.0.tree.get(), index= ) }; + if ret.is_null() { + return None; + } + + // SAFETY: If the pointer is not null, then it references a valid = instance of `T`. It is + // safe to borrow the instance mutably because the signature of th= is function enforces that + // the mutable borrow is not used after the spinlock is dropped. + Some(unsafe { T::borrow_mut(ret) }) + } +} + impl<'tree, T: ForeignOwnable> MaState<'tree, T> { /// Initialize a new `MaState` with the given tree. /// @@ -303,6 +404,44 @@ fn mas_find_raw(&mut self, max: usize) -> *mut c_void { // to the tree. unsafe { bindings::mas_find(self.as_raw(), max) } } + + /// Find the next entry in the maple tree. + /// + /// # Examples + /// + /// Iterate the maple tree. + /// + /// ``` + /// use kernel::maple_tree::{MapleTree, InsertErrorKind}; + /// use kernel::sync::Arc; + /// + /// let tree =3D KBox::pin_init(MapleTree::>::new(), GFP_KERN= EL)?; + /// + /// let ten =3D Arc::new(10, GFP_KERNEL)?; + /// let twenty =3D Arc::new(20, GFP_KERNEL)?; + /// tree.insert(100, ten, GFP_KERNEL)?; + /// tree.insert(200, twenty, GFP_KERNEL)?; + /// + /// let mut ma_lock =3D tree.lock(); + /// let mut iter =3D ma_lock.ma_state(0, usize::MAX); + /// + /// assert_eq!(*iter.mas_find(usize::MAX).unwrap(), 10); + /// assert_eq!(*iter.mas_find(usize::MAX).unwrap(), 20); + /// assert!(iter.mas_find(usize::MAX).is_none()); + /// # Ok::<_, Error>(()) + /// ``` + #[inline] + pub fn mas_find(&mut self, max: usize) -> Option> { + let ret =3D self.mas_find_raw(max); + if ret.is_null() { + return None; + } + + // SAFETY: If the pointer is not null, then it references a valid = instance of `T`. It's + // safe to access it mutably as the returned reference borrows thi= s `MaState`, and the + // `MaState` has read/write access to the maple tree. + Some(unsafe { T::borrow_mut(ret) }) + } } =20 /// Error type for failure to insert a new value. --=20 2.51.0.rc1.167.g924127e9c0-goog From nobody Sat Oct 4 06:29:31 2025 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.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 3D521322DAE for ; Tue, 19 Aug 2025 10:34:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755599699; cv=none; b=S+Bah031qSRjBO6c97cZHEdPuU+acaQE69CLkJugYBqSZJxRP63QNmf9oKaCeHSVV+B5aRdT5ygiBRGiY/rP/51+N67d0dpiu+5nyGqhmw8Y9WSutIeoRjbVVtr34vwYb8v2CaWw5xoDsHOYt4U7gKLH+KQOdP7g8JiI69DACXE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755599699; c=relaxed/simple; bh=X9XFKJ/dRuLjFf9dlRypSpmNCQXkOPPPLNvJwnrWGes=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ZQrmQGyRSVCR96ubFwLgxCuStkgVMoYPpmdDrsQJjsXR61dNaD1KnlykyFtd8jlTuRd53Rov8nYa8yRccEL0bl6gTddGR58jM0LaQxkendM1teH7NvajJLvXdhCsGQPm0egnDdkH8mDl2JRlDfkGN08TQF+GDaOq7hfxkkUtVv4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ZmSOsqLx; arc=none smtp.client-ip=209.85.128.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--aliceryhl.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ZmSOsqLx" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-45a1b04f817so18213425e9.1 for ; Tue, 19 Aug 2025 03:34:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1755599695; x=1756204495; 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=jTGsOM3ccmHHhc5WskUdW4VbNNgxc3UCr+/674UGKtg=; b=ZmSOsqLxiqA8Pc6zabKPDuKPMnURo5Whx6060N9jiFvE0YAgbY3J15s4fMt1xo3+RD L2PJE8N0nbHlOQyfMQLVsrjVdru4wY1+MQ8aJjqGgt8oiS786A+MM25DNH8KqOrNtTqa ghKJ/3jDB/uUWOcI7LK3AtpIZBo6y75AZteUGxb22qXIRamLNujvdFSG2rzuyu5kCd1Q oupc2IUWF1mZ6Wgv8E6KpeaJ8meuXSTR4ZjwdJ8mCgnCExDWd+R6PnQbZJmn9oyyYTAm Xs5LWE0lx0ZWgVK9rAWTs2rgz2Q7WVeDXPOgHwfTCvTLNeuniQ0sj8fByH7yLpsIEdDc DqJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755599695; x=1756204495; 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=jTGsOM3ccmHHhc5WskUdW4VbNNgxc3UCr+/674UGKtg=; b=QgNRB5LTjXpGjtC218SGFK8jqaqRh3JnKfB+24jkJHbVdIHZDBHe3IATdcZhFV4Kxw GW0wTyHEbp1mtBB5dxOB5plkjP/J6XwXCi1wdhGIO0Brluo4w6cRvvZhHyZ5YCaUbFuj FfATxVQ/rcdr9d9Tn9gKlrXdZYPEXeblYsYyR/jzqFfLjh7bRhWiPOJT3ukwB8vRUD7o gD8IX5nI0TwVKr5H6H+kmEQHr+EIPGeOTnw9nfVXwKZUD4Mmd2FGuFBUTCD8AGyU1Guw kLCGGDfpX8RPwChbUbntUeNZd79GSz380bfG+dGhSpF7ovCI2Gcu/yM6M7Bx5jxSifU7 IhDQ== X-Forwarded-Encrypted: i=1; AJvYcCWepqiNgBlhTW86KAWGokTrcu/+cFOfid2SMEAI4i5RXjGO6V3MRlZkKHW70RpRxfpjC7l27z29cljcnBo=@vger.kernel.org X-Gm-Message-State: AOJu0YzHVGRn/N6vP8YZL2JHdL9ow2dyMr/ri3tHhekkQQZccPsdirqx xjtBw6C65t6BkfyQt3uBZJ0YMjuHu6/gZ42Di5urtJMHFLp+tdoEcsZ1s6Eh9dL1J21JJ+d0fPz V+GVc2Gno6acUQpcOww== X-Google-Smtp-Source: AGHT+IFY21x4v/c1ZoUPG7tLMqMibOhzvpRD5BMkY3Xd0T8BDUmpsW7QgUomHK+xQi2rAb1pfFGxLGRbobFtkVM= X-Received: from wmsr19.prod.google.com ([2002:a05:600c:8b13:b0:459:d7a7:e5d4]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:4e88:b0:459:dde3:1a55 with SMTP id 5b1f17b1804b1-45b43e0c021mr17265175e9.24.1755599695523; Tue, 19 Aug 2025 03:34:55 -0700 (PDT) Date: Tue, 19 Aug 2025 10:34:45 +0000 In-Reply-To: <20250819-maple-tree-v2-0-229b48657bab@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250819-maple-tree-v2-0-229b48657bab@google.com> X-Developer-Key: i=aliceryhl@google.com; a=openpgp; fpr=49F6C1FAA74960F43A5B86A1EE7A392FDE96209F X-Developer-Signature: v=1; a=openpgp-sha256; l=6521; i=aliceryhl@google.com; h=from:subject:message-id; bh=X9XFKJ/dRuLjFf9dlRypSpmNCQXkOPPPLNvJwnrWGes=; b=owEBbQKS/ZANAwAKAQRYvu5YxjlGAcsmYgBopFNJRvS/NdC9m8TcOEVhic75KUQrLzgS9PtUi Y6nIpEm/2GJAjMEAAEKAB0WIQSDkqKUTWQHCvFIvbIEWL7uWMY5RgUCaKRTSQAKCRAEWL7uWMY5 RhidD/9bOogkPZA/VWPUlEqA1/8iz3EqugHgMIrI+0iosvnnBfQrUU8Ck7XrXwbeBzHmtWzxD66 TfJxRTgVL9JqZmx+a4DCu63RM9uDqGGSx50ItDgZbLT4bjNgO0eEEbbzVj0yr/OXPKs5/5/ClQW iINNCRMbUVhbxsHhqgKJDZuCn26vYQ18E5Re1o/ry8ld2MZmkzfHjyB652N3gE1zk9kb/aVzycw Y5L0ksW1ENA9GXp2mM5MZAUWaL6WuKCKZ/GXaoLNKGHQYRWFlK7T1Gbsic+AkQq4HPqWmY7LLAa fTxDPJ9mm3zHFxAtIZW+fP3WwU/VCxc4qwqgTOj+CphQZxK3MzGv4xlS2hC40TtuTc3gV01Z09p zDITES+B3bASFSzWk496J8CNNjEZ72qSLw+b1JWzzCBJtv7l0DyRUUEBKzuZiXFvUJMsO+gNcLy bfYWhWvrICdK+WYU5aPJJxgdzN5f5RV8teyOE9XFC9canILgc8hYUxfzvlIcBrGpeBQk5KvBqiH oHH0UThsbT/gaE8Atx39fQmgW4kPaqoKE8/N2o8lbBRrPWvQq1cew46RPhUWsxi2qHHxDIkQ/6k A6w7Gx4LU0LhSUTnil1TOfubvtyeWTdvWhSBmsmKH0QTE4Ww9N8YbS4FCUkrAA8yZBJ0Rh9X4wg 10e6HI9o/y1DVzw== X-Mailer: b4 0.14.2 Message-ID: <20250819-maple-tree-v2-4-229b48657bab@google.com> Subject: [PATCH v2 4/5] rust: maple_tree: add MapleTreeAlloc From: Alice Ryhl To: Andrew Morton , "Liam R. Howlett" , Lorenzo Stoakes , Miguel Ojeda , Andrew Ballance Cc: Boqun Feng , Gary Guo , "=?utf-8?q?Bj=C3=B6rn_Roy_Baron?=" , Benno Lossin , Andreas Hindborg , Trevor Gross , Danilo Krummrich , linux-kernel@vger.kernel.org, maple-tree@lists.infradead.org, rust-for-linux@vger.kernel.org, linux-mm@kvack.org, Alice Ryhl Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable To support allocation trees, we introduce a new type MapleTreeAlloc for the case where the tree is created using MT_FLAGS_ALLOC_RANGE. To ensure that you can only call mtree_alloc_range on an allocation tree, we restrict thta method to the new MapleTreeAlloc type. However, all methods on MapleTree remain accessible to MapleTreeAlloc as allocation trees can use the other methods without issues. Signed-off-by: Alice Ryhl Reviewed-by: Daniel Almeida Reviewed-by: Danilo Krummrich --- rust/kernel/maple_tree.rs | 158 ++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 158 insertions(+) diff --git a/rust/kernel/maple_tree.rs b/rust/kernel/maple_tree.rs index 17e4d8586ebad56aee87a97befdfec5741f147de..1a32960e6e721ca32ca45d8bb63= fcffedeae3424 100644 --- a/rust/kernel/maple_tree.rs +++ b/rust/kernel/maple_tree.rs @@ -33,6 +33,26 @@ pub struct MapleTree { _p: PhantomData, } =20 +/// A maple tree with `MT_FLAGS_ALLOC_RANGE` set. +/// +/// All methods on [`MapleTree`] are also accessible on this type. +#[pin_data] +#[repr(transparent)] +pub struct MapleTreeAlloc { + #[pin] + tree: MapleTree, +} + +// Make MapleTree methods usable on MapleTreeAlloc. +impl core::ops::Deref for MapleTreeAlloc { + type Target =3D MapleTree; + + #[inline] + fn deref(&self) -> &MapleTree { + &self.tree + } +} + /// A helper type used for navigating a [`MapleTree`]. /// /// # Invariants @@ -364,6 +384,107 @@ pub fn load(&mut self, index: usize) -> Option> { } } =20 +impl MapleTreeAlloc { + /// Create a new allocation tree. + pub fn new() -> impl PinInit { + let tree =3D pin_init!(MapleTree { + // SAFETY: This initializes a maple tree into a pinned slot. T= he maple tree will be + // destroyed in Drop before the memory location becomes invali= d. + tree <- Opaque::ffi_init(|slot| unsafe { + bindings::mt_init_flags(slot, bindings::MT_FLAGS_ALLOC_RAN= GE) + }), + _p: PhantomData, + }); + + pin_init!(MapleTreeAlloc { tree <- tree }) + } + + /// Insert an entry with the given size somewhere in the given range. + /// + /// The maple tree will search for a location in the given range where= there is space to insert + /// the new range. If there is not enough available space, then an err= or will be returned. + /// + /// The index of the new range is returned. + /// + /// # Examples + /// + /// ``` + /// use kernel::maple_tree::{MapleTreeAlloc, AllocErrorKind}; + /// + /// let tree =3D KBox::pin_init(MapleTreeAlloc::>::new(), GF= P_KERNEL)?; + /// + /// let ten =3D KBox::new(10, GFP_KERNEL)?; + /// let twenty =3D KBox::new(20, GFP_KERNEL)?; + /// let thirty =3D KBox::new(30, GFP_KERNEL)?; + /// let hundred =3D KBox::new(100, GFP_KERNEL)?; + /// + /// // Allocate three ranges. + /// let idx1 =3D tree.alloc_range(100, ten, ..1000, GFP_KERNEL)?; + /// let idx2 =3D tree.alloc_range(100, twenty, ..1000, GFP_KERNEL)?; + /// let idx3 =3D tree.alloc_range(100, thirty, ..1000, GFP_KERNEL)?; + /// + /// assert_eq!(idx1, 0); + /// assert_eq!(idx2, 100); + /// assert_eq!(idx3, 200); + /// + /// // This will fail because the remaining space is too small. + /// assert_eq!( + /// tree.alloc_range(800, hundred, ..1000, GFP_KERNEL).unwrap_err(= ).cause, + /// AllocErrorKind::Busy, + /// ); + /// # Ok::<_, Error>(()) + /// ``` + pub fn alloc_range( + &self, + size: usize, + value: T, + range: R, + gfp: Flags, + ) -> Result> + where + R: RangeBounds, + { + let Some((min, max)) =3D to_maple_range(range) else { + return Err(AllocError { + value, + cause: AllocErrorKind::InvalidRequest, + }); + }; + + let ptr =3D T::into_foreign(value); + let mut index =3D 0; + + // SAFETY: The tree is valid, and we are passing a pointer to an o= wned instance of `T`. + let res =3D to_result(unsafe { + bindings::mtree_alloc_range( + self.tree.tree.get(), + &mut index, + ptr, + size, + min, + max, + gfp.as_raw(), + ) + }); + + if let Err(err) =3D res { + // SAFETY: As `mtree_alloc_range` failed, it is safe to take b= ack ownership. + let value =3D unsafe { T::from_foreign(ptr) }; + + let cause =3D if err =3D=3D ENOMEM { + AllocErrorKind::AllocError(kernel::alloc::AllocError) + } else if err =3D=3D EBUSY { + AllocErrorKind::Busy + } else { + AllocErrorKind::InvalidRequest + }; + Err(AllocError { value, cause }) + } else { + Ok(index) + } + } +} + impl<'tree, T: ForeignOwnable> MaState<'tree, T> { /// Initialize a new `MaState` with the given tree. /// @@ -480,3 +601,40 @@ fn from(insert_err: InsertError) -> Error { Error::from(insert_err.cause) } } + +/// Error type for failure to insert a new value. +pub struct AllocError { + /// The value that could not be inserted. + pub value: T, + /// The reason for the failure to insert. + pub cause: AllocErrorKind, +} + +/// The reason for the failure to insert. +#[derive(PartialEq, Eq, Copy, Clone)] +pub enum AllocErrorKind { + /// There is not enough space for the requested allocation. + Busy, + /// Failure to allocate memory. + AllocError(kernel::alloc::AllocError), + /// The insertion request was invalid. + InvalidRequest, +} + +impl From for Error { + #[inline] + fn from(kind: AllocErrorKind) -> Error { + match kind { + AllocErrorKind::Busy =3D> EBUSY, + AllocErrorKind::AllocError(kernel::alloc::AllocError) =3D> ENO= MEM, + AllocErrorKind::InvalidRequest =3D> EINVAL, + } + } +} + +impl From> for Error { + #[inline] + fn from(insert_err: AllocError) -> Error { + Error::from(insert_err.cause) + } +} --=20 2.51.0.rc1.167.g924127e9c0-goog From nobody Sat Oct 4 06:29:31 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 A8064322C96 for ; Tue, 19 Aug 2025 10:34:58 +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=1755599700; cv=none; b=i1pjDqDZ9TIshqkfotS1WpUOqC9Pk53l3ATBE6hvZiaxjgK/bly47CtEIEmgxwauXIDnO3uL0gcagy07MslJjMItQhea3VAy4oQgk0j9iiSGySF5LwVTHuRoHghg/mX/WODUfR2yzTHClwd+9N7wYOyKsju/MEduO1sWXwkccL0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755599700; c=relaxed/simple; bh=EOiel7LVR149bFLKGxoFqzCvExjuT+NKJ9JARxaqNE0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=dwEz4JoPFSfgHGr6NfiydIy4EtnhRYuJCehFeWpRSYx9AZlCT79zg7dNaNSI/OaOqfpQqq2MvpNIMHPsK/R65bIyvc190XJ3C9ArxzvnllfhaTWd8Qjo9CIqEejFgA/YDzHZMGuB65oMh66s60qg78C5u9nTz1lUaWAlc6WSGHU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=1JqnrJ2R; 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--aliceryhl.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="1JqnrJ2R" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-45a1b0514a5so22857825e9.1 for ; Tue, 19 Aug 2025 03:34:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1755599697; x=1756204497; 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=aT2hi3ZyL1ihosw5H2KL076sTulcA2Gel0+KFrHTzHA=; b=1JqnrJ2RHz8vVkhqhiT1HqM3qxIVweV4C7Gi3pAf65EjvLyua/6xbkKy7IO1QWbxj8 PhPJ+5MoFaDcWB/pt0aIU7YEHUwlzGP3FXp2f/KbDGEC8440ult2/nzY00JjaFXjIaI2 hftG3NEzkOKGJVjXZts5HGnwJlXiDEWjtASDEIaARYYccwnOP5tHeNhPrE8SDmtWujTk rOTkrIhqB3KGajqAISQl2cpaNsFzfhSYMjt31s5o6VMChIsUge7XWhimxclLb8cpA0wa uVEm17YG7RlXwbGA0VFZK2b2WXfJKqEjmFa8xVhgPhx5VbuGrudlMxomRGXWr3NJ4aQe qbyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755599697; x=1756204497; 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=aT2hi3ZyL1ihosw5H2KL076sTulcA2Gel0+KFrHTzHA=; b=HtDBoHrYdcB6pcwQt1L32Ms0BNZpbH7fPg5C2VN17XT9Ah3OXpzLWaBrYk0UeGN74P Vs28PlvwtOrw7ou2UoWsDQvDjITRVwv3HSdqfXEzJzuPh4FT9gdG/M7GsGIjiBZ4RBys sA3HC/4tDsUYwQ0NljWY8V2Ltz8oXZgEqk+L/7WG85WzEZ6yTpIsKb9UUCMmOBO4sY88 tD/hN6xGqibgmuQBvvdMAsAIcxS6PrMB17Ox8xOz0o2UbwLF5WpJ5En4Al7aJ3/2QwJy mkSZZ8uZ+KB1VRjEQ6mAp9Na1XWch8GRrGciyK99XGIE7DpzTw6psbdgSYHjTKvY+eUt /JQA== X-Forwarded-Encrypted: i=1; AJvYcCUhOm8YAxokZVCv4gfumSOONLfmU/Z26EdsgHTf5zhz6TrGRKYRXpaxSTxWyfgm8sq1NhVs4R7uDj6XV1c=@vger.kernel.org X-Gm-Message-State: AOJu0Ywv7EzB2C5bwswKEg/F++SYgW1mHj72T81CQ8cw8XYOs8kJr71H 0jzJWmAwdE0OIPqLsYSQcnIf0+npZlgF3GG1pieGUfPXHhw+xBrUBTywNPstB5qNX7LH0uaXmhC 7WnhDYs60fOiK5ovzeg== X-Google-Smtp-Source: AGHT+IFOGHcN3UGy6VodHfv2J2ggOgbe86pTWO6txjKCELGMHO36iGV+vPOgfJvJAny0LQ3kLq09givQwoeUMc4= X-Received: from wmbhj22.prod.google.com ([2002:a05:600c:5296:b0:459:dc8a:ec9f]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:1c92:b0:459:ddad:a3a3 with SMTP id 5b1f17b1804b1-45b43e0acf3mr15822075e9.25.1755599696980; Tue, 19 Aug 2025 03:34:56 -0700 (PDT) Date: Tue, 19 Aug 2025 10:34:46 +0000 In-Reply-To: <20250819-maple-tree-v2-0-229b48657bab@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250819-maple-tree-v2-0-229b48657bab@google.com> X-Developer-Key: i=aliceryhl@google.com; a=openpgp; fpr=49F6C1FAA74960F43A5B86A1EE7A392FDE96209F X-Developer-Signature: v=1; a=openpgp-sha256; l=1469; i=aliceryhl@google.com; h=from:subject:message-id; bh=EOiel7LVR149bFLKGxoFqzCvExjuT+NKJ9JARxaqNE0=; b=owEBbQKS/ZANAwAKAQRYvu5YxjlGAcsmYgBopFNJ4MbXWnL5teO5qvs43aMJT0mDzFTXDzw79 BbWKKmKtB2JAjMEAAEKAB0WIQSDkqKUTWQHCvFIvbIEWL7uWMY5RgUCaKRTSQAKCRAEWL7uWMY5 RhYTD/wL2LeD5NE64x8lArC2giqMmSV3REyTMDWOno7w4OdPBRVM/Oz9wWYgLIPTbeV1QmF5Jyk 0XFENYuN8fmnsFffLrBXTMq6HAdVs2Lbajo5+L4zmGA1gkzlBXbpJG4PfOZ4qvn5Dzkiz1bYbAi WhhbeCup3Wjv2LGWY29sPJ/DcWceGwtlfpR+YONXd/b+VJZPR8MWAcVAk3XUQhmSKRHGr9a1xio cjWa6Tna348T5l5OKzZxmniidC1Yh+x2ghDuPw2lMyxLGjOvJ5AUSug5VwWHTJ8B51CTGopnW3d LaXtTuSEcD4p0/4HQakYfNJBjLug119/pRyALfhYvDz6mYPFLtIJmSV575neg1OhS3UbJjWI9bH XDzc93hsgAH9PEOYfSq2DZ4JNvOMOHACzCBdlTWr1lATj2uvnXmMVcFq3MPOVxVVO/gG7RRLbfk nJYOGikMz8NZ2gstjBPkWZsVrN4Acir72RBvpbfHv6qTXZgNMwsuIAKfm3krzGCEr7m3Hpgo6+x UQeOjkoq02yqNvmFTs4O0hPchVA7rla9sswrJS/qIKIhUyksF6QnOdLtx9Hjpy72ukV2PSBbvEc +Fb8UzdjoLFkzjp5Jt/h9BYeap/rzovKPbTyRpCiZzKuxJLoqfEkRkFydZRrjBlqjJjU2Ct9ZNg 8N/gEflH+HHezNA== X-Mailer: b4 0.14.2 Message-ID: <20250819-maple-tree-v2-5-229b48657bab@google.com> Subject: [PATCH v2 5/5] rust: maple_tree: add MAINTAINERS entry From: Alice Ryhl To: Andrew Morton , "Liam R. Howlett" , Lorenzo Stoakes , Miguel Ojeda , Andrew Ballance Cc: Boqun Feng , Gary Guo , "=?utf-8?q?Bj=C3=B6rn_Roy_Baron?=" , Benno Lossin , Andreas Hindborg , Trevor Gross , Danilo Krummrich , linux-kernel@vger.kernel.org, maple-tree@lists.infradead.org, rust-for-linux@vger.kernel.org, linux-mm@kvack.org, Alice Ryhl Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Similar to and just below the existing MAPLE TREE entry. Signed-off-by: Alice Ryhl --- Liam: I'm not sure what you prefer for the MAINTAINERS entry, so let me know if you want anything changed. There are also a few other options, for example, I could just add the files under the existing MAPLE TREE entry? The get_maintainers script should still send any relevant patches my way because they also match the RUST entry that has a wildcard on the rust/ directory. Which tree does maple tree patches usually land through? Andrew Ballance: You mentioned being interested in being listed here as well? --- MAINTAINERS | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 26053163fe5aed2fc4b4e39d47062c93b873ac13..4a52d884e36eafe1c8192272071= 23c51caf02ee5 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14674,6 +14674,16 @@ F: lib/test_maple_tree.c F: tools/testing/radix-tree/maple.c F: tools/testing/shared/linux/maple_tree.h =20 +MAPLE TREE [RUST] +M: Liam R. Howlett +M: Alice Ryhl +L: maple-tree@lists.infradead.org +L: linux-mm@kvack.org +L: rust-for-linux@vger.kernel.org +S: Supported +F: rust/helpers/maple_tree.c +F: rust/kernel/maple_tree.rs + MARDUK (CREATOR CI40) DEVICE TREE SUPPORT M: Rahul Bedarkar L: linux-mips@vger.kernel.org --=20 2.51.0.rc1.167.g924127e9c0-goog