Skip to contentSkip to conversation

drm/amdgpu: Toggle msix after FLR for sriov

PATCH In review Emily Deng 2 participants 5 messages Mar 30, 2021

Subsystems (2)
lore
Share & tools
lore

Emily Deng

author
#0 lore raw

PATCH 1/1 drm/amdgpu: Toggle msix after FLR for sriov

From: "Emily.Deng" <[email protected]>

After FLR, the msix will be cleared, so need to toggle it for sriov.

v2:
Change name with amdgpu_irq prefix, remove #ifdef.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +14 -0
index 03412543427a..3045f52e613d 100644
@@ -277,6 +277,17 @@ static bool amdgpu_msi_ok(struct amdgpu_device *adev)
 	return true;
 }
 
+static void amdgpu_irq_restore_msix(struct amdgpu_device *adev)
+{
+	u16 ctrl;
+
+	pci_read_config_word(adev->pdev, adev->pdev->msix_cap + PCI_MSIX_FLAGS, &ctrl);
+	ctrl &= ~PCI_MSIX_FLAGS_ENABLE;
+	pci_write_config_word(adev->pdev, adev->pdev->msix_cap + PCI_MSIX_FLAGS, ctrl);
+	ctrl |= PCI_MSIX_FLAGS_ENABLE;
+	pci_write_config_word(adev->pdev, adev->pdev->msix_cap + PCI_MSIX_FLAGS, ctrl);
+}
+
 /**
  * amdgpu_irq_init - initialize interrupt handling
  *
@@ -558,6 +569,9 @@ void amdgpu_irq_gpu_reset_resume_helper(struct amdgpu_device *adev)
 {
 	int i, j, k;
 
+	if (amdgpu_sriov_vf(adev))
+		amdgpu_irq_restore_msix(adev);
+
 	for (i = 0; i < AMDGPU_IRQ_CLIENTID_MAX; ++i) {
 		if (!adev->irq.client[i].sources)
 			continue;
Signature · 6 lines
2.25.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#1 lore raw
Quoted 19 lines · Emily Deng

From: "Emily.Deng" <[email protected]>

After FLR, the msix will be cleared, so need to toggle it for sriov.

v2:
Change name with amdgpu_irq prefix, remove #ifdef.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c | 14 ++++++++++++++
  1 file changed, 14 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +0 -0
index 03412543427a..3045f52e613d 100644
@@ -277,6 +277,17 @@ static bool amdgpu_msi_ok(struct amdgpu_device *adev)
  	return true;
  }

drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c static bool amdgpu_msi_ok(struct amdgpu_device *adev) · line 288

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +9 -0
 
+static void amdgpu_irq_restore_msix(struct amdgpu_device *adev)
+{
+	u16 ctrl;
+
+	pci_read_config_word(adev->pdev, adev->pdev->msix_cap + PCI_MSIX_FLAGS, &ctrl);
+	ctrl &= ~PCI_MSIX_FLAGS_ENABLE;
+	pci_write_config_word(adev->pdev, adev->pdev->msix_cap + PCI_MSIX_FLAGS, ctrl);
+	ctrl |= PCI_MSIX_FLAGS_ENABLE;
+	pci_write_config_word(adev->pdev, adev->pdev->msix_cap + PCI_MSIX_FLAGS, ctrl);

Why write 1st clear and then set the msix flag if we know that msix is already cleared.

drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c void amdgpu_irq_gpu_reset_resume_helper(struct amdgpu_device *adev) · line 573

Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +4 -0
+}
+
  /**
   * amdgpu_irq_init - initialize interrupt handling
   *
@@ -558,6 +569,9 @@ void amdgpu_irq_gpu_reset_resume_helper(struct amdgpu_device *adev)
  {
  	int i, j, k;
 
+	if (amdgpu_sriov_vf(adev))
+		amdgpu_irq_restore_msix(adev);

Is it possible to load amdgpu on guest without msix ? If so then we need to probe if msix is enabled.

Nirmoy

drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c void amdgpu_irq_gpu_reset_resume_helper(struct amdgpu_device *adev) · line 577

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +1 -0
+
  	for (i = 0; i < AMDGPU_IRQ_CLIENTID_MAX; ++i) {
  		if (!adev->irq.client[i].sources)
  			continue;

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#2 lore raw

[AMD Official Use Only - Internal Distribution Only]

Quoted 38 lines

-----Original Message-----
From: Das, Nirmoy <[email protected]>
Sent: Tuesday, March 30, 2021 4:59 PM
To: Deng, Emily <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: Toggle msix after FLR for sriov

drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c static bool amdgpu_msi_ok(struct amdgpu_device

Quoted 18 lines · Emily Deng

From: "Emily.Deng" <[email protected]>

After FLR, the msix will be cleared, so need to toggle it for sriov.

v2:
Change name with amdgpu_irq prefix, remove #ifdef.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c | 14 ++++++++++++++
  1 file changed, 14 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +0 -0
index 03412543427a..3045f52e613d 100644
@@ -277,6 +277,17 @@ static bool amdgpu_msi_ok(struct amdgpu_device

*adev)

drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c static bool amdgpu_msi_ok(struct amdgpu_device *adev)

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +4 -0
  return true;
  }
 
+static void amdgpu_irq_restore_msix(struct amdgpu_device *adev) {
+u16 ctrl;
+
+pci_read_config_word(adev->pdev, adev->pdev->msix_cap +

PCI_MSIX_FLAGS, &ctrl);

drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c static bool amdgpu_msi_ok(struct amdgpu_device · line 285

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +2 -0
+ctrl &= ~PCI_MSIX_FLAGS_ENABLE;
+pci_write_config_word(adev->pdev, adev->pdev->msix_cap +

PCI_MSIX_FLAGS, ctrl);

Quoted 7 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c static bool amdgpu_msi_ok(struct amdgpu_device · line 288

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +3 -0
+ctrl |= PCI_MSIX_FLAGS_ENABLE;
+pci_write_config_word(adev->pdev, adev->pdev->msix_cap +
+PCI_MSIX_FLAGS, ctrl);

Why write 1st clear and then set the msix flag if we know that msix is already cleared

For vf assigned to guest VM, after FLR, the msix table will be reset. As the flr is done on host driver. The qemu and vfio driver don't know
this, and the msix is still enable from qemu and vfio driver side. So if want to re-setup the msix table, first need to disable and re-enable the msix from guest VM side or the qemu will do nothing as it thought the msix is already enabled.

Quoted 21 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c void amdgpu_irq_gpu_reset_resume_helper(struct

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +2 -0
+}
+
  /**
   * amdgpu_irq_init - initialize interrupt handling
   *
@@ -558,6 +569,9 @@ void amdgpu_irq_gpu_reset_resume_helper(struct

amdgpu_device *adev)

drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c void amdgpu_irq_gpu_reset_resume_helper(struct amdgpu_device *adev) · line 573

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +2 -0
  {
  int i, j, k;
 
+if (amdgpu_sriov_vf(adev))
+amdgpu_irq_restore_msix(adev);

Is it possible to load amdgpu on guest without msix ? If so then we need to probe if msix is enabled.

Quoted 7 lines

Nirmoy

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +1 -0
+
  for (i = 0; i < AMDGPU_IRQ_CLIENTID_MAX; ++i) {
  if (!adev->irq.client[i].sources)
  continue;

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#3 lore raw
Quoted 46 lines · Emily

[AMD Official Use Only - Internal Distribution Only]

Quoted 38 lines

-----Original Message-----
From: Das, Nirmoy <[email protected]>
Sent: Tuesday, March 30, 2021 4:59 PM
To: Deng, Emily <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: Toggle msix after FLR for sriov

drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c static bool amdgpu_msi_ok(struct amdgpu_device

Quoted 18 lines · Emily Deng

From: "Emily.Deng" <[email protected]>

After FLR, the msix will be cleared, so need to toggle it for sriov.

v2:
Change name with amdgpu_irq prefix, remove #ifdef.

---
   drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c | 14 ++++++++++++++
   1 file changed, 14 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +0 -0
index 03412543427a..3045f52e613d 100644
@@ -277,6 +277,17 @@ static bool amdgpu_msi_ok(struct amdgpu_device

*adev)

drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c static bool amdgpu_msi_ok(struct amdgpu_device *adev)

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +4 -0
   return true;
   }
 
+static void amdgpu_irq_restore_msix(struct amdgpu_device *adev) {
+u16 ctrl;
+
+pci_read_config_word(adev->pdev, adev->pdev->msix_cap +

PCI_MSIX_FLAGS, &ctrl);

drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c static bool amdgpu_msi_ok(struct amdgpu_device · line 285

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +2 -0
+ctrl &= ~PCI_MSIX_FLAGS_ENABLE;
+pci_write_config_word(adev->pdev, adev->pdev->msix_cap +

PCI_MSIX_FLAGS, ctrl);

Quoted 6 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c static bool amdgpu_msi_ok(struct amdgpu_device · line 288

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +3 -0
+ctrl |= PCI_MSIX_FLAGS_ENABLE;
+pci_write_config_word(adev->pdev, adev->pdev->msix_cap +
+PCI_MSIX_FLAGS, ctrl);

Why write 1st clear and then set the msix flag if we know that msix is already cleared

Quoted 3 lines

For vf assigned to guest VM, after FLR, the msix table will be reset. As the flr is done on host driver. The qemu and vfio driver don't know
this, and the msix is still enable from qemu and vfio driver side. So if want to re-setup the msix table, first need to disable and re-enable the msix from guest VM side or the qemu will do nothing as it thought the msix is already enabled.

Thanks for the detailed explanation, Emily. Please add a comment so that we know/remember why we are doing this.

Nirmoy

Quoted 19 lines
Quoted 19 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c void amdgpu_irq_gpu_reset_resume_helper(struct

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +2 -0
+}
+
   /**
    * amdgpu_irq_init - initialize interrupt handling
    *
@@ -558,6 +569,9 @@ void amdgpu_irq_gpu_reset_resume_helper(struct

amdgpu_device *adev)

drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c void amdgpu_irq_gpu_reset_resume_helper(struct amdgpu_device *adev) · line 573

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +2 -0
   {
   int i, j, k;
 
+if (amdgpu_sriov_vf(adev))
+amdgpu_irq_restore_msix(adev);

Is it possible to load amdgpu on guest without msix ? If so then we need to probe if msix is enabled.

Quoted 7 lines
Quoted 7 lines

Nirmoy

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +1 -0
+
   for (i = 0; i < AMDGPU_IRQ_CLIENTID_MAX; ++i) {
   if (!adev->irq.client[i].sources)
   continue;

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#4 lore raw

[AMD Official Use Only - Internal Distribution Only]

Quoted 59 lines

-----Original Message-----
From: Das, Nirmoy <[email protected]>
Sent: Tuesday, March 30, 2021 5:34 PM
To: Deng, Emily <[email protected]>; Das, Nirmoy <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: Toggle msix after FLR for sriov

Quoted 22 lines · Emily

[AMD Official Use Only - Internal Distribution Only]

Quoted 20 lines

-----Original Message-----
From: Das, Nirmoy <[email protected]>
Sent: Tuesday, March 30, 2021 4:59 PM
To: Deng, Emily <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: Toggle msix after FLR for sriov

Quoted 12 lines · Emily Deng

From: "Emily.Deng" <[email protected]>

After FLR, the msix will be cleared, so need to toggle it for sriov.

v2:
Change name with amdgpu_irq prefix, remove #ifdef.

---
   drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c | 14 ++++++++++++++
   1 file changed, 14 insertions(+)
Quoted 6 lines
Quoted 6 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c static bool amdgpu_msi_ok(struct

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +0 -0
index 03412543427a..3045f52e613d 100644
@@ -277,6 +277,17 @@ static bool amdgpu_msi_ok(struct

amdgpu_device

Quoted 18 lines
Quoted 12 lines

*adev)

drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c static bool amdgpu_msi_ok(struct amdgpu_device *adev)

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +4 -0
   return true;
   }
 
+static void amdgpu_irq_restore_msix(struct amdgpu_device *adev) {
+u16 ctrl;
+
+pci_read_config_word(adev->pdev, adev->pdev->msix_cap +

PCI_MSIX_FLAGS, &ctrl);

drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c static bool amdgpu_msi_ok(struct · line 285

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +2 -0
+ctrl &= ~PCI_MSIX_FLAGS_ENABLE;
+pci_write_config_word(adev->pdev, adev->pdev->msix_cap +

PCI_MSIX_FLAGS, ctrl);

Quoted 6 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c static bool amdgpu_msi_ok(struct · line 288

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +3 -0
+ctrl |= PCI_MSIX_FLAGS_ENABLE;
+pci_write_config_word(adev->pdev, adev->pdev->msix_cap +
+PCI_MSIX_FLAGS, ctrl);

Why write 1st clear and then set the msix flag if we know that msix is already cleared

Quoted 3 lines

For vf assigned to guest VM, after FLR, the msix table will be reset. As the flr is done on host driver. The qemu and vfio driver don't know this, and the msix is still enable from qemu and vfio driver side. So if want to

Quoted 7 lines

re-setup the msix table, first need to disable and re-enable the msix from guest VM side or the qemu will do nothing as it thought the msix is already enabled.

Thanks for the detailed explanation, Emily. Please add a comment so that we know/remember why we are doing this.

Ok, will do this. Thanks.

Quoted 7 lines

Nirmoy

Quoted 2 lines
Quoted 2 lines
Quoted 16 lines
Quoted 6 lines
Quoted 6 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c void

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +2 -0
+}
+
   /**
    * amdgpu_irq_init - initialize interrupt handling
    *
@@ -558,6 +569,9 @@ void

amdgpu_irq_gpu_reset_resume_helper(struct

Quoted 9 lines
Quoted 9 lines

amdgpu_device *adev)

drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c void amdgpu_irq_gpu_reset_resume_helper(struct amdgpu_device *adev) · line 573

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +2 -0
   {
   int i, j, k;
 
+if (amdgpu_sriov_vf(adev))
+amdgpu_irq_restore_msix(adev);

Is it possible to load amdgpu on guest without msix ? If so then we need to probe if msix is enabled.

It is decided by host driver, not guest driver.

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

Nirmoy

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +1 -0
+
   for (i = 0; i < AMDGPU_IRQ_CLIENTID_MAX; ++i) {
   if (!adev->irq.client[i].sources)
   continue;

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx