Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp621461pxb; Thu, 15 Apr 2021 02:36:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxjDkF7CKG2F6Ya4rBYoWSE2ZHDFrVAjQN8N5COzy7+OohVGi2DktSD/qtVFh4H7u9u10Ef X-Received: by 2002:aa7:c950:: with SMTP id h16mr3013381edt.381.1618479373238; Thu, 15 Apr 2021 02:36:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618479373; cv=none; d=google.com; s=arc-20160816; b=gdnFkkFcAqzYyXedIkvsK1Z/tdD0U62SHfw+jjc3QlsSVnJWNn1Ed1mRp8mRa36zbX +BT7yaCsnAdrqXSVzAjdKhVcA07wSjGK9QaX9NamdrcYMDTrlDabV3Zdr3Q31DL7Ckxd PXcpeiZN7NH2QV64TryWW/jdai+AAIJjsJVpyGXQQldZWiKMg99zs6gvSlflMOW8HlL5 QAqDPiYGIjxGf72wCPqDM17BqgdNOkZ4BGG32OaF/uI+rngM3bFqEFeCeWNkmp8gxj9C EJRKOznRDHVpISWHvPM3aZ7lYCwxljlhG/EcHHeXMnJiceUg0+rtlKQKtIqE7lmNOSjt 7RAg== 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=2oxhfmgq4/lBHZsTv5waxIB12jAdndxIiCGYaYJ0QbU=; b=REKAx3BInAKOidPD3dbSLQMEipmFHxglcXTKzDJLC83xPfi2dFVe/BmD1xpoWnw45C 7uACTtvMQS5Sly5CxzTC91W/RieBASsHSfYczh7l+dKfMzZ0RR0AjYzwFw30f2F99/31 xDipAB6LjhYXZjrOl5loA2E1efrAuqOrD9EDROtwrAaWcQKQVojxKu5EOMvbgJubh37b I7/dI9YstxDxr3eJflxW8dU6no6nXxDilZNHz8kAHrKKNn+6XsjMufDqUmtF/32vPVyQ u2YpsOmlYMtFT2soiblexRG6+RiGez51ZzQrl0w6fCz10h0SQsSjutCutm18sPHgAf4Q t1Zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=UbdMnzkM; 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=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e26si2005163edv.198.2021.04.15.02.35.49; Thu, 15 Apr 2021 02:36:13 -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=@chromium.org header.s=google header.b=UbdMnzkM; 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=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232216AbhDOJe6 (ORCPT + 99 others); Thu, 15 Apr 2021 05:34:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231200AbhDOJe5 (ORCPT ); Thu, 15 Apr 2021 05:34:57 -0400 Received: from mail-il1-x136.google.com (mail-il1-x136.google.com [IPv6:2607:f8b0:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10865C061574 for ; Thu, 15 Apr 2021 02:34:34 -0700 (PDT) Received: by mail-il1-x136.google.com with SMTP id r5so11467879ilb.2 for ; Thu, 15 Apr 2021 02:34:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=2oxhfmgq4/lBHZsTv5waxIB12jAdndxIiCGYaYJ0QbU=; b=UbdMnzkMjlp4dVJzE5P6mIlHvL1lwGcw1qltoT9qncf5Oc0r2fUgB9SKUW0wR9lDVC tKEZRlsxRg6hWGuydX2yQhRoWDikqmWFp5mOfPESNP0UQuEbY0Z7R5UaUJ+XT9zQ6g7R /KAeiqhfw8gm2oDkm/y60F44SPj0DkvpIy+BE= 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=2oxhfmgq4/lBHZsTv5waxIB12jAdndxIiCGYaYJ0QbU=; b=ZAGgfmIFYNEWx3022OaUYGKCmzrSVDAhzhU9Rm0x1+UJlFaCIT8OHrLoterIkFMQJx I9F9Jj+YoR/MCkD129r+XeB5E2r3DHSGMCN2Q8NrjWRdZFJ/w++JDDwkhXmmW6ur38S4 3GQ+zfCRVh5rRY+/RGr7v2O8K8vhCyrXUZxUUqPTvrCdB1DhHrXzi81bxErCZMM4oCGi nNg9D8/wiRlgAsGE7uQB5eStlssu7b26/RsCW36KMMnKYQ5oo2/jdBL2Y8UQkBV4vFfE W2JTsWxst8XrJkS7P8KpNFUEh7TPSWf+dBX2AsKW2euv316Q1b2ZrgPT9DOFbdjNgtyd EldQ== X-Gm-Message-State: AOAM530tguKav0Zk4p/gBshcbXC6Q/VBsr1ahu5QuYNTHhe4w2vVdy/g tQoKCcygJx2oVm8HRHKa9fftZc7EFxG42pndk6v8+w== X-Received: by 2002:a92:ce90:: with SMTP id r16mr2135098ilo.220.1618479273627; Thu, 15 Apr 2021 02:34:33 -0700 (PDT) MIME-Version: 1.0 References: <20210412153754.235500-1-revest@chromium.org> <20210412153754.235500-4-revest@chromium.org> In-Reply-To: From: Florent Revest Date: Thu, 15 Apr 2021 11:34:22 +0200 Message-ID: Subject: Re: [PATCH bpf-next v3 3/6] bpf: Add a bpf_snprintf helper To: Andrii Nakryiko Cc: bpf , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Yonghong Song , KP Singh , Brendan Jackman , open list Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 15, 2021 at 12:57 AM Andrii Nakryiko wrote: > > On Wed, Apr 14, 2021 at 2:46 AM Florent Revest wrote: > > > > On Wed, Apr 14, 2021 at 1:16 AM Andrii Nakryiko > > wrote: > > > On Mon, Apr 12, 2021 at 8:38 AM Florent Revest wrote: > > > > + > > > > + return err + 1; > > > > > > snprintf() already returns string length *including* terminating zero, > > > so this is wrong > > > > lib/vsprintf.c says: > > * The return value is the number of characters which would be > > * generated for the given input, excluding the trailing null, > > * as per ISO C99. > > > > Also if I look at the "no arg" test case in the selftest patch. > > "simple case" is asserted to return 12 which seems correct to me > > (includes the terminating zero only once). Am I missing something ? > > > > no, you are right, but that means that bpf_trace_printk is broken, it > doesn't do + 1 (which threw me off here), shall we fix that? Answered in the 1/6 thread > > However that makes me wonder whether it would be more appropriate to > > return the value excluding the trailing null. On one hand it makes > > sense to be coherent with other BPF helpers that include the trailing > > zero (as discussed in patch v1), on the other hand the helper is > > clearly named after the standard "snprintf" function and it's likely > > that users will assume it works the same as the std snprintf. > > > Having zero included simplifies BPF code tremendously for cases like > bpf_probe_read_str(). So no, let's stick with including zero > terminator in return size. Cool :)