From patchwork Wed Nov 29 22:49:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13473627 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="SunDNM5+" Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEC6AF4 for ; Wed, 29 Nov 2023 14:49:21 -0800 (PST) Received: by mail-pf1-x449.google.com with SMTP id d2e1a72fcca58-6cde4342fe9so232967b3a.2 for ; Wed, 29 Nov 2023 14:49:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701298161; x=1701902961; darn=vger.kernel.org; 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=jcB+0ufG8RNDzGznsHxIgoB+eIgiTMrBs/Lse4iREj8=; b=SunDNM5+HWKgI2Dw6O6zLkHFzNp81SfN6D8k9EE84c+NY1ZS5HjuXZtaPFvZz2lXuw wZZuNYc57zBjtx/iht6V13qU4sjzldsOIMBWaFlNAdOZorjGo64oxGaojZETQH4zBT9u w6vyWR7Jl6rzdrl/FOTjCn16aYZPvduNZ4pgRfgMzJYjGMZu/Hd5BuBuL8NJWu4msnhK jiz2FJpMcZ8+wmzwliDsp52VzW9dHvLz9QekyZwCGJ33DeL31SD36Pygv2MhkUZfPW6a kZPtgfW+RD8jkPRQNxNbuHI1hZ+yC28pigQe9r4ra4hSUiSlNlR97wAsMCm/wQ6Z/O3K wZkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701298161; x=1701902961; 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=jcB+0ufG8RNDzGznsHxIgoB+eIgiTMrBs/Lse4iREj8=; b=cYcm2vEKwlTvbBIIXAiuAai+lGVrCIASR0DcrRI6qF4W50hOmB6HpbhOve5nIokLSF w2N6r4QEnRTfHM3IdLh17x5PFK+5ekRd/A8Zp7q3ZmC3cuEobL95Bt68ANYHE0YVmhKE XeKvlOwAOdXcfS61IADAqQnyvOAubLRa7/RPR9rgmZ+vkXTRvIja/DoQQ4qKrVlg3T4L 7bVyL1R9ZoojQAlroH5aVzKSjaF3c3W69ZMXWF3qff8O64Bzh00km0RQQ57W+k1j9nML gV+6QDtusHOf0WVt6zcgS/2XBBar/INNm8jpJuvWJxQd7XRAKqyky+tTNy09MdyrLUxp A6TQ== X-Gm-Message-State: AOJu0YzFQmg20d/0rwVAz1dIra+fhKm9OswT1UD8de9Ro2AONeFLLvPq t+4ieB0P8Pn7TcelCA4UBlNN+UjZwtM= X-Google-Smtp-Source: AGHT+IGlptR+ACsn5xm5Y7kirHJtCxe5a03VMwEUdpXfliyZg3YTs1xMsjqpw1vLtzpj7r+7POud+dCpEzA= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6a00:1389:b0:6cb:95ab:cf8d with SMTP id t9-20020a056a00138900b006cb95abcf8dmr5297305pfg.6.1701298161246; Wed, 29 Nov 2023 14:49:21 -0800 (PST) Reply-To: Sean Christopherson Date: Wed, 29 Nov 2023 14:49:13 -0800 In-Reply-To: <20231129224916.532431-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20231129224916.532431-1-seanjc@google.com> X-Mailer: git-send-email 2.43.0.rc1.413.gea7ed67945-goog Message-ID: <20231129224916.532431-2-seanjc@google.com> Subject: [PATCH v2 1/4] KVM: selftests: Fix MWAIT error message when guest assertion fails From: Sean Christopherson To: Paolo Bonzini , Sean Christopherson Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Maxim Levitsky Print out the test and vector as intended when a guest assert fails an assertion regarding MONITOR/MWAIT faulting. Unfortunately, the guest printf support doesn't detect such issues at compile-time, so the bug manifests as a confusing error message, e.g. in the most confusing case, the test complains that it got vector "0" instead of expected vector "0". Fixes: 0f52e4aaa614 ("KVM: selftests: Convert the MONITOR/MWAIT test to use printf guest asserts") Reviewed-by: Maxim Levitsky Link: https://lore.kernel.org/r/20231107182159.404770-1-seanjc@google.com Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/x86_64/monitor_mwait_test.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 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 80aa3d8b18f8..853802641e1e 100644 --- a/tools/testing/selftests/kvm/x86_64/monitor_mwait_test.c +++ b/tools/testing/selftests/kvm/x86_64/monitor_mwait_test.c @@ -27,10 +27,12 @@ do { \ \ if (fault_wanted) \ __GUEST_ASSERT((vector) == UD_VECTOR, \ - "Expected #UD on " insn " for testcase '0x%x', got '0x%x'", vector); \ + "Expected #UD on " insn " for testcase '0x%x', got '0x%x'", \ + testcase, vector); \ else \ __GUEST_ASSERT(!(vector), \ - "Expected success on " insn " for testcase '0x%x', got '0x%x'", vector); \ + "Expected success on " insn " for testcase '0x%x', got '0x%x'", \ + testcase, vector); \ } while (0) static void guest_monitor_wait(int testcase) From patchwork Wed Nov 29 22:49:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13473628 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="oFDeVasz" Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E51F1131 for ; Wed, 29 Nov 2023 14:49:23 -0800 (PST) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5d1ed4b268dso5550397b3.0 for ; Wed, 29 Nov 2023 14:49:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701298163; x=1701902963; darn=vger.kernel.org; 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=jt3afr9C/NIzRrhpIhGigrnj+umWBaK2U3Kv0056zgw=; b=oFDeVaszqKVpYECsszkTNp3hDCq4mOQ/hhLZwwKbGX/2IbL05++SIxSHozA+I1Zx0F JOasnrDzTVBYPGnoCxfQ+CcaHqrWnkxk2TlilZQF4LvxMZN8bI522kR8ma6nPg7gb5nQ vTCUu1knw80Zz/VdVbpkWeT69SC8elC1NqwsXvMQqw2aNbArNf8FrrxMi2y+8fEhOCyc jn+OVT3jIUi60yYeYvdWIZ0tyS/9/RnwSTDgmOAUMIeQ2uFFyTBGDe+GM7Hbx6boMtQ6 NC1CJrztFe5zsDq3gh7YBbLBJ9ecbWc4VOlfU+u63V0MbzljfYGxn1yBVB0vEI2V53sk K4fQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701298163; x=1701902963; 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=jt3afr9C/NIzRrhpIhGigrnj+umWBaK2U3Kv0056zgw=; b=PLiEWrDxv4aCkxv2+ULR7O0GlH8BtRgmyRAFa+QLUvF02fVyesyj/NXR9Jayu3pdpU njaid1pxGZZBe/vSPVu+lxQgYU77XgrKX2tJ1isMhASq2B6UEHxvA0OJYtJMJo0WqKVc jgJxg1BdOR/CTVqxvZ5/f8f8N+q519K8sAKr98W82RR0lStn9ComdNXBE8aJ/c+lgWdG E78421qYtznWjXDxmDiNu0rfBNZnQsYC8ZpsJ4hUe+i67BLLLgOkW1zicOJnfWrOCK1t xcAgzmPRASnD1n2CHhrOOMCsdM14SAVIxsj3GvKfOfstHwBwrjAuDX7s6/flIYYhso/D 5lgg== X-Gm-Message-State: AOJu0YyClxXiQBQGhx+ak+fQjXM3dhqprYzatwwHSAQwOPKnvFGLX1gc DmXR0JPRYC2HpVH5s4+PCxw8OfTeYBQ= X-Google-Smtp-Source: AGHT+IGulxVXRNgaFOL2lJyl25oFAVWs5bdYEbG4SzfwCCsdRMsJGWH3Ec6G/kWD9vUh4OgGxi+dx9bVB6k= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a81:b614:0:b0:5cc:3af6:291 with SMTP id u20-20020a81b614000000b005cc3af60291mr614082ywh.5.1701298163174; Wed, 29 Nov 2023 14:49:23 -0800 (PST) Reply-To: Sean Christopherson Date: Wed, 29 Nov 2023 14:49:14 -0800 In-Reply-To: <20231129224916.532431-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20231129224916.532431-1-seanjc@google.com> X-Mailer: git-send-email 2.43.0.rc1.413.gea7ed67945-goog Message-ID: <20231129224916.532431-3-seanjc@google.com> Subject: [PATCH v2 2/4] KVM: selftests: Fix benign %llx vs. %lx issues in guest asserts From: Sean Christopherson To: Paolo Bonzini , Sean Christopherson Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Maxim Levitsky Convert %llx to %lx as appropriate in guest asserts. The guest printf implementation treats them the same as KVM selftests are 64-bit only, but strictly adhering to the correct format will allow annotating the underlying helpers with __printf() without introducing new warnings in the build. Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/set_memory_region_test.c | 6 +++--- tools/testing/selftests/kvm/x86_64/hyperv_features.c | 2 +- .../selftests/kvm/x86_64/private_mem_conversions_test.c | 2 +- .../selftests/kvm/x86_64/svm_nested_soft_inject_test.c | 4 ++-- tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c | 2 +- tools/testing/selftests/kvm/x86_64/xcr0_cpuid_test.c | 8 ++++---- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tools/testing/selftests/kvm/set_memory_region_test.c b/tools/testing/selftests/kvm/set_memory_region_test.c index 6637a0845acf..03ec7efd19aa 100644 --- a/tools/testing/selftests/kvm/set_memory_region_test.c +++ b/tools/testing/selftests/kvm/set_memory_region_test.c @@ -157,17 +157,17 @@ static void guest_code_move_memory_region(void) */ val = guest_spin_on_val(0); __GUEST_ASSERT(val == 1 || val == MMIO_VAL, - "Expected '1' or MMIO ('%llx'), got '%llx'", MMIO_VAL, val); + "Expected '1' or MMIO ('%lx'), got '%lx'", MMIO_VAL, val); /* Spin until the misaligning memory region move completes. */ val = guest_spin_on_val(MMIO_VAL); __GUEST_ASSERT(val == 1 || val == 0, - "Expected '0' or '1' (no MMIO), got '%llx'", val); + "Expected '0' or '1' (no MMIO), got '%lx'", val); /* Spin until the memory region starts to get re-aligned. */ val = guest_spin_on_val(0); __GUEST_ASSERT(val == 1 || val == MMIO_VAL, - "Expected '1' or MMIO ('%llx'), got '%llx'", MMIO_VAL, val); + "Expected '1' or MMIO ('%lx'), got '%lx'", MMIO_VAL, val); /* Spin until the re-aligning memory region move completes. */ val = guest_spin_on_val(MMIO_VAL); diff --git a/tools/testing/selftests/kvm/x86_64/hyperv_features.c b/tools/testing/selftests/kvm/x86_64/hyperv_features.c index 9f28aa276c4e..4bb63b6ee4a0 100644 --- a/tools/testing/selftests/kvm/x86_64/hyperv_features.c +++ b/tools/testing/selftests/kvm/x86_64/hyperv_features.c @@ -66,7 +66,7 @@ static void guest_msr(struct msr_data *msr) if (msr->write) __GUEST_ASSERT(!vector, - "WRMSR(0x%x) to '0x%llx', RDMSR read '0x%llx'", + "WRMSR(0x%x) to '0x%lx', RDMSR read '0x%lx'", msr->idx, msr->write_val, msr_val); /* Invariant TSC bit appears when TSC invariant control MSR is written to */ diff --git a/tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.c b/tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.c index 4d6a37a5d896..65ad38b6be1f 100644 --- a/tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.c +++ b/tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.c @@ -35,7 +35,7 @@ do { \ \ for (i = 0; i < size; i++) \ __GUEST_ASSERT(mem[i] == pattern, \ - "Guest expected 0x%x at offset %lu (gpa 0x%llx), got 0x%x", \ + "Guest expected 0x%x at offset %lu (gpa 0x%lx), got 0x%x", \ pattern, i, gpa + i, mem[i]); \ } while (0) diff --git a/tools/testing/selftests/kvm/x86_64/svm_nested_soft_inject_test.c b/tools/testing/selftests/kvm/x86_64/svm_nested_soft_inject_test.c index 7ee44496cf97..0c7ce3d4e83a 100644 --- a/tools/testing/selftests/kvm/x86_64/svm_nested_soft_inject_test.c +++ b/tools/testing/selftests/kvm/x86_64/svm_nested_soft_inject_test.c @@ -103,7 +103,7 @@ static void l1_guest_code(struct svm_test_data *svm, uint64_t is_nmi, uint64_t i run_guest(vmcb, svm->vmcb_gpa); __GUEST_ASSERT(vmcb->control.exit_code == SVM_EXIT_VMMCALL, - "Expected VMMCAL #VMEXIT, got '0x%x', info1 = '0x%llx, info2 = '0x%llx'", + "Expected VMMCAL #VMEXIT, got '0x%x', info1 = '0x%lx, info2 = '0x%lx'", vmcb->control.exit_code, vmcb->control.exit_info_1, vmcb->control.exit_info_2); @@ -133,7 +133,7 @@ static void l1_guest_code(struct svm_test_data *svm, uint64_t is_nmi, uint64_t i run_guest(vmcb, svm->vmcb_gpa); __GUEST_ASSERT(vmcb->control.exit_code == SVM_EXIT_HLT, - "Expected HLT #VMEXIT, got '0x%x', info1 = '0x%llx, info2 = '0x%llx'", + "Expected HLT #VMEXIT, got '0x%x', info1 = '0x%lx, info2 = '0x%lx'", vmcb->control.exit_code, vmcb->control.exit_info_1, vmcb->control.exit_info_2); diff --git a/tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c b/tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c index ebbcb0a3f743..2a8d4ac2f020 100644 --- a/tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c +++ b/tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c @@ -56,7 +56,7 @@ static void guest_test_perf_capabilities_gp(uint64_t val) uint8_t vector = wrmsr_safe(MSR_IA32_PERF_CAPABILITIES, val); __GUEST_ASSERT(vector == GP_VECTOR, - "Expected #GP for value '0x%llx', got vector '0x%x'", + "Expected #GP for value '0x%lx', got vector '0x%x'", val, vector); } diff --git a/tools/testing/selftests/kvm/x86_64/xcr0_cpuid_test.c b/tools/testing/selftests/kvm/x86_64/xcr0_cpuid_test.c index 77d04a7bdadd..dc6217440db3 100644 --- a/tools/testing/selftests/kvm/x86_64/xcr0_cpuid_test.c +++ b/tools/testing/selftests/kvm/x86_64/xcr0_cpuid_test.c @@ -25,7 +25,7 @@ do { \ \ __GUEST_ASSERT((__supported & (xfeatures)) != (xfeatures) || \ __supported == ((xfeatures) | (dependencies)), \ - "supported = 0x%llx, xfeatures = 0x%llx, dependencies = 0x%llx", \ + "supported = 0x%lx, xfeatures = 0x%llx, dependencies = 0x%llx", \ __supported, (xfeatures), (dependencies)); \ } while (0) @@ -42,7 +42,7 @@ do { \ uint64_t __supported = (supported_xcr0) & (xfeatures); \ \ __GUEST_ASSERT(!__supported || __supported == (xfeatures), \ - "supported = 0x%llx, xfeatures = 0x%llx", \ + "supported = 0x%lx, xfeatures = 0x%llx", \ __supported, (xfeatures)); \ } while (0) @@ -81,7 +81,7 @@ static void guest_code(void) vector = xsetbv_safe(0, supported_xcr0); __GUEST_ASSERT(!vector, - "Expected success on XSETBV(0x%llx), got vector '0x%x'", + "Expected success on XSETBV(0x%lx), got vector '0x%x'", supported_xcr0, vector); for (i = 0; i < 64; i++) { @@ -90,7 +90,7 @@ static void guest_code(void) vector = xsetbv_safe(0, supported_xcr0 | BIT_ULL(i)); __GUEST_ASSERT(vector == GP_VECTOR, - "Expected #GP on XSETBV(0x%llx), supported XCR0 = %llx, got vector '0x%x'", + "Expected #GP on XSETBV(0x%llx), supported XCR0 = %lx, got vector '0x%x'", BIT_ULL(i), supported_xcr0, vector); } From patchwork Wed Nov 29 22:49:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13473629 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="j01pUN2F" Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C737E193 for ; Wed, 29 Nov 2023 14:49:25 -0800 (PST) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5caf61210e3so4589437b3.0 for ; Wed, 29 Nov 2023 14:49:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701298165; x=1701902965; darn=vger.kernel.org; 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=obqRJwrAc0R30oE9DQOo5RZu0y3Es0pUF6guVfZd4RE=; b=j01pUN2FfrLsdIdVuWQONS6o2QYDAtPibP9zZIe4jIeN5cS2kUhvpbzr7BF3hZjSet 2ZkCXkWYDDb3LbvsCg6MNGp/uI3ZwWjvG3tB/NpKbth1cXF9xjFCY4IOkWXkyNsTMzdF cM44Fg6edusAbgN+/1twVIToLEu87QMLKubFhD3TyKwsu4VEiK9Be/rc25ZbGe7boCMG L7S3pTyB7sD3/nbhc26aKpXgbKsbslKIwSW3f69MdMyR/aGKMoK54MEgW+idjIXrMdv7 +DCabK675yKPbgf1InOA1Ocogyl1FPlGVwNWmlKBUtG/uY4NvG+dMkkd18VNkfQdQSlJ aPkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701298165; x=1701902965; 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=obqRJwrAc0R30oE9DQOo5RZu0y3Es0pUF6guVfZd4RE=; b=l3OVVJZzrXnP/EbD3GGx3B7YlHfYPb2p7a5C/FuIY6CiUS+ToN1lc0C9UFirg0ujXd 2GxhYbaaec/0BR+SYwpna9m+2gU5hGY/ROA0qQA9hjXuEOL3VUL/XUXWPGpZzrAK4nCN RcBp5xTHkleLMn4SgTSdW+PdJPG5yEH5aED3kEdCyAMz+MCYXBI6myTi+dJq+xKw8mvv xN3f2xs1oQ9wA2iXCX4TSKrMElYBGkmg184KeFc7kHPbT5Wp6HYLqY7okJPm7oYEvdlY kwBH0D1VyJHhi+XRxURaNG/e91g1LKc+VhTXM2YggqHpfLYYA/XR+6Hy8DwSvZxW1ab9 4BZw== X-Gm-Message-State: AOJu0Yx2rXgKanLp93Cyx08A7M9DsI2RnZlb0kfr5YOloxhqD/eW9jyG HNgfGxWWO8i5WB+t8PVM7Raqzyenm70= X-Google-Smtp-Source: AGHT+IFiO/2Aj0FYANjdTLdz18AsCY+hgJd7gw2a7Qpd4J7gUjOl+TCyJnqhI0rjeJ5wx0LkoWDUuMe+l24= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:690c:e19:b0:5ca:724d:9256 with SMTP id cp25-20020a05690c0e1900b005ca724d9256mr709697ywb.7.1701298165115; Wed, 29 Nov 2023 14:49:25 -0800 (PST) Reply-To: Sean Christopherson Date: Wed, 29 Nov 2023 14:49:15 -0800 In-Reply-To: <20231129224916.532431-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20231129224916.532431-1-seanjc@google.com> X-Mailer: git-send-email 2.43.0.rc1.413.gea7ed67945-goog Message-ID: <20231129224916.532431-4-seanjc@google.com> Subject: [PATCH v2 3/4] KVM: selftests: Fix broken assert messages in Hyper-V features test From: Sean Christopherson To: Paolo Bonzini , Sean Christopherson Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Maxim Levitsky Swap the ordering of parameters to guest asserts related to {RD,WR}MSR success/failure in the Hyper-V features test. As is, the output will be mangled and broken due to passing an integer as a string and vice versa. Opportunistically fix a benign %u vs. %lu issue as well. Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/x86_64/hyperv_features.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/kvm/x86_64/hyperv_features.c b/tools/testing/selftests/kvm/x86_64/hyperv_features.c index 4bb63b6ee4a0..29f6bdbce817 100644 --- a/tools/testing/selftests/kvm/x86_64/hyperv_features.c +++ b/tools/testing/selftests/kvm/x86_64/hyperv_features.c @@ -55,11 +55,11 @@ static void guest_msr(struct msr_data *msr) if (msr->fault_expected) __GUEST_ASSERT(vector == GP_VECTOR, "Expected #GP on %sMSR(0x%x), got vector '0x%x'", - msr->idx, msr->write ? "WR" : "RD", vector); + msr->write ? "WR" : "RD", msr->idx, vector); else __GUEST_ASSERT(!vector, "Expected success on %sMSR(0x%x), got vector '0x%x'", - msr->idx, msr->write ? "WR" : "RD", vector); + msr->write ? "WR" : "RD", msr->idx, vector); if (vector || is_write_only_msr(msr->idx)) goto done; @@ -102,11 +102,11 @@ static void guest_hcall(vm_vaddr_t pgs_gpa, struct hcall_data *hcall) vector = __hyperv_hypercall(hcall->control, input, output, &res); if (hcall->ud_expected) { __GUEST_ASSERT(vector == UD_VECTOR, - "Expected #UD for control '%u', got vector '0x%x'", + "Expected #UD for control '%lu', got vector '0x%x'", hcall->control, vector); } else { __GUEST_ASSERT(!vector, - "Expected no exception for control '%u', got vector '0x%x'", + "Expected no exception for control '%lu', got vector '0x%x'", hcall->control, vector); GUEST_ASSERT_EQ(res, hcall->expect); } From patchwork Wed Nov 29 22:49:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13473630 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ZENs0hs/" 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 EBDE2D71 for ; Wed, 29 Nov 2023 14:49:27 -0800 (PST) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5cd6a86a898so4891677b3.3 for ; Wed, 29 Nov 2023 14:49:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701298167; x=1701902967; darn=vger.kernel.org; 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=bWMFxsne+gpl88lI6YduYGZQRPXK3Vk37mspokD2wHM=; b=ZENs0hs/af+xss6arfJvEJ5iNBhj5w5Tw0B5WLQ/ahBMHb7/kuDwrbb0l37y2gFMQ2 IXHxvxwaTrC1GK+fm+Jwt5Iv8pBDepdDA4/JG3ymZVpq697ntXmm0ZM8fZRgYSUC7Cmt 2CDbgAbsWRn2OFGktvMbrYV5jTQntahQ9cxHBg2wlDXxitdY0CCYZNiva8W98jWCXOxp FI8fjQ7klVKVPO9loK1bmfPzhRPTJ42nlgzkwWLSkxlSyOXXY+vEp+YzxfXzQOW0yCRX 7Nt6NNsoG2FOwi3IK9rvHDmOiuKBnDDw1F/NmEYVSoD7MwpA/aj0sv7yLs3OikJqPrui CtzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701298167; x=1701902967; 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=bWMFxsne+gpl88lI6YduYGZQRPXK3Vk37mspokD2wHM=; b=p28oHkl81W5Q+VOWfo25tSJjrX8Qxti/ZCt88BO+IJRtBOsNalM7oRAwpYMkuMdKaJ WpcDG6AHAlUHc0+35XG0XaV7lrAyUDTuepikBFH2U/vM/aQSXjjAdlwx1F+Z7fN8qVQ6 UiA6TGFwnnibdubtLf0Ow6K2ZyvGaCf/xMJEdtKMJu1+JcCUzLM8xvfl5fo6r+4RZAzl sDZkId4Ea3kON9zWvjU+63wWPNmcJRLRBZRhs2HWif5YsiUPZ081qmil/kjqKAxe0+Du 6Yk/cLv2vcWna1sQCa2rpM6h+BfLazlbUdyr2AoXPHokk1u576/5M9PEa3Y6pKmwpPV3 puTg== X-Gm-Message-State: AOJu0YwyLxEBrSXHW3qLnesK/KZiIoGdQWwcUvxbR85+hcCjLQ6lRjYZ 8GeH8ZHkQcyYVpoGbRvJ3R/5Vw2ju7M= X-Google-Smtp-Source: AGHT+IFfWN+UtOLGwzsyM0bGshSYC31E3NK9PtvRfmfe+lo2abmXbvWxKKN8xpuOIW7WpNfpdw1ylMe6zJM= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a81:be15:0:b0:5d0:a744:719a with SMTP id i21-20020a81be15000000b005d0a744719amr342961ywn.2.1701298167236; Wed, 29 Nov 2023 14:49:27 -0800 (PST) Reply-To: Sean Christopherson Date: Wed, 29 Nov 2023 14:49:16 -0800 In-Reply-To: <20231129224916.532431-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20231129224916.532431-1-seanjc@google.com> X-Mailer: git-send-email 2.43.0.rc1.413.gea7ed67945-goog Message-ID: <20231129224916.532431-5-seanjc@google.com> Subject: [PATCH v2 4/4] KVM: selftests: Annotate guest ucall, printf, and assert helpers with __printf() From: Sean Christopherson To: Paolo Bonzini , Sean Christopherson Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Maxim Levitsky Annotate guest printf helpers with __printf() so that the compiler will warn about incorrect formatting at compile time (see git log for how easy it is to screw up with the formatting). Suggested-by: Maxim Levitsky Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/include/test_util.h | 2 +- tools/testing/selftests/kvm/include/ucall_common.h | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/kvm/include/test_util.h b/tools/testing/selftests/kvm/include/test_util.h index a0c7dd3a5b30..71a41fa924b7 100644 --- a/tools/testing/selftests/kvm/include/test_util.h +++ b/tools/testing/selftests/kvm/include/test_util.h @@ -191,7 +191,7 @@ static inline uint32_t atoi_non_negative(const char *name, const char *num_str) } int guest_vsnprintf(char *buf, int n, const char *fmt, va_list args); -int guest_snprintf(char *buf, int n, const char *fmt, ...); +__printf(3, 4) int guest_snprintf(char *buf, int n, const char *fmt, ...); char *strdup_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2), nonnull(1))); diff --git a/tools/testing/selftests/kvm/include/ucall_common.h b/tools/testing/selftests/kvm/include/ucall_common.h index 0fb472a5a058..d9d6581b8d4f 100644 --- a/tools/testing/selftests/kvm/include/ucall_common.h +++ b/tools/testing/selftests/kvm/include/ucall_common.h @@ -34,9 +34,10 @@ void ucall_arch_do_ucall(vm_vaddr_t uc); void *ucall_arch_get_ucall(struct kvm_vcpu *vcpu); void ucall(uint64_t cmd, int nargs, ...); -void ucall_fmt(uint64_t cmd, const char *fmt, ...); -void ucall_assert(uint64_t cmd, const char *exp, const char *file, - unsigned int line, const char *fmt, ...); +__printf(2, 3) void ucall_fmt(uint64_t cmd, const char *fmt, ...); +__printf(5, 6) void ucall_assert(uint64_t cmd, const char *exp, + const char *file, unsigned int line, + const char *fmt, ...); uint64_t get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc); void ucall_init(struct kvm_vm *vm, vm_paddr_t mmio_gpa); int ucall_nr_pages_required(uint64_t page_size);