dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Alvin Sun" <alvin.sun@linux.dev>
Cc: dri-devel@lists.freedesktop.org, ojeda@kernel.org, gary@garyguo.net
Subject: Re: [PATCH v7 09/10] drm/tyr: support write-combine BO mappings
Date: Sun, 22 Nov 2026 13:16:27 +0000	[thread overview]
Message-ID: <sashiko-outbox-227955@kernel.org> (raw)
In-Reply-To: <20261122-tyr-ioctls-v7-9-3a2af624b992@linux.dev>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] drm/tyr: unconditional sg_table() call in new_object() for
  write-back BOs
- [Medium] drm/tyr: should_map_wc() disables WC on coherent devices
  without GPU coherency
--

commit 86892ff5c6c9751c0ce3610b27d27ca95ece458f
Author: Sami Tolvanen <samitolvanen@google.com>

drm/tyr: support write-combine BO mappings

This commit queries device DMA coherence at probe time to decide whether
shmem-backed GEM buffer objects should be mapped write-combine or
write-back, and fetches the scatter-gather table at BO creation time to
flush zeroed pages.

> diff --git a/drivers/gpu/drm/tyr/driver.rs b/drivers/gpu/drm/tyr/driver.rs
> index ba03cc4c52539..6869ab345d8fd 100644
> --- a/drivers/gpu/drm/tyr/driver.rs
> +++ b/drivers/gpu/drm/tyr/driver.rs
[ ... ]
> @@ -151,6 +158,8 @@ fn probe<'bound>(
>              // other threads of execution.
>              unsafe { pdev.dma_set_mask_and_coherent(DmaMask::try_new(pa_bits)?)? };
>  
> +            let coherent = pdev.as_ref().dma_attr() == DmaAttr::COHERENT;
> +
>              let unreg_dev = drm::UnregisteredDevice::<TyrDrmDriver>::new(pdev, Ok(()))?;
>  
>              let mmu = Mmu::new(pdev.as_ref(), iomem.as_arc_borrow(), &gpu_info)?;
> @@ -161,6 +170,7 @@ fn probe<'bound>(
>                  &unreg_dev,
>                  mmu.as_arc_borrow(),
>                  &gpu_info,
> +                coherent,
>              )?;

[Severity: Medium]
Can enabling write-back BO mappings when DmaAttr::COHERENT is set break MCU
boot before GPU and MMU coherency are configured?

Tyr currently hardcodes non-coherent operation in the GPU and MMU:
GpuInfo::new() sets selected_coherency to DRM_PANTHOR_GPU_COHERENCY_NONE
without programming COHERENCY_ENABLE, VmAsData::new() sets coherent_walk to
false, and MEMATTR::attribute_from_mair() always encodes
Coherency::MidgardInnerDomain.  On a platform whose firmware marks the GPU
device as dma-coherent, passing coherent = true causes KernelBo::new() to
create MCU firmware section BOs with map_wc: false, so
Firmware::init_section_mem() writes firmware sections through a write-back
cached vmap without CPU cache maintenance while the MCU reads stale memory
from DRAM.

> diff --git a/drivers/gpu/drm/tyr/gem.rs b/drivers/gpu/drm/tyr/gem.rs
> index 60f6363995a5a..55e2d67b96d98 100644
> --- a/drivers/gpu/drm/tyr/gem.rs
> +++ b/drivers/gpu/drm/tyr/gem.rs
[ ... ]
> @@ -56,24 +69,48 @@ fn new(_dev: &TyrDrmDevice, _size: usize, args: BoCreateArgs) -> impl PinInit<Se
>  /// Type alias for Tyr GEM buffer objects.
>  pub(crate) type Bo = gem::shmem::Object<BoData>;
>  
> +/// Returns whether a BO should be mapped write-combine.
> +pub(crate) fn should_map_wc(coherent: bool, flags: u32) -> bool {
> +    if coherent {
> +        return false;
> +    }
> +
> +    if flags & uapi::drm_panthor_bo_flags_DRM_PANTHOR_BO_WB_MMAP != 0 {
> +        return false;
> +    }
> +
> +    true
> +}
> +
>  /// Create a new GEM buffer object.
>  #[expect(dead_code)]
> -pub(crate) fn new_object(ddev: &TyrDrmDevice, size: usize, flags: u32) -> Result<ARef<Bo>> {
> +pub(crate) fn new_object(
> +    ddev: &TyrDrmDevice,
> +    pdev: &Device<Bound>,
> +    size: usize,
> +    flags: u32,
> +    coherent: bool,
> +) -> Result<ARef<Bo>> {
>      if size == 0 {
>          return Err(EINVAL);
>      }
>  
>      let aligned_size = size.checked_next_multiple_of(PAGE_SIZE).ok_or(EINVAL)?;
>  
> -    Bo::new(
> +    let map_wc = should_map_wc(coherent, flags);
> +    let bo = Bo::new(
>          ddev,
>          aligned_size,
>          shmem::ObjectConfig {
> -            map_wc: true,
> +            map_wc,
>              parent_resv_obj: None,
>          },
>          BoCreateArgs { flags },
> -    )
> +    )?;
> +
> +    bo.sg_table(pdev)?;
> +
> +    Ok(bo)
>  }

[Severity: Medium]
Should bo.sg_table(pdev) only be called when map_wc is true?

When map_wc is false (for example with DRM_PANTHOR_BO_WB_MMAP), calling
bo.sg_table(pdev) here eagerly pins all backing pages and runs
dma_map_sgtable() at BO creation time even though CPU accesses use cached
mappings.  Because shmem::Object::sg_table() caches the result in a SetOnce,
consuming that one-shot dma_map_sgtable() call before userspace writes to
the write-back mapping also means the later sg_table() call in
GpuVmData::sm_step_map() during VM_BIND returns the cached table without
flushing dirty CPU cache lines.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261122-tyr-ioctls-v7-0-3a2af624b992@linux.dev?part=9

  reply	other threads:[~2026-11-22 13:16 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-22 12:50 [PATCH v7 00/10] drm/tyr: add VM and BO ioctl support Alvin Sun
2026-11-22 12:50 ` [PATCH v7 01/10] rust: sizes: add SZ_4G constant Alvin Sun
2026-11-22 12:50 ` [PATCH v7 02/10] rust: task: add task_size() Alvin Sun
2026-11-25 14:45   ` Daniel Almeida
2026-11-22 12:50 ` [PATCH v7 03/10] rust: sync: arc: relax `ForeignOwnable` for `Arc<T>` Alvin Sun
2026-11-22 12:50 ` [PATCH v7 04/10] drm/tyr: add per-file VM pool Alvin Sun
2026-11-24 23:43   ` Deborah Brouwer
2026-11-25 15:14   ` Daniel Almeida
2026-11-22 12:50 ` [PATCH v7 05/10] drm/tyr: add user and MCU VM specifications Alvin Sun
2026-11-25 16:13   ` Daniel Almeida
2026-11-22 12:50 ` [PATCH v7 06/10] drm/tyr: add BO creation and lookup helpers Alvin Sun
2026-11-22 12:50 ` [PATCH v7 07/10] drm/tyr: add VM-related ioctls Alvin Sun
2026-11-22 13:19   ` sashiko-bot
2026-11-24 23:40   ` Deborah Brouwer
2026-11-25 18:49   ` Daniel Almeida
2026-11-22 12:50 ` [PATCH v7 08/10] rust: device: expose the device DMA attribute Alvin Sun
2026-11-25 18:52   ` Daniel Almeida
2026-11-22 12:50 ` [PATCH v7 09/10] drm/tyr: support write-combine BO mappings Alvin Sun
2026-11-22 13:16   ` sashiko-bot [this message]
2026-11-25 19:59   ` Daniel Almeida
2026-11-22 12:50 ` [PATCH v7 10/10] drm/tyr: add BO-related ioctls Alvin Sun
2026-11-22 13:15   ` sashiko-bot
2026-11-25 21:02   ` Daniel Almeida
2026-11-23 22:25 ` [PATCH v7 00/10] drm/tyr: add VM and BO ioctl support Daniel Almeida

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-227955@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=alvin.sun@linux.dev \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gary@garyguo.net \
    --cc=ojeda@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox