Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp10937987rwp; Fri, 21 Jul 2023 07:07:32 -0700 (PDT) X-Google-Smtp-Source: APBJJlH1XYINIkzz+IATMzXOvkifr2TjWq2+E1EuNfm2TRiVwvzhHbBDOmuDR7Gwedjs34EmJzUl X-Received: by 2002:a17:902:f68f:b0:1b6:6b90:7c2f with SMTP id l15-20020a170902f68f00b001b66b907c2fmr2176723plg.55.1689948452179; Fri, 21 Jul 2023 07:07:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689948452; cv=none; d=google.com; s=arc-20160816; b=wE5bb7vTik5bwN5RC6+kB8zVtE9kuFze9w0rgM9Rlp0eHul0GGrL3Vdkrqz4Tn8Tdq E5fVYDEG8QFmXcwLzKk1KTtY1C1/FnJ+677Lfr9NCgbYOlPxlvZL4jB9dK/Ho0FZSAbH ZZQHmPYNYRqJYf6EwyneAfbHK6ojoW0Z0IxgeORocf0Hjh/puPYJENDHb5LOJx0UYukj PEnLTyI4+9COzJSlvzDvVc7jTijPwxieRkZZ4PZ7hRinyAtL1Bw9YxZx6QhOPY28arUc Dy4re0FbZALoPU/6mXuYDySpHq5/7hwQR2eRA0hERPEkL6vYoynzixB8/k2mPrrYrHvy zTgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=hbLptwVDtXfTKjDH0FBjj8aFDbHRFOTsDjRBnw9MaQA=; fh=qfO5LNPXeE+qNW4zKcERgQW8DlUaFgo6OgOhlWYyNkk=; b=WHqjLyKYjtA84ov16U0y1QVWSGYa1uESgeI1K2g5+tOlRGdoqYkYqDy5UZrxrozMZB F5Pk1awTbo58PUvM3IbfDYWWRwtBTyJTTKyED78Ytaa9AN7TqdZqELhAMCblgnk3mmhy gcv2b4fCPQvxJDiLh5cIcSKkgQyx/4AfJUPPTZ4UNCHHDsnImj/B2TXbPU7XlNikgiIc TxJklDorS7ZL6bSGs5bsMIcWNcALmB6R2QgDW8ziJnkR5zYLTg/HGIeQlDWvAv9Wlb/q hMfHx5B6s/5FiqBZYrsLKna9Rt0VwobBHxFei/BIk5xvLYMnPMfWewfbuzMuwYlB1xAs UyRg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bd8-20020a170902830800b001b7fa1a9a36si2995610plb.67.2023.07.21.07.07.17; Fri, 21 Jul 2023 07:07:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230346AbjGUNce (ORCPT + 99 others); Fri, 21 Jul 2023 09:32:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229790AbjGUNcd (ORCPT ); Fri, 21 Jul 2023 09:32:33 -0400 Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06E781711; Fri, 21 Jul 2023 06:32:32 -0700 (PDT) Received: from local by pidgin.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.96) (envelope-from ) id 1qMqEZ-00024i-03; Fri, 21 Jul 2023 13:31:51 +0000 Date: Fri, 21 Jul 2023 14:31:42 +0100 From: Daniel Golle To: Christoph Hellwig Cc: Jens Axboe , Ulf Hansson , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Dave Chinner , Matthew Wilcox , Thomas =?iso-8859-1?Q?Wei=DFschuh?= , Jan Kara , Damien Le Moal , Ming Lei , Min Li , Christian Loehle , Adrian Hunter , Hannes Reinecke , Jack Wang , Florian Fainelli , Yeqi Fu , Avri Altman , Hans de Goede , Ye Bin , Greg Kroah-Hartman , =?utf-8?B?UmFmYcWCIE1pxYJlY2tp?= , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mmc@vger.kernel.org, linux-mtd@lists.infradead.org Subject: Re: [RFC PATCH 6/6] block: implement NVMEM provider Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 20, 2023 at 11:35:55PM -0700, Christoph Hellwig wrote: > > +static int blk_nvmem_reg_read(void *priv, unsigned int from, > > + void *val, size_t bytes) > > +{ > > + pgoff_t f_index = from >> PAGE_SHIFT; > > + struct address_space *mapping; > > + struct blk_nvmem *bnv = priv; > > + size_t bytes_left = bytes; > > + struct folio *folio; > > + unsigned long offs, to_read; > > + void *p; > > Btw, this function really should be using kern_read on a file > using filp_open instead of poking into block device internals. Unfortunately filp_open requires a device inode on a filesystem to be able to open a block device. What if the root filesystem has not yet been mounted, or even requires NVMEM (let's say for the Ethernet MAC address to be known for a nfsroot, nbd or iSCSI to work) to be available first? Can you imagine we could implement something like filp_open_bdev which takes a (struct block_device *) as parameter instead of (const char *)? That would allow the driver to open and read from the block device before any filesystems (incl. /dev) become ready. > That way you can even have a generic file provider that works > on anything that can be read from. > While this could also be useful, it doesn't fulfil the requirement of making NVMEM available as early as possible for other drivers to use, e.g. for the Ethernet MAC address. And it would also heavily deviate from how things work with other types of flash storage typically used in embedded Linux devices such as SPI NOR or NAND flash which is represented as MTD device. Sidenote: block2mtd is also not an option because one cannot reference block2mtd devices in device tree, hence they cannot serve as NVMEM providers.