Skip to contentSkip to conversation

x86: Test IOAPIC physical and logical destination mode

PATCH Applied Nitesh Narayan Lal 5 participants 11 messages Nov 6, 2019 – Dec 5, 2019 KVM

lore
Share & tools
lore
#0 lore raw

cover x86: Test IOAPIC physical and logical destination mode

The first patch adds smp configuration to ioapic unittest and
the second one adds the support to test both physical and logical destination modes under fixed delivery mode.

Nitesh Narayan Lal (2):
x86: ioapic: Add the smp configuration to ioapic unittest
x86: ioapic: Test physical and logical destination mode

 x86/ioapic.c      | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 x86/unittests.cfg |  1 +
 2 files changed, 66 insertions(+)
#1 lore raw

PATCH 1/2 x86: ioapic: Add the smp configuration to ioapic unittest

Adds -smp configuration for ioapic unittest. This is essentially required to test IOAPIC Logical destination mode, where we send an interrupt to more than one vcpus at the same time.

---
 x86/unittests.cfg | 1 +
 1 file changed, 1 insertion(+)
x86/unittests.cfg +1 -0
index 5ecb9bb..6ed0b86 100644
@@ -45,6 +45,7 @@ timeout = 30
 
 [ioapic]
 file = ioapic.flat
+smp = 4
 extra_params = -cpu qemu64
 arch = x86_64
 
Signature · 1 line
1.8.3.1
#2 lore raw

PATCH 2/2 x86: ioapic: Test physical and logical destination mode

In reply to Nitesh Narayan Lal

This patch tests the physical destination mode by sending an interrupt to one of the vcpus and logical destination mode by sending an interrupt to more than one vcpus.

---
 x86/ioapic.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)
x86/ioapic.c +65 -0
index c32dabd..31aec03 100644
@@ -405,12 +405,73 @@ static void test_ioapic_self_reconfigure(void)
 	report("Reconfigure self", g_isr_84 == 1 && e.remote_irr == 0);
 }
 
+static volatile int g_isr_85;
+
+static void ioapic_isr_85(isr_regs_t *regs)
+{
+	++g_isr_85;
+	set_irq_line(0x0e, 0);
+	eoi();
+}
+
+static void test_ioapic_physical_destination_mode(void)
+{
+	ioapic_redir_entry_t e = {
+		.vector = 0x85,
+		.delivery_mode = 0,
+		.dest_mode = 0,
+		.dest_id = 0x1,
+		.trig_mode = TRIGGER_LEVEL,
+	};
+	handle_irq(0x85, ioapic_isr_85);
+	ioapic_write_redir(0xe, e);
+	set_irq_line(0x0e, 1);
+	do {
+		pause();
+	} while(g_isr_85 != 1);
+	report("ioapic physical destination mode", g_isr_85 == 1);
+}
+
+static volatile int g_isr_86;
+
+static void ioapic_isr_86(isr_regs_t *regs)
+{
+	++g_isr_86;
+	set_irq_line(0x0e, 0);
+	eoi();
+}
+
+static void test_ioapic_logical_destination_mode(void)
+{
+	/* Number of vcpus which are configured/set in dest_id */
+	int nr_vcpus = 3;
+	ioapic_redir_entry_t e = {
+		.vector = 0x86,
+		.delivery_mode = 0,
+		.dest_mode = 1,
+		.dest_id = 0xd,
+		.trig_mode = TRIGGER_LEVEL,
+	};
+	handle_irq(0x86, ioapic_isr_86);
+	ioapic_write_redir(0xe, e);
+	set_irq_line(0x0e, 1);
+	do {
+		pause();
+	} while(g_isr_86 < nr_vcpus);
+	report("ioapic logical destination mode", g_isr_86 == nr_vcpus);
+}
+
+static void update_cr3(void *cr3)
+{
+	write_cr3((ulong)cr3);
+}
 
 int main(void)
 {
 	setup_vm();
 	smp_init();
 
+	on_cpus(update_cr3, (void *)read_cr3());
 	mask_pic_interrupts();
 
 	if (enable_x2apic())
@@ -448,7 +509,11 @@ int main(void)
 		test_ioapic_edge_tmr_smp(true);
 
 		test_ioapic_self_reconfigure();
+		test_ioapic_physical_destination_mode();
 	}
 
+	if (cpu_count() > 3)
+		test_ioapic_logical_destination_mode();
+
 	return report_summary();
 }
Signature · 1 line
1.8.3.1
#3 lore raw

Re: [kvm-unit-tests Patch v1 2/2] x86: ioapic: Test physical and logical destination mode

Quoted 8 lines · Nitesh Narayan Lal

This patch tests the physical destination mode by sending an interrupt to one of the vcpus and logical destination mode by sending an interrupt to more than one vcpus.

---
  x86/ioapic.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 65 insertions(+)

Hi,

I think this patch likely broke the possibility to run the ioapic test under TCG (it was still working some weeks ago):

https://gitlab.com/huth/kvm-unit-tests/-/jobs/363553211#L1815

Do you care about this test to be runnable under TCG, or shall I simply cook a patch to disable it in the gitlab CI?

Thomas

#4 lore raw

Re: [kvm-unit-tests Patch v1 2/2] x86: ioapic: Test physical and logical destination mode

Quoted 10 lines · Thomas Huth
Quoted 8 lines · Nitesh Narayan Lal

This patch tests the physical destination mode by sending an interrupt to one of the vcpus and logical destination mode by sending an interrupt to more than one vcpus.

---
  x86/ioapic.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

  1 file changed, 65 insertions(+)
Quoted 6 lines

 Hi,

I think this patch likely broke the possibility to run the ioapic test under TCG (it was still working some weeks ago):

 https://gitlab.com/huth/kvm-unit-tests/-/jobs/363553211#L1815

Hi Thomas,

Not sure about the cause of it. I will take a look.

Quoted 5 lines

Do you care about this test to be runnable under TCG, or shall I simply cook a patch to disable it in the gitlab CI?

 Thomas

Signature · 2 lines
Thanks
Nitesh
#5 lore raw

Re: [kvm-unit-tests Patch v1 2/2] x86: ioapic: Test physical and logical destination mode

In reply to Thomas Huth
Quoted 12 lines · Thomas Huth
Quoted 8 lines · Nitesh Narayan Lal

This patch tests the physical destination mode by sending an interrupt to one of the vcpus and logical destination mode by sending an interrupt to more than one vcpus.

---
  x86/ioapic.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

  1 file changed, 65 insertions(+)

 Hi,

Quoted 7 lines

I think this patch likely broke the possibility to run the ioapic test under TCG (it was still working some weeks ago):

 https://gitlab.com/huth/kvm-unit-tests/-/jobs/363553211#L1815

Do you care about this test to be runnable under TCG, or shall I simply cook a patch to disable it in the gitlab CI?

Hi Thomas,

I don't think there is a need for this test to be runnable under TCG. So we can skip this for it.

Quoted 2 lines

 Thomas

Signature · 2 lines
Thanks
Nitesh
#6 lore raw

Re: [kvm-unit-tests Patch v1 2/2] x86: ioapic: Test physical and logical destination mode

In reply to Nitesh Narayan Lal
Quoted 31 lines · Nitesh Narayan Lal

This patch tests the physical destination mode by sending an interrupt to one of the vcpus and logical destination mode by sending an interrupt to more than one vcpus.

---
 x86/ioapic.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)
x86/ioapic.c +14 -0
index c32dabd..31aec03 100644
@@ -405,12 +405,73 @@ static void test_ioapic_self_reconfigure(void)
 	report("Reconfigure self", g_isr_84 == 1 && e.remote_irr == 0);
 }
 
+static volatile int g_isr_85;
+
+static void ioapic_isr_85(isr_regs_t *regs)
+{
+	++g_isr_85;
+	set_irq_line(0x0e, 0);
+	eoi();
+}
+
+static void test_ioapic_physical_destination_mode(void)
+{
+	ioapic_redir_entry_t e = {
+		.vector = 0x85,
+		.delivery_mode = 0,

x86/ioapic.c static void test_ioapic_self_reconfigure(void) · line 431

Quoted 10 lines
x86/ioapic.c +10 -0
+		.dest_mode = 0,
+		.dest_id = 0x1,
+		.trig_mode = TRIGGER_LEVEL,
+	};
+	handle_irq(0x85, ioapic_isr_85);
+	ioapic_write_redir(0xe, e);
+	set_irq_line(0x0e, 1);
+	do {
+		pause();
+	} while(g_isr_85 != 1);

Does this loop (and the next one) end up running forever if the test fails? Would it be worth adding some timeout to detect failure?

Quoted 48 lines
x86/ioapic.c +37 -0
+	report("ioapic physical destination mode", g_isr_85 == 1);
+}
+
+static volatile int g_isr_86;
+
+static void ioapic_isr_86(isr_regs_t *regs)
+{
+	++g_isr_86;
+	set_irq_line(0x0e, 0);
+	eoi();
+}
+
+static void test_ioapic_logical_destination_mode(void)
+{
+	/* Number of vcpus which are configured/set in dest_id */
+	int nr_vcpus = 3;
+	ioapic_redir_entry_t e = {
+		.vector = 0x86,
+		.delivery_mode = 0,
+		.dest_mode = 1,
+		.dest_id = 0xd,
+		.trig_mode = TRIGGER_LEVEL,
+	};
+	handle_irq(0x86, ioapic_isr_86);
+	ioapic_write_redir(0xe, e);
+	set_irq_line(0x0e, 1);
+	do {
+		pause();
+	} while(g_isr_86 < nr_vcpus);
+	report("ioapic logical destination mode", g_isr_86 == nr_vcpus);
+}
+
+static void update_cr3(void *cr3)
+{
+	write_cr3((ulong)cr3);
+}
 
 int main(void)
 {
 	setup_vm();
 	smp_init();
 
+	on_cpus(update_cr3, (void *)read_cr3());
 	mask_pic_interrupts();
 
 	if (enable_x2apic())
@@ -448,7 +509,11 @@ int main(void)
 		test_ioapic_edge_tmr_smp(true);

x86/ioapic.c int main(void) · line 519

Quoted 10 lines
x86/ioapic.c +4 -0
 
 		test_ioapic_self_reconfigure();
+		test_ioapic_physical_destination_mode();
 	}
 
+	if (cpu_count() > 3)
+		test_ioapic_logical_destination_mode();
+
 	return report_summary();
 }

--
Cheers,
Christophe de Dinechin (IRC c3d)

#7 lore raw

Re: [kvm-unit-tests Patch v1 2/2] x86: ioapic: Test physical and logical destination mode

Quoted 37 lines · Christophe de Dinechin
Quoted 35 lines · Nitesh Narayan Lal

This patch tests the physical destination mode by sending an interrupt to one of the vcpus and logical destination mode by sending an interrupt to more than one vcpus.

---
 x86/ioapic.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)
x86/ioapic.c +18 -0
index c32dabd..31aec03 100644
@@ -405,12 +405,73 @@ static void test_ioapic_self_reconfigure(void)
 	report("Reconfigure self", g_isr_84 == 1 && e.remote_irr == 0);
 }
 
+static volatile int g_isr_85;
+
+static void ioapic_isr_85(isr_regs_t *regs)
+{
+	++g_isr_85;
+	set_irq_line(0x0e, 0);
+	eoi();
+}
+
+static void test_ioapic_physical_destination_mode(void)
+{
+	ioapic_redir_entry_t e = {
+		.vector = 0x85,
+		.delivery_mode = 0,
+		.dest_mode = 0,
+		.dest_id = 0x1,
+		.trig_mode = TRIGGER_LEVEL,
+	};
Quoted 8 lines

x86/ioapic.c static void test_ioapic_self_reconfigure(void) · line 431

Quoted 6 lines
x86/ioapic.c +6 -0
+	handle_irq(0x85, ioapic_isr_85);
+	ioapic_write_redir(0xe, e);
+	set_irq_line(0x0e, 1);
+	do {
+		pause();
+	} while(g_isr_85 != 1);

Does this loop (and the next one) end up running forever if the test fails? Would it be worth adding some timeout to detect failure?

AFAIK there is already a timeout in place. i.e., if we don't receive an interrupt then eventually the timeout will occur and the test will terminate.

Quoted 64 lines
Quoted 49 lines
x86/ioapic.c +37 -0
+	report("ioapic physical destination mode", g_isr_85 == 1);
+}
+
+static volatile int g_isr_86;
+
+static void ioapic_isr_86(isr_regs_t *regs)
+{
+	++g_isr_86;
+	set_irq_line(0x0e, 0);
+	eoi();
+}
+
+static void test_ioapic_logical_destination_mode(void)
+{
+	/* Number of vcpus which are configured/set in dest_id */
+	int nr_vcpus = 3;
+	ioapic_redir_entry_t e = {
+		.vector = 0x86,
+		.delivery_mode = 0,
+		.dest_mode = 1,
+		.dest_id = 0xd,
+		.trig_mode = TRIGGER_LEVEL,
+	};
+	handle_irq(0x86, ioapic_isr_86);
+	ioapic_write_redir(0xe, e);
+	set_irq_line(0x0e, 1);
+	do {
+		pause();
+	} while(g_isr_86 < nr_vcpus);
+	report("ioapic logical destination mode", g_isr_86 == nr_vcpus);
+}
+
+static void update_cr3(void *cr3)
+{
+	write_cr3((ulong)cr3);
+}
 
 int main(void)
 {
 	setup_vm();
 	smp_init();
 
+	on_cpus(update_cr3, (void *)read_cr3());
 	mask_pic_interrupts();
 
 	if (enable_x2apic())
@@ -448,7 +509,11 @@ int main(void)
 		test_ioapic_edge_tmr_smp(true);

x86/ioapic.c int main(void) · line 519

Quoted 10 lines
x86/ioapic.c +4 -0
 
 		test_ioapic_self_reconfigure();
+		test_ioapic_physical_destination_mode();
 	}
 
+	if (cpu_count() > 3)
+		test_ioapic_logical_destination_mode();
+
 	return report_summary();
 }

--
Cheers,
Christophe de Dinechin (IRC c3d)

Signature · 2 lines
Thanks
Nitesh
#8 lore raw
In reply to Nitesh Narayan Lal
Quoted 11 lines · Nitesh Narayan Lal

The first patch adds smp configuration to ioapic unittest and
the second one adds the support to test both physical and logical destination modes under fixed delivery mode.

Nitesh Narayan Lal (2):
x86: ioapic: Add the smp configuration to ioapic unittest
x86: ioapic: Test physical and logical destination mode

 x86/ioapic.c      | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 x86/unittests.cfg |  1 +
 2 files changed, 66 insertions(+)

I just wanted to check if there are any more suggestions or comments which I need to address before this can be merged?

Signature · 2 lines
Thanks
Nitesh
#9 lore raw
In reply to Nitesh Narayan Lal
Quoted 11 lines · Nitesh Narayan Lal

The first patch adds smp configuration to ioapic unittest and
the second one adds the support to test both physical and logical destination modes under fixed delivery mode.

Nitesh Narayan Lal (2):
x86: ioapic: Add the smp configuration to ioapic unittest
x86: ioapic: Test physical and logical destination mode

 x86/ioapic.c      | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 x86/unittests.cfg |  1 +
 2 files changed, 66 insertions(+)

Looks good to me.

maintainer Applied
#10 lore raw
In reply to Nitesh Narayan Lal
Quoted 4 lines · Nitesh Narayan Lal

The first patch adds smp configuration to ioapic unittest and
the second one adds the support to test both physical and logical destination modes under fixed delivery mode.

Quoted 8 lines

Nitesh Narayan Lal (2):
x86: ioapic: Add the smp configuration to ioapic unittest
x86: ioapic: Test physical and logical destination mode

 x86/ioapic.c      | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 x86/unittests.cfg |  1 +
 2 files changed, 66 insertions(+)

Applied, thanks.

Paolo