From patchwork Mon Dec 19 16:04:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFkaW0gS3LEjW3DocWZ?= X-Patchwork-Id: 9480495 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8FA99601C2 for ; Mon, 19 Dec 2016 16:07:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 96D7227D64 for ; Mon, 19 Dec 2016 16:07:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8B9B3283FD; Mon, 19 Dec 2016 16:07:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3D10527D64 for ; Mon, 19 Dec 2016 16:07:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1762632AbcLSQGY (ORCPT ); Mon, 19 Dec 2016 11:06:24 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38748 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759547AbcLSQGX (ORCPT ); Mon, 19 Dec 2016 11:06:23 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E43DC4E4E6 for ; Mon, 19 Dec 2016 16:06:01 +0000 (UTC) Received: from potion (dhcp-1-247.brq.redhat.com [10.34.1.247]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id uBJG5xD4006376; Mon, 19 Dec 2016 11:06:00 -0500 Received: by potion (sSMTP sendmail emulation); Mon, 19 Dec 2016 17:05:59 +0100 From: =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= To: kvm@vger.kernel.org Cc: Paolo Bonzini , David Hildenbrand Subject: [kvm-unit-tests PATCH] x86: apic: add physical broadcast test Date: Mon, 19 Dec 2016 17:04:29 +0100 Message-Id: <20161219160429.5237-1-rkrcmar@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 19 Dec 2016 16:06:01 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Broadcast to address 0xff is not exercised by seabios+linux so we better test it. Signed-off-by: Radim Krčmář --- 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();