From patchwork Wed Oct 9 15:49:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13828688 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 BAD671FF7BC for ; Wed, 9 Oct 2024 15:49:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728489000; cv=none; b=KvjHH2s/9BK6G+5al92oR9jHGQvJiKKbm3ID/1VT9C6FJE9i35wflMAkojjx8PU80rQWVljPXmdv6to5k2USaVoX95By64QCHS6FfdXUFfJuRppVczzocmFuOsRfj+hTPILWwE20pVfYkR88jTSZ3U/DPmI1Ei6SQib8E/nxLBk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728489000; c=relaxed/simple; bh=LPFOToixC43DMJpxxdLhELluVDI5pW/ki1X7rgFZYA4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=O6IK7JrUlrFK0nnubwwEWMBKb1Rnsyx3fmPY+3sm14oQHyL4HDRBPjUX29+YgkKt9iLX2pUKDHfkxh8L81ldp7BsA9zmVTraaIYiTnC0PxckKCAO1u4Pqm1/fO+xLEkxCMxCwdqValMrDbfQur4Fep+OJ89SaxgU3uxp+j1KFZs= 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=ZDEVa4PD; arc=none smtp.client-ip=209.85.128.202 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="ZDEVa4PD" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-690404fd230so59396737b3.3 for ; Wed, 09 Oct 2024 08:49:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728488998; x=1729093798; 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=+3zZkwU+2EpnRGguJhn2Ww+Ghmvy6uOMqwsBdHy8Row=; b=ZDEVa4PDOhQ1q/Q0LSGFJku8Btp1er6OCVG6vGwD+/yDBR6aZA8GPUOV3Vb10jIHvM 7ok0cW2YCsnop9udUND3nhQjNn2vFzZfinkObODIfkztzLYczolMRha4Vw7+444EyiiC rOdmLaGO3uabbVEg98u9vyRSumhJ+YgscW6mfRG3l5Bh0NSQipcyDps4PAv9IaEX6B0L Jn5n5MdDIfIkEjsyirpaA2oGAF78rdWuvvIrG4qCAGVm8bcsuLXxDo16cWsMy+9JNie1 JK73gvZOikKA5YsCekCCRo9SKVlEBEGju00xWZjS9QcDr6C0cmIT3wII/Y7AsKFpT/Zj fRqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728488998; x=1729093798; 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=+3zZkwU+2EpnRGguJhn2Ww+Ghmvy6uOMqwsBdHy8Row=; b=kezg4MAorPXKTJpRDyfo96uKRc4kEZGbK/n/yaUryKba4X33xR6B777+5fRQS60rw5 L99r9J6MOK5P58vk8yTfYNVngAqrTe69ztka4JTj6vu8xI9atDB3kkiNcT5zfvYs+FI7 pBsZ07CqDagHtxZAzinS7eOkC5LLazWxkedq1zCpFtdxtzGLQR2ZscTe8w4+iO0+FGwz ooLTuD7cyzGIwZ7CYt7Ekl8FvuL/YnK4uOP824xK7Mefvi+ZQD+PGizsdbEkWnika/yv dJV46hl2LV44GD593WcsKuiJ25W40+atq+olCyc7O/gLDCYCZefOL00vqZ1rAm7MC6sV en3g== X-Forwarded-Encrypted: i=1; AJvYcCVtlvu6l5HLgJBmKZngYqYVans0aIlUHlUR6ixTnCMFab51hnnVpf+TBsRdo6h9o7GHK9g=@vger.kernel.org X-Gm-Message-State: AOJu0YxQ60iyADDk8zlidw/ya0OeAOLbAZnX1rh13ESG8p/wKHIsCUZH fLonkCRiEG5+iQ9JwOfAwcqEe8KkTKacQej7uVzFqpPeCF/isHr4vgIx1v5ONwl5Vu4Ra2uaMjq R/A== X-Google-Smtp-Source: AGHT+IGq8S+cJ3hbYyw4prFkdU6bbiVB3Ddo6czJU4p6VUDHrgM9P6PS5yQttOYl+xpjVaNBwpEpnchtMNk= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:9d:3983:ac13:c240]) (user=seanjc job=sendgmr) by 2002:a05:690c:460d:b0:6db:89f0:b897 with SMTP id 00721157ae682-6e3221683d8mr69407b3.4.1728488997664; Wed, 09 Oct 2024 08:49:57 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 9 Oct 2024 08:49:40 -0700 In-Reply-To: <20241009154953.1073471-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@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-2-seanjc@google.com> Subject: [PATCH v3 01/14] KVM: Move KVM_REG_SIZE() definition to common uAPI header 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 Define KVM_REG_SIZE() in the common kvm.h header, and delete the arm64 and RISC-V versions. As evidenced by the surrounding definitions, all aspects of the register size encoding are generic, i.e. RISC-V should have moved arm64's definition to common code instead of copy+pasting. Signed-off-by: Sean Christopherson Acked-by: Anup Patel --- arch/arm64/include/uapi/asm/kvm.h | 3 --- arch/riscv/include/uapi/asm/kvm.h | 3 --- include/uapi/linux/kvm.h | 4 ++++ 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/arch/arm64/include/uapi/asm/kvm.h b/arch/arm64/include/uapi/asm/kvm.h index 964df31da975..80b26134e59e 100644 --- a/arch/arm64/include/uapi/asm/kvm.h +++ b/arch/arm64/include/uapi/asm/kvm.h @@ -43,9 +43,6 @@ #define KVM_COALESCED_MMIO_PAGE_OFFSET 1 #define KVM_DIRTY_LOG_PAGE_OFFSET 64 -#define KVM_REG_SIZE(id) \ - (1U << (((id) & KVM_REG_SIZE_MASK) >> KVM_REG_SIZE_SHIFT)) - struct kvm_regs { struct user_pt_regs regs; /* sp = sp_el0 */ diff --git a/arch/riscv/include/uapi/asm/kvm.h b/arch/riscv/include/uapi/asm/kvm.h index e97db3296456..4f8d0c04a47b 100644 --- a/arch/riscv/include/uapi/asm/kvm.h +++ b/arch/riscv/include/uapi/asm/kvm.h @@ -207,9 +207,6 @@ struct kvm_riscv_sbi_sta { #define KVM_RISCV_TIMER_STATE_OFF 0 #define KVM_RISCV_TIMER_STATE_ON 1 -#define KVM_REG_SIZE(id) \ - (1U << (((id) & KVM_REG_SIZE_MASK) >> KVM_REG_SIZE_SHIFT)) - /* If you need to interpret the index values, here is the key: */ #define KVM_REG_RISCV_TYPE_MASK 0x00000000FF000000 #define KVM_REG_RISCV_TYPE_SHIFT 24 diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 637efc055145..9deeb13e3e01 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -1070,6 +1070,10 @@ struct kvm_dirty_tlb { #define KVM_REG_SIZE_SHIFT 52 #define KVM_REG_SIZE_MASK 0x00f0000000000000ULL + +#define KVM_REG_SIZE(id) \ + (1U << (((id) & KVM_REG_SIZE_MASK) >> KVM_REG_SIZE_SHIFT)) + #define KVM_REG_SIZE_U8 0x0000000000000000ULL #define KVM_REG_SIZE_U16 0x0010000000000000ULL #define KVM_REG_SIZE_U32 0x0020000000000000ULL From patchwork Wed Oct 9 15:49:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13828689 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.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 D7C7C20011C for ; Wed, 9 Oct 2024 15:50:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728489002; cv=none; b=n/Sz7yrGeMXPfIQ5hH/igG3si9ppmCaOKryaMbBm2rDUSZdmjpp4alGTg131gRTiNo7LOEoLpk6VK8MZDxYeJNFrflVgSOHmP1IKNPFgABXo8GcchKwkvEevhABfXjcr96kT5/dPYbzF65M/WpTRPyoM5wfL/OMaZ1UBOBOXw64= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728489002; c=relaxed/simple; bh=/7fWtV+q7/Fq6/s5md+zD0Cb6GIP2xL9NGhc499VzYw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=vGdD4peTdonFs4uXPkhraAhpmI+rodfvzRSjXl3YCl53vJCOB/FWlaCpPEj1saYcyNwpSUV04D4AwRORcA8EMwvEHjdrpyhD0ZEWByOmklTAZDCOm1SNA8UP2hD7wwbyqJrJDK8b5GsHPNHa9DMTOCuQ673c/IRoNNWI3lffBoQ= 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=Zl0xW/N1; arc=none smtp.client-ip=209.85.219.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="Zl0xW/N1" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e262e764f46so11720571276.1 for ; Wed, 09 Oct 2024 08:50:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728489000; x=1729093800; 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=jVTsixz4sZ4koZFPUtECwdZDuBQDlBcuBCpi0vcsFcE=; b=Zl0xW/N1UhvCYjDzwG3PWxW2toYTEheC0YCTX8BmhyASF7lpfmJEOPP9Ylm71LpDuy 0iJokk70f2MFxyZxv0Ngtfz8gPUXf/zVHELWWqKZbx7w9NocOOo06eKB3WhVknsC+Fii Jkc9xjVa9jPbNva3NFFbJ/WO7iHTmoZ5EtnsmCprmgx+4eqzG9/jaCiZr5wBNYQ3e5e6 mpL+FYegINY9kc6R+uxmqX9qXCq/c6yjALMw2zVoasqUiL9eVJiC+nxClyri6ic5liXh T8KSk/wE1nxsUoLRrYeEl6oF3vxgfcumgbouDVTn4pasBnlJypNUjKXQqE9eyIxmziTY zXAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728489000; x=1729093800; 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=jVTsixz4sZ4koZFPUtECwdZDuBQDlBcuBCpi0vcsFcE=; b=NYKqNoQVaUk9IIADgADi0lA/Oe0rDR6GrcofIp4chetVzoXJwQhnNzY1gbYL3NTg4X y1f+RwsYoD2mPvGYpnI3Lv5nEWwMX7YJnwrOyO72JlSbfBThxcrb68uTtzUzCRVqapI2 Ob1LGFAbYXdCkxcIyT3V32ZbR7UDeCcx7PMiVTds0TSwvEEJhDUKX8zA+eogXiKzFUEh TdU6y+rcUtaHxc2H9exD/l5H00NR6YGEkzJlixODaE+hBg/4V3J5RsFtO5NHtD7TP0W8 RiuSOz/Bn21/xvD+35l2GgT1sKTWbTc/e9QkbHixvSzYoA8KQWMxPJuu7YLWsvJmoD5I KDdg== X-Forwarded-Encrypted: i=1; AJvYcCWn+xXX3+ks8wHR9EQ+aAwr7wEfZ/vX89f5hDZXHi3ebDzvm7j31B3Y831tTB02N9wBs/E=@vger.kernel.org X-Gm-Message-State: AOJu0YwV54jqfMAWcb0xG7uCbSUTIpuCMyeGd1nhLtOvc9YE4pc2pPRR cDb2rk/JgAl3VD8V1kSNLnCcgTa3T1x2CKErfhsqjd77V3qWgE5QreFDt7Jrrkx3WDbOoqaLY/U kHw== X-Google-Smtp-Source: AGHT+IFJReZxJVdNM9WOc4CTIpT8xwBaol9zgUnZweoXlrW7QgctCL6Q+XRwMroT/XXO2vZfV7gZvg3Vxc0= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:9d:3983:ac13:c240]) (user=seanjc job=sendgmr) by 2002:a05:6902:4ac:b0:e28:fdfc:b788 with SMTP id 3f1490d57ef6-e28fe4426b8mr2248276.9.1728488999652; Wed, 09 Oct 2024 08:49:59 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 9 Oct 2024 08:49:41 -0700 In-Reply-To: <20241009154953.1073471-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@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-3-seanjc@google.com> Subject: [PATCH v3 02/14] KVM: selftests: Disable strict aliasing 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 Disable strict aliasing, as has been done in the kernel proper for decades (literally since before git history) to fix issues where gcc will optimize away loads in code that looks 100% correct, but is _technically_ undefined behavior, and thus can be thrown away by the compiler. E.g. arm64's vPMU counter access test casts a uint64_t (unsigned long) pointer to a u64 (unsigned long long) pointer when setting PMCR.N via u64p_replace_bits(), which gcc-13 detects and optimizes away, i.e. ignores the result and uses the original PMCR. The issue is most easily observed by making set_pmcr_n() noinline and wrapping the call with printf(), e.g. sans comments, for this code: printf("orig = %lx, next = %lx, want = %lu\n", pmcr_orig, pmcr, pmcr_n); set_pmcr_n(&pmcr, pmcr_n); printf("orig = %lx, next = %lx, want = %lu\n", pmcr_orig, pmcr, pmcr_n); gcc-13 generates: 0000000000401c90 : 401c90: f9400002 ldr x2, [x0] 401c94: b3751022 bfi x2, x1, #11, #5 401c98: f9000002 str x2, [x0] 401c9c: d65f03c0 ret 0000000000402660 : 402724: aa1403e3 mov x3, x20 402728: aa1503e2 mov x2, x21 40272c: aa1603e0 mov x0, x22 402730: aa1503e1 mov x1, x21 402734: 940060ff bl 41ab30 <_IO_printf> 402738: aa1403e1 mov x1, x20 40273c: 910183e0 add x0, sp, #0x60 402740: 97fffd54 bl 401c90 402744: aa1403e3 mov x3, x20 402748: aa1503e2 mov x2, x21 40274c: aa1503e1 mov x1, x21 402750: aa1603e0 mov x0, x22 402754: 940060f7 bl 41ab30 <_IO_printf> with the value stored in [sp + 0x60] ignored by both printf() above and in the test proper, resulting in a false failure due to vcpu_set_reg() simply storing the original value, not the intended value. $ ./vpmu_counter_access Random seed: 0x6b8b4567 orig = 3040, next = 3040, want = 0 orig = 3040, next = 3040, want = 0 ==== Test Assertion Failure ==== aarch64/vpmu_counter_access.c:505: pmcr_n == get_pmcr_n(pmcr) pid=71578 tid=71578 errno=9 - Bad file descriptor 1 0x400673: run_access_test at vpmu_counter_access.c:522 2 (inlined by) main at vpmu_counter_access.c:643 3 0x4132d7: __libc_start_call_main at libc-start.o:0 4 0x413653: __libc_start_main at ??:0 5 0x40106f: _start at ??:0 Failed to update PMCR.N to 0 (received: 6) Somewhat bizarrely, gcc-11 also exhibits the same behavior, but only if set_pmcr_n() is marked noinline, whereas gcc-13 fails even if set_pmcr_n() is inlined in its sole caller. Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116912 Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile index 960cf6a77198..6246d69d82d7 100644 --- a/tools/testing/selftests/kvm/Makefile +++ b/tools/testing/selftests/kvm/Makefile @@ -241,10 +241,10 @@ CFLAGS += -Wall -Wstrict-prototypes -Wuninitialized -O2 -g -std=gnu99 \ -Wno-gnu-variable-sized-type-not-at-end -MD -MP -DCONFIG_64BIT \ -fno-builtin-memcmp -fno-builtin-memcpy \ -fno-builtin-memset -fno-builtin-strnlen \ - -fno-stack-protector -fno-PIE -I$(LINUX_TOOL_INCLUDE) \ - -I$(LINUX_TOOL_ARCH_INCLUDE) -I$(LINUX_HDR_PATH) -Iinclude \ - -I$( X-Patchwork-Id: 13828690 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 BED602010E6 for ; Wed, 9 Oct 2024 15:50:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728489005; cv=none; b=mgLd1ydr96i/bfj+3jtgLv7AGtI2wNjHhvmewfldq77gwnKdvYnLMTu8HUugiGtU93DJLn6NgiSMx6Fh3j8TIHZvcMzdgNkyENr5Nfto7z5Cfs1jDRlPP4EAxXouy/Y0gkozHpL3w0+wxMZGC8y7O28OiSqIDMJEAWDJODWc/hE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728489005; c=relaxed/simple; bh=mascmOoR+U8Uop0PV1U2Hewwvq3+nx5/Wf91f8Bpnys=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=KGzZTX4/FfBiUU9nb0UABMTOGyK/ezf+lEjdpQMIqKmZVpTIfX/h2dBy9JTSC1gOm+7zHrrf4YPADhXuhJLlBNpQdvG10Jpb2iwhI+DRqZvCYGhCjMxCwk31msoBxbjf5A0NZkCNoEBEksUyw7nxNaW0QMs7/uoceSD/AtbPoZQ= 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=Fu4kAK5y; arc=none smtp.client-ip=209.85.128.202 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="Fu4kAK5y" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6886cd07673so129318457b3.3 for ; Wed, 09 Oct 2024 08:50:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728489002; x=1729093802; 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=EiPL5cI8NvF0twMUG6Y300Z+LBOp/l7tSBViVr6g/nI=; b=Fu4kAK5ybutU56Ysd00rI1CVmo+FY+1C/aMnxgg4ilLzVDc6aLIwzzzNeZD6knBtUJ QxmvDHD2PlsDghdo8KGM8EXtKYXYH9dOLnhgD0TacnqT+1Gl9uEfmkV12CMJ0GKYXWaB t8JOkqGuY+meBfdahEFdeHRxY2eiaV/9hyB3wFa7sLoa6/SlV8DNKGr+OlT6jf1upDfE Q5xzAlTCWL/Y8XNQaK1wK9D+XojEjXXnfs9tW3htL87UwE6X8Rg1p2JzzkFwAz+5ekGv sPUXLn3VYxLx+vDeHwJTlseK/Bc/XgCylw2qyZGTlz2t3y2+4k8J+Ou6PIAtJY5OdYSu ROtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728489002; x=1729093802; 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=EiPL5cI8NvF0twMUG6Y300Z+LBOp/l7tSBViVr6g/nI=; b=MdNDFmaJ6xjEbaTG+YdifmQws5vsNUGo3z5XFfKWk9e/dygwp4FiVE9yGWsBzavXyg ltnx/3cHeH/AXh3WrEuSDYTT3R4ByDt4xx942i5FUY1SUOZdru57INmHXSifTQdtqvtn tPuT+NWteZXik1w3vLln14ahjriJltjTQ8dn1ZJm+/5b+piMCbZO/4e65hiWcM5+TzRc rsd7VxWYgBtN0vZ/brV70HrXFc/ezgVXC8i2AU0bYxwKobwAZpFee9OrLaCVVilJXrIJ 3zgmV9ps/QVohcXEdKjW9z/Iloo2RMeZabQy8kW0HpG/we8uufrJ/tqVbEKX0xE/NAOQ FcDQ== X-Forwarded-Encrypted: i=1; AJvYcCUPhnZSTGheg2JD+/sZxf4pup9c/PAOhzMnL0VpxQ75FDWjL4Jiu1AImWnNRaZmv7YVH80=@vger.kernel.org X-Gm-Message-State: AOJu0YyBmK0sCZMkPOULjTyFf1/RpkOkX4TNTB1geN6rpzmkwF2YDJGZ BfgiX8ILSdbc/g7uYIc2Ewg5jelIxnjE8G5QOpb2oyDLVvabHIPaGn/C+E1WQT804zhR3dUFTF1 ysQ== X-Google-Smtp-Source: AGHT+IHkLjmdUrZYhhm5eRcfFOqOUhABNFF7PuEYH6Y5okDTpmSWv2NhEiyKmUQ7vk7izRkmLFjJAO6m578= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:9d:3983:ac13:c240]) (user=seanjc job=sendgmr) by 2002:a05:690c:987:b0:6e2:1842:c2e9 with SMTP id 00721157ae682-6e32244b67dmr225727b3.4.1728489001806; Wed, 09 Oct 2024 08:50:01 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 9 Oct 2024 08:49:42 -0700 In-Reply-To: <20241009154953.1073471-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@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-4-seanjc@google.com> Subject: [PATCH v3 03/14] KVM: selftests: Return a value from vcpu_get_reg() instead of using an out-param 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 Return a uint64_t from vcpu_get_reg() instead of having the caller provide a pointer to storage, as none of the vcpu_get_reg() usage in KVM selftests accesses a register larger than 64 bits, and vcpu_set_reg() only accepts a 64-bit value. If a use case comes along that needs to get a register that is larger than 64 bits, then a utility can be added to assert success and take a void pointer, but until then, forcing an out param yields ugly code and prevents feeding the output of vcpu_get_reg() into vcpu_set_reg(). Reviewed-by: Andrew Jones Signed-off-by: Sean Christopherson --- .../selftests/kvm/aarch64/aarch32_id_regs.c | 10 +-- .../selftests/kvm/aarch64/debug-exceptions.c | 4 +- .../selftests/kvm/aarch64/hypercalls.c | 6 +- .../selftests/kvm/aarch64/no-vgic-v3.c | 2 +- .../testing/selftests/kvm/aarch64/psci_test.c | 6 +- .../selftests/kvm/aarch64/set_id_regs.c | 18 ++--- .../kvm/aarch64/vpmu_counter_access.c | 19 +++--- .../testing/selftests/kvm/include/kvm_util.h | 6 +- .../selftests/kvm/lib/aarch64/processor.c | 8 +-- .../selftests/kvm/lib/riscv/processor.c | 66 +++++++++---------- .../testing/selftests/kvm/riscv/arch_timer.c | 2 +- .../testing/selftests/kvm/riscv/ebreak_test.c | 2 +- .../selftests/kvm/riscv/sbi_pmu_test.c | 2 +- tools/testing/selftests/kvm/s390x/resets.c | 2 +- tools/testing/selftests/kvm/steal_time.c | 3 +- 15 files changed, 78 insertions(+), 78 deletions(-) diff --git a/tools/testing/selftests/kvm/aarch64/aarch32_id_regs.c b/tools/testing/selftests/kvm/aarch64/aarch32_id_regs.c index 8e5bd07a3727..447d61cae4db 100644 --- a/tools/testing/selftests/kvm/aarch64/aarch32_id_regs.c +++ b/tools/testing/selftests/kvm/aarch64/aarch32_id_regs.c @@ -97,7 +97,7 @@ static void test_user_raz_wi(struct kvm_vcpu *vcpu) uint64_t reg_id = raz_wi_reg_ids[i]; uint64_t val; - vcpu_get_reg(vcpu, reg_id, &val); + val = vcpu_get_reg(vcpu, reg_id); TEST_ASSERT_EQ(val, 0); /* @@ -106,7 +106,7 @@ static void test_user_raz_wi(struct kvm_vcpu *vcpu) */ vcpu_set_reg(vcpu, reg_id, BAD_ID_REG_VAL); - vcpu_get_reg(vcpu, reg_id, &val); + val = vcpu_get_reg(vcpu, reg_id); TEST_ASSERT_EQ(val, 0); } } @@ -126,14 +126,14 @@ static void test_user_raz_invariant(struct kvm_vcpu *vcpu) uint64_t reg_id = raz_invariant_reg_ids[i]; uint64_t val; - vcpu_get_reg(vcpu, reg_id, &val); + val = vcpu_get_reg(vcpu, reg_id); TEST_ASSERT_EQ(val, 0); r = __vcpu_set_reg(vcpu, reg_id, BAD_ID_REG_VAL); TEST_ASSERT(r < 0 && errno == EINVAL, "unexpected KVM_SET_ONE_REG error: r=%d, errno=%d", r, errno); - vcpu_get_reg(vcpu, reg_id, &val); + val = vcpu_get_reg(vcpu, reg_id); TEST_ASSERT_EQ(val, 0); } } @@ -144,7 +144,7 @@ static bool vcpu_aarch64_only(struct kvm_vcpu *vcpu) { uint64_t val, el0; - vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_ID_AA64PFR0_EL1), &val); + val = vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_ID_AA64PFR0_EL1)); el0 = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64PFR0_EL1_EL0), val); return el0 == ID_AA64PFR0_EL1_ELx_64BIT_ONLY; diff --git a/tools/testing/selftests/kvm/aarch64/debug-exceptions.c b/tools/testing/selftests/kvm/aarch64/debug-exceptions.c index 2582c49e525a..b3f3025d2f02 100644 --- a/tools/testing/selftests/kvm/aarch64/debug-exceptions.c +++ b/tools/testing/selftests/kvm/aarch64/debug-exceptions.c @@ -501,7 +501,7 @@ void test_single_step_from_userspace(int test_cnt) TEST_ASSERT(ss_enable, "Unexpected KVM_EXIT_DEBUG"); /* Check if the current pc is expected. */ - vcpu_get_reg(vcpu, ARM64_CORE_REG(regs.pc), &pc); + pc = vcpu_get_reg(vcpu, ARM64_CORE_REG(regs.pc)); TEST_ASSERT(!test_pc || pc == test_pc, "Unexpected pc 0x%lx (expected 0x%lx)", pc, test_pc); @@ -583,7 +583,7 @@ int main(int argc, char *argv[]) uint64_t aa64dfr0; vm = vm_create_with_one_vcpu(&vcpu, guest_code); - vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_ID_AA64DFR0_EL1), &aa64dfr0); + aa64dfr0 = vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_ID_AA64DFR0_EL1)); __TEST_REQUIRE(debug_version(aa64dfr0) >= 6, "Armv8 debug architecture not supported."); kvm_vm_free(vm); diff --git a/tools/testing/selftests/kvm/aarch64/hypercalls.c b/tools/testing/selftests/kvm/aarch64/hypercalls.c index 9d192ce0078d..ec54ec7726e9 100644 --- a/tools/testing/selftests/kvm/aarch64/hypercalls.c +++ b/tools/testing/selftests/kvm/aarch64/hypercalls.c @@ -173,7 +173,7 @@ static void test_fw_regs_before_vm_start(struct kvm_vcpu *vcpu) const struct kvm_fw_reg_info *reg_info = &fw_reg_info[i]; /* First 'read' should be an upper limit of the features supported */ - vcpu_get_reg(vcpu, reg_info->reg, &val); + val = vcpu_get_reg(vcpu, reg_info->reg); TEST_ASSERT(val == FW_REG_ULIMIT_VAL(reg_info->max_feat_bit), "Expected all the features to be set for reg: 0x%lx; expected: 0x%lx; read: 0x%lx", reg_info->reg, FW_REG_ULIMIT_VAL(reg_info->max_feat_bit), val); @@ -184,7 +184,7 @@ static void test_fw_regs_before_vm_start(struct kvm_vcpu *vcpu) "Failed to clear all the features of reg: 0x%lx; ret: %d", reg_info->reg, errno); - vcpu_get_reg(vcpu, reg_info->reg, &val); + val = vcpu_get_reg(vcpu, reg_info->reg); TEST_ASSERT(val == 0, "Expected all the features to be cleared for reg: 0x%lx", reg_info->reg); @@ -214,7 +214,7 @@ static void test_fw_regs_after_vm_start(struct kvm_vcpu *vcpu) * Before starting the VM, the test clears all the bits. * Check if that's still the case. */ - vcpu_get_reg(vcpu, reg_info->reg, &val); + val = vcpu_get_reg(vcpu, reg_info->reg); TEST_ASSERT(val == 0, "Expected all the features to be cleared for reg: 0x%lx", reg_info->reg); diff --git a/tools/testing/selftests/kvm/aarch64/no-vgic-v3.c b/tools/testing/selftests/kvm/aarch64/no-vgic-v3.c index 943d65fc6b0b..f80a519f73bb 100644 --- a/tools/testing/selftests/kvm/aarch64/no-vgic-v3.c +++ b/tools/testing/selftests/kvm/aarch64/no-vgic-v3.c @@ -164,7 +164,7 @@ int main(int argc, char *argv[]) uint64_t pfr0; vm = vm_create_with_one_vcpu(&vcpu, NULL); - vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_ID_AA64PFR0_EL1), &pfr0); + pfr0 = vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_ID_AA64PFR0_EL1)); __TEST_REQUIRE(FIELD_GET(ARM64_FEATURE_MASK(ID_AA64PFR0_EL1_GIC), pfr0), "GICv3 not supported."); kvm_vm_free(vm); diff --git a/tools/testing/selftests/kvm/aarch64/psci_test.c b/tools/testing/selftests/kvm/aarch64/psci_test.c index 61731a950def..544ebd2b121b 100644 --- a/tools/testing/selftests/kvm/aarch64/psci_test.c +++ b/tools/testing/selftests/kvm/aarch64/psci_test.c @@ -102,8 +102,8 @@ static void assert_vcpu_reset(struct kvm_vcpu *vcpu) { uint64_t obs_pc, obs_x0; - vcpu_get_reg(vcpu, ARM64_CORE_REG(regs.pc), &obs_pc); - vcpu_get_reg(vcpu, ARM64_CORE_REG(regs.regs[0]), &obs_x0); + obs_pc = vcpu_get_reg(vcpu, ARM64_CORE_REG(regs.pc)); + obs_x0 = vcpu_get_reg(vcpu, ARM64_CORE_REG(regs.regs[0])); TEST_ASSERT(obs_pc == CPU_ON_ENTRY_ADDR, "unexpected target cpu pc: %lx (expected: %lx)", @@ -143,7 +143,7 @@ static void host_test_cpu_on(void) */ vcpu_power_off(target); - vcpu_get_reg(target, KVM_ARM64_SYS_REG(SYS_MPIDR_EL1), &target_mpidr); + target_mpidr = vcpu_get_reg(target, KVM_ARM64_SYS_REG(SYS_MPIDR_EL1)); vcpu_args_set(source, 1, target_mpidr & MPIDR_HWID_BITMASK); enter_guest(source); diff --git a/tools/testing/selftests/kvm/aarch64/set_id_regs.c b/tools/testing/selftests/kvm/aarch64/set_id_regs.c index 2a3fe7914b72..8a1d92048aef 100644 --- a/tools/testing/selftests/kvm/aarch64/set_id_regs.c +++ b/tools/testing/selftests/kvm/aarch64/set_id_regs.c @@ -336,7 +336,7 @@ static uint64_t test_reg_set_success(struct kvm_vcpu *vcpu, uint64_t reg, uint64_t mask = ftr_bits->mask; uint64_t val, new_val, ftr; - vcpu_get_reg(vcpu, reg, &val); + val = vcpu_get_reg(vcpu, reg); ftr = (val & mask) >> shift; ftr = get_safe_value(ftr_bits, ftr); @@ -346,7 +346,7 @@ static uint64_t test_reg_set_success(struct kvm_vcpu *vcpu, uint64_t reg, val |= ftr; vcpu_set_reg(vcpu, reg, val); - vcpu_get_reg(vcpu, reg, &new_val); + new_val = vcpu_get_reg(vcpu, reg); TEST_ASSERT_EQ(new_val, val); return new_val; @@ -360,7 +360,7 @@ static void test_reg_set_fail(struct kvm_vcpu *vcpu, uint64_t reg, uint64_t val, old_val, ftr; int r; - vcpu_get_reg(vcpu, reg, &val); + val = vcpu_get_reg(vcpu, reg); ftr = (val & mask) >> shift; ftr = get_invalid_value(ftr_bits, ftr); @@ -374,7 +374,7 @@ static void test_reg_set_fail(struct kvm_vcpu *vcpu, uint64_t reg, TEST_ASSERT(r < 0 && errno == EINVAL, "Unexpected KVM_SET_ONE_REG error: r=%d, errno=%d", r, errno); - vcpu_get_reg(vcpu, reg, &val); + val = vcpu_get_reg(vcpu, reg); TEST_ASSERT_EQ(val, old_val); } @@ -471,7 +471,7 @@ static void test_clidr(struct kvm_vcpu *vcpu) uint64_t clidr; int level; - vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_CLIDR_EL1), &clidr); + clidr = vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_CLIDR_EL1)); /* find the first empty level in the cache hierarchy */ for (level = 1; level < 7; level++) { @@ -496,7 +496,7 @@ static void test_ctr(struct kvm_vcpu *vcpu) { u64 ctr; - vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_CTR_EL0), &ctr); + ctr = vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_CTR_EL0)); ctr &= ~CTR_EL0_DIC_MASK; if (ctr & CTR_EL0_IminLine_MASK) ctr--; @@ -512,7 +512,7 @@ static void test_vcpu_ftr_id_regs(struct kvm_vcpu *vcpu) test_clidr(vcpu); test_ctr(vcpu); - vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_MPIDR_EL1), &val); + val = vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_MPIDR_EL1)); val++; vcpu_set_reg(vcpu, KVM_ARM64_SYS_REG(SYS_MPIDR_EL1), val); @@ -525,7 +525,7 @@ static void test_assert_id_reg_unchanged(struct kvm_vcpu *vcpu, uint32_t encodin size_t idx = encoding_to_range_idx(encoding); uint64_t observed; - vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(encoding), &observed); + observed = vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(encoding)); TEST_ASSERT_EQ(test_reg_vals[idx], observed); } @@ -560,7 +560,7 @@ int main(void) vm = vm_create_with_one_vcpu(&vcpu, guest_code); /* Check for AARCH64 only system */ - vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_ID_AA64PFR0_EL1), &val); + val = vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_ID_AA64PFR0_EL1)); el0 = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64PFR0_EL1_EL0), val); aarch64_only = (el0 == ID_AA64PFR0_EL1_ELx_64BIT_ONLY); diff --git a/tools/testing/selftests/kvm/aarch64/vpmu_counter_access.c b/tools/testing/selftests/kvm/aarch64/vpmu_counter_access.c index d31b9f64ba14..30d9c9e7ae35 100644 --- a/tools/testing/selftests/kvm/aarch64/vpmu_counter_access.c +++ b/tools/testing/selftests/kvm/aarch64/vpmu_counter_access.c @@ -440,8 +440,7 @@ static void create_vpmu_vm(void *guest_code) "Failed to create vgic-v3, skipping"); /* Make sure that PMUv3 support is indicated in the ID register */ - vcpu_get_reg(vpmu_vm.vcpu, - KVM_ARM64_SYS_REG(SYS_ID_AA64DFR0_EL1), &dfr0); + dfr0 = vcpu_get_reg(vpmu_vm.vcpu, KVM_ARM64_SYS_REG(SYS_ID_AA64DFR0_EL1)); pmuver = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64DFR0_EL1_PMUVer), dfr0); TEST_ASSERT(pmuver != ID_AA64DFR0_EL1_PMUVer_IMP_DEF && pmuver >= ID_AA64DFR0_EL1_PMUVer_IMP, @@ -484,7 +483,7 @@ static void test_create_vpmu_vm_with_pmcr_n(uint64_t pmcr_n, bool expect_fail) create_vpmu_vm(guest_code); vcpu = vpmu_vm.vcpu; - vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_PMCR_EL0), &pmcr_orig); + pmcr_orig = vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_PMCR_EL0)); pmcr = pmcr_orig; /* @@ -493,7 +492,7 @@ static void test_create_vpmu_vm_with_pmcr_n(uint64_t pmcr_n, bool expect_fail) */ set_pmcr_n(&pmcr, pmcr_n); vcpu_set_reg(vcpu, KVM_ARM64_SYS_REG(SYS_PMCR_EL0), pmcr); - vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_PMCR_EL0), &pmcr); + pmcr = vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_PMCR_EL0)); if (expect_fail) TEST_ASSERT(pmcr_orig == pmcr, @@ -521,7 +520,7 @@ static void run_access_test(uint64_t pmcr_n) vcpu = vpmu_vm.vcpu; /* Save the initial sp to restore them later to run the guest again */ - vcpu_get_reg(vcpu, ARM64_CORE_REG(sp_el1), &sp); + sp = vcpu_get_reg(vcpu, ARM64_CORE_REG(sp_el1)); run_vcpu(vcpu, pmcr_n); @@ -572,12 +571,12 @@ static void run_pmregs_validity_test(uint64_t pmcr_n) * Test if the 'set' and 'clr' variants of the registers * are initialized based on the number of valid counters. */ - vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(set_reg_id), ®_val); + reg_val = vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(set_reg_id)); TEST_ASSERT((reg_val & (~valid_counters_mask)) == 0, "Initial read of set_reg: 0x%llx has unimplemented counters enabled: 0x%lx", KVM_ARM64_SYS_REG(set_reg_id), reg_val); - vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(clr_reg_id), ®_val); + reg_val = vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(clr_reg_id)); TEST_ASSERT((reg_val & (~valid_counters_mask)) == 0, "Initial read of clr_reg: 0x%llx has unimplemented counters enabled: 0x%lx", KVM_ARM64_SYS_REG(clr_reg_id), reg_val); @@ -589,12 +588,12 @@ static void run_pmregs_validity_test(uint64_t pmcr_n) */ vcpu_set_reg(vcpu, KVM_ARM64_SYS_REG(set_reg_id), max_counters_mask); - vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(set_reg_id), ®_val); + reg_val = vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(set_reg_id)); TEST_ASSERT((reg_val & (~valid_counters_mask)) == 0, "Read of set_reg: 0x%llx has unimplemented counters enabled: 0x%lx", KVM_ARM64_SYS_REG(set_reg_id), reg_val); - vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(clr_reg_id), ®_val); + reg_val = vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(clr_reg_id)); TEST_ASSERT((reg_val & (~valid_counters_mask)) == 0, "Read of clr_reg: 0x%llx has unimplemented counters enabled: 0x%lx", KVM_ARM64_SYS_REG(clr_reg_id), reg_val); @@ -625,7 +624,7 @@ static uint64_t get_pmcr_n_limit(void) uint64_t pmcr; create_vpmu_vm(guest_code); - vcpu_get_reg(vpmu_vm.vcpu, KVM_ARM64_SYS_REG(SYS_PMCR_EL0), &pmcr); + pmcr = vcpu_get_reg(vpmu_vm.vcpu, KVM_ARM64_SYS_REG(SYS_PMCR_EL0)); destroy_vpmu_vm(); return get_pmcr_n(pmcr); } diff --git a/tools/testing/selftests/kvm/include/kvm_util.h b/tools/testing/selftests/kvm/include/kvm_util.h index bc7c242480d6..287a3ec06df4 100644 --- a/tools/testing/selftests/kvm/include/kvm_util.h +++ b/tools/testing/selftests/kvm/include/kvm_util.h @@ -702,11 +702,13 @@ static inline int __vcpu_set_reg(struct kvm_vcpu *vcpu, uint64_t id, uint64_t va return __vcpu_ioctl(vcpu, KVM_SET_ONE_REG, ®); } -static inline void vcpu_get_reg(struct kvm_vcpu *vcpu, uint64_t id, void *addr) +static inline uint64_t vcpu_get_reg(struct kvm_vcpu *vcpu, uint64_t id) { - struct kvm_one_reg reg = { .id = id, .addr = (uint64_t)addr }; + uint64_t val; + struct kvm_one_reg reg = { .id = id, .addr = (uint64_t)&val }; vcpu_ioctl(vcpu, KVM_GET_ONE_REG, ®); + return val; } static inline void vcpu_set_reg(struct kvm_vcpu *vcpu, uint64_t id, uint64_t val) { diff --git a/tools/testing/selftests/kvm/lib/aarch64/processor.c b/tools/testing/selftests/kvm/lib/aarch64/processor.c index fe4dc3693112..4af94272a758 100644 --- a/tools/testing/selftests/kvm/lib/aarch64/processor.c +++ b/tools/testing/selftests/kvm/lib/aarch64/processor.c @@ -281,8 +281,8 @@ void aarch64_vcpu_setup(struct kvm_vcpu *vcpu, struct kvm_vcpu_init *init) */ vcpu_set_reg(vcpu, KVM_ARM64_SYS_REG(SYS_CPACR_EL1), 3 << 20); - vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_SCTLR_EL1), &sctlr_el1); - vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_TCR_EL1), &tcr_el1); + sctlr_el1 = vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_SCTLR_EL1)); + tcr_el1 = vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_TCR_EL1)); /* Configure base granule size */ switch (vm->mode) { @@ -360,8 +360,8 @@ void vcpu_arch_dump(FILE *stream, struct kvm_vcpu *vcpu, uint8_t indent) { uint64_t pstate, pc; - vcpu_get_reg(vcpu, ARM64_CORE_REG(regs.pstate), &pstate); - vcpu_get_reg(vcpu, ARM64_CORE_REG(regs.pc), &pc); + pstate = vcpu_get_reg(vcpu, ARM64_CORE_REG(regs.pstate)); + pc = vcpu_get_reg(vcpu, ARM64_CORE_REG(regs.pc)); fprintf(stream, "%*spstate: 0x%.16lx pc: 0x%.16lx\n", indent, "", pstate, pc); diff --git a/tools/testing/selftests/kvm/lib/riscv/processor.c b/tools/testing/selftests/kvm/lib/riscv/processor.c index 6ae47b3d6b25..dd663bcf0cc0 100644 --- a/tools/testing/selftests/kvm/lib/riscv/processor.c +++ b/tools/testing/selftests/kvm/lib/riscv/processor.c @@ -221,39 +221,39 @@ void vcpu_arch_dump(FILE *stream, struct kvm_vcpu *vcpu, uint8_t indent) { struct kvm_riscv_core core; - vcpu_get_reg(vcpu, RISCV_CORE_REG(mode), &core.mode); - vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.pc), &core.regs.pc); - vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.ra), &core.regs.ra); - vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.sp), &core.regs.sp); - vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.gp), &core.regs.gp); - vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.tp), &core.regs.tp); - vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.t0), &core.regs.t0); - vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.t1), &core.regs.t1); - vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.t2), &core.regs.t2); - vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.s0), &core.regs.s0); - vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.s1), &core.regs.s1); - vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.a0), &core.regs.a0); - vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.a1), &core.regs.a1); - vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.a2), &core.regs.a2); - vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.a3), &core.regs.a3); - vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.a4), &core.regs.a4); - vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.a5), &core.regs.a5); - vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.a6), &core.regs.a6); - vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.a7), &core.regs.a7); - vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.s2), &core.regs.s2); - vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.s3), &core.regs.s3); - vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.s4), &core.regs.s4); - vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.s5), &core.regs.s5); - vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.s6), &core.regs.s6); - vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.s7), &core.regs.s7); - vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.s8), &core.regs.s8); - vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.s9), &core.regs.s9); - vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.s10), &core.regs.s10); - vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.s11), &core.regs.s11); - vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.t3), &core.regs.t3); - vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.t4), &core.regs.t4); - vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.t5), &core.regs.t5); - vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.t6), &core.regs.t6); + core.mode = vcpu_get_reg(vcpu, RISCV_CORE_REG(mode)); + core.regs.pc = vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.pc)); + core.regs.ra = vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.ra)); + core.regs.sp = vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.sp)); + core.regs.gp = vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.gp)); + core.regs.tp = vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.tp)); + core.regs.t0 = vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.t0)); + core.regs.t1 = vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.t1)); + core.regs.t2 = vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.t2)); + core.regs.s0 = vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.s0)); + core.regs.s1 = vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.s1)); + core.regs.a0 = vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.a0)); + core.regs.a1 = vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.a1)); + core.regs.a2 = vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.a2)); + core.regs.a3 = vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.a3)); + core.regs.a4 = vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.a4)); + core.regs.a5 = vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.a5)); + core.regs.a6 = vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.a6)); + core.regs.a7 = vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.a7)); + core.regs.s2 = vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.s2)); + core.regs.s3 = vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.s3)); + core.regs.s4 = vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.s4)); + core.regs.s5 = vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.s5)); + core.regs.s6 = vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.s6)); + core.regs.s7 = vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.s7)); + core.regs.s8 = vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.s8)); + core.regs.s9 = vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.s9)); + core.regs.s10 = vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.s10)); + core.regs.s11 = vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.s11)); + core.regs.t3 = vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.t3)); + core.regs.t4 = vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.t4)); + core.regs.t5 = vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.t5)); + core.regs.t6 = vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.t6)); fprintf(stream, " MODE: 0x%lx\n", core.mode); diff --git a/tools/testing/selftests/kvm/riscv/arch_timer.c b/tools/testing/selftests/kvm/riscv/arch_timer.c index 2c792228ac0b..9e370800a6a2 100644 --- a/tools/testing/selftests/kvm/riscv/arch_timer.c +++ b/tools/testing/selftests/kvm/riscv/arch_timer.c @@ -93,7 +93,7 @@ struct kvm_vm *test_vm_create(void) vcpu_init_vector_tables(vcpus[i]); /* Initialize guest timer frequency. */ - vcpu_get_reg(vcpus[0], RISCV_TIMER_REG(frequency), &timer_freq); + timer_freq = vcpu_get_reg(vcpus[0], RISCV_TIMER_REG(frequency)); sync_global_to_guest(vm, timer_freq); pr_debug("timer_freq: %lu\n", timer_freq); diff --git a/tools/testing/selftests/kvm/riscv/ebreak_test.c b/tools/testing/selftests/kvm/riscv/ebreak_test.c index 0e0712854953..cfed6c727bfc 100644 --- a/tools/testing/selftests/kvm/riscv/ebreak_test.c +++ b/tools/testing/selftests/kvm/riscv/ebreak_test.c @@ -60,7 +60,7 @@ int main(void) TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_DEBUG); - vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.pc), &pc); + pc = vcpu_get_reg(vcpu, RISCV_CORE_REG(regs.pc)); TEST_ASSERT_EQ(pc, LABEL_ADDRESS(sw_bp_1)); /* skip sw_bp_1 */ diff --git a/tools/testing/selftests/kvm/riscv/sbi_pmu_test.c b/tools/testing/selftests/kvm/riscv/sbi_pmu_test.c index f299cbfd23ca..f45c0ecc902d 100644 --- a/tools/testing/selftests/kvm/riscv/sbi_pmu_test.c +++ b/tools/testing/selftests/kvm/riscv/sbi_pmu_test.c @@ -608,7 +608,7 @@ static void test_vm_events_overflow(void *guest_code) vcpu_init_vector_tables(vcpu); /* Initialize guest timer frequency. */ - vcpu_get_reg(vcpu, RISCV_TIMER_REG(frequency), &timer_freq); + timer_freq = vcpu_get_reg(vcpu, RISCV_TIMER_REG(frequency)); sync_global_to_guest(vm, timer_freq); run_vcpu(vcpu); diff --git a/tools/testing/selftests/kvm/s390x/resets.c b/tools/testing/selftests/kvm/s390x/resets.c index 357943f2bea8..b58f75b381e5 100644 --- a/tools/testing/selftests/kvm/s390x/resets.c +++ b/tools/testing/selftests/kvm/s390x/resets.c @@ -61,7 +61,7 @@ static void test_one_reg(struct kvm_vcpu *vcpu, uint64_t id, uint64_t value) { uint64_t eval_reg; - vcpu_get_reg(vcpu, id, &eval_reg); + eval_reg = vcpu_get_reg(vcpu, id); TEST_ASSERT(eval_reg == value, "value == 0x%lx", value); } diff --git a/tools/testing/selftests/kvm/steal_time.c b/tools/testing/selftests/kvm/steal_time.c index a8d3afa0b86b..cce2520af720 100644 --- a/tools/testing/selftests/kvm/steal_time.c +++ b/tools/testing/selftests/kvm/steal_time.c @@ -269,9 +269,8 @@ static void guest_code(int cpu) static bool is_steal_time_supported(struct kvm_vcpu *vcpu) { uint64_t id = RISCV_SBI_EXT_REG(KVM_RISCV_SBI_EXT_STA); - unsigned long enabled; + unsigned long enabled = vcpu_get_reg(vcpu, id); - vcpu_get_reg(vcpu, id, &enabled); TEST_ASSERT(enabled == 0 || enabled == 1, "Expected boolean result"); return enabled; From patchwork Wed Oct 9 15:49:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13828691 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.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 B4535201109 for ; Wed, 9 Oct 2024 15:50:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728489006; cv=none; b=t3PVyZiJfsjyS2YEMf8MLbUnaCyqOR5mh0C1wav2M/87qzkrGHilrdRMoCBtkw5M38kq1s0ISa5eIJ0qtZoI/LQICnotQTRopsDt7NZQwy5OpnjyGnJw5SGi11XmOxS1WqwqmpO4eQR9rggCzD7L8pqfUlZi1k3KDb4rvnsr07g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728489006; c=relaxed/simple; bh=yMjqrBBrs5fD7ztP9Hd+ZjDB2ceAdIl8KOqv0sYfMVY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=PxTz26s2GjTTDnsguPZKF7ySGAbqAxE42Q0Y8O/DNsSK2uTfEXYPO2qUXDebtlI0ZtYG3fY2Eogx4oNobc/q59P+bzTfJs4rYK76uJknw4+PnZJFtd/Omi54ZrFiJT8H4XCJ3Yl0qQmtQ64PVEzKXn18GMy3DL0CaaaZULmnr9g= 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=KdUXTV9p; arc=none smtp.client-ip=209.85.210.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="KdUXTV9p" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-71e1e989aa2so1030441b3a.3 for ; Wed, 09 Oct 2024 08:50:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728489004; x=1729093804; 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=x0cgmo92qPc8MR1y7gAJGg1sCyN/CNSLMfDMg1eW/5U=; b=KdUXTV9p3IjcpOSmHzQFFPIOx+QacZMhGzbwcxZB1x7gfMmdjM0rel2+OfkCYqAjb0 Q1jjQpw7rA/mxrn6z+c6xk8rgoDJsOvqdj0pDu+Ei1h05+0mZo4SPji+CbqbqqVgqgQz 1OtH3aCz+ICOzTChlVDlBSFhxPNz5vbMVDEQnUD9MnTfoUOTbXF7phJHcOSiCq6rjWFD cBRpG3p0aTW1D0EC2/zxOjJTGL0JTkykRX0yC3DU1TMx2w6hU5FYq43wp0+YzTae9Ms0 FHBURjiQ3gVtdEBUwk5gIiqucB5amQeNy1B2nSr92ghdV4lz3z4LiHkLfhDGHWXhsQPX EPXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728489004; x=1729093804; 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=x0cgmo92qPc8MR1y7gAJGg1sCyN/CNSLMfDMg1eW/5U=; b=I8SVP0XHKNDpBN/Cl3DUxoSQ4YMu8AimZu3rJatGfXOdWuvm4gw0BEudBWcK4C2PvV Vf4fUSqJDrjyjEAsCA/DNLuBi5NGUazzJqDJ2JtvNyZfpUP/Rnf0EFSvH0pVWZr6cpbh yHmeVoNRekiTqNpksbPdcNrJ2g5nEf+w88p8yxJL++nWLQjkMWDm6qJ4N7DyaQtwkKXF /6ocmQq0vgh4u4wb/GkX/NnAst714mPpy80Ua9XfpmbpdeqzsrKdZWG424Fn6plApwLH bx1sgeIAEVLGZ0T4idEmihysqMGo4ZF+9QkXLJgcJFIEBmnGZBEFCYBKWNcTqwAB2NQ6 V3ZA== X-Forwarded-Encrypted: i=1; AJvYcCVUrOz+CYmfM0BsZBG6GOx+BbpNcy16PfmQWifXCqoNMFexfnHWnegiUPPRljWe3mG6zV4=@vger.kernel.org X-Gm-Message-State: AOJu0YyXVppbdGvakUbjqF25xPEbtGhqNusf3KhXJY/YmbsGmg3hG83L TW2clGCzY4Jtizgvmw/FxkcwIfD1r8+Bw3FkWh/dIx1FEvNPcojEvAcHBtljQRNTEtNOsHyTHgH 8YQ== X-Google-Smtp-Source: AGHT+IERUBPfneULnJ59z0o0A04D0VCwsGKXUdX4SfWVGxtKdYKWNTs8AEtFgRMkbcfSQG42khoM/WAQWlQ= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:9d:3983:ac13:c240]) (user=seanjc job=sendgmr) by 2002:a05:6a00:4fcf:b0:71d:fb06:e79b with SMTP id d2e1a72fcca58-71e1daa9410mr6141b3a.0.1728489003716; Wed, 09 Oct 2024 08:50:03 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 9 Oct 2024 08:49:43 -0700 In-Reply-To: <20241009154953.1073471-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@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-5-seanjc@google.com> Subject: [PATCH v3 04/14] KVM: selftests: Assert that vcpu_{g,s}et_reg() won't truncate 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 Assert that the register being read/written by vcpu_{g,s}et_reg() is no larger than a uint64_t, i.e. that a selftest isn't unintentionally truncating the value being read/written. Ideally, the assert would be done at compile-time, but that would limit the checks to hardcoded accesses and/or require fancier compile-time assertion infrastructure to filter out dynamic usage. Reviewed-by: Andrew Jones Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/include/kvm_util.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/testing/selftests/kvm/include/kvm_util.h b/tools/testing/selftests/kvm/include/kvm_util.h index 287a3ec06df4..4c4e5a847f67 100644 --- a/tools/testing/selftests/kvm/include/kvm_util.h +++ b/tools/testing/selftests/kvm/include/kvm_util.h @@ -707,6 +707,8 @@ static inline uint64_t vcpu_get_reg(struct kvm_vcpu *vcpu, uint64_t id) uint64_t val; struct kvm_one_reg reg = { .id = id, .addr = (uint64_t)&val }; + TEST_ASSERT(KVM_REG_SIZE(id) <= sizeof(val), "Reg %lx too big", id); + vcpu_ioctl(vcpu, KVM_GET_ONE_REG, ®); return val; } @@ -714,6 +716,8 @@ static inline void vcpu_set_reg(struct kvm_vcpu *vcpu, uint64_t id, uint64_t val { struct kvm_one_reg reg = { .id = id, .addr = (uint64_t)&val }; + TEST_ASSERT(KVM_REG_SIZE(id) <= sizeof(val), "Reg %lx too big", id); + vcpu_ioctl(vcpu, KVM_SET_ONE_REG, ®); } From patchwork Wed Oct 9 15:49:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13828692 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 88412201253 for ; Wed, 9 Oct 2024 15:50:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728489008; cv=none; b=rbFaKgQYpj7aSdpeLjhc+PYHmJxcAATCWI7wH7tqtuuUp7ZcLN8Mdg09T6X7eFuUeaFEjccLG0IYkmiUw7G0vP3LqQ3n57xfwpwQjaQFC/NI8Qn/D2cHf2tXlfxJG5vOgrrRnz+tVlyO3zfQubk/PiqxiG4PiiiqsqQL39pSc2Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728489008; c=relaxed/simple; bh=wpp1BhgAAr1F0pJrXcm4U6/ifagqLD98EYbry7T//bg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=o1A+CxoZ7SbbPjZtxzvtb591GcwlwYvB3w9kXKtoGSHkXK5/XTiI87v2DkDfMVuwCLmQ6hCbM/G9cUZ3Cn0z5SrfwW36RBazET7vLQT1EQC0UVkZfMTB5MLiUphOstI+E2NbXLfQeAYvDalKiUr7b+qhIosVlJ8dMqVHDHctLIY= 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=1jQMqcI4; arc=none smtp.client-ip=209.85.128.202 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="1jQMqcI4" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e0082c1dd0so146324377b3.3 for ; Wed, 09 Oct 2024 08:50:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728489005; x=1729093805; 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=dEQn+W1SexZcTNgUxAN0PCwUsSeaftCY9kaEGEXOiDc=; b=1jQMqcI4ubJqBBaBjtssAPl+91NX0ubjwFKhAxkC2iYTvoOgNiTTAZ79cE8kWudMDz CLOhv3Lp2kuDlvHCIqyQ66mqCSCCqReDoJm5wGrSaCmhbXoIoTbjiF9yndR7xIKEqd95 SvkfXWvjN0oeh1UbHH1xY0eiXy1v4c7/FFdSZJhHteOsAgFeRyynjgoOL/4HwedvSNkl ebjonR3SgVBCz4CRY6FcuMNo/lwg02P8N1WTXR/cfw+qvkKfw2zU5bF8IoC8WQTv+pUN w3Yb0fsKno2oL/PAo+Zi8nKcWH97sog569/hxnZgp8VNUICJjEhysP6vEMF2aeY1MEpw LLlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728489005; x=1729093805; 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=dEQn+W1SexZcTNgUxAN0PCwUsSeaftCY9kaEGEXOiDc=; b=OYi/MtCDZD4JA+yeR9hgpNUf4Dow4m43bUR9rwMQNpfWjFjgzHfd2DpaVrYZ2AfG/2 9jtQsr8ESq6x5XtukF5Rvml0hgnA21dksLYgFx0Yr6GZRcxVe/MzMyPGFeds1sxU1UV4 Tsn0EJkN9wSqS0H02HMPVFnYxL4PaiyRk4psWFo8QQVQzrziQRjNfUa9OimIySxMNj22 +R+IJ+8vHA1UpEwDBweDcAQ2tyulbIBUOakc0M0xNhup7G2oy9gylwHzHi5eAO2lvrpf b4hrPJBdPcld3zGsDJaJ0M4UtmCWS6ihSz/jyb//LBY+rgT7vVWuxLw9tTGgPV7Hrafp Ckmg== X-Forwarded-Encrypted: i=1; AJvYcCVh18Nxowwab1pZKC9Mi3E09ol+gaylXEb8gqHwYBCPgV6xje/PPnlDutb2RIhuC+IEmjw=@vger.kernel.org X-Gm-Message-State: AOJu0YwCZRQM1/MmmFxe1Q3fe4dXGuILimVYqKozeI8NUEjJ/8s1yH1U f1ETdgTDCLMO4xsn86x7A/1DR3spx77OAzcSoWvREuI99wGMDS9ih0kdRIjtMnl0xp4/slo/iYh R3Q== X-Google-Smtp-Source: AGHT+IFrWalNmEyn72/5CXUVKhi80GHo8XaYDR+iQ/XjxOT9S8VfevqUwXplC0nvvzPPLclQ9b5vmaVf6gI= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:9d:3983:ac13:c240]) (user=seanjc job=sendgmr) by 2002:a0d:cd84:0:b0:6e3:b08:92cb with SMTP id 00721157ae682-6e321d4062cmr303877b3.0.1728489005619; Wed, 09 Oct 2024 08:50:05 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 9 Oct 2024 08:49:44 -0700 In-Reply-To: <20241009154953.1073471-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@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-6-seanjc@google.com> Subject: [PATCH v3 05/14] KVM: selftests: Check for a potential unhandled exception iff KVM_RUN succeeded 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 Don't check for an unhandled exception if KVM_RUN failed, e.g. if it returned errno=EFAULT, as reporting unhandled exceptions is done via a ucall, i.e. requires KVM_RUN to exit cleanly. Theoretically, checking for a ucall on a failed KVM_RUN could get a false positive, e.g. if there were stale data in vcpu->run from a previous exit. Reviewed-by: James Houghton Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/lib/kvm_util.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index a2b7df5f1d39..6b3161a0990f 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -1646,7 +1646,8 @@ int _vcpu_run(struct kvm_vcpu *vcpu) rc = __vcpu_run(vcpu); } while (rc == -1 && errno == EINTR); - assert_on_unhandled_exception(vcpu); + if (!rc) + assert_on_unhandled_exception(vcpu); return rc; } From patchwork Wed Oct 9 15:49:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13828693 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 786B4202F67 for ; Wed, 9 Oct 2024 15:50:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728489009; cv=none; b=EnGstcivQhhzSyxSbkDTr1KBaBCC0QEywFpJ7hcwSDGIiAynwVsAGohCQoTr/wRaF7GEK7QippYXsJwnS127v6oth4HQ4Rmmy2jybXzoYJNX/u3pZq4ICW8CnqtkwaC2wpq7zeZ2MhavQ9Eh0iqNJmdhx4Brpb77QKCGi/HJuK8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728489009; c=relaxed/simple; bh=rzKl++CWaUW8jRUGQiR8avz8+vDBd2uSvVkufkDoQug=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=skufGYgiVXndsIMV3An0rsnN91E5SRrQzYByeeXa7xlph7t3iqab8B80wl9ozhDPFQY7ruc6ZeG7gJWpzlpsisfU/lKSnp0BD3rOvzSFWs5nWsnZjlv/dr/TTxTL99ZSd+doZeIX/IVed6R/ojcDhvVLWBueJxHjqNd6LnlJlCQ= 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=I/AY7GT1; arc=none smtp.client-ip=209.85.128.202 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="I/AY7GT1" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e0082c1dd0so146325547b3.3 for ; Wed, 09 Oct 2024 08:50:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728489007; x=1729093807; 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=9+y7oelTnk6r5KXO5BIzd9TWGjZrwMN3AFTrylQnTmc=; b=I/AY7GT1bgD9i8lobvu05GIV2nOjbI9GCdlGiaHQK3NhazjbvpUDZ31rMp5fFeW4B7 6TtkLxvwLRU5ZSjIiRQ/hidvAY3HMTbKSa5+ITsLd2mcU3rCOjQUg/WkGCCugrR4RGja 1nagJRpsWiJmEACvdZss6FPxtXY/sv6jtOoy1C3HqDAsdxRBmg3WrKEIoRPdjObsdV9K Fil3n56TnJtj+HIZyMsm9j0qbv99StAFFqHDoXhiqwD6JXcUQ79/5bU4O6V60ZG3s3Zs 1GQuCC2iVaLrY/ltHaR5HgtSKRRdYDL4BfZF6Nv2fdhQTR8um+k38A3AdN0NoYli2qM2 QBNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728489007; x=1729093807; 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=9+y7oelTnk6r5KXO5BIzd9TWGjZrwMN3AFTrylQnTmc=; b=ZtCBEiZLSSt+RhyoCB+em2sMXDdCnd0k7GdqnD2JA9m86CfxsbNGTRJJO/e5LoVOyg 47pH8j6s2ScnWL/auxONvaqq/SiiCOLyXnv1Zpuv+PglXeyfO6aOABJ8vGKkuqZn/heo 9st/pEat5wJAZ84E6yTpZZwk1mN6HM1gMEU1l9Yne+51Fpq6SuF9Y7nXPGrFleN874TO ON1lUGq9hPUt3rfI73Unn3CnfmFWLNEPaSaLmZsvkVJxyehMxLd75SY2o6IT10cOccOu FXR5iLVJDQ5iieeishkxXZVPNxlBC3qIQOkS4YTMz1WpWkevfVbd1vUHxfGLkVuDgNyO 5LXA== X-Forwarded-Encrypted: i=1; AJvYcCXbcnLNFbetudgpzCTwCHYtz+oVg2Gl8RTqTjM5ovGRaaRF31ZeL7UXniKC/iAAXakIms0=@vger.kernel.org X-Gm-Message-State: AOJu0YxVbt6w5fN9vQyw3ucklPylLToMdLyviarp5fRLbBXaVLT+n7+R XfvYgpPsitlqjZS8FfhMuihdMEykyKxbOUE3KzWsWLPbin79V2Vrvq+aKXItPIZ6sSxmwzydGMx Ygg== X-Google-Smtp-Source: AGHT+IEnOiEr/7ufmCoIIHo0RYjnE1E6sJgU5IKNyLPqmQLuHnTee5V8zvUGQ36LhzFM/1nmzHnRUzKqVBw= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:9d:3983:ac13:c240]) (user=seanjc job=sendgmr) by 2002:a05:690c:4b08:b0:6e3:b93:3ae2 with SMTP id 00721157ae682-6e3220deef6mr671277b3.1.1728489007658; Wed, 09 Oct 2024 08:50:07 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 9 Oct 2024 08:49:45 -0700 In-Reply-To: <20241009154953.1073471-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@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-7-seanjc@google.com> Subject: [PATCH v3 06/14] KVM: selftests: Rename max_guest_memory_test 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 Rename max_guest_memory_test to mmu_stress_test so that the name isn't horribly misleading when future changes extend the test to verify things like mprotect() interactions, and because the test is useful even when its configured to populate far less than the maximum amount of guest memory. Reviewed-by: James Houghton Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/Makefile | 2 +- .../kvm/{max_guest_memory_test.c => mmu_stress_test.c} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename tools/testing/selftests/kvm/{max_guest_memory_test.c => mmu_stress_test.c} (100%) diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile index 6246d69d82d7..8c69a14dc93d 100644 --- a/tools/testing/selftests/kvm/Makefile +++ b/tools/testing/selftests/kvm/Makefile @@ -139,7 +139,7 @@ TEST_GEN_PROGS_x86_64 += guest_print_test TEST_GEN_PROGS_x86_64 += hardware_disable_test TEST_GEN_PROGS_x86_64 += kvm_create_max_vcpus TEST_GEN_PROGS_x86_64 += kvm_page_table_test -TEST_GEN_PROGS_x86_64 += max_guest_memory_test +TEST_GEN_PROGS_x86_64 += mmu_stress_test TEST_GEN_PROGS_x86_64 += memslot_modification_stress_test TEST_GEN_PROGS_x86_64 += memslot_perf_test TEST_GEN_PROGS_x86_64 += rseq_test diff --git a/tools/testing/selftests/kvm/max_guest_memory_test.c b/tools/testing/selftests/kvm/mmu_stress_test.c similarity index 100% rename from tools/testing/selftests/kvm/max_guest_memory_test.c rename to tools/testing/selftests/kvm/mmu_stress_test.c From patchwork Wed Oct 9 15:49:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13828694 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.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 7C39B202F8D for ; Wed, 9 Oct 2024 15:50:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728489013; cv=none; b=rOvQSDnwTD3UflwDXQ60vmein7UrZC3x2vEBVZql1SebdXXRvNJot36jsikVXIvHC07mk1qMwedzqV3yBMd1WQrBT8JiHsBjfansZoV2Qhxal0eRb4t2xJB7kfOndsCh8UiMsifmbIudQPbrFtRp1O1FNJGKkT7ssTdJdNDQ8+U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728489013; c=relaxed/simple; bh=iJgiAVVkswthc5+5Sg734uhrpe9cCqrlEjv/8yEej0c=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=sFGpg5PLETlKn0coADy8mg+5Gq0v7sViu2XDO8qHpgwhZjXMj/+DRMP/qmkB6J0CHfwxotaah4yzIXxV5PHIOeNrqBBfdmfBtrIK3fnfF7EEDwucgCSBqxg9enqFN3c4S03hwtxDxnOFAoduQy7bx/X5iYBd/nb85Y+8FuZO930= 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=fnSDfYS5; arc=none smtp.client-ip=209.85.128.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="fnSDfYS5" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6e000d68bb1so13383397b3.1 for ; Wed, 09 Oct 2024 08:50:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728489009; x=1729093809; 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=mkSNDDdTvmOytZei+cHiV7cpe/wxQK6hsvQ24y9wIjk=; b=fnSDfYS5iKalBfRgLhSpGhQWtvNUH11/UhY8QMNsbYym7XT99Yrnn9mrQX3riHWc/P UI3GJRwt3uEJgL+A3DpzeAKkyPosHfBmmyhE/7fpu0GzgV/oTBwXSFkdgbOOiA3ab+3B uC0+3LGzDIwwU7aWDf0ibuuOXNv++AVSH4EK72+ql0rzDe5D5Tc89nxcJbOExXHLES12 yXrCloidBZprENpMLCEZW6yAL/lWLpL1OFmck//KPytksB0QHzpBFLXBXxeB0EdMntU9 9lTjVam33Az+4d6I6KBEKvZprvVQZeMiA8q4kb5Ze3EWNuk//mF0gzKSMyhUbsmzSXGd kcbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728489009; x=1729093809; 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=mkSNDDdTvmOytZei+cHiV7cpe/wxQK6hsvQ24y9wIjk=; b=Bl8hIJsCgJvhqzvd9S59ReuSbshYmNYzzLlQZKVXdDcZUKvATgQOBWEVZvtDdZD+Qh CMHS409SJ0MfaSkfyzl8M1UcGn+mJWosIB34IRY6g7r81duD7qx1wMXhsyMuOAT5i/RR lUzBDRF6VgLEXqYAck12U+rilhrkEopBc3SANE08XbXfzYWD/OkgUNJqLva/tTozWkCc wQ6kEty+sf+VxM5Jc1CJex/mKTFKNIOUeFryZX79J90Vw0DrgRjFU5PZ55XAyBphXotn 83LKzoH+LMaIvvGvXGmWUt83uiCpeJxzt456BYFa8gcBBT+QU3GuDvt0JA+xFc8kDR/o +PTg== X-Forwarded-Encrypted: i=1; AJvYcCUHbDn8jEC69RjF5/ybTYZHuxPODjC2Sc8euC1ZRs7Msmi1z6vhoTDRE5YE5gZ4jN2s6Ls=@vger.kernel.org X-Gm-Message-State: AOJu0Yy+dPbklLdB9GKb3ebuNUFf2P9Ti3RloABEAB+hdFW6vblE1wuw cd/KmQNo7n/eSV0QlXbVQutDBxn7qniGm7PnRjoc0OSavDAao8wcA2IDjVZ9HXSYCVldypDuWkL kkg== X-Google-Smtp-Source: AGHT+IE+D7P5FL0ahoVlcq9P7kEER6bVqpKARxPS0zk7xyFxuVv8bFBUXfQ/Ook8UnSyIIw/scGTO80UaRk= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:9d:3983:ac13:c240]) (user=seanjc job=sendgmr) by 2002:a05:690c:4706:b0:6e2:a355:7b5c with SMTP id 00721157ae682-6e32f33bf7emr177b3.5.1728489009508; Wed, 09 Oct 2024 08:50:09 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 9 Oct 2024 08:49:46 -0700 In-Reply-To: <20241009154953.1073471-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@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-8-seanjc@google.com> Subject: [PATCH v3 07/14] KVM: selftests: Only muck with SREGS on x86 in 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 Try to get/set SREGS in mmu_stress_test only when running on x86, as the ioctls are supported only by x86 and PPC, and the latter doesn't yet support KVM selftests. Reviewed-by: James Houghton Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/mmu_stress_test.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/kvm/mmu_stress_test.c b/tools/testing/selftests/kvm/mmu_stress_test.c index 0b9678858b6d..847da23ec1b1 100644 --- a/tools/testing/selftests/kvm/mmu_stress_test.c +++ b/tools/testing/selftests/kvm/mmu_stress_test.c @@ -59,10 +59,10 @@ static void run_vcpu(struct kvm_vcpu *vcpu) static void *vcpu_worker(void *data) { + struct kvm_sregs __maybe_unused sregs; struct vcpu_info *info = data; struct kvm_vcpu *vcpu = info->vcpu; struct kvm_vm *vm = vcpu->vm; - struct kvm_sregs sregs; vcpu_args_set(vcpu, 3, info->start_gpa, info->end_gpa, vm->page_size); @@ -70,12 +70,12 @@ static void *vcpu_worker(void *data) run_vcpu(vcpu); rendezvous_with_boss(); +#ifdef __x86_64__ vcpu_sregs_get(vcpu, &sregs); -#ifdef __x86_64__ /* Toggle CR0.WP to trigger a MMU context reset. */ sregs.cr0 ^= X86_CR0_WP; -#endif vcpu_sregs_set(vcpu, &sregs); +#endif rendezvous_with_boss(); run_vcpu(vcpu); From patchwork Wed Oct 9 15:49:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13828695 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (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 EA2C62038CF for ; Wed, 9 Oct 2024 15:50:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728489014; cv=none; b=C77CEymplDrJlkL0WrTPgVfzp3L9ABipthNPUPcppbD5wxc/JtbCM7UkAVDsxU4/BgUjIkOxgr4zz2StH0VdbvkQy3+zh4y3+wlkNhtWZwu14h7ZxNLXnGaAHCXNhGEd0bXb7B0MNR4HI8kDCGosX9y0/4qctkwyegJrrxo4yBc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728489014; c=relaxed/simple; bh=go2nSUoOu7DLGf2G03lp2uqdBfC+a2fqniLkbFG5GlI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=g5NtKlcyFQKmdq5fQGe7/S25tDFQd10SPuBfsEzmWE07Nk5h9bEdGpqDqHbZ5rT7HRUXnap4ch76JRLIgpsg69kdhFwI3DeC3cfO/tT2Fsfben6fcMHEyUIaB4ywmkyNUpjpF8qH9w/sULN7IGGHvUM3lFWzkofsnkQL5XWun3k= 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=yuaRRkWH; arc=none smtp.client-ip=209.85.219.202 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="yuaRRkWH" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e0353b731b8so9598714276.2 for ; Wed, 09 Oct 2024 08:50:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728489012; x=1729093812; 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=BR1gG58gw5F7E+LpSzoPu+wX+wiyja7ptJ1fl5K+zYE=; b=yuaRRkWHUpaQW6R1zC8KmVLk7LZ4KoXDgjH+7DhZZjo84iFhsXvBBB79W7zRaP80Ip NLCqRZtX3ue3+a9NZUgmp3fLL4+W7oEb8I+SI3PCnSj6ROXc5jYiyW0TggvtinpLCROC M2YllRT7zAUFeharTgVDn6boRcIM5SRusunlNhfVmbn0EDgmgU657KATjNKspJYTN171 52wJBxY7gVldYw/EHt8Y/seBGyNRdCjXUxtnCl9pG6Vt1f3jBvCuEnneXNEvghIQHqjZ AiNqZLIFNi7fE0V+JlXdaj8M87POruZqgTn8pfFbRhapZjgg5BCdGNphVITLmNXqQm2H rs/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728489012; x=1729093812; 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=BR1gG58gw5F7E+LpSzoPu+wX+wiyja7ptJ1fl5K+zYE=; b=sRYBg0nTBrBoiCPHJUCf315IrDgXqAvWp4tjgx6A3DV4M+O6ZZIFeQlfpj38L4GLHH kdNXYDU0ZN+ZdVnoDREve31br5EjfdvWhDWbsE452Xhj9QEVxgd4W37R1H+Mwajn4oC9 tlTNOCrqssPQE2gMXOv+IFDnwRlisAz7jFgDrXW2cZeTWOFttEvzcM5qdkG//0mjYZY4 yGs7JkUNDlSBT29DMRpWDcFgT3sUDw3/jaEsl7B8FarKd7RHS3dRcryxYk9BNw8vINYO Pl0XCcmrG6cA47iAallIy1hGSpWFqRr5zO1BEPSQrXXKYqeBo4sdTs7JOAFxOPQ+CMzZ ZCAw== X-Forwarded-Encrypted: i=1; AJvYcCW4RJlPFaucVaTrpkIrisWAqKPJj2f50iip4Qkt3cjFfoQO6KUGAIbCtl6ibVaK8qqrKlg=@vger.kernel.org X-Gm-Message-State: AOJu0YzjRSHs1WgAObeOz33CtwtoSMT+xbSsqGgWdpj+t77Q7AjbMQrj ppF8Ir5Fihq1W0+za8G34vcAlZxOEG5sSx2WpFcT8iGhYor7fzd7PR1mrXeggiW1+HTG+Cw7qTy ZvQ== X-Google-Smtp-Source: AGHT+IHLwQuTuSKn2K83jzMORxhmnJG2QJIDSetKispH+vrqgQjqJfiOQ3+gOO6ZQgZWYqSyd9aEi5B6J6c= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:9d:3983:ac13:c240]) (user=seanjc job=sendgmr) by 2002:a25:6948:0:b0:e29:6a6:ed83 with SMTP id 3f1490d57ef6-e2906a6f043mr903276.11.1728489011277; Wed, 09 Oct 2024 08:50:11 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 9 Oct 2024 08:49:47 -0700 In-Reply-To: <20241009154953.1073471-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@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-9-seanjc@google.com> Subject: [PATCH v3 08/14] KVM: selftests: Compute number of extra pages needed in 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 Create mmu_stress_tests's VM with the correct number of extra pages needed to map all of memory in the guest. The bug hasn't been noticed before as the test currently runs only on x86, which maps guest memory with 1GiB pages, i.e. doesn't need much memory in the guest for page tables. Reviewed-by: James Houghton Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/mmu_stress_test.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/kvm/mmu_stress_test.c b/tools/testing/selftests/kvm/mmu_stress_test.c index 847da23ec1b1..5467b12f5903 100644 --- a/tools/testing/selftests/kvm/mmu_stress_test.c +++ b/tools/testing/selftests/kvm/mmu_stress_test.c @@ -209,7 +209,13 @@ int main(int argc, char *argv[]) vcpus = malloc(nr_vcpus * sizeof(*vcpus)); TEST_ASSERT(vcpus, "Failed to allocate vCPU array"); - vm = vm_create_with_vcpus(nr_vcpus, guest_code, vcpus); + vm = __vm_create_with_vcpus(VM_SHAPE_DEFAULT, nr_vcpus, +#ifdef __x86_64__ + max_mem / SZ_1G, +#else + max_mem / vm_guest_mode_params[VM_MODE_DEFAULT].page_size, +#endif + guest_code, vcpus); max_gpa = vm->max_gfn << vm->page_shift; TEST_ASSERT(max_gpa > (4 * slot_size), "MAXPHYADDR <4gb "); From patchwork Wed Oct 9 15:49:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13828696 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.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 8ECA220408F for ; Wed, 9 Oct 2024 15:50:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728489016; cv=none; b=S/CAYDOiT3yM2ncF0zolkYop1OrWNC48ykPJ0Xs3gJIgT2m4hbxcrFtOJ8GrM84GbSMNBJADpHqpEJFYPTPdHczFybSoDLbM6AB8xFbHpMjdsmIqXpUhUhHGtq12POaMrl1JT3gRZ9w+AjMVj55Tk2ukO8TThD5R05uBQVZZSqA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728489016; c=relaxed/simple; bh=n7uJjw0M+CvpEDCyIwANzPoenH4vXh1rKtEVamrxwhI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=E5qF+Js0M5kju2talYoEqFGC0fhU4gzhVKpbjIALGV1a1YfBLdWSr5nM4dQikH3cTL4WwcronNzEZDpBw4115nnQBfHubCI8RWbpTd7L0kMQ60xOfXAo1eJXSzW0bd+wx5VNxU4FLHetqIelTsfn+Oiqq87jtP5+i/1wm4eJRqY= 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=XuXSEu6i; arc=none smtp.client-ip=209.85.128.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="XuXSEu6i" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6dbbeee08f0so16867207b3.0 for ; Wed, 09 Oct 2024 08:50:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728489014; x=1729093814; 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=pKnU0Kp/o5z6vCl+SnuNv4XsTANtPNd0KXgSeGLrrD0=; b=XuXSEu6ilNt3ZE0hwR4wttyKQThAE6OvDhRnZ7B14HahxekMpOIqkR4BwQ9I81YF79 HRWtmVnbrr5XxsDzpB/hSnGb8gR5/ZE7y/RDXSJorKrBIdj1zQHNm6P/BMq2b07+w4CG hoCHwgunZIEcSqd1gbsc1sLq4iYNm+jL6kSA8wR8Uk9mxPGUjBrIi/Xx3vo/aQiuStMU IBY+9yMyv8ipXQEJml6EkuBXPomiqqno6d1+EUyWEkHiDh0ShOWH9wDQbQr7DgnBkVjH mPhKfyUzWkirJCzB5R77pen2Ei/vjlb7bLH3vMCGH0FiyTztRgY/xep2pn/CmHqtygD8 xMcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728489014; x=1729093814; 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=pKnU0Kp/o5z6vCl+SnuNv4XsTANtPNd0KXgSeGLrrD0=; b=h3qTzIR0hyFIdkkNrVX6HTf35ObweF91ER1lu4bniVjTADwJiia5e7dmBUCVg4Uj7/ uGf5DS9mMDVbJzVA1GGTqoTvaT/oHOmaGTj2vVSLujWA680mkMaDVu4Xw3joelqP3ic1 5i6cmcbxk/F3p7wdmrr0Jw7aHSjY/eS46kFiaaRpRQk9D9Kbzg7tNKwvk6k7gsMGoiNo oVtNt4TiIhFb85Xv/suffJSHylTvy/reDhi9qjc/MkVxCGQ/xggtkgDoewbb5uNkN747 /HNyBn9hCJqLOy25UNbrw3Y5kMm2vLt/qZH4XBGHmAP4WUyT9qn/m6FmIsUCtm0Gr4ck wPIw== X-Forwarded-Encrypted: i=1; AJvYcCX08Jd7E5GoGSXQr0EQiw9cL7yoObpboStfhrcPr4GFtxWD4R8eqMeOqSP8XhJjMM0IN8s=@vger.kernel.org X-Gm-Message-State: AOJu0YxBzX5ObJlAB963PehXvytvRrtOKJW3s3jIVECxc/Arr4lS2Sxa JA/W9AX9/dyevKZ69ZBvRRVcRUBJoPEqiceTq6hfVhdHXQNftA2gdYi6G4RNzAkcwwKAozvD1jL PPw== X-Google-Smtp-Source: AGHT+IFl4KKTDXOPETiRWWIkjcYQuDw12IfhMjxBQcTnANGnaD3TD9lTchjjvx4T5v8klQyshc757dwsFY8= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:9d:3983:ac13:c240]) (user=seanjc job=sendgmr) by 2002:a05:690c:2b86:b0:68e:8de6:617c with SMTP id 00721157ae682-6e32f279e6fmr2237b3.5.1728489013701; Wed, 09 Oct 2024 08:50:13 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 9 Oct 2024 08:49:48 -0700 In-Reply-To: <20241009154953.1073471-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@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-10-seanjc@google.com> Subject: [PATCH v3 09/14] KVM: sefltests: Explicitly include ucall_common.h in mmu_stress_test.c 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 Explicitly include ucall_common.h in the MMU stress test, as unlike arm64 and x86-64, RISC-V doesn't include ucall_common.h in its processor.h, i.e. this will allow enabling the test on RISC-V. Reported-by: Andrew Jones Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/mmu_stress_test.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/testing/selftests/kvm/mmu_stress_test.c b/tools/testing/selftests/kvm/mmu_stress_test.c index 5467b12f5903..fbb693428a82 100644 --- a/tools/testing/selftests/kvm/mmu_stress_test.c +++ b/tools/testing/selftests/kvm/mmu_stress_test.c @@ -15,6 +15,7 @@ #include "test_util.h" #include "guest_modes.h" #include "processor.h" +#include "ucall_common.h" static void guest_code(uint64_t start_gpa, uint64_t end_gpa, uint64_t stride) { From patchwork Wed Oct 9 15:49:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13828697 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) (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 53367204931 for ; Wed, 9 Oct 2024 15:50:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728489018; cv=none; b=siUIy0RvpRYD4JRpJse7XxnZaaAOmTB2jNWvuv04vraEDrxh3m360EWLbsAmK+48sQfkSMvctcVbqIHo9jSEnmBZTKQzvJ/+4w9p6KfMBdXZLSK1aJ8tcncwFhJWxpSy1kVdTJ6NuNN/IbE4KxYeEXRjrNEm/UYfljw3HhYH10Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728489018; c=relaxed/simple; bh=IEk3C5HK+2fLDSHn3IY0LURHtrY8S+z4Dg7g0+3tBIE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=bqIqAgDBO0hhaQpCOc8+/UNgL0lzaPYMonqjuEBurlH9LcOUNJiP2I+NnWLyEDG/ZsBv/RMTRDoDmsaSEywDpdsl4rFfV3h+ZPpvVrkSpOkdM5lAeY0pL5Tm/XU9XA4VGPlq9wMBOXffM+rIYcJ5IdRldTuEdPdUKbkd3MLXZA8= 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=SC0Xr9KF; arc=none smtp.client-ip=209.85.210.202 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="SC0Xr9KF" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-71dff575924so4722253b3a.1 for ; Wed, 09 Oct 2024 08:50:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728489017; x=1729093817; 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=jc3MwSNX0+J+oR+H6AzLHubLG9mcnf8agevCb1Rjaqg=; b=SC0Xr9KFKVS+OuNrNVXnfhZhUQDs143QXNtk9fObCyxmmza2V56z0t/hM6ig7CWTWR HMDoYKBqXZOHF+OjTm5QK2Z8n0qVVKZgcnRM11BGSez+VI8/wDxNeP8pBakF5t38BJMF BDwjjtEJ3jEHSvzDydtJAw0pDWHsbbPKUaKbIhRLkj9GScfZr7io170xOsV1db06kIlJ mhBpNFA+7weoNjrxq4Xuu9wWBzIdiHFiyUOU+DCIW7GAlKksrqiHrGN/6+YJD37rCCoy +rP5x/KYH8vwCX5qu58QUAEO6EGpV0V2XLvI69K14+zxqFfY6t29wG/dBTcERAaK8S5S bKzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728489017; x=1729093817; 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=jc3MwSNX0+J+oR+H6AzLHubLG9mcnf8agevCb1Rjaqg=; b=A9s+ddeS3ENpsOS4X8KfGOi+GdUDHSYjE+U9jqrh5efPJS9d3nlwu0cqCmu3pfshmv lZIOLKh8iTTcWKPwskbHUpNpjgOo9s+Cl98AWylrg6UYW+btG83N4ZTR5YPhgUXaVCEl DKrTjdMycKHHq5jiefEsQxSWwYRVNSjP71VIfrfyAzvU76iiPzwePZkGJYlHbWOoFurT ZfncezXKKM2yKIZTQVmu7+McmC2ALfuaiOJJwaa74BbDBIkb7Xxop6mLYBBmrfGDvlTx FDN/VrDudrnEaefQsLXEjLIrJKcEQi92A8xoaShIrjdL84yEeieOqS8sgemaw88OwVAJ YBgw== X-Forwarded-Encrypted: i=1; AJvYcCUqiTVxJaR6rgW581rcbDu1rCoZiP5ZJQSg2VjlyvMa+22qfgL6XgxVYNlJwWJruw6Ucvs=@vger.kernel.org X-Gm-Message-State: AOJu0Yy09CkW+XEJxtrC1GaEZFGDZH0swXM9bbPOMJA7WOSaRINsmgvC tvKJhGIQn3U6qMsf8BsqoDpb37taDjM8aSsy8XWdZAbBuDJkECPrO0OlUqI3ibf3Stxt2qIH++e Dpg== X-Google-Smtp-Source: AGHT+IHtPJEK4UvnUH2lB7bwyfqs7oKhFlAZAFDdmrNEVSIuNr6gJJns/OGC4yt52V7y0o2FJEVYvG06l9M= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:9d:3983:ac13:c240]) (user=seanjc job=sendgmr) by 2002:aa7:8f88:0:b0:71d:ec11:1214 with SMTP id d2e1a72fcca58-71e1daad342mr3780b3a.0.1728489015563; Wed, 09 Oct 2024 08:50:15 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 9 Oct 2024 08:49:49 -0700 In-Reply-To: <20241009154953.1073471-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@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-11-seanjc@google.com> Subject: [PATCH v3 10/14] KVM: selftests: Enable mmu_stress_test on arm64 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 Enable the mmu_stress_test on arm64. The intent was to enable the test across all architectures when it was first added, but a few goofs made it unrunnable on !x86. Now that those goofs are fixed, at least for arm64, enable the test. Cc: Oliver Upton Cc: Marc Zyngier Reviewed-by: James Houghton Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile index 8c69a14dc93d..4db74792d689 100644 --- a/tools/testing/selftests/kvm/Makefile +++ b/tools/testing/selftests/kvm/Makefile @@ -178,6 +178,7 @@ TEST_GEN_PROGS_aarch64 += kvm_create_max_vcpus TEST_GEN_PROGS_aarch64 += kvm_page_table_test TEST_GEN_PROGS_aarch64 += memslot_modification_stress_test TEST_GEN_PROGS_aarch64 += memslot_perf_test +TEST_GEN_PROGS_aarch64 += mmu_stress_test TEST_GEN_PROGS_aarch64 += rseq_test TEST_GEN_PROGS_aarch64 += set_memory_region_test TEST_GEN_PROGS_aarch64 += steal_time From patchwork Wed Oct 9 15:49:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13828698 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (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 C1176204F68 for ; Wed, 9 Oct 2024 15:50:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728489021; cv=none; b=kryaINKvHmBWoWpsKnoTDSurLyvRXas6cM8Exm+b9QqLJH7u9/QOiXJq1SEaAfA5P1UytuIEmM+cKGprF4NVr4kdau9RNkU272FGnUP2zwIbuFJZNVuv1oS252QuMfiioChrzDed0+ovpgvuoTpiIKxaj7IqUX6Ap1w0Cm1C8VE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728489021; c=relaxed/simple; bh=ySYmz6+XDdTBZKIHQpIWEkeL65GnrCL3nDWRuqk8AHs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=HUv9Ln6oiXUHPSS+CTIsFZEVqtc5bSNNQ3CMbLBMgk+xqhsXXiLiq/vFR/29C7chRjpf2AuCKuJt0T1CISc3Sq9iTcJuerqrKg/8h25+cE4cVAuHfFSRHDPJbnY4VPv8m1QFSudd/pFx/6c5D10JLym3782XoFs0lX7327zblSg= 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=knLE5FfQ; arc=none smtp.client-ip=209.85.219.202 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="knLE5FfQ" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e2903a1cfe3so877516276.1 for ; Wed, 09 Oct 2024 08:50:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728489019; x=1729093819; 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=IpGlLPpdKIlhRCfJQtftwzWlWOxZ3g0ZRZhoTsEcT4I=; b=knLE5FfQmeSTB7xMcSplj1mP74VJ5UFP8UfVhbVUJ8rBuIBMXJj3WqSuOX3HoVtZvE B0WFiRXWtzZ96ejyKsV9QtaDO1upWXTsXDangHzQDFDQWbNdfs1UVkIcuvBZEn7U8uZ7 O1p5UEhXn/QCXdYPYNG0hYq0iSwgCXL8JwvDQ/FgvWCK9Etz6xlaS7NbXos4hf6gepew E1dUStsKLx2pt+D4WsXAxycW0IghnAR7tOxHIPWw76FzW6UwJMOCQfVqlGzYIpAwOGEI qJcfS5lRwCuLRLJorEfQMS00IsqfCkCrQaH5DhU0Exchs7U7cP/kfpJnG4fJJpnmHPe5 bEuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728489019; x=1729093819; 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=IpGlLPpdKIlhRCfJQtftwzWlWOxZ3g0ZRZhoTsEcT4I=; b=mAC2CRUKWnPlm/lLFV5n4HjqQdXbr+7hHwTPHeJ9H49eX/4hkZN4gGGEjl6Kxtw9X3 0C89bzQ5cUMfI7IU957us/T8ZOiIB8tCwEAyGmFqJxxEr9VcTwt2XYuvrIbOX5qcyNUj BfOd9N/xpQx1gF2v3F/irWpP5m7iJY49G2PHxNIKFtoPGK5vrR7uENT/8qZyIRSfugEj JDHcPAye9NrNlK9JTBGG/bEy7ppvrjikjTToNAwub1Kcli993i64Ggkg6Go8TKWyLA2J z56jjG53Pl3VjVthy999H8quoilK8yEzjkVY0GyHZdD7OnBJH3V3NtM2j2UbGFCZWgt0 0sbg== X-Forwarded-Encrypted: i=1; AJvYcCXxef+NBWCZDENzPT3htQXky2vuy/x7/o83FOtNArzKqvXndt39COC3auTK365HiMbmJnA=@vger.kernel.org X-Gm-Message-State: AOJu0YyY97P8nh/uWasQBq/ZQxAlmFKRRVz7xhawE54+9c2eB9vFAUiy wFDArCLXiegfbG7Ht37bqHExG3CDnkNqBnFTuYwugBg9HLzb2ztdF8uRbr24HZdNjZNPbkqvQxB NCw== X-Google-Smtp-Source: AGHT+IHJrTSljEGX+w+vGWljsF6J67uTWXS92qMmyHsTMzVm3HG9JVjkOOVhTNIgejhJpa5nZzlmmTlBPQo= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:9d:3983:ac13:c240]) (user=seanjc job=sendgmr) by 2002:a25:8248:0:b0:e28:e97f:5397 with SMTP id 3f1490d57ef6-e290b7ec5bdmr51276.3.1728489018761; Wed, 09 Oct 2024 08:50:18 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 9 Oct 2024 08:49:50 -0700 In-Reply-To: <20241009154953.1073471-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@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-12-seanjc@google.com> Subject: [PATCH v3 11/14] KVM: selftests: Use vcpu_arch_put_guest() in 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 Use vcpu_arch_put_guest() to write memory from the guest in mmu_stress_test as an easy way to provide a bit of extra coverage. Reviewed-by: James Houghton Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/mmu_stress_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/kvm/mmu_stress_test.c b/tools/testing/selftests/kvm/mmu_stress_test.c index fbb693428a82..656a837c7f49 100644 --- a/tools/testing/selftests/kvm/mmu_stress_test.c +++ b/tools/testing/selftests/kvm/mmu_stress_test.c @@ -23,7 +23,7 @@ static void guest_code(uint64_t start_gpa, uint64_t end_gpa, uint64_t stride) for (;;) { for (gpa = start_gpa; gpa < end_gpa; gpa += stride) - *((volatile uint64_t *)gpa) = gpa; + vcpu_arch_put_guest(*((volatile uint64_t *)gpa), gpa); GUEST_SYNC(0); } } From patchwork Wed Oct 9 15:49:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13828699 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.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 55729204F78 for ; Wed, 9 Oct 2024 15:50:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728489023; cv=none; b=EvyVqHRaOtO7bkPjDZvgRhI7nJF8y2aKMEWUjXyOSTiveuFKq9uSRN5KAdzPmDCZ/wJHEPOyWYekfFR3X26xyhxkIz7xxmvRARfgOvN2YgSZLmjPypS0aB8bA56OV9ckFXUQj6hL6+u9m9FYiuL5Hm8xD52vMkYWcrOTJbiYyAI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728489023; c=relaxed/simple; bh=itS1mlB5ofbsTPJgxID6BNl/jc/V5lwuHkPPw41X7OE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=B9yAUuP8xMcdM7H8vTMY94jXgUtlg8a1atvLjUx+RbmwaHuW3IUWeo7XGJR1gOof39LCgz4PR1Rw8fnOTYQ7VwerT+tkfDew289HrW96oNqb87E96pDaNtw2luSLIvqUs1/9+RVfu9T5iYshaZG9bYH4St1c5lwZPQereMXNW9I= 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=icjC7PP7; arc=none smtp.client-ip=209.85.128.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="icjC7PP7" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6e3231725c9so103847b3.1 for ; Wed, 09 Oct 2024 08:50:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728489020; x=1729093820; 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=HIeWF4AKDrrEZVf143SgWaofUVl00+qhbF3Z20PXTUE=; b=icjC7PP79stHSqasPNDzLPn/8fDaP9+O/ZBr8baTbexc2BiRHAE/aamlJuYaw69h9G OBbEV1FO2juBTxepKFTQINzYSissy2JL9RM9gErpQJ8lKbs+n6TuXamepmL2ESsDFU86 498jv/bxBDya5muONfvcGyBnWJCc0jBwRtdb1hjnfA3AsN5Qfx+nAVhJIQng+peNeAOf 1EghiUNqHDoJL9rdwwqdgTZqa+UM7zhtSSTIUsnJkVZo66Rkvn9ws82yZoty43a3motv 3kYrZA9fJDVDVX/z5mujdyIasP8XS1dKQuDgPz8hbnf73j0bgapX72FHQEtweOhQOoFX HrxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728489020; x=1729093820; 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=HIeWF4AKDrrEZVf143SgWaofUVl00+qhbF3Z20PXTUE=; b=j5F7bVMMWKTxcCNgYlB8Q1F4aRWJySkpH943ReafoavOCX1gHkxbWdHZ9SNUL9Wd1P o+Z/HirqxMX/twXutEOjydonYCJEsyaDtjdtBmWJOVZrjxY/AbzJ0XqeGpsEXvyqMeqI VqGZkRdoSl63sFBDVJ8JitdF9Z8RAHA9Xr94hB8GVvaDiDBrwk8rdm8euVEHLwkqeP0n Cxa5iDozsrfytTBFWzcJza/CTY264elhj5bvlkXKDYd6iVJjx/Dq37L5P8w5z53OEfQi Bub5XB8KLtRyTLLMl58VkBcS3irqDnNVlijInNT6WCZ4yq0ZyUWghMEVVDa5nzn31fZ7 KLGQ== X-Forwarded-Encrypted: i=1; AJvYcCVbiYaJdemmq1MdigBqwsuqsGpSvxJzb39+Lr5Dctd/du6PAv4XGZZ/fl+sY+hUt3xZduk=@vger.kernel.org X-Gm-Message-State: AOJu0Yy+W6R2RyYMTklQglvZUE6jJEaGKS5cJOin7WuuvjTZ5s80YxNX P4sGIiHQJnxONcrraIpVHqDad6mhUZRiIm+KJQLVk6Fu24c0F8DYSkBDcZmpn5oK8qeznAX1fIX 1lQ== X-Google-Smtp-Source: AGHT+IGckGzXTau4NGP/kAJ156CIPWl2QZt/eqMK5BUWyK8KyKg1g8Tc1FgMI3mqgA8yRsZ3clSiNLLsE+M= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:9d:3983:ac13:c240]) (user=seanjc job=sendgmr) by 2002:a05:690c:2093:b0:6d4:30f0:3a74 with SMTP id 00721157ae682-6e322171640mr503647b3.6.1728489020502; Wed, 09 Oct 2024 08:50:20 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 9 Oct 2024 08:49:51 -0700 In-Reply-To: <20241009154953.1073471-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@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-13-seanjc@google.com> Subject: [PATCH v3 12/14] KVM: selftests: Precisely limit the number of guest loops in 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 Run the exact number of guest loops required in mmu_stress_test instead of looping indefinitely in anticipation of adding more stages that run different code (e.g. reads instead of writes). Reviewed-by: James Houghton Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/mmu_stress_test.c | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/kvm/mmu_stress_test.c b/tools/testing/selftests/kvm/mmu_stress_test.c index 656a837c7f49..c6bf18cb7c89 100644 --- a/tools/testing/selftests/kvm/mmu_stress_test.c +++ b/tools/testing/selftests/kvm/mmu_stress_test.c @@ -20,12 +20,15 @@ static void guest_code(uint64_t start_gpa, uint64_t end_gpa, uint64_t stride) { uint64_t gpa; + int i; - for (;;) { + for (i = 0; i < 2; i++) { for (gpa = start_gpa; gpa < end_gpa; gpa += stride) vcpu_arch_put_guest(*((volatile uint64_t *)gpa), gpa); - GUEST_SYNC(0); + GUEST_SYNC(i); } + + GUEST_ASSERT(0); } struct vcpu_info { @@ -52,10 +55,18 @@ static void rendezvous_with_boss(void) } } -static void run_vcpu(struct kvm_vcpu *vcpu) +static void assert_sync_stage(struct kvm_vcpu *vcpu, int stage) +{ + struct ucall uc; + + TEST_ASSERT_EQ(get_ucall(vcpu, &uc), UCALL_SYNC); + TEST_ASSERT_EQ(uc.args[1], stage); +} + +static void run_vcpu(struct kvm_vcpu *vcpu, int stage) { vcpu_run(vcpu); - TEST_ASSERT_EQ(get_ucall(vcpu, NULL), UCALL_SYNC); + assert_sync_stage(vcpu, stage); } static void *vcpu_worker(void *data) @@ -69,7 +80,8 @@ static void *vcpu_worker(void *data) rendezvous_with_boss(); - run_vcpu(vcpu); + /* Stage 0, write all of guest memory. */ + run_vcpu(vcpu, 0); rendezvous_with_boss(); #ifdef __x86_64__ vcpu_sregs_get(vcpu, &sregs); @@ -79,7 +91,8 @@ static void *vcpu_worker(void *data) #endif rendezvous_with_boss(); - run_vcpu(vcpu); + /* Stage 1, re-write all of guest memory. */ + run_vcpu(vcpu, 1); rendezvous_with_boss(); return NULL; From patchwork Wed Oct 9 15:49:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13828700 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) (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 6E5A8204F91 for ; Wed, 9 Oct 2024 15:50:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728489024; cv=none; b=IUB0vmDWg6MgE9VFn7HGEK5jd6FZkHMK0fUF4S4o6g7HP8nfUGdGqdg1ZpIP/pmbb8p+irPwk6grKmoRF8xIwJdxJnVbeOqCIyRzj2KTmeK7DUZ2K3r5HRY8HQbv5bx9k/CDN3dtjwaY4UQQcDenoNfay0DfqG1bagJNcE+9Mac= 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.202 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-f202.google.com with SMTP id 41be03b00d2f7-7e9fe0a21a7so3418842a12.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=CZJ1Cvahcc4rBMIGRGvCB4RBM9CfImJ1oPXHSG6IhmQwWlgOCEF/10T5vi0H+w53bv KcVckfVIutXnNkxkqGkXHWW69oMtyxzH+0oSQFhKrv5hyZcE6A781kO9fq9/qityReyD 3leaeYuM8U/9IMTwQzKD1DM8oxiDw3Zv0R6/NwDdKI026hDcC8018k9vGlAsfdxl8NG+ EaMb6L7mKXl6id/HXXzciWsalA03TKtKj2qWMJcJrVOQv604eBWlkZxOmp1hefU0zcHW zpCQZ4b3oSXkc7uwhLV6uIouL0xm3V9HLEQcMLay83DDD4+4OvpaqTGA37ln71VDm79v 0wCQ== X-Forwarded-Encrypted: i=1; AJvYcCXJFN+UL3LKlPoeyw1C6XYrre6Pfts1OEeiJzxZXk3yhKxoufI7PVIXYbYYqx9j2qC5RJI=@vger.kernel.org X-Gm-Message-State: AOJu0YzzkSjci1HSjIpo7SEhHyc9daranYpNUm+D7XLhxdR9kHsy4lJa Z/lE/HjmwThClID3IPGi3D1jidsKgt5wviZ/l1JAIRsDhWKZqfSXqQ4D99Rg5zLUMZgyWTEtJhy 9ew== 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: kvm@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 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); } + for (gpa = start_gpa; gpa < end_gpa; gpa += stride) + *((volatile uint64_t *)gpa); + GUEST_SYNC(2); + GUEST_ASSERT(0); } @@ -95,6 +99,10 @@ static void *vcpu_worker(void *data) run_vcpu(vcpu, 1); rendezvous_with_boss(); + /* Stage 2, read all of guest memory, which is now read-only. */ + run_vcpu(vcpu, 2); + rendezvous_with_boss(); + return NULL; } @@ -175,7 +183,7 @@ int main(int argc, char *argv[]) const uint64_t start_gpa = SZ_4G; const int first_slot = 1; - 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 = false; @@ -279,14 +287,20 @@ int main(int argc, char *argv[]) rendezvous_with_vcpus(&time_reset, "reset"); rendezvous_with_vcpus(&time_run2, "run 2"); + mprotect(mem, slot_size, PROT_READ); + rendezvous_with_vcpus(&time_ro, "mprotect RO"); + + time_ro = timespec_sub(time_ro, time_run2); time_run2 = timespec_sub(time_run2, time_reset); - time_reset = timespec_sub(time_reset, time_run1); + time_reset = timespec_sub(time_reset, time_run1); time_run1 = timespec_sub(time_run1, time_start); - pr_info("run1 = %ld.%.9lds, reset = %ld.%.9lds, run2 = %ld.%.9lds\n", + pr_info("run1 = %ld.%.9lds, reset = %ld.%.9lds, run2 = %ld.%.9lds, " + "ro = %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); /* * Delete even numbered slots (arbitrary) and unmap the first half of From patchwork Wed Oct 9 15:49:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13828701 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.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 84A7B205E37 for ; Wed, 9 Oct 2024 15:50:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728489027; cv=none; b=osV/+YMjG/Xggb7Jl7enRIm/SMNrfP8S4a98VOqlmEaaSQosmdWaFVuqC6nNpfZqx3oC7BB6pQwNsyUXMZpF+JEXZ+1dkYGZGc0o0UVK1/gavo/gyVa+DGASmKmsRsgdXy3SLKUV5WF1Zhle4H4ePg10llJ03R7/rQNgwkiEPxY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728489027; c=relaxed/simple; bh=mY+b3Elc5MdSudJ5jMgcrdjdRtDcgJfJ1HtYD0SpHWQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=b3hBRX5ILlnKdMQ0cba/y7TxQTkQf7fkYCgPQmta1ZaiMWz6NPei2FnZ4RQIPJC3rnFBuCeJrftwqNfR3KGFkSgwa5q5l83HRaWUOYuF6XTQvRlyjtSmSWOwpVfXj98SCaaGGEUnLAtQ5H/ed4i4WVjs7DCZ4a7BTIpd1MsLC5w= 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=lOOuUpio; arc=none smtp.client-ip=209.85.214.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="lOOuUpio" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-20c61e4b890so14625385ad.1 for ; Wed, 09 Oct 2024 08:50:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728489025; x=1729093825; 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=pdirxHCOZgZcScGJrji1f7MunRQ6Bg++3PkXMCIJLoA=; b=lOOuUpio2s6VhAEzmu5WisaBkuwwK4BsTXLQ0olhKvX1udM0w44/X002nQObplp8Di NCwNW3xXOwe/7za4IjQWLXgRqAUKncYst56DmlARYPWJutEwUfsijimRQcxFlji6ivWR XYN5Yy3iBLBjsUWREAgPr4uXzpBNgfP+sgaoL+jzkJZ6ci+/Qgs7NSKEdQ542v8+odlx MTZz3Fnw5/azYupC8k96MbAGEiec3veEMFge+c9OKmg/P9w4dtLMc/lfIijMjnYiQRA0 vNwEZ65LMdQxaa4dmlA66VUxWerr1LtHDyKQqNEFEbFE5Res6wdSHdlk1dHY/l53c5AY Ipfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728489025; x=1729093825; 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=pdirxHCOZgZcScGJrji1f7MunRQ6Bg++3PkXMCIJLoA=; b=XXua1BsysBYkjSIAdO1tYe0G9IiL2sN7p4dnAUGZVX0aET2tnEdnxhxpl7Y71iQ313 JCIJNx/C+3f9xYlT6/ItC2IEmyLC3VpvQ6KQLJ/YurYLuBHpZJbDRZRHZ7htzKn0AnrC V1id6u3ZOBbLjPYwMJGRYCZXUIBmhV1meGnebeulMb4CD7Iv3RpBOAeZ3tm1crg8ifza DWZuF1ufNYCNyIp1l1xPM1qqhJrpvdOI97gJJAv+StqkW7+eTOqkg0O+LWgG0ob+CgJe 8cbXmZHB6HYt1ikfaNKHtljCUNJOtuP9QPJ/1SpXSDbAitF1EUpSQ25sSGbASumr6jPD Tpjg== X-Forwarded-Encrypted: i=1; AJvYcCXVK0PK8y5UT25SCUuYD9CYVpzExEwmIIhWvXyE9V7/5V8SHEiDtLax6Svk+6jT3YJbxNk=@vger.kernel.org X-Gm-Message-State: AOJu0YzSMHkvBeqeb67BvvDbxzLQGXS5dTP/M0KRPZKZEwURq+9nHFCq H1DltCYtter7M3SvhR1Rr300PoRSfYD2Njom8wPzyekkNq0b0Wqh+JGD3bSRqzDwdW3qmMXTAbM Seg== X-Google-Smtp-Source: AGHT+IF06EOvabba1YpY/m+9TdddfKJv+phXMs6xFxlGn64HlbjifXqL0d0/QpkP5vVUJng9o1/hHhmQcTE= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:9d:3983:ac13:c240]) (user=seanjc job=sendgmr) by 2002:a17:902:d2c2:b0:20b:ad74:c83d with SMTP id d9443c01a7336-20c6377b2e8mr457555ad.8.1728489024593; Wed, 09 Oct 2024 08:50:24 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 9 Oct 2024 08:49:53 -0700 In-Reply-To: <20241009154953.1073471-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@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-15-seanjc@google.com> Subject: [PATCH v3 14/14] KVM: selftests: Verify KVM correctly handles mprotect(PROT_READ) 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 Add two phases to mmu_stress_test to verify that KVM correctly handles guest memory that was writable, and then made read-only in the primary MMU, and then made writable again. Add bonus coverage for x86 and arm64 to verify that all of guest memory was marked read-only. Making forward progress (without making memory writable) requires arch specific code to skip over the faulting instruction, but the test can at least verify each vCPU's starting page was made read-only for other architectures. Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/mmu_stress_test.c | 104 +++++++++++++++++- 1 file changed, 101 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/kvm/mmu_stress_test.c b/tools/testing/selftests/kvm/mmu_stress_test.c index 0918fade9267..d9c76b4c0d88 100644 --- a/tools/testing/selftests/kvm/mmu_stress_test.c +++ b/tools/testing/selftests/kvm/mmu_stress_test.c @@ -17,6 +17,8 @@ #include "processor.h" #include "ucall_common.h" +static bool mprotect_ro_done; + static void guest_code(uint64_t start_gpa, uint64_t end_gpa, uint64_t stride) { uint64_t gpa; @@ -32,6 +34,42 @@ static void guest_code(uint64_t start_gpa, uint64_t end_gpa, uint64_t stride) *((volatile uint64_t *)gpa); GUEST_SYNC(2); + /* + * Write to the region while mprotect(PROT_READ) is underway. Keep + * looping until the memory is guaranteed to be read-only, otherwise + * vCPUs may complete their writes and advance to the next stage + * prematurely. + * + * For architectures that support skipping the faulting instruction, + * generate the store via inline assembly to ensure the exact length + * of the instruction is known and stable (vcpu_arch_put_guest() on + * fixed-length architectures should work, but the cost of paranoia + * is low in this case). For x86, hand-code the exact opcode so that + * there is no room for variability in the generated instruction. + */ + do { + for (gpa = start_gpa; gpa < end_gpa; gpa += stride) +#ifdef __x86_64__ + asm volatile(".byte 0x48,0x89,0x00" :: "a"(gpa) : "memory"); /* mov %rax, (%rax) */ +#elif defined(__aarch64__) + asm volatile("str %0, [%0]" :: "r" (gpa) : "memory"); +#else + vcpu_arch_put_guest(*((volatile uint64_t *)gpa), gpa); +#endif + } while (!READ_ONCE(mprotect_ro_done)); + + /* + * Only architectures that write the entire range can explicitly sync, + * as other architectures will be stuck on the write fault. + */ +#if defined(__x86_64__) || defined(__aarch64__) + GUEST_SYNC(3); +#endif + + for (gpa = start_gpa; gpa < end_gpa; gpa += stride) + vcpu_arch_put_guest(*((volatile uint64_t *)gpa), gpa); + GUEST_SYNC(4); + GUEST_ASSERT(0); } @@ -79,6 +117,7 @@ static void *vcpu_worker(void *data) struct vcpu_info *info = data; struct kvm_vcpu *vcpu = info->vcpu; struct kvm_vm *vm = vcpu->vm; + int r; vcpu_args_set(vcpu, 3, info->start_gpa, info->end_gpa, vm->page_size); @@ -101,6 +140,57 @@ static void *vcpu_worker(void *data) /* Stage 2, read all of guest memory, which is now read-only. */ run_vcpu(vcpu, 2); + + /* + * Stage 3, write guest memory and verify KVM returns -EFAULT for once + * the mprotect(PROT_READ) lands. Only architectures that support + * validating *all* of guest memory sync for this stage, as vCPUs will + * be stuck on the faulting instruction for other architectures. Go to + * stage 3 without a rendezvous + */ + do { + r = _vcpu_run(vcpu); + } while (!r); + TEST_ASSERT(r == -1 && errno == EFAULT, + "Expected EFAULT on write to RO memory, got r = %d, errno = %d", r, errno); + +#if defined(__x86_64__) || defined(__aarch64__) + /* + * Verify *all* writes from the guest hit EFAULT due to the VMA now + * being read-only. x86 and arm64 only at this time as skipping the + * instruction that hits the EFAULT requires advancing the program + * counter, which is arch specific and relies on inline assembly. + */ +#ifdef __x86_64__ + vcpu->run->kvm_valid_regs = KVM_SYNC_X86_REGS; +#endif + for (;;) { + r = _vcpu_run(vcpu); + if (!r) + break; + TEST_ASSERT_EQ(errno, EFAULT); +#if defined(__x86_64__) + WRITE_ONCE(vcpu->run->kvm_dirty_regs, KVM_SYNC_X86_REGS); + vcpu->run->s.regs.regs.rip += 3; +#elif defined(__aarch64__) + vcpu_set_reg(vcpu, ARM64_CORE_REG(regs.pc), + vcpu_get_reg(vcpu, ARM64_CORE_REG(regs.pc)) + 4); +#endif + + } + assert_sync_stage(vcpu, 3); +#endif /* __x86_64__ || __aarch64__ */ + rendezvous_with_boss(); + + /* + * Stage 4. Run to completion, waiting for mprotect(PROT_WRITE) to + * make the memory writable again. + */ + do { + r = _vcpu_run(vcpu); + } while (r && errno == EFAULT); + TEST_ASSERT_EQ(r, 0); + assert_sync_stage(vcpu, 4); rendezvous_with_boss(); return NULL; @@ -183,7 +273,7 @@ int main(int argc, char *argv[]) const uint64_t start_gpa = SZ_4G; const int first_slot = 1; - struct timespec time_start, time_run1, time_reset, time_run2, time_ro; + struct timespec time_start, time_run1, time_reset, time_run2, time_ro, time_rw; uint64_t max_gpa, gpa, slot_size, max_mem, i; int max_slots, slot, opt, fd; bool hugepages = false; @@ -288,19 +378,27 @@ int main(int argc, char *argv[]) rendezvous_with_vcpus(&time_run2, "run 2"); mprotect(mem, slot_size, PROT_READ); + usleep(10); + mprotect_ro_done = true; + sync_global_to_guest(vm, mprotect_ro_done); + rendezvous_with_vcpus(&time_ro, "mprotect RO"); + mprotect(mem, slot_size, PROT_READ | PROT_WRITE); + rendezvous_with_vcpus(&time_rw, "mprotect RW"); + time_rw = timespec_sub(time_rw, time_ro); time_ro = timespec_sub(time_ro, time_run2); time_run2 = timespec_sub(time_run2, time_reset); time_reset = timespec_sub(time_reset, time_run1); time_run1 = timespec_sub(time_run1, time_start); pr_info("run1 = %ld.%.9lds, reset = %ld.%.9lds, run2 = %ld.%.9lds, " - "ro = %ld.%.9lds\n", + "ro = %ld.%.9lds, rw = %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_ro.tv_sec, time_ro.tv_nsec); + time_ro.tv_sec, time_ro.tv_nsec, + time_rw.tv_sec, time_rw.tv_nsec); /* * Delete even numbered slots (arbitrary) and unmap the first half of