From patchwork Wed Apr 7 17:16:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?C=C3=A9dric_Le_Goater?= X-Patchwork-Id: 12189033 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A21ADC433B4 for ; Wed, 7 Apr 2021 17:31:45 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 4BEFD61242 for ; Wed, 7 Apr 2021 17:31:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4BEFD61242 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kaod.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:37244 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lUC1o-00018F-0J for qemu-devel@archiver.kernel.org; Wed, 07 Apr 2021 13:31:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38920) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUBnh-0007Tu-3A; Wed, 07 Apr 2021 13:17:09 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:15742) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUBnc-0006ly-Se; Wed, 07 Apr 2021 13:17:08 -0400 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 137H3MW9072187; Wed, 7 Apr 2021 13:16:53 -0400 Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0a-001b2d01.pphosted.com with ESMTP id 37rw6kgn2k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 07 Apr 2021 13:16:52 -0400 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.0.43/8.16.0.43) with SMTP id 137HDcS5031054; Wed, 7 Apr 2021 17:16:50 GMT Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by ppma03ams.nl.ibm.com with ESMTP id 37rvbqgwc4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 07 Apr 2021 17:16:50 +0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 137HGmBN48103848 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 7 Apr 2021 17:16:48 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 38AEE5204F; Wed, 7 Apr 2021 17:16:48 +0000 (GMT) Received: from smtp.tlslab.ibm.com (unknown [9.101.4.1]) by d06av21.portsmouth.uk.ibm.com (Postfix) with SMTP id EE8F752052; Wed, 7 Apr 2021 17:16:47 +0000 (GMT) Received: from yukon.ibmuc.com (unknown [9.171.70.229]) by smtp.tlslab.ibm.com (Postfix) with ESMTP id 0C5AE220190; Wed, 7 Apr 2021 19:16:46 +0200 (CEST) From: =?utf-8?q?C=C3=A9dric_Le_Goater?= To: Peter Maydell Subject: [PATCH 09/24] aspeed: Add Scater-Gather support for HACE Hash Date: Wed, 7 Apr 2021 19:16:22 +0200 Message-Id: <20210407171637.777743-10-clg@kaod.org> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210407171637.777743-1-clg@kaod.org> References: <20210407171637.777743-1-clg@kaod.org> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: u8I3oDBvdfs5CM-OYciVjmDI1T_GSbHZ X-Proofpoint-ORIG-GUID: u8I3oDBvdfs5CM-OYciVjmDI1T_GSbHZ X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.761 definitions=2021-04-07_09:2021-04-07, 2021-04-07 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 impostorscore=0 bulkscore=0 priorityscore=1501 mlxscore=0 suspectscore=0 mlxlogscore=721 clxscore=1034 phishscore=0 spamscore=0 malwarescore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104070116 Received-SPF: softfail client-ip=148.163.156.1; envelope-from=clg@kaod.org; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrew Jeffery , qemu-devel@nongnu.org, Klaus Heinrich Kiwi , qemu-arm@nongnu.org, =?utf-8?q?C=C3=A9dric_Le_Goater?= , Joel Stanley Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Klaus Heinrich Kiwi Complement the Aspeed HACE support with Scatter-Gather hash support for sha256 and sha512. Scatter-Gather is only supported on AST2600-series. Signed-off-by: Klaus Heinrich Kiwi [ clg: - fixes for checkpatch errors ] Signed-off-by: Cédric Le Goater Message-Id: <20210326193745.13558-2-klaus@linux.vnet.ibm.com> Signed-off-by: Cédric Le Goater --- docs/system/arm/aspeed.rst | 2 +- hw/misc/aspeed_hace.c | 133 +++++++++++++++++++++++++++++++++++-- 2 files changed, 128 insertions(+), 7 deletions(-) diff --git a/docs/system/arm/aspeed.rst b/docs/system/arm/aspeed.rst index f9466e6d8245..8680fd9409db 100644 --- a/docs/system/arm/aspeed.rst +++ b/docs/system/arm/aspeed.rst @@ -49,7 +49,7 @@ Supported devices * Ethernet controllers * Front LEDs (PCA9552 on I2C bus) * LPC Peripheral Controller (a subset of subdevices are supported) - * Hash/Crypto Engine (HACE) - Hash support only, no scatter-gather + * Hash/Crypto Engine (HACE) - Hash support only Missing devices diff --git a/hw/misc/aspeed_hace.c b/hw/misc/aspeed_hace.c index 6e5b447a4835..8b3eebfaec63 100644 --- a/hw/misc/aspeed_hace.c +++ b/hw/misc/aspeed_hace.c @@ -57,6 +57,14 @@ /* Other cmd bits */ #define HASH_IRQ_EN BIT(9) #define HASH_SG_EN BIT(18) +/* Scatter-gather data list */ +#define SG_LIST_LEN_SIZE 4 +#define SG_LIST_LEN_MASK 0x0FFFFFFF +#define SG_LIST_LEN_LAST BIT(31) +#define SG_LIST_ADDR_SIZE 4 +#define SG_LIST_ADDR_MASK 0x7FFFFFFF +#define SG_LIST_ENTRY_SIZE (SG_LIST_LEN_SIZE + SG_LIST_ADDR_SIZE) +#define ASPEED_HACE_MAX_SG 256 /* max number of entries */ static const struct { uint32_t mask; @@ -129,6 +137,121 @@ static int do_hash_operation(AspeedHACEState *s, int algo) return 0; } +static int do_hash_sg_operation(AspeedHACEState *s, int algo) +{ + hwaddr src, dest, req_size; + uint32_t entry_len, entry_addr; + uint8_t *digest_buf = NULL; + unsigned int i = 0; + MemTxResult result; + struct iovec iov[ASPEED_HACE_MAX_SG]; + size_t digest_len = 0, size = 0; + int rc; + + req_size = s->regs[R_HASH_SRC_LEN]; + dest = s->regs[R_HASH_DEST]; + + while (i < ASPEED_HACE_MAX_SG) { + src = s->regs[R_HASH_SRC] + (i * SG_LIST_ENTRY_SIZE); + entry_len = address_space_ldl_le(&s->dram_as, src, + MEMTXATTRS_UNSPECIFIED, &result); + if (result != MEMTX_OK) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: failed to load SG Array length entry %"PRIu32 + " from 0x%"HWADDR_PRIx"\n", __func__, i, src); + rc = -EACCES; + goto cleanup; + } + entry_addr = address_space_ldl_le(&s->dram_as, src + SG_LIST_LEN_SIZE, + MEMTXATTRS_UNSPECIFIED, &result); + if (result != MEMTX_OK) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: failed to load SG Array address entry %"PRIu32 + " from 0x%"HWADDR_PRIx"\n", + __func__, i, src + SG_LIST_LEN_SIZE); + rc = -EACCES; + goto cleanup; + } + + iov[i].iov_len = (hwaddr) (entry_len & SG_LIST_LEN_MASK); + iov[i].iov_base = address_space_map(&s->dram_as, + entry_addr & SG_LIST_ADDR_MASK, + &iov[i].iov_len, false, + MEMTXATTRS_UNSPECIFIED); + if (!iov[i].iov_base) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: failed to map dram for SG array entry %"PRIu32 + " for region 0x%"PRIx32", len %"PRIu32"\n", + __func__, i, entry_addr & SG_LIST_ADDR_MASK, + entry_len & SG_LIST_LEN_MASK); + rc = -EACCES; + goto cleanup; + } + if (iov[i].iov_len != (entry_len & SG_LIST_LEN_MASK)) + qemu_log_mask(LOG_GUEST_ERROR, + "%s: Warning: dram map for SG region entry %"PRIu32 + " requested size %"PRIu32" != mapped size %"PRIu64"\n", + __func__, i, entry_len & SG_LIST_LEN_MASK, + iov[i].iov_len); + + size += iov[i].iov_len; + i++; + + if (entry_len & SG_LIST_LEN_LAST) { + break; + } + } + + if (!(entry_len & SG_LIST_LEN_LAST)) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: Error: Exhausted maximum of %"PRIu32 + " SG array entries\n", + __func__, ASPEED_HACE_MAX_SG); + rc = -ENOTSUP; + goto cleanup; + } + + if (size != req_size) + qemu_log_mask(LOG_GUEST_ERROR, + "%s: Warning: requested SG total size %"PRIu64 + " != actual size %"PRIu64"\n", + __func__, req_size, size); + + rc = qcrypto_hash_bytesv(algo, iov, i, &digest_buf, &digest_len, + &error_fatal); + if (rc < 0) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: qcrypto failed\n", + __func__); + goto cleanup; + } + + rc = address_space_write(&s->dram_as, dest, MEMTXATTRS_UNSPECIFIED, + digest_buf, digest_len); + if (rc) + qemu_log_mask(LOG_GUEST_ERROR, + "%s: address space write failed\n", __func__); + g_free(digest_buf); + +cleanup: + + for (; i > 0; i--) { + address_space_unmap(&s->dram_as, iov[i - 1].iov_base, + iov[i - 1].iov_len, false, + iov[i - 1].iov_len); + } + + /* + * Set status bits to indicate completion. Testing shows hardware sets + * these irrespective of HASH_IRQ_EN. + */ + if (!rc) { + s->regs[R_STATUS] |= HASH_IRQ; + } + + return rc; +} + + static uint64_t aspeed_hace_read(void *opaque, hwaddr addr, unsigned int size) { @@ -187,11 +310,6 @@ static void aspeed_hace_write(void *opaque, hwaddr addr, uint64_t data, "%s: HMAC engine command mode %"PRIx64" not implemented", __func__, (data & HASH_HMAC_MASK) >> 8); } - if (data & HASH_SG_EN) { - qemu_log_mask(LOG_UNIMP, - "%s: Hash scatter gather mode not implemented", - __func__); - } if (data & BIT(1)) { qemu_log_mask(LOG_UNIMP, "%s: Cascaded mode not implemented", @@ -204,7 +322,10 @@ static void aspeed_hace_write(void *opaque, hwaddr addr, uint64_t data, __func__, data & ahc->hash_mask); break; } - do_hash_operation(s, algo); + if (data & HASH_SG_EN) + do_hash_sg_operation(s, algo); + else + do_hash_operation(s, algo); if (data & HASH_IRQ_EN) { qemu_irq_raise(s->irq);