From nobody Thu Dec 18 15:12:24 2025 Received: from mail-ua1-f74.google.com (mail-ua1-f74.google.com [209.85.222.74]) (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 F2C6C81741 for ; Thu, 27 Mar 2025 01:24:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743038696; cv=none; b=sCC7JzJmfaNk6MEe+enTRiBz+Utf0oo9pPzVegb/y+r8c+JaQVKSKzW3reo7SdEF2LtzM2h/CQw7doaxPKcfyUFDBuH0jVTDwhYTkQj7tugVKJxk0V0QOwus01EO8h9Vt8ZqVkuFopJvTr7sueEvegF06CBsNOx3+TNODjISvw0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743038696; c=relaxed/simple; bh=t3Wu8WcpTKr4Hin+dqDU2xino9yOT2vt8H5/bautCRE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=GTrE0MZ04Q6xlF5cASccV/HghArruzYyIyYx0yLjyTLAHpB2S5yVQ3q1rZroOejj0/ME8sYuvWdiozsAjj32t8kpiAZKLvTcZKrOs2iz5kn2aLlktTXjHTR3/7hFJamdgDTaTFbU5vVvrzUfRBGf6jjibGWdTb5JBDmnt8tnKcM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jthoughton.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=vDqshJIt; arc=none smtp.client-ip=209.85.222.74 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--jthoughton.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="vDqshJIt" Received: by mail-ua1-f74.google.com with SMTP id a1e0cc1a2514c-86d383c48ccso141468241.3 for ; Wed, 26 Mar 2025 18:24:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1743038694; x=1743643494; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=v0fJldEh3ljJ4akdD7WwAxn/Ekty9pCM03IX50ZdZwg=; b=vDqshJIt4TrIrHLwYkq2s+Ews+BnUk+gqOBJzu7lltl4HgZpUlnj8+0JntsuC5Wx3C zbWwuWKMohwzV3jg7+UmKhmZ8mlrUYYePEfzo0lAiatpG0UyKs5nEEi8i/2yQa6MQrpR w8s6VxRF2ZYF5ukqSO4pC4DWI4IZCiqF+TTT/Rjyvoan9OdwR15WR/NMxym4n9l/sULa DCQm/UQ3w8HjBtCu4/fDkLdd2f9W+Z5J8hiS8IdkHmAmBg+Wqrjslu4n3kVuvqcotiby lzUZYXYLAS441qTEIGCFTr1EvmL8XKzdhqTSB9rOrmBxsh4LIt9y7XV8gwlev+RYwh/O yLYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743038694; x=1743643494; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=v0fJldEh3ljJ4akdD7WwAxn/Ekty9pCM03IX50ZdZwg=; b=vJFKuWO9x7UP7V4MwAPnXm9uyww8odVDwSo1OJirp7otif8cHODx9b/lS6/damutmB wufoL7mhEBy1EnFLCFXwFHfxDsGsVA04SZJxjMdWUnAW5ijXrobZAQBEz0syQNZb0PiE 83HeO2juN9YBjX97iaOeWjiwkuVPnTcR0Fu8vmennPw9UE7VDSz3YSi2ZJoxraFJ/jYW LhmpDJnjt4bHj9yCKBz0rY9/8kRmoauMPwzJwXRwyYVT6sNok3UUpKwsKae88w5FjGsD 4N8tnFAVfTKbEx8yon8HngoyBAuWl57ZGRFBV8ak2610c8i0FNZl50L7MXS0ISPMAwdu YsJw== X-Forwarded-Encrypted: i=1; AJvYcCX3MwIXz92RwziT+DCPiAxxDG6Ax5qkpTCAjO/1yeySS6moeCbWbLc98NZFPokloWFJ6FIuRVNnFoyhIt0=@vger.kernel.org X-Gm-Message-State: AOJu0Yy4qNi6w0baewzg9AGHui1fq9Cl+Fre3eO70NIu/ZoP9p/oSiB5 Da16M1Sn/kcOxEAC7H//trIkuP3RVZOafbKvcDfJHGeq876hV1zOQdP+e8Hz7Np7Gj/v9uXy3L5 MgO7XvX5Ub1yo/ZXqpw== X-Google-Smtp-Source: AGHT+IFSht9Rl/okSnd4o3+xfp04VCJSDQHoeYgTEaziVfScJ5lh7/JF2NmdZD1IhD0J/mpc5enurRpuXJWld2NG X-Received: from uabil9.prod.google.com ([2002:a05:6130:6009:b0:86b:9d15:75ab]) (user=jthoughton job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6102:3585:b0:4c5:1bff:4589 with SMTP id ada2fe7eead31-4c5870b7afcmr2199208137.22.1743038693829; Wed, 26 Mar 2025 18:24:53 -0700 (PDT) Date: Thu, 27 Mar 2025 01:23:47 +0000 In-Reply-To: <20250327012350.1135621-1-jthoughton@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250327012350.1135621-1-jthoughton@google.com> X-Mailer: git-send-email 2.49.0.395.g12beb8f557-goog Message-ID: <20250327012350.1135621-3-jthoughton@google.com> Subject: [PATCH 2/5] KVM: selftests: access_tracking_perf_test: Add option to skip the sanity check From: James Houghton To: Sean Christopherson , kvm@vger.kernel.org Cc: Maxim Levitsky , Axel Rasmussen , Tejun Heo , Johannes Weiner , mkoutny@suse.com, Yu Zhao , James Houghton , cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Maxim Levitsky Add an option to skip sanity check of number of still idle pages, and set it by default to skip, in case hypervisor or NUMA balancing is detected. Signed-off-by: Maxim Levitsky Co-developed-by: James Houghton Signed-off-by: James Houghton Reviewed-by: Maxim Levitsky --- .../selftests/kvm/access_tracking_perf_test.c | 61 ++++++++++++++++--- .../testing/selftests/kvm/include/test_util.h | 1 + tools/testing/selftests/kvm/lib/test_util.c | 7 +++ 3 files changed, 60 insertions(+), 9 deletions(-) diff --git a/tools/testing/selftests/kvm/access_tracking_perf_test.c b/tool= s/testing/selftests/kvm/access_tracking_perf_test.c index 447e619cf856e..0e594883ec13e 100644 --- a/tools/testing/selftests/kvm/access_tracking_perf_test.c +++ b/tools/testing/selftests/kvm/access_tracking_perf_test.c @@ -65,6 +65,16 @@ static int vcpu_last_completed_iteration[KVM_MAX_VCPUS]; /* Whether to overlap the regions of memory vCPUs access. */ static bool overlap_memory_access; =20 +/* + * If the test should only warn if there are too many idle pages (i.e., it= is + * expected). + * -1: Not yet set. + * 0: We do not expect too many idle pages, so FAIL if too many idle page= s. + * 1: Having too many idle pages is expected, so merely print a warning if + * too many idle pages are found. + */ +static int idle_pages_warn_only =3D -1; + struct test_params { /* The backing source for the region of memory. */ enum vm_mem_backing_src_type backing_src; @@ -177,18 +187,12 @@ static void mark_vcpu_memory_idle(struct kvm_vm *vm, * arbitrary; high enough that we ensure most memory access went through * access tracking but low enough as to not make the test too brittle * over time and across architectures. - * - * When running the guest as a nested VM, "warn" instead of asserting - * as the TLB size is effectively unlimited and the KVM doesn't - * explicitly flush the TLB when aging SPTEs. As a result, more pages - * are cached and the guest won't see the "idle" bit cleared. */ if (still_idle >=3D pages / 10) { -#ifdef __x86_64__ - TEST_ASSERT(this_cpu_has(X86_FEATURE_HYPERVISOR), + TEST_ASSERT(idle_pages_warn_only, "vCPU%d: Too many pages still idle (%lu out of %lu)", vcpu_idx, still_idle, pages); -#endif + printf("WARNING: vCPU%d: Too many pages still idle (%lu out of %lu), " "this will affect performance results.\n", vcpu_idx, still_idle, pages); @@ -328,6 +332,31 @@ static void run_test(enum vm_guest_mode mode, void *ar= g) memstress_destroy_vm(vm); } =20 +static int access_tracking_unreliable(void) +{ +#ifdef __x86_64__ + /* + * When running nested, the TLB size is effectively unlimited and the + * KVM doesn't explicitly flush the TLB when aging SPTEs. As a result, + * more pages are cached and the guest won't see the "idle" bit cleared. + */ + if (this_cpu_has(X86_FEATURE_HYPERVISOR)) { + puts("Skipping idle page count sanity check, because the test is run nes= ted"); + return 1; + } +#endif + /* + * When NUMA balancing is enabled, guest memory can be mapped + * PROT_NONE, and the Accessed bits won't be queriable. + */ + if (is_numa_balancing_enabled()) { + puts("Skipping idle page count sanity check, because NUMA balancing is e= nabled"); + return 1; + } + + return 0; +} + static void help(char *name) { puts(""); @@ -342,6 +371,12 @@ static void help(char *name) printf(" -v: specify the number of vCPUs to run.\n"); printf(" -o: Overlap guest memory accesses instead of partitioning\n" " them into a separate region of memory for each vCPU.\n"); + printf(" -w: Control whether the test warns or fails if more than 10%\n" + " of pages are still seen as idle/old after accessing guest\n" + " memory. >0 =3D=3D warn only, 0 =3D=3D fail, <0 =3D=3D auto.= For auto\n" + " mode, the test fails by default, but switches to warn only\n" + " if NUMA balancing is enabled or the test detects it's runnin= g\n" + " in a VM.\n"); backing_src_help("-s"); puts(""); exit(0); @@ -359,7 +394,7 @@ int main(int argc, char *argv[]) =20 guest_modes_append_default(); =20 - while ((opt =3D getopt(argc, argv, "hm:b:v:os:")) !=3D -1) { + while ((opt =3D getopt(argc, argv, "hm:b:v:os:w:")) !=3D -1) { switch (opt) { case 'm': guest_modes_cmdline(optarg); @@ -376,6 +411,11 @@ int main(int argc, char *argv[]) case 's': params.backing_src =3D parse_backing_src_type(optarg); break; + case 'w': + idle_pages_warn_only =3D + atoi_non_negative("Idle pages warning", + optarg); + break; case 'h': default: help(argv[0]); @@ -388,6 +428,9 @@ int main(int argc, char *argv[]) "CONFIG_IDLE_PAGE_TRACKING is not enabled"); close(page_idle_fd); =20 + if (idle_pages_warn_only =3D=3D -1) + idle_pages_warn_only =3D access_tracking_unreliable(); + for_each_guest_mode(run_test, ¶ms); =20 return 0; diff --git a/tools/testing/selftests/kvm/include/test_util.h b/tools/testin= g/selftests/kvm/include/test_util.h index 77d13d7920cb8..c6ef895fbd9ab 100644 --- a/tools/testing/selftests/kvm/include/test_util.h +++ b/tools/testing/selftests/kvm/include/test_util.h @@ -153,6 +153,7 @@ bool is_backing_src_hugetlb(uint32_t i); void backing_src_help(const char *flag); enum vm_mem_backing_src_type parse_backing_src_type(const char *type_name); long get_run_delay(void); +bool is_numa_balancing_enabled(void); =20 /* * Whether or not the given source type is shared memory (as opposed to diff --git a/tools/testing/selftests/kvm/lib/test_util.c b/tools/testing/se= lftests/kvm/lib/test_util.c index 3dc8538f5d696..03eb99af9b8de 100644 --- a/tools/testing/selftests/kvm/lib/test_util.c +++ b/tools/testing/selftests/kvm/lib/test_util.c @@ -176,6 +176,13 @@ size_t get_trans_hugepagesz(void) return get_sysfs_val("/sys/kernel/mm/transparent_hugepage/hpage_pmd_size"= ); } =20 +bool is_numa_balancing_enabled(void) +{ + if (!test_sysfs_path("/proc/sys/kernel/numa_balancing")) + return false; + return get_sysfs_val("/proc/sys/kernel/numa_balancing") =3D=3D 1; +} + size_t get_def_hugetlb_pagesz(void) { char buf[64]; --=20 2.49.0.395.g12beb8f557-goog