From patchwork Sat Jul 29 00:36:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13332798 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 28567C001DF for ; Sat, 29 Jul 2023 00:37:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Reply-To:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID :Mime-Version:Date:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=qOl1GGPcbTPTil7iLS41acsbjKDuTrq2rU//gt+BReE=; b=goImN4kH5VvLR9 ztTbUa4Abocd3JTXzgGYAz/0zh4Yb1v2nAe1Qj7YR4UptsKQSMRt3PkFlM/PQntHNyrIEHLcMtJxY epP2H3c6HEZFzRuneUjhu4ZTxtN5XgEAy4tWsZnS/wKdQHApTmLRfwwC9dpaXAOcEG4wZecg/qCwm e0DoxFgbfBEfdiZUn7EkxbtFQRK81ajuR7xJbKm98Vi8Djw26wZmGDzyXX29usiVqW0BweYhV875T s48FE3ZK1jg3K2oZLZGQU8wGgvjuaUfZYhEjmgUAMq1hbJZbwvVrhLlj8CMZw7TrL+6vomPcfiE2H T+pw9SeBV5MEopE88p3Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qPXxC-005cfB-2D; Sat, 29 Jul 2023 00:37:06 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qPXwz-005cZK-2j for linux-arm-kernel@lists.infradead.org; Sat, 29 Jul 2023 00:36:55 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-583a89cccf6so26730407b3.1 for ; Fri, 28 Jul 2023 17:36:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1690591006; x=1691195806; h=cc:to:from:subject:message-id:mime-version:date:reply-to:from:to:cc :subject:date:message-id:reply-to; bh=dMhJ/b6DMkuq/YdDrUWNaUZgSpR6tSiB89ISkM72Wx4=; b=uDNZSukByS7JyZ2jTEcrBQl7mGqhWoKqA2jPxWizvz2EyIAtNwjBDsbWnq8K25aP1c aGUNlsQCf/llPt5k93kDpL4/X2KOWZMToFa5soFdm8SQZ80FiVSihf9oTl/ob06d4uLB A89y28pB2flFbHcOhZSaDKEr1iY46y9zNb3+YdGFthAy7fQZVnSH2+uJlM3jA3U9b+s0 1lob8zXM5sLoRCYLPUaqo5Y8s5wf+iEZDOMb/VHGGR5MKtEIbQJv8IwQ6aUQjSQXD4nL iyyyuFW0dkdEnlSBWkk1bEMBBgfS5s9+l9tIhsWOiBjr/xL04hP/43Ge/C3IBQpzoNAN hyAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690591006; x=1691195806; h=cc:to:from:subject:message-id:mime-version:date:reply-to :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=dMhJ/b6DMkuq/YdDrUWNaUZgSpR6tSiB89ISkM72Wx4=; b=gydeRf1yHsg/o9SKKDTvNcSoOG0X85QIiCteq7NkegfW0K+6iLKWrSAPc7D0xJt+15 57kYSWlldQM9oKGCjEo7744WU3hgveAd7XtVIZwdUOP4VeYfgaQ+yxROcH7aBR6RguwS ET5f+ENWT90tCE5pyOi9A6vu5MmbZzrJok+oE5CoTbJuARZyBaPpF5b3LelzEYFGYaA/ mjwIODlruh4YS2fc655gQ8kK+gjZOYA1Pv2zaEOK3myCC6yh7c+Hd1KbYvJsnrZJC7ZR J/85lwhdfnKVijU/Z7kCpadoauvID5CiQsLchREk6MIbNwf73UQPZq4/8S3yGMG0qeJB WMhw== X-Gm-Message-State: ABy/qLb1LwTwhIhr2olcEiahxADH7/18DtT9/UB96sl7f9zZWr2Xe1tU aHZnW3x4/wZP44l9Mh5N0fIw0HvCrd0= X-Google-Smtp-Source: APBJJlF8MZMONjBAnx6gWcIkUk+d8DyxD4xCa+6q0yvO/BGd+aR/kU76AQtPV98ljgxWdHS1cmKtERBcZkE= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a25:19c2:0:b0:d0d:1563:58f2 with SMTP id 185-20020a2519c2000000b00d0d156358f2mr17145ybz.2.1690591006063; Fri, 28 Jul 2023 17:36:46 -0700 (PDT) Date: Fri, 28 Jul 2023 17:36:09 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.41.0.487.g6d72f3e995-goog Message-ID: <20230729003643.1053367-1-seanjc@google.com> Subject: [PATCH v4 00/34] KVM: selftests: Guest printf and asserts overhaul From: Sean Christopherson To: Paolo Bonzini , Marc Zyngier , Oliver Upton , Christian Borntraeger , Janosch Frank , Claudio Imbrenda Cc: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, Sean Christopherson , Thomas Huth , " =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= " , Aaron Lewis X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230728_173653_885194_7200A2DB X-CRM114-Status: GOOD ( 21.21 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Sean Christopherson Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This is effectively v4 of Aaron's series to add printf capabilities to the guest[*]. I also pulled in Thomas' patch to rename ASSERT_EQ() to TEST_ASSERT_EQ(), mainly so that we can decide on a common output format for both host and guest asserts in a single series, but also so that all these basically treewide patches are contained in a single series. Note, Aaron did all of the heavy lifting, I just mopped up. The core code is pretty much unchanged from Aaron's v3, v4 massages the assert code a bit and converts all the tests. I initially did the conversion in one big patch (the flag is ugly), but after hitting a nasty bug (see "Add a shameful hack to preserve/clobber GPRs across ucall") that occurred purely due to the compiler using registers differently, I decided splitting it up was probably for the best (even though I still think it probably wasn't worth the effort). Other maintainers, I want to get this into 6.6, hell or high water. The ability to use proper asserts in the guest is super nice, and given how much selftests code is written via CTRL-C + CTRL-V, the sooner we switch over the better. My thought is to apply this whole thing to kvm-x86/selftests early next week, and then create a tag to make that part of branch immutable. That would allow other architectures to pull the code into their trees, e.g. if an arch is gaining a big selftest or something. Apologies for not giving advance warning, I was originally thinking we could leisurely convert to the printf-based asserts, but then realized that we would probably never get rid of the old crud if we tried that approach. Any objections, or better ideas? Thanks! Oh, and tested on Intel, AMD, and whatever flavor of ARM we have. Compile tested on s390 and RISC-V. [*] https://lore.kernel.org/all/20230607224520.4164598-1-aaronlewis@google.com Aaron Lewis (5): KVM: selftests: Add strnlen() to the string overrides KVM: selftests: Add guest_snprintf() to KVM selftests KVM: selftests: Add additional pages to the guest to accommodate ucall KVM: selftests: Add string formatting options to ucall KVM: selftests: Add a selftest for guest prints and formatted asserts Sean Christopherson (28): KVM: selftests: Make TEST_ASSERT_EQ() output look like normal TEST_ASSERT() KVM: selftests: Add a shameful hack to preserve/clobber GPRs across ucall KVM: selftests: Add formatted guest assert support in ucall framework KVM: selftests: Convert aarch_timer to printf style GUEST_ASSERT KVM: selftests: Convert debug-exceptions to printf style GUEST_ASSERT KVM: selftests: Convert ARM's hypercalls test to printf style GUEST_ASSERT KVM: selftests: Convert ARM's page fault test to printf style GUEST_ASSERT KVM: selftests: Convert ARM's vGIC IRQ test to printf style GUEST_ASSERT KVM: selftests: Convert the memslot performance test to printf guest asserts KVM: selftests: Convert s390's memop test to printf style GUEST_ASSERT KVM: selftests: Convert s390's tprot test to printf style GUEST_ASSERT KVM: selftests: Convert set_memory_region_test to printf-based GUEST_ASSERT KVM: selftests: Convert steal_time test to printf style GUEST_ASSERT KVM: selftests: Convert x86's CPUID test to printf style GUEST_ASSERT KVM: selftests: Convert the Hyper-V extended hypercalls test to printf asserts KVM: selftests: Convert the Hyper-V feature test to printf style GUEST_ASSERT KVM: selftests: Convert x86's KVM paravirt test to printf style GUEST_ASSERT KVM: selftests: Convert the MONITOR/MWAIT test to use printf guest asserts KVM: selftests: Convert x86's nested exceptions test to printf guest asserts KVM: selftests: Convert x86's set BSP ID test to printf style guest asserts KVM: selftests: Convert the nSVM software interrupt test to printf guest asserts KVM: selftests: Convert x86's TSC MSRs test to use printf guest asserts KVM: selftests: Convert the x86 userspace I/O test to printf guest assert KVM: selftests: Convert VMX's PMU capabilities test to printf guest asserts KVM: selftests: Convert x86's XCR0 test to use printf-based guest asserts KVM: selftests: Rip out old, param-based guest assert macros KVM: selftests: Print out guest RIP on unhandled exception KVM: selftests: Use GUEST_FAIL() in ARM's arch timer helpers Thomas Huth (1): KVM: selftests: Rename the ASSERT_EQ macro tools/testing/selftests/kvm/Makefile | 3 + .../selftests/kvm/aarch64/aarch32_id_regs.c | 8 +- .../selftests/kvm/aarch64/arch_timer.c | 22 +- .../selftests/kvm/aarch64/debug-exceptions.c | 8 +- .../selftests/kvm/aarch64/hypercalls.c | 20 +- .../selftests/kvm/aarch64/page_fault_test.c | 17 +- .../testing/selftests/kvm/aarch64/vgic_irq.c | 3 +- .../testing/selftests/kvm/guest_print_test.c | 221 +++++++++++++ .../kvm/include/aarch64/arch_timer.h | 12 +- .../testing/selftests/kvm/include/test_util.h | 18 +- .../selftests/kvm/include/ucall_common.h | 97 +++--- .../testing/selftests/kvm/lib/guest_sprintf.c | 307 ++++++++++++++++++ tools/testing/selftests/kvm/lib/kvm_util.c | 6 +- .../selftests/kvm/lib/string_override.c | 9 + .../testing/selftests/kvm/lib/ucall_common.c | 44 +++ .../selftests/kvm/lib/x86_64/processor.c | 18 +- .../testing/selftests/kvm/lib/x86_64/ucall.c | 32 +- .../selftests/kvm/max_guest_memory_test.c | 2 +- .../testing/selftests/kvm/memslot_perf_test.c | 4 +- tools/testing/selftests/kvm/s390x/cmma_test.c | 62 ++-- tools/testing/selftests/kvm/s390x/memop.c | 13 +- tools/testing/selftests/kvm/s390x/tprot.c | 11 +- .../selftests/kvm/set_memory_region_test.c | 21 +- tools/testing/selftests/kvm/steal_time.c | 20 +- .../testing/selftests/kvm/x86_64/cpuid_test.c | 12 +- .../x86_64/dirty_log_page_splitting_test.c | 18 +- .../x86_64/exit_on_emulation_failure_test.c | 2 +- .../kvm/x86_64/hyperv_extended_hypercalls.c | 3 +- .../selftests/kvm/x86_64/hyperv_features.c | 29 +- .../selftests/kvm/x86_64/kvm_pv_test.c | 8 +- .../selftests/kvm/x86_64/monitor_mwait_test.c | 35 +- .../kvm/x86_64/nested_exceptions_test.c | 16 +- .../kvm/x86_64/recalc_apic_map_test.c | 6 +- .../selftests/kvm/x86_64/set_boot_cpu_id.c | 6 +- .../kvm/x86_64/svm_nested_soft_inject_test.c | 22 +- .../selftests/kvm/x86_64/tsc_msrs_test.c | 34 +- .../selftests/kvm/x86_64/userspace_io_test.c | 10 +- .../vmx_exception_with_invalid_guest_state.c | 2 +- .../selftests/kvm/x86_64/vmx_pmu_caps_test.c | 31 +- .../selftests/kvm/x86_64/xapic_state_test.c | 8 +- .../selftests/kvm/x86_64/xcr0_cpuid_test.c | 29 +- .../selftests/kvm/x86_64/xen_vmcall_test.c | 20 +- 42 files changed, 938 insertions(+), 331 deletions(-) create mode 100644 tools/testing/selftests/kvm/guest_print_test.c create mode 100644 tools/testing/selftests/kvm/lib/guest_sprintf.c base-commit: fdf0eaf11452d72945af31804e2a1048ee1b574c