From patchwork Mon Aug 12 14:13:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 1971634 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=HodDfTGO; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=VxS/F2h0; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=p8uP2XhY; 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 4WjJ3y3zyKz1ydp for ; Tue, 13 Aug 2024 01:15:26 +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=MXuI15iyWXmkfzSsNAz9ZvD8fVQx8lb5kP1WC1eBdo4=; b=HodDfTGO2yhWTv mEZ/AxAwRclFjcGmnZ1AXbBBRa7vZRV7vv89bDSyNx6/n8BMQ477XAUYJC0rAC19Y7Rfzwc8gWVQn MrIIyzV7eEz8faJur6HjkRNaJhDwHm5dMXCTSzrJiuGzcep8MAewFT1UalteMQiSa0uI2bAo1DzFv knAD3EFm//e8rKLLjyOypZe6XUR2INxDmh8SxyuPNAwMj0qATKPotxsNJHCHBTEBIYn+5EJ+VWqF5 Vp2vzu1adLDZruT7/5SAZRozl2xz4jkXwptsgpwSnvluIW+93XaTdkgwwls/qh/XKW2iKeKuOEsN/ owhuo+zit/ayaIckljGg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sdWlY-00000000hpm-3bir; Mon, 12 Aug 2024 15:15:24 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sdVoQ-00000000Y6y-1CoX for kvm-riscv@bombadil.infradead.org; Mon, 12 Aug 2024 14:14:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=+iYX6kGglESM6CdwC18ttg651AtfAE9zmr/i9M+sIAk=; b=VxS/F2h0fbzi08GxCko6sD1x6i xQpCFFoeYROTCsXhTCu+egIqlQOobGcNYtiR8j+Kdl3IkVUI5B4r3EHlxDUVGQl8c8glMWHULObFg BKdv2ChH0Crux8uFFes+HH8LFPx4FaJydd3wmhb5mkVIRzU2kecPO9qU12w/AJTZsRRx5tO+GjyQ4 U5XK2asltiN94qDG8YeSEKmFQxmA1TcmHgvzGjY3JNK1Y2QhEO8ZET6a44KSU9+6lxVH1eF/wwr7E Q728zv7kxvqXnGeWMRzPAJQZol5BdRzP6+Om7sq3rXHDVzhO8ElOUox1omxwBkKwU9FySfmi9XNz5 WyIdLFSg==; Received: from out-176.mta1.migadu.com ([2001:41d0:203:375::b0]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sdVoL-00000007a6V-34XE for kvm-riscv@lists.infradead.org; Mon, 12 Aug 2024 14:14:17 +0000 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=1723472044; 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=+iYX6kGglESM6CdwC18ttg651AtfAE9zmr/i9M+sIAk=; b=p8uP2XhYmr+8yOUvIajF9qHHC1XuadpXSoTvbqQR4rXIQXIteUeKclgbN/zQdR1H3dbd1k J64WM+xgmlC2Psy6LLJoAEy1onGq+YfKVGPdlMnQPug5fFrEEV2hVvL/vSffO0r6+W7HP9 9Ip4juu9m2eP1n15YIeStTQGB7gqFWc= 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/4] riscv: sbi: dbcn: Output return values Date: Mon, 12 Aug 2024 16:13:56 +0200 Message-ID: <20240812141354.119889-7-andrew.jones@linux.dev> In-Reply-To: <20240812141354.119889-6-andrew.jones@linux.dev> References: <20240812141354.119889-6-andrew.jones@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240812_151413_944411_10E0D4F2 X-CRM114-Status: UNSURE ( 8.82 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "desiato.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: When a test fails its nice to be able to see exactly what error code it failed with in order to immediately start debug. Signed-off-by: Andrew Jones --- riscv/sbi.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_HELO_PASS SPF: HELO matches 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_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.0 T_SCC_BODY_TEXT_LINE No description available. 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 When a test fails its nice to be able to see exactly what error code it failed with in order to immediately start debug. Signed-off-by: Andrew Jones --- riscv/sbi.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/riscv/sbi.c b/riscv/sbi.c index 93a79d8095f5..2393929b965d 100644 --- a/riscv/sbi.c +++ b/riscv/sbi.c @@ -299,7 +299,7 @@ static void check_dbcn(void) num_calls++; } while (num_bytes != 0 && ret.error == SBI_SUCCESS); - report(ret.error == SBI_SUCCESS, "write success"); + report(ret.error == SBI_SUCCESS, "write success (error=%ld)", ret.error); report_info("%d sbi calls made", num_calls); /* Bytes are read from memory and written to the console */ @@ -307,7 +307,7 @@ static void check_dbcn(void) paddr = strtoull(getenv("INVALID_ADDR"), NULL, 0); split_phys_addr(paddr, &base_addr_hi, &base_addr_lo); ret = __dbcn_sbi_ecall(SBI_EXT_DBCN_CONSOLE_WRITE, 1, base_addr_lo, base_addr_hi); - report(ret.error == SBI_ERR_INVALID_PARAM, "invalid parameter: address"); + report(ret.error == SBI_ERR_INVALID_PARAM, "invalid parameter: address (error=%ld)", ret.error); } report_prefix_pop(); @@ -317,8 +317,8 @@ static void check_dbcn(void) puts("DBCN_WRITE TEST CHAR: "); ret = __dbcn_sbi_ecall(SBI_EXT_DBCN_CONSOLE_WRITE_BYTE, (u8)DBCN_WRITE_BYTE_TEST_BYTE, 0, 0); puts("\n"); - report(ret.error == SBI_SUCCESS, "write success"); - report(ret.value == 0, "expected ret.value"); + report(ret.error == SBI_SUCCESS, "write success (error=%ld)", ret.error); + report(ret.value == 0, "expected ret.value (%ld)", ret.value); report_prefix_pop(); } From patchwork Mon Aug 12 14:13:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 1971635 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=VFWMOTMi; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=PYRNIv3i; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=WcKdXkOp; 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 4WjJ3z0p1bz20Fy for ; Tue, 13 Aug 2024 01:15:27 +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=zTEdnlKbgPO59Z4R1CdPOyRbmdwDXgvtcIF68VUPTeU=; b=VFWMOTMiUCEt/1 1OFeEh131RrTvXNw73UrOR1FTunJ05hiaGMo3gjufk3YrVoYnAXboY6FusIw56crab76OsfxvTOY6 A5e075ADq16p1bGu+f6HIaYU+POWdDURzwCiBj9ncYGQyF6wSaMLPeZkA2j5jh0SJsQ/XucyZyE83 jrZwbnGKlcpkg8xaFvR0EomzAR7UJCK7HvJzLG7elrhCUx2lKv/BGjFCEf0S/rAbALrS6a2taY3Tx GHXiOaIkmOuyicrBkW/QRVtbd2/Y6EiGNKoF28x5UxFmNCWQHUSWa8CxwSgUiXtAHZA2usZ673SOU j7p+XL9zl6ZyFLM6YeRg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sdWlZ-00000000hqF-2wM1; Mon, 12 Aug 2024 15:15:25 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sdVoS-00000000Y7R-3hIO for kvm-riscv@bombadil.infradead.org; Mon, 12 Aug 2024 14:14:20 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=A9b7yuIV81EFMV6IdsZHbE23iNNqeOt+Yr7GlpQoJ2U=; b=PYRNIv3i2wz8lbX2WzDzJ4Njr/ QqtHMo/q37uMMlHwkbRpJvYkWqotcPkGM87D/+JWRs2I7LetGTPpOsYl6kW9p1A0rlu1SmiNur3Wg 6GBSA/lBJoFaX2QOEA9CoM0hndCpQieRwJtS0cuOWpzB9Jy+RlErbEqbi2pv5wogP+dEkBzFsJw6j mf75dj61SMeKGlFgCTTk/ODQCu8kWpuSil2ca+GOlhxxe7IJPytQqnd72Kz3CCvP8V3Iri+O4StB2 cWwznask03WAb7FdELKq5ZAo+r227QAr0THFBkfu/sX3bxIvZYtvQd6hHaDUiIXKoS14DZcMzAnY/ uW5CwiNQ==; Received: from out-172.mta1.migadu.com ([2001:41d0:203:375::ac]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sdVoP-00000007a7M-33mC for kvm-riscv@lists.infradead.org; Mon, 12 Aug 2024 14:14:19 +0000 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=1723472046; 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=A9b7yuIV81EFMV6IdsZHbE23iNNqeOt+Yr7GlpQoJ2U=; b=WcKdXkOpLXJkYKNd+uzWDJsFq+cUddbvk+aFcGe4SaqVzs4wV72WyCKQ3FY7StzdnZFep9 6ZUTblKd/Q0roIDQZ020HvVhLtOdWJyZx1VRMWwEg5ArEbiphCZRqV1MuTrQcqYHqbEG53 JqZXt8ZLKOMQ7XRAFeY79fYnJQ2CSmc= 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/4] riscv: sbi: Use strtoul to avoid overflow Date: Mon, 12 Aug 2024 16:13:57 +0200 Message-ID: <20240812141354.119889-8-andrew.jones@linux.dev> In-Reply-To: <20240812141354.119889-6-andrew.jones@linux.dev> References: <20240812141354.119889-6-andrew.jones@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240812_151417_974818_E42B6683 X-CRM114-Status: UNSURE ( 8.99 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "desiato.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: We want to compare the expected values provided by environment variables with signed long results, but we should parse those values as unsigned as they may actually represent unsigned numbers with the [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_HELO_PASS SPF: HELO matches 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_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.0 T_SCC_BODY_TEXT_LINE No description available. 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 We want to compare the expected values provided by environment variables with signed long results, but we should parse those values as unsigned as they may actually represent unsigned numbers with the MSB set, and, if that's the case, then strtol will assert when detecting the signed value overflow. Signed-off-by: Andrew Jones --- riscv/sbi.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/riscv/sbi.c b/riscv/sbi.c index 2393929b965d..7b63a97deda6 100644 --- a/riscv/sbi.c +++ b/riscv/sbi.c @@ -85,14 +85,14 @@ static void check_base(void) report_prefix_push("spec_version"); if (env_or_skip("SPEC_VERSION")) { - expected = strtol(getenv("SPEC_VERSION"), NULL, 0); + expected = (long)strtoul(getenv("SPEC_VERSION"), NULL, 0); gen_report(&ret, 0, expected); } report_prefix_pop(); report_prefix_push("impl_id"); if (env_or_skip("IMPL_ID")) { - expected = strtol(getenv("IMPL_ID"), NULL, 0); + expected = (long)strtoul(getenv("IMPL_ID"), NULL, 0); ret = __base_sbi_ecall(SBI_EXT_BASE_GET_IMP_ID, 0); gen_report(&ret, 0, expected); } @@ -100,14 +100,14 @@ static void check_base(void) report_prefix_push("impl_version"); if (env_or_skip("IMPL_VERSION")) { - expected = strtol(getenv("IMPL_VERSION"), NULL, 0); + expected = (long)strtoul(getenv("IMPL_VERSION"), NULL, 0); ret = __base_sbi_ecall(SBI_EXT_BASE_GET_IMP_VERSION, 0); gen_report(&ret, 0, expected); } report_prefix_pop(); report_prefix_push("probe_ext"); - expected = getenv("PROBE_EXT") ? strtol(getenv("PROBE_EXT"), NULL, 0) : 1; + expected = getenv("PROBE_EXT") ? (long)strtoul(getenv("PROBE_EXT"), NULL, 0) : 1; ret = __base_sbi_ecall(SBI_EXT_BASE_PROBE_EXT, SBI_EXT_BASE); gen_report(&ret, 0, expected); report_prefix_push("unavailable"); @@ -118,7 +118,8 @@ static void check_base(void) report_prefix_push("mvendorid"); if (env_or_skip("MVENDORID")) { - expected = strtol(getenv("MVENDORID"), NULL, 0); + expected = (long)strtoul(getenv("MVENDORID"), NULL, 0); + assert(__riscv_xlen == 32 || !(expected >> 32)); ret = __base_sbi_ecall(SBI_EXT_BASE_GET_MVENDORID, 0); gen_report(&ret, 0, expected); } @@ -126,7 +127,7 @@ static void check_base(void) report_prefix_push("marchid"); if (env_or_skip("MARCHID")) { - expected = strtol(getenv("MARCHID"), NULL, 0); + expected = (long)strtoul(getenv("MARCHID"), NULL, 0); ret = __base_sbi_ecall(SBI_EXT_BASE_GET_MARCHID, 0); gen_report(&ret, 0, expected); } @@ -134,7 +135,7 @@ static void check_base(void) report_prefix_push("mimpid"); if (env_or_skip("MIMPID")) { - expected = strtol(getenv("MIMPID"), NULL, 0); + expected = (long)strtoul(getenv("MIMPID"), NULL, 0); ret = __base_sbi_ecall(SBI_EXT_BASE_GET_MIMPID, 0); gen_report(&ret, 0, expected); } From patchwork Mon Aug 12 14:13:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 1971636 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=lz7Ihp7+; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=IEvVYQlJ; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=rpKSyQ3F; 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 4WjJ3z2mGsz20G8 for ; Tue, 13 Aug 2024 01:15:27 +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=t74X91bPYa//05oVPbMxOW+r5oWQG1Ai/tHRA9DUvTc=; b=lz7Ihp7+RBW9O8 XHqa/62mHmLX57PnDh2TYDDI1WeLX+WGDAJ8eeOsUEu7zC0pq4hNh2Kba9uTrjQ2lHaBw+D8V+qzb TsZCpUEWSnmpoQBswEN+OYqsG2rlX4F3YTOqbYDcX7l8yeRGxTmZEZqYb2rBGEMROiOARMG4z5Bqf GYNVDcK7R2H9RvtoDmoT9sZoncXtgqVltVx/T6mDhd3VXUM1+Ul7BM7dqs/N8d1ad8EowEXHdPqme C0MHiRkJ9Duua1sBCqeU0sOrw13+yMJ4VZjeLhUP+sLTzo1JUazBGLjDqyqFq8NiictLN22Q2oMM0 0M8XkZyRZBBiI6aBTEvw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sdWla-00000000hqU-02Yq; Mon, 12 Aug 2024 15:15:26 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sdVoU-00000000Y7r-1cFI for kvm-riscv@bombadil.infradead.org; Mon, 12 Aug 2024 14:14:22 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=z+e3Q8KOZHypd1yOxyWSLWdeBIgtLiWk/Fp9jlVyymY=; b=IEvVYQlJcJ9BfE0EMJ8iT79qzO HEBeYQh5DevSInwTaQaXf6nYBC3F2izIuxptbF/tTpl5dKNhO1vdpF7rywFzwrFzlLZBOzFyUeeXT VyQYdgd51bPqaQYvSroJ71I/wdeGLUDB43F1iBi2luLvmOs8UtvqN88RIYeMkNBDn8rZZy8C4udxL GRnC/Wwj7eHBHnQ8/AoOJdwd6ke8Ol3wmxo2UTkVqwq1JSh7ybthpc5jUvybega0kb0RnCK0fasZ9 3X9JljNb45625yjdxIoVcRwqXlnyDlexfuuwya/6gQ5LTI7cZ4J8+Fjxm8sV+dZ5m0nlYBMJDOZ/f KzYewM+A==; Received: from out-187.mta1.migadu.com ([95.215.58.187]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sdVoR-00000007a86-160P for kvm-riscv@lists.infradead.org; Mon, 12 Aug 2024 14:14:21 +0000 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=1723472049; 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=z+e3Q8KOZHypd1yOxyWSLWdeBIgtLiWk/Fp9jlVyymY=; b=rpKSyQ3FTDFuqrhN9P85IbxO3DCJeflCl5eY89sAc8XOADDnqMGrD2KlcIwWKevSdR6iUo f55sl8gMENhjuYLmR1wUvvgE3u2ADH7SvRlkZztQr8gR9+22z39/i/ZrRCqMmlKul1jrlZ qciR8NBE1mswWpy7ogzIejTobxoXVl4= 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 3/4] riscv: sbi: Prefix several environment variables with SBI Date: Mon, 12 Aug 2024 16:13:58 +0200 Message-ID: <20240812141354.119889-9-andrew.jones@linux.dev> In-Reply-To: <20240812141354.119889-6-andrew.jones@linux.dev> References: <20240812141354.119889-6-andrew.jones@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240812_151419_575435_CFFBF83D X-CRM114-Status: UNSURE ( 8.51 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.9 (/) X-Spam-Report: Spam detection software, running on the system "desiato.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: Unit tests will likely share the environ so prefix variables that are specific to specific tests to avoid polluting the name space. We don't prefix generic stuff since they could be used by any test. Content analysis details: (-0.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [95.215.58.187 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches 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_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.0 T_SCC_BODY_TEXT_LINE No description available. 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 Unit tests will likely share the environ so prefix variables that are specific to specific tests to avoid polluting the name space. We don't prefix generic stuff since they could be used by any test. Signed-off-by: Andrew Jones --- riscv/sbi.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/riscv/sbi.c b/riscv/sbi.c index 7b63a97deda6..3f7ca6a78cfc 100644 --- a/riscv/sbi.c +++ b/riscv/sbi.c @@ -84,30 +84,30 @@ static void check_base(void) } report_prefix_push("spec_version"); - if (env_or_skip("SPEC_VERSION")) { - expected = (long)strtoul(getenv("SPEC_VERSION"), NULL, 0); + if (env_or_skip("SBI_SPEC_VERSION")) { + expected = (long)strtoul(getenv("SBI_SPEC_VERSION"), NULL, 0); gen_report(&ret, 0, expected); } report_prefix_pop(); report_prefix_push("impl_id"); - if (env_or_skip("IMPL_ID")) { - expected = (long)strtoul(getenv("IMPL_ID"), NULL, 0); + if (env_or_skip("SBI_IMPL_ID")) { + expected = (long)strtoul(getenv("SBI_IMPL_ID"), NULL, 0); ret = __base_sbi_ecall(SBI_EXT_BASE_GET_IMP_ID, 0); gen_report(&ret, 0, expected); } report_prefix_pop(); report_prefix_push("impl_version"); - if (env_or_skip("IMPL_VERSION")) { - expected = (long)strtoul(getenv("IMPL_VERSION"), NULL, 0); + if (env_or_skip("SBI_IMPL_VERSION")) { + expected = (long)strtoul(getenv("SBI_IMPL_VERSION"), NULL, 0); ret = __base_sbi_ecall(SBI_EXT_BASE_GET_IMP_VERSION, 0); gen_report(&ret, 0, expected); } report_prefix_pop(); report_prefix_push("probe_ext"); - expected = getenv("PROBE_EXT") ? (long)strtoul(getenv("PROBE_EXT"), NULL, 0) : 1; + expected = getenv("SBI_PROBE_EXT") ? (long)strtoul(getenv("SBI_PROBE_EXT"), NULL, 0) : 1; ret = __base_sbi_ecall(SBI_EXT_BASE_PROBE_EXT, SBI_EXT_BASE); gen_report(&ret, 0, expected); report_prefix_push("unavailable"); @@ -183,8 +183,8 @@ static void timer_check_set_timer(bool mask_timer_irq) struct sbiret ret; unsigned long begin, end, duration; const char *mask_test_str = mask_timer_irq ? " for mask irq test" : ""; - unsigned long d = getenv("TIMER_DELAY") ? strtol(getenv("TIMER_DELAY"), NULL, 0) : 200000; - unsigned long margin = getenv("TIMER_MARGIN") ? strtol(getenv("TIMER_MARGIN"), NULL, 0) : 200000; + unsigned long d = getenv("SBI_TIMER_DELAY") ? strtol(getenv("SBI_TIMER_DELAY"), NULL, 0) : 200000; + unsigned long margin = getenv("SBI_TIMER_MARGIN") ? strtol(getenv("SBI_TIMER_MARGIN"), NULL, 0) : 200000; d = usec_to_cycles(d); margin = usec_to_cycles(margin); From patchwork Mon Aug 12 14:13:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 1971637 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=uPCFUKQm; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=jxBTHNfm; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=sPkIH0pc; 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 4WjJ3y3NFyz1yYC for ; Tue, 13 Aug 2024 01:15:26 +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=1kyjQpH6wGyIqsZaKlbnUVZjDuAIygY27+iF2wQSg54=; b=uPCFUKQmP2d76W ofwoflUD7ZP/tET+dSnHNhWzfcmttqtfq8q4gA2JerNxAUvldzmJk2vAb5X6N4GWgJ9MhjPwNrGxh NsyHphPdXp27tssfJjKMLu+4IZm7JpYTSHvcN8qRGQvVTIQ10ToFRwukdFtpTCqJMDXyYrSziIQnV uoh/4FhR89P0WPKnrPqk9ylOzAHN6BR1zutp4LnDZ/cn/RuO6ZyMNcawQbHJXUAZlta7LhfCiqLR9 KG/eyf5+7SjNzxwcvszNV8Qgndg0lWRWn060lKO04qlav5aHONUbZ9p2AjdfwaJnzf6Ao5KKwnsrz zf7Itx9AESplHqesLrJg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sdWlZ-00000000hpq-0dts; Mon, 12 Aug 2024 15:15:25 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sdVoQ-00000000Y6w-19AW for kvm-riscv@bombadil.infradead.org; Mon, 12 Aug 2024 14:14:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=uxDUAgwyU7LZpMoLOtgb1JYYiYJmCsjV9g+S3q6q5t0=; b=jxBTHNfmurPZKMoRks9ZV+bn88 8xA7M1fM4OzPbEsa+xezMkGydGVZwrxBD3dvMcFMpQMACQnuqPFbNJFr/qMteQYKNSzvC0eas3Edb IXHIoOr1PaQzMzOQayhDUE4OWmO7OnfgX9FNbFaeaC5N/VhfOU9pW6hhXnvtJiC07rS1cQLiGBBI8 2gxJxqKZKJedo7NwmJXWSroJqdGId+rMuMqABYeC1O3dpeOE2njUhcqsabrzufg1avKqMp1JIj8hb Lj4jNODJyol20Gk7N9hZAOPpM6r6eeumR3KFENkisFDS93RC7F6kLaMMv8prP9/DZZfF9oBIQ8tRv 9sSFts0w==; Received: from out-174.mta1.migadu.com ([2001:41d0:203:375::ae]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sdVoM-00000007a8F-0yPQ for kvm-riscv@lists.infradead.org; Mon, 12 Aug 2024 14:14:17 +0000 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=1723472051; 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=uxDUAgwyU7LZpMoLOtgb1JYYiYJmCsjV9g+S3q6q5t0=; b=sPkIH0pcIOYjgfqFJqLk8SM0SHovIHM6PcSps5yh4S0ocoeZvccTjSpAzHg86UmEhgTjMF u0OW3de8vGFvbKuKFE8DVaCGZADAD2TFTyusNSBNBJHA2Nnq1zfxWRWYAZWg7nwKeZyJgG zXzKFYACpgKZBDahttngtYEpqa/WLZM= 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 4/4] riscv: sbi: dbcn: Add high address tests Date: Mon, 12 Aug 2024 16:13:59 +0200 Message-ID: <20240812141354.119889-10-andrew.jones@linux.dev> In-Reply-To: <20240812141354.119889-6-andrew.jones@linux.dev> References: <20240812141354.119889-6-andrew.jones@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240812_151414_433249_33607EFC X-CRM114-Status: GOOD ( 17.66 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "desiato.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: On platforms where we have high memory (above 4G) such as on the QEMU virt machine model with over 2G of RAM configured, then we can test DBCN with addresses above 4G on 32-bit and on both 32-bit and [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_HELO_PASS SPF: HELO matches 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_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.0 T_SCC_BODY_TEXT_LINE No description available. 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 On platforms where we have high memory (above 4G) such as on the QEMU virt machine model with over 2G of RAM configured, then we can test DBCN with addresses above 4G on 32-bit and on both 32-bit and 64-bit we can try crossing page boundaries both below 4G and from below 4G into 4G. Add those tests along with a bit of refactoring and the introduction of a couple helpers to find and check high addresses. Signed-off-by: Andrew Jones --- riscv/sbi.c | 134 +++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 116 insertions(+), 18 deletions(-) diff --git a/riscv/sbi.c b/riscv/sbi.c index 3f7ca6a78cfc..4f1e65dd3be6 100644 --- a/riscv/sbi.c +++ b/riscv/sbi.c @@ -5,18 +5,25 @@ * Copyright (C) 2023, Ventana Micro Systems Inc., Andrew Jones */ #include +#include #include +#include #include +#include +#include #include #include #include #include #include +#include #include #include #include #include +#define HIGH_ADDR_BOUNDARY ((phys_addr_t)1 << 32) + static void help(void) { puts("Test SBI\n"); @@ -46,6 +53,25 @@ static void split_phys_addr(phys_addr_t paddr, unsigned long *hi, unsigned long *hi = (unsigned long)(paddr >> 32); } +static bool check_addr(phys_addr_t start, phys_addr_t size) +{ + struct mem_region *r = memregions_find(start); + return r && r->end - start >= size && r->flags == MR_F_UNUSED; +} + +static phys_addr_t get_highest_addr(void) +{ + phys_addr_t highest_end = 0; + struct mem_region *r; + + for (r = mem_regions; r->end; ++r) { + if (r->end > highest_end) + highest_end = r->end; + } + + return highest_end - 1; +} + static bool env_or_skip(const char *env) { if (!getenv(env)) { @@ -266,16 +292,60 @@ 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) +{ + unsigned long base_addr_lo, base_addr_hi; + phys_addr_t paddr = virt_to_phys((void *)s); + int num_calls = 0; + struct sbiret ret; + + split_phys_addr(paddr, &base_addr_hi, &base_addr_lo); + + do { + ret = __dbcn_sbi_ecall(SBI_EXT_DBCN_CONSOLE_WRITE, num_bytes, base_addr_lo, base_addr_hi); + num_bytes -= ret.value; + paddr += ret.value; + split_phys_addr(paddr, &base_addr_hi, &base_addr_lo); + num_calls++; + } while (num_bytes != 0 && ret.error == SBI_SUCCESS); + + report(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) +{ + int nr_pages = page_offset ? 2 : 1; + void *vaddr; + + if (page_addr != PAGE_ALIGN(page_addr) || page_addr + PAGE_SIZE < HIGH_ADDR_BOUNDARY || + !check_addr(page_addr, nr_pages * PAGE_SIZE)) { + report_skip("Memory above 4G required"); + return; + } + + vaddr = alloc_vpages(nr_pages); + + 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); +} + /* * Only the write functionality is tested here. There's no easy way to * non-interactively test the read functionality. */ static void check_dbcn(void) { - unsigned long num_bytes, base_addr_lo, base_addr_hi; + unsigned long num_bytes = strlen(DBCN_WRITE_TEST_STRING); + unsigned long base_addr_lo, base_addr_hi; + bool do_invalid_addr = false; phys_addr_t paddr; - int num_calls = 0; struct sbiret ret; + const char *tmp; + char *buf; report_prefix_push("dbcn"); @@ -286,33 +356,61 @@ static void check_dbcn(void) return; } - num_bytes = strlen(DBCN_WRITE_TEST_STRING); - paddr = virt_to_phys((void *)&DBCN_WRITE_TEST_STRING); - split_phys_addr(paddr, &base_addr_hi, &base_addr_lo); - report_prefix_push("write"); - do { - ret = __dbcn_sbi_ecall(SBI_EXT_DBCN_CONSOLE_WRITE, num_bytes, base_addr_lo, base_addr_hi); - num_bytes -= ret.value; - paddr += ret.value; - split_phys_addr(paddr, &base_addr_hi, &base_addr_lo); - num_calls++; - } while (num_bytes != 0 && ret.error == SBI_SUCCESS); + dbcn_write_test(DBCN_WRITE_TEST_STRING, num_bytes); - report(ret.error == SBI_SUCCESS, "write success (error=%ld)", ret.error); - report_info("%d sbi calls made", num_calls); + 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); + report_prefix_pop(); + + 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); + else + report_skip("user disabled"); + report_prefix_pop(); + + if (__riscv_xlen == 32) { + report_prefix_push("high page"); + tmp = getenv("SBI_DBCN_SKIP_HIGH_PAGE"); + if (!tmp || atol(tmp) == 0) { + paddr = HIGH_ADDR_BOUNDARY; + tmp = getenv("HIGH_PAGE"); + if (tmp) + paddr = strtoull(tmp, NULL, 0); + dbcn_high_write_test(DBCN_WRITE_TEST_STRING, num_bytes, paddr, 0); + } else { + report_skip("user disabled"); + } + report_prefix_pop(); + } /* Bytes are read from memory and written to the console */ - if (env_or_skip("INVALID_ADDR")) { + report_prefix_push("invalid parameter"); + tmp = getenv("INVALID_ADDR_AUTO"); + if (tmp && atol(tmp) == 1) { + paddr = get_highest_addr() + 1; + do_invalid_addr = true; + } else if (env_or_skip("INVALID_ADDR")) { paddr = strtoull(getenv("INVALID_ADDR"), NULL, 0); + do_invalid_addr = true; + } + + if (do_invalid_addr) { split_phys_addr(paddr, &base_addr_hi, &base_addr_lo); ret = __dbcn_sbi_ecall(SBI_EXT_DBCN_CONSOLE_WRITE, 1, base_addr_lo, base_addr_hi); - report(ret.error == SBI_ERR_INVALID_PARAM, "invalid parameter: address (error=%ld)", ret.error); + report(ret.error == SBI_ERR_INVALID_PARAM, "address (error=%ld)", ret.error); } - report_prefix_pop(); + report_prefix_pop(); report_prefix_push("write_byte"); puts("DBCN_WRITE TEST CHAR: ");