Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp18655393ybl; Fri, 3 Jan 2020 06:34:27 -0800 (PST) X-Google-Smtp-Source: APXvYqw09N7d/fk5Yr6KYOKPNP5osztIUtvSRtcPniAnNdu+DiN/cOhism7t//SF7uj8Rc+QdmhB X-Received: by 2002:a9d:6211:: with SMTP id g17mr91737532otj.168.1578062067277; Fri, 03 Jan 2020 06:34:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578062067; cv=none; d=google.com; s=arc-20160816; b=wmoLJTayXO7ILcnK1WY9nASe7ZxatgwWo81243f1mD57kQCtisT7wT6WirvflTNvLQ jgvsc2hmY0hLcyBbB8bkkIC+o597e8c2ts/8542k0JJIv0SY36DS+G1H/Dj1Wo1aWC2r SmVoJv3z41qmbnFeAUUchNWF/9unMp5pBLiHQHkTyyLgMdhduAATXWNo21mvjEDaoJW5 hsiAtBiVO9cHrN9laJypL/GfYOoT/pUIPQM4Jv3DPmrBsmSHPXtFRXVz0s2CZZ3/ahkg /lkjSdM3ceWfqldmGIhn+xcKaI/zVMq2IBjdSaE/cyYLeE/2WS1ya1d/J0Nk+3TEsxA9 mVVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=ifraCwegUS/YivrX8FO5mIlbsVExhwEeZ5ejvcnHh4s=; b=aFozrD8LrdUcY2qMs2WGecZcrywGsgocNoLT2ecPIC3Z0mG+06l37jXVC+NAoUnu0Z 4fbntCiWecnPOY4kvurZSAMojsfQ/5kSmBqiDmJETtDpj22K6RMhlXDgAWWpdVW2jYA6 S7avajMkpbbCTLlWp09BBrhWfk4wvL5ZCCHU8rsMvWFoIq4cmjV/enxMPLuEwYZ/ngNR EZXYEVqsMh6B1lySsPluhNLkGyNDzpbuvnSZLo2XEayOj3xwY9+KktHxfDXCX+HYecqc NHJxsf6LU9n7T4Aoz/7nPVEdL4xvxNwFtJGZlCZ7Jo6zwspQ2icTMGQo13unhOfgmmrc LdvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zAwEgWPw; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b20si30887217otf.199.2020.01.03.06.34.07; Fri, 03 Jan 2020 06:34:27 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zAwEgWPw; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727631AbgACOds (ORCPT + 99 others); Fri, 3 Jan 2020 09:33:48 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:34655 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727598AbgACOds (ORCPT ); Fri, 3 Jan 2020 09:33:48 -0500 Received: by mail-wm1-f65.google.com with SMTP id c127so7076068wme.1 for ; Fri, 03 Jan 2020 06:33:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ifraCwegUS/YivrX8FO5mIlbsVExhwEeZ5ejvcnHh4s=; b=zAwEgWPw4pO0DCHgDxwW1alXNOnJdhvkMmGWwa4F2qVRueh+4ee3ZVMcsPLX0aTmQO Uj7cc057zj1I3A6YNXgdGAguam4Mw5u5aRjun4z9EvhDvX84EO4uqsgpz/YDvRIIwgfh QIl4O+rcCf69b12V++lHu85ivalDffEqxOseu5ng+n4U+DbsGkGGrv7QKqeagR8BTma1 p03NAL/DTcGNJ/0F43Z6iVzsGy2BkJHEhPvlERGOHkhKUyHdQTt8F0hkvoCejLXzboyn yWMviFSgaE8Kyy+RvRkzEP0M20lKX4i4e/OemeUK594XJNQT+jxZJFL1etBxmEvF8rUH P2eQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ifraCwegUS/YivrX8FO5mIlbsVExhwEeZ5ejvcnHh4s=; b=albKHbBve9PUwuN1EBGXyPsrYSSbEDXie04zUcYOaylE7PdsgIQG6+T9i5uJMupFmM B5HBtABia+MVKljHo7uSvipNkUocfYIsc68zzr3AIZulU7LcdPcDPeJiwueCJm1hjU2h fiMcl+EFN2C1Bj9A94aVMfgAWv+Bg/rZYYMCENiCS8wtj/Cms/OGm+k9uSpYBPI7swwK At+MifUWbm3eXC1XhDn55vsVG4O0/zoT3jv7doy++gnTpbS0enTlfxmyxPTvAHQUFIUG 2Z8RN/Be6j/cB85kb+swXz4O3EVu+ps1PQU4WyJPWaY1ESJTJQmGvtknh3+avWtGWJkO QAjg== X-Gm-Message-State: APjAAAVXc9wuSEVU4PWQ72/sc3kBxIWc6iPyAjVxugro47rqeqxmVxp2 Kc6yPS0fIPK6NzZpMMg+4yWcqcJzPt95aNaijCtVAEErvbpZ3w== X-Received: by 2002:a1c:3dc3:: with SMTP id k186mr19338410wma.95.1578062026229; Fri, 03 Jan 2020 06:33:46 -0800 (PST) MIME-Version: 1.0 References: <20191220190218.28884-1-cotequeiroz@gmail.com> In-Reply-To: From: Ard Biesheuvel Date: Fri, 3 Jan 2020 15:33:35 +0100 Message-ID: Subject: Re: QCE hw-crypto DMA issues To: Eneas Queiroz Cc: "open list:HARDWARE RANDOM NUMBER GENERATOR CORE" Content-Type: text/plain; charset="UTF-8" Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Thu, 2 Jan 2020 at 22:09, Eneas Queiroz wrote: > > I'm changing the subject title, as the original series has been merged. > > On Mon, Dec 23, 2019 at 6:46 AM Ard Biesheuvel wrote: >> >> On Fri, 20 Dec 2019 at 20:02, Eneas U de Queiroz wrote: >> > >> > I've been trying to make the Qualcomm Crypto Engine work with GCM-mode >> > AES. I fixed some bugs, and added an option to build only hashes or >> > skciphers, as the VPN performance increases if you leave some of that to >> > the CPU. >> > >> > A discussion about this can be found here: >> > https://github.com/openwrt/openwrt/pull/2518 >> > >> > I'm using openwrt to test this, and there's no support for kernel 5.x >> > yet. So I have backported the recent skcipher updates, and tested this >> > with 4.19. I don't have the hardware with me, but I have run-tested >> > everything, working remotely. >> > >> > All of the skciphers directly implemented by the driver work. They pass >> > the tcrypt tests, and also some tests from userspace using AF_ALG: >> > https://github.com/cotequeiroz/afalg_tests >> > >> > However, I can't get gcm(aes) to work. When setting the gcm-mode key, >> > it sets the ctr(aes) key, then encrypt a block of zeroes, and uses that >> > as the ghash key. The driver fails to perform that encryption. I've >> > dumped the input and output data, and they apparently are not touched by >> > the QCE. The IV, which written to a buffer appended to the results sg >> > list gets updated, but the results themselves are not. I'm not sure >> > what goes wrong, if it is a DMA/cache problem, memory alignment, or >> > whatever. >> > >> >> This does sound like a DMA problem. I assume the accelerator is not >> cache coherent? >> >> In any case, it is dubious whether the round trip to the accelerator >> is worth it when encrypting the GHASH key. Just call aes_encrypt() >> instead, and do it in software. > > > ipsec still fails, even if I use software for every single-block operation. I can perhaps leave that as an optimization, but it won't fix the main issue. > >> > If I take 'be128 hash' out of the 'data' struct, and kzalloc them >> > separately in crypto_gcm_setkey (crypto/gcm.c), it encrypts the data >> > just fine--perhaps the payload and the request struct can't be in the >> > same page? >> > >> >> Non-cache coherent DMA involves cache invalidation on inbound data. So >> if both the device and the CPU write to the same cacheline while the >> buffer is mapped for DMA from device to memory, one of the updates >> gets lost. > > > Can you give me any pointers/examples of how I can make this work? > You could have a look at commit ed527b13d800dd515a9e6c582f0a73eca65b2e1b