From nobody Wed Dec 17 18:00:51 2025 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 9E0BE13CFA6 for ; Sat, 11 Jan 2025 00:30:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736555421; cv=none; b=d/yMiYrDBjCSbAAffKvT9XjJHb/ORwGLTrl6hHdjrkN1O16xlGcIgbnsAaNcbuJKwgY8Z2pGmcOlBswZ4VupFy5rkSpGxccjMgKofvihVLAL/gQK/p4b688/0AUzyKF2DKRV2jvuCVPo7qsthHEuWi4qij+yiPkksrfeoMCliHc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736555421; c=relaxed/simple; bh=rXm6MMpaJw1qyS71V+xzDjJly4UwYlWkG0d7xvwWsQY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=mgA1VbPw8H7fKudkm6cgKVqkdMNuzgt8zXpzUkO1tp6PXlg7APg61V6eUbl8xqCBcb6h2Qaaaa62h0U9QKBBXrPx1UtrmH6PoHXUWTOlILfj3c7+KAD+rf8GWX9mgRA8yY8zic+uKmSoC7BzTe1ubyV5mc38y0gTRmqWAzvai64= 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=QwBmfj0a; arc=none smtp.client-ip=209.85.216.73 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="QwBmfj0a" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2ee5616e986so6611180a91.2 for ; Fri, 10 Jan 2025 16:30:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736555419; x=1737160219; 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=6IhW12gqYntCz1+c2D5eBg8yPy5WGu0Pw6mNyLGrlAc=; b=QwBmfj0aX/nLbvgdBIxuKwpN3JomCHl7lT8hne1JEbhKbFG/LtH3wHityFXMvkA0zE 7ykVI/7KsstbTWD31dW1QlInBZMdZR0C4l7ENdgb1BQbm0ggPSd6D9qV5cA13vylbr1w Socwvgdzd4JERkV9vpHqMbY4qojF4GTszam29Ej6ym8peQw6ic2YTQhWT/909CPzZSg8 wz+M/ptizYuPOKQAKmEOHth/xQncpAiRCc+05nDoDj6S3ym6iOgSchH0mSwBiiPvpD46 dM6F9NAWwuAizQm59chGhiwocofoSFyCmjLKTd4JOy4oUscbecyHaMIKMh2J4bURNs+r F/SA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736555419; x=1737160219; 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=6IhW12gqYntCz1+c2D5eBg8yPy5WGu0Pw6mNyLGrlAc=; b=fUhLf3nsH/WKa/6P5cWx8u80KxD/89yy1qcWZIvcgPAeW/PLbhZX9Z3HiLy6z6Opyq kJ7qM2ilydkf1MonL2gHbPaVm9LZvrxXmjDEg0rqq1Mz4MkzaE89kakHPMCFiapnv819 94gHuoyD/Ibep+xx6oxuniPCGQKJue+yAeoFbCOQlynDYYxTONIv60OrHYj/F394/8cF GHZdgFUoOAblKmtjIcjgZqj5ubnPKdEsA6MunlFM+x2WhUOu/ogptgzenwI4Frx+v6Cx QkUlC1VSD0oRjTULBTM9xroxEJY6zVu56A12CCU3BqZgXccT0AWPauYaFFsMMYAkdmIR TTIw== X-Forwarded-Encrypted: i=1; AJvYcCXqjV4gOqrL3UdTZTB//gYT1+xf84yip2B3cAuf11+H7udArvam9rNt7WinecS4gGVES05W6sJFBup4AFo=@vger.kernel.org X-Gm-Message-State: AOJu0YxBjFf1gDYPht0m6xrRNWz8g3YOE9Zg6r2NtbKd+3w2zJxxajre OpVGELj8L/J5RVOPptcJZ0jS3PWW/xY/1E1iQgQXh5ELaw7/dEjdXTMXM4nDieMHqxZipTiDkZ9 1sw== X-Google-Smtp-Source: AGHT+IGBV97wTYRM8hlFr4fJkGJVU7xqzfHB/Clf/Nbfpa7h/esWcwhR69zEh8pcrRr99qn6u0ZSD0nAMiI= X-Received: from pjwx3.prod.google.com ([2002:a17:90a:c2c3:b0:2ea:931d:7ced]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:2d43:b0:2ee:fdf3:390d with SMTP id 98e67ed59e1d1-2f5490ed82dmr16491422a91.31.1736555418949; Fri, 10 Jan 2025 16:30:18 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 10 Jan 2025 16:29:50 -0800 In-Reply-To: <20250111003004.1235645-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250111003004.1235645-1-seanjc@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20250111003004.1235645-7-seanjc@google.com> Subject: [PATCH v2 06/20] KVM: selftests: Read per-page value into local var when verifying dirty_log_test From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Peter Xu , Maxim Levitsky , Sean Christopherson Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Cache the page's value during verification in a local variable, re-reading from the pointer is ugly and error prone, e.g. allows for bugs like checking the pointer itself instead of the value. No functional change intended. Reviewed-by: Maxim Levitsky Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/dirty_log_test.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/tools/testing/selftests/kvm/dirty_log_test.c b/tools/testing/s= elftests/kvm/dirty_log_test.c index 08cbecd1a135..5a04a7bd73e0 100644 --- a/tools/testing/selftests/kvm/dirty_log_test.c +++ b/tools/testing/selftests/kvm/dirty_log_test.c @@ -520,11 +520,10 @@ static void vm_dirty_log_verify(enum vm_guest_mode mo= de, unsigned long *bmap) { uint64_t page, nr_dirty_pages =3D 0, nr_clean_pages =3D 0; uint64_t step =3D vm_num_host_pages(mode, 1); - uint64_t *value_ptr; uint64_t min_iter =3D 0; =20 for (page =3D 0; page < host_num_pages; page +=3D step) { - value_ptr =3D host_test_mem + page * host_page_size; + uint64_t val =3D *(uint64_t *)(host_test_mem + page * host_page_size); =20 /* If this is a special page that we were tracking... */ if (__test_and_clear_bit_le(page, host_bmap_track)) { @@ -545,11 +544,10 @@ static void vm_dirty_log_verify(enum vm_guest_mode mo= de, unsigned long *bmap) * the corresponding page should be either the * previous iteration number or the current one. */ - matched =3D (*value_ptr =3D=3D iteration || - *value_ptr =3D=3D iteration - 1); + matched =3D (val =3D=3D iteration || val =3D=3D iteration - 1); =20 if (host_log_mode =3D=3D LOG_MODE_DIRTY_RING && !matched) { - if (*value_ptr =3D=3D iteration - 2 && min_iter <=3D iteration - 2) { + if (val =3D=3D iteration - 2 && min_iter <=3D iteration - 2) { /* * Short answer: this case is special * only for dirty ring test where the @@ -597,7 +595,7 @@ static void vm_dirty_log_verify(enum vm_guest_mode mode= , unsigned long *bmap) TEST_ASSERT(matched, "Set page %"PRIu64" value %"PRIu64 " incorrect (iteration=3D%"PRIu64")", - page, *value_ptr, iteration); + page, val, iteration); } else { nr_clean_pages++; /* @@ -619,11 +617,11 @@ static void vm_dirty_log_verify(enum vm_guest_mode mo= de, unsigned long *bmap) * we'll see that page P is cleared, with * value "iteration-1". */ - TEST_ASSERT(*value_ptr <=3D iteration, + TEST_ASSERT(val <=3D iteration, "Clear page %"PRIu64" value %"PRIu64 " incorrect (iteration=3D%"PRIu64")", - page, *value_ptr, iteration); - if (*value_ptr =3D=3D iteration) { + page, val, iteration); + if (val =3D=3D iteration) { /* * This page is _just_ modified; it * should report its dirtyness in the --=20 2.47.1.613.gc27f4b7a9f-goog