accel/ivpu: Limit SSIDs to 128 on all generations
Karol Wachowski
maintainerPATCH v2 1/1 accel/ivpu: Limit SSIDs to 128 on all generations
Some generations support only 128 SSIDs, while the KMD configured 256 CD table entries and allowed user contexts up to SSID 130. Align the limit across all generations.
Limit the CD table to 128 entries and the user SSID range to 2-127, so root can create 126 contexts and non-root users 64. Also fix the off by one SSID bounds checks against the CD table size.
Before this patch the driver allowed 128 user contexts. Now the limit is 128 SSIDs in total, which leaves 126 user contexts, so the only cost is 2 contexts for root. Non-root users keep 64. In return the SSID range, the CD table size and the bounds checks all match, testing gets simpler because exact limits can be checked instead of loose minimums, and the userspace interface is consistent with the same limits on all generations.
---
v1: https://lore.kernel.org/all/[email protected]/
v2:
- Explain in the commit message why the limit is applied to all
generations: it costs only 2 contexts for root (128 -> 126), simplifies testing and makes the userspace interface consistent (Jeff)
drivers/accel/ivpu/ivpu_drv.c | 2 +- drivers/accel/ivpu/ivpu_drv.h | 3 ++- drivers/accel/ivpu/ivpu_mmu.c | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-)
drivers/accel/ivpu/ivpu_drv.c +1 -1
@@ -127,7 +127,7 @@ static struct ivpu_user_limits *ivpu_user_limits_alloc(struct ivpu_device *vdev, limits->max_ctx_count =ivpu_get_context_count (vdev); limits->max_db_count =ivpu_get_doorbell_count (vdev); }else { - limits->max_ctx_count =ivpu_get_context_count (vdev) /2 ; + limits->max_ctx_count =IVPU_NON_ROOT_USER_MAX_CONTEXTS ; limits->max_db_count =ivpu_get_doorbell_count (vdev) /2 ; }
drivers/accel/ivpu/ivpu_drv.h +2 -1
@@ -38,7 +38,8 @@/* SSID 1 is used by the VPU to represent reserved context */ #define IVPU_RESERVED_CONTEXT_MMU_SSID 1#define IVPU_USER_CONTEXT_MIN_SSID 2 -#define IVPU_USER_CONTEXT_MAX_SSID (IVPU_USER_CONTEXT_MIN_SSID + 128) +#define IVPU_USER_CONTEXT_MAX_SSID 127 +#define IVPU_NON_ROOT_USER_MAX_CONTEXTS 64#define IVPU_MIN_DB 1#define IVPU_MAX_DB 255
drivers/accel/ivpu/ivpu_mmu.c +3 -3
@@ -65,7 +65,7 @@#define IVPU_MMU_IDR5_REF_FPGA 0x00800075#define IVPU_MMU_CDTAB_ENT_SIZE 64 -#define IVPU_MMU_CDTAB_ENT_COUNT_LOG2 8/* 256 entries */ +#define IVPU_MMU_CDTAB_ENT_COUNT_LOG2 7/* 128 entries */ #define IVPU_MMU_CDTAB_ENT_COUNT ((u32)1 << IVPU_MMU_CDTAB_ENT_COUNT_LOG2)#define IVPU_MMU_STREAM_ID0 0
@@ -700,7 +700,7 @@ static int ivpu_mmu_cdtab_entry_set(struct ivpu_device *vdev, u32 ssid, u64 cd_du64 cd[4 ];int ret =0 ; -if (ssid >IVPU_MMU_CDTAB_ENT_COUNT ) +if (ssid >=IVPU_MMU_CDTAB_ENT_COUNT )return -EINVAL ; entry = cdtab->base + (ssid *IVPU_MMU_CDTAB_ENT_SIZE );
@@ -918,7 +918,7 @@ int ivpu_mmu_disable_ssid_events(struct ivpu_device *vdev, u32 ssid)u64 *entry;u64 val; -if (ssid >IVPU_MMU_CDTAB_ENT_COUNT ) +if (ssid >=IVPU_MMU_CDTAB_ENT_COUNT )return -EINVAL ;mutex_lock (&mmu->lock);
Signature · 1 line
2.43.0
Quoted 16 lines · Karol Wachowski
Some generations support only 128 SSIDs, while the KMD configured 256 CD table entries and allowed user contexts up to SSID 130. Align the limit across all generations.
Limit the CD table to 128 entries and the user SSID range to 2-127, so root can create 126 contexts and non-root users 64. Also fix the off by one SSID bounds checks against the CD table size.
Before this patch the driver allowed 128 user contexts. Now the limit is 128 SSIDs in total, which leaves 126 user contexts, so the only cost is 2 contexts for root. Non-root users keep 64. In return the SSID range, the CD table size and the bounds checks all match, testing gets simpler because exact limits can be checked instead of loose minimums, and the userspace interface is consistent with the same limits on all generations.
Quoted 1 line
Signed-off-by Karol Wachowski <[email protected]>
Quoted 17 lines · Jeff Hugo
Quoted 16 lines · Karol Wachowski
Some generations support only 128 SSIDs, while the KMD configured 256 CD table entries and allowed user contexts up to SSID 130. Align the limit across all generations.
Limit the CD table to 128 entries and the user SSID range to 2-127, so root can create 126 contexts and non-root users 64. Also fix the off by one SSID bounds checks against the CD table size.
Before this patch the driver allowed 128 user contexts. Now the limit is 128 SSIDs in total, which leaves 126 user contexts, so the only cost is 2 contexts for root. Non-root users keep 64. In return the SSID range, the CD table size and the bounds checks all match, testing gets simpler because exact limits can be checked instead of loose minimums, and the userspace interface is consistent with the same limits on all generations.
Quoted 2 lines
Quoted 1 line
Signed-off-by Karol Wachowski <[email protected]>Reviewed-by Jeff Hugo <[email protected]>
Thank you! applied to drm-misc-next.