From patchwork Sat Jul 29 00:36:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13332822 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 76885C001E0 for ; Sat, 29 Jul 2023 00:39:10 +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 :References:Mime-Version:In-Reply-To:Date:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=sXAPoFrmIhBGsC9HtohGe2/1J4mBH7+sDM96nX+XG40=; b=UX5bR09Fd7HZU+ eFJm/utF3UCeFydpMgyOGSMTblYqDfDPuPftFTE7hQc73t5udRernHPSn8d4cFmKMiAPdsPyjGn6c asNndPhY2aaRyn5NRqsWVpRttXxZNVGlSv/Ch2n+Sx+MT4uSJa4/OQ4syy5Yz+68VxomGaigdXfBg fQKZTAtzVIPPx1QMuCix+6mI5Y8zTGurbsDnRWB1If+/x9RWvWuW9YbTSYIohopkegX4s8ifcidFZ BsKPlhMKWU06vE6ZGS485G+j8CF04JUFMldN6Zxy6EZ7u+ls5vXVgRjR6FT3i4hZ2WaSHtEnbR90/ Z2v1RsdkqtgaMeXfMelg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qPXyT-005dPA-10; Sat, 29 Jul 2023 00:38:25 +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 1qPXxe-005cyn-0H for linux-arm-kernel@lists.infradead.org; Sat, 29 Jul 2023 00:37:37 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5840614b13cso45312847b3.0 for ; Fri, 28 Jul 2023 17:37:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1690591052; x=1691195852; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=x4HKEzKPUNSBzX9E0pO5Q/S6phjiWeOhLiSfPQ8QooI=; b=3J4eqVLdR3ykoPJRa1CUqiAo7FXGwSPiLo4xvH7nk6TpWaa/JGpNhmBWPw3KGYxRL0 9qMYcdR0/u6TUawhaqgYIaxBi5b32u3oPLpRlG7qWlPPXPZunewy09jWcWhC5Cl19DL7 zBgBnw4cSdRNiEkbsjo5Gcp2bAEBX0lBRSqsq7y6cBmpf20gsU/X+fWwZZk0O0I+ym7u pJ0NqE4APMBHTdZkdJxn5Xpo8lTIwyoI4uNBVqd4epT2ornrp+APUS9uMhgYVKkxnoLv zYejQkImQ3xyT5zUPKO72TgnNFsAd3LxTmVwJsnOtP65P8WX4nYqjQ+E8aENux/RDqvj E9gQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690591052; x=1691195852; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=x4HKEzKPUNSBzX9E0pO5Q/S6phjiWeOhLiSfPQ8QooI=; b=Dta6jrAG6cAwe1MJO1nePNJmGH5xlPD0iFcwBBzLrSmLW9zIC5+evucHdNSKHn+8Ie iXjZFGhklnXFe7KLqU5T9mhZAP7hpdkcey/GP9cdNHnUaot6vW/UV8hubDkd4v9kFixj 5I8WxzqTh5bBVDUlMuWU69KyY5JmDzNlNxwglpJWhazokKBcLIQ5gfWlxTUsApxcedDo KWCn0Bd37j4xWQNazzIs1ytyBNobpqNpgB/43avBJQQ3ZBmHHk4UuFUc1Ge3Ex5i1+ij RT8N/9t24m/t5dh9lIEoqvjpfMpFq5LjNutPJCrkynd0xWLts0DV2Zvsu5pVV+S0owDJ JTkw== X-Gm-Message-State: ABy/qLamf7NDeBWGRm0OUX8vXNeYDfvJONsIV1LPiKhDyd1Acd1SwzSp tCeAsSz8XU4pOD5kBGXMKRWRPUQ2yJU= X-Google-Smtp-Source: APBJJlEzrltnG1bwndm5pPHC3kHPtaj+RzjLvULD33K65TOP6Fq4kMafYhL6vJSstsfRiau2YYzr8Mp1Vdw= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a81:b665:0:b0:56c:f903:8678 with SMTP id h37-20020a81b665000000b0056cf9038678mr39663ywk.2.1690591052589; Fri, 28 Jul 2023 17:37:32 -0700 (PDT) Date: Fri, 28 Jul 2023 17:36:33 -0700 In-Reply-To: <20230729003643.1053367-1-seanjc@google.com> Mime-Version: 1.0 References: <20230729003643.1053367-1-seanjc@google.com> X-Mailer: git-send-email 2.41.0.487.g6d72f3e995-goog Message-ID: <20230729003643.1053367-25-seanjc@google.com> Subject: [PATCH v4 24/34] KVM: selftests: Convert the MONITOR/MWAIT test to use printf guest asserts 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_173734_150456_B30C4235 X-CRM114-Status: GOOD ( 12.72 ) 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 Convert x86's MONITOR/MWAIT test to use printf-based guest asserts. Add a macro to handle reporting failures to reduce the amount of copy+paste needed for MONITOR vs. MWAIT. Signed-off-by: Sean Christopherson --- .../selftests/kvm/x86_64/monitor_mwait_test.c | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/tools/testing/selftests/kvm/x86_64/monitor_mwait_test.c b/tools/testing/selftests/kvm/x86_64/monitor_mwait_test.c index 72812644d7f5..960fecab3742 100644 --- a/tools/testing/selftests/kvm/x86_64/monitor_mwait_test.c +++ b/tools/testing/selftests/kvm/x86_64/monitor_mwait_test.c @@ -1,4 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 +#define USE_GUEST_ASSERT_PRINTF 1 + #include #include #include @@ -16,14 +18,25 @@ enum monitor_mwait_testcases { MWAIT_DISABLED = BIT(2), }; +/* + * If both MWAIT and its quirk are disabled, MONITOR/MWAIT should #UD, in all + * other scenarios KVM should emulate them as nops. + */ +#define GUEST_ASSERT_MONITOR_MWAIT(insn, testcase, vector) \ +do { \ + bool fault_wanted = ((testcase) & MWAIT_QUIRK_DISABLED) && \ + ((testcase) & MWAIT_DISABLED); \ + \ + if (fault_wanted) \ + __GUEST_ASSERT((vector) == UD_VECTOR, \ + "Expected #UD on " insn " for testcase '0x%x', got '0x%x'", vector); \ + else \ + __GUEST_ASSERT(!(vector), \ + "Expected success on " insn " for testcase '0x%x', got '0x%x'", vector); \ +} while (0) + static void guest_monitor_wait(int testcase) { - /* - * If both MWAIT and its quirk are disabled, MONITOR/MWAIT should #UD, - * in all other scenarios KVM should emulate them as nops. - */ - bool fault_wanted = (testcase & MWAIT_QUIRK_DISABLED) && - (testcase & MWAIT_DISABLED); u8 vector; GUEST_SYNC(testcase); @@ -33,16 +46,10 @@ static void guest_monitor_wait(int testcase) * intercept checks, so the inputs for MONITOR and MWAIT must be valid. */ vector = kvm_asm_safe("monitor", "a"(guest_monitor_wait), "c"(0), "d"(0)); - if (fault_wanted) - GUEST_ASSERT_2(vector == UD_VECTOR, testcase, vector); - else - GUEST_ASSERT_2(!vector, testcase, vector); + GUEST_ASSERT_MONITOR_MWAIT("MONITOR", testcase, vector); vector = kvm_asm_safe("mwait", "a"(guest_monitor_wait), "c"(0), "d"(0)); - if (fault_wanted) - GUEST_ASSERT_2(vector == UD_VECTOR, testcase, vector); - else - GUEST_ASSERT_2(!vector, testcase, vector); + GUEST_ASSERT_MONITOR_MWAIT("MWAIT", testcase, vector); } static void guest_code(void) @@ -85,7 +92,7 @@ int main(int argc, char *argv[]) testcase = uc.args[1]; break; case UCALL_ABORT: - REPORT_GUEST_ASSERT_2(uc, "testcase = %lx, vector = %ld"); + REPORT_GUEST_ASSERT(uc); goto done; case UCALL_DONE: goto done;