From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 316A0C433F5 for ; Thu, 14 Oct 2021 09:50:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 16B33610CF for ; Thu, 14 Oct 2021 09:50:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230081AbhJNJwf (ORCPT ); Thu, 14 Oct 2021 05:52:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229468AbhJNJwe (ORCPT ); Thu, 14 Oct 2021 05:52:34 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43D92C061570 for ; Thu, 14 Oct 2021 02:50:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=C5nkd01YLTlf7v89BaQCa2Vx27CtYGym5ql5OHtCf9E=; b=L+Hh+/Pkw+yWZryYkDXLimrEwJ EUeCh1j4sbu1Pf0zM5gWWF+gBr7LT3ySXqHYHUDdOva8+LBmDc3qDMFMRFra5eVEB8ej2x9asa/bJ x+0a8RyksElKfDV1OLMZBcKYW7vlLIQJEFtU1Qsf4RrIE0HxdAuQMFic2iyxZboYbo2yUiRjy/2tb d/KTdLDkSLDQ+QR0G1R+Rife4gl+D9Dhz8XKy/ibTSoNRXpy1SSIJU22PGrMLET8Pm3d1rDG1uvZ3 JPJ9FIrTLkfJg0uDtx9T5+gVsgOXADoLZqNL/z376AoLarbUQQjCwlXD3iVCouG58AQMR75WX0nu7 vYiBBINw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1maxM2-008EWc-Pc; Thu, 14 Oct 2021 09:49:05 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id EC1CA3001C0; Thu, 14 Oct 2021 11:48:50 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id D3FD82D6E98E3; Thu, 14 Oct 2021 11:48:50 +0200 (CEST) Date: Thu, 14 Oct 2021 11:48:50 +0200 From: Peter Zijlstra To: Josh Poimboeuf Cc: x86@kernel.org, andrew.cooper3@citrix.com, linux-kernel@vger.kernel.org, alexei.starovoitov@gmail.com, ndesaulniers@google.com Subject: Re: [PATCH 9/9] bpf,x86: Respect X86_FEATURE_RETPOLINE* Message-ID: References: <20211013122217.304265366@infradead.org> <20211013123645.706163435@infradead.org> <20211013210605.bz6l7o5xzik5ckga@treble> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 14, 2021 at 11:46:11AM +0200, Peter Zijlstra wrote: > --- a/arch/x86/net/bpf_jit_comp.c > +++ b/arch/x86/net/bpf_jit_comp.c > @@ -396,6 +396,37 @@ static int get_pop_bytes(bool *callee_re > return bytes; > } > > +#define EMIT_LFENCE() EMIT3(0x0F, 0xAE, 0xE8) > + > +#ifdef CONFIG_RETPOLINE > +#define INDIRECT_SIZE (5) Bah, that should be: #define INDIRECT_SIZE (2 + 3*cpu_feature_enabled(X86_FEATURE_RETPOLINE)) > +#else > +#define INDIRECT_SIZE (2) > +#endif > + > +static void emit_indirect_jump(u8 **pprog, int reg, u8 *ip) > +{ > + static const void *reg_thunk[] = { > +#undef GEN > +#define GEN(reg) __x86_indirect_thunk_ ## reg, > +#include > + }; > + > + u8 *prog = *pprog; > + > +#ifdef CONFIG_RETPOLINE > + if (cpu_feature_enabled(X86_FEATURE_RETPOLINE_AMD)) { > + EMIT_LFENCE(); > + EMIT2(0xFF, 0xE0 + reg); > + } else if (cpu_feature_enabled(X86_FEATURE_RETPOLINE)) { > + emit_jump(&prog, reg_thunk[reg], ip); > + } else > +#endif > + EMIT2(0xFF, 0xE0 + reg); > + > + *pprog = prog; > +}