Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp166255ybi; Thu, 20 Jun 2019 20:18:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqySf3YAGEg/f5Ftd0/kgS0JSj/Zr18SqQL5ApMbcyOvPAvoHwqkXTVdk2jMwDjtf4hJH/sN X-Received: by 2002:a17:90a:2627:: with SMTP id l36mr3499855pje.71.1561087093621; Thu, 20 Jun 2019 20:18:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561087093; cv=none; d=google.com; s=arc-20160816; b=vyqUKwtBPh61tJMpqYylIs0ImYwNdgHWujygcUMX8Cfe0xazaAg8bYQ/CqnQvuOjmr 9RmtRhGYRLTT4Vu90+RnkoQWd5AQa4DDQfk/z3nlqFT4xaJHBGpY2kXCh/ykMDlBmi6a bqgqQALPaXabyes4scVo4nn8wWTUfPV5WLosoFwWb6sEdsRlFouvPLWV1Nf45azA7kQ6 D8cTmFl741oqmVwbnIf+bnjqsxJJETwKPJ/4pu2/RlnnsNgK5jqPziZ/7on9iLDNjLr9 yucDudM3qx2ZzYuGvMyX2vEZJie4BJR6FTkg7C/AN9AVVSgbwj2v3pNc9kYXFHfGhSZg ayMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=yovFZbmPJo2JMJ84aJ92Qsbw+aZvdcSM9qXOwPLSpuU=; b=O6pkhuA8SLRed6np07gnsBK08f90U67jSfQQfhdg6eyl2KjUPLM7CxXb4t4Wj1H8LH gnKJ0XIIk9kPXQouQv20EkCqcCIqs+LKk7Zev3Fgs0SgNlEzLbCkS2WvwGv6fVVYzOb8 T4/jYVsuSg77dhBCs3m1Xs3SON0rFFqGdLbtLvoz7fsfuOEGXADdNVdIN59+g1hUThbS 4CzUDBTUtxugwPMzLNlfhEd1ncfza0C74aho5DDmpGaMIy+v+ikzAL5j48XIU/Qwz3oS 40r+XULG8lPqGGtpcLGt6B5LhDXJXMCdNfqjG3QIH8ZK925a8In/sY4hBJnkfJr4lq7p SQZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=i7NAHT3Z; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 126si1333913pgb.349.2019.06.20.20.17.50; Thu, 20 Jun 2019 20:18:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=i7NAHT3Z; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725985AbfFUDRk (ORCPT + 99 others); Thu, 20 Jun 2019 23:17:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:44692 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725906AbfFUDRj (ORCPT ); Thu, 20 Jun 2019 23:17:39 -0400 Received: from sol.localdomain (c-24-5-143-220.hsd1.ca.comcast.net [24.5.143.220]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BBC9020679; Fri, 21 Jun 2019 03:17:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561087058; bh=8upGiMNBTtWDElF9gjCLmVIbeZJwV8B0qLNbePNiBiU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=i7NAHT3Z7Kbuc4XrtwXOF81T38DWmrfYNGoBYndscZEb0luoJO0t/EdZKKvzbOvX0 ndbZtCx8sjRpIUemKoBxuF9qRXD3gVk9mg4H3uF3Xx1mOpmgmVa2tgoCOCaVDe5DIG xBvf1lzHH0jscgF3GCUVG9dpoP8HuP1RtKSkB8qc= Date: Thu, 20 Jun 2019 20:17:36 -0700 From: Eric Biggers To: "Darrick J. Wong" Cc: linux-fscrypt@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, linux-integrity@vger.kernel.org, Jaegeuk Kim , "Theodore Y . Ts'o" , Victor Hsieh , Chandan Rajendra , Dave Chinner , Christoph Hellwig , Linus Torvalds Subject: Re: [PATCH v5 14/16] ext4: add basic fs-verity support Message-ID: <20190621031736.GA742@sol.localdomain> References: <20190620205043.64350-1-ebiggers@kernel.org> <20190620205043.64350-15-ebiggers@kernel.org> <20190620235938.GE5375@magnolia> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190620235938.GE5375@magnolia> User-Agent: Mutt/1.12.1 (2019-06-15) Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Hi Darrick, On Thu, Jun 20, 2019 at 04:59:38PM -0700, Darrick J. Wong wrote: > > diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h > > index 1cb67859e0518b..5a1deea3fb3e37 100644 > > --- a/fs/ext4/ext4.h > > +++ b/fs/ext4/ext4.h > > @@ -41,6 +41,7 @@ > > #endif > > > > #include > > +#include > > > > #include > > > > @@ -395,6 +396,7 @@ struct flex_groups { > > #define EXT4_TOPDIR_FL 0x00020000 /* Top of directory hierarchies*/ > > #define EXT4_HUGE_FILE_FL 0x00040000 /* Set to each huge file */ > > #define EXT4_EXTENTS_FL 0x00080000 /* Inode uses extents */ > > +#define EXT4_VERITY_FL 0x00100000 /* Verity protected inode */ > > Hmm, a new inode flag, superblock rocompat feature flag, and > (presumably) the Merkle tree has some sort of well defined format which > starts at the next 64k boundary past EOF. > > Would you mind updating the relevant parts of the ondisk format > documentation in Documentation/filesystems/ext4/, please? > > I saw that the Merkle tree and verity descriptor formats themselves are > documented in the first patch, so you could simply link the ext4 > documentation to it. > Sure, I'll update the ext4 documentation. > > +/* > > + * Read some verity metadata from the inode. __vfs_read() can't be used because > > + * we need to read beyond i_size. > > + */ > > +static int pagecache_read(struct inode *inode, void *buf, size_t count, > > + loff_t pos) > > +{ > > + while (count) { > > + size_t n = min_t(size_t, count, > > + PAGE_SIZE - offset_in_page(pos)); > > + struct page *page; > > + void *addr; > > + > > + page = read_mapping_page(inode->i_mapping, pos >> PAGE_SHIFT, > > + NULL); > > + if (IS_ERR(page)) > > + return PTR_ERR(page); > > + > > + addr = kmap_atomic(page); > > + memcpy(buf, addr + offset_in_page(pos), n); > > + kunmap_atomic(addr); > > + > > + put_page(page); > > + > > + buf += n; > > + pos += n; > > + count -= n; > > + } > > + return 0; > > +} > > + > > +/* > > + * Write some verity metadata to the inode for FS_IOC_ENABLE_VERITY. > > + * kernel_write() can't be used because the file descriptor is readonly. > > + */ > > +static int pagecache_write(struct inode *inode, const void *buf, size_t count, > > + loff_t pos) > > +{ > > + while (count) { > > + size_t n = min_t(size_t, count, > > + PAGE_SIZE - offset_in_page(pos)); > > + struct page *page; > > + void *fsdata; > > + void *addr; > > + int res; > > + > > + res = pagecache_write_begin(NULL, inode->i_mapping, pos, n, 0, > > + &page, &fsdata); > > + if (res) > > + return res; > > + > > + addr = kmap_atomic(page); > > + memcpy(addr + offset_in_page(pos), buf, n); > > + kunmap_atomic(addr); > > + > > + res = pagecache_write_end(NULL, inode->i_mapping, pos, n, n, > > + page, fsdata); > > + if (res < 0) > > + return res; > > + if (res != n) > > + return -EIO; > > + > > + buf += n; > > + pos += n; > > + count -= n; > > + } > > + return 0; > > +} > > This same code is duplicated in the f2fs patch. Is there a reason why > they don't share this common code? Even if you have to hide it under > fs/verity/ ? > Yes, pagecache_read() and pagecache_write() are identical between ext4 and f2fs. I didn't put them in fs/verity/ because the "metadata past EOF" approach is a choice of ext4 and f2fs and not intrinsic to the fs-verity feature itself, so to avoid confusion I made the fs/verity/ support layer be completely clean of any assumption that that's the way filesystems implement fs-verity. Also, making the fsverity_operations call back into fs/verity/ adds a little extra conceptual complexity about what belongs where, since then we'd have a call stack of filesystem => fs/verity/ => filesystem => fs/verity/. But if people would rather that ext4 and f2fs share these two functions anyway, then sure, we could move them into fs/verity/, and other filesystems (if they take a different approach to fs-verity) simply won't use them. - Eric