From patchwork Wed Sep 8 04:50:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 98240 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 90AA8A0548; Wed, 8 Sep 2021 06:51:12 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E4AAA4113C; Wed, 8 Sep 2021 06:51:01 +0200 (CEST) Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by mails.dpdk.org (Postfix) with ESMTP id 03BE64111D for ; Wed, 8 Sep 2021 06:50:58 +0200 (CEST) Received: by mail-pl1-f169.google.com with SMTP id l11so533455plk.6 for ; Tue, 07 Sep 2021 21:50:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tLGt3g/fE8Nac84joYAxwvRrDCCn7AsXDgoSw6xww6c=; b=uhnfrPMLAQGsk8TJalH4Z6RSjVvbvSfOQa51kkixJzKevsNG7xKTSPBREyt05vF6on sCwLoqQ+vltZpYuswKv54cqkXt+1pcem1PaEhrWcGfdTbCFKzEWLsWDTYoei3aDOZM2D IiDzWh99jb7F5V4uDW4Fhk+cpSN93iSN7qv9ffYcFZszp4tqPnSdOWFbqbfNN1LhCA7U m96ZoAGjOMwGzqSsFE3xEJQEymdmZRJ0WK2mHuYvA3eGUHklkgvy3QBOzP+oF74Snth+ X7pg0zXchkVFYRNFT1/r4RYVd3ycYNxrjZdpVtYtqOez3AFQhFszhqOJM6OM/+uXsddV PRZg== 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=tLGt3g/fE8Nac84joYAxwvRrDCCn7AsXDgoSw6xww6c=; b=RY6Oz3aDdxTsBH56FvOy/Zns4N18aMmFBBs8UGCBlmMRhKX2ZLqUFyqQ8J9dmUVA5E iIsmnR96xCIWByXFJ8KV4YxrkyZLKy0Jw44dLA2/X0hblqnvemuynyjg1l9UzoVPs+4u /5tfmh03RApEZ9QGqtogRSJEu5teGJ8pexq2oFI7q/8FESMFWobgKpDDJUcsQatbT3ss 51yqeJlE+D4eSerm2tHI9fGuvroqiVB+vYwr3jigSoi4EJx62YMwtKbWaWfsiSCgiLZ5 C0zBQTE1DttYGaYCFqyddGK+0v+ICwyyq9gcYeYtFHvv39Sj4PhQAKyPxA+skS/BNG1j C7GA== X-Gm-Message-State: AOAM530XyHe6qQ4/4UBuDujIqY7Qzbxl6M5BfLqJTdpRr2Jb1GR5bCK/ 415kf/Ee6iOVAnYz2IKvKRq5UTawqB3vsw== X-Google-Smtp-Source: ABdhPJxhFsgZoQwMQmRARMtfQqDimOJp52D9jh+ptdggFTRCU/ggN7OKoRF8KlVL6shs44PwaNf95A== X-Received: by 2002:a17:90b:1642:: with SMTP id il2mr954682pjb.133.1631076657778; Tue, 07 Sep 2021 21:50:57 -0700 (PDT) Received: from hermes.local (204-195-33-123.wavecable.com. [204.195.33.123]) by smtp.gmail.com with ESMTPSA id e2sm701241pfn.141.2021.09.07.21.50.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 21:50:57 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Konstantin Ananyev Date: Tue, 7 Sep 2021 21:50:46 -0700 Message-Id: <20210908045052.123849-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210908045052.123849-1-stephen@networkplumber.org> References: <20210903004732.109023-1-stephen@networkplumber.org> <20210908045052.123849-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v3 2/8] bpf: allow self-xor operation X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" When doing BPF filter program conversion, a common way to zero a register in single instruction is: xor r7,r7 The BPF validator would not allow this because the value of r7 was undefined. But after this operation it always zero so allow it as a special case. Cc: Konstantin Ananyev Signed-off-by: Stephen Hemminger --- lib/bpf/bpf_validate.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/bpf/bpf_validate.c b/lib/bpf/bpf_validate.c index 7b1291b382e9..7647a7454dc2 100644 --- a/lib/bpf/bpf_validate.c +++ b/lib/bpf/bpf_validate.c @@ -661,8 +661,12 @@ eval_alu(struct bpf_verifier *bvf, const struct ebpf_insn *ins) op = BPF_OP(ins->code); - err = eval_defined((op != EBPF_MOV) ? rd : NULL, - (op != BPF_NEG) ? &rs : NULL); + /* Allow self-xor as way to zero register */ + if (op == BPF_XOR && ins->src_reg == ins->dst_reg) + err = NULL; + else + err = eval_defined((op != EBPF_MOV) ? rd : NULL, + (op != BPF_NEG) ? &rs : NULL); if (err != NULL) return err;