Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp2366132lqz; Tue, 2 Apr 2024 15:35:57 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXFvDZMUBNgGeS3f8ddgPVInI0W5JYJLeiB5ETqmNR1GD7bc+JfYiShyBJ6yBnh+9jdD4mCPeMaVaL4vRl3BdD5W7Tyu3phMGI2w7z0iw== X-Google-Smtp-Source: AGHT+IFx4y71ERk6sprxNPtDeOEfteWnGGrfw9pd11r0nULHoNX5sRYsxaUeH0Er+wee5tvjUMaH X-Received: by 2002:a05:620a:905:b0:78a:6aa8:f239 with SMTP id v5-20020a05620a090500b0078a6aa8f239mr1465735qkv.25.1712097357291; Tue, 02 Apr 2024 15:35:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712097357; cv=pass; d=google.com; s=arc-20160816; b=RXZwEl1Fbfm7824oRe2uu5WIx5yIjlZ4pbSn2vtGfnA0QE0G5USC/x1eB+f1vDgcgv ts06dVM5tJsdyh+CLP4W6zKv9qK10Ci/iB7GXMDNpvxFAypcRWgZRl1OPLXOAE8ddRa0 2yKQcTXBmLQd3mMSjEA7nADvaDrc18L3CiH2xZuE9fUb6A3CyVs1HZ2yP5zAQS9mGHsP hnhVqgPkVMaf9Xj0Durxr36oFfqZCLMZPvAWwhCCcKNMPJjtxxMEnj5H8RWfJxW3dYSW 4hov+DcLs15EpNnxe/X7lLP7PKtq9MiTK97TD1qBZ34cMN1Fb+pOF63CyjdNcXIi+1A+ Fbsg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:feedback-id:references :in-reply-to:message-id:subject:cc:from:to:date:dkim-signature; bh=ZR6oanZJrjCoyu/0f+lqsJmEQvmkfNvERkB55FpMbLg=; fh=lLUD0Y0lftUliXRu0ABC3iCsqeJl3bPdDmGTUCgf9RI=; b=bnHxtvuT/eLC1PEHG9rvr8nTgBVlFWC/9eAFxQvMF2AIjU4jQbLn7TPI0klgcnTJNu nO1RlKI9oGTmq5WYSK3rt/IukQkKtyiW6pRDMjxpOKd08sgpb9761ZlQhKxdSRWOmyRO SMHzu+3A8WQ8k7POKsuqG4gq/6WfT00e0hBn0a75LqJhlmByqzc5x1kwaGSV0eaBSm7f Q2r4WROeWrriAHUUxWWKSc/AW6WcHHu45MKTPV09zlu5Z7fwbcZrSXeUBa0yf2JNew/G yZ/YPS5JBQDI5LMuFl7q/GdoCwne028qldWukKE24bieTzEwMFxOj1XQIU1j9yxMEP6h vqBw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=Y6alFi2P; arc=pass (i=1 spf=pass spfdomain=proton.me dkim=pass dkdomain=proton.me dmarc=pass fromdomain=proton.me); spf=pass (google.com: domain of linux-kernel+bounces-128794-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-128794-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id ee19-20020a05620a801300b0078be7af266fsi4895098qkb.761.2024.04.02.15.35.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Apr 2024 15:35:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-128794-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=Y6alFi2P; arc=pass (i=1 spf=pass spfdomain=proton.me dkim=pass dkdomain=proton.me dmarc=pass fromdomain=proton.me); spf=pass (google.com: domain of linux-kernel+bounces-128794-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-128794-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id DEF291C22470 for ; Tue, 2 Apr 2024 22:35:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5906A22625; Tue, 2 Apr 2024 22:35:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b="Y6alFi2P" Received: from mail-40131.protonmail.ch (mail-40131.protonmail.ch [185.70.40.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F39011EB2B; Tue, 2 Apr 2024 22:35:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.70.40.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712097347; cv=none; b=NkYOVngHUJUh8hT20AOrE4kRHs52wael3+oTbvYI/Y39W1wPyqtDb+UO7VUBFhq//zj2LwJX91RCQW/00YxL/rif16THWYoip06tOc3dZb9yR/9wjAvNQGCuGQLn22wSNjv0dr07UtHOYVN/qCVORK8B8KFiYykQpwUcCGHTbBg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712097347; c=relaxed/simple; bh=jkjZO7jwr0PCImAu66df4aVlb2K6kWhUeVLD66IVeD8=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bwvNCN7cryhpU27XcOOCZT8TAi1GRxM90UhCx4sdExTfIFzaAzK04MgF6F/nMYlH7SNRdMiGQbB6iQq8d5unAS8dk0jeWXOsxpffjipT5TKzCtuot/Bo9awjFo1ws389adOv6UxKb9ym0wW+fC4nSWR+fsVR/wAZwObYOmNJXVQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me; spf=pass smtp.mailfrom=proton.me; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b=Y6alFi2P; arc=none smtp.client-ip=185.70.40.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=proton.me DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1712097336; x=1712356536; bh=ZR6oanZJrjCoyu/0f+lqsJmEQvmkfNvERkB55FpMbLg=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=Y6alFi2PVO8tJG/+5EOowTtK6yQ+6aIb1zfjGhrRz4XFdszTaso4nG7qq2q1l6LY+ UjBcXlcQgC1v+9CJIw/VhW9joS+lqyz4GMBIHL+jlObSUxBQAQqya602hokAIoiUFP b3kQoeWnN5BPVxHGvKa9kLXAs+T3zKIyP7HzmNWETIAH/pB1V+ulitRQKT7+3/s908 1Czkrja20NNZrbd02NDy4tBSDb1XkLEWJ4/0CKsw0hbl36F8YidFnW6vrLaLG0HK0N S+03aHDnbdVnBf9lFuYk+FA4/L2msRvXoAopXACBRbWwZTCzalO59KEDknT+nycfxA l2Dax32bzBzbA== Date: Tue, 02 Apr 2024 22:35:32 +0000 To: Andreas Hindborg From: Benno Lossin Cc: Jens Axboe , Christoph Hellwig , Keith Busch , Damien Le Moal , Bart Van Assche , Hannes Reinecke , "linux-block@vger.kernel.org" , Andreas Hindborg , Niklas Cassel , Greg KH , Matthew Wilcox , Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , Alice Ryhl , Chaitanya Kulkarni , Luis Chamberlain , Yexuan Yang <1182282462@bupt.edu.cn>, =?utf-8?Q?Sergio_Gonz=C3=A1lez_Collado?= , Joel Granados , "Pankaj Raghav (Samsung)" , Daniel Gomez , open list , "rust-for-linux@vger.kernel.org" , "lsf-pc@lists.linux-foundation.org" , "gost.dev@samsung.com" Subject: Re: [RFC PATCH 4/5] rust: block: add rnull, Rust null_blk implementation Message-ID: <1e8a2a1f-abbf-44ba-8344-705a9cbb1627@proton.me> In-Reply-To: <87msqc3p0e.fsf@metaspace.dk> References: <20240313110515.70088-1-nmi@metaspace.dk> <20240313110515.70088-5-nmi@metaspace.dk> <87msqc3p0e.fsf@metaspace.dk> Feedback-ID: 71780778:user:proton Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 02.04.24 14:52, Andreas Hindborg wrote: > Benno Lossin writes: >=20 >> On 3/13/24 12:05, Andreas Hindborg wrote: >>> +module! { >>> + type: NullBlkModule, >>> + name: "rnull_mod", >>> + author: "Andreas Hindborg", >>> + license: "GPL v2", >>> + params: { >>> + param_memory_backed: bool { >>> + default: true, >>> + permissions: 0, >>> + description: "Use memory backing", >>> + }, >>> + // Problems with pin_init when `irq_mode` >> >> Can you elaborate? >=20 > I think we discussed this before, but I do not recall what you decided > was the issue. Ah I vaguely remember. > It is probably easier if you can apply the patches and try to build with > this on top: >=20 > diff --git a/drivers/block/rnull.rs b/drivers/block/rnull.rs > index 04bdb6668558..bd089c5e6e89 100644 > --- a/drivers/block/rnull.rs > +++ b/drivers/block/rnull.rs > @@ -48,7 +48,7 @@ > description: "Use memory backing", > }, > // Problems with pin_init when `irq_mode` > - param_irq_mode: u8 { > + irq_mode: u8 { > default: 0, > permissions: 0, > description: "IRQ Mode (0: None, 1: Soft, 2: Timer)", > @@ -101,7 +101,7 @@ fn add_disk(tagset: Arc>) -> Re= sult > return Err(kernel::error::code::EINVAL); > } >=20 > - let irq_mode =3D (*param_irq_mode.read()).try_into()?; > + let irq_mode =3D (*irq_mode.read()).try_into()?; >=20 > let queue_data =3D Box::pin_init(pin_init!( > QueueData { >=20 > --- >=20 > There is some kind of name clash issue when using `pin_init!` in the expr= ession on > line 106: >=20 > let queue_data =3D Box::pin_init(pin_init!( > QueueData { > tree <- TreeContainer::new(), > completion_time_nsec: *param_completion_time_nsec.read(), > irq_mode, > memory_backed: *param_memory_backed.read(), > block_size, > } > ))?; >=20 > I cannot immediately decipher the error message: >=20 > RUSTC [M] drivers/block/rnull.o > error[E0277]: the trait bound `__rnull_mod_irq_mode: From` is not sat= isfied > --> /home/aeh/src/linux-rust/linux/drivers/block/rnull.rs:104:39 > | > 104 | let irq_mode =3D (*irq_mode.read()).try_into()?; > | ^^^^^^^^ the trait `From`= is not implemented for `__rnull_mod_irq_mode` > | > =3D note: required for `u8` to implement `Into<__rnull_mod_irq_mode>` > =3D note: required for `__rnull_mod_irq_mode` to implement `TryFrom` > =3D note: required for `u8` to implement `TryInto<__rnull_mod_irq_mod= e>` >=20 > error[E0308]: mismatched types > --> /home/aeh/src/linux-rust/linux/drivers/block/rnull.rs:106:36 > | > 106 | let queue_data =3D Box::pin_init(pin_init!( > | ____________________________________^ > 107 | | QueueData { > 108 | | tree <- TreeContainer::new(), > 109 | | completion_time_nsec: *param_completion_time_nsec.re= ad(), > ... | > 113 | | } > 114 | | ))?; > | | ^ > | | | > | |_____expected `IRQMode`, found `__rnull_mod_irq_mode` > | arguments to this function are incorrect > | > note: function defined here > --> /home/aeh/.rustup/toolchains/1.74.1-x86_64-unknown-linux-gnu/lib/= rustlib/src/rust/library/core/src/ptr/mod.rs:1365:21 > | > 1365 | pub const unsafe fn write(dst: *mut T, src: T) { > | ^^^^^ > =3D note: this error originates in the macro `$crate::__init_interna= l` which comes from the expansion of the macro `pin_init` (in Nightly build= s, run with -Z macro-backtrace for more info) >=20 > error[E0308]: mismatched types > --> /home/aeh/src/linux-rust/linux/drivers/block/rnull.rs:106:36 > | > 39 | / module! { > 40 | | type: NullBlkModule, > 41 | | name: "rnull_mod", > 42 | | author: "Andreas Hindborg", > ... | > 71 | | }, > 72 | | } > | |_- constant defined here > ... > 106 | let queue_data =3D Box::pin_init(pin_init!( > | ____________________________________^ > | |____________________________________| > | |____________________________________| > | |____________________________________| > | | > 107 | | QueueData { > 108 | | tree <- TreeContainer::new(), > 109 | | completion_time_nsec: *param_completion_time_nsec.rea= d(), > ... | > 113 | | } > 114 | | ))?; > | | ^ > | |_____| > | |_____expected `DropGuard`, found `__rnull_mod_irq_mode` > | |_____this expression has type `DropGuard` > | |_____`irq_mode` is interpreted as a constant, not a new binding > | help: introduce a new binding instead: `other_irq_mode` > | > =3D note: expected struct `DropGuard` > found struct `__rnull_mod_irq_mode` > =3D note: this error originates in the macro `$crate::__init_internal= ` which comes from the expansion of the macro `pin_init` (in Nightly builds= , run with -Z macro-backtrace for more info) >=20 > error: aborting due to 3 previous errors >=20 > Some errors have detailed explanations: E0277, E0308. > For more information about an error, try `rustc --explain E0277`. > make[5]: *** [/home/aeh/src/linux-rust/linux/scripts/Makefile.build:293: = drivers/block/rnull.o] Error 1 So I did some digging and there are multiple things at play. I am going to explain the second error first, since that one might be a problem with `pin_init`: - the `params` extension of the `module!` macro creates constants with snake case names. - your `QueueData` struct has the same name as a field. - `pin_init!` generates `let $field_name =3D ...` statements for each field you initialize Now when you define a constant in Rust, you are able to pattern-match with that constant, eg: const FOO: u8 =3D 0; =20 fn main() { match 10 { FOO =3D> println!("foo"), _ =3D> {} } } So when you do `let FOO =3D x;`, then it interprets `FOO` as the constant. This is still true if the constant has a snake case name. Since the expression in the `pin_init!` macro has type `DropGuard<$field_type>`, we get the error "expected `DropGuard`, found `__rnull_mod_irq_mode`". Now to the first error, this is a problem with the parameter handling of `module`. By the same argument above, your let binding in line 104: let irq_mode =3D (*irq_mode.read()).try_into()?; Tries to pattern-match the `irq_mode` constant with the right expression. Since you use the `try_into` function, it tries to search for a `TryInto` implementation for the type of `irq_mode` which is generated by the `module!` macro. The type is named __rnull_mod_irq_mode. Now what to do about this. For the second error (the one related to `pin_init`), I could create a patch that fixes it by adding the suffix `_guard` to those let bindings, preventing the issue. Not sure if we need that though, since it will not get rid of the first issue. For the first issue, I think there is no other way than to use a different name for either the field or the constant. Since constants are usually named using screaming snake case, I think it should be renamed. I believe your reason for using a snake case name is that these names are used directly as the names for the parameters when loading the module and there the convention is to use snake case, right? In that case I think we could expect people to write the screaming snake case name in rust and have it automatically be lower-cased by the `module!` macro when it creates the names that the parameters are shown with. Hope this helps! --=20 Cheers, Benno