Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp916416imm; Wed, 26 Sep 2018 08:44:28 -0700 (PDT) X-Google-Smtp-Source: ACcGV62mqCi+O4dSnDa+UhLTpzKhIgPpEjmuS9RJ7+26qO5+T1G0FlncNLjlfvZ5eoAIw3TfpFhR X-Received: by 2002:a17:902:b7c2:: with SMTP id v2-v6mr6735226plz.238.1537976667957; Wed, 26 Sep 2018 08:44:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537976667; cv=none; d=google.com; s=arc-20160816; b=B73KqS3ZW46xDaUMqUpr02Ls4kvm80Icd4HygKXNf/7UrQ8qr/mnCz1fDpByd4JUr9 Ej5TrIwrLj8SmLr3Y+Cwf3cGhhi2BKBZUme4Lv9yoc4udq/kQfS3VwFJ6McC4GAXOrud l3TfXRZcVtahK3/8+hnLduv0K7yYb2KrTVL8IoQsIoN2MXJ81YMbfU75h5D8h0mlzibR KgX3wpxsH2rFUcM+jXnh3eLHUAMiWH4v95Ph9DsYQ2aQ/bDHE1Ue93ujEMHLzyh1xHXa 3SMDJ0BqK2MRSgnGxY4Ju/m6tfoTNN/3QI08+kf1KT70g8upzn2W55RGygBWz5F+lD7k tKdg== 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=fCJVnPPLWEATgE21wxrgrVuRh7WoK5vHrKiJ+37zDQI=; b=yI+wYInfNoHUw+cq4cRegxq+y6LwbDSR/kqZ9WclqZ2Q6TFpD9J480wgFE2FjAhhPn fWF7XzQKPfoR3hkcQhLmAAzcMTRxi8aLUFMvNSfut+cs/mtcmZMzot0oeRInaH9UxvYs XNYW6qe1RslRABSLhhpYSvzJN7uNyMcD7GqSNMio5/SIXhiPfz1CcUicSV3bqKGnMxyM Bkm8R1Shf3tdNyfd0EAB1yNJ5pcOXwwV4XroVw7DPdgU4LTUdN/oXeweP5BD4GNDxi4j s/IqaJATrMER1NaY4KoBKx117A2/7ko9kC/H6+wLS7gWDZ+cGkDpY1c9zAlYOe7Ut44Z A/Cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dKgVTvnw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 d4-v6si585534pgj.341.2018.09.26.08.44.12; Wed, 26 Sep 2018 08:44:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=dKgVTvnw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 S1728436AbeIZVzf (ORCPT + 99 others); Wed, 26 Sep 2018 17:55:35 -0400 Received: from mail-it1-f195.google.com ([209.85.166.195]:52117 "EHLO mail-it1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728354AbeIZVzf (ORCPT ); Wed, 26 Sep 2018 17:55:35 -0400 Received: by mail-it1-f195.google.com with SMTP id 74-v6so1847845itw.1 for ; Wed, 26 Sep 2018 08:42:04 -0700 (PDT) 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=fCJVnPPLWEATgE21wxrgrVuRh7WoK5vHrKiJ+37zDQI=; b=dKgVTvnwsOIU54webWPzIw7ix9mbqW0LGgx9gn4osbXwU1nkGWZCYqTIWHQ3jxcmfs CHyze8oyoSeqit+/xvP9aQH7Z/ruDBP947+pe0kY9bf6i1QzbAWyN1eUqQakJoMancmy vHS3O3ZnKUqEH32zKo4oV5RksxVxl/BMTo4Q8= 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=fCJVnPPLWEATgE21wxrgrVuRh7WoK5vHrKiJ+37zDQI=; b=PLNdEDHCAWUuVH+QPw1V+8B1on6Nheub+TVkSy0jiOwP444lMhHE08VGLy3e88aPWI hvBQYuiljhJi1ET028PC1zVAKB54PT+Y3QHdL1z+UAVxPjPpN/I25ni8jvGY12GTH+Zt jPHJaN7mTHZizBgWS+EBO//mBLFFREOIoKQpPq5vjryG7PATqmsUBgvXRk/zHHmJ5DHT sKILbbS5xANzD+8OwUYhNzLqhuIquTcqwo5Q4JtJmOhSmg3m12bsgXyHnZM1CtqJJBUc QRSiBD5WbvMjfz1CFZjeKBaJo3FPM7utLhj4fmPmVBoSEw/ozTBMqo3KrSHTtv9y1eFj s+Cw== X-Gm-Message-State: ABuFfogV9oQboPkBJHkDnIn8qsdoT9327xWn8bPF5H4Ikw4VSYYRLFBv WYof7+KOgR6CsmeD0vdHJf0dy/vQjpBN4lLW4+LTtlxY X-Received: by 2002:a24:e48e:: with SMTP id o136-v6mr5515810ith.58.1537976523776; Wed, 26 Sep 2018 08:42:03 -0700 (PDT) MIME-Version: 1.0 References: <20180925145622.29959-1-Jason@zx2c4.com> <20180925145622.29959-8-Jason@zx2c4.com> In-Reply-To: From: Ard Biesheuvel Date: Wed, 26 Sep 2018 17:41:50 +0200 Message-ID: Subject: Re: [PATCH net-next v6 07/23] zinc: ChaCha20 ARM and ARM64 implementations To: "Jason A. Donenfeld" , Herbert Xu , Thomas Gleixner Cc: Linux Kernel Mailing List , "" , "open list:HARDWARE RANDOM NUMBER GENERATOR CORE" , "David S. Miller" , Greg Kroah-Hartman , Samuel Neves , Andy Lutomirski , Jean-Philippe Aumasson , Russell King , linux-arm-kernel Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 26 Sep 2018 at 16:02, Ard Biesheuvel wrote: > > (+ Herbert, Thomas) > > On Wed, 26 Sep 2018 at 15:33, Jason A. Donenfeld wrote: > > > > Hi Ard, > > > > On Wed, Sep 26, 2018 at 10:59 AM Ard Biesheuvel > > wrote: > > > > +static inline bool chacha20_arch(struct chacha20_ctx *state, u8 *dst, > > > > + const u8 *src, size_t len, > > > > + simd_context_t *simd_context) > > > > +{ > > > > +#if defined(CONFIG_KERNEL_MODE_NEON) > > > > + if (chacha20_use_neon && len >= CHACHA20_BLOCK_SIZE * 3 && > > > > + simd_use(simd_context)) > > > > + chacha20_neon(dst, src, len, state->key, state->counter); > > > > + else > > > > +#endif > > > > > > Better to use IS_ENABLED() here: > > > > > > > + if (IS_ENABLED(CONFIG_KERNEL_MODE_NEON)) && > > > > + chacha20_use_neon && len >= CHACHA20_BLOCK_SIZE * 3 && > > > > + simd_use(simd_context)) > > > > Good idea. I'll fix that up. > > > > > > > > Also, this still has unbounded worst case scheduling latency, given > > > that the outer library function passes its entire input straight into > > > the NEON routine. > > > > The vast majority of crypto routines in arch/*/crypto/ follow this > > same exact pattern, actually. I realize a few don't -- probably the > > ones you had a hand in :) -- but I think this is up to the caller to > > handle. > > Anything that uses the scatterwalk API (AEADs and skciphers) will > handle at most a page at a time. Hashes are different, which is why > some of them have to handle it explicitly. > > > I made a change so that in chacha20poly1305.c, it calls > > simd_relax after handling each scatter-gather element, so a > > "construction" will handle this gracefully. But I believe it's up to > > the caller to decide on what sizes of information it wants to pass to > > primitives. Put differently, this also hasn't ever been an issue > > before -- the existing state of the tree indicates this -- and so I > > don't anticipate this will be a real issue now. > > The state of the tree does not capture all relevant context or > history. The scheduling latency issue was brought up very recently by > the -rt folks on the mailing lists. > > > And if it becomes one, > > this is something we can address *later*, but certainly there's no use > > of adding additional complexity to the initial patchset to do this > > now. > > > > You are introducing a very useful SIMD abstraction, but it lets code > run with preemption disabled for unbounded amounts of time, and so now > is the time to ensure we get it right. > Actually, looking at the code again, the abstraction does appear to be fine, it is just the chacha20 code that does not make use of it.