Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp386750rdb; Thu, 18 Jan 2024 06:37:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IGS6kcT9emFeaJN+ZTNBxkyWYEf+TYMn/4HaNBuhaEzz6g9zcUGARuOj0QGVwXKmpRn6LTh X-Received: by 2002:a05:6e02:eea:b0:361:a1b2:4c1 with SMTP id j10-20020a056e020eea00b00361a1b204c1mr408714ilk.52.1705588642279; Thu, 18 Jan 2024 06:37:22 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705588642; cv=pass; d=google.com; s=arc-20160816; b=hkr3u1ned0LKuVjasfqCe0p23S9yF9yD/CG/wNnzuyqfUHJd2v+o6vGiaaoSTy1NMQ iVXzLBp9vlQUQLmn4euC56C7wZKgmq6RDPRuwV1IhbTQCbEaNI017gfdYrwOV87o6AHr trM+uDUJbZ02ciDRtxKndks6H0t8N8EuWi9qaX6hN16DaITx39IGheAWkoHo5WTfqHs6 q9rWxvY51HeBnHlSC1YHnHkcNUqoFyTUGVfBrsCx4gxAP8Bn48QAz2YiZ0C9pXxoFblK PwznU4OJBN1TytPz6miDnG1e5POF6N9sPdtqIoTzUD+rZ5U21uQ9Yp4Ql0C/OnA+yYmT IhFA== 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=0v0DKUVm/o60VD+s4pHxHrhv8BixZc6h40304F/G0T0=; fh=OP+vvG9ih/wBlPG6J6WwyVN77+HGWDbQuR6Uf4lsYyg=; b=lcFdi5AMvxMiiHV8SY5lGTInVvgCI5B58w0QjtIsurVL5ha3ginQHDnFPZ9Nc5ot4R CsM4gx8PaFI40KHkAwFXFBJ0sCurLKYIiGWBWxd8LtJcoUnDVMxXwQY2fNV2fhwQkmAF znVpSYWE9j3+GgRIZ2CzLskxlGVQwcXXxqsawgBP8Ih3c/zl0p7441grXUgMuEPTR9Gs eEhe4CtlhFX7qlxVLhtdkK+JJ8F+mvcgNO/yYYA7tjGykdm0J3/KVRtxC0FoJL4ubu8Z Ags2h5TvABDNjYbI8g90edFcoyMA4CLWG14iFA0SwMymLv3TCM0oFYRV4Bz69CeU9xvL OfcA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=vZ6nQwB3; 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-30201-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30201-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id n5-20020a634d45000000b005cf60f46fabsi1543492pgl.24.2024.01.18.06.37.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 06:37:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-30201-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=vZ6nQwB3; 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-30201-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30201-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 2969E283A39 for ; Thu, 18 Jan 2024 14:37:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 091E41E532; Thu, 18 Jan 2024 14:36:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="vZ6nQwB3" Received: from mail-lf1-f73.google.com (mail-lf1-f73.google.com [209.85.167.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 5C5D91DDCE for ; Thu, 18 Jan 2024 14:36:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705588616; cv=none; b=Ef34mu74CH/Pj8pNL8zs4fmfaIZmdaDNI/ksWUGNjybLCKEHvnY2av2axMHGEQMxRSL8c7zhkVaVgBoeUQsunEjn6kpTENUcepAgtIIu8iXqp+K+61SuKkFJcroFPIGsmIJq2h5EyOMFHMpr2aBw6wMDAzym1wM0aqinPcyR52c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705588616; c=relaxed/simple; bh=jhNAUl+zNRT0DrGGSk/2IHTE6BjJ/ijabDZTUKUpX+o=; h=Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Google-Smtp-Source:X-Received:Date: Mime-Version:X-Developer-Key:X-Developer-Signature:X-Mailer: Message-ID:Subject:From:To:Cc:Content-Type; b=U2u8VXtqeqWS0wa+e82ZD8khUaWvBf+azUTJdrT306i1OhnxkuX5fGQMQ6WXx7A1RDGcogjshUpv/D3cPMa418FWqyZxqmyWj5P93nfWI7wr7JOwlc+BpQ9NqeocBvFAkvYsC95yfTEvXD86TiuHm9TlLxwznq7zb4EDALJrCyg= 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=vZ6nQwB3; arc=none smtp.client-ip=209.85.167.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 Received: by mail-lf1-f73.google.com with SMTP id 2adb3069b0e04-50e75f8d722so387467e87.0 for ; Thu, 18 Jan 2024 06:36:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1705588612; x=1706193412; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=0v0DKUVm/o60VD+s4pHxHrhv8BixZc6h40304F/G0T0=; b=vZ6nQwB3rF9RTmCwwzjKD2KEIdqtgr0KLnHrSxJL2zk8sXvhd6qYWtegXpkjj8qdIC pHFpRjwyld5aCBq6ajCNCzkBzZDod4NBaLqv9sGvrgzTrKNn77BYjmlU14htf0ERuvDq BFINVc5iNyeiN830lIZWYJ/WsPWjWrGR28WKNK/LnpWpcpFffwtm2dsbUsFX37snAQkF kdiyAuRTyT93bY598ii8s04i1xC+rB08NpHkUs8kiuTL6kinup0jxt6voRzw2buFadDf vnPfzU0vVsfv9T4BASs68dWq4i9A7220APwzAD6p4UNU2Zk0EdAqZvbEeLxh1ymlXehn 3zsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705588612; x=1706193412; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=0v0DKUVm/o60VD+s4pHxHrhv8BixZc6h40304F/G0T0=; b=PIGg6pT/ibJpWO8w7zQR4Vp9Vg0aZTvx1ajC8ucQ/85SvbVDEpm5K4TehCncZAqWsO Z3U/W0sAz4MXlXKfNSXyMv/gBFd/xEpUsQojjIV+ZJKl/231wjrnbl2ZDz6F0nCkPwRY /9OzXX4SKCdCiUTZNlwRYDzBekSr0J3X3jp37gl6e4qwKESkzo9ooArYDIm77KJHJEyg hkbUOES85qrgKZwRjEF8rb1f2EqDvswKKQXyW+XprBtATHaIox64Vn5mj4F2yRsJE7QQ /kUy9rUt8zxzKtOLcVq/FgnGjl9udJXWuRbt0jYKiU/GYnDphvUaVskzhuiD4sTsGCEI dqaA== X-Gm-Message-State: AOJu0YzIEtt0mFYea4OoiN5OkqVTJEOW1FP5hAj9jNqiXvqZm+XufA+G WIKjQR//SGlePLTwSK0/LcwQctPyoa2djjQt4S/I+k1fi/BB0t58+f4KFIa+aF6frUaog6xWXys GNK8Lw769ymQGpw== X-Received: from aliceryhl2.c.googlers.com ([fda3:e722:ac3:cc00:68:949d:c0a8:572]) (user=aliceryhl job=sendgmr) by 2002:a05:6512:34c1:b0:50e:b2ba:147 with SMTP id w1-20020a05651234c100b0050eb2ba0147mr6622lfr.2.1705588612573; Thu, 18 Jan 2024 06:36:52 -0800 (PST) Date: Thu, 18 Jan 2024 14:36:41 +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=4635; i=aliceryhl@google.com; h=from:subject; bh=jhNAUl+zNRT0DrGGSk/2IHTE6BjJ/ijabDZTUKUpX+o=; b=owEBbQKS/ZANAwAKAQRYvu5YxjlGAcsmYgBlqTHLOLO4pSaf2+zw3LdhQoTIc4w+uP2NKl9Y9 /cn6Z7VrtmJAjMEAAEKAB0WIQSDkqKUTWQHCvFIvbIEWL7uWMY5RgUCZakxywAKCRAEWL7uWMY5 Rk99D/0TYZ05gVZnIv1O/8NQ7Qj2KOYRm7SGdDQU0riJGIupvyVGm85cuWSZ+eFKcM2VZQIbXqQ AKCyaWC79/EkRmp0tOTOA8dWiYyfYcAsdUCaEDMuPeGV72JyAeYpHSYHdOSgBOqf2EMr4dPBTA8 lK7aYxg/qAUulf8m8m4uEHjVy0qSglOrzsshCv7uM6U0F3RjjdjcsQh2YnvBEXHV4gBT15TmLP4 EY9QNde/ga8sOa7g4jIRvKg9TbpuImJQbL781fMYeXpfziHfGQqUoWX2N9PYym8i2i4raxaHaRO CeItS4DcdWjdqqgHAxRI2LA97Aou6+QeD7irIJmsm1E9LClzp0XaUGNlJ2QRFYIndXRzq5gNQC6 szUZZcnDUdFW8JTMDTgNXnpNR6H+xL4rtW6aLwO530sIYCeSKpa1SgnqLwbo8Dhpmz52O9/IIuf J9BIO3+QS6OQAoMc/wm1F8rnH8Y3EFaAp0RNVEtET3HldJjSC5WH+fw7vP/E7YMPddtpa/lQXRI x2J4ruw9QgvhMQvEZ9ui2v9J+hQHIbVjuWoWb103Ga0kRT2g3oVkYcIFVA63Q0+Rjm6Bp60Nr37 hXK6bG4BCWgN01WrjKI6GvH/32QP+6h+2SlX/3YzYu/4pe3tjebyngBh9tP9hTVwCNGrExsbf3M DOXWb0TOVvL4wXA== X-Mailer: git-send-email 2.43.0.381.gb435a96ce8-goog Message-ID: <20240118-alice-file-v3-0-9694b6f9580c@google.com> Subject: [PATCH v3 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 Cc: Dan Williams , Kees Cook , Matthew Wilcox , Thomas Gleixner , Daniel Xu , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-fsdevel@vger.kernel.org, Alice Ryhl 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: 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: types: add `NotThreadSafe`": [PATCH 5/9] rust: file: add `FileDescriptorReservation` 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: 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 `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 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 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: security: add abstraction for secctx rust: types: add `NotThreadSafe` rust: task: add `Task::current_raw` 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 | 74 +++++ rust/kernel/file.rs | 512 ++++++++++++++++++++++++++++++++ rust/kernel/lib.rs | 3 + rust/kernel/security.rs | 71 +++++ rust/kernel/sync.rs | 1 + rust/kernel/sync/lock.rs | 15 +- rust/kernel/sync/poll.rs | 113 +++++++ rust/kernel/task.rs | 112 ++++++- rust/kernel/types.rs | 17 ++ 12 files changed, 1015 insertions(+), 12 deletions(-) create mode 100644 rust/kernel/cred.rs create mode 100644 rust/kernel/file.rs create mode 100644 rust/kernel/security.rs create mode 100644 rust/kernel/sync/poll.rs --- base-commit: 711cbfc717650532624ca9f56fbaf191bed56e67 change-id: 20231123-alice-file-525b98e8a724 Best regards, -- Alice Ryhl