Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp52571pxm; Tue, 22 Feb 2022 06:14:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJwn9UtEdwiHkN7FRq7u7H2SZdh5MzhwYjNv+vZOXy+sbwA8/AAMbw9eTDnOB777teyARTxe X-Received: by 2002:a05:6402:278f:b0:410:d242:465e with SMTP id b15-20020a056402278f00b00410d242465emr27445691ede.292.1645539272506; Tue, 22 Feb 2022 06:14:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645539272; cv=none; d=google.com; s=arc-20160816; b=VRX/+daUpGPisIr6AkGbIsek5BkQZObz53Ta1clb9zxOaEPBePb+FnD0tTdHalF1UD ocGofKVfqeEIzD3g4uV6Q9OCRjoE1DiRSF0cHfcAF5uW51zjmdehVwJrCRmBeuKATSBM gMAp8Y+K5DdaesBNX1PsxCg79/ITu7KjF1LTp5VYs8ff3SDaNEYawbpNLnN6tiaGaUvU Jdl00dcs0s1iWuEu8teAS86xcBlXsNqwxeybgZzPWKX28TLRJhK5EIOKkTKSRXsbGmqJ 3ipthddvutRePxHGVrwdfodTH7h9kzuze55xNbSmY3MXEbTeRS1YOoV4U2PzeFrvR+I9 1r4g== 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=DSnVlm1pnvPlsXEUHsvfD8JkoYeM0OADeZxR4i9i5M8=; b=NoVkClXapmanN4v6opwfA41jzuEin2uX1ro2APrUQSwTBLFc04JgadgyyYtvcHJcrI jl2M5TezwGP6da4EtFhFAZtkK92nTGU+MxxUG3aZd5RV/x62g1nnJ1gG7XevXWefpFl9 Vbu1loJgIgnp/Mkbea05C4rzDI7YujRusBJUYQ+X486PWrzRX8ndwFhK885ojMDq7tvr tUK3GEkdmrQmb4Iy8x1ZYVFFkJM3j/zJC5EQe2XFK4pHGACBeYu0HuqJ5R9MfMOtVtv4 sJwFiff6dNSzHnB7zLGpKIrZdmw7qL4f5gu5dNbTQu2Uyi/H2Ff9F5jGQfiQs3aOnbxO v5jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=pVwCQv5L; 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 g5si12724362edy.70.2022.02.22.06.14.06; Tue, 22 Feb 2022 06:14:32 -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=pVwCQv5L; 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 S232006AbiBVMs5 (ORCPT + 99 others); Tue, 22 Feb 2022 07:48:57 -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-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" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 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