Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0FC33C4332D for ; Fri, 20 Mar 2020 09:25:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D238120739 for ; Fri, 20 Mar 2020 09:25:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="fWw8R5oh" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727231AbgCTJZn (ORCPT ); Fri, 20 Mar 2020 05:25:43 -0400 Received: from us-smtp-delivery-74.mimecast.com ([63.128.21.74]:23472 "EHLO us-smtp-delivery-74.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727213AbgCTJZm (ORCPT ); Fri, 20 Mar 2020 05:25:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584696342; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=a5t+K99nOllz6/nKHgn1LHqrPr5sxfTVf2PPG+27oSQ=; b=fWw8R5oh8VulmNcr/Sav5pjNBNhHAyK06olHPFhiV1G3o58cuu7NESX8ouVktPHRnY0E8o vqUH2zKNsEOrFq7ZhxO8SpGsJGO0OgT0y9ChqpzrzykDtJYM4Cer32e7Mb9728BXYl6pNH XbmitK53osmgVPUHix3yeoxxqwJf2II= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-414-vLEtzNdIOh6WSnEv-oVOsA-1; Fri, 20 Mar 2020 05:25:40 -0400 X-MC-Unique: vLEtzNdIOh6WSnEv-oVOsA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0CA15DB60; Fri, 20 Mar 2020 09:25:39 +0000 (UTC) Received: from laptop.redhat.com (ovpn-113-142.ams2.redhat.com [10.36.113.142]) by smtp.corp.redhat.com (Postfix) with ESMTP id 744D95C1D8; Fri, 20 Mar 2020 09:25:33 +0000 (UTC) From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, maz@kernel.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, qemu-devel@nongnu.org, qemu-arm@nongnu.org Cc: drjones@redhat.com, andre.przywara@arm.com, peter.maydell@linaro.org, yuzenghui@huawei.com, alexandru.elisei@arm.com, thuth@redhat.com Subject: [kvm-unit-tests PATCH v7 13/13] arm/arm64: ITS: pending table migration test Date: Fri, 20 Mar 2020 10:24:28 +0100 Message-Id: <20200320092428.20880-14-eric.auger@redhat.com> In-Reply-To: <20200320092428.20880-1-eric.auger@redhat.com> References: <20200320092428.20880-1-eric.auger@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Content-Transfer-Encoding: quoted-printable Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Add two new migration tests. One testing the migration of a topology where collection were unmapped. The second test checks the migration of the pending table. Signed-off-by: Eric Auger --- v6 -> v7: - test_migrate_unmapped_collection now uses pe0=3D0. Otherwise, depending on SMP value it collides with collections created by setup1() - use of for_each_present_cpu v5 -> v6: - s/Set the PTZ/Clear the PTZ - Move the collection inval after MAPC - remove the unmap collection test v4 -> v5: - move stub from header to arm/gic.c v3 -> v4: - do not talk about odd/even CPUs, use pe0 and pe1 - comment the delay v2 -> v3: - tests belong to both its and migration groups - use LPI(i) - gicv3_lpi_set_pending_table_bit renamed into gicv3_lpi_set_clr_pending --- arm/gic.c | 138 ++++++++++++++++++++++++++++++++++++++++++++++ arm/unittests.cfg | 16 ++++++ 2 files changed, 154 insertions(+) diff --git a/arm/gic.c b/arm/gic.c index 6ecfdbc..2c661dc 100644 --- a/arm/gic.c +++ b/arm/gic.c @@ -193,6 +193,7 @@ static void lpi_handler(struct pt_regs *regs __unused= ) smp_rmb(); /* pairs with wmb in lpi_stats_expect */ lpi_stats.observed.cpu_id =3D smp_processor_id(); lpi_stats.observed.lpi_id =3D irqnr; + acked[lpi_stats.observed.cpu_id]++; smp_wmb(); /* pairs with rmb in check_lpi_stats */ } =20 @@ -236,6 +237,22 @@ static void secondary_lpi_test(void) while (1) wfi(); } + +static void check_lpi_hits(int *expected, const char *msg) +{ + bool pass =3D true; + int i; + + for_each_present_cpu(i) { + if (acked[i] !=3D expected[i]) { + report_info("expected %d LPIs on PE #%d, %d observed", + expected[i], i, acked[i]); + pass =3D false; + break; + } + } + report(pass, "%s", msg); +} #endif =20 static void gicv2_ipi_send_self(void) @@ -591,6 +608,8 @@ static void gic_test_mmio(void) static void test_its_introspection(void) {} static void test_its_trigger(void) {} static void test_its_migration(void) {} +static void test_its_pending_migration(void) {} +static void test_migrate_unmapped_collection(void) {} =20 #else /* __aarch64__ */ =20 @@ -659,6 +678,15 @@ static int its_prerequisites(int nb_cpus) return 0; } =20 +static void set_lpi(struct its_device *dev, u32 eventid, u32 physid, + struct its_collection *col) +{ + assert(dev && col); + + its_send_mapti(dev, physid, eventid, col); + gicv3_lpi_set_config(physid, LPI_PROP_DEFAULT); +} + /* * Setup the configuration for those mappings: * dev_id=3D2 event=3D20 -> vcpu 3, intid=3D8195 @@ -790,6 +818,108 @@ static void test_its_migration(void) its_send_int(dev7, 255); check_lpi_stats("dev7/eventid=3D255 triggers LPI 8196 on PE #2 after mi= gration"); } + +static void test_migrate_unmapped_collection(void) +{ + struct its_collection *col; + struct its_device *dev2, *dev7; + int pe0 =3D 0; + u8 config; + + if (its_setup1()) + return; + + col =3D its_create_collection(pe0, pe0); + dev2 =3D its_get_device(2); + dev7 =3D its_get_device(7); + + /* MAPTI with the collection unmapped */ + set_lpi(dev2, 0, 8192, col); + + puts("Now migrate the VM, then press a key to continue...\n"); + (void)getchar(); + report_info("Migration complete"); + + /* on the destination, map the collection */ + its_send_mapc(col, true); + its_send_invall(col); + + lpi_stats_expect(2, 8196); + its_send_int(dev7, 255); + check_lpi_stats("dev7/eventid=3D 255 triggered LPI 8196 on PE #2"); + + config =3D gicv3_lpi_get_config(8192); + report(config =3D=3D LPI_PROP_DEFAULT, + "Config of LPI 8192 was properly migrated"); + + lpi_stats_expect(pe0, 8192); + its_send_int(dev2, 0); + check_lpi_stats("dev2/eventid =3D 0 triggered LPI 8192 on PE0"); +} + +static void test_its_pending_migration(void) +{ + struct its_device *dev; + struct its_collection *collection[2]; + int *expected =3D malloc(nr_cpus * sizeof(int)); + int pe0 =3D nr_cpus - 1, pe1 =3D nr_cpus - 2; + u64 pendbaser; + void *ptr; + int i; + + if (its_prerequisites(4)) + return; + + dev =3D its_create_device(2 /* dev id */, 8 /* nb_ites */); + its_send_mapd(dev, true); + + collection[0] =3D its_create_collection(pe0, pe0); + collection[1] =3D its_create_collection(pe1, pe1); + its_send_mapc(collection[0], true); + its_send_mapc(collection[1], true); + + /* disable lpi at redist level */ + gicv3_lpi_rdist_disable(pe0); + gicv3_lpi_rdist_disable(pe1); + + /* lpis are interleaved inbetween the 2 PEs */ + for (i =3D 0; i < 256; i++) { + struct its_collection *col =3D i % 2 ? collection[0] : + collection[1]; + int vcpu =3D col->target_address >> 16; + + its_send_mapti(dev, LPI(i), i, col); + gicv3_lpi_set_config(LPI(i), LPI_PROP_DEFAULT); + gicv3_lpi_set_clr_pending(vcpu, LPI(i), true); + } + its_send_invall(collection[0]); + its_send_invall(collection[1]); + + /* Clear the PTZ bit on each pendbaser */ + + expected[pe0] =3D 128; + expected[pe1] =3D 128; + + ptr =3D gicv3_data.redist_base[pe0] + GICR_PENDBASER; + pendbaser =3D readq(ptr); + writeq(pendbaser & ~GICR_PENDBASER_PTZ, ptr); + + ptr =3D gicv3_data.redist_base[pe1] + GICR_PENDBASER; + pendbaser =3D readq(ptr); + writeq(pendbaser & ~GICR_PENDBASER_PTZ, ptr); + + gicv3_lpi_rdist_enable(pe0); + gicv3_lpi_rdist_enable(pe1); + + puts("Now migrate the VM, then press a key to continue...\n"); + (void)getchar(); + report_info("Migration complete"); + + /* let's wait for the 256 LPIs to be handled */ + mdelay(1000); + + check_lpi_hits(expected, "128 LPIs on both PE0 and PE1 after migration"= ); +} #endif =20 int main(int argc, char **argv) @@ -831,6 +961,14 @@ int main(int argc, char **argv) report_prefix_push(argv[1]); test_its_migration(); report_prefix_pop(); + } else if (!strcmp(argv[1], "its-pending-migration")) { + report_prefix_push(argv[1]); + test_its_pending_migration(); + report_prefix_pop(); + } else if (!strcmp(argv[1], "its-migrate-unmapped-collection")) { + report_prefix_push(argv[1]); + test_migrate_unmapped_collection(); + report_prefix_pop(); } else if (strcmp(argv[1], "its-introspection") =3D=3D 0) { report_prefix_push(argv[1]); test_its_introspection(); diff --git a/arm/unittests.cfg b/arm/unittests.cfg index 480adec..b96f0a1 100644 --- a/arm/unittests.cfg +++ b/arm/unittests.cfg @@ -144,6 +144,22 @@ extra_params =3D -machine gic-version=3D3 -append 'i= ts-migration' groups =3D its migration arch =3D arm64 =20 +[its-pending-migration] +file =3D gic.flat +smp =3D $MAX_SMP +accel =3D kvm +extra_params =3D -machine gic-version=3D3 -append 'its-pending-migration= ' +groups =3D its migration +arch =3D arm64 + +[its-migrate-unmapped-collection] +file =3D gic.flat +smp =3D $MAX_SMP +accel =3D kvm +extra_params =3D -machine gic-version=3D3 -append 'its-migrate-unmapped-= collection' +groups =3D its migration +arch =3D arm64 + # Test PSCI emulation [psci] file =3D psci.flat --=20 2.20.1