From nobody Sun Feb 8 07:25:14 2026 Received: from DM5PR21CU001.outbound.protection.outlook.com (mail-centralusazon11011051.outbound.protection.outlook.com [52.101.62.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 13A4A324701; Fri, 30 Jan 2026 08:35:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.62.51 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769762137; cv=fail; b=bw4TsjNp1FGtj0OktnjWg6h9E7bopVeKFLdoxI0IbTmdWbilAyy7QzZiWM5P0c0OBTra+epnsh0Rwe1eeyKZQOXQG3sNUL7ZftGTMgrrq9xTx3HbbIz0NU/tMhOb+KBblOFqZPQheCmhi2JNSDUOTdhQcDVt0TRPb4esL28l7uU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769762137; c=relaxed/simple; bh=xEDiAFtaOWeE2R9kf2Sl0hlyEE2Cg9vfGOttWTAIYhE=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=Io8ZpjBsJH9GBF16hqtPp6lLfKUH6MibNHKPPRSghy/YDDEl3gDB4NaR8dhtS/SYMXxq4Iuk9zNeiv5QLYzCcTNML0ha5ciJ8QX6wQnWrqaSNNVsRq8DGZbhJ+aehEuQlASSY2+0pIxsKpxqCK/3HRdFzq8nHX2MYAlIabl13Is= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=CKXUgdb5; arc=fail smtp.client-ip=52.101.62.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="CKXUgdb5" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=YLTAEgs2YTxEaOEjq7DyS/r2agrDklNbFSc0Eft5C9wprN4XmPaF1OsTuj8q7+woLBCCaHSlVm/b9AntcCDojHUg5HooI+UTaTg0LzNp74aFUi9p18QludPt+7zSE4Rd5Y1d5F8K1l25hHDikvUaADvXPMerwiNKXRqAnAh3p9uyhP3bbLWkDstlIUxik8gA08xfhlI+gZIDuGKyeDmh6iMFEdP9d3iXwgns9QFij9YRs4wfTmBfOjW0TCBcf/KoyT5Yt0cjMFAKeLj4BIEFa5XXHKAbp7CrBhce4G8+dcwX+ymiDRUsisZxRAdqhlCcvRDyh2XCNJIGVAW5dsrZgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=kA9R8Rxz1G7iPOKp8pYm905Gu/KbLbGJ3myVy5aVskE=; b=zI4tqpUk1i7fPUYfhN/F2+cWd6PdgtGi8ZWGdDVc1knszDnJV3cU4BWIDG//hOAQ/pF3xlM1IpbiIqPsG/Krx4vI7t3ZyU+C0GAjvmSVgSIlB8y7/ppEpAllfw/KshaQusF8ojoZ1VChkj6jH0BgY4fsgFkrK6kam4Z5alU4+t95Htn28PExC0x1TVkNGvgfabxYIK0Z/Tmq+ENHMH+OpujOfE/faGt1/mcBP3Y/oDgCC4oZMhhGVGty1iFsaAuOI9XHZoOOsriZQL3QRLYDLA0YXZCu4Po/0HMh5QFTnYpo4jabOp4gjcZ3WmdIjOMBps+bS7zQewLV9rm4hzpVXQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kA9R8Rxz1G7iPOKp8pYm905Gu/KbLbGJ3myVy5aVskE=; b=CKXUgdb5sANlkb9lEO4Fe/Bxv3FunTxgwE1ltXNAb+9O7iLJ192JK6VL7rRRK0TuBqqYlviME9mR2o86F/qwkb8/i3/CMX9KN7nwQt2ibym1ANqH8Cxc7eccDwgwnptFcruSQN1+hxRPrHRQ2F36XAG8VuoO8uvwArS+zc0iYlBHJcwPLX0G6LTXVlUNSYkad1Vjl4PFQkBmjVi1I6XiKxoYyUhKqJhMB8nUJ0MP9BhXt9B3coZMwNRX5d+3uw7ojp9rT92h7hPM9GFbkUNV0GFJ2Q14jfwRbYK99SdjV/FNSjvTS8qMwWwxr252oF6fkmaYm/f1KAu5oDHrN9HXrQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from BL0PR12MB2353.namprd12.prod.outlook.com (2603:10b6:207:4c::31) by DS0PR12MB9400.namprd12.prod.outlook.com (2603:10b6:8:1b6::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9564.11; Fri, 30 Jan 2026 08:35:28 +0000 Received: from BL0PR12MB2353.namprd12.prod.outlook.com ([fe80::99b:dcff:8d6d:78e0]) by BL0PR12MB2353.namprd12.prod.outlook.com ([fe80::99b:dcff:8d6d:78e0%6]) with mapi id 15.20.9542.010; Fri, 30 Jan 2026 08:35:28 +0000 From: Eliot Courtney Date: Fri, 30 Jan 2026 17:34:04 +0900 Subject: [PATCH 1/9] rust: dma: rename CoherentAllocation fallible methods Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260130-coherent-array-v1-1-bcd672dacc70@nvidia.com> References: <20260130-coherent-array-v1-0-bcd672dacc70@nvidia.com> In-Reply-To: <20260130-coherent-array-v1-0-bcd672dacc70@nvidia.com> To: Danilo Krummrich , Alexandre Courbot , Alice Ryhl , David Airlie , Simona Vetter , Abdiel Janulgue , Daniel Almeida , Robin Murphy , Andreas Hindborg , Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Trevor Gross Cc: nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, driver-core@lists.linux.dev, rust-for-linux@vger.kernel.org, Eliot Courtney X-Mailer: b4 0.14.3 X-ClientProxiedBy: TY4P286CA0048.JPNP286.PROD.OUTLOOK.COM (2603:1096:405:36e::9) To BL0PR12MB2353.namprd12.prod.outlook.com (2603:10b6:207:4c::31) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL0PR12MB2353:EE_|DS0PR12MB9400:EE_ X-MS-Office365-Filtering-Correlation-Id: e8a4548a-69bd-4688-0126-08de5fda85cb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|1800799024|376014|7416014|10070799003|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?B?L0hWd25lS2MvL1FFc3h3OGtTNGhUVGU1aHNtMTQ2dTlRbVlPMDJGRklqdmVi?= =?utf-8?B?UTNqaklPMU1pV3hpQWRQZGFFMytiOXVUY1N0VHM5WGN4dElQVVVYQ0VQTi9N?= =?utf-8?B?MEYxajFscndvaWFTMXVTL1dEcko2aTNBK0E5Q2d3QnVwTHc5eWR4V1l1SzJX?= =?utf-8?B?bFNaV29aaXR5TzlrVG8rZENCbnJBak1ubTBrNzl0OVdqUG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ZWUxc25DWkI2SllQQitDQ3VHclBCejVkUXU1?= =?utf-8?B?dDY0WEtmaGloUzh3UWtHUUJPU1dTQ3U5OENMZHVMWlNjM0QzTEFVMHJvV1Jz?= =?utf-8?B?ZEJzcldYRXphbnNzT3I3M25uV2t5emZwSm5lMkJyUUhNNStQZFQ4VzFTNGU5?= =?utf-8?B?TVE9PQ==?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL0PR12MB2353.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(1800799024)(376014)(7416014)(10070799003)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 2 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?UnYzVTJ3TmF1eG43ZzNGNTV0bkMwYUpoV3JxYi9abFgyVGNVQWFNeFJBRGVI?= =?utf-8?B?dzRLTjFrcE1Dc05TMWJxcy8vbVRRd3Fhb3UvRVhOcFFlVU80eHRHcnJ5c2lO?= =?utf-8?B?UzRad2JsMWJOWEdEaUZZL2NUWjdwS3V6RFlxS3AwVGJod2ttVmNUMUhPZlhu?= =?utf-8?B?SDZsQWk3dnByRUUwbEhvcUVOdE9EV0djWjBRNDRvUVFzeGZma3YvaFQwdFdP?= =?utf-8?B?MFREancrV3V3OE1DaUNHNXI3amVWODlXTE1vcUFYTGlTWUdtbEZIYVdwWFln?= =?utf-8?B?SnoreHM4eVFjTUV2Zm9vc3k4SHZqWGhUcmZOZFlpVjFoN05GV0pWRDRrc2VK?= =?utf-8?B?dnZFeFdXbFQ4b01SMHh0VEVmanpiV0hEOWthTEhnTW90T3NjT1lPVENUc0NE?= =?utf-8?B?eHMxQkoyOGMydzRzTmpNcURyNGZiTW45allEQjVkUENjWlkvcG1aaWdueFFh?= =?utf-8?B?eDZQU0kxVFR0WFd0Vm9IZ215Tk5QY1V3NThsbnVjdmtzRjF1SWdIaE1rVmtu?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NBSXBGTTEyeDA1czAzeTFleU84?= =?utf-8?Q?f/PzpWG7tvnhQ62jiiJmiTfBT/5tkRmHmAEN+MGcI50Ge?= X-MS-Exchange-AntiSpam-MessageData-1: 3k7R/UpR75IBeA== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: e8a4548a-69bd-4688-0126-08de5fda85cb X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB2353.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jan 2026 08:35:28.6437 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 6M2yVZmO+G1gDn9UwFNdv27hOrehoQ2d8wxu0r2sQ3vt+j7ira8Sjn5d6zQeWUwna7z50M/if0cFNfRFOPTGMw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB9400 Prefix fallible methods in CoherentAllocation with try_. Prefix dma_write! and dma_read! macros with try_ to better indicate they can fail. Signed-off-by: Eliot Courtney --- drivers/gpu/nova-core/dma.rs | 2 +- drivers/gpu/nova-core/falcon.rs | 2 +- drivers/gpu/nova-core/firmware/fwsec.rs | 4 +- drivers/gpu/nova-core/gsp.rs | 16 +++---- drivers/gpu/nova-core/gsp/boot.rs | 6 +-- drivers/gpu/nova-core/gsp/cmdq.rs | 14 +++--- rust/kernel/dma.rs | 85 +++++++++++++++++------------= ---- samples/rust/rust_dma.rs | 6 +-- 8 files changed, 69 insertions(+), 66 deletions(-) diff --git a/drivers/gpu/nova-core/dma.rs b/drivers/gpu/nova-core/dma.rs index 7215398969da..f77754f12f02 100644 --- a/drivers/gpu/nova-core/dma.rs +++ b/drivers/gpu/nova-core/dma.rs @@ -33,7 +33,7 @@ pub(crate) fn from_data(dev: &device::Device, data: &[u8]) -> Res Self::new(dev, data.len()).and_then(|mut dma_obj| { // SAFETY: We have just allocated the DMA memory, we are the o= nly users and // we haven't made the device aware of the handle yet. - unsafe { dma_obj.write(data, 0)? } + unsafe { dma_obj.try_write(data, 0)? } Ok(dma_obj) }) } diff --git a/drivers/gpu/nova-core/falcon.rs b/drivers/gpu/nova-core/falcon= .rs index 82c661aef594..9cd271de0554 100644 --- a/drivers/gpu/nova-core/falcon.rs +++ b/drivers/gpu/nova-core/falcon.rs @@ -460,7 +460,7 @@ fn dma_wr>( FalconMem::Imem =3D> (load_offsets.src_start, fw.dma_handle()), FalconMem::Dmem =3D> ( 0, - fw.dma_handle_with_offset(load_offsets.src_start.into_safe= _cast())?, + fw.try_dma_handle_with_offset(load_offsets.src_start.into_= safe_cast())?, ), }; if dma_start % DmaAddress::from(DMA_LEN) > 0 { diff --git a/drivers/gpu/nova-core/firmware/fwsec.rs b/drivers/gpu/nova-cor= e/firmware/fwsec.rs index b28e34d279f4..515b19926b49 100644 --- a/drivers/gpu/nova-core/firmware/fwsec.rs +++ b/drivers/gpu/nova-core/firmware/fwsec.rs @@ -191,7 +191,7 @@ unsafe fn transmute(fw: &DmaObjec= t, offset: usize) -> Resu // SAFETY: The safety requirements of the function guarantee the devic= e won't read // or write to memory while the reference is alive and that this call = won't race // with writes to the same memory region. - T::from_bytes(unsafe { fw.as_slice(offset, size_of::())? }).ok_or(E= INVAL) + T::from_bytes(unsafe { fw.try_as_slice(offset, size_of::())? }).ok_= or(EINVAL) } =20 /// Reinterpret the area starting from `offset` in `fw` as a mutable insta= nce of `T` (which must @@ -210,7 +210,7 @@ unsafe fn transmute_mut( // SAFETY: The safety requirements of the function guarantee the devic= e won't read // or write to memory while the reference is alive and that this call = won't race // with writes or reads to the same memory region. - T::from_bytes_mut(unsafe { fw.as_slice_mut(offset, size_of::())? })= .ok_or(EINVAL) + T::from_bytes_mut(unsafe { fw.try_as_slice_mut(offset, size_of::())= ? }).ok_or(EINVAL) } =20 /// The FWSEC microcode, extracted from the BIOS and to be run on the GSP = falcon. diff --git a/drivers/gpu/nova-core/gsp.rs b/drivers/gpu/nova-core/gsp.rs index fb6f74797178..43bc35fd3b55 100644 --- a/drivers/gpu/nova-core/gsp.rs +++ b/drivers/gpu/nova-core/gsp.rs @@ -8,10 +8,10 @@ CoherentAllocation, DmaAddress, // }, - dma_write, pci, prelude::*, - transmute::AsBytes, // + transmute::AsBytes, + try_dma_write, // }; =20 pub(crate) mod cmdq; @@ -92,7 +92,7 @@ fn new(dev: &device::Device) -> Result { unsafe { // Copy the self-mapping PTE at the expected location. obj.0 - .as_slice_mut(size_of::(), size_of_val(&ptes))? + .try_as_slice_mut(size_of::(), size_of_val(&ptes))? .copy_from_slice(ptes.as_bytes()) }; =20 @@ -131,13 +131,13 @@ pub(crate) fn new(pdev: &pci::Device) = -> Result) ->= Result::alloc_coherent(dev, 1, GFP= _KERNEL | __GFP_ZERO)?; - dma_write!(wpr_meta[0] =3D GspFwWprMeta::new(&gsp_fw, &fb_layout))= ?; + try_dma_write!(wpr_meta[0] =3D GspFwWprMeta::new(&gsp_fw, &fb_layo= ut))?; =20 self.cmdq .send_command(bar, commands::SetSystemInfo::new(pdev))?; diff --git a/drivers/gpu/nova-core/gsp/cmdq.rs b/drivers/gpu/nova-core/gsp/= cmdq.rs index 3991ccc0c10f..9c94f4c6ff6d 100644 --- a/drivers/gpu/nova-core/gsp/cmdq.rs +++ b/drivers/gpu/nova-core/gsp/cmdq.rs @@ -15,7 +15,6 @@ CoherentAllocation, DmaAddress, // }, - dma_write, io::poll::read_poll_timeout, prelude::*, sync::aref::ARef, @@ -24,6 +23,7 @@ AsBytes, FromBytes, // }, + try_dma_write, // }; =20 use crate::{ @@ -201,9 +201,11 @@ fn new(dev: &device::Device) -> Result<= Self> { =20 let gsp_mem =3D CoherentAllocation::::alloc_coherent(dev, 1, GFP_KERNE= L | __GFP_ZERO)?; - dma_write!(gsp_mem[0].ptes =3D PteArray::new(gsp_mem.dma_handle())= ?)?; - dma_write!(gsp_mem[0].cpuq.tx =3D MsgqTxHeader::new(MSGQ_SIZE, RX_= HDR_OFF, MSGQ_NUM_PAGES))?; - dma_write!(gsp_mem[0].cpuq.rx =3D MsgqRxHeader::new())?; + try_dma_write!(gsp_mem[0].ptes =3D PteArray::new(gsp_mem.dma_handl= e())?)?; + try_dma_write!( + gsp_mem[0].cpuq.tx =3D MsgqTxHeader::new(MSGQ_SIZE, RX_HDR_OFF= , MSGQ_NUM_PAGES) + )?; + try_dma_write!(gsp_mem[0].cpuq.rx =3D MsgqRxHeader::new())?; =20 Ok(Self(gsp_mem)) } @@ -221,7 +223,7 @@ fn new(dev: &device::Device) -> Result { // - The `CoherentAllocation` contains exactly one object. // - We will only access the driver-owned part of the shared memor= y. // - Per the safety statement of the function, no concurrent acces= s will be performed. - let gsp_mem =3D &mut unsafe { self.0.as_slice_mut(0, 1) }.unwrap()= [0]; + let gsp_mem =3D &mut unsafe { self.0.try_as_slice_mut(0, 1) }.unwr= ap()[0]; // PANIC: per the invariant of `cpu_write_ptr`, `tx` is `<=3D MSGQ= _NUM_PAGES`. let (before_tx, after_tx) =3D gsp_mem.cpuq.msgq.data.split_at_mut(= tx); =20 @@ -256,7 +258,7 @@ fn new(dev: &device::Device) -> Result { // - The `CoherentAllocation` contains exactly one object. // - We will only access the driver-owned part of the shared memor= y. // - Per the safety statement of the function, no concurrent acces= s will be performed. - let gsp_mem =3D &unsafe { self.0.as_slice(0, 1) }.unwrap()[0]; + let gsp_mem =3D &unsafe { self.0.try_as_slice(0, 1) }.unwrap()[0]; // PANIC: per the invariant of `cpu_read_ptr`, `xx` is `<=3D MSGQ_= NUM_PAGES`. let (before_rx, after_rx) =3D gsp_mem.gspq.msgq.data.split_at(rx); =20 diff --git a/rust/kernel/dma.rs b/rust/kernel/dma.rs index 909d56fd5118..02321d5f3f06 100644 --- a/rust/kernel/dma.rs +++ b/rust/kernel/dma.rs @@ -482,7 +482,7 @@ pub fn dma_handle(&self) -> DmaAddress { /// device as the DMA address base of the region. /// /// Returns `EINVAL` if `offset` is not within the bounds of the alloc= ation. - pub fn dma_handle_with_offset(&self, offset: usize) -> Result { + pub fn try_dma_handle_with_offset(&self, offset: usize) -> Result { if offset >=3D self.count { Err(EINVAL) } else { @@ -494,7 +494,7 @@ pub fn dma_handle_with_offset(&self, offset: usize) -> = Result { =20 /// Common helper to validate a range applied from the allocated regio= n in the CPU's virtual /// address space. - fn validate_range(&self, offset: usize, count: usize) -> Result { + fn try_validate_range(&self, offset: usize, count: usize) -> Result { if offset.checked_add(count).ok_or(EOVERFLOW)? > self.count { return Err(EINVAL); } @@ -514,8 +514,8 @@ fn validate_range(&self, offset: usize, count: usize) -= > Result { /// slice is live. /// * Callers must ensure that this call does not race with a write to= the same region while /// the returned slice is live. - pub unsafe fn as_slice(&self, offset: usize, count: usize) -> Result<&= [T]> { - self.validate_range(offset, count)?; + pub unsafe fn try_as_slice(&self, offset: usize, count: usize) -> Resu= lt<&[T]> { + self.try_validate_range(offset, count)?; // SAFETY: // - The pointer is valid due to type invariant on `CoherentAlloca= tion`, // we've just checked that the range and index is within bounds.= The immutability of the @@ -525,8 +525,8 @@ pub unsafe fn as_slice(&self, offset: usize, count: usi= ze) -> Result<&[T]> { Ok(unsafe { core::slice::from_raw_parts(self.start_ptr().add(offse= t), count) }) } =20 - /// Performs the same functionality as [`CoherentAllocation::as_slice`= ], except that a mutable - /// slice is returned. + /// Performs the same functionality as [`CoherentAllocation::try_as_sl= ice`], except that a + /// mutable slice is returned. /// /// # Safety /// @@ -534,8 +534,8 @@ pub unsafe fn as_slice(&self, offset: usize, count: usi= ze) -> Result<&[T]> { /// slice is live. /// * Callers must ensure that this call does not race with a read or = write to the same region /// while the returned slice is live. - pub unsafe fn as_slice_mut(&mut self, offset: usize, count: usize) -> = Result<&mut [T]> { - self.validate_range(offset, count)?; + pub unsafe fn try_as_slice_mut(&mut self, offset: usize, count: usize)= -> Result<&mut [T]> { + self.try_validate_range(offset, count)?; // SAFETY: // - The pointer is valid due to type invariant on `CoherentAlloca= tion`, // we've just checked that the range and index is within bounds.= The immutability of the @@ -561,11 +561,11 @@ pub unsafe fn as_slice_mut(&mut self, offset: usize, = count: usize) -> Result<&mu /// let buf: &[u8] =3D &somedata; /// // SAFETY: There is no concurrent HW operation on the device and n= o other R/W access to the /// // region. - /// unsafe { alloc.write(buf, 0)?; } + /// unsafe { alloc.try_write(buf, 0)?; } /// # Ok::<(), Error>(()) } /// ``` - pub unsafe fn write(&mut self, src: &[T], offset: usize) -> Result { - self.validate_range(offset, src.len())?; + pub unsafe fn try_write(&mut self, src: &[T], offset: usize) -> Result= { + self.try_validate_range(offset, src.len())?; // SAFETY: // - The pointer is valid due to type invariant on `CoherentAlloca= tion` // and we've just checked that the range and index is within bou= nds. @@ -581,12 +581,13 @@ pub unsafe fn write(&mut self, src: &[T], offset: usi= ze) -> Result { Ok(()) } =20 - /// Returns a pointer to an element from the region with bounds checki= ng. `offset` is in - /// units of `T`, not the number of bytes. + /// Returns a pointer to an element from the region with bounds checki= ng. `offset` is in units + /// of `T`, not the number of bytes. /// - /// Public but hidden since it should only be used from [`dma_read`] a= nd [`dma_write`] macros. + /// Public but hidden since it should only be used from [`try_dma_read= `] and [`try_dma_write`] + /// macros. #[doc(hidden)] - pub fn item_from_index(&self, offset: usize) -> Result<*mut T> { + pub fn try_item_from_index(&self, offset: usize) -> Result<*mut T> { if offset >=3D self.count { return Err(EINVAL); } @@ -602,10 +603,10 @@ pub fn item_from_index(&self, offset: usize) -> Resul= t<*mut T> { /// /// # Safety /// - /// This must be called from the [`dma_read`] macro which ensures that= the `field` pointer is - /// validated beforehand. + /// This must be called from the [`try_dma_read`] macro which ensures = that the `field` pointer + /// is validated beforehand. /// - /// Public but hidden since it should only be used from [`dma_read`] m= acro. + /// Public but hidden since it should only be used from [`try_dma_read= `] macro. #[doc(hidden)] pub unsafe fn field_read(&self, field: *const F) -> F { // SAFETY: @@ -625,10 +626,10 @@ pub unsafe fn field_read(&self, field: = *const F) -> F { /// /// # Safety /// - /// This must be called from the [`dma_write`] macro which ensures tha= t the `field` pointer is - /// validated beforehand. + /// This must be called from the [`try_dma_write`] macro which ensures= that the `field` pointer + /// is validated beforehand. /// - /// Public but hidden since it should only be used from [`dma_write`] = macro. + /// Public but hidden since it should only be used from [`try_dma_writ= e`] macro. #[doc(hidden)] pub unsafe fn field_write(&self, field: *mut F, val: F) { // SAFETY: @@ -684,18 +685,18 @@ unsafe impl Send for C= oherentAllocation {} /// unsafe impl kernel::transmute::AsBytes for MyStruct{}; /// /// # fn test(alloc: &kernel::dma::CoherentAllocation) -> Result= { -/// let whole =3D kernel::dma_read!(alloc[2]); -/// let field =3D kernel::dma_read!(alloc[1].field); +/// let whole =3D kernel::try_dma_read!(alloc[2]); +/// let field =3D kernel::try_dma_read!(alloc[1].field); /// # Ok::<(), Error>(()) } /// ``` #[macro_export] -macro_rules! dma_read { - ($dma:expr, $idx: expr, $($field:tt)*) =3D> {{ +macro_rules! try_dma_read { + ($dma:expr, $idx:expr, $($field:tt)*) =3D> {{ (|| -> ::core::result::Result<_, $crate::error::Error> { - let item =3D $crate::dma::CoherentAllocation::item_from_index(= &$dma, $idx)?; - // SAFETY: `item_from_index` ensures that `item` is always a v= alid pointer and can be - // dereferenced. The compiler also further validates the expre= ssion on whether `field` - // is a member of `item` when expanded by the macro. + let item =3D $crate::dma::CoherentAllocation::try_item_from_in= dex(&$dma, $idx)?; + // SAFETY: `try_item_from_index` ensures that `item` is always= a valid pointer + // and can be dereferenced. The compiler also further validate= s the expression + // on whether `field` is a member of `item` when expanded by t= he macro. unsafe { let ptr_field =3D ::core::ptr::addr_of!((*item) $($field)*= ); ::core::result::Result::Ok( @@ -705,10 +706,10 @@ macro_rules! dma_read { })() }}; ($dma:ident [ $idx:expr ] $($field:tt)* ) =3D> { - $crate::dma_read!($dma, $idx, $($field)*) + $crate::try_dma_read!($dma, $idx, $($field)*) }; ($($dma:ident).* [ $idx:expr ] $($field:tt)* ) =3D> { - $crate::dma_read!($($dma).*, $idx, $($field)*) + $crate::try_dma_read!($($dma).*, $idx, $($field)*) }; } =20 @@ -728,32 +729,32 @@ macro_rules! dma_read { /// unsafe impl kernel::transmute::AsBytes for MyStruct{}; /// /// # fn test(alloc: &kernel::dma::CoherentAllocation) -> Result= { -/// kernel::dma_write!(alloc[2].member =3D 0xf); -/// kernel::dma_write!(alloc[1] =3D MyStruct { member: 0xf }); +/// kernel::try_dma_write!(alloc[2].member =3D 0xf); +/// kernel::try_dma_write!(alloc[1] =3D MyStruct { member: 0xf }); /// # Ok::<(), Error>(()) } /// ``` #[macro_export] -macro_rules! dma_write { +macro_rules! try_dma_write { ($dma:ident [ $idx:expr ] $($field:tt)*) =3D> {{ - $crate::dma_write!($dma, $idx, $($field)*) + $crate::try_dma_write!($dma, $idx, $($field)*) }}; ($($dma:ident).* [ $idx:expr ] $($field:tt)* ) =3D> {{ - $crate::dma_write!($($dma).*, $idx, $($field)*) + $crate::try_dma_write!($($dma).*, $idx, $($field)*) }}; ($dma:expr, $idx: expr, =3D $val:expr) =3D> { (|| -> ::core::result::Result<_, $crate::error::Error> { - let item =3D $crate::dma::CoherentAllocation::item_from_index(= &$dma, $idx)?; - // SAFETY: `item_from_index` ensures that `item` is always a v= alid item. + let item =3D $crate::dma::CoherentAllocation::try_item_from_in= dex(&$dma, $idx)?; + // SAFETY: `try_item_from_index` ensures that `item` is always= a valid item. unsafe { $crate::dma::CoherentAllocation::field_write(&$dma, i= tem, $val) } ::core::result::Result::Ok(()) })() }; ($dma:expr, $idx: expr, $(.$field:ident)* =3D $val:expr) =3D> { (|| -> ::core::result::Result<_, $crate::error::Error> { - let item =3D $crate::dma::CoherentAllocation::item_from_index(= &$dma, $idx)?; - // SAFETY: `item_from_index` ensures that `item` is always a v= alid pointer and can be - // dereferenced. The compiler also further validates the expre= ssion on whether `field` - // is a member of `item` when expanded by the macro. + let item =3D $crate::dma::CoherentAllocation::try_item_from_in= dex(&$dma, $idx)?; + // SAFETY: `try_item_from_index` ensures that `item` is always= a valid pointer + // and can be dereferenced. The compiler also further validate= s the expression + // on whether `field` is a member of `item` when expanded by t= he macro. unsafe { let ptr_field =3D ::core::ptr::addr_of_mut!((*item) $(.$fi= eld)*); $crate::dma::CoherentAllocation::field_write(&$dma, ptr_fi= eld, $val) diff --git a/samples/rust/rust_dma.rs b/samples/rust/rust_dma.rs index 9c45851c876e..7a87048575df 100644 --- a/samples/rust/rust_dma.rs +++ b/samples/rust/rust_dma.rs @@ -68,7 +68,7 @@ fn probe(pdev: &pci::Device, _info: &Self::IdInfo) = -> impl PinInit) { dev_info!(self.pdev, "Unload DMA test driver.\n"); =20 for (i, value) in TEST_VALUES.into_iter().enumerate() { - let val0 =3D kernel::dma_read!(self.ca[i].h); - let val1 =3D kernel::dma_read!(self.ca[i].b); + let val0 =3D kernel::try_dma_read!(self.ca[i].h); + let val1 =3D kernel::try_dma_read!(self.ca[i].b); assert!(val0.is_ok()); assert!(val1.is_ok()); =20 --=20 2.52.0