All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iommu/amd: Fix interrupt remapping when disable guest_mode
@ 2017-06-23 11:56 ` Suravee Suthikulpanit
  0 siblings, 0 replies; 4+ messages in thread
From: Suravee Suthikulpanit @ 2017-06-23 11:56 UTC (permalink / raw)
  To: iommu, linux-kernel; +Cc: joro, Suravee Suthikulpanit, Joerg Roedel

Pass-through devices to VM guest can get updated affinity
information via irq_set_affinity(). Currently, AMD IOMMU driver
in GA mode ignores the updated information if the pass-through
device is setup to use vAPIC, which could cause invalid interrupt
remapping when not running in guest_mode.

Also, the guest_mode bit should be set and cleared only when
SVM updates posted-interrupt information via irq_set_vcpu_affinity().

Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
Cc: Joerg Roedel <jroedel@suse.de>
---
 drivers/iommu/amd_iommu.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index b17536d6..1055863 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -3883,7 +3883,6 @@ static void irte_ga_prepare(void *entry,
 
 	irte->lo.val                      = 0;
 	irte->hi.val                      = 0;
-	irte->lo.fields_remap.guest_mode  = dev_data ? dev_data->use_vapic : 0;
 	irte->lo.fields_remap.int_type    = delivery_mode;
 	irte->lo.fields_remap.dm          = dest_mode;
 	irte->hi.fields.vector            = vector;
@@ -3939,10 +3938,10 @@ static void irte_ga_set_affinity(void *entry, u16 devid, u16 index,
 	struct irte_ga *irte = (struct irte_ga *) entry;
 	struct iommu_dev_data *dev_data = search_dev_data(devid);
 
-	if (!dev_data || !dev_data->use_vapic) {
+	if (!dev_data || !dev_data->use_vapic ||
+	    !irte->lo.fields_remap.guest_mode) {
 		irte->hi.fields.vector = vector;
 		irte->lo.fields_remap.destination = dest_apicid;
-		irte->lo.fields_remap.guest_mode = 0;
 		modify_irte_ga(devid, index, irte, NULL);
 	}
 }
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH] iommu/amd: Fix interrupt remapping when disable guest_mode
@ 2017-06-23 11:56 ` Suravee Suthikulpanit
  0 siblings, 0 replies; 4+ messages in thread
From: Suravee Suthikulpanit @ 2017-06-23 11:56 UTC (permalink / raw)
  To: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA
  Cc: Joerg Roedel

Pass-through devices to VM guest can get updated affinity
information via irq_set_affinity(). Currently, AMD IOMMU driver
in GA mode ignores the updated information if the pass-through
device is setup to use vAPIC, which could cause invalid interrupt
remapping when not running in guest_mode.

Also, the guest_mode bit should be set and cleared only when
SVM updates posted-interrupt information via irq_set_vcpu_affinity().

Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit-5C7GfCeVMHo@public.gmane.org>
Cc: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
---
 drivers/iommu/amd_iommu.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index b17536d6..1055863 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -3883,7 +3883,6 @@ static void irte_ga_prepare(void *entry,
 
 	irte->lo.val                      = 0;
 	irte->hi.val                      = 0;
-	irte->lo.fields_remap.guest_mode  = dev_data ? dev_data->use_vapic : 0;
 	irte->lo.fields_remap.int_type    = delivery_mode;
 	irte->lo.fields_remap.dm          = dest_mode;
 	irte->hi.fields.vector            = vector;
@@ -3939,10 +3938,10 @@ static void irte_ga_set_affinity(void *entry, u16 devid, u16 index,
 	struct irte_ga *irte = (struct irte_ga *) entry;
 	struct iommu_dev_data *dev_data = search_dev_data(devid);
 
-	if (!dev_data || !dev_data->use_vapic) {
+	if (!dev_data || !dev_data->use_vapic ||
+	    !irte->lo.fields_remap.guest_mode) {
 		irte->hi.fields.vector = vector;
 		irte->lo.fields_remap.destination = dest_apicid;
-		irte->lo.fields_remap.guest_mode = 0;
 		modify_irte_ga(devid, index, irte, NULL);
 	}
 }
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] iommu/amd: Fix interrupt remapping when disable guest_mode
@ 2017-06-24 16:43   ` kbuild test robot
  0 siblings, 0 replies; 4+ messages in thread
From: kbuild test robot @ 2017-06-24 16:43 UTC (permalink / raw)
  To: Suravee Suthikulpanit
  Cc: kbuild-all, iommu, linux-kernel, joro, Suravee Suthikulpanit,
	Joerg Roedel

[-- Attachment #1: Type: text/plain, Size: 3331 bytes --]

Hi Suravee,

[auto build test WARNING on iommu/next]
[also build test WARNING on v4.12-rc6 next-20170623]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Suravee-Suthikulpanit/iommu-amd-Fix-interrupt-remapping-when-disable-guest_mode/20170624-162701
base:   https://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu.git next
config: x86_64-randconfig-b0-06242320 (attached as .config)
compiler: gcc-4.4 (Debian 4.4.7-8) 4.4.7
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

All warnings (new ones prefixed by >>):

   drivers/iommu/amd_iommu.c: In function 'irte_ga_prepare':
>> drivers/iommu/amd_iommu.c:4002: warning: unused variable 'dev_data'

vim +/dev_data +4002 drivers/iommu/amd_iommu.c

880ac60e Suravee Suthikulpanit 2016-08-23  3986  {
880ac60e Suravee Suthikulpanit 2016-08-23  3987  	union irte *irte = (union irte *) entry;
880ac60e Suravee Suthikulpanit 2016-08-23  3988  
880ac60e Suravee Suthikulpanit 2016-08-23  3989  	irte->val                = 0;
880ac60e Suravee Suthikulpanit 2016-08-23  3990  	irte->fields.vector      = vector;
880ac60e Suravee Suthikulpanit 2016-08-23  3991  	irte->fields.int_type    = delivery_mode;
880ac60e Suravee Suthikulpanit 2016-08-23  3992  	irte->fields.destination = dest_apicid;
880ac60e Suravee Suthikulpanit 2016-08-23  3993  	irte->fields.dm          = dest_mode;
880ac60e Suravee Suthikulpanit 2016-08-23  3994  	irte->fields.valid       = 1;
880ac60e Suravee Suthikulpanit 2016-08-23  3995  }
880ac60e Suravee Suthikulpanit 2016-08-23  3996  
880ac60e Suravee Suthikulpanit 2016-08-23  3997  static void irte_ga_prepare(void *entry,
880ac60e Suravee Suthikulpanit 2016-08-23  3998  			    u32 delivery_mode, u32 dest_mode,
d98de49a Suravee Suthikulpanit 2016-08-23  3999  			    u8 vector, u32 dest_apicid, int devid)
880ac60e Suravee Suthikulpanit 2016-08-23  4000  {
880ac60e Suravee Suthikulpanit 2016-08-23  4001  	struct irte_ga *irte = (struct irte_ga *) entry;
d98de49a Suravee Suthikulpanit 2016-08-23 @4002  	struct iommu_dev_data *dev_data = search_dev_data(devid);
880ac60e Suravee Suthikulpanit 2016-08-23  4003  
880ac60e Suravee Suthikulpanit 2016-08-23  4004  	irte->lo.val                      = 0;
880ac60e Suravee Suthikulpanit 2016-08-23  4005  	irte->hi.val                      = 0;
880ac60e Suravee Suthikulpanit 2016-08-23  4006  	irte->lo.fields_remap.int_type    = delivery_mode;
880ac60e Suravee Suthikulpanit 2016-08-23  4007  	irte->lo.fields_remap.dm          = dest_mode;
880ac60e Suravee Suthikulpanit 2016-08-23  4008  	irte->hi.fields.vector            = vector;
880ac60e Suravee Suthikulpanit 2016-08-23  4009  	irte->lo.fields_remap.destination = dest_apicid;
880ac60e Suravee Suthikulpanit 2016-08-23  4010  	irte->lo.fields_remap.valid       = 1;

:::::: The code at line 4002 was first introduced by commit
:::::: d98de49a53e48f51332e97568127e722415e1232 iommu/amd: Enable vAPIC interrupt remapping mode by default

:::::: TO: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
:::::: CC: Joerg Roedel <jroedel@suse.de>

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 21363 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] iommu/amd: Fix interrupt remapping when disable guest_mode
@ 2017-06-24 16:43   ` kbuild test robot
  0 siblings, 0 replies; 4+ messages in thread
From: kbuild test robot @ 2017-06-24 16:43 UTC (permalink / raw)
  To: Suravee Suthikulpanit
  Cc: Joerg Roedel, linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	kbuild-all-JC7UmRfGjtg

[-- Attachment #1: Type: text/plain, Size: 3373 bytes --]

Hi Suravee,

[auto build test WARNING on iommu/next]
[also build test WARNING on v4.12-rc6 next-20170623]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Suravee-Suthikulpanit/iommu-amd-Fix-interrupt-remapping-when-disable-guest_mode/20170624-162701
base:   https://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu.git next
config: x86_64-randconfig-b0-06242320 (attached as .config)
compiler: gcc-4.4 (Debian 4.4.7-8) 4.4.7
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

All warnings (new ones prefixed by >>):

   drivers/iommu/amd_iommu.c: In function 'irte_ga_prepare':
>> drivers/iommu/amd_iommu.c:4002: warning: unused variable 'dev_data'

vim +/dev_data +4002 drivers/iommu/amd_iommu.c

880ac60e Suravee Suthikulpanit 2016-08-23  3986  {
880ac60e Suravee Suthikulpanit 2016-08-23  3987  	union irte *irte = (union irte *) entry;
880ac60e Suravee Suthikulpanit 2016-08-23  3988  
880ac60e Suravee Suthikulpanit 2016-08-23  3989  	irte->val                = 0;
880ac60e Suravee Suthikulpanit 2016-08-23  3990  	irte->fields.vector      = vector;
880ac60e Suravee Suthikulpanit 2016-08-23  3991  	irte->fields.int_type    = delivery_mode;
880ac60e Suravee Suthikulpanit 2016-08-23  3992  	irte->fields.destination = dest_apicid;
880ac60e Suravee Suthikulpanit 2016-08-23  3993  	irte->fields.dm          = dest_mode;
880ac60e Suravee Suthikulpanit 2016-08-23  3994  	irte->fields.valid       = 1;
880ac60e Suravee Suthikulpanit 2016-08-23  3995  }
880ac60e Suravee Suthikulpanit 2016-08-23  3996  
880ac60e Suravee Suthikulpanit 2016-08-23  3997  static void irte_ga_prepare(void *entry,
880ac60e Suravee Suthikulpanit 2016-08-23  3998  			    u32 delivery_mode, u32 dest_mode,
d98de49a Suravee Suthikulpanit 2016-08-23  3999  			    u8 vector, u32 dest_apicid, int devid)
880ac60e Suravee Suthikulpanit 2016-08-23  4000  {
880ac60e Suravee Suthikulpanit 2016-08-23  4001  	struct irte_ga *irte = (struct irte_ga *) entry;
d98de49a Suravee Suthikulpanit 2016-08-23 @4002  	struct iommu_dev_data *dev_data = search_dev_data(devid);
880ac60e Suravee Suthikulpanit 2016-08-23  4003  
880ac60e Suravee Suthikulpanit 2016-08-23  4004  	irte->lo.val                      = 0;
880ac60e Suravee Suthikulpanit 2016-08-23  4005  	irte->hi.val                      = 0;
880ac60e Suravee Suthikulpanit 2016-08-23  4006  	irte->lo.fields_remap.int_type    = delivery_mode;
880ac60e Suravee Suthikulpanit 2016-08-23  4007  	irte->lo.fields_remap.dm          = dest_mode;
880ac60e Suravee Suthikulpanit 2016-08-23  4008  	irte->hi.fields.vector            = vector;
880ac60e Suravee Suthikulpanit 2016-08-23  4009  	irte->lo.fields_remap.destination = dest_apicid;
880ac60e Suravee Suthikulpanit 2016-08-23  4010  	irte->lo.fields_remap.valid       = 1;

:::::: The code at line 4002 was first introduced by commit
:::::: d98de49a53e48f51332e97568127e722415e1232 iommu/amd: Enable vAPIC interrupt remapping mode by default

:::::: TO: Suravee Suthikulpanit <suravee.suthikulpanit-5C7GfCeVMHo@public.gmane.org>
:::::: CC: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 21363 bytes --]

[-- Attachment #3: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-06-24 16:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-23 11:56 [PATCH] iommu/amd: Fix interrupt remapping when disable guest_mode Suravee Suthikulpanit
2017-06-23 11:56 ` Suravee Suthikulpanit
2017-06-24 16:43 ` kbuild test robot
2017-06-24 16:43   ` kbuild test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.