From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 59E38C2BA18 for ; Thu, 20 Jun 2024 22:30:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To:References: MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=zHREBPCUIs8n+I6KtcDeDKXi3C09zaSei5HzCaoQhXU=; b=hothGVIlIYXs/EaRMa3Bxuf6qQ 3FD8B36myp0bhl6FG+dGQRImskvMI/DJBzTxMYnjhhoi9WGmTKtgfO/ODvp+C50HaLMMlmGzqmyLp TWnbhzOWwgSS8ZtPlxf19hf5hXgEZ1ETGxyqeM2wu4yahzt2S78flh9ZJmolfq454fjGS+ZuwXRfj GImnnKiRN4WnNjzt+Na+Cph3iUGiss5eeLuaGO59p5oUAOI/mnZKJ8cppJUG5tlLl4nLeX4vx6bVG nXIieXjU43a0TS6fFhbBDZwC8hLDzamC+EYE7PNA6PQpxKq2629VeulUnMvefCioc9Q4xc55p63P1 iiVAADhQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKQId-00000006xRt-3jNK; Thu, 20 Jun 2024 22:30:36 +0000 Received: from mail-il1-x129.google.com ([2607:f8b0:4864:20::129]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKQIa-00000006xRP-1wrL for linux-arm-kernel@lists.infradead.org; Thu, 20 Jun 2024 22:30:34 +0000 Received: by mail-il1-x129.google.com with SMTP id e9e14a558f8ab-375bb80e5b8so17645ab.1 for ; Thu, 20 Jun 2024 15:30:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1718922631; x=1719527431; darn=lists.infradead.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=zHREBPCUIs8n+I6KtcDeDKXi3C09zaSei5HzCaoQhXU=; b=LqcIImpzeNKOPRILoAZhzx/sXc1dCSmUFDn1C1NmgjAO4IHSugurkcNnGkqnCzUYiE Q0vUcYfFTKBzdZSOmKpAs9xuKw2YMjyNmZHSSb7/GzabeEIBj9tThZ5rCgXsyG3f1c1a aXauvL3++EK/WQ+8FYKpdDbW3LTEqS3J8GLkl5vnR0odi/9Ks8BhaVlrt9iRkvubXjh3 oCPZRUeObk+KwUI2wGB2VPid0JlnAa7Cujr2kISjzkAV2sguKDHYK6/uiN6Bp2uTU0Ej bdzUHoIidr8hl3kf7/JjMGttDui0BWefd5s5YIYkaT8UKRIFt3FNlbMW09JTL/4BphEC 1qbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718922631; x=1719527431; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zHREBPCUIs8n+I6KtcDeDKXi3C09zaSei5HzCaoQhXU=; b=J1L/rN+hfLFW0DtwFz8YvFrkz2HnytAkt52JImRTwLaOqk6R6aM7pKbqJC7r4vyw42 SCMrr6GhJxmd9AKkR39ut86FfapM+5vtF9kpCENNCFKBMp1XKeIX5c7U4ytV6+A4zNxo p4d265L5A+EPRHijkmSUJLr3jtxsQ7W3JgoQ+zEC+4pyIBp3c0dtb8nJKn7AZt+2Q8E+ /0E7ctLLm4Ed1m2OK66DwvzK+4GS64PC0EsLk3cqiZosKRkiRVKTP0MWsmwJ9NRsGZPA geDgRQXrCvKSwuMr65zOtb0uu9NMFX8SPfzKCJ8rNIVSIypY9zC8dN9WzSSRIzE/Fcuj cKyQ== X-Forwarded-Encrypted: i=1; AJvYcCWjHzCoQSH6qdvAlPTIc1GqdYAdhnA8lkoic9A+qP2I8OZagTfArZNnknHqWoyWX5s3oMO8TCWo1J1tNxtrvmF7oNe1RvBo3UeCOB8xTGc7KtSeSZM= X-Gm-Message-State: AOJu0Yw+Pq5pKlAvVXnZi9UIA2QN55BvqIPkUa40lcegi756TLk45JI9 rWF0Tx1IY17wwucMgdgmSrOmCxQ8f6HsyyXg2Nx9qyWS7Ib1N7z3DC1931zg9Vniyw9rl2+iZK+ OfgtP9ZHu+SouXxNHztGHpkX4BGA6J6jQeHBh X-Google-Smtp-Source: AGHT+IG3QZzSrTWr7FqOD3AtuM1SKP3sfyODhN7mg13aomMD50DF/jtHQSYwrOACQW7sSeuYOA45Mb+PEMZtdzwhpq8= X-Received: by 2002:a92:dc10:0:b0:375:9e2b:a832 with SMTP id e9e14a558f8ab-3762f4f3869mr453635ab.21.1718922630941; Thu, 20 Jun 2024 15:30:30 -0700 (PDT) MIME-Version: 1.0 References: <20240619083200.1047073-1-shahuang@redhat.com> <20240619083200.1047073-2-shahuang@redhat.com> In-Reply-To: <20240619083200.1047073-2-shahuang@redhat.com> From: Raghavendra Rao Ananta Date: Thu, 20 Jun 2024 15:30:18 -0700 Message-ID: Subject: Re: [PATCH v10 1/3] KVM: selftests: aarch64: Add helper function for the vpmu vcpu creation To: Shaoqin Huang Cc: Oliver Upton , Marc Zyngier , kvmarm@lists.linux.dev, Eric Auger , James Morse , Suzuki K Poulose , Zenghui Yu , Paolo Bonzini , Shuah Khan , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240620_153032_700964_6B9D1969 X-CRM114-Status: GOOD ( 24.39 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Shaoqin On Wed, Jun 19, 2024 at 1:32=E2=80=AFAM Shaoqin Huang = wrote: > > Create a vcpu with vpmu would be a common requirement for the vpmu test, > so add the helper function for the vpmu vcpu creation. And use those > helper function in the vpmu_counter_access.c test. > > Use this chance to delete the meaningless ASSERT about the pmuver, > because KVM does not advertise an IMP_DEF PMU to guests. > > No functional changes intended. > > Reviewed-by: Eric Auger > Signed-off-by: Shaoqin Huang > --- > .../kvm/aarch64/vpmu_counter_access.c | 32 ++++--------------- > .../selftests/kvm/include/aarch64/vpmu.h | 28 ++++++++++++++++ > 2 files changed, 34 insertions(+), 26 deletions(-) > create mode 100644 tools/testing/selftests/kvm/include/aarch64/vpmu.h > > diff --git a/tools/testing/selftests/kvm/aarch64/vpmu_counter_access.c b/= tools/testing/selftests/kvm/aarch64/vpmu_counter_access.c > index d31b9f64ba14..68da44198719 100644 > --- a/tools/testing/selftests/kvm/aarch64/vpmu_counter_access.c > +++ b/tools/testing/selftests/kvm/aarch64/vpmu_counter_access.c > @@ -16,6 +16,7 @@ > #include > #include > #include > +#include > #include > #include > > @@ -407,18 +408,8 @@ static void guest_code(uint64_t expected_pmcr_n) > /* Create a VM that has one vCPU with PMUv3 configured. */ > static void create_vpmu_vm(void *guest_code) > { > - struct kvm_vcpu_init init; > - uint8_t pmuver, ec; > - uint64_t dfr0, irq =3D 23; > - struct kvm_device_attr irq_attr =3D { > - .group =3D KVM_ARM_VCPU_PMU_V3_CTRL, > - .attr =3D KVM_ARM_VCPU_PMU_V3_IRQ, > - .addr =3D (uint64_t)&irq, > - }; > - struct kvm_device_attr init_attr =3D { > - .group =3D KVM_ARM_VCPU_PMU_V3_CTRL, > - .attr =3D KVM_ARM_VCPU_PMU_V3_INIT, > - }; > + uint8_t ec; > + uint64_t irq =3D 23; > > /* The test creates the vpmu_vm multiple times. Ensure a clean st= ate */ > memset(&vpmu_vm, 0, sizeof(vpmu_vm)); > @@ -430,26 +421,15 @@ static void create_vpmu_vm(void *guest_code) > guest_sync_handler); > } > > - /* Create vCPU with PMUv3 */ > - vm_ioctl(vpmu_vm.vm, KVM_ARM_PREFERRED_TARGET, &init); > - init.features[0] |=3D (1 << KVM_ARM_VCPU_PMU_V3); > - vpmu_vm.vcpu =3D aarch64_vcpu_add(vpmu_vm.vm, 0, &init, guest_cod= e); > + vpmu_vm.vcpu =3D vm_vcpu_add_with_vpmu(vpmu_vm.vm, 0, guest_code)= ; > vcpu_init_descriptor_tables(vpmu_vm.vcpu); > vpmu_vm.gic_fd =3D vgic_v3_setup(vpmu_vm.vm, 1, 64); > __TEST_REQUIRE(vpmu_vm.gic_fd >=3D 0, > "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); > - pmuver =3D FIELD_GET(ARM64_FEATURE_MASK(ID_AA64DFR0_EL1_PMUVer), = dfr0); > - TEST_ASSERT(pmuver !=3D ID_AA64DFR0_EL1_PMUVer_IMP_DEF && > - pmuver >=3D ID_AA64DFR0_EL1_PMUVer_IMP, > - "Unexpected PMUVER (0x%x) on the vCPU with PMUv3", pm= uver); > - > /* Initialize vPMU */ > - vcpu_ioctl(vpmu_vm.vcpu, KVM_SET_DEVICE_ATTR, &irq_attr); > - vcpu_ioctl(vpmu_vm.vcpu, KVM_SET_DEVICE_ATTR, &init_attr); > + vpmu_set_irq(vpmu_vm.vcpu, irq); > + vpmu_init(vpmu_vm.vcpu); > } > > static void destroy_vpmu_vm(void) > diff --git a/tools/testing/selftests/kvm/include/aarch64/vpmu.h b/tools/t= esting/selftests/kvm/include/aarch64/vpmu.h > new file mode 100644 > index 000000000000..5ef6cb011e41 > --- /dev/null > +++ b/tools/testing/selftests/kvm/include/aarch64/vpmu.h > @@ -0,0 +1,28 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > + > +#include > + > +static inline struct kvm_vcpu *vm_vcpu_add_with_vpmu(struct kvm_vm *vm, > + uint32_t vcpu_id, > + void *guest_code) > +{ > + struct kvm_vcpu_init init; > + > + /* Create vCPU with PMUv3 */ > + vm_ioctl(vm, KVM_ARM_PREFERRED_TARGET, &init); > + init.features[0] |=3D (1 << KVM_ARM_VCPU_PMU_V3); > + > + return aarch64_vcpu_add(vm, 0, &init, guest_code); > +} > + > +static void vpmu_set_irq(struct kvm_vcpu *vcpu, int irq) > +{ > + kvm_device_attr_set(vcpu->fd, KVM_ARM_VCPU_PMU_V3_CTRL, > + KVM_ARM_VCPU_PMU_V3_IRQ, &irq); > +} > + > +static void vpmu_init(struct kvm_vcpu *vcpu) > +{ > + kvm_device_attr_set(vcpu->fd, KVM_ARM_VCPU_PMU_V3_CTRL, > + KVM_ARM_VCPU_PMU_V3_INIT, NULL); > +} > -- > 2.40.1 > > Reviewed-by: Raghavendra Rao Ananta - Raghavendra