From patchwork Tue Apr 16 18:44:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 13632334 Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.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 8F2DC13D286 for ; Tue, 16 Apr 2024 18:45:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713293108; cv=none; b=a2LKKVv8TJaE+HL6pbxsvMtbZ+cq/MCAoB2NFz9warleiJt1duYG5bMIpvNw+RtilMDy0kU5M7SSPKPlvJih6GRmNjUCJ5FsrPhPTiCyUG/NT9wSm7C1w2IJG3QSt8+MUta4NWh8UfRn3fQwNiaqFxnwSeqBktwiBi40boz4ef0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713293108; c=relaxed/simple; bh=RcVsdOTpWmQDe3QFQB057eZKtxuHNPDvA9mLhc2A9Tw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=uRUN4vpjeW6/CUdBWboAtu0jjjt9OB9SUdqoJdSg3hPxqXSGqM2eI4RT4qfyG9IQRvUFcrTW3hdO2uOBuE1nj730B5SKptjllMYjuppmsPp9/WIe5/LmIUOH582NHNVRGfZo2oS4H5iyUchuEjvDRWZWN4H6ur6MMq/HWFK6FYM= 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=snwywB6x; arc=none smtp.client-ip=209.85.216.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 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="snwywB6x" Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-2a2d0ca3c92so47625a91.0 for ; Tue, 16 Apr 2024 11:45:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1713293107; x=1713897907; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vBWeKaYtpXhvKjSg+whNN/rWnhjngNSIx7A/W77I8WQ=; b=snwywB6x/3UYo6Sz2k/vaH6cYHfVblxy4eiN9A0CLwoitN8wmbLafPdvyXRVGVeQhk Hyz2dcCSctc8pwk6cfhBRob2ORmU1ApcAnc3i7La9eX5UlOKIRvCbxx9dbAVzFYIH18h mAWJRhZMYBgsf4EyPk+SFCql4ReGh5bcZ4RhEZwh2ZK4PcknxW5VTi4e21BDzIRluQvv 84dG0jZLcUonrVg4FSLe524JTsE6/FzHUMsVfKEg/S1VvEE7ue+qSxtBmeWmjd7rtJSi x7A4d1rlJPNz+2mIJ0Dn3Rs+PU4U9hra6wjYUjin2gZVBnkPMSb/tDH035uJXu3qMdig Okqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713293107; x=1713897907; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vBWeKaYtpXhvKjSg+whNN/rWnhjngNSIx7A/W77I8WQ=; b=MxmryDuGBo6UVx1xOV0tTVNkejJ317oAcGVUiIqa0YksZVetjyh/d/FoRSWaUDgm5b o3BBp2+861vV4FyEB/0qhXEbb4kzU3aekwGqm3DggwCL+Brfq3ZG/mCfqDJeBO9gCEV1 1aE3rqIRJ/AX7QuMRtOLTpFdsmmR+sXEo95w1dU7K7/RjSK3KYoocamBXXJ5NJc6Zcd8 g+li1A0gGRsCZLud97YUSYJOk0I+42UkAqrAm/ek+fL6+NTEyuNYmG8kbyQMC2KBbxjz BjAgZqXIqYazf/BozbxPYHQ3HUh0Jm97ZjhnnMw5SxQD4YOqtchxD0kcCkr83S7w0l75 1mOg== X-Forwarded-Encrypted: i=1; AJvYcCWA3dKWaqEJG2x9eXFOALWcR3FQUDrZ1LGMuNCtvfSzg6S7WCD6Fek6766s/b5L3maEBltO5/AsjDHZYpSlWWboDTIk X-Gm-Message-State: AOJu0Yzr9sKGVEmiMWxah4amwaGHcuvRCYnWdii1wodJORjihxCFwoDo cWxWtQ/Ps5b0q3KU18Enm+GT58E/huf7Xz+Aay+4scWesdfpf9yHS/16eWvoH/4= X-Google-Smtp-Source: AGHT+IEmOJnsCqKgMiSjK9JvIG/qr/zmtZv2INOC30OQkmamLtid+925iE6tPmkwso7m5t8fIgxSaw== X-Received: by 2002:a17:90a:bc1:b0:2a1:64a:bb63 with SMTP id x1-20020a17090a0bc100b002a1064abb63mr4135416pjd.2.1713293106909; Tue, 16 Apr 2024 11:45:06 -0700 (PDT) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id o19-20020a17090aac1300b002a269828bb8sm8883645pjq.40.2024.04.16.11.45.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 11:45:06 -0700 (PDT) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Andrew Jones , Ajay Kaher , Albert Ou , Alexandre Ghiti , Anup Patel , 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, Will Deacon , x86@kernel.org Subject: [PATCH v7 18/24] KVM: riscv: selftests: Add helper functions for extension checks Date: Tue, 16 Apr 2024 11:44:15 -0700 Message-Id: <20240416184421.3693802-19-atishp@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240416184421.3693802-1-atishp@rivosinc.com> References: <20240416184421.3693802-1-atishp@rivosinc.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 __vcpu_has_ext can check both SBI and ISA extensions when the first argument is properly converted to SBI/ISA extension IDs. Introduce two helper functions to make life easier for developers so they don't have to worry about the conversions. Replace the current usages as well with new helpers. Reviewed-by: Andrew Jones Signed-off-by: Atish Patra --- tools/testing/selftests/kvm/include/riscv/processor.h | 10 ++++++++++ tools/testing/selftests/kvm/riscv/arch_timer.c | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/kvm/include/riscv/processor.h b/tools/testing/selftests/kvm/include/riscv/processor.h index 3b9cb39327ff..5f389166338c 100644 --- a/tools/testing/selftests/kvm/include/riscv/processor.h +++ b/tools/testing/selftests/kvm/include/riscv/processor.h @@ -50,6 +50,16 @@ static inline uint64_t __kvm_reg_id(uint64_t type, uint64_t subtype, bool __vcpu_has_ext(struct kvm_vcpu *vcpu, uint64_t ext); +static inline bool __vcpu_has_isa_ext(struct kvm_vcpu *vcpu, uint64_t isa_ext) +{ + return __vcpu_has_ext(vcpu, RISCV_ISA_EXT_REG(isa_ext)); +} + +static inline bool __vcpu_has_sbi_ext(struct kvm_vcpu *vcpu, uint64_t sbi_ext) +{ + return __vcpu_has_ext(vcpu, RISCV_SBI_EXT_REG(sbi_ext)); +} + struct ex_regs { unsigned long ra; unsigned long sp; diff --git a/tools/testing/selftests/kvm/riscv/arch_timer.c b/tools/testing/selftests/kvm/riscv/arch_timer.c index 0f9cabd99fd4..735b78569021 100644 --- a/tools/testing/selftests/kvm/riscv/arch_timer.c +++ b/tools/testing/selftests/kvm/riscv/arch_timer.c @@ -85,7 +85,7 @@ struct kvm_vm *test_vm_create(void) int nr_vcpus = test_args.nr_vcpus; vm = vm_create_with_vcpus(nr_vcpus, guest_code, vcpus); - __TEST_REQUIRE(__vcpu_has_ext(vcpus[0], RISCV_ISA_EXT_REG(KVM_RISCV_ISA_EXT_SSTC)), + __TEST_REQUIRE(__vcpu_has_isa_ext(vcpus[0], KVM_RISCV_ISA_EXT_SSTC), "SSTC not available, skipping test\n"); vm_init_vector_tables(vm);