Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp85650lqj; Sat, 1 Jun 2024 09:01:56 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU1p3x3O8yHk8uhnAgyLDVKCxCJCcwiT1xM/E5rX9CfUJCLo2wP9acgrK4aJ2epyG0O5F3cxXW/tdc044SUwzzurUzvKXB4LcWDPjQdpQ== X-Google-Smtp-Source: AGHT+IEMzgxtVn/K54PX6dTB98OR/xKN+rHw9lzfAwExnZXWcyjCVxpcYUY4JQ5C77EVRk0wFE+A X-Received: by 2002:a05:6358:a54:b0:199:53ec:148c with SMTP id e5c5f4694b2df-19b490d9ecemr445676455d.20.1717257716056; Sat, 01 Jun 2024 09:01:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717257716; cv=pass; d=google.com; s=arc-20160816; b=dPJCQ9rV4a917jS/GN77IXy7WUmFmC1yyHwMxe7YuNL4SfKhysaGONjB0KRRk1glcu NZsiLhNzdhOUYqGMEHxSnxnYMfGnwcDZSXSZZ7d5jQ7ZhrPv38o2STdHuGhbOZyOY8u+ VtAvIsm7mZ/NXB+j99X7HIhWHkL39lERzgR7nZ9UtfQIn8c3fnFBmwbhYlVsOHWMcYVj xIAWq6bQNp83PL82IuiUgezzV0QVOEabjUWlYmlvo2tLUcUHJvvEZ4KsPckZiIozdD83 GC3NWuWyRRZDZHq1/Wj6AzGT/33e8y4RYG9qdRufl60vtnP/u9Elpfu/2wQOgsMrwBfY HMyQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=Fh3JzTFJrAeeV6b/9yKMReST/q82loi1Af2BXuYJz8g=; fh=mLtYmnvi8N1qilcpx6hbUXqdVJe/uI94G/pc9OmZLmk=; b=cfnqNAe9oxjGsBJ+qDtGi8XDjSv/NoKXd5pvVQfFOi5Svcfva3oUQ/6Zp19Ntzhd6L diyxX54fV7zvyOndMaYikRsnq8fYTuVZ+4o+G99u1FM3PymO5EaW/F7l0mKOif95DnmF VsLjtN3kL6B13Ox+oxPb7OGteuW6dcHtxr7Ut92HDZfqpSuPopsxEq++dcrqNrSNCs91 MkHWzqhmg4q+IlAnif255+5fWoKYnE00dewKiosla4k+OZoKiwvNqNWMqjIwxXMqtPAC 2uPwafuhmTQQHnjfgzjHdkI83zwciscvtr4ay+Hb/WZaW+//doWN6J6O7cv3d2p2JAuH fdbw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="aBW/k6tO"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-197943-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-197943-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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-794f2f05ab1si444290485a.105.2024.06.01.09.01.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Jun 2024 09:01:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-197943-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=@kernel.org header.s=k20201202 header.b="aBW/k6tO"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-197943-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-197943-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id BAA461C20C8B for ; Sat, 1 Jun 2024 16:01:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B1AEA1534E5; Sat, 1 Jun 2024 16:01:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="aBW/k6tO" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 CD338849C; Sat, 1 Jun 2024 16:01:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717257704; cv=none; b=MukHyTqboeVXBEnPYwJl0ZqEbszKA0NLiZGrbmfbSeoPDIJoh1zKe5FthFxHdTeqP++PCQ+OWRz68DofVYecq5NbQU/3rzwS1RQSo21IQcJh0rsauJK5GUVGNPiYwH+fSWzriABgkAjKcdDE20yKb/EvfVkij9xYY9IJ0gMzXWY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717257704; c=relaxed/simple; bh=05XcYlktPM9pcAbcI9h/LPTYxBT6cd0X0+gq8dP8Swk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ON7PZqtM6/dc6Q25+85h3UQvfnq4QpP7pAZE65ekuAU5v8M8W1z+4uh59zZw8wF+VFzMfMlApy7yZ3msU8K+pWc/phctn6/AxX03BPIaQbI6Gu53pJfYHFtLiuyD6A06c7a5fnZZklr0eYTAAnbNexcGIOtb4kJ/m3Gks5f6sb0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aBW/k6tO; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3FA5CC116B1; Sat, 1 Jun 2024 16:01:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717257704; bh=05XcYlktPM9pcAbcI9h/LPTYxBT6cd0X0+gq8dP8Swk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=aBW/k6tO1AlSkw9xyimIASc2BVuXv2zG1SJq7TJAMI4fnlceS+O4aznhSSgmqAb7L oAj2bHpB8+Ati8UbWWlQJcPrsHsZec1izqTtk4DR7hFILXRIHAQrdT8K5dwQUb/KGQ wjnB1AQ86sXN6wtzG6zb0BLzcwKrGW4gdOnu89prB2HekO29VQ6FMRoivn5Eo7T986 VO4+TC8LLDP37vBdA0kvPXnjIL7j2s2eDPB6K/L7KY/PaBag8wBkYa+tLIeKC3aa1d CsT6y/ssq+/b4DxI5RhDa/9B4IPZIWGypFpPwnFjOoAFQ5g5wg1bN2+024tXH2ZP9x KKLadKjVdV5bQ== Date: Sat, 1 Jun 2024 10:01:40 -0600 From: Keith Busch To: Andreas Hindborg Cc: Jens Axboe , Christoph Hellwig , Damien Le Moal , Bart Van Assche , Hannes Reinecke , Ming Lei , "linux-block@vger.kernel.org" , Andreas Hindborg , Greg KH , Matthew Wilcox , Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron , Benno Lossin , Alice Ryhl , Chaitanya Kulkarni , Luis Chamberlain , Yexuan Yang <1182282462@bupt.edu.cn>, Sergio =?iso-8859-1?Q?Gonz=E1lez?= Collado , Joel Granados , "Pankaj Raghav (Samsung)" , Daniel Gomez , Niklas Cassel , Philipp Stanner , Conor Dooley , Johannes Thumshirn , Matias =?iso-8859-1?Q?Bj=F8rling?= , open list , "rust-for-linux@vger.kernel.org" , "lsf-pc@lists.linux-foundation.org" , "gost.dev@samsung.com" Subject: Re: [PATCH v4 2/3] rust: block: add rnull, Rust null_blk implementation Message-ID: References: <20240601134005.621714-1-nmi@metaspace.dk> <20240601134005.621714-3-nmi@metaspace.dk> <875xusoetn.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=us-ascii Content-Disposition: inline In-Reply-To: <875xusoetn.fsf@metaspace.dk> On Sat, Jun 01, 2024 at 05:36:20PM +0200, Andreas Hindborg wrote: > Keith Busch writes: > > > On Sat, Jun 01, 2024 at 03:40:04PM +0200, Andreas Hindborg wrote: > >> +impl kernel::Module for NullBlkModule { > >> + fn init(_module: &'static ThisModule) -> Result { > >> + pr_info!("Rust null_blk loaded\n"); > >> + let tagset = Arc::pin_init(TagSet::try_new(1, 256, 1), flags::GFP_KERNEL)?; > >> + > >> + let disk = { > >> + let block_size: u16 = 4096; > >> + if block_size % 512 != 0 || !(512..=4096).contains(&block_size) { > >> + return Err(kernel::error::code::EINVAL); > >> + } > > > > You've set block_size to the literal 4096, then validate its value > > immediately after? Am I missing some way this could ever be invalid? > > Good catch. It is because I have a patch in the outbound queue that allows setting > the block size via a module parameter. The module parameter patch is not > upstream yet. Once I have that up, I will send the patch with the block > size config. > > Do you think it is OK to have this redundancy? It would only be for a > few cycles. It's fine, just wondering why it's there. But it also allows values like 1536 and 3584, which are not valid block sizes, so I think you want the check to be: if !(512..=4096).contains(&block_size) || ((block_size & (block_size - 1)) != 0)