Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp4482410ybp; Mon, 7 Oct 2019 09:05:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqxedV3JbgqAvL5aeYkrIBNkcsoU7KjEQjPBaNST0F+qhNEpF9ylWfINYOx+t2xrH8rUT5BB X-Received: by 2002:a50:b6aa:: with SMTP id d39mr28990551ede.16.1570464356738; Mon, 07 Oct 2019 09:05:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570464356; cv=none; d=google.com; s=arc-20160816; b=EASS6sSnpUbtbEkEI7nrnJQU30/PUvrgZovL7WyOxK9FKq+5L05kmg0qpx5TP2GV9j 4d6IBaA1NbRDNnj5Zg5chCTabqT7WYe7nEffZbjyNdckMFLB+eAafIitkA8xFo5HSuwo LDJb12QRZ3E191MAExQRVIoddiUFN10CFT2ENi+GKD6trDONmzjpFA8N04sbcGQ4L3TM hJkM1/9cvlEKc9QdT6GY4xYtsZgVsW0XCCdOGTk8XXeeQt8to1k1lmItiF7aTQdqfTMz t3s2eL7FWn7ihX/NP5Swm78EqXFAgK/OkbRO2yqqyQdkoPChqEctUoZP18X86aytjsGL XVOQ== 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=Psx8Y6ska3tjBqBr+MWMYNRJvejJM/fqyboyM0jIAWM=; b=EtyePl6MOSbayaYrcEf3QEKgP37Rc9GDBuzwMp2AxKhLBxMZU2tzqY6D9i2/7ueuyL j+Jf73U2JHyIiRHDswdj7Ts+Oft229mIUKhur05YRS98Q9sslz1KDPbxuIb7GabKTenP a2EnVNHFxVN8W4H2w2F8C13Apkl+WxM29MTqTjLgk8kiA3BSgGvvuCktVRTGgcMsTURH ljgwEn+JQdaWPEb1S7jz3iXI05LTELvkeqOpRbLN3Gd7ZnfmZ+iopfITJubsPYiGa/g+ EGZqcXlW43N8VbgiIT2geRDhMImuzyDKiyq3ii9rXb7asYt8ObwYC0PZWkEv+oNQ8u1T QzxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VkuU+YoI; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k7si7031583eja.377.2019.10.07.09.05.25; Mon, 07 Oct 2019 09:05:56 -0700 (PDT) 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=@kernel.org header.s=default header.b=VkuU+YoI; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727711AbfJGQFU (ORCPT + 99 others); Mon, 7 Oct 2019 12:05:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:56032 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727801AbfJGQFU (ORCPT ); Mon, 7 Oct 2019 12:05:20 -0400 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D285C205C9 for ; Mon, 7 Oct 2019 16:05:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570464319; bh=tZ52lW+2owZ6FS8euu9Nt3i0FCpurv5BeoGCv2dYG3s=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=VkuU+YoIU5W6SZLGb2McUzcOZB3NJf2191T66r4PcBZsw0EosDDPIhFV5LrC0Da24 Hx8b52vSREg5zQK8UgMHkulwcy/yRJaP9vm6ks2f3JgbjaMYQ9uqY4NNSQV8rLdHcH XYjOAiP5TQzXvPl0ZHm+mSUIFvXtDFfWXRePNuRI= Received: by mail-wr1-f43.google.com with SMTP id o18so15947113wrv.13 for ; Mon, 07 Oct 2019 09:05:18 -0700 (PDT) X-Gm-Message-State: APjAAAUqGLgyUB21OBVhoyaY2uY1JMO2wcZ9iDoTh7i5Ln7JxtY2rMrC ZdBjJtcHfJHHLnKy9bHh41XYt6KlnPZBEV2uWr/0ig== X-Received: by 2002:a05:6000:1632:: with SMTP id v18mr24495521wrb.61.1570464317306; Mon, 07 Oct 2019 09:05:17 -0700 (PDT) MIME-Version: 1.0 References: <04D32F59-34D4-4EBF-80E3-69088D14C5D8@amacapital.net> In-Reply-To: From: Andy Lutomirski Date: Mon, 7 Oct 2019 09:05:05 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 00/20] crypto: crypto API library interfaces for WireGuard To: Ard Biesheuvel Cc: "Jason A. Donenfeld" , "open list:HARDWARE RANDOM NUMBER GENERATOR CORE" , Herbert Xu , David Miller , Greg KH , Linus Torvalds , Samuel Neves , Dan Carpenter , Arnd Bergmann , Eric Biggers , Andy Lutomirski , Will Deacon , Marc Zyngier , Catalin Marinas , Martin Willi , Peter Zijlstra , Josh Poimboeuf 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 Mon, Oct 7, 2019 at 8:12 AM Ard Biesheuvel wrote: > > On Mon, 7 Oct 2019 at 17:02, Andy Lutomirski wrote: > > > > On Sun, Oct 6, 2019 at 10:24 PM Ard Biesheuvel > > wrote: > > > > > > On Mon, 7 Oct 2019 at 06:44, Andy Lutomirski wrote: > > > > > > > > > > > Actually, this can be addressed by retaining the module dependencies > > > > > as before, but permitting the arch module to be omitted at load time. > > > > > > > > I think that, to avoid surprises, you should refuse to load the arch module if the generic module is loaded, too. > > > > > > > > > > Most arch code depends on CPU features that may not be available given > > > the context, either because they are SIMD or because they are optional > > > CPU instructions. So we need both modules at the same time anyway, so > > > that we can fall back to the generic code at runtime. > > > > > > So what I'd like is to have the generic module provide the library > > > interface, but rely on arch modules that are optional. > > > > > > We already have 95% of what we need with weak references. We have the > > > ability to test for presence of the arch code at runtime, and we even > > > have code patching for all architectures (through static relocations). > > > > > > However, one could argue that this is more a [space] optimization than > > > anything else, so I am willing to park this discussion until support > > > for static calls has been merged, and proceed with something simpler. > > > > I'd suggest tabling it until static calls are merged. PeterZ just > > sent a new patchbomb for it anyway. > > > > As it turns out, static calls are a poor fit for this. Imagine an interface like > > poly1305_init(state) > poly1305_update(state, input) > poly1305_fina(state, digest) > > which can be implemented by different libraries. The problem is that > state is opaque, and so it is generally not guaranteed that a sequence > that was started using one implementation can be completed using > another one. > > Since the whole point is having a simple library interface, > complicating this with RCU hooks or other crazy plumbing to ensure > that no calls are in progress when you switch one out for another one, > I don't think static calls are suitable for this use case. > > > What I'm trying to get at here and apparently saying badly is that I > > want to avoid a situation where lsmod shows the arch module loaded but > > the arch code isn't actually executing. > > My goal here is to allow the generic library to be loaded with or > without the arch code, with the arch code always being used when it is > loaded. This is what I implemented using weak references, but it > requires a tweak in the module loader (two lines but not pretty). > Using weak references preserves the dependency order, since the > generic module will depend on the arch module (and up the refcount) it > any of its weak references were fulfilled by the arch module in > question. Using static calls will invert the dependency relation, > since the arch code will need to perform a static_call_update() to > make [users of] the generic library point to its code. How this works > with managing the module refcounts and unload order is an open > question afaict. Indeed. Dealing with unloading when static calls are in use may be messy. > > > Regardless of how everything > > gets wired up (static calls, weak refs, etc), the system's behavior > > should match the system's configuration, which means that we should > > not allow any improper order of loading things so that everything > > *appears* to be loaded but does not actually function. > > > > Yes. that is the whole point. > > > Saying "modprobe will do the right thing and let's not worry about > > silly admins using insmod directly" is not a good solution. > > Agreed. > > I have disregarded static calls and weak references for the time > being, and I will proceed with an implementation that uses neither. > The downside of this is that, e.g., we are forced to load the NEON > module on non-NEON capable hardware without calling any of its code, > but this is basically the Zinc situation only with the NEON and the > generic code living in different modules. Makes sense. It can always be improved after the initial implementation is merged.