Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp713937imm; Fri, 5 Oct 2018 10:28:56 -0700 (PDT) X-Google-Smtp-Source: ACcGV602C7J8FIWyhSd/s7gYOPQPVGEa7+ZPDCCy+GHlUnxUiDnlcC1mwA78tMwM07QruG1xr115 X-Received: by 2002:a62:1655:: with SMTP id 82-v6mr12840247pfw.11.1538760536526; Fri, 05 Oct 2018 10:28:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538760536; cv=none; d=google.com; s=arc-20160816; b=eDVtImHlLyazh5c92ICoo5T5OivjyduX6KmH+hCB3NQEb7VoPkGzyPvA8tlnMjzA/p LN3ohv8aMi+Iiau6/vBG13nV03wOdQgxf0G9AI8/G5bp5dYJQ2tMGM4L2+KNaRDLUEb1 4KdXOZLk+z0o1lh/N/vRm1qmB1FbnH6dEfJkxj7vYf+7Fc+aRE/2Hko1c+0+O45waSKs s7xFt0KTGciDiHG2iEZhG6RcW+n3kWhGXzd7Mjh5xpcfA2Jd0isqvfj+m96DDzSJETR/ pBUKiTUyLb80gWMjpeY6KbVVxdm8gmopu0IKhRnXdRIERnKAXXeh+06jKFuGT7T3ae2h 5SzA== 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 :references:in-reply-to:mime-version:dkim-signature; bh=KeuwEIGLwIhFnp/zlZGqWtiTYKkJEMFiADynXUfL25E=; b=PEJsYXe0TiAhK6iEN5FbiYMx6jJhLhNgMkRuP9dV6HPRPVt/iTZlGPLQSYku6Zk1Z/ GhqRwoMNkPTFDorl0wRzRHYwVhtD7JqwZlMM+sM45xbgxnaMDNBlb7+HVuEUxcsLV9Ks bQIrauxYrVAggKvctZ8EpdSJCGMVoi2u3MW8jJyy29rB1IsugGSfRzckbdI5QYNai7lC SEk0C/7h+rfNMs/POrMMEJHe0AyBuXW9kEvubH0JgfbdgI6NBk6/UDfbWrBO7q+u3zHM mw4s8F+ZXVwD8ViABiS4+h3MdBGHhvQdM9DBZbhQw3uFbsbKkFKnzWFhRh3S42eLd/SM jv9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SUJiV1sb; 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 z33-v6si9400268plb.169.2018.10.05.10.28.41; Fri, 05 Oct 2018 10:28:56 -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=SUJiV1sb; 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 S1728819AbeJFA1z (ORCPT + 99 others); Fri, 5 Oct 2018 20:27:55 -0400 Received: from mail-it1-f194.google.com ([209.85.166.194]:36320 "EHLO mail-it1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728361AbeJFA1z (ORCPT ); Fri, 5 Oct 2018 20:27:55 -0400 Received: by mail-it1-f194.google.com with SMTP id c85-v6so3817008itd.1 for ; Fri, 05 Oct 2018 10:28:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=KeuwEIGLwIhFnp/zlZGqWtiTYKkJEMFiADynXUfL25E=; b=SUJiV1sbbTKmPc9HPG1slNKP6p5baYgdH3XkIvNxgRs4ZyKISmE9fT6fEB0CJTl/S5 0ubY+Idg3BztaD8swEnk88xueIApSBYO2WkK04eHlOC81j2jOl1U1DuyQl8yMLQROAJy XUfuCNIMkrwNy9Z2/fTdHg1vmErnsGL1+zH60= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=KeuwEIGLwIhFnp/zlZGqWtiTYKkJEMFiADynXUfL25E=; b=kxyZ2OqMqb1UH3ag5JMgUoPF7Q1RzX1pHIL5pK6U9J5Twyisuw02kBzUQwyjExpGKu igNLbIeG22IPS8n8wGgTepFO8Kun8lJXsJf6TPxXGkIWcG5JCFFca1q3mHk90pIcdx9n 6QjyB5cC3o/PImzXBvBjCXbiJOLewHyhIPK/20J8dQdLBruwLLeCCTwiPIAv5/CmuLZK rU3np73m9bWuITjKATk645++gOK6v04wh1ZUwZH/rXRHhTewyhEmJIi+wmBsbdZYajak 9KsB03ce5TWyNKwZwHS2c95mPz6YALDWhZvWqvQ/fAmpekdD7aivcLBhgidVrxnmuiUo IanA== X-Gm-Message-State: ABuFfohZAogCVWh1gBy/P27yC7dOL8wH2dc88MyHL+tLeWbpm2FdXRZs aDKcOTeQMkd3he1RiKFVDbSGU5trxIKBmvGsgh7iq1wD X-Received: by 2002:a24:a10b:: with SMTP id y11-v6mr5209852ite.148.1538760492849; Fri, 05 Oct 2018 10:28:12 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a6b:5910:0:0:0:0:0 with HTTP; Fri, 5 Oct 2018 10:28:12 -0700 (PDT) In-Reply-To: References: <20181005081333.15018-1-ard.biesheuvel@linaro.org> <20181005133705.GA4588@zx2c4.com> From: Ard Biesheuvel Date: Fri, 5 Oct 2018 19:28:12 +0200 Message-ID: Subject: Re: [RFC PATCH 0/9] patchable function pointers for pluggable crypto routines To: Andy Lutomirski Cc: "Jason A. Donenfeld" , LKML , Eric Biggers , Samuel Neves , 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 5 October 2018 at 19:26, Andy Lutomirski wrote: > 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.) Basically