From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 34678C433F5 for ; Mon, 2 May 2022 18:12:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=9GWHoPCjxegG1IPpBkorBL1UrztEWOnOseXsXhPxx5M=; b=z6ug5G3ptk1gTm 9ar/oxtLwGORwWO9jovtu8uP2BihCV3RREuOR7+eA2fgBM9IARDYNld5J9ZMzKY9PkRB1573cotoC uBS0J46YcS14ZQB9zNOBemcqNTHWGIjPXBNUrM4Tfwb0qs6uE+9U8JZpdEucVRanpmuZ6Abzk8ICo DX2RiSzN89buOYxSZyVOEx2jas6ITGsjsF0TaGQynCNl5SRwwSbXVyEy/17SEk3XrzQVehaCHgc5l vrgsPBj5ixLWsS+HXiAKyU+Kq2pu99yo7kuMHRKjNl/wR/dUWUrd8nLXKP+Ee9paQGRGaZaqGon9O t8t/rpC4kyw1o4u2AuRQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nlaWL-0029HI-6H; Mon, 02 May 2022 18:11:41 +0000 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nlaWH-0029G0-1k for linux-arm-kernel@lists.infradead.org; Mon, 02 May 2022 18:11:38 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 7F13EB81995; Mon, 2 May 2022 18:11:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D703FC385AF; Mon, 2 May 2022 18:11:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1651515094; bh=zzrXkz9pG9pqxiWh52xFbya/y73Z84xkuk20846MbhA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=RNw9zzBf2LscPWVecm8dJYV91hgvntZDW/ZEM7cWrvM8NFvCu+59+ys9EYMubhH0k HanKFcFhoioip2QeMDfl7Iz4Hj/ur5ee5CP13X6aqkTnktn0NGDijHhVcPKgi+BU0g EZ4iWqmT1AijJXGIsvb1cMsxWWf3ijvMplWr5L2k8dyhNA0HqT6BC+rV+yqobBusnj 9sm1Gx+aayW93isjbHSpunRNHDxna023sUC1OiqW5XTXvR84mXgt2fP99eTiEj1oCY vvJi08JtTjYSSopfEQkWwxK2GZyp/ohzmEsktcsvvJvgo9N9/IXTsAsaSy3E8oYmpb Jd8OTnonv5SCQ== Date: Mon, 2 May 2022 11:11:32 -0700 From: Eric Biggers To: Nathan Huckleberry Cc: linux-crypto@vger.kernel.org, linux-fscrypt.vger.kernel.org@google.com, Herbert Xu , "David S. Miller" , linux-arm-kernel@lists.infradead.org, Paul Crowley , Sami Tolvanen , Ard Biesheuvel Subject: Re: [PATCH v5 7/8] crypto: arm64/polyval: Add PMULL accelerated implementation of POLYVAL Message-ID: References: <20220427003759.1115361-1-nhuck@google.com> <20220427003759.1115361-8-nhuck@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220502_111137_277402_6D976033 X-CRM114-Status: GOOD ( 20.27 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Sun, May 01, 2022 at 01:21:52PM -0700, Eric Biggers wrote: > > +static int polyval_arm64_update(struct shash_desc *desc, > > + const u8 *src, unsigned int srclen) > > +{ > > + struct polyval_desc_ctx *dctx = shash_desc_ctx(desc); > > + struct polyval_tfm_ctx *ctx = crypto_shash_ctx(desc->tfm); > > + u8 *pos; > > + unsigned int nblocks; > > + unsigned int n; > > + > > + if (dctx->bytes) { > > + n = min(srclen, dctx->bytes); > > + pos = dctx->buffer + POLYVAL_BLOCK_SIZE - dctx->bytes; > > + > > + dctx->bytes -= n; > > + srclen -= n; > > + > > + while (n--) > > + *pos++ ^= *src++; > > + > > + if (!dctx->bytes) > > + internal_polyval_mul(dctx->buffer, > > + ctx->key_powers[NUM_KEY_POWERS-1]); > > + } > > + > > + nblocks = srclen/POLYVAL_BLOCK_SIZE; > > + internal_polyval_update(ctx, src, nblocks, dctx->buffer); > > + srclen -= nblocks*POLYVAL_BLOCK_SIZE; > > This is executing a kernel_neon_begin()/kernel_neon_end() section of unbounded > length. To allow the task to be preempted occasionally, it needs to handle the > input in chunks, e.g. 4K at a time, like the existing code for other algorithms > does. Something like the following would work: > > @@ -122,13 +118,16 @@ static int polyval_arm64_update(struct shash_desc *desc, > ctx->key_powers[NUM_KEY_POWERS-1]); > } > > - nblocks = srclen/POLYVAL_BLOCK_SIZE; > - internal_polyval_update(ctx, src, nblocks, dctx->buffer); > - srclen -= nblocks*POLYVAL_BLOCK_SIZE; > + while (srclen >= POLYVAL_BLOCK_SIZE) { > + /* Allow rescheduling every 4K bytes. */ > + nblocks = min(srclen, 4096U) / POLYVAL_BLOCK_SIZE; > + internal_polyval_update(ctx, src, nblocks, dctx->buffer); > + srclen -= nblocks * POLYVAL_BLOCK_SIZE; > + src += nblocks * POLYVAL_BLOCK_SIZE; > + } > > if (srclen) { > dctx->bytes = POLYVAL_BLOCK_SIZE - srclen; > - src += nblocks*POLYVAL_BLOCK_SIZE; > pos = dctx->buffer; > while (srclen--) > *pos++ ^= *src++; > Also to be clear, this problem is specific to the "shash" API. You don't need to worry about it for "skcipher" algorithms such as xctr(*), as they have to walk a scatterlist to get their data, and that happens a page at a time. - Eric _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel