From patchwork Sat Sep 21 10:08:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Raphael Tiovalen X-Patchwork-Id: 1988128 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=Bn21LdjB; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=ee1qvxd4; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X9lgk1458z1y36 for ; Sat, 21 Sep 2024 20:22:42 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=5BBtXAMdqp42iyyb36P+Ddr9NZhw8he7vTcNIloSAU4=; b=Bn21LdjB00/PQf GQ9TnfhJkgJ4GEOQEpCHeTs7sINM+mk0R8B4SOqhSJ39mmPC/OC7yiFk4gA1lMFmpOFgOdgzZiKiQ wNF7M+x40etXhb7XqireXcijeQDcXzZZpx5KRI3v0gByBDWwsHCPsXNeufqk2VcS5rAkI7JZL3cV0 AVECeqTMXU7qLfp3GDeA2gcT5gNkhroCd7emfCCkuTteYuKPbGd9k3IfHmsH4KWCA5+9cPB6Z9zci ibVJGwDpPQieyfMoSiNtx+VCbZdlZd2FEGPPnx2RiY+xFaeGItn8XYlFh7PdxRzwPEcaj8ewYQcGx +I1b9pVjeApfDIr/ax/A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1srxGC-0000000Dbpc-3QBi; Sat, 21 Sep 2024 10:22:40 +0000 Received: from mail-pg1-x531.google.com ([2607:f8b0:4864:20::531]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1srx2c-0000000DaUE-1Rfk for kvm-riscv@lists.infradead.org; Sat, 21 Sep 2024 10:08:39 +0000 Received: by mail-pg1-x531.google.com with SMTP id 41be03b00d2f7-7db90a28cf6so1539176a12.0 for ; Sat, 21 Sep 2024 03:08:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726913317; x=1727518117; darn=lists.infradead.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=UJdVfx/CtG7GsoMRDoYaQc5sG4VZUAB77/RAuJ5eHsk=; b=ee1qvxd4w/L4+67+mYVy7tURiSV+yjXqd654jVkq2eKeh8YEwuWuohcPTI1IdABf4X ArPW9ml1jcDjAAaM+7/nA76LGOxiRygo2QtCoCW3RSBKQWWW0/mDuGTeGA8MFo0fLI1B 9NXV0pW/scJZbKNJH8QVa9stUGgNygpFDKtAKhCASKecWK4VAjp6vrmBq5GnRwdDr/nc JlOz+iPg9cjHm4pYfkf0b2eBUmWilbDvoAigcSOTu1DV1QOJ+BU/Td7KE200mc2Bd7/0 zZz7MT8VuuyL4xeSwg0EhQlVNrh9mR2YHcI3HzBFDaeTCNwgzOa5NJWQhpHtsNo0CY5b NLbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726913317; x=1727518117; 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=UJdVfx/CtG7GsoMRDoYaQc5sG4VZUAB77/RAuJ5eHsk=; b=MpbvF9PdT/PcO0K8gKQ4qDjbs1Vm6xRhB3KBochjvPUMXOFxp6g75UrM1dQivmlfqV 1H20ahGrqlxd1o+Po5D9IUAgKMtwYn3nKQY6URzF3L7MEY07ItPqZ/HGyZRuA4pmPvNn HmLqwu8Adsdlxk4BHjkFgDaZJhzwWLuxaIJTBhoweNzYEb0GEesYCErr414Pny94W7iD 1v/iVpNz5zg4dTiJ7E9e2Pf2RNi2V3ksAJwcMVPPTxfwKoLP0ad0s2RYoC2QxPFos9o0 ET5ZmdLYuIjuTQ5Dq+fybmy8oXYXieTD+lJOWZgItPsJB16lKPePLAdekT/NxGcVNyph G27A== X-Forwarded-Encrypted: i=1; AJvYcCUfUcgircTqa1Dgxx6tF5xvhJ7lrxkKGTdFmL+viTcfa5kiKKQ6tOE5/k46pqG0VPI1VYF5xgmO4BU=@lists.infradead.org X-Gm-Message-State: AOJu0Yw3uCiVzYraUHWzTP+0qlK4gEPOkTVeEDY+1x/XF72F2wIy64e4 ul92B9TOxNNOgS+NXsqClaTyf/ZnV3Le1CA6576MBQ+xPmcMr41s X-Google-Smtp-Source: AGHT+IFtu3T1HLYQLvnDw2+j7zkRNFc+AqSVwVetbu/CGynIPlNRQSNPqI6+AkVybKDGMUU1fCsCZA== X-Received: by 2002:a17:90b:1286:b0:2d8:7a63:f9c8 with SMTP id 98e67ed59e1d1-2dd6ce9b501mr14726309a91.14.1726913317187; Sat, 21 Sep 2024 03:08:37 -0700 (PDT) Received: from JRT-PC.. ([203.116.176.98]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2dd6ee7c03fsm5680024a91.11.2024.09.21.03.08.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Sep 2024 03:08:36 -0700 (PDT) From: James Raphael Tiovalen To: kvm@vger.kernel.org, kvm-riscv@lists.infradead.org Cc: andrew.jones@linux.dev, atishp@rivosinc.com, cade.richard@berkeley.edu, James Raphael Tiovalen Subject: [kvm-unit-tests PATCH v5 2/5] riscv: sbi: Provide entry point for HSM tests Date: Sat, 21 Sep 2024 18:08:20 +0800 Message-ID: <20240921100824.151761-3-jamestiotio@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240921100824.151761-1-jamestiotio@gmail.com> References: <20240921100824.151761-1-jamestiotio@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240921_030838_412870_A79F076D X-CRM114-Status: GOOD ( 17.84 ) X-Spam-Score: -2.1 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: The HSM tests will need to test HSM start and resumption from HSM suspend. Provide an entry point written in assembly that doesn't use a stack for this. Results of the test are written to global per-h [...] Content analysis details: (-2.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:531 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [jamestiotio(at)gmail.com] X-BeenThere: kvm-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "kvm-riscv" Errors-To: kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org The HSM tests will need to test HSM start and resumption from HSM suspend. Provide an entry point written in assembly that doesn't use a stack for this. Results of the test are written to global per-hart arrays to be checked by the main SBI HSM test function. The started/resumed hart does its checks and then just loops until it gets a signal from the main SBI HSM test function to invoke HSM stop. Signed-off-by: James Raphael Tiovalen Co-developed-by: Andrew Jones Signed-off-by: Andrew Jones --- riscv/Makefile | 3 +- riscv/sbi-tests.h | 10 +++++++ riscv/sbi-asm.S | 71 +++++++++++++++++++++++++++++++++++++++++++++++ riscv/sbi.c | 5 ++++ 4 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 riscv/sbi-tests.h create mode 100644 riscv/sbi-asm.S diff --git a/riscv/Makefile b/riscv/Makefile index 2ee7c5bb..4676d262 100644 --- a/riscv/Makefile +++ b/riscv/Makefile @@ -43,6 +43,7 @@ cflatobjs += lib/riscv/timer.o ifeq ($(ARCH),riscv32) cflatobjs += lib/ldiv32.o endif +cflatobjs += riscv/sbi-asm.o ######################################## @@ -80,7 +81,7 @@ CFLAGS += -mcmodel=medany CFLAGS += -std=gnu99 CFLAGS += -ffreestanding CFLAGS += -O2 -CFLAGS += -I $(SRCDIR)/lib -I $(SRCDIR)/lib/libfdt -I lib +CFLAGS += -I $(SRCDIR)/lib -I $(SRCDIR)/lib/libfdt -I lib -I $(SRCDIR)/riscv asm-offsets = lib/riscv/asm-offsets.h include $(SRCDIR)/scripts/asm-offsets.mak diff --git a/riscv/sbi-tests.h b/riscv/sbi-tests.h new file mode 100644 index 00000000..f5cc8635 --- /dev/null +++ b/riscv/sbi-tests.h @@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _RISCV_SBI_TESTS_H_ +#define _RISCV_SBI_TESTS_H_ + +#define SBI_HSM_TEST_DONE (1 << 0) +#define SBI_HSM_TEST_HARTID_A1 (1 << 1) +#define SBI_HSM_TEST_SATP (1 << 2) +#define SBI_HSM_TEST_SIE (1 << 3) + +#endif /* _RISCV_SBI_TESTS_H_ */ diff --git a/riscv/sbi-asm.S b/riscv/sbi-asm.S new file mode 100644 index 00000000..f165f9da --- /dev/null +++ b/riscv/sbi-asm.S @@ -0,0 +1,71 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Helper assembly code routines for RISC-V SBI extension tests. + * + * Copyright (C) 2024, James Raphael Tiovalen + */ +#define __ASSEMBLY__ +#include + +#include "sbi-tests.h" + +.section .text + +/* + * sbi_hsm_check + * a0 and a1 are set by SBI HSM start/suspend + * s1 is the address of the results array + * Doesn't return. + * + * This function is only called from HSM start and on resumption + * from HSM suspend which means we can do whatever we like with + * all registers. So, to avoid complicated register agreements with + * other assembly functions called, we just always use the saved + * registers for anything that should be maintained across calls. + */ +#define RESULTS_ARRAY s1 +#define RESULTS_MAP s2 +#define CPU_INDEX s3 +.balign 4 +sbi_hsm_check: + li RESULTS_MAP, 0 + bne a0, a1, 1f + ori RESULTS_MAP, RESULTS_MAP, SBI_HSM_TEST_HARTID_A1 +1: csrr t0, CSR_SATP + bnez t0, 2f + ori RESULTS_MAP, RESULTS_MAP, SBI_HSM_TEST_SATP +2: csrr t0, CSR_SSTATUS + andi t0, t0, SR_SIE + bnez t0, 3f + ori RESULTS_MAP, RESULTS_MAP, SBI_HSM_TEST_SIE +3: call hartid_to_cpu + mv CPU_INDEX, a0 + li t0, -1 + bne CPU_INDEX, t0, 5f +4: pause + j 4b +5: ori RESULTS_MAP, RESULTS_MAP, SBI_HSM_TEST_DONE + add t0, RESULTS_ARRAY, CPU_INDEX + sb RESULTS_MAP, 0(t0) + la t1, sbi_hsm_stop_hart + add t1, t1, CPU_INDEX +6: lb t0, 0(t1) + pause + beqz t0, 6b + li a7, 0x48534d /* SBI_EXT_HSM */ + li a6, 1 /* SBI_EXT_HSM_HART_STOP */ + ecall +7: pause + j 7b + +.balign 4 +.global sbi_hsm_check_hart_start +sbi_hsm_check_hart_start: + la RESULTS_ARRAY, sbi_hsm_hart_start_checks + j sbi_hsm_check + +.balign 4 +.global sbi_hsm_check_non_retentive_suspend +sbi_hsm_check_non_retentive_suspend: + la RESULTS_ARRAY, sbi_hsm_non_retentive_hart_suspend_checks + j sbi_hsm_check diff --git a/riscv/sbi.c b/riscv/sbi.c index a7abc08c..b5147dee 100644 --- a/riscv/sbi.c +++ b/riscv/sbi.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -429,6 +430,10 @@ static void check_dbcn(void) report_prefix_popn(2); } +unsigned char sbi_hsm_stop_hart[NR_CPUS]; +unsigned char sbi_hsm_hart_start_checks[NR_CPUS]; +unsigned char sbi_hsm_non_retentive_hart_suspend_checks[NR_CPUS]; + int main(int argc, char **argv) { if (argc > 1 && !strcmp(argv[1], "-h")) {