From patchwork Tue Apr 4 14:53:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Albershteyn X-Patchwork-Id: 13200424 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 086E0C77B60 for ; Tue, 4 Apr 2023 14:56:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234204AbjDDO4u (ORCPT ); Tue, 4 Apr 2023 10:56:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233015AbjDDO4Y (ORCPT ); Tue, 4 Apr 2023 10:56:24 -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 DCB623C11 for ; Tue, 4 Apr 2023 07:55:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680620126; 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=mf1FPmX34sPBqBJ1RqvZnmanS11JhvTJ+HM36CjFqII=; b=hXUwnpVOoZRgvuq01tAF1D/CKBAMdI+vFnftbN9IBw4zTGaCeqKNjVM+IB0Y/zFgKEefUp I+WqKbu4tomEmBW2Y2lJoBnK8Yv/IvqB1zMb3rOAEi9Nx7VSmKa1Tn6X73hMERP7NgMhA/ tyU+GCzk9XH7QWjThFIYxOHNOPIyY7E= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-501-kxyp6N-HPvWGiSRmjzR-_w-1; Tue, 04 Apr 2023 10:55:24 -0400 X-MC-Unique: kxyp6N-HPvWGiSRmjzR-_w-1 Received: by mail-qt1-f198.google.com with SMTP id v10-20020a05622a130a00b003e4ee70e001so16129935qtk.6 for ; Tue, 04 Apr 2023 07:55:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680620124; 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=mf1FPmX34sPBqBJ1RqvZnmanS11JhvTJ+HM36CjFqII=; b=08Oypfhjih33FsAJBiUFeCsTZWxMZVHvkZ7uYHSo60Z28GLX6zHJk9I7T6+1797mSI O0TPuGLwvXnBaWf6l0cdg8SzQ/L3Em3/k/24chFngI1bNimT3xf+bMa6AGW4LG7eod2R I0lvQQIfNUzPlFecKKj0Pr78nRrLa2UflRquMyOuOS6pTXLHYXJCBJm+1xDndJn90KHs zVr0IDkRGkH76r0p/kKiBeqfSfoMGdCMm126MkXokHLCPnAujemu/jV3ReRZwUJJAQGr i481eWnIeQ+saXQxFS/R6qvoSYRqEPWK/ZuLRB1XAdKgyYJ2AeZglQ+sBFY7jZkakpQI TZCw== X-Gm-Message-State: AAQBX9c1qwFU0HnOVb0IRJVE3knU0TTTISfulekhmFid9pXAvfPLudbT /NYk1Qb163OC4B9XvvjwmOO0Pb7pmD7WwrnMCo5xbBYbjHq+GvAWvPIqNdzyjoMJDmGi41HtcX+ Pk2K0B76yolbtPc7QuUK7EQ== X-Received: by 2002:a05:622a:586:b0:3e4:df94:34fa with SMTP id c6-20020a05622a058600b003e4df9434famr4035260qtb.37.1680620124163; Tue, 04 Apr 2023 07:55:24 -0700 (PDT) X-Google-Smtp-Source: AKy350bRYRoH4ADtP4T/X8Xk7AmNG3QGNTCPUhw/3V50RQPtNVC1H25ltfcQUL3M/obCpWJOFk1Kng== X-Received: by 2002:a05:622a:586:b0:3e4:df94:34fa with SMTP id c6-20020a05622a058600b003e4df9434famr4035211qtb.37.1680620123789; Tue, 04 Apr 2023 07:55:23 -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.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Apr 2023 07:55:23 -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 13/23] xfs: add iomap's readpage operations Date: Tue, 4 Apr 2023 16:53:09 +0200 Message-Id: <20230404145319.2057051-14-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 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org The read IO path provides callout for configuring ioend. This allows filesystem to add verification of completed BIOs. The xfs_prepare_read_ioend() configures bio->bi_end_io which places verification task in the workqueue. The task does fs-verity verification and then call back to the iomap to finish IO. This patch add callouts implementation to verify pages with fs-verity. Also implements folio operation .verify_folio for direct folio verification by fs-verity. Signed-off-by: Andrey Albershteyn --- fs/xfs/xfs_aops.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ fs/xfs/xfs_iomap.c | 11 +++++++++++ fs/xfs/xfs_linux.h | 1 + 3 files changed, 57 insertions(+) diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c index daa0dd4768fb..2a3ab5afd665 100644 --- a/fs/xfs/xfs_aops.c +++ b/fs/xfs/xfs_aops.c @@ -548,6 +548,49 @@ xfs_vm_bmap( return iomap_bmap(mapping, block, &xfs_read_iomap_ops); } +static void +xfs_read_work_end_io( + struct work_struct *work) +{ + struct iomap_read_ioend *ioend = + container_of(work, struct iomap_read_ioend, work); + struct bio *bio = &ioend->read_inline_bio; + + fsverity_verify_bio(bio); + iomap_read_end_io(bio); + /* + * The iomap_read_ioend has been freed by bio_put() in + * iomap_read_end_io() + */ +} + +static void +xfs_read_end_io( + struct bio *bio) +{ + struct iomap_read_ioend *ioend = + container_of(bio, struct iomap_read_ioend, read_inline_bio); + struct xfs_inode *ip = XFS_I(ioend->io_inode); + + WARN_ON_ONCE(!queue_work(ip->i_mount->m_postread_workqueue, + &ioend->work)); +} + +static void +xfs_prepare_read_ioend( + struct iomap_read_ioend *ioend) +{ + if (!fsverity_active(ioend->io_inode)) + return; + + INIT_WORK(&ioend->work, &xfs_read_work_end_io); + ioend->read_inline_bio.bi_end_io = &xfs_read_end_io; +} + +static const struct iomap_readpage_ops xfs_readpage_ops = { + .prepare_ioend = &xfs_prepare_read_ioend, +}; + STATIC int xfs_vm_read_folio( struct file *unused, @@ -555,6 +598,7 @@ xfs_vm_read_folio( { struct iomap_readpage_ctx ctx = { .cur_folio = folio, + .ops = &xfs_readpage_ops, }; return iomap_read_folio(&ctx, &xfs_read_iomap_ops); @@ -566,6 +610,7 @@ xfs_vm_readahead( { struct iomap_readpage_ctx ctx = { .rac = rac, + .ops = &xfs_readpage_ops, }; iomap_readahead(&ctx, &xfs_read_iomap_ops); diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c index 285885c308bd..e0f3c5d709f6 100644 --- a/fs/xfs/xfs_iomap.c +++ b/fs/xfs/xfs_iomap.c @@ -27,6 +27,7 @@ #include "xfs_dquot_item.h" #include "xfs_dquot.h" #include "xfs_reflink.h" +#include "xfs_verity.h" #define XFS_ALLOC_ALIGN(mp, off) \ (((off) >> mp->m_allocsize_log) << mp->m_allocsize_log) @@ -83,8 +84,18 @@ xfs_iomap_valid( return true; } +static bool +xfs_verify_folio( + struct folio *folio, + loff_t pos, + unsigned int len) +{ + return fsverity_verify_folio(folio, len, pos); +} + static const struct iomap_folio_ops xfs_iomap_folio_ops = { .iomap_valid = xfs_iomap_valid, + .verify_folio = xfs_verify_folio, }; int diff --git a/fs/xfs/xfs_linux.h b/fs/xfs/xfs_linux.h index e88f18f85e4b..c574fbf4b67d 100644 --- a/fs/xfs/xfs_linux.h +++ b/fs/xfs/xfs_linux.h @@ -63,6 +63,7 @@ typedef __u32 xfs_nlink_t; #include #include #include +#include #include #include