Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp1360199pxy; Fri, 23 Apr 2021 06:27:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzDl7ZuTre7hFJNq8yMAyduxl5bpZPMalSTCNEZWx+g3O0/bzc4vVWe0LK2Q6+8AEe+6Dfr X-Received: by 2002:a17:90a:6396:: with SMTP id f22mr5772299pjj.91.1619184451601; Fri, 23 Apr 2021 06:27:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619184451; cv=none; d=google.com; s=arc-20160816; b=ShvYUQYLdjOeXstZN1woyrWBAUYqlxF20OLSj6dcnh2TpomfQ5uSqhO2/TGggIv9PG w5FWZNbOf+PRNXGNSFGsaEHS4cu2R+wqXU6V0h0yVV5MUUN+Lb/P1m9zpMRmfQetf5mr 8M/S1h51e9RhlaC7ymQO8wyF/+ylopLIsBFr+QTUxU+8TmuKTulm26IXqpF/Neh2BSZU V4fS3jVwX5C1SEhkLyvjvPoVwZ00fqvp77zJ06Od1kk5vDp6dbWq0W9Z/EtuMDbdVQNb 8kWlBV6sfT8nxuvXJEZ0QsZntWouDYmuRdBEwoTZMm5Nq8sFi37WhH4YbHucQqIks5R6 dkeg== 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=W9t1u365J/63AT2Wytry3Gy5TCslV9JQ80oTdyfzGqA=; b=R9NlInrhXfJOBlJPCKFajQPQ54wusuzRg4/hHfTJeWo5yHEvh06c/531qFBEGmMQfa aBZTedKQrrwGD1WO3xn2YVDOzyow2rgsFTjPizq2rSJ5RLcEIbBqE+D2y01875vL1Ons Sb8AZiS8aV1cyxjNgltrT1ZQO46bRrlaImo1Qn9EtQAZONGV57lllzZJIfzuGyQMGjxt oPQamyHQQ84RbEFGPYXkMGg7YuO1IqFjhaiK+9mpWY4CqeL4kF1qQLFNvsnSHNxl9Owd osI6G2rtaxqaCict3zZ1cr4OFEsQX+62BxGbgMtuXt7TRuoO8i8fAk3PeWY6stW65WVZ bIRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="PZG/CKA0"; 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 p15si6720213pgk.50.2021.04.23.06.27.18; Fri, 23 Apr 2021 06:27:31 -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="PZG/CKA0"; 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 S229976AbhDWN1H (ORCPT + 99 others); Fri, 23 Apr 2021 09:27:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229456AbhDWN1H (ORCPT ); Fri, 23 Apr 2021 09:27:07 -0400 Received: from mail-io1-xd29.google.com (mail-io1-xd29.google.com [IPv6:2607:f8b0:4864:20::d29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0CBCCC061574 for ; Fri, 23 Apr 2021 06:26:30 -0700 (PDT) Received: by mail-io1-xd29.google.com with SMTP id f21so12772477ioh.8 for ; Fri, 23 Apr 2021 06:26:30 -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=W9t1u365J/63AT2Wytry3Gy5TCslV9JQ80oTdyfzGqA=; b=PZG/CKA0JMPJkboWk7lRr/z0ls0N6+Pb8D2Kj9oBOVyMRu/HgkUZlnAgMHgVxAUc/V w9xz/OgZ3w2YCLWxiezZP4JEOhkC1vASKWmffk6HsIjQJ+H7uZuo2G3DqJoRBYHv6PE4 xTtuaua32tjtoTPLNLl33OjiJvscXab45quB8= 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=W9t1u365J/63AT2Wytry3Gy5TCslV9JQ80oTdyfzGqA=; b=BjsK9/bCf4PqMp6ZgQ9ycFQ0GeIxEPR6xO8t2ZkpLSR0rVs3Fff60T5Zm5hWlkgewW yM5TAO1yHmt5ojgM3aUyp1l8WbBMC9AaWku9ihHK20QGyICGEbPAPjegTNmTnE2Jz82W ICDGgiBZBmKVtvANzf8SH20ntzU+H0vrcstKthd9waVxAKWXM/zOwJ6O77DhPUjT+zW0 xnMvmZrm0n085t8ehmMoXKpHHUdB4f3UBS0lTNAedD5pngEwuBM5PnFAgPo5cgxpBAqQ i0Cxm1t3XfjVIzPbw7cQP+KnUFFVMi1KD4zj9UzCC5RN4alWcaoTUby4kXbfKEAr6khn +Pdg== X-Gm-Message-State: AOAM530U2/O6gCjFeul7/u6BlMDDQp8tGhJSb+5i5o7Zh6o/+lnBxyGi ywkrET4VhoS6+iedrE2mGVqwzc9+70hf4+/eYoCSQg== X-Received: by 2002:a05:6638:2515:: with SMTP id v21mr3691903jat.110.1619184389457; Fri, 23 Apr 2021 06:26:29 -0700 (PDT) MIME-Version: 1.0 References: <20210423011517.4069221-1-revest@chromium.org> <8f89faf1-d7e6-ebe0-fb7d-c5b8243d140a@rasmusvillemoes.dk> In-Reply-To: <8f89faf1-d7e6-ebe0-fb7d-c5b8243d140a@rasmusvillemoes.dk> From: Florent Revest Date: Fri, 23 Apr 2021 15:26:18 +0200 Message-ID: Subject: Re: [PATCH bpf-next 0/2] Implement BPF formatted output helpers with bstr_printf To: Rasmus Villemoes Cc: bpf , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , 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 Fri, Apr 23, 2021 at 10:50 AM Rasmus Villemoes wrote: > > On 23/04/2021 03.15, Florent Revest wrote: > > Our formatted output helpers are currently implemented with > > snprintf-like functions which take arguments as va_list but the types > > stored in a va_list need to be known at compilation time which causes > > problems when dealing with arguments from the BPF world that are always > > u64 but considered differently depending on the format specifiers they > > are associated with at runtime. > > > > This series replaces snprintf usages with bstr_printf calls. This lets > > us construct a binary representation of arguments in bpf_printf_prepare > > at runtime that matches an ABI that is neither arch nor compiler > > specific. > > > > This solves a bug reported by Rasmus Villemoes that would mangle > > arguments on 32 bit machines. > > That's not entirely accurate. The arguments are also mangled on x86-64, > it's just that in a few cases that goes unnoticed. That's why I > suggested you try and take your test case (which I assume had been > passing with flying colours on x86-64) and rearrange the specifiers, > arguments and expected output string so that the (morally) 32 bit > arguments end up beyond those-that-end-up-in-the-reg_save_area. > > IOWs, it is the 32 bit arguments that are mangled (because they get > passed as-if they were actually 64 bits), and that applies on all > architectures; nothing to do with sizeof(long). Mh, yes, I get your point and I agree that my description does not really fit what you reported. I tried what you suggested though, with the current bpf-next/master on x86_64: BPF_SNPRINTF(out, sizeof(out), "%u %d %u %d %u %d %u %d %u %d %u %d", 1, -2, 3, -4, 5, -6, 7, -8, 9, -10, 11, -12); And out is "1 -2 3 -4 5 -6 7 -8 9 -10 11 -12" so i can't seem to be able to produce the bug you described. Do you think I'm missing something? Would you try it differently ?