Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1825030lqe; Tue, 9 Apr 2024 01:04:12 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVoa6H6tlThdHDIEXxL21D0xnMo23wga2yhraoR7EYLbxIwirm7HmO+y/t1LI1fyNQJjVMxnw0wFn/cuyd40Y3lo6EKu0SgkHi8lMCl3w== X-Google-Smtp-Source: AGHT+IEWjoUUqNFxrW6xVJmOBm2LsR8RXjH/0xjBXxdn6G4OVH8OnWMcbZMP/Ar90Nca8wo22mE/ X-Received: by 2002:a17:902:d182:b0:1e0:1a1f:5e4 with SMTP id m2-20020a170902d18200b001e01a1f05e4mr8846724plb.55.1712649852341; Tue, 09 Apr 2024 01:04:12 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712649852; cv=pass; d=google.com; s=arc-20160816; b=TTjGRkAHKe30jxS3f0twdHA07lvH3giI1OhApHW5UypqXr9jEw9fv/JzxdaqYeIBeK TiCs9hRkZAKRyQDMxbQbWVJwK1tbmZZR/rcD8eckTulA2oGMlslZ2bXcWbMTAtcHa1i5 AxzuTBsXEro9DZ35Ysy9mEECKUTD5mH45jiAct9uBZGIA6KGTOCD2LcDV6PH6sAs1XHM aR4Dp+Amy3Vuewem9U0YsUG0PasFnzINLEA/uDFh+KMB6keKEDSVr1Eggxhdf9pkMiB/ fucHc8fxgMaKN1VXTqU1mXmum5x4GPJWOYGxIA6CAeDYrlbcinVxPv472wRBqCk/VKbf sHnw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=hCIVc0ToTPxKSHwFH39eeFiQ4Iaybjud05qpLdkE0so=; fh=gaKXNLThCBu7XqEF+OIYsPuGXO9AUGCWBxjHRzZNzhM=; b=m8CcrewMlvUsxhpLSueReK9y7Le6Ta1OnnBM88GmCPT3hAGarsAnbhuoMaXvSgKMCK uMNUOgUTfeVz6xYFCGTZVuJqjmDw4/PC1/+xRkhWqOaDiThn0rs9qHvuesdrnt25GyfA AG8AUFUboyLUV6iFvwy7uortov1OvAacI1KLlZNIK77rgQagoyTaQez31N3X5/B6wrSY ZctYP78D+2liPLksg4vuM9599SFtArbKxgBFGKEpT367KrfFWLSFuQ7jrPwER2C2RmPV aU8WyzLkam9U9vfMOvkd76TEqvn96S2ybbmL7iw/MnSiqxCpPmfiGKu4dpfCwOehvc05 upZg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=bDvmIuLJ; arc=pass (i=1 spf=pass spfdomain=ventanamicro.com dkim=pass dkdomain=ventanamicro.com); spf=pass (google.com: domain of linux-kernel+bounces-136406-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-136406-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id z16-20020a170902d55000b001e2c6dcbf62si127626plf.215.2024.04.09.01.04.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 01:04:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-136406-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=bDvmIuLJ; arc=pass (i=1 spf=pass spfdomain=ventanamicro.com dkim=pass dkdomain=ventanamicro.com); spf=pass (google.com: domain of linux-kernel+bounces-136406-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-136406-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 12D38B225F5 for ; Tue, 9 Apr 2024 08:02:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EA0A07E10B; Tue, 9 Apr 2024 08:01:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="bDvmIuLJ" Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) (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 1B7876A031 for ; Tue, 9 Apr 2024 08:01:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712649714; cv=none; b=m//Q+35XzDEA+0byVTreqhjL33GJjDPxFGPdl0UC6Cm330iNV1ksjKlgQEdncCuLajBHnoAD/FfYANEpO2FLdEXpO+YdzrWdMTw94RuJ/ysGp+GRPfGaVs//QJsVZEccEDYCQN79k0fXo9Ixd7shnqxDdvFflPIr8utvt2cvHNk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712649714; c=relaxed/simple; bh=bMz8MjfIFsUyXV5WBM+KwspP/jmIVlkv1FepIQu2Qp4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ZONJl7yn+FMyG6FZMq4/l/HDLLYxEgY51AKpd+tVcK87mc9mz/gFRx0/pn1PQaR7T71O2hvA0b1i+LTJNFDzgq3zMjVzfCQ5pip5fy1T8fGEha0Q6xkDbTiEPYJcP95bXblN1jA9Zi16hbDBdVHMJd5nPqjOXgv14iG/36YyKOk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=bDvmIuLJ; arc=none smtp.client-ip=209.85.218.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-a51e452a1ceso124851966b.0 for ; Tue, 09 Apr 2024 01:01:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1712649710; x=1713254510; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=hCIVc0ToTPxKSHwFH39eeFiQ4Iaybjud05qpLdkE0so=; b=bDvmIuLJoYJqpdDTSPlonpFWZ014QS2fVczgt/f+ynUjQb2JujJWKWF12nHXlha+3H +zywUUlMWJ0TajJEgqBtUVF/t+zW5EWW5A2nOf8wmwsPZHnrmHYaq1K8/ACLGAqIDc71 blYJwT13++VKoz638Dp1c+9PUBEt/DbD3l/ziA/nFGyX9/UU857ifGmcMTJg52CzW9WL R7PLZOBpEHMcWLXHynqP1d1uqMvNS37Fk8loTmXGwMKJHxUNq3M6yqpL7v4Oe4GodW9U gGIcw+qmWANNzonmrTZPY4zZyk3H52XleZAkKfVOmthbobOBh/vzHuRl2tQQhG20Ohdx 7HVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712649710; x=1713254510; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=hCIVc0ToTPxKSHwFH39eeFiQ4Iaybjud05qpLdkE0so=; b=wFiPyYM9Xpd9A7Ojz8WMeHog8UQBVcKcUNpgIjiUUarNmCCvkJY1LuJ3xk5T5IcSnh bGdNcvhQ5FWHye9jxPr6JxV1BgEph/eyJUOijLW5Oh88mzArQVQnM+cBtttNfDZHc+3q TeotR6uwGlpQRYPnMYhbymAErb1zQ9yIlwY9ZTtRh59V2SfKrQWCgehYnZOxqPDbG7sX ORLQucL8zfogGlsWNxmxO4eJyfWfKThhVWeUpIHsIDlGuYlwz75W/YV2hv/Yg1ZMyD02 AKcKgopu/iWv5Xxa/09IsY2nQ5uwLpz4U7v3Gr7ZybJViJ5uZ2EHi1yIw0KlrOfDmQAh WR9Q== X-Gm-Message-State: AOJu0YwpjMhRAUgeRKAJKrd8TcS5EeAg4quGYZeTecHQnL23PwFXQKll xtJWMa0rItlVMliiuvXDHohKc6twALumiS2yMKaT1vxvp0+oEPa1zhsdBK0T6Rk= X-Received: by 2002:a17:906:c454:b0:a4d:f5e6:2e34 with SMTP id ck20-20020a170906c45400b00a4df5e62e34mr6793646ejb.19.1712649710207; Tue, 09 Apr 2024 01:01:50 -0700 (PDT) Received: from localhost (2001-1ae9-1c2-4c00-20f-c6b4-1e57-7965.ip6.tmcz.cz. [2001:1ae9:1c2:4c00:20f:c6b4:1e57:7965]) by smtp.gmail.com with ESMTPSA id xh13-20020a170906da8d00b00a51c0c0cb86sm3775778ejb.22.2024.04.09.01.01.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 01:01:49 -0700 (PDT) Date: Tue, 9 Apr 2024 10:01:48 +0200 From: Andrew Jones To: Atish Patra 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 Subject: Re: [PATCH v5 20/22] KVM: riscv: selftests: Add SBI PMU selftest Message-ID: <20240409-dd055c3d08e027cf2a5cb4dc@orel> References: <20240403080452.1007601-1-atishp@rivosinc.com> <20240403080452.1007601-21-atishp@rivosinc.com> <20240405-d1a4cb9a441a05a9d2f8b1c8@orel> <976411ab-6ddf-4b10-8e13-1575928415ce@rivosinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <976411ab-6ddf-4b10-8e13-1575928415ce@rivosinc.com> 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 = 0; > > > + bool probe; > > > + struct sbiret ret; > > > + int num_counters = 0, i; > > > + union sbi_pmu_ctr_info ctrinfo; > > > + > > > + probe = guest_sbi_probe_extension(SBI_EXT_PMU, &out_val); > > > + GUEST_ASSERT(probe && out_val == 1); > > > + > > > + num_counters = get_num_counters(); > > > + > > > + for (i = 0; i < num_counters; i++) { > > > + ret = sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_GET_INFO, 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 = 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 = 0; > > > + kvm_vm_free(vm); > > > +} > > > + > > > +static void test_vm_basic_test(void *guest_code) > > > +{ > > > + struct kvm_vm *vm; > > > + struct kvm_vcpu *vcpu; > > > + > > > + vm = 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 record > > that it had to handle anything. > > > > The objective of the test is to ensure that we get an illegal instruction > 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 if 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. > > The verify part is that the test doesn't end up in a illegal instruction > 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 = NULL; > > > + struct kvm_vcpu *vcpu = NULL; > > > + > > > + vm = 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 >