From nobody Wed Nov 27 16:52:50 2024 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 4E8F7204F98 for ; Wed, 9 Oct 2024 15:50:23 +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=1728489024; cv=none; b=Wr8cqSMgMay6onj1cZZ8uSahM6WgsPBc/5iAf1Z+VD8B88pwqYQvetYVUEC0pwdZILkpl7aPGWsmYODZvQTdOrHheF00RZr3xirpO8RISXzkwayEkF7A5Apuvqfd9qzi+nbtSmot18nbZUQdG5a/wDgGJxazYk0ki1wXI18uQQc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728489024; c=relaxed/simple; bh=L+zYpIw4P5/gRa37oTXv0c2QuaS7Yn3cq9MWxsxRKK4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=l2kG8erQ8FkO59uUGTyPuDu8onczyVuW602/FqlMLVaFniJ9p64Ja7SKsOBqYl86rvmIx7QUyxn5CYyuOD4YANWvEajNjhJgdFIn8u0xXGqli2LzRJOxH5VE3iv31eqlUIphP9gKp+CALtMjfztAHuJvLfPokGHe7knPw4NZyas= 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=XGyWBYQv; 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="XGyWBYQv" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-7e9fe0a21a7so3418843a12.3 for ; Wed, 09 Oct 2024 08:50:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728489023; x=1729093823; 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=EGuxTu/doK/WQ641h0uZhH1HM6LHjGgjZS75tNbw6SU=; b=XGyWBYQvcXRzOlkMt5LWPfjY3zmFTgna2TUiC1AeU65mDr2oJAWv2Q2DXshHtSlPYz z0VKn6qloPeO3PP3JvgH2byIkO7k1vknjYmM0HotPanr/A5AjPrQlZUvH+Om+EGtItUn JKdjSUUvcGxQw5Io0ydrmstWc9TKLdlhL+x+Gad52ArG5zG5ng7tF9XBcoP1wrfvAnHZ ICPEuzXjq+Gx/M1QvB91F1rgFJ6Mn4J8wrFK1FUKbXS92getUy0KkTa/cJn4pS4vgWXc hIPkic7pbrXRnPiMggAXcUsLPihADnwi8BBkCfiRw0aNM5C+t4OIiIXs7UyRA22I4DgB re7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728489023; x=1729093823; 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=EGuxTu/doK/WQ641h0uZhH1HM6LHjGgjZS75tNbw6SU=; b=Sk1yakTQvx6eu8zCLwinX9AOErbN0Srse1eOpRiqyE6z8ZkIUOWgK+HHQNHIaFTbfc KW6hFYDZUsnyy8rNOJgTX1aGePPTplMSjNMorwLzXRPHQZmJfzpQp9iQeKTNLiaZRV6/ ofan6liv48asXvQdKy5RN2Nzyd778Zyf0F1Fz2jb2YTEn0WmAjsIc/+gHmZLxw7Pqlxf XspB4YMtdimtvAYV7kQ1XzGoiRl1R+tOCLXaOW4Z/zOdRwzvLqfvnKjAT+EJ59zrx/WW IZ50A7L6OOCRU8srdJcDKQWoKk/jDkf97muFMHaWxTC4YHM+G1UrqppdOfytxf44emgY gu9g== X-Forwarded-Encrypted: i=1; AJvYcCUYrwUuQBOA9Dogo4AJnilgTvzW3iO46frbm64BmE1wmIFJvN9VNdrk1mIyNxvvDJuuo394qJa7qtBOkmw=@vger.kernel.org X-Gm-Message-State: AOJu0YyDeZkTBGrxVvjfH9bbOXhzGYH2ZdV0c5Rk0O+U8nKj8PmTXPpc vYz3Lsj0KFa7BdArxsUQaptGjaysFghmIPi8iXmZUL4WsaVLNf7C0Gp1J6XEyrdIyi+DTH+Mv0g ubA== X-Google-Smtp-Source: AGHT+IG8czWnoykzOejAJo4GJw9hcMcaR/sDDZx+5vRUFyaEmI5qH9Oe9i56gZjLIllNwEPwjpmEWoICf38= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:9d:3983:ac13:c240]) (user=seanjc job=sendgmr) by 2002:a63:704c:0:b0:7cd:8363:9f29 with SMTP id 41be03b00d2f7-7ea320345ffmr3164a12.2.1728489022361; Wed, 09 Oct 2024 08:50:22 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 9 Oct 2024 08:49:52 -0700 In-Reply-To: <20241009154953.1073471-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: <20241009154953.1073471-1-seanjc@google.com> X-Mailer: git-send-email 2.47.0.rc0.187.ge670bccf7e-goog Message-ID: <20241009154953.1073471-14-seanjc@google.com> Subject: [PATCH v3 13/14] KVM: selftests: Add a read-only mprotect() phase to mmu_stress_test From: Sean Christopherson To: Marc Zyngier , Oliver Upton , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Paolo Bonzini , Christian Borntraeger , Janosch Frank , Claudio Imbrenda 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, Sean Christopherson , Andrew Jones , James Houghton Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a third phase of mmu_stress_test to verify that mprotect()ing guest memory to make it read-only doesn't cause explosions, e.g. to verify KVM correctly handles the resulting mmu_notifier invalidations. Reviewed-by: James Houghton Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/mmu_stress_test.c | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/kvm/mmu_stress_test.c b/tools/testing/= selftests/kvm/mmu_stress_test.c index c6bf18cb7c89..0918fade9267 100644 --- a/tools/testing/selftests/kvm/mmu_stress_test.c +++ b/tools/testing/selftests/kvm/mmu_stress_test.c @@ -28,6 +28,10 @@ static void guest_code(uint64_t start_gpa, uint64_t end_= gpa, uint64_t stride) GUEST_SYNC(i); } =20 + for (gpa =3D start_gpa; gpa < end_gpa; gpa +=3D stride) + *((volatile uint64_t *)gpa); + GUEST_SYNC(2); + GUEST_ASSERT(0); } =20 @@ -95,6 +99,10 @@ static void *vcpu_worker(void *data) run_vcpu(vcpu, 1); rendezvous_with_boss(); =20 + /* Stage 2, read all of guest memory, which is now read-only. */ + run_vcpu(vcpu, 2); + rendezvous_with_boss(); + return NULL; } =20 @@ -175,7 +183,7 @@ int main(int argc, char *argv[]) const uint64_t start_gpa =3D SZ_4G; const int first_slot =3D 1; =20 - struct timespec time_start, time_run1, time_reset, time_run2; + struct timespec time_start, time_run1, time_reset, time_run2, time_ro; uint64_t max_gpa, gpa, slot_size, max_mem, i; int max_slots, slot, opt, fd; bool hugepages =3D false; @@ -279,14 +287,20 @@ int main(int argc, char *argv[]) rendezvous_with_vcpus(&time_reset, "reset"); rendezvous_with_vcpus(&time_run2, "run 2"); =20 + mprotect(mem, slot_size, PROT_READ); + rendezvous_with_vcpus(&time_ro, "mprotect RO"); + + time_ro =3D timespec_sub(time_ro, time_run2); time_run2 =3D timespec_sub(time_run2, time_reset); - time_reset =3D timespec_sub(time_reset, time_run1); + time_reset =3D timespec_sub(time_reset, time_run1); time_run1 =3D timespec_sub(time_run1, time_start); =20 - pr_info("run1 =3D %ld.%.9lds, reset =3D %ld.%.9lds, run2 =3D %ld.%.9lds\= n", + pr_info("run1 =3D %ld.%.9lds, reset =3D %ld.%.9lds, run2 =3D %ld.%.9lds, " + "ro =3D %ld.%.9lds\n", time_run1.tv_sec, time_run1.tv_nsec, time_reset.tv_sec, time_reset.tv_nsec, - time_run2.tv_sec, time_run2.tv_nsec); + time_run2.tv_sec, time_run2.tv_nsec, + time_ro.tv_sec, time_ro.tv_nsec); =20 /* * Delete even numbered slots (arbitrary) and unmap the first half of --=20 2.47.0.rc0.187.ge670bccf7e-goog