From patchwork Sun Oct 11 11:34:22 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin Labbe X-Patchwork-Id: 7368791 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Original-To: patchwork-linux-crypto@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 8039C9F36A for ; Sun, 11 Oct 2015 11:34:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 824A620723 for ; Sun, 11 Oct 2015 11:34:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7FA1220722 for ; Sun, 11 Oct 2015 11:34:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751787AbbJKLe1 (ORCPT ); Sun, 11 Oct 2015 07:34:27 -0400 Received: from mail-wi0-f178.google.com ([209.85.212.178]:36496 "EHLO mail-wi0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751699AbbJKLe0 (ORCPT ); Sun, 11 Oct 2015 07:34:26 -0400 Received: by wicgb1 with SMTP id gb1so118189159wic.1; Sun, 11 Oct 2015 04:34:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=to:cc:from:subject:message-id:date:user-agent:mime-version :content-type:content-transfer-encoding; bh=UaqMd7lEAQ/WZuq0cQG9FiQj3HYVWp0rUaCO5MPLjr4=; b=FqowBJxQkK2LVFHp1JG8J/DkqRHj6wSD6KRvDc0Hb3Bhm19+7Dn5VsLKXF+WkXPxC2 uAdhSBSF3oRGYJyg52rtqVav8pha2XeV/RmnOt+hSScse8f1n/HWQuNdkkVsrQ4PUtwt qjbBuXsa+Wy4TZ2JUHzX+mtd6En6ABLJYHHzChnfRuUbJp11NYrffLNZpNTwfwHhdJHk 7LoZZErJkvofpw57nipjesnldDyVdNcDZKziYhKL5M4ZHwFGA4TFFE6fiGxwctssfUw1 zH2TBKord0DSJceJyosK7YZWb3pIH8GIl9FmUUDnos+LvXOjkl322hxHdppLpUSCGBZI OS1g== X-Received: by 10.180.107.130 with SMTP id hc2mr8371958wib.92.1444563264928; Sun, 11 Oct 2015 04:34:24 -0700 (PDT) Received: from ?IPv6:2a01:240:fe00:142::2? (cl-323.mrs-01.fr.sixxs.net. [2a01:240:fe00:142::2]) by smtp.googlemail.com with ESMTPSA id ry1sm13326637wjb.24.2015.10.11.04.34.24 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 11 Oct 2015 04:34:24 -0700 (PDT) To: linux-crypto@vger.kernel.org Cc: Linux Kernel Mailing List , "linux-sunxi@googlegroups.com" From: Corentin LABBE Subject: crypto: sun4i-ss: bug with cryptodev Message-ID: <561A493E.6030902@gmail.com> Date: Sun, 11 Oct 2015 13:34:22 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hello I am working on some tools for checking the good working of crypto device (and benching them). One of the tool use cryptodev (http://cryptodev-linux.org/) for using the kernel crypto API (and so any hardware accelerated crypto). The tool compare the results of an AES cipher via cryptodev and the result of the same cipher via openssl. Exactly it test the results of one encryption, and then the decryption. For an unknown reason, the tool detect a problem with my sun4i-ss driver. The last n bytes of data are garbage. This happens randomly for any length of data starting from 4096 bytes(I never got any fail with size < 4096). But always on the deciphering test. Example: I have the src buffer of 32768 bytes, I cipher it via cryptodev in the dst buffer and then cipher it in odst via openssl. Then I compare dst and odst, that part is always working. Then I use cryptodev to decipher dst in ddst, and compare src and ddst. The test fail with ddst being garbage at offset 28784. (the offset is always different in each fail). I have tried to find which change cause that problem and it seems to be introduced in v10. But it is very strange because I am sure to have tested all versions with this tool. I have found a fix for this problem, but I do not like it and I do not understand why it solve the problem. The fix is to remove the flag SG_MITER_ATOMIC from the destination buffer miter. (and so change the spinlock to irq_save but changing only the spinlock does not solve the problem). For giving more information I use cryptodev 1.7, and my tool is available at https://github.com/montjoie/cryptotest. So I seek any advice for understanding why removing SG_MITER_ATOMIC fix the problem. For giving more informations, without my driver, the same test works, so I thinked that the problem was with my driver. But I have made two other tools, one what do the same thing with AF_ALG, and one who is a module who use the crypto API for checking against the cbc(aes-generic) (instead of openssl). Both tools do not find any error. Best regards the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/crypto/sunxi-ss/sun4i-ss-cipher.c b/drivers/crypto/sunxi-ss/sun4i-ss-cipher.c index e070c31..07ee88e 100644 --- a/drivers/crypto/sunxi-ss/sun4i-ss-cipher.c +++ b/drivers/crypto/sunxi-ss/sun4i-ss-cipher.c @@ -35,6 +35,7 @@ static int sun4i_ss_opti_poll(struct ablkcipher_request *areq) unsigned int todo; struct sg_mapping_iter mi, mo; unsigned int oi, oo; /* offset for in and out */ + unsigned long flags; if (areq->nbytes == 0) return 0; @@ -49,7 +50,7 @@ static int sun4i_ss_opti_poll(struct ablkcipher_request *areq) return -EINVAL; } - spin_lock_bh(&ss->slock); + spin_lock_irqsave(&ss->slock, flags); for (i = 0; i < op->keylen; i += 4) writel(*(op->key + i / 4), ss->base + SS_KEY0 + i); @@ -65,7 +66,7 @@ static int sun4i_ss_opti_poll(struct ablkcipher_request *areq) sg_miter_start(&mi, areq->src, sg_nents(areq->src), SG_MITER_FROM_SG | SG_MITER_ATOMIC); sg_miter_start(&mo, areq->dst, sg_nents(areq->dst), - SG_MITER_TO_SG | SG_MITER_ATOMIC); + SG_MITER_TO_SG); sg_miter_next(&mi); sg_miter_next(&mo); if (!mi.addr || !mo.addr) { @@ -117,7 +118,7 @@ release_ss: sg_miter_stop(&mi); sg_miter_stop(&mo); writel(0, ss->base + SS_CTL); - spin_unlock_bh(&ss->slock); + spin_unlock_irqrestore(&ss->slock, flags); return err; } -- To unsubscribe from this list: send the line "unsubscribe linux-crypto" in