Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp1925632rwb; Fri, 28 Jul 2023 18:18:34 -0700 (PDT) X-Google-Smtp-Source: APBJJlEmJvJj3qC0E9M9dDxX5v8aLyrt0Jovr8PhoEJLCsq/V+K3oY36rrMhv7T7aEgmqIE0UNND X-Received: by 2002:a17:902:d507:b0:1b6:c229:c350 with SMTP id b7-20020a170902d50700b001b6c229c350mr4170669plg.18.1690593514114; Fri, 28 Jul 2023 18:18:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690593514; cv=none; d=google.com; s=arc-20160816; b=G1wcrEFekkTzJnIVKU3BvoOEzMd3D71hUol4smZjlWqGdiqI9zPbwR6wJQu7aGQ812 2pR296adQcrzzBZfhBkxA4/L9FywmdzVo8RVfX8qq30nE+/ZNFOoBgfPiwaiDicgdpI+ risaQUGrPRSxnLd1EGzojU9kgq/o3TvnPn/x5XtmsdxT6DbDWbnGIyZhXoqu0qQjBxjP 0e+FLlQLZH7f5FGHHeACZWZgu7I6H6zjwhV+m+3NFuAzVu7VmMFHJ094/YllaP/ogkeA qmhxMcmB4/OjjAByn2SNsyvgbihaGnz1VHK0c659AruK4ydYkyZTlg9oFvy7sm8ri/d3 Mgrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:reply-to:dkim-signature; bh=x4HKEzKPUNSBzX9E0pO5Q/S6phjiWeOhLiSfPQ8QooI=; fh=Ctt0ydInMKwei8YFBFbw7rU4p8H0G/T51ZI/KkO6Md4=; b=YBf5dIaiHLBvqEuc3RRKq7+e93PMWudSFOvBH85oZsMu3D1DF/wcaKG4smHJg7vYoj RJKl7K5Bp9jWu8ITfeaagxQinq3H3kCLo/khMhkQxEnXgjIvbZfPynBtqC2zQYDDh4Wu IkE3iiNu0Gl0GZVukK3rvEZsBvTaROrEbLwvf4PJ91dID81MaG1eMSy6++83jk85R22A 7Cy79UU/Mo4ALsuz8Xxn7h2v5YJtgHzPCxzk5km5d9H52ZBs5GEbwn8bMT4LfK0Z2qel czEBPt08ktus2PSqth6epcTtEg3tdqkkAAEVzJGHN7IIOypgGx6cmS2OTrmT+1qG6gsW SweQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=3J4eqVLd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y18-20020a17090322d200b001bbd0450af8si3968531plg.187.2023.07.28.18.18.21; Fri, 28 Jul 2023 18:18:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=3J4eqVLd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236630AbjG2Ajy (ORCPT + 99 others); Fri, 28 Jul 2023 20:39:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236595AbjG2Aiz (ORCPT ); Fri, 28 Jul 2023 20:38:55 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B9CA49F9 for ; Fri, 28 Jul 2023 17:38:03 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5840614b13cso45312867b3.0 for ; Fri, 28 Jul 2023 17:38:03 -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=cn2vke9h9nQD8OfXMRaCRvvWBew3dKXQcec9CIwbs2Dw5mHmBr56WxnfOgL7xZ3stv hGK3PLWDiMp/1blyT7i/U6/T/1F69AaEFLJvn5vGqkg4S0315i/ea5eXNxvtRWs9Z9j4 SMSWzYr/w7P0EgqJ9R51Ksfy8mk8oICwV+m7+ukz3wBdHT3VmjUnHfSBBU53FVnBfjb5 kAHaqFZAn19uCzQrlMyK1HajtM3ZscUMBm0Yj5WSVyFHFEdtx8n/WNPzS+EliNZYmC+x +3nH8SrhxQXFO7Ig4Tc600oFAdDrEKVK5TTTMmu/4YlY0ORaW9+ZzVeYfZx3qqcrnEUu gg1A== X-Gm-Message-State: ABy/qLamBLeAj/UMrqRGyV/74iG+70Uegj9qR5/85MgLq+9S+YEZx/er mnTP5LUL4FbvxqnR5AT+vrrGPwuJTBs= 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) Reply-To: Sean Christopherson 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=20Mathieu-Daud=C3=A9?=" , Aaron Lewis Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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; -- 2.41.0.487.g6d72f3e995-goog