From patchwork Sat Mar 2 11:25:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bo Gan X-Patchwork-Id: 1907122 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=lgoTX3sj; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=HsQo09m5; 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=opensbi-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 4Tn2hD4DqFz23pN for ; Sat, 2 Mar 2024 22:25:48 +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:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id: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=cK5Uj4LUAt7XruhCdF1rrLBaruLOe0+SswAsspgl4+4=; b=lgoTX3sjTvprO6 5loaDICH0ujUTIazpRuCGCYJbRyFK6yW3argfPg8VvsUbZQQGAvJjEkwQhHZW2VOsbH3wtOiLPxjd wHeVty4uphLf9X2UWTP4ojms8tMBiTDfXE+1N0FkaqlpP3lM1lw5BxLvXHmXjMbhVSaq6h09Vzj9j nEHTeAEpbVmURpmp/Sk+s5Wi1wcg/lxcAvGyEkNsLpojo8YnKJnxJt38AuNKwpl0hyBJiw33hBE8m 99HqVoNpf3FXxFU8Aa/UKN3ZtTN/6Uch6EfmQ/ZHzIhp6BkueojND3dh6PBBiEl915ydbeZsbAyZi FEbKfV2N26bCbsIcMZxg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rgNUp-00000003PZA-2hxQ; Sat, 02 Mar 2024 11:25:39 +0000 Received: from mail-ua1-x930.google.com ([2607:f8b0:4864:20::930]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rgNUn-00000003PWz-0m4S for opensbi@lists.infradead.org; Sat, 02 Mar 2024 11:25:38 +0000 Received: by mail-ua1-x930.google.com with SMTP id a1e0cc1a2514c-7d995bd557eso1835299241.0 for ; Sat, 02 Mar 2024 03:25:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709378735; x=1709983535; darn=lists.infradead.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=jrVZtkdYfwN+hXTHUU5t8lf+it50sIyzSs2PUHLsx8Q=; b=HsQo09m5dprbmDLCXsV2ASnLP8za9bufCRtHYnUVfd7JhSltNjaWe7k5yau8Ajvf72 eByovSpHF9io0zhbrlzTGqTBzhpESoEjWk8glDRbMnINRr72aS6HWj/JRkU/+GQeIXky HiWjLb+NLHHBaz3FqYQ0Ff4/i6mTuaqT4SFpzLRt7885S9Xf+oryFfgkt5Rz6WwNFkGs 8a5i6yX6ZtBpHWY9uXmRv08bPK/Ai5LTBBbbBB1cHv1MAaj1YLeNp9J57We2rMFXzwR1 opYbrSfc2R4qspQ2LSyBH/T6JNxRszqBPlkxk/fM9BE5rPa7fC4gl+gEQIX62BXodGbJ ytcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709378735; x=1709983535; h=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=jrVZtkdYfwN+hXTHUU5t8lf+it50sIyzSs2PUHLsx8Q=; b=PMudPvnKqsR+kyVE3l2gYdhDj4CE5gSJBLwztw/a2nSZLHdthqRvOD3qMkjVSQBZeV LegtdqIGN473DjX1/NmISsBD8BQ5LW2m1njQZLq58NThs0lKzZp66qKrQtWRFmTgMlDA lMx0qgwK1T9F0BR/rmO+s0miubfBI88uq1e9YMXU8Ipai2i3ihoQiSUMdhsxRLxl3ef5 tyHZH4O4JvQ31FAydgvYopUysSKHFCNiFOKNumYNnXSG5xIdjQCoQsc1Umxojp/fnHXx pf7Hh+gcuAcQxGWynFgJu6mZU+04wQMAm64ttXn79kHyEQRitgbUT6C/lqnWAMSmv5Vp w+4w== X-Gm-Message-State: AOJu0Yz3rb3OTW0vq8nxvDa1vVit89bbRqo4bFXrbZVTdWEZDAZWCw/s Ky/Q55hPenXJlysVaOjYk1a+22jin2ugODCBzo4vC0pAVobtXXH95Qd7qL5a X-Google-Smtp-Source: AGHT+IE6SYyer7fds89YPqdE+vb/8Zg/zMpXUViEHgjPN27FRkrCSHy0KtOMR4b4cZw7K2W/bgjpdg== X-Received: by 2002:a05:6102:18c3:b0:470:6fe6:5a08 with SMTP id jj3-20020a05610218c300b004706fe65a08mr3252072vsb.34.1709378733401; Sat, 02 Mar 2024 03:25:33 -0800 (PST) Received: from m91p.airy.home ([172.92.174.232]) by smtp.gmail.com with ESMTPSA id ih12-20020a0561022d0c00b0046ecdfd5a94sm21265vsb.14.2024.03.02.03.25.32 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 02 Mar 2024 03:25:33 -0800 (PST) From: Bo Gan To: opensbi@lists.infradead.org Cc: wxjstz@126.com, anup@brainfault.org Subject: [PATCH v3 1/6] lib: sbi: rename sbi_misaligned_ldst.c to sbi_trap_ldst.c Date: Sat, 2 Mar 2024 03:25:20 -0800 Message-Id: <1709378725-56656-2-git-send-email-ganboing@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1709378725-56656-1-git-send-email-ganboing@gmail.com> References: <1709378725-56656-1-git-send-email-ganboing@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240302_032537_244775_4374958D X-CRM114-Status: UNSURE ( 9.10 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.2 (/) 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: Signed-off-by: Bo Gan --- lib/sbi/objects.mk | 2 +- lib/sbi/{sbi_misaligned_ldst.c => sbi_trap_ldst.c} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename lib/sbi/{sbi_misaligned_ldst.c => sbi [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:930 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -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_SIGNED Message has a DKIM or DK signature, not necessarily valid 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [ganboing(at)gmail.com] -0.0 T_SCC_BODY_TEXT_LINE No description available. X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Signed-off-by: Bo Gan Reviewed-by: Anup Patel --- lib/sbi/objects.mk | 2 +- lib/sbi/{sbi_misaligned_ldst.c => sbi_trap_ldst.c} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename lib/sbi/{sbi_misaligned_ldst.c => sbi_trap_ldst.c} (100%) diff --git a/lib/sbi/objects.mk b/lib/sbi/objects.mk index 0a50e95..204dd6b 100644 --- a/lib/sbi/objects.mk +++ b/lib/sbi/objects.mk @@ -70,7 +70,6 @@ libsbi-objs-y += sbi_illegal_insn.o libsbi-objs-y += sbi_init.o libsbi-objs-y += sbi_ipi.o libsbi-objs-y += sbi_irqchip.o -libsbi-objs-y += sbi_misaligned_ldst.o libsbi-objs-y += sbi_platform.o libsbi-objs-y += sbi_pmu.o libsbi-objs-y += sbi_dbtr.o @@ -80,6 +79,7 @@ libsbi-objs-y += sbi_system.o libsbi-objs-y += sbi_timer.o libsbi-objs-y += sbi_tlb.o libsbi-objs-y += sbi_trap.o +libsbi-objs-y += sbi_trap_ldst.o libsbi-objs-y += sbi_unpriv.o libsbi-objs-y += sbi_expected_trap.o libsbi-objs-y += sbi_cppc.o diff --git a/lib/sbi/sbi_misaligned_ldst.c b/lib/sbi/sbi_trap_ldst.c similarity index 100% rename from lib/sbi/sbi_misaligned_ldst.c rename to lib/sbi/sbi_trap_ldst.c From patchwork Sat Mar 2 11:25:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bo Gan X-Patchwork-Id: 1907123 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=PyK8V3ts; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=GYAZWMn2; 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=opensbi-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 4Tn2hF5RmYz1yX7 for ; Sat, 2 Mar 2024 22:25:49 +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:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id: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=rJKAJU6w9d0CjT813YDz6PJt+g/AESso6WNCfJ2WjT0=; b=PyK8V3tsv1hcaD 99lLRK/GwOo/2SrUDIyEnQMDPHpGO+nXj7NqgfurExnkuogiLA3bx8wdRo6y3gWrxCBzRw6t+lkHY hq4sOIJbl9G03iTFBNl6ydhqdB6LHvCFQlF16Kalsmxjs3jNr9G0Dq1juxarWG2dO+8f5XSdN8s7m SllfiwX5up7yR7UMdktSnIBuHiNOfQTI5wKb6v/R9jmdW8+NYDbcUDX8jmLXcP+u2Gz16i9447l2Z SwGn6GaVnUypTbZAtPzxEa/2Z0aI+c5Iaw5dELru7memBet0scrcGeiWVG7Vu6MH1vTHaBDGQBj+8 p6/L4yk3S0mispT32v1A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rgNUr-00000003PaU-2xP7; Sat, 02 Mar 2024 11:25:41 +0000 Received: from mail-oa1-x36.google.com ([2001:4860:4864:20::36]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rgNUo-00000003PX2-06co for opensbi@lists.infradead.org; Sat, 02 Mar 2024 11:25:39 +0000 Received: by mail-oa1-x36.google.com with SMTP id 586e51a60fabf-21e63b586fcso1610505fac.3 for ; Sat, 02 Mar 2024 03:25:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709378736; x=1709983536; darn=lists.infradead.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=bADdgjXOwCjkJm5suI0Y//Hoz6NhlmiVGTdY3mhGlz8=; b=GYAZWMn2CXnxgLOq169dosGbA06TFlh2W6Ddsu769hGX7KQVIxbby9uM8fgGez6Wp/ 54jKPQgoqLDW7V2wb24g5Iiwc/G2bnJFpQD+gUj2RVGuibYcj3CacKc9OATMj/B0LLP5 ZVcMp/qY6pQHqoxiCP+yUC/ae7r51tT1DVxv7SR3peb4X4mY01r0c2dOeSsZLUj2hjZF SJz1EGhmb5VhHt883WtULEP9fwOCZuLkyCqEw59OZGWd+UDVJtK/xJ6hKbK9XDe3TxX7 mqawQP0L4tmH1mtsv0jOo3TrkhIiU1UtVJJOGWDepezdJfUMZGgn27b2KRImMofAJsp/ 1Zxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709378736; x=1709983536; h=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=bADdgjXOwCjkJm5suI0Y//Hoz6NhlmiVGTdY3mhGlz8=; b=Nrki7bxIxeUzlgJsf9hJ6/vKg57WK1mpwgAB43LBOU1mSW/o9yEf806KlLTg1ObbHJ LdYZo2B6lTpBDPowOaY3DfZAVL5DT3Uvl6L8JKRoAj9F0KVCvPN52P4lS6I9xrpfw+pw unEz8gsa5lLXpTpZfQske/sNcijxQGVHxF4iMdsWlnjmW/ggmh+ou0ototyAmov2iFQx suVnNsW8AViTGImrqNlGlMDrBwpEFrkmh2f0SbJjKiJBzBXcsexO8Qs3m1/fQRRisd8X Bhb0Kt6py+1FnsHkIeNKBtDkj8vnYXB42fkPoCw+IJkdpDsFKA7oPSMVs05O+CASXLUN YNaw== X-Gm-Message-State: AOJu0YyqC0+mLOncN02Swy8jrW5PiNQSrvpKl3mFR7oJWm7HwjaZQk4i dcRcIXukaNVK/USKLNwgsgzJJA71qjSbIKNroL/OX7w95DovK81z9/a6fesE X-Google-Smtp-Source: AGHT+IFrK1j4Bmx5tZXWR0SQ0RcQlvrzJ0XNignyb2y3xdhcjUOaMX9C78o1zDxBVUofuLNMWY6fEA== X-Received: by 2002:a05:6870:348:b0:21f:7e35:8f4d with SMTP id n8-20020a056870034800b0021f7e358f4dmr4707766oaf.6.1709378734581; Sat, 02 Mar 2024 03:25:34 -0800 (PST) Received: from m91p.airy.home ([172.92.174.232]) by smtp.gmail.com with ESMTPSA id ih12-20020a0561022d0c00b0046ecdfd5a94sm21265vsb.14.2024.03.02.03.25.33 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 02 Mar 2024 03:25:34 -0800 (PST) From: Bo Gan To: opensbi@lists.infradead.org Cc: wxjstz@126.com, anup@brainfault.org Subject: [PATCH v3 2/6] include: sbi: rename sbi_misaligned_ldst.h to sbi_trap_ldst.h Date: Sat, 2 Mar 2024 03:25:21 -0800 Message-Id: <1709378725-56656-3-git-send-email-ganboing@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1709378725-56656-1-git-send-email-ganboing@gmail.com> References: <1709378725-56656-1-git-send-email-ganboing@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240302_032538_110537_523E2B2E X-CRM114-Status: UNSURE ( 9.66 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.2 (/) 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: Signed-off-by: Bo Gan --- include/sbi/{sbi_misaligned_ldst.h => sbi_trap_ldst.h} | 4 ++-- lib/sbi/sbi_trap.c | 2 +- lib/sbi/sbi_trap_ldst.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) re [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2001:4860:4864:20:0:0:0:36 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -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_SIGNED Message has a DKIM or DK signature, not necessarily valid 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [ganboing(at)gmail.com] -0.0 T_SCC_BODY_TEXT_LINE No description available. X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Signed-off-by: Bo Gan Reviewed-by: Anup Patel --- include/sbi/{sbi_misaligned_ldst.h => sbi_trap_ldst.h} | 4 ++-- lib/sbi/sbi_trap.c | 2 +- lib/sbi/sbi_trap_ldst.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) rename include/sbi/{sbi_misaligned_ldst.h => sbi_trap_ldst.h} (86%) diff --git a/include/sbi/sbi_misaligned_ldst.h b/include/sbi/sbi_trap_ldst.h similarity index 86% rename from include/sbi/sbi_misaligned_ldst.h rename to include/sbi/sbi_trap_ldst.h index ab27eb4..9bbd237 100644 --- a/include/sbi/sbi_misaligned_ldst.h +++ b/include/sbi/sbi_trap_ldst.h @@ -7,8 +7,8 @@ * Anup Patel */ -#ifndef __SBI_MISALIGNED_LDST_H__ -#define __SBI_MISALIGNED_LDST_H__ +#ifndef __SBI_TRAP_LDST_H__ +#define __SBI_TRAP_LDST_H__ #include diff --git a/lib/sbi/sbi_trap.c b/lib/sbi/sbi_trap.c index dbf307c..145db4b 100644 --- a/lib/sbi/sbi_trap.c +++ b/lib/sbi/sbi_trap.c @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/lib/sbi/sbi_trap_ldst.c b/lib/sbi/sbi_trap_ldst.c index aa512de..be9a394 100644 --- a/lib/sbi/sbi_trap_ldst.c +++ b/lib/sbi/sbi_trap_ldst.c @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include #include From patchwork Sat Mar 2 11:25:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bo Gan X-Patchwork-Id: 1907124 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=vx+amiXB; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=SfUDYKB+; 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=opensbi-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 4Tn2hH2sTNz1yX7 for ; Sat, 2 Mar 2024 22:25:51 +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:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id: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=nJBXjM1NsqljTJYwFX6RHz4CASk+xS0mn9OSwzrzl9A=; b=vx+amiXBXMcsVf FFpexhC8gt8cxDTWmK6e6gYCg1g8zwXuI1aHpEJK9wR4rA75AWez7t+vUg6z6T+JUqOe8Zkhq0sQ7 d0BkjKqmGsXgxw9+H6N0D4uJouEwzvUv/a9C/t4a46ZAaqhaeyYtEe259V9O0RYGO3uA6XJ4V5Bp0 Atm98Szx8YlAG4lTZB82ZxgRT4Jey3a2DoznaMclO1v83m+gVCCkBhf9/IRf7epcrGiyi5CY2oFCB BGo39LHs6K3/j2MZMbAkkCboYKVYq5vIub8rBVevA/YA7KvqEqIKpJ68U9OSHqVSfb4UoBLlO6YP1 pkvlIbL6ewV5GzrJorbw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rgNUs-00000003Pb5-3GsU; Sat, 02 Mar 2024 11:25:42 +0000 Received: from mail-oa1-x2a.google.com ([2001:4860:4864:20::2a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rgNUo-00000003PXg-36JU for opensbi@lists.infradead.org; Sat, 02 Mar 2024 11:25:40 +0000 Received: by mail-oa1-x2a.google.com with SMTP id 586e51a60fabf-204235d0913so2166365fac.1 for ; Sat, 02 Mar 2024 03:25:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709378736; x=1709983536; darn=lists.infradead.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=hfatTDggRkrBb553TM2+XXMAQ4gErQmz52I1tXtOews=; b=SfUDYKB+jY2jfdfXdplWD/GoZ3A9/w3J03S9BBdoX+uGraakuyRHjMDqDg2ik/SV/J VVHNBssrvD7mhhq+UEPjOgvLcewC1m0mV6ODCWhjSXdrY2i029+i5ygxA04UKonEnAI2 VMVtWOzGTNQIYx4RwRRvllto9CSkkUngMwjYJgPzTZo4soVoL9Do3GalwHcjAj71poFZ dPCCfGE0FhYCZDBOgg5zq6NqRRgo8i3FANmgUi4ymrntr7u6jTSgAmTdLr6DDKgl3mon j5ERUgA1olIXTrVEeLjwHk7okQ/DUouDsk5d8iHhLmRt1GTOhJeGBeh00YeR6lyJk6f3 dNQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709378736; x=1709983536; h=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=hfatTDggRkrBb553TM2+XXMAQ4gErQmz52I1tXtOews=; b=l87NPYUZEs2EqV9n8dh+fUeg8W+VCaqPy9c3lniFALauxZFj25Qx68u132jS9X5lJX mQYQCDGCaFzBanmgQIoZX0tljC4K6ET0bHu9W5zdWmrtYRrKihQ5W8JYTR4+seCuCc8f 4fGNtIK7z8jXkpLsWl9VYx5I3gKgNfhj7oEhSHCAdps/EJepOlr40qdBBg8uV1qITphl 9IOzP1y1sex1hg6Mq7AMRF54MuLRUMqVZQyml9qQksWsZIlZC/t7SJOcfejJcYZHY2+d E6UaC8fsMRf40mrj5BHAgE+FYkIw9BAiOB/BQJ9djCEwrnfa7Pb+fqr9H3suYvQRl8qQ Psqw== X-Gm-Message-State: AOJu0YyWug517Wfoha/q0dc1YofSa12sUVliNmtLgJ/S+r9tHq6YzjHv 74SfIL0cVGakMnFIJ6xUEcskbaJzQW9W6rfLz20tRIdbutMALtb9atJIybw8 X-Google-Smtp-Source: AGHT+IGfQX0qaHdnAkCWnMecz2BE6Yqazxs7h4O/4tdFYs96bzJGjXfE9murA6XSZz90pcO9/Wc+lQ== X-Received: by 2002:a05:6870:5e46:b0:21f:dad7:85bd with SMTP id ne6-20020a0568705e4600b0021fdad785bdmr4653050oac.14.1709378736344; Sat, 02 Mar 2024 03:25:36 -0800 (PST) Received: from m91p.airy.home ([172.92.174.232]) by smtp.gmail.com with ESMTPSA id ih12-20020a0561022d0c00b0046ecdfd5a94sm21265vsb.14.2024.03.02.03.25.34 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 02 Mar 2024 03:25:35 -0800 (PST) From: Bo Gan To: opensbi@lists.infradead.org Cc: wxjstz@126.com, anup@brainfault.org Subject: [PATCH v3 3/6] lib: sbi: change prototype of sbi_trap_redirect Date: Sat, 2 Mar 2024 03:25:22 -0800 Message-Id: <1709378725-56656-4-git-send-email-ganboing@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1709378725-56656-1-git-send-email-ganboing@gmail.com> References: <1709378725-56656-1-git-send-email-ganboing@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240302_032538_804845_EE1ED107 X-CRM114-Status: GOOD ( 11.93 ) X-Spam-Score: -0.2 (/) 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: sbi_trap_redirect now uses const pointer to `trap`. This ensures the caller that we never change `trap` in sbi_trap_redirect. Signed-off-by: Bo Gan --- include/sbi/sbi_trap.h | 2 +- lib/sbi/sbi_trap.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2001:4860:4864:20:0:0:0:2a listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -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_SIGNED Message has a DKIM or DK signature, not necessarily valid 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [ganboing(at)gmail.com] -0.0 T_SCC_BODY_TEXT_LINE No description available. X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org sbi_trap_redirect now uses const pointer to `trap`. This ensures the caller that we never change `trap` in sbi_trap_redirect. Signed-off-by: Bo Gan Reviewed-by: Anup Patel --- include/sbi/sbi_trap.h | 2 +- lib/sbi/sbi_trap.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/sbi/sbi_trap.h b/include/sbi/sbi_trap.h index a562b95..2727bdb 100644 --- a/include/sbi/sbi_trap.h +++ b/include/sbi/sbi_trap.h @@ -225,7 +225,7 @@ static inline unsigned long sbi_regs_gva(const struct sbi_trap_regs *regs) } int sbi_trap_redirect(struct sbi_trap_regs *regs, - struct sbi_trap_info *trap); + const struct sbi_trap_info *trap); struct sbi_trap_regs *sbi_trap_handler(struct sbi_trap_regs *regs); diff --git a/lib/sbi/sbi_trap.c b/lib/sbi/sbi_trap.c index 145db4b..1024981 100644 --- a/lib/sbi/sbi_trap.c +++ b/lib/sbi/sbi_trap.c @@ -84,7 +84,7 @@ static void __noreturn sbi_trap_error(const char *msg, int rc, * @return 0 on success and negative error code on failure */ int sbi_trap_redirect(struct sbi_trap_regs *regs, - struct sbi_trap_info *trap) + const struct sbi_trap_info *trap) { ulong hstatus, vsstatus, prev_mode; #if __riscv_xlen == 32 From patchwork Sat Mar 2 11:25:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bo Gan X-Patchwork-Id: 1907126 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=0XwelENU; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=LX4pXj6w; 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=opensbi-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 4Tn2hM18cNz23pN for ; Sat, 2 Mar 2024 22:25:55 +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:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id: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=MrJs7k7tzox1RU7spbZ5NnuAlEVVcMJfl4HLJX3wi2c=; b=0XwelENU/9TeAQ At0jaYJjd1PW/lIVFdDGNIW1MW9BqBodWW/1zw9mGxzSQ0ZgcqWboBNffr3RE+dEsgA7s2Xm1ffl3 9yejhpivZ1B9iGLL53NN5KddPPGNqOmY9fnBOBUhWwYWc/PDVSR0O0G8Wzk9KpSoOug9Q0dthvi2b p1njvM6uhk+T3VeVgF/Ayhup2EbNKAQ+J3tA0GOSyIQC4sm7Ltp2m25FB3BSPSD4RT4OdIEQx4j3r 0k3HZ48NRIxpbmsU4je5OPIi20thY1DW89n8KG8UqxlNhtlHonNdNWHp50fpYRgtEzGrRAtq/y/kt /PxVz/NMLwWjpvT5oW4Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rgNUw-00000003Pda-0Rbn; Sat, 02 Mar 2024 11:25:46 +0000 Received: from mail-oa1-x2c.google.com ([2001:4860:4864:20::2c]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rgNUq-00000003PZC-2cpS for opensbi@lists.infradead.org; Sat, 02 Mar 2024 11:25:42 +0000 Received: by mail-oa1-x2c.google.com with SMTP id 586e51a60fabf-21ffac15528so1189319fac.0 for ; Sat, 02 Mar 2024 03:25:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709378738; x=1709983538; darn=lists.infradead.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=ODyDQDvGpp/iLMOgnSdBHPjjIT7Be8DItxQF01o5EVs=; b=LX4pXj6wwdMBgvn1p6a1G5WkoqV/A5S79eYxIOaYaDtuk39q4QEV/pDhJqs4IRpMDj u0G6m6FGvB2F9tHen+KMq0u4ql4HBa5vZWzwDCwPKO8t+vFYq3HOp8aJCkLsD/Bal1RN d85dhUa6pnZOTZbG/AZUAur93IQs56cBM7klSDqdw0uAn34RLoO1lDmEEQ60WaFc8pP3 MSvtgDqpYW5udZoZ5gVUR+91YjMXRCV22x0IyGXQ4Nuuq1df/86aEmgM2zNTXNVzyvQy zzRDI0SdKcd7Dl7r5QpmyYekCUbhspSnn/diBgkd++Lh2uxIifBzBkE09mpl2bPhubbX pULg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709378738; x=1709983538; h=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=ODyDQDvGpp/iLMOgnSdBHPjjIT7Be8DItxQF01o5EVs=; b=w+8YAFhyiH9uCggDon9L8uOQozoB61xPQClVYEmy2UldeRQr8fgPsC0ISZmRQoYRlb x/rh3OmTqmMAExmFMAJ5rZzYha7EUchDkEyb/XM/mJPK6g3PuWyio0g0z2Pn245IpKQc z8H4ZRAFrFo77lWfQJnlmccYkeQ9PwHVubLMQJjcwpYNDWHpKF7Pqx6JSNHdE5I9xz5R IAoUL05dWrhRbTJjpzrJ1ZEzs8ps3CDPrb3LcFu2A2ADmm1u4HfJdrRMicJ6HN272F8G l0dotyny+96iig7UuG+tFN6S8p0bp2tJscD/HFZ+o7pvylptAhbs29FIxw6UWS2UbD25 L/iQ== X-Gm-Message-State: AOJu0YxkYea108lvxAE8C1i82+e1Qn2lTmfM2owE6UPX4jEQ3ldGPrFW PPx2mQ65z6m7kwrW+sVAxbvy4sB7m23ZTP5CR4MGFmsmb42ZRqDaS95UaMuu X-Google-Smtp-Source: AGHT+IFxXGAOaoRe2vJiQGxuNQtezEpJIrnq8gWNb7XFEaSDh32r5VDAnaUP1ZcZ6sJk/AAWeBZcgg== X-Received: by 2002:a05:6871:8b85:b0:220:be60:b6fd with SMTP id tp5-20020a0568718b8500b00220be60b6fdmr3330199oab.13.1709378738064; Sat, 02 Mar 2024 03:25:38 -0800 (PST) Received: from m91p.airy.home ([172.92.174.232]) by smtp.gmail.com with ESMTPSA id ih12-20020a0561022d0c00b0046ecdfd5a94sm21265vsb.14.2024.03.02.03.25.36 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 02 Mar 2024 03:25:37 -0800 (PST) From: Bo Gan To: opensbi@lists.infradead.org Cc: wxjstz@126.com, anup@brainfault.org Subject: [PATCH v3 4/6] lib: sbi: abstract out insn decoding to unify mem fault handlers Date: Sat, 2 Mar 2024 03:25:23 -0800 Message-Id: <1709378725-56656-5-git-send-email-ganboing@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1709378725-56656-1-git-send-email-ganboing@gmail.com> References: <1709378725-56656-1-git-send-email-ganboing@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240302_032540_721622_4C4BD499 X-CRM114-Status: GOOD ( 20.69 ) X-Spam-Score: -0.2 (/) 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: This patch abstracts out the instruction decoding part of misaligned ld/st fault handlers, so it can be reused by ld/st access fault handlers. Also Added lb/lbu/sb decoding. (previously unreachable by [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2001:4860:4864:20:0:0:0:2c listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -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_SIGNED Message has a DKIM or DK signature, not necessarily valid 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [ganboing(at)gmail.com] -0.0 T_SCC_BODY_TEXT_LINE No description available. X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org This patch abstracts out the instruction decoding part of misaligned ld/st fault handlers, so it can be reused by ld/st access fault handlers. Also Added lb/lbu/sb decoding. (previously unreachable by misaligned fault) sbi_trap_emulate_load/store is now the common handler which takes a `emu` parameter that is responsible for emulating the misaligned or access fault. The `emu` callback is expected to fixup the fault, and based on the return code of `emu`, sbi_trap_emulate_load/store will: r/wlen => the fixup is successful and regs/mepc needs to be updated. 0 => the fixup is successful, but regs/mepc should be left untouched (this is usually used if `emu` does `sbi_trap_redirect`) -err => failed, sbi_trap_error will be called For now, load/store access faults are blindly redirected. It will be enhanced in the following patches. Signed-off-by: Bo Gan --- include/sbi/sbi_trap_ldst.h | 48 +++++++++++-- lib/sbi/sbi_trap.c | 34 ++++++---- lib/sbi/sbi_trap_ldst.c | 162 +++++++++++++++++++++++++++----------------- 3 files changed, 165 insertions(+), 79 deletions(-) diff --git a/include/sbi/sbi_trap_ldst.h b/include/sbi/sbi_trap_ldst.h index 9bbd237..646b242 100644 --- a/include/sbi/sbi_trap_ldst.h +++ b/include/sbi/sbi_trap_ldst.h @@ -11,13 +11,51 @@ #define __SBI_TRAP_LDST_H__ #include +#include -struct sbi_trap_regs; +union sbi_reg_data { + u64 data_u64; + u32 data_u32; + u8 data_bytes[8]; + ulong data_ulong; +}; -int sbi_misaligned_load_handler(ulong addr, ulong tval2, ulong tinst, - struct sbi_trap_regs *regs); +/** + * Load emulator callback: + * + * @return rlen=success, 0=success w/o regs modification, or negative error + */ +typedef int (*sbi_trap_ld_emulator)(int rlen, union sbi_reg_data *out_val, + struct sbi_trap_regs *regs, + const struct sbi_trap_info *orig_trap); -int sbi_misaligned_store_handler(ulong addr, ulong tval2, ulong tinst, - struct sbi_trap_regs *regs); +/** + * Store emulator callback: + * + * @return wlen=success, 0=success w/o regs modification, or negative error + */ +typedef int (*sbi_trap_st_emulator)(int wlen, union sbi_reg_data in_val, + struct sbi_trap_regs *regs, + const struct sbi_trap_info *orig_trap); + +int sbi_trap_emulate_load(struct sbi_trap_regs *regs, + const struct sbi_trap_info *orig_trap, + sbi_trap_ld_emulator emu); + +int sbi_trap_emulate_store(struct sbi_trap_regs *regs, + const struct sbi_trap_info *orig_trap, + sbi_trap_st_emulator emu); + +int sbi_misaligned_load_handler(struct sbi_trap_regs *regs, + const struct sbi_trap_info *orig_trap); + +int sbi_misaligned_store_handler(struct sbi_trap_regs *regs, + const struct sbi_trap_info *orig_trap); + +int sbi_load_fault_handler(struct sbi_trap_regs *regs, + const struct sbi_trap_info *orig_trap); + +int sbi_store_fault_handler(struct sbi_trap_regs *regs, + const struct sbi_trap_info *orig_trap); #endif diff --git a/lib/sbi/sbi_trap.c b/lib/sbi/sbi_trap.c index 1024981..eb4cc0f 100644 --- a/lib/sbi/sbi_trap.c +++ b/lib/sbi/sbi_trap.c @@ -285,6 +285,13 @@ struct sbi_trap_regs *sbi_trap_handler(struct sbi_trap_regs *regs) } return regs; } + /* Original trap_info */ + trap.epc = regs->mepc; + trap.cause = mcause; + trap.tval = mtval; + trap.tval2 = mtval2; + trap.tinst = mtinst; + trap.gva = sbi_regs_gva(regs); switch (mcause) { case CAUSE_ILLEGAL_INSTRUCTION: @@ -292,11 +299,13 @@ struct sbi_trap_regs *sbi_trap_handler(struct sbi_trap_regs *regs) msg = "illegal instruction handler failed"; break; case CAUSE_MISALIGNED_LOAD: - rc = sbi_misaligned_load_handler(mtval, mtval2, mtinst, regs); + sbi_pmu_ctr_incr_fw(SBI_PMU_FW_MISALIGNED_LOAD); + rc = sbi_misaligned_load_handler(regs, &trap); msg = "misaligned load handler failed"; break; case CAUSE_MISALIGNED_STORE: - rc = sbi_misaligned_store_handler(mtval, mtval2, mtinst, regs); + sbi_pmu_ctr_incr_fw(SBI_PMU_FW_MISALIGNED_STORE); + rc = sbi_misaligned_store_handler(regs, &trap); msg = "misaligned store handler failed"; break; case CAUSE_SUPERVISOR_ECALL: @@ -305,20 +314,19 @@ struct sbi_trap_regs *sbi_trap_handler(struct sbi_trap_regs *regs) msg = "ecall handler failed"; break; case CAUSE_LOAD_ACCESS: + sbi_pmu_ctr_incr_fw(SBI_PMU_FW_ACCESS_LOAD); + rc = sbi_load_fault_handler(regs, &trap); + msg = "load fault handler failed"; + break; case CAUSE_STORE_ACCESS: - sbi_pmu_ctr_incr_fw(mcause == CAUSE_LOAD_ACCESS ? - SBI_PMU_FW_ACCESS_LOAD : SBI_PMU_FW_ACCESS_STORE); - /* fallthrough */ + sbi_pmu_ctr_incr_fw(SBI_PMU_FW_ACCESS_STORE); + rc = sbi_store_fault_handler(regs, &trap); + msg = "store fault handler failed"; + break; default: /* If the trap came from S or U mode, redirect it there */ - trap.epc = regs->mepc; - trap.cause = mcause; - trap.tval = mtval; - trap.tval2 = mtval2; - trap.tinst = mtinst; - trap.gva = sbi_regs_gva(regs); - - rc = sbi_trap_redirect(regs, &trap); + msg = "trap redirect failed"; + rc = sbi_trap_redirect(regs, &trap); break; } diff --git a/lib/sbi/sbi_trap_ldst.c b/lib/sbi/sbi_trap_ldst.c index be9a394..5516954 100644 --- a/lib/sbi/sbi_trap_ldst.c +++ b/lib/sbi/sbi_trap_ldst.c @@ -16,12 +16,6 @@ #include #include -union reg_data { - u8 data_bytes[8]; - ulong data_ulong; - u64 data_u64; -}; - static ulong sbi_misaligned_tinst_fixup(ulong orig_tinst, ulong new_tinst, ulong addr_offset) { @@ -34,23 +28,22 @@ static ulong sbi_misaligned_tinst_fixup(ulong orig_tinst, ulong new_tinst, return orig_tinst | (addr_offset << SH_RS1); } -int sbi_misaligned_load_handler(ulong addr, ulong tval2, ulong tinst, - struct sbi_trap_regs *regs) +int sbi_trap_emulate_load(struct sbi_trap_regs *regs, + const struct sbi_trap_info *orig_trap, + sbi_trap_ld_emulator emu) { ulong insn, insn_len; - union reg_data val; + union sbi_reg_data val = { 0 }; struct sbi_trap_info uptrap; - int i, fp = 0, shift = 0, len = 0; + int rc, fp = 0, shift = 0, len = 0; - sbi_pmu_ctr_incr_fw(SBI_PMU_FW_MISALIGNED_LOAD); - - if (tinst & 0x1) { + if (orig_trap->tinst & 0x1) { /* * Bit[0] == 1 implies trapped instruction value is * transformed instruction or custom instruction. */ - insn = tinst | INSN_16BIT_MASK; - insn_len = (tinst & 0x2) ? INSN_LEN(insn) : 2; + insn = orig_trap->tinst | INSN_16BIT_MASK; + insn_len = (orig_trap->tinst & 0x2) ? INSN_LEN(insn) : 2; } else { /* * Bit[0] == 0 implies trapped instruction value is @@ -64,7 +57,12 @@ int sbi_misaligned_load_handler(ulong addr, ulong tval2, ulong tinst, insn_len = INSN_LEN(insn); } - if ((insn & INSN_MASK_LW) == INSN_MATCH_LW) { + if ((insn & INSN_MASK_LB) == INSN_MATCH_LB) { + len = 1; + shift = 8 * (sizeof(ulong) - len); + } else if ((insn & INSN_MASK_LBU) == INSN_MATCH_LBU) { + len = 1; + } else if ((insn & INSN_MASK_LW) == INSN_MATCH_LW) { len = 4; shift = 8 * (sizeof(ulong) - len); #if __riscv_xlen == 64 @@ -124,26 +122,13 @@ int sbi_misaligned_load_handler(ulong addr, ulong tval2, ulong tinst, #endif #endif } else { - uptrap.epc = regs->mepc; - uptrap.cause = CAUSE_MISALIGNED_LOAD; - uptrap.tval = addr; - uptrap.tval2 = tval2; - uptrap.tinst = tinst; - uptrap.gva = sbi_regs_gva(regs); - return sbi_trap_redirect(regs, &uptrap); + return sbi_trap_redirect(regs, orig_trap); } - val.data_u64 = 0; - for (i = 0; i < len; i++) { - val.data_bytes[i] = sbi_load_u8((void *)(addr + i), - &uptrap); - if (uptrap.cause) { - uptrap.epc = regs->mepc; - uptrap.tinst = sbi_misaligned_tinst_fixup( - tinst, uptrap.tinst, i); - return sbi_trap_redirect(regs, &uptrap); - } - } + rc = emu(len, &val, regs, orig_trap); + + if (rc <= 0) + return rc; if (!fp) SET_RD(insn, regs, ((long)(val.data_ulong << shift)) >> shift); @@ -159,23 +144,22 @@ int sbi_misaligned_load_handler(ulong addr, ulong tval2, ulong tinst, return 0; } -int sbi_misaligned_store_handler(ulong addr, ulong tval2, ulong tinst, - struct sbi_trap_regs *regs) +int sbi_trap_emulate_store(struct sbi_trap_regs *regs, + const struct sbi_trap_info *orig_trap, + sbi_trap_st_emulator emu) { ulong insn, insn_len; - union reg_data val; + union sbi_reg_data val; struct sbi_trap_info uptrap; - int i, len = 0; + int rc, len = 0; - sbi_pmu_ctr_incr_fw(SBI_PMU_FW_MISALIGNED_STORE); - - if (tinst & 0x1) { + if (orig_trap->tinst & 0x1) { /* * Bit[0] == 1 implies trapped instruction value is * transformed instruction or custom instruction. */ - insn = tinst | INSN_16BIT_MASK; - insn_len = (tinst & 0x2) ? INSN_LEN(insn) : 2; + insn = orig_trap->tinst | INSN_16BIT_MASK; + insn_len = (orig_trap->tinst & 0x2) ? INSN_LEN(insn) : 2; } else { /* * Bit[0] == 0 implies trapped instruction value is @@ -191,7 +175,9 @@ int sbi_misaligned_store_handler(ulong addr, ulong tval2, ulong tinst, val.data_ulong = GET_RS2(insn, regs); - if ((insn & INSN_MASK_SW) == INSN_MATCH_SW) { + if ((insn & INSN_MASK_SB) == INSN_MATCH_SB) { + len = 1; + } else if ((insn & INSN_MASK_SW) == INSN_MATCH_SW) { len = 4; #if __riscv_xlen == 64 } else if ((insn & INSN_MASK_SD) == INSN_MATCH_SD) { @@ -238,27 +224,81 @@ int sbi_misaligned_store_handler(ulong addr, ulong tval2, ulong tinst, #endif #endif } else { - uptrap.epc = regs->mepc; - uptrap.cause = CAUSE_MISALIGNED_STORE; - uptrap.tval = addr; - uptrap.tval2 = tval2; - uptrap.tinst = tinst; - uptrap.gva = sbi_regs_gva(regs); - return sbi_trap_redirect(regs, &uptrap); + return sbi_trap_redirect(regs, orig_trap); } - for (i = 0; i < len; i++) { - sbi_store_u8((void *)(addr + i), val.data_bytes[i], - &uptrap); - if (uptrap.cause) { - uptrap.epc = regs->mepc; - uptrap.tinst = sbi_misaligned_tinst_fixup( - tinst, uptrap.tinst, i); - return sbi_trap_redirect(regs, &uptrap); - } - } + rc = emu(len, val, regs, orig_trap); + + if (rc <= 0) + return rc; regs->mepc += insn_len; return 0; } + +static int sbi_misaligned_ld_emulator(int rlen, union sbi_reg_data *out_val, + struct sbi_trap_regs *regs, + const struct sbi_trap_info *orig_trap) +{ + struct sbi_trap_info uptrap; + int i; + + for (i = 0; i < rlen; i++) { + out_val->data_bytes[i] = + sbi_load_u8((void *)(orig_trap->tval + i), &uptrap); + if (uptrap.cause) { + uptrap.epc = regs->mepc; + uptrap.tinst = sbi_misaligned_tinst_fixup( + orig_trap->tinst, uptrap.tinst, i); + return sbi_trap_redirect(regs, &uptrap); + } + } + return rlen; +} + +int sbi_misaligned_load_handler(struct sbi_trap_regs *regs, + const struct sbi_trap_info *orig_trap) +{ + return sbi_trap_emulate_load(regs, orig_trap, + sbi_misaligned_ld_emulator); +} + +static int sbi_misaligned_st_emulator(int wlen, union sbi_reg_data in_val, + struct sbi_trap_regs *regs, + const struct sbi_trap_info *orig_trap) +{ + struct sbi_trap_info uptrap; + int i; + + for (i = 0; i < wlen; i++) { + sbi_store_u8((void *)(orig_trap->tval + i), + in_val.data_bytes[i], &uptrap); + if (uptrap.cause) { + uptrap.epc = regs->mepc; + uptrap.tinst = sbi_misaligned_tinst_fixup( + orig_trap->tinst, uptrap.tinst, i); + return sbi_trap_redirect(regs, &uptrap); + } + } + return wlen; +} + +int sbi_misaligned_store_handler(struct sbi_trap_regs *regs, + const struct sbi_trap_info *orig_trap) +{ + return sbi_trap_emulate_store(regs, orig_trap, + sbi_misaligned_st_emulator); +} + +int sbi_load_fault_handler(struct sbi_trap_regs *regs, + const struct sbi_trap_info *orig_trap) +{ + return sbi_trap_redirect(regs, orig_trap); +} + +int sbi_store_fault_handler(struct sbi_trap_regs *regs, + const struct sbi_trap_info *orig_trap) +{ + return sbi_trap_redirect(regs, orig_trap); +} From patchwork Sat Mar 2 11:25:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bo Gan X-Patchwork-Id: 1907125 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=4SETOB6x; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=CxiyOnOh; 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=opensbi-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 4Tn2hM0GD8z1yX7 for ; Sat, 2 Mar 2024 22:25:55 +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:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id: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=GbszNZQGhB6zBYARANFFxqLVn8iFxXHjXzBHQyp2UvM=; b=4SETOB6xGCHqQp J/QUAR1uD9Z+o60cfbt9BqeH7UhgWSbhum0GaKJF7mUSaRG3URATjEOSf551IVPOe7yQE0nrNcwX6 7cyGC4Dpyg0PaZOZ7Slz+/cxIjz7PpuePJEmW17sONGZMYkcnQio6kF45xDWkuwQ5M9Sn3CZufIkh 0auV2KRlwbOs5TYh5J9f8BEL3fHSwqs58vBzUuDO8rQKSwL/RkL+hM6oxs6hVsPJxNmI+58nM+uGV IyPBlRxM+CqElv4wcYga3B/MFRQrbsyQFVIBRV7005MflHOviTCEp5EQM5hKVLrZYRgqgnXO3tzyL ssLtNWhBA3nikqwe4Ayw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rgNUx-00000003Per-1ARv; Sat, 02 Mar 2024 11:25:47 +0000 Received: from mail-ua1-x92c.google.com ([2607:f8b0:4864:20::92c]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rgNUs-00000003PaK-099N for opensbi@lists.infradead.org; Sat, 02 Mar 2024 11:25:43 +0000 Received: by mail-ua1-x92c.google.com with SMTP id a1e0cc1a2514c-7d6275d7d4dso1358141241.2 for ; Sat, 02 Mar 2024 03:25:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709378740; x=1709983540; darn=lists.infradead.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=r9KybGoQ0+tjb9bceq5N5VPlHO5o+sMhKRnzwxEEpBY=; b=CxiyOnOh6AUFrJNF20x3nw+nlEEJ9BwHtZ99MM7wTu6hYQIXQs279Vr5NXceM6NBuK etoWLrc326pWhIzeZaYNlLY+ti88sF44tfvWVcjw+INbV4fXkhzNOsdK3TXPpmak9bvG glRFjYMSl4/LFJa4IL9IqJXS61Ny8YZOeEu3DULkx6dU0rkaVsYTnLcgPIXj012z/qzn wwXfc5VzOxCHQCSOWrYJihB44ag4SVpYQ6vZ3Llrj+m2q0C+wP0AfaFICV4FZ/AOxm/R zxKZMEnwzAR8eh9G2uAV1oDcO6npfihfmvHkMwFFdndYIJDIlZMoT/5AJM+01yRRMETs YaoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709378740; x=1709983540; h=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=r9KybGoQ0+tjb9bceq5N5VPlHO5o+sMhKRnzwxEEpBY=; b=p/7nvyfw/6Pb+TsW90mAJHUDowRS2Pz1qwC225VoQ+nzwy1956TEQ+ADTNp+/XLWzB X7H+zQ+BnCA0Ky8bqoj7DWnkNmEQsTBjW/YPskviOjSwh7G2YOg0+b8Fbf0fhLZPo2/a stBVoil3uIvUc2evWb6/yckw062/6MJZ9E8OQRfVtMhd5hGmGzhMakB5eaH31YMHVKA0 tqZjz2oqt+25Vts0da7tEo4FlRbtOjm0faz2XA/CfDvuc+loQVJEREfJgKl4BOrgl7gy HuGG2ol5Tf+IBL2aIx1F6jELzDtJZNO4XnaN1VaYDbnuBv8h006XlBVYlEppj+BYmbeG epdA== X-Gm-Message-State: AOJu0YwL58Un1mGuUQiQlwlcTi+ixXBvaWQUJ6nRLpNpVGbHrss+N45M RZ1gTu1dWh2V9sndO2Fz0iNEkEtVSBme+kU42DIpzGU6aJE1fVHsucB4kK4x X-Google-Smtp-Source: AGHT+IFEzNoSynQrdFCfvrppiyODLUSPwCqt2HnrGo4FqcL+owicv9ngzjtHlvYSoLEdyZB/YwDQQQ== X-Received: by 2002:a05:6102:2758:b0:472:5572:fe32 with SMTP id p24-20020a056102275800b004725572fe32mr3494248vsu.13.1709378739756; Sat, 02 Mar 2024 03:25:39 -0800 (PST) Received: from m91p.airy.home ([172.92.174.232]) by smtp.gmail.com with ESMTPSA id ih12-20020a0561022d0c00b0046ecdfd5a94sm21265vsb.14.2024.03.02.03.25.38 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 02 Mar 2024 03:25:38 -0800 (PST) From: Bo Gan To: opensbi@lists.infradead.org Cc: wxjstz@126.com, anup@brainfault.org Subject: [PATCH v3 5/6] include: sbi: add emulate_load/store handler to platform ops Date: Sat, 2 Mar 2024 03:25:24 -0800 Message-Id: <1709378725-56656-6-git-send-email-ganboing@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1709378725-56656-1-git-send-email-ganboing@gmail.com> References: <1709378725-56656-1-git-send-email-ganboing@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240302_032542_228777_B4048F23 X-CRM114-Status: GOOD ( 11.11 ) X-Spam-Score: -0.2 (/) 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: This patch allows the platform to define load/store emulators. This enables a platform to trap-and-emulate special devices or filter access to existing physical devices. Signed-off-by: Bo Gan --- include/sbi/sbi_platform.h | 11 +++++++++++ 1 file changed, 11 insertions(+) Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:92c listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -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_SIGNED Message has a DKIM or DK signature, not necessarily valid 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [ganboing(at)gmail.com] -0.0 T_SCC_BODY_TEXT_LINE No description available. X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org This patch allows the platform to define load/store emulators. This enables a platform to trap-and-emulate special devices or filter access to existing physical devices. Signed-off-by: Bo Gan --- include/sbi/sbi_platform.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/sbi/sbi_platform.h b/include/sbi/sbi_platform.h index 2fb33e1..06247dc 100644 --- a/include/sbi/sbi_platform.h +++ b/include/sbi/sbi_platform.h @@ -53,6 +53,8 @@ struct sbi_domain_memregion; struct sbi_ecall_return; struct sbi_trap_regs; struct sbi_hart_features; +struct sbi_trap_info; +union sbi_reg_data; /** Possible feature flags of a platform */ enum sbi_platform_features { @@ -139,6 +141,15 @@ struct sbi_platform_operations { int (*vendor_ext_provider)(long funcid, struct sbi_trap_regs *regs, struct sbi_ecall_return *out); + + /** platform specific handler to fixup load fault */ + int (*emulate_load)(int rlen, union sbi_reg_data *out_val, + struct sbi_trap_regs *regs, + const struct sbi_trap_info *orig_trap); + /** platform specific handler to fixup store fault */ + int (*emulate_store)(int wlen, union sbi_reg_data in_val, + struct sbi_trap_regs *regs, + const struct sbi_trap_info *orig_trap); }; /** Platform default per-HART stack size for exception/interrupt handling */ From patchwork Sat Mar 2 11:25:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bo Gan X-Patchwork-Id: 1907127 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=EFivjfof; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=X9C6udeR; 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=opensbi-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 4Tn2hP5r25z1yX7 for ; Sat, 2 Mar 2024 22:25:57 +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:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id: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=YMHwtL/RfcHgX8xgh6//VmePrE/4u7EwANQp9zn1P30=; b=EFivjfofwGsaxZ IlF6YLAPWmCdG1Z78vTpKO8oWCtcwggTVo08UNp/MeMbfAmdTXQj34AJ41UlctSGRh7Uo6SRfn4gz SHyLeqrQNekyX0LredMW6OSZBGoTGbaeX0O9Jna4FE32MeCVs3LnFSOb4fldqf9NjRVvU85oBq0XS cbKHHS8JcNTS04p7Dz6WMs0sqmlhG9j5a11xmSgX5FhWLqVHSV1yPTLZbmBLfxfh8ubojNGJ45vLd aPPRCxyzTNcDqultbEWhUrw+ShxsALf1wv2TsA/v57g990E5WUB8FJ6B5SqV/FzXgpnEliYrILEqp lkhhu11EFUQwfCoCCm/g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rgNV0-00000003Pgr-0xcE; Sat, 02 Mar 2024 11:25:50 +0000 Received: from mail-ot1-x331.google.com ([2607:f8b0:4864:20::331]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rgNUt-00000003Pb2-1v3Z for opensbi@lists.infradead.org; Sat, 02 Mar 2024 11:25:45 +0000 Received: by mail-ot1-x331.google.com with SMTP id 46e09a7af769-6e4a5ee63f4so1422835a34.3 for ; Sat, 02 Mar 2024 03:25:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709378741; x=1709983541; darn=lists.infradead.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=VrkQmSnj8cSNoFOP5/bEPENMXhdm2a5nHqeCawtBBwQ=; b=X9C6udeRW4X25rTr781LylJuDy6wDmMKslJmlN2kOy4wjTxkl17mn0QJLRoiy5pIw3 ZxjBU8fkNhY3UoewPZnB/ydivdAxY/F7/X7Bd+NzAJYX55VexFtUSrVoVLx2Pq7rn1ou uYurjQEkOe3InxzPUvSrfNhN1X55gcIkIP9o/c9p6ZiW2K90mpzBtqWJal+65bcgEdDF ohyO91Wo5sLOiOOA4frvpPavYB5HdTaCMwyAEVflmoxBqYr9szhVl1sqvWnWnvS6YTwn hqs/HYjOXRLwKwqNFDtRrtpfJYtBmfW2b2hTcaJyIH5vmEBiPD8TGZuFZJmfQlO439Ee 3C9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709378741; x=1709983541; h=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=VrkQmSnj8cSNoFOP5/bEPENMXhdm2a5nHqeCawtBBwQ=; b=Qq3ZN9BK96NO5zNhjO2agQPOeR82JgI8nEnlHO3bZgMz3pBe7PcbeDTC9ylW8wDjVR i7JpRCN+K6o9M/9EVq9QlOMQb0ocM/i2wLmJ3D0RIeQGlHR/dgrdeicl5Ig6KIyy+ACe EWXz+kzIuPMJO78Bv7p4yIJBKFjzk5SbCobJ0Qeqz0GMTlG4Iw0Q96aT/iecW+pUWQaD iVHkD74kJiIyPW/XduPu56eZjVT3mxf5AkYIDn8zEgst58DYlSPC7wuZGzAWCqCO9lpI 6CsfrSaFVQjHXAkxFKm+IYGjHBQuPgVvTQXB5PIrMc959R5KOBMoqotqPSsAlw/1Y5JB CXOw== X-Gm-Message-State: AOJu0YwsylP2Fr2hbI74oGl/aihqUzGJFhtKtyVMfX9rDRp/2P63nB1E bIM4hJ0BAPVotFQcVpnNHEVXQRq7ZfXok0s8xB9mh1Av2hsX2IeiNE6qjilA X-Google-Smtp-Source: AGHT+IG53kW1uuL6jIMEoldwQm2b2dLQRcP9Bi7RXWskW4yJXWz9Aa3Ef1qWunBOYQBc10pVAJMdiw== X-Received: by 2002:a05:6870:972c:b0:21e:9aa5:f3f7 with SMTP id n44-20020a056870972c00b0021e9aa5f3f7mr4423237oaq.58.1709378741224; Sat, 02 Mar 2024 03:25:41 -0800 (PST) Received: from m91p.airy.home ([172.92.174.232]) by smtp.gmail.com with ESMTPSA id ih12-20020a0561022d0c00b0046ecdfd5a94sm21265vsb.14.2024.03.02.03.25.39 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 02 Mar 2024 03:25:40 -0800 (PST) From: Bo Gan To: opensbi@lists.infradead.org Cc: wxjstz@126.com, anup@brainfault.org Subject: [PATCH v3 6/6] lib: sbi: call platform load/store emulators Date: Sat, 2 Mar 2024 03:25:25 -0800 Message-Id: <1709378725-56656-7-git-send-email-ganboing@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1709378725-56656-1-git-send-email-ganboing@gmail.com> References: <1709378725-56656-1-git-send-email-ganboing@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240302_032543_688053_F154FAE3 X-CRM114-Status: GOOD ( 13.64 ) X-Spam-Score: -0.2 (/) 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: sbi_load/store_fault_handler now tries to call platform emulators if defined. Otherwise, redirects the fault. We let the handler fail if the trap was originated from M mode. In this case, something must be very wrong and we should not attempt to access sbi_platform_ptr(sbi_scratch_thishart_ptr()). Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:331 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -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_SIGNED Message has a DKIM or DK signature, not necessarily valid 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [ganboing(at)gmail.com] -0.0 T_SCC_BODY_TEXT_LINE No description available. X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org sbi_load/store_fault_handler now tries to call platform emulators if defined. Otherwise, redirects the fault. We let the handler fail if the trap was originated from M mode. In this case, something must be very wrong and we should not attempt to access sbi_platform_ptr(sbi_scratch_thishart_ptr()). Signed-off-by: Bo Gan --- include/sbi/sbi_platform.h | 25 +++++++++++++++++++++++++ lib/sbi/sbi_trap_ldst.c | 17 +++++++++++++++-- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/include/sbi/sbi_platform.h b/include/sbi/sbi_platform.h index 06247dc..c556925 100644 --- a/include/sbi/sbi_platform.h +++ b/include/sbi/sbi_platform.h @@ -48,6 +48,7 @@ #include #include #include +#include struct sbi_domain_memregion; struct sbi_ecall_return; @@ -686,6 +687,30 @@ static inline int sbi_platform_vendor_ext_provider( return SBI_ENOTSUPP; } +static inline int +sbi_platform_emulate_load(const struct sbi_platform *plat, + struct sbi_trap_regs *regs, + const struct sbi_trap_info *orig_trap) +{ + if (plat && sbi_platform_ops(plat)->emulate_load) { + return sbi_trap_emulate_load( + regs, orig_trap, sbi_platform_ops(plat)->emulate_load); + } + return sbi_trap_redirect(regs, orig_trap); +} + +static inline int +sbi_platform_emulate_store(const struct sbi_platform *plat, + struct sbi_trap_regs *regs, + const struct sbi_trap_info *orig_trap) +{ + if (plat && sbi_platform_ops(plat)->emulate_store) { + return sbi_trap_emulate_store( + regs, orig_trap, sbi_platform_ops(plat)->emulate_store); + } + return sbi_trap_redirect(regs, orig_trap); +} + #endif #endif diff --git a/lib/sbi/sbi_trap_ldst.c b/lib/sbi/sbi_trap_ldst.c index 5516954..606830e 100644 --- a/lib/sbi/sbi_trap_ldst.c +++ b/lib/sbi/sbi_trap_ldst.c @@ -15,6 +15,7 @@ #include #include #include +#include static ulong sbi_misaligned_tinst_fixup(ulong orig_tinst, ulong new_tinst, ulong addr_offset) @@ -294,11 +295,23 @@ int sbi_misaligned_store_handler(struct sbi_trap_regs *regs, int sbi_load_fault_handler(struct sbi_trap_regs *regs, const struct sbi_trap_info *orig_trap) { - return sbi_trap_redirect(regs, orig_trap); + /* If fault came from M mode, just fail */ + if (((regs->mstatus & MSTATUS_MPP) >> MSTATUS_MPP_SHIFT) == PRV_M) { + return SBI_EINVAL; + } + + return sbi_platform_emulate_load(sbi_platform_thishart_ptr(), regs, + orig_trap); } int sbi_store_fault_handler(struct sbi_trap_regs *regs, const struct sbi_trap_info *orig_trap) { - return sbi_trap_redirect(regs, orig_trap); + /* If fault came from M mode, just fail */ + if (((regs->mstatus & MSTATUS_MPP) >> MSTATUS_MPP_SHIFT) == PRV_M) { + return SBI_EINVAL; + } + + return sbi_platform_emulate_store(sbi_platform_thishart_ptr(), regs, + orig_trap); }