From patchwork Fri Mar 21 16:54:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 14025804 Received: from out-185.mta0.migadu.com (out-185.mta0.migadu.com [91.218.175.185]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7B28322D786 for ; Fri, 21 Mar 2025 16:54:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.185 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742576055; cv=none; b=ltKzLU7Se12a9OaXN1bBdrTimaR+jXfZzEg1h/i7zGDHtfI3f7jmVpiPQg/GirWJHYaKwqXOqkanEihgG+umxdLP7ndzIKuEMYmhCmmF4Fp/zBLlnDwa4HXfvMG6b3Jle9iVnP2YvcguQ3Ndvkqony/eGS4ZEojrvUwU3Ki/EF0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742576055; c=relaxed/simple; bh=sxgvp/HlbbMAhjzZBi4WoFmdngeoDetQ93BR65bG61E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HaI3e+VmR7Z9zWIaljHG3agE8VKAdRZyWr8YUKR0eBrMVz+QMm4Te8UVjVlO2mvNGR+2FCFUCjrmd+tAWKD84sgx9mNYEbEcTOGeuMZk/jHyqz+jTXlP67xfbvatq8wO1ycdf8C93swGZfAXqGrWkDP5pBi9WSxML7+RBgNs/ZA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=DzV+ddJu; arc=none smtp.client-ip=91.218.175.185 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="DzV+ddJu" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1742576049; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=G9zKZEdfQYZeghDcnUUsQR01GtR2H7Xuam0AVo+Vzx0=; b=DzV+ddJu0d7wt8hCmpHLUTZn0Jgcfy5vaXvNYtiEoXyOkAoIfE1oEiZ5an96GxNgoXf1aN H0jyEm4J6YrP8XbtY6T/FwFPDtQpybRRKykQv/xLAOty5mBhqCPzofFBq/CE2P1TLT1IuV tsF4wVQnnnV3wWG19aK0KJjxeZqJk04= From: Andrew Jones To: kvm-riscv@lists.infradead.org, kvm@vger.kernel.org Cc: cleger@rivosinc.com, atishp@rivosinc.com, akshaybehl231@gmail.com Subject: [kvm-unit-tests PATCH 1/3] lib/riscv: Also provide sbiret impl functions Date: Fri, 21 Mar 2025 17:54:05 +0100 Message-ID: <20250321165403.57859-6-andrew.jones@linux.dev> In-Reply-To: <20250321165403.57859-5-andrew.jones@linux.dev> References: <20250321165403.57859-5-andrew.jones@linux.dev> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT We almost always return sbiret from sbi wrapper functions so do that for sbi_get_imp_version() and sbi_get_imp_id(), but asserting no error and returning the value is also useful, so continue to provide those functions too, just with a slightly different name. Signed-off-by: Andrew Jones Reviewed-by: Clément Léger --- lib/riscv/asm/sbi.h | 6 ++++-- lib/riscv/sbi.c | 18 ++++++++++++++---- riscv/sbi-sse.c | 4 ++-- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/lib/riscv/asm/sbi.h b/lib/riscv/asm/sbi.h index edaee462c3fa..a5738a5ce209 100644 --- a/lib/riscv/asm/sbi.h +++ b/lib/riscv/asm/sbi.h @@ -260,9 +260,11 @@ struct sbiret sbi_send_ipi_cpumask(const cpumask_t *mask); struct sbiret sbi_send_ipi_broadcast(void); struct sbiret sbi_set_timer(unsigned long stime_value); struct sbiret sbi_get_spec_version(void); -unsigned long sbi_get_imp_version(void); -unsigned long sbi_get_imp_id(void); +struct sbiret sbi_get_imp_version(void); +struct sbiret sbi_get_imp_id(void); long sbi_probe(int ext); +unsigned long __sbi_get_imp_version(void); +unsigned long __sbi_get_imp_id(void); typedef void (*sbi_sse_handler_fn)(void *data, struct pt_regs *regs, unsigned int hartid); diff --git a/lib/riscv/sbi.c b/lib/riscv/sbi.c index 53d25489f905..2959378f64bb 100644 --- a/lib/riscv/sbi.c +++ b/lib/riscv/sbi.c @@ -183,21 +183,31 @@ struct sbiret sbi_set_timer(unsigned long stime_value) return sbi_ecall(SBI_EXT_TIME, SBI_EXT_TIME_SET_TIMER, stime_value, 0, 0, 0, 0, 0); } -unsigned long sbi_get_imp_version(void) +struct sbiret sbi_get_imp_version(void) +{ + return sbi_ecall(SBI_EXT_BASE, SBI_EXT_BASE_GET_IMP_VERSION, 0, 0, 0, 0, 0, 0); +} + +struct sbiret sbi_get_imp_id(void) +{ + return sbi_ecall(SBI_EXT_BASE, SBI_EXT_BASE_GET_IMP_ID, 0, 0, 0, 0, 0, 0); +} + +unsigned long __sbi_get_imp_version(void) { struct sbiret ret; - ret = sbi_ecall(SBI_EXT_BASE, SBI_EXT_BASE_GET_IMP_VERSION, 0, 0, 0, 0, 0, 0); + ret = sbi_get_imp_version(); assert(!ret.error); return ret.value; } -unsigned long sbi_get_imp_id(void) +unsigned long __sbi_get_imp_id(void) { struct sbiret ret; - ret = sbi_ecall(SBI_EXT_BASE, SBI_EXT_BASE_GET_IMP_ID, 0, 0, 0, 0, 0, 0); + ret = sbi_get_imp_id(); assert(!ret.error); return ret.value; diff --git a/riscv/sbi-sse.c b/riscv/sbi-sse.c index 97e07725c359..bc6afaf5481e 100644 --- a/riscv/sbi-sse.c +++ b/riscv/sbi-sse.c @@ -1232,8 +1232,8 @@ void check_sse(void) return; } - if (sbi_get_imp_id() == SBI_IMPL_OPENSBI && - sbi_get_imp_version() < sbi_impl_opensbi_mk_version(1, 7)) { + if (__sbi_get_imp_id() == SBI_IMPL_OPENSBI && + __sbi_get_imp_version() < sbi_impl_opensbi_mk_version(1, 7)) { report_skip("OpenSBI < v1.7 detected, skipping tests"); report_prefix_pop(); return; From patchwork Fri Mar 21 16:54:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 14025806 Received: from out-173.mta0.migadu.com (out-173.mta0.migadu.com [91.218.175.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 91D7922D798 for ; Fri, 21 Mar 2025 16:54:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742576057; cv=none; b=qMb7/KBOxB4uRniqq3635MWFO5gF91TE5/mPEAKeHwOnGRbPJoNXqo07Xf3jBY7ofiSGdSAA/F8GoH4wtN1Ep8ttJTPaiGMD6PQd1pPHe6uuK1pTO+szAUPKiOi6YlYbxDorPkv3tyBgfvE5TedAZEcl2zZh9+8L+u0yj7d1LnQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742576057; c=relaxed/simple; bh=LQy2BpsJNqJRQtLtOSIbjCqjkePGZ7+3X1JuspfVXM8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iLjsxDcAreHNEK3y3HlYL+I8Hetoj6eSuD3qNHlUjILoiIYXoALRvFZZQXRi5tejXr5kZxX9BpdbeLuHjzjGGYtNeW9dbslzCogrnfz1KIDb/T7Q8v8rWiWPJoSNtbaGd7uABnIhpB8PaYKrwtLCCBRxOGfAjREhSflj9f4a5c4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=IDzwI5Zg; arc=none smtp.client-ip=91.218.175.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="IDzwI5Zg" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1742576051; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PKtK3T8rQ5Y+UYKn5E6rBhpv2qWXGv+TG0wqcWzYaf8=; b=IDzwI5ZgUb7t4iU+0juMWN+ZBm8S3yokyisfop8Qtzgb8Wr7GYhrpxH+LnDfn0c3pqVa/X 9WmhoaQRycHK3P7IO16oaawvV+a9mCY6cNI0pUKXlm6K552hob1zsCeiaDkzMOsr6SMLBw c2iWC7DoHrTUJCW7OaEUswtPc9Eb33c= From: Andrew Jones To: kvm-riscv@lists.infradead.org, kvm@vger.kernel.org Cc: cleger@rivosinc.com, atishp@rivosinc.com, akshaybehl231@gmail.com Subject: [kvm-unit-tests PATCH 2/3] riscv: sbi: Add kfail versions of sbiret_report functions Date: Fri, 21 Mar 2025 17:54:06 +0100 Message-ID: <20250321165403.57859-7-andrew.jones@linux.dev> In-Reply-To: <20250321165403.57859-5-andrew.jones@linux.dev> References: <20250321165403.57859-5-andrew.jones@linux.dev> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT report_kfail is useful for SBI testing to allowing CI to PASS even when SBI implementations have known failures. Since sbiret_report functions are frequently used by SBI tests, make kfail versions of them too. Signed-off-by: Andrew Jones Reviewed-by: Clément Léger --- riscv/sbi-tests.h | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/riscv/sbi-tests.h b/riscv/sbi-tests.h index ddfad7fef293..d5c4ae709632 100644 --- a/riscv/sbi-tests.h +++ b/riscv/sbi-tests.h @@ -39,7 +39,8 @@ #include #include -#define __sbiret_report(ret, expected_error, expected_value, has_value, expected_error_name, fmt, ...) ({ \ +#define __sbiret_report(kfail, ret, expected_error, expected_value, \ + has_value, expected_error_name, fmt, ...) ({ \ long ex_err = expected_error; \ long ex_val = expected_value; \ bool has_val = !!(has_value); \ @@ -48,9 +49,9 @@ bool pass; \ \ if (has_val) \ - pass = report(ch_err && ch_val, fmt, ##__VA_ARGS__); \ + pass = report_kfail(kfail, ch_err && ch_val, fmt, ##__VA_ARGS__); \ else \ - pass = report(ch_err, fmt ": %s", ##__VA_ARGS__, expected_error_name); \ + pass = report_kfail(kfail, ch_err, fmt ": %s", ##__VA_ARGS__, expected_error_name); \ \ if (!pass && has_val) \ report_info(fmt ": expected (error: %ld, value: %ld), received: (error: %ld, value %ld)", \ @@ -63,14 +64,23 @@ }) #define sbiret_report(ret, expected_error, expected_value, ...) \ - __sbiret_report(ret, expected_error, expected_value, true, #expected_error, __VA_ARGS__) + __sbiret_report(false, ret, expected_error, expected_value, true, #expected_error, __VA_ARGS__) #define sbiret_report_error(ret, expected_error, ...) \ - __sbiret_report(ret, expected_error, 0, false, #expected_error, __VA_ARGS__) + __sbiret_report(false, ret, expected_error, 0, false, #expected_error, __VA_ARGS__) #define sbiret_check(ret, expected_error, expected_value) \ sbiret_report(ret, expected_error, expected_value, "check sbi.error and sbi.value") +#define sbiret_kfail(kfail, ret, expected_error, expected_value, ...) \ + __sbiret_report(kfail, ret, expected_error, expected_value, true, #expected_error, __VA_ARGS__) + +#define sbiret_kfail_error(kfail, ret, expected_error, ...) \ + __sbiret_report(kfail, ret, expected_error, 0, false, #expected_error, __VA_ARGS__) + +#define sbiret_check_kfail(kfail, ret, expected_error, expected_value) \ + sbiret_kfail(kfail, ret, expected_error, expected_value, "check sbi.error and sbi.value") + static inline bool env_or_skip(const char *env) { if (!getenv(env)) { From patchwork Fri Mar 21 16:54:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 14025807 Received: from out-189.mta0.migadu.com (out-189.mta0.migadu.com [91.218.175.189]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9559F22D7AD for ; Fri, 21 Mar 2025 16:54:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.189 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742576059; cv=none; b=fqBApq1cIfurYUDlGxQk/3PIebxLLGTGGGZ66wjTpctItfCr+15hIzWGsX5Cq7febZPe0WAiGfwbFMyxEQvnMeg6V+VS/1UKF97nRzmIHxbKyYW5xJD3j9JwapsDi9q+ZynIFQ4+57KgMLy5334IlfLrudX21EkgwFg+35HCC1Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742576059; c=relaxed/simple; bh=mtq+uEaM31NpCw4KEGkVMWdG5F+I9RFiW1f1U8ZhqZY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gXF6tEhDV4eLvseKqQfCVLPtHGBL22KSHogxwqAtsXOLzn6XFgvdn4JQaB8Z3KH2yxTzvaVUxGPuhJcwSQ9aqiq4tE5kIesl/XVL3A/W7s6FQWU9NwqBKMQshap8x8pGngcRqxt35Fz/K+hbL7zODbm6lj+OoCapCZQCn7IMYgA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=NnbjDHen; arc=none smtp.client-ip=91.218.175.189 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="NnbjDHen" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1742576053; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UIolc26Z9WyQwzj190zC3vU/7vb8zQejDnHfjjlS2TY=; b=NnbjDHenGbSrKQVFGKgBN+CwdoxdxAfoFHK3CZWZKR0PiBVecIWj1ZLTqlBjykdDmPrHE7 GEEoHwnBwlYMhnSqtyBequ2VItBsBxe1svNQ4bF0TLyyfn6NcEOQ2/CfwGMy30iy0ItSpM dbkGVD1B/QPMv0QrMAinnYfIGZxC06U= From: Andrew Jones To: kvm-riscv@lists.infradead.org, kvm@vger.kernel.org Cc: cleger@rivosinc.com, atishp@rivosinc.com, akshaybehl231@gmail.com Subject: [kvm-unit-tests PATCH 3/3] riscv: sbi: Use kfail for known opensbi failures Date: Fri, 21 Mar 2025 17:54:07 +0100 Message-ID: <20250321165403.57859-8-andrew.jones@linux.dev> In-Reply-To: <20250321165403.57859-5-andrew.jones@linux.dev> References: <20250321165403.57859-5-andrew.jones@linux.dev> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT Use kfail for the opensbi s/SBI_ERR_DENIED/SBI_ERR_DENIED_LOCKED/ change. We expect it to be fixed in 1.7, so only kfail for opensbi which has a version less than that. Also change the other uses of kfail to only kfail for opensbi versions less than 1.7. Signed-off-by: Andrew Jones Reviewed-by: Clément Léger --- riscv/sbi-fwft.c | 20 +++++++++++++------- riscv/sbi.c | 6 ++++-- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/riscv/sbi-fwft.c b/riscv/sbi-fwft.c index 3d225997c0ec..c52fbd6e77a6 100644 --- a/riscv/sbi-fwft.c +++ b/riscv/sbi-fwft.c @@ -83,19 +83,21 @@ static void fwft_feature_lock_test_values(uint32_t feature, size_t nr_values, report_prefix_push("locked"); + bool kfail = __sbi_get_imp_id() == SBI_IMPL_OPENSBI && + __sbi_get_imp_version() < sbi_impl_opensbi_mk_version(1, 7); + for (int i = 0; i < nr_values; ++i) { ret = fwft_set(feature, test_values[i], 0); - sbiret_report_error(&ret, SBI_ERR_DENIED_LOCKED, - "Set to %lu without lock flag", test_values[i]); + sbiret_kfail_error(kfail, &ret, SBI_ERR_DENIED_LOCKED, + "Set to %lu without lock flag", test_values[i]); ret = fwft_set(feature, test_values[i], SBI_FWFT_SET_FLAG_LOCK); - sbiret_report_error(&ret, SBI_ERR_DENIED_LOCKED, - "Set to %lu with lock flag", test_values[i]); + sbiret_kfail_error(kfail, &ret, SBI_ERR_DENIED_LOCKED, + "Set to %lu with lock flag", test_values[i]); } ret = fwft_get(feature); - sbiret_report(&ret, SBI_SUCCESS, locked_value, - "Get value %lu", locked_value); + sbiret_report(&ret, SBI_SUCCESS, locked_value, "Get value %lu", locked_value); report_prefix_pop(); } @@ -103,6 +105,7 @@ static void fwft_feature_lock_test_values(uint32_t feature, size_t nr_values, static void fwft_feature_lock_test(uint32_t feature, unsigned long locked_value) { unsigned long values[] = {0, 1}; + fwft_feature_lock_test_values(feature, 2, values, locked_value); } @@ -317,7 +320,10 @@ static void fwft_check_pte_ad_hw_updating(void) report(ret.value == 0 || ret.value == 1, "first get value is 0/1"); enabled = ret.value; - report_kfail(true, !enabled, "resets to 0"); + + bool kfail = __sbi_get_imp_id() == SBI_IMPL_OPENSBI && + __sbi_get_imp_version() < sbi_impl_opensbi_mk_version(1, 7); + report_kfail(kfail, !enabled, "resets to 0"); install_exception_handler(EXC_LOAD_PAGE_FAULT, adue_read_handler); install_exception_handler(EXC_STORE_PAGE_FAULT, adue_write_handler); diff --git a/riscv/sbi.c b/riscv/sbi.c index 83bc55125d46..edb1a6bef1ac 100644 --- a/riscv/sbi.c +++ b/riscv/sbi.c @@ -515,10 +515,12 @@ end_two: sbiret_report_error(&ret, SBI_SUCCESS, "no targets, hart_mask_base is 1"); /* Try the next higher hartid than the max */ + bool kfail = __sbi_get_imp_id() == SBI_IMPL_OPENSBI && + __sbi_get_imp_version() < sbi_impl_opensbi_mk_version(1, 7); ret = sbi_send_ipi(2, max_hartid); - report_kfail(true, ret.error == SBI_ERR_INVALID_PARAM, "hart_mask got expected error (%ld)", ret.error); + sbiret_kfail_error(kfail, &ret, SBI_ERR_INVALID_PARAM, "hart_mask"); ret = sbi_send_ipi(1, max_hartid + 1); - report_kfail(true, ret.error == SBI_ERR_INVALID_PARAM, "hart_mask_base got expected error (%ld)", ret.error); + sbiret_kfail_error(kfail, &ret, SBI_ERR_INVALID_PARAM, "hart_mask_base"); report_prefix_pop();