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 X-Spam-Level: X-Spam-Status: No, score=-6.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 42A6CC433E2 for ; Tue, 15 Sep 2020 13:56:05 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D63B020738 for ; Tue, 15 Sep 2020 13:56:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="lqXe74P9"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="zs+wxazN" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D63B020738 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=thBLR1Khrxbu7D0X5TI+mchCTmL8agl3MjPuOturT8s=; b=lqXe74P9wZWWXVF+2H5Mdd9+W 1cvHCV9g72ejAyEieqJQ/UZJ6XluJZCZLR4d7Z1zIvX1vRsD2qIXsShG+2gMhIZ8bgjMdXP9xFqz6 LP49Yf5yLNe4BsWjqgrMu0w94FKDZFlR5kj+YHXqCUxEnjgVpgO8qktHLJh8bp1g9w7+rkN90JuJH 87o0Or5E0p01dPb5yan4a3x4tjDLfianjdVEPe9++fqUn20UGuZ11GVrE7GpH/vRs8p4BjKZJ6LX9 VfgWlPBe2An+YwK3SVQwI/oSJ7MEc2hXWedXDg6XCuKjlFwSXj/E0do+cYeWQXhe/SjtspZWBZgxy abf3EoHWw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kIBPv-0001wI-E5; Tue, 15 Sep 2020 13:54:43 +0000 Received: from mail-ej1-x643.google.com ([2a00:1450:4864:20::643]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kIBPs-0001vJ-Ve for linux-arm-kernel@lists.infradead.org; Tue, 15 Sep 2020 13:54:41 +0000 Received: by mail-ej1-x643.google.com with SMTP id j11so5267731ejk.0 for ; Tue, 15 Sep 2020 06:54:38 -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=V0f+7jYc1VZ0xT9gf9lsEJVLz0D0kjFVwKaPphgijL/WklPPpSiZaZE9r7X7d1RWJS vuX0GbYl1VMRX4MygMPAV4RNJiR/Moz5m2V1QCyo4KYkr/oOvVjruGSR4lI9G43wW6ZZ ESzWnwT2I0ZaI3NVZpVJ3Vq3Y7oNKMqVw0d+bRL3I0AJZNZ/3xGILq0uUlhkzTaTnJYb 7pC+4cAIYk8+Gjkrna62NKYUhpn9lnd6ZVZQF+b1q/gycp7/fUdHiHgKDyoj9dlLHg2q fFAC1pvZEijKMTPsOmWCWpDAaS8S850qHB4JeZygffsaIjTHCg4Hp7qKvzEliMFjwZXZ xs/g== X-Gm-Message-State: AOAM531mQoDPYKQ7i10vrsJZFuItEsrRpNdQVaAfy3ezwH8bgSXEJSeZ ke8WZd4ZwW/5Uhmlhn8rGnenhw== X-Google-Smtp-Source: ABdhPJzqkOj32ZaO+3P5Qf1khy2XosqxXmtjomHSAQuuF7ae+SHvA1glksbWQzSbDtjFWs0zPPHdnw== 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 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-Disposition: inline In-Reply-To: <20200915131102.GA26439@willie-the-truck> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200915_095441_032322_089A75E2 X-CRM114-Status: GOOD ( 15.52 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Song Liu , Zi Shen Lim , Alexei Starovoitov , ardb@kernel.org, Daniel Borkmann , naresh.kamboju@linaro.org, John Fastabend , Catalin Marinas , Jakub Kicinski , Andrii Nakryiko , Jesper Dangaard Brouer , Yonghong Song , KP Singh , linux-arm-kernel@lists.infradead.org, Yauheni Kaliuta , netdev@vger.kernel.org, Ilias Apalodimas , linux-kernel@vger.kernel.org, "David S. Miller" , Jiri Olsa , bpf@vger.kernel.org, Martin KaFai Lau Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel