nova-core: align Bar0/Bar1 and remvove unnecessary Arc
Subsystems (4)
Danilo Krummrich
maintainercover nova-core: align Bar0/Bar1 and remvove unnecessary Arc
Get rid of the Bar0/Bar1 type alias inconsistency and the unnecessary reference count of BarUser.
There's much more to improve, but this just crossed my way.
Danilo Krummrich (4):
gpu: nova-core: align Bar1 alias with Bar0
gpu: nova-core: remove unnecessary Arc around BarUser
gpu: nova-core: mm: get rid of Arc<BarUser> in BarUserAccess
gpu: nova-core: mm: fix lifetime name in BarUser
drivers/gpu/nova-core/driver.rs | 4 +-- drivers/gpu/nova-core/gpu.rs | 26 ++++++++--------- drivers/gpu/nova-core/mm.rs | 5 ++-- drivers/gpu/nova-core/mm/bar_user.rs | 43 +++++++++++++--------------- 4 files changed, 36 insertions(+), 42 deletions(-)
base-commit: 896ed083362758b33c49a1b5e5a3423c5814d87e
Signature · 1 line
2.55.0
Danilo Krummrich
maintainerPATCH 1/4 gpu: nova-core: align Bar1 alias with Bar0
Make Bar1 an alias for a borrowed pci::Bar in order to match the Bar0 type alias.
--- drivers/gpu/nova-core/driver.rs | 4 ++-- drivers/gpu/nova-core/gpu.rs | 2 +- drivers/gpu/nova-core/mm/bar_user.rs | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-)
drivers/gpu/nova-core/driver.rs +2 -2
@@ -32,7 +32,7 @@ pub(crate) struct NovaCore<'bound> {#[pin] pub(crate) gpu: Gpu<'bound>, bar: pci::Bar<'bound, BAR0_SIZE>, - bar1: Bar1<'bound>, + bar1: pci::Bar<'bound>,#[allow(clippy::type_complexity)] _reg: auxiliary::Registration<'bound, CovariantForLt!(())>, }
@@ -43,7 +43,7 @@ pub(crate) struct NovaCore<'bound> {pub (crate )type Bar0 <'a> = &'a pci::Bar <'a,BAR0_SIZE >;pub (crate )type NovaRegisters = kernel::io::Region <BAR0_SIZE >; -pub (crate )type Bar1 <'a> = pci::Bar <'a>; +pub (crate )type Bar1 <'a> = &'a pci::Bar <'a>;/// Returns the Linux PCI resource index that holds BAR1 for an NVIDIA GPU. ///
drivers/gpu/nova-core/gpu.rs +1 -1
@@ -353,7 +353,7 @@ impl<'gpu> Gpu<'gpu> {pub (crate )fn new <'a>( pdev: &'gpu pci::Device <device::Core <'a>>, bar:Bar0 <'gpu>, - bar1: &'gpuBar1 <'gpu>, + bar1:Bar1 <'gpu>, ) ->impl PinInit <Self ,Error > +use <'gpu, 'a> {let dev = pdev.as_ref ();
drivers/gpu/nova-core/mm/bar_user.rs +2 -2
@@ -41,7 +41,7 @@pub (crate )struct BarUser <'gpu> {#[pin] vmm:Mutex <Vmm >, - bar1: &'gpuBar1 <'gpu>, + bar1:Bar1 <'gpu>, }impl <'gpu>BarUser <'gpu> {
@@ -50,7 +50,7 @@ pub(crate) fn new( pdb_addr: VramAddress, chipset: Chipset, va_size: u64, - bar1: &'gpu Bar1<'gpu>, + bar1: Bar1<'gpu>, ) -> Result<impl PinInit<Self> + 'gpu> { let vmm = Vmm::new(pdb_addr, chipset.mmu_version(), va_size)?; Ok(pin_init!(Self {
Signature · 1 line
2.55.0
Re: [PATCH 1/4] gpu: nova-core: align Bar1 alias with Bar0
Quoted 5 lines · Danilo Krummrich
Make Bar1 an alias for a borrowed
pci::Barin order to match the Bar0 type alias.Signed-off-by Danilo Krummrich <[email protected]>---
Danilo Krummrich
maintainerPATCH 2/4 gpu: nova-core: remove unnecessary Arc around BarUser
In reply to Danilo KrummrichRemove the unnecessary Arc around BarUser and get rid of Result<impl PinInit<T>> in favor of impl PinInit<T, Error>.
--- drivers/gpu/nova-core/gpu.rs | 24 +++++++++++------------- drivers/gpu/nova-core/mm.rs | 5 ++--- drivers/gpu/nova-core/mm/bar_user.rs | 16 +++++++++------- 3 files changed, 22 insertions(+), 23 deletions(-)
drivers/gpu/nova-core/gpu.rs +11 -13
@@ -16,7 +16,6 @@ SizeConstants, SZ_4K, // }, - sync::Arc, };use crate ::{
@@ -309,7 +308,8 @@ pub(crate) struct Gpu<'gpu> {/// the GSP is still operational. mm: GpuMm<'gpu>,/// BAR1 user interface for CPU access to GPU virtual memory. - bar_user: Arc<BarUser<'gpu>>, +#[pin] + bar_user: BarUser<'gpu>,/// GSP and its resources. #[pin] gsp_resources: GspResources<'gpu>,
@@ -465,19 +465,17 @@ pub(crate) fn new<'a>( },// Create BAR1 user interface for CPU access to GPU virtual memory. - bar_user: { + bar_user <- {let pdb_addr =VramAddress ::from_raw (gsp_static_info.bar1_pde_base);let bar1_idx =crate ::driver::bar1_resource_index (pdev)?;let bar1_size = pdev.resource_len (bar1_idx)?; -Arc ::pin_init ( -BarUser ::new ( - pdb_addr, - gsp_resources.spec.chipset, - bar1_size, - bar1, - )?, -GFP_KERNEL , - )? + +BarUser ::new ( + pdb_addr, + gsp_resources.spec.chipset, + bar1_size, + bar1, + ) }, }) }
@@ -493,7 +491,7 @@ pub(crate) fn run_selftests(self: Pin<&mut Self>, pdev: &pci::Device<device::Bou dev, this.mm, regions, - this.bar_user, + &this.bar_user, this.gsp_static_info.bar1_pde_base, this.spec.chipset, ) {
drivers/gpu/nova-core/mm.rs +2 -3
@@ -298,8 +298,7 @@ pub(crate) mod selftest {use kernel::{ device, - sizes::SizeConstants , - sync::Arc ,// + sizes::SizeConstants ,// };use super ::*;
@@ -309,7 +308,7 @@ pub(crate) fn run( dev: &device::Device<device::Bound>, mm: &mut GpuMm<'_>, usable_fb_regions: &[Range<u64>], - bar_user: &Arc<bar_user::BarUser<'_>>, + bar_user: &bar_user::BarUser<'_>, bar1_pdb: u64, chipset: Chipset, ) -> Result {
drivers/gpu/nova-core/mm/bar_user.rs +9 -7
@@ -51,12 +51,14 @@ pub(crate) fn new( chipset: Chipset, va_size: u64, bar1: Bar1<'gpu>, - ) -> Result<impl PinInit<Self> + 'gpu> { -let vmm =Vmm ::new (pdb_addr, chipset.mmu_version (), va_size)?; -Ok (pin_init! (Self { - vmm <-new_mutex! (vmm,"bar_user_vmm" ), + ) -> impl PinInit<Self, Error> + 'gpu { +try_pin_init! (Self { + vmm <-new_mutex! ( +Vmm ::new (pdb_addr, chipset.mmu_version (), va_size)?, +"bar_user_vmm" , + ), bar1, - })) + }) }/// Map physical pages to a contiguous BAR1 virtual range.
@@ -183,7 +185,7 @@ fn drop(&mut self) {pub (crate )fn run_self_test ( dev: &device::Device <device::Bound >, mm: &mut GpuMm <'_>, - bar_user: &Arc <BarUser <'_>>, + bar_user: &BarUser <'_>, bar1_pdb:u64 , chipset:Chipset , ) ->Result {
@@ -389,7 +391,7 @@ pub(crate) fn run_self_test(// Test 4: Exercise `BarUser::map()` end-to-end. let bar_user =Arc ::pin_init ( -BarUser ::new (pdb_addr, chipset,SZ_64K .into_safe_cast (), bar1)?, +BarUser ::new (pdb_addr, chipset,SZ_64K .into_safe_cast (), bar1),GFP_KERNEL , )?;let access = bar_user.map (mm, &[test_pfn],true )?;
Signature · 1 line
2.55.0
Re: [PATCH 2/4] gpu: nova-core: remove unnecessary Arc around BarUser
Quoted 5 lines · Danilo Krummrich
Remove the unnecessary Arc around BarUser and get rid of Result<impl PinInit<T>> in favor of impl PinInit<T, Error>.
Signed-off-by Danilo Krummrich <[email protected]>---
Danilo Krummrich
maintainerPATCH 3/4 gpu: nova-core: mm: get rid of Arc<BarUser> in BarUserAccess
In reply to Danilo KrummrichThere is no need for a reference count here. BarUserAccess can just borrow from BarUser.
--- drivers/gpu/nova-core/mm/bar_user.rs | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-)
drivers/gpu/nova-core/mm/bar_user.rs +8 -13
@@ -7,10 +7,7 @@ io::Io, new_mutex, prelude::*, - sync::{ -Arc , -Mutex ,// - }, + sync::Mutex, // };use crate ::{
@@ -63,11 +60,11 @@ pub(crate) fn new(/// Map physical pages to a contiguous BAR1 virtual range. pub (crate )fn map ( - self: &Arc <Self >, + &self, mm: &mut GpuMm <'_>, pfns: &[Pfn ], writable:bool , - ) ->Result <BarUserAccess <'gpu>> { + ) ->Result <BarUserAccess <'_>> {if pfns.is_empty () {return Err (EINVAL ); }
@@ -75,15 +72,17 @@ pub(crate) fn map(let mapped = vmm.map_pages (mm, pfns,None , writable)?;Ok (BarUserAccess { - bar_user: self.clone (), + bar_user: self, mapped:Some (mapped), }) } }/// Access object for a mapped BAR1 region. -pub (crate )struct BarUserAccess <'gpu> { - bar_user:Arc <BarUser <'gpu>>, +/// +/// Borrows the [`BarUser`] managing the mapping for the lifetime of the access object. +pub (crate )struct BarUserAccess <'a> { + bar_user: &'aBarUser <'a>,/// [`BarUserAccess::release`] [`Option::take`]s this; `Some` at /// drop time means `release()` was never called. mapped:Option <MappedRange >,
@@ -390,10 +389,6 @@ pub(crate) fn run_self_test(drop (vmm);// Test 4: Exercise `BarUser::map()` end-to-end. -let bar_user =Arc ::pin_init ( -BarUser ::new (pdb_addr, chipset,SZ_64K .into_safe_cast (), bar1), -GFP_KERNEL , - )?;let access = bar_user.map (mm, &[test_pfn],true )?;// Write pattern via PRAMIN, read via BarUserAccess.
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH 3/4] gpu: nova-core: mm: get rid of Arc<BarUser> in BarUserAccess
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] nova-core: mm: obsolete comment claims Test 4 constructs a fresh BarUser --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] nova-core: mm: obsolete comment claims Test 4 constructs a fresh BarUser --
commit b705dbdc6dba4759072fbccc510dc7a0935032c8
Author: Danilo Krummrich <[email protected]>
gpu: nova-core: mm: get rid of Arc<BarUser> in BarUserAccess
There is no need for a reference count here. BarUserAccess can just borrow from BarUser.
Quoted 4 lines
drivers/gpu/nova-core/mm/bar_user.rs +0
-0
[ ... ]
drivers/gpu/nova-core/mm/bar_user.rs pub(crate) fn run_self_test( · line 394
Quoted 11 lines
drivers/gpu/nova-core/mm/bar_user.rs +0
-4@@ -390,10 +389,6 @@ pub(crate) fn run_self_test(drop (vmm);// Test 4: Exercise `BarUser::map()` end-to-end. -let bar_user =Arc ::pin_init ( -BarUser ::new (pdb_addr, chipset,SZ_64K .into_safe_cast (), bar1), -GFP_KERNEL , - )?;let access = bar_user.map (mm, &[test_pfn],true )?;// Write pattern via PRAMIN, read via BarUserAccess.
[Severity: Low]
Should the comment just above drop(vmm) in run_self_test() in drivers/gpu/nova-core/mm/bar_user.rs be updated?
It currently says: "Release Tests 1-3's Vmm before Test 4 constructs a fresh BarUser on the same PDB."
Since this patch removes the construction of a fresh BarUser for Test 4, that part of the comment is now obsolete.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Re: [PATCH 3/4] gpu: nova-core: mm: get rid of Arc<BarUser> in BarUserAccess
In reply to Danilo KrummrichQuoted 5 lines · Danilo Krummrich
There is no need for a reference count here. BarUserAccess can just borrow from BarUser.
Signed-off-by Danilo Krummrich <[email protected]>---
Danilo Krummrich
maintainerPATCH 4/4 gpu: nova-core: mm: fix lifetime name in BarUser
In reply to Danilo KrummrichBarUser should not use 'gpu as a name for its lifetime; stick to a generic 'a until we need pin-init selfref for this struct.
--- drivers/gpu/nova-core/mm/bar_user.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/gpu/nova-core/mm/bar_user.rs +5 -5
@@ -35,20 +35,20 @@ /// /// Owns the [`Vmm`] for the BAR1 address space. #[pin_data] -pub(crate) struct BarUser<'gpu> { +pub(crate) struct BarUser<'a> { #[pin] vmm: Mutex<Vmm>, - bar1: Bar1<'gpu>, + bar1: Bar1<'a>, } -impl<'gpu> BarUser<'gpu> { +impl<'a> BarUser<'a> { /// Create a pin-initializer for [`BarUser`]. pub(crate) fn new( pdb_addr: VramAddress, chipset: Chipset, va_size: u64, - bar1: Bar1<'gpu>, - ) -> impl PinInit<Self, Error> + 'gpu { + bar1: Bar1<'a>, + ) -> impl PinInit<Self, Error> + 'a { try_pin_init!(Self { vmm <- new_mutex!( Vmm::new(pdb_addr, chipset.mmu_version(), va_size)?,
Signature · 1 line
2.55.0
Re: [PATCH 4/4] gpu: nova-core: mm: fix lifetime name in BarUser
Quoted 5 lines · Danilo Krummrich
BarUser should not use 'gpu as a name for its lifetime; stick to a generic 'a until we need pin-init selfref for this struct.
Signed-off-by Danilo Krummrich <[email protected]>---
Quoted 10 lines · Danilo Krummrich
Get rid of the Bar0/Bar1 type alias inconsistency and the unnecessary reference count of BarUser.
There's much more to improve, but this just crossed my way.
Danilo Krummrich (4):
gpu: nova-core: align Bar1 alias with Bar0
gpu: nova-core: remove unnecessary Arc around BarUser
gpu: nova-core: mm: get rid of Arc<BarUser> in BarUserAccess
gpu: nova-core: mm: fix lifetime name in BarUser
The series,
Quoted 1 line · Danilo Krummrich
[PATCH 0/4] nova-core: align Bar0/Bar1 and remvove unnecessary Arc
Applied, thanks!
Branch: drm-rust-next
Tree: https://gitlab.freedesktop.org/drm/rust/kernel.git
[1/4] gpu: nova-core: align Bar1 alias with Bar0
commit: c0c5d21b466c
[2/4] gpu: nova-core: remove unnecessary Arc around BarUser
commit: 224618807575[3/4] gpu: nova-core: mm: get rid of Arc<BarUser> in BarUserAccess
commit: 05e647ea4069
[ Update stale comment in run_self_test(). - Danilo ]
[4/4] gpu: nova-core: mm: fix lifetime name in BarUser
commit: bf91bd56fc46
The patches will appear in the next linux-next integration (typically within 24 hours on weekdays).
The patches are queued up for the upcoming merge window for the next major kernel release.