Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp890051pxb; Wed, 27 Oct 2021 14:33:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxfRlRpMcQhw+yWP06J4kGigNp+8RRlHcK6whpQ0ju85eX3j/9+qEegMQJkuDh3DbT7+7Vc X-Received: by 2002:a50:e183:: with SMTP id k3mr576870edl.22.1635370382721; Wed, 27 Oct 2021 14:33:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635370382; cv=none; d=google.com; s=arc-20160816; b=qrqwbSEJidqP1BVmzocq5gNArpWc/7Ew+JiKTlYKzS56kp7Xp4lsnprooCtr2vg8tB V0yvpioo/syhx1qGq7QoAv25DKuVGn1kkeYsMG5asTUJ/mrwAosCbtiKj90vj8J9Bha0 ST4BSyNq2+h+jwW3xlM/GinHTKNpPOoOcBqJxWo01wNpJiGjEIRV+YcTe3EwYq5iVAqg HsBcLtr7+JfnMMW1MpmGjlRjB37gTIUSw5zyv4IwLI3fDQb1q9Xkw57CNd2d8VQ2IZ9i +8IvmcpTmXaC7aC7ZENPKd8MxJCMBAr1TlsWsnC8bqz49BW40GUJosLgs0htqjhdUSLr W4vA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=CWsVp+SrjAMjXLWg5aGWLi275IB1/UGr/3Kbpvbrlz0=; b=Ca+hQ6GQQ2pHPKkgku8BM7X5+bbRAODSVV3FyLzN5ohYKcOnOIoHUGQgCsW+LlUAbX MI/EjuuZbL+dV5thbUPRR9xzqCFI9AEfPeRRHUeL1ASz9u4uTrhyypYnDbVmQxBCh7sM PLPxOTfUvw1u40bDgYIo/7qhSK5rDKAojpA959z5EMpRzzQ9xphHJUrnj3v/B9hL8gSJ oIKzHoT5s94xahdpSOIfb+fkR75AzE5Ln0bCDmc/jmio27L4xTcrk9W+UwTTeCd34a3R 8XZhxN18exFrxxgkVbvpV7vjppzlqYgSwtCziDDnVItr4Bd2BQYBTrCu11EoIrf6lXR8 I6cg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="U/dhtVVC"; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id sa6si2017637ejc.173.2021.10.27.14.32.40; Wed, 27 Oct 2021 14:33:02 -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=@gmail.com header.s=20210112 header.b="U/dhtVVC"; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243060AbhJ0Q5w (ORCPT + 97 others); Wed, 27 Oct 2021 12:57:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233200AbhJ0Q5t (ORCPT ); Wed, 27 Oct 2021 12:57:49 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A206C061570; Wed, 27 Oct 2021 09:55:23 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id d3so5238947wrh.8; Wed, 27 Oct 2021 09:55:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=CWsVp+SrjAMjXLWg5aGWLi275IB1/UGr/3Kbpvbrlz0=; b=U/dhtVVCVlDcYpws+z+H9Kda0couCD6neCQIXUYqlrfO99hMTp9STdc0AieEg3qQT/ LEA+vxDrmd6yzu18iRRAB7YQmULVytVd3yh6Xi9gtG1Ybl4G92/I6YlQOxY2glyzB2ez RSpQKKllcdr7iULn1KqydmlmuPpSummlQFliAWT5I/z2CsL6lBTRCzfsah1skJPOy7c9 7fl5PnuRz4XGmicNOMSDHCBzne9RpQHzLWK3ekMeRb6Bn9YJ7j+y2J1ySvyKN3NyAZOS WMWEP7YuQVmedJe+ydRZaG8mrxdMVK14JVyiTBZqk+ID/fmMClq1kcVaIJXjqN1JFrno T0vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=CWsVp+SrjAMjXLWg5aGWLi275IB1/UGr/3Kbpvbrlz0=; b=GbPyR0kSMEZ1c/nN+UCjDxMAxLptgl9CNM3gygBpeWbz+lMzHrg/lGzgfL14Gwgh+6 Zmt8FGNiATvNTreeloBfRad3BdSTlfSJ/t5SoKq6/5k9aMrEfXtmDb1uZSxEdHo+HAZU RqzvM93AWIlEKR2vdiQOF7s52+o21NqJJEiJnW3pp6Y8n+Dkns265w8mDYH2b3KOzL9g lcwISDRXHKta+EATbUaZLGU2sVM8P7wZ52fwmSk6sTL6rg8ppAd6vd7JkuFTb5fCJdC7 azVgK5A6DjJXsbx6JyPEYpzuEt08qq80XJVzfMWVRK3U1gvY4WWduSHKCC485SQsTrSF p+oQ== X-Gm-Message-State: AOAM530YusuGvNTDbbproLfpA4sgHDaF3ixbyjm0AOXHB+4VGvH3GZPH VExyvOQZpdclxnKysYaeSnLlOs3GsjwqvhnnVOA= X-Received: by 2002:a05:6000:2c6:: with SMTP id o6mr21600827wry.321.1635353722089; Wed, 27 Oct 2021 09:55:22 -0700 (PDT) MIME-Version: 1.0 References: <20211027111822.3801679-1-tongtiangen@huawei.com> In-Reply-To: <20211027111822.3801679-1-tongtiangen@huawei.com> From: =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= Date: Wed, 27 Oct 2021 18:55:10 +0200 Message-ID: Subject: Re: [PATCH bpf-next,v3] riscv, bpf: Add BPF exception tables To: Tong Tiangen Cc: Paul Walmsley , Palmer Dabbelt , Palmer Dabbelt , Albert Ou , Luke Nelson , Xi Wang , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , linux-riscv , LKML , Netdev , bpf Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 27 Oct 2021 at 13:03, Tong Tiangen wrote: > > When a tracing BPF program attempts to read memory without using the > bpf_probe_read() helper, the verifier marks the load instruction with > the BPF_PROBE_MEM flag. Since the riscv JIT does not currently recognize > this flag it falls back to the interpreter. > > Add support for BPF_PROBE_MEM, by appending an exception table to the > BPF program. If the load instruction causes a data abort, the fixup > infrastructure finds the exception table and fixes up the fault, by > clearing the destination register and jumping over the faulting > instruction. > > A more generic solution would add a "handler" field to the table entry, > like on x86 and s390. > > The same issue in ARM64 is fixed in: > commit 800834285361 ("bpf, arm64: Add BPF exception tables") > > Signed-off-by: Tong Tiangen > Tested-by: Pu Lehui > --- > v3: > Modify according to Bj=C3=B6rn's comments, mainly code optimization. Thank you! I ran this patch against the test_bpf.ko, and selftests/bpf -- no regressions, and after the patch is applied more tests passes. Yay! On a related note. The RISC-V selftests/bpf is in a pretty lousy state. I'll send a cleanup patch for them soonish. E.g.: * RISC-V is missing in bpf_tracing.h (libbpf) * Some programs don't converge in 16 steps, I had to increase it to ~32 * The selftest/bpf Makefile needed some RV specific changes * ...a lot of tests still don't pass, and needs to be looked in to Feel free to add: Acked-by: Bj=C3=B6rn T=C3=B6pel > v2: > Modify according to Bj=C3=B6rn's comments, mainly removes redundant head = files > extable.h and some code style issues. > > arch/riscv/mm/extable.c | 19 +++- > arch/riscv/net/bpf_jit.h | 1 + > arch/riscv/net/bpf_jit_comp64.c | 185 +++++++++++++++++++++++++------- > arch/riscv/net/bpf_jit_core.c | 19 ++-- > 4 files changed, 177 insertions(+), 47 deletions(-) > [...] Bj=C3=B6rn