Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp5995658rwb; Mon, 14 Nov 2022 12:36:50 -0800 (PST) X-Google-Smtp-Source: AA0mqf4R86+0oKnmIQWE2Uot6bHy3xf5Juu1fcaXxee26vk1jOy2kzCE12mvrr3d+vZEieMvtfLT X-Received: by 2002:a63:d813:0:b0:460:ea44:226b with SMTP id b19-20020a63d813000000b00460ea44226bmr13447747pgh.137.1668458209776; Mon, 14 Nov 2022 12:36:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668458209; cv=none; d=google.com; s=arc-20160816; b=v8jzhzQpAR3fQVtM3m8J7uvTA6rjMrFjjb+VWR5ZohsTQkyghoTR1eGEXTD/y8Gxjq D34Z6UX5Tv31mnNCCl31DZ0Hbg1rIsYR9OkjvmNGpRNnWd+Kt2aQmzzMr/Bp5WXSEAJL SPaaOhTx5pho8Wa+6r6jJiIgaH1DAsk3EQ7shMSkiJV5Lb5eHMt3IN3PJJyhlLyhnBfS hPcixV76BR2qGT5XtY7f+5xZXM9QEzOl7cE2bwAv8EkYrX8FEpcNSgzitN7wT1clXJnp CN0fFG7vjfPuMXSkiK32biYMT/Z1LAtYR9szYtoeIoQajVhZYz/oXWlTt/uHKDpyCdKl SQ9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=6ovN/KmE3k+WBFZFXF8j1G39y12WeXYLS+PvRskBsx0=; b=HzLP8E9Z1IzXxkz0oBFu5I0iisi9UIOHm7ZKyXZsJcUEgEz7qO7X6BmBdcE/7//+H5 vZs210n/XhvgWK3g5vjcFdTBDNekgqOXrKGguYhWjGCsUtg9e8mSleReX6YMZiFhlT7D +fFbGhjRhotMZyBpugofOm3yhe7C0iru17vvqUHR8oNSlYHH9YMr2AVCVUaY+2jd+tSC T8cZlXSM1NxukXvhgnX/ZuXKeV2+IZhtxfqYiwoJ178pXEV6KIDuW5sB8cr+yfFECfI3 a0eu5NnUfcJivBjAlOsanNkuJFQrfGTk8uAMkDWZSuYj9o/YKKnCeSYnPrBjUHdr1Jc/ eklw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=GuJ0+9mU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h69-20020a638348000000b0045f5e2b350esi9528987pge.466.2022.11.14.12.36.37; Mon, 14 Nov 2022 12:36:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=GuJ0+9mU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S236162AbiKNUMO (ORCPT + 88 others); Mon, 14 Nov 2022 15:12:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237610AbiKNUMH (ORCPT ); Mon, 14 Nov 2022 15:12:07 -0500 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDC491B7A9; Mon, 14 Nov 2022 12:12:04 -0800 (PST) Received: by mail-ej1-x62f.google.com with SMTP id n12so31023996eja.11; Mon, 14 Nov 2022 12:12:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=6ovN/KmE3k+WBFZFXF8j1G39y12WeXYLS+PvRskBsx0=; b=GuJ0+9mUHfci0E4m5LUtezP8A7urTPPz7Xe9SGVcUwua0Ng41nRyDaobl9GxxbigEb DLGt9yaDZzJFUN9+IZC0rS8UvY+H3AUFKSZTqzE0W0lshN3CKl8QaLj/xcii3z5FGGoX JnTESJZXxSBAnQmNzuJQENTcePLRqby1foUR6IAe4aVvzYNmUiDPv//e0a6rHGP7c+ru Op16OpgovM1WUmUDedkKCHGsHfXlIbV+Y1JjAdA6dj3b0XTsEj7EzSLwoSbwnJMRZWbY WFi+j+6wcgA6uSBApRUyZA4JWlnNEpHNs7StKbZ3iXvxRMFK+1eFU/AqYIVXXE13Fkr9 pADA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6ovN/KmE3k+WBFZFXF8j1G39y12WeXYLS+PvRskBsx0=; b=Yeg5J1ZnqyGpLrd0EFwuEcQkmz9XhW0a6oi+QHfnm87CIRf7my6dL2x3uB67L616Sw 1rKwhUnTUs6tCVN4ursZ9iNJul66NErpZLwfsJ8L0q+M4AMecFajJnUKQAXMUg2YdLH4 F+S5FTCSLTJz7AtYeW0r129xsMF8FrgF1EA0I304oUY2wLH8+M7i3TVPJJKrgCODPZVg q0KC2JJtTUemKT5E55gtEuVHMl3sjHpWCuvDYi0R3BD1bmWM3syVhp+Ut+GOpI/6ydp0 4Qq/QavQ86mtiPrDa4dYRjudRyhBq7HycR09hqwfxvKdpBdjVf4uq2pBPbzR1RbKg5mE Z95A== X-Gm-Message-State: ANoB5pkRVthz+gq/tofISm/zHWN1BhdVaEBmYFM0Ob3EUUceKsHTP+1M rp1C05+loKxHCsbsIwYLVLknUM0scpmhMZ9xNJQ= X-Received: by 2002:a17:906:68c4:b0:7ad:d662:f568 with SMTP id y4-20020a17090668c400b007add662f568mr10962621ejr.616.1668456723383; Mon, 14 Nov 2022 12:12:03 -0800 (PST) MIME-Version: 1.0 References: <20221110164152.26136-1-ojeda@kernel.org> <20221110164152.26136-4-ojeda@kernel.org> In-Reply-To: <20221110164152.26136-4-ojeda@kernel.org> From: =?UTF-8?Q?Sergio_Gonz=C3=A1lez_Collado?= Date: Mon, 14 Nov 2022 10:04:14 -0500 Message-ID: Subject: Re: [PATCH v1 03/28] rust: print: add `pr_cont!` macro To: Miguel Ojeda Cc: Wedson Almeida Filho , Alex Gaynor , Boqun Feng , Gary Guo , =?UTF-8?Q?Bj=C3=B6rn_Roy_Baron?= , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, Adam Bratschi-Kaye Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.5 required=5.0 tests=BAYES_00,DATE_IN_PAST_03_06, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 10 Nov 2022 at 11:43, Miguel Ojeda wrote: > > This level is a bit different from the rest since it does not > pass the module name to the `_printk()` call. > > Thus add a new parameter to the general `print_macro!` to > handle it differently. > > 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: Gary Guo > Signed-off-by: Gary Guo > Signed-off-by: Miguel Ojeda > --- > rust/kernel/print.rs | 72 ++++++++++++++++++++++++++++++++++++++------ > 1 file changed, 63 insertions(+), 9 deletions(-) > > diff --git a/rust/kernel/print.rs b/rust/kernel/print.rs > index 694f51c6da5c..29bf9c2e8aee 100644 > --- a/rust/kernel/print.rs > +++ b/rust/kernel/print.rs > @@ -81,6 +81,7 @@ pub mod format_strings { > pub static NOTICE: [u8; LENGTH] =3D generate(false, bindings::KERN_N= OTICE); > pub static INFO: [u8; LENGTH] =3D generate(false, bindings::KERN_INF= O); > pub static DEBUG: [u8; LENGTH] =3D generate(false, bindings::KERN_DE= BUG); > + pub static CONT: [u8; LENGTH] =3D generate(true, bindings::KERN_CONT= ); > } > > /// Prints a message via the kernel's [`_printk`]. > @@ -111,6 +112,26 @@ pub unsafe fn call_printk( > } > } > > +/// Prints a message via the kernel's [`_printk`] for the `CONT` level. > +/// > +/// Public but hidden since it should only be used from public macros. > +/// > +/// [`_printk`]: ../../../../include/linux/printk.h > +#[doc(hidden)] > +#[cfg_attr(not(CONFIG_PRINTK), allow(unused_variables))] > +pub fn call_printk_cont(args: fmt::Arguments<'_>) { > + // `_printk` does not seem to fail in any path. > + // > + // SAFETY: The format string is fixed. > + #[cfg(CONFIG_PRINTK)] > + unsafe { > + bindings::_printk( > + format_strings::CONT.as_ptr() as _, > + &args as *const _ as *const c_void, > + ); > + } > +} > + > /// Performs formatting and forwards the string to [`call_printk`]. > /// > /// Public but hidden since it should only be used from public macros. > @@ -120,7 +141,7 @@ pub unsafe fn call_printk( > #[allow(clippy::crate_in_macro_def)] > macro_rules! print_macro ( > // The non-continuation cases (most of them, e.g. `INFO`). > - ($format_string:path, $($arg:tt)+) =3D> ( > + ($format_string:path, false, $($arg:tt)+) =3D> ( > // SAFETY: This hidden macro should only be called by the docume= nted > // printing macros which ensure the format string is one of the = fixed > // ones. All `__LOG_PREFIX`s are null-terminated as they are gen= erated > @@ -134,6 +155,13 @@ macro_rules! print_macro ( > ); > } > ); > + > + // The `CONT` case. > + ($format_string:path, true, $($arg:tt)+) =3D> ( > + $crate::print::call_printk_cont( > + format_args!($($arg)+), > + ); > + ); > ); > > /// Stub for doctests > @@ -174,7 +202,7 @@ macro_rules! print_macro ( > #[macro_export] > macro_rules! pr_emerg ( > ($($arg:tt)*) =3D> ( > - $crate::print_macro!($crate::print::format_strings::EMERG, $($ar= g)*) > + $crate::print_macro!($crate::print::format_strings::EMERG, false= , $($arg)*) > ) > ); > > @@ -198,7 +226,7 @@ macro_rules! pr_emerg ( > #[macro_export] > macro_rules! pr_alert ( > ($($arg:tt)*) =3D> ( > - $crate::print_macro!($crate::print::format_strings::ALERT, $($ar= g)*) > + $crate::print_macro!($crate::print::format_strings::ALERT, false= , $($arg)*) > ) > ); > > @@ -222,7 +250,7 @@ macro_rules! pr_alert ( > #[macro_export] > macro_rules! pr_crit ( > ($($arg:tt)*) =3D> ( > - $crate::print_macro!($crate::print::format_strings::CRIT, $($arg= )*) > + $crate::print_macro!($crate::print::format_strings::CRIT, false,= $($arg)*) > ) > ); > > @@ -246,7 +274,7 @@ macro_rules! pr_crit ( > #[macro_export] > macro_rules! pr_err ( > ($($arg:tt)*) =3D> ( > - $crate::print_macro!($crate::print::format_strings::ERR, $($arg)= *) > + $crate::print_macro!($crate::print::format_strings::ERR, false, = $($arg)*) > ) > ); > > @@ -270,7 +298,7 @@ macro_rules! pr_err ( > #[macro_export] > macro_rules! pr_warn ( > ($($arg:tt)*) =3D> ( > - $crate::print_macro!($crate::print::format_strings::WARNING, $($= arg)*) > + $crate::print_macro!($crate::print::format_strings::WARNING, fal= se, $($arg)*) > ) > ); > > @@ -294,7 +322,7 @@ macro_rules! pr_warn ( > #[macro_export] > macro_rules! pr_notice ( > ($($arg:tt)*) =3D> ( > - $crate::print_macro!($crate::print::format_strings::NOTICE, $($a= rg)*) > + $crate::print_macro!($crate::print::format_strings::NOTICE, fals= e, $($arg)*) > ) > ); > > @@ -319,7 +347,7 @@ macro_rules! pr_notice ( > #[doc(alias =3D "print")] > macro_rules! pr_info ( > ($($arg:tt)*) =3D> ( > - $crate::print_macro!($crate::print::format_strings::INFO, $($arg= )*) > + $crate::print_macro!($crate::print::format_strings::INFO, false,= $($arg)*) > ) > ); > > @@ -346,7 +374,33 @@ macro_rules! pr_info ( > macro_rules! pr_debug ( > ($($arg:tt)*) =3D> ( > if cfg!(debug_assertions) { > - $crate::print_macro!($crate::print::format_strings::DEBUG, $= ($arg)*) > + $crate::print_macro!($crate::print::format_strings::DEBUG, f= alse, $($arg)*) > } > ) > ); > + > +/// Continues a previous log message in the same line. > +/// > +/// Use only when continuing a previous `pr_*!` macro (e.g. [`pr_info!`]= ). > +/// > +/// Equivalent to the kernel's [`pr_cont`] macro. > +/// > +/// Mimics the interface of [`std::print!`]. See [`core::fmt`] and > +/// `alloc::format!` for information about the formatting syntax. > +/// > +/// [`pr_cont`]: https://www.kernel.org/doc/html/latest/core-api/printk-= basics.html#c.pr_cont > +/// [`std::print!`]: https://doc.rust-lang.org/std/macro.print.html > +/// > +/// # Examples > +/// > +/// ``` > +/// # use kernel::pr_cont; > +/// pr_info!("hello"); > +/// pr_cont!(" {}\n", "there"); > +/// ``` > +#[macro_export] > +macro_rules! pr_cont ( > + ($($arg:tt)*) =3D> ( > + $crate::print_macro!($crate::print::format_strings::CONT, true, = $($arg)*) > + ) > +); > -- > 2.38.1 > Reviewed-by: Sergio Gonz=C3=A1lez Collado