From patchwork Mon Feb 19 11:48:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Gilbride X-Patchwork-Id: 20589 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1228617dyc; Mon, 19 Feb 2024 03:48:58 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXWYWe9MLmzmkMKOWlvuuG+GDRQnvbr0i+3Lqc7HqTQd6hpR1Fw/aCESh2jZ5VQFV0Hy4cZ6PBsyAr0WMeWUV5BAyys8g== X-Google-Smtp-Source: AGHT+IGmJxh3qr6U57yeso9bwuoUFO7+ix0+OW+VoUDZCt1tBjKkHbz+kFk3Glyyyc4fGmAeRR2+ X-Received: by 2002:a05:6102:18d9:b0:470:5667:65db with SMTP id jj25-20020a05610218d900b00470566765dbmr1982819vsb.4.1708343338783; Mon, 19 Feb 2024 03:48:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708343338; cv=pass; d=google.com; s=arc-20160816; b=xEsfus+VISybjOdb/Z5ofoM/Apgwqp8uNo8yGO2XwO0siedyYwOn+0+Xr115VAZZSq Fx0qu+8mNkCZ7vy7vtiJHWCpLs9UqGysD8E+LK0vQHWpFbWEEKVG0bc+/07J5VpBpYEf BnqehPDm0yaCSL3r/JAzR4sCmZe2B15wooaHLbuPFbWULOgzZjmi/pjKQV3qyCADM1Eh 5z+lNAW2v8uNMoObr6w02DKa0IQgOhEo3Th1D1AlH1Wsy3Us3go7v5iHUCZItCgT0OYi UD9lzwkJglbnggp3Hrkajdli2qltO94OOMTWiXUlSprpHrQHqK6IY/9veGkoRr5sMKdp Xxew== 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=Zq3hIb/a7G7RDHkyPhkOMlDdykFo1mSw4GBQxXEi8tU=; fh=vlMMpqyFibvhUOoj3fgbjFyrAKtSBR3Gl5DpMqTTlxY=; b=O6mYUKI+aYZxykI4B1q7ySq8+JaNI0rdOaz8VFRbOQSBrGWOjupJJw9OSoLnCQMen3 54CE5S5J8ZJUBWsSf1oZBDyc7e3+lNIHMOmMtJHmf1kCTIf2IY3NuhzZRkZRfWRTS01h b5VKfUg71vtqr965p09OD8VW3e416MSlYy8C+ThYZiCLZ2SeHtITQkQ5x3SnEsJ4JivA pz0R2mYPWp9RxHg2VAjxyI5yA8zRSW9A3VBJ0ZE10KtfH1C2G7poQsluG1kQUsneO+iH qMAJQp3zIwpowNOppocMIsw6f24C/GaWdSYmq6h2qz4bZvUj6V57Z7VCNVlmFf0mzhxt hD8w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=oqk6Y6EN; 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-71240-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71240-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id x15-20020a05622a000f00b0042c0509f5e9si6374359qtw.324.2024.02.19.03.48.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 03:48:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-71240-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=oqk6Y6EN; 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-71240-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71240-ouuuleilei=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 7765D1C21136 for ; Mon, 19 Feb 2024 11:48:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 24D652D627; Mon, 19 Feb 2024 11:48:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="oqk6Y6EN" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (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 6E5592C68E for ; Mon, 19 Feb 2024 11:48:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708343316; cv=none; b=AnuiemWU4FrZufXcH/wneTP+ZXQbz3kZ3S9J4QiUUIun5F8fqgtKdPeC64xAADfj8c7zPaiPZCV9NGWJi4VeGaxqxbYYlfXj7kEiOo+TItxS+f7Sx2TaPB4CCpeQDHPlANqpYmG+81IuzOloospsPjf7PAkMTc0hZdhWyrEMtAU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708343316; c=relaxed/simple; bh=0BgyreMqzz0PMtI4QUlHgDPJch1SnZJpj6ZUNM2eegA=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=q7Ta6azk+LRZy1kRb0gLN9+89aTc7BowKPgfUXIohja06lZwBtK3xxLrTOztu8xHL6cM5jg/lihc7fi7prwM8B52f+QpPKtxqHdkxqHbWS1NEU/sRIsQbrsSJ/7LWcv99hxJhmytOA3QF5ZgiX7KQkpgjDbDbVHCgJRxmjJq4gg= 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=oqk6Y6EN; arc=none smtp.client-ip=209.85.219.201 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-f201.google.com with SMTP id 3f1490d57ef6-dc74ac7d015so5325860276.0 for ; Mon, 19 Feb 2024 03:48:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708343313; x=1708948113; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=Zq3hIb/a7G7RDHkyPhkOMlDdykFo1mSw4GBQxXEi8tU=; b=oqk6Y6ENgoe+QN87VFoeCynR06gMK0PE9szXy93wj+qpKdCv/Ut+jWHL38P+q4KSCJ +isL9ifP+vUnGrjI7URyHTo0P/2R5wFkCgxUTyOJT1G3HMT4ZempChegdeW5REDR3IQc 2y8oZetCWnFiaFe9QvzzLdjpfZnbvGZBpC/ijeOJwKKuTIdKiZZhe2U9JAf+1Jxj0Dur GPIM9ceiLB9zfZOHGfq/vD0vnfQffbMFWEq3DJVkrquS2YvyVWFw/zqD654De1YqziG4 BuzH+TD7sHyhjuOAJEAWeuu6pRHNWehubdtbG1FEj2z0Qsy0uDz84AHn+uLis/NPkfWD OlDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708343313; x=1708948113; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Zq3hIb/a7G7RDHkyPhkOMlDdykFo1mSw4GBQxXEi8tU=; b=NuFCwZA6ohol2lCgcbt64+HqPiYk+ADXn0bb4FZZ91fu7BAK+62LLsJhb78IpAj0kF ICxfdgJd4Bp2fpP4cSiqaUfgj0bhRs/a8HedRmVfcnG7FBmPRv5/PiC664pGCqWPYlKx rer/qor9ISoLU8FuTzj9GTon6kfQqUqJwlT2EP8tSIWbYa5dUDsUnDOQ56C+xWhM7Xdp XT6zE8jxqZ7FCUYEDz31Y5gD9KxGUtKK6ZgHt3s8hh8TF2Eabs/n4KQVFSinEvJuiLS1 yPSM4p+zGVO4oGpLUXte4FLRh6G0yfZ/XrGILvD930Whs9BsknToCTNJa1dujo68Yquq ndiw== X-Forwarded-Encrypted: i=1; AJvYcCWfKDmPcKG/9bRV5ehkZZb4FiaFzoJs0+7/gPMIECeKNeil16UmRIr8EUhiV+UiAW1tw5UFNiY39RcZX/V/oGtufGNoRJL/qlqsGDM5 X-Gm-Message-State: AOJu0YzpJiU6D++TpbLuXo8BiBxHaMJZ9nZuvRhFcLdVSGrfE0pQe+F6 LZ5uwdv2p+uuyc5Ik3AoQ+KrqvX5j4jMM/XlPm30YoKbUPtBbaAI6mfV58GB5/Earbq+ivuPtmd nb6DSCGufreVbtjMo6OkYRnkD1A== X-Received: from mattgilbride.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:2ac5]) (user=mattgilbride job=sendgmr) by 2002:a05:6902:1b85:b0:dc2:26f6:fbc8 with SMTP id ei5-20020a0569021b8500b00dc226f6fbc8mr479732ybb.7.1708343313437; Mon, 19 Feb 2024 03:48:33 -0800 (PST) Date: Mon, 19 Feb 2024 11:48:07 +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=H4sIAPc/02UC/1XMQQ7CIBCF4as0s3bMAK2xrryH6QJwSkm0NNAQT cPdpd25/F9evg0SR88Jbs0GkbNPPsw15KkBO+nZMfpnbZAklZDUoWkxmjUyozZGaBKXkTRB/S+ RR/85rMdQe/JpDfF70Fns66609K9kgYR937FiZnW1dHchuBefbXjDUEr5AbpTt/SjAAAA X-Mailer: b4 0.12.4 Message-ID: <20240219-b4-rbtree-v2-0-0b113aab330d@google.com> Subject: [PATCH v2 0/6] 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=B8n?= =?utf-8?q?nev=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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791327824955300886 X-GMAIL-MSGID: 1791327824955300886 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 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 (4): rust: add `container_of!` macro 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 | 33 ++ rust/kernel/rbtree.rs | 1214 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1254 insertions(+) --- base-commit: 41bccc98fb7931d63d03f326a746ac4d429c1dd3 change-id: 20231205-b4-rbtree-abb1a016f0a0 Best regards,