Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp37083imn; Tue, 2 Aug 2022 17:27:36 -0700 (PDT) X-Google-Smtp-Source: AA6agR4R8BuPRK+cCr4cSmVcWz4/XQaplumDF2NWFK6TSct2wXSSkRHD5AbC0ZJvqV/9WFgVbhdm X-Received: by 2002:a62:1a14:0:b0:52d:daae:b289 with SMTP id a20-20020a621a14000000b0052ddaaeb289mr5565743pfa.55.1659486456360; Tue, 02 Aug 2022 17:27:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659486456; cv=none; d=google.com; s=arc-20160816; b=z3vTJoAh6TKuL5bRSPHqAGwV0tafb7IQGJa/iaz7T+jcB6/7vQToOWKCeDZsadCMT5 VFXLiM3sxEr/+MP6DliFJFTRLK4pT3ZTTRudbUjXVfmFq1ChnsdwA6Dag1FXDqKRCQNy 0T7nKibhdJR+0K6h4N3Znvoeo0kXqEwcoQlStkqDIlH9g3qX7Nyl4YONaaLVWY+mZKmH brosdnHMH3CQi6wa7oi53R7bwFpIx4vZATZiW0vr4NxjkQyOAQrWqtg1AJLJgsMzpcKE 1cCsa3t9KFGmwZSdsDCVNDLReAaMmpliIqGfknBvCQK+9RqNLTQhEC/GxcuiXarVLBe/ /wqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=ZbHc1iEAZVkOCSroOZMrX+NJF9WF2AGs0gYDdDjKIqI=; b=ZzTOX61DH91E6i9b9yGY5BfUuALKYnea770wLJ56azqmg4HDHaG4EEx/QP5OZoyxw4 JZAc4nigw/+P3jm5AGJVny8k/Sf42kkDWTOhYyIJP3Nn+kgio69d3gb7FDOQxwzI4Drx BGQHJ9uwMx/YWip2j85vDPyPs0+pZjmqFRwmNWawXNb2ISRNlthfE8ZXDQ4jgF67aznj tQQqc8C7JoqBNzFWe/eB7b+Q7RFeuYF4a/fRZ4O0PeuPURXVHV9c/Kmyw7hwNkvpfzEe eW/ILe0/pM3lYAMJkaQv2j3yPPX609ThfxP6JVUJJpa3y9wkATDt/M6KEk7dE0fOQesU RiKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Wes9hWt4; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z11-20020a170903018b00b0016db2f3f496si891607plg.209.2022.08.02.17.26.56; Tue, 02 Aug 2022 17:27:36 -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=@google.com header.s=20210112 header.b=Wes9hWt4; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230312AbiHCAQH (ORCPT + 99 others); Tue, 2 Aug 2022 20:16:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230234AbiHCAQF (ORCPT ); Tue, 2 Aug 2022 20:16:05 -0400 Received: from mail-qt1-x82c.google.com (mail-qt1-x82c.google.com [IPv6:2607:f8b0:4864:20::82c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B850BBF6B for ; Tue, 2 Aug 2022 17:16:02 -0700 (PDT) Received: by mail-qt1-x82c.google.com with SMTP id e5so11585399qts.1 for ; Tue, 02 Aug 2022 17:16:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ZbHc1iEAZVkOCSroOZMrX+NJF9WF2AGs0gYDdDjKIqI=; b=Wes9hWt4rUxxS8EfD4lQNuBDh6FZLW2G0p1/zsD08Z/MLFvRRsoH8ub00qjH7TPihF WETa1mBrEKqnzd9vD3uYpOLCjn6gGdrR0xL2ER87xtrjcWSSXeLFVucs9ZVgyYzYG7mv NMiyxPJ/VYMbgtxFSz+Sc5m4du1qlaLg8Yi6SBHMFWq2S0eUHV2probHStP53F6+yQe4 xxy7Bjs+4mD/7HFHin+LGujMFpNrc4DfIlfclng4wFN+AEjVvBQztnxpFwjT39V6wFqq 9P/7XiMVpxtE17Dgq+j8nzP00+OofOs4gSPyjzWi9YkX8lEwOfD7NxH7/UR42xRlJQS8 Q+Lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ZbHc1iEAZVkOCSroOZMrX+NJF9WF2AGs0gYDdDjKIqI=; b=RZioovqRr6RigDYS5dKj+CgAqiHy2xiA06UXq5fvKYVsMscAPugUyocdp3PkwH5Cuy mFtETzqpz1q8IEFADXCczjhm8l2II1ddO0kNzHonXxqrfwi+LsRURK+u47GCtxfeTTma 1nKF3m/ejobjHZGXdTMwdfLYS+b6JpniVCfGz0wb/ipzOPzyKVTHHUlFQxquiddBvVWE 9zRxeh++UoP1MZsqJom2ke/oYTkM0Stn0vS2nSaSv2wpLXYHyn5+GqpxQ5kDZUmtbqWe zK5S+uOzw0Os83Zys6Yl4W8sjUdjUdnpa1gnG0VVkS01FTFi+eC1GGZlVWBlsLWVAGWf Ht+A== X-Gm-Message-State: AJIora9erTd0GipKhZZ5wkqAk70jPwuOCgV1QDcncmB/i3aJi4uDUUho SV4T4189Uz0GvO93XR8muEzNTK3w5yvx3ZdvDUnGtg== X-Received: by 2002:a05:622a:4e:b0:31e:f84c:bf17 with SMTP id y14-20020a05622a004e00b0031ef84cbf17mr20355611qtw.566.1659485761782; Tue, 02 Aug 2022 17:16:01 -0700 (PDT) MIME-Version: 1.0 References: <20220801205039.2755281-1-haoluo@google.com> In-Reply-To: From: Hao Luo Date: Tue, 2 Aug 2022 17:15:50 -0700 Message-ID: Subject: Re: [PATCH bpf-next v1] bpf, iter: clean up bpf_seq_read(). To: Jiri Olsa 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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 Tue, Aug 2, 2022 at 4:14 AM Jiri Olsa wrote: > > 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? > Thanks Jiri. To be honest, I don't know. There are two paths that may lead to an error "p". First, seq->op->start() could return ERR, in that case, '"offs'" is zero and we set it to zero already. This is fine. The other one, seq->op->next() could return ERR. This is a case where bpf_seq_read() fails to handle right now, so I am not sure what to do. Based on my understanding reading the code, if seq->count isn't zeroed, the current read() will not copy data, but the next read() will copy data (see the "if (seq->count)" at the beginning of bpf_seq_read). If seq->count is zeroed, the data in buffer will be discarded. I don't know what is right. > 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