Skip to contentSkip to conversation

drm/amdgpu: make mcbp a per device setting

PATCH In review Alex Deucher 3 participants 5 messages Jun 16, 2023 – Jun 28, 2023

Subsystems (2)
lore
Share & tools
lore

Alex Deucher

author maintainer
#0 lore raw

PATCH 1/2 drm/amdgpu: make mcbp a per device setting

So we can selectively enable it on certain devices. No intended functional change.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 19 +++++++++++++++----
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h    |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c    |  4 ++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c   |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c   |  3 ---
 drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c     |  4 ++--
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c     |  2 +-
 7 files changed, 22 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +15 -4
index f39db4a2c2cf..78c6265fe79b 100644
@@ -2551,7 +2551,7 @@ static int amdgpu_device_ip_init(struct amdgpu_device *adev)
 			adev->ip_blocks[i].status.hw = true;
 
 			/* right after GMC hw init, we create CSA */
-			if (amdgpu_mcbp) {
+			if (adev->gfx.mcbp) {
 				r = amdgpu_allocate_static_csa(adev, &adev->virt.csa_obj,
 							       AMDGPU_GEM_DOMAIN_VRAM |
 							       AMDGPU_GEM_DOMAIN_GTT,
@@ -3672,6 +3672,18 @@ static const struct attribute *amdgpu_dev_attributes[] = {
 	NULL
 };
 
+static void amdgpu_device_set_mcbp(struct amdgpu_device *adev)
+{
+	if (amdgpu_mcbp == 1)
+		adev->gfx.mcbp = true;
+
+	if (amdgpu_sriov_vf(adev))
+		adev->gfx.mcbp = true;
+
+	if (adev->gfx.mcbp)
+		DRM_INFO("MCBP is enabled\n");
+}
+
 /**
  * amdgpu_device_init - initialize the driver
  *
@@ -3823,9 +3835,6 @@ int amdgpu_device_init(struct amdgpu_device *adev,
 	DRM_INFO("register mmio base: 0x%08X\n", (uint32_t)adev->rmmio_base);
 	DRM_INFO("register mmio size: %u\n", (unsigned)adev->rmmio_size);
 
-	if (amdgpu_mcbp)
-		DRM_INFO("MCBP is enabled\n");
-
 	/*
 	 * Reset domain needs to be present early, before XGMI hive discovered
 	 * (if any) and intitialized to use reset sem and in_gpu reset flag
@@ -3851,6 +3860,8 @@ int amdgpu_device_init(struct amdgpu_device *adev,
 	if (r)
 		return r;
 
+	amdgpu_device_set_mcbp(adev);
+
 	/* Get rid of things like offb */
 	r = drm_aperture_remove_conflicting_pci_framebuffers(adev->pdev, &amdgpu_kms_driver);
 	if (r)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +1 -0
index ce0f7a8ad4b8..a4ff515ce896 100644
@@ -434,6 +434,7 @@ struct amdgpu_gfx {
 	uint16_t 			xcc_mask;
 	uint32_t			num_xcc_per_xcp;
 	struct mutex			partition_mutex;
+	bool				mcbp; /* mid command buffer preemption */
 };
 
 struct amdgpu_gfx_ras_reg_entry {
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +2 -2
index e3531aa3c8bd..cca5a495611f 100644
@@ -805,7 +805,7 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
 		dev_info->ids_flags = 0;
 		if (adev->flags & AMD_IS_APU)
 			dev_info->ids_flags |= AMDGPU_IDS_FLAGS_FUSION;
-		if (amdgpu_mcbp)
+		if (adev->gfx.mcbp)
 			dev_info->ids_flags |= AMDGPU_IDS_FLAGS_PREEMPTION;
 		if (amdgpu_is_tmz(adev))
 			dev_info->ids_flags |= AMDGPU_IDS_FLAGS_TMZ;
@@ -1247,7 +1247,7 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
 		goto error_vm;
 	}
 
-	if (amdgpu_mcbp) {
+	if (adev->gfx.mcbp) {
 		uint64_t csa_addr = amdgpu_csa_vaddr(adev) & AMDGPU_GMC_HOLE_MASK;
 
 		r = amdgpu_map_static_csa(adev, &fpriv->vm, adev->virt.csa_obj,
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +1 -1
index 78ec3420ef85..dacf281d2b21 100644
@@ -72,7 +72,7 @@ uint64_t amdgpu_sdma_get_csa_mc_addr(struct amdgpu_ring *ring,
 	int r;
 
 	/* don't enable OS preemption on SDMA under SRIOV */
-	if (amdgpu_sriov_vf(adev) || vmid == 0 || !amdgpu_mcbp)
+	if (amdgpu_sriov_vf(adev) || vmid == 0 || !adev->gfx.mcbp)
 		return 0;
 
 	if (ring->is_mes_queue) {
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +0 -3
index 25b4d7f0bd35..41aa853a07d2 100644
@@ -66,9 +66,6 @@ void amdgpu_virt_init_setting(struct amdgpu_device *adev)
 	adev->cg_flags = 0;
 	adev->pg_flags = 0;
 
-	/* enable mcbp for sriov */
-	amdgpu_mcbp = 1;
-
 	/* Reduce kcq number to 2 to reduce latency */
 	if (amdgpu_num_kcq == -1)
 		amdgpu_num_kcq = 2;
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +2 -2
index be984f8c71c7..44af8022b89f 100644
@@ -8307,7 +8307,7 @@ static void gfx_v10_0_ring_emit_ib_gfx(struct amdgpu_ring *ring,
 
 	control |= ib->length_dw | (vmid << 24);
 
-	if (amdgpu_mcbp && (ib->flags & AMDGPU_IB_FLAG_PREEMPT)) {
+	if (ring->adev->gfx.mcbp && (ib->flags & AMDGPU_IB_FLAG_PREEMPT)) {
 		control |= INDIRECT_BUFFER_PRE_ENB(1);
 
 		if (flags & AMDGPU_IB_PREEMPTED)
@@ -8482,7 +8482,7 @@ static void gfx_v10_0_ring_emit_cntxcntl(struct amdgpu_ring *ring,
 {
 	uint32_t dw2 = 0;
 
-	if (amdgpu_mcbp)
+	if (ring->adev->gfx.mcbp)
 		gfx_v10_0_ring_emit_ce_meta(ring,
 				    (!amdgpu_sriov_vf(ring->adev) && flags & AMDGPU_IB_PREEMPTED) ? true : false);
 
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +1 -1
index 690e121d9dda..3a7af59e83ca 100644
@@ -5311,7 +5311,7 @@ static void gfx_v11_0_ring_emit_ib_gfx(struct amdgpu_ring *ring,
 
 	control |= ib->length_dw | (vmid << 24);
 
-	if (amdgpu_mcbp && (ib->flags & AMDGPU_IB_FLAG_PREEMPT)) {
+	if (ring->adev->gfx.mcbp && (ib->flags & AMDGPU_IB_FLAG_PREEMPT)) {
 		control |= INDIRECT_BUFFER_PRE_ENB(1);
 
 		if (flags & AMDGPU_IB_PREEMPTED)
Signature · 1 line
2.40.1
author maintainer
#1 lore raw

PATCH 2/2 drm/amdgpu: enable mcbp by default on gfx9

It's required for high priority queues.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 5 +++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c    | 6 +++---
 2 files changed, 8 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +5 -0
index 78c6265fe79b..3eb370b77ad9 100644
@@ -3677,6 +3677,11 @@ static void amdgpu_device_set_mcbp(struct amdgpu_device *adev)
 	if (amdgpu_mcbp == 1)
 		adev->gfx.mcbp = true;
 
+	if ((adev->ip_versions[GC_HWIP][0] >= IP_VERSION(9, 0, 0)) &&
+	    (adev->ip_versions[GC_HWIP][0] < IP_VERSION(10, 0, 0)) &&
+	    adev->gfx.num_gfx_rings)
+		adev->gfx.mcbp = true;
+
 	if (amdgpu_sriov_vf(adev))
 		adev->gfx.mcbp = true;
 
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +3 -3
index 03874371af60..308149dd7d00 100644
@@ -180,7 +180,7 @@ uint amdgpu_dc_feature_mask = 2;
 uint amdgpu_dc_debug_mask;
 uint amdgpu_dc_visual_confirm;
 int amdgpu_async_gfx_ring = 1;
-int amdgpu_mcbp;
+int amdgpu_mcbp = -1;
 int amdgpu_discovery = -1;
 int amdgpu_mes;
 int amdgpu_mes_kiq;
@@ -635,10 +635,10 @@ module_param_named(async_gfx_ring, amdgpu_async_gfx_ring, int, 0444);
 
 /**
  * DOC: mcbp (int)
- * It is used to enable mid command buffer preemption. (0 = disabled (default), 1 = enabled)
+ * It is used to enable mid command buffer preemption. (0 = disabled, 1 = enabled, -1 auto (default))
  */
 MODULE_PARM_DESC(mcbp,
-	"Enable Mid-command buffer preemption (0 = disabled (default), 1 = enabled)");
+	"Enable Mid-command buffer preemption (0 = disabled, 1 = enabled), -1 = auto (default)");
 module_param_named(mcbp, amdgpu_mcbp, int, 0444);
 
 /**
Signature · 1 line
2.40.1
#2 lore raw

RE: [PATCH 2/2] drm/amdgpu: enable mcbp by default on gfx9

[AMD Official Use Only - General]

Reviewed-and-tested-by Jiadong Zhu <[email protected]>

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Alex Deucher
Sent: Saturday, June 17, 2023 5:10 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>
Subject: [PATCH 2/2] drm/amdgpu: enable mcbp by default on gfx9

It's required for high priority queues.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 5 +++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c    | 6 +++---
 2 files changed, 8 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +5 -0
index 78c6265fe79b..3eb370b77ad9 100644
@@ -3677,6 +3677,11 @@ static void amdgpu_device_set_mcbp(struct amdgpu_device *adev)
        if (amdgpu_mcbp == 1)
                adev->gfx.mcbp = true;
 
+       if ((adev->ip_versions[GC_HWIP][0] >= IP_VERSION(9, 0, 0)) &&
+           (adev->ip_versions[GC_HWIP][0] < IP_VERSION(10, 0, 0)) &&
+           adev->gfx.num_gfx_rings)
+               adev->gfx.mcbp = true;
+
        if (amdgpu_sriov_vf(adev))
                adev->gfx.mcbp = true;
 
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +5 -2
index 03874371af60..308149dd7d00 100644
@@ -180,7 +180,7 @@ uint amdgpu_dc_feature_mask = 2;  uint amdgpu_dc_debug_mask;  uint amdgpu_dc_visual_confirm;  int amdgpu_async_gfx_ring = 1; -int amdgpu_mcbp;
+int amdgpu_mcbp = -1;
 int amdgpu_discovery = -1;
 int amdgpu_mes;
 int amdgpu_mes_kiq;
@@ -635,10 +635,10 @@ module_param_named(async_gfx_ring, amdgpu_async_gfx_ring, int, 0444);
 
 /**
  * DOC: mcbp (int)
- * It is used to enable mid command buffer preemption. (0 = disabled (default), 1 = enabled)
+ * It is used to enable mid command buffer preemption. (0 = disabled, 1
+ = enabled, -1 auto (default))
  */
 MODULE_PARM_DESC(mcbp,
-       "Enable Mid-command buffer preemption (0 = disabled (default), 1 = enabled)");
+       "Enable Mid-command buffer preemption (0 = disabled, 1 = enabled), -1
+= auto (default)");
 module_param_named(mcbp, amdgpu_mcbp, int, 0444);

/**
--
2.40.1

#3 lore raw
In reply to Alex Deucher

[AMD Official Use Only - General]

Reviewed-and-tested-by Jiadong Zhu <[email protected]>

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Alex Deucher
Sent: Saturday, June 17, 2023 5:10 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>
Subject: [PATCH 1/2] drm/amdgpu: make mcbp a per device setting

So we can selectively enable it on certain devices. No intended functional change.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 19 +++++++++++++++----
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h    |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c    |  4 ++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c   |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c   |  3 ---
 drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c     |  4 ++--
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c     |  2 +-
 7 files changed, 22 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +12 -4
index f39db4a2c2cf..78c6265fe79b 100644
@@ -2551,7 +2551,7 @@ static int amdgpu_device_ip_init(struct amdgpu_device *adev)
                        adev->ip_blocks[i].status.hw = true;
 
                        /* right after GMC hw init, we create CSA */
-                       if (amdgpu_mcbp) {
+                       if (adev->gfx.mcbp) {
                                r = amdgpu_allocate_static_csa(adev, &adev->virt.csa_obj,
                                                               AMDGPU_GEM_DOMAIN_VRAM |
                                                               AMDGPU_GEM_DOMAIN_GTT,
@@ -3672,6 +3672,18 @@ static const struct attribute *amdgpu_dev_attributes[] = {
        NULL
 };
 
+static void amdgpu_device_set_mcbp(struct amdgpu_device *adev) {
+       if (amdgpu_mcbp == 1)
+               adev->gfx.mcbp = true;
+
+       if (amdgpu_sriov_vf(adev))
+               adev->gfx.mcbp = true;
+
+       if (adev->gfx.mcbp)
+               DRM_INFO("MCBP is enabled\n");
+}
+
 /**
  * amdgpu_device_init - initialize the driver
  *
@@ -3823,9 +3835,6 @@ int amdgpu_device_init(struct amdgpu_device *adev,
        DRM_INFO("register mmio base: 0x%08X\n", (uint32_t)adev->rmmio_base);
        DRM_INFO("register mmio size: %u\n", (unsigned)adev->rmmio_size);
 
-       if (amdgpu_mcbp)
-               DRM_INFO("MCBP is enabled\n");
-
        /*
         * Reset domain needs to be present early, before XGMI hive discovered
         * (if any) and intitialized to use reset sem and in_gpu reset flag @@ -3851,6 +3860,8 @@ int amdgpu_device_init(struct amdgpu_device *adev,
        if (r)
                return r;

+ amdgpu_device_set_mcbp(adev);
+

        /* Get rid of things like offb */
        r = drm_aperture_remove_conflicting_pci_framebuffers(adev->pdev, &amdgpu_kms_driver);
        if (r)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +1 -0
index ce0f7a8ad4b8..a4ff515ce896 100644
@@ -434,6 +434,7 @@ struct amdgpu_gfx {
        uint16_t                        xcc_mask;
        uint32_t                        num_xcc_per_xcp;
        struct mutex                    partition_mutex;
+       bool                            mcbp; /* mid command buffer preemption */
 };
 
 struct amdgpu_gfx_ras_reg_entry {
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +1 -1
index e3531aa3c8bd..cca5a495611f 100644
@@ -805,7 +805,7 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
                dev_info->ids_flags = 0;
                if (adev->flags & AMD_IS_APU)
                        dev_info->ids_flags |= AMDGPU_IDS_FLAGS_FUSION;
-               if (amdgpu_mcbp)
+               if (adev->gfx.mcbp)
                        dev_info->ids_flags |= AMDGPU_IDS_FLAGS_PREEMPTION;
                if (amdgpu_is_tmz(adev))
                        dev_info->ids_flags |= AMDGPU_IDS_FLAGS_TMZ; @@ -1247,7 +1247,7 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
                goto error_vm;
        }

- if (amdgpu_mcbp) {

+       if (adev->gfx.mcbp) {
                uint64_t csa_addr = amdgpu_csa_vaddr(adev) & AMDGPU_GMC_HOLE_MASK;

                r = amdgpu_map_static_csa(adev, &fpriv->vm, adev->virt.csa_obj, diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c

index 78ec3420ef85..dacf281d2b21 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +1 -1
@@ -72,7 +72,7 @@ uint64_t amdgpu_sdma_get_csa_mc_addr(struct amdgpu_ring *ring,
        int r;
 
        /* don't enable OS preemption on SDMA under SRIOV */
-       if (amdgpu_sriov_vf(adev) || vmid == 0 || !amdgpu_mcbp)
+       if (amdgpu_sriov_vf(adev) || vmid == 0 || !adev->gfx.mcbp)
                return 0;
 
        if (ring->is_mes_queue) {
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +0 -3
index 25b4d7f0bd35..41aa853a07d2 100644
@@ -66,9 +66,6 @@ void amdgpu_virt_init_setting(struct amdgpu_device *adev)
        adev->cg_flags = 0;
        adev->pg_flags = 0;
 
-       /* enable mcbp for sriov */
-       amdgpu_mcbp = 1;
-
        /* Reduce kcq number to 2 to reduce latency */
        if (amdgpu_num_kcq == -1)
                amdgpu_num_kcq = 2;
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +2 -2
index be984f8c71c7..44af8022b89f 100644
@@ -8307,7 +8307,7 @@ static void gfx_v10_0_ring_emit_ib_gfx(struct amdgpu_ring *ring,
 
        control |= ib->length_dw | (vmid << 24);
 
-       if (amdgpu_mcbp && (ib->flags & AMDGPU_IB_FLAG_PREEMPT)) {
+       if (ring->adev->gfx.mcbp && (ib->flags & AMDGPU_IB_FLAG_PREEMPT)) {
                control |= INDIRECT_BUFFER_PRE_ENB(1);
 
                if (flags & AMDGPU_IB_PREEMPTED)
@@ -8482,7 +8482,7 @@ static void gfx_v10_0_ring_emit_cntxcntl(struct amdgpu_ring *ring,  {
        uint32_t dw2 = 0;
 
-       if (amdgpu_mcbp)
+       if (ring->adev->gfx.mcbp)
                gfx_v10_0_ring_emit_ce_meta(ring,
                                    (!amdgpu_sriov_vf(ring->adev) && flags & AMDGPU_IB_PREEMPTED) ? true : false);
 
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +1 -1
index 690e121d9dda..3a7af59e83ca 100644
@@ -5311,7 +5311,7 @@ static void gfx_v11_0_ring_emit_ib_gfx(struct amdgpu_ring *ring,
 
        control |= ib->length_dw | (vmid << 24);
 
-       if (amdgpu_mcbp && (ib->flags & AMDGPU_IB_FLAG_PREEMPT)) {
+       if (ring->adev->gfx.mcbp && (ib->flags & AMDGPU_IB_FLAG_PREEMPT)) {
                control |= INDIRECT_BUFFER_PRE_ENB(1);
 
                if (flags & AMDGPU_IB_PREEMPTED)

--
2.40.1

Acked-by on v1 1/2
#4 lore raw
In reply to Alex Deucher

Am 16.06.23 um 23:10 schrieb Alex Deucher:

Quoted 4 lines

So we can selectively enable it on certain devices. No intended functional change.

Quoted 157 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 19 +++++++++++++++----
  drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h    |  1 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c    |  4 ++--
  drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c   |  2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c   |  3 ---
  drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c     |  4 ++--
  drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c     |  2 +-
  7 files changed, 22 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +15 -4
index f39db4a2c2cf..78c6265fe79b 100644
@@ -2551,7 +2551,7 @@ static int amdgpu_device_ip_init(struct amdgpu_device *adev)
  			adev->ip_blocks[i].status.hw = true;
 
  			/* right after GMC hw init, we create CSA */
-			if (amdgpu_mcbp) {
+			if (adev->gfx.mcbp) {
  				r = amdgpu_allocate_static_csa(adev, &adev->virt.csa_obj,
  							       AMDGPU_GEM_DOMAIN_VRAM |
  							       AMDGPU_GEM_DOMAIN_GTT,
@@ -3672,6 +3672,18 @@ static const struct attribute *amdgpu_dev_attributes[] = {
  	NULL
  };
 
+static void amdgpu_device_set_mcbp(struct amdgpu_device *adev)
+{
+	if (amdgpu_mcbp == 1)
+		adev->gfx.mcbp = true;
+
+	if (amdgpu_sriov_vf(adev))
+		adev->gfx.mcbp = true;
+
+	if (adev->gfx.mcbp)
+		DRM_INFO("MCBP is enabled\n");
+}
+
  /**
   * amdgpu_device_init - initialize the driver
   *
@@ -3823,9 +3835,6 @@ int amdgpu_device_init(struct amdgpu_device *adev,
  	DRM_INFO("register mmio base: 0x%08X\n", (uint32_t)adev->rmmio_base);
  	DRM_INFO("register mmio size: %u\n", (unsigned)adev->rmmio_size);
 
-	if (amdgpu_mcbp)
-		DRM_INFO("MCBP is enabled\n");
-
  	/*
  	 * Reset domain needs to be present early, before XGMI hive discovered
  	 * (if any) and intitialized to use reset sem and in_gpu reset flag
@@ -3851,6 +3860,8 @@ int amdgpu_device_init(struct amdgpu_device *adev,
  	if (r)
  		return r;
 
+	amdgpu_device_set_mcbp(adev);
+
  	/* Get rid of things like offb */
  	r = drm_aperture_remove_conflicting_pci_framebuffers(adev->pdev, &amdgpu_kms_driver);
  	if (r)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +1 -0
index ce0f7a8ad4b8..a4ff515ce896 100644
@@ -434,6 +434,7 @@ struct amdgpu_gfx {
  	uint16_t 			xcc_mask;
  	uint32_t			num_xcc_per_xcp;
  	struct mutex			partition_mutex;
+	bool				mcbp; /* mid command buffer preemption */
  };
 
  struct amdgpu_gfx_ras_reg_entry {
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +2 -2
index e3531aa3c8bd..cca5a495611f 100644
@@ -805,7 +805,7 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
  		dev_info->ids_flags = 0;
  		if (adev->flags & AMD_IS_APU)
  			dev_info->ids_flags |= AMDGPU_IDS_FLAGS_FUSION;
-		if (amdgpu_mcbp)
+		if (adev->gfx.mcbp)
  			dev_info->ids_flags |= AMDGPU_IDS_FLAGS_PREEMPTION;
  		if (amdgpu_is_tmz(adev))
  			dev_info->ids_flags |= AMDGPU_IDS_FLAGS_TMZ;
@@ -1247,7 +1247,7 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
  		goto error_vm;
  	}
 
-	if (amdgpu_mcbp) {
+	if (adev->gfx.mcbp) {
  		uint64_t csa_addr = amdgpu_csa_vaddr(adev) & AMDGPU_GMC_HOLE_MASK;
 
  		r = amdgpu_map_static_csa(adev, &fpriv->vm, adev->virt.csa_obj,
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +1 -1
index 78ec3420ef85..dacf281d2b21 100644
@@ -72,7 +72,7 @@ uint64_t amdgpu_sdma_get_csa_mc_addr(struct amdgpu_ring *ring,
  	int r;
 
  	/* don't enable OS preemption on SDMA under SRIOV */
-	if (amdgpu_sriov_vf(adev) || vmid == 0 || !amdgpu_mcbp)
+	if (amdgpu_sriov_vf(adev) || vmid == 0 || !adev->gfx.mcbp)
  		return 0;
 
  	if (ring->is_mes_queue) {
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +0 -3
index 25b4d7f0bd35..41aa853a07d2 100644
@@ -66,9 +66,6 @@ void amdgpu_virt_init_setting(struct amdgpu_device *adev)
  	adev->cg_flags = 0;
  	adev->pg_flags = 0;
 
-	/* enable mcbp for sriov */
-	amdgpu_mcbp = 1;
-
  	/* Reduce kcq number to 2 to reduce latency */
  	if (amdgpu_num_kcq == -1)
  		amdgpu_num_kcq = 2;
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +2 -2
index be984f8c71c7..44af8022b89f 100644
@@ -8307,7 +8307,7 @@ static void gfx_v10_0_ring_emit_ib_gfx(struct amdgpu_ring *ring,
 
  	control |= ib->length_dw | (vmid << 24);
 
-	if (amdgpu_mcbp && (ib->flags & AMDGPU_IB_FLAG_PREEMPT)) {
+	if (ring->adev->gfx.mcbp && (ib->flags & AMDGPU_IB_FLAG_PREEMPT)) {
  		control |= INDIRECT_BUFFER_PRE_ENB(1);
 
  		if (flags & AMDGPU_IB_PREEMPTED)
@@ -8482,7 +8482,7 @@ static void gfx_v10_0_ring_emit_cntxcntl(struct amdgpu_ring *ring,
  {
  	uint32_t dw2 = 0;
 
-	if (amdgpu_mcbp)
+	if (ring->adev->gfx.mcbp)
  		gfx_v10_0_ring_emit_ce_meta(ring,
  				    (!amdgpu_sriov_vf(ring->adev) && flags & AMDGPU_IB_PREEMPTED) ? true : false);
 
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +1 -1
index 690e121d9dda..3a7af59e83ca 100644
@@ -5311,7 +5311,7 @@ static void gfx_v11_0_ring_emit_ib_gfx(struct amdgpu_ring *ring,
 
  	control |= ib->length_dw | (vmid << 24);
 
-	if (amdgpu_mcbp && (ib->flags & AMDGPU_IB_FLAG_PREEMPT)) {
+	if (ring->adev->gfx.mcbp && (ib->flags & AMDGPU_IB_FLAG_PREEMPT)) {
  		control |= INDIRECT_BUFFER_PRE_ENB(1);
 
  		if (flags & AMDGPU_IB_PREEMPTED)