Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1696694pxb; Wed, 20 Oct 2021 09:59:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzw84vhuC68tFTUFyR00e7aF9EwiOoOPkkVNzTlMkNM0UAqaLkn53D2R1iKRg/HwtdjBjVF X-Received: by 2002:a05:6402:14d5:: with SMTP id f21mr190520edx.268.1634749154615; Wed, 20 Oct 2021 09:59:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634749154; cv=none; d=google.com; s=arc-20160816; b=Rsj7MxgMULopiNCgshnRg+Jizjb2RVFvTugMw0dxZELW355PhyJXlNkkVo3fA1zgrO DuxcrVTlwj4V7//YdYs31SB/enLWAYwCQjZ1ak2a9P6sC7Qa+dOnLe0RK35CPkucl22/ GtNbbShvuhTXfGpFjuXI5idAFT06kyb5nH2hZYRsxUiY90s+pquPCSY6PVodCHl2Ig26 DqQ0uzu7wIeymEKM77e2kym0FI2ibYnFaAYelK1bFcIUQeTvBdMH8SDAKJb/2IeyrYkS 9iV5pqJj2wjBmMpA2fXNtQH5dp1wg7fhukiYBkA9SpObUKbrNHt4CCi/pihMDxH4lcik dpgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=4wSvmizuMO2m4fT0eDjoslMhMT4OHvvAsI38HO+Btc8=; b=X25eYLHnjW6rNMlSb8jbZ26bWcGFu6u8DFOlRQxeifGNp8R6/DGbToNddQ0tdoYQ89 lNggYl+LDuT2hIpVtSq6VdAGCLY4OlLfVD3qg+q16CSLLhci7zUkyb5LgtwmYuwuhiBA 17Ra9E/fqMIdmqX0/By0xsHre5G7G5kILp/vSevGYEyvK3CWyU9gz1/09JP4OC4DCp/I xDfBYmhCdeDFi8RkQMGouAuybm6RzQ1iItPgb/xASISU/HpXNfCdGGCMLxDzsl1ggc/x 2+W5TQvG56PyCsR9ttX2J0B0wlX5VMtJV8+vU2X2Xr4NtXOtEdcHzpob9enA2bmLFs0C gH9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=GRfVsFo4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id eb14si5912276edb.415.2021.10.20.09.58.47; Wed, 20 Oct 2021 09:59:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=GRfVsFo4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230233AbhJTQ7S (ORCPT + 99 others); Wed, 20 Oct 2021 12:59:18 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:50903 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229771AbhJTQ7P (ORCPT ); Wed, 20 Oct 2021 12:59:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1634749021; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=4wSvmizuMO2m4fT0eDjoslMhMT4OHvvAsI38HO+Btc8=; b=GRfVsFo40gTsTcmJ4o/7fOVLMhLi1vZpC5iu5rvAvneOWjOX+440WGA5h/3vIvkg2VZbJ3 YCUsOK30w98OGjERNuz5VqVlqpVwfdN8wVRxngCOWNxHdHGOfiM4vhmV0+tyOFQamW8n3y E9FDw/loTC/g/SoXUB/FHgEc2j0n1Fw= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-200-9jFM-v80OVSEvlA5Jv-m_A-1; Wed, 20 Oct 2021 12:56:59 -0400 X-MC-Unique: 9jFM-v80OVSEvlA5Jv-m_A-1 Received: by mail-qv1-f71.google.com with SMTP id q9-20020ad45749000000b00382b7c83aa1so3276009qvx.11 for ; Wed, 20 Oct 2021 09:56:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=4wSvmizuMO2m4fT0eDjoslMhMT4OHvvAsI38HO+Btc8=; b=e5Lsedl5wyAPdKL7cdNLptuc07PnTjwEMQvvp9skw8wJh8CHPf5gQ6ef0wIZfBQfz4 /WHWmC0fNo6+b85zBlpCt8MtT15Vs6jvCnrqt+6MlfLaEJfo7IDQG3IGEccc6dUd4WBl qSIyOEyJFAtxR5b76cnskk/RofAcegE+qFx9M2JNcpCwAn3GzwTUrXmsGuQ7PAMvCtme F9LfaJcT1zd0LEbVXIEyw7y3wF2vbpvR7AKhQuugGI4zunaATP1CY8IOI8kKonxqy23K sr1N1ighxRMjLPUa83JA2JjH+KAY9FS6g+oBzjiLAJIt6R4V8fgQ9SmwSTpGijw+nbpp 71bg== X-Gm-Message-State: AOAM532KCMjc2Xwnv16ncWN2qk7ENGuKhu1ErJ4WI/Q+7BQ45bWtD2gC 3OAUWx/JZs8X/mjIqRFqKKYsQWgk1USGRzFzcDqo3xQzdC9gBGUPiGqUl9tz9pkUYXSDDMTeIi2 KXC7ggTU7phUt0xTTgqzM0pQA X-Received: by 2002:a37:94c1:: with SMTP id w184mr189648qkd.103.1634749019196; Wed, 20 Oct 2021 09:56:59 -0700 (PDT) X-Received: by 2002:a37:94c1:: with SMTP id w184mr189627qkd.103.1634749018955; Wed, 20 Oct 2021 09:56:58 -0700 (PDT) Received: from treble ([2600:1700:6e32:6c00::15]) by smtp.gmail.com with ESMTPSA id 101sm1179629qta.17.2021.10.20.09.56.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Oct 2021 09:56:58 -0700 (PDT) Date: Wed, 20 Oct 2021 09:56:55 -0700 From: Josh Poimboeuf To: Peter Zijlstra Cc: x86@kernel.org, andrew.cooper3@citrix.com, linux-kernel@vger.kernel.org, alexei.starovoitov@gmail.com, ndesaulniers@google.com Subject: Re: [PATCH v2 14/14] bpf,x86: Respect X86_FEATURE_RETPOLINE* Message-ID: <20211020165655.632slp4ujsajis4j@treble> References: <20211020104442.021802560@infradead.org> <20211020105843.345016338@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 20, 2021 at 01:09:51PM +0200, Peter Zijlstra wrote: > Alexei; could the above not be further improved with something like the > below? > > Despite several hours trying and Song helping, I can't seem to run > anything bpf, that stuff is cursed. So I've no idea if the below > actually works, but it seems reasonable. The below fix gets it to run with test_verififer. I do like it, it does seem less fiddly and more robust against future changes, though it probably needs a comment for 'out_label' clarifying it only works because this function is always called at least twice for a given bpf_tail_call emission. --- diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c index 08f32c9fceaa..c9230c5bbca5 100644 --- a/arch/x86/net/bpf_jit_comp.c +++ b/arch/x86/net/bpf_jit_comp.c @@ -457,7 +457,7 @@ static void emit_bpf_tail_call_indirect(u8 **pprog, bool *callee_regs_used, EMIT3(0x39, 0x56, /* cmp dword ptr [rsi + 16], edx */ offsetof(struct bpf_array, map.max_entries)); - offset = out_label - (prog - start) + 2; + offset = out_label - (prog - start + 2); EMIT2(X86_JBE, offset); /* jbe out */ /* @@ -467,7 +467,7 @@ static void emit_bpf_tail_call_indirect(u8 **pprog, bool *callee_regs_used, EMIT2_off32(0x8B, 0x85, tcc_off); /* mov eax, dword ptr [rbp - tcc_off] */ EMIT3(0x83, 0xF8, MAX_TAIL_CALL_CNT); /* cmp eax, MAX_TAIL_CALL_CNT */ - offset = out_label - (prog - start) + 2; + offset = out_label - (prog - start + 2); EMIT2(X86_JA, offset); /* ja out */ EMIT3(0x83, 0xC0, 0x01); /* add eax, 1 */ EMIT2_off32(0x89, 0x85, tcc_off); /* mov dword ptr [rbp - tcc_off], eax */ @@ -482,7 +482,7 @@ static void emit_bpf_tail_call_indirect(u8 **pprog, bool *callee_regs_used, */ EMIT3(0x48, 0x85, 0xC9); /* test rcx,rcx */ - offset = out_label - (prog - start) + 2; + offset = out_label - (prog - start + 2); EMIT2(X86_JE, offset); /* je out */ *pprog = prog;