Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp6105290rwl; Tue, 4 Apr 2023 07:57:47 -0700 (PDT) X-Google-Smtp-Source: AKy350Z1jejkvj2CrUpUp4rYSj8QjOA0jnu4ZBaTfWZOEE1ekrzlaS84g4iDbdo96oLAvzM0Cw6p X-Received: by 2002:a17:906:858f:b0:889:58bd:86f1 with SMTP id v15-20020a170906858f00b0088958bd86f1mr2656757ejx.14.1680620267150; Tue, 04 Apr 2023 07:57:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680620267; cv=none; d=google.com; s=arc-20160816; b=PX/lkFGE8uRIktZFWHcFDj22roMGpT7hngB9+myKWIxYJxafZwEBrW1+Kz5S1dvPqL dQ6MfQZHB0sS+PurlA5qoJTewpHPgQE0n0kRbdtNcV5sKhMlMdHKbJWPhe9aWz6THHVH 4de/IDPmI2nMZ5+thin3bmCNIg7Sii5I7P+DlhCw43bdsxgI/cxfOTTcPvlhlR38Z8Ub FwC/+3gwswU44Jf/SFi4XDnP4HnvugA0bERwkCkVLFEjFvsxUtmyVgBOqzYClP/gNE/Y FXDKS7QqQyPEdLTvUCBt3k9t0N4BYznVtj/kujbfLzKMBkR0H8HEUEN9iQuSo++FgxLe ZuFw== 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=k8y9WhZdDNtrUXoW/FedDtUjjZj566BJYHrOtFmmOqc=; b=CDZovpYUX6uO0mPxxfcMJXE3e+OKNEV22O+SNJf8NoLtGmmtsgePIdLB6SvP3d9g1Z TJuKxAru/o4faiRscLGmd/oEdNxaviM4FoyS7uNyyNR6mYNxGeXYm+X+lQ9jg3MviPHa mYEO92G6MdgyIX5oMHT+Q5OqgHl0kqU7rWw/08AKMD4l29N7Xunif43jMeGgnNK+i05o ExjTSfBqlqKO+Y1NJXj29MrIjvJXJFOmfoyJGreSD5FYeRdkyvrJZ+fMuGuZ5LzHgIyh UbNxUMQIPnFnRubvNa0pjmyGKj74zYoM0TGlRRuXHdyiOUsGuJVnaFETp8XRoLEGaaws ij4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=c08jyUMI; 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 a22-20020a170906671600b0092cf65c1a30si1421332ejp.814.2023.04.04.07.57.22; Tue, 04 Apr 2023 07:57:47 -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=c08jyUMI; 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 S233770AbjDDO4s (ORCPT + 99 others); Tue, 4 Apr 2023 10:56:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233879AbjDDO4X (ORCPT ); Tue, 4 Apr 2023 10:56:23 -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 5C14C268C for ; Tue, 4 Apr 2023 07:55:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680620120; 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=k8y9WhZdDNtrUXoW/FedDtUjjZj566BJYHrOtFmmOqc=; b=c08jyUMIg/r+38hT2w/+STbgAdqRO3dKyyGpDRTrAhZ7ei4LOi/PzN6YTmKHJ2CydvuCWV KdYoOMtsWIBsneZTh4xnqwAUcoEMkSLK5pWWxc3ergaSOm04F1lNPJ+fsuHDnNsshtPHAd 1QveC5OaqnqMgT+ktYfvFdiqdJaY4yQ= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-211-If4eMEwKNC2sxEhhJ35WIA-1; Tue, 04 Apr 2023 10:55:19 -0400 X-MC-Unique: If4eMEwKNC2sxEhhJ35WIA-1 Received: by mail-qt1-f200.google.com with SMTP id x5-20020a05622a000500b003e259c363f9so22262196qtw.22 for ; Tue, 04 Apr 2023 07:55:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680620119; 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=k8y9WhZdDNtrUXoW/FedDtUjjZj566BJYHrOtFmmOqc=; b=D/kwr3gt91NZDQQKJD8UQjZ0MOztcPokIMLq+ALvkNtPHxC3wOwUn13Ow4TAb90n1D /C/2dYtwQ3M2eoAbwCLtCeja3E27K1GlOl7jmhMdfuQ3kQLTy8H6XcC7Ne2L17c6dZU7 SkPjiT2j65cLsGOp7knUaQNZEnd5EhrGKrHXzfu4YlRjbVThb3SnB0WtyBVJBfj9wStO 3j+0iGi736p6wPiX6NeEvmLUFlDe0gSVCqJrS1nKRVMW0ftW06mGmFfLS7uA7/fprYp+ Cr8cdmAIWshVY3Z807L9DBVYQAMf455l65Ta/puxHyx2tgUKRq3pryLO3oflDegbra9p 6w4w== X-Gm-Message-State: AAQBX9d89jOTWDzsVUsLu55uiMQyxlMb3hzwhx1hpywanShkK2wE98Xz z+2H3KwxN6mnMbz1WM0kIKywUpEkpSjqpe881OQmgb3D03bGth1jm80nVG7CeEutPkxEomqIg54 zLf97+Bs/qaULOwLuPGan X-Received: by 2002:ac8:5b06:0:b0:3d4:3d6c:a62b with SMTP id m6-20020ac85b06000000b003d43d6ca62bmr3793782qtw.27.1680620118595; Tue, 04 Apr 2023 07:55:18 -0700 (PDT) X-Received: by 2002:ac8:5b06:0:b0:3d4:3d6c:a62b with SMTP id m6-20020ac85b06000000b003d43d6ca62bmr3793740qtw.27.1680620118202; Tue, 04 Apr 2023 07:55:18 -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.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Apr 2023 07:55:17 -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 11/23] xfs: add XFS_DA_OP_BUFFER to make xfs_attr_get() return buffer Date: Tue, 4 Apr 2023 16:53:07 +0200 Message-Id: <20230404145319.2057051-12-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 One of essential ideas of fs-verity is that pages which are already verified won't need to be re-verified if they still in page cache. The XFS stores Merkle tree blocks in extended attributes. Each attribute has one Merkle tree block. We can not directly mark underlying xfs_buf's pages as checked. The are not aligned with xattr value and we don't have a reference to that buffer which is immediately release when value is copied out. One way to track that this block was verified is to mark xattr's buffer as verified. If buffer is evicted the incore XBF_VERITY_CHECKED flag is lost. When the xattr is read again xfs_attr_get() returns new buffer without the flag. The flag is then used to tell fs-verity if it's new page or cached one. This patch adds XFS_DA_OP_BUFFER to tell xfs_attr_get() to xfs_buf_hold() underlying buffer and return it as xfs_da_args->bp. The caller must then xfs_buf_rele() the buffer. Signed-off-by: Andrey Albershteyn --- fs/xfs/libxfs/xfs_attr.c | 5 ++++- fs/xfs/libxfs/xfs_attr_leaf.c | 7 +++++++ fs/xfs/libxfs/xfs_attr_remote.c | 13 +++++++++++-- fs/xfs/libxfs/xfs_da_btree.h | 5 ++++- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/fs/xfs/libxfs/xfs_attr.c b/fs/xfs/libxfs/xfs_attr.c index 711022742e34..298b74245267 100644 --- a/fs/xfs/libxfs/xfs_attr.c +++ b/fs/xfs/libxfs/xfs_attr.c @@ -251,6 +251,8 @@ xfs_attr_get_ilocked( * If the attribute is found, but exceeds the size limit set by the caller in * args->valuelen, return -ERANGE with the size of the attribute that was found * in args->valuelen. + * + * Using XFS_DA_OP_BUFFER the caller have to release the buffer args->bp. */ int xfs_attr_get( @@ -269,7 +271,8 @@ xfs_attr_get( args->hashval = xfs_da_hashname(args->name, args->namelen); /* Entirely possible to look up a name which doesn't exist */ - args->op_flags = XFS_DA_OP_OKNOENT; + args->op_flags = XFS_DA_OP_OKNOENT | + (args->op_flags & XFS_DA_OP_BUFFER); lock_mode = xfs_ilock_attr_map_shared(args->dp); error = xfs_attr_get_ilocked(args); diff --git a/fs/xfs/libxfs/xfs_attr_leaf.c b/fs/xfs/libxfs/xfs_attr_leaf.c index beee51ad75ce..112bb2604c89 100644 --- a/fs/xfs/libxfs/xfs_attr_leaf.c +++ b/fs/xfs/libxfs/xfs_attr_leaf.c @@ -2533,6 +2533,13 @@ xfs_attr3_leaf_getvalue( name_loc = xfs_attr3_leaf_name_local(leaf, args->index); ASSERT(name_loc->namelen == args->namelen); ASSERT(memcmp(args->name, name_loc->nameval, args->namelen) == 0); + + /* must be released by the caller */ + if (args->op_flags & XFS_DA_OP_BUFFER) { + xfs_buf_hold(bp); + args->bp = bp; + } + return xfs_attr_copy_value(args, &name_loc->nameval[args->namelen], be16_to_cpu(name_loc->valuelen)); diff --git a/fs/xfs/libxfs/xfs_attr_remote.c b/fs/xfs/libxfs/xfs_attr_remote.c index d440393b40eb..72908e0e1c86 100644 --- a/fs/xfs/libxfs/xfs_attr_remote.c +++ b/fs/xfs/libxfs/xfs_attr_remote.c @@ -424,9 +424,18 @@ xfs_attr_rmtval_get( error = xfs_attr_rmtval_copyout(mp, bp, args->dp->i_ino, &offset, &valuelen, &dst); - xfs_buf_relse(bp); - if (error) + xfs_buf_unlock(bp); + /* must be released by the caller */ + if (args->op_flags & XFS_DA_OP_BUFFER) + args->bp = bp; + else + xfs_buf_rele(bp); + + if (error) { + if (args->op_flags & XFS_DA_OP_BUFFER) + xfs_buf_rele(args->bp); return error; + } /* roll attribute extent map forwards */ lblkno += map[i].br_blockcount; diff --git a/fs/xfs/libxfs/xfs_da_btree.h b/fs/xfs/libxfs/xfs_da_btree.h index a4b29827603f..269d26730bca 100644 --- a/fs/xfs/libxfs/xfs_da_btree.h +++ b/fs/xfs/libxfs/xfs_da_btree.h @@ -61,6 +61,7 @@ typedef struct xfs_da_args { uint8_t filetype; /* filetype of inode for directories */ void *value; /* set of bytes (maybe contain NULLs) */ int valuelen; /* length of value */ + struct xfs_buf *bp; /* OUT: xfs_buf which contains the attr */ unsigned int attr_filter; /* XFS_ATTR_{ROOT,SECURE,INCOMPLETE} */ unsigned int attr_flags; /* XATTR_{CREATE,REPLACE} */ xfs_dahash_t hashval; /* hash value of name */ @@ -95,6 +96,7 @@ typedef struct xfs_da_args { #define XFS_DA_OP_REMOVE (1u << 6) /* this is a remove operation */ #define XFS_DA_OP_RECOVERY (1u << 7) /* Log recovery operation */ #define XFS_DA_OP_LOGGED (1u << 8) /* Use intent items to track op */ +#define XFS_DA_OP_BUFFER (1u << 9) /* Return underlying buffer */ #define XFS_DA_OP_FLAGS \ { XFS_DA_OP_JUSTCHECK, "JUSTCHECK" }, \ @@ -105,7 +107,8 @@ typedef struct xfs_da_args { { XFS_DA_OP_NOTIME, "NOTIME" }, \ { XFS_DA_OP_REMOVE, "REMOVE" }, \ { XFS_DA_OP_RECOVERY, "RECOVERY" }, \ - { XFS_DA_OP_LOGGED, "LOGGED" } + { XFS_DA_OP_LOGGED, "LOGGED" }, \ + { XFS_DA_OP_BUFFER, "BUFFER" } /* * Storage for holding state during Btree searches and split/join ops. -- 2.38.4