]> Gentwo Git Trees - linux/.git/commitdiff
drm/xe/pf: Use migration-friendly GGTT auto-provisioning
authorMichal Wajdeczko <michal.wajdeczko@intel.com>
Wed, 12 Nov 2025 12:44:08 +0000 (13:44 +0100)
committerMichal Wajdeczko <michal.wajdeczko@intel.com>
Thu, 13 Nov 2025 13:32:34 +0000 (14:32 +0100)
Instead of trying very hard to find the largest fair GGTT size that
could be allocated for VFs on the current tile, pick some smaller
rounded down to power-of-two value that is more likely to be
provisioned in the same manner by the other PF instance:

  num VFs | GGTT space (MiB)
  --------+-----------------
   63..57 | 56
   56..29 | 64
   28..15 | 128
   14..8  | 256
    7..4  | 512
    3..2  | 1024
       1  | 2048 (regular PF)
       1  | 3584 (admin only PF)

Note that due to FW/HW limitations we can't share all 4GiB GGTT
address space with VFs, so for the larger (>7) number of the VFs
the change in the outcome is happening at different points than
we have in case of GuC contexts/doorbells IDs.

Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
Reviewed-by: Piotr Piórkowski <piotr.piorkowski@intel.com>
Link: https://patch.msgid.link/20251112124408.8094-1-michal.wajdeczko@intel.com
drivers/gpu/drm/xe/tests/xe_gt_sriov_pf_config_kunit.c
drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c

index cb3db3e793e159bca22bff46d583d213f49d550b..42bfc4bcfbcfe76936433829c49a4d10f11bb86d 100644 (file)
@@ -145,11 +145,57 @@ static void fair_doorbells(struct kunit *test)
                KUNIT_ASSERT_EQ(test, SZ_128, pf_profile_fair_dbs(gt, num_vfs));
 }
 
+static void fair_ggtt_1vf(struct kunit *test)
+{
+       struct xe_gt *gt = test->priv;
+       struct xe_device *xe = gt_to_xe(gt);
+
+       pf_set_admin_mode(xe, false);
+       KUNIT_ASSERT_FALSE(test, xe_sriov_pf_admin_only(xe));
+       KUNIT_EXPECT_EQ(test, SZ_2G, pf_profile_fair_ggtt(gt, 1));
+
+       pf_set_admin_mode(xe, true);
+       KUNIT_ASSERT_TRUE(test, xe_sriov_pf_admin_only(xe));
+       KUNIT_EXPECT_EQ(test, SZ_2G + SZ_1G + SZ_512M, pf_profile_fair_ggtt(gt, 1));
+}
+
+static void fair_ggtt(struct kunit *test)
+{
+       unsigned int num_vfs = (unsigned long)test->param_value;
+       struct xe_gt *gt = test->priv;
+       struct xe_device *xe = gt_to_xe(gt);
+       u64 alignment = pf_get_ggtt_alignment(gt);
+       u64 shareable = SZ_2G + SZ_1G + SZ_512M;
+
+       pf_set_admin_mode(xe, false);
+       KUNIT_ASSERT_FALSE(test, xe_sriov_pf_admin_only(xe));
+
+       KUNIT_EXPECT_TRUE(test, IS_ALIGNED(pf_profile_fair_ggtt(gt, num_vfs), alignment));
+       KUNIT_EXPECT_GE(test, shareable, num_vfs * pf_profile_fair_ggtt(gt, num_vfs));
+
+       if (num_vfs > 56)
+               KUNIT_ASSERT_EQ(test, SZ_64M - SZ_8M, pf_profile_fair_ggtt(gt, num_vfs));
+       else if (num_vfs > 28)
+               KUNIT_ASSERT_EQ(test, SZ_64M, pf_profile_fair_ggtt(gt, num_vfs));
+       else if (num_vfs > 14)
+               KUNIT_ASSERT_EQ(test, SZ_128M, pf_profile_fair_ggtt(gt, num_vfs));
+       else if (num_vfs > 7)
+               KUNIT_ASSERT_EQ(test, SZ_256M, pf_profile_fair_ggtt(gt, num_vfs));
+       else if (num_vfs > 3)
+               KUNIT_ASSERT_EQ(test, SZ_512M, pf_profile_fair_ggtt(gt, num_vfs));
+       else if (num_vfs > 1)
+               KUNIT_ASSERT_EQ(test, SZ_1G, pf_profile_fair_ggtt(gt, num_vfs));
+       else
+               KUNIT_ASSERT_EQ(test, SZ_2G, pf_profile_fair_ggtt(gt, num_vfs));
+}
+
 static struct kunit_case pf_gt_config_test_cases[] = {
        KUNIT_CASE(fair_contexts_1vf),
        KUNIT_CASE(fair_doorbells_1vf),
+       KUNIT_CASE(fair_ggtt_1vf),
        KUNIT_CASE_PARAM(fair_contexts, num_vfs_gen_param),
        KUNIT_CASE_PARAM(fair_doorbells, num_vfs_gen_param),
+       KUNIT_CASE_PARAM(fair_ggtt, num_vfs_gen_param),
        {}
 };
 
index 9c14f029613554cd7b76f4b9419215daa1141626..62f6cc45a7640ede51c2b1a31865140bf2ba9bc3 100644 (file)
@@ -9,6 +9,7 @@
 #include "abi/guc_actions_sriov_abi.h"
 #include "abi/guc_klvs_abi.h"
 
+#include "regs/xe_gtt_defs.h"
 #include "regs/xe_guc_regs.h"
 
 #include "xe_bo.h"
@@ -697,6 +698,22 @@ static u64 pf_estimate_fair_ggtt(struct xe_gt *gt, unsigned int num_vfs)
        return fair;
 }
 
+static u64 pf_profile_fair_ggtt(struct xe_gt *gt, unsigned int num_vfs)
+{
+       bool admin_only_pf = xe_sriov_pf_admin_only(gt_to_xe(gt));
+       u64 shareable = ALIGN_DOWN(GUC_GGTT_TOP, SZ_512M);
+       u64 alignment = pf_get_ggtt_alignment(gt);
+
+       if (admin_only_pf && num_vfs == 1)
+               return ALIGN_DOWN(shareable, alignment);
+
+       /* need to hardcode due to ~512M of GGTT being reserved */
+       if (num_vfs > 56)
+               return SZ_64M - SZ_8M;
+
+       return rounddown_pow_of_two(shareable / num_vfs);
+}
+
 /**
  * xe_gt_sriov_pf_config_set_fair_ggtt - Provision many VFs with fair GGTT.
  * @gt: the &xe_gt (can't be media)
@@ -710,6 +727,7 @@ static u64 pf_estimate_fair_ggtt(struct xe_gt *gt, unsigned int num_vfs)
 int xe_gt_sriov_pf_config_set_fair_ggtt(struct xe_gt *gt, unsigned int vfid,
                                        unsigned int num_vfs)
 {
+       u64 profile = pf_profile_fair_ggtt(gt, num_vfs);
        u64 fair;
 
        xe_gt_assert(gt, vfid);
@@ -723,6 +741,11 @@ int xe_gt_sriov_pf_config_set_fair_ggtt(struct xe_gt *gt, unsigned int vfid,
        if (!fair)
                return -ENOSPC;
 
+       fair = min(fair, profile);
+       if (fair < profile)
+               xe_gt_sriov_info(gt, "Using non-profile provisioning (%s %llu vs %llu)\n",
+                                "GGTT", fair, profile);
+
        return xe_gt_sriov_pf_config_bulk_set_ggtt(gt, vfid, num_vfs, fair);
 }