Received: by 2002:ab2:23c8:0:b0:1f2:fdbc:cb93 with SMTP id a8csp38174lqe; Tue, 26 Mar 2024 19:36:01 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU/fE9m58j2JdnVZxxNb7Y6Ysn76DB4+PHF32+nZ38EV8xU9T6B5MnRSfSE2bfJqDnJaCxag/XoBFZCpof4PzY4mZtV4fu2tBkuWk6gpg== X-Google-Smtp-Source: AGHT+IEtO6w89lwBxR1J1ltFZV9Lk7q9b6IwNe/wV2yEAHqfSW0T/N7CFOiTqjCy1Cz4rptacRE7 X-Received: by 2002:a05:6a20:dd9d:b0:1a3:6404:7f0a with SMTP id kw29-20020a056a20dd9d00b001a364047f0amr9802247pzb.50.1711506960540; Tue, 26 Mar 2024 19:36:00 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711506960; cv=pass; d=google.com; s=arc-20160816; b=NZM0Qj63QfOMwPlB0sFUb5PThbGViJ5kHA8VEag638QEW2/lB9zA0xgGEiIoNBEW5d Av3xmR4hvC5qsb0EIwW3GXuZ/tMT4fm2M5v0QU+RKHi1clnPPvEQSb3TXaAlrHsTcapF XBLp1Gt6C13vVpml1SfSOzfmzuG0XaOoAYxj1jUoj3p40wj8l4QhstfNGg4NGRWHQ8CJ Vw4E/XBb0YZxgfzN/Ezauig19imxcSnL5CXT4ijWmBWXVeTitLdkLOWIkjT/xXGcVeDB hNDHFKYSpkELPxSJAhm8SC7hOBhRF5udbuR7e+XQ9p+QFM7eTxJIpjS8uZVJtZGAsUML tgkQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=zzpuZiLAjFHmsEl2ZTO7rWcGk9hHOOanbD6SfZr3xsA=; fh=9unoopXNQ0/AGU2G2RCKIGf9etjxHxiahaIDQ4Ufyts=; b=UIprE1liNBk3e/t3sASCLrukHQ7Zlaq8geeRk5jJ1CQMgT2YcqLsapV66y//fqrgsV 9Emb8Pq4tVqmGFv9nDioKpYyTE9cwgVC64MsSAKMrSyZWt4X4KRbD3wpyfckcIYt4QYL WwAE24spFyJwO1SgoAYKxvQryKElHXM86wQv/kx42AbkoEMXHjU/S5srhouStwM29cP4 AI53o9usPit5sV0zO8D4ptbklAtFsFYnI67dMnZ5sadRu479olKaUakhxd1sZPgYqNqd EdN4jt96ooXCk4hwgbcAu0n9eSGxqWy0Y3eOgEJkvYNtx3+gIJjNIdfiAHKIMMkyj1Qi mlrA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=EOci+0Vi; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-120222-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-120222-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id q7-20020a17090311c700b001e0e95612cbsi2762170plh.579.2024.03.26.19.36.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 19:36:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-120222-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=@gmail.com header.s=20230601 header.b=EOci+0Vi; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-120222-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-120222-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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 1FC4F2E6D8A for ; Wed, 27 Mar 2024 02:36:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A9CCA21104; Wed, 27 Mar 2024 02:35:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EOci+0Vi" Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) (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 3304212E55; Wed, 27 Mar 2024 02:35:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711506951; cv=none; b=LLrnzlNrAZ0QuG/wN13EO9RlsnjQ6C1k7UP55G5tDMEfyxkihlwFFjNYcq8DVFoCw/p5oponHcIuAhYtKPHKsg7bkBHYqnK5WfLI698VEGMzF/jWoBm3/WlBNbXmf1aGgBZDRtTGqtktuDkR+MHQIBD3vw7QqtHR/ZSKpjiC6Ro= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711506951; c=relaxed/simple; bh=y2zzynm2zh+qE9qqZdgoMEYhwSx3j6X8bOh+znAcf7c=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=aSoMVfD4skdM2bIRYz1AAoGesoRt7tPqtdQrkxnvQHeWZraILRtAhvzVOxIvMrxeNaycfo+7gNZFMwfGbXsJjW3d+W9TuKkmJBAb18LFyOi6KMEY0YVoffNkgTk20M6HmBG2jCNXLhExIw2Yn8QEtJLLJXUXHcy16eb7R4gphLE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=EOci+0Vi; arc=none smtp.client-ip=209.85.215.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pg1-f175.google.com with SMTP id 41be03b00d2f7-5ce07cf1e5dso3593228a12.2; Tue, 26 Mar 2024 19:35:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711506949; x=1712111749; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=zzpuZiLAjFHmsEl2ZTO7rWcGk9hHOOanbD6SfZr3xsA=; b=EOci+0ViXgUeTvvdksfSPSk3vKbRJVmqDN06d+krvoDgrmLNbunE/LpiQG2QUsRd6i cW0VlJ4kYiLzIQWDrB7BKODwvtW9BHswVECXSECQsw20qGQAEXrnqr9T+qiqH+x8sjPw Np5ey7YUIbv/SgfuZ3WMmmQ5YSFAC47PS2PtX8rtgoyfRgJfWWmpNujEbQn5niVGfmVK 2FB3qYxmM3UrXWNL5zlP2GeBxZmF3qCskPA96g85zP4Ce/GmDKHhNC2hLdO/a3eGN9Vs Ce3+Or0pLRz7/cEvoe8Otf9iul/LOOzxOxEJB6GI0Exh2ioxiEckJ3wHIg5TuTIadoV7 z9Ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711506949; x=1712111749; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=zzpuZiLAjFHmsEl2ZTO7rWcGk9hHOOanbD6SfZr3xsA=; b=eJ0mPx4UVDnhzcHBoS9N/wOX4TKXcTCPfoPFOWuxdOPpvyHrfPIVJX5vrR1c56iHbn OZWBERCEdi0d6wJxr8Dw1vSEFWIWyIkzi72OLC5aEQyyXxfDThN0fnidsCbuBOIv4yNv 7Gdj/WySdoKt73ixIn5w27QtbNjkqnAcuGYUSd7MYfvn1uijRYRbVj2wW0fet/nGI/1c 6IEv5TdQofZDklWHbhStms+NUAc9U6ovoRQsXxzNxzyEKk91fHGg0k1gEJHn9EgBhvHZ eWM9R8XZYY+cWwoV1C3FxtYtONvswwJaBJxVePjFtzY517IJXWnXTvsI/r4yYfwaZxM2 0rLA== X-Forwarded-Encrypted: i=1; AJvYcCWmbVrTyBsYptkuQ679dxAwCXbpNgR9chEgIfA/QggrH63eiRkFEfiYro5+n7+uXDgk4qzGBSS0Fi6g8kXPqT+gPRKOQlzsmY0h0tyX X-Gm-Message-State: AOJu0Yz8XXPMa3tpP+y9KgWdq5IPb8p9CuR0eAsyDioMC2pp3EzJQId/ QIBFrtCjYPRUm8BO8AUgI8x51EH5FWvQWHu5eKrBpnF9fQK1Lt2JRajo8nA7 X-Received: by 2002:a17:90a:f305:b0:2a0:3813:773b with SMTP id ca5-20020a17090af30500b002a03813773bmr10706507pjb.9.1711506948866; Tue, 26 Mar 2024 19:35:48 -0700 (PDT) Received: from wedsonaf-dev.home.lan ([189.124.190.154]) by smtp.googlemail.com with ESMTPSA id l20-20020a17090a409400b0029b2e5bc1b9sm347441pjg.23.2024.03.26.19.35.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 19:35:48 -0700 (PDT) From: Wedson Almeida Filho To: rust-for-linux@vger.kernel.org Cc: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , linux-kernel@vger.kernel.org, Wedson Almeida Filho Subject: [PATCH v2 00/10] Allocation APIs Date: Tue, 26 Mar 2024 23:35:21 -0300 Message-Id: <20240327023531.187880-1-wedsonaf@gmail.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Wedson Almeida Filho Revamp how we use the `alloc` crate. We currently have a fork of the crate with changes to `Vec`; other changes have been upstreamed (to the Rust project). This series removes the fork and exposes all the functionality as extension traits. Additionally, it also introduces allocation flag parameters to all functions that may result in allocations (e.g., `Box::new`, `Arc::new`, `Vec::push`, etc.) without the `try_` prefix -- the names are available because we build `alloc` with `no_global_oom_handling`. Lastly, the series also removes our reliance on the `allocator_api` unstable feature. Long term, we still want to make such functionality available in upstream Rust, but this allows us to make progress now and reduces our maintainance burden. In summary: 1. Removes `alloc` fork 2. Removes use of `allocator_api` unstable feature 3. Introduces flags (e.g., GFP_KERNEL, GFP_ATOMIC) when allocating --- Changes in v2: - Updated description of `alloc` crate. - Renamed vecext and boxext modules to vec_ext and box_ext. - Added derive directive to `AllocError`. - Updated safety comment in `BoxExt::new`. - Updated `VecExt::push` and `VecExt::extend_from_slice` to use `spare_capacity_mut` - Add directive to not compile `destructure` and `rebuild` in when `test` or `testlib` are configured. Otherwise we have a warning because `push` and `extend_from_slice` don't use them anymore. - Updated indentation in `Arc::new_uninit` - Moved the removal of `TryReserveError` convesion to `Error` to patch 7, where usage of `TryReserveError` is actually removed. - Link to v1: https://lore.kernel.org/rust-for-linux/20240325195418.166013-1-wedsonaf@gmail.com/T/#t Wedson Almeida Filho (10): rust: kernel: move `allocator` module under `alloc` rust: alloc: introduce the `VecExt` trait kbuild: use the upstream `alloc` crate rust: alloc: remove our fork of the `alloc` crate rust: alloc: introduce allocation flags rust: alloc: introduce the `BoxExt` trait rust: alloc: update `VecExt` to take allocation flags rust: sync: update `Arc` and `UniqueArc` to take allocation flags rust: init: update `init` module to take allocation flags rust: kernel: remove usage of `allocator_api` unstable feature rust/Makefile | 16 +- rust/alloc/README.md | 36 - rust/alloc/alloc.rs | 452 ---- rust/alloc/boxed.rs | 2463 ----------------- rust/alloc/collections/mod.rs | 160 -- rust/alloc/lib.rs | 288 -- rust/alloc/raw_vec.rs | 611 ----- rust/alloc/slice.rs | 890 ------- rust/alloc/vec/drain.rs | 255 -- rust/alloc/vec/extract_if.rs | 115 - rust/alloc/vec/into_iter.rs | 454 ---- rust/alloc/vec/is_zero.rs | 204 -- rust/alloc/vec/mod.rs | 3683 -------------------------- rust/alloc/vec/partial_eq.rs | 49 - rust/alloc/vec/set_len_on_drop.rs | 35 - rust/alloc/vec/spec_extend.rs | 119 - rust/bindings/bindings_helper.h | 3 + rust/kernel/alloc.rs | 69 + rust/kernel/{ => alloc}/allocator.rs | 6 +- rust/kernel/alloc/box_ext.rs | 61 + rust/kernel/alloc/vec_ext.rs | 124 + rust/kernel/error.rs | 13 +- rust/kernel/init.rs | 57 +- rust/kernel/lib.rs | 5 +- rust/kernel/prelude.rs | 2 + rust/kernel/str.rs | 6 +- rust/kernel/sync/arc.rs | 50 +- rust/kernel/sync/condvar.rs | 2 +- rust/kernel/sync/lock/mutex.rs | 2 +- rust/kernel/sync/lock/spinlock.rs | 2 +- rust/kernel/types.rs | 4 +- rust/kernel/workqueue.rs | 14 +- samples/rust/rust_minimal.rs | 6 +- samples/rust/rust_print.rs | 4 +- scripts/generate_rust_analyzer.py | 2 +- 35 files changed, 349 insertions(+), 9913 deletions(-) delete mode 100644 rust/alloc/README.md delete mode 100644 rust/alloc/alloc.rs delete mode 100644 rust/alloc/boxed.rs delete mode 100644 rust/alloc/collections/mod.rs delete mode 100644 rust/alloc/lib.rs delete mode 100644 rust/alloc/raw_vec.rs delete mode 100644 rust/alloc/slice.rs delete mode 100644 rust/alloc/vec/drain.rs delete mode 100644 rust/alloc/vec/extract_if.rs delete mode 100644 rust/alloc/vec/into_iter.rs delete mode 100644 rust/alloc/vec/is_zero.rs delete mode 100644 rust/alloc/vec/mod.rs delete mode 100644 rust/alloc/vec/partial_eq.rs delete mode 100644 rust/alloc/vec/set_len_on_drop.rs delete mode 100644 rust/alloc/vec/spec_extend.rs create mode 100644 rust/kernel/alloc.rs rename rust/kernel/{ => alloc}/allocator.rs (96%) create mode 100644 rust/kernel/alloc/box_ext.rs create mode 100644 rust/kernel/alloc/vec_ext.rs base-commit: 768409cff6cc89fe1194da880537a09857b6e4db -- 2.34.1