From patchwork Thu Oct 24 12:28: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: 2001684 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=DKJ3E1Ze; 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=Ekd1+zEK; 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 4XZ5013XSDz1xx6 for ; Thu, 24 Oct 2024 23:32:17 +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=1mGszdV06JotI9rNiETkP6KDONBEOxK2jPM5xsNj2Y4=; b=DKJ3E1Ze1bBuNY CygYlv2iIh1lCWeDJcW7bOuMcSJBpO9HHzS/K7Oz0jJw1HXYqcpGdZaIGSCLNe50lBa01xEbK60RF yQRnts5CPSLriMJI0R7H9He4OoeMsfOFRZs7lfKhqqiLN1Eq2beLvsZ3xzKF/INGO7oqXAJOp9IJF wzzHp25acdsGjr1tKWBf4JkxY6j/3CBjJdTauLmFULNcVR3im5TrxgX9xslICDHndsjwQCTwtcWGH dmo0wdnbvC1GFA7iojZKRieNHxj4Y+scaUWd+OGHF32YNoN5DHqCw4gZqqfq7ZcSCopORsnnK74tM DazYg/lbif7my5ezQ+OQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t3x0i-00000000LXj-0JuV; Thu, 24 Oct 2024 12:32:16 +0000 Received: from out-178.mta0.migadu.com ([91.218.175.178]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t3wxT-00000000L38-3eiN for kvm-riscv@lists.infradead.org; Thu, 24 Oct 2024 12:28:57 +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=1729772932; 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=vrJKQYsqPwfe+UgIDxmj85EUMOBw0DGpaZVWjzi1Ymg=; b=Ekd1+zEKQDJLHGukcW5X+Va3WoHLQu4VX98H9BK4ukiC1n2JeRaXb3pgtRnrN8Ww0x32lN CHzACX2HJ6KyLui+rATAalHJ8tDcI7NNQXv3L8ODilKsxMpud9VgVOzWvpzxO1FV5RzXki JKeEQ01l7PThEB35FSxRA/ZdKcLaKFA= From: Andrew Jones To: kvm@vger.kernel.org, kvm-riscv@lists.infradead.org Cc: cade.richard@gmail.com, atishp@rivosinc.com, jamestiotio@gmail.com Subject: [kvm-unit-tests PATCH 1/2] riscv: Add sbi_send_ipi_broadcast Date: Thu, 24 Oct 2024 14:28:41 +0200 Message-ID: <20241024122839.71753-5-andrew.jones@linux.dev> In-Reply-To: <20241024122839.71753-4-andrew.jones@linux.dev> References: <20241024122839.71753-4-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-20241024_052856_168666_365D83F1 X-CRM114-Status: UNSURE ( 8.41 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -2.8 (--) 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: Coming SBI IPI tests will use this, but as it could be useful for other tests too, add it to the library. Signed-off-by: Andrew Jones --- lib/riscv/asm/sbi.h | 1 + lib/riscv/sbi.c | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) Content analysis details: (-2.8 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [91.218.175.178 listed in list.dnswl.org] 0.0 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED RBL: ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. [91.218.175.178 listed in sa-trusted.bondedsender.org] 0.0 RCVD_IN_VALIDITY_SAFE_BLOCKED RBL: ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. [91.218.175.178 listed in sa-accredit.habeas.com] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 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.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.0 RCVD_IN_VALIDITY_RPBL_BLOCKED RBL: ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. [91.218.175.178 listed in bl.score.senderscore.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 Coming SBI IPI tests will use this, but as it could be useful for other tests too, add it to the library. Signed-off-by: Andrew Jones --- lib/riscv/asm/sbi.h | 1 + lib/riscv/sbi.c | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/riscv/asm/sbi.h b/lib/riscv/asm/sbi.h index 1319439b7118..102486c00de3 100644 --- a/lib/riscv/asm/sbi.h +++ b/lib/riscv/asm/sbi.h @@ -87,6 +87,7 @@ struct sbiret sbi_hart_get_status(unsigned long hartid); struct sbiret sbi_send_ipi(unsigned long hart_mask, unsigned long hart_mask_base); struct sbiret sbi_send_ipi_cpu(int cpu); 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); long sbi_probe(int ext); diff --git a/lib/riscv/sbi.c b/lib/riscv/sbi.c index f25bde169490..02dd338c1915 100644 --- a/lib/riscv/sbi.c +++ b/lib/riscv/sbi.c @@ -62,13 +62,18 @@ struct sbiret sbi_send_ipi_cpu(int cpu) return sbi_send_ipi(1UL, cpus[cpu].hartid); } +struct sbiret sbi_send_ipi_broadcast(void) +{ + return sbi_send_ipi(0, -1UL); +} + struct sbiret sbi_send_ipi_cpumask(const cpumask_t *mask) { struct sbiret ret; cpumask_t tmp; if (cpumask_full(mask)) - return sbi_send_ipi(0, -1UL); + return sbi_send_ipi_broadcast(); cpumask_copy(&tmp, mask); From patchwork Thu Oct 24 12:28:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 2001686 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=J/XxAX77; 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=VmkMl5HN; 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 4XZ5016Cwvz1xxC for ; Thu, 24 Oct 2024 23:32:17 +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=OrGZMLqvnq1QRBph+gnOxNNmGErgTG15QOzCpUNSKqw=; b=J/XxAX77FeiNSk SIbhrOkXgMMtZdZuP26QHKViAWm5bvLHNY/EkFLec55EF8j0wuQb+AKD9DL33eKk9HPkEnTN6Qtg2 dtkYUVMJxbtNBfdnfXP6tSWLlrI9EzmI4kjFKC77wqGOC0kZPz0Lp4qBarP8vW+tA9+p4FntSrvkH eZOyn6e/JnVSfJPEIqpmbaMFbcFr7GLanEGMU+jv3YJEmHIohbbXSmYgrnFZIJuggOw7quWCkaCtI sEmof8LLSUbA9orZaSJn8BUIfG6FC1Snl2nOkKRexdgPv5WWDwWV7DanrVkEhBubkTcDUaNAcSg3M sY8paUmiiAaxzkJi+P9Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t3x0i-00000000LY3-1fTn; Thu, 24 Oct 2024 12:32:16 +0000 Received: from out-184.mta0.migadu.com ([91.218.175.184]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t3wxV-00000000L3Z-0CDS for kvm-riscv@lists.infradead.org; Thu, 24 Oct 2024 12:28:58 +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=1729772934; 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=iuvqwX7Xl8Oqd3hqT+kimWuv1EwUZ8WYIXxTgppAxhI=; b=VmkMl5HN1h6oqSiOWG4PblVlgohhH4FjGUTcJ0/+gP95PX98j7qTYjHXpnpihK1nJhrDKK Suzi9qDUnKZSxqAVGSBhcM5WcjInz3R37NZpKgMCLz2UpJ8JIG3BTi7R308xR+HLOuBtXW SYgFusmQWJzBHmIb+lFXrWHwT/djH74= From: Andrew Jones To: kvm@vger.kernel.org, kvm-riscv@lists.infradead.org Cc: cade.richard@gmail.com, atishp@rivosinc.com, jamestiotio@gmail.com, Cade Richard Subject: [kvm-unit-tests PATCH 2/2] riscv: sbi: Add IPI extension tests Date: Thu, 24 Oct 2024 14:28:42 +0200 Message-ID: <20241024122839.71753-6-andrew.jones@linux.dev> In-Reply-To: <20241024122839.71753-4-andrew.jones@linux.dev> References: <20241024122839.71753-4-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-20241024_052857_441359_9566F1D9 X-CRM114-Status: GOOD ( 13.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: From: Cade Richard Ensure IPIs directed at single harts are received and also that all harts receive IPIs on broadcast. Also check for invalid param errors when the params result in hartids greater than the max. Content analysis details: (-2.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED RBL: ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. [91.218.175.184 listed in sa-trusted.bondedsender.org] 0.0 RCVD_IN_VALIDITY_SAFE_BLOCKED RBL: ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. [91.218.175.184 listed in sa-accredit.habeas.com] 0.0 RCVD_IN_VALIDITY_RPBL_BLOCKED RBL: ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. [91.218.175.184 listed in bl.score.senderscore.com] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 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.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 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 From: Cade Richard Ensure IPIs directed at single harts are received and also that all harts receive IPIs on broadcast. Also check for invalid param errors when the params result in hartids greater than the max. Signed-off-by: Cade Richard [Made all changes for the review comments from the last review, also additional fixes and cleanups, and rewrote the commit message.] Signed-off-by: Andrew Jones --- riscv/sbi.c | 149 +++++++++++++++++++++++++++++++++++++++++++- riscv/unittests.cfg | 1 + 2 files changed, 148 insertions(+), 2 deletions(-) diff --git a/riscv/sbi.c b/riscv/sbi.c index d46befa1c6c1..82a116ff1b40 100644 --- a/riscv/sbi.c +++ b/riscv/sbi.c @@ -6,11 +6,15 @@ */ #include #include +#include +#include +#include +#include +#include #include #include -#include #include -#include + #include #include #include @@ -47,6 +51,20 @@ static struct sbiret sbi_dbcn_write_byte(uint8_t byte) return sbi_ecall(SBI_EXT_DBCN, SBI_EXT_DBCN_CONSOLE_WRITE_BYTE, byte, 0, 0, 0, 0, 0); } +static int rand_online_cpu(prng_state* ps) +{ + int cpu, me = smp_processor_id(); + + for (;;) { + cpu = prng32(ps) % nr_cpus; + cpu = cpumask_next(cpu - 1, &cpu_present_mask); + if (cpu != nr_cpus && cpu != me && cpu_present(cpu)) + break; + } + + return cpu; +} + static void split_phys_addr(phys_addr_t paddr, unsigned long *hi, unsigned long *lo) { *lo = (unsigned long)paddr; @@ -287,6 +305,132 @@ static void check_time(void) report_prefix_popn(2); } +static bool ipi_received[NR_CPUS]; +static bool ipi_timeout[NR_CPUS]; +static cpumask_t ipi_done; + +static void ipi_timeout_handler(struct pt_regs *regs) +{ + timer_stop(); + ipi_timeout[smp_processor_id()] = true; +} + +static void ipi_irq_handler(struct pt_regs *regs) +{ + ipi_ack(); + ipi_received[smp_processor_id()] = true; +} + +static void ipi_hart_wait(void *data) +{ + unsigned long timeout = (unsigned long)data; + int me = smp_processor_id(); + + install_irq_handler(IRQ_S_SOFT, ipi_irq_handler); + install_irq_handler(IRQ_S_TIMER, ipi_timeout_handler); + local_ipi_enable(); + timer_irq_enable(); + local_irq_enable(); + + timer_start(timeout); + while (!READ_ONCE(ipi_received[me]) && !READ_ONCE(ipi_timeout[me])) + cpu_relax(); + local_irq_disable(); + timer_stop(); + local_ipi_disable(); + timer_irq_disable(); + + cpumask_set_cpu(me, &ipi_done); +} + +static void ipi_hart_check(cpumask_t *mask) +{ + int cpu; + + for_each_cpu(cpu, mask) { + if (ipi_timeout[cpu]) { + const char *rec = ipi_received[cpu] ? "but was still received" + : "and has still not been received"; + report_fail("ipi timed out on cpu%d %s", cpu, rec); + } + + ipi_timeout[cpu] = false; + ipi_received[cpu] = false; + } +} + +static void check_ipi(void) +{ + unsigned long d = getenv("SBI_IPI_TIMEOUT") ? strtol(getenv("SBI_IPI_TIMEOUT"), NULL, 0) : 200000; + int nr_cpus_present = cpumask_weight(&cpu_present_mask); + int me = smp_processor_id(); + unsigned long max_hartid = 0; + static prng_state ps; + struct sbiret ret; + cpumask_t tmp; + int cpu; + + ps = prng_init(0xDEADBEEF); + + report_prefix_push("ipi"); + + if (!sbi_probe(SBI_EXT_IPI)) { + report_skip("ipi extension not available"); + report_prefix_pop(); + return; + } + + if (nr_cpus_present < 2) { + report_skip("At least 2 cpus required"); + report_prefix_pop(); + return; + } + + report_prefix_push("random hart"); + cpu = rand_online_cpu(&ps); + cpumask_copy(&ipi_done, &cpu_present_mask); + cpumask_clear_cpu(cpu, &ipi_done); + on_cpu_async(cpu, ipi_hart_wait, (void *)d); + ret = sbi_send_ipi_cpu(cpu); + report(ret.error == SBI_SUCCESS, "ipi returned success"); + while (cpumask_weight(&ipi_done) != nr_cpus_present) + cpu_relax(); + cpumask_clear(&ipi_done); + cpumask_clear(&tmp); + cpumask_set_cpu(cpu, &tmp); + ipi_hart_check(&tmp); + report_prefix_pop(); + + report_prefix_push("broadcast"); + cpumask_copy(&tmp, &cpu_present_mask); + cpumask_clear_cpu(me, &tmp); + on_cpumask_async(&tmp, ipi_hart_wait, (void *)d); + ret = sbi_send_ipi_broadcast(); + report(ret.error == SBI_SUCCESS, "ipi returned success"); + while (cpumask_weight(&ipi_done) != nr_cpus_present - 1) + cpu_relax(); + cpumask_clear(&ipi_done); + ipi_hart_check(&tmp); + report_prefix_pop(); + + report_prefix_push("invalid parameters"); + + for_each_present_cpu(cpu) { + if (cpus[cpu].hartid > max_hartid) + max_hartid = cpus[cpu].hartid; + } + + /* Try the next higher hartid than the max */ + ret = sbi_send_ipi(2, max_hartid); + report(ret.error == SBI_ERR_INVALID_PARAM, "hart_mask got expected error (%ld)", ret.error); + ret = sbi_send_ipi(1, max_hartid + 1); + report(ret.error == SBI_ERR_INVALID_PARAM, "hart_mask_base got expected error (%ld)", ret.error); + + report_prefix_pop(); + + report_prefix_pop(); +} + 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]; @@ -442,6 +586,7 @@ int main(int argc, char **argv) report_prefix_push("sbi"); check_base(); check_time(); + check_ipi(); check_dbcn(); return report_summary(); diff --git a/riscv/unittests.cfg b/riscv/unittests.cfg index cbd36bf63e14..2eb760eca24e 100644 --- a/riscv/unittests.cfg +++ b/riscv/unittests.cfg @@ -16,4 +16,5 @@ groups = selftest # Set $FIRMWARE_OVERRIDE to /path/to/firmware to select the SBI implementation. [sbi] file = sbi.flat +smp = $MAX_SMP groups = sbi