From patchwork Tue Mar 12 10:27:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1910934 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=OkMOZuMZ; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=BrOsKn8J; 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 4Tv8xq2p7Sz1yWt for ; Tue, 12 Mar 2024 21:28:47 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=CQVQOzFMh5NlNeTfOH9dqF9YDkpIhbjG8/oOQLVqsoA=; b=OkMOZuMZHJgNgs NYQdfn23s7fPo39orPaZpZnb1JsV5mZU8Ht+BDdShLfwFxF2stHy2gKhoW1HxuEgDpn2COm8omCcJ pfo3DjQkipHXNc1Xauk3VWFAwZtJRQ1giLZa7Z8KBV/tOckv48PEz1cdjz7RblxWMIH5RlO/J6H9t 59YH/s1ja83VIoTK/1JTZAqda/zTD1/A10+jXLylLN76ThX7AW3V73+6IjbTtf4yNN7iXEVlNGLkX IhJil48Fza/3klu4VK1CEcCN4wWrH+golBY+CzN+s65suYOLqin3oYwc4Atpqt9cjbsANke7tDM2h B91SmZl+d9Pmrhh/grWQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rjzN9-00000005LW8-1ztI; Tue, 12 Mar 2024 10:28:39 +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 1rjzN4-00000005LRE-2zMR for opensbi@lists.infradead.org; Tue, 12 Mar 2024 10:28:37 +0000 Received: by mail-ot1-x331.google.com with SMTP id 46e09a7af769-6e52b9234c0so906281a34.2 for ; Tue, 12 Mar 2024 03:28:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1710239314; x=1710844114; darn=lists.infradead.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=eloQEcHkIZB8rfIJSIkH8drhLZQ3glwIMiM4p2UGQyE=; b=BrOsKn8J+H664cYRQCO6MMNqJBkUdUK6yj3AKCQspFdxy86oUrAhUOhuA5slLC8LV2 TdFNiA6woIfG3LseWrwDj0wOBuM9IUw9MN6xAWzTn3RfkDYyftYK0ryPYmMUWrXP5dRL CUybLsPzfuvr6n/CAOeoDW6G4z3f5004VeQSrEj5ZuIksxZyg84+smvdMTvaruDCFkBR MOi5jXZTOPtSOwKUew/fkCXSSCEyzys+l3GSM2rU8Tsad/lgcgS1BqoCgs5/Etze9Ffv DxvhwVX9YtYr4j9S+/uLy3s1ZRO7pOByGDruhPPinoHiQd1n3Nlw6pUoGwJ5MOGp3/pj MuaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710239314; x=1710844114; 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=eloQEcHkIZB8rfIJSIkH8drhLZQ3glwIMiM4p2UGQyE=; b=ptFZZalz66EiJwr6aHlIED/Ia9u+kiO4uHHBjOqUvcFmBPahVB9C7BQN855mFdEQkO 231vgaoE0gqw4uhmJPiPa3DUXcGEe40xNekGiWGI/YEuO53yO60qDeFQ3udckOaHu94N opjmZeNxTWjta6qsLM152TKmJ8z2YkgPPp/qs3xcQvUqn8jItxvL1h7WTX4bC3ir2Gyj N7wHfiLk7GKJekwk4Dmi+xwcWXNAjYnOdbAyob16SHgT39Wc17q4QICm7qoUCQIMIKAs u4P6VHamJxCGZauTEpG22oeQSH3xJi1mlmZQY2xl7KAvcAKN1XDeXk2COZwgVPhndMRN hp8g== X-Forwarded-Encrypted: i=1; AJvYcCUyNky1yFazdtgsS1vAvGxGha6yFhyFEflcfXvvqQ+bm/kN7CWshYMOVhGNXGfbmWL2T7LlrfqQH8TGAlbpvuxYfeXl9VHA1q2vp+M= X-Gm-Message-State: AOJu0YzZmBaSAhe4oXohmPJvGtqCges5M7CcKSfVGei16xy4yKPRQ8Cb wd9WLTa5o5iu5nqP2jGnbe9ZS7JTBCRBEqIyewz7CreOyDUSiunBdURnAYYUjuzm6gxx33tyoUw OAtE= X-Google-Smtp-Source: AGHT+IHov7e7h+W49UbJOckyKCrI/bxru+0MpAgGavAoZF+QiFHZpMw3DckBjHu2urO0zpm56NKsrg== X-Received: by 2002:a9d:62d6:0:b0:6e5:1c3e:e931 with SMTP id z22-20020a9d62d6000000b006e51c3ee931mr9366814otk.16.1710239313600; Tue, 12 Mar 2024 03:28:33 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([103.97.165.210]) by smtp.gmail.com with ESMTPSA id j9-20020a9d7d89000000b006e12266433csm1374540otn.27.2024.03.12.03.28.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 03:28:33 -0700 (PDT) From: Anup Patel To: Atish Patra Cc: Andrew Jones , Anup Patel , opensbi@lists.infradead.org, Anup Patel Subject: [PATCH v2 05/10] lib: sbi: Simplify parameters of misaligned and access fault handlers Date: Tue, 12 Mar 2024 15:57:59 +0530 Message-Id: <20240312102804.1436376-6-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240312102804.1436376-1-apatel@ventanamicro.com> References: <20240312102804.1436376-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240312_032834_936945_74FDD78E X-CRM114-Status: GOOD ( 12.40 ) 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: The struct sbi_trap_context already has the information needed by misaligned load/store and access fault load/store handlers so directly pass struct sbi_trap_context pointer to these functions. Signed-off-by: Anup Patel --- include/sbi/sbi_trap_ldst.h | 12 +++---- lib/sbi/sbi_trap.c | 8 ++--- lib/sbi/sbi_trap_ldst.c | 67 ++++++++++++++++++ 3 files [...] 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_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_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.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: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org The struct sbi_trap_context already has the information needed by misaligned load/store and access fault load/store handlers so directly pass struct sbi_trap_context pointer to these functions. Signed-off-by: Anup Patel Reviewed-by: Samuel Holland Reviewed-by: Clément Léger --- include/sbi/sbi_trap_ldst.h | 12 +++---- lib/sbi/sbi_trap.c | 8 ++--- lib/sbi/sbi_trap_ldst.c | 67 ++++++++++++++++++------------------- 3 files changed, 40 insertions(+), 47 deletions(-) diff --git a/include/sbi/sbi_trap_ldst.h b/include/sbi/sbi_trap_ldst.h index 9cab4e4..8aee316 100644 --- a/include/sbi/sbi_trap_ldst.h +++ b/include/sbi/sbi_trap_ldst.h @@ -20,16 +20,12 @@ union sbi_ldst_data { ulong data_ulong; }; -int sbi_misaligned_load_handler(struct sbi_trap_regs *regs, - const struct sbi_trap_info *orig_trap); +int sbi_misaligned_load_handler(struct sbi_trap_context *tcntx); -int sbi_misaligned_store_handler(struct sbi_trap_regs *regs, - const struct sbi_trap_info *orig_trap); +int sbi_misaligned_store_handler(struct sbi_trap_context *tcntx); -int sbi_load_access_handler(struct sbi_trap_regs *regs, - const struct sbi_trap_info *orig_trap); +int sbi_load_access_handler(struct sbi_trap_context *tcntx); -int sbi_store_access_handler(struct sbi_trap_regs *regs, - const struct sbi_trap_info *orig_trap); +int sbi_store_access_handler(struct sbi_trap_context *tcntx); #endif diff --git a/lib/sbi/sbi_trap.c b/lib/sbi/sbi_trap.c index 4dbda06..a2afb0a 100644 --- a/lib/sbi/sbi_trap.c +++ b/lib/sbi/sbi_trap.c @@ -290,12 +290,12 @@ struct sbi_trap_context *sbi_trap_handler(struct sbi_trap_context *tcntx) break; case CAUSE_MISALIGNED_LOAD: sbi_pmu_ctr_incr_fw(SBI_PMU_FW_MISALIGNED_LOAD); - rc = sbi_misaligned_load_handler(regs, trap); + rc = sbi_misaligned_load_handler(tcntx); msg = "misaligned load handler failed"; break; case CAUSE_MISALIGNED_STORE: sbi_pmu_ctr_incr_fw(SBI_PMU_FW_MISALIGNED_STORE); - rc = sbi_misaligned_store_handler(regs, trap); + rc = sbi_misaligned_store_handler(tcntx); msg = "misaligned store handler failed"; break; case CAUSE_SUPERVISOR_ECALL: @@ -305,12 +305,12 @@ struct sbi_trap_context *sbi_trap_handler(struct sbi_trap_context *tcntx) break; case CAUSE_LOAD_ACCESS: sbi_pmu_ctr_incr_fw(SBI_PMU_FW_ACCESS_LOAD); - rc = sbi_load_access_handler(regs, trap); + rc = sbi_load_access_handler(tcntx); msg = "load fault handler failed"; break; case CAUSE_STORE_ACCESS: sbi_pmu_ctr_incr_fw(SBI_PMU_FW_ACCESS_STORE); - rc = sbi_store_access_handler(regs, trap); + rc = sbi_store_access_handler(tcntx); msg = "store fault handler failed"; break; default: diff --git a/lib/sbi/sbi_trap_ldst.c b/lib/sbi/sbi_trap_ldst.c index 5a0537b..f9c0241 100644 --- a/lib/sbi/sbi_trap_ldst.c +++ b/lib/sbi/sbi_trap_ldst.c @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -23,8 +22,7 @@ * @return rlen=success, 0=success w/o regs modification, or negative error */ typedef int (*sbi_trap_ld_emulator)(int rlen, union sbi_ldst_data *out_val, - struct sbi_trap_regs *regs, - const struct sbi_trap_info *orig_trap); + struct sbi_trap_context *tcntx); /** * Store emulator callback: @@ -32,8 +30,7 @@ typedef int (*sbi_trap_ld_emulator)(int rlen, union sbi_ldst_data *out_val, * @return wlen=success, 0=success w/o regs modification, or negative error */ typedef int (*sbi_trap_st_emulator)(int wlen, union sbi_ldst_data in_val, - struct sbi_trap_regs *regs, - const struct sbi_trap_info *orig_trap); + struct sbi_trap_context *tcntx); static ulong sbi_misaligned_tinst_fixup(ulong orig_tinst, ulong new_tinst, ulong addr_offset) @@ -47,10 +44,11 @@ static ulong sbi_misaligned_tinst_fixup(ulong orig_tinst, ulong new_tinst, return orig_tinst | (addr_offset << SH_RS1); } -static int sbi_trap_emulate_load(struct sbi_trap_regs *regs, - const struct sbi_trap_info *orig_trap, +static int sbi_trap_emulate_load(struct sbi_trap_context *tcntx, sbi_trap_ld_emulator emu) { + const struct sbi_trap_info *orig_trap = &tcntx->trap; + struct sbi_trap_regs *regs = &tcntx->regs; ulong insn, insn_len; union sbi_ldst_data val = { 0 }; struct sbi_trap_info uptrap; @@ -150,8 +148,7 @@ static int sbi_trap_emulate_load(struct sbi_trap_regs *regs, return sbi_trap_redirect(regs, orig_trap); } - rc = emu(len, &val, regs, orig_trap); - + rc = emu(len, &val, tcntx); if (rc <= 0) return rc; @@ -169,10 +166,11 @@ static int sbi_trap_emulate_load(struct sbi_trap_regs *regs, return 0; } -static int sbi_trap_emulate_store(struct sbi_trap_regs *regs, - const struct sbi_trap_info *orig_trap, +static int sbi_trap_emulate_store(struct sbi_trap_context *tcntx, sbi_trap_st_emulator emu) { + const struct sbi_trap_info *orig_trap = &tcntx->trap; + struct sbi_trap_regs *regs = &tcntx->regs; ulong insn, insn_len; union sbi_ldst_data val; struct sbi_trap_info uptrap; @@ -254,8 +252,7 @@ static int sbi_trap_emulate_store(struct sbi_trap_regs *regs, return sbi_trap_redirect(regs, orig_trap); } - rc = emu(len, val, regs, orig_trap); - + rc = emu(len, val, tcntx); if (rc <= 0) return rc; @@ -265,9 +262,10 @@ static int sbi_trap_emulate_store(struct sbi_trap_regs *regs, } static int sbi_misaligned_ld_emulator(int rlen, union sbi_ldst_data *out_val, - struct sbi_trap_regs *regs, - const struct sbi_trap_info *orig_trap) + struct sbi_trap_context *tcntx) { + const struct sbi_trap_info *orig_trap = &tcntx->trap; + struct sbi_trap_regs *regs = &tcntx->regs; struct sbi_trap_info uptrap; int i; @@ -283,17 +281,16 @@ static int sbi_misaligned_ld_emulator(int rlen, union sbi_ldst_data *out_val, return rlen; } -int sbi_misaligned_load_handler(struct sbi_trap_regs *regs, - const struct sbi_trap_info *orig_trap) +int sbi_misaligned_load_handler(struct sbi_trap_context *tcntx) { - return sbi_trap_emulate_load(regs, orig_trap, - sbi_misaligned_ld_emulator); + return sbi_trap_emulate_load(tcntx, sbi_misaligned_ld_emulator); } static int sbi_misaligned_st_emulator(int wlen, union sbi_ldst_data in_val, - struct sbi_trap_regs *regs, - const struct sbi_trap_info *orig_trap) + struct sbi_trap_context *tcntx) { + const struct sbi_trap_info *orig_trap = &tcntx->trap; + struct sbi_trap_regs *regs = &tcntx->regs; struct sbi_trap_info uptrap; int i; @@ -309,17 +306,17 @@ static int sbi_misaligned_st_emulator(int wlen, union sbi_ldst_data in_val, return wlen; } -int sbi_misaligned_store_handler(struct sbi_trap_regs *regs, - const struct sbi_trap_info *orig_trap) +int sbi_misaligned_store_handler(struct sbi_trap_context *tcntx) { - return sbi_trap_emulate_store(regs, orig_trap, - sbi_misaligned_st_emulator); + return sbi_trap_emulate_store(tcntx, sbi_misaligned_st_emulator); } static int sbi_ld_access_emulator(int rlen, union sbi_ldst_data *out_val, - struct sbi_trap_regs *regs, - const struct sbi_trap_info *orig_trap) + struct sbi_trap_context *tcntx) { + const struct sbi_trap_info *orig_trap = &tcntx->trap; + struct sbi_trap_regs *regs = &tcntx->regs; + /* If fault came from M mode, just fail */ if (((regs->mstatus & MSTATUS_MPP) >> MSTATUS_MPP_SHIFT) == PRV_M) return SBI_EINVAL; @@ -332,16 +329,17 @@ static int sbi_ld_access_emulator(int rlen, union sbi_ldst_data *out_val, return rlen; } -int sbi_load_access_handler(struct sbi_trap_regs *regs, - const struct sbi_trap_info *orig_trap) +int sbi_load_access_handler(struct sbi_trap_context *tcntx) { - return sbi_trap_emulate_load(regs, orig_trap, sbi_ld_access_emulator); + return sbi_trap_emulate_load(tcntx, sbi_ld_access_emulator); } static int sbi_st_access_emulator(int wlen, union sbi_ldst_data in_val, - struct sbi_trap_regs *regs, - const struct sbi_trap_info *orig_trap) + struct sbi_trap_context *tcntx) { + const struct sbi_trap_info *orig_trap = &tcntx->trap; + struct sbi_trap_regs *regs = &tcntx->regs; + /* If fault came from M mode, just fail */ if (((regs->mstatus & MSTATUS_MPP) >> MSTATUS_MPP_SHIFT) == PRV_M) return SBI_EINVAL; @@ -354,8 +352,7 @@ static int sbi_st_access_emulator(int wlen, union sbi_ldst_data in_val, return wlen; } -int sbi_store_access_handler(struct sbi_trap_regs *regs, - const struct sbi_trap_info *orig_trap) +int sbi_store_access_handler(struct sbi_trap_context *tcntx) { - return sbi_trap_emulate_store(regs, orig_trap, sbi_st_access_emulator); + return sbi_trap_emulate_store(tcntx, sbi_st_access_emulator); }