From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5FA8FC433EF for ; Tue, 22 Feb 2022 12:48:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232021AbiBVMs6 (ORCPT ); Tue, 22 Feb 2022 07:48:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229524AbiBVMsx (ORCPT ); Tue, 22 Feb 2022 07:48:53 -0500 Received: from mail-io1-xd2d.google.com (mail-io1-xd2d.google.com [IPv6:2607:f8b0:4864:20::d2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A512128646; Tue, 22 Feb 2022 04:48:28 -0800 (PST) Received: by mail-io1-xd2d.google.com with SMTP id w7so19919985ioj.5; Tue, 22 Feb 2022 04:48:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=DSnVlm1pnvPlsXEUHsvfD8JkoYeM0OADeZxR4i9i5M8=; b=pVwCQv5LBjsugdh+7vDCxpRlDakRlPHpcVYS8tNW8pAOjg+z5UXxPH9KtjReUVspDH Xlfpr3EN3JWcTSBFJLdLS8u6YjZHlTk1L/OEJs4eLICN6n/ia+kkfMFtVXQeFLS23053 wLtnQEQ/YJessaHF9AdF+vjTTzcFA88aJQ9UGlvwOwHXx6htqafubgm49xR038VdF/c4 Q5AIMyTEtWe/TEpUOVtYJ4gu6lldqKNFLKp7gDYJK2YvUsstj08UQnEK1FnOnTGwDGfN bErnvwYFMLOdqLwHtaDRJ9lYE4ABozPUPGe3hbaMQQgWKttIel+qOoqQE/bKTpgoNnWP r6lA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=DSnVlm1pnvPlsXEUHsvfD8JkoYeM0OADeZxR4i9i5M8=; b=qiF5qx4g1Z3suG9dL0ALMBcLeIVZyoQKYGRvjZMDueM/2g6ckb8Etw8lOSoa24fBe+ sVhGfzUvIH/5DgmiJMvWefcMTB7RvyMRKiHqvFGSr2UMvFglF0KXW635etsp9ROpi4Sc bAp1EE7W3FyDrsLwCAKMHok583qLWhKFeckrdkVKTosY7rRQCUhFGUc1JKtv1tLHbSM1 BZKnaPZkU8W5zUdAXieKES3Tc6RW33web+BiN/iAE80ruYwD475Q/AjUVteuLbrFb/gE N4jNYUMd/xG1ljU/g5E4PYtJlXUOtUIpEpivbxUYrDGlBKStIlgzhXVW8Ellw2joysYP P6WA== X-Gm-Message-State: AOAM53183pK1j4Hb61IT5N+yKrEt1nwbLyOaxPoeWP4FWWXkGOzyHzOr csXeIABkb/ZvFV/fH4o4SrTgLA2Xoxwd9BIFCHo= X-Google-Smtp-Source: ABdhPJyfjGzROAJYPQ75otU9qXSyZlq6fGWMQ1NrI71zYpxlJZGh8wVIUJ1plAwh/v24/ZvWPEvlbG+T2j9kl4CGRyY= X-Received: by 2002:a05:6638:1117:b0:30d:1e9f:26ca with SMTP id n23-20020a056638111700b0030d1e9f26camr19007788jal.256.1645534107755; Tue, 22 Feb 2022 04:48:27 -0800 (PST) MIME-Version: 1.0 References: <20220212130410.6901-1-ojeda@kernel.org> <20220212130410.6901-11-ojeda@kernel.org> In-Reply-To: From: Miguel Ojeda Date: Tue, 22 Feb 2022 13:48:16 +0100 Message-ID: Subject: Re: [PATCH v4 10/20] rust: add `kernel` crate To: Petr Mladek Cc: Miguel Ojeda , Linus Torvalds , Greg Kroah-Hartman , rust-for-linux , linux-kernel , Wedson Almeida Filho , Alex Gaynor , Geoffrey Thomas , Finn Behrens , Adam Bratschi-Kaye , Michael Ellerman , Sumera Priyadarsini , Sven Van Asbroeck , Gary Guo , Boris-Chengbiao Zhou , Boqun Feng , Fox Chen , Dan Robertson , Viktor Garske , Dariusz Sosnowski , =?UTF-8?Q?L=C3=A9o_Lanteri_Thauvin?= , Niklas Mohrin , Gioh Kim , Daniel Xu , Milan Landaverde , Morgan Bartlett , Maciej Falkowski , Jiapeng Chong , Sergey Senozhatsky , Steven Rostedt , John Ogness Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Petr, On Tue, Feb 22, 2022 at 10:06 AM Petr Mladek wrote: > > What exactly should we keep in sync, please? > > I see only handling of KERN_* prefix in print.rs. I do not see there > any counter part of LOG_LINE_MAX, CONSOLE_LOG_MAX, or PREFIX_MAX. Good catch! We had a buffer on the Rust side in the past, but that is not the case anymore since commit 9e8bd679ecf2 ("Support Rust `core::fmt::Argument` in vsprintf") on our side, so we will remove the comment. > I am sorry but I am not familiar with rust. What are these limits > 2 and 10 used for, please? > > I guess that 2 is the size of a single KERN_* identifier. > But what is 10? > > Note that printk() format prefix is typically just a single KERN_* > identifier. But there might be more. Well, in practice only the > following combination makes sense: KERN_CONT + KERN_. What we are doing here is generating compile-time format strings that are then used by the `pr_*!` macros (which call the C side `printk()` with one of the strings). In other words, this is not parsing arbitrary `printk()` format strings (which I am guessing something like that is your concern -- please let me know if I got it wrong). To clarify a bit what the code does and what the constants are: - `generate()` is called at compile-time. - The size of these generated strings is always 10. - We compose those strings by using the first 2 bytes of `KERN_*`. However, we also take the chance to check (at compile-time) they have the contents we expect, including the third zero byte. - Then other 8 bytes are used to complete the 10: either "%pA" plus 0 padding (`CONT` level) or "%s: %pA" (otherwise). > Finally, is there any way to test whether any change in the printk > code breaks the rust support? One way is to compile the code, e.g. the `assert!`s in the `generate` function run at compile-time, thus they provide a first layer of defense. Another way is to use `samples/rust/print.rs` which we run in the CI as a black box test. Is that what you had in mind? Or something like unit tests or self tests? Thanks for taking a look! Cheers, Miguel