From patchwork Tue Jan 11 03:51:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Weiwei Li X-Patchwork-Id: 12709489 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 70E10C433EF for ; Tue, 11 Jan 2022 03:56:20 +0000 (UTC) Received: from localhost ([::1]:40936 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n78Gh-0000Jj-6X for qemu-devel@archiver.kernel.org; Mon, 10 Jan 2022 22:56:19 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39130) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n78CN-0001qb-Cu; Mon, 10 Jan 2022 22:51:51 -0500 Received: from smtp25.cstnet.cn ([159.226.251.25]:56192 helo=cstnet.cn) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n78CJ-0004Nw-TO; Mon, 10 Jan 2022 22:51:50 -0500 Received: from localhost.localdomain (unknown [180.156.147.178]) by APP-05 (Coremail) with SMTP id zQCowAD3_wPK_txh2Dz9BQ--.65038S2; Tue, 11 Jan 2022 11:51:39 +0800 (CST) From: Weiwei Li To: richard.henderson@linaro.org, palmer@dabbelt.com, alistair.francis@wdc.com, bin.meng@windriver.com, qemu-riscv@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH v4 0/7] support subsets of scalar crypto extension Date: Tue, 11 Jan 2022 11:51:17 +0800 Message-Id: <20220111035124.9468-1-liweiwei@iscas.ac.cn> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-CM-TRANSID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YvjfUF9a9DUUUU X-Originating-IP: [180.156.147.178] X-CM-SenderInfo: 5olzvxxzhlqxpvfd2hldfou0/ Received-SPF: pass client-ip=159.226.251.25; envelope-from=liweiwei@iscas.ac.cn; helo=cstnet.cn X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: wangjunqiang@iscas.ac.cn, Weiwei Li , lazyparser@gmail.com, luruibo2000@163.com, lustrew@foxmail.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" This patchset implements RISC-V scalar crypto extension v1.0.0 version instructions. Partial instructions are reused from B-extension. Specification: https://github.com/riscv/riscv-crypto The port is available here: https://github.com/plctlab/plct-qemu/tree/plct-k-upstream-v4 To test rvk implementation, specify cpu argument with 'zks=true,zkn=true' or "zbkb=true,zbkc=true,zbkx=true,zknd=true,zkne=true,zknh=true,zksed=true,zksh=true,zkr=true" to enable K-extension support. This implementation can pass the ACT tests for K with our extended act support for qemu (available at https://github.com/plctlab/plct-qemu/tree/plct-k-upstream-v4-with-act) v4: * drop "x-" in exposed properties * delete unrelated changes v3: * add extension check for SEED csr access v2: * optimize implementation for brev8, xperm, zip, unzip * use aes related sbox array from crypto/aes.h * move sm4_sbox to crypto/sm4.c, and share it with target/arm Weiwei Li (7): target/riscv: rvk: add cfg properties for zbk* and zk* target/riscv: rvk: add implementation of instructions for Zbk* crypto include/crypto target/arm: move sm4_sbox to crypto target/riscv: rvk: add implementation of instructions for Zk* target/riscv: rvk: add CSR support for Zkr disas/riscv.c: rvk: add disas support for Zbk* and Zk* instructions target/riscv: rvk: expose zbk* and zk* properties crypto/meson.build | 1 + crypto/sm4.c | 49 +++ disas/riscv.c | 170 +++++++++ include/crypto/sm4.h | 6 + target/arm/crypto_helper.c | 36 +- target/riscv/bitmanip_helper.c | 74 ++++ target/riscv/cpu.c | 37 ++ target/riscv/cpu.h | 13 + target/riscv/cpu_bits.h | 9 + target/riscv/crypto_helper.c | 446 ++++++++++++++++++++++ target/riscv/csr.c | 74 ++++ target/riscv/helper.h | 42 +++ target/riscv/insn32.decode | 94 ++++- target/riscv/insn_trans/trans_rvb.c.inc | 127 ++++++- target/riscv/insn_trans/trans_rvk.c.inc | 467 ++++++++++++++++++++++++ target/riscv/meson.build | 3 +- target/riscv/pmp.h | 8 +- target/riscv/translate.c | 8 + 18 files changed, 1594 insertions(+), 70 deletions(-) create mode 100644 crypto/sm4.c create mode 100644 include/crypto/sm4.h create mode 100644 target/riscv/crypto_helper.c create mode 100644 target/riscv/insn_trans/trans_rvk.c.inc