From patchwork Tue Jan 1 01:37:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 1019735 X-Patchwork-Delegate: davem@davemloft.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="mqVG1my0"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43TGzQ2GJhz9s9h for ; Tue, 1 Jan 2019 12:38:26 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728204AbfAABiJ (ORCPT ); Mon, 31 Dec 2018 20:38:09 -0500 Received: from mail-qt1-f194.google.com ([209.85.160.194]:38621 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728181AbfAABiI (ORCPT ); Mon, 31 Dec 2018 20:38:08 -0500 Received: by mail-qt1-f194.google.com with SMTP id p17so30465275qtl.5 for ; Mon, 31 Dec 2018 17:38:06 -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=T2xNGCSsVBK5ScYZkXPQHJ9A+9jw+KuicAl15uZMZdY=; b=mqVG1my0VLdBewuc6rzu0T4/jrKvC03dmhIihrXfMZBFl9B27UYRE88K6dzwdzvPF7 moGQ6Nw3CNc955Kyv7XAwMhMbV4Eo/w4zNp81KTMhj7RGDbqC1oWT09gkUW7PqxzHJlb RwpBT6sMKLMUvIanQBIsH5pgEptuREIlVvj8cV5g3MKDcZYqMQ5/u5RvWdnrJNHm5JxR NyMRFQcdT7F1I9ofcvqKSgcZyPk1TSCAyt4u0fgscMkaGY5mRRiIA6ZqQAOnZ5We8KRz ZsljytPTTCWIftrhKZOUg7NlqcNukiiTyfyfRVwie3tkWOHKyGnZEuTAFjQH9cdvRJ1l 6Uwg== 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=T2xNGCSsVBK5ScYZkXPQHJ9A+9jw+KuicAl15uZMZdY=; b=amYrTEmQWYESEcuKaPfivtjEHrwrelPSxYg1spjzm0Wb9sBYlw87QaBF9U+gjwIBxS zWySYp0e2sgirwLMyo/R981AK3h+DjYLB49AmFEzZJCMu8nZ1pdX7jkvGCfG/SmBy6kv Ro4Z1DndQViBqZju0lLtS73AUdzlaGN3m+oBFste0MWJSmeHv+NSVfpiC/KGRggKN7EJ amvRCdw/kBg25lLa6XFq8po8Z0EzriqS8fJWh0HfvNKayCzps7yU5xjmDj8gqRiFs3ck T3Xu16KVLhgBzkE4ZHyzj0/SOZjMUnpsdFYCyS+TDrI9n79Vz/M4Qs3v9xLIdK6U+ReJ 6Wjg== X-Gm-Message-State: AJcUukcoXB3N/pSPioaTJGi33fWwnXnDhopB8j2nm1K+LUHmke+zqMhN uIvMZEwWmo1xR32fXz+ldVIq7A== X-Google-Smtp-Source: ALg8bN5KeumfUkj1XU+vSMxNClWZqitv/DU4YtSNKqVmVOmjey3e9lkFDu3aUEX6Sr9M8/11mVi3fg== X-Received: by 2002:ac8:6784:: with SMTP id b4mr38353301qtp.103.1546306686356; Mon, 31 Dec 2018 17:38:06 -0800 (PST) Received: from jkicinski-Precision-T1700.netronome.com ([66.60.152.14]) by smtp.gmail.com with ESMTPSA id p72sm19707544qke.87.2018.12.31.17.38.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 31 Dec 2018 17:38:05 -0800 (PST) From: Jakub Kicinski To: alexei.starovoitov@gmail.com, daniel@iogearbox.net, yhs@fb.com Cc: netdev@vger.kernel.org, oss-drivers@netronome.com, Jakub Kicinski Subject: [RFC bpf-next v4 06/12] bpf: verifier: record original instruction index Date: Mon, 31 Dec 2018 17:37:37 -0800 Message-Id: <20190101013743.23935-7-jakub.kicinski@netronome.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190101013743.23935-1-jakub.kicinski@netronome.com> References: <20190101013743.23935-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 c233efc106c6..414d1aeba897 100644 --- a/include/linux/bpf_verifier.h +++ b/include/linux/bpf_verifier.h @@ -176,6 +176,7 @@ struct bpf_insn_aux_data { int ctx_field_size; /* the ctx field size for load insn, maybe 0 */ int sanitize_stack_off; /* stack slot to be cleared */ bool seen; /* this insn was processed by the verifier */ + 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 10f22b2f0e89..3efa9f2285fe 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -7112,7 +7112,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 */ @@ -7127,12 +7127,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];