Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp689320rwo; Wed, 2 Aug 2023 02:33:04 -0700 (PDT) X-Google-Smtp-Source: APBJJlFoqBEMJv3sxYTRDYEWxz1WF/P19WnHJmIA7m4N9YuBwicbM7SZXESTI16RuE8lyWa4z66v X-Received: by 2002:a05:6358:419b:b0:134:ce45:b782 with SMTP id w27-20020a056358419b00b00134ce45b782mr6189549rwc.21.1690968784171; Wed, 02 Aug 2023 02:33:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690968784; cv=none; d=google.com; s=arc-20160816; b=08nK/bJ121kHgxeeNwmQAQ6ELxykBYV74L08ncw0MPVG63Ukw/XxnJTxGSNe9Zbue1 3B7JWutOzXz8LIsAQP5swI+SgR1PkVTSnD9Ivpco9oPDSOu/f9XAdO9gWHhEk4NaDKbe dcVp8Z9TmHDQpjAYbDIxoLfV1zrpBBHsHicx1x5OafAwO4MVapkeRETmgbk26xBJxzzM on4PilzYcly/Dr+cLT6Fr+qHuHV2+s7OW7Gf3Iz36unn7udhygyDaWNkvbCdss12T2nc OeFSCeVhp4TPpRNOxNofBEHtGlEm1pIScjwanfBH6qaeYNJIC5KI2v7T+74JGLqZl2nO j+xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=hTlYTUXYUY0uT5dVegExxW34rudjU0yRbAqg9Bg5Z/A=; fh=UdJdH4vQKxS+5XnCtFg9l5sh/DROdYaOMN3nYQryBK0=; b=Zy4hA1kP/mtAyg6uyniUw+fKK4F1+zEyt74p9Ue2+SduSVvqao5BPZhJsnXVDJQ7/6 9/h7His77OLDQVIOPpLiCXBGvto38BERbH529vvUCzp0oIKrcPkBrexAipTiRIrCiYMH lcb4I6SBiQWz3zgrcBHCe53utxBE7yzjErbsVhdK4iOs8eyBVTXIU6IjmmThNqrIDN37 7/PLxKuBLak2VNYAxsYjKseyGWaNkLmMZiG2pgTntg7l0iYfIapNkMzICIFEH6AgGBnW 2EHxOwSivdMCE/2ReOxO1sygmvnbyXSfrZWxIgWXH4+TeToMp3Z5DkC46s8Yl4fmmt3T 1d4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@umich.edu header.s=google-2016-06-03 header.b=jt1i3UyG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=umich.edu Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r30-20020a63fc5e000000b0055337ca9ce9si3537151pgk.248.2023.08.02.02.32.51; Wed, 02 Aug 2023 02:33:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@umich.edu header.s=google-2016-06-03 header.b=jt1i3UyG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=umich.edu Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229694AbjHBHqW (ORCPT + 99 others); Wed, 2 Aug 2023 03:46:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233451AbjHBHp5 (ORCPT ); Wed, 2 Aug 2023 03:45:57 -0400 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD2E144B9 for ; Wed, 2 Aug 2023 00:43:29 -0700 (PDT) Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-99bd1d0cf2fso984777266b.3 for ; Wed, 02 Aug 2023 00:43:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=umich.edu; s=google-2016-06-03; t=1690962208; x=1691567008; 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=hTlYTUXYUY0uT5dVegExxW34rudjU0yRbAqg9Bg5Z/A=; b=jt1i3UyGg5T8VU7eoMf85nHf6pgJoeHFxp53BuGY+DiO76l/fHQrsYT4K/fJuRnm8S dVrV+pGSUvLjAqkp3PYAwaLppgWCK35UNVv/OPwqrcST2L5PLWvqp1OODp/KoipUp82s uZz82tOu/a1sIslbBKKYqVERgHoB4bXvh+LzeySCN45nzw2PoFcfx5mxgug/LDd9e52Y ZHgmGKpJNcQyHY3eddpYCexB8rEhuNvI+ula63l8RraTy1lcP2qhtPEVcgIwTuPSlbcN B42wWafgVMfjIK/+22+omr2Qn2GQI6MuK4qBSBPIvIrmK4tUQS4C+AYDh8mGKztFeBd5 qcPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690962208; x=1691567008; 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=hTlYTUXYUY0uT5dVegExxW34rudjU0yRbAqg9Bg5Z/A=; b=g+8bi281FxYPnLhcURtWD9Au7LahkAkSIY/rBebBbTe9Yt9ZdFjQl0XBy5IwEzssZD VQDZLKOm04k4yFWOgZjxrdX1GyrpEUbDKVCT8MMzEHzfgcRBcJbUJaMxZWCT7BqF0Hza gfLWkIgbFzIWysuSU9D6lZVyrpJ92l2gyVikiyuUB9agqG4eG9Tqdgs+18N9Oy+sV22J lHs8JcSgEb4GBCmwix0iGPXIv3RoZdQKMKVlIcVxNgPq9RFBU5eThQCa2QtdVDzgsluO 3RReGw49vbtUagLgZIyjd65HLz3o2LxkW9YpyyAfuJ9ue6kOFjS1D4O2d1kt7Y9iWhCD N7ng== X-Gm-Message-State: ABy/qLbU7BhgyHQ93Xcmd/KwSshty6XeAwfGdTch3QCpX7WpPNQXfsj0 0W6jKw80x7qTnRBFM7oACGkL+JUqqcy1sCnAesGSgQ== X-Received: by 2002:a17:907:77ce:b0:992:a9c3:244f with SMTP id kz14-20020a17090777ce00b00992a9c3244fmr3991552ejc.4.1690962207821; Wed, 02 Aug 2023 00:43:27 -0700 (PDT) MIME-Version: 1.0 References: <20230729220317.416771-1-ojeda@kernel.org> In-Reply-To: <20230729220317.416771-1-ojeda@kernel.org> From: Trevor Gross Date: Wed, 2 Aug 2023 03:43:16 -0400 Message-ID: Subject: Re: [PATCH 1/2] rust: upgrade to Rust 1.71.0 To: Miguel Ojeda Cc: Wedson Almeida Filho , Alex Gaynor , Boqun Feng , Gary Guo , =?UTF-8?Q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Andreas Hindborg , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Jul 29, 2023 at 6:05=E2=80=AFPM Miguel Ojeda wro= te: > > This is the second upgrade to the Rust toolchain, from 1.68.2 to 1.71.0 > (i.e. the latest). > > See the upgrade policy [1] and the comments on the first upgrade in > commit 3ed03f4da06e ("rust: upgrade to Rust 1.68.2"). > > # Unstable features > > No unstable features (that we use) were stabilized. > > Therefore, the only unstable feature allowed to be used outside > the `kernel` crate is still `new_uninit`, though other code to be > upstreamed may increase the list. > > Please see [2] for details. > > # Required changes > > For the upgrade, this patch requires the following changes: > > - Removal of the `__rust_*` allocator functions, together with > the addition of the `__rust_no_alloc_shim_is_unstable` static. > See [3] for details. > > - Some more compiler builtins added due to `::midpoint()` > that got added in Rust 1.71 [4]. > > # `alloc` upgrade and reviewing > > The vast majority of changes are due to our `alloc` fork being upgraded > at once. > > There are two kinds of changes to be aware of: the ones coming from > upstream, which we should follow as closely as possible, and the updates > needed in our added fallible APIs to keep them matching the newer > infallible APIs coming from upstream. > > Instead of taking a look at the diff of this patch, an alternative > approach is reviewing a diff of the changes between upstream `alloc` and > the kernel's. This allows to easily inspect the kernel additions only, > especially to check if the fallible methods we already have still match > the infallible ones in the new version coming from upstream. > > Another approach is reviewing the changes introduced in the additions in > the kernel fork between the two versions. This is useful to spot > potentially unintended changes to our additions. > > To apply these approaches, one may follow steps similar to the following > to generate a pair of patches that show the differences between upstream > Rust and the kernel (for the subset of `alloc` we use) before and after > applying this patch: > > # Get the difference with respect to the old version. > git -C rust checkout $(linux/scripts/min-tool-version.sh rustc) > git -C linux ls-tree -r --name-only HEAD -- rust/alloc | > cut -d/ -f3- | > grep -Fv README.md | > xargs -IPATH cp rust/library/alloc/src/PATH linux/rust/alloc/PATH > git -C linux diff --patch-with-stat --summary -R > old.patch > git -C linux restore rust/alloc > > # Apply this patch. > git -C linux am rust-upgrade.patch > > # Get the difference with respect to the new version. > git -C rust checkout $(linux/scripts/min-tool-version.sh rustc) > git -C linux ls-tree -r --name-only HEAD -- rust/alloc | > cut -d/ -f3- | > grep -Fv README.md | > xargs -IPATH cp rust/library/alloc/src/PATH linux/rust/alloc/PATH > git -C linux diff --patch-with-stat --summary -R > new.patch > git -C linux restore rust/alloc > > Now one may check the `new.patch` to take a look at the additions (first > approach) or at the difference between those two patches (second > approach). For the latter, a side-by-side tool is recommended. > > Link: https://rust-for-linux.com/rust-version-policy [1] > Link: https://github.com/Rust-for-Linux/linux/issues/2 [2] > Link: https://github.com/rust-lang/rust/pull/86844 [3] > Link: https://github.com/rust-lang/rust/pull/92048 [4] > Signed-off-by: Miguel Ojeda > [...] Reviewed-by: Trevor Gross A few highlights since 1.68.2 that may eventually be of use: - `CStr::is_empty` and `CStr::from_bytes_until_nul` help smooth FFI a bit - `NonNull::slice_from_raw_parts` for slice pointers - `AtomicX::as_ptr` makes interop with C more clear (doesn't seem like we use these types anywhere yet) - const `ptr::read` and `ptr::read_unaligned` - `{Option, Result}::is_some_and` - `core::cell::OnceCell` one-time initialization - `repr(C)` enums now use `c_int` rather than always `i32` (no difference f= or currently supported targets)