Received: by 2002:a05:6500:2018:b0:1fb:9675:f89d with SMTP id t24csp931273lqh; Sat, 1 Jun 2024 02:16:38 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVsgQvTr6ZjYhQwjNfJA1IR3J2r9IPKocrhuQdyZOSkfg5iIQ2QJByeIrdVlIdqJFV+tb6qGwLUy8sdiP8T5vYRh+cqnIdw1Jg2bAKzCQ== X-Google-Smtp-Source: AGHT+IGz1BPImZA7Z29ZueCszpLDtb6zy43m1IlFT5kUf/LbrMPyYAdMHUTDtjOCDWY1jhYTwEVW X-Received: by 2002:a05:620a:e1d:b0:792:ea76:133c with SMTP id af79cd13be357-794f5c7954emr410248685a.24.1717233397966; Sat, 01 Jun 2024 02:16:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717233397; cv=pass; d=google.com; s=arc-20160816; b=lQcGFoemrfh1P8fvDcsd1dkc71LBynjvoaCgYNCQX1DbnOSiNeq4OAhZo+j731qgbK 7H69PP7UMlcmCHIsrVc6ilnkOuMi7CgBGhA+YW6ASE63f7YjhWWFO0DjKsHpuq83uK7X ZmfpPqA3rmPqr+8bmODABImUQyJ7nEEd3ZOVxFn6y9+gD78v31uk8heKZ/kLyU+51lqC cpU1r9OSxVG+LjJKf50mZIqTiB5F0cHK7tkYhibRhDR2KS9a7C8rARtx4Om4Ksim5oyD 4sOLJ2YA5KUR5oSiQO6lnjLQ8vfTL60UiIYaPEp99Lqv2x+PoDRAKBfuuar8SjzathK1 kXcA== 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=XSHQKn8Qe0ezivdh2WpMnm74QPZf/l0QE6ECgprOFW8=; fh=5Uk5eHj3wIw8VuTUn/umANY+EZ6Ozb0aCmYyC7Yu+LQ=; b=G6HuQjZdPjxDvwtMklsnawBNNHCCK2PQc9LADyx6ZUJpOBRZfQVJ0iO0fks2vPlRTl dsY4cn5OggLENHoArTfa8hnDxaQ0ehqxbMqG3q8IVbn3rWgDiGtOoLMyMaUZqbt2+uHU 1JXp7V7ZXHpA/xubTe+rwaNItrgCoBOxArZnFj819x+jRZZK/OununUkQgsPmcuy+UHJ ikffA4NsXDi/kFkhgzXUGbh0f9c2vVhZeTKTppNLqjk9DLdFjeyjGV8sIXSo0t8EYv8G jUN/5pJ5yRZhf3IziflEHqISmRniNT5cWQpi/1LvYcddkXhwTwa9DtXO06liSzBmeH9v 1tyQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=ktJwwC6A; 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-197785-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-197785-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. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id af79cd13be357-794f2f0552esi394291885a.18.2024.06.01.02.16.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Jun 2024 02:16:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-197785-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=ktJwwC6A; 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-197785-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-197785-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 9C39D1C20BA4 for ; Sat, 1 Jun 2024 09:16:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0B85B14E2E4; Sat, 1 Jun 2024 09:16:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b="ktJwwC6A" Received: from mail-4316.protonmail.ch (mail-4316.protonmail.ch [185.70.43.16]) (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 7FD9313EFE5; Sat, 1 Jun 2024 09:16:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.70.43.16 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717233374; cv=none; b=dRtb4yhqAYYWWADy2ugsugmjc9pDEk7u5bmUL/m5hZdGPaEOxZusTEXDm002n8FwMsI3p95JOg6RPOrh/ByhgHx4GgeAaJDwMcghUnxNZKCeomUhsLRaJnhU8vYSSnypCYAF4FskJF+oChc6JixW9hF7akivuLtButWEPM86OBw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717233374; c=relaxed/simple; bh=valRT79Qyh8MqljC8cw+qpWMGMEcVYjXDrKWZFTYhuc=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=YlnRoqpMfw/qXibnivp/RWuF7uZnCGj8mgpb1aKMsKSz8j1xL018iaeSQJot/xeEXgTv7opCqLjM4g2gHTfhxh16Y6kD601fPPkvDhuqfZCX+K0O5UohAJk4UFFpzClLco4E1YSyAb6uk5clYaXfvOwxXde7HPG43M63zCoBVgo= 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=ktJwwC6A; arc=none smtp.client-ip=185.70.43.16 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=1717233364; x=1717492564; bh=XSHQKn8Qe0ezivdh2WpMnm74QPZf/l0QE6ECgprOFW8=; 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=ktJwwC6ANSJRgcP1fd72xGNtggWoVSmB8/YgPHKZkn7rcyKt7832MGmWe8XykhbvA iFlgGz7G/34HxSfdClYqv+BBqod10gGcKNJOIyrmP8XoJLD4qkJRZOpU6TUOsjub1b i3IrD4SToqlRNMkzUm5Pvjq1xHA8XtZYFNRF3RTIfWLIltSovvV3t9EalYMUimuqvQ dKgG33RRBXtE2W6T7iDryvHEDHKaN1j7uvE6Znuh8I8vJ1kYoID3Tmq6LkelYlc5pI jGdV0JvInK5LwdVlx3LaezO0gvi8I9y+zl1iHB/U2Np1mKOekag3qjEPXoebSVZdA0 /YyUYOgmnC3BA== Date: Sat, 01 Jun 2024 09:15:59 +0000 To: Andreas Hindborg , Jens Axboe , Christoph Hellwig , Keith Busch , Damien Le Moal , Bart Van Assche , Hannes Reinecke , Ming Lei , "linux-block@vger.kernel.org" From: Benno Lossin Cc: Andreas Hindborg , 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 , Niklas Cassel , Philipp Stanner , Conor Dooley , Johannes Thumshirn , =?utf-8?Q?Matias_Bj=C3=B8rling?= , open list , "rust-for-linux@vger.kernel.org" , "lsf-pc@lists.linux-foundation.org" , "gost.dev@samsung.com" Subject: Re: [PATCH v3 2/3] rust: block: add rnull, Rust null_blk implementation Message-ID: <2021ea8f-a3df-46c6-8fdf-61b1df231773@proton.me> In-Reply-To: <20240601081806.531954-3-nmi@metaspace.dk> References: <20240601081806.531954-1-nmi@metaspace.dk> <20240601081806.531954-3-nmi@metaspace.dk> Feedback-ID: 71780778:user:proton X-Pm-Message-ID: 750ec28b436cee911f397833a294bd2d4dcc5890 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 01.06.24 10:18, Andreas Hindborg wrote: > From: Andreas Hindborg >=20 > This patch adds an initial version of the Rust null block driver. >=20 > Signed-off-by: Andreas Hindborg > --- > drivers/block/Kconfig | 9 +++++ > drivers/block/Makefile | 3 ++ > drivers/block/rnull.rs | 78 ++++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 90 insertions(+) > create mode 100644 drivers/block/rnull.rs I left two comments below, but it already seems fine to me: Reviewed-by: Benno Lossin >=20 > diff --git a/drivers/block/Kconfig b/drivers/block/Kconfig > index 5b9d4aaebb81..ed209f4f2798 100644 > --- a/drivers/block/Kconfig > +++ b/drivers/block/Kconfig > @@ -354,6 +354,15 @@ config VIRTIO_BLK > =09 This is the virtual block driver for virtio. It can be used with > QEMU based VMMs (like KVM or Xen). Say Y or M. >=20 > +config BLK_DEV_RUST_NULL > +=09tristate "Rust null block driver (Experimental)" > +=09depends on RUST > +=09help > +=09 This is the Rust implementation of the null block driver. For now i= t > +=09 is only a minimal stub. > + > +=09 If unsure, say N. > + > config BLK_DEV_RBD > =09tristate "Rados block device (RBD)" > =09depends on INET && BLOCK > diff --git a/drivers/block/Makefile b/drivers/block/Makefile > index 101612cba303..1105a2d4fdcb 100644 > --- a/drivers/block/Makefile > +++ b/drivers/block/Makefile > @@ -9,6 +9,9 @@ > # needed for trace events > ccflags-y=09=09=09=09+=3D -I$(src) >=20 > +obj-$(CONFIG_BLK_DEV_RUST_NULL) +=3D rnull_mod.o > +rnull_mod-y :=3D rnull.o > + > obj-$(CONFIG_MAC_FLOPPY)=09+=3D swim3.o > obj-$(CONFIG_BLK_DEV_SWIM)=09+=3D swim_mod.o > obj-$(CONFIG_BLK_DEV_FD)=09+=3D floppy.o > diff --git a/drivers/block/rnull.rs b/drivers/block/rnull.rs > new file mode 100644 > index 000000000000..c69ea7e7436e > --- /dev/null > +++ b/drivers/block/rnull.rs > @@ -0,0 +1,78 @@ > +// SPDX-License-Identifier: GPL-2.0 > + > +//! This is a Rust implementation of the C null block driver. > +//! > +//! Supported features: > +//! > +//! - blk-mq interface > +//! - direct completion > +//! - block size 4k > +//! > +//! The driver is not configurable. > + > +use kernel::{ > + alloc::flags, > + block::mq::{ > + self, > + gen_disk::{self, GenDisk}, > + Operations, TagSet, > + }, > + error::Result, > + new_mutex, pr_info, > + prelude::*, > + sync::{Arc, Mutex}, > + types::ARef, > +}; > + > +module! { > + type: NullBlkModule, > + name: "rnull_mod", > + author: "Andreas Hindborg", > + license: "GPL v2", > +} > + > +struct NullBlkModule { > + _disk: Pin>>>, > +} > + > +impl kernel::Module for NullBlkModule { > + fn init(_module: &'static ThisModule) -> Result { > + pr_info!("Rust null_blk loaded\n"); > + let tagset =3D Arc::pin_init(TagSet::try_new(1, 256, 1), flags::= GFP_KERNEL)?; > + > + let disk =3D { > + let block_size: u16 =3D 4096; > + if block_size % 512 !=3D 0 || !(512..=3D4096).contains(&bloc= k_size) { > + return Err(kernel::error::code::EINVAL); > + } > + > + let mut disk =3D gen_disk::GenDisk::try_new(tagset)?; > + disk.set_name(format_args!("rnullb{}", 0))?; > + disk.set_capacity_sectors(4096 << 11); > + disk.set_queue_logical_block_size(block_size.into()); > + disk.set_queue_physical_block_size(block_size.into()); > + disk.set_rotational(false); > + disk.add() > + }?; Personally, I would prefer to put the `?` into the line above. > + > + let disk =3D Box::pin_init(new_mutex!(disk, "nullb:disk"), flags= ::GFP_KERNEL)?; > + > + Ok(Self { _disk: disk }) > + } > +} > + > +struct NullBlkDevice; > + > +#[vtable] > +impl Operations for NullBlkDevice { > + #[inline(always)] > + fn queue_rq(rq: ARef>, _is_last: bool) -> Result { > + mq::Request::end_ok(rq) > + .map_err(|_e| kernel::error::code::EIO) > + .expect("Fatal error - expected to be able to end request"); I expected something more along the lines of: "expected to be able to end request, since `NullBlkDevice` never takes refcounts on Requests and as such the ARef must be unique, but `end_ok` only fails if that is not the case". But maybe that would fit better in a comment, what do you think? > + > + Ok(()) > + } > + > + fn commit_rqs() {} > +} > -- > 2.45.1 >=20