Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp2282927rdb; Mon, 5 Feb 2024 01:18:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IEE53iY9Eb5EWks535KT8Y/F395oVsIyntpic52rqJ9Zgka5P3sTMTHCUeZ9IGQaaYMlYEJ X-Received: by 2002:a17:906:3189:b0:a37:20d4:22be with SMTP id 9-20020a170906318900b00a3720d422bemr4861072ejy.49.1707124738867; Mon, 05 Feb 2024 01:18:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707124738; cv=pass; d=google.com; s=arc-20160816; b=fEOhV+fz2BaskraiIutwKBDkO7NQWEd4sc+fuI39H8yaMHwDtndVatEs7Sl19YjRMq 3wg3OD9OzSf6X2y7Mz/CYXC5jZ7gYqKfPaFm98g8BtmDEZilp05cBAtkCoIQtV4AzyNd KF9sbFNGVpb/yYPSCiFUoUa5dw6apvUKW+HXb3LjCSeGKLklpag836FgkKlGwpY4QY+8 aYi/d8c+uPmgxj6+ful2sSspAcAgqxI/jzddYoFbriI5mbsnI6fQ3L5wK0MvU4iboQn8 z4r3POlVsd1SaQ/AvjXQGplGcfQ3kIqgBEsCqmMk6iaEQT2ywmQrqtxwxlsbOkDy1S76 R+RQ== 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=7Gxk2ajCeRlR024TKzSLzvly8WJN2T7k2cWPUi6bXG0=; fh=BEWCLSzQUFV4IsRDUqMVucuHPMmZadLws0eFLUFpINU=; b=KwWiiq47+wJoXN8ZhgaJX5q0kimepcbXrrcsCuAgP8/791gfEQ5bo8N2NmVp08pxiA KGN2VOCCURZ9Xe1cemUmN8RGy+RX4iLAmGiPSA61nYGsR+ZWmuZFW3j5P38Stfthn+gw grpa5KkYNjf+ggpbAifDumlEPfvnGvKacR9LkFfn91POA+JOH8kz1g2xkGyDXc+KsTaF HC0ZU/Ht53do3CS2GsQGnI4UTnihQ8+QwW3PkZElLJGtytkjzksPERi4YzwxwZenN96L mpajqL+h4IrkrKR2/ur/eRwV5lAur8/ER6JJOgb1or+r5FcdV0o3fbh54L28hKHeCY3D 3nGA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ok6j71GH; 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-52280-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-52280-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=1; AJvYcCXbn6J0SUuCZrb3hOen0Rp8Mint2PQAIbRdtRAjv8rRm29PFQpagSV+5vNTXhgmeIJVh0wpm6m6YMkhSyAUfz0qhaBg2orVoUX41YpG2g== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id kj27-20020a170907765b00b00a3554080d78si3593004ejc.220.2024.02.05.01.18.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 01:18:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-52280-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ok6j71GH; 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-52280-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-52280-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 719D91F215CA for ; Mon, 5 Feb 2024 09:18:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2D6E5125C2; Mon, 5 Feb 2024 09:18:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ok6j71GH" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (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 B84E7125A1 for ; Mon, 5 Feb 2024 09:18:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707124729; cv=none; b=C6fWd2U2zodQVdvRB8+DzA0/F/OmXd9UGXaITgVMf/4J9yqfXGcdUcOXhg5O38SM/5ZWbdZmbIcPFIqXs3xlQNU7p8hgSCQ0bYMiSeb8qWLXSOih0fDbEU6+fI2p23X4LwxGGD4e7H12iNwVSMONkZFVr3SvicqOsMhLrmsy12U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707124729; c=relaxed/simple; bh=8XZJ/IgL1JMzY5lgcFPKVTKdQYsXG/HJaPx+Ik6gB94=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=eK68i/+i49J9VmBCTIrLGpirusln4R1ff0VfJPSZUKKIgj8iJ6cLFIP0GxD1t1GWCQD3vJbuHi+oBSIVXAUQCG0AuviR3SKdSqfhMRk1Pk/Yq+33/gtpa7mmcl1UQ/6qIH8cNcimoTRjoiWJF1SI7zg8Yv6rWWlS7wOwtoe7YCY= 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=ok6j71GH; arc=none smtp.client-ip=209.85.219.201 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-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc7165d7ca3so612634276.2 for ; Mon, 05 Feb 2024 01:18:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707124726; x=1707729526; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=7Gxk2ajCeRlR024TKzSLzvly8WJN2T7k2cWPUi6bXG0=; b=ok6j71GHOBJYAAjH1mmtEmSRXRP5Eqdbvk1SDKKjq+5+TDCHhCoVLfUqAe0+pvH/+3 MKOqQwJHgqrjM4ZW+gLKhlczv/Oa5LieCkBIraAPtLkn122YzL7p97Fh0jCjoLNeYlZB rpMyt7wDiHYiBPaZhZ08F4YUoB0K+MuBRRdlQjD2xUckwCI1V2uoBPrcwsxhr5EDQkT5 AgBfzc6k8PVVij1fkWbIJVk6eaESAEwapZT77fwIwDDaxeBjZOzhn+6qZq4j6/SPqTBM hjuWaFdMpAor0egUgqrkdzJFQ9LM9myHuUzXGm/fxC4scmUhpBCv4bI5dFXt3W8KasLV XFFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707124726; x=1707729526; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=7Gxk2ajCeRlR024TKzSLzvly8WJN2T7k2cWPUi6bXG0=; b=LMDS+dslb8LauyC8tz8xSwHvMu9oXJWTk/uhozyPbK3jqabzQqwVD1KFLHneXDuQ63 j62dhb7g5CTeeAQqGwckwKg7Rn2XJtfPsyQqEgVpFnfS99kuQQSYARSAbf/Ic8fxYUrT YpK6POr7Hu8ZXexGw8gtYY7wt9cSw4iwXyonv1P5c1gga92d3zdA/0ttAUHsEA9t0aqe QTeZsYex9VgU6BaauScOU1D+EDj+VxGoFrcLQ6wjcK7OCGuA4wkG8hTsKoXYs3dpuMBP NZwdmut9yeQY6040/5O6DdmVZWtIYVzRgm0GYKlmhRVq4MUA2S3Ibo3WWJLcrZarvB74 1tyQ== X-Gm-Message-State: AOJu0Ywa7SwNCS/cdXGH94Etjl9yfhlBjs1g6eunFf5716bro3BjPPtz CsNzQje/OsFUH6Rn/IIlFYG0t7GZqhdQ3TzO6rg/PY+2aIfX4d0WtpEYWBfTVOa8T4/RXiG0CNU 2ZtGaRH/4Ht46rQ== X-Received: from aliceryhl2.c.googlers.com ([fda3:e722:ac3:cc00:68:949d:c0a8:572]) (user=aliceryhl job=sendgmr) by 2002:a05:6902:cc9:b0:dc2:57c9:b44d with SMTP id cq9-20020a0569020cc900b00dc257c9b44dmr534896ybb.8.1707124726693; Mon, 05 Feb 2024 01:18:46 -0800 (PST) Date: Mon, 5 Feb 2024 09:18:42 +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=2746; i=aliceryhl@google.com; h=from:subject; bh=8XZJ/IgL1JMzY5lgcFPKVTKdQYsXG/HJaPx+Ik6gB94=; b=owEBbQKS/ZANAwAKAQRYvu5YxjlGAcsmYgBlwKei/WJXwNa1kGveDERZkE/7Gq9ywL3f6UUFi yDyixhV/tCJAjMEAAEKAB0WIQSDkqKUTWQHCvFIvbIEWL7uWMY5RgUCZcCnogAKCRAEWL7uWMY5 RqTMD/9zwprbrEKhYMbbQgpYaTRFzdeJBBljXrR0q+elDRZhdzFV1kRDfRBS+VMz5Bu7DYAaPUi xn3o7LZMOwbzRwsbBCjZLYwcAIXQIFe/HDaioHdWcqeLgDPIYws1cpxydVGHh7bxU0tpSePWvwC QXYEQtvH2jI4Qc2CRa1RnspuEAF+YJIMbJobmiKv7XzE2gWu2RAOFvmeu5aIlF3fvZE8M8t/GhM 4yHziaSlbBLNVRIR51Cv04j32kOKtJcDYeiZ3eRTEY7NiSm6Edj4BPDUqMOBVMlomcFMM1+E8uQ cLsQghCvtFkcf8nkENTifcr9jLP/X5dt5FlsuYA61LElfJGJ9pXWm9ARSgb1+0YMxggz9wlsCbH JWCs3tr8P6fepJZ891HfxlYQDYtRcqV2EH5G4jY0qY+95Zgpk4bvHbnM0IMPHcjF+bm/5vj2RRQ 78ZzUZaXUi9XHqXyOTznrmjCItWCIabNbUHItLYW194R/Gog4gwwuRVii+YUXdSnAkZskS0tG33 nK+1fwSqy2DvSGfFS/cel4+NZsBsLvLCw/X5I56FrPeC8+X+/TQWBUf9naMXzQYz+9OGSQmC4CN gCP+FGu7KKvoZusZZA06xwn2V0K/xX97XT3Gdc9xyg6YaXxWR9TimpHhi4SgoPxkyFSRgN8I11B jPnV3IRbPAUNi6w== X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog Message-ID: <20240205091842.2858516-1-aliceryhl@google.com> Subject: [PATCH] rust: stop using ptr_metadata feature From: Alice Ryhl To: Miguel Ojeda Cc: Wedson Almeida Filho , Alex Gaynor , Boqun Feng , Gary Guo , "=?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?=" , Benno Lossin , Alice Ryhl , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" The `byte_sub` method was stabilized in Rust 1.75.0. By using that method, we no longer need the unstable `ptr_metadata` feature for implementing `Arc::from_raw`. This brings us one step closer towards not using unstable compiler features. Signed-off-by: Alice Ryhl --- This patch is based on rust-next because it depends on the patch [1] that upgrades to Rust 1.75.0. [1]: https://lore.kernel.org/all/20231224172128.271447-1-ojeda@kernel.org/ rust/kernel/lib.rs | 1 - rust/kernel/sync/arc.rs | 10 ++++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs index b89ecf4e97a0..b8d4c8167a29 100644 --- a/rust/kernel/lib.rs +++ b/rust/kernel/lib.rs @@ -17,7 +17,6 @@ #![feature(dispatch_from_dyn)] #![feature(new_uninit)] #![feature(offset_of)] -#![feature(ptr_metadata)] #![feature(receiver_trait)] #![feature(unsize)] diff --git a/rust/kernel/sync/arc.rs b/rust/kernel/sync/arc.rs index 77cdbcf7bd2e..16309c3a9a01 100644 --- a/rust/kernel/sync/arc.rs +++ b/rust/kernel/sync/arc.rs @@ -30,7 +30,7 @@ mem::{ManuallyDrop, MaybeUninit}, ops::{Deref, DerefMut}, pin::Pin, - ptr::{NonNull, Pointee}, + ptr::NonNull, }; use macros::pin_data; @@ -239,18 +239,16 @@ pub unsafe fn from_raw(ptr: *const T) -> Self { // binary, so its layout is not so large that it can trigger arithmetic overflow. let val_offset = unsafe { refcount_layout.extend(val_layout).unwrap_unchecked().1 }; - let metadata: ::Metadata = core::ptr::metadata(ptr); // SAFETY: The metadata of `T` and `ArcInner` is the same because `ArcInner` is a struct // with `T` as its last field. // // This is documented at: // . - let metadata: as Pointee>::Metadata = - unsafe { core::mem::transmute_copy(&metadata) }; + let ptr = ptr as *mut ArcInner; + // SAFETY: The pointer is in-bounds of an allocation both before and after offsetting the // pointer, since it originates from a previous call to `Arc::into_raw` and is still valid. - let ptr = unsafe { (ptr as *mut u8).sub(val_offset) as *mut () }; - let ptr = core::ptr::from_raw_parts_mut(ptr, metadata); + let ptr = unsafe { ptr.byte_sub(val_offset) }; // SAFETY: By the safety requirements we know that `ptr` came from `Arc::into_raw`, so the // reference count held then will be owned by the new `Arc` object. base-commit: f090f0d0eea9666a96702b29bc9a64cbabee85c5 -- 2.43.0.594.gd9cf4e227d-goog