Received: by 2002:ab2:687:0:b0:1f4:6588:b3a7 with SMTP id s7csp75605lqe; Tue, 9 Apr 2024 15:12:04 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUvXt63qI4iIm3eCDigK3ibWuk+QlOo36EsFXXH3kggKFzPXluaYJkarHpXmwJoAWntfzdjfct0oBW4w6epfVRMJyw0xyeJghEFrgHlJg== X-Google-Smtp-Source: AGHT+IHMrqpwMY5c58PYzlChG/UBWo3QFeKFFyhjN9UMTqkvY3/XKsoKzqgUr15Z8gM32T0JJGD0 X-Received: by 2002:a17:903:22d0:b0:1e4:54d1:a159 with SMTP id y16-20020a17090322d000b001e454d1a159mr1020907plg.47.1712700724283; Tue, 09 Apr 2024 15:12:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712700724; cv=pass; d=google.com; s=arc-20160816; b=HzTvk/HN6NeghXjAHWKr3gXAtXkDDXg8o9A3saz6tvIImxSGW+ppj/2eznAi6Mc7Gp rsaueN/nvGHZEv9WiBNYLU82HAGm8m99TaHKFkIcMzqxELhPlVq4fdfv7RDaW6/pjPIH hVEwdn6xuvF3hXIaRhBe0q/K2M0pIjwZ8QW0rfBAy713yJ62u02sw1bJClqcQC/29WU5 28OHbeCIuBvVzOINXIrSOlrlzGl2exToEImd4C3kLoVzTSnovDwW+5fqoZpTweYd4YpQ jGDNy6kTvdeYQLsTsB+xvKO8kpCR1pMXVvWHzaXBKdGTnwuu2pCsZbnW4+tWalBdrpHY Zdcg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=Cl1aEg9ZkKTDAHIndPvHsR0jY5Vb252ppSopDvYPPc0=; fh=7UGrb3v1rJK2pHiZ+fx5JbbeetHQ6CcJ/jeNkqtgDVI=; b=Zg8zlZv1+Nlywi8SAGbeKLSnHWt0w7MBtwmelk56F0rx63wI8COZNG0L76Cqgesbqy 6wGqpD+xnB6Ck8Q3CAkTxJvV7VloqY7K9omDPs7CiBcilzilKNEiM6mi0ORofGIoPFoP YxIRbPe7fWYHcYLuYRPuu5EHB46Z91SIiNn3TbQ2LFJJWJuRIf3C2T1TVN6rDGqZSC9I HSnWlEVAKNxrga92ECkZLJTHbZzODctYtiBVSjl1gHoF7MHfHzzE6VI4XXT57fa2xD0n /KWWXadJVQAJH4MsyPoOsxcb+zoCwsjZNIGsh6R/glNFiqWO1ht5URShs5DrrYf+Nw5F ov6A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=RhnzFJav; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-137659-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-137659-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id i9-20020a170902eb4900b001e0af99fb00si8853802pli.180.2024.04.09.15.12.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 15:12:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-137659-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=RhnzFJav; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-137659-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-137659-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 893F3283F90 for ; Tue, 9 Apr 2024 22:12:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9F1B2158D8C; Tue, 9 Apr 2024 22:11:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="RhnzFJav" Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) (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 90CF2158D71 for ; Tue, 9 Apr 2024 22:11:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712700711; cv=none; b=F+aVx0+FUeuvDf0BRGV9oAEeialJ7dcknGxIvD+3ZLunImGYDoTokmq780c8Li30H4CsVa1UNXk5uCibBJX4U9HbMDToc/imaDsumcA7eEbJsBzCdr0bC/d3zrjzt4OrspoLf840J2EdAuqW9f1D4IhyADqI84IUF+qkR8KNv2g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712700711; c=relaxed/simple; bh=uMpfpNZT/JircILPCLdeo5TrXY5VRv3On2Rb7xVenag=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=kCv/6W06ZJsQce5zROg5hbXjGoNU+K1coiap3/EUj3AmqqlzcQA5Qp9u5eOU2ykDVe4Pxp8WlDOI7kHKA1h0tt1vnvUEkZ/iKEa16WXvdMuqjcGfOXTGCuYdim+0dRLJQiyfUOYhv+23W763fg49RStktzweWF44OImfydSB7Kc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=RhnzFJav; arc=none smtp.client-ip=209.85.167.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-516dc51bb72so4448526e87.1 for ; Tue, 09 Apr 2024 15:11:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1712700707; x=1713305507; 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=Cl1aEg9ZkKTDAHIndPvHsR0jY5Vb252ppSopDvYPPc0=; b=RhnzFJavAW22HzyhcV/Gy4v2dytOK6WXyYGaaavpe4bm1F3DBPuUVWEl9YyJDglq02 hz20n5XkmPKvl64MrlD07li95V5W7X4keJtztYRcKbcZIOYocJG9230XSzaLgKiMPT/m qvwgolJ2761GdbMaRrVRoD0NEfiNqQxXFsle/Wn3P+BSBiPv0smTZfNileY6pKzKwdY8 3TMcJhI+lTjd42dIcPZJ3PMHloCzp0Qt5nT0+g8anlfZvUpvnD+G9PgwlaEHKtc91uXg 6limkaC8xel9vjq9BNB6qVct2X/s+fTSY26SxwXoGXU0+59t1evcss6Xx3+rh39Lz6GI xGxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712700707; x=1713305507; 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=Cl1aEg9ZkKTDAHIndPvHsR0jY5Vb252ppSopDvYPPc0=; b=JOGeUuO11oNMP2jZgEGMp1knngprhnE33dLzdRdD3GZ2DkiJwlEOdjJNv7NzAMo/aa yqV6XLAdBxpJ6kP7bLULwDsmWT4HqGx50NPQngKJjiGS/C/NnVWLTHLBrZx5Cx/W8rox 6JnzQUEWU1Qi6L0NOoRex61qo0wxk2NAKv5pFM7fe+Xm711MsAInybEtWX/v0NAQ+orJ 7z2kuIvd6qRdoZ1Um7dKEC/ngvxY8//zb9N4bzfTqsGnj6qX4DQ/9i4uIgm1Nt/yXCSd WClKgSE5mrDBC3hSbypKFWiMsaTWj/4CQmIBn8prqjzinI0X6WmXtcu2n3DrXnXSBlVH jTyg== X-Gm-Message-State: AOJu0Yxqz6gPE92nwq+8uN3qKg9igY1MxEizhebTHT/JzM5L5wGoLJKP acPmRbM21lOCKhFSsyjZkH/OvDeock+8yAB7YRGG8a8Wex1GaS4+OoJS78CkxnVjNj/DRGOOFfy hjaUtZ0Gf4QAerzsyFzhgkfHnRWx63qS9rkAL8g== X-Received: by 2002:a19:f70b:0:b0:513:b90f:f4dd with SMTP id z11-20020a19f70b000000b00513b90ff4ddmr352775lfe.49.1712700707477; Tue, 09 Apr 2024 15:11:47 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240403080452.1007601-1-atishp@rivosinc.com> <20240403080452.1007601-21-atishp@rivosinc.com> <20240405-d1a4cb9a441a05a9d2f8b1c8@orel> <976411ab-6ddf-4b10-8e13-1575928415ce@rivosinc.com> <20240409-dd055c3d08e027cf2a5cb4dc@orel> In-Reply-To: <20240409-dd055c3d08e027cf2a5cb4dc@orel> From: Atish Kumar Patra Date: Tue, 9 Apr 2024 15:11:36 -0700 Message-ID: Subject: Re: [PATCH v5 20/22] KVM: riscv: selftests: Add SBI PMU selftest To: Andrew Jones Cc: linux-kernel@vger.kernel.org, Anup Patel , Ajay Kaher , Alexandre Ghiti , Alexey Makhalov , Conor Dooley , Juergen Gross , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Palmer Dabbelt , Paolo Bonzini , Paul Walmsley , Shuah Khan , virtualization@lists.linux.dev, VMware PV-Drivers Reviewers , Will Deacon , x86@kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Apr 9, 2024 at 1:01=E2=80=AFAM Andrew Jones wrote: > > On Mon, Apr 08, 2024 at 05:37:19PM -0700, Atish Patra wrote: > > On 4/5/24 05:50, Andrew Jones wrote: > > > On Wed, Apr 03, 2024 at 01:04:49AM -0700, Atish Patra wrote: > > > ... > > > > +static void test_pmu_basic_sanity(void) > > > > +{ > > > > + long out_val =3D 0; > > > > + bool probe; > > > > + struct sbiret ret; > > > > + int num_counters =3D 0, i; > > > > + union sbi_pmu_ctr_info ctrinfo; > > > > + > > > > + probe =3D guest_sbi_probe_extension(SBI_EXT_PMU, &out_val); > > > > + GUEST_ASSERT(probe && out_val =3D=3D 1); > > > > + > > > > + num_counters =3D get_num_counters(); > > > > + > > > > + for (i =3D 0; i < num_counters; i++) { > > > > + ret =3D sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_GET_IN= FO, i, > > > > + 0, 0, 0, 0, 0); > > > > + > > > > + /* There can be gaps in logical counter indicies*/ > > > > + if (ret.error) > > > > + continue; > > > > + GUEST_ASSERT_NE(ret.value, 0); > > > > + > > > > + ctrinfo.value =3D ret.value; > > > > + > > > > + /** > > > > + * Accesibillity check of hardware and read capability of= firmware counters. > > > > > > Accessibility > > > > > > > Fixed it. > > > > > > + * The spec doesn't mandate any initial value. No need to= check any value. > > > > + */ > > > > + read_counter(i, ctrinfo); > > > > + } > > > > + > > > > + GUEST_DONE(); > > > > +} > > > > + > > > > +static void run_vcpu(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: > > > > + case UCALL_SYNC: > > > > + break; > > > > + default: > > > > + TEST_FAIL("Unknown ucall %lu", uc.cmd); > > > > + break; > > > > + } > > > > +} > > > > + > > > > +void test_vm_destroy(struct kvm_vm *vm) > > > > +{ > > > > + memset(ctrinfo_arr, 0, sizeof(union sbi_pmu_ctr_info) * RISCV_MAX= _PMU_COUNTERS); > > > > + counter_mask_available =3D 0; > > > > + kvm_vm_free(vm); > > > > +} > > > > + > > > > +static void test_vm_basic_test(void *guest_code) > > > > +{ > > > > + struct kvm_vm *vm; > > > > + struct kvm_vcpu *vcpu; > > > > + > > > > + vm =3D vm_create_with_one_vcpu(&vcpu, guest_code); > > > > + __TEST_REQUIRE(__vcpu_has_sbi_ext(vcpu, KVM_RISCV_SBI_EXT_PMU), > > > > + "SBI PMU not available, skipping test"= ); > > > > + vm_init_vector_tables(vm); > > > > + /* Illegal instruction handler is required to verify read access = without configuration */ > > > > + vm_install_exception_handler(vm, EXC_INST_ILLEGAL, guest_illegal_= exception_handler); > > > > > > I still don't see where the "verify" part is. The handler doesn't rec= ord > > > that it had to handle anything. > > > > > > > The objective of the test is to ensure that we get an illegal instructi= on > > without configuration. > > This part I guessed. > > > The presence of the registered exception handler is > > sufficient for that. > > This part I disagree with. The handler may not be necessary and not run i= f > we don't get the ILL. Usually when I write tests like these I set a > boolean in the handler and check it after the instruction which should > have sent us there to make sure we did indeed go there. > Ahh I got your point now. That makes sense. Since it was just a sanity test= , I hadn't put the boolean check earlier. But you are correct about bugs in kvm code which wouldn't generate an expected ILL . I have added it. Thanks for the suggestion :) > > > > The verify part is that the test doesn't end up in a illegal instructio= n > > exception when you try to access a counter without configuring. > > > > Let me know if you think we should more verbose comment to explain the > > scenario. > > > > With a boolean the test code will be mostly self documenting, but a short > comment saying why we expect the boolean to be set would be good too. > > Thanks, > drew > > > > > > > + > > > > + vcpu_init_vector_tables(vcpu); > > > > + run_vcpu(vcpu); > > > > + > > > > + test_vm_destroy(vm); > > > > +} > > > > + > > > > +static void test_vm_events_test(void *guest_code) > > > > +{ > > > > + struct kvm_vm *vm =3D NULL; > > > > + struct kvm_vcpu *vcpu =3D NULL; > > > > + > > > > + vm =3D vm_create_with_one_vcpu(&vcpu, guest_code); > > > > + __TEST_REQUIRE(__vcpu_has_sbi_ext(vcpu, KVM_RISCV_SBI_EXT_PMU), > > > > + "SBI PMU not available, skipping test"= ); > > > > + run_vcpu(vcpu); > > > > + > > > > + test_vm_destroy(vm); > > > > +} > > > > + > > > > +int main(void) > > > > +{ > > > > + test_vm_basic_test(test_pmu_basic_sanity); > > > > + pr_info("SBI PMU basic test : PASS\n"); > > > > + > > > > + test_vm_events_test(test_pmu_events); > > > > + pr_info("SBI PMU event verification test : PASS\n"); > > > > + > > > > + return 0; > > > > +} > > > > -- > > > > 2.34.1 > > > > > > > > > > Thanks, > > > drew > >