Received: by 2002:a4f:b056:0:0:0:0:0 with SMTP id m22csp2666164ivi; Tue, 15 Sep 2020 16:09:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxYNQlMdGXuXGjbCkeDRYYJ/luXO6H3i/FP0PejooUntLJc2dCq17txeRXxdjg17eRfTuuV X-Received: by 2002:a17:906:d97b:: with SMTP id rp27mr23636456ejb.18.1600211345372; Tue, 15 Sep 2020 16:09:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600211345; cv=none; d=google.com; s=arc-20160816; b=ZSLBb4MTsjXqP6wp7uMmOnbZ4RSzQFMba5DS+FFRaMjODjSnWir//2IMl7wfj88gQI IuVU+kNcBTmH88ceDPA01bVXI3PQzS0wNwWw1JQUxyhxSfCSAEaYhIhdf4Eaad7O+WrX PPkFmCkm7DDkT9SI9rgTxBnf+Q8eug0yKUkVv96/Ib+NrLCaJEtfUplIpylcJdHt3VUh Qxtb//JAIAj4sjwXJh11dF6qf0B7KWRikc5gA1MhlHJ/E2Z+UfNnnp6aIyAwCrVZmiJ9 J0HJlQh5bGtXipRyFQrXzqWv9ql3ofaZZIL3Qt6IJaQPEfZPREXfP4Ux6JGvoe0f0oQW jjGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=8j+lblg1sV2zcZbQlE+z8kJXho9SmxIjdqx8+vh4bbk=; b=joeHy4YvQR6lCBrgF6gFioWoy1yG6hP2CN9v2d0ruzS/ehLccdaiDP+MJP9HPFq5zg JzvRqggN9OquOHGeSj+7Oh/ObDILT8zFFoqwIZNuwg3Nh60zBokUTSlp6NtPmLkXPaPe 7K7eLShAqWOogbJFKSYzl4tnDxd6VWxw8fAe7DFeTncx8+fB+hNmHxWZt9wyqkRW9IiS wzfJ0dO2DrYEwLc2Nox3XV7dmY6rA9TWVHnACLaLCxypEj7glwKsGJ/paCWDOikJ0L/G sk5H6DL4GXFuBJs17Ad480mdLfEzo24QOGS35riKRGAY2S/RRcIyft1OD+NmQj4KwTsM KOSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zs+wxazN; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x24si10239119eju.477.2020.09.15.16.08.43; Tue, 15 Sep 2020 16:09:05 -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=@linaro.org header.s=google header.b=zs+wxazN; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727381AbgIOXG6 (ORCPT + 99 others); Tue, 15 Sep 2020 19:06:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727160AbgIOOr7 (ORCPT ); Tue, 15 Sep 2020 10:47:59 -0400 Received: from mail-ej1-x642.google.com (mail-ej1-x642.google.com [IPv6:2a00:1450:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 673E4C061220 for ; Tue, 15 Sep 2020 06:54:39 -0700 (PDT) Received: by mail-ej1-x642.google.com with SMTP id lo4so5177273ejb.8 for ; Tue, 15 Sep 2020 06:54:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=8j+lblg1sV2zcZbQlE+z8kJXho9SmxIjdqx8+vh4bbk=; b=zs+wxazNDlzCncy6nDFpBVAZ1RQDAAaDIp4sgRNsL1wLq+A775Sonp1E73R0J25AVP wy+SnCoRFJgQhHKHZxHVMgMyOAfT7swYrS/2Rkpjo9PLimRa4BF4VyHBmitwaNFAfcbz PkB8vA6NoDvNsOx1u/zLDI1sXyOsnQ5gSnY6qSzqhMoaisXFVrFuMrFvjpWZULthxOZL yBYcG7YdLvAu7bvVsIqNSivaWKPF3tEQyn6nXD0JOghQw6y+WAMp7D/93G/lWsu9zjwy c9O1KIyEwffdY/suauSk9oektYPK33FRkuqorQX/7ozLl40NPRjHfLGr3LLDJQMrwpek Fhyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=8j+lblg1sV2zcZbQlE+z8kJXho9SmxIjdqx8+vh4bbk=; b=ci4Mfn38hT+JipxAEdpYYXVAAQdeY5h9TmfINuUj7+emY+qkypUWyFVvhGOvQcGZ0C abHWQ0GdqL6qVd/DLrKf4AfobROmqApCYUSdA223FrIlPTdm9ze7pwrr+rLH6YCrM2yE ZKBiS5G/u65aMNlqO/HW0jbgJ1ISPNkQeqUo/bZYm9UksFzyj6KRyKlUhU4ZvvmZ9vuk 1ycx9ZE37z3nRuK1s7ywjpLf37K4xM3Ob8YyHw6Q+PTf6XTt40tNwRMMg4hxjM+C4ff8 JVXR/GUE3Osr40dDe8YKfz3SLnS2eQp//I/q6YET4rQhqdWX1N1NkK60RHM3ZcTwKVRP 2Xlg== X-Gm-Message-State: AOAM531Xiq6uTXOY1y3JHvfxQrgV2KlSMh/Nd8WvSElrFBfAhNK/2K7s f1bKGPdsvmf38fHA+apR2YyuaQ== X-Received: by 2002:a17:907:417c:: with SMTP id oe20mr19627489ejb.322.1600178078059; Tue, 15 Sep 2020 06:54:38 -0700 (PDT) Received: from myrica ([2001:1715:4e26:a7e0:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id ef3sm7912845ejb.114.2020.09.15.06.54.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Sep 2020 06:54:37 -0700 (PDT) Date: Tue, 15 Sep 2020 15:54:19 +0200 From: Jean-Philippe Brucker To: Will Deacon Cc: Ilias Apalodimas , bpf@vger.kernel.org, ardb@kernel.org, naresh.kamboju@linaro.org, Jiri Olsa , Yauheni Kaliuta , Daniel Borkmann , Alexei Starovoitov , Zi Shen Lim , Catalin Marinas , Martin KaFai Lau , Song Liu , Yonghong Song , Andrii Nakryiko , John Fastabend , KP Singh , "David S. Miller" , Jakub Kicinski , Jesper Dangaard Brouer , netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] arm64: bpf: Fix branch offset in JIT Message-ID: <20200915135419.GB1748187@myrica> References: <20200914160355.19179-1-ilias.apalodimas@linaro.org> <20200915131102.GA26439@willie-the-truck> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200915131102.GA26439@willie-the-truck> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 15, 2020 at 02:11:03PM +0100, Will Deacon wrote: > > ret = build_insn(insn, ctx, extra_pass); > > if (ret > 0) { > > i++; > > if (ctx->image == NULL) > > - ctx->offset[i] = ctx->idx; > > + ctx->offset[i] = ctx->offset[i - 1]; > > Does it matter that we set the offset for both halves of a 16-byte BPF > instruction? I think that's a change in behaviour here. After testing this patch a bit, I think setting only the first slot should be sufficient, and we can drop these two lines. It does make a minor difference, because although the BPF verifier normally rejects a program that jumps into the middle of a 16-byte instruction, it can validate it in some cases: BPF_LD_IMM64(BPF_REG_0, 2) // 16-byte immediate load BPF_JMP_IMM(BPF_JLE, BPF_REG_0, 1, -2) // If r0 <= 1, branch to BPF_EXIT_INSN() // the middle of the insn The verifier detects that the condition is always false and doesn't follow the branch, hands the program to the JIT. So if we don't set the second slot, then we generate an invalid branch offset. But that doesn't really matter as the branch is never taken. Thanks, Jean