[PATCH v2 20/26] drm/xe/pf: Add helper to retrieve VF's LMEM object

Michał Winiarski posted 26 patches 3 months, 2 weeks ago
There is a newer version of this series
[PATCH v2 20/26] drm/xe/pf: Add helper to retrieve VF's LMEM object
Posted by Michał Winiarski 3 months, 2 weeks ago
From: Lukasz Laguna <lukasz.laguna@intel.com>

Instead of accessing VF's lmem_obj directly, introduce a helper function
to make the access more convenient.

Signed-off-by: Lukasz Laguna <lukasz.laguna@intel.com>
Signed-off-by: Michał Winiarski <michal.winiarski@intel.com>
---
 drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c | 31 ++++++++++++++++++++++
 drivers/gpu/drm/xe/xe_gt_sriov_pf_config.h |  1 +
 2 files changed, 32 insertions(+)

diff --git a/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c b/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c
index c857879e28fe5..28d648c386487 100644
--- a/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c
+++ b/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c
@@ -1643,6 +1643,37 @@ int xe_gt_sriov_pf_config_bulk_set_lmem(struct xe_gt *gt, unsigned int vfid,
 					   "LMEM", n, err);
 }
 
+static struct xe_bo *pf_get_vf_config_lmem_obj(struct xe_gt *gt, unsigned int vfid)
+{
+	struct xe_gt_sriov_config *config = pf_pick_vf_config(gt, vfid);
+
+	return config->lmem_obj;
+}
+
+/**
+ * xe_gt_sriov_pf_config_get_lmem_obj - Take a reference to the struct &xe_bo backing VF LMEM.
+ * @gt: the &xe_gt
+ * @vfid: the VF identifier
+ *
+ * This function can only be called on PF.
+ * The caller is responsible for calling xe_bo_put() on the returned object.
+ *
+ * Return: pointer to struct &xe_bo backing VF LMEM (if any).
+ */
+struct xe_bo *xe_gt_sriov_pf_config_get_lmem_obj(struct xe_gt *gt, unsigned int vfid)
+{
+	struct xe_bo *lmem_obj;
+
+	xe_gt_assert(gt, vfid);
+
+	mutex_lock(xe_gt_sriov_pf_master_mutex(gt));
+	lmem_obj = pf_get_vf_config_lmem_obj(gt, vfid);
+	xe_bo_get(lmem_obj);
+	mutex_unlock(xe_gt_sriov_pf_master_mutex(gt));
+
+	return lmem_obj;
+}
+
 static u64 pf_query_free_lmem(struct xe_gt *gt)
 {
 	struct xe_tile *tile = gt->tile;
diff --git a/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.h b/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.h
index 6916b8f58ebf2..03c5dc0cd5fef 100644
--- a/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.h
+++ b/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.h
@@ -36,6 +36,7 @@ int xe_gt_sriov_pf_config_set_lmem(struct xe_gt *gt, unsigned int vfid, u64 size
 int xe_gt_sriov_pf_config_set_fair_lmem(struct xe_gt *gt, unsigned int vfid, unsigned int num_vfs);
 int xe_gt_sriov_pf_config_bulk_set_lmem(struct xe_gt *gt, unsigned int vfid, unsigned int num_vfs,
 					u64 size);
+struct xe_bo *xe_gt_sriov_pf_config_get_lmem_obj(struct xe_gt *gt, unsigned int vfid);
 
 u32 xe_gt_sriov_pf_config_get_exec_quantum(struct xe_gt *gt, unsigned int vfid);
 int xe_gt_sriov_pf_config_set_exec_quantum(struct xe_gt *gt, unsigned int vfid, u32 exec_quantum);
-- 
2.50.1

Re: [PATCH v2 20/26] drm/xe/pf: Add helper to retrieve VF's LMEM object
Posted by Michal Wajdeczko 3 months, 2 weeks ago

On 10/22/2025 12:41 AM, Michał Winiarski wrote:
> From: Lukasz Laguna <lukasz.laguna@intel.com>
> 
> Instead of accessing VF's lmem_obj directly, introduce a helper function
> to make the access more convenient.
> 
> Signed-off-by: Lukasz Laguna <lukasz.laguna@intel.com>
> Signed-off-by: Michał Winiarski <michal.winiarski@intel.com>
> ---
>  drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c | 31 ++++++++++++++++++++++
>  drivers/gpu/drm/xe/xe_gt_sriov_pf_config.h |  1 +
>  2 files changed, 32 insertions(+)
> 
> diff --git a/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c b/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c
> index c857879e28fe5..28d648c386487 100644
> --- a/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c
> +++ b/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c
> @@ -1643,6 +1643,37 @@ int xe_gt_sriov_pf_config_bulk_set_lmem(struct xe_gt *gt, unsigned int vfid,
>  					   "LMEM", n, err);
>  }
>  
> +static struct xe_bo *pf_get_vf_config_lmem_obj(struct xe_gt *gt, unsigned int vfid)
> +{
> +	struct xe_gt_sriov_config *config = pf_pick_vf_config(gt, vfid);
> +
> +	return config->lmem_obj;
> +}
> +
> +/**
> + * xe_gt_sriov_pf_config_get_lmem_obj - Take a reference to the struct &xe_bo backing VF LMEM.

    * xe_gt_sriov_pf_config_get_lmem_obj() - Take ...

> + * @gt: the &xe_gt
> + * @vfid: the VF identifier

since you assert vfid below, add "(can't be 0)"

> + *
> + * This function can only be called on PF.
> + * The caller is responsible for calling xe_bo_put() on the returned object.
> + *
> + * Return: pointer to struct &xe_bo backing VF LMEM (if any).
> + */
> +struct xe_bo *xe_gt_sriov_pf_config_get_lmem_obj(struct xe_gt *gt, unsigned int vfid)
> +{
> +	struct xe_bo *lmem_obj;
> +
> +	xe_gt_assert(gt, vfid);
> +
> +	mutex_lock(xe_gt_sriov_pf_master_mutex(gt));
> +	lmem_obj = pf_get_vf_config_lmem_obj(gt, vfid);
> +	xe_bo_get(lmem_obj);
> +	mutex_unlock(xe_gt_sriov_pf_master_mutex(gt));
> +
> +	return lmem_obj;

or just

{
	guard(mutex)(xe_gt_sriov_pf_master_mutex(gt));

	return xe_bo_get(pf_get_vf_config_lmem_obj(gt, vfid));
}

> +}
> +
>  static u64 pf_query_free_lmem(struct xe_gt *gt)
>  {
>  	struct xe_tile *tile = gt->tile;
> diff --git a/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.h b/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.h
> index 6916b8f58ebf2..03c5dc0cd5fef 100644
> --- a/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.h
> +++ b/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.h
> @@ -36,6 +36,7 @@ int xe_gt_sriov_pf_config_set_lmem(struct xe_gt *gt, unsigned int vfid, u64 size
>  int xe_gt_sriov_pf_config_set_fair_lmem(struct xe_gt *gt, unsigned int vfid, unsigned int num_vfs);
>  int xe_gt_sriov_pf_config_bulk_set_lmem(struct xe_gt *gt, unsigned int vfid, unsigned int num_vfs,
>  					u64 size);
> +struct xe_bo *xe_gt_sriov_pf_config_get_lmem_obj(struct xe_gt *gt, unsigned int vfid);
>  
>  u32 xe_gt_sriov_pf_config_get_exec_quantum(struct xe_gt *gt, unsigned int vfid);
>  int xe_gt_sriov_pf_config_set_exec_quantum(struct xe_gt *gt, unsigned int vfid, u32 exec_quantum);

probably we should block VF's reprovisioning during the SAVE/RESTORE,
but that could be done later as follow up

Reviewed-by: Michal Wajdeczko <michal.wajdeczko@intel.com>

Re: [PATCH v2 20/26] drm/xe/pf: Add helper to retrieve VF's LMEM object
Posted by Michał Winiarski 3 months, 1 week ago
On Thu, Oct 23, 2025 at 10:25:08PM +0200, Michal Wajdeczko wrote:
> 
> 
> On 10/22/2025 12:41 AM, Michał Winiarski wrote:
> > From: Lukasz Laguna <lukasz.laguna@intel.com>
> > 
> > Instead of accessing VF's lmem_obj directly, introduce a helper function
> > to make the access more convenient.
> > 
> > Signed-off-by: Lukasz Laguna <lukasz.laguna@intel.com>
> > Signed-off-by: Michał Winiarski <michal.winiarski@intel.com>
> > ---
> >  drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c | 31 ++++++++++++++++++++++
> >  drivers/gpu/drm/xe/xe_gt_sriov_pf_config.h |  1 +
> >  2 files changed, 32 insertions(+)
> > 
> > diff --git a/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c b/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c
> > index c857879e28fe5..28d648c386487 100644
> > --- a/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c
> > +++ b/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c
> > @@ -1643,6 +1643,37 @@ int xe_gt_sriov_pf_config_bulk_set_lmem(struct xe_gt *gt, unsigned int vfid,
> >  					   "LMEM", n, err);
> >  }
> >  
> > +static struct xe_bo *pf_get_vf_config_lmem_obj(struct xe_gt *gt, unsigned int vfid)
> > +{
> > +	struct xe_gt_sriov_config *config = pf_pick_vf_config(gt, vfid);
> > +
> > +	return config->lmem_obj;
> > +}
> > +
> > +/**
> > + * xe_gt_sriov_pf_config_get_lmem_obj - Take a reference to the struct &xe_bo backing VF LMEM.
> 
>     * xe_gt_sriov_pf_config_get_lmem_obj() - Take ...

Ok.

> 
> > + * @gt: the &xe_gt
> > + * @vfid: the VF identifier
> 
> since you assert vfid below, add "(can't be 0)"

Ok.

> 
> > + *
> > + * This function can only be called on PF.
> > + * The caller is responsible for calling xe_bo_put() on the returned object.
> > + *
> > + * Return: pointer to struct &xe_bo backing VF LMEM (if any).
> > + */
> > +struct xe_bo *xe_gt_sriov_pf_config_get_lmem_obj(struct xe_gt *gt, unsigned int vfid)
> > +{
> > +	struct xe_bo *lmem_obj;
> > +
> > +	xe_gt_assert(gt, vfid);
> > +
> > +	mutex_lock(xe_gt_sriov_pf_master_mutex(gt));
> > +	lmem_obj = pf_get_vf_config_lmem_obj(gt, vfid);
> > +	xe_bo_get(lmem_obj);
> > +	mutex_unlock(xe_gt_sriov_pf_master_mutex(gt));
> > +
> > +	return lmem_obj;
> 
> or just
> 
> {
> 	guard(mutex)(xe_gt_sriov_pf_master_mutex(gt));
> 
> 	return xe_bo_get(pf_get_vf_config_lmem_obj(gt, vfid));
> }

Ok.

> 
> > +}
> > +
> >  static u64 pf_query_free_lmem(struct xe_gt *gt)
> >  {
> >  	struct xe_tile *tile = gt->tile;
> > diff --git a/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.h b/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.h
> > index 6916b8f58ebf2..03c5dc0cd5fef 100644
> > --- a/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.h
> > +++ b/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.h
> > @@ -36,6 +36,7 @@ int xe_gt_sriov_pf_config_set_lmem(struct xe_gt *gt, unsigned int vfid, u64 size
> >  int xe_gt_sriov_pf_config_set_fair_lmem(struct xe_gt *gt, unsigned int vfid, unsigned int num_vfs);
> >  int xe_gt_sriov_pf_config_bulk_set_lmem(struct xe_gt *gt, unsigned int vfid, unsigned int num_vfs,
> >  					u64 size);
> > +struct xe_bo *xe_gt_sriov_pf_config_get_lmem_obj(struct xe_gt *gt, unsigned int vfid);
> >  
> >  u32 xe_gt_sriov_pf_config_get_exec_quantum(struct xe_gt *gt, unsigned int vfid);
> >  int xe_gt_sriov_pf_config_set_exec_quantum(struct xe_gt *gt, unsigned int vfid, u32 exec_quantum);
> 
> probably we should block VF's reprovisioning during the SAVE/RESTORE,
> but that could be done later as follow up

Yeah - I ended up leaving it out of this series.
But the general work-in-progress idea was to block provisioning access
from userspace if we're in any WIP state.

> 
> Reviewed-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
> 

Thanks,
-Michał