Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp169369pxp; Fri, 11 Mar 2022 01:39:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJxwli8d97xzAO/zytD5B5lrxsV1T5HZ88Q9xUB7BJmU50rlsA5Zr1NFsKK7vq46qrEtGRnu X-Received: by 2002:a17:907:7656:b0:6d0:1f5a:2bec with SMTP id kj22-20020a170907765600b006d01f5a2becmr7735162ejc.164.1646991591351; Fri, 11 Mar 2022 01:39:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646991591; cv=none; d=google.com; s=arc-20160816; b=Km2x54annwfHLWl5Ug9XTFl62ub/ORgZUpTzfvb0OfSZ0DaES25AEdz8iowjq2AhZn E3CtdzWBZ86PXCi1iBdXM2cguxkC1USH5ePKVJQbgiP2+6fYE0KRBPpuD6tsptqepIf4 uC9EcQnyNhOkSozsYQF5Xj1+a+rTsZfPn7LZvBBwVPbFLqO5AsnMrR0YJJ/9vN/W+h/H vZsL0Grs7qdWk35VSkOo8ahrfMhedWqepdziAC4JwAMnFP3ft0vMmDV+PulHGpYGA0bR kqNfHCtnp16VO4ShYOEY3B20lhpOemqaHiM+Ru7fAzEpOlev8Klga6rV7+k/4RWWe7Ha roPA== 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=C0NJCF215u7J1keWHi6UUO/2cqd9pO2REm63LKre0R0=; b=oesX+uBVABweuzhdXE5npOPI/hPIPdQ1wZKslg2MNaWkFu1rtUT5vmlNFyAEToJUND zpnScNGadGXRu6zn45G8nEjGhm6iv8ETdszecEyZGZxejZ+dVm/rKbxsK/QBmP50S1Rt L4brGYPo9JMCTQpmW4zmh4FYmac6ko3cchslKHVsk7bAWPb08nDfxg8Loviezgqdimpd kqZJ+gwn1cdANbIpiRbQIbCoJe0T34IND5Mauft3TIOZcCua8EqEQulkK1ayc1WuNDfQ gvrdnHV2JeL4i+H/8hUzo/0/1+WsHyWwrZrJBNds/tPftUDvo6wGHvPk5rAN8lsU3S+0 jNXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=MIUeSn8O; 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 t13-20020a170906178d00b006cf9c53ba53si4378742eje.419.2022.03.11.01.39.23; Fri, 11 Mar 2022 01:39:51 -0800 (PST) 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=MIUeSn8O; 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 S234741AbiCKAZH (ORCPT + 99 others); Thu, 10 Mar 2022 19:25:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241006AbiCKAZG (ORCPT ); Thu, 10 Mar 2022 19:25:06 -0500 Received: from mail-qv1-xf2e.google.com (mail-qv1-xf2e.google.com [IPv6:2607:f8b0:4864:20::f2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14A1D1A12A4 for ; Thu, 10 Mar 2022 16:24:03 -0800 (PST) Received: by mail-qv1-xf2e.google.com with SMTP id kj21so2984873qvb.11 for ; Thu, 10 Mar 2022 16:24:03 -0800 (PST) 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=C0NJCF215u7J1keWHi6UUO/2cqd9pO2REm63LKre0R0=; b=MIUeSn8OYMGKM8eYxc6CG4lNAZsIgeK628Xe2+I9+LMKomBR6RsPIZoXcUB0LX4UY0 1joG4HRzqHJDO2cOEFMSOcOqY6pRmnFsoNZpkmgcbDRgR9pHxOMK15xwZCoCgv1RNMEO DYFyfYu2uZj9Zm8Ic7zt5bYFEGDXUhWngyAXxIrqJIZ4Gvw6upyEbcxzncXDzkyXwaKU fL74LBGBYt/f7A2+4A6EvclX+a+SkJMUVkh5NN09Y+esV6JBKgA2o1KmyCu4Dw1RGpaU 1t+mI4u7axYdiNvfuqizL3kqmMVV+uJV+LR3s2jjgKnCSNuHLlSXHDM+EamzTk6mRyFR VziA== 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=C0NJCF215u7J1keWHi6UUO/2cqd9pO2REm63LKre0R0=; b=8DHQjaL3Q/jKGN3U4hsR6w0GlKAi0PeW2wH8ggWldLQOWALlMOmgMmev9IkZm1pQbz tCssjfH/1igZhIXVJa9DbpU9dhbKvxMAaHhCzEQe+NGP02D4GRkjk6jG+9xqmFnG5bw9 IuLZGlBsdf05qvYARJZITXiSz06ZGA7x49UUa+u7sd3KZCsOLW8hLwtNmrtUC5peiXkV A3oHtrGkY3pN26D6o/4d6l+Q6nQWYnPLhvw+NZDS8eiT1a1Uij0HcsZ1MhZ6ZqFmlR56 JolKJ6b+oEnXvxyhIKfM31OwAm9udiPa0innNezxk589yQQlqGenobmzuCSui5VhZNI8 4AHg== X-Gm-Message-State: AOAM530GiGaOyY9piSF2oqnX3a1elTgMUdu+p1Il890Z1KmuOmg5aqag Y3dm0qWINmTElGh3Ty+3K3bUhaYnREpRHAQewZB9RQ== X-Received: by 2002:a05:6214:2a4a:b0:435:8b63:ecfb with SMTP id jf10-20020a0562142a4a00b004358b63ecfbmr6118246qvb.44.1646958241993; Thu, 10 Mar 2022 16:24:01 -0800 (PST) MIME-Version: 1.0 References: <20220310082202.1229345-1-namhyung@kernel.org> In-Reply-To: From: Hao Luo Date: Thu, 10 Mar 2022 16:23:50 -0800 Message-ID: Subject: Re: [PATCH 1/2] bpf: Adjust BPF stack helper functions to accommodate skip > 0 To: Yonghong Song Cc: Namhyung Kim , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , John Fastabend , KP Singh , netdev@vger.kernel.org, bpf@vger.kernel.org, LKML , Arnaldo Carvalho de Melo , Peter Zijlstra , Eugene Loh 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, T_SCC_BODY_TEXT_LINE,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 Thu, Mar 10, 2022 at 2:54 PM Yonghong Song wrote: > > > > On 3/10/22 12:22 AM, Namhyung Kim wrote: > > Let's say that the caller has storage for num_elem stack frames. Then, > > the BPF stack helper functions walk the stack for only num_elem frames. > > This means that if skip > 0, one keeps only 'num_elem - skip' frames. > > > > This is because it sets init_nr in the perf_callchain_entry to the end > > of the buffer to save num_elem entries only. I believe it was because > > the perf callchain code unwound the stack frames until it reached the > > global max size (sysctl_perf_event_max_stack). > > > > However it now has perf_callchain_entry_ctx.max_stack to limit the > > iteration locally. This simplifies the code to handle init_nr in the > > BPF callstack entries and removes the confusion with the perf_event's > > __PERF_SAMPLE_CALLCHAIN_EARLY which sets init_nr to 0. > > > > Also change the comment on bpf_get_stack() in the header file to be > > more explicit what the return value means. > > > > Based-on-patch-by: Eugene Loh > > Signed-off-by: Namhyung Kim > > The change looks good to me. This patch actually fixed a bug > discussed below: > > > https://lore.kernel.org/bpf/30a7b5d5-6726-1cc2-eaee-8da2828a9a9c@oracle.com/ > > A reference to the above link in the commit message > will be useful for people to understand better with an > example. > > Also, the following fixes tag should be added: > > Fixes: c195651e565a ("bpf: add bpf_get_stack helper") > > Since the bug needs skip > 0 which is seldomly used, > and the current returned stack is still correct although > with less entries, I guess that is why less people > complains. > > Anyway, ack the patch: > Acked-by: Yonghong Song > > > > --- > > include/uapi/linux/bpf.h | 4 +-- > > kernel/bpf/stackmap.c | 56 +++++++++++++++++----------------------- > > 2 files changed, 26 insertions(+), 34 deletions(-) > > > > diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h > > index b0383d371b9a..77f4a022c60c 100644 > > --- a/include/uapi/linux/bpf.h > > +++ b/include/uapi/linux/bpf.h > > @@ -2975,8 +2975,8 @@ union bpf_attr { > > * > > * # sysctl kernel.perf_event_max_stack= > > * Return > > - * A non-negative value equal to or less than *size* on success, > > - * or a negative error in case of failure. > > + * The non-negative copied *buf* length equal to or less than > > + * *size* on success, or a negative error in case of failure. > > * > > * long bpf_skb_load_bytes_relative(const void *skb, u32 offset, void *to, u32 len, u32 start_header) Namhyung, I think you also need to mirror the change in tools/include/uapi/linux/bpf.h