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=-9.0 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 5B831C282C2 for ; Wed, 23 Jan 2019 06:45:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2828D21726 for ; Wed, 23 Jan 2019 06:45:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=netronome-com.20150623.gappssmtp.com header.i=@netronome-com.20150623.gappssmtp.com header.b="IXRsEpDX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726816AbfAWGpz (ORCPT ); Wed, 23 Jan 2019 01:45:55 -0500 Received: from mail-qt1-f195.google.com ([209.85.160.195]:35903 "EHLO mail-qt1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726766AbfAWGpx (ORCPT ); Wed, 23 Jan 2019 01:45:53 -0500 Received: by mail-qt1-f195.google.com with SMTP id t13so1235768qtn.3 for ; Tue, 22 Jan 2019 22:45:52 -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=5QyGY4uQ3ATzJptkV6KuPS6Z79uckB4GJuZklE5ze0k=; b=IXRsEpDXRi+90k/H3/6+xA63vfoxE6UE+zrLTrJaV9ElvsyYfbJMuAo3UCBc0o035y Np8I7FSsrp/brnUxVPaYI6oY7arG//MFvrXqZw6rRP5b7j9KJwS/oCGADiCFSxr27NYj 7R1FwtEtEfbXSHEl+VFUsnigYe64QcZ49vHlezFDcEbTdPgZiIuOF1eQC7vkLiSO+IoE +Yg6gvfoQAy/8QRw6KkObqBMzWBk+YMokYgqreC5qizH1xpK5BBsqpytAjR0ev2+fr08 eOIczsp97tlwPpjbZLsVhyot7GOGtU+oacBIgwYm7MPuofOclIeo1bIk3bGQU/XH7Ogh f7Zg== 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=5QyGY4uQ3ATzJptkV6KuPS6Z79uckB4GJuZklE5ze0k=; b=AutYTTb0mUtdDKfmiCQQGhI0hILfLjBKQ3IIqjm29syB7J1rFoW3fESLLnQtBpOYFD 0OY26ZZAZKEXJHotQLjNHBVfvAjUzieJgpFS4jX0dnWTrOl6iwaCuebVJCwhS0LwlBYm 2Yo9m2CUjWThMD9HT97RdjnF3kaZAMstZ3CqVV1pdeoaE9y+czPiV2D5sB5M+5AHB81V f9OAup2SW5jvlqc5+N0uuk9YGUKDMt8jXeYZqZOjfnrS7TG0qTsFMQKozKj6OlxAz5sV v00+Js6yrD8Gpy2Z1T34n2H0g6GYPhzJ6vjWLwWLni5aG14q7+/fJce7/f5aDeK2jG7l zOLg== X-Gm-Message-State: AJcUukd0OOtoROS4qpEkfV52uf+m3VhkrtUT+2XPYcMYV4N65+absK8u bh1OOKryTRBZJ50uRKVjbfX+k1NnCtw= X-Google-Smtp-Source: ALg8bN7FdmDyoiyp/MaMlj6AuTuDe/xQebG8RovqahOwcvX7avwnDT2qsGAczcINaQhgMkZzfMo9hA== X-Received: by 2002:aed:31c5:: with SMTP id 63mr988357qth.385.1548225952245; Tue, 22 Jan 2019 22:45:52 -0800 (PST) Received: from jkicinski-Precision-T1700.netronome.com ([66.60.152.14]) by smtp.gmail.com with ESMTPSA id k6sm80589046qtk.41.2019.01.22.22.45.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 Jan 2019 22:45:51 -0800 (PST) From: Jakub Kicinski To: alexei.starovoitov@gmail.com, daniel@iogearbox.net Cc: yhs@fb.com, netdev@vger.kernel.org, oss-drivers@netronome.com, kafai@fb.com, Jakub Kicinski Subject: [PATCH bpf-next v5 06/12] bpf: verifier: record original instruction index Date: Tue, 22 Jan 2019 22:45:23 -0800 Message-Id: <20190123064529.13518-7-jakub.kicinski@netronome.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190123064529.13518-1-jakub.kicinski@netronome.com> References: <20190123064529.13518-1-jakub.kicinski@netronome.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 f39bca188a5c..f2c49b4235df 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -7371,7 +7371,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 */ @@ -7386,12 +7386,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]; -- 2.19.2