Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp2592309lqz; Wed, 3 Apr 2024 02:48:02 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVHkstREcNUtyPOOZWBarvpfVY/i3VoO+aCaGXFwnZsX4DL0t/yjLbgA4NdayA9OYfprDdxeRleyT2orsQtMGWMNnc1edzPR8ptQgzqdA== X-Google-Smtp-Source: AGHT+IHvCgdWRM+cJX0mo2XxeCPFu+ODImL3I7ByLnCsD5coSV1VFY8ILlzoYRApQt44T/iWNG1i X-Received: by 2002:a17:907:7812:b0:a4e:2230:8583 with SMTP id la18-20020a170907781200b00a4e22308583mr10002188ejc.18.1712137682646; Wed, 03 Apr 2024 02:48:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712137682; cv=pass; d=google.com; s=arc-20160816; b=hHJBiTgeibQiw0Qu3ET7Tn/uHZNEfT6sGjEZxQULuxUYOGABM6vl2Te4tYOGwbM1L/ S6whF995YvtCNgmHV7WKBiMrk95cu+WAD4d8vyhdOaPkFaxf5xuSFVkceUqcZHjYYCg0 WaSdlcgOe9VGfikeGza6OMI+sJTButxv+7KbfQkWmmUYpnw8+mlv+luZgb4pNXxDgU61 fAPAodvppvRgB3iHU6ZhKnb+079V59smyQXuTPAHdgOAxdIbqVHt+zeBl4xQ5HZsvsMh BjmEPirfFiWirt0PKeZAayn7D7gR1qW6wvebbsbZMkUrMN2xj5bWjBJjBJfEaKZXRM0A tmxQ== 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:message-id:date:user-agent :references:in-reply-to:subject:cc:to:from:dkim-signature; bh=38SEkdXIN7qI57DkSuG7SyOZVG7UjoZz3fx+kBnmeVk=; fh=qvQZYWLbi4i6pyVMkqiQ2XMzoJc7WfiNTLxIQAe33zM=; b=OjqdvwBR04Isdgd0/RE9lCY+df0GF/rGyttNH9BpanM9zK+auWReMnUljaNAheYR59 GNPkZl/1/we7GIs0YJLvwDOwHhUkveTnP+9qG7yudhKLWDnyaJEDSR4KsmHIj19E82i3 bbTMYm0dD3tg1U8hl/M2UYfKL5V+yksTLIVO4FdzukwCcghNaXF6X1u3p5ovXbMhBAxK TEYPkx+702R/+sbEgf243TKm00n/V4uaHwXj3kh8hU2A3Oggl77XKPt4RNF/b6iuvvRL B9EI9MCtXc2Fd/ro16q6CDm67SgE7W2IEMFUANi+/o4Y5cAMXVJK/J6T1s0CW761ZlkK B7EQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@metaspace-dk.20230601.gappssmtp.com header.s=20230601 header.b=1q8H9D3R; arc=pass (i=1 dkim=pass dkdomain=metaspace-dk.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-129451-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-129451-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id lu26-20020a170906fada00b00a4df5bd62e2si6643506ejb.550.2024.04.03.02.48.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 02:48:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-129451-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@metaspace-dk.20230601.gappssmtp.com header.s=20230601 header.b=1q8H9D3R; arc=pass (i=1 dkim=pass dkdomain=metaspace-dk.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-129451-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-129451-linux.lists.archive=gmail.com@vger.kernel.org" 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 086541F21520 for ; Wed, 3 Apr 2024 09:48:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 19FFC135A63; Wed, 3 Apr 2024 09:47:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=metaspace-dk.20230601.gappssmtp.com header.i=@metaspace-dk.20230601.gappssmtp.com header.b="1q8H9D3R" Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D3EC554725 for ; Wed, 3 Apr 2024 09:47:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712137648; cv=none; b=hJVR6tGpKZH5wczKUG2CJmJQtRrHF51E5D+T8cpDfL3mBAeB8I4PM1R3jaiLOTpxJHudh/43qHPQiMT31zz9MFPOWvR1o6Q/qc3V95XW2s0m3GP8W87Ewijb9PaXKHKm2dZRM++PL48UtYOodxG6ady5l3hm0OnFbbx66NlENPA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712137648; c=relaxed/simple; bh=GRfag88koxETtlzSVNB41LuzJOoQ5upi+5Ad5sKRA7g=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=ZQ9nv0+LCQ4Spvx3mXzrLMsX/mylQ5spGRMWO6dKSLzbDIFjwfb42OqET6Ke5bpQ8qFTin+RXH1b9xYNJpa5znk1cpIgJHxJtnqty+xIP9Bpe8url9nRxE/GTLEMedEqrnZ5ZOlqQUNCzqt3PjEgS8fZt4BmLR1aWE1hc72XUBQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=metaspace.dk; spf=none smtp.mailfrom=metaspace.dk; dkim=pass (2048-bit key) header.d=metaspace-dk.20230601.gappssmtp.com header.i=@metaspace-dk.20230601.gappssmtp.com header.b=1q8H9D3R; arc=none smtp.client-ip=209.85.167.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=metaspace.dk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=metaspace.dk Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-513e25afabaso6836249e87.2 for ; Wed, 03 Apr 2024 02:47:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=metaspace-dk.20230601.gappssmtp.com; s=20230601; t=1712137644; x=1712742444; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:user-agent :references:in-reply-to:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=38SEkdXIN7qI57DkSuG7SyOZVG7UjoZz3fx+kBnmeVk=; b=1q8H9D3RzPDHhPPW4oaXaZvc7oz9L7SA26PXsYzg9aJb7w0nJs77TmQf4sne7GpRyp 8f+2IRi+bET4fzqdjNgBWX0GF1cY/6++n4eXh1B+TUSb8r3SPA8Qy+7gCGRQmZVdXCqv Gt/DNTfEPvAsm6LrazzTyVsYRu9vjYBJ+qOjCmby6PCkvP8p2TMILUxCQRBSF3Y6T7+y DX4pHS3CEzoR2K+i6bATZ8xtk/z9I7RIZ3PApLsQX8+f3ouPxW9KVR0QvLNcWJ0hP+Ki UikiKhmT1iwwy64yKoByLHAcGOTjYBPJqOq1B4bB1f3ca1VKViCSSEY2ROa4HoI5ehfD HoHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712137644; x=1712742444; h=content-transfer-encoding:mime-version:message-id:date:user-agent :references:in-reply-to:subject:cc:to:from:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=38SEkdXIN7qI57DkSuG7SyOZVG7UjoZz3fx+kBnmeVk=; b=NwaSwqJW6bV3BpoJvKbyhpPAW00dqAOwTXdVjp4LDhzo59vVurkB2V1NxSIKOM5tRr KCwCbpXhbfpe9fSgjLmSmuySEl8Ow83C8cjDBi8rQD2KLrh7s+q2mxs7WTsWXQbrvRvk OJjeF4AwiqV5LKDztnde61I4Vst6xg2506hFD/tNwzbjoLebrYBcHvj5/ud2hnxuEbOE JVO97XJe4V3ziYwujatcwhcfe3RMhsgjgotKSviXsHedguMzaK8b9TVTKjEnwZ1nwmGU QJPJDoBQE4jD01lh32xB0fon4v0Gvm6cUTnUMUbARKdjgh9blf+Jg4/lY1GXKFY35ir7 5LcA== X-Forwarded-Encrypted: i=1; AJvYcCXcgSgEnOLGwAQqYjTh/mMDh8dwGbn9oOW6cFU522fjpqwGuh0g9U0zzOwVb85gpQvdnEnBZVrRe+5ItB/CcVPMjpC9jb8GWliJwhFT X-Gm-Message-State: AOJu0YxRCKpHnR3PQAXg1Qm/RUdpaw26OfCXHCN7J7IoOEf3dsve7JSq feIIINO8QzzbZGpDaniKgllUOtXZNPoZSgZdG1Uafkt/ZDIeyCjzdKrr9QYlU7E= X-Received: by 2002:a05:6512:480b:b0:516:26ca:c1fe with SMTP id eo11-20020a056512480b00b0051626cac1femr7053161lfb.8.1712137643891; Wed, 03 Apr 2024 02:47:23 -0700 (PDT) Received: from localhost ([147.161.155.112]) by smtp.gmail.com with ESMTPSA id en19-20020a056000421300b0034365152f2asm4259837wrb.97.2024.04.03.02.47.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 02:47:23 -0700 (PDT) From: Andreas Hindborg To: 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>, Sergio =?utf-8?Q?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 In-Reply-To: <1e8a2a1f-abbf-44ba-8344-705a9cbb1627@proton.me> (Benno Lossin's message of "Tue, 02 Apr 2024 22:35:32 +0000") References: <20240313110515.70088-1-nmi@metaspace.dk> <20240313110515.70088-5-nmi@metaspace.dk> <87msqc3p0e.fsf@metaspace.dk> <1e8a2a1f-abbf-44ba-8344-705a9cbb1627@proton.me> User-Agent: mu4e 1.12.2; emacs 29.3 Date: Wed, 03 Apr 2024 11:47:18 +0200 Message-ID: <87edbmsrq1.fsf@metaspace.dk> 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 Benno Lossin writes: [...] > > > 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=20=20=20=20=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`". Thanks for the analysis! So in this expanded code: 1 { 2 unsafe { ::core::ptr::write(&raw mut ((*slot).irq_mode), irq_mode) = }; 3 } 4 let irq_mode =3D unsafe { 5 $crate::init::__internal::DropGuard::new(&raw mut ((*slot).irq_mode= )) 6 }; the `irq_mode` on line 2 will refer to the correct thing, but the one on line 6 will be a pattern match against a constant? That is really surprising to me. Can we make the let binding in line 6 be `let irq_mode_pin_init` or something similar? > > 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. I think that is a good idea =F0=9F=91=8D > > 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. I was thinking about putting the parameters in a separate name space, but making them screaming snake case is also a good idea. So it would be `module_parameters::IRQ_MODE` to access the parameter with the name `irq_mode` exposed towards the user. Developers can always opt in to bringi= ng the symbols into scope with a `use`. Best regards, Andreas