From patchwork Fri Dec 20 01:39:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13915997 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2A0797346F for ; Fri, 20 Dec 2024 01:39:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734658757; cv=none; b=NQBPNcNHgdWENvLzEKkT3cC+A4CN1HTa0nvKuAU1IWcV0yghb2/rMK5kGwaFtyTkdBnNOudHAeImj6ynptOUja2WTt6Z5xNcvBLe1i8QQnGuMcRlzhoX+ebdfywofkgQAjvPltKZ4szKczBkjSj+uxhqwfXGspyn8orROj1d4GE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734658757; c=relaxed/simple; bh=cdYoQmC1gHgaq22PDsiZGCRoGD7RLzRK9PeAtDWgW1s=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Jb4kEYNeRV8mGXmz0CNoEF0LcIyiIRDMc2C74PmaHkVK5H2f7uPj/NlB6JRV0dmVY4iRDHbcdLC4cEGtxI4jJV3o/5bOvBNZi/DrBO6lEOlPJWZe4UfeMlLU1erGT7HWKrNC7bsqaTAUEV19gfYnvKZyPeRVumATkcC/xRK4OBE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Xrb47Avc; arc=none smtp.client-ip=209.85.215.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Xrb47Avc" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-7f712829f05so883691a12.0 for ; Thu, 19 Dec 2024 17:39:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734658755; x=1735263555; 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=FOB7JN0OSt2j8FiVppNC5qzgljC2YrzarOO3DmltLC8=; b=Xrb47AvcWGXho1oJMLU7+rUDiTU4pz0Zlc4qK/+wdhWg3mQoU+RUexLsNYkOdS/+Jr 92anryNYkKe199xlAT8gOgVkdSfZ3LxW5cAijWTIVD+TfLNUjKwFIW4hFieMphNHd1Pg J3iSGT4t3dQcMO+PNl6P/JnYO0YKaUpC6CAn7tcRF/OdrLWEk1QItf1P3qFtXFsf4bri VM0lcYrBzXaLgIrEYu4ce4H2uKX4XLDM9vXTFMXsY3hmR7T+Wo7VbTNLlNO2rrZNHvtI eyPMCRoeS/Mng/KSq3mAeZE77+ROaV7jb+2XoKQAXMXAawC2Oa+U8YlREnxynhq/6x61 HkVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734658755; x=1735263555; 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=FOB7JN0OSt2j8FiVppNC5qzgljC2YrzarOO3DmltLC8=; b=U5yZqnFV0t0RRIe/jvxeY9TL7j8WQoepqx3A+jgEKsPmTHOEIgCdsSSP2kVrjOR8ap GXAGU32nmLIkoAQbLJ36npFXLq5a+gh/7t/0VvxovMBU4FazBgEuoasSqZO0OjtRjzmQ ERN+gbkMS7uwhoTUfvsDQz2spTub8LQE4/fmM0l2/bGuvRTRE8xj44OUCciGWvC5ZBBD FmhOq3q/UZhpfDS5SfehgEMh5wykZi1iePVZAtUrHDbJa+XMNihdhLa5p/oIe0P3YS/p wzOCN28oFO5Q4VX4j4E3ldRYq5wygWO2ODZyI/qHQ4Ub9mui34fTLKh8Cfky0P5tKbKq LUTw== X-Forwarded-Encrypted: i=1; AJvYcCXOdSPHCab6wuIVnWDSTq9ZBmvlq+PQVzJrTPhRy6ULR2zo8DZK0YcXq9LYi8p4n7WvrGQ=@vger.kernel.org X-Gm-Message-State: AOJu0YzHY7CnDcuT8h1K8LpoAEuIunIfZfv+ak5nxmZGUdWBzPWrknCh 0IRAla8im3PG/ixQeLJNqqXlAJi8TDsTpqt0Fh2idE/6K4H1hLuZ15MHTtc1/6bTgmkOEDuuM/a 4ig== X-Google-Smtp-Source: AGHT+IGgztxRUxTUpaMUvL86uRz7hYZyu/zAmCoVzo4yvg4Q5SlFHbLBFYN3ktm59BGI0bTCiW14R+y2ITQ= X-Received: from pfbkt9.prod.google.com ([2002:a05:6a00:4ba9:b0:72a:bc54:8507]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:33a6:b0:1e5:c43f:f36d with SMTP id adf61e73a8af0-1e5e046189cmr1878060637.18.1734658755535; Thu, 19 Dec 2024 17:39:15 -0800 (PST) Reply-To: Sean Christopherson Date: Thu, 19 Dec 2024 17:39:02 -0800 In-Reply-To: <20241220013906.3518334-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241220013906.3518334-1-seanjc@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241220013906.3518334-5-seanjc@google.com> Subject: [PATCH 4/8] KVM: selftests: Macrofy vm_get_stat() to auto-generate stat name string From: Sean Christopherson To: Marc Zyngier , Oliver Upton , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Sean Christopherson , Paolo Bonzini Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Turn vm_get_stat() into a macro that generates a string for the stat name, as opposed to taking a string. This will allow hardening stat usage in the future to generate errors on unknown stats at compile time. No functional change intended. Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/include/kvm_util.h | 14 +++++++------- .../kvm/x86/dirty_log_page_splitting_test.c | 6 +++--- .../testing/selftests/kvm/x86/nx_huge_pages_test.c | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tools/testing/selftests/kvm/include/kvm_util.h b/tools/testing/selftests/kvm/include/kvm_util.h index 4c4e5a847f67..044c2231431e 100644 --- a/tools/testing/selftests/kvm/include/kvm_util.h +++ b/tools/testing/selftests/kvm/include/kvm_util.h @@ -534,13 +534,13 @@ void read_stat_data(int stats_fd, struct kvm_stats_header *header, void __vm_get_stat(struct kvm_vm *vm, const char *stat_name, uint64_t *data, size_t max_elements); -static inline uint64_t vm_get_stat(struct kvm_vm *vm, const char *stat_name) -{ - uint64_t data; - - __vm_get_stat(vm, stat_name, &data, 1); - return data; -} +#define vm_get_stat(vm, stat) \ +({ \ + uint64_t data; \ + \ + __vm_get_stat(vm, #stat, &data, 1); \ + data; \ +}) void vm_create_irqchip(struct kvm_vm *vm); diff --git a/tools/testing/selftests/kvm/x86/dirty_log_page_splitting_test.c b/tools/testing/selftests/kvm/x86/dirty_log_page_splitting_test.c index 2929c067c207..b0d2b04a7ff2 100644 --- a/tools/testing/selftests/kvm/x86/dirty_log_page_splitting_test.c +++ b/tools/testing/selftests/kvm/x86/dirty_log_page_splitting_test.c @@ -41,9 +41,9 @@ struct kvm_page_stats { static void get_page_stats(struct kvm_vm *vm, struct kvm_page_stats *stats, const char *stage) { - stats->pages_4k = vm_get_stat(vm, "pages_4k"); - stats->pages_2m = vm_get_stat(vm, "pages_2m"); - stats->pages_1g = vm_get_stat(vm, "pages_1g"); + stats->pages_4k = vm_get_stat(vm, pages_4k); + stats->pages_2m = vm_get_stat(vm, pages_2m); + stats->pages_1g = vm_get_stat(vm, pages_1g); stats->hugepages = stats->pages_2m + stats->pages_1g; pr_debug("\nPage stats after %s: 4K: %ld 2M: %ld 1G: %ld huge: %ld\n", diff --git a/tools/testing/selftests/kvm/x86/nx_huge_pages_test.c b/tools/testing/selftests/kvm/x86/nx_huge_pages_test.c index e7efb2b35f8b..c0d84827f736 100644 --- a/tools/testing/selftests/kvm/x86/nx_huge_pages_test.c +++ b/tools/testing/selftests/kvm/x86/nx_huge_pages_test.c @@ -73,7 +73,7 @@ static void check_2m_page_count(struct kvm_vm *vm, int expected_pages_2m) { int actual_pages_2m; - actual_pages_2m = vm_get_stat(vm, "pages_2m"); + actual_pages_2m = vm_get_stat(vm, pages_2m); TEST_ASSERT(actual_pages_2m == expected_pages_2m, "Unexpected 2m page count. Expected %d, got %d", @@ -84,7 +84,7 @@ static void check_split_count(struct kvm_vm *vm, int expected_splits) { int actual_splits; - actual_splits = vm_get_stat(vm, "nx_lpage_splits"); + actual_splits = vm_get_stat(vm, nx_lpage_splits); TEST_ASSERT(actual_splits == expected_splits, "Unexpected NX huge page split count. Expected %d, got %d",