From: "Radim Krčmář" <rkrcmar@redhat.com>
To: kvm@vger.kernel.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
David Hildenbrand <david@redhat.com>
Subject: [kvm-unit-tests PATCH] x86: apic: add physical broadcast test
Date: Mon, 19 Dec 2016 17:04:29 +0100 [thread overview]
Message-ID: <20161219160429.5237-1-rkrcmar@redhat.com> (raw)
Broadcast to address 0xff is not exercised by seabios+linux so we better
test it.
Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
---
The bounded wait loop is bad ... time to introduce TSC magic?
---
x86/apic.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 46 insertions(+)
diff --git a/x86/apic.c b/x86/apic.c
index 39c7fd19913d..b25ba45e4b8f 100644
--- a/x86/apic.c
+++ b/x86/apic.c
@@ -5,6 +5,7 @@
#include "desc.h"
#include "isr.h"
#include "msr.h"
+#include "atomic.h"
static void test_lapic_existence(void)
{
@@ -16,6 +17,7 @@ static void test_lapic_existence(void)
}
#define TSC_DEADLINE_TIMER_VECTOR 0xef
+#define BROADCAST_VECTOR 0xcf
static int tdt_count;
@@ -411,6 +413,49 @@ static void test_apic_timer_one_shot(void)
(tsc2 - tsc1 >= interval));
}
+static atomic_t broadcast_counter;
+
+static void broadcast_handler(isr_regs_t *regs)
+{
+ atomic_inc(&broadcast_counter);
+ eoi();
+}
+
+static bool broadcast_received(unsigned ncpus)
+{
+ unsigned counter;
+
+ for (int i = 123456789; i; i--) {
+ counter = atomic_read(&broadcast_counter);
+ if (counter >= ncpus)
+ break;
+ pause();
+ }
+
+ atomic_set(&broadcast_counter, 0);
+
+ return counter == ncpus;
+}
+
+static void test_physical_broadcast(void)
+{
+ unsigned ncpus = cpu_count();
+ unsigned long cr3 = read_cr3();
+ u32 broadcast_address = enable_x2apic() ? 0xffffffff : 0xff;
+
+ handle_irq(BROADCAST_VECTOR, broadcast_handler);
+ for (int c = 1; c < ncpus; c++)
+ on_cpu(c, update_cr3, (void *)cr3);
+
+ apic_icr_write(APIC_DEST_PHYSICAL | APIC_DM_FIXED | APIC_INT_ASSERT |
+ BROADCAST_VECTOR, broadcast_address);
+ report("APIC physical broadcast address", broadcast_received(ncpus));
+
+ apic_icr_write(APIC_DEST_PHYSICAL | APIC_DM_FIXED | APIC_INT_ASSERT |
+ BROADCAST_VECTOR | APIC_DEST_ALLINC, 0);
+ report("APIC physical broadcast shorthand", broadcast_received(ncpus));
+}
+
int main()
{
setup_vm();
@@ -425,6 +470,7 @@ int main()
test_apicbase();
test_self_ipi();
+ test_physical_broadcast();
test_sti_nmi();
test_multiple_nmi();
--
2.11.0
next reply other threads:[~2016-12-19 16:06 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-19 16:04 Radim Krčmář [this message]
2016-12-22 10:02 ` [kvm-unit-tests PATCH] x86: apic: add physical broadcast test Paolo Bonzini
2016-12-22 18:23 ` Radim Krčmář
2016-12-22 10:45 ` Paolo Bonzini
2016-12-22 18:15 ` Radim Krčmář
2016-12-22 18:24 ` Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20161219160429.5237-1-rkrcmar@redhat.com \
--to=rkrcmar@redhat.com \
--cc=david@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox