Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp138964lqj; Sat, 1 Jun 2024 11:16:05 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUVB2PBr8mim1IBf33d4wDGKYET7SI6wSeG3BNoN/zstyjNZJ/RFTSw1ZXxB0ntMWNRXl8503UDqLAQAlHfNoa2gj/oXuBqDAnmeY93vw== X-Google-Smtp-Source: AGHT+IFI8wjPh7s/7z4Sze51vLyf30m27eX2M30qbpjeGVMVYUJDu0WNDAzFW44RDz/JPKRjEJRu X-Received: by 2002:a17:903:32c2:b0:1f3:b55:e247 with SMTP id d9443c01a7336-1f6370a783bmr40953005ad.55.1717265765100; Sat, 01 Jun 2024 11:16:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717265765; cv=pass; d=google.com; s=arc-20160816; b=TtcRnCW9pcW4sTVz+oJA+DDjlGpqUVe2QaoNPRMKKqqeTb8VWYI3UleTXBulpVpqcw CUkg3FqU3tR4cy7/IbK7NaoBKIOrs/s595LFwXPdxiRyDySodBSYas8Ga1jmGLpGVpWQ ILz7Rh82IpSH44T387gkWYcl1x/2eafjIo4WEI7+WjGPfBZe5Jm75O9VsisddjKOY9sV YxL8Hdr05OBAnYR/9gSrpyynvcbRARXnk3YPZo+WYtnTvD72SHtJNVyufKu1QxX/TDFr 3GhSCy47W/pp/flCi8yLHTgTeRyLZ2hY8fCwjL/lafJekEcdCSmPQkbQW6t/z1FxD40s XFHg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :message-id:date:references:in-reply-to:subject:cc:to:from :dkim-signature; bh=2mL6l8seCFLH+FLqk0uzi6xe60dPnwEuIbsZWb+Jgs8=; fh=C/qoa+V0gIzaOxS9TtaDN3SZSKkvoyzFfjHe1Ea+ISA=; b=e+WupFNVVF2NxtI//c8R9QYwMMkhUqrBHv2FRvrdsKzsBsDbGBPeCBSQbpCaY5gCKS f9LQh+IXFdHGfJHcfIbbcJfHD6QDliuFG1ou750sDhpl821bK+V7vRbqosbyFvV9BDUg y0pEoUJhUtizTi7oLtMQLDaYBcnrWJ4PjtONzj00TxtzPyJc1OBAmx3kgFchWYUQgwkK rmTycpoxxxO/tPbo0kRuGrV5gWDrx51yKdTShSGfbLhwI2G4ULbLJkbaLsQF3YLCLGHb /kWvjHEM17KjTEPuk+B5aWTboPM6r1VMjOPSCWkkYQvMxKIvIIzNxSMfyab1Y7ls+0hi NJZw==; 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=wwKh0pMr; arc=pass (i=1 dkim=pass dkdomain=metaspace-dk.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-197962-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-197962-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d9443c01a7336-1f6323660c5si38239495ad.177.2024.06.01.11.16.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Jun 2024 11:16:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-197962-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@metaspace-dk.20230601.gappssmtp.com header.s=20230601 header.b=wwKh0pMr; arc=pass (i=1 dkim=pass dkdomain=metaspace-dk.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-197962-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-197962-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id B451D282699 for ; Sat, 1 Jun 2024 16:59:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AD009153BC9; Sat, 1 Jun 2024 16:59:42 +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="wwKh0pMr" Received: from mail-lj1-f173.google.com (mail-lj1-f173.google.com [209.85.208.173]) (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 91B041534FB for ; Sat, 1 Jun 2024 16:59:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717261181; cv=none; b=uA9hoDkM0mh8vyL/nR03rtbBaKkSUTDkrddZGFcfn6LQ650K3PBcjcsHYiHse5MZuV326mleJsO00LBRhdeiFNcEIBBNQeNj5Vl4EMWww+yveL6Ydtz23oYH/uprsFDevh0BstqvsT/p9NOZZpPIBbs/edfTpOLGuYOjlx3R9kY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717261181; c=relaxed/simple; bh=vY83/g5DnlUfQZA9zDchrVy8+HtF22bRD22oke+NysM=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=CBY0T7c1T8kz+8iqGLXP+D1yW0j2vLBDGlh97WvWoXskofbhuyaI081lTY/K0i/BoZFTG6YqzKRoDZHhjLbARpCF+/mZt4WjoIwjibIvLT9BRb5r6ucLvpU2Glj0Yv6KPIfXywo+Z/BNNTzeLqWAnCHCYmmRxJpM/gtLl+hTjVk= 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=wwKh0pMr; arc=none smtp.client-ip=209.85.208.173 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-lj1-f173.google.com with SMTP id 38308e7fff4ca-2e95a74d51fso46245291fa.2 for ; Sat, 01 Jun 2024 09:59:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=metaspace-dk.20230601.gappssmtp.com; s=20230601; t=1717261178; x=1717865978; darn=vger.kernel.org; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=2mL6l8seCFLH+FLqk0uzi6xe60dPnwEuIbsZWb+Jgs8=; b=wwKh0pMrCWNf4pWpmwi3ABDnaTpDxSwyyrA80PhnQmjMYHVBfFwl1gU1tNehlN70yp AjJVtXUN+8hXokiyJ4QYKhcpZsbH2K27Em0LrPQfHHzp5ud8CI1uNPsSH5In2/0iMC5w zsicMxacBqOKMgUTEKxQCKKQxQn8p7iB838ge4xG4Y6IJqpHpNzmKUpWDWtfb/DLrP9u d0fZhIEP7ExWRHBgIbhq9cF5dV0QFebPozDtHJEWTJmEBB74d7sMPhaqoP/3Z9PlRsFB 3l3Vc+c6tWQXlmYxHmUpRs/+fGnyzJ+XWXONFfpmAVWwSzZLkla5MghltLYFGqBEtbqS fZkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717261178; x=1717865978; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=2mL6l8seCFLH+FLqk0uzi6xe60dPnwEuIbsZWb+Jgs8=; b=DULeOekf9LE0akBLADFdSLZpRJMoY2HVjfsA+ajday9k8EFbS8BlXIPoVNDe3YkVRd tUvvG2xcCbrFT/1vaAiuhyyrV0HGmlIChYuBiVThPsgvhhgtlnGvqfhVARd83zlVmHI3 OUZY8o4DqCNNtBWxUEAjH8iEnoea+1xrFirvj+L0hGGDHO+MMhCQxIHxsCUxb9plKiqY 6IcNwKmYGonFPPkrCj+031VBv2ZbTKLTPLsDjsdgK3q7KvifKSnlZ2PYmuVgf0XJcrGR qrx4laPQ0qHNTtaqqiTQ29XyImOg6INIIS/qnMcUOUNM+3PmhbN/hjBOwyHEzuQsPlmq eEdQ== X-Forwarded-Encrypted: i=1; AJvYcCWxwZ5TmZjBRkLh3AMtEy/4TqLp1D/vxf8REdEwIiMmga8Sbxlqaan8u60xksrDYyk7VYTPSIW0FHjv+S6XOUCgzgb9CQGcdJ1ocmq0 X-Gm-Message-State: AOJu0YyJRg1AbGByIhDI7m7ZObZWmUcviNited2S5AoUM4bDssVAy5j1 UkINT2TbHzA93453BcTz/P1H+sqAchn4GHVmjLGOM8/XFoaeA5VIg9uZJpAGg2x/axDGTiQMPvY H X-Received: by 2002:a2e:3517:0:b0:2e2:a99a:4c4 with SMTP id 38308e7fff4ca-2ea951f5e53mr39476581fa.47.1717261177607; Sat, 01 Jun 2024 09:59:37 -0700 (PDT) Received: from localhost ([79.142.230.34]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a67ea67b4b2sm217708466b.117.2024.06.01.09.59.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Jun 2024 09:59:37 -0700 (PDT) From: Andreas Hindborg To: Keith Busch 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 , =?utf-8?Q?Bj=C3=B6rn?= Roy Baron , Benno Lossin , 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 , Niklas Cassel , Philipp Stanner , Conor Dooley , Johannes Thumshirn , Matias =?utf-8?Q?Bj=C3=B8rling?= , 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 In-Reply-To: (Keith Busch's message of "Sat, 1 Jun 2024 10:01:40 -0600") References: <20240601134005.621714-1-nmi@metaspace.dk> <20240601134005.621714-3-nmi@metaspace.dk> <875xusoetn.fsf@metaspace.dk> Date: Sat, 01 Jun 2024 18:59:31 +0200 Message-ID: <871q5goaz0.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 Keith Busch writes: > 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) Right, that makes sense. I modeled it after the C null_blk validation code in `null_validate_conf`. It contains this: dev->blocksize = round_down(dev->blocksize, 512); dev->blocksize = clamp_t(unsigned int, dev->blocksize, 512, 4096); That would have the same semantics, right? I guess I'll try to make a device with a 1536 block size and see what happens. BR Andreas