From patchwork Wed Nov 6 11:38:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 2007485 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=0MPNlMTG; 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=DAvbv7zs; 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 4Xk4KY2sW4z1xyM for ; Wed, 6 Nov 2024 23:30:09 +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=0MPNlMTGMDWk/r xB4xkWWdCs68L0TF7nt1sNPFVSMWBoqIXctQ4dEwEzjWYKbFEdD/7BKGkpIoXBjmcAEm+veqdotIl cHq2eMtigGm+yTr7NUpJw1AY/8hIxCGWS2bYE0Y4y6XZ62jP1wFS4DuIwHwDxqlFyk7wGUtrqmqjW 0ERE2Awd+WBosIdq5Ghy5CTEi1cBo9lcgxz2dmdOJ4F01jaj+e5YNG7+R5Z5PqAxfd3IBLhLn65Na 6pfdf4m9tHxFFskPMCWgNoK+VB6N7l0wjT92TwkZ4lpLl3I0VnQrJOWb0Gkj58cqRVThzi52UZ2Gd mwsT2CPAenx5fBpgHLHg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t8fAm-00000003CIi-0fBP; Wed, 06 Nov 2024 12:30:08 +0000 Received: from out-186.mta0.migadu.com ([91.218.175.186]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t8eMj-00000002wo2-3Nyt for kvm-riscv@lists.infradead.org; Wed, 06 Nov 2024 11:38:27 +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=1730893103; 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=DAvbv7zs/SfPNk1LVBFE5rQsOlzAM2Bk+0rhx8Az5ssH2roZPbYm6nFYOHhF69DqjkdbXI aiAf9LTeVb3O/P+Bn372MgeGFRTK+SoVpy371ifF9X0TKPIXy6YUnwGOtv+RFafcp+9kvC +NcFHtIvH0HG9DsYCG4Par8HRE1Ca9U= 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 v2 1/3] riscv: Add sbi_send_ipi_broadcast Date: Wed, 6 Nov 2024 12:38:16 +0100 Message-ID: <20241106113814.42992-6-andrew.jones@linux.dev> In-Reply-To: <20241106113814.42992-5-andrew.jones@linux.dev> References: <20241106113814.42992-5-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-20241106_033826_023459_BFDC0392 X-CRM114-Status: UNSURE ( 9.21 ) X-CRM114-Notice: Please train this message. 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: 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.1 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 -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 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.186 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.186 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.186 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 Wed Nov 6 11:38:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 2007486 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=KDV0I05u; 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=h1pBx/cW; 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 4Xk4KY6r34z1xyX for ; Wed, 6 Nov 2024 23:30:09 +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=3FQVzSZOr+zkpmVMoyhv8DsO8+wMLJsniln6aryhALk=; b=KDV0I05urZgjsV 6kdLZXph6WuW4N6TVv3ia/UrRLhvxrpO4JpfwUQhrMkcOKS7+MJxDOKh4Z85Ax47ZfoMDXEwg1EAu UGwsF8bqJ2bFBvXFYa+ElAV0vwSPdo1W8kMJOTVFRXZzjZvWCjwLobs6QajK1kK9oz7Z0DQsqTFH9 2Nkfqg9Ugr3eqp99BjtVTYfVeZh6CYnt/AmGZchKfN233mBbXOFFFAP0kbShjSqJw9oRCbrH/9xSC Q9aQE8zSZJ/lzchCvtjoa6eCS/nRNqo3/xtbj1wzFC3FGAGsvErl3yS/md09OegubzkbfDN6GSCQn RAZ+Iy8pvx1G+9e8PN8g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t8fAm-00000003CJ1-28Sa; Wed, 06 Nov 2024 12:30:08 +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 1t8eMm-00000002wpf-3FPI for kvm-riscv@lists.infradead.org; Wed, 06 Nov 2024 11:38:30 +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=1730893106; 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=CVQZ+vtAuPPUPtcf7+iSeuuM3vx7C5aQKk0deTKTf1A=; b=h1pBx/cWxI8zDs59SGTH3rj39p+Vz3S38Wq5RcGJHtpPUqZeaXxmpBBil0q8IJM1wFjxZq hi8EHCRLcUUCvbTFPPssI7gUJgcqiTeBBu8LRfKmfyDadJiDSgl/pFHINt/0zgg7WUfhol KOj6xI5Tht7mCTJzwPNIvNHF7kgt9CU= 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 v2 2/3] riscv: sbi: Add IPI extension tests Date: Wed, 6 Nov 2024 12:38:17 +0100 Message-ID: <20241106113814.42992-7-andrew.jones@linux.dev> In-Reply-To: <20241106113814.42992-5-andrew.jones@linux.dev> References: <20241106113814.42992-5-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-20241106_033829_053649_9F5E259D X-CRM114-Status: GOOD ( 15.79 ) 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_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_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 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 -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.184 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 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 Co-developed-by: Andrew Jones Signed-off-by: Andrew Jones --- lib/cpumask.h | 13 ++++ riscv/sbi.c | 147 +++++++++++++++++++++++++++++++++++++++++++- riscv/unittests.cfg | 1 + 3 files changed, 159 insertions(+), 2 deletions(-) diff --git a/lib/cpumask.h b/lib/cpumask.h index 37d360786573..b4cd83a66a56 100644 --- a/lib/cpumask.h +++ b/lib/cpumask.h @@ -72,6 +72,19 @@ static inline bool cpumask_subset(const struct cpumask *src1, const struct cpuma return !lastmask || !((cpumask_bits(src1)[i] & ~cpumask_bits(src2)[i]) & lastmask); } +static inline bool cpumask_equal(const struct cpumask *src1, const struct cpumask *src2) +{ + unsigned long lastmask = BIT_MASK(nr_cpus) - 1; + int i; + + for (i = 0; i < BIT_WORD(nr_cpus); ++i) { + if (cpumask_bits(src1)[i] != cpumask_bits(src2)[i]) + return false; + } + + return !lastmask || (cpumask_bits(src1)[i] & lastmask) == (cpumask_bits(src2)[i] & lastmask); +} + static inline bool cpumask_empty(const cpumask_t *mask) { unsigned long lastmask = BIT_MASK(nr_cpus) - 1; diff --git a/riscv/sbi.c b/riscv/sbi.c index c081953c877c..cdf8d13cc9cf 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 @@ -46,6 +50,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; @@ -286,6 +304,130 @@ 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; + cpumask_t ipi_receivers; + static prng_state ps; + struct sbiret ret; + 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"); + cpumask_clear(&ipi_done); + cpumask_clear(&ipi_receivers); + cpu = rand_online_cpu(&ps); + cpumask_set_cpu(cpu, &ipi_receivers); + 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_equal(&ipi_done, &ipi_receivers)) + cpu_relax(); + ipi_hart_check(&ipi_receivers); + report_prefix_pop(); + + report_prefix_push("broadcast"); + cpumask_clear(&ipi_done); + cpumask_copy(&ipi_receivers, &cpu_present_mask); + cpumask_clear_cpu(me, &ipi_receivers); + on_cpumask_async(&ipi_receivers, ipi_hart_wait, (void *)d); + ret = sbi_send_ipi_broadcast(); + report(ret.error == SBI_SUCCESS, "ipi returned success"); + while (!cpumask_equal(&ipi_done, &ipi_receivers)) + cpu_relax(); + ipi_hart_check(&ipi_receivers); + 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_kfail(true, ret.error == SBI_ERR_INVALID_PARAM, "hart_mask got expected error (%ld)", ret.error); + 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); + + report_prefix_pop(); + + report_prefix_pop(); +} + #define DBCN_WRITE_TEST_STRING "DBCN_WRITE_TEST_STRING\n" #define DBCN_WRITE_BYTE_TEST_BYTE ((u8)'a') @@ -437,6 +579,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 From patchwork Wed Nov 6 11:38:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 2007487 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=W6yvBh+5; 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=S7nJ8xmY; 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 4Xk4KZ2818z1xyM for ; Wed, 6 Nov 2024 23:30:10 +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=Qz5RAq097tKFDHnTRgiBjdZSTKtrwsh0SnlUHa6lpsM=; b=W6yvBh+5NL2KGj sPzGCrXB1Lu9TyRglBRaMjy6YjFWUOB9yPb/Gafzgn63x/ccXHL/QVQogoUxPzj5tIbQZARBHhdVI ZOQ98fiQoIwcO5ekvWs1Q/bL3GZXPeBTuyJvdDjS+CD+jr0N723KLrb7kO8LHDyWVejUKkW44PyOz VATzRfzl16am5U0HlJ8hkPlqvXcZe1bzXwfMYoLauve+TyqBg4q1kPK8OyaBySBGFBDLc+vGE1rrj q+S/OPoaUr0eiJEgv58Es47IItO+uTWMXZfbR6o65buy20Ub7Kv9TJ+o/rMx4hvB06IqoXdohwNDW CFKZ3V5/qPKszuyFHe8w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t8fAn-00000003CJU-0Iz7; Wed, 06 Nov 2024 12:30:09 +0000 Received: from out-177.mta1.migadu.com ([95.215.58.177]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t8eMs-00000002wsF-32Vz for kvm-riscv@lists.infradead.org; Wed, 06 Nov 2024 11:38:36 +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=1730893112; 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=RPZ3SUBHEP/krVjbR2O6PIbvJJxePC2EroXXOKSSCDU=; b=S7nJ8xmYxMgu5etE4xqwe8IYMoEjgQUGtik2But4/mZBwT9zeFfIhTNGgwZTnBRhqKTjjZ nk6YDK4kJKrWGu+npE4tqPwPlDgsR6JfTzlgdrAKeiZXfD13o4+xZoFVexzx4gD9DOqLBr 4h0UpDGkf0INUPSYAwZwk7KvRsFbb0A= 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 v2 3/3] riscv: sbi: Add two in hart_mask IPI test Date: Wed, 6 Nov 2024 12:38:18 +0100 Message-ID: <20241106113814.42992-8-andrew.jones@linux.dev> In-Reply-To: <20241106113814.42992-5-andrew.jones@linux.dev> References: <20241106113814.42992-5-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-20241106_033834_933168_91B4B2E3 X-CRM114-Status: GOOD ( 10.83 ) 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: We should ensure that when hart_mask has more than one hartid that both harts get IPIs with a single call of the IPI function. Signed-off-by: Andrew Jones --- riscv/sbi.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 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 [95.215.58.177 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 -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 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. [95.215.58.177 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. [95.215.58.177 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. [95.215.58.177 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 We should ensure that when hart_mask has more than one hartid that both harts get IPIs with a single call of the IPI function. Signed-off-by: Andrew Jones --- riscv/sbi.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/riscv/sbi.c b/riscv/sbi.c index cdf8d13cc9cf..8ccdf42f902a 100644 --- a/riscv/sbi.c +++ b/riscv/sbi.c @@ -364,10 +364,11 @@ static void check_ipi(void) int nr_cpus_present = cpumask_weight(&cpu_present_mask); int me = smp_processor_id(); unsigned long max_hartid = 0; + unsigned long hartid1, hartid2; cpumask_t ipi_receivers; static prng_state ps; struct sbiret ret; - int cpu; + int cpu, cpu2; ps = prng_init(0xDEADBEEF); @@ -398,6 +399,42 @@ static void check_ipi(void) ipi_hart_check(&ipi_receivers); report_prefix_pop(); + report_prefix_push("two in hart_mask"); + + if (nr_cpus_present < 3) { + report_skip("3 cpus required"); + goto end_two; + } + + cpu = rand_online_cpu(&ps); + hartid1 = cpus[cpu].hartid; + hartid2 = 0; + for_each_present_cpu(cpu2) { + if (cpu2 == cpu || cpu2 == me) + continue; + hartid2 = cpus[cpu2].hartid; + if (__builtin_labs(hartid2 - hartid1) < BITS_PER_LONG) + break; + } + if (cpu2 == nr_cpus) { + report_skip("hartids are too sparse"); + goto end_two; + } + + cpumask_clear(&ipi_done); + cpumask_clear(&ipi_receivers); + cpumask_set_cpu(cpu, &ipi_receivers); + cpumask_set_cpu(cpu2, &ipi_receivers); + on_cpu_async(cpu, ipi_hart_wait, (void *)d); + on_cpu_async(cpu2, ipi_hart_wait, (void *)d); + ret = sbi_send_ipi((1UL << __builtin_labs(hartid2 - hartid1)) | 1UL, hartid1 < hartid2 ? hartid1 : hartid2); + report(ret.error == SBI_SUCCESS, "ipi returned success"); + while (!cpumask_equal(&ipi_done, &ipi_receivers)) + cpu_relax(); + ipi_hart_check(&ipi_receivers); +end_two: + report_prefix_pop(); + report_prefix_push("broadcast"); cpumask_clear(&ipi_done); cpumask_copy(&ipi_receivers, &cpu_present_mask);