From patchwork Thu Oct 27 13:02:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 1695401 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=kvm-riscv-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=AwFfOBWU; 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=hel5t1Nv; 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 4Mym8z1LbZz23lD for ; Fri, 28 Oct 2022 00:04:18 +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=+qgny0h6ooHZigj/AupkNCK9fpEEHWzJ3Uu9P7nhQyw=; b=AwFfOBWUukBUUi Sh2qLF7pSlTt+xiijt1oC/l8Wlv+m+6/Peu95SVZGE6WZ1WIbqRACPtxb2yhAa/NH4yd24HaIlFD9 V2yHcEY0hWLPZ0vOzwPMeG3K5sEEAG3IWHmTipKClDJk2wqmSOanfAC/ZbrFOA4iH5rkdy0Tfgl9H VdnaEwQ823snWYbaem9Prns2eBMA/BQxrhM99soJMugRaX4u8qCKcEFxRmjxzhxXgDaLRYwVEFWmJ h0ERD87YhrAVTm+76qr5ssdRCJp3eEiZho/r1koZCQaHPAXg263J0qEljZ34Xf/Wx3unJxs0HpFK1 G54rlK+dZHdewlEWiRbQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oo2YQ-00DJYO-Du; Thu, 27 Oct 2022 13:04:14 +0000 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oo2X8-00DJ0F-Nt for kvm-riscv@lists.infradead.org; Thu, 27 Oct 2022 13:02:56 +0000 Received: by mail-wr1-x434.google.com with SMTP id y16so2016784wrt.12 for ; Thu, 27 Oct 2022 06:02:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; 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=tB7b6oKR1dfUOgZAsQ2t0LFxMC26256opXYDnh4htWI=; b=hel5t1Nv9aALn3lZc7KRzARJ3XpiGU6rcAWv9iymh/hkpgFOsASWeFOaZxpDcuqONb Uahw+bFSpnYkyKNOnw3JIihcsnWSypIdzcSt5lvYu17/rLeURHLwBrqvQstEk/aIO6yf Joe7tzfOfw8LSZrKRZQrvlNCOKQZW515+MjsuUHhaIfRAAHjbruDwMAylkx7Xoq0tkfA ShO3333gIUMLNuHxnrM97f/VnPo0pa2kWH1OQtaLkExt96dUdEavsgpSQ7RRR70jnODA ONVK9QSQGJRQcVMMGOl0h2wvefqIynqprVEfCFSxpKxJDDC7+OYpaY74LLgzkj/4eH6m yBuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=tB7b6oKR1dfUOgZAsQ2t0LFxMC26256opXYDnh4htWI=; b=feYdXJUZMex4OrW0V4EAY1b4JcShWLrSUtXPenmI7Pyv3NyhQRy7QYouR6iTpcwjrQ 4TEzegGpQG7G9rRicfuuI2IAF/pSoXPh7bVnQQoDGrZMPyXkyRt6e3KMYhJLC3tXv+CC tseDPw8hkSEc+H1bjAe+WSwtyNYekRdVaFXCgJDdjbCjWsiKE3AuzZfEAxXOAtRMLQeP qlR/ysOL4hGCshVvFr/fWvxW/A9MXxhPbnfRnXoK6GYr7NLC16YWye/amd2ncjusPHye khYKbjJRj5Y4UNzBiWryNbCJMzcvwzsnrHgkIEQlWBO8QbOdpFhEbT6KTRXYjhAwq+h7 WJfg== X-Gm-Message-State: ACrzQf3oWy0R9VjMOT1AIjrfyUdZV+Iy4Jr9gbrusyEK+TbKHJYS5mB/ BpJKFkDCShwwzYBAiIyJyajNgw== X-Google-Smtp-Source: AMsMyM7xmBzpLb+o7KlqopAHv9x2UiU8xiso95f8+//9/YjTCtomW7FGBNQJ1bQ6lAs8B/j1nZi+EA== X-Received: by 2002:a5d:5a18:0:b0:22f:4f72:213a with SMTP id bq24-20020a5d5a18000000b0022f4f72213amr32675517wrb.57.1666875770575; Thu, 27 Oct 2022 06:02:50 -0700 (PDT) Received: from localhost (cst2-173-61.cust.vodafone.cz. [31.30.173.61]) by smtp.gmail.com with ESMTPSA id n5-20020a05600c304500b003a84375d0d1sm4426782wmh.44.2022.10.27.06.02.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Oct 2022 06:02:50 -0700 (PDT) From: Andrew Jones To: linux-riscv@lists.infradead.org, kvm-riscv@lists.infradead.org Cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , Anup Patel , Heiko Stuebner , Conor Dooley , Atish Patra , Jisheng Zhang Subject: [PATCH 1/9] RISC-V: Factor out body of riscv_init_cbom_blocksize loop Date: Thu, 27 Oct 2022 15:02:39 +0200 Message-Id: <20221027130247.31634-2-ajones@ventanamicro.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221027130247.31634-1-ajones@ventanamicro.com> References: <20221027130247.31634-1-ajones@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221027_060254_809188_45CC2E69 X-CRM114-Status: GOOD ( 10.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: Refactor riscv_init_cbom_blocksize() to prepare for it to be used for both cbom block size and cboz block size. Signed-off-by: Andrew Jones --- arch/riscv/mm/cacheflush.c | 45 +++++++++++++++++++++ 1 file changed, 25 insertions(+), 20 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 [2a00:1450:4864:20:0:0:0:434 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: kvm-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "kvm-riscv" Errors-To: kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Refactor riscv_init_cbom_blocksize() to prepare for it to be used for both cbom block size and cboz block size. Signed-off-by: Andrew Jones Reviewed-by: Heiko Stuebner Reviewed-by: Conor Dooley --- arch/riscv/mm/cacheflush.c | 45 +++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/arch/riscv/mm/cacheflush.c b/arch/riscv/mm/cacheflush.c index 57b40a350420..f096b9966cae 100644 --- a/arch/riscv/mm/cacheflush.c +++ b/arch/riscv/mm/cacheflush.c @@ -91,34 +91,39 @@ void flush_icache_pte(pte_t pte) unsigned int riscv_cbom_block_size; EXPORT_SYMBOL_GPL(riscv_cbom_block_size); +static void cbo_get_block_size(struct device_node *node, + const char *name, u32 *blksz, + unsigned long *first_hartid) +{ + unsigned long hartid; + u32 val; + + if (riscv_of_processor_hartid(node, &hartid)) + return; + + if (of_property_read_u32(node, name, &val)) + return; + + if (!*blksz) { + *blksz = val; + *first_hartid = hartid; + } else if (*blksz != val) { + pr_warn("%s mismatched between harts %lu and %lu\n", + name, *first_hartid, hartid); + } +} + void riscv_init_cbom_blocksize(void) { struct device_node *node; unsigned long cbom_hartid; - u32 val, probed_block_size; - int ret; + u32 probed_block_size; probed_block_size = 0; for_each_of_cpu_node(node) { - unsigned long hartid; - - ret = riscv_of_processor_hartid(node, &hartid); - if (ret) - continue; - /* set block-size for cbom extension if available */ - ret = of_property_read_u32(node, "riscv,cbom-block-size", &val); - if (ret) - continue; - - if (!probed_block_size) { - probed_block_size = val; - cbom_hartid = hartid; - } else { - if (probed_block_size != val) - pr_warn("cbom-block-size mismatched between harts %lu and %lu\n", - cbom_hartid, hartid); - } + cbo_get_block_size(node, "riscv,cbom-block-size", + &probed_block_size, &cbom_hartid); } if (probed_block_size) From patchwork Thu Oct 27 13:02:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 1695407 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=kvm-riscv-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=y+d3ds//; 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+s3px9Y; 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 4MymBg3B5fz23kY for ; Fri, 28 Oct 2022 00:05: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=8o3KXUiDU7f93JnzemWE+2uIPYa2ukIj1BOvrGalF7U=; b=y+d3ds//4lcQ0z WXp/yhu1xYRxKQhvcYs2UIVRBFVKqj35Lz68D36yQGdIKyD0ztqQiH/C/Ju6CmStmcWcLJT5lCIR6 21jPHnjujjN1S6n/pEG5iAR/o7tBeDoGGambKWZ1VLv0roNi96/PvMa6e2hx2Q4D4bKOeFFFMQtG1 f1FFDMDStAioTDoj+O5Xcg/ROWCSxmDD55+AMCfCfJiTuYMda/RqsnrC++pb0L++CVpY1wxHS2KKL hVuZ4c3K92MoMmqqzEf/pZs2fJIULxZYn0mE879bAtuR656SVT9XY/G0EKYwiqqtGlPetmuyYGath 9cQ71srHsmuA5oZuaVhg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oo2Zp-00DKPH-DM; Thu, 27 Oct 2022 13:05:41 +0000 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oo2XI-00DJ4U-IB for kvm-riscv@lists.infradead.org; Thu, 27 Oct 2022 13:03:07 +0000 Received: by mail-wm1-x32d.google.com with SMTP id fn7-20020a05600c688700b003b4fb113b86so1169981wmb.0 for ; Thu, 27 Oct 2022 06:03:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; 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=ypq1jHU6FqMI0efCbfJSsSlnjMaAcFVEo7l5rTk9GE0=; b=A+s3px9YR/AIymPX+iXjL/IgHW8a/E3j00udC/0Eh0iE7BQNoIGWhqZfDSqPOmE7SH 7XMJrsmNoxHGia7hHEzpD1Gzz5Wgc6g2HxFxP67iG6GLSwb4LAmB2IT5LJqsZy3Nwgdl aWuYKZl4zEw+rb6isikRjJIViYqcO5r97i/e7Hm5oUkU+e8PSqDkcnFaM9zWBTWfDluS 7BBN4Gc390iP2Xj6Q5uHfMZL9RpvHJ4bpvR1I7eVa8emu8Ap4INKTyPwPT0y1qWbxs3M ZM1WOO2vmEu3fVEzk0np5cUc0S30zYuRJhBWfCsEnBz4ybUHUmW/3uzu+/+n/5jV3vO6 hgSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=ypq1jHU6FqMI0efCbfJSsSlnjMaAcFVEo7l5rTk9GE0=; b=4zcJasVC6lImBrKs/IOVuDBcbzftY6QYpROAY15cJ3lX0Enco4AkFW7JwJPtHINUof x1nphZ4TQx+lNfXv/+OGUfRGmyGb3YyTRx6Wai+C0rtzzrzW3T+n8yLfY8OdgNM+tFS3 eeTriLpNeicYTm0vgtsCuKWuPFAW/Cqu1rcqnoOA9zLe6wKw14p17l/RXbEQQ78C3f15 +H7SH/OnsXUttYRdhA5ogfXGlFzOiQYjLVafv2yqCu4/eD9RWC2aImTMnnv2gyQDcW3c crDA+pxIIVTlsVDZrQFZB7hM/S+eCbQQmt2KrOr2hLm1MbODjHScubBchRcojizJFJbI aXEQ== X-Gm-Message-State: ACrzQf1t09uNhwyPdhxmBPvC9Eg+SFuu+xeHGIgDNAD0L3+EJW7WnT9P z+c3LIO3Rfr+ygW0ChR6JcruNQ== X-Google-Smtp-Source: AMsMyM4pGTsLz/Q3zR03Raj8BHQ6U4ZtX2hvt4fOM3kTory1SVpA8TO1ZKOw9RnoLtWuCl8yhvaqgA== X-Received: by 2002:a05:600c:4b19:b0:3c6:cc7c:763c with SMTP id i25-20020a05600c4b1900b003c6cc7c763cmr5868711wmp.57.1666875772197; Thu, 27 Oct 2022 06:02:52 -0700 (PDT) Received: from localhost (cst2-173-61.cust.vodafone.cz. [31.30.173.61]) by smtp.gmail.com with ESMTPSA id i17-20020a05600c355100b003a8434530bbsm5047740wmq.13.2022.10.27.06.02.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Oct 2022 06:02:51 -0700 (PDT) From: Andrew Jones To: linux-riscv@lists.infradead.org, kvm-riscv@lists.infradead.org Cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , Anup Patel , Heiko Stuebner , Conor Dooley , Atish Patra , Jisheng Zhang Subject: [PATCH 2/9] RISC-V: Add Zicboz detection and block size parsing Date: Thu, 27 Oct 2022 15:02:40 +0200 Message-Id: <20221027130247.31634-3-ajones@ventanamicro.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221027130247.31634-1-ajones@ventanamicro.com> References: <20221027130247.31634-1-ajones@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221027_060304_656584_2E78B344 X-CRM114-Status: GOOD ( 17.23 ) 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: Mostly follow the same pattern as Zicbom, but leave out the toolchain checks as we plan to use the insn-def framework for the cbo.zero instruction. Signed-off-by: Andrew Jones --- arch/riscv/Kconfig | 13 +++++++++++++ arch/riscv/include/asm/cacheflush.h | 3 ++- arch/riscv/include/asm/hwcap.h | 1 + arch/riscv/kernel/cpu.c [...] 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:32d 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: kvm-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "kvm-riscv" Errors-To: kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Mostly follow the same pattern as Zicbom, but leave out the toolchain checks as we plan to use the insn-def framework for the cbo.zero instruction. Signed-off-by: Andrew Jones Reviewed-by: Heiko Stuebner Reviewed-by: Conor Dooley --- arch/riscv/Kconfig | 13 +++++++++++++ arch/riscv/include/asm/cacheflush.h | 3 ++- arch/riscv/include/asm/hwcap.h | 1 + arch/riscv/kernel/cpu.c | 1 + arch/riscv/kernel/cpufeature.c | 10 ++++++++++ arch/riscv/kernel/setup.c | 2 +- arch/riscv/mm/cacheflush.c | 23 +++++++++++++++-------- 7 files changed, 43 insertions(+), 10 deletions(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 6b48a3ae9843..c20e6fa0c0b1 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -433,6 +433,19 @@ config RISCV_ISA_ZICBOM If you don't know what to do here, say Y. +config RISCV_ISA_ZICBOZ + bool "Zicboz extension support for faster zeroing of memory" + depends on !XIP_KERNEL && MMU + select RISCV_ALTERNATIVE + default y + help + Adds support to dynamically detect the presence of the ZICBOZ + extension (cbo.zero instruction) and enable its usage. + + The Zicboz extension is used for faster zeroing of memory. + + If you don't know what to do here, say Y. + config FPU bool "FPU support" default y diff --git a/arch/riscv/include/asm/cacheflush.h b/arch/riscv/include/asm/cacheflush.h index f6fbe7042f1c..5b31568cf5e6 100644 --- a/arch/riscv/include/asm/cacheflush.h +++ b/arch/riscv/include/asm/cacheflush.h @@ -43,7 +43,8 @@ void flush_icache_mm(struct mm_struct *mm, bool local); #endif /* CONFIG_SMP */ extern unsigned int riscv_cbom_block_size; -void riscv_init_cbom_blocksize(void); +extern unsigned int riscv_cboz_block_size; +void riscv_init_cbo_blocksizes(void); #ifdef CONFIG_RISCV_DMA_NONCOHERENT void riscv_noncoherent_supported(void); diff --git a/arch/riscv/include/asm/hwcap.h b/arch/riscv/include/asm/hwcap.h index 5d6492bde446..eaa5a972ad2d 100644 --- a/arch/riscv/include/asm/hwcap.h +++ b/arch/riscv/include/asm/hwcap.h @@ -45,6 +45,7 @@ #define RISCV_ISA_EXT_ZIHINTPAUSE 29 #define RISCV_ISA_EXT_SSTC 30 #define RISCV_ISA_EXT_SVINVAL 31 +#define RISCV_ISA_EXT_ZICBOZ 32 #define RISCV_ISA_EXT_ID_MAX RISCV_ISA_EXT_MAX diff --git a/arch/riscv/kernel/cpu.c b/arch/riscv/kernel/cpu.c index fa427bdcf773..bf969218f609 100644 --- a/arch/riscv/kernel/cpu.c +++ b/arch/riscv/kernel/cpu.c @@ -144,6 +144,7 @@ static struct riscv_isa_ext_data isa_ext_arr[] = { __RISCV_ISA_EXT_DATA(svpbmt, RISCV_ISA_EXT_SVPBMT), __RISCV_ISA_EXT_DATA(zicbom, RISCV_ISA_EXT_ZICBOM), __RISCV_ISA_EXT_DATA(zihintpause, RISCV_ISA_EXT_ZIHINTPAUSE), + __RISCV_ISA_EXT_DATA(zicboz, RISCV_ISA_EXT_ZICBOZ), __RISCV_ISA_EXT_DATA("", RISCV_ISA_EXT_MAX), }; diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index 18b9ed4df1f4..e13b3391de76 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -78,6 +78,15 @@ static bool riscv_isa_extension_check(int id) return false; } return true; + case RISCV_ISA_EXT_ZICBOZ: + if (!riscv_cboz_block_size) { + pr_err("Zicboz detected in ISA string, but no cboz-block-size found\n"); + return false; + } else if (!is_power_of_2(riscv_cboz_block_size)) { + pr_err("cboz-block-size present, but is not a power-of-2\n"); + return false; + } + return true; } return true; @@ -225,6 +234,7 @@ void __init riscv_fill_hwcap(void) SET_ISA_EXT_MAP("zihintpause", RISCV_ISA_EXT_ZIHINTPAUSE); SET_ISA_EXT_MAP("sstc", RISCV_ISA_EXT_SSTC); SET_ISA_EXT_MAP("svinval", RISCV_ISA_EXT_SVINVAL); + SET_ISA_EXT_MAP("zicboz", RISCV_ISA_EXT_ZICBOZ); } #undef SET_ISA_EXT_MAP } diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c index a07917551027..26de0d8fd23d 100644 --- a/arch/riscv/kernel/setup.c +++ b/arch/riscv/kernel/setup.c @@ -296,7 +296,7 @@ void __init setup_arch(char **cmdline_p) setup_smp(); #endif - riscv_init_cbom_blocksize(); + riscv_init_cbo_blocksizes(); riscv_fill_hwcap(); apply_boot_alternatives(); #ifdef CONFIG_RISCV_DMA_NONCOHERENT diff --git a/arch/riscv/mm/cacheflush.c b/arch/riscv/mm/cacheflush.c index f096b9966cae..208e0d58bde3 100644 --- a/arch/riscv/mm/cacheflush.c +++ b/arch/riscv/mm/cacheflush.c @@ -91,6 +91,9 @@ void flush_icache_pte(pte_t pte) unsigned int riscv_cbom_block_size; EXPORT_SYMBOL_GPL(riscv_cbom_block_size); +unsigned int riscv_cboz_block_size; +EXPORT_SYMBOL_GPL(riscv_cboz_block_size); + static void cbo_get_block_size(struct device_node *node, const char *name, u32 *blksz, unsigned long *first_hartid) @@ -113,19 +116,23 @@ static void cbo_get_block_size(struct device_node *node, } } -void riscv_init_cbom_blocksize(void) +void riscv_init_cbo_blocksizes(void) { + unsigned long cbom_hartid, cboz_hartid; + u32 cbom_blksz = 0, cboz_blksz = 0; struct device_node *node; - unsigned long cbom_hartid; - u32 probed_block_size; - probed_block_size = 0; for_each_of_cpu_node(node) { - /* set block-size for cbom extension if available */ + /* set block-size for cbom and/or cboz extension if available */ cbo_get_block_size(node, "riscv,cbom-block-size", - &probed_block_size, &cbom_hartid); + &cbom_blksz, &cbom_hartid); + cbo_get_block_size(node, "riscv,cboz-block-size", + &cboz_blksz, &cboz_hartid); } - if (probed_block_size) - riscv_cbom_block_size = probed_block_size; + if (cbom_blksz) + riscv_cbom_block_size = cbom_blksz; + + if (cboz_blksz) + riscv_cboz_block_size = cboz_blksz; } From patchwork Thu Oct 27 13:02:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 1695403 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=kvm-riscv-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=0jvRzkEx; 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=HpADHk/4; 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 4Mym985ZZlz23kj for ; Fri, 28 Oct 2022 00:04:28 +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=V4Z/FVwzpptFniPKp1AQjuKh7sJsluqojlVp0TMzN4w=; b=0jvRzkExl5Vafn J0VF78D7ttIVdUGPz+mE5Kpvgpi8ajS1j8fyX12B32tXOQ6fVqWTmiLoUAJj/RuMXrkS4l4WDG3c/ l5SEdkL2t0vdOqHijN31pUfTBna0N0D+/NK9WJNA5xmg/kH6puYTSlP3R9kKVigeClZqxVYwpUG4c ceSBmWvKOlw9VFtNc3o4xNIOnOgA3g66ocRePlqOmOv+qpyunru3T2BwoTAKh36iyVqTYcJPTZcXH CIVvvYvV75NlQwgSbNdJ7glYHiD9iT+UjuXhYMaQWf5cpKBtsVTbU4PXCGI0qT08PNRxxnGOfC1E+ DP0PvwzLzCXJu7BARGuw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oo2YY-00DJdp-1K; Thu, 27 Oct 2022 13:04:22 +0000 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oo2XD-00DJ32-T0 for kvm-riscv@lists.infradead.org; Thu, 27 Oct 2022 13:03:02 +0000 Received: by mail-wm1-x332.google.com with SMTP id 5so949200wmo.1 for ; Thu, 27 Oct 2022 06:02:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; 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=KbUhxPuTy0jvwUlmdsFF6eMymGDJdoEDGUQqDgTA5G8=; b=HpADHk/4BhSephNX9PjCwzPq+u7ON6KbLkjy9rqEGS72imhKdp2XeGaBWjGNVeDPR/ t7gaFSWTtYPSxdHvqM3FwW/tPxcmUvqjo4N4pghN80NthcACr1Af5lNwe3tHrL0OIMKJ oBQbODjZam9y5KkxXoy26F4FBM5YnB5IP1j4C+/D3MGegc236po1UVH4VKRPt95lvd19 eASt1lmI6/TcImRjbryjQWiGZdNVAUsnO+BqvjX6+VcF4p7sfswmem1nJKgPexB2wGID DuxTivhH3mgpox8g7PT1z+WE4qDJD5cKmFsQ8SAYLenkLGGVX3FT5qn8u22JlyKvI1tB 0rIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=KbUhxPuTy0jvwUlmdsFF6eMymGDJdoEDGUQqDgTA5G8=; b=yawoXYs0jC9iG7NY5sRxGO8zoKwyOCe/GGxxytWvCjUcZ1XUEhPV/UpEYhrfgBg5Gw zHKA9j0I35JeLX6+gSHHixU4N/5x0KEVBcdkedsQhVrnkDtZClz4wbtcjVG5J9e4VlZ/ RzkTJSp4aEnRnTbAZs79uwd+kRmzB+DUxSH9t2727JmZPaiF1+Yt6FcDZNERWiGJgZnY vesv7jloZSvA0gP+cgbPo0lJ7Uy5QLjHCNGjTY2dksr18ij13QlZf1fd0q5JsG/t58x6 3xW+aVFl7TAJm/eaoiSdFWzK5N9s1f0q5+uwO3mGFPfjAWcwoRUKzbjSYCKDUy49skEE ezEA== X-Gm-Message-State: ACrzQf0nvNn2FcYz9LOqntEd61CFxeGuVpD2ebd026SJuszGOJ/DkVYT RPkiz3mcpmIwMV1BvwnG31H0OQ== X-Google-Smtp-Source: AMsMyM5fJj8yQsDoS1zq2027Jxq7yIoL/mg2qeZwvX+oHpS+36nH9RZ9vECWCmHKqFRMVVATrhJfcw== X-Received: by 2002:a05:600c:3b97:b0:3c7:14f0:f8d2 with SMTP id n23-20020a05600c3b9700b003c714f0f8d2mr5893020wms.159.1666875775469; Thu, 27 Oct 2022 06:02:55 -0700 (PDT) Received: from localhost (cst2-173-61.cust.vodafone.cz. [31.30.173.61]) by smtp.gmail.com with ESMTPSA id w8-20020adfde88000000b002366f9bd717sm1369029wrl.45.2022.10.27.06.02.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Oct 2022 06:02:55 -0700 (PDT) From: Andrew Jones To: linux-riscv@lists.infradead.org, kvm-riscv@lists.infradead.org Cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , Anup Patel , Heiko Stuebner , Conor Dooley , Atish Patra , Jisheng Zhang Subject: [PATCH 3/9] RISC-V: insn-def: Define cbo.zero Date: Thu, 27 Oct 2022 15:02:41 +0200 Message-Id: <20221027130247.31634-4-ajones@ventanamicro.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221027130247.31634-1-ajones@ventanamicro.com> References: <20221027130247.31634-1-ajones@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221027_060259_978755_4D6C701C X-CRM114-Status: UNSURE ( 8.41 ) 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: CBO instructions use the I-type of instruction format where the immediate is used to identify the CBO instruction type. Add I-type instruction encoding support to insn-def and also add cbo.zero. Signed-off-by: Andrew Jones --- arch/riscv/include/asm/insn-def.h | 50 +++++++++++++++++++++++++++++++ 1 file changed, 50 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 [2a00:1450:4864:20:0:0:0:332 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: kvm-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "kvm-riscv" Errors-To: kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org CBO instructions use the I-type of instruction format where the immediate is used to identify the CBO instruction type. Add I-type instruction encoding support to insn-def and also add cbo.zero. Signed-off-by: Andrew Jones Reviewed-by: Heiko Stuebner Reviewed-by: Conor Dooley --- arch/riscv/include/asm/insn-def.h | 50 +++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/arch/riscv/include/asm/insn-def.h b/arch/riscv/include/asm/insn-def.h index 16044affa57c..f13054716556 100644 --- a/arch/riscv/include/asm/insn-def.h +++ b/arch/riscv/include/asm/insn-def.h @@ -12,6 +12,12 @@ #define INSN_R_RD_SHIFT 7 #define INSN_R_OPCODE_SHIFT 0 +#define INSN_I_SIMM12_SHIFT 20 +#define INSN_I_RS1_SHIFT 15 +#define INSN_I_FUNC3_SHIFT 12 +#define INSN_I_RD_SHIFT 7 +#define INSN_I_OPCODE_SHIFT 0 + #ifdef __ASSEMBLY__ #ifdef CONFIG_AS_HAS_INSN @@ -20,6 +26,10 @@ .insn r \opcode, \func3, \func7, \rd, \rs1, \rs2 .endm + .macro insn_i, opcode, func3, rd, rs1, simm12 + .insn i \opcode, \func3, \rd, \rs1, \simm12 + .endm + #else #include @@ -33,9 +43,18 @@ (.L__gpr_num_\rs2 << INSN_R_RS2_SHIFT)) .endm + .macro insn_i, opcode, func3, rd, rs1, simm12 + .4byte ((\opcode << INSN_I_OPCODE_SHIFT) | \ + (\func3 << INSN_I_FUNC3_SHIFT) | \ + (.L__gpr_num_\rd << INSN_I_RD_SHIFT) | \ + (.L__gpr_num_\rs1 << INSN_I_RS1_SHIFT) | \ + (\simm12 << INSN_I_SIMM12_SHIFT)) + .endm + #endif #define __INSN_R(...) insn_r __VA_ARGS__ +#define __INSN_I(...) insn_i __VA_ARGS__ #else /* ! __ASSEMBLY__ */ @@ -44,6 +63,9 @@ #define __INSN_R(opcode, func3, func7, rd, rs1, rs2) \ ".insn r " opcode ", " func3 ", " func7 ", " rd ", " rs1 ", " rs2 "\n" +#define __INSN_I(opcode, func3, rd, rs1, simm12) \ + ".insn i " opcode ", " func3 ", " rd ", " rs1 ", " simm12 "\n" + #else #include @@ -60,14 +82,32 @@ " (.L__gpr_num_\\rs2 << " __stringify(INSN_R_RS2_SHIFT) "))\n" \ " .endm\n" +#define DEFINE_INSN_I \ + __DEFINE_ASM_GPR_NUMS \ +" .macro insn_i, opcode, func3, rd, rs1, simm12\n" \ +" .4byte ((\\opcode << " __stringify(INSN_I_OPCODE_SHIFT) ") |" \ +" (\\func3 << " __stringify(INSN_I_FUNC3_SHIFT) ") |" \ +" (.L__gpr_num_\\rd << " __stringify(INSN_I_RD_SHIFT) ") |" \ +" (.L__gpr_num_\\rs1 << " __stringify(INSN_I_RS1_SHIFT) ") |" \ +" (\\simm12 << " __stringify(INSN_I_SIMM12_SHIFT) "))\n" \ +" .endm\n" + #define UNDEFINE_INSN_R \ " .purgem insn_r\n" +#define UNDEFINE_INSN_I \ +" .purgem insn_i\n" + #define __INSN_R(opcode, func3, func7, rd, rs1, rs2) \ DEFINE_INSN_R \ "insn_r " opcode ", " func3 ", " func7 ", " rd ", " rs1 ", " rs2 "\n" \ UNDEFINE_INSN_R +#define __INSN_I(opcode, func3, rd, rs1, simm12) \ + DEFINE_INSN_I \ + "insn_i " opcode ", " func3 ", " rd ", " rs1 ", " simm12 "\n" \ + UNDEFINE_INSN_I + #endif #endif /* ! __ASSEMBLY__ */ @@ -76,9 +116,14 @@ __INSN_R(RV_##opcode, RV_##func3, RV_##func7, \ RV_##rd, RV_##rs1, RV_##rs2) +#define INSN_I(opcode, func3, rd, rs1, simm12) \ + __INSN_I(RV_##opcode, RV_##func3, RV_##rd, \ + RV_##rs1, RV_##simm12) + #define RV_OPCODE(v) __ASM_STR(v) #define RV_FUNC3(v) __ASM_STR(v) #define RV_FUNC7(v) __ASM_STR(v) +#define RV_SIMM12(v) __ASM_STR(v) #define RV_RD(v) __ASM_STR(v) #define RV_RS1(v) __ASM_STR(v) #define RV_RS2(v) __ASM_STR(v) @@ -87,6 +132,7 @@ #define RV___RS1(v) __RV_REG(v) #define RV___RS2(v) __RV_REG(v) +#define RV_OPCODE_MISC_MEM RV_OPCODE(15) #define RV_OPCODE_SYSTEM RV_OPCODE(115) #define HFENCE_VVMA(vaddr, asid) \ @@ -134,4 +180,8 @@ INSN_R(OPCODE_SYSTEM, FUNC3(0), FUNC7(51), \ __RD(0), RS1(gaddr), RS2(vmid)) +#define CBO_ZERO(base) \ + INSN_I(OPCODE_MISC_MEM, FUNC3(2), __RD(0), \ + RS1(base), SIMM12(4)) + #endif /* __ASM_INSN_DEF_H */ From patchwork Thu Oct 27 13:02:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 1695402 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=kvm-riscv-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=qoyfTddj; 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=K29mJiHC; 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 4Mym8z6pyzz23kj for ; Fri, 28 Oct 2022 00:04:19 +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=qxmvtFocDBv6r9VtigiTIiGiO5ArWK4IH0c5ROZdRlo=; b=qoyfTddj03aOnJ qQeY2pUBEkTeSskLX/vWvx3/iA48xU3BHn0uyfJxD7LEYGJxHL/BufgQZG9lbz90N9drhsFgzAiL7 2pPkZ7Ep/s10JsEecN9wZlgXGj60hxOYyp1gwY2eQ4tDz5kd2QExOsAkwydoraxb5PLSBZWIGEVI+ lsioHQ9gOha0GWpPhwg03/wHuvSOIun5XZFMq3dPr6wxYxclmZ/iPgZeJfPsuOHtIYcSgin9s851L xsXIDCyl7L+h47lbMEpk8Azkv2nSYA3N853ZvGZnrEPClVPtZiN4KFgXiSFveVIWzlxkPVpBAaxZ0 26UwcCozAMeABWw3TT2A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oo2YQ-00DJYd-WF; Thu, 27 Oct 2022 13:04:15 +0000 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oo2XD-00DJ35-3n for kvm-riscv@lists.infradead.org; Thu, 27 Oct 2022 13:03:00 +0000 Received: by mail-wr1-x430.google.com with SMTP id j15so2065699wrq.3 for ; Thu, 27 Oct 2022 06:02:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; 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=KS8Y5qGcq+TUeCm2VzHt6k1tiEHh3xZNsxJCuYP0OtE=; b=K29mJiHCubCTveiarEOUq2CVRHNeJSKN8+4a5Lc+cwX228AupQjsPwdjlP8mnDv00m iI/R842lfKG9eQY9fuoTZ6v6m546OWW4CNbfpuUfb0RoxYcap7vfmbBPZCheOiLLUfJ/ qDePRCNA8JIcXaNOIZ0UUbfjQpsHt9SX0z/5rUqc4KSDFzmoJ1217vl1/NbG5Se4Pv2Z qOj9JTvNyK0f24BJ2SZ2iyeKKD9/tSkKhjhcIP2oFA2syix8ksb+N87C+sUwbKhdj0+U lo44ADmgyXQ7lh/Stu1rdxwXzljYxQ0TqLXRnztR44UcHRzduxOGbhfHRSz6i8/UxFXA 5KUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=KS8Y5qGcq+TUeCm2VzHt6k1tiEHh3xZNsxJCuYP0OtE=; b=amVwScMoOAeJjg+UtzsIIU2/rv4T33sP7PCW+7SMasxoTnXI/+VyEDQWonJseLyqo/ erUveOUvepa1xkDXEECt2aMwOwnaD+rzUFy0eQl1L0uGPIds/aLvK/F7Q/wr74JLbnB3 siI74DXOyIWiqfVA2PdNuIrJKXFy9TX157rnn7WEmrseZoRQ1lgAV/qbRYqVz/zToFTE V26tR8B0GuWwFcVkG3YUQ7HoABywa5lxyBFZ4VqL2bHEAhELxG/q9d2qcYQ99ANJOZC6 nznXjH6RHy6Aao67CHhMF9mjlal6ev9QcVcnq2YatsXnzePHCF2FhVT7D9z/8pAQKGey fmQQ== X-Gm-Message-State: ACrzQf3cq532sc40VO61uc5FG+EhwMZiBqnGplORduGEhmxUz7zSOsWc ZW5lr3rrtDuOXaK1fRm3SXm04g== X-Google-Smtp-Source: AMsMyM5qog3y7CoIBUY7/1O/pd/VFJ50AlErLBDW0eu0vaYNGmqAJfpZ8624Jz3nN/V5/sjMEcvqyg== X-Received: by 2002:adf:e911:0:b0:236:73b7:e668 with SMTP id f17-20020adfe911000000b0023673b7e668mr12854735wrm.96.1666875777062; Thu, 27 Oct 2022 06:02:57 -0700 (PDT) Received: from localhost (cst2-173-61.cust.vodafone.cz. [31.30.173.61]) by smtp.gmail.com with ESMTPSA id 26-20020a05600c029a00b003c4ecff4e25sm1551492wmk.9.2022.10.27.06.02.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Oct 2022 06:02:56 -0700 (PDT) From: Andrew Jones To: linux-riscv@lists.infradead.org, kvm-riscv@lists.infradead.org Cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , Anup Patel , Heiko Stuebner , Conor Dooley , Atish Patra , Jisheng Zhang Subject: [PATCH 4/9] RISC-V: Use Zicboz in clear_page when available Date: Thu, 27 Oct 2022 15:02:42 +0200 Message-Id: <20221027130247.31634-5-ajones@ventanamicro.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221027130247.31634-1-ajones@ventanamicro.com> References: <20221027130247.31634-1-ajones@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221027_060259_212393_6B7BA137 X-CRM114-Status: GOOD ( 13.81 ) 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: Using memset() to zero a 4K page takes 563 total instructions where 20 are branches. clear_page() with Zicboz takes 198 total instructions where 64 are branches. We could reduce the number branches 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 [2a00:1450:4864:20:0:0:0:430 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: kvm-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "kvm-riscv" Errors-To: kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Using memset() to zero a 4K page takes 563 total instructions where 20 are branches. clear_page() with Zicboz takes 198 total instructions where 64 are branches. We could reduce the number branches by unrolling, but since the cboz block size isn't fixed, cbo.zero doesn't take an offset, and even PAGE_SIZE doesn't have to be 4K forever, we'd end up implementing a Duff device where each unrolled block would not only contain a cbo.zero instruction, but also an add to update the base address. So, for now, it seems the simple tight loop approach is better. At least we don't have to worry as much about potential icache misses as unrolled loops do. Of course as hardware becomes available we can experiment with unrolling too. Signed-off-by: Andrew Jones --- arch/riscv/include/asm/page.h | 6 +++++- arch/riscv/lib/Makefile | 1 + arch/riscv/lib/clear_page.S | 28 ++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 arch/riscv/lib/clear_page.S diff --git a/arch/riscv/include/asm/page.h b/arch/riscv/include/asm/page.h index ac70b0fd9a9a..a86d6d8a9ca0 100644 --- a/arch/riscv/include/asm/page.h +++ b/arch/riscv/include/asm/page.h @@ -49,10 +49,14 @@ #ifndef __ASSEMBLY__ +#ifdef CONFIG_RISCV_ISA_ZICBOZ +void clear_page(void *page); +#else #define clear_page(pgaddr) memset((pgaddr), 0, PAGE_SIZE) +#endif #define copy_page(to, from) memcpy((to), (from), PAGE_SIZE) -#define clear_user_page(pgaddr, vaddr, page) memset((pgaddr), 0, PAGE_SIZE) +#define clear_user_page(pgaddr, vaddr, page) clear_page(pgaddr) #define copy_user_page(vto, vfrom, vaddr, topg) \ memcpy((vto), (vfrom), PAGE_SIZE) diff --git a/arch/riscv/lib/Makefile b/arch/riscv/lib/Makefile index 25d5c9664e57..9ee5e2ab5143 100644 --- a/arch/riscv/lib/Makefile +++ b/arch/riscv/lib/Makefile @@ -5,5 +5,6 @@ lib-y += memset.o lib-y += memmove.o lib-$(CONFIG_MMU) += uaccess.o lib-$(CONFIG_64BIT) += tishift.o +lib-$(CONFIG_RISCV_ISA_ZICBOZ) += clear_page.o obj-$(CONFIG_FUNCTION_ERROR_INJECTION) += error-inject.o diff --git a/arch/riscv/lib/clear_page.S b/arch/riscv/lib/clear_page.S new file mode 100644 index 000000000000..cafa24a918d6 --- /dev/null +++ b/arch/riscv/lib/clear_page.S @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include +#include +#include +#include +#include +#include + +/* void clear_page(void *page) */ +ENTRY(__clear_page) +WEAK(clear_page) + li a2, PAGE_SIZE + ALTERNATIVE("j .Lno_zicboz", "nop", + 0, RISCV_ISA_EXT_ZICBOZ, CONFIG_RISCV_ISA_ZICBOZ) + la a3, riscv_cboz_block_size + lw a1, 0(a3) + add a2, a0, a2 +.Lzero_loop: + CBO_ZERO(a0) + add a0, a0, a1 + bltu a0, a2, .Lzero_loop + ret +.Lno_zicboz: + li a1, 0 + la a3, __memset + jr a3 +END(__clear_page) From patchwork Thu Oct 27 13:02:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 1695405 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=kvm-riscv-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=Qv9/SPeU; 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=H4XTc9NB; 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 4Mym9Y1ZHLz23kj for ; Fri, 28 Oct 2022 00:04: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: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=1rQvNBQAk2Lo74xQy/m9B1gkLP607AEM16bQHATg87U=; b=Qv9/SPeUphXc+Z gyug0JTgEMK7ku0Hz2o/IbeVz5KWO5qxuRAs6T0HylUlh3AjDqxnb5E1A0Enm4YMNjC7ztzkJ1uwk 75Z+MVhEVW2BBk8ET2r+EXnKq2OcsVVTuq13KHC/7AUgpH3Ut2wyDlA95o/futYav5OnF19ZrB9WU q/p4uv8D4gvKbeWXJqGZzo50pU8GicKwFggarug3aTvHC2QBJYFZmmeHgOkY9oCHSNMs7kx7MCVh+ sd3LY+AI4rNkqSTkC1ZDSR0WTvdM979SWvk1Jy8AHWF4YioQTmpz07FuBqRx824sAhgsKgaWUJ3Kr YQVwDOEbO2VihtahBqUg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oo2Yu-00DJsD-AK; Thu, 27 Oct 2022 13:04:44 +0000 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oo2XG-00DJ3S-ET for kvm-riscv@lists.infradead.org; Thu, 27 Oct 2022 13:03:04 +0000 Received: by mail-wm1-x32e.google.com with SMTP id jb18so939273wmb.4 for ; Thu, 27 Oct 2022 06:02:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; 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=MkY7EBDKO6YXvCwJ11XvLx5xkQ3Vf2bmYTCjXFGfgfc=; b=H4XTc9NBsb1BqLLz0pUlmU/ySHHap0gfu+qxRtuEL5bQF46sXwrWOz175WuqXLTSQU PfMNR7VkOWUGUjBHSNjORgsc9Lr8keFONx226QSxAqIHyEWIoZWyx1f1FIz/i4o6lUNC 6H1+0P/Zi8l63M018gcJrZQ156tcT2+o47YZaqZ/fu8ooGUFPj1Zlnaq94W6HRJxYm6x dp9BZNNfbmb8R0l4C3L++278AM2NmDI8PKgMaPkh4cczt0hpoMVkH00zxcwFvzehinRf ubE+sR8pPtEMLgZjvEfjOhS+2OAhlttoC7NzbotarQicPzKuR3MhR1XKBhQqxN1f9Gm4 ee2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=MkY7EBDKO6YXvCwJ11XvLx5xkQ3Vf2bmYTCjXFGfgfc=; b=0Dt7fQPJcGp4QFgLhCuJfAto3HC2uBVgKyliu1+TdFw81c1UK0lEw+zNdEQ2zv+6EV 1ghm05jG4FXh5yrh5IZoSuGCBIfSimW6t7aO0Kwldj0AbkvORseYoz5gnfkE6u+gmFuu WADcANYC6Ht3GVAI2qoOstkzL6TE3EoJI8XaVMYHj9v5UgTMYK5zNgRMnT0ZEZGLZ5GZ UDBugFXngBxhgg6jZqo4ZA5JR4u3uCgb1A1fCo0CjPBgdCJvyq5mzJeLa3w4hDZdRchl GyA9iWUTZU94AcJ+i0cENwSVCNWvt4Wo3hm6FyObfEO8cfqZvMnykr5wYWzPslisPieh lXJg== X-Gm-Message-State: ACrzQf1Ut/rCEACXqi6e221lfPxlyFByhC72xOmeFG/3UrU6QpV/0iLz jmvaSOgTZDBy3BLeimMwSSP9vLrPrycn9Q== X-Google-Smtp-Source: AMsMyM6aeY8K5XUzA/BRxMJmVWftTkQvbYq+9rPyWVzasbJtRk3cWmZ6gkszvKIpjuPdqTcabm00VQ== X-Received: by 2002:a05:600c:21c5:b0:3c6:ec59:5180 with SMTP id x5-20020a05600c21c500b003c6ec595180mr5738306wmj.130.1666875778776; Thu, 27 Oct 2022 06:02:58 -0700 (PDT) Received: from localhost (cst2-173-61.cust.vodafone.cz. [31.30.173.61]) by smtp.gmail.com with ESMTPSA id o17-20020a5d62d1000000b0023672104c24sm1112864wrv.74.2022.10.27.06.02.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Oct 2022 06:02:58 -0700 (PDT) From: Andrew Jones To: linux-riscv@lists.infradead.org, kvm-riscv@lists.infradead.org Cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , Anup Patel , Heiko Stuebner , Conor Dooley , Atish Patra , Jisheng Zhang Subject: [PATCH 5/9] RISC-V: KVM: Provide UAPI for Zicboz block size Date: Thu, 27 Oct 2022 15:02:43 +0200 Message-Id: <20221027130247.31634-6-ajones@ventanamicro.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221027130247.31634-1-ajones@ventanamicro.com> References: <20221027130247.31634-1-ajones@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221027_060302_519395_E5EF2678 X-CRM114-Status: GOOD ( 11.83 ) 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: We're about to allow guests to use the Zicboz extension. KVM userspace needs to know the cache block size in order to properly advertise it to the guest. Provide a virtual config register for userspac [...] 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:32e 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: kvm-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "kvm-riscv" Errors-To: kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org We're about to allow guests to use the Zicboz extension. KVM userspace needs to know the cache block size in order to properly advertise it to the guest. Provide a virtual config register for userspace to get it with the GET_ONE_REG API, but setting it cannot be supported, so disallow SET_ONE_REG. Signed-off-by: Andrew Jones Reviewed-by: Conor Dooley Reviewed-by: Anup Patel --- arch/riscv/include/uapi/asm/kvm.h | 1 + arch/riscv/kvm/vcpu.c | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/arch/riscv/include/uapi/asm/kvm.h b/arch/riscv/include/uapi/asm/kvm.h index 8985ff234c01..4bbf55cb2b70 100644 --- a/arch/riscv/include/uapi/asm/kvm.h +++ b/arch/riscv/include/uapi/asm/kvm.h @@ -49,6 +49,7 @@ struct kvm_sregs { struct kvm_riscv_config { unsigned long isa; unsigned long zicbom_block_size; + unsigned long zicboz_block_size; }; /* CORE registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */ diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c index 71ebbc4821f0..18a739070b51 100644 --- a/arch/riscv/kvm/vcpu.c +++ b/arch/riscv/kvm/vcpu.c @@ -270,6 +270,11 @@ static int kvm_riscv_vcpu_get_reg_config(struct kvm_vcpu *vcpu, return -EINVAL; reg_val = riscv_cbom_block_size; break; + case KVM_REG_RISCV_CONFIG_REG(zicboz_block_size): + if (!riscv_isa_extension_available(vcpu->arch.isa, ZICBOZ)) + return -EINVAL; + reg_val = riscv_cboz_block_size; + break; default: return -EINVAL; } @@ -329,6 +334,8 @@ static int kvm_riscv_vcpu_set_reg_config(struct kvm_vcpu *vcpu, break; case KVM_REG_RISCV_CONFIG_REG(zicbom_block_size): return -EOPNOTSUPP; + case KVM_REG_RISCV_CONFIG_REG(zicboz_block_size): + return -EOPNOTSUPP; default: return -EINVAL; } From patchwork Thu Oct 27 13:02:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 1695404 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=kvm-riscv-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=DJVVvcQE; 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=XEjt/ZvA; 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 4Mym99136Pz23kp for ; Fri, 28 Oct 2022 00:04:29 +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=E5cnQ1X+bSxCyO7DtDnatHCLytwV5atQLxQzkI6h2Ko=; b=DJVVvcQEzOCfdP hQOjZsOQ0je0QR/tugZf4TW4G+oumrORUTZeleF51ydRa5P2wScLOoohWlPDYCKpmAXSeHa9q/dIP Ntz43c7orGEGhZHpAcqn57teJTLb7rTfjeIO0xzYAllHd2OhIgNv4Ut156CY/lBU1Ids0gi10fDaV krihEvae5kPbdAy9/8wzI04bVtjNgudg9FjCAFqzvslyxr3rjaWr6ooDFvUs908ls9NGNi19qYVrK a2gdWBLr35o8pZ/j0oTDjCPZ3RxTZa4Mz68YMm351dUXUJvMFWWnP5MTCl8BWCSvTKgKlmboKkflU ibo+G4Tmp1DAEflR+diw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oo2YY-00DJeK-Jl; Thu, 27 Oct 2022 13:04:22 +0000 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oo2XF-00DJ4T-Un for kvm-riscv@lists.infradead.org; Thu, 27 Oct 2022 13:03:03 +0000 Received: by mail-wr1-x430.google.com with SMTP id bk15so2017297wrb.13 for ; Thu, 27 Oct 2022 06:03:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; 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=obHF+5YDsySvdPBRcVj0srfYU63GXDl3O8xwcIRgRzw=; b=XEjt/ZvArDPmY4O3ubEf3FujxIx+hIRcqEDq9rTYRI9KTMRAuRngXTxCm3EVoXc/yN g0Fv4acWyGLzdWsbIVaf2fJu5cEFo0Kar0WYS5SbqUP8k4ygFRculFyTlwiQ45mwSHy/ ZbzKEw3RPP5c0g3DVgSOjnOwELOkg11dT+Gru8oWW5P2MBtieV1vZ6ppDGbilq8LzLy2 kO8iY1j0Dvovbex6DXyP7v2fhh/r22aSobVWXo7ETdQj0dHQ3NVLkdGG3iXU4plFpJoT MosssL5GjYPK6DAVPCGNwo4NNvrS2Bcz0oI13Yp0jUXSkDFyBdiuDda5kJaeZQWiaYqE uK4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=obHF+5YDsySvdPBRcVj0srfYU63GXDl3O8xwcIRgRzw=; b=iEYMAUIgkpUC8KhcN2HACRR2oR6NUSm/H3UtYwIuD72rIU/m/TRJU1eiUHN5d9CdWV 7LGcd7DCVBpclcKz6me2bJP7LPf+PkpnvcOPSb/8dWDvfRDsIn+JGsHsWDI4cNk14XW6 EKfPIAN9+5oh8DcjAiA2ay9a9XCVACN4efh7PWdu4OgbukLe/UN9hP5ntWwWO7ZWwYiS zVdhvSjBlIiVQksQQaHjgNakNlBdE3wk0oZkSVW7GgcSKkxV46XTBO1VjGRmMSIIi/tB FI4yoya8lff1IeNulvfoH9YSGcjKeRGViqVqXl8RfAZa2tn2ZUUmpyNo4MsNFjtSJ0cg Kcag== X-Gm-Message-State: ACrzQf0Aj+8yTYjKw5+JeRWv9itAprDHL6alvsebdyPhNG07tRnbtVVl CfUjnHWF0UnLidh2J8pizFWIyQ== X-Google-Smtp-Source: AMsMyM7eLuv8Ea9bPqNxCBUDLH2ursMZDlUftRfPXYQUA+OGiuSj1yFkGbXboPh33UxYspEn7WiHOA== X-Received: by 2002:adf:e446:0:b0:236:773b:c6f0 with SMTP id t6-20020adfe446000000b00236773bc6f0mr12575244wrm.55.1666875780398; Thu, 27 Oct 2022 06:03:00 -0700 (PDT) Received: from localhost (cst2-173-61.cust.vodafone.cz. [31.30.173.61]) by smtp.gmail.com with ESMTPSA id j21-20020a05600c42d500b003b492753826sm1399176wme.43.2022.10.27.06.02.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Oct 2022 06:03:00 -0700 (PDT) From: Andrew Jones To: linux-riscv@lists.infradead.org, kvm-riscv@lists.infradead.org Cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , Anup Patel , Heiko Stuebner , Conor Dooley , Atish Patra , Jisheng Zhang Subject: [PATCH 6/9] RISC-V: KVM: Expose Zicboz to the guest Date: Thu, 27 Oct 2022 15:02:44 +0200 Message-Id: <20221027130247.31634-7-ajones@ventanamicro.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221027130247.31634-1-ajones@ventanamicro.com> References: <20221027130247.31634-1-ajones@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221027_060302_064106_AEC6350A X-CRM114-Status: UNSURE ( 9.60 ) 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: Guests may use the cbo.zero instruction when the CPU has the Zicboz extension and the hypervisor sets henvcfg.CBZE. Add Zicboz support for KVM guests which may be enabled and disabled from KVM userspace using the ISA extension ONE_REG API. 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:430 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: kvm-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "kvm-riscv" Errors-To: kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Guests may use the cbo.zero instruction when the CPU has the Zicboz extension and the hypervisor sets henvcfg.CBZE. Add Zicboz support for KVM guests which may be enabled and disabled from KVM userspace using the ISA extension ONE_REG API. Signed-off-by: Andrew Jones Reviewed-by: Conor Dooley Reviewed-by: Anup Patel --- arch/riscv/include/uapi/asm/kvm.h | 1 + arch/riscv/kvm/vcpu.c | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/arch/riscv/include/uapi/asm/kvm.h b/arch/riscv/include/uapi/asm/kvm.h index 4bbf55cb2b70..8dc21ceee7aa 100644 --- a/arch/riscv/include/uapi/asm/kvm.h +++ b/arch/riscv/include/uapi/asm/kvm.h @@ -103,6 +103,7 @@ enum KVM_RISCV_ISA_EXT_ID { KVM_RISCV_ISA_EXT_SVINVAL, KVM_RISCV_ISA_EXT_ZIHINTPAUSE, KVM_RISCV_ISA_EXT_ZICBOM, + KVM_RISCV_ISA_EXT_ZICBOZ, KVM_RISCV_ISA_EXT_MAX, }; diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c index 18a739070b51..7758faec590a 100644 --- a/arch/riscv/kvm/vcpu.c +++ b/arch/riscv/kvm/vcpu.c @@ -62,6 +62,7 @@ static const unsigned long kvm_isa_ext_arr[] = { KVM_ISA_EXT_ARR(SVPBMT), KVM_ISA_EXT_ARR(ZIHINTPAUSE), KVM_ISA_EXT_ARR(ZICBOM), + KVM_ISA_EXT_ARR(ZICBOZ), }; static unsigned long kvm_riscv_vcpu_base2isa_ext(unsigned long base_ext) @@ -821,6 +822,9 @@ static void kvm_riscv_vcpu_update_config(const unsigned long *isa) if (riscv_isa_extension_available(isa, ZICBOM)) henvcfg |= (ENVCFG_CBIE | ENVCFG_CBCFE); + if (riscv_isa_extension_available(isa, ZICBOZ)) + henvcfg |= ENVCFG_CBZE; + csr_write(CSR_HENVCFG, henvcfg); #ifdef CONFIG_32BIT csr_write(CSR_HENVCFGH, henvcfg >> 32); From patchwork Thu Oct 27 13:02:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 1695406 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=kvm-riscv-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=Vn5kws0o; 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=P4Rmb/aK; 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 4MymBJ4tC3z23kY for ; Fri, 28 Oct 2022 00:05:28 +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=Ia2HIohe7DqL+7wwuF24ymdVrhmMvcZfM4mQoXLL54g=; b=Vn5kws0o6/m5i8 dMKIvJ2kkFx/kIoKouMroJcJjKIzLUM3MyjfLQWa3qfPhbupMAiaJVTsl36WIJCZS9Lw8K1LlQuBT fsMffg5BBKNckZghdXAkhN6koqIW6iagPZfIUqlxR6A3mcP65F0zPhZKhi3dO4Enily8dSo4c/Ejr CGKxo86QGwRzQpjVVcmZD0jG7h5ANq30VMYsd7NZmYU/YoIAh/QKqEBJQT+2UIJ9CPc1jeF7He5B6 mVnsYcboOILQcbhpRf+QYPO1ShB4WsjCQAxvc61lI71pqXFM9F+5YUEnKEWQIbWPjqcI1ZApzPZCU gHWPYsa+nkozzdQ67RSw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oo2ZX-00DKF9-Rm; Thu, 27 Oct 2022 13:05:23 +0000 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oo2XI-00DJ5q-IA for kvm-riscv@lists.infradead.org; Thu, 27 Oct 2022 13:03:07 +0000 Received: by mail-wm1-x329.google.com with SMTP id l32so951785wms.2 for ; Thu, 27 Oct 2022 06:03:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; 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=iHol30iu44SieCnbzpUR445EegurXqWLLkR68727Pz8=; b=P4Rmb/aKJYj4I/dJnJ+97nCWi9d28PM7o71dsxYkuzKu45hoqGPh2TDljqlRkhHUOe eoqfUBSiHKDa2fh6aKUO5Jo9KVQE9wn2uxaeYgjJTdif9mwFofsWzA10kLeJuYV15sda ylkejUDWZGgSY83tARiRxdsn77nZZyip6rBdGNjINjrYH+l7v03NcSIztLut4O+lQ+B0 8GxNMRxzmxEUUgNRQgvB1YGgcbesRtHgD9UMzacQ2PjC9Dc+vwen0jrcKEOf86m/gESZ nPtgBXmV38IgA0i92RM69CNVwapwjPQkS2Opn0UjaFzyqtZzS6HJvj7hULsZ6HdMRNO+ cQwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=iHol30iu44SieCnbzpUR445EegurXqWLLkR68727Pz8=; b=YA2MN8i6+cHlo3g4UR0yGN9VCHQGmAc81ipmfFkJSiCRuj+MPq6BPfpCF+oq4T/JS6 gRHdJdTB1Kx8i44aTjjHdk0CVwGxT3w0VJ93pR1a+cXyYGCjc2DLnHJ7A+NGgosKz7zS MUHqcw7Ebkq9rjOwslnA2OA7NcPAnakR+//1sPCFwCSvXKkxJenjgCgSyx6V55WTOjs4 Fjfo3+V4V5aK/ctrcZ4j1DrxtZ1O4Yt2bMhpB0RxP8kq7cZ/vsh7PErwfGV0FcEM9enQ 9O/v9tzqO0KfKD6VBX+IJQvhQiNYNsCy9xT8Y+/TSIaV00Jppu7q4kp2Y3f4zAR5a8zT lK4A== X-Gm-Message-State: ACrzQf2l09HrSqH15o/2AJnyBNB9zvhGHG5rywIB0IXz4mASwmm9bIK4 uwVDueRvrrPb9nsKymJGYI9sMQ== X-Google-Smtp-Source: AMsMyM5oTmv9IrhDQSVkJF02JpfmYS7iTDg1CKhw9ywqtCc3quIDdLwe0QXTE/CT4hcoU7ucDP6QJg== X-Received: by 2002:a05:600c:468a:b0:3c6:f84a:1fae with SMTP id p10-20020a05600c468a00b003c6f84a1faemr5697142wmo.148.1666875782181; Thu, 27 Oct 2022 06:03:02 -0700 (PDT) Received: from localhost (cst2-173-61.cust.vodafone.cz. [31.30.173.61]) by smtp.gmail.com with ESMTPSA id k18-20020adff5d2000000b002366f300e57sm1127522wrp.23.2022.10.27.06.03.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Oct 2022 06:03:01 -0700 (PDT) From: Andrew Jones To: linux-riscv@lists.infradead.org, kvm-riscv@lists.infradead.org Cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , Anup Patel , Heiko Stuebner , Conor Dooley , Atish Patra , Jisheng Zhang Subject: [PATCH 7/9] RISC-V: lib: Improve memset assembler formatting Date: Thu, 27 Oct 2022 15:02:45 +0200 Message-Id: <20221027130247.31634-8-ajones@ventanamicro.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221027130247.31634-1-ajones@ventanamicro.com> References: <20221027130247.31634-1-ajones@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221027_060304_694745_F327D1B2 X-CRM114-Status: GOOD ( 12.20 ) 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: Aligning the first operand of each instructions with a tab is a typical style which improves readability. Apply it to memset.S. While there, we also make a small grammar change to a comment. No functional change intended. 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:329 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: kvm-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "kvm-riscv" Errors-To: kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Aligning the first operand of each instructions with a tab is a typical style which improves readability. Apply it to memset.S. While there, we also make a small grammar change to a comment. No functional change intended. Signed-off-by: Andrew Jones Reviewed-by: Conor Dooley --- arch/riscv/lib/memset.S | 143 ++++++++++++++++++++-------------------- 1 file changed, 72 insertions(+), 71 deletions(-) diff --git a/arch/riscv/lib/memset.S b/arch/riscv/lib/memset.S index 34c5360c6705..e613c5c27998 100644 --- a/arch/riscv/lib/memset.S +++ b/arch/riscv/lib/memset.S @@ -3,111 +3,112 @@ * Copyright (C) 2013 Regents of the University of California */ - #include #include /* void *memset(void *, int, size_t) */ ENTRY(__memset) WEAK(memset) - move t0, a0 /* Preserve return value */ + move t0, a0 /* Preserve return value */ /* Defer to byte-oriented fill for small sizes */ - sltiu a3, a2, 16 - bnez a3, 4f + sltiu a3, a2, 16 + bnez a3, 4f /* * Round to nearest XLEN-aligned address - * greater than or equal to start address + * greater than or equal to the start address. */ - addi a3, t0, SZREG-1 - andi a3, a3, ~(SZREG-1) - beq a3, t0, 2f /* Skip if already aligned */ + addi a3, t0, SZREG-1 + andi a3, a3, ~(SZREG-1) + beq a3, t0, 2f /* Skip if already aligned */ + /* Handle initial misalignment */ - sub a4, a3, t0 + sub a4, a3, t0 1: - sb a1, 0(t0) - addi t0, t0, 1 - bltu t0, a3, 1b - sub a2, a2, a4 /* Update count */ + sb a1, 0(t0) + addi t0, t0, 1 + bltu t0, a3, 1b + sub a2, a2, a4 /* Update count */ 2: /* Duff's device with 32 XLEN stores per iteration */ /* Broadcast value into all bytes */ - andi a1, a1, 0xff - slli a3, a1, 8 - or a1, a3, a1 - slli a3, a1, 16 - or a1, a3, a1 + andi a1, a1, 0xff + slli a3, a1, 8 + or a1, a3, a1 + slli a3, a1, 16 + or a1, a3, a1 #ifdef CONFIG_64BIT - slli a3, a1, 32 - or a1, a3, a1 + slli a3, a1, 32 + or a1, a3, a1 #endif /* Calculate end address */ - andi a4, a2, ~(SZREG-1) - add a3, t0, a4 + andi a4, a2, ~(SZREG-1) + add a3, t0, a4 - andi a4, a4, 31*SZREG /* Calculate remainder */ - beqz a4, 3f /* Shortcut if no remainder */ - neg a4, a4 - addi a4, a4, 32*SZREG /* Calculate initial offset */ + andi a4, a4, 31*SZREG /* Calculate remainder */ + beqz a4, 3f /* Shortcut if no remainder */ + neg a4, a4 + addi a4, a4, 32*SZREG /* Calculate initial offset */ /* Adjust start address with offset */ - sub t0, t0, a4 + sub t0, t0, a4 /* Jump into loop body */ /* Assumes 32-bit instruction lengths */ - la a5, 3f + la a5, 3f #ifdef CONFIG_64BIT - srli a4, a4, 1 + srli a4, a4, 1 #endif - add a5, a5, a4 - jr a5 + add a5, a5, a4 + jr a5 3: - REG_S a1, 0(t0) - REG_S a1, SZREG(t0) - REG_S a1, 2*SZREG(t0) - REG_S a1, 3*SZREG(t0) - REG_S a1, 4*SZREG(t0) - REG_S a1, 5*SZREG(t0) - REG_S a1, 6*SZREG(t0) - REG_S a1, 7*SZREG(t0) - REG_S a1, 8*SZREG(t0) - REG_S a1, 9*SZREG(t0) - REG_S a1, 10*SZREG(t0) - REG_S a1, 11*SZREG(t0) - REG_S a1, 12*SZREG(t0) - REG_S a1, 13*SZREG(t0) - REG_S a1, 14*SZREG(t0) - REG_S a1, 15*SZREG(t0) - REG_S a1, 16*SZREG(t0) - REG_S a1, 17*SZREG(t0) - REG_S a1, 18*SZREG(t0) - REG_S a1, 19*SZREG(t0) - REG_S a1, 20*SZREG(t0) - REG_S a1, 21*SZREG(t0) - REG_S a1, 22*SZREG(t0) - REG_S a1, 23*SZREG(t0) - REG_S a1, 24*SZREG(t0) - REG_S a1, 25*SZREG(t0) - REG_S a1, 26*SZREG(t0) - REG_S a1, 27*SZREG(t0) - REG_S a1, 28*SZREG(t0) - REG_S a1, 29*SZREG(t0) - REG_S a1, 30*SZREG(t0) - REG_S a1, 31*SZREG(t0) - addi t0, t0, 32*SZREG - bltu t0, a3, 3b - andi a2, a2, SZREG-1 /* Update count */ + REG_S a1, 0(t0) + REG_S a1, SZREG(t0) + REG_S a1, 2*SZREG(t0) + REG_S a1, 3*SZREG(t0) + REG_S a1, 4*SZREG(t0) + REG_S a1, 5*SZREG(t0) + REG_S a1, 6*SZREG(t0) + REG_S a1, 7*SZREG(t0) + REG_S a1, 8*SZREG(t0) + REG_S a1, 9*SZREG(t0) + REG_S a1, 10*SZREG(t0) + REG_S a1, 11*SZREG(t0) + REG_S a1, 12*SZREG(t0) + REG_S a1, 13*SZREG(t0) + REG_S a1, 14*SZREG(t0) + REG_S a1, 15*SZREG(t0) + REG_S a1, 16*SZREG(t0) + REG_S a1, 17*SZREG(t0) + REG_S a1, 18*SZREG(t0) + REG_S a1, 19*SZREG(t0) + REG_S a1, 20*SZREG(t0) + REG_S a1, 21*SZREG(t0) + REG_S a1, 22*SZREG(t0) + REG_S a1, 23*SZREG(t0) + REG_S a1, 24*SZREG(t0) + REG_S a1, 25*SZREG(t0) + REG_S a1, 26*SZREG(t0) + REG_S a1, 27*SZREG(t0) + REG_S a1, 28*SZREG(t0) + REG_S a1, 29*SZREG(t0) + REG_S a1, 30*SZREG(t0) + REG_S a1, 31*SZREG(t0) + + addi t0, t0, 32*SZREG + bltu t0, a3, 3b + andi a2, a2, SZREG-1 /* Update count */ 4: /* Handle trailing misalignment */ - beqz a2, 6f - add a3, t0, a2 + beqz a2, 6f + add a3, t0, a2 5: - sb a1, 0(t0) - addi t0, t0, 1 - bltu t0, a3, 5b + sb a1, 0(t0) + addi t0, t0, 1 + bltu t0, a3, 5b 6: ret END(__memset) From patchwork Thu Oct 27 13:02:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 1695408 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=kvm-riscv-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=qFbzE0Y8; 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=oTmS6SGE; 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 4MymBg6Nkhz23kp for ; Fri, 28 Oct 2022 00:05: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=9qA1W+eKHg9Cs/Qei11nTTKebSMrotf6jnyXF783D/Y=; b=qFbzE0Y8m5jciB LkA2cg0obafZzbTy0Bgr27mpgFkc4TF/Et/BEHwFSuM8uA81Y1qYWmqeWjjuqYC1gkdWiMmvsL+qf OGEIqg+gbZyP+Tf+QbY+qXCXlYAyv9OsR41BTL1ShPWXHg0pKdmW06cPkwFsQ4da6FEXBOdds8ih1 5fU3ljE2i74TSFyCu3BAh7KloGRCxC+yW5enl7Ep30TXnBSVEdWnWktn3GBrFfmmDIuilGUzX7SN4 1sDDaosluo3PD/pbHmPZCJoc+54tSe0AqvwdyjiJMW/5dddL5xkUdB24PGcm5yWA/tIDbNPJKDOMd qQ87j61w7Ka95XGS6uBw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oo2Zq-00DKPO-BP; Thu, 27 Oct 2022 13:05:42 +0000 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oo2XJ-00DJ35-Kk for kvm-riscv@lists.infradead.org; Thu, 27 Oct 2022 13:03:07 +0000 Received: by mail-wr1-x430.google.com with SMTP id j15so2066419wrq.3 for ; Thu, 27 Oct 2022 06:03:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; 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=QEd63VkcdB1NsGmp6u1XxlrgxZv1boF1F6ofZVnsAx4=; b=oTmS6SGE95EGgR+AsNmA0GQUZ/mSautMKrVhTV+HabUzbDAYBEMdEk/AJlAqYrjiQ8 6jDQnAcw825tkqEUj86AXfmUd0Dsyy/2Rk3lwW7mU2MScIlyCZWIgKIVGcDdsPzHZm7t OSm/iU2XzZ1ybglxDX8suf7Ca+Bflp3AXl/zsrAvARZe9fiLG18SKamqYETOfqjT9zFZ 6IgLm1po1z5ZHP0m8YyAarCd9sS6Iqkw9w9CbkWMXghPeQfBU5m5asAtRxTz1uZp71I7 Urn3uqBJUL/8XBHtZutakAPLqabPakTML25wZ8uf4mvh/+ez//W0s0zJ5VllP2Yls723 aDOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=QEd63VkcdB1NsGmp6u1XxlrgxZv1boF1F6ofZVnsAx4=; b=im4ToKSpPalPHZEeWdV/uMtBKU11VMxCWROb6f9ywue9BklAsr2lRFa/hvq7UHoF+I t9Tqd8F02VkV1Ch4Ddc+xdsOmo8ItzrvnniY0gLD7oKq6FBEz3qR0UME9xuJLxt05DIh uu17kCOFcXR2naI0jGCxkArCYuCBmq+SaDIXs76I2C4CDAyH3QjoU4YofZiqvOmv2Nxh Z6thQFcnfCosG4jYIH1RLVN7G1WEIN2YXEVZJi6cEKInO6EE8lr8gZHcH3Qockl/OKzz kzv/KRE/S3Qw0gq9gZzn3SR60YqkT1AhFnt6YIR0jNEVEKDkRMOyB7J2tfTJ78W58lPq HydA== X-Gm-Message-State: ACrzQf1kRhEdXqyNKsVlWOevXCAKgyNEsa9GHGENndOxwdfoTcl5PyPF UwD9gBSOytuzF047c3FA2jbQxQ== X-Google-Smtp-Source: AMsMyM6HI/rqwTzlHsKApbQwPIKac0TnBA+k85KqTvvBnsdLq4iX0AyKZmCmNJi5p4UgKkIy8qI9vQ== X-Received: by 2002:a5d:4846:0:b0:236:64b1:50fe with SMTP id n6-20020a5d4846000000b0023664b150femr17354643wrs.672.1666875783732; Thu, 27 Oct 2022 06:03:03 -0700 (PDT) Received: from localhost (cst2-173-61.cust.vodafone.cz. [31.30.173.61]) by smtp.gmail.com with ESMTPSA id n7-20020a05600c500700b003b47ff307e1sm1680939wmr.31.2022.10.27.06.03.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Oct 2022 06:03:03 -0700 (PDT) From: Andrew Jones To: linux-riscv@lists.infradead.org, kvm-riscv@lists.infradead.org Cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , Anup Patel , Heiko Stuebner , Conor Dooley , Atish Patra , Jisheng Zhang Subject: [PATCH 8/9] RISC-V: lib: Use named labels in memset Date: Thu, 27 Oct 2022 15:02:46 +0200 Message-Id: <20221027130247.31634-9-ajones@ventanamicro.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221027130247.31634-1-ajones@ventanamicro.com> References: <20221027130247.31634-1-ajones@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221027_060305_744624_5A24B3C3 X-CRM114-Status: UNSURE ( 9.63 ) 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: In a coming patch we'll be adding more branch targets. Let's change the numeric labels to named labels to make it easier to read and integrate with. No functional change intended. Signed-off-by: Andrew Jones --- arch/riscv/lib/memset.S | 29 +++++++++++++++ 1 file changed, 15 insertions(+), 14 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 [2a00:1450:4864:20:0:0:0:430 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: kvm-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "kvm-riscv" Errors-To: kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org In a coming patch we'll be adding more branch targets. Let's change the numeric labels to named labels to make it easier to read and integrate with. No functional change intended. Signed-off-by: Andrew Jones Reviewed-by: Conor Dooley --- arch/riscv/lib/memset.S | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/arch/riscv/lib/memset.S b/arch/riscv/lib/memset.S index e613c5c27998..74e4c7feec00 100644 --- a/arch/riscv/lib/memset.S +++ b/arch/riscv/lib/memset.S @@ -13,7 +13,7 @@ WEAK(memset) /* Defer to byte-oriented fill for small sizes */ sltiu a3, a2, 16 - bnez a3, 4f + bnez a3, .Lfinish /* * Round to nearest XLEN-aligned address @@ -21,17 +21,18 @@ WEAK(memset) */ addi a3, t0, SZREG-1 andi a3, a3, ~(SZREG-1) - beq a3, t0, 2f /* Skip if already aligned */ + beq a3, t0, .Ldo_duff /* Skip if already aligned */ /* Handle initial misalignment */ sub a4, a3, t0 -1: +.Lmisaligned1: sb a1, 0(t0) addi t0, t0, 1 - bltu t0, a3, 1b + bltu t0, a3, .Lmisaligned1 sub a2, a2, a4 /* Update count */ -2: /* Duff's device with 32 XLEN stores per iteration */ +.Ldo_duff: + /* Duff's device with 32 XLEN stores per iteration */ /* Broadcast value into all bytes */ andi a1, a1, 0xff slli a3, a1, 8 @@ -48,7 +49,7 @@ WEAK(memset) add a3, t0, a4 andi a4, a4, 31*SZREG /* Calculate remainder */ - beqz a4, 3f /* Shortcut if no remainder */ + beqz a4, .Lduff_loop /* Shortcut if no remainder */ neg a4, a4 addi a4, a4, 32*SZREG /* Calculate initial offset */ @@ -57,13 +58,13 @@ WEAK(memset) /* Jump into loop body */ /* Assumes 32-bit instruction lengths */ - la a5, 3f + la a5, .Lduff_loop #ifdef CONFIG_64BIT srli a4, a4, 1 #endif add a5, a5, a4 jr a5 -3: +.Lduff_loop: REG_S a1, 0(t0) REG_S a1, SZREG(t0) REG_S a1, 2*SZREG(t0) @@ -98,17 +99,17 @@ WEAK(memset) REG_S a1, 31*SZREG(t0) addi t0, t0, 32*SZREG - bltu t0, a3, 3b + bltu t0, a3, .Lduff_loop andi a2, a2, SZREG-1 /* Update count */ -4: +.Lfinish: /* Handle trailing misalignment */ - beqz a2, 6f + beqz a2, .Ldone add a3, t0, a2 -5: +.Lmisaligned2: sb a1, 0(t0) addi t0, t0, 1 - bltu t0, a3, 5b -6: + bltu t0, a3, .Lmisaligned2 +.Ldone: ret END(__memset) From patchwork Thu Oct 27 13:02:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 1695409 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=kvm-riscv-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=W/nxq3aS; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=f3dpru2z; 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=nicqwmHc; 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 4MymBy4zt1z23kY for ; Fri, 28 Oct 2022 00:06:00 +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=v1I2ZNgIh0zJURINPBygv+LF35Kkf1y+sbc6D8plNos=; b=W/nxq3aS8XvsQt SNNcyMpd9ejoQyYAaSs3VLgPnLKTTP8Mk++SPBsG/y9nycs9QgtjvcpmrXEXhoRepzH/mvTn3M7o0 LNbDR2kZPLNmA2FGD2n8D74hCnLothVdMc6sK2gQzW7vDExlNcoyf0aFhCSwD2M/RdEUq/muSD0um UYC+Na3Zhows2tfIWqPH3lV8jUEbO2/0CleW432axkcet6R0VkQhsq8r0Y6GIQZVE/+4let2DkJCT V2PcT2bVZKi/HCV+UVA0Ep+XCEk7a0KUPF2zn/V5WP7rtGfAVXGMo7/xVq0qkqVffjNw9cBLKNXaf 4Cok5V4M+l0w4QOE1wBQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oo2a2-00DKXK-U7; Thu, 27 Oct 2022 13:05:54 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oo2XY-00DJDP-3t for kvm-riscv@bombadil.infradead.org; Thu, 27 Oct 2022 13:03:20 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:Content-type :MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:Content-ID:Content-Description; bh=GAX0DbNejfkrqb/S2+c7OCAri1uVnAqmCEyoErzwy+w=; b=f3dpru2zN+uJStZ+Kv3PpdahfB mSehHh4DTYJNwEhBmTZfqZ31sDiHz6Jfs2Pz2XPQFKzdIZ4DUAm39ZbXifORUp5jI8X2cukRUsqLm ckOF0xDYn4f7Hj1JPKINZfvuuwnsipUcZlLaHB0CoU2PmOWaQ7YmDXmvog0iq5rGuW6p0T2xjlHOO DZgr7JJvKBeql0sDbo/cKvucSSyzU56eprL1LfA95/L/QsN1H9489vggMbuC0axls5Aae/qTyu2Lv dohbfFyZMbG9AP7OXioHUoXrJ832d5NleR6sv2tijQCR9OrNoj82csEy2sPvqn7lgNrZzvmELfI+i xsDKA+yw==; Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by desiato.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oo2XR-006rb7-Ba for kvm-riscv@lists.infradead.org; Thu, 27 Oct 2022 13:03:17 +0000 Received: by mail-wm1-x32d.google.com with SMTP id n14so943986wmq.3 for ; Thu, 27 Oct 2022 06:03:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; 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=GAX0DbNejfkrqb/S2+c7OCAri1uVnAqmCEyoErzwy+w=; b=nicqwmHcGSd/cPEoKhB2mITBUJDVsZIpcBjUeRu/UNeejWFxAbVCbiXvQNCBT1U+RT GKpBsNF4KSut9TthK82igyPHqyeWQtpvOVaHpHNqpax8QG89meINxY+BIqWWSpZzfylo 2bmdt/+48kjj7k2d3Kk59pZ6Pl/Nz6CDqQsirFrFij058JSsHZoNZLRlunZEimKhejsj i1CVWsLdrvywT3e8/rPByTZ6F46agQ4ANm0wafDnbfyFKQSkqtbwHeoL6AlCV5tVRafs Y+t2okAsaU19qg1wwAEsy4GV3NYke+Y80WB8ACVSYvOMx5WMJsz9ggUN/GUDCcfJT9Vm uBQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=GAX0DbNejfkrqb/S2+c7OCAri1uVnAqmCEyoErzwy+w=; b=ZiKdMe+v6zt1fE+TLhVBfNzYrq4bgyULgh7zrkxFTGEycLjdtkbPthIhJf31fyNUk1 CuQ5fz5cKUEg0KxeBeCpbPuvBHe5duVFe8/8Cube+W/rCQX6WwKuMW8HARCmj1fyoMTU uWNpvOtTAlKV+DRSg+ObRymcaQTds+RIGhWziRuMGK+Vo7shOK3MKCGGzmoRmgsx/rjK CoKFjwIwWXpALOnkeddw6B6mPbcZdu1TfbhkPNGkqK2GGXwPmxX2/cCFLU6S0nB2CxHk Ob4WAIGO9P/zMmnoLOTFAWAXk56t7S/jQ60YkKrFQE5GUKND4IIR2KOdS8k6OsFwESge cjSw== X-Gm-Message-State: ACrzQf1+sRf1/alhhdICU0OsK1kiJibZdoClz7pxxZKIMDvAzoleo6Uu j8+sQAfHE9OXi1in37IKXkPV0A== X-Google-Smtp-Source: AMsMyM7ARWH3OcOCRtZrDUXW7Z8rm9Eg/J7+KLXEhlq6z0XD8gxE/KqKxtjNZJgJbPW14RpQGr+eQA== X-Received: by 2002:a05:600c:3147:b0:3c6:f860:9610 with SMTP id h7-20020a05600c314700b003c6f8609610mr5950330wmo.170.1666875786146; Thu, 27 Oct 2022 06:03:06 -0700 (PDT) Received: from localhost (cst2-173-61.cust.vodafone.cz. [31.30.173.61]) by smtp.gmail.com with ESMTPSA id e4-20020a5d5004000000b0023655e51c33sm1119677wrt.4.2022.10.27.06.03.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Oct 2022 06:03:05 -0700 (PDT) From: Andrew Jones To: linux-riscv@lists.infradead.org, kvm-riscv@lists.infradead.org Cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , Anup Patel , Heiko Stuebner , Conor Dooley , Atish Patra , Jisheng Zhang Subject: [PATCH 9/9] RISC-V: Use Zicboz in memset when available Date: Thu, 27 Oct 2022 15:02:47 +0200 Message-Id: <20221027130247.31634-10-ajones@ventanamicro.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221027130247.31634-1-ajones@ventanamicro.com> References: <20221027130247.31634-1-ajones@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221027_140314_391861_B88656C7 X-CRM114-Status: GOOD ( 15.64 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "desiato.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: RISC-V has an optimized memset() which does byte by byte writes up to the first sizeof(long) aligned address, then uses Duff's device until the last sizeof(long) aligned address, and finally byte by b [...] 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:32d listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -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.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.0 T_SCC_BODY_TEXT_LINE No description available. X-BeenThere: kvm-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "kvm-riscv" Errors-To: kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org RISC-V has an optimized memset() which does byte by byte writes up to the first sizeof(long) aligned address, then uses Duff's device until the last sizeof(long) aligned address, and finally byte by byte to the end. When memset is used to zero memory and the Zicboz extension is available, then we can extend that by doing the optimized memset up to the first Zicboz block size aligned address, then use the Zicboz zero instruction for each block to the last block size aligned address, and finally the optimized memset to the end. Signed-off-by: Andrew Jones --- arch/riscv/lib/memset.S | 81 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/arch/riscv/lib/memset.S b/arch/riscv/lib/memset.S index 74e4c7feec00..786b85b5e9cc 100644 --- a/arch/riscv/lib/memset.S +++ b/arch/riscv/lib/memset.S @@ -5,6 +5,12 @@ #include #include +#include +#include +#include + +#define ALT_ZICBOZ(old, new) ALTERNATIVE(old, new, 0, RISCV_ISA_EXT_ZICBOZ, \ + CONFIG_RISCV_ISA_ZICBOZ) /* void *memset(void *, int, size_t) */ ENTRY(__memset) @@ -15,6 +21,58 @@ WEAK(memset) sltiu a3, a2, 16 bnez a3, .Lfinish +#ifdef CONFIG_RISCV_ISA_ZICBOZ + ALT_ZICBOZ("j .Ldo_memset", "nop") + /* + * t1 will be the Zicboz block size. + * Zero means we're not using Zicboz, and we don't when a1 != 0 + */ + li t1, 0 + bnez a1, .Ldo_memset + la a3, riscv_cboz_block_size + lw t1, 0(a3) + + /* + * Round to nearest Zicboz block-aligned address + * greater than or equal to the start address. + */ + addi a3, t1, -1 + not t2, a3 /* t2 is Zicboz block size mask */ + add a3, t0, a3 + and t3, a3, t2 /* t3 is Zicboz block aligned start */ + + /* Did we go too far or not have at least one block? */ + add a3, a0, a2 + and a3, a3, t2 + bgtu a3, t3, .Ldo_zero + li t1, 0 + j .Ldo_memset + +.Ldo_zero: + /* Use Duff for initial bytes if there are any */ + bne t3, t0, .Ldo_memset + +.Ldo_zero2: + /* Calculate end address */ + and a3, a2, t2 + add a3, t0, a3 + sub a4, a3, t0 + +.Lzero_loop: + CBO_ZERO(t0) + add t0, t0, t1 + bltu t0, a3, .Lzero_loop + li t1, 0 /* We're done with Zicboz */ + + sub a2, a2, a4 /* Update count */ + sltiu a3, a2, 16 + bnez a3, .Lfinish + + /* t0 is Zicboz block size aligned, so it must be SZREG aligned */ + j .Ldo_duff3 +#endif + +.Ldo_memset: /* * Round to nearest XLEN-aligned address * greater than or equal to the start address. @@ -33,6 +91,18 @@ WEAK(memset) .Ldo_duff: /* Duff's device with 32 XLEN stores per iteration */ + +#ifdef CONFIG_RISCV_ISA_ZICBOZ + ALT_ZICBOZ("j .Ldo_duff2", "nop") + beqz t1, .Ldo_duff2 + /* a3, "end", is start of block aligned start. a1 is 0 */ + move a3, t3 + sub a4, a3, t0 /* a4 is SZREG aligned count */ + move t4, a4 /* Save count for later, see below. */ + j .Ldo_duff4 +#endif + +.Ldo_duff2: /* Broadcast value into all bytes */ andi a1, a1, 0xff slli a3, a1, 8 @@ -44,10 +114,12 @@ WEAK(memset) or a1, a3, a1 #endif +.Ldo_duff3: /* Calculate end address */ andi a4, a2, ~(SZREG-1) add a3, t0, a4 +.Ldo_duff4: andi a4, a4, 31*SZREG /* Calculate remainder */ beqz a4, .Lduff_loop /* Shortcut if no remainder */ neg a4, a4 @@ -100,6 +172,15 @@ WEAK(memset) addi t0, t0, 32*SZREG bltu t0, a3, .Lduff_loop + +#ifdef CONFIG_RISCV_ISA_ZICBOZ + ALT_ZICBOZ("j .Lcount_update", "nop") + beqz t1, .Lcount_update + sub a2, a2, t4 /* Difference was saved above */ + j .Ldo_zero2 +#endif + +.Lcount_update: andi a2, a2, SZREG-1 /* Update count */ .Lfinish: