Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp748599rdb; Fri, 2 Feb 2024 02:56:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IFqyCvQLdtwiFUXQADS31VnZryELKOnKNQijOqnyep2Gw3x9dNb0POi2A/QkGkRZCgUrMoO X-Received: by 2002:a05:651c:204d:b0:2d0:527b:43ee with SMTP id t13-20020a05651c204d00b002d0527b43eemr4471351ljo.7.1706871363566; Fri, 02 Feb 2024 02:56:03 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706871363; cv=pass; d=google.com; s=arc-20160816; b=iejbb7d0kp3dwHtQ5CyqH/sp0TJuBUeHvhMlXv/cZbcqv3UmJ9O5DDLfmFdWXEJj/X nmqwenKEgR1t+E1/2fjN2XV5lxjK5J8DhH7Bll3yybNEoOmVwBaMigDGZm0Ynsbhe51O Uic/za3cfoT0nDomvtcZuVg2OxYD4zqvqlcFpj/mxDhbyWFzZBoSUQJAg4GBu2ZavYKL JgJ6sA658qBo+HBSIDismeAlWQxxyfARDUrbau7KaHRgWUVVgnhAeWsUyA13tfrwzwMZ 9pldwBgedAA/jajbCnUTXcfMvyywJBoYA7Rggcujpr80oKc0UxTgYdYxB0JhkA6e3cZs K3rQ== 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=t1SYVq7IWrVJrOWe+eZ7mALVplGmC5gzqBZJtitkX2o=; fh=wm20PIOXrTkcJTSUaZTVM4BRMrc8IfXI6/zTpvyc8Lk=; b=cYF48X5tp8DXqxop9yt4Q1fQekBKiTP021q3n/dSrm3E6vNKJ2wmAINhcuXBUCO1OM LUSqNszO7W0ytNXfS0iAENu3e/2jRpiOdrIwN1nLb45kdSngmyoWJbdUQS4XRGWMkrHh ck7nKcJAR1EevrGBk9mHA7bEe7BW+gUK44HDJ3xWGqJcCwOZ+HqZE7wWp3/w5izES5+w 88mr+VjL89kQpllXtDbSVFaQj0vjefZ4LxIK2qQuBBz+yXUKIYiufFRzFHMocCUkAAr/ ht2HvjqtTXFvXteftW6YGLzMACBkwo2uyMOjgiJg6KuSOkYjSNFrjn/llDVpsTRerxzz /E9w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=4SvTzjPO; arc=pass (i=1 spf=pass spfdomain=flex--aliceryhl.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-49705-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49705-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=1; AJvYcCX+OT8M2dxF6upBy17o0HZ6cZYngi2VqussjnBGKehygZz4GmSj1kTZpzIZnfg5AlIJjCppaoRPLhVo7IiD0sEe0icdLiAl2h867WmjYQ== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id p4-20020aa7d304000000b0055feea651b9si491522edq.53.2024.02.02.02.56.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 02:56:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49705-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=4SvTzjPO; arc=pass (i=1 spf=pass spfdomain=flex--aliceryhl.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-49705-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49705-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 24EA81F2B4CA for ; Fri, 2 Feb 2024 10:56:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7F15A13D506; Fri, 2 Feb 2024 10:55:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="4SvTzjPO" Received: from mail-lf1-f74.google.com (mail-lf1-f74.google.com [209.85.167.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 4C3CA18B15 for ; Fri, 2 Feb 2024 10:55:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706871350; cv=none; b=qdzL71CfXI5c+/dY3nsLSjf2HdviHQw6Oh4NWINVXoNC+CwMgHohmxE+iGB4ZaMsjMBg68xIWKHwVBr9s00jBzEZtLWW3ngol+QYc0vrVXXihsuzd74VONHKNfixNlhuLHZDT44r0bWkiZLP0A6GYco9UnUwTFg2yNVDY6GvwN4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706871350; c=relaxed/simple; bh=mGdvPWrbrx4U8RhRaK04UOHddGQFO92nBOYIqfwKAKs=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=Nr+qSuBwScfnm4XkUnbpi6OWyy/wabzCy0eg7bIOXYZIYABgOjOjarBALv+gn1EDA8ozC7yvR35BhXEWJT2jKIwwpFP8+/kLm012SxwAJMf6sVPIzQ+499xJh3n/Mv5//ZyOGqoqbi3xsXv9s7CZwIthyHbIAmw4Az36DOovp8s= 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=4SvTzjPO; arc=none smtp.client-ip=209.85.167.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 Received: by mail-lf1-f74.google.com with SMTP id 2adb3069b0e04-51126da2a28so1659521e87.3 for ; Fri, 02 Feb 2024 02:55:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706871346; x=1707476146; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=t1SYVq7IWrVJrOWe+eZ7mALVplGmC5gzqBZJtitkX2o=; b=4SvTzjPOjDDGfytsfa573Xx9cwxtFjxUPiBqoIOMNBglS9ZCncd9GhKzQa4VdpbFX+ /XBze1+N+PESq3NzdgEDNtImJvmqLPxC+csVbz+r9NMzyinhJThLhW1MiuQLEQlyAmF3 q0AJ5HOgGM8ZuO+unDcvSv393cCySsbj+EugqqvDnFde0bxhCZL3eq6806qmt2UGI1ug EchYz7TPgDghgq5B47hjsDxUiGUAbH9WDdMiBMVl9twXjiBYh3rJfKRnK/P++g5WOg/L zykTYnKLQ6l0t6+CbLEoUL6xcIhMTCu9197swrj95K8s2L6ZTUdvVRcN1lH57/Cf3kSt cImg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706871346; x=1707476146; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=t1SYVq7IWrVJrOWe+eZ7mALVplGmC5gzqBZJtitkX2o=; b=Zr56ZcjIZwSYcbJbSoZQJ+GED5s02ea91z9zCkJi1nUKs6lc05L33COKjKNRy5+Bc3 gGrJh434IBQXNIzPcndTyetxFeXFsJjLmw4v/EKyAZ9nq877iCaOxpF6pWhbdHTwckDP CkFW0eBzVW2W/fzF5f8Lk2NV+MlQPSLCg0d2JqLrPhUaSx4qwvprqRMtWlmfUMo/k6Z6 Mocept5kKkA3le9QhlFV7v58JvvuvlmmGUkQzknkPjdiKJ2MFpAYNTc+E7wiAbmIRIE1 xxLnlH8rJ2LPDMuXjVkabPOIwFynbVdvTY/2xoF+NLmMbAaPi1lcP79rPOWj9gplZrhq Eyqw== X-Gm-Message-State: AOJu0YwO6lc1ugwVlegyiDZ07QDK0H8cEToLOUBY9Z8gGBI8qAb0pSNo 1rMlrmwWeBPJeL7b0KSYKhBcz9mvyuumji14b2Ux8qhRX5xgI0Sc7DWG76tlE6ALkOy3mOKb1Mj m5t9KEurxWOAnnw== X-Received: from aliceryhl2.c.googlers.com ([fda3:e722:ac3:cc00:68:949d:c0a8:572]) (user=aliceryhl job=sendgmr) by 2002:a05:6512:3904:b0:511:2c22:91d4 with SMTP id a4-20020a056512390400b005112c2291d4mr5781lfu.3.1706871346299; Fri, 02 Feb 2024 02:55:46 -0800 (PST) Date: Fri, 2 Feb 2024 10:55:34 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Developer-Key: i=aliceryhl@google.com; a=openpgp; fpr=49F6C1FAA74960F43A5B86A1EE7A392FDE96209F X-Developer-Signature: v=1; a=openpgp-sha256; l=5345; i=aliceryhl@google.com; h=from:subject:message-id; bh=mGdvPWrbrx4U8RhRaK04UOHddGQFO92nBOYIqfwKAKs=; b=owEBbQKS/ZANAwAKAQRYvu5YxjlGAcsmYgBlvMjE6pCs+rI00fx1280XNJDyXvExjIQNzU+nr 4V0h3LOxsaJAjMEAAEKAB0WIQSDkqKUTWQHCvFIvbIEWL7uWMY5RgUCZbzIxAAKCRAEWL7uWMY5 Rv3FD/9TOTqjOveDki2tSpD80/JyKVOjmRv1jn9DDlUbxoGmotj+mKova98vX82ceo5Y5Cq9ccl QC8FYuSQRinH3IndTurAWmKwbvzGcFUXUXOJeL2H9+4kfKua4aB84OEbWuZIaAWYms7tSS3IFlg yL6Q1rDzIjxnhSAtbgLR+tRp+1kBt9j6+oqD4Vrd44iMUOiiGe8StLOVH6+07pk0W2CVHmd2Gig pUWDSrKRI8Q3ix1BdtJ8iv4/GNdaT9EEwQni9GNQGuoV/bxp0WDZ3keBeHVYVaoxhFh+UpTRnFY TXhq6sLHQLtxzprIU8HziNPOwZaZZwMAHJbMboxr/yDBY0RsW8yc0qW4Vn5dlJPo3CAZnF4kqPy jYQXA58Of3ZgfHKa3fH9SgrZ/RaQiH9AR9z3+xFsqZtKjfOTrdzJwqndoJf19SZBKaak13oXQoB zs2AwoRa/0pS/6taFC9RWys9PC9+K0hgi7Y1PK6TGgUIiKkdJvFxpBUt5tjnfkSIBfWgvL+0vND /gi2c0xpclugDJf81un4VHb3x6T5MTTzLKChyCXAqPXkmod8aXNyfvxhFwrrOUt180qmmCxoNNW 2ROBqYZHrCMGU9OCoRPwWwbTCblkNmnkJ6wS4rkUgGaIfTKvDJ9zviTKBcDpIiJsDO6h1kR0SUh t0SwRm/tA3zcUmw== X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog Message-ID: <20240202-alice-file-v4-0-fc9c2080663b@google.com> Subject: [PATCH v4 0/9] File abstractions needed by Rust Binder From: Alice Ryhl To: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , "=?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?=" , Benno Lossin , Andreas Hindborg , Peter Zijlstra , Alexander Viro , Christian Brauner , Greg Kroah-Hartman , "=?UTF-8?q?Arve=20Hj=C3=B8nnev=C3=A5g?=" , Todd Kjos , Martijn Coenen , Joel Fernandes , Carlos Llamas , Suren Baghdasaryan , Dan Williams , Kees Cook , Matthew Wilcox , Thomas Gleixner Cc: Daniel Xu , Alice Ryhl , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-fsdevel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" This patchset contains the file abstractions needed by the Rust implementation of the Binder driver. Please see the Rust Binder RFC for usage examples: https://lore.kernel.org/rust-for-linux/20231101-rust-binder-v1-0-08ba9197f637@google.com/ Users of "rust: types: add `NotThreadSafe`": [PATCH 5/9] rust: file: add `FileDescriptorReservation` Users of "rust: task: add `Task::current_raw`": [PATCH 7/9] rust: file: add `Kuid` wrapper [PATCH 8/9] rust: file: add `DeferredFdCloser` Users of "rust: file: add Rust abstraction for `struct file`": [PATCH RFC 02/20] rust_binder: add binderfs support to Rust binder [PATCH RFC 03/20] rust_binder: add threading support Users of "rust: cred: add Rust abstraction for `struct cred`": [PATCH RFC 05/20] rust_binder: add nodes and context managers [PATCH RFC 06/20] rust_binder: add oneway transactions [PATCH RFC 11/20] rust_binder: send nodes in transaction [PATCH RFC 13/20] rust_binder: add BINDER_TYPE_FD support Users of "rust: security: add abstraction for secctx": [PATCH RFC 06/20] rust_binder: add oneway transactions Users of "rust: file: add `FileDescriptorReservation`": [PATCH RFC 13/20] rust_binder: add BINDER_TYPE_FD support [PATCH RFC 14/20] rust_binder: add BINDER_TYPE_FDA support Users of "rust: file: add `Kuid` wrapper": [PATCH RFC 05/20] rust_binder: add nodes and context managers [PATCH RFC 06/20] rust_binder: add oneway transactions Users of "rust: file: add `DeferredFdCloser`": [PATCH RFC 14/20] rust_binder: add BINDER_TYPE_FDA support Users of "rust: file: add abstraction for `poll_table`": [PATCH RFC 07/20] rust_binder: add epoll support This patchset is based on rust-next, which means that it doesn't compile without the following patch, which has not yet made it further upstream than rust-next. https://lore.kernel.org/all/20240105012930.1426214-1-charmitro@posteo.net/ This patchset has some uses of read_volatile in place of READ_ONCE. Please see the following rfc for context on this: https://lore.kernel.org/all/20231025195339.1431894-1-boqun.feng@gmail.com/ Signed-off-by: Alice Ryhl --- Changes in v4: - Moved the two really simple patches to the beginning of the patchset. - Update Send safety comments. - Use srctree relative links. - Mention that `Credential::euid` is immutable. - Update some safety comments to mention the invariant on Self. - Use new name for close_fd_get_file. - Move safety comments on DeferredFdCloser around and be more explicit about how many refcounts we own. - Reword safety comments related to _qproc. - Add Reviewed-by where appropriate. - Link to v3: https://lore.kernel.org/r/20240118-alice-file-v3-0-9694b6f9580c@google.com Changes in v3: - Completely rewrite comments about refcounting in the first patch. - And add a note to the documentation in fs/file.c. - Discuss speculation gadgets in commit message for the Kuid wrapper. - Introduce NotThreadSafe and Task::current_raw patches and use them in later patches. - Improve safety comments in DeferredFdCloser. - Some other minor changes. - Link to v2: https://lore.kernel.org/r/20231206-alice-file-v2-0-af617c0d9d94@google.com Changes in v2: - Update various docs and safety comments. - Rename method names to match the C name. - Use ordinary read instead of READ_ONCE in File::cred. - Changed null check in secctx. - Add type alias for PhantomData in FileDescriptorReservation. - Use Kuid::from_raw in Kuid::current_euid. - Make DeferredFdCloser fallible if it is unable to schedule a task work. And also schedule the task work *before* closing the file. - Moved PollCondVar to rust/kernel/sync. - Updated PollCondVar to use wake_up_pollfree. - Link to v1: https://lore.kernel.org/all/20231129-alice-file-v1-0-f81afe8c7261@google.com/ Link to RFC: https://lore.kernel.org/all/20230720152820.3566078-1-aliceryhl@google.com/ --- Alice Ryhl (6): rust: types: add `NotThreadSafe` rust: task: add `Task::current_raw` rust: security: add abstraction for secctx rust: file: add `Kuid` wrapper rust: file: add `DeferredFdCloser` rust: file: add abstraction for `poll_table` Wedson Almeida Filho (3): rust: file: add Rust abstraction for `struct file` rust: cred: add Rust abstraction for `struct cred` rust: file: add `FileDescriptorReservation` fs/file.c | 7 + rust/bindings/bindings_helper.h | 8 + rust/helpers.c | 94 ++++++++ rust/kernel/cred.rs | 81 +++++++ rust/kernel/file.rs | 514 ++++++++++++++++++++++++++++++++++++++++ rust/kernel/lib.rs | 3 + rust/kernel/security.rs | 72 ++++++ rust/kernel/sync.rs | 1 + rust/kernel/sync/lock.rs | 15 +- rust/kernel/sync/poll.rs | 117 +++++++++ rust/kernel/task.rs | 108 ++++++++- rust/kernel/types.rs | 17 ++ 12 files changed, 1025 insertions(+), 12 deletions(-) --- base-commit: f090f0d0eea9666a96702b29bc9a64cbabee85c5 change-id: 20231123-alice-file-525b98e8a724 Best regards, -- Alice Ryhl