From patchwork Wed Sep 11 11:33:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13800271 Received: from out-188.mta0.migadu.com (out-188.mta0.migadu.com [91.218.175.188]) (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 D2758191F82 for ; Wed, 11 Sep 2024 11:33:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726054429; cv=none; b=KSOTK0U6mOlpyj3awYj2/MW90vEw1Yvu6YQz4/pUwDKzo3ZU1mJ96230T5tZ6JXEr0zZ/i6MJ3sw9tOwxevxz2/pPyNuf+RbbDpt7x7v1S8fi436j74RfqIMusc8Re7G4ScoEIIoO2TNm8sP/xcrnaKLPctc/7wPMnIG7CnaQZQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726054429; c=relaxed/simple; bh=jOPkwIeIRNma8QU1tLX23XTm2I6skaXAWmOFQNnD+C4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Fo9+cnCkGDk2MW8OrfHguImN2feNRMZEEUNKz2Jtb+jIhuV5+TowQdLCJ0Uxh5vLPJ6nhCxOVegbfoJhaFbb4f8L22NJCsele2VIEctcqwzAXMtLKJgsZ9FazIEMJvbE1q40CGqLGLmR3GUHJgnZELHULTg8udPyfTf1CnN+EmA= 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=LJ2/ylCb; arc=none smtp.client-ip=91.218.175.188 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="LJ2/ylCb" 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=1726054424; 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=gBmiCmcqbljsNZT/u+6f2NIjy3RBdVTjXQpgbf8WLZc=; b=LJ2/ylCbFrLTQ50OfizVDoVBNlDKNw9gQNj0wrPsEHD6+z+Yfb4mSl5s4SR3PPBm/UVTgg emWoL6ykzNFQdjOX9NNEiiI2+2VtNNQ4mYypgOTkUdBXYHRVJDZgldI60+YX8i/pg8Zz/K ysrMIwmel0QALNI6PM7yp8le5RDtaW4= From: Andrew Jones To: kvm@vger.kernel.org, kvm-riscv@lists.infradead.org Cc: atishp@rivosinc.com, cade.richard@berkeley.edu, jamestiotio@gmail.com Subject: [kvm-unit-tests PATCH 1/2] riscv: sbi: Highmem isn't always supported Date: Wed, 11 Sep 2024 13:33:40 +0200 Message-ID: <20240911113338.156844-5-andrew.jones@linux.dev> In-Reply-To: <20240911113338.156844-4-andrew.jones@linux.dev> References: <20240911113338.156844-4-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 When an SBI implementation has opted not to support memory accesses above 4G (highmem), such as 32-bit OpenSBI, then report failures to access that memory as "expected failures". Use yet another environment variable to inform the testsuite of this SBI implementation behavior. Signed-off-by: Andrew Jones --- riscv/sbi.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/riscv/sbi.c b/riscv/sbi.c index 093c20a096da..300d5ae63084 100644 --- a/riscv/sbi.c +++ b/riscv/sbi.c @@ -288,7 +288,7 @@ static void check_time(void) #define DBCN_WRITE_TEST_STRING "DBCN_WRITE_TEST_STRING\n" #define DBCN_WRITE_BYTE_TEST_BYTE ((u8)'a') -static void dbcn_write_test(const char *s, unsigned long num_bytes) +static void dbcn_write_test(const char *s, unsigned long num_bytes, bool xfail) { unsigned long base_addr_lo, base_addr_hi; phys_addr_t paddr = virt_to_phys((void *)s); @@ -305,12 +305,13 @@ static void dbcn_write_test(const char *s, unsigned long num_bytes) num_calls++; } while (num_bytes != 0 && ret.error == SBI_SUCCESS); - report(ret.error == SBI_SUCCESS, "write success (error=%ld)", ret.error); + report_xfail(xfail, ret.error == SBI_SUCCESS, "write success (error=%ld)", ret.error); report_info("%d sbi calls made", num_calls); } static void dbcn_high_write_test(const char *s, unsigned long num_bytes, - phys_addr_t page_addr, size_t page_offset) + phys_addr_t page_addr, size_t page_offset, + bool highmem_supported) { int nr_pages = page_offset ? 2 : 1; void *vaddr; @@ -326,7 +327,7 @@ static void dbcn_high_write_test(const char *s, unsigned long num_bytes, for (int i = 0; i < nr_pages; ++i) install_page(current_pgtable(), page_addr + i * PAGE_SIZE, vaddr + i * PAGE_SIZE); memcpy(vaddr + page_offset, DBCN_WRITE_TEST_STRING, num_bytes); - dbcn_write_test(vaddr + page_offset, num_bytes); + dbcn_write_test(vaddr + page_offset, num_bytes, !highmem_supported); } /* @@ -338,6 +339,7 @@ static void check_dbcn(void) unsigned long num_bytes = strlen(DBCN_WRITE_TEST_STRING); unsigned long base_addr_lo, base_addr_hi; bool do_invalid_addr = false; + bool highmem_supported = true; phys_addr_t paddr; struct sbiret ret; const char *tmp; @@ -353,21 +355,26 @@ static void check_dbcn(void) report_prefix_push("write"); - dbcn_write_test(DBCN_WRITE_TEST_STRING, num_bytes); + dbcn_write_test(DBCN_WRITE_TEST_STRING, num_bytes, false); assert(num_bytes < PAGE_SIZE); report_prefix_push("page boundary"); buf = alloc_pages(1); memcpy(&buf[PAGE_SIZE - num_bytes / 2], DBCN_WRITE_TEST_STRING, num_bytes); - dbcn_write_test(&buf[PAGE_SIZE - num_bytes / 2], num_bytes); + dbcn_write_test(&buf[PAGE_SIZE - num_bytes / 2], num_bytes, false); report_prefix_pop(); + tmp = getenv("SBI_HIGHMEM_NOT_SUPPORTED"); + if (tmp && atol(tmp) != 0) + highmem_supported = false; + report_prefix_push("high boundary"); tmp = getenv("SBI_DBCN_SKIP_HIGH_BOUNDARY"); if (!tmp || atol(tmp) == 0) dbcn_high_write_test(DBCN_WRITE_TEST_STRING, num_bytes, - HIGH_ADDR_BOUNDARY - PAGE_SIZE, PAGE_SIZE - num_bytes / 2); + HIGH_ADDR_BOUNDARY - PAGE_SIZE, PAGE_SIZE - num_bytes / 2, + highmem_supported); else report_skip("user disabled"); report_prefix_pop(); @@ -379,7 +386,7 @@ static void check_dbcn(void) tmp = getenv("HIGH_PAGE"); if (tmp) paddr = strtoull(tmp, NULL, 0); - dbcn_high_write_test(DBCN_WRITE_TEST_STRING, num_bytes, paddr, 0); + dbcn_high_write_test(DBCN_WRITE_TEST_STRING, num_bytes, paddr, 0, highmem_supported); } else { report_skip("user disabled"); } From patchwork Wed Sep 11 11:33:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13800272 Received: from out-175.mta0.migadu.com (out-175.mta0.migadu.com [91.218.175.175]) (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 B4EE6188599 for ; Wed, 11 Sep 2024 11:33:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726054432; cv=none; b=tnZ72sY72mf+RJnZlRBSEQihD9peqH8T2Mr0Dv6TpNC1/nEGA3vSNiNH0wSpLjDMBArbHGktVyRmMSODEmXwS2pkPFrIwQrCrfRlBhnVGC7jpRWOFpg+OuD/s6s7jSCnf4IG2ktGr7i50EhLle7OFkdHs1+92/Yay4n+n4X3KXM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726054432; c=relaxed/simple; bh=/QzG2vGxXI8pxu2o7WbDktWTen/2b5iMkHZG59SyQO4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Cm3kl2dUKqVRa7ue7hlwe13bmCJUhDmb32YFmOZFA1F10Ka8oboMwbC+5OXspkU/IpNUA9phOAXTU4VmiCSKUjlhNiWosYPCIvpjSSXZEd6rxurS1tcWEt0bhc1sgZiOvr0fFNMVuZCDYPwgCJaMkDmEUd85sD1hbIBLoujqG1M= 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=qJxVdPHL; arc=none smtp.client-ip=91.218.175.175 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="qJxVdPHL" 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=1726054428; 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=b7ix4KMbxRc+JMeF5CRb97eBA/z83HaJRk00C+aiWJA=; b=qJxVdPHL7XoqLqAjEhQCCGhnCbCSj9qaertpl3Jod8JnrwyUgAFsKPc4F9IfQg76z0dzwe ixfLgPCBswpvFWUTFdX1Wn9eQuNbcX61zM0LJxpW/aslN3THaIpJCVFq47XZ5U+SnnksGY 74DbWXq5wpLYj9dOYG0bA9lDG9vuxl8= From: Andrew Jones To: kvm@vger.kernel.org, kvm-riscv@lists.infradead.org Cc: atishp@rivosinc.com, cade.richard@berkeley.edu, jamestiotio@gmail.com Subject: [kvm-unit-tests PATCH 2/2] riscv: sbi: Improve spec version test Date: Wed, 11 Sep 2024 13:33:41 +0200 Message-ID: <20240911113338.156844-6-andrew.jones@linux.dev> In-Reply-To: <20240911113338.156844-4-andrew.jones@linux.dev> References: <20240911113338.156844-4-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 SBI spec version states that bit 31 must be zero and doesn't say anything about bits greater than 31 (for rv64). Check that bit 31 is zero and assume all other bits are UNKNOWN, so mask them off before testing. Signed-off-by: Andrew Jones --- lib/riscv/sbi.c | 2 +- riscv/sbi.c | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/riscv/sbi.c b/lib/riscv/sbi.c index ecc63acdebb7..f8ed873c2eee 100644 --- a/lib/riscv/sbi.c +++ b/lib/riscv/sbi.c @@ -97,7 +97,7 @@ long sbi_probe(int ext) struct sbiret ret; ret = sbi_ecall(SBI_EXT_BASE, SBI_EXT_BASE_GET_SPEC_VERSION, 0, 0, 0, 0, 0, 0); - assert(!ret.error && ret.value >= 2); + assert(!ret.error && (ret.value & 0x7ffffffful) >= 2); ret = sbi_ecall(SBI_EXT_BASE, SBI_EXT_BASE_PROBE_EXT, ext, 0, 0, 0, 0, 0); assert(!ret.error); diff --git a/riscv/sbi.c b/riscv/sbi.c index 300d5ae63084..f6d62c5644ae 100644 --- a/riscv/sbi.c +++ b/riscv/sbi.c @@ -105,18 +105,25 @@ static void check_base(void) report_prefix_push("base"); ret = sbi_base(SBI_EXT_BASE_GET_SPEC_VERSION, 0); - if (ret.error || ret.value < 2) { - report_skip("SBI spec version 0.2 or higher required"); - return; - } + if (!ret.error) + ret.value &= 0xfffffffful; report_prefix_push("spec_version"); if (env_or_skip("SBI_SPEC_VERSION")) { expected = (long)strtoul(getenv("SBI_SPEC_VERSION"), NULL, 0); + assert_msg(!(expected & BIT(31)), "SBI spec version bit 31 must be zero"); + assert_msg(__riscv_xlen == 32 || !(expected >> 32), "SBI spec version bits greater than 31 are UNKNOWN"); gen_report(&ret, 0, expected); } report_prefix_pop(); + ret.value &= 0x7ffffffful; + + if (ret.error || ret.value < 2) { + report_skip("SBI spec version 0.2 or higher required"); + return; + } + report_prefix_push("impl_id"); if (env_or_skip("SBI_IMPL_ID")) { expected = (long)strtoul(getenv("SBI_IMPL_ID"), NULL, 0);