Received: by 2002:ac0:c50a:0:0:0:0:0 with SMTP id y10csp1337870imi; Fri, 1 Jul 2022 07:46:57 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tzElNogrmG8yqqOH6t6QESgDmWLxtYplvUNp65RaHgLIAweczjt+tJUYHCjIwtgdyE+YR9 X-Received: by 2002:a63:5217:0:b0:40d:b32b:6e4b with SMTP id g23-20020a635217000000b0040db32b6e4bmr12802220pgb.17.1656686817580; Fri, 01 Jul 2022 07:46:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656686817; cv=none; d=google.com; s=arc-20160816; b=LR7xplUpJxnY54ltA++/lAP3Sha2dL59arj8tNBGjiRXdc+U8jkDcwXsL3F/wZIVa7 Pr0ZjKaXdudyZ52IdsYMd7qRuMQB9mmDs8I4wdl4XcsotiGUFwHNbqbxUMoX6BE3Dpov 2V4cS4Q15pz372NhBnva4sNNe7JI32+MUl+YzMe2SlmFwN/F+i+88n8kWxd1RhZ1ft47 +v2MM8ItgkbJhSFHs47Lr7D5aUsRy5h+v4i9FA7imSlAu1R5pksX6AH7C7k2GmUUnfQf ZmsF3MY0TMZJkHXVGOO6sl9HW6LdaYGlq6oHmWjSzSaagPFbrb9JiPtAECe59hMKPIic fCdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=jRwySDKOkvzeBhkaDAVoFlFG2iOMGFhMIqAO8rOHfKY=; b=K2B64KtOTK+SirjVkdLoP3gwrhvaIUZoj1Zf8cOSAW2wPRFn05DIEzLd2OLEC9IKIv cLiuSAFhFlDPwRPVe9HVRnrkZ+5qVFFD+Ji7Tag/IIeyYCo3GaYEDSxRKfdbrVq83CCl X8y5rRPimj4oq6zS8ucelfmzgDBQfTnQ3U7mCAxho8bHpE8zLHhOkdLXfk8cR4MIyW1D iB2TU+QrUDbw1FZRH+H7tDf0fB489unijzKzIsa6ArDfB1RfjxgHwZ4rBTDxVv6bI04W luS4xYmHLLKn7vIm9qR2rPrInF9vhYiH0D2D4FePRmweRoJWuh7fEszMKCygi1W65klf fcfA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id pc2-20020a17090b3b8200b001e6820f720esi73919pjb.125.2022.07.01.07.46.21; Fri, 01 Jul 2022 07:46:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233060AbiGAOi7 (ORCPT + 99 others); Fri, 1 Jul 2022 10:38:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233276AbiGAOio (ORCPT ); Fri, 1 Jul 2022 10:38:44 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7C8656D56F; Fri, 1 Jul 2022 07:36:19 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 89713113E; Fri, 1 Jul 2022 07:36:19 -0700 (PDT) Received: from donnerap.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 03FFE3F792; Fri, 1 Jul 2022 07:36:17 -0700 (PDT) Date: Fri, 1 Jul 2022 15:36:14 +0100 From: Andre Przywara To: Corentin Labbe Cc: herbert@gondor.apana.org.au, hch@lst.de, heiko@sntech.de, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-sunxi@lists.linux.dev, Ben Dooks Subject: Re: [RFC PATCH] crypto: flush poison data Message-ID: <20220701153614.0a576f9c@donnerap.cambridge.arm.com> In-Reply-To: <20220701132735.1594822-1-clabbe@baylibre.com> References: <20220701132735.1594822-1-clabbe@baylibre.com> Organization: ARM X-Mailer: Claws Mail 3.18.0 (GTK+ 2.24.32; aarch64-unknown-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Fri, 1 Jul 2022 13:27:35 +0000 Corentin Labbe wrote: Hi, > On my Allwinner D1 nezha, the sun8i-ce fail self-tests due to: > alg: skcipher: cbc-des3-sun8i-ce encryption overran dst buffer on test vector 0 > > In fact the buffer is not overran by device but by the dma_map_single() operation. > > To prevent any corruption of the poisoned data, simply flush them before > giving the buffer to the tested driver. > > Signed-off-by: Corentin Labbe > --- > > Hello > > I put this patch as RFC, since this behavour happen only on non yet merged RISCV code. > (Mostly riscv: implement Zicbom-based CMO instructions + the t-head variant) > > Regards > > crypto/testmgr.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/crypto/testmgr.c b/crypto/testmgr.c > index c59bd9e07978..187163e2e593 100644 > --- a/crypto/testmgr.c > +++ b/crypto/testmgr.c > @@ -19,6 +19,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -205,6 +206,8 @@ static void testmgr_free_buf(char *buf[XBUFSIZE]) > static inline void testmgr_poison(void *addr, size_t len) > { > memset(addr, TESTMGR_POISON_BYTE, len); > + /* Be sure data is written to prevent corruption from some DMA sync */ > + flush_icache_range((unsigned long)addr, (unsigned long)addr + len); As Ben already mentioned, this looks like having nothing to do with the I cache. I guess you picked that because it does the required cache cleaning and doesn't require a vma parameter? But more importantly: I think drivers shouldn't do explicit cache maintenance, this is what the DMA API is for. So if you get DMA corruption, then this points to some flaw in the DMA API usage: either the buffer belongs to the CPU, then the device must not write to it. Or the buffer belongs to the device, then the CPU cannot expect to write to that without that data potentially getting corrupted. So can you check if that's the case? Cheers, Andre > } > > /* Is the memory region still fully poisoned? */