From patchwork Sun Nov 10 17:16:32 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: 2009264 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=W/OCbDwW; 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=BE6Fstoe; 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 4XmfVh26Bsz1y02 for ; Mon, 11 Nov 2024 04:17:00 +1100 (AEDT) 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=7wagcUV8fcTXXvmAfYGmxQPRTHMcc7TcMoDYvJ1zrsM=; b=W/OCbDwW8BFWEu GBQpJudut49geZ3tStNl8I+n4CEqhJ7aeRhgDphnRiNQkmz3Us9u+99SUOc/M2wjZkaGyUAQTaE+k 2kvgTJ2wqQkTUHEfRittTFHW1CA7XujAq3GR9Y4CqPovwYFq2abquARoR93+HfxO70tKuGsihHLPN Bs3uzKQrRFLuRu0I1QkAv5sNX5LfpaxjeD2HoEIihk/QX8Jbz779xLCf2l8IkTD26aTg3l9wOSMn1 tEydVrEhYQKadJv7P0+gJ+9tyqAw1hboM+gNEYAqNXDskPsq8P8I47q36rvzrcri+F70D2qmaY+XS a71SyP0hoebKerS97N8A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tABYY-0000000FIBX-3wsm; Sun, 10 Nov 2024 17:16:58 +0000 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tABYW-0000000FIAb-1rCb for kvm-riscv@lists.infradead.org; Sun, 10 Nov 2024 17:16:58 +0000 Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-720aa3dbda5so2681544b3a.1 for ; Sun, 10 Nov 2024 09:16:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731259015; x=1731863815; 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=Ds30340H5u/Hl2oqGpMQaS9rIjLGNP90ApJLeFxnb+c=; b=BE6FstoeiEsgN1TujpUYUWDoMs8zxyc1lRv1FLbMsGSJzDrzQ/qrruR0AxZWT/NcOi 4kq2MImr/tjyAcx7s65p/upKat2cZjIYJvgubX0Ggxunrs24bCFgWrMwh0wTz52VSlIG tWJLZ/fVLa0nqYh50rrELDQP6rnUu1Y3kSum58XZE4TLXNDpjjeFv9639AxAdTC0Mm5Y IFm98VApqV5uQMN2sugo/2cYC8FZQiKZS0QULBT1yhXRpxNx0GT7tdl+otvLrwxUaewv YU2y8xtdWJj2no3jNmc9IU6pcs8KfceRAjk22WWpug4D0fKtW2plGp+HbQB+E4UeY3AW WXdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731259015; x=1731863815; 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=Ds30340H5u/Hl2oqGpMQaS9rIjLGNP90ApJLeFxnb+c=; b=m10PAYg5fXAAstuUiO13KE5r8j+cXt7cCDaVmQPsg7H4hbpHr6QUszAtVCWE+z1cm8 HXxBJlz4iRTxc5XlBtpNfXrrMzaNmtsqDFvEh0oQt+gTiLs9808y9449cIP/XUCE5QiF dAgljus5925Bu+MCWIXz/tc/DRlzZF4LevWlMHoh4X9Wn+Wck2G6OGpVworPhfqk8bxt po/RZIYRDY64jGesK7vU4CCqGrecpZ5fezv+vPR4w4f1zpHslcnJHJxMOV2B6OQ9NqLP Ulj2Zrw3mkA0j6Y6PHEt1VdO7qfANapHgdArT6XQNU4GQPjovVFtHnW32EaKML0+Ofkr srRg== X-Forwarded-Encrypted: i=1; AJvYcCXHRLa9dGdD61z7rhUxB68XPFBr48jpRRml/fKkfjtWFCr300SQ5WydRZAMUjjPt9Rz/VGyBYVE7UU=@lists.infradead.org X-Gm-Message-State: AOJu0Yz0YgtSyvPkiv9JgDnuBVxjMmjymUcKFoa6oaP3gmN8JyhW7ZaP ianGvQnTwN7KA92rd9EE8hHu9eQ+A8dIBs+fyKY3mqCpD6hcd5/x X-Google-Smtp-Source: AGHT+IHvTy5s8BptVPzH0lYKXRzguVjuoBL+jf+PoLw+XgNdo7eSV70D8xFOcrXuyM1hrj21MWWujQ== X-Received: by 2002:a05:6a20:7f8c:b0:1db:d738:f2ff with SMTP id adf61e73a8af0-1dc228ac37fmr15670992637.2.1731259015238; Sun, 10 Nov 2024 09:16:55 -0800 (PST) Received: from JRT-PC.. ([202.166.44.78]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-724078641a2sm7578415b3a.20.2024.11.10.09.16.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Nov 2024 09:16:54 -0800 (PST) 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 v7 1/2] riscv: sbi: Fix entry point of HSM tests Date: Mon, 11 Nov 2024 01:16:32 +0800 Message-ID: <20241110171633.113515-2-jamestiotio@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241110171633.113515-1-jamestiotio@gmail.com> References: <20241110171633.113515-1-jamestiotio@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241110_091656_506642_7823F75E X-CRM114-Status: GOOD ( 11.61 ) 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: With the current trick of setting opaque as hartid, the HSM tests would not be able to catch a bug where a0 is set to opaque and a1 is set to hartid. Fix this issue by setting a1 to an array with some [...] 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:430 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -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 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -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 With the current trick of setting opaque as hartid, the HSM tests would not be able to catch a bug where a0 is set to opaque and a1 is set to hartid. Fix this issue by setting a1 to an array with some magic number as the first element and hartid as the second element, following the behavior of the SUSP tests. Signed-off-by: James Raphael Tiovalen --- riscv/sbi-tests.h | 13 ++++++++++--- riscv/sbi-asm.S | 33 +++++++++++++++++++-------------- riscv/sbi.c | 1 + 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/riscv/sbi-tests.h b/riscv/sbi-tests.h index d0a7561a..162f0d53 100644 --- a/riscv/sbi-tests.h +++ b/riscv/sbi-tests.h @@ -9,9 +9,16 @@ #define SBI_CSR_SATP_IDX 4 #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) +#define SBI_HSM_TEST_MAGIC_A1 (1 << 1) +#define SBI_HSM_TEST_HARTID_A1 (1 << 2) +#define SBI_HSM_TEST_SATP (1 << 3) +#define SBI_HSM_TEST_SIE (1 << 4) + +#define SBI_HSM_MAGIC 0x453 + +#define SBI_HSM_MAGIC_IDX 0 +#define SBI_HSM_HARTID_IDX 1 +#define SBI_HSM_NUM_OF_PARAMS 2 #define SBI_SUSP_TEST_SATP (1 << 0) #define SBI_SUSP_TEST_SIE (1 << 1) diff --git a/riscv/sbi-asm.S b/riscv/sbi-asm.S index e871ea50..9ac77c5c 100644 --- a/riscv/sbi-asm.S +++ b/riscv/sbi-asm.S @@ -30,34 +30,39 @@ .balign 4 sbi_hsm_check: li HSM_RESULTS_MAP, 0 - bne a0, a1, 1f + REG_L t0, ASMARR(a1, SBI_HSM_MAGIC_IDX) + li t1, SBI_HSM_MAGIC + bne t0, t1, 1f + ori HSM_RESULTS_MAP, HSM_RESULTS_MAP, SBI_HSM_TEST_MAGIC_A1 +1: REG_L t0, ASMARR(a1, SBI_HSM_HARTID_IDX) + bne a0, t0, 2f ori HSM_RESULTS_MAP, HSM_RESULTS_MAP, SBI_HSM_TEST_HARTID_A1 -1: csrr t0, CSR_SATP - bnez t0, 2f +2: csrr t0, CSR_SATP + bnez t0, 3f ori HSM_RESULTS_MAP, HSM_RESULTS_MAP, SBI_HSM_TEST_SATP -2: csrr t0, CSR_SSTATUS +3: csrr t0, CSR_SSTATUS andi t0, t0, SR_SIE - bnez t0, 3f + bnez t0, 4f ori HSM_RESULTS_MAP, HSM_RESULTS_MAP, SBI_HSM_TEST_SIE -3: call hartid_to_cpu +4: call hartid_to_cpu mv HSM_CPU_INDEX, a0 li t0, -1 - bne HSM_CPU_INDEX, t0, 5f -4: pause - j 4b -5: ori HSM_RESULTS_MAP, HSM_RESULTS_MAP, SBI_HSM_TEST_DONE + bne HSM_CPU_INDEX, t0, 6f +5: pause + j 5b +6: ori HSM_RESULTS_MAP, HSM_RESULTS_MAP, SBI_HSM_TEST_DONE add t0, HSM_RESULTS_ARRAY, HSM_CPU_INDEX sb HSM_RESULTS_MAP, 0(t0) la t1, sbi_hsm_stop_hart add t1, t1, HSM_CPU_INDEX -6: lb t0, 0(t1) +7: lb t0, 0(t1) pause - beqz t0, 6b + beqz t0, 7b li a7, 0x48534d /* SBI_EXT_HSM */ li a6, 1 /* SBI_EXT_HSM_HART_STOP */ ecall -7: pause - j 7b +8: pause + j 8b .balign 4 .global sbi_hsm_check_hart_start diff --git a/riscv/sbi.c b/riscv/sbi.c index 6f2d3e35..300e5cc9 100644 --- a/riscv/sbi.c +++ b/riscv/sbi.c @@ -483,6 +483,7 @@ static void check_ipi(void) 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]; +unsigned long sbi_hsm_hart_start_params[NR_CPUS * SBI_HSM_NUM_OF_PARAMS]; #define DBCN_WRITE_TEST_STRING "DBCN_WRITE_TEST_STRING\n" #define DBCN_WRITE_BYTE_TEST_BYTE ((u8)'a')