Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp3300766rdg; Tue, 17 Oct 2023 10:11:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHoaOYS1YaJlvGmSNTn+26pv4q4A6DExhGTejPZw+5Ziv4TpLmANesFCTiEo2j6H1mwghdV X-Received: by 2002:a05:6a20:8628:b0:163:a041:336c with SMTP id l40-20020a056a20862800b00163a041336cmr2226077pze.48.1697562693057; Tue, 17 Oct 2023 10:11:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697562693; cv=none; d=google.com; s=arc-20160816; b=KySelFB4uuKkZsL+iQDLD+v/bc/xi6Ib7q1Y0NGBU1/1nfBlU6/H7nYVP9ltwSo7qH A6tt/CHf/PFXClOafZEn/G6DrQbgoI5RQyZNhZ+D/FdBdzslYisujBXmtONhoZ+5uT7u P136LtPGavB3z0eE636k9k1F9E0pMljGPT0q+pmxM9RjY70lmGqvsdeHGNzlwAAGZa04 9pp8y5V4+mK1lEXg3CxEEVlBzwtyy/Zp6B9a/Lgnv7v7Vn4Dx+K/zwozRyXmjmp2y32b Tk3+LjVjgBm0pQvB6yIxfw1hko6uf6QZkoP/wRAL9AiPGQ3VH4ZViOfBJcBiK+d/sE/7 m3IA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=GYRiu9lSScYzjuPNTRfPjUaha4Cty0VP8HNHJXHNDls=; fh=Ydzx9+q2LPKW+62Dx8Wwj8Mofu196V11LHOTZ5Nf2xk=; b=JW6pyilHXktRfg50HGFHYQ6VYaubW3Zr8Gt2wLZTevTe00VIYPQQZwDOsbKvJ57t3/ dXbnS25glZVXMeLCXcepjGzuU5RwNk93BSmiX6GzJbcneG9L6zt/Qpc+AJhnaSwvYcxm JfMvnhkOhCsclL6v7DDOlXevWsUPm/Mn8UCWJG79doBtsWFLkI2wr3W3GReT9I31qSyd C6/Urz42M8tsVv1rTZD9DwHPLfzCHwo9L523rq4v0YbOM0m2oPjcZF9fsBlhoYMDX1UO lJDR8CzXRLjkeYE7MQccFamwrKLrnSfq+Vg0WS4iQUdSLusE35431PyC2Ccqu5uWcewo UShA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=fHww+4mv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id bv186-20020a632ec3000000b005b7c7f06e9esi189355pgb.34.2023.10.17.10.11.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 10:11:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=fHww+4mv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 3E0D88076D2C; Tue, 17 Oct 2023 10:11:30 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343848AbjJQRLM (ORCPT + 99 others); Tue, 17 Oct 2023 13:11:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343863AbjJQRLJ (ORCPT ); Tue, 17 Oct 2023 13:11:09 -0400 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BFB8F5 for ; Tue, 17 Oct 2023 10:11:08 -0700 (PDT) Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1c9c145bb5bso7845ad.1 for ; Tue, 17 Oct 2023 10:11:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697562668; x=1698167468; darn=vger.kernel.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=GYRiu9lSScYzjuPNTRfPjUaha4Cty0VP8HNHJXHNDls=; b=fHww+4mvszkXGZWotRCgYzNFytJzmMs6Vw5TBL7j+Zat4huTQMM3qF5lXAXxwT/sdt LPYt0DQDn7Je9yDOXGgVbUldCgwdOb2Hv2xxG8nQpZIuxpvkL4BzUjJN5gf1yQ9Rcp96 HPvYVoDjuC73kLT94+vj5tl7/ZPoahf/j5R2gl/S1X7B73VhRyy/ZiofS/J5m0PGDNb4 nUcrUAXoaxDXFQsHgsp4cITEuChi+YLXi4Po4sQS99bT3VuSK+e/Uejkk7yQV7GgPqlo z0ap8NeNcwoLjN573G4hPxTatQEB/QRzrvUcXpNWcbNkaH7qu5ExpCaTZwG0n4R2f9Gk ynNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697562668; x=1698167468; 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=GYRiu9lSScYzjuPNTRfPjUaha4Cty0VP8HNHJXHNDls=; b=bQnZ0ABJqSZciU1NwZr09Vtykjk7Fi9GOOUYjTyGhW6pIkIRPRWaJiI0yIDsw7Nne5 Pohx+p2C35WgBUF2+md8UNSKWro7mpkFy00rdD/xotQaJCIXYuDIOi0UHvYfLPqO5LkE Laxgf9QS0Vri9Q5A6XiXCNULqIk4Azy20T75izBCA8YhngDKv2R/BnZ0XQNmsmBUs06X 43TyQSqI+171gU0vhvvvXuk5n0YkBB8DaxhuMEGXFaGFJhtX/nudZ4YQNj3oGVmMJpX5 8QCNiSNJZv04tId+Xlt254wiYPJqsbN+xhx6X1mM34SQpSNee3RAYbLfZhyj/DK6nth7 sG1A== X-Gm-Message-State: AOJu0YzkZUR3Y2jZtPVi5kVeHbizs3ZOIciZg/vmCG/TJWKNVWrm5XVC fYLbEhRgidAHlFiMRxZRDaWHhCogKmkrQnqPeZFZ6w== X-Received: by 2002:a17:902:6b47:b0:1c9:d7d8:862c with SMTP id g7-20020a1709026b4700b001c9d7d8862cmr17098plt.10.1697562667428; Tue, 17 Oct 2023 10:11:07 -0700 (PDT) MIME-Version: 1.0 References: <20231009230858.3444834-1-rananta@google.com> <20231009230858.3444834-11-rananta@google.com> In-Reply-To: From: Raghavendra Rao Ananta Date: Tue, 17 Oct 2023 10:10:55 -0700 Message-ID: Subject: Re: [PATCH v7 10/12] KVM: selftests: aarch64: Introduce vpmu_counter_access test To: Sebastian Ott Cc: Oliver Upton , Marc Zyngier , Alexandru Elisei , James Morse , Suzuki K Poulose , Paolo Bonzini , Zenghui Yu , Shaoqin Huang , Jing Zhang , Reiji Watanabe , Colton Lewis , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Tue, 17 Oct 2023 10:11:30 -0700 (PDT) On Tue, Oct 17, 2023 at 8:48=E2=80=AFAM Sebastian Ott w= rote: > > On Mon, 9 Oct 2023, Raghavendra Rao Ananta wrote: > > +static void guest_code(uint64_t expected_pmcr_n) > > +{ > > + uint64_t pmcr, pmcr_n; > > + > > + __GUEST_ASSERT(expected_pmcr_n <=3D ARMV8_PMU_MAX_GENERAL_COUNTER= S, > > + "Expected PMCR.N: 0x%lx; ARMv8 general counters: = 0x%lx", > > + expected_pmcr_n, ARMV8_PMU_MAX_GENERAL_COUNTERS); > > + > > + pmcr =3D read_sysreg(pmcr_el0); > > + pmcr_n =3D get_pmcr_n(pmcr); > > + > > + /* Make sure that PMCR_EL0.N indicates the value userspace set */ > > + __GUEST_ASSERT(pmcr_n =3D=3D expected_pmcr_n, > > + "Expected PMCR.N: 0x%lx, PMCR.N: 0x%lx", > > + pmcr_n, expected_pmcr_n); > > Expected vs read value is swapped. > Good catch! I'll fix this in v8. > > Also, since the kernel has special handling for this, should we add a > test like below? > > +static void immutable_test(void) > +{ > + struct kvm_vcpu *vcpu; > + uint64_t sp, pmcr, pmcr_n; > + struct kvm_vcpu_init init; > + > + create_vpmu_vm(guest_code); > + > + vcpu =3D vpmu_vm.vcpu; > + > + /* Save the initial sp to restore them later to run the guest aga= in */ > + vcpu_get_reg(vcpu, ARM64_CORE_REG(sp_el1), &sp); > + > + vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_PMCR_EL0), &pmcr); > + pmcr_n =3D get_pmcr_n(pmcr); > + > + run_vcpu(vcpu, pmcr_n); > + > + vm_ioctl(vpmu_vm.vm, KVM_ARM_PREFERRED_TARGET, &init); > + init.features[0] |=3D (1 << KVM_ARM_VCPU_PMU_V3); > + aarch64_vcpu_setup(vcpu, &init); > + vcpu_init_descriptor_tables(vcpu); > + vcpu_set_reg(vcpu, ARM64_CORE_REG(sp_el1), sp); > + vcpu_set_reg(vcpu, ARM64_CORE_REG(regs.pc), (uint64_t)guest_code)= ; > + > + /* Update the PMCR_EL0.N after the VM ran once */ > + set_pmcr_n(&pmcr, 0); > + vcpu_set_reg(vcpu, KVM_ARM64_SYS_REG(SYS_PMCR_EL0), pmcr); > + > + /* Verify that the guest still gets the unmodified value */ > + run_vcpu(vcpu, pmcr_n); > + > + destroy_vpmu_vm(); > +} Thanks for the suggestion! I'll add this test case in v8. - Raghavendra >