Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp5869010pxv; Wed, 7 Jul 2021 13:43:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw9ATLFXpK3B0ie2fBFaSoYXXeQeENnRDh3lWPiOrPF7yBuJXw7cWI53Bt2vKSN/rjhH0ie X-Received: by 2002:a05:6602:10e:: with SMTP id s14mr21751369iot.52.1625690625667; Wed, 07 Jul 2021 13:43:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625690625; cv=none; d=google.com; s=arc-20160816; b=Wz4Fz1MaQ3pDSGrZ+If7MFk2NrNH9aECkqpUfV8wTHqLDWsmvsNx9al/z2mIcGrmFc K6VVfYRMmbFstlWXXkwxx2P8BNBQlqkkXHAv/LYxYK8MVWkxM194FKXSSVz0wGUZB1fK G5lPZF3TUF8RBgrbbQqsX/sPoUgiFBHmcPqGMdPF6Hv1covYLJGaaHRIaUzMJywRbBAB h3eBYKMjvAO3PSN5xZr+VhS0EloF29CAbFMBeYkxIhIEROKxT3f4X0hhwU9fxKBeRWY/ yk10K6KRWTVn+gtGcvZZ6Dmcqj/603PBXYSyTazfJ2zUE0IGFmaKB19fvGNAysqXAaS/ AJbA== 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=WK/UppGz71jkba2Ll+L/TuQuuPyl95ERCqbRa/Kjsng=; b=Xur3FbYWZoSzw/IawBZg5I0udZ7vGw1qu+DX/k121eywE1rXUCZqn9sC8AEZr/VMqz RieoedY9+48rUoDVOWUla/KbHg9ehxnQyor5dMzI8mUrfuQTLVYD94VNVWQ7iv5E/NWY lCMm7mOyG3hynPiApDKNOiJZlTecz2qPYhO7oz1VWZ5ChsBG0SeZog9b7ncZf0CmibyR TIDXLXGLaOc0Im6poD0VmP0ApCzb24wKPcJS+1GFlFZHdguE04i4AEFIelhRTACrVK4r AtdxbOS72PasO6AbpAnZqq7Hvk0qm4pUFcNpp4Fn9QP0kFF8Alo+bQwrj0M7dg1Fiyl+ cg9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=FSqoFPJd; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z16si127352ilm.29.2021.07.07.13.43.33; Wed, 07 Jul 2021 13:43:45 -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=@google.com header.s=20161025 header.b=FSqoFPJd; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232066AbhGGUeY (ORCPT + 99 others); Wed, 7 Jul 2021 16:34:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230120AbhGGUeW (ORCPT ); Wed, 7 Jul 2021 16:34:22 -0400 Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EEB1FC061574 for ; Wed, 7 Jul 2021 13:31:40 -0700 (PDT) Received: by mail-lf1-x12d.google.com with SMTP id r26so7568026lfp.2 for ; Wed, 07 Jul 2021 13:31:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=WK/UppGz71jkba2Ll+L/TuQuuPyl95ERCqbRa/Kjsng=; b=FSqoFPJdoDp0fQFVFmgACdu+RsTBYS6NEnKKjiyts1bU2UXWQczZw6EcT+rtRpRZC9 /MrzUA7pCtAzqijIcSp1iBVFa0LsV1MryY0RUBPgg74FFM1PhinqG7lJ17YlbxIMxott XUqEZnTK3/EoGhPaPyCmuWHOC+UH3RkXbDwBa6AEw15C4LMzm8LDcK4ez0XWMdhKZHsb PpPd05Kyh6/UXVjhj/3jkQHTA5pxu2zjORv7VKHQ503Uxo+gOiKADo2lY4ObP/SoHPPa V98c7llgs4ePbWcMdO4yPJPF8tqfHlO20oo6ifhqNbh2KoJyNKW90Dn5oQ6N6r9fmUid NF+Q== 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=WK/UppGz71jkba2Ll+L/TuQuuPyl95ERCqbRa/Kjsng=; b=RQsS4WdLv8x+JTkPsEHNLlvK038C9XEOtdtie0JNyM9bvgvz9VgpxZoCcrxGeCkRRG 69vJuYjx9uDsBP0HJo/sM2Fpoav4x3cM7QhYac1oF8I5Af5PvRzlOWzYl2BfiSsigcwl 3lgaWaGm00BnezI23UqnPsNsDJr7m1ar6oftv5G5OdB3I99GzhwIHAMFL+E4VtY8VYN8 7rPUEN2wbbX2Bv1CnGmjaHpyyLU66Y7ZRFGz05Nr51GFu9nv7k5A8+blP3uPTvEa9YT/ kpvPEzRPVqZ/AoMJb7ngN1kSaCfwRHJhlMaFMP4BsFUm9EjijS+R1tsPxKagq6e+v7wY W55g== X-Gm-Message-State: AOAM533jotYoow49PXP15cUpZOux4km1OWlSJCJTW1QtvKEKgYaP2hzq AeHTRHODVUYyQC9GIpAZWY0H5Rjvq8AMT4CUcIwBjQ== X-Received: by 2002:a2e:8708:: with SMTP id m8mr20831340lji.244.1625689898523; Wed, 07 Jul 2021 13:31:38 -0700 (PDT) MIME-Version: 1.0 References: <20210704202756.29107-1-ojeda@kernel.org> <20210704202756.29107-5-ojeda@kernel.org> In-Reply-To: <20210704202756.29107-5-ojeda@kernel.org> From: Nick Desaulniers Date: Wed, 7 Jul 2021 13:31:18 -0700 Message-ID: Subject: Re: [PATCH 04/17] vsprintf: add new `%pA` format specifier To: ojeda@kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , rust-for-linux@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Alex Gaynor , Geoffrey Thomas , Finn Behrens , Adam Bratschi-Kaye , Wedson Almeida Filho , Boqun Feng , Sumera Priyadarsini , Michael Ellerman , Sven Van Asbroeck , Gary Guo , Boris-Chengbiao Zhou , Fox Chen , Ayaan Zaidi , Douglas Su , Yuki Okushi Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Jul 4, 2021 at 1:29 PM wrote: > > From: Miguel Ojeda > > This patch adds a format specifier `%pA` to `vsprintf` which formats > a pointer as `core::fmt::Arguments`. Doing so allows us to directly > format to the internal buffer of `printf`, so we do not have to use > a temporary buffer on the stack to pre-assemble the message on > the Rust side. > > This specifier is intended only to be used from Rust and not for C, so > `checkpatch.pl` is intentionally unchanged to catch any misuse. > > Co-developed-by: Alex Gaynor > Signed-off-by: Alex Gaynor > Co-developed-by: Geoffrey Thomas > Signed-off-by: Geoffrey Thomas > Co-developed-by: Finn Behrens > Signed-off-by: Finn Behrens > Co-developed-by: Adam Bratschi-Kaye > Signed-off-by: Adam Bratschi-Kaye > Co-developed-by: Wedson Almeida Filho > Signed-off-by: Wedson Almeida Filho > Co-developed-by: Boqun Feng > Signed-off-by: Boqun Feng > Co-developed-by: Sumera Priyadarsini > Signed-off-by: Sumera Priyadarsini > Co-developed-by: Michael Ellerman > Signed-off-by: Michael Ellerman > Co-developed-by: Sven Van Asbroeck > Signed-off-by: Sven Van Asbroeck > Co-developed-by: Gary Guo > Signed-off-by: Gary Guo > Co-developed-by: Boris-Chengbiao Zhou > Signed-off-by: Boris-Chengbiao Zhou > Co-developed-by: Fox Chen > Signed-off-by: Fox Chen > Co-developed-by: Ayaan Zaidi > Signed-off-by: Ayaan Zaidi > Co-developed-by: Douglas Su > Signed-off-by: Douglas Su > Co-developed-by: Yuki Okushi > Signed-off-by: Yuki Okushi > Signed-off-by: Miguel Ojeda > --- > lib/vsprintf.c | 12 ++++++++++++ > 1 file changed, 12 insertions(+) > > diff --git a/lib/vsprintf.c b/lib/vsprintf.c > index f0c35d9b65b..e7afe954004 100644 > --- a/lib/vsprintf.c > +++ b/lib/vsprintf.c > @@ -2182,6 +2182,10 @@ char *fwnode_string(char *buf, char *end, struct fwnode_handle *fwnode, > return widen_string(buf, buf - buf_start, end, spec); > } > > +#ifdef CONFIG_RUST > +char *rust_fmt_argument(char* buf, char* end, void *ptr); Which patch in the series adds the definition of rust_fmt_argument? Sorry, I haven't looked through the entire series yet, but I don't think it was an earlier patch in the series. If it's later in the series, you may want to rebase this to be after (or combine it with the patch that provides the definition). For instance, let's say the first half of this series was accepted/merged, but not the latter half. It would be weird to provide such definitions/calls to undefined symbols. > +#endif > + > /* Disable pointer hashing if requested */ > bool no_hash_pointers __ro_after_init; > EXPORT_SYMBOL_GPL(no_hash_pointers); > @@ -2335,6 +2339,10 @@ early_param("no_hash_pointers", no_hash_pointers_enable); > * > * Note: The default behaviour (unadorned %p) is to hash the address, > * rendering it useful as a unique identifier. > + * > + * There is also a '%pA' format specifier, but it is only intended to be used > + * from Rust code to format core::fmt::Arguments. Do *not* use it from C. > + * See rust/kernel/print.rs for details. > */ > static noinline_for_stack > char *pointer(const char *fmt, char *buf, char *end, void *ptr, > @@ -2407,6 +2415,10 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr, > return device_node_string(buf, end, ptr, spec, fmt + 1); > case 'f': > return fwnode_string(buf, end, ptr, spec, fmt + 1); > +#ifdef CONFIG_RUST > + case 'A': > + return rust_fmt_argument(buf, end, ptr); > +#endif > case 'x': > return pointer_string(buf, end, ptr, spec); > case 'e': > -- > 2.32.0 > -- Thanks, ~Nick Desaulniers