Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp2475298imn; Tue, 2 Aug 2022 04:22:59 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tfaf17Yh4PyB9mXlpbzOk0dGCKyJw9Td4WBWDCmlIoJAdBgrMgtinHbnjN4c8f997hQzs4 X-Received: by 2002:a17:906:6a21:b0:72f:2174:16e6 with SMTP id qw33-20020a1709066a2100b0072f217416e6mr16047325ejc.177.1659439379123; Tue, 02 Aug 2022 04:22:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659439379; cv=none; d=google.com; s=arc-20160816; b=QkBoPDUtIFJpBYz+uEBsnamyJs8tCKfeK2Qn1e/qRfZltzbqXHbvsTqnBiH8v43wLx vjTqmo/ZTEoLvFIIujHi6kt3qsl72/dty8KkdEXNMm5OwylhK5NHGBHMKuDaj2cWQVbw SJp/t4hX6WJf9esEdWC0rmtD+NUyKEofcrN8zfzyh+0HE4ZtRb6EMnaZ+hW1DFBNwHhG LtmEbUzYCjbd6mLUD4c4hh67WyDGihpOkvBJyw2yFABNaAcwcykqY9GC5rBldA6DSFgZ 7jSQZtnyTHv08tF61uICTzvBkS5/QNThjvk9AhjSjhhaTHc58nRN4G8pvW1JTssmcBYA lg+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:date:from:dkim-signature; bh=Q2ZorbTmwuDDxNcSA+CRBMBDw68FJCVnA16N7n1OJ/A=; b=ejVQHz8xCYMog4+EYmLo8KmpIJyZuAeJfkVZ4LjjmWTU5wOQ8BMn9WAG4guTSN0apo S/6+fDKYceKBAWWvElg8XFXQ0Jefz0P1LyLLbBc+KProsldx6IMPcSbrkGFZG0MkY2Ea rsVkSwDKgAbfnaSyxDy3py2xMn40AAd3IOpnwUCD1vEKKFdtKVBFKb1UrRz4T0vffe73 tn/0zPyV1jJ4x76/tWZv55zTqmANHt7IuBoH42iJyvJgoYi5HcL9B5Ux32eLI8zTJkhS NEwdJBfTtf5PY5Jdbw2kKmQgI6LoRqc3ocTjmAd74hw+A9V2KVwxD8FOuI6S97bUjMxl y38g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="GcVjzh0/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u14-20020a50d50e000000b0043a0b68e0b2si10987878edi.432.2022.08.02.04.22.34; Tue, 02 Aug 2022 04:22:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="GcVjzh0/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236952AbiHBLPI (ORCPT + 99 others); Tue, 2 Aug 2022 07:15:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236944AbiHBLO4 (ORCPT ); Tue, 2 Aug 2022 07:14:56 -0400 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E71CD51429; Tue, 2 Aug 2022 04:14:40 -0700 (PDT) Received: by mail-ed1-x536.google.com with SMTP id i13so17148671edj.11; Tue, 02 Aug 2022 04:14:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:from:to:cc; bh=Q2ZorbTmwuDDxNcSA+CRBMBDw68FJCVnA16N7n1OJ/A=; b=GcVjzh0/p/KZxLPeq9Lz5V9KkQ42dJ5jDt3hPxamKoboGjTcWIZzyWnJsflK2gDYLG 5U8G9FdO3l+Gp2VJb0vhMjbmtvXE4xfmjUcybdMpAw6PHSqqZWOCkEuIzgSJsNJcKLTc oCpbLjQEsyYroswpxkE2M3KeQVi8Q++wZUcUjrbMpFV+yoKLptXNx43WPtWhpmWxz6jB b33HyGAnSgnzBAApBZwqbYlYfxNkYZeB/JJK5BBtoA70UTiqPLP4Oop4GQxvsPRVfOy9 wMFvMItd8yiNBtH4NEwjuv2QeU7z1Zl9YrpKb2IgqduySvRnbp5ZjrGXid1hq12IlkYW qRWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:x-gm-message-state:from:to:cc; bh=Q2ZorbTmwuDDxNcSA+CRBMBDw68FJCVnA16N7n1OJ/A=; b=EAfWSu1jD7WPmtGdFQU6lQCNu33KujoL9FHCCZLJjx9W63QUFtPE5YDWVhAKuChTJc XvTekF7WTexzA66gQduN5cFQ5pX2AmtXZ5pjlgR4j5uGHu3/XLdM5CKJSkUpMIxfKkXU /3jWtdHjUqmDW3oKy4BaXdeWnjxdZIvNIVn4ebwPB0bGQ1x/AMUOpT/cZnA20vmI0k6S Yj/TmHEVlIhiyUGKQO8OAYui0yoOSuOwvpaJRiMESomQNpBWAf3ts/4EL6xpYcMhsX09 Rx+PCV0yg8npSnThmNqVP19usHuz+0isBXa4eg6L2c8xIKha+izt3ZouBcb/lmxoaVf3 uuZA== X-Gm-Message-State: ACgBeo1AgVtg9+r7AxUxj/zjjJlJh0W8Vehx6sPSeOsj/gtkF6/7TaLB MRxYmoY5LMbcUeOTTptcZfO9nUbh4dUlyA== X-Received: by 2002:a05:6402:14b:b0:43d:a7dd:4376 with SMTP id s11-20020a056402014b00b0043da7dd4376mr8621228edu.89.1659438879075; Tue, 02 Aug 2022 04:14:39 -0700 (PDT) Received: from krava ([83.240.61.12]) by smtp.gmail.com with ESMTPSA id kx6-20020a170907774600b00724261b592esm6138051ejc.186.2022.08.02.04.14.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Aug 2022 04:14:38 -0700 (PDT) From: Jiri Olsa X-Google-Original-From: Jiri Olsa Date: Tue, 2 Aug 2022 13:14:36 +0200 To: Hao Luo Cc: linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , John Fastabend , Stanislav Fomichev Subject: Re: [PATCH bpf-next v1] bpf, iter: clean up bpf_seq_read(). Message-ID: References: <20220801205039.2755281-1-haoluo@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220801205039.2755281-1-haoluo@google.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 01, 2022 at 01:50:39PM -0700, Hao Luo wrote: SNIP > +static int do_seq_show(struct seq_file *seq, void *p, size_t offs) > +{ > + int err; > + > + WARN_ON(IS_ERR_OR_NULL(p)); > + > + err = seq->op->show(seq, p); > + if (err > 0) { > + /* object is skipped, decrease seq_num, so next > + * valid object can reuse the same seq_num. > + */ > + bpf_iter_dec_seq_num(seq); > + seq->count = offs; > + return err; > + } > + > + if (err < 0 || seq_has_overflowed(seq)) { > + seq->count = offs; > + return err ? err : -E2BIG; > + } > + > + /* err == 0 and no overflow */ > + return 0; > +} > + > +/* do_seq_stop, stops at the given object 'p'. 'p' could be an ERR or NULL. If > + * 'p' is an ERR or there was an overflow, reset seq->count to 'offs' and > + * returns error. Returns 0 otherwise. > + */ > +static int do_seq_stop(struct seq_file *seq, void *p, size_t offs) > +{ > + if (IS_ERR(p)) { > + seq->op->stop(seq, NULL); > + seq->count = offs; should we set seq->count to 0 in case of error? jirka > + return PTR_ERR(p); > + } > + > + seq->op->stop(seq, p); > + if (!p) { > + if (!seq_has_overflowed(seq)) { > + bpf_iter_done_stop(seq); > + } else { > + seq->count = offs; > + if (offs == 0) > + return -E2BIG; > + } > + } > + return 0; > +} > + > /* maximum visited objects before bailing out */ > #define MAX_ITER_OBJECTS 1000000 > SNIP