Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp2794142rwb; Mon, 5 Sep 2022 01:19:14 -0700 (PDT) X-Google-Smtp-Source: AA6agR6pbgzMJ6aVWn9RMlzjmYvU7dVGbAtI0Z5NrmIcLjLevgEnOrEpTt9HPJpeTDnEVi16hhUd X-Received: by 2002:a17:906:d552:b0:74f:8506:2dc8 with SMTP id cr18-20020a170906d55200b0074f85062dc8mr10166443ejc.345.1662365954371; Mon, 05 Sep 2022 01:19:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662365954; cv=none; d=google.com; s=arc-20160816; b=tXE43IsqN1Z7fzf3uo6+zvLuY2tVEkOK/D/oyYgdebc7X4yUtuyICHKnQ6LxeHQhBo 4c728SAauzSu8tq8YYp0KxZpcAYDvRJDoh8fCquKNn4IQ5MdzrR9zYJRuNKgQWWADQWe W0B02YF4XU3q3JAbV53Z4VZBRWN5+RDKaaOEbh4m0HAQaj5OKgpa9PaXnfWe4r+01KCT SVW09UpNJYtn0Ye/FNGmt23UnoMVQtPwvcnIlIfe+rAvjhNC89jjhC3yGFDWiz2Kiq3R 12pgdxDjGafPSBiiEMkowLgRMnvt35dKz/NryfpV7xJBPzL2rj89E0IAqMcU93DqxbN4 W68w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:dkim-signature:date; bh=gRgVXREhnYAT2UWNxZgIgPWYkP5DgXnZ3gmvS0nsTF4=; b=U3QnucD8TrBzRTA6NIuYmW8e+H1xAG7XRuOEZXsDHyP6sZcSygJoKrQgeKfvwCxV6s Wlm/0dCm2IvOwrbi/7du4Qktu2iSNfL5HXY00oy/2rSR1W5N18xbYqatyIi8gFzqlxwQ ZWTqvcRUs77AO3IYoSXJRxzgjfMeJgj/cidzPkQFj4U09CO2g3UvfiZ/08HiUrdSkcGB B8pLjIEavUxilgD8HAv+RmdY8yGtv7YHAv7fKCtknuFJ2LgATIqqTg6u2IgnAcIaqaPa nRuRUUubrizOf8g8BR35kshHZ0ZW0qt6dFbdNLXKwCOq27YJeRYXAjIimwmyCn/MROLx IjAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=PPMqe7wK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f3-20020a05640214c300b0044e9292dcd2si1134399edx.57.2022.09.05.01.18.50; Mon, 05 Sep 2022 01:19:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=PPMqe7wK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236372AbiIEHch (ORCPT + 99 others); Mon, 5 Sep 2022 03:32:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236462AbiIEHcF (ORCPT ); Mon, 5 Sep 2022 03:32:05 -0400 Received: from out0.migadu.com (out0.migadu.com [94.23.1.103]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19A5A1C924; Mon, 5 Sep 2022 00:31:44 -0700 (PDT) Date: Mon, 5 Sep 2022 09:31:40 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1662363102; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=gRgVXREhnYAT2UWNxZgIgPWYkP5DgXnZ3gmvS0nsTF4=; b=PPMqe7wKlQ/65Q8WGpBqIXrecN3XgJnWaf9c6H0A94uv7qWM3jAWlxuIiTRFdrcJL4e2DJ ieF6OM+VKlBxFN0JV2bDVl5b9QldpfuOGhyBr6FIk66uLyHLfX5eP5VXjLRy8GwQ+E5cZ+ QUim7QAeV6B1zXmG+09AFJvUHb8eskg= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Andrew Jones To: Oliver Upton Cc: Marc Zyngier , James Morse , Alexandru Elisei , Paolo Bonzini , Shuah Khan , Suzuki K Poulose , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, Reiji Watanabe , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: Re: [PATCH v2 7/7] KVM: selftests: Add test for RAZ/WI AArch32 ID registers Message-ID: <20220905073140.lrsrbyu2zhkiki5a@kamzik> References: <20220902154804.1939819-1-oliver.upton@linux.dev> <20220902154804.1939819-8-oliver.upton@linux.dev> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220902154804.1939819-8-oliver.upton@linux.dev> X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 02, 2022 at 03:48:03PM +0000, Oliver Upton wrote: > Add a test to assert that KVM handles the AArch64 views of the AArch32 > ID registers as RAZ/WI (writable only from userspace). > > Signed-off-by: Oliver Upton > --- > tools/testing/selftests/kvm/.gitignore | 1 + > tools/testing/selftests/kvm/Makefile | 1 + > .../kvm/aarch64/aarch64_only_id_regs.c | 135 ++++++++++++++++++ > 3 files changed, 137 insertions(+) > create mode 100644 tools/testing/selftests/kvm/aarch64/aarch64_only_id_regs.c > > diff --git a/tools/testing/selftests/kvm/.gitignore b/tools/testing/selftests/kvm/.gitignore > index d625a3f83780..4331af62a982 100644 > --- a/tools/testing/selftests/kvm/.gitignore > +++ b/tools/testing/selftests/kvm/.gitignore > @@ -1,4 +1,5 @@ > # SPDX-License-Identifier: GPL-2.0-only > +/aarch64/aarch64_only_id_regs > /aarch64/arch_timer > /aarch64/debug-exceptions > /aarch64/get-reg-list > diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile > index 4c122f1b1737..efe155259095 100644 > --- a/tools/testing/selftests/kvm/Makefile > +++ b/tools/testing/selftests/kvm/Makefile > @@ -144,6 +144,7 @@ TEST_GEN_PROGS_x86_64 += system_counter_offset_test > # Compiled outputs used by test targets > TEST_GEN_PROGS_EXTENDED_x86_64 += x86_64/nx_huge_pages_test > > +TEST_GEN_PROGS_aarch64 += aarch64/aarch64_only_id_regs > TEST_GEN_PROGS_aarch64 += aarch64/arch_timer > TEST_GEN_PROGS_aarch64 += aarch64/debug-exceptions > TEST_GEN_PROGS_aarch64 += aarch64/get-reg-list > diff --git a/tools/testing/selftests/kvm/aarch64/aarch64_only_id_regs.c b/tools/testing/selftests/kvm/aarch64/aarch64_only_id_regs.c > new file mode 100644 > index 000000000000..704a3e7524a8 > --- /dev/null > +++ b/tools/testing/selftests/kvm/aarch64/aarch64_only_id_regs.c > @@ -0,0 +1,135 @@ > +// SPDX-License-Identifier: GPL-2.0-only > +/* > + * aarch64_only_id_regs - Test for ID register behavior on AArch64-only systems > + * > + * Copyright (c) 2022 Google LLC. > + * > + * Test that KVM handles the AArch64 views of the AArch32 ID registers as RAZ > + * and WI from userspace. > + */ > + > +#include > + > +#include "kvm_util.h" > +#include "processor.h" > +#include "test_util.h" > + > +#define BAD_ID_REG_VAL 0x1badc0deul > + > +#define GUEST_ASSERT_REG_RAZ(reg) GUEST_ASSERT_EQ(read_sysreg_s(reg), 0) > + > +static void guest_main(void) > +{ > + GUEST_ASSERT_REG_RAZ(SYS_ID_PFR0_EL1); > + GUEST_ASSERT_REG_RAZ(SYS_ID_PFR1_EL1); > + GUEST_ASSERT_REG_RAZ(SYS_ID_DFR0_EL1); > + GUEST_ASSERT_REG_RAZ(SYS_ID_MMFR0_EL1); > + GUEST_ASSERT_REG_RAZ(SYS_ID_MMFR1_EL1); > + GUEST_ASSERT_REG_RAZ(SYS_ID_MMFR2_EL1); > + GUEST_ASSERT_REG_RAZ(SYS_ID_MMFR3_EL1); > + GUEST_ASSERT_REG_RAZ(SYS_ID_ISAR0_EL1); > + GUEST_ASSERT_REG_RAZ(SYS_ID_ISAR1_EL1); > + GUEST_ASSERT_REG_RAZ(SYS_ID_ISAR2_EL1); > + GUEST_ASSERT_REG_RAZ(SYS_ID_ISAR3_EL1); > + GUEST_ASSERT_REG_RAZ(SYS_ID_ISAR4_EL1); > + GUEST_ASSERT_REG_RAZ(SYS_ID_ISAR5_EL1); > + GUEST_ASSERT_REG_RAZ(SYS_ID_MMFR4_EL1); > + GUEST_ASSERT_REG_RAZ(SYS_ID_ISAR6_EL1); > + GUEST_ASSERT_REG_RAZ(SYS_MVFR0_EL1); > + GUEST_ASSERT_REG_RAZ(SYS_MVFR1_EL1); > + GUEST_ASSERT_REG_RAZ(SYS_MVFR2_EL1); > + GUEST_ASSERT_REG_RAZ(SYS_ID_PFR2_EL1); > + GUEST_ASSERT_REG_RAZ(SYS_ID_MMFR5_EL1); > + > + GUEST_DONE(); > +} > + > +static void test_guest_raz(struct kvm_vcpu *vcpu) > +{ > + struct ucall uc; > + > + vcpu_run(vcpu); > + > + switch (get_ucall(vcpu, &uc)) { > + case UCALL_ABORT: > + REPORT_GUEST_ASSERT(uc); > + break; > + case UCALL_DONE: > + break; > + default: > + TEST_FAIL("Unexpected ucall: %lu", uc.cmd); > + } > +} > + > +static uint64_t reg_ids[] = { > + KVM_ARM64_SYS_REG(SYS_ID_PFR0_EL1), > + KVM_ARM64_SYS_REG(SYS_ID_PFR1_EL1), > + KVM_ARM64_SYS_REG(SYS_ID_DFR0_EL1), > + KVM_ARM64_SYS_REG(SYS_ID_MMFR0_EL1), > + KVM_ARM64_SYS_REG(SYS_ID_MMFR1_EL1), > + KVM_ARM64_SYS_REG(SYS_ID_MMFR2_EL1), > + KVM_ARM64_SYS_REG(SYS_ID_MMFR3_EL1), > + KVM_ARM64_SYS_REG(SYS_ID_ISAR0_EL1), > + KVM_ARM64_SYS_REG(SYS_ID_ISAR1_EL1), > + KVM_ARM64_SYS_REG(SYS_ID_ISAR2_EL1), > + KVM_ARM64_SYS_REG(SYS_ID_ISAR3_EL1), > + KVM_ARM64_SYS_REG(SYS_ID_ISAR4_EL1), > + KVM_ARM64_SYS_REG(SYS_ID_ISAR5_EL1), > + KVM_ARM64_SYS_REG(SYS_ID_MMFR4_EL1), > + KVM_ARM64_SYS_REG(SYS_ID_ISAR6_EL1), > + KVM_ARM64_SYS_REG(SYS_MVFR0_EL1), > + KVM_ARM64_SYS_REG(SYS_MVFR1_EL1), > + KVM_ARM64_SYS_REG(SYS_MVFR2_EL1), > + KVM_ARM64_SYS_REG(SYS_ID_PFR2_EL1), > + KVM_ARM64_SYS_REG(SYS_ID_MMFR5_EL1), Hi Oliver, I see all the hidden and unallocated registers have been filtered out of the test lists. They should also behave as RAZ, right? Maybe we should keep them in the lists here for consistency and to test them as well. Thanks, drew > +}; > + > +static void test_user_raz_wi(struct kvm_vcpu *vcpu) > +{ > + int i; > + > + for (i = 0; i < ARRAY_SIZE(reg_ids); i++) { > + uint64_t reg_id = reg_ids[i]; > + uint64_t val; > + > + vcpu_get_reg(vcpu, reg_id, &val); > + ASSERT_EQ(val, 0); > + > + /* > + * Expect the ioctl to succeed with no effect on the register > + * value. > + */ > + vcpu_set_reg(vcpu, reg_id, BAD_ID_REG_VAL); > + > + vcpu_get_reg(vcpu, reg_id, &val); > + ASSERT_EQ(val, 0); > + } > +} > + > +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); > + > + el0 = (val & ARM64_FEATURE_MASK(ID_AA64PFR0_EL0)) >> ID_AA64PFR0_EL0_SHIFT; > + return el0 == ID_AA64PFR0_ELx_64BIT_ONLY; > +} > + > +int main(void) > +{ > + struct kvm_vcpu *vcpu; > + struct kvm_vm *vm; > + > + vm = vm_create_with_one_vcpu(&vcpu, guest_main); > + > + TEST_REQUIRE(vcpu_aarch64_only(vcpu)); > + > + ucall_init(vm, NULL); > + > + test_user_raz_wi(vcpu); > + test_guest_raz(vcpu); > + > + ucall_uninit(vm); > + kvm_vm_free(vm); > +} > -- > 2.37.2.789.g6183377224-goog >