From patchwork Sat Jan 19 18:06:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 1028004 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=netronome.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=netronome-com.20150623.gappssmtp.com header.i=@netronome-com.20150623.gappssmtp.com header.b="QdgiqO8V"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43hm4Z0CtHz9s55 for ; Sun, 20 Jan 2019 05:07:42 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729031AbfASSH2 (ORCPT ); Sat, 19 Jan 2019 13:07:28 -0500 Received: from mail-qk1-f194.google.com ([209.85.222.194]:42824 "EHLO mail-qk1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728973AbfASSHW (ORCPT ); Sat, 19 Jan 2019 13:07:22 -0500 Received: by mail-qk1-f194.google.com with SMTP id 68so9860061qke.9 for ; Sat, 19 Jan 2019 10:07:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netronome-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tkRhK5EZWbJqLbs/TjhNg+3mB2dNBQEiSC9ATXnSwX0=; b=QdgiqO8VRx3/oqeBANovdfJ+lC2pGKVaAyAeN0naGvcCFsYrDgTRE9VHte5QKvtd++ /2EMAhK+x47R1/HL/g2f+JVLz9xomVaXknXWsYgLtbPsaqjp1Ierhg1+F+C/OTLK2r/y z37pnx9UYiEgkad1mLuqk8leY4pDQV50EUMLFvlrCpCvaUF22mqu7xjB+EmC/oDbqrLd Qj1RYa5OU5UKQZbwTFlzzK3V6RU00oRHpSE/flCCn9JiciDZMc8MnFR9PxwZr3Ks3eDe Rnlv7mCEg+aLysUGLWVvAGVeQPe3n/1N7xpUOexL60c6k5h8FIXCgOFZqt2J6QJMlzMR EPVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tkRhK5EZWbJqLbs/TjhNg+3mB2dNBQEiSC9ATXnSwX0=; b=DapAsyzhq7hv686eyyXeX1D2Mh2fDh537eLXA4GvMMyrgdcQ13HM766Fbsqdfz+5SL qMF+c7QaxyN7H97gv/YT87D1aCjP6k96B11niiGofTjXztqKdyvar/B71DVDsRwXYwQ6 jKapmTxwRB+fB2QUsdVlYE7FXlEUUfeyIZoKMVlYPQFViB/VAIUlXVYQZAZqYtC9LD6o R4eaPOOGq++rdUQId4Z5oFJ1jVEctk2Or3oFr/ZXZCumS7ma2Q5POB5uaVOPw74CIbRG VQHuNaBi7Q8AP2EY5MbCQyH+s3vMze/NtAabWsP9HYd8IyM98vILf8iBgWP07UwqEj1h ds3Q== X-Gm-Message-State: AJcUukcPLng6qJgTM5RX9rHBQ5HrhbCAyjcPVXR1oSeLCm6nJFXeR+ML MwRxvERo0z8NSD9lbqoGJEcfqA== X-Google-Smtp-Source: ALg8bN7unnhSqjqTis52eNf3z+nq6gB4J6qui5uvn+n3V3hB4/Y9NHlQC3I3xNKqG84FIirfX2vm/w== X-Received: by 2002:ae9:e311:: with SMTP id v17mr4823041qkf.193.1547921241189; Sat, 19 Jan 2019 10:07:21 -0800 (PST) Received: from jkicinski-Precision-T1700.netronome.com ([66.60.152.14]) by smtp.gmail.com with ESMTPSA id v2sm46521518qte.75.2019.01.19.10.07.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 19 Jan 2019 10:07:20 -0800 (PST) From: Jakub Kicinski To: alexei.starovoitov@gmail.com, daniel@iogearbox.net Cc: netdev@vger.kernel.org, oss-drivers@netronome.com, yhs@fb.com, Jakub Kicinski Subject: [PATCH bpf-next v5 06/12] bpf: verifier: record original instruction index Date: Sat, 19 Jan 2019 10:06:50 -0800 Message-Id: <20190119180656.24635-7-jakub.kicinski@netronome.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190119180656.24635-1-jakub.kicinski@netronome.com> References: <20190119180656.24635-1-jakub.kicinski@netronome.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The communication between the verifier and advanced JITs is based on instruction indexes. We have to keep them stable throughout the optimizations otherwise referring to a particular instruction gets messy quickly. Signed-off-by: Jakub Kicinski Reviewed-by: Quentin Monnet --- include/linux/bpf_verifier.h | 1 + kernel/bpf/verifier.c | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/include/linux/bpf_verifier.h b/include/linux/bpf_verifier.h index 573cca00a0e6..f3ae00ee5516 100644 --- a/include/linux/bpf_verifier.h +++ b/include/linux/bpf_verifier.h @@ -187,6 +187,7 @@ struct bpf_insn_aux_data { int sanitize_stack_off; /* stack slot to be cleared */ bool seen; /* this insn was processed by the verifier */ u8 alu_state; /* used in combination with alu_limit */ + unsigned int orig_idx; /* original instruction index */ }; #define MAX_USED_MAPS 64 /* max number of maps accessed by one eBPF program */ diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index ae13172ea257..fdb5b9aa5fa0 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -7364,7 +7364,7 @@ int bpf_check(struct bpf_prog **prog, union bpf_attr *attr, { struct bpf_verifier_env *env; struct bpf_verifier_log *log; - int ret = -EINVAL; + int i, len, ret = -EINVAL; bool is_priv; /* no program is valid */ @@ -7379,12 +7379,14 @@ int bpf_check(struct bpf_prog **prog, union bpf_attr *attr, return -ENOMEM; log = &env->log; + len = (*prog)->len; env->insn_aux_data = - vzalloc(array_size(sizeof(struct bpf_insn_aux_data), - (*prog)->len)); + vzalloc(array_size(sizeof(struct bpf_insn_aux_data), len)); ret = -ENOMEM; if (!env->insn_aux_data) goto err_free_env; + for (i = 0; i < len; i++) + env->insn_aux_data[i].orig_idx = i; env->prog = *prog; env->ops = bpf_verifier_ops[env->prog->type];