Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>
To: Lucas De Marchi <lucas.demarchi@intel.com>,
	intel-xe@lists.freedesktop.org
Cc: Shekhar Chauhan <shekhar.chauhan@intel.com>,
	Balasubramani Vivekanandan	
	<balasubramani.vivekanandan@intel.com>,
	Matt Roper <matthew.d.roper@intel.com>,
	 Tejas Upadhyay <tejas.upadhyay@intel.com>
Subject: Re: [PATCH 12/23] drm/xe/xe3p: Flush userptr/shrinker bo cachelines manually
Date: Tue, 14 Oct 2025 14:58:55 +0200	[thread overview]
Message-ID: <d2517d66f571e11a760cb143981b7ca238f5cd58.camel@linux.intel.com> (raw)
In-Reply-To: <20251013-xe3p-v1-12-bfb74f038215@intel.com>

Hi,

On Mon, 2025-10-13 at 20:24 -0700, Lucas De Marchi wrote:
> From: Tejas Upadhyay <tejas.upadhyay@intel.com>
> 
> Starting with Xe3p, HW will flush cachelines marked with XA only when
> media is off. We have few cases where kernel will have non-XA
> cachelines
> which needs manual flush as we postpone the invalidation.

is XA- and non-XA cachelines described somewhere in the code?

> 
> Flush asap from correctness POV to ensure non accelerated CPU copy to
> swap/shmem file will see coherent view of memory, but also from
> security
> POV where later flush can't corrupt the next user of those pages.
> 
> Signed-off-by: Tejas Upadhyay <tejas.upadhyay@intel.com>
> [ TODO: xe_device_needs_cache_flush() seems a bad name that doesn't
>   really review the context - it may need to be renamed/localized ]
> Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>

This worries me. Any dma-fence *must*, when signaled, have flushed all
caches from data resulting from the operation it marks the completion
of. The code below indicates that's not the case?

Note also that the wait for idle in xe_bo_trigger_rebind does not
guarantee that the bo is idle, just that there are no pending bind
operations.

In fault mode we have a slightly different approach to ensure data is
flushed before pages are released.

Could you elaborate a bit on how this is intendend to work.

Thanks,
Thomas


> ---
>  drivers/gpu/drm/xe/xe_bo.c      |  3 ++-
>  drivers/gpu/drm/xe/xe_device.c  | 20 ++++++++++++++++++++
>  drivers/gpu/drm/xe/xe_device.h  |  1 +
>  drivers/gpu/drm/xe/xe_userptr.c |  3 ++-
>  4 files changed, 25 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
> index 7b65020818738..05bc61d9e37cf 100644
> --- a/drivers/gpu/drm/xe/xe_bo.c
> +++ b/drivers/gpu/drm/xe/xe_bo.c
> @@ -673,7 +673,8 @@ static int xe_bo_trigger_rebind(struct xe_device
> *xe, struct xe_bo *bo,
>  
>  		if (!xe_vm_in_fault_mode(vm)) {
>  			drm_gpuvm_bo_evict(vm_bo, true);
> -			continue;
> +			if (!xe_device_needs_cache_flush(xe))
> +				continue;
>  		}
>  
>  		if (!idle) {
> diff --git a/drivers/gpu/drm/xe/xe_device.c
> b/drivers/gpu/drm/xe/xe_device.c
> index 7efa8da9e1069..168a45fe36838 100644
> --- a/drivers/gpu/drm/xe/xe_device.c
> +++ b/drivers/gpu/drm/xe/xe_device.c
> @@ -1081,6 +1081,26 @@ void xe_device_l2_flush(struct xe_device *xe)
>  	xe_force_wake_put(gt_to_fw(gt), fw_ref);
>  }
>  
> +/**
> + * xe_device_needs_cache_flush - Whether the cache needs to be
> flushed
> + * @xe: The device to check.
> + *
> + * Return: true if the device needs cache flush, false otherwise.
> + */
> +bool xe_device_needs_cache_flush(struct xe_device *xe)
> +{
> +	/*
> +	 * Xe3p will flush cachelines marked with XA only when media
> is off. We
> +	 * have few cases where kernel will have non-XA cachelines
> which needs
> +	 * manual flush and this is one of them as we postpone the
> +	 * invalidation. Flush asap from correctness POV to ensure
> non
> +	 * accelerated CPU copy to swap/shmem file will see coherent
> view of
> +	 * memory, but also from security POV where later flush
> can't corrupt
> +	 * the next user of those pages.
> +	 */
> +	return GRAPHICS_VER(xe) >= 35 && !IS_DGFX(xe);
> +}
> +
>  /**
>   * xe_device_td_flush() - Flush transient L3 cache entries
>   * @xe: The device
> diff --git a/drivers/gpu/drm/xe/xe_device.h
> b/drivers/gpu/drm/xe/xe_device.h
> index 32cc6323b7f64..15e67db44b56c 100644
> --- a/drivers/gpu/drm/xe/xe_device.h
> +++ b/drivers/gpu/drm/xe/xe_device.h
> @@ -179,6 +179,7 @@ void xe_device_snapshot_print(struct xe_device
> *xe, struct drm_printer *p);
>  u64 xe_device_canonicalize_addr(struct xe_device *xe, u64 address);
>  u64 xe_device_uncanonicalize_addr(struct xe_device *xe, u64
> address);
>  
> +bool xe_device_needs_cache_flush(struct xe_device *xe);
>  void xe_device_td_flush(struct xe_device *xe);
>  void xe_device_l2_flush(struct xe_device *xe);
>  
> diff --git a/drivers/gpu/drm/xe/xe_userptr.c
> b/drivers/gpu/drm/xe/xe_userptr.c
> index f16e92cd80904..86ce1c3ef41aa 100644
> --- a/drivers/gpu/drm/xe/xe_userptr.c
> +++ b/drivers/gpu/drm/xe/xe_userptr.c
> @@ -112,7 +112,8 @@ static void __vma_userptr_invalidate(struct xe_vm
> *vm, struct xe_userptr_vma *uv
>  				    false, MAX_SCHEDULE_TIMEOUT);
>  	XE_WARN_ON(err <= 0);
>  
> -	if (xe_vm_in_fault_mode(vm) && userptr->initial_bind) {
> +	if ((xe_vm_in_fault_mode(vm) ||
> xe_device_needs_cache_flush(vm->xe)) &&
> +	    userptr->initial_bind) {
>  		err = xe_vm_invalidate_vma(vma);
>  		XE_WARN_ON(err);
>  	}
> 


  reply	other threads:[~2025-10-14 12:59 UTC|newest]

Thread overview: 78+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-14  3:24 [PATCH 00/23] drm/xe: Add Xe3p support Lucas De Marchi
2025-10-14  3:24 ` [PATCH 01/23] drm/xe/xe3: Add support for graphics IP versions 30.04 & 30.05 Lucas De Marchi
2025-10-14  6:17   ` Shekhar Chauhan
2025-10-14 16:11   ` Matt Roper
2025-10-14  3:24 ` [PATCH 02/23] drm/xe/xe3p_lpm: Add support for media IP versions 35.00 & 35.03 Lucas De Marchi
2025-10-14  6:22   ` Shekhar Chauhan
2025-10-14 16:14   ` Matt Roper
2025-10-14  3:24 ` [PATCH 03/23] drm/xe/xe3p_lpm: Configure MAIN_GAMCTRL_QUEUE_SELECT Lucas De Marchi
2025-10-14 16:34   ` Matt Roper
2025-10-15  2:28     ` Lucas De Marchi
2025-10-15  6:36       ` Vivekanandan, Balasubramani
2025-10-15 14:03         ` Lucas De Marchi
2025-10-16 14:20           ` Vivekanandan, Balasubramani
2025-10-15 14:59       ` Matt Roper
2025-10-14  3:24 ` [PATCH 04/23] drm/xe/xe3p_lpm: Add special check in Media GT for Main GAMCTRL Lucas De Marchi
2025-10-14 16:36   ` Matt Roper
2025-10-14  3:24 ` [PATCH 05/23] drm/xe/xe3p_lpm: Stop reading the CTC_MODE register Lucas De Marchi
2025-10-14 11:58   ` Shekhar Chauhan
2025-10-14 16:52     ` Matt Roper
2025-10-15  3:41       ` Lucas De Marchi
2025-10-15  9:19         ` Vivekanandan, Balasubramani
2025-10-15 15:04           ` Matt Roper
2025-10-14 16:40   ` Matt Roper
2025-10-14 16:53     ` Matt Roper
2025-10-14  3:24 ` [PATCH 06/23] drm/xe/xe3p_lpm: Skip disabling NOA on unsupported IPs Lucas De Marchi
2025-10-14 17:04   ` Matt Roper
2025-10-14  3:24 ` [PATCH 07/23] drm/xe/xe3p_lpm: Handle MCR steering Lucas De Marchi
2025-10-15  9:56   ` Vivekanandan, Balasubramani
2025-10-14  3:24 ` [PATCH 08/23] drm/xe/xe3p: Stop programming RCU_MODE's fixed slice mode setting Lucas De Marchi
2025-10-15 12:24   ` Vivekanandan, Balasubramani
2025-10-14  3:24 ` [PATCH 09/23] drm/xe/xe3p: Determine service copy availability from fuse Lucas De Marchi
2025-10-15 20:14   ` Gustavo Sousa
2025-10-14  3:24 ` [PATCH 10/23] drm/xe/xe3p: Skip TD flush Lucas De Marchi
2025-10-14 19:35   ` Matt Roper
2025-10-14  3:24 ` [PATCH 11/23] drm/xe/xe3p: Enable L2 flush optimization feature Lucas De Marchi
2025-10-14 19:43   ` Matt Roper
2025-10-15  4:02     ` Lucas De Marchi
2025-10-14  3:24 ` [PATCH 12/23] drm/xe/xe3p: Flush userptr/shrinker bo cachelines manually Lucas De Marchi
2025-10-14 12:58   ` Thomas Hellström [this message]
2025-10-15 18:42     ` Lucas De Marchi
2025-10-14  3:24 ` [PATCH 13/23] drm/xe: Dump CURRENT_LRCA and CSMQDEBUG registers Lucas De Marchi
2025-10-14 17:24   ` Matt Roper
2025-10-15  4:07     ` Lucas De Marchi
2025-10-14  3:24 ` [PATCH 14/23] drm/xe/nvl: Define NVL-S platform Lucas De Marchi
2025-10-14  7:34   ` Shekhar Chauhan
2025-10-14  3:24 ` [PATCH 15/23] drm/xe/nvls: Define GuC firmware for NVL-S Lucas De Marchi
2025-10-15 18:49   ` Lucas De Marchi
2025-10-14  3:24 ` [PATCH 16/23] drm/xe/nvls: Attach MOCS table " Lucas De Marchi
2025-10-14  7:45   ` Shekhar Chauhan
2025-10-14  3:24 ` [PATCH 17/23] drm/xe/xe3p_xpc: Add Xe3p_XPC IP definition Lucas De Marchi
2025-10-14  8:04   ` Shekhar Chauhan
2025-10-14  8:12     ` Shekhar Chauhan
2025-10-14 17:33     ` Matt Roper
2025-10-15  2:47       ` Shekhar Chauhan
2025-10-14 17:36   ` Matt Roper
2025-10-14  3:24 ` [PATCH 18/23] drm/xe/xe3p_xpc: Add L3 bank mask Lucas De Marchi
2025-10-14 17:46   ` Matt Roper
2025-10-14  3:24 ` [PATCH 19/23] drm/xe/xe3p_xpc: Add MCR steering Lucas De Marchi
2025-10-14  3:24 ` [PATCH 20/23] drm/xe/xe3p_xpc: Add support for compute walker for non-MSIx Lucas De Marchi
2025-10-14 18:07   ` Matt Roper
2025-10-15 17:07     ` Lucas De Marchi
2025-10-15 17:12       ` Matt Roper
2025-10-14  3:24 ` [PATCH 21/23] drm/xe/xe3p_xpc: Skip compression tuning on platforms without flatccs Lucas De Marchi
2025-10-14  8:09   ` Shekhar Chauhan
2025-10-14  8:13     ` Shekhar Chauhan
2025-10-14 18:14     ` Matt Roper
2025-10-15  2:52       ` Shekhar Chauhan
2025-10-15 14:38         ` Lucas De Marchi
2025-10-15 15:34           ` Shekhar Chauhan
2025-10-14  3:24 ` [PATCH 22/23] drm/xe/xe3p_xpc: Setup PAT table Lucas De Marchi
2025-10-16 14:07   ` Vivekanandan, Balasubramani
2025-10-14  3:24 ` [PATCH 23/23] drm/xe/xe3p: Add xe3p EU stall data format Lucas De Marchi
2025-10-14 19:11   ` Matt Roper
2025-10-15 23:05     ` Harish Chegondi
2025-10-14  3:45 ` ✗ CI.checkpatch: warning for drm/xe: Add Xe3p support Patchwork
2025-10-14  3:47 ` ✓ CI.KUnit: success " Patchwork
2025-10-14  4:22 ` ✓ Xe.CI.BAT: " Patchwork
2025-10-14 12:06 ` ✓ Xe.CI.Full: " Patchwork

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=d2517d66f571e11a760cb143981b7ca238f5cd58.camel@linux.intel.com \
    --to=thomas.hellstrom@linux.intel.com \
    --cc=balasubramani.vivekanandan@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=lucas.demarchi@intel.com \
    --cc=matthew.d.roper@intel.com \
    --cc=shekhar.chauhan@intel.com \
    --cc=tejas.upadhyay@intel.com \
    /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