From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) (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 AF628217666 for ; Fri, 7 Mar 2025 11:17:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741346230; cv=none; b=GnZIWKJ53ZYHEHEZsCtHGNpfFV9Ce6zBo2cUdh7TT8ibfl6FxMaeCmCxLwNuj0r7bBoUWAWJxpQFokdATzELKvuz2+y8cgo4vAxW8zqMFd8v9oNxewjOdoVDWq1HSEISfbpKwgiNl9y34cEPEulZlsT9zQ/bLD+AowI++Q1xQjs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741346230; c=relaxed/simple; bh=phHfA6KQhI9tzLKWRyLl5Cm7ekKU7mLN5aentr1Yft8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=lrc+I5iIbDunQvPhkDcEsujYg1bl7dz+NyTkkqmOO2bQs82uwpodOkybxbL28otL1392Qd+Qcl6HhFoOTqQ6DlmO45YqOGrWeT1k6ywe5/hDbtdjweGCp3vRtgKy2+rbe1pz5zRBAEjKB80ZQrPJ00iAqVAFUxvUmesIz6wC36Y= 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=A2Q3wnVw; arc=none smtp.client-ip=209.85.128.73 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="A2Q3wnVw" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-4394c489babso8158275e9.1 for ; Fri, 07 Mar 2025 03:17:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1741346227; x=1741951027; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=7NCud3YDrS8rMqDriMRjnUp9EmgptAXkjuXyMh39DeE=; b=A2Q3wnVw0PlGHPudWHBhQsiPeR7vkL0PFoQA/ykpwIla5mRxM01hOpq+HtuzE4jofY wXA6hwDbCbLUavV4M6q9OMyfFgPewlfV1Ef88U2x5i6brkp4YhGTM0uNFDRgLODP6E7P Z6ScfzfVqBnrrYriZRdq1cwMPSt0V/UDnTgQdixfOST9kgY3qiEnqFf2HeP5w6ngZCCE yNt7d2K5WpjEi2JOzyrrRmPjkfe+dADzLZrlg6WMWY1s+lp4V/FT4HPKEspgvLkNCe6J BSDx0sMJCvfbNsRPGk3qCGea7i3euED46ebJQDm36ppktS+azXomtijrsG3bGoDKfCeP W5Tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741346227; x=1741951027; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7NCud3YDrS8rMqDriMRjnUp9EmgptAXkjuXyMh39DeE=; b=PW5X39Ef8K8zFJV5WgEfWUAV/56gn6cFM81ivKcNZAQMKyjVa79+O9s68KVyNtiVf/ 2h4do3lQq1EXbj1kXhefNEGqbo3s7r+7DbQ+Bt7y1sXV14s9pksBJeJsz1M3TkSDeo1f P/O33lbnDvI5w3G3IM7K1Wk2FG7wkjxGrIxMbUiWOvinnHEed+5nTgPJyaADPi/P2t5e BWABV89Q9/GE1jsaTCIZv910ASk1G2qXGdqVK6dZ/E7dPUAuU7BBT1MO86MYqmEc2Q95 GXObqjTvjr1ReDjNmJNTiWUQiRr97sUU08va+UJN5xqkJ7EHV93HaxjCOMRHakgtDXCt y+6g== X-Gm-Message-State: AOJu0YybnsuC4xX2AtKKQPDY7oPrJtNdaPibcfShD5VTAf/G+y0zD3zn G1gPQprjpR5QwGXmuAqaR76xwfkpWqqTJL0AQudU3bzvK8PDymM8w9PanqbQtRGn9CAEQAskuYg Vr6T4l/zgeJzDGw== X-Google-Smtp-Source: AGHT+IH5/jQh6E6kSDoYmzpqJhrOtDcnc6+Obu9PZ9gPPi3bYRV7MA4XFxyIILhgKXpg3G8LM6+X3I03hodwVqU= X-Received: from wmbfl11.prod.google.com ([2002:a05:600c:b8b:b0:43b:c7c8:d3ae]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:1c9d:b0:43b:ca39:6c7d with SMTP id 5b1f17b1804b1-43cb91c5830mr14428465e9.3.1741346227107; Fri, 07 Mar 2025 03:17:07 -0800 (PST) Date: Fri, 7 Mar 2025 11:17:04 +0000 In-Reply-To: <20250307110821.1703422-3-abdiel.janulgue@gmail.com> Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250307110821.1703422-1-abdiel.janulgue@gmail.com> <20250307110821.1703422-3-abdiel.janulgue@gmail.com> Message-ID: Subject: Re: [PATCH v13 2/7] rust: add dma coherent allocator abstraction. From: Alice Ryhl To: Abdiel Janulgue Cc: rust-for-linux@vger.kernel.org, daniel.almeida@collabora.com, dakr@kernel.org, robin.murphy@arm.com, Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , "=?utf-8?B?QmrDtnJu?= Roy Baron" , Benno Lossin , Andreas Hindborg , Trevor Gross , Valentin Obst , open list , Christoph Hellwig , Marek Szyprowski , airlied@redhat.com, "open list:DMA MAPPING HELPERS" Content-Type: text/plain; charset="utf-8" On Fri, Mar 07, 2025 at 01:06:19PM +0200, Abdiel Janulgue wrote: > Add a simple dma coherent allocator rust abstraction. Based on > Andreas Hindborg's dma abstractions from the rnvme driver, which > was also based on earlier work by Wedson Almeida Filho. > > A CoherentAllocation is wrapped in Devres which basically guarantees > that a driver can't make a CoherentAllocation out-live driver unbind. > This is needed, since DMA allocations potentially also result in > programming of the IOMMU. IOMMU mappings are device resources and > hence the device / driver lifecycle needs to be enforced. > > Signed-off-by: Abdiel Janulgue You might want to add #[inline] annotations to the various methods, but otherwise LGTM. Reviewed-by: Alice Ryhl > +/// Helper function to set the bit mask for DMA addressing. > +pub const fn dma_bit_mask(n: usize) -> u64 { > + if n > 64 { > + return 0; > + } > + if n == 64 { > + !0 > + } else { > + (1 << (n)) - 1 > + } > +} You don't use this method? Alice