Received: by 2002:a05:7208:2204:b0:82:bbfa:f723 with SMTP id s4csp341479rbb; Thu, 18 Apr 2024 07:18:00 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXpP004e/0743DBqZEzz8FuCFg6pCbnshMNfRomXsN4be2Rwg52TIalWfTWptwPDLRZ5R4u3OSjBhPAbu39Cb9SgeGKr8svXCWWKB7NDQ== X-Google-Smtp-Source: AGHT+IGjd8jyg9y63JgW6lglvJtt1LwN26XAm6dlMj33I+kB96zDJI7oM5UgrROPgFEizM8aUCjI X-Received: by 2002:a50:935a:0:b0:56d:fdb3:bcc0 with SMTP id n26-20020a50935a000000b0056dfdb3bcc0mr2829976eda.11.1713449880372; Thu, 18 Apr 2024 07:18:00 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713449880; cv=pass; d=google.com; s=arc-20160816; b=Vjw462bawKgu7VDB0I7hZL6S/9zyMdxESaqIiF3xQ4WqMCikaXap26WZZYjQ5EQE0z abT5+04Yai9JcYEM13yPJNMMWR7KV7Blla2a3YKJy9agtInvxrGM+gxtliq0tFhkr2bg nZgRPSHZgCTVNyguJLfDgzp9ZP4CFe3fJ1BS2IUwHQfOArhHEiHMQJ7p8x7M/6Pxodw3 PoBz7e9BrRsfFDmppoK8BC+V7cSwAp0olEeGDXZZJ7VAvsbXnDszs0Ozi4OgpF/RmX2L 9thDoXI5AFqlHhpF4sZQH/nAbxo9oQcxql3nL00XSpCanNzSWbVyd04m2LulB1gNV2zM Kc3A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature; bh=jwRanQRdUIcfSKJvkIkP9Sl2pJsKe5JFR6MS4BygDeE=; fh=T4rOlmpVKJ6RHguRFTKcS2hiZzKRq4eI1SgQivCNjkk=; b=LCEt8k/SF7J8Z7Z6DR25I+46ksV8rf0EfI7j8x4puhNiRJT9lwY7hEKEqu1xEb899n vVZulhAuK22FD40yVSvEDxr43Oz5O4qBljtdyq7RJx9EVrpoN/JXOx6dTpnv0iVJg2bG SIdDzvV0q4inCgTZaeIzFrHKs3HlQSm3HvGv8dlADBtOUrnUVwTfV3qBYz6IvQhjA+m2 dr5yRSeeee8qW3sI0l4Nj1f3Eq4sKU0t2m/2X01Q+tCkLVgn/s3QC4W/RsWxXnLilwfB WH1pCtBrhi5UXAu4757IQmMFW3GOMgft/NW5P7KXdVAGf8XL3FprUbb6jTKwPBzDzmXL 5KZg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=yPRMROaM; arc=pass (i=1 spf=pass spfdomain=flex--mattgilbride.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-150260-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-150260-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id i13-20020aa7c70d000000b0056c3f718c8fsi888036edq.340.2024.04.18.07.18.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 07:18:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-150260-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=yPRMROaM; arc=pass (i=1 spf=pass spfdomain=flex--mattgilbride.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-150260-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-150260-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id B88641F20EE6 for ; Thu, 18 Apr 2024 14:16:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 80DEB168AEC; Thu, 18 Apr 2024 14:15:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="yPRMROaM" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (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 97D33165FD8 for ; Thu, 18 Apr 2024 14:15:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713449747; cv=none; b=XjehrEvm1jwFKxMyyi/8oGIPX+JhzefPA2XR+5YAGJyKalatWehyMfW3TPL1t9nE8rEJaR4vKdtVnedKC3s4RgzBh9j6nHD/TZBTfNo++vzj4GUK+zz8E+ewtm+yuvNEo6Sksru4C2HoXMuIFedVKoSCZjfLNk/uukGa67jMcbs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713449747; c=relaxed/simple; bh=m1YV3MNun7XuWA7B78NVbZOkPP2rvdY4f2uOk5CQSy0=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=l3522Ldq5USx6Uabqg0Md84fk1HpKlnY7cL9abKKdarlwqZ4AY7fYleDyRAY6oAL1C8M0/tL2VjTGXOeAf29sNCMrnqlIZ/CNWh/V/fuA47JaNOxSNCQG3m2fPO9B7uLXGmxnt142Bjv3Forc2ShmY2JIi9p7zOqjGPeYwcDQn4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--mattgilbride.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=yPRMROaM; arc=none smtp.client-ip=209.85.219.202 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--mattgilbride.bounces.google.com Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-de4645bee83so1446499276.3 for ; Thu, 18 Apr 2024 07:15:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713449743; x=1714054543; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=jwRanQRdUIcfSKJvkIkP9Sl2pJsKe5JFR6MS4BygDeE=; b=yPRMROaMcK6r3zz+iIgMkjx+K7tmye5Q3rIhJC9bH+w0/6WnKuImA4DRCEep4c3aX2 mowYJnOqpR+n32lZ1I7t0SiyjHOrN+2Zsb8r394mllTUrQEmTZMAjviKFWZkQuzbK0rW ZSHXSRwnjArVz9tGdHttNU3s+55T6a6TH+1XqeRGIqUOFyMkOsAcbFA/rrZgKaONR6DB e9/w2suJGE9/x+IO1zSx1+Meo9lFP7X8V/a79Uh+vNTBgcgF0KDMXKfYvDjAPTax0Gkk BACaLl7bcW0ttfonJaiS7NuX36hx0/wSnR2zp7M6rqaB7K39Vnj/rbPCaZNhTHJ4snNW kqsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713449743; x=1714054543; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=jwRanQRdUIcfSKJvkIkP9Sl2pJsKe5JFR6MS4BygDeE=; b=KfFqlQodKmptzXQfKrMZqtF8i6cWBiJVXmOcHcNvDvyNVx1r3JWJl6dnjPfYoSJRQ4 klZMfjYLMYVdOSctzgec9beB7dWLMOiMl4ue4fNTbyr2mQvs+wRAfiZ6IksnRZjznnmr LLBa77HYW+5TddKqeWPYRJpQFuWLB6qNcz74L3gLDMikjJikGkRotspOzniXoMU3/mP4 eiY1oHc/6H/nmxgBhE3RvmUG6fs8RCSHE6pP4pVnTztPNnXosRmbQwIdWfcUQgJjooKP gw+4dnl/Mm1CPc0nF5lEZkkJ2Ftszk0f+aGkkPvlli9PqG1DRHp2SZZ6U/UFKad7HfIE RIRg== X-Forwarded-Encrypted: i=1; AJvYcCVPnHA1XBK4k25qiI2PjvCum884mSv7elbDevV/dK3/i2b7sPQMc3QZ73s04l6wQTaEBLgk6RLpxeYvIiReqXraKwss1NN/xDJkxOTj X-Gm-Message-State: AOJu0Yz6/KQy26GJpYdBuqCfSrfm2T1EDQ2B3WtHnXjyJffC2k92uzCe A2JU3KA0Mep2JUoQOPBvgDdD0eNdrNoMqBcmi6X/6d+8bW0DB25I9b7pTIu8SPmaY/RdasCWwG5 3OhUHSq3j3W6draOtw7qc5wUcxA== X-Received: from mattgilbride.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:2ac5]) (user=mattgilbride job=sendgmr) by 2002:a05:6902:150d:b0:de4:5ce5:2656 with SMTP id q13-20020a056902150d00b00de45ce52656mr241547ybu.8.1713449743516; Thu, 18 Apr 2024 07:15:43 -0700 (PDT) Date: Thu, 18 Apr 2024 14:15:39 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAAwrIWYC/1WMQQ6CMBBFr0Jmbc1MB4y48h7GRQsDNFFqWtJoC He3sILl+/nvzRAlOIlwK2YIklx0fszApwKawYy9KNdmBo2aSWOlbKmCnYKIMtaSQbp0aBDy/xO kc9+t9XhmHlycfPht6UTrulZKPFYSKVR1XQmLCF8bvPfe9y85N/4NaybpnUr1XtVZRUvExlhmb A/qsix/YmUBvd4AAAA= X-Mailer: b4 0.12.4 Message-ID: <20240418-b4-rbtree-v3-0-323e134390ce@google.com> Subject: [PATCH v3 0/5] Red-black tree abstraction needed by Rust Binder From: Matt Gilbride To: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , "=?utf-8?q?Bj=C3=B6rn_Roy_Baron?=" , Benno Lossin , Andreas Hindborg , Alice Ryhl , Greg Kroah-Hartman , "=?utf-8?q?Arve_Hj=C3=B8nnev=C3=A5g?=" , Todd Kjos , Martijn Coenen , Joel Fernandes , Carlos Llamas , Suren Baghdasaryan , Christian Brauner Cc: Rob Landley , Davidlohr Bueso , Michel Lespinasse , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Matt Gilbride Content-Type: text/plain; charset="utf-8" This patchset contains the red-black tree abstractions needed by the Rust implementation of the Binder driver. Binder driver benefits from O(log n) search/insertion/deletion of key/value mappings in various places, including `process.rs` and `range_alloc.rs`. In `range_alloc.rs`, the ability to store and search by a generic key type is also useful. Please see the Rust Binder RFC for usage examples [1]. Note that the `container_of` macro is currently used only by `rbtree` itself. Users of "rust: rbtree: add red-black tree implementation backed by the C version" [PATCH RFC 03/20] rust_binder: add threading support [PATCH RFC 05/20] rust_binder: add nodes and context managers [PATCH RFC 06/20] rust_binder: add oneway transactions Users of "rust: rbtree: add `RBTreeIterator`" [PATCH RFC 17/20] rust_binder: add oneway spam detection Users of "rust: rbtree: add `RBTreeIteratorMut`" [PATCH RFC 06/20] rust_binder: add oneway transactions Users of "rust: rbtree: add `RBTreeCursor`" [PATCH RFC 06/20] rust_binder: add oneway transactions Users of "rust: rbtree: add RBTree::entry" Not used in the original RFC, but introduced after further code review. See: https://r.android.com/2849906 The Rust Binder RFC addresses the upstream deprecation of red-black tree. Quoted here for convenience: "This RFC uses the kernel's red-black tree for key/value mappings, but we are aware that the red-black tree is deprecated. We did this to make the performance comparison more fair, since C binder also uses rbtree for this. We intend to replace these with XArrays instead. That said, we don't think that XArray is a good fit for the range allocator, and we propose to continue using the red-black tree for the range allocator." Link: https://lore.kernel.org/rust-for-linux/20231101-rust-binder-v1-0-08ba9197f637@google.com/ [1] Signed-off-by: Matt Gilbride --- Changes in v3: - Address various feedback re: SAFETY and INVARIANT comments from v2. - Update variable naming and add detailed comments for the `RBTree::insert` (later moved to `RBTree::raw_entry`) implementation. - Link to v2: https://lore.kernel.org/r/20240219-b4-rbtree-v2-0-0b113aab330d@google.com Changes in v2: - Update documentation link to the C header file - Use `core::convert::Infallible` in try_reserve_node - Link to v1: https://lore.kernel.org/r/20240205-b4-rbtree-v1-0-995e3eee38c0@google.com --- Alice Ryhl (1): rust: rbtree: add `RBTree::entry` Matt Gilbride (1): rust: rbtree: add `RBTreeCursor` Wedson Almeida Filho (3): rust: rbtree: add red-black tree implementation backed by the C version rust: rbtree: add `RBTreeIterator` rust: rbtree: add `RBTreeIteratorMut` rust/helpers.c | 7 + rust/kernel/lib.rs | 1 + rust/kernel/rbtree.rs | 1275 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1283 insertions(+) --- base-commit: 768409cff6cc89fe1194da880537a09857b6e4db change-id: 20231205-b4-rbtree-abb1a016f0a0 Best regards, -- Matt Gilbride