Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp711945imm; Fri, 5 Oct 2018 10:26:55 -0700 (PDT) X-Google-Smtp-Source: ACcGV61i694azirTheSLVHHrRvEI+3JHeHBHITl2rgHwfvu1zs9AxDKBPBg8ZpECyR0UQlmq2W8l X-Received: by 2002:a63:982:: with SMTP id 124-v6mr11176522pgj.80.1538760415903; Fri, 05 Oct 2018 10:26:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538760415; cv=none; d=google.com; s=arc-20160816; b=FNuer7d7+7oSYfckNyr6C6WJ1Hg5QiP7aR7VOxi+XnRdSJFly9+SiMsGiPtYLRXl2Z p1KuQEm5uqW4uNr4kC7cmr4xXNT7zWmTbiBNCS0tHJdHn32hm17FOiCWOhSA3qO0Ixcs ANPeVkkxLVa7I3buc5KiuJEXHJyhUajhKBpEAODpOwa0ojDsAuiWyI2tmIGLQGRhvp1L mWEifFsepmgVHTRlcEzh49AM/R5c+Gbm4rWhVNcX3g+kJKgFLde0dz7p5XRtscvizon/ 9EcQFGTJwAigqHp1sHvCCVxCV9cy3hRe+2UrFzT62sxTZYJoBTtxe5z8JQHt4l/gLzQ/ a8wg== 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=GkNZvFddRQ2RTLbh1pRS9AK31o9IIZUlAclTsG//gn8=; b=JTn+QRqVZ8bhwsf1pgoxa6RsBWvpzJWAy/+czUJ05IsFL0PUANNjC/mqNk4Iu/kggj lmpHEMs5pH22uSBTyQuZ0tnSikeNYUsT9cgJnj5F2V1PZEAe+7maeVOSmBNDYt/aKPdN AhqeqQbfxCWJRli4b7Ig7Wz2zBxlxzkyyO3UGw2UnwraiBhS41hrQ0NNxd9pjMiRFNTr F7KDUt8RPuw/j7rSBl4vJpyglq6+9pbhA4nJp0yPnz4UlDJQz7uhv8c0PKUM2mSBFsh/ v8IbkMGW3Ahr/lZPa8Y8cefsgIjbTvkwDdhwZmLImNhnrn1XWOtae3T4PpFCxYDKKTT1 KVbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ogbD5313; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z70-v6si8829011pfi.214.2018.10.05.10.26.40; Fri, 05 Oct 2018 10:26:55 -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=@kernel.org header.s=default header.b=ogbD5313; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728729AbeJFA0E (ORCPT + 99 others); Fri, 5 Oct 2018 20:26:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:49376 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727941AbeJFA0D (ORCPT ); Fri, 5 Oct 2018 20:26:03 -0400 Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) (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 DB5DB2147D for ; Fri, 5 Oct 2018 17:26:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1538760382; bh=BtUlJXPxzROTLh5ruMHdsHXX1cniMwLqNEy6YBOxFLs=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=ogbD53136bMyzbUp+AM5lY86M5wI4GC/2eqIE5nF/p9BR8+YU3qEI24enlHUImd+q 9VqU9PDHVrk6rVGLNNpQkQIEB+qE3rHEsqj7byjxw4Uaujs97vuzCA6VbNiMjafP3Y kkIGCzpCEFlTKHOQpIFhcZWVYqWLvVc6+x7Hqh00= Received: by mail-wr1-f54.google.com with SMTP id e4-v6so14364115wrs.0 for ; Fri, 05 Oct 2018 10:26:21 -0700 (PDT) X-Gm-Message-State: ABuFfohq6CKEQBBiFuMFdL8TJUPqD28x0gQ8o84imGdWXYdK/F06OrfM 36e6jAQGiFnKQ8PdQzetRIjZpeLcIZcMaIW0Z6hANw== X-Received: by 2002:adf:82e3:: with SMTP id 90-v6mr8597642wrc.131.1538760380286; Fri, 05 Oct 2018 10:26:20 -0700 (PDT) MIME-Version: 1.0 References: <20181005081333.15018-1-ard.biesheuvel@linaro.org> <20181005133705.GA4588@zx2c4.com> In-Reply-To: From: Andy Lutomirski Date: Fri, 5 Oct 2018 10:26:08 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC PATCH 0/9] patchable function pointers for pluggable crypto routines To: Ard Biesheuvel Cc: "Jason A. Donenfeld" , LKML , Eric Biggers , Samuel Neves , Andrew Lutomirski , Arnd Bergmann , Herbert Xu , "David S. Miller" , Catalin Marinas , Will Deacon , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Thomas Gleixner , Ingo Molnar , Kees Cook , "Martin K. Petersen" , Greg KH , Andrew Morton , Richard Weinberger , Peter Zijlstra , Linux Crypto Mailing List , linux-arm-kernel , linuxppc-dev 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 Fri, Oct 5, 2018 at 10:15 AM Ard Biesheuvel wrote: > > On 5 October 2018 at 15:37, Jason A. Donenfeld wrote: > ... > > Therefore, I think this patch goes in exactly the wrong direction. I > > mean, if you want to introduce dynamic patching as a means for making > > the crypto API's dynamic dispatch stuff not as slow in a post-spectre > > world, sure, go for it; that may very well be a good idea. But > > presenting it as an alternative to Zinc very widely misses the point and > > serves to prolong a series of bad design choices, which are now able to > > be rectified by putting energy into Zinc instead. > > > > This series has nothing to do with dynamic dispatch: the call sites > call crypto functions using ordinary function calls (although my > example uses CRC-T10DIF), and these calls are redirected via what is > essentially a PLT entry, so that we can supsersede those routines at > runtime. If you really want to do it PLT-style, then just do: extern void whatever_func(args); Call it like: whatever_func(args here); And rig up something to emit asm like: GLOBAL(whatever_func) jmpq default_whatever_func ENDPROC(whatever_func) Architectures without support can instead do: void whatever_func(args) { READ_ONCE(patchable_function_struct_for_whatever_func->ptr)(args); } and patch the asm function for basic support. It will be slower than necessary, but maybe the relocation trick could be used on top of this to redirect the call to whatever_func directly to the target for architectures that want to squeeze out the last bit of performance. This might actually be the best of all worlds: easy implementation on all architectures, no inline asm, and the totally non-magical version works with okay performance. (Is this what your code is doing? I admit I didn't follow all the way through all the macros.)