From: Andrew Jones <andrew.jones@linux.dev>
To: kvm-riscv@lists.infradead.org
Cc: atishp@rivosinc.com, cleger@rivosinc.com, jamestiotio@gmail.com
Subject: [kvm-unit-tests PATCH v2 03/11] riscv: sbi: Ensure we have IPIs enabled for HSM suspend tests
Date: Thu, 27 Feb 2025 15:19:27 +0100 [thread overview]
Message-ID: <20250227141946.91604-16-andrew.jones@linux.dev> (raw)
In-Reply-To: <20250227141946.91604-13-andrew.jones@linux.dev>
We'll start cleaning up after each test, so the HSM tests need to
ensure they have IPIs setup themselves since they plan to use them.
Signed-off-by: Andrew Jones <andrew.jones@linux.dev>
---
riscv/sbi.c | 62 ++++++++++++++++++++++++++++++++---------------------
1 file changed, 37 insertions(+), 25 deletions(-)
diff --git a/riscv/sbi.c b/riscv/sbi.c
index 7c7a2d2ddddb..d7bf758e23fb 100644
--- a/riscv/sbi.c
+++ b/riscv/sbi.c
@@ -62,7 +62,7 @@ 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 struct sbiret sbi_hart_suspend(uint32_t suspend_type, unsigned long resume_addr, unsigned long opaque)
+static struct sbiret sbi_hart_suspend_raw(unsigned long suspend_type, unsigned long resume_addr, unsigned long opaque)
{
return sbi_ecall(SBI_EXT_HSM, SBI_EXT_HSM_HART_SUSPEND, suspend_type, resume_addr, opaque, 0, 0, 0);
}
@@ -568,59 +568,71 @@ static void hart_start_invalid_hartid(void *data)
sbi_hsm_invalid_hartid_check = true;
}
-static void hart_retentive_suspend(void *data)
+static void ipi_nop(struct pt_regs *regs)
+{
+ ipi_ack();
+}
+
+static void hart_suspend_and_wait_ipi(unsigned long suspend_type, unsigned long resume_addr,
+ unsigned long opaque, bool returns, const char *typestr)
{
unsigned long hartid = current_thread_info()->hartid;
- struct sbiret ret = sbi_hart_suspend(SBI_EXT_HSM_HART_SUSPEND_RETENTIVE, 0, 0);
+ struct sbiret ret;
+ install_irq_handler(IRQ_S_SOFT, ipi_nop);
+ local_ipi_enable();
+ local_irq_enable();
+
+ ret = sbi_hart_suspend_raw(suspend_type, resume_addr, opaque);
if (ret.error)
- report_fail("failed to retentive suspend cpu%d (hartid = %lx) (error=%ld)",
- smp_processor_id(), hartid, ret.error);
+ report_fail("failed to %s cpu%d (hartid = %lx) (error=%ld)",
+ typestr, smp_processor_id(), hartid, ret.error);
+ else if (!returns)
+ report_fail("failed to %s cpu%d (hartid = %lx) (call should not return)",
+ typestr, smp_processor_id(), hartid);
+
+ local_irq_disable();
+ local_ipi_disable();
+ install_irq_handler(IRQ_S_SOFT, NULL);
+}
+
+static void hart_retentive_suspend(void *data)
+{
+ hart_suspend_and_wait_ipi(SBI_EXT_HSM_HART_SUSPEND_RETENTIVE, 0, 0, true, "retentive suspend");
}
static void hart_non_retentive_suspend(void *data)
{
- unsigned long hartid = current_thread_info()->hartid;
unsigned long params[] = {
[SBI_HSM_MAGIC_IDX] = SBI_HSM_MAGIC,
- [SBI_HSM_HARTID_IDX] = hartid,
+ [SBI_HSM_HARTID_IDX] = current_thread_info()->hartid,
};
- struct sbiret ret = sbi_hart_suspend(SBI_EXT_HSM_HART_SUSPEND_NON_RETENTIVE,
- virt_to_phys(&sbi_hsm_check_non_retentive_suspend),
- virt_to_phys(params));
- report_fail("failed to non-retentive suspend cpu%d (hartid = %lx) (error=%ld)",
- smp_processor_id(), hartid, ret.error);
+ hart_suspend_and_wait_ipi(SBI_EXT_HSM_HART_SUSPEND_NON_RETENTIVE,
+ virt_to_phys(&sbi_hsm_check_non_retentive_suspend), virt_to_phys(params),
+ false, "non-retentive suspend");
}
/* This test function is only being run on RV64 to verify that upper bits of suspend_type are ignored */
static void hart_retentive_suspend_with_msb_set(void *data)
{
- unsigned long hartid = current_thread_info()->hartid;
unsigned long suspend_type = SBI_EXT_HSM_HART_SUSPEND_RETENTIVE | (_AC(1, UL) << (__riscv_xlen - 1));
- struct sbiret ret = sbi_ecall(SBI_EXT_HSM, SBI_EXT_HSM_HART_SUSPEND, suspend_type, 0, 0, 0, 0, 0);
- if (ret.error)
- report_fail("failed to retentive suspend cpu%d (hartid = %lx) with MSB set (error=%ld)",
- smp_processor_id(), hartid, ret.error);
+ hart_suspend_and_wait_ipi(suspend_type, 0, 0, true, "retentive suspend with MSB set");
}
/* This test function is only being run on RV64 to verify that upper bits of suspend_type are ignored */
static void hart_non_retentive_suspend_with_msb_set(void *data)
{
- unsigned long hartid = current_thread_info()->hartid;
unsigned long suspend_type = SBI_EXT_HSM_HART_SUSPEND_NON_RETENTIVE | (_AC(1, UL) << (__riscv_xlen - 1));
unsigned long params[] = {
[SBI_HSM_MAGIC_IDX] = SBI_HSM_MAGIC,
- [SBI_HSM_HARTID_IDX] = hartid,
+ [SBI_HSM_HARTID_IDX] = current_thread_info()->hartid,
};
- struct sbiret ret = sbi_ecall(SBI_EXT_HSM, SBI_EXT_HSM_HART_SUSPEND, suspend_type,
- virt_to_phys(&sbi_hsm_check_non_retentive_suspend), virt_to_phys(params),
- 0, 0, 0);
-
- report_fail("failed to non-retentive suspend cpu%d (hartid = %lx) with MSB set (error=%ld)",
- smp_processor_id(), hartid, ret.error);
+ hart_suspend_and_wait_ipi(suspend_type,
+ virt_to_phys(&sbi_hsm_check_non_retentive_suspend), virt_to_phys(params),
+ false, "non-retentive suspend with MSB set");
}
static bool hart_wait_on_status(unsigned long hartid, enum sbi_ext_hsm_sid status, unsigned long duration)
--
2.48.1
--
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv
next prev parent reply other threads:[~2025-02-27 14:43 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-27 14:19 [kvm-unit-tests PATCH v2 00/11] riscv: sbi: Test improvements and a couple new Andrew Jones
2025-02-27 14:19 ` [kvm-unit-tests PATCH v2 01/11] riscv: sbi: Drop fwft upper bits test Andrew Jones
2025-02-27 14:21 ` Clément Léger
2025-02-27 14:19 ` [kvm-unit-tests PATCH v2 02/11] riscv: sbi: Add fwft pte_hw_ad_updating test Andrew Jones
2025-02-27 14:30 ` Clément Léger
2025-02-27 14:19 ` Andrew Jones [this message]
2025-02-27 14:19 ` [kvm-unit-tests PATCH v2 04/11] riscv: sbi: Ensure SUSP test gets an interrupt Andrew Jones
2025-02-27 14:19 ` [kvm-unit-tests PATCH v2 05/11] riscv: sbi: Improve susp expected error output Andrew Jones
2025-02-27 14:38 ` Clément Léger
2025-02-27 14:19 ` [kvm-unit-tests PATCH v2 06/11] riscv: sbi: Improve interrupt handling cleanup Andrew Jones
2025-02-27 14:19 ` [kvm-unit-tests PATCH v2 07/11] lib/cpumask: Add some operators Andrew Jones
2025-02-27 14:22 ` [kvm-unit-tests PATCH v2 08/11] riscv: sbi: HSM suspend may not be supported Andrew Jones
2025-02-27 14:22 ` [kvm-unit-tests PATCH v2 09/11] riscv: sbi: Probe/skip SUSP Andrew Jones
2025-02-27 14:22 ` [kvm-unit-tests PATCH v2 10/11] riscv: sbi: susp: Check upper bits of sleep_type are ignored Andrew Jones
2025-02-27 14:22 ` [kvm-unit-tests PATCH v2 11/11] riscv: sbi: Add bad fid tests Andrew Jones
2025-02-27 14:33 ` Clément Léger
2025-03-04 9:31 ` [kvm-unit-tests PATCH v2 00/11] riscv: sbi: Test improvements and a couple new Andrew Jones
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250227141946.91604-16-andrew.jones@linux.dev \
--to=andrew.jones@linux.dev \
--cc=atishp@rivosinc.com \
--cc=cleger@rivosinc.com \
--cc=jamestiotio@gmail.com \
--cc=kvm-riscv@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).