From patchwork Tue Jan 7 19:25:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Xavier X-Patchwork-Id: 13929536 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C772EE77198 for ; Tue, 7 Jan 2025 19:25:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5AFC76B0089; Tue, 7 Jan 2025 14:25:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 55F6A6B008A; Tue, 7 Jan 2025 14:25:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 427276B008C; Tue, 7 Jan 2025 14:25:58 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 22A526B0089 for ; Tue, 7 Jan 2025 14:25:58 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id C9BBFC0C3A for ; Tue, 7 Jan 2025 19:25:57 +0000 (UTC) X-FDA: 82981635954.09.B4EE449 Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) by imf28.hostedemail.com (Postfix) with ESMTP id D45A4C0012 for ; Tue, 7 Jan 2025 19:25:55 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=CCbRxjQ4; spf=pass (imf28.hostedemail.com: domain of felipeaggger@gmail.com designates 209.85.216.50 as permitted sender) smtp.mailfrom=felipeaggger@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736277955; a=rsa-sha256; cv=none; b=L9KwBrChFqzdnGa8bGNVwdZTXaLBguVLvFK8JY/BbXcXqgvxD0crOVc7+uuY7YNPqVNtJ4 RpuI4pEsYAQXfgHGzDS4XFEpUWFgkDOec7bi7b+pu+DuerESK7jSj8i1Tq9aFZKmdmlpub VqrpWE2MDkZnZMpvJmQ9k9wQVyL98g8= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=CCbRxjQ4; spf=pass (imf28.hostedemail.com: domain of felipeaggger@gmail.com designates 209.85.216.50 as permitted sender) smtp.mailfrom=felipeaggger@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736277955; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=unsOP1LTIRQtPtFksLGg0xqqMMd0uoUu0hBUdGxfdW4=; b=gCRNgit1pdSV5n8lpMnH7OecUTu6/i7UwFd/bEI6q35dXOrIJlT+2d3vaWifs28+1fe+YB 7Or9JUinAUEoIUmMZK/+K08JqK2yqJZLXz8DWFZevzm07JvRbz03fOBCPwdgO8VUf8PIUz Hl65FtzoEObFXDqJ+BbJL5Ubsh3IWqk= Received: by mail-pj1-f50.google.com with SMTP id 98e67ed59e1d1-2ef89dbd8eeso17349454a91.0 for ; Tue, 07 Jan 2025 11:25:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736277954; x=1736882754; darn=kvack.org; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=unsOP1LTIRQtPtFksLGg0xqqMMd0uoUu0hBUdGxfdW4=; b=CCbRxjQ4hRxP9ZjFZfT8AY4xkosdz1PkIcTZQwqfp6Pl8TVYvn1C0HmFZioaSzspt8 dauIkYT0XeialYJdcrD7carirIEVI+IkyURR2mQbADUS/lIxLMWpnf5qsOo2VBwgxQEr l6PBhRTeVHcfahmKEUB+uhcSudzlFM2mq2zIYjNyd47ldeIoMmSLc2bjDpQD/kdKyA9t +nkyPlNAnup9bWJ59ylRESqg8PTJ22C5Xmjj1S2FEmSZSmFvUtWnqYieBneylev6DvYG VYWFUY4a0GMGB6jt5sEX4UhxpMpYGjVQZ+B6hOqg4Yp/MtSgImO1gbXibYjq+n7N1mTF rNfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736277954; x=1736882754; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=unsOP1LTIRQtPtFksLGg0xqqMMd0uoUu0hBUdGxfdW4=; b=MeB9M+gc1zlpiq7EcLJaQPrvrcLctkJoT6/FLb3hohT62L4bAFVy4qN28rSQPZfr9J wym99Yik2akmF5cS0Aik+6SLDT9ca/dr/MVJ2bifK4ciZRXH5P/8YAVTUFc/7vWLl0qL vcjER4pClRHKgW+RSmeOsTVNpCK2NFxKpVUK+eLEuSxSErP2IVsSy5w/tkX+uEt4UWo0 uBvYNbIq2CwlxnHngNICmcueo39YyaliZEeBexddlq/FQ/AYL0iQkqnCPIes6XPKIzVf aW2vHGmgZtvnx3UNQwCWs4WfZHYP3FJjK1bVxQrFqQKjneVGOxuSNjK4T0hKl42NMXp3 R41g== X-Forwarded-Encrypted: i=1; AJvYcCX6qmiXE0hEWBxCEOHg5XArc/iBzdlzofXsmM3/8v7QaVKcAnMSm5cj7gzZKIRUqy7A3vaFqcjGNQ==@kvack.org X-Gm-Message-State: AOJu0YwOjjGKXifWcnoZZky/bArstV6BGrTDwygYV2e6jMA7ktp9NNNK j5KG5+oD9gDfz3fgtnmL36pe9EWIs2uu2DnbvTkh2qNY02XtZ2DJ X-Gm-Gg: ASbGncuIMy1l2sON99UH7t9NSNC1Bjn/PtQXqN+CW714ZhDn9jRl8KPt6Q/lvl0g+As JjX5GIL/J3iUtIx7yzbxZPRut7N0Scu6OFavhCwVKAtt19TGntiOR0kMsli1f1dLZA5N5S93RHC ChXc2dGlK5IcVB4JGMXdJ/qjcFTsjbxZ88XOrLLEGbK9CMndM4RYF8lNl9EHFVkIHSx280/KYLq REikWQmiRcQcaGw6ALYG+af87o5qhsh3TIATTLxGOce2aSxbhwq5zCWj5khvLAT X-Google-Smtp-Source: AGHT+IEqQLD06XC797Et0O8P0YnnpNcnaA3E9h169RfRG/a+WQ00x3BmgYSZ1cRkSl6yCnZ/Rs7Ikg== X-Received: by 2002:a17:90b:270d:b0:2ef:31a9:95c6 with SMTP id 98e67ed59e1d1-2f548ebf526mr95047a91.14.1736277954451; Tue, 07 Jan 2025 11:25:54 -0800 (PST) Received: from fedora.local ([2804:d57:4e50:a700:a12d:2a91:966f:2aae]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-219dc9f6967sm312431175ad.214.2025.01.07.11.25.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jan 2025 11:25:54 -0800 (PST) From: Filipe Xavier Date: Tue, 07 Jan 2025 16:25:39 -0300 Subject: [PATCH v2] rust: generalize userSliceReader to support any Vec MIME-Version: 1.0 Message-Id: <20250107-gen-userslice-readall-alloc-v2-1-d7fe4d19241a@gmail.com> X-B4-Tracking: v=1; b=H4sIALJ/fWcC/5XOPQ7CMAwF4KtUmQlqnCYNTNwDMaSO00bqD0qgA qHenZQJMdHBw7Pkz+/FEsVAiR2LF4s0hxSmMQfYFQw7O7bEg8uZQQmVAADe0sjv+Sj1AYlHss7 2Pc8zITdldUCtDWlFLAvXSD48Pvr5knMX0m2Kz8+zWazb/9xZcMEbqwAroywZf2oHG/o9TsP65 n8DVd3UrjrU4MsvY+02w4Y+kK3ao7GlVISefi25wZLZkqQb4bSTDt23tSzLG0r2RpOiAQAA X-Change-ID: 20241222-gen-userslice-readall-alloc-8049c668e65e To: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Andrew Morton Cc: rust-for-linux@vger.kernel.org, linux-mm@kvack.org, Filipe Xavier , Filipe Xavier X-Mailer: b4 0.14.2 X-Rspamd-Queue-Id: D45A4C0012 X-Stat-Signature: phdkpixrcincqb9focezu6hor6i14m4u X-Rspam-User: X-Rspamd-Server: rspam09 X-HE-Tag: 1736277955-142075 X-HE-Meta: U2FsdGVkX1/soMUV2+9lTh/fEwai6/IRuPw75qp3ZezhHDCmhtXfkwInSGfJ1gwMZHpmvoY5e80PADFDWFlqPs2gpUVBiTw83N7HU+1+EtU7hjae24QRl2qCveQPP2O6UDZm1mUoBN+hfmFs32bdsmnpiAUqPbHTdeWvjqvIhAABw0CpXjgRorGrNCzd15154a64BhRy5v+x5cAiBw5vtYRWeJ4SoQ5TTjgYSop1d6O4NBjl47ABmLCbo2JNV1QiJtwWvQI8FGuyPXD1m4DEpjlsZYlwNqoGvt9QoDapk/T2hdttXwvsVnqAkJVr7zvMzTqH/ucnAX0pTAKxS837S9eM3vkRlbAPA1iUJ13jgM5X5cDf0O39TnyVR//mPtNdiUlvli315fIW5Gxg9dVYgsAlIlIYxFuvudiiIix/tkbLhIRId9asQes5QxOEJxujY2v7E0YjO7gU1saiaqJ8iHHSqlnHECSEQSEy4T8npJVFc5U/LgEVlmpBWVFYlPGMcsfKWYQHqW9th/uEIEvCs1UdP+Ui5PefOKtxxwi8JkpCB+LFMTZq4RQ9d2L+aNDrXw5m7ECxL6esWxXroqGFamSnPxN/XYiZM4TZytL8jovTq8vFLtMK4mZhSGQbFxibOWfKAjJc6Ql6WiNuGLoEq4YjHOkwMEZnzs0VAhk7k3qbsG/Pz/WzG2DCqaTCNX8PD3h58njz/GKRFLZzVn2g4phob+p+WTCfhTOnkFWZfhdmBBTvesiy/K2UPyH8+4r+Xjd/iNq7UC9Ob4DiXecCbTlxnj9T/WscVWcx8E5Kb0Uy2gXUcDeAHkICHSj8lOxauzskgesZSQnBhbb1HJcNTgfIvf1VSF54LSsrw+Sz5fAmadZaGFhJXbi6y5cj3pYzwWsA418DwCjVd2ZRRYVBdhJJjZboe2xLDwRTOXMqJomLsLo64xOmYbNlY9N7EhLxLe1RMH4H2Hommw1nb4R g3JwlMLs zijOCccsqqPgvqfIrThfe+S/GIEu9FEUkwQwIDTZrBJRtIp7v8fwHrAOeBAsdfYjuXKxm5TN3cDV4erTIRUSpV5mJ5Xa0aBnSgJ3LHCFtla3Bemp+ffiR9xTxozjAJwZCET+XJPQZtkwxjAi7SqAHk/2cGfJAwLd6l+62v9XQuj3nQfUsFvC/gqAjy17I7FqAv/Y32+RTrpABT6i8HSkieNly6uO8w9gz40m9ugFpoqz2gCUw4VDHulRrzqL/gaE2wVHPEVzGaXuzYuKP/M6pH0+uw3Sa/zMYAlmoQOPBqhJTtJ2RJfI3uss71qopRCgGYe/wZTOQ9MAG823ejixsNm7mg/h8tzdrh6VCAaGpv4/ajTAozjnpzyrssBnKsDmZqD00VxhgUrY3fC0HNgF50NqyCZ5JCv8HPIGsd+UGr7km7ZuRv7rVCvEy9TN1aM+1OiMSrEv1Bchb+5+g+kjZxVg7b8SfElfMVw+mc6PxKa/VgaNZZrbLLzzjKMrqUnIe7hJa X-Bogosity: Unsure, tests=bogofilter, spamicity=0.499999, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The UserSliceReader::read_all function is currently restricted to use only Vec with the kmalloc allocator. However, there is no reason for this limitation. This patch generalizes the function to accept any Vec regardless of the allocator used. There's a use-case for a KVVec in Binder to avoid maximum sizes for a certain array. Link: https://github.com/Rust-for-Linux/linux/issues/1136 Signed-off-by: Filipe Xavier Reviewed-by: Alice Ryhl Reviewed-by: Boqun Feng --- Changes in v2: - Commit description: added use case on description and send to memorymanagment on copy. - Link to v1: https://lore.kernel.org/r/20241222-gen-userslice-readall-alloc-v1-1-c57b7d4972f0@gmail.com --- rust/kernel/uaccess.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- base-commit: 0c5928deada15a8d075516e6e0d9ee19011bb000 change-id: 20241222-gen-userslice-readall-alloc-8049c668e65e Best regards, diff --git a/rust/kernel/uaccess.rs b/rust/kernel/uaccess.rs index cc044924867b89f6116c7f9ec216d8cea2b3f8d7..719b0a48ff5550acc19f2e607c0a09f818145def 100644 --- a/rust/kernel/uaccess.rs +++ b/rust/kernel/uaccess.rs @@ -5,7 +5,7 @@ //! C header: [`include/linux/uaccess.h`](srctree/include/linux/uaccess.h) use crate::{ - alloc::Flags, + alloc::{Allocator, Flags}, bindings, error::Result, ffi::c_void, @@ -127,7 +127,7 @@ pub fn new(ptr: UserPtr, length: usize) -> Self { /// Reads the entirety of the user slice, appending it to the end of the provided buffer. /// /// Fails with [`EFAULT`] if the read happens on a bad address. - pub fn read_all(self, buf: &mut KVec, flags: Flags) -> Result { + pub fn read_all(self, buf: &mut Vec, flags: Flags) -> Result { self.reader().read_all(buf, flags) } @@ -281,7 +281,7 @@ pub fn read(&mut self) -> Result { /// Reads the entirety of the user slice, appending it to the end of the provided buffer. /// /// Fails with [`EFAULT`] if the read happens on a bad address. - pub fn read_all(mut self, buf: &mut KVec, flags: Flags) -> Result { + pub fn read_all(mut self, buf: &mut Vec, flags: Flags) -> Result { let len = self.length; buf.reserve(len, flags)?;