Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp207946lqj; Sat, 1 Jun 2024 15:21:05 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVhWIw4+kW5/Hd3VzYhJm5Sbvyb/ofGFnIZlgQsUNVTHEMPWUZ7BTDf+QQl8MzjtHxpHSpAW0ylTTmcTV+YPgzIYqXlaiI1jg5pl41Lvw== X-Google-Smtp-Source: AGHT+IFdt98CqZG+aTq+qzQc2D3184uN1QJ/HemenaNxQQKW+VCluJOqTRVqE6hi/TkEE1Q3ZQ6J X-Received: by 2002:a05:6a20:748a:b0:1af:ab0b:1c08 with SMTP id adf61e73a8af0-1b26f2cbe8amr6807677637.46.1717280465451; Sat, 01 Jun 2024 15:21:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717280465; cv=pass; d=google.com; s=arc-20160816; b=athVDkvM33k512+CnlglhUMaiq09Evwu1D/h/42gG2sQLaOexC+/KrKUpZRowirvrl D40VyImD1aU9rtCjnVwFqxXWGtNMzBdROJkeItIifNo0JWhoYyN+1CQ+vPrCN1f+3V/n UClUwx8q+8zRWrtza3Y0MXv47FnB2zYnwwp8vSY9o2A2yolYapH1UItHjuug2nAFIXe5 ldcFzLZbzbERDTDr7aWiTumReRHkBgxzAMN66cdXFr9VoYSvDunyEZuzGCK1HLV34cHT MdiZLcqSO7NnychArXkv4h/BFUeZSGVrXfBwvY1Wo4HgcRZ7Ep5J/GdIDhx8/VhJc8Tm fTng== 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=jr2Al8+ndIMPJPdlShlncDNXoaIKKJSR1q01cY4wntc=; fh=TKsNwceP5dvmjIPuoEvjBSqmWrlB3DXEvKE5zIu5Ncw=; b=UyjhZ3mP7LznFGMJldA83URuzf6CqprZu3MGInnQ4LCLf3633fXNtcj/xARRq+M8IR M91+LBQwbJsQ5KmnumiiHXIP39z1Te2YrExqU6xLF29XGW+eG55/ZcWBD7m0qq3/p9G4 V1A9xx15iBfnoZgUJ0hsGjLj9j4E7nw/PvQoQPur3QCDWi1Qvcz/GVFBH3o22GqgXdnB SrpIV2xKnF/po1sOVLJ6UbXwKizTXZByisKoKuOowobycZFUjb/7w/euOIZSVxFMI9ub ipsGpiTGgLEKip7PxeFOUB9igwNKTf/dj+lKjKCcFYuNT65JxKlwbeXPGNFJCJYXVej2 eDjA==; 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=j6+JKXK9; arc=pass (i=1 dkim=pass dkdomain=metaspace-dk.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-197993-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-197993-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 41be03b00d2f7-6c3540faff0si4097209a12.60.2024.06.01.15.21.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Jun 2024 15:21:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-197993-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=j6+JKXK9; arc=pass (i=1 dkim=pass dkdomain=metaspace-dk.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-197993-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-197993-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 8B68F2821C1 for ; Sat, 1 Jun 2024 19:54:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E8E46154BF3; Sat, 1 Jun 2024 19:54:02 +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="j6+JKXK9" Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (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 0485614E2EF for ; Sat, 1 Jun 2024 19:53:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717271642; cv=none; b=l6CrNx8/N5g5cSCimwr+hA6agYy+KJF8r0yv1fTH0zqZTZET+F4YugvLFNakgQHVMc+zgmxQhIbGey8CMDQavgi1t3t+yyA1S0ti7LVmvuQJM7hj0tf+DdZAlGdgvuwZ9UKjUC/ptZDK82UlxNFelLb0QqO0natMtGMDLEzsGQA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717271642; c=relaxed/simple; bh=sjTvnLL15+axd8kEPHCrI1q2EZzeItpEAdxMZyj56QQ=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=XSqvT35W+dTLlhw7LsPsOA61HnZC6NHhusj10lCBGQw8cizAff4PdNANicnA+WY44BdEMkmpOSPuPzA+dbc6mQDE9R55itFW6+uE8L99PKPoNkPlRDkuKEsdWYcYkroIEiqM/1UJ8fZ4joJ2hyh6UEhTgeZ8IWlVgfjXUbr8XXc= 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=j6+JKXK9; arc=none smtp.client-ip=209.85.208.49 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-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-57a44c2ce80so970161a12.0 for ; Sat, 01 Jun 2024 12:53:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=metaspace-dk.20230601.gappssmtp.com; s=20230601; t=1717271638; x=1717876438; 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=jr2Al8+ndIMPJPdlShlncDNXoaIKKJSR1q01cY4wntc=; b=j6+JKXK9DoUXHI7BnH41+jvrY3T7Uyzt4W0eazDXOhSvG1K8S2duPPt/Hqm6AhZsgB C5IQLXFJWRYblqCxJQ7FXZ4oFVxqRUvL0Y33GYbPZcv9WftEP2hFcMYzw2b3WLcyorYc 0gzd+u8pPG9J11WR6tkwwwXgXD+dbl2/gIOU3bEDJHMsXT0RJRS1EaBMjqBWvRQj6nM2 bfyVgH55WgIRcRuDIaL8FRIrMBdCbEH6GZ0k/SU/S7rmqhLqgRDpPy7/3ib8HP6XaIrw o/j2AgllMma/RokiDWrjkbT8gvYHvAF10tOZyQh5sWBK1cfVyWF6uwVl6+uEhzlw0Q7A yWTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717271638; x=1717876438; 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=jr2Al8+ndIMPJPdlShlncDNXoaIKKJSR1q01cY4wntc=; b=pOblLEPq3oORT01qMPfLOh+BgNQhdBIzc0Q8r4P38HOYUkJ6BOoJgK2jChfOztxSTi Ify28HyIvV5PgsCr0x0ktCRUs0F5rLBWoXHPhQgQBDVsEeNNvFfsAp4cK1O02GHCvddT brhzok2Zy9seOLHJq1MmjFMq54A053Mj3RTLAkuoWEt+0UuefkR8VSIz4FzelwQe8Au0 B0avtHiEE/6gRE0RYSevjbRT8V7XTNvuBCcoU4A/OWMiuwb4CtIUnkLJPvyJlnNzLDbb OWmoIB7Y7CKBsjpQKiGpFIlP7RFjen/oGfK6CQZbIsApkm37z/JQ3XePtHV7MtmSs5nG PVvw== X-Forwarded-Encrypted: i=1; AJvYcCUs0GflijoIZmzyek+CsY8FODZBgpR+LzTDJWptXr23L/5LjF1oGuboIqp6/jsPJ1flWv42QIwKuQGp2Uc4Hw7snsjfOpKJoqiUjwDQ X-Gm-Message-State: AOJu0YyuAz41IOkYWyPsxhUlzKjPB0eX+LqDQoAf6qH7d9HGkR6zTilt Nl5zZMhbh88Fr8vcnp7nM/zECA3nIvrZ8g1ttWjuvf2dvGcRxG5d1N7nL1YwcpY= X-Received: by 2002:a50:9992:0:b0:57a:2546:2512 with SMTP id 4fb4d7f45d1cf-57a36456201mr3737951a12.34.1717271637875; Sat, 01 Jun 2024 12:53:57 -0700 (PDT) Received: from localhost ([79.142.230.34]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-57a31b9958fsm2594386a12.2.2024.06.01.12.53.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Jun 2024 12:53:57 -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: <871q5goaz0.fsf@metaspace.dk> (Andreas Hindborg's message of "Sat, 01 Jun 2024 18:59:31 +0200") References: <20240601134005.621714-1-nmi@metaspace.dk> <20240601134005.621714-3-nmi@metaspace.dk> <875xusoetn.fsf@metaspace.dk> <871q5goaz0.fsf@metaspace.dk> Date: Sat, 01 Jun 2024 21:53:38 +0200 Message-ID: <87wmn8mocd.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 Andreas Hindborg writes: > 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. This happens: root@debian:~# insmod /mnt/linux-build/drivers/block/null_blk/null_blk.ko bs=1536 BUG: kernel NULL pointer dereference, address: 0000000000000000 #PF: supervisor write access in kernel mode #PF: error_code(0x0002) - not-present page PGD 0 P4D 0 Oops: Oops: 0002 [#1] SMP CPU: 2 PID: 291 Comm: insmod Not tainted 6.10.0-rc1+ #839 Probably a good idea with a better check. BR Andreas