From patchwork Mon May 1 12:08:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 1775482 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=) 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=V9Ot0SrD; 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=A+CG0NLi; dkim-atps=neutral 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 (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Q92c61HJJz20fX for ; Mon, 1 May 2023 22:30:30 +1000 (AEST) 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: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:In-Reply-To:References: List-Owner; bh=skcpPisvhWCd4rnCp/dl10+/u1Vbf9IOfZ6HPiLQgwE=; b=V9Ot0SrDmieBHH kVKw9qtFKDkR5NFuPzM/ssOKhq8G0DZVwrUAUb2L5nuOW49Pft27RktsNnlFME5GiHnP6aBEpfC9Z GZmkSO9RCJ+Fli77i6ECRh0yFNemh7+xjdDUroyhLht/JMQ1fV1CVtbPo521QllPUuAWYfqAqgMoa bTDrlROhBFcC92McMx/+4Qn/XOVfCjoy01/vsRujQWcnVhbjMN9x+fhQ6C0E5JYATuKMQdgS8kq6/ l2aw8gH05FQvrub2q0HLTunVMuYwZLS+IdmDyyDojQNjv2Sk42wMESwV+t373Z+G0qq5dJCxAcSfY ZG8prD0IqQ+CP/KI1GoQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1ptSfX-00Fxqs-2a; Mon, 01 May 2023 12:30:15 +0000 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1ptSKk-00FpeP-0T for opensbi@lists.infradead.org; Mon, 01 May 2023 12:08:47 +0000 Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-3062678861fso1070376f8f.0 for ; Mon, 01 May 2023 05:08:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1682942921; x=1685534921; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=O4uU/jMCRixqXXoBAf2vxscN/vc5VkA3W+O2nNQNMXQ=; b=A+CG0NLio9xwJk6Ntb1gMBzDrUsRUSiJ9SugILZ1SYR4qJgEetimjHdT8qUviqUbRJ 8GamS851aAezwpF9s4jyEZ+39vjGbMNNBMI/hUS1DveGTJAqR/pRlvDX20MaKIqLbjVu xzeIEV3FTwgey/Rh0A7rS9XfEjQWBffpUBCLoRg0w2oTubKq40V72oE7hKuELLOnAiYF GYkztcq+bikfO3Z6E042z7AzCHIjRBYMGX3uluIuW7Cd21ACDQde26XgB7oWPNsJgtlw wrZBjNE+V5OIwaD3jEfEpx8X5g7Dg+It4+VklXtghrlywDe//V+i52lhowPCvh+XNdTv USTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682942921; x=1685534921; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=O4uU/jMCRixqXXoBAf2vxscN/vc5VkA3W+O2nNQNMXQ=; b=LFtv65Y0LjOCqMf7lFSU6IO61aMklMIquhyYhNuamwid7YWOrdKvA+ThMtO88oBtaz sFgEFDRnh0fqJVT+6Z4ImnjrzXd9His1lj8LJ4V0FZ+erSBhfXqSQp1MiCkcZj0e1tuG 6epIS9Fv5AS1nCl3TsAgRdawuRv8YCWpSN/6WutLJtST08VIOIEfBLFcjLJvceyGEwX5 TErk/0+Zob0dwpzj155QE/UlY4qaG7ffXPr/HQXP0vNpzoVoJWOvgsvRgj17T4Cw2tIy yneRG56vqvWCMZO2k7OVEkDMcYSAf7BRs1E2UT86IYl9+uxOyCSjphYvbeUTzOLOP23/ OnjA== X-Gm-Message-State: AC+VfDyVaH1lft8slhk+zc2loJFuKGEn1LzTF5GpHUDYL4UllR1M9xNU 4kSMyCOguczuksXS++eNkbCUqFV0KoryjNz1m7w= X-Google-Smtp-Source: ACHHUZ4k87KTrzpHPBlTNxhLh9fPoFXPiza7bsOsPRQ47f3WSVqKFwADeAWYA6cpAWPmTQNsmg9uKw== X-Received: by 2002:a05:6000:12c5:b0:2ef:1c8c:1113 with SMTP id l5-20020a05600012c500b002ef1c8c1113mr9723309wrx.9.1682942920874; Mon, 01 May 2023 05:08:40 -0700 (PDT) Received: from localhost (cst2-173-16.cust.vodafone.cz. [31.30.173.16]) by smtp.gmail.com with ESMTPSA id f11-20020adffccb000000b002f90a75b843sm28086892wrs.117.2023.05.01.05.08.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 May 2023 05:08:40 -0700 (PDT) From: Andrew Jones To: opensbi@lists.infradead.org Cc: Xiang W , Anup Patel Subject: [PATCH v3] lib: sbi: Ensure SBI extension is available Date: Mon, 1 May 2023 14:08:39 +0200 Message-Id: <20230501120839.334341-1-ajones@ventanamicro.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230501_050846_192555_2E14F6AA X-CRM114-Status: GOOD ( 17.41 ) 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: Ensure attempts to invoke SBI extension functions fail with SBI_ERR_NOT_SUPPORTED when the extension's probe function has reported that the extension is not available. To avoid invoking probe too freq [...] 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 [2a00:1450:4864:20:0:0:0:42a 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_VALID Message has at least one valid DKIM or DK signature 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 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 Ensure attempts to invoke SBI extension functions fail with SBI_ERR_NOT_SUPPORTED when the extension's probe function has reported that the extension is not available. To avoid invoking probe too frequently, we check single extension ID extensions at init time and even drop them from the extension list when their probe fails. If the probe succeeds, we keep it, and then later seeing that it's a single extension ID extension is enough to know it's available. Extensions which have multiple IDs must have its probe called for each, so we don't try to reduce calls to those. It's expected that these multi-ID extension probe functions implement their own optimizations in order to ensure extension lookups are fast. Signed-off-by: Andrew Jones --- v3: - Only apply optimization to single extension ID extensions [Xiang] - Drop extensions from extension list when they can be probed at init time (and drop the, now unnecessary, status) [Anup] lib/sbi/sbi_ecall.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/lib/sbi/sbi_ecall.c b/lib/sbi/sbi_ecall.c index 76a1ae9ab733..cb73105d7aa8 100644 --- a/lib/sbi/sbi_ecall.c +++ b/lib/sbi/sbi_ecall.c @@ -42,16 +42,19 @@ static SBI_LIST_HEAD(ecall_exts_list); struct sbi_ecall_extension *sbi_ecall_find_extension(unsigned long extid) { - struct sbi_ecall_extension *t, *ret = NULL; + struct sbi_ecall_extension *t; + unsigned long out_val; sbi_list_for_each_entry(t, &ecall_exts_list, head) { if (t->extid_start <= extid && extid <= t->extid_end) { - ret = t; - break; + if (t->extid_start != t->extid_end && t->probe && + (t->probe(extid, &out_val) || !out_val)) + return NULL; + return t; } } - return ret; + return NULL; } int sbi_ecall_register_extension(struct sbi_ecall_extension *ext) @@ -148,15 +151,26 @@ int sbi_ecall_handler(struct sbi_trap_regs *regs) int sbi_ecall_init(void) { - int ret; struct sbi_ecall_extension *ext; - unsigned long i; + unsigned long out_val, i; + int ret; for (i = 0; i < sbi_ecall_exts_size; i++) { ext = sbi_ecall_exts[i]; - ret = sbi_ecall_register_extension(ext); - if (ret) - return ret; + /* + * Don't bother adding extensions which have a single extension + * ID and its probe fails. Extensions with multiple IDs need to + * have their probe called on specific IDs, so we need to add + * them here and probe on each use. And, of course, if there + * isn't a probe function, then the extension is always + * available, so we add it here. + */ + if (ext->extid_start != ext->extid_end || !ext->probe || + (!ext->probe(ext->extid_start, &out_val) && out_val)) { + ret = sbi_ecall_register_extension(ext); + if (ret) + return ret; + } } return 0;