Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp595231pxu; Fri, 11 Dec 2020 09:31:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJwXmkDTNev+9Zwgjmzsqua+gvXSZtpOJLrh/xIQ6ztpoldU7cAhwXODLuDk2bD/ZlqDEwAx X-Received: by 2002:a05:6402:30ac:: with SMTP id df12mr13399514edb.175.1607707898813; Fri, 11 Dec 2020 09:31:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607707898; cv=none; d=google.com; s=arc-20160816; b=RQp7vwFZTY0T2nR28rWVaosLmLNG1Q1D/o8wUN5qvc41ivKsR/NI8CVht9p5HqkCwu CN6ZiGe3aDHQyH7/ELpQtFQnJHi6Fm2DYSqlo/99jKPxp9TuamBwqXfR3TiJkRtJkVFe 1L6LX290TM2lgAJH0a+64Hm8cFUgQYOlmsJvKwvIhfmJQvEmrC0JE4yeMaQC21bwBszP zMCzI2OO2l/HqEBAxOUeZxmzJS93mH8AdDfg9d3ocjvcbfn46SPGkqB8NO3DgYarasrD YAtJijsXXt6bV15EeOjJ3rJnsQ3wufZfStnIsTsmmfY3zbbpoCyLeTO4R+jdDFMTsK1p 7M2Q== 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=1h5XSPlxBUAGIpDD6oUcqWJAS8gNOKHKgcM+M6tRgfA=; b=DowGOnAuboLnwwu7CcSb78FwiRM7+TReuDg7AhHezBYaiGcdQ/EaavfngTjkIabrBD bNPHU1LiQYYUtPST2BTEsYhzgtgs+6grnDFoOnzSxfQrdLKZ9jfntlnJrGY+rzJ77V4i n/qEBZ/a3YQdyVMYeJHkvpAFnmWXThTOlwppv11NGtIYtXchcxxYpvyBYuQtEfxsrre3 r3HJGbzMvSLhhCFA4zKCtEtun3VyZZY6gKyb0Xx2vKWD/eyX/Floq1E50guo20pPjh94 o0CAQvpkFBA/llMWLYy+4nY+avGfIpBKPugjHLPNY+4lP/XR8Xz9pit7gh1quxTlC/WF sTfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=daMZ90XZ; 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 hq10si4868489ejc.616.2020.12.11.09.31.14; Fri, 11 Dec 2020 09:31:38 -0800 (PST) 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=daMZ90XZ; 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 S2394795AbgLKOlp (ORCPT + 99 others); Fri, 11 Dec 2020 09:41:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390253AbgLKOlX (ORCPT ); Fri, 11 Dec 2020 09:41:23 -0500 Received: from mail-il1-x141.google.com (mail-il1-x141.google.com [IPv6:2607:f8b0:4864:20::141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4677C0613D6 for ; Fri, 11 Dec 2020 06:40:42 -0800 (PST) Received: by mail-il1-x141.google.com with SMTP id c18so8963593iln.10 for ; Fri, 11 Dec 2020 06:40:42 -0800 (PST) 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=1h5XSPlxBUAGIpDD6oUcqWJAS8gNOKHKgcM+M6tRgfA=; b=daMZ90XZ7NG9OuBhNiKSIaPPKcnzqc9MvC3Id1B4HJXdiIHI9KemCaJ0p3X8Qh05TG FXFS0Da7TeaP8i2IrkytZR86/ZlzVPRT0yNtqmcNv6EADPQBCc/WWX+gzaRdgcj6Dice Y2+dal9jJKpRBuGcmVDkwb1XNu2ZYyHFuk1VU= 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=1h5XSPlxBUAGIpDD6oUcqWJAS8gNOKHKgcM+M6tRgfA=; b=S+lPDfgeutrku1zan1QxpLfW2QbS+WASbOCOO/PIK0mbCRPXqWqCCnCa90P8QSK1nk t4eo8ELa+INm+Aqcra2vNG5+qoUWakncBlhuJWCOk2/NEfivojX9+8zNhCal1IYxmSs7 JWJxXiHAxPKedenJwG12Z/YbcdSTPpITLPzcEh6oGu4xlLYY+U0uBHiz3FilLadsQ4Hh FBQDD0M7OqcJJUBv4GT7UOHvJhdux+ubJsY0wakyDSZWQEJT7paZTHh6n/hEhglrTexC 5easr+pluUsQui8LXW0RQzvHjwudT3X5lL05nOMOmokv36r/mXlbGMPVtKP5j3N0nRkC Rkug== X-Gm-Message-State: AOAM532N7c8DXGZKWNNiitrS6GdemMdrfo3BhxZPY+QM/Ldtrx7acB+8 41jG5X2DNaOIgiiCNNSEsMo7R3c0Bz52fDZsiMLykg== X-Received: by 2002:a92:4c3:: with SMTP id 186mr16661316ile.177.1607697642071; Fri, 11 Dec 2020 06:40:42 -0800 (PST) MIME-Version: 1.0 References: <20201126165748.1748417-1-revest@google.com> <50047415-cafe-abab-a6ba-e85bb6a9b651@fb.com> <194b5a6e6e30574a035a3e3baa98d7fde7f91f1c.camel@chromium.org> In-Reply-To: From: Florent Revest Date: Fri, 11 Dec 2020 15:40:31 +0100 Message-ID: Subject: Re: [PATCH bpf-next 1/2] bpf: Add a bpf_kallsyms_lookup helper To: Alexei Starovoitov Cc: Andrii Nakryiko , Yonghong Song , KP Singh , bpf , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Florent Revest , open list Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Dec 2, 2020 at 10:18 PM Alexei Starovoitov wrote: > I still think that adopting printk/vsnprintf for this instead of > reinventing the wheel > is more flexible and easier to maintain long term. > Almost the same layout can be done with vsnprintf > with exception of \0 char. > More meaningful names, etc. > See Documentation/core-api/printk-formats.rst I agree this would be nice. I finally got a bit of time to experiment with this and I noticed a few things: First of all, because helpers only have 5 arguments, if we use two for the output buffer and its size and two for the format string and its size, we are only left with one argument for a modifier. This is still enough for our usecase (where we'd only use "%ps" for example) but it does not strictly-speaking allow for the same layout that Andrii proposed. > If we force fmt to come from readonly map then bpf_trace_printk()-like > run-time check of fmt string can be moved into load time check > and performance won't suffer. Regarding this bit, I have the impression that this would not be possible, but maybe I'm missing something ? :) The iteration that bpf_trace_printk does over the format string argument is not only used for validation. It is also used to remember what extra operations need to be done based on the modifier types. For example, it remembers whether an arg should be interpreted as 32bits or 64bits. In the case of string printing, it also remembers whether it is a kernel-space or user-space pointer so that bpf_trace_copy_string can be called with the right arg. If we were to run the iteration over the format string in the verifier, how would you recommend that we "remember" the modifier type until the helper gets called ?