Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp4420085ybp; Mon, 7 Oct 2019 08:12:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqwWWyqlt23Fxpf6An/RyjWrubbqgY8fs8Sl43AyP2ypw6MTriOnBL0snaJn6PgunPMgRAaX X-Received: by 2002:a50:eb44:: with SMTP id z4mr28876584edp.207.1570461172356; Mon, 07 Oct 2019 08:12:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570461172; cv=none; d=google.com; s=arc-20160816; b=WiDUnfaH3JJlJS4BkqyOT70YeWg/Wh9yPcR/eQqOdOeOz3nnyM0+3F7VX38i+NFFkR J+rM2nKOrxbGI82evBHELH6hBE5mzXoEvQLa+hm4Q4zywaRAq0vdMrszhPxiqgVib9uw zdPuadOKTtOC2p0BOupby0/7IZaOKhu2CFC7lEVen5q+2vN+7iPAz6gP7F2Vx/mkvEQp QLwm2vuWVY0R4lPwYpqiYC1cRjIVHLY2oB+fonSkySE1U/ACU2vzXnj3Sgfdh7LkUg3w IyX737iCyG+hEqpCH2TqaLA6p+q3tnytpCQfXpJsvbN7pbBPDWlKVvjhG/dN5XPCPPxd 6dbQ== 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=X1p0OfMCa1ZqMu/HdbF1dLDmeHh9sQqaQGFSoVRKm5g=; b=dnDh9gb+TCd2AvSQWsgCgP8zQzVVDlkk2+c5Y/D77gSTGWwSPGzG7G8vtqtG5+3IFq N7Lo+TrGHH3GCT0/BKYkkeeUuRggB8Cd/C/3dOhUDPfJaO/nB6jBRqcwItlbHCSgseyB mhMwASiTL+P4spygQzVjQMPuM+UIH3WyeVfcJ7lDzfk/s1ajwPcgNnKO0e/X4IgfLrpK QReIi2ya3LFs3MzdACG7FsupPQ63bOU08HSzDvDmibJ/4TN27+sXvy5emrnapOPyVrSX s/UnFkM47/w7TyLlD6U7c2LMWXBRELYce3xVgPW4oR6Ragr39lHL0ioQ54PqtgQ0UgvZ en4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QTaJ84Wi; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b22si8920303eda.194.2019.10.07.08.12.26; Mon, 07 Oct 2019 08:12:52 -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=@linaro.org header.s=google header.b=QTaJ84Wi; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727490AbfJGPMZ (ORCPT + 99 others); Mon, 7 Oct 2019 11:12:25 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:40742 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726334AbfJGPMY (ORCPT ); Mon, 7 Oct 2019 11:12:24 -0400 Received: by mail-wr1-f68.google.com with SMTP id h4so7043849wrv.7 for ; Mon, 07 Oct 2019 08:12:22 -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=X1p0OfMCa1ZqMu/HdbF1dLDmeHh9sQqaQGFSoVRKm5g=; b=QTaJ84Wivj7ViFOasFVFZ2dj3Ot1OiE2g5DXLSCzVjsUMWFY2H0dAS45UW9hWWVwzL Q0hHXHU/1YTE+ug+myO81k09ekHkqNCxxnTX32Z7qwMNT7OKBolffIXGjsBCZ5NFwUJj igamA4/udJcnx3K8Ziup7t2I+Ro8dcH8goRio8o1oHq5h4csLYQi+SKLeb6dthcKdX5t E8a5xomZja3uh8K4VQmQvTVrkVoB8MuRt1XRQKRVRLFYLKWYcVW34r5jPPZV9CXPfyic mN48uxmspZIBO4U+XImplR64xRTIF66ofLHuTRF3rByJ5r/23qTyebnTrmYRp2HAPWAt 6ugQ== 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=X1p0OfMCa1ZqMu/HdbF1dLDmeHh9sQqaQGFSoVRKm5g=; b=h9bQir0HZyCtZMjNK66k9UOFVdAaD3hpudS118M/ngh50NWPUPox61gpRc41kL6r3Y Alip6pwXWsMZ3vTWs/9wIlJYPjg5Sx85IruaQZwjGa37ABFDpDpzAiSyigZWmXWNnt80 XMUu1w4bAQjgxpinJ1+JBawRdy2yf6pKd09v9Wb1xPrjcFbYQeVV4fuIB0XS1zMFO4Zn jF6piFvb7vbaet5m4rtDYZIRwqgl0Y8CET+1EoUTjK1GEDp6e3+IwkBUQNlXHczujIc0 92NJsHrf4ysoDlhZVH+WBi2dPe/TI8UN7beENP+8Vlmawv+u4lnS9NEwY0yNh/yQN8Wd 5ubg== X-Gm-Message-State: APjAAAUqyHe9t5iZu03UXyAHYy3XR9EkEPqsU/FbVdID8n8cghSHLZAS 7bg1zPCdLtbqI+gnm6voabkHCuilcZajdylsjc+zItCq6kkoaw== X-Received: by 2002:adf:fb11:: with SMTP id c17mr24339838wrr.0.1570461141884; Mon, 07 Oct 2019 08:12:21 -0700 (PDT) MIME-Version: 1.0 References: <04D32F59-34D4-4EBF-80E3-69088D14C5D8@amacapital.net> In-Reply-To: From: Ard Biesheuvel Date: Mon, 7 Oct 2019 17:12:10 +0200 Message-ID: Subject: Re: [PATCH v2 00/20] crypto: crypto API library interfaces for WireGuard To: Andy Lutomirski 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, 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. > 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.