From patchwork Sun Aug 25 17:08:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Raphael Tiovalen X-Patchwork-Id: 13776840 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D5FF315442A for ; Sun, 25 Aug 2024 17:08:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724605719; cv=none; b=pQg+4e94W45Bl6ObyddosA9yon1yYw0qFMguiVaWffiPTEernFDAZm0t7/0vq+dF2desDNO5C1fZZFYoMxUHAE10o7CjvIA+5uS2BATMxI7Ekgx1hxIT/+080VIISrB7v/EenFXMZbZqwllNAefFpjR14w/Rlktr4slBO9foJu0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724605719; c=relaxed/simple; bh=3dmDRLqbgjk6WsCgvQb/v8iExYY8qXNF7IuvGb4qIyQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YbfAeADUB/F6AkgWbDW5JBJg2Ugpjt7pPNNoo/9zG5cjO5hIGsyfnNbaMV0iNS/H8bIZyOKzdc8Keje1IfxDRmClQzHpMaKGQh7vFtmk9gWwv38RXttqwQIUblG7fg5EiUXAc5Gytc/aVSQWNzZIfhKN3PSSZZJMQVOhrK1pKBc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=jqi3O6es; arc=none smtp.client-ip=209.85.214.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jqi3O6es" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-20231aa8908so27013735ad.0 for ; Sun, 25 Aug 2024 10:08:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724605717; x=1725210517; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3uvZgdBkzqRgKxJdiD6ICI93DbcAzIJAn5xzIEe2DlE=; b=jqi3O6esmiyLdsxxxwoKO6uUri0CnntQBa6dX48rErimmZGxhk9gU9Z9U8neALUijM oAoQOiG3bRemYfLPhavQGxL4y9j1t1NDP1yfo9ZTQYTopOu8cmWywi2L6i/yh4RYIJOo SJCKbJyS7aWx6RGkSjP+0nuDC0JSm6iz2/SIzjzXuJDbFXI/7J7RsWe5Q/9pjYuhWMZq /8SFbdLPzhDKrjMw9jO/0Et3aP5ojvfereZ/T3f8pxl/XGEK/7QMEKRuXKQlXkpe/oc0 HgYt8wPHk3VdgDXpO5DOIG2Dt3DqOp4GQMAbeAIQn+gdfjuA2mc2/7iCBl7Awmd3HS2H ZTKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724605717; x=1725210517; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3uvZgdBkzqRgKxJdiD6ICI93DbcAzIJAn5xzIEe2DlE=; b=S4TlgezOaoCCsl3PNVnOdr+6Zixht4XukwGrGLHjuH2ky0t/j6Ac1lBtsTuANelMOa QEgeg0BA8WhHnDRq/h+6m7QcXHF21ayOHbtfZJouUnOvFaA301DzfEmYikr2xVrXJcs9 pPyT9IBgBlpjk1Wrxufsi7u5SCt6B4tQMtM5rLMGbAHGYMzc169SZzdWmaA1TZZd1s+V TEPTAg2qK8/5R0C6uRhBhEOawJslMejnmgyyvOAOaG8/kXwMTo9r0JSHoV2a2b3cH1el oyC04066lyhr7EbOD+8R/u5xONagRIth09NToz06oqE09VSWSAWcz6zOAZMbfTACMOQW Vhug== X-Gm-Message-State: AOJu0YweKzs7CRLGn0zxjieD9Y63INOqFT0rKkoDGVb4camHZ5efomvY BSupoFloTQt2UskNlxXu+bVYv2y8BQ7xJ063dtFuiOE/kJSJnyiQrxdxgDKj X-Google-Smtp-Source: AGHT+IE9/Dpje8Upv5MAJrw8Ui4K2DOheALKcYSW+r6BB5Zuv3KXlXZl0VXnkGhl9noA7oy5EnQVRw== X-Received: by 2002:a17:903:22c9:b0:201:cda4:69cb with SMTP id d9443c01a7336-2039e4a8fedmr77819525ad.9.1724605716549; Sun, 25 Aug 2024 10:08:36 -0700 (PDT) Received: from JRT-PC.. ([202.166.44.78]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-203855dd985sm56083165ad.164.2024.08.25.10.08.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Aug 2024 10:08:36 -0700 (PDT) From: James Raphael Tiovalen To: kvm@vger.kernel.org, kvm-riscv@lists.infradead.org Cc: andrew.jones@linux.dev, atishp@rivosinc.com, cade.richard@berkeley.edu, James Raphael Tiovalen Subject: [kvm-unit-tests PATCH v2 1/4] lib/report: Add helper methods to clear multiple prefixes Date: Mon, 26 Aug 2024 01:08:21 +0800 Message-ID: <20240825170824.107467-2-jamestiotio@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240825170824.107467-1-jamestiotio@gmail.com> References: <20240825170824.107467-1-jamestiotio@gmail.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add a method to pop a specified number of prefixes and another method to clear all prefixes. Suggested-by: Andrew Jones Signed-off-by: James Raphael Tiovalen --- lib/libcflat.h | 2 ++ lib/report.c | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/libcflat.h b/lib/libcflat.h index 16a83880..0286ddec 100644 --- a/lib/libcflat.h +++ b/lib/libcflat.h @@ -96,6 +96,8 @@ void report_prefix_pushf(const char *prefix_fmt, ...) __attribute__((format(printf, 1, 2))); extern void report_prefix_push(const char *prefix); extern void report_prefix_pop(void); +extern void report_prefix_popn(int n); +extern void report_prefix_clear(void); extern void report(bool pass, const char *msg_fmt, ...) __attribute__((format(printf, 2, 3), nonnull(2))); extern void report_xfail(bool xfail, bool pass, const char *msg_fmt, ...) diff --git a/lib/report.c b/lib/report.c index 7f3c4f05..d45afedc 100644 --- a/lib/report.c +++ b/lib/report.c @@ -80,6 +80,19 @@ void report_prefix_pop(void) spin_unlock(&lock); } +void report_prefix_popn(int n) +{ + while (n--) + report_prefix_pop(); +} + +void report_prefix_clear(void) +{ + spin_lock(&lock); + prefixes[0] = '\0'; + spin_unlock(&lock); +} + static void va_report(const char *msg_fmt, bool pass, bool xfail, bool kfail, bool skip, va_list va) { From patchwork Sun Aug 25 17:08:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Raphael Tiovalen X-Patchwork-Id: 13776841 Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 27A9716B385 for ; Sun, 25 Aug 2024 17:08:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724605721; cv=none; b=mTyekVG6xXE3DuLFq6yAVD/FpeOZOS8KkGoOF7zuTyKk9Vt5rkLIaeMI6hstTFyHzW86g4prylL7m/42mkFC8pAsOU+fdCTdELwDSr+LcoO6hHp2Tte7Mv8vIbjcxLSNvWyFq9imZij0JtIZDmojRUqeXCseksF2X2WqRpYSano= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724605721; c=relaxed/simple; bh=LmCO7WYGCC4UfmJqvJeP5lbrEtWp9P+qyQs7RPqh5U4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=X+YkByv+PRDUKBzQvh0t36CvojW77iG/i+FPPggmZh0H/CJ7Z7ILIwrskfI9EnqEPBKGYuM7pv4NN4njVBkgQkyE0b5RjWPLhS9k6BurCjHAStAhigp3v4bcw7ErU7IcEhiDbSmg6R3XmdhkspFs2AoWKIkCN5Qncm/qLlYbgWA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Ene3xXKS; arc=none smtp.client-ip=209.85.215.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Ene3xXKS" Received: by mail-pg1-f175.google.com with SMTP id 41be03b00d2f7-7c3e1081804so2096293a12.3 for ; Sun, 25 Aug 2024 10:08:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724605719; x=1725210519; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=OpNs22/pulDn9EZCJ53fTAiUtjwD32EvR4w6J/z7Ezc=; b=Ene3xXKSKyaObx710cwvXThr2DJO4gSmqnKfA0qRA6SHx6jwggu06Q0jsCf7GmEjpS tI4b3+op4mKCej/watnBBjoGhyG2beEFwoeAJ23qLw8EXqgjaduPgDsIak9iHWpx+3jd Iqa9vJiAXh70AkrQ0Psvy0gTzv3rwFcGpi1O9xKwTRz5FiMM6RGZy/QDwUKDEqUA5fYn WUAAOfNkJOYXkP4JhpCn30WQFYP/A9L7DDgNfkDim2BHDAXpiOfsf8HjqkZ2PJPwxhOI URKkMEeTOPE9RrlDAyyxYcFmXPB3qaeUWa/6PGmMqJPcb/E8eu+oCbCY5usCTeundyWv 9gbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724605719; x=1725210519; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OpNs22/pulDn9EZCJ53fTAiUtjwD32EvR4w6J/z7Ezc=; b=qfvPuquPwp7wpxvaj+ExazvEjmhZzKiwhFfrJ4eFs7dFlpItKbHUE2VDkZiqi6AQgn aGc82GNrTo1Uw0mXnC1kuw0c/n8jqkPX1megr129rxd8OmJBxbC2+3QglkIiWd1Hikbg DCajK91vT6ybPcbkmb9FDoQHyui8uKRLRhbUlTzLVL6ajG0RQPR6ULR9MWXklYPV69yD YDfwRrcNEJUSWRUaFVlKHoNxvY2lNNpkae9ZvYeNEce7hAeB9VL81WatFKXhh7sooSeh sg0bRUlH5imAyRgy+eZKzbR6Zt5wRNB72uND+pkDl3CpoD/3k8tqsuxaNobE1REFjspJ iWvw== X-Gm-Message-State: AOJu0YxrLS4BwRHpf33ZVlnd+WTB4WU5Z/SNdsiHtT9eZ/uzXIiWTKCQ IXTq5ZV1fKXpUiA3CES//QQr/tZBfq/p9LR5r43jIuG/srQpbOJjCbsAYn9y X-Google-Smtp-Source: AGHT+IGbsYg+h5bAdNUHI2eUlxM5CFhQGrj73ZM/hb+QDkq1R4yeITyP/ZwpkMtw60F4N1W6uwVH2A== X-Received: by 2002:a05:6a20:cf90:b0:1c6:fb2a:4696 with SMTP id adf61e73a8af0-1cc89d6bac4mr7566434637.19.1724605718842; Sun, 25 Aug 2024 10:08:38 -0700 (PDT) Received: from JRT-PC.. ([202.166.44.78]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-203855dd985sm56083165ad.164.2024.08.25.10.08.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Aug 2024 10:08:38 -0700 (PDT) From: James Raphael Tiovalen To: kvm@vger.kernel.org, kvm-riscv@lists.infradead.org Cc: andrew.jones@linux.dev, atishp@rivosinc.com, cade.richard@berkeley.edu, James Raphael Tiovalen Subject: [kvm-unit-tests PATCH v2 2/4] riscv: sbi: Add IPI extension support Date: Mon, 26 Aug 2024 01:08:22 +0800 Message-ID: <20240825170824.107467-3-jamestiotio@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240825170824.107467-1-jamestiotio@gmail.com> References: <20240825170824.107467-1-jamestiotio@gmail.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add IPI EID and FID constants and a helper function to perform the IPI SBI ecall. Signed-off-by: James Raphael Tiovalen --- lib/riscv/asm/sbi.h | 6 ++++++ lib/riscv/sbi.c | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/lib/riscv/asm/sbi.h b/lib/riscv/asm/sbi.h index 47e91025..a864e268 100644 --- a/lib/riscv/asm/sbi.h +++ b/lib/riscv/asm/sbi.h @@ -17,6 +17,7 @@ enum sbi_ext_id { SBI_EXT_BASE = 0x10, SBI_EXT_TIME = 0x54494d45, + SBI_EXT_IPI = 0x735049, SBI_EXT_HSM = 0x48534d, SBI_EXT_SRST = 0x53525354, SBI_EXT_DBCN = 0x4442434E, @@ -43,6 +44,10 @@ enum sbi_ext_time_fid { SBI_EXT_TIME_SET_TIMER = 0, }; +enum sbi_ext_ipi_fid { + SBI_EXT_IPI_SEND_IPI = 0, +}; + enum sbi_ext_dbcn_fid { SBI_EXT_DBCN_CONSOLE_WRITE = 0, SBI_EXT_DBCN_CONSOLE_READ, @@ -61,6 +66,7 @@ struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0, void sbi_shutdown(void); struct sbiret sbi_hart_start(unsigned long hartid, unsigned long entry, unsigned long sp); +struct sbiret sbi_send_ipi(unsigned long hart_mask, unsigned long hart_mask_base); long sbi_probe(int ext); #endif /* !__ASSEMBLY__ */ diff --git a/lib/riscv/sbi.c b/lib/riscv/sbi.c index 3d4236e5..19d58ab7 100644 --- a/lib/riscv/sbi.c +++ b/lib/riscv/sbi.c @@ -39,6 +39,11 @@ struct sbiret sbi_hart_start(unsigned long hartid, unsigned long entry, unsigned return sbi_ecall(SBI_EXT_HSM, SBI_EXT_HSM_HART_START, hartid, entry, sp, 0, 0, 0); } +struct sbiret sbi_send_ipi(unsigned long hart_mask, unsigned long hart_mask_base) +{ + return sbi_ecall(SBI_EXT_IPI, SBI_EXT_IPI_SEND_IPI, hart_mask, hart_mask_base, 0, 0, 0, 0); +} + long sbi_probe(int ext) { struct sbiret ret; From patchwork Sun Aug 25 17:08:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Raphael Tiovalen X-Patchwork-Id: 13776842 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 64B8316F0C6 for ; Sun, 25 Aug 2024 17:08:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724605723; cv=none; b=KuNNwv3MA+cO9XWB0/MYlpB9/VtD/l1OO60kmyOA8ARfwLnG115nCEI8fF6G6xC9VFxAAMVSXYwqLNtPNGMOVsReubzBihiAaYIS1cLOVQyXOif5yl1O3K48BcdL9E/qcqsLcgaXswi5PlTGrCuVbIsw4NZ6RrrcYz01agJlpX8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724605723; c=relaxed/simple; bh=tyBlGvQ4IpzB2ul/Qu+0jHPBIGsIUSGhkR9hzLEpGtc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gvzObrpjSaZ2+Mo3JuJGtf9VwWQI4GZUOqIy/e+ILrn4Zxc9UQ2STmqMU7MQadDS9cxG8ysqX2RCoj+5N8ObzQ3CH/GbfzXFJWfp0dWZ2aumOfyducGbjEhFWT7Tpd22ImRxOWnZh3fFL3EaVdf6uLugI4Vd7icFOjI+yaOaCkA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=NlRfIt4h; arc=none smtp.client-ip=209.85.214.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NlRfIt4h" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-20202df1c2fso29078525ad.1 for ; Sun, 25 Aug 2024 10:08:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724605721; x=1725210521; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gckUWFxhpGbWVlGAGlzsWH3byBepNJj4AE/d1tkaAcc=; b=NlRfIt4hK+rHi5tMtWOhjiSDcM+Mv2rE506LBDBT1vHXqlvv6qz205R3NZZWV22k+b 4s+Dh9hrEPTFP4fjLYVKx0gNL7mKyVDcDRyGN7djWbiCXH2M/EuEnNubligvDB6dE7X3 TU3fqfUjcPAAo80KDQhLDX6QWhdj1a2NWwjMEPjlNN11BBi5OQLLIEJJlA+BLAVLNNcz NbzGzKONIFWXqHw1faIb3Tw2+HL8qtv1owIfTaeE3rQQzCATTFVGNRSHQ9RCESDNz8Sl h8PivztlDWtU/HfVzd79jThpOyCOEPcO61VmX8nULThHokfPBguXFTtBzwnw8UeXfAuV 2U1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724605721; x=1725210521; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gckUWFxhpGbWVlGAGlzsWH3byBepNJj4AE/d1tkaAcc=; b=jEfTZ1OZo/7+t++JzA6cP7BTTQ31pJZ078oOwDAxWZ2oKEDMIoyzO0CTj2/8gbSn1I sv68RIv572BCU7lekoVLRCuep5NB529T30dQHapmGyaWaPvmZnSE8a6+wDXtw8eOwEp5 brdmQ7qRaoCJfl05Vpoq/PZFC5JGgNKwdN5DKCAP0KqCnSlwgXGKFfennw5wfxgvt0J/ VhhFSe/hZ6WhugevItr856hKLyxGVhVC406b1rsP38mp5ToE2T9LqSMl8KkA5/WZ3utd kZA522BJVubqN9SlYliA+0G1HkY5mzBnk+z89bp6eqKsO4mjfy+uSno3QbnuiInmQgba CWmg== X-Gm-Message-State: AOJu0Ywc89cU5dol0wbdrs3p/hSUIP7DtL/ExO2WROqEKQJOFBAKfXG+ Y/aS2xODjy5l/X6sHe9ivZAmcqRnSyKq2iN5pW/LDMYJV1Rj5lyeyUO+7xMQ X-Google-Smtp-Source: AGHT+IHZzM/qViHLzQpOrmEC/WRNtKeiND6zRKFGZ5NNcOHQwbqPlhRQOWaK/R3e/WS76nMTxpy+Gw== X-Received: by 2002:a17:902:f68c:b0:1f9:d6bf:a67c with SMTP id d9443c01a7336-2039c31cca4mr128706135ad.5.1724605720939; Sun, 25 Aug 2024 10:08:40 -0700 (PDT) Received: from JRT-PC.. ([202.166.44.78]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-203855dd985sm56083165ad.164.2024.08.25.10.08.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Aug 2024 10:08:40 -0700 (PDT) From: James Raphael Tiovalen To: kvm@vger.kernel.org, kvm-riscv@lists.infradead.org Cc: andrew.jones@linux.dev, atishp@rivosinc.com, cade.richard@berkeley.edu, James Raphael Tiovalen Subject: [kvm-unit-tests PATCH v2 3/4] riscv: sbi: Add HSM extension functions Date: Mon, 26 Aug 2024 01:08:23 +0800 Message-ID: <20240825170824.107467-4-jamestiotio@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240825170824.107467-1-jamestiotio@gmail.com> References: <20240825170824.107467-1-jamestiotio@gmail.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add helper functions to perform hart-related operations to prepare for the HSM tests. Also add the HSM state IDs and default suspend type constants. Signed-off-by: James Raphael Tiovalen Reviewed-by: Andrew Jones --- lib/riscv/asm/sbi.h | 17 +++++++++++++++++ lib/riscv/sbi.c | 10 ++++++++++ riscv/sbi.c | 5 +++++ 3 files changed, 32 insertions(+) diff --git a/lib/riscv/asm/sbi.h b/lib/riscv/asm/sbi.h index a864e268..4e48ceaa 100644 --- a/lib/riscv/asm/sbi.h +++ b/lib/riscv/asm/sbi.h @@ -48,6 +48,21 @@ enum sbi_ext_ipi_fid { SBI_EXT_IPI_SEND_IPI = 0, }; +enum sbi_ext_hsm_sid { + SBI_EXT_HSM_STARTED = 0, + SBI_EXT_HSM_STOPPED, + SBI_EXT_HSM_START_PENDING, + SBI_EXT_HSM_STOP_PENDING, + SBI_EXT_HSM_SUSPENDED, + SBI_EXT_HSM_SUSPEND_PENDING, + SBI_EXT_HSM_RESUME_PENDING, +}; + +enum sbi_ext_hsm_hart_suspend_type { + SBI_EXT_HSM_HART_SUSPEND_RETENTIVE = 0, + SBI_EXT_HSM_HART_SUSPEND_NON_RETENTIVE = 0x80000000, +}; + enum sbi_ext_dbcn_fid { SBI_EXT_DBCN_CONSOLE_WRITE = 0, SBI_EXT_DBCN_CONSOLE_READ, @@ -66,6 +81,8 @@ struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0, void sbi_shutdown(void); struct sbiret sbi_hart_start(unsigned long hartid, unsigned long entry, unsigned long sp); +struct sbiret sbi_hart_stop(void); +struct sbiret sbi_hart_get_status(unsigned long hartid); struct sbiret sbi_send_ipi(unsigned long hart_mask, unsigned long hart_mask_base); long sbi_probe(int ext); diff --git a/lib/riscv/sbi.c b/lib/riscv/sbi.c index 19d58ab7..256196b7 100644 --- a/lib/riscv/sbi.c +++ b/lib/riscv/sbi.c @@ -39,6 +39,16 @@ struct sbiret sbi_hart_start(unsigned long hartid, unsigned long entry, unsigned return sbi_ecall(SBI_EXT_HSM, SBI_EXT_HSM_HART_START, hartid, entry, sp, 0, 0, 0); } +struct sbiret sbi_hart_stop(void) +{ + return sbi_ecall(SBI_EXT_HSM, SBI_EXT_HSM_HART_STOP, 0, 0, 0, 0, 0, 0); +} + +struct sbiret sbi_hart_get_status(unsigned long hartid) +{ + return sbi_ecall(SBI_EXT_HSM, SBI_EXT_HSM_HART_STATUS, hartid, 0, 0, 0, 0, 0); +} + struct sbiret sbi_send_ipi(unsigned long hart_mask, unsigned long hart_mask_base) { return sbi_ecall(SBI_EXT_IPI, SBI_EXT_IPI_SEND_IPI, hart_mask, hart_mask_base, 0, 0, 0, 0); diff --git a/riscv/sbi.c b/riscv/sbi.c index 36ddfd48..6469304b 100644 --- a/riscv/sbi.c +++ b/riscv/sbi.c @@ -72,6 +72,11 @@ static phys_addr_t get_highest_addr(void) return highest_end - 1; } +static struct sbiret sbi_hart_suspend(uint32_t 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); +} + static bool env_or_skip(const char *env) { if (!getenv(env)) { From patchwork Sun Aug 25 17:08:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Raphael Tiovalen X-Patchwork-Id: 13776843 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CCC9B16F273 for ; Sun, 25 Aug 2024 17:08:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724605726; cv=none; b=a18FedfLiKYmTnTERqkmQZfIPdNIk3qJ3QY9E1QW/V8oCtPJpupAEq52hnpKf1CftjvOuhMr5mpZBkxH9Tct/FDsTKOVzsXwFt78vBnP0NiEftzKxYC8gMOmxB3SN/jDsoRA15phT5f7welOMgaU0EJPnZJc03iEgIBObpV2X9I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724605726; c=relaxed/simple; bh=maoNae85CCqTT7K9OY62uSidL0LqV8Fj48Xw+e3iXp4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Al/aXwob6kryUNW8eRv4R/XgMC9PJ3HcdnWT26/z1X2x3qn1f379UwEl0jRmKSXl3v7EHElH7BZtRpZNdFwlq9UBzaRiIGEk1ynxLP7oYzjNfQnpJr+rfUkPe3MHacd9SS917pnbWbqi5RLns3MmCJ3owDz/b5kW81QtlSA3yFQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ISMyEHVQ; arc=none smtp.client-ip=209.85.214.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ISMyEHVQ" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-201ee6b084bso29604875ad.2 for ; Sun, 25 Aug 2024 10:08:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724605723; x=1725210523; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lUzCQefNyTL9tkyHPQdjVTYyES/LTP6VixeQz23zJug=; b=ISMyEHVQ9v1pd2nTkEa/zw51CgIuWyzQ4COVqw658J5aEpveUIenLE4Clb/GwbgVn3 6B2D0z1IiyXy0YMOFRyU2C6gLFdyBch3nmBVlQY+9EMrW/c3yL3lvdDyaNO6NaX0LPe1 xM4//p3Io3yd12+3P/CLB7J3iNH4o0nF1GqZHQul03Ydeq1ch//7QDAwYR1BhQowqRL8 NHBahLvsyAfa7t5y+/SLcixBQ6Wux6h+RMOu+eGpltpAvW4Jp/W6QetWRzAfCsVj8lAh jZ5eZtRLR26Hjr0y6A07J86u9xxAvEqoEoK9lADi2b9YxH6IIUrLqqlVXJ13yHl1pRhq KjcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724605723; x=1725210523; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lUzCQefNyTL9tkyHPQdjVTYyES/LTP6VixeQz23zJug=; b=JDprAle5zI/1se17BifKEPIJMDlDxIHuh4dVMXH5R0KOFDtztUfse0pUQHus5wr8sN 9f1nH569727YZZAmU3kYrrtNUFad9KpZs3kLMUtgBK2p1Uf2Gce0WsEhFGybkphWpSXs 9DVT3YBdT7axgqEnN/3iOFXv/W9bgvLmuuBOYxU3KmWeY4hcHEl/YHAQIvW5oaJOcxcE r4ewLHc4kGo8lqwG0UJEfpokv7wZh5du5K//IfnqC5AxYNW+IDIOmVAeSwC4XIgzy7Ym BV7b1e2g4AY7YWx64gcW58uuLh9K5RBjLD2kWpGcT4Ns3QQ0N1cHJHOj6+2WasjRtlIY PmFw== X-Gm-Message-State: AOJu0YyN8H0iqz27B6BT7DFhUKACNEWYJdxn5ePFuDC+pGnbaYUeWoGv 7epbvO02vkszuCve9oBbysANAtzCd99wb5+DteYQo3qLz9i4rzVoRf5iRyli X-Google-Smtp-Source: AGHT+IHSMra+TZeq7WaJtXtWwt/rEXBtykcPthl5euqqudAP4rvqh1ngyOshr+1O2GkNogelorLzAw== X-Received: by 2002:a17:902:db0e:b0:1fc:5ed5:ff56 with SMTP id d9443c01a7336-2039e54a903mr90611115ad.61.1724605723228; Sun, 25 Aug 2024 10:08:43 -0700 (PDT) Received: from JRT-PC.. ([202.166.44.78]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-203855dd985sm56083165ad.164.2024.08.25.10.08.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Aug 2024 10:08:42 -0700 (PDT) From: James Raphael Tiovalen To: kvm@vger.kernel.org, kvm-riscv@lists.infradead.org Cc: andrew.jones@linux.dev, atishp@rivosinc.com, cade.richard@berkeley.edu, James Raphael Tiovalen Subject: [kvm-unit-tests PATCH v2 4/4] riscv: sbi: Add tests for HSM extension Date: Mon, 26 Aug 2024 01:08:24 +0800 Message-ID: <20240825170824.107467-5-jamestiotio@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240825170824.107467-1-jamestiotio@gmail.com> References: <20240825170824.107467-1-jamestiotio@gmail.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add some tests for all of the HSM extension functions. These tests ensure that the HSM extension functions follow the behavior as described in the SBI specification. Signed-off-by: James Raphael Tiovalen --- riscv/Makefile | 7 +- riscv/sbi-asm.S | 79 ++++++++++ riscv/sbi.c | 382 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 465 insertions(+), 3 deletions(-) create mode 100644 riscv/sbi-asm.S diff --git a/riscv/Makefile b/riscv/Makefile index 179a373d..548041ad 100644 --- a/riscv/Makefile +++ b/riscv/Makefile @@ -43,6 +43,7 @@ cflatobjs += lib/riscv/timer.o ifeq ($(ARCH),riscv32) cflatobjs += lib/ldiv32.o endif +cflatobjs += riscv/sbi-asm.o ######################################## @@ -99,7 +100,7 @@ cflatobjs += lib/efi.o .PRECIOUS: %.so %.so: EFI_LDFLAGS += -defsym=EFI_SUBSYSTEM=0xa --no-undefined -%.so: %.o $(FLATLIBS) $(SRCDIR)/riscv/efi/elf_riscv64_efi.lds $(cstart.o) %.aux.o +%.so: %.o $(FLATLIBS) $(SRCDIR)/riscv/efi/elf_riscv64_efi.lds $(cstart.o) $(sbi-asm.o) %.aux.o $(LD) $(EFI_LDFLAGS) -o $@ -T $(SRCDIR)/riscv/efi/elf_riscv64_efi.lds \ $(filter %.o, $^) $(FLATLIBS) $(EFI_LIBS) @@ -115,7 +116,7 @@ cflatobjs += lib/efi.o -O binary $^ $@ else %.elf: LDFLAGS += -pie -n -z notext -%.elf: %.o $(FLATLIBS) $(SRCDIR)/riscv/flat.lds $(cstart.o) %.aux.o +%.elf: %.o $(FLATLIBS) $(SRCDIR)/riscv/flat.lds $(cstart.o) $(sbi-asm.o) %.aux.o $(LD) $(LDFLAGS) -o $@ -T $(SRCDIR)/riscv/flat.lds \ $(filter %.o, $^) $(FLATLIBS) @chmod a-x $@ @@ -127,7 +128,7 @@ else endif generated-files = $(asm-offsets) -$(tests:.$(exe)=.o) $(cstart.o) $(cflatobjs): $(generated-files) +$(tests:.$(exe)=.o) $(cstart.o) $(sbi-asm.o) $(cflatobjs): $(generated-files) arch_clean: asm_offsets_clean $(RM) $(TEST_DIR)/*.{o,flat,elf,so,efi,debug} \ diff --git a/riscv/sbi-asm.S b/riscv/sbi-asm.S new file mode 100644 index 00000000..f31bc096 --- /dev/null +++ b/riscv/sbi-asm.S @@ -0,0 +1,79 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Helper assembly code routines for RISC-V SBI extension tests. + * + * Copyright (C) 2024, James Raphael Tiovalen + */ +#define __ASSEMBLY__ +#include +#include +#include + +#define SBI_HSM_TEST_DONE (1 << 0) +#define SBI_HSM_TEST_SATP (1 << 1) +#define SBI_HSM_TEST_SIE (1 << 2) +#define SBI_HSM_TEST_HARTID_A1 (1 << 3) + +.section .text +.balign 4 +.global sbi_hsm_check_hart_start +sbi_hsm_check_hart_start: + li t0, 0 + csrr t1, CSR_SATP + bnez t1, 1f + li t0, SBI_HSM_TEST_SATP +1: csrr t1, CSR_SSTATUS + andi t1, t1, SR_SIE + bnez t1, 2f + ori t0, t0, SBI_HSM_TEST_SIE +2: bne a0, a1, 3f + ori t0, t0, SBI_HSM_TEST_HARTID_A1 +3: ori t0, t0, SBI_HSM_TEST_DONE + la t1, sbi_hsm_hart_start_checks + add t1, t1, a0 + sb t0, 0(t1) +4: la t0, sbi_hsm_stop_hart + add t0, t0, a0 + lb t0, 0(t0) + pause + beqz t0, 4b + li a7, 0x48534d /* SBI_EXT_HSM */ + li a6, 1 /* SBI_EXT_HSM_HART_STOP */ + ecall + j halt + +.balign 4 +.global sbi_hsm_check_non_retentive_suspend +sbi_hsm_check_non_retentive_suspend: + li t0, 0 + csrr t1, CSR_SATP + bnez t1, 1f + li t0, SBI_HSM_TEST_SATP +1: csrr t1, CSR_SSTATUS + andi t1, t1, SR_SIE + bnez t1, 2f + ori t0, t0, SBI_HSM_TEST_SIE +2: bne a0, a1, 3f + ori t0, t0, SBI_HSM_TEST_HARTID_A1 +3: ori t0, t0, SBI_HSM_TEST_DONE + la t1, sbi_hsm_non_retentive_hart_suspend_checks + add t1, t1, a0 + sb t0, 0(t1) +4: la t0, sbi_hsm_stop_hart + add t0, t0, a0 + lb t0, 0(t0) + pause + beqz t0, 4b + li a7, 0x48534d /* SBI_EXT_HSM */ + li a6, 1 /* SBI_EXT_HSM_HART_STOP */ + ecall + j halt + +.section .data +.balign PAGE_SIZE +.global sbi_hsm_hart_start_checks +sbi_hsm_hart_start_checks: .space CONFIG_NR_CPUS +.global sbi_hsm_non_retentive_hart_suspend_checks +sbi_hsm_non_retentive_hart_suspend_checks: .space CONFIG_NR_CPUS +.global sbi_hsm_stop_hart +sbi_hsm_stop_hart: .space CONFIG_NR_CPUS diff --git a/riscv/sbi.c b/riscv/sbi.c index 6469304b..25fc2e81 100644 --- a/riscv/sbi.c +++ b/riscv/sbi.c @@ -6,6 +6,8 @@ */ #include #include +#include +#include #include #include #include @@ -17,8 +19,10 @@ #include #include #include +#include #include #include +#include #include #include @@ -425,6 +429,383 @@ static void check_dbcn(void) report_prefix_pop(); } +#define SBI_HSM_TEST_DONE (1 << 0) +#define SBI_HSM_TEST_SATP (1 << 1) +#define SBI_HSM_TEST_SIE (1 << 2) +#define SBI_HSM_TEST_HARTID_A1 (1 << 3) + +static cpumask_t cpus_alive_after_start; +static cpumask_t cpus_alive_after_retentive_suspend; +extern void sbi_hsm_check_hart_start(void); +extern void sbi_hsm_check_non_retentive_suspend(void); +extern unsigned char sbi_hsm_stop_hart[NR_CPUS]; +extern unsigned char sbi_hsm_hart_start_checks[NR_CPUS]; +extern unsigned char sbi_hsm_non_retentive_hart_suspend_checks[NR_CPUS]; +static void on_secondary_cpus_async(void (*func)(void *data), void *data) +{ + int cpu, me = smp_processor_id(); + + for_each_present_cpu(cpu) { + if (cpu == me) + continue; + on_cpu_async(cpu, func, data); + } +} + +static bool cpumask_test_secondary_cpus(cpumask_t *mask) +{ + int cpu, me = smp_processor_id(); + + for_each_present_cpu(cpu) { + if (cpu == me) + continue; + + if (!cpumask_test_cpu(cpu, mask)) + return false; + } + + return true; +} + +static void hart_execute(void *data) +{ + int me = smp_processor_id(); + + cpumask_set_cpu(me, &cpus_alive_after_start); +} + +static void hart_retentive_suspend(void *data) +{ + int me = smp_processor_id(); + unsigned long hartid = current_thread_info()->hartid; + struct sbiret ret = sbi_hart_suspend(SBI_EXT_HSM_HART_SUSPEND_RETENTIVE, __pa(NULL), __pa(NULL)); + + if (ret.error) + report_fail("failed to retentive suspend hart %ld", hartid); + else + cpumask_set_cpu(me, &cpus_alive_after_retentive_suspend); +} + +static void hart_non_retentive_suspend(void *data) +{ + unsigned long hartid = 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), hartid); + + if (ret.error) + report_fail("failed to non-retentive suspend hart %ld", hartid); +} + +static void hart_wait_on_status(unsigned long hartid, enum sbi_ext_hsm_sid status) +{ + struct sbiret ret = sbi_hart_get_status(hartid); + + while (!ret.error && ret.value == status) + ret = sbi_hart_get_status(hartid); + + if (ret.error) + report_fail("got %ld while waiting on status %u for hart %lx\n", ret.error, status, hartid); +} + +static void check_hsm(void) +{ + struct sbiret ret; + unsigned long hartid; + unsigned char per_hart_start_checks, per_hart_non_retentive_suspend_checks; + unsigned long hart_mask[NR_CPUS / BITS_PER_LONG] = {0}; + bool ipi_failed = false; + int cpu, me = smp_processor_id(); + + report_prefix_push("hsm"); + + if (!sbi_probe(SBI_EXT_HSM)) { + report_skip("hsm extension not available"); + report_prefix_pop(); + return; + } + + report_prefix_push("hart_get_status"); + + hartid = current_thread_info()->hartid; + ret = sbi_hart_get_status(hartid); + + if (ret.error == SBI_ERR_INVALID_PARAM) { + report_fail("current hartid is invalid"); + report_prefix_popn(2); + return; + } else if (ret.value != SBI_EXT_HSM_STARTED) { + report_fail("current hart is not started"); + report_prefix_popn(2); + return; + } + + report_pass("status of current hart is started"); + + report_prefix_pop(); + + report_prefix_push("hart_start"); + + ret = sbi_hart_start(hartid, virt_to_phys(&hart_execute), __pa(NULL)); + report(ret.error == SBI_ERR_ALREADY_AVAILABLE, "boot hart is already started"); + + ret = sbi_hart_start(ULONG_MAX, virt_to_phys(&hart_execute), __pa(NULL)); + report(ret.error == SBI_ERR_INVALID_PARAM, "invalid hartid check"); + + if (nr_cpus < 2) { + report_skip("no other cpus to run the remaining hsm tests on"); + report_prefix_popn(2); + return; + } + + for_each_present_cpu(cpu) { + if (cpu == me) + continue; + + hartid = cpus[cpu].hartid; + ret = sbi_hart_start(hartid, virt_to_phys(&sbi_hsm_check_hart_start), hartid); + + if (ret.error) { + report_fail("failed to start test hart %ld", hartid); + report_prefix_popn(2); + return; + } + } + + for_each_present_cpu(cpu) { + if (cpu == me) + continue; + + hartid = cpus[cpu].hartid; + + hart_wait_on_status(hartid, SBI_EXT_HSM_STOPPED); + hart_wait_on_status(hartid, SBI_EXT_HSM_START_PENDING); + ret = sbi_hart_get_status(hartid); + report(!ret.error && ret.value == SBI_EXT_HSM_STARTED, + "test hart with hartid %ld successfully started", hartid); + } + + for_each_present_cpu(cpu) { + if (cpu == me) + continue; + + hartid = cpus[cpu].hartid; + + while (!((per_hart_start_checks = READ_ONCE(sbi_hsm_hart_start_checks[hartid])) + & SBI_HSM_TEST_DONE)) + cpu_relax(); + + report(per_hart_start_checks & SBI_HSM_TEST_SATP, + "satp is zero for test hart %ld", hartid); + report(per_hart_start_checks & SBI_HSM_TEST_SIE, + "sstatus.SIE is zero for test hart %ld", hartid); + report(per_hart_start_checks & SBI_HSM_TEST_HARTID_A1, + "a0 and a1 are hartid for test hart %ld", hartid); + } + + report_prefix_pop(); + + report_prefix_push("hart_stop"); + + for_each_present_cpu(cpu) { + if (cpu == me) + continue; + + hartid = cpus[cpu].hartid; + WRITE_ONCE(sbi_hsm_stop_hart[hartid], true); + } + + for_each_present_cpu(cpu) { + if (cpu == me) + continue; + + hartid = cpus[cpu].hartid; + hart_wait_on_status(hartid, SBI_EXT_HSM_STARTED); + hart_wait_on_status(hartid, SBI_EXT_HSM_STOP_PENDING); + ret = sbi_hart_get_status(hartid); + report(!ret.error && (ret.value == SBI_EXT_HSM_STOPPED), + "test hart %ld successfully stopped", hartid); + } + + /* Reset the stop flags so that we can reuse them after suspension tests */ + for_each_present_cpu(cpu) { + if (cpu == me) + continue; + + hartid = cpus[cpu].hartid; + WRITE_ONCE(sbi_hsm_stop_hart[hartid], false); + } + + report_prefix_pop(); + + report_prefix_push("hart_start"); + + on_secondary_cpus_async(hart_execute, NULL); + + for_each_present_cpu(cpu) { + if (cpu == me) + continue; + + hartid = cpus[cpu].hartid; + hart_wait_on_status(hartid, SBI_EXT_HSM_STOPPED); + hart_wait_on_status(hartid, SBI_EXT_HSM_START_PENDING); + ret = sbi_hart_get_status(hartid); + report(!ret.error && (ret.value == SBI_EXT_HSM_STARTED), + "new hart with hartid %ld successfully started", hartid); + } + + while (!cpumask_test_secondary_cpus(&cpu_idle_mask)) + cpu_relax(); + + report(cpumask_full(&cpu_online_mask), "all cpus online"); + report(cpumask_test_secondary_cpus(&cpus_alive_after_start), + "all secondary harts successfully executed code after start"); + + report_prefix_pop(); + + report_prefix_push("hart_suspend"); + + if (sbi_probe(SBI_EXT_IPI)) { + on_secondary_cpus_async(hart_retentive_suspend, NULL); + + for_each_present_cpu(cpu) { + if (cpu == me) + continue; + + hartid = cpus[cpu].hartid; + hart_mask[hartid / BITS_PER_LONG] |= 1UL << hartid; + hart_wait_on_status(hartid, SBI_EXT_HSM_STARTED); + hart_wait_on_status(hartid, SBI_EXT_HSM_SUSPEND_PENDING); + ret = sbi_hart_get_status(hartid); + report(!ret.error && (ret.value == SBI_EXT_HSM_SUSPENDED), + "hart %ld successfully retentive suspended", hartid); + } + + for (int i = 0; i < NR_CPUS / BITS_PER_LONG; ++i) { + if (hart_mask[i]) { + ret = sbi_send_ipi(hart_mask[i], i * BITS_PER_LONG); + if (ret.error) { + ipi_failed = true; + report_fail("got %ld when sending ipi to retentive suspended harts", + ret.error); + break; + } + } + } + + if (!ipi_failed) { + for_each_present_cpu(cpu) { + if (cpu == me) + continue; + + hartid = cpus[cpu].hartid; + hart_wait_on_status(hartid, SBI_EXT_HSM_SUSPENDED); + hart_wait_on_status(hartid, SBI_EXT_HSM_RESUME_PENDING); + ret = sbi_hart_get_status(hartid); + report(!ret.error && (ret.value == SBI_EXT_HSM_STARTED), + "hart %ld successfully retentive resumed", hartid); + } + + while (!cpumask_test_secondary_cpus(&cpu_idle_mask)) + cpu_relax(); + + report(cpumask_full(&cpu_online_mask), "all cpus online"); + report(cpumask_test_secondary_cpus(&cpus_alive_after_retentive_suspend), + "all secondary harts successfully executed code after retentive suspend"); + } + + /* Reset the ipi_failed flag so that we can reuse it for non-retentive suspension tests */ + ipi_failed = false; + + on_secondary_cpus_async(hart_non_retentive_suspend, NULL); + + for_each_present_cpu(cpu) { + if (cpu == me) + continue; + + hartid = cpus[cpu].hartid; + hart_wait_on_status(hartid, SBI_EXT_HSM_STARTED); + hart_wait_on_status(hartid, SBI_EXT_HSM_SUSPEND_PENDING); + ret = sbi_hart_get_status(hartid); + report(!ret.error && (ret.value == SBI_EXT_HSM_SUSPENDED), + "hart %ld successfully non-retentive suspended", hartid); + } + + for (int i = 0; i < NR_CPUS / BITS_PER_LONG; ++i) { + if (hart_mask[i]) { + ret = sbi_send_ipi(hart_mask[i], i * BITS_PER_LONG); + if (ret.error) { + ipi_failed = true; + report_fail("got %ld when sending ipi to non-retentive suspended harts", + ret.error); + break; + } + } + } + + if (!ipi_failed) { + for_each_present_cpu(cpu) { + if (cpu == me) + continue; + + hartid = cpus[cpu].hartid; + hart_wait_on_status(hartid, SBI_EXT_HSM_SUSPENDED); + hart_wait_on_status(hartid, SBI_EXT_HSM_RESUME_PENDING); + ret = sbi_hart_get_status(hartid); + report(!ret.error && (ret.value == SBI_EXT_HSM_STARTED), + "hart %ld successfully non-retentive resumed", hartid); + } + + for_each_present_cpu(cpu) { + if (cpu == me) + continue; + + hartid = cpus[cpu].hartid; + + while (!((per_hart_non_retentive_suspend_checks = + READ_ONCE(sbi_hsm_non_retentive_hart_suspend_checks[hartid])) + & SBI_HSM_TEST_DONE)) + cpu_relax(); + + report(per_hart_non_retentive_suspend_checks & SBI_HSM_TEST_SATP, + "satp is zero for test hart %ld", hartid); + report(per_hart_non_retentive_suspend_checks & SBI_HSM_TEST_SIE, + "sstatus.SIE is zero for test hart %ld", hartid); + report(per_hart_non_retentive_suspend_checks & SBI_HSM_TEST_HARTID_A1, + "a0 and a1 are hartid for test hart %ld", hartid); + } + + report_prefix_pop(); + + report_prefix_push("hart_stop"); + + for_each_present_cpu(cpu) { + if (cpu == me) + continue; + + hartid = cpus[cpu].hartid; + WRITE_ONCE(sbi_hsm_stop_hart[hartid], true); + } + + for_each_present_cpu(cpu) { + if (cpu == me) + continue; + + hartid = cpus[cpu].hartid; + hart_wait_on_status(hartid, SBI_EXT_HSM_STARTED); + hart_wait_on_status(hartid, SBI_EXT_HSM_STOP_PENDING); + ret = sbi_hart_get_status(hartid); + report(!ret.error && (ret.value == SBI_EXT_HSM_STOPPED), + "test hart %ld successfully stopped", hartid); + } + } + } else { + report_skip("skipping suspension tests since ipi extension is unavailable"); + } + + report_prefix_popn(2); +} + int main(int argc, char **argv) { if (argc > 1 && !strcmp(argv[1], "-h")) { @@ -435,6 +816,7 @@ int main(int argc, char **argv) report_prefix_push("sbi"); check_base(); check_time(); + check_hsm(); check_dbcn(); return report_summary();