public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Yonghong Song <yhs@fb.com>, Alexei Starovoitov <ast@kernel.org>,
	Sasha Levin <sashal@kernel.org>,
	netdev@vger.kernel.org, bpf@vger.kernel.org
Subject: [PATCH AUTOSEL 5.7 05/19] bpf: Set the number of exception entries properly for subprograms
Date: Tue, 14 Jul 2020 10:38:35 -0400	[thread overview]
Message-ID: <20200714143849.4035283-5-sashal@kernel.org> (raw)
In-Reply-To: <20200714143849.4035283-1-sashal@kernel.org>

From: Yonghong Song <yhs@fb.com>

[ Upstream commit c4c0bdc0d2d084ed847c7066bdf59fe2cd25aa17 ]

Currently, if a bpf program has more than one subprograms, each program will be
jitted separately. For programs with bpf-to-bpf calls the
prog->aux->num_exentries is not setup properly. For example, with
bpf_iter_netlink.c modified to force one function to be not inlined and with
CONFIG_BPF_JIT_ALWAYS_ON the following error is seen:
   $ ./test_progs -n 3/3
   ...
   libbpf: failed to load program 'iter/netlink'
   libbpf: failed to load object 'bpf_iter_netlink'
   libbpf: failed to load BPF skeleton 'bpf_iter_netlink': -4007
   test_netlink:FAIL:bpf_iter_netlink__open_and_load skeleton open_and_load failed
   #3/3 netlink:FAIL
The dmesg shows the following errors:
   ex gen bug
which is triggered by the following code in arch/x86/net/bpf_jit_comp.c:
   if (excnt >= bpf_prog->aux->num_exentries) {
     pr_err("ex gen bug\n");
     return -EFAULT;
   }

This patch fixes the issue by computing proper num_exentries for each
subprogram before calling JIT.

Signed-off-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 kernel/bpf/verifier.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 739d9ba3ba6b7..eebdd5307713b 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -9613,7 +9613,7 @@ static int jit_subprogs(struct bpf_verifier_env *env)
 	int i, j, subprog_start, subprog_end = 0, len, subprog;
 	struct bpf_insn *insn;
 	void *old_bpf_func;
-	int err;
+	int err, num_exentries;
 
 	if (env->subprog_cnt <= 1)
 		return 0;
@@ -9688,6 +9688,14 @@ static int jit_subprogs(struct bpf_verifier_env *env)
 		func[i]->aux->nr_linfo = prog->aux->nr_linfo;
 		func[i]->aux->jited_linfo = prog->aux->jited_linfo;
 		func[i]->aux->linfo_idx = env->subprog_info[i].linfo_idx;
+		num_exentries = 0;
+		insn = func[i]->insnsi;
+		for (j = 0; j < func[i]->len; j++, insn++) {
+			if (BPF_CLASS(insn->code) == BPF_LDX &&
+			    BPF_MODE(insn->code) == BPF_PROBE_MEM)
+				num_exentries++;
+		}
+		func[i]->aux->num_exentries = num_exentries;
 		func[i] = bpf_int_jit_compile(func[i]);
 		if (!func[i]->jited) {
 			err = -ENOTSUPP;
-- 
2.25.1


  parent reply	other threads:[~2020-07-14 14:45 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-14 14:38 [PATCH AUTOSEL 5.7 01/19] gpio: arizona: handle pm_runtime_get_sync failure case Sasha Levin
2020-07-14 14:38 ` [PATCH AUTOSEL 5.7 02/19] gpio: arizona: put pm_runtime in case of failure Sasha Levin
2020-07-14 14:38 ` [PATCH AUTOSEL 5.7 03/19] KVM: s390: reduce number of IO pins to 1 Sasha Levin
2020-07-14 14:38 ` [PATCH AUTOSEL 5.7 04/19] pinctrl: amd: fix npins for uart0 in kerncz_groups Sasha Levin
2020-07-14 14:38 ` Sasha Levin [this message]
2020-07-14 14:38 ` [PATCH AUTOSEL 5.7 06/19] mac80211: allow rx of mesh eapol frames with default rx key Sasha Levin
2020-07-14 14:38 ` [PATCH AUTOSEL 5.7 07/19] scsi: scsi_transport_spi: Fix function pointer check Sasha Levin
2020-07-14 14:38 ` [PATCH AUTOSEL 5.7 08/19] xtensa: fix __sync_fetch_and_{and,or}_4 declarations Sasha Levin
2020-07-14 14:38 ` [PATCH AUTOSEL 5.7 09/19] xtensa: update *pos in cpuinfo_op.next Sasha Levin
2020-07-14 14:38 ` [PATCH AUTOSEL 5.7 10/19] scsi: mpt3sas: Fix unlock imbalance Sasha Levin
2020-07-14 14:38 ` [PATCH AUTOSEL 5.7 11/19] drivers/net/wan/lapbether: Fixed the value of hard_header_len Sasha Levin
2020-07-14 14:38 ` [PATCH AUTOSEL 5.7 12/19] ALSA: hda/hdmi: fix failures at PCM open on Intel ICL and later Sasha Levin
2020-07-14 14:38 ` [PATCH AUTOSEL 5.7 13/19] net: usb: qmi_wwan: add support for Quectel EG95 LTE modem Sasha Levin
2020-07-14 14:38 ` [PATCH AUTOSEL 5.7 14/19] net: sky2: initialize return of gm_phy_read Sasha Levin
2020-07-14 14:38 ` [PATCH AUTOSEL 5.7 15/19] drm/nouveau/i2c/g94-: increase NV_PMGR_DP_AUXCTL_TRANSACTREQ timeout Sasha Levin
2020-07-14 14:38 ` [PATCH AUTOSEL 5.7 16/19] scsi: mpt3sas: Fix error returns in BRM_status_show Sasha Levin
2020-07-14 14:38 ` [PATCH AUTOSEL 5.7 17/19] scsi: dh: Add Fujitsu device to devinfo and dh lists Sasha Levin
2020-07-14 14:38 ` [PATCH AUTOSEL 5.7 18/19] dm: use bio_uninit instead of bio_disassociate_blkg Sasha Levin
2020-07-14 14:38 ` [PATCH AUTOSEL 5.7 19/19] drivers/firmware/psci: Fix memory leakage in alloc_init_cpu_groups() Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200714143849.4035283-5-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=yhs@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox