Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp817654lqt; Fri, 19 Apr 2024 11:13:19 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWCJZocO8J9pXgpAtCCHCHezLIYqR1dnZb8VI7TYD58pPunEyk1nEC3ZWkQP4P+S0TwZR+n5KMliXSOIGX8SkUcVbfX6uF43kF41trCeQ== X-Google-Smtp-Source: AGHT+IH6rvCcgz8fh6bcfCF2/mh7MQW3Qc9Om2yMmBOqobeuempIIkiDeKF2PhHOpMNh0o5FgvgH X-Received: by 2002:a17:90a:b10f:b0:2aa:cadb:d290 with SMTP id z15-20020a17090ab10f00b002aacadbd290mr4466276pjq.13.1713550398854; Fri, 19 Apr 2024 11:13:18 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713550398; cv=pass; d=google.com; s=arc-20160816; b=OdYQqj0DtRWh2oy/fPz2voE1stT8szqnwUqaek4W1D1I2vFMIIeUOyDALc2UOVefJB hb6S19mGpd9iCZwR4Y6s2n1qHcXZCWugbxQnhQX6S+zMwDTXeacGdh0SZiv2U+k8DYI0 hodkwMJOZIMP6/iev+0k+pnXvhtJTdopLykFpXPN3jGZpjN2+BD6ZKF09zSO1H8eBg7w 3dPphfUh4ICKvIGeFpre6VoSa+DhzgvNYsXrVqNYnefJabxypBDxig2afru+0Lovhzoe UCi/Z9ZlyzG+c4tyf2rU7G3WDMcOAqXuytLYWW+3M5ci3jzWW4BWiXXHTbqmNEkFWX7K l/qg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=pr4pi+Kny8bbVl+Iz+PAepuZ7kpgc/VuFcgkzz8aTw4=; fh=+efXn21EAV0gqpiMltgZwJF2DxIKc3OeIiIhzs1zePA=; b=sHSJdPpwR9G45ObfiRBTAbA5W27uox+yEGvz6tzf5ZWmbqWhVYiyFlwcJi5UCsDSad xWkEbImv4k57T15zlAVEpqhH398GnySID1gn2oErWKy7hvUdO9LPm/vDqPkd/PL0n3/0 FHykIUhhatu+myIPN5r2YKNUc85U1W08Z4OaZBe4rjPwgb6CiO9b6E5Pts/OC6HsxDRE /p1U+m2OMdQwfh3Q1lk+v/WQ+wpvk1h6VtY36KL36zweyxXmxLO/0SDOTDRhntMfM8tj 2yfXUfWm0MHNvHmu4L6i5mNxIGabEHN4uia+qCsbNvhfGhW5YRJjc0+cqGgh389/O7pT fOWQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=CDhuYTbj; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-151858-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151858-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 f13-20020a170902684d00b001e8dd83996esi1232069pln.180.2024.04.19.11.13.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 11:13:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-151858-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=CDhuYTbj; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-151858-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151858-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 D34E8282CEE for ; Fri, 19 Apr 2024 18:12:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D374413BC0E; Fri, 19 Apr 2024 18:12:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="CDhuYTbj" Received: from mail-vs1-f49.google.com (mail-vs1-f49.google.com [209.85.217.49]) (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 7042B13A871 for ; Fri, 19 Apr 2024 18:12:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.217.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713550358; cv=none; b=YDdIJ1Kw1A6H3EHYoJnnq9/qJLYiEb5Snk38Lf9gWXFUIUbEGP6zQyzFAt7lNhWnHpApGnkkMLqHQJpHfZcU10YQLWqFvLFCrdcRAcGcPGYD1tGzN9wTymR9Wm88hmRBVswwGAQwex9vaiFtDwprxyMaOepidflYpwhtGQQ2PIA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713550358; c=relaxed/simple; bh=5OoEVXRanZ24jLnT2Kd6vCgLBegTb1q/k9NQXr41LEw=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=OIVLRd6V7Gx2EXUTpYYfC1anS2uuZXYJW2ZwSDy0M80mWkBF/fD5iOLBmHxmvusWOvIELT4XicZo6f59/9446dV0N41wXWl4ambmiupArPIhEOEmZFh3Xxwj58T2LQW9wiHMRrE+aSvrcYALL5o/a0GT61uBsuxzVLAxaH9TFcg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=CDhuYTbj; arc=none smtp.client-ip=209.85.217.49 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=google.com Received: by mail-vs1-f49.google.com with SMTP id ada2fe7eead31-479dd0261c8so1486316137.0 for ; Fri, 19 Apr 2024 11:12:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713550356; x=1714155156; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=pr4pi+Kny8bbVl+Iz+PAepuZ7kpgc/VuFcgkzz8aTw4=; b=CDhuYTbj3VMN44oaNXnXxu27FtJXw/vS8mw1ORPB+RdOKvkG6MzSDK1Zf9LSM9bI46 ZrxThK4rGMaaCTZUfKDeEZJJK1HsaKI/+wwEFyXpF+umz6gNkzcZ1aqA9y7zs09QeEDw lefHg3x1vMfrscfG8kz5QsZ8KU4kWSqFOLvqj5Fi+ZdvlqQrwKmHdrHGn6s/a2FJE6vN liFXM0z1xQsNd25NoPAYkWDXD0SoPpCJr5FS+tHm9tPyVUi30nYzRM3VxQN71KFqh+iE 4uBYaTONRyZYQeKOruSS9MystM32a2sq/mtE5KBj7u4igNq+blWNZ0gza/y07v8D0gmt gosA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713550356; x=1714155156; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pr4pi+Kny8bbVl+Iz+PAepuZ7kpgc/VuFcgkzz8aTw4=; b=b8vjQbOc68djA5wvoiEIOqhx9pEhg9xiuirZAPc+WGjH4g98klqvvdZtgnaaEXk2AT j+kJT6qwQNxJxgSiBEag3W+LanEMsIRQhv3Wsa0i1htrMMS+4Y95mfoKQLTLUBrWeVlm J+hT7PBUDbieJXXL97tVwtElhc7NMHiIOMHHL+HtBkVZWbpx6AR4trKmujIbSNVmBscW 44LMyfEbr0hYeOMTE1kNjGdHp0HQ4Pq4iu3n1/xl6/aZLEhtu1P3IDhdB7gkX3KZG4zv A0/dhLkaIvwJx8KF0vEupnEEvpFzUra5l2geuwa+tECUSlPX2hIO3wog7Sb/Tzp4XEqV ay3g== X-Forwarded-Encrypted: i=1; AJvYcCUX/RCE2D3Dmlcc34rmtymOHTsF97TTI47b1hxmvtQdtzd5ya4x9O9NSvSEr9tLtWx1EDJoPu9kGgn9U38YWUVu119uG1HX0x5ZGqTN X-Gm-Message-State: AOJu0Yz2O43tiqpxOjKvUpXTsXi1QgZVNk40BQoTknV9JvOSqFh/sjm5 3ng/cHPjSFpzdr6a4QHfVWpAr9ptVn21bAY6jXmnBDl6X60bPZiCUaWkyBhukFkrWdfmpwst0ZC qclQVtHUh41Za+giBBQBSVY7AgyTcznQIiNyK X-Received: by 2002:a05:6102:2844:b0:47b:5f05:5a57 with SMTP id az4-20020a056102284400b0047b5f055a57mr8647652vsb.16.1713550356213; Fri, 19 Apr 2024 11:12:36 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240418-alice-mm-v6-0-cb8f3e5d688f@google.com> <20240418-alice-mm-v6-1-cb8f3e5d688f@google.com> In-Reply-To: From: Alice Ryhl Date: Fri, 19 Apr 2024 20:12:24 +0200 Message-ID: Subject: Re: [PATCH v6 1/4] rust: uaccess: add userspace pointers To: Boqun Feng Cc: Miguel Ojeda , Matthew Wilcox , Al Viro , Andrew Morton , Kees Cook , Alex Gaynor , Wedson Almeida Filho , Gary Guo , =?UTF-8?Q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Greg Kroah-Hartman , =?UTF-8?B?QXJ2ZSBIasO4bm5ldsOlZw==?= , Todd Kjos , Martijn Coenen , Joel Fernandes , Carlos Llamas , Suren Baghdasaryan , Arnd Bergmann , Trevor Gross , linux-mm@kvack.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, Christian Brauner Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Apr 19, 2024 at 7:11=E2=80=AFPM Boqun Feng w= rote: > > On Thu, Apr 18, 2024 at 08:59:17AM +0000, Alice Ryhl wrote: > [...] > > + /// 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 Vec, flags: Flags) -> Resu= lt { > > + let len =3D self.length; > > + buf.reserve(len, flags)?; > > (Reportedy by Miguel) > > When compile with `make rusttest`, kernel crate is compiled as userspace > program, so we need to explicitly pick where the `reserve` comes from > (Vec or VecExt), the current version will hit the following error: > > error[E0061]: this method takes 1 argument but 2 arguments were s= upplied > --> rust/kernel/uaccess.rs:296:13 > | > 296 | buf.reserve(len, flags)?; > | ^^^^^^^ ------- > | | | > | | unexpected argument of type `Flags= ` > | help: remove the extra argument > | > note: method defined here > --> /home/boqun/linux-rust/rust/test/sysroot/lib/rustlib/src/r= ust/library/alloc/src/vec/mod.rs:910:12 > | > 910 | pub fn reserve(&mut self, additional: usize) { > | ^^^^^^^ > > error[E0277]: the `?` operator can only be applied to values that= implement `Try` > --> rust/kernel/uaccess.rs:296:9 > | > 296 | buf.reserve(len, flags)?; > | ^^^^^^^^^^^^^^^^^^^^^^^^ the `?` operator cannot be= applied to type `()` > | > =3D help: the trait `Try` is not implemented for `()` > > error: aborting due to 2 previous errors > > Some errors have detailed explanations: E0061, E0277. > For more information about an error, try `rustc --explain E0061`. > > and we need to the following fix > > diff --git a/rust/kernel/uaccess.rs b/rust/kernel/uaccess.rs > index 39481e374c40..80f7e7ca2f5e 100644 > --- a/rust/kernel/uaccess.rs > +++ b/rust/kernel/uaccess.rs > @@ -293,7 +293,7 @@ pub fn read(&mut self) -> Result { > /// Fails with `EFAULT` if the read happens on a bad address. > pub fn read_all(mut self, buf: &mut Vec, flags: Flags) -> Result= { > let len =3D self.length; > - buf.reserve(len, flags)?; > + VecExt::::reserve(buf, len, flags)?; > > // The call to `try_reserve` was successful, so the spare capaci= ty is at least `len` bytes > // long. I'm sorry, what? This seems like a problem with `make rusttest`. Alice