Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp6105842rwl; Tue, 4 Apr 2023 07:58:16 -0700 (PDT) X-Google-Smtp-Source: AKy350YfV0q4PACt31d3PYSU+pOjRYToP7t53hmnDzaDTPJ83zW6h1spc/nCndh99RZ7Hs+pQgMf X-Received: by 2002:aa7:c68f:0:b0:4ac:b614:dd00 with SMTP id n15-20020aa7c68f000000b004acb614dd00mr2401693edq.30.1680620296179; Tue, 04 Apr 2023 07:58:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680620296; cv=none; d=google.com; s=arc-20160816; b=kqB1w66xdAq6CAECUj07H09h5HzoKXlHwrh06kJ8qPnr0jEZKS06TCEAAlQ+3E5ov4 z//fx5WAbsew2gCNRMvhH87sBmOPbq7700pRMLcsjj3ImTC1YGIehJr806M3C6S7Ibg4 0/GIySeCzHFV2/CcZrzrjBbNn6JhE23hdRSo9DB8rXZi0vTcA0VyY9n5Q/obruhePGlp JGEVrWNyii1omVDK95R54SYLCOcKZw+uY9wmF6/wlectld2gKerz89Y2CuMTbPHnqJaN uEFHB2Rnnfb+RltqNZQygOpO/d/lNBhy/C6lacB9HuzIkm4JR8hzZaGCzZnD8vRhQq7e h6Vg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=vAR4IqzKft1FulbfGVumK2HKMhiXaE7ZaLXEvaQK8Qc=; b=vxU9NxKHpMN0zZypOt1sg8iP1S4cVvAVXWa1C/RkRfIEOXryVO2DO7OkZISKLyWpn6 SLxQSElMGZxbRrN8H1bSFQaWHdENjPuK7MCxqCjunXcKEdl/cBgeCLwUcaoNuS1kEwH+ XOv51wjvXHMHvcZZ1pqno4UJzJTYZFKTWezoK4C2GJ0OrlPhSMz7Tbdj9dGrNAVmPPRh z8gwtVwFArvSXcE3y1GdTfkBJhKiPWEM0VHNuOFLQXALDqTaSUB6SeVGm+cIHsJb/mtM hRDYZ4NVmORh8hcF9epXcCDWsFyxz5jC746V3K96E8fdkmeOUJ2pSjlS5q04zzqQB2Gb /59w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=D4d9ou9t; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q16-20020aa7cc10000000b004af627b3205si10758970edt.641.2023.04.04.07.57.51; Tue, 04 Apr 2023 07:58:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=D4d9ou9t; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234872AbjDDO5N (ORCPT + 99 others); Tue, 4 Apr 2023 10:57:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234843AbjDDO4j (ORCPT ); Tue, 4 Apr 2023 10:56:39 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D4B23AB1 for ; Tue, 4 Apr 2023 07:55:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680620154; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vAR4IqzKft1FulbfGVumK2HKMhiXaE7ZaLXEvaQK8Qc=; b=D4d9ou9t1nRjb8JTn2Ct4oJ2J+W+CksICLmxS3PvbOL98RnpCTmCbdUJlnueFGvvaIx9HZ wB6mW+MoKJzTR7TBcpvtB24jSXfDY8uLW/Yeta5BCKMC0wClaEiJXXWQExn1g5quHt4QxR tY4LmVcFuBCFZXyn2d4Xt8o5AV+/TLs= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-67-wHIKg-h8PTaniCRxU_MSEw-1; Tue, 04 Apr 2023 10:55:53 -0400 X-MC-Unique: wHIKg-h8PTaniCRxU_MSEw-1 Received: by mail-qv1-f69.google.com with SMTP id v8-20020a0ccd88000000b005c1927d1609so14635584qvm.12 for ; Tue, 04 Apr 2023 07:55:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680620152; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vAR4IqzKft1FulbfGVumK2HKMhiXaE7ZaLXEvaQK8Qc=; b=BpWK5LRX1ntEalxItushUVC8dQBaR1pIY8vVSXkedkdpzhbLM0tLlswAC9bpg4YbyP wfK7M5aGCiUVsPnl8VbNxEUD2QUZGvl5VXIXLsBi6N/QNbaV2rNpsGuwA4Vx7eQfXv5V oCqIZ7WA3sj5tNmqOdj9orH9cpuN6OQ+Spg/J8g8K9bFCCuYAE9aQwj/9bvWT8LbD8Wl piZ0P2V9IrawLNJmqsRnE7JxpCGrpAV8WEx8V/jNEiOoCwFvsqR6Igyk8u+gAjkxG4BJ xDt63AWTlwE4HXG+fbc7h0+L67qvbMIWMQFTb9t9bVLRmLe31e0ib/u8W/lA1n7OUNQn 0HeA== X-Gm-Message-State: AAQBX9fmpoPRZo3wRLp/4PMEuuTy0k3A9XQgaH/aGPwCKhDJlpuBLyG8 zfGiGwTNPriY5K5QAETQ8eEPv3/7+VQVdjG0YMns0PiP0xY/SfrPPsMEJgf13ObBO97I96VTcMk urz2OOTW545hX+zyxMmYp X-Received: by 2002:a05:6214:da8:b0:5c5:471a:1e2f with SMTP id h8-20020a0562140da800b005c5471a1e2fmr3781899qvh.51.1680620152502; Tue, 04 Apr 2023 07:55:52 -0700 (PDT) X-Received: by 2002:a05:6214:da8:b0:5c5:471a:1e2f with SMTP id h8-20020a0562140da800b005c5471a1e2fmr3781877qvh.51.1680620152126; Tue, 04 Apr 2023 07:55:52 -0700 (PDT) Received: from aalbersh.remote.csb ([109.183.6.197]) by smtp.gmail.com with ESMTPSA id j4-20020ac86644000000b003e6387431dcsm3296539qtp.7.2023.04.04.07.55.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Apr 2023 07:55:51 -0700 (PDT) From: Andrey Albershteyn To: djwong@kernel.org, dchinner@redhat.com, ebiggers@kernel.org, hch@infradead.org, linux-xfs@vger.kernel.org, fsverity@lists.linux.dev Cc: rpeterso@redhat.com, agruenba@redhat.com, xiang@kernel.org, chao@kernel.org, damien.lemoal@opensource.wdc.com, jth@kernel.org, linux-erofs@lists.ozlabs.org, linux-btrfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, cluster-devel@redhat.com, Andrey Albershteyn Subject: [PATCH v2 21/23] xfs: handle merkle tree block size != fs blocksize != PAGE_SIZE Date: Tue, 4 Apr 2023 16:53:17 +0200 Message-Id: <20230404145319.2057051-22-aalbersh@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230404145319.2057051-1-aalbersh@redhat.com> References: <20230404145319.2057051-1-aalbersh@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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-ext4@vger.kernel.org In case of different Merkle tree block size fs-verity expects ->read_merkle_tree_page() to return Merkle tree page filled with Merkle tree blocks. The XFS stores each merkle tree block under extended attribute. Those attributes are addressed by block offset into Merkle tree. This patch make ->read_merkle_tree_page() to fetch multiple merkle tree blocks based on size ratio. Also the reference to each xfs_buf is passed with page->private to ->drop_page(). Signed-off-by: Andrey Albershteyn --- fs/xfs/xfs_verity.c | 74 +++++++++++++++++++++++++++++++++++---------- fs/xfs/xfs_verity.h | 8 +++++ 2 files changed, 66 insertions(+), 16 deletions(-) diff --git a/fs/xfs/xfs_verity.c b/fs/xfs/xfs_verity.c index a9874ff4efcd..ef0aff216f06 100644 --- a/fs/xfs/xfs_verity.c +++ b/fs/xfs/xfs_verity.c @@ -134,6 +134,10 @@ xfs_read_merkle_tree_page( struct page *page = NULL; __be64 name = cpu_to_be64(index << PAGE_SHIFT); uint32_t bs = 1 << log_blocksize; + int blocks_per_page = + (1 << (PAGE_SHIFT - log_blocksize)); + int n = 0; + int offset = 0; struct xfs_da_args args = { .dp = ip, .attr_filter = XFS_ATTR_VERITY, @@ -143,26 +147,59 @@ xfs_read_merkle_tree_page( .valuelen = bs, }; int error = 0; + bool is_checked = true; + struct xfs_verity_buf_list *buf_list; page = alloc_page(GFP_KERNEL); if (!page) return ERR_PTR(-ENOMEM); - error = xfs_attr_get(&args); - if (error) { - kmem_free(args.value); - xfs_buf_rele(args.bp); + buf_list = kzalloc(sizeof(struct xfs_verity_buf_list), GFP_KERNEL); + if (!buf_list) { put_page(page); - return ERR_PTR(-EFAULT); + return ERR_PTR(-ENOMEM); } - if (args.bp->b_flags & XBF_VERITY_CHECKED) + /* + * Fill the page with Merkle tree blocks. The blcoks_per_page is higher + * than 1 when fs block size != PAGE_SIZE or Merkle tree block size != + * PAGE SIZE + */ + for (n = 0; n < blocks_per_page; n++) { + offset = bs * n; + name = cpu_to_be64(((index << PAGE_SHIFT) + offset)); + args.name = (const uint8_t *)&name; + + error = xfs_attr_get(&args); + if (error) { + kmem_free(args.value); + /* + * No more Merkle tree blocks (e.g. this was the last + * block of the tree) + */ + if (error == -ENOATTR) + break; + xfs_buf_rele(args.bp); + put_page(page); + kmem_free(buf_list); + return ERR_PTR(-EFAULT); + } + + buf_list->bufs[buf_list->buf_count++] = args.bp; + + /* One of the buffers was dropped */ + if (!(args.bp->b_flags & XBF_VERITY_CHECKED)) + is_checked = false; + + memcpy(page_address(page) + offset, args.value, args.valuelen); + kmem_free(args.value); + args.value = NULL; + } + + if (is_checked) SetPageChecked(page); + page->private = (unsigned long)buf_list; - page->private = (unsigned long)args.bp; - memcpy(page_address(page), args.value, args.valuelen); - - kmem_free(args.value); return page; } @@ -191,16 +228,21 @@ xfs_write_merkle_tree_block( static void xfs_drop_page( - struct page *page) + struct page *page) { - struct xfs_buf *buf = (struct xfs_buf *)page->private; + int i = 0; + struct xfs_verity_buf_list *buf_list = + (struct xfs_verity_buf_list *)page->private; - ASSERT(buf != NULL); + ASSERT(buf_list != NULL); - if (PageChecked(page)) - buf->b_flags |= XBF_VERITY_CHECKED; + for (i = 0; i < buf_list->buf_count; i++) { + if (PageChecked(page)) + buf_list->bufs[i]->b_flags |= XBF_VERITY_CHECKED; + xfs_buf_rele(buf_list->bufs[i]); + } - xfs_buf_rele(buf); + kmem_free(buf_list); put_page(page); } diff --git a/fs/xfs/xfs_verity.h b/fs/xfs/xfs_verity.h index ae5d87ca32a8..433b2f4ae3bc 100644 --- a/fs/xfs/xfs_verity.h +++ b/fs/xfs/xfs_verity.h @@ -16,4 +16,12 @@ extern const struct fsverity_operations xfs_verity_ops; #define xfs_verity_ops NULL #endif /* CONFIG_FS_VERITY */ +/* Minimal Merkle tree block size is 1024 */ +#define XFS_VERITY_MAX_MBLOCKS_PER_PAGE (1 << (PAGE_SHIFT - 10)) + +struct xfs_verity_buf_list { + unsigned int buf_count; + struct xfs_buf *bufs[XFS_VERITY_MAX_MBLOCKS_PER_PAGE]; +}; + #endif /* __XFS_VERITY_H__ */ -- 2.38.4