Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp796468pxy; Wed, 5 May 2021 14:15:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxgKi9YSxLTs1WNEGpJ2IqipzqR/edvzEfISj7N+XrywVCK0K8xPiQMxkCOpdQ5v70kKyti X-Received: by 2002:a05:6402:17d8:: with SMTP id s24mr1050489edy.155.1620249324145; Wed, 05 May 2021 14:15:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620249324; cv=none; d=google.com; s=arc-20160816; b=0q61ERsrdVsn7LfjOhASFX783OFlFUamXPYNoJzQMsibADv2S5LhVj6TKPeOPib7bE Lsc096vNSYopS560Vwp6DwgJmfebjex4J65l6vJI8JWqRmJTtQNn2Z+3T1+F7UaCvK4b kupyJwNS8i4iMsog7mDo12xLgiNJBlpGFG3SVeW63goFfKU1xE8gSKeZL/WgDvP6xNC7 W4L7WWpIxsDbncXMuKJBtzMsq/JMMaZ2dFNLYRf0cnW8VQg97w+5/BIIEmqBBaNTmTq5 y2U2rlEohfq2ccg2xTvOlJ1r6pSnqcWsd7c2GE4c6AbvErwLcultJ6dVbqUH75YCCOQp 29gA== 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=WDMfQFqI//uoDmFx0L1nKcXQXu3zQsow+j5o+jsouGM=; b=E6gDQe+lXUlwZxsi8voq1B5cETT6KEfkxCEx02yAwy5xZNez/XoiN1DUC39NMuDo+Q q3aRikCYJ/iECY6NHpme/twWFEto94UD4v5pcpYNT2LKmL2k8+hx0DxkVc/4lo9c5rXy 4bfhTfq56/PUlZmPz53KWi0yPmw3g25p7pbNfkY1iX8nwXICXaB0s1GtiHalC6TKwWRd 0sGXifiQt31o9q+5MrfniQ0YlSFZpNWmZSFrcpu8bXHEvFwVdMo+DbDWSIahjOrKoXP5 rQcBldU3i7OPndAcztxKGwy0pMjFBCi0jysp8DYx7umRVufiwltB14J6aDvJeNnwgou2 mCfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=HHaySOxX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i14si543526eje.207.2021.05.05.14.15.00; Wed, 05 May 2021 14:15:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=HHaySOxX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S229928AbhEEUtT (ORCPT + 99 others); Wed, 5 May 2021 16:49:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229893AbhEEUtT (ORCPT ); Wed, 5 May 2021 16:49:19 -0400 Received: from mail-yb1-xb2e.google.com (mail-yb1-xb2e.google.com [IPv6:2607:f8b0:4864:20::b2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2DA64C061574; Wed, 5 May 2021 13:48:22 -0700 (PDT) Received: by mail-yb1-xb2e.google.com with SMTP id h202so4445372ybg.11; Wed, 05 May 2021 13:48:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=WDMfQFqI//uoDmFx0L1nKcXQXu3zQsow+j5o+jsouGM=; b=HHaySOxX/sizuss/R6FVSVAvU+L1PbRaw39ai5J7Twm2dwIBOrYCRpo5Fmbd1vQjBS sNamWGyhRc0O00Hc/WaSaki4JPkDH27eO3XCj6tCJvw4QTxBcCQO+a9T2ekpuSQvJVS6 ZmwuEDESO46AbYMy3KxCDSkcpLWY19wK85FD08ZD/E0J5kmZYgy5ZqBBGbYPpSmp5mXR vUm1pwfr9B3X47CkPMwGucZNxJszC3l0IBU4pafHQY+L55rNoPB9uoTBQ65gqiFPeijA Dq7BGuvlR1LGXolFJepoF4cjQT9s0BwZNcsx6WVC1gtEI1A1GR1mazx3fA7mSbqZs2ot ajvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=WDMfQFqI//uoDmFx0L1nKcXQXu3zQsow+j5o+jsouGM=; b=f5JraOAvmSruRbbuMotktiy3wPnspPIKRRKMK/xk3jxY14UwND6NPAJQmLPqgz7Ojo 0W8Wo+W5hbmfW0+TEfC0D4M0bVPHQHD2M5A6+cdy+h3GaPkfT7rcpF9YlGRQgPYSBfEM l5X9rwI0c/yEDZ4gVXjIKwUEJgI068aFQvL598GeU3aGEY25tb7Y2nikmuxm5aLTL0VE 19yoE6SaDPIg42Ez+FeJGaXBo0iI8SkBW/DKHXax1Y9DbHfVQcigcTvyEMIX59h/uJ/A lds5PXFN4JAm0BIn/5n70/ULlOxWXme9ncTPP1I9P8zIN9y/ocvkEFmAYYVU/DNR79ty DiXw== X-Gm-Message-State: AOAM531PJHxtlLgEupuhpTTqsizKFG3uIXPNNWjKUMwvRhc2XJekRUf5 nyRKaNPl94eHTfNjV20uYNxNNukMII3QRXMYy+w= X-Received: by 2002:a25:ba06:: with SMTP id t6mr843188ybg.459.1620247701369; Wed, 05 May 2021 13:48:21 -0700 (PDT) MIME-Version: 1.0 References: <20210505162307.2545061-1-revest@chromium.org> In-Reply-To: From: Andrii Nakryiko Date: Wed, 5 May 2021 13:48:10 -0700 Message-ID: Subject: Re: [PATCH bpf] bpf: Don't WARN_ON_ONCE in bpf_bprintf_prepare To: Daniel Borkmann Cc: Florent Revest , bpf , Alexei Starovoitov , Andrii Nakryiko , KP Singh , Brendan Jackman , Stanislav Fomichev , open list , syzbot Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 5, 2021 at 1:00 PM Daniel Borkmann wrote: > > On 5/5/21 8:55 PM, Andrii Nakryiko wrote: > > On Wed, May 5, 2021 at 9:23 AM Florent Revest wrote: > >> > >> The bpf_seq_printf, bpf_trace_printk and bpf_snprintf helpers share one > >> per-cpu buffer that they use to store temporary data (arguments to > >> bprintf). They "get" that buffer with try_get_fmt_tmp_buf and "put" it > >> by the end of their scope with bpf_bprintf_cleanup. > >> > >> If one of these helpers gets called within the scope of one of these > >> helpers, for example: a first bpf program gets called, uses > > > > Can we afford having few struct bpf_printf_bufs? They are just 512 > > bytes, so can we have 3-5 of them? Tracing low-level stuff isn't the > > only situation where this can occur, right? If someone is doing > > bpf_snprintf() and interrupt occurs and we run another BPF program, it > > will be impossible to do bpf_snprintf() or bpf_trace_printk() from the > > second BPF program, etc. We can't eliminate the probability, but > > having a small stack of buffers would make the probability so > > miniscule as to not worry about it at all. > > > > Good thing is that try_get_fmt_tmp_buf() abstracts all the details, so > > the changes are minimal. Nestedness property is preserved for > > non-sleepable BPF programs, right? If we want this to work for > > sleepable we'd need to either: 1) disable migration or 2) instead of oh wait, we already disable migration for sleepable BPF progs, so it should be good to do nestedness level only > > assuming a stack of buffers, do a loop to find unused one. Should be > > acceptable performance-wise, as it's not the fastest code anyway > > (printf'ing in general). > > > > In any case, re-using the same buffer for sort-of-optional-to-work > > bpf_trace_printk() and probably-important-to-work bpf_snprintf() is > > suboptimal, so seems worth fixing this. > > > > Thoughts? > > Yes, agree, it would otherwise be really hard to debug. I had the same > thought on why not allowing nesting here given users very likely expect > these helpers to just work for all the contexts. > > Thanks, > Daniel