From patchwork Mon Feb 12 16:57:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Albershteyn X-Patchwork-Id: 13553737 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B23353D564 for ; Mon, 12 Feb 2024 16:59:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757196; cv=none; b=Ufm0eggQX3TmUUwfd50Y6Da9nNz0aqvDTOTe61msiEzqVl6iM2LPC91k/Of4lhyr8ZGpg1tf4gcV4pVpLFeQkjaORF7npC7Sm0w3m+b2TENZYR7/7hleRO9oZnjyCNydcv18o75ZiVqjfSgvn1Iwil0Ha2SxnpLUvV94tAMt4eA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757196; c=relaxed/simple; bh=grAu43Eie92E+XOQ7d04C6cdM5uR0Ox/AK1rLCL9Nso=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Q7+OKLEzAjelb8ourgbOXe4hpF0HftHLpyphpm4vi5G+S3sEj+2vPwkkxzkMa2f8KJXOUzoy5DcXpTENHsKvW4rGwrIYj6G6HgeGyW+cA+cBKT9F0kit7mO3+wLP7HOw5SU/2AqPBCqpUCQCrIIH5zfV1ELEyAjgullhtmrCbbs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=AvnKSH0O; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="AvnKSH0O" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707757193; 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=qXH4oA7cWAgzu2mxLxXFHd34t/bbMKvcNeTx3/w9/Kc=; b=AvnKSH0OREyC5LKGLWcTU+tBkaCZQxdVTi8BD5GAmFv7x63WKH5wHbBjcP/mTwsPsnq3rN SuGu/wsAZNZ3rFxvc0mU33uU1/+kCSvmOL87nH3hQs+OPc2SMYBAUUlX2lbx37TburxvJz Cv0wXEqbcHZEj54JazIxVg97M4zNVuE= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-41-IbuDHt19ONKBPl7Mn1bOsw-1; Mon, 12 Feb 2024 11:59:51 -0500 X-MC-Unique: IbuDHt19ONKBPl7Mn1bOsw-1 Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-5611e1da4c6so2258294a12.1 for ; Mon, 12 Feb 2024 08:59:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707757190; x=1708361990; 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=qXH4oA7cWAgzu2mxLxXFHd34t/bbMKvcNeTx3/w9/Kc=; b=il8FPzoZwEvj6goC7REFFRf1obtOvOhHdYoVmeqO/6a+ZRmMiae4cBqTX9FPpEOk7R mcHzWnLUS4+K371MpuERN6AD1CtVzZeQE7IdXUCnZwNDU7DJzJJ1QIm/TXF0fqIiDSwU hrUA4uI5VayqaIzsEDBtg6ggntOun+R3emfDtk1OqclxnYoacJPKWVw0qLzpM4r6aQo6 ZtsZnAQcH/mUXYZaILyZWCZvqo1OzhMt4myubvyBMPC0MtPZnbKRNMxOEcBhYeGCe+mB wCnwwFaRE1qwSQcuaILDIcj8BiAKgR/lY93/+ipPDW18qaOAawPPH054fBszRmX96FCt khuQ== X-Forwarded-Encrypted: i=1; AJvYcCV8VYmc9i2GBT0J+tGkLFQh4c3Zx1HUzoJLmdraCoefyqz2rNfv/OFnvdIUbkqouZU4xxX6yFCecV8UjRrr2KqbAwXT43HbwuPe X-Gm-Message-State: AOJu0YwBRBPQqMTJb8JIw7fPmUdI+oL9YmtVw9KAkkyEH7WnO8NpUD7y VVBmtFgEmlHITTdQ/dhSwm8vCgK2rT4tKo1sZJN8TL/b5kESxp2cTgJv5w2wbDwDGu8Liy7DZrL M7TxZLhYfTjl4c/4PGtoqDZmNp7ZA6roVRoGafhV+aldivCcHlZ3Ppbk1 X-Received: by 2002:aa7:d7d4:0:b0:560:f198:2487 with SMTP id e20-20020aa7d7d4000000b00560f1982487mr5725042eds.25.1707757190728; Mon, 12 Feb 2024 08:59:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IFLTFCgjo7kG8sCDmOGPNpbHgDlSUUvJl8h+Af/sj+QMHQFJDSJruZtXYf+qgH+oOeYv5g8Jg== X-Received: by 2002:aa7:d7d4:0:b0:560:f198:2487 with SMTP id e20-20020aa7d7d4000000b00560f1982487mr5725032eds.25.1707757190528; Mon, 12 Feb 2024 08:59:50 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCUfEo4gBfEtirxv7HSr/88kXx7viNjV4HuFhlzUNIiY6IyNW2AWYmZVS4vQmlg90MWz21goBMarPo6dXNa+9eqUrYrm+vCO3BlCUvfdJ6ynwFiac43yD1m01qUPoWkHG1jp/r9sPnS4/ER4K+0uXiJmHEn0AzD/xStG3C/M/vXIdJWHySWWcXmngt8x2D0+veb4zPn8QcxNwCDm59PtK4BSAsixgL9l2cON1i6+AKvcLXm8nxCWUt+4Glmj41+v Received: from thinky.redhat.com ([109.183.6.197]) by smtp.gmail.com with ESMTPSA id 14-20020a0564021f4e00b0056176e95a88sm2620261edz.32.2024.02.12.08.59.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 08:59:50 -0800 (PST) From: Andrey Albershteyn To: fsverity@lists.linux.dev, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, chandan.babu@oracle.com, djwong@kernel.org, ebiggers@kernel.org Cc: Andrey Albershteyn , Eric Biggers Subject: [PATCH v4 01/25] fsverity: remove hash page spin lock Date: Mon, 12 Feb 2024 17:57:58 +0100 Message-Id: <20240212165821.1901300-2-aalbersh@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240212165821.1901300-1-aalbersh@redhat.com> References: <20240212165821.1901300-1-aalbersh@redhat.com> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The spin lock is not necessary here as it can be replaced with memory barrier which should be better performance-wise. When Merkle tree block size differs from page size, in is_hash_block_verified() two things are modified during check - a bitmap and PG_checked flag of the page. Each bit in the bitmap represent verification status of the Merkle tree blocks. PG_checked flag tells if page was just re-instantiated or was in pagecache. Both of this states are shared between verification threads. Page which was re-instantiated can not have already verified blocks (bit set in bitmap). The spin lock was used to allow only one thread to modify both of these states and keep order of operations. The only requirement here is that PG_Checked is set strictly after bitmap is updated. This way other threads which see that PG_Checked=1 (page cached) knows that bitmap is up-to-date. Otherwise, if PG_Checked is set before bitmap is cleared, other threads can see bit=1 and therefore will not perform verification of that Merkle tree block. However, there's still the case when one thread is setting a bit in verify_data_block() and other thread is clearing it in is_hash_block_verified(). This can happen if two threads get to !PageChecked branch and one of the threads is rescheduled before resetting the bitmap. This is fine as at worst blocks are re-verified in each thread. Signed-off-by: Eric Biggers Reviewed-by: Andrey Albershteyn Signed-off-by: Andrey Albershteyn --- fs/verity/fsverity_private.h | 1 - fs/verity/open.c | 1 - fs/verity/verify.c | 48 ++++++++++++++++++------------------ 3 files changed, 24 insertions(+), 26 deletions(-) diff --git a/fs/verity/fsverity_private.h b/fs/verity/fsverity_private.h index a6a6b2749241..b3506f56e180 100644 --- a/fs/verity/fsverity_private.h +++ b/fs/verity/fsverity_private.h @@ -69,7 +69,6 @@ struct fsverity_info { u8 file_digest[FS_VERITY_MAX_DIGEST_SIZE]; const struct inode *inode; unsigned long *hash_block_verified; - spinlock_t hash_page_init_lock; }; #define FS_VERITY_MAX_SIGNATURE_SIZE (FS_VERITY_MAX_DESCRIPTOR_SIZE - \ diff --git a/fs/verity/open.c b/fs/verity/open.c index 6c31a871b84b..fdeb95eca3af 100644 --- a/fs/verity/open.c +++ b/fs/verity/open.c @@ -239,7 +239,6 @@ struct fsverity_info *fsverity_create_info(const struct inode *inode, err = -ENOMEM; goto fail; } - spin_lock_init(&vi->hash_page_init_lock); } return vi; diff --git a/fs/verity/verify.c b/fs/verity/verify.c index 904ccd7e8e16..4fcad0825a12 100644 --- a/fs/verity/verify.c +++ b/fs/verity/verify.c @@ -19,7 +19,6 @@ static struct workqueue_struct *fsverity_read_workqueue; static bool is_hash_block_verified(struct fsverity_info *vi, struct page *hpage, unsigned long hblock_idx) { - bool verified; unsigned int blocks_per_page; unsigned int i; @@ -43,12 +42,20 @@ static bool is_hash_block_verified(struct fsverity_info *vi, struct page *hpage, * re-instantiated from the backing storage are re-verified. To do * this, we use PG_checked again, but now it doesn't really mean * "checked". Instead, now it just serves as an indicator for whether - * the hash page is newly instantiated or not. + * the hash page is newly instantiated or not. If the page is new, as + * indicated by PG_checked=0, we clear the bitmap bits for the page's + * blocks since they are untrustworthy, then set PG_checked=1. + * Otherwise we return the bitmap bit for the requested block. * - * The first thread that sees PG_checked=0 must clear the corresponding - * bitmap bits, then set PG_checked=1. This requires a spinlock. To - * avoid having to take this spinlock in the common case of - * PG_checked=1, we start with an opportunistic lockless read. + * Multiple threads may execute this code concurrently on the same page. + * This is safe because we use memory barriers to ensure that if a + * thread sees PG_checked=1, then it also sees the associated bitmap + * clearing to have occurred. Also, all writes and their corresponding + * reads are atomic, and all writes are safe to repeat in the event that + * multiple threads get into the PG_checked=0 section. (Clearing a + * bitmap bit again at worst causes a hash block to be verified + * redundantly. That event should be very rare, so it's not worth using + * a lock to avoid. Setting PG_checked again has no effect.) */ if (PageChecked(hpage)) { /* @@ -58,24 +65,17 @@ static bool is_hash_block_verified(struct fsverity_info *vi, struct page *hpage, smp_rmb(); return test_bit(hblock_idx, vi->hash_block_verified); } - spin_lock(&vi->hash_page_init_lock); - if (PageChecked(hpage)) { - verified = test_bit(hblock_idx, vi->hash_block_verified); - } else { - blocks_per_page = vi->tree_params.blocks_per_page; - hblock_idx = round_down(hblock_idx, blocks_per_page); - for (i = 0; i < blocks_per_page; i++) - clear_bit(hblock_idx + i, vi->hash_block_verified); - /* - * A write memory barrier is needed here to give RELEASE - * semantics to the below SetPageChecked() operation. - */ - smp_wmb(); - SetPageChecked(hpage); - verified = false; - } - spin_unlock(&vi->hash_page_init_lock); - return verified; + blocks_per_page = vi->tree_params.blocks_per_page; + hblock_idx = round_down(hblock_idx, blocks_per_page); + for (i = 0; i < blocks_per_page; i++) + clear_bit(hblock_idx + i, vi->hash_block_verified); + /* + * A write memory barrier is needed here to give RELEASE semantics to + * the below SetPageChecked() operation. + */ + smp_wmb(); + SetPageChecked(hpage); + return false; } /* From patchwork Mon Feb 12 16:57:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Albershteyn X-Patchwork-Id: 13553738 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CE6C83D566 for ; Mon, 12 Feb 2024 16:59:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757197; cv=none; b=H8D3/mhYwl9/jTXO6+ioG9SQdVwEX2rsXCm3HnWzvdzwWf4QcwgxpEDucKr9gtGaByWdfJH/DbbmZThXd+Uthc7ZthYWijBZeH5IAtz0z40c7KmEe8TUKPSV5sTK+25cRzHoJzW+WzbLl6TRs93YEh+LxmQQIhNcmRLk5JEJ+CA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757197; c=relaxed/simple; bh=87EPGtfLnNyrrHm7LdrhSWDHeKqbwuyh0xK6FyLRPoU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=IP2NHObE0RiB3JJn/sinL/55iRxsTB6lBBRLKsvu1YzAmuKPdRW5hcIDjaTNREKuTydKPj75j1eN6usfA4wZF8TsVEf96qI1OMbWKezMYeT1FCjRzXeynAbJRmlK2YA1WpfqufOTjrOjmdMUumAU4ujDkKrgWXTdo+dKVCAU9P0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=X3GI5FRx; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="X3GI5FRx" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707757194; 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=HwoEMzof6tyueQTnUsTnW4349H23j9VoC/QRGqyWkKM=; b=X3GI5FRxvdZDu3YXBXmSqIJw24+p+YoVIQ3IGtJ+QibzcWYT/8xY8M1yOlNFo++mTLVpy/ RIfS5Cq8JoXt3DLM+bsdgqoJ0lDl3hjRsX7hBlKLrB6ecFjFLGox3gjaGjc/oJCey1gFof M4iP4FGXhfMYRJKjkOCtIXE2qHvC6D4= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-324-1adGI3MMME27-OPWRkEdFg-1; Mon, 12 Feb 2024 11:59:53 -0500 X-MC-Unique: 1adGI3MMME27-OPWRkEdFg-1 Received: by mail-ed1-f71.google.com with SMTP id 4fb4d7f45d1cf-55ffcfed2ffso4899039a12.0 for ; Mon, 12 Feb 2024 08:59:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707757192; x=1708361992; 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=HwoEMzof6tyueQTnUsTnW4349H23j9VoC/QRGqyWkKM=; b=OymbmhKrrXkKVX2kkQXy9NZ3kOlsaTmPoT+tymdK//z+blMfZKYfP+4m52d5uEKO65 gzyHtTtGZLuEf1HOdmtJZ2YLiX6VHQf+NcpTfNtmDYYOovSKGaL02ASsG4M/i1Aj7TjS yh4DnQwBYQbIE550GMtULCl0MPv+4y6WaNSc6Z0guUvT2Df2JtsG13KxRX8clqxm5GIV ZiQJFsMsF97rTsT8Fypa1ou5a/Qurv/weGxs1YJv5SGnTKBmBbVIjBEr//7Pdp9Vrw4K Tugf3l6cJFlKzKvH4y2ZTL1KHQVhTIkM3iimsVuv2EoE3m2YB5Xn1P6uLpD1bV39cNx/ DoFA== X-Forwarded-Encrypted: i=1; AJvYcCXrX7JkpIGKq/lG4GDvFjdntjhs0JhyQL6I1HGO0XEX5iyAYh9asTE903wJA56PmMmVLDiP+9KyKmnGfRDixNTVc9gUsEWyxCeg X-Gm-Message-State: AOJu0YyJAxauA/pUm9SaKXKHSEtvkTsWjv73D0dw+WOIPYTYNCzM9SKg WwtsIG6bxVMgBB/j6CrPuh/osIPgr36rzt3JnkMk7orwQOGO9HKYmIBLQRHDKTPzAsmtUj2X/IP acwR5Oy0R6RoSzKR4Pdzgi7zz+qRul6pBGTSb6jJr90kq5Q3uWKe7snvO X-Received: by 2002:aa7:d981:0:b0:560:f90e:4da3 with SMTP id u1-20020aa7d981000000b00560f90e4da3mr98353eds.0.1707757192143; Mon, 12 Feb 2024 08:59:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IHfoUglQy6VQsrJO7Bagpl3UpwVFuud3MHrG+CNzln++dGXQv+WdUFa5OXovBNIauYyQ9cb3w== X-Received: by 2002:aa7:d981:0:b0:560:f90e:4da3 with SMTP id u1-20020aa7d981000000b00560f90e4da3mr98331eds.0.1707757191771; Mon, 12 Feb 2024 08:59:51 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCXhqGB6LbMhOcQTOQgMj83RdGTEaY3whGVGA8PGqFvwppxAzy8CpFHJkl6rYQf2kAItMH8HOxTUL6AGyf+3FSY2zvJsR/pI04kLc506uc4/aJwM48k67gNBX62vrEnp4WvkoJxC7o6d+vBiHtYj0hTnoc5ObmWXKh4xKDS8jI5CkjTcQvGZk8kwP+thsw+hRdRPVWZSlSpcD56gF6LDBDXIw4kTlNenUcMBMLN++ug0Xu4lNlSPOI2gA0xs9/NG9dVt9+p1cKx9JUmsoeI31hAT Received: from thinky.redhat.com ([109.183.6.197]) by smtp.gmail.com with ESMTPSA id 14-20020a0564021f4e00b0056176e95a88sm2620261edz.32.2024.02.12.08.59.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 08:59:51 -0800 (PST) From: Andrey Albershteyn To: fsverity@lists.linux.dev, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, chandan.babu@oracle.com, djwong@kernel.org, ebiggers@kernel.org Cc: Allison Henderson , Mark Tinguely , Dave Chinner Subject: [PATCH v4 02/25] xfs: add parent pointer support to attribute code Date: Mon, 12 Feb 2024 17:57:59 +0100 Message-Id: <20240212165821.1901300-3-aalbersh@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240212165821.1901300-1-aalbersh@redhat.com> References: <20240212165821.1901300-1-aalbersh@redhat.com> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Allison Henderson Add the new parent attribute type. XFS_ATTR_PARENT is used only for parent pointer entries; it uses reserved blocks like XFS_ATTR_ROOT. Signed-off-by: Mark Tinguely Signed-off-by: Dave Chinner Signed-off-by: Allison Henderson Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_attr.c | 3 ++- fs/xfs/libxfs/xfs_da_format.h | 5 ++++- fs/xfs/libxfs/xfs_log_format.h | 1 + fs/xfs/scrub/attr.c | 2 +- fs/xfs/xfs_trace.h | 3 ++- 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/fs/xfs/libxfs/xfs_attr.c b/fs/xfs/libxfs/xfs_attr.c index e965a48e7db9..1292ab043b4f 100644 --- a/fs/xfs/libxfs/xfs_attr.c +++ b/fs/xfs/libxfs/xfs_attr.c @@ -924,7 +924,8 @@ xfs_attr_set( struct xfs_inode *dp = args->dp; struct xfs_mount *mp = dp->i_mount; struct xfs_trans_res tres; - bool rsvd = (args->attr_filter & XFS_ATTR_ROOT); + bool rsvd = (args->attr_filter & (XFS_ATTR_ROOT | + XFS_ATTR_PARENT)); int error, local; int rmt_blks = 0; unsigned int total; diff --git a/fs/xfs/libxfs/xfs_da_format.h b/fs/xfs/libxfs/xfs_da_format.h index 24f9d1461f9a..18e8c7d44ab8 100644 --- a/fs/xfs/libxfs/xfs_da_format.h +++ b/fs/xfs/libxfs/xfs_da_format.h @@ -703,12 +703,15 @@ struct xfs_attr3_leafblock { #define XFS_ATTR_LOCAL_BIT 0 /* attr is stored locally */ #define XFS_ATTR_ROOT_BIT 1 /* limit access to trusted attrs */ #define XFS_ATTR_SECURE_BIT 2 /* limit access to secure attrs */ +#define XFS_ATTR_PARENT_BIT 3 /* parent pointer attrs */ #define XFS_ATTR_INCOMPLETE_BIT 7 /* attr in middle of create/delete */ #define XFS_ATTR_LOCAL (1u << XFS_ATTR_LOCAL_BIT) #define XFS_ATTR_ROOT (1u << XFS_ATTR_ROOT_BIT) #define XFS_ATTR_SECURE (1u << XFS_ATTR_SECURE_BIT) +#define XFS_ATTR_PARENT (1u << XFS_ATTR_PARENT_BIT) #define XFS_ATTR_INCOMPLETE (1u << XFS_ATTR_INCOMPLETE_BIT) -#define XFS_ATTR_NSP_ONDISK_MASK (XFS_ATTR_ROOT | XFS_ATTR_SECURE) +#define XFS_ATTR_NSP_ONDISK_MASK \ + (XFS_ATTR_ROOT | XFS_ATTR_SECURE | XFS_ATTR_PARENT) /* * Alignment for namelist and valuelist entries (since they are mixed diff --git a/fs/xfs/libxfs/xfs_log_format.h b/fs/xfs/libxfs/xfs_log_format.h index 269573c82808..eb7406c6ea41 100644 --- a/fs/xfs/libxfs/xfs_log_format.h +++ b/fs/xfs/libxfs/xfs_log_format.h @@ -972,6 +972,7 @@ struct xfs_icreate_log { */ #define XFS_ATTRI_FILTER_MASK (XFS_ATTR_ROOT | \ XFS_ATTR_SECURE | \ + XFS_ATTR_PARENT | \ XFS_ATTR_INCOMPLETE) /* diff --git a/fs/xfs/scrub/attr.c b/fs/xfs/scrub/attr.c index 83c7feb38714..49f91cc85a65 100644 --- a/fs/xfs/scrub/attr.c +++ b/fs/xfs/scrub/attr.c @@ -494,7 +494,7 @@ xchk_xattr_rec( /* Retrieve the entry and check it. */ hash = be32_to_cpu(ent->hashval); badflags = ~(XFS_ATTR_LOCAL | XFS_ATTR_ROOT | XFS_ATTR_SECURE | - XFS_ATTR_INCOMPLETE); + XFS_ATTR_INCOMPLETE | XFS_ATTR_PARENT); if ((ent->flags & badflags) != 0) xchk_da_set_corrupt(ds, level); if (ent->flags & XFS_ATTR_LOCAL) { diff --git a/fs/xfs/xfs_trace.h b/fs/xfs/xfs_trace.h index 0984a1c884c7..07e8a69f8e56 100644 --- a/fs/xfs/xfs_trace.h +++ b/fs/xfs/xfs_trace.h @@ -83,7 +83,8 @@ struct xfs_perag; #define XFS_ATTR_FILTER_FLAGS \ { XFS_ATTR_ROOT, "ROOT" }, \ { XFS_ATTR_SECURE, "SECURE" }, \ - { XFS_ATTR_INCOMPLETE, "INCOMPLETE" } + { XFS_ATTR_INCOMPLETE, "INCOMPLETE" }, \ + { XFS_ATTR_PARENT, "PARENT" } DECLARE_EVENT_CLASS(xfs_attr_list_class, TP_PROTO(struct xfs_attr_list_context *ctx), From patchwork Mon Feb 12 16:58:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Albershteyn X-Patchwork-Id: 13553739 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 64DD33D571 for ; Mon, 12 Feb 2024 16:59:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757198; cv=none; b=GMSWLp2JVEEwJj5cCKGeMuB+V3o6uGAWup5B7H+LnadZ4/+2ccpQkfm2VsQBuk2fAz1RZaljMhRMP3rb1yVlkj1r+Sw1wHqveXo2WhaQ5LkcxiL2OTZHnnaw3rbhbvfhJ2LJLVlMUv+Kjd0rU1oVYG5oIFuyYj5zr2hhWGHS37Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757198; c=relaxed/simple; bh=iGCn00rEq7PG+afvZlZGmDPn+zqmaqJVYlT49tydKx4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qGeKjt4VIqYfbv7LKRA/bBOn43GT+yL2/LBmWpSIYYn7I/FJ8SQeENjYy8k9zZHyT9Vx3vJXaO0k1QPwJEi9dfdYWoEjEuJJFSPagTz6Bxj/qw77v+TTcllHjbcTFtT8TOc+QeIk1++NLxvKShvbcFxWOKnLbDip1z5Ppy6jekk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=e7bWp9aI; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="e7bWp9aI" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707757195; 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=oBcesGNJ85C40O8Wbwe4Jalf+KuBJVBEen9IDHFprmk=; b=e7bWp9aIrLFYJKpRrPcHgst4fLfT3P7gaO+ZMT64XU7DmriSVHBMYCb32S/RHjJFoIXniO Q1nz60DUpGc9B5tphLgL1TL87JfnSoC/EnNm5Cc9IVC0d0muVM3qPrW6zTN5zqJnLS1DuL qXyKKbunkx49rPx+M+69VDGNSGvIDMo= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-189-U73VCrmtPR6miijwFsu9aw-1; Mon, 12 Feb 2024 11:59:53 -0500 X-MC-Unique: U73VCrmtPR6miijwFsu9aw-1 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-a2c4e9cb449so228875266b.1 for ; Mon, 12 Feb 2024 08:59:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707757192; x=1708361992; 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=oBcesGNJ85C40O8Wbwe4Jalf+KuBJVBEen9IDHFprmk=; b=n/Jp0nLF0FjAPZtXu00kwprICX5hbO08mauCmOazaSTiBUlgeLo3T68NIJCldQJtq5 gMZ1PfjC4F7if8OtSd9BFon/wM79kpKD/8rOyZfhpSBcC+X/OzeSAY5y3SeNQL7azXI8 1w+JG9soMPUOoskiZnouCWgW3w7vGwzvDwm0WBrnvSjv3g6T+7ua9w9hDs0605Z0RPKO nkK8X7x0noADyY3R/IKo+06FinfqHhiy5A1dEZUso3MlkGJO3dHLEy4Ac8HAkPqcGEo0 5zuWKqC6lbj1WpNmWuuIYTNANksQn/C5zpR7CDbG5W6K7/wG7j/rUbl3YHvoDtjBDZFx VIRA== X-Forwarded-Encrypted: i=1; AJvYcCUm5hSqeP5uLS/CO1qZEKBfAseQnp218MrgMY8xEX4YjZrsnGSo2zaybycDMRZ9dFYCQA0xoxWxkwFFuBexPqjUAHSQxKMgC2Qi X-Gm-Message-State: AOJu0YwFSUgYHaVKCezF4H2CN/O63mTEUKe2pJYSzUcqpyBTBBllxia9 1p5ePgYjRsVCm64hfFDfPcYbA+zlXPi3qW2TccG+rQHNl1tKrARQk82yt3Apim4GtKbgX34BCyV x9AjfSE6y3//pmfXzGsxbTxtxiPEDchwsM6JanZz2ec6J0jPMRSclD2ge X-Received: by 2002:aa7:d38c:0:b0:55f:8c38:36a9 with SMTP id x12-20020aa7d38c000000b0055f8c3836a9mr5424651edq.42.1707757192752; Mon, 12 Feb 2024 08:59:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IHuAQY974HjwvfUXd9S/s2x7iBcid/UjzWaSIP6F1pOXoRVZe6HEND0f94MhpBhdqSR92/o6g== X-Received: by 2002:aa7:d38c:0:b0:55f:8c38:36a9 with SMTP id x12-20020aa7d38c000000b0055f8c3836a9mr5424640edq.42.1707757192557; Mon, 12 Feb 2024 08:59:52 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCUGdzvN1PlvyWuInXAHyDTNZDbZ3DXfxNsW3DTnGhPYQmdNWEbiWbsvxSno4SsYIW0Gcc8LWGDwRbTSQjOvUTlNaq3J5lBwDWuoz3D61CyakzhU+/Ztf5vms14kBfBl/qVaSH9L8ZAthUJf82RYURpX4L4q69P/l+ZSHjyspsgs02K9geKDabKzvF1PUu2mwvnnBAFZcgcXNEYnNv6JM0AnWcmeZWP24ZAuM994uoKNEWHfrsbobAzZthWH4rHt Received: from thinky.redhat.com ([109.183.6.197]) by smtp.gmail.com with ESMTPSA id 14-20020a0564021f4e00b0056176e95a88sm2620261edz.32.2024.02.12.08.59.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 08:59:52 -0800 (PST) From: Andrey Albershteyn To: fsverity@lists.linux.dev, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, chandan.babu@oracle.com, djwong@kernel.org, ebiggers@kernel.org Cc: Allison Henderson , Dave Chinner Subject: [PATCH v4 03/25] xfs: define parent pointer ondisk extended attribute format Date: Mon, 12 Feb 2024 17:58:00 +0100 Message-Id: <20240212165821.1901300-4-aalbersh@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240212165821.1901300-1-aalbersh@redhat.com> References: <20240212165821.1901300-1-aalbersh@redhat.com> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Allison Henderson We need to define the parent pointer attribute format before we start adding support for it into all the code that needs to use it. The EA format we will use encodes the following information: name={parent inode #, parent inode generation, dirent namehash} value={dirent name} The inode/gen gives all the information we need to reliably identify the parent without requiring child->parent lock ordering, and allows userspace to do pathname component level reconstruction without the kernel ever needing to verify the parent itself as part of ioctl calls. Storing the dirent name hash in the key reduces hash collisions if a file is hardlinked multiple times in the same directory. By using the NVLOOKUP mode in the extended attribute code to match parent pointers using both the xattr name and value, we can identify the exact parent pointer EA we need to modify/remove in rename/unlink operations without searching the entire EA space. By storing the dirent name, we have enough information to be able to validate and reconstruct damaged directory trees. Earlier iterations of this patchset encoded the directory offset in the parent pointer key, but this format required repair to keep that in sync across directory rebuilds, which is unnecessary complexity. Signed-off-by: Dave Chinner Signed-off-by: Allison Henderson Reviewed-by: Darrick J. Wong [djwong: replace diroffset with the namehash in the pptr key] Signed-off-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_da_format.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/fs/xfs/libxfs/xfs_da_format.h b/fs/xfs/libxfs/xfs_da_format.h index 18e8c7d44ab8..e5eacfe75021 100644 --- a/fs/xfs/libxfs/xfs_da_format.h +++ b/fs/xfs/libxfs/xfs_da_format.h @@ -867,4 +867,24 @@ static inline unsigned int xfs_dir2_dirblock_bytes(struct xfs_sb *sbp) xfs_failaddr_t xfs_da3_blkinfo_verify(struct xfs_buf *bp, struct xfs_da3_blkinfo *hdr3); +/* + * Parent pointer attribute format definition + * + * The xattr name encodes the parent inode number, generation and the crc32c + * hash of the dirent name. + * + * The xattr value contains the dirent name. + */ +struct xfs_parent_name_rec { + __be64 p_ino; + __be32 p_gen; + __be32 p_namehash; +}; + +/* + * Maximum size of the dirent name that can be stored in a parent pointer. + * This matches the maximum dirent name length. + */ +#define XFS_PARENT_DIRENT_NAME_MAX_SIZE (MAXNAMELEN - 1) + #endif /* __XFS_DA_FORMAT_H__ */ From patchwork Mon Feb 12 16:58:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Albershteyn X-Patchwork-Id: 13553740 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 462AF3D995 for ; Mon, 12 Feb 2024 16:59:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757200; cv=none; b=A97vU+r4qCV5zmmKm+F7oGMBWT3xW+MZ+KPQiLL0jH0fzYB3tG0WB6xLrsccfFkFAuTe/LzDqYQnIJ1w5K5ffSO9zcDMnaL+4ROXkZ4jUsNxUpuYh/kXWbZ4rCk78HcZDrkB3CDw5NlmNi6r5HQADk1Je5J7rrBZvc5QNBve24Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757200; c=relaxed/simple; bh=9JqrbAfmSsH3ERdkRpC8IPSggMzVJkaaLqkB8F5T9EI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=fJOPKDnR2bj3NY1H0Lw/lnDU6cPvIpDHBvrZFDdBS2F3ycLJsJ4/lVj3unhhEeKthg8T1E0t0F2dhy1FvbsLJpyD8mjJEgVjruc61Vvk/rDBwy5/EvxodgHMkx47JDhxo0cTyJmJVyxkP1SVLl9kgnmt+iUrMDwMOKkKB8sxZFE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=OylYtCGI; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="OylYtCGI" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707757197; 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=7qFP4poM8gEvIFjfXy0QwY6pOEwAMOFuQs9zumtA0Rw=; b=OylYtCGIpLQITjs7fMBqhSE4eCrKgEumlwRCBSSMyVLeSGRcBtOT1/Bu+m0Qv5wlgHH8V8 GZ5BBwllFLfW6D6+iHYoCNBZ/2MrNn6g2huImTAW4BvUaoBFQ2wqCg7x9c73bbuzSZ+6A5 if7vhPn8TRvGCwszwVjs8BMS7Xz99Cc= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-175-qXBD_INCPp-ZhdjVcvYhPA-1; Mon, 12 Feb 2024 11:59:55 -0500 X-MC-Unique: qXBD_INCPp-ZhdjVcvYhPA-1 Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-559555e38b0so3140356a12.3 for ; Mon, 12 Feb 2024 08:59:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707757194; x=1708361994; 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=7qFP4poM8gEvIFjfXy0QwY6pOEwAMOFuQs9zumtA0Rw=; b=JZ5W7QtMzen3xzwzZYEpIyNTIjM7C5zDUwR1Fb80aZsokMbddV9CynBLJUtyzRf+vd lj4J+5/ex/pNJ9yIIF6slBdQacmHn5POhvUnAgqnIQZjb1/pwvSCiZyGO0mNvu+BLkFx TvOh9LYW8zQv4enRqw7bU+Crnibt8Cqr1se/ZTmWU408uizVI7cxRGMil2XbqG7Md1TV o50yAKEYPzeA8LZHkJS7OWPgjnxaPqQufCS/KTVwXOE0dFl+dxWyTXnkAmbkJnPhOCdh woaBoo4xTBqbfshUnEPO/o6/bKNFAC5gP+j1R4N5BcIVu45aGHIOY4r+iGa4Fbfnen7A o1tg== X-Forwarded-Encrypted: i=1; AJvYcCXWHHbVP6Pos8L0fbH7Marbdiq3665y9eCBOF6XCN4J4tcJ8+Sdk8fBJG7MiZfFiDe/wfQve8uBC6Bvq0KKUeLfPLcUvor62A9D X-Gm-Message-State: AOJu0Yx4qfwn0cetzaiopLXSl0bpkPRdVF2X1Ei59Ll+Odfy7co2XZ07 fiCk91gu9Fig8sBrDrCSjcxWYuY5pCCrkdNrUKEHuZXkWDDOiV8KrVaNJsFVFfgRAw5HL3S4tyv VT/xxwTIdJAXae3uPJO9Jk67YJigVWNVewkcpzqa+PdYymbAiYBgDzoVt X-Received: by 2002:a50:f617:0:b0:561:9652:5637 with SMTP id c23-20020a50f617000000b0056196525637mr3659216edn.37.1707757194134; Mon, 12 Feb 2024 08:59:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IGyqJb1xpGFjqn3vJ1D5hirpPLDzmRKHxkeP+Sul2WzwXFn0vPfXCQQQxMCa6uPvEMMQbzT7A== X-Received: by 2002:a50:f617:0:b0:561:9652:5637 with SMTP id c23-20020a50f617000000b0056196525637mr3659193edn.37.1707757193796; Mon, 12 Feb 2024 08:59:53 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCW15t2/qN+81/gTVJVaHFlHCRoy1SV6DbG8x2VqPSugS1HhtAx2zTTQr1Q6u1PNlEg5V3nZUjaI7j76OEk8aQIdPjXyyZ97YD83BdXLq5oWzaUmPfTVHnUVDAOhBo8DD1s78Ei6+LZkX6u/4zBrMQ6IoPRwXTgJ6nyEE86RRpNBv5bhUrRADnka3myGH6mexm5lulkydp/ZHrbv/9EupTI1msGa8udBR2ij Received: from thinky.redhat.com ([109.183.6.197]) by smtp.gmail.com with ESMTPSA id 14-20020a0564021f4e00b0056176e95a88sm2620261edz.32.2024.02.12.08.59.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 08:59:53 -0800 (PST) From: Andrey Albershteyn To: fsverity@lists.linux.dev, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, chandan.babu@oracle.com, djwong@kernel.org, ebiggers@kernel.org Cc: Allison Henderson Subject: [PATCH v4 04/25] xfs: add parent pointer validator functions Date: Mon, 12 Feb 2024 17:58:01 +0100 Message-Id: <20240212165821.1901300-5-aalbersh@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240212165821.1901300-1-aalbersh@redhat.com> References: <20240212165821.1901300-1-aalbersh@redhat.com> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Allison Henderson Attribute names of parent pointers are not strings. So we need to modify attr_namecheck to verify parent pointer records when the XFS_ATTR_PARENT flag is set. At the same time, we need to validate attr values during log recovery if the xattr is really a parent pointer. Signed-off-by: Allison Henderson Reviewed-by: Darrick J. Wong [djwong: move functions to xfs_parent.c, adjust for new disk format] Signed-off-by: Darrick J. Wong --- fs/xfs/Makefile | 1 + fs/xfs/libxfs/xfs_attr.c | 10 ++- fs/xfs/libxfs/xfs_attr.h | 3 +- fs/xfs/libxfs/xfs_da_format.h | 8 +++ fs/xfs/libxfs/xfs_parent.c | 113 ++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_parent.h | 19 ++++++ fs/xfs/scrub/attr.c | 2 +- fs/xfs/xfs_attr_item.c | 6 +- fs/xfs/xfs_attr_list.c | 14 +++-- 9 files changed, 165 insertions(+), 11 deletions(-) create mode 100644 fs/xfs/libxfs/xfs_parent.c create mode 100644 fs/xfs/libxfs/xfs_parent.h diff --git a/fs/xfs/Makefile b/fs/xfs/Makefile index fbe3cdc79036..8be90c685b0b 100644 --- a/fs/xfs/Makefile +++ b/fs/xfs/Makefile @@ -41,6 +41,7 @@ xfs-y += $(addprefix libxfs/, \ xfs_inode_buf.o \ xfs_log_rlimit.o \ xfs_ag_resv.o \ + xfs_parent.o \ xfs_rmap.o \ xfs_rmap_btree.o \ xfs_refcount.o \ diff --git a/fs/xfs/libxfs/xfs_attr.c b/fs/xfs/libxfs/xfs_attr.c index 1292ab043b4f..f9846df41669 100644 --- a/fs/xfs/libxfs/xfs_attr.c +++ b/fs/xfs/libxfs/xfs_attr.c @@ -26,6 +26,7 @@ #include "xfs_trace.h" #include "xfs_attr_item.h" #include "xfs_xattr.h" +#include "xfs_parent.h" struct kmem_cache *xfs_attr_intent_cache; @@ -1514,9 +1515,14 @@ xfs_attr_node_get( /* Returns true if the attribute entry name is valid. */ bool xfs_attr_namecheck( - const void *name, - size_t length) + struct xfs_mount *mp, + const void *name, + size_t length, + unsigned int flags) { + if (flags & XFS_ATTR_PARENT) + return xfs_parent_namecheck(mp, name, length, flags); + /* * MAXNAMELEN includes the trailing null, but (name/length) leave it * out, so use >= for the length check. diff --git a/fs/xfs/libxfs/xfs_attr.h b/fs/xfs/libxfs/xfs_attr.h index 81be9b3e4004..92711c8d2a9f 100644 --- a/fs/xfs/libxfs/xfs_attr.h +++ b/fs/xfs/libxfs/xfs_attr.h @@ -547,7 +547,8 @@ int xfs_attr_get(struct xfs_da_args *args); int xfs_attr_set(struct xfs_da_args *args); int xfs_attr_set_iter(struct xfs_attr_intent *attr); int xfs_attr_remove_iter(struct xfs_attr_intent *attr); -bool xfs_attr_namecheck(const void *name, size_t length); +bool xfs_attr_namecheck(struct xfs_mount *mp, const void *name, size_t length, + unsigned int flags); int xfs_attr_calc_size(struct xfs_da_args *args, int *local); void xfs_init_attr_trans(struct xfs_da_args *args, struct xfs_trans_res *tres, unsigned int *total); diff --git a/fs/xfs/libxfs/xfs_da_format.h b/fs/xfs/libxfs/xfs_da_format.h index e5eacfe75021..1b79c4de90bc 100644 --- a/fs/xfs/libxfs/xfs_da_format.h +++ b/fs/xfs/libxfs/xfs_da_format.h @@ -746,6 +746,14 @@ xfs_attr3_leaf_name(xfs_attr_leafblock_t *leafp, int idx) return &((char *)leafp)[be16_to_cpu(entries[idx].nameidx)]; } +static inline int +xfs_attr3_leaf_flags(xfs_attr_leafblock_t *leafp, int idx) +{ + struct xfs_attr_leaf_entry *entries = xfs_attr3_leaf_entryp(leafp); + + return entries[idx].flags; +} + static inline xfs_attr_leaf_name_remote_t * xfs_attr3_leaf_name_remote(xfs_attr_leafblock_t *leafp, int idx) { diff --git a/fs/xfs/libxfs/xfs_parent.c b/fs/xfs/libxfs/xfs_parent.c new file mode 100644 index 000000000000..1d45f926c13a --- /dev/null +++ b/fs/xfs/libxfs/xfs_parent.c @@ -0,0 +1,113 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2022-2024 Oracle. + * All rights reserved. + */ +#include "xfs.h" +#include "xfs_fs.h" +#include "xfs_format.h" +#include "xfs_da_format.h" +#include "xfs_log_format.h" +#include "xfs_shared.h" +#include "xfs_trans_resv.h" +#include "xfs_mount.h" +#include "xfs_bmap_btree.h" +#include "xfs_inode.h" +#include "xfs_error.h" +#include "xfs_trace.h" +#include "xfs_trans.h" +#include "xfs_da_btree.h" +#include "xfs_attr.h" +#include "xfs_dir2.h" +#include "xfs_dir2_priv.h" +#include "xfs_attr_sf.h" +#include "xfs_bmap.h" +#include "xfs_defer.h" +#include "xfs_log.h" +#include "xfs_xattr.h" +#include "xfs_parent.h" +#include "xfs_trans_space.h" + +/* + * Parent pointer attribute handling. + * + * Because the attribute value is a filename component, it will never be longer + * than 255 bytes. This means the attribute will always be a local format + * attribute as it is xfs_attr_leaf_entsize_local_max() for v5 filesystems will + * always be larger than this (max is 75% of block size). + * + * Creating a new parent attribute will always create a new attribute - there + * should never, ever be an existing attribute in the tree for a new inode. + * ENOSPC behavior is problematic - creating the inode without the parent + * pointer is effectively a corruption, so we allow parent attribute creation + * to dip into the reserve block pool to avoid unexpected ENOSPC errors from + * occurring. + */ + +/* Return true if parent pointer EA name is valid. */ +bool +xfs_parent_namecheck( + struct xfs_mount *mp, + const struct xfs_parent_name_rec *rec, + size_t reclen, + unsigned int attr_flags) +{ + if (!(attr_flags & XFS_ATTR_PARENT)) + return false; + + /* pptr updates use logged xattrs, so we should never see this flag */ + if (attr_flags & XFS_ATTR_INCOMPLETE) + return false; + + if (reclen != sizeof(struct xfs_parent_name_rec)) + return false; + + /* Only one namespace bit allowed. */ + if (hweight32(attr_flags & XFS_ATTR_NSP_ONDISK_MASK) > 1) + return false; + + return true; +} + +/* Return true if parent pointer EA value is valid. */ +bool +xfs_parent_valuecheck( + struct xfs_mount *mp, + const void *value, + size_t valuelen) +{ + if (valuelen == 0 || valuelen > XFS_PARENT_DIRENT_NAME_MAX_SIZE) + return false; + + if (value == NULL) + return false; + + return true; +} + +/* Return true if the ondisk parent pointer is consistent. */ +bool +xfs_parent_hashcheck( + struct xfs_mount *mp, + const struct xfs_parent_name_rec *rec, + const void *value, + size_t valuelen) +{ + struct xfs_name dname = { + .name = value, + .len = valuelen, + }; + xfs_ino_t p_ino; + + /* Valid dirent name? */ + if (!xfs_dir2_namecheck(value, valuelen)) + return false; + + /* Valid inode number? */ + p_ino = be64_to_cpu(rec->p_ino); + if (!xfs_verify_dir_ino(mp, p_ino)) + return false; + + /* Namehash matches name? */ + return be32_to_cpu(rec->p_namehash) == xfs_dir2_hashname(mp, &dname); +} diff --git a/fs/xfs/libxfs/xfs_parent.h b/fs/xfs/libxfs/xfs_parent.h new file mode 100644 index 000000000000..fcfeddb645f6 --- /dev/null +++ b/fs/xfs/libxfs/xfs_parent.h @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2022-2024 Oracle. + * All Rights Reserved. + */ +#ifndef __XFS_PARENT_H__ +#define __XFS_PARENT_H__ + +/* Metadata validators */ +bool xfs_parent_namecheck(struct xfs_mount *mp, + const struct xfs_parent_name_rec *rec, size_t reclen, + unsigned int attr_flags); +bool xfs_parent_valuecheck(struct xfs_mount *mp, const void *value, + size_t valuelen); +bool xfs_parent_hashcheck(struct xfs_mount *mp, + const struct xfs_parent_name_rec *rec, const void *value, + size_t valuelen); + +#endif /* __XFS_PARENT_H__ */ diff --git a/fs/xfs/scrub/attr.c b/fs/xfs/scrub/attr.c index 49f91cc85a65..9a1f59f7b5a4 100644 --- a/fs/xfs/scrub/attr.c +++ b/fs/xfs/scrub/attr.c @@ -195,7 +195,7 @@ xchk_xattr_listent( } /* Does this name make sense? */ - if (!xfs_attr_namecheck(name, namelen)) { + if (!xfs_attr_namecheck(sx->sc->mp, name, namelen, flags)) { xchk_fblock_set_corrupt(sx->sc, XFS_ATTR_FORK, args.blkno); goto fail_xref; } diff --git a/fs/xfs/xfs_attr_item.c b/fs/xfs/xfs_attr_item.c index 9e02111bd890..6f6eeaaa9010 100644 --- a/fs/xfs/xfs_attr_item.c +++ b/fs/xfs/xfs_attr_item.c @@ -588,7 +588,8 @@ xfs_attr_recover_work( */ attrp = &attrip->attri_format; if (!xfs_attri_validate(mp, attrp) || - !xfs_attr_namecheck(nv->name.i_addr, nv->name.i_len)) + !xfs_attr_namecheck(mp, nv->name.i_addr, nv->name.i_len, + attrp->alfi_attr_filter)) return -EFSCORRUPTED; attr = xfs_attri_recover_work(mp, dfp, attrp, &ip, nv); @@ -728,7 +729,8 @@ xlog_recover_attri_commit_pass2( return -EFSCORRUPTED; } - if (!xfs_attr_namecheck(attr_name, attri_formatp->alfi_name_len)) { + if (!xfs_attr_namecheck(mp, attr_name, attri_formatp->alfi_name_len, + attri_formatp->alfi_attr_filter)) { XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, item->ri_buf[1].i_addr, item->ri_buf[1].i_len); return -EFSCORRUPTED; diff --git a/fs/xfs/xfs_attr_list.c b/fs/xfs/xfs_attr_list.c index e368ad671e26..1521ca2f0ce3 100644 --- a/fs/xfs/xfs_attr_list.c +++ b/fs/xfs/xfs_attr_list.c @@ -58,6 +58,7 @@ xfs_attr_shortform_list( struct xfs_attr_sf_sort *sbuf, *sbp; struct xfs_attr_sf_hdr *sf = dp->i_af.if_data; struct xfs_attr_sf_entry *sfe; + struct xfs_mount *mp = dp->i_mount; int sbsize, nsbuf, count, i; int error = 0; @@ -81,8 +82,9 @@ xfs_attr_shortform_list( (dp->i_af.if_bytes + sf->count * 16) < context->bufsize)) { for (i = 0, sfe = xfs_attr_sf_firstentry(sf); i < sf->count; i++) { if (XFS_IS_CORRUPT(context->dp->i_mount, - !xfs_attr_namecheck(sfe->nameval, - sfe->namelen))) + !xfs_attr_namecheck(mp, sfe->nameval, + sfe->namelen, + sfe->flags))) return -EFSCORRUPTED; context->put_listent(context, sfe->flags, @@ -173,8 +175,9 @@ xfs_attr_shortform_list( cursor->offset = 0; } if (XFS_IS_CORRUPT(context->dp->i_mount, - !xfs_attr_namecheck(sbp->name, - sbp->namelen))) { + !xfs_attr_namecheck(mp, sbp->name, + sbp->namelen, + sbp->flags))) { error = -EFSCORRUPTED; goto out; } @@ -464,7 +467,8 @@ xfs_attr3_leaf_list_int( } if (XFS_IS_CORRUPT(context->dp->i_mount, - !xfs_attr_namecheck(name, namelen))) + !xfs_attr_namecheck(mp, name, namelen, + entry->flags))) return -EFSCORRUPTED; context->put_listent(context, entry->flags, name, namelen, valuelen); From patchwork Mon Feb 12 16:58:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Albershteyn X-Patchwork-Id: 13553741 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C33993D571 for ; Mon, 12 Feb 2024 16:59:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757200; cv=none; b=nFqQmn4TF4Mu00Q8yxmdcjv+rTH28jlc/IbGglphAAFcgjwSSiWzILsv2zBGykhjXBKfWnGtoAJeBofy/zaEvjh5K2pk1oW1o7iXDRhSJcN3w8QwRpISmknP26oMzdhfb7YOsK5uMiwQCGbIc8uNJDe8NhkTEcpTEBn3jvmAld8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757200; c=relaxed/simple; bh=cvhOJNMgYbCTZs0crMMOB5Pl60dq3zxJ6bSAHeiofko=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ho8vcIFZi2BFXR9hpvcpA2chuGPNdyhaCZqvHHIE8SRT93XttK3JGUl3Zr0X5coAn/jUNCY/5Q01WY1nkw+xqLxyRHdkbi8uYvu1Mhp1NxiX9q3isJ9MBQxpUq+66SLgDnu62XPh+9QGaY3zn/l8v+vA6qms9xIeMkV3dOlwLPM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=QgkvNQzR; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="QgkvNQzR" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707757197; 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=2eZDjHaP7Kupt8d6Iu2ty2GFMw3W0f+xpOseohnHwTk=; b=QgkvNQzRABClfyHN7EUeiR8M2W4rUFw3Gwl3+n9KRatC0j4m+ZfppebrNRH9mSJxN0lvQr v4tq1BO+UyrgKJk3npvNw3TVm9iHOoDHoCtXiHCq2BrEEpDIyJwhtXJHuVUCEYY/cv6MNx UZiynRqKqpiLokcYf3vWRf8tz88sDjM= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-307-iL-5HdG7O6WgTW8KG55LMg-1; Mon, 12 Feb 2024 11:59:56 -0500 X-MC-Unique: iL-5HdG7O6WgTW8KG55LMg-1 Received: by mail-ed1-f71.google.com with SMTP id 4fb4d7f45d1cf-5597da35ebbso2420661a12.2 for ; Mon, 12 Feb 2024 08:59:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707757195; x=1708361995; 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=2eZDjHaP7Kupt8d6Iu2ty2GFMw3W0f+xpOseohnHwTk=; b=tT31Kk7rO/dAMtz8ewgSw7QPs/oPTQRPLZHdgshWrtOKqvN0KglGBruQVj7+HlszyX Y6masmVuTFR6um8hy8ffTNi44pQs9LAHN13iJrQ3NxxsO7Ij7jW5TzfoZHSIMkzoMFrk 5LSgxebOV0H77WGVwLem+3Lz9EgHIuFFCEmZIwEFN/lC/S3e89RikPYOvMA2KhNtuCQ8 a+lRP2kRdaQtKbrmBYHYWwKjLuCJDgtfGSejuoULGh9GWHCA+x4YHbn0Xrp/XHpksJOp BDsSOoi7A2k65g4O9E6hmrmZdWIN6nSfWToqOjZpcs582Lj8kwxAeOkAk//l/kDP4Fy2 ZcxA== X-Gm-Message-State: AOJu0YxobdL4Fv+CjRhaeaWRhWkM0X3IYOXFPquBJvm1YOF+hJd8sCBt eQZ9M+koNXyk7Qm5IQ1vRrvOCgLOo62iOyZ3w5m+xXv4QTcgXkffTRjpNvlcQrxs+8RPGMv7SAa yMJv55ahKajIN9ZVOaMCtAPp9O7QPE9aZKyxmaprBx3xp05JTEuNi3dV0 X-Received: by 2002:a05:6402:544:b0:55f:c3c1:34e with SMTP id i4-20020a056402054400b0055fc3c1034emr1476950edx.15.1707757195350; Mon, 12 Feb 2024 08:59:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IGyQP1vpD0d7s1DLfQrdN0VArL3Z7/S/UGhBKfUY5OPPaBlXP9kgpE6F85URgM94E6HCoBQBw== X-Received: by 2002:a05:6402:544:b0:55f:c3c1:34e with SMTP id i4-20020a056402054400b0055fc3c1034emr1476936edx.15.1707757195175; Mon, 12 Feb 2024 08:59:55 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVMULeE9s3nH+f2UMQCVjIYAATNr91A4Ha5f9VSJraW6oqpiPL3tmAHAY6PdEz054BS664a2YaRiaMUr/8qUiCssI9wfT114LLRO4KVxI9+V0jszODBczr1+t3NlI/Rz45VtOoo6Ui5gEPxUDyPQKU3N9O2/8/ta9Zk1gx9LBEHd/xz9LtHu9mXtCI9WUv9KptxyN5Fs3L6rp+W5VAUwLQh/y9gvRq8YnP/ Received: from thinky.redhat.com ([109.183.6.197]) by smtp.gmail.com with ESMTPSA id 14-20020a0564021f4e00b0056176e95a88sm2620261edz.32.2024.02.12.08.59.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 08:59:54 -0800 (PST) From: Andrey Albershteyn To: fsverity@lists.linux.dev, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, chandan.babu@oracle.com, djwong@kernel.org, ebiggers@kernel.org Cc: Andrey Albershteyn Subject: [PATCH v4 05/25] fs: add FS_XFLAG_VERITY for verity files Date: Mon, 12 Feb 2024 17:58:02 +0100 Message-Id: <20240212165821.1901300-6-aalbersh@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240212165821.1901300-1-aalbersh@redhat.com> References: <20240212165821.1901300-1-aalbersh@redhat.com> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add extended attribute FS_XFLAG_VERITY for inodes with fs-verity enabled. Signed-off-by: Andrey Albershteyn --- Documentation/filesystems/fsverity.rst | 12 ++++++++++++ fs/ioctl.c | 11 +++++++++++ include/uapi/linux/fs.h | 1 + 3 files changed, 24 insertions(+) diff --git a/Documentation/filesystems/fsverity.rst b/Documentation/filesystems/fsverity.rst index 13e4b18e5dbb..19e59e87999e 100644 --- a/Documentation/filesystems/fsverity.rst +++ b/Documentation/filesystems/fsverity.rst @@ -326,6 +326,18 @@ the file has fs-verity enabled. This can perform better than FS_IOC_GETFLAGS and FS_IOC_MEASURE_VERITY because it doesn't require opening the file, and opening verity files can be expensive. +FS_IOC_FSGETXATTR +----------------- + +Since Linux v6.9, FS_XFLAG_VERITY (0x00020000) file attribute is set for verity +files. The attribute can be observed via lsattr. + + [root@vm:~]# lsattr /mnt/test/foo + --------------------V- /mnt/test/foo + +Note that this attribute cannot be set with FS_IOC_FSSETXATTR as enabling verity +requires input parameters. See FS_IOC_ENABLE_VERITY. + .. _accessing_verity_files: Accessing verity files diff --git a/fs/ioctl.c b/fs/ioctl.c index 76cf22ac97d7..38c00e47c069 100644 --- a/fs/ioctl.c +++ b/fs/ioctl.c @@ -481,6 +481,8 @@ void fileattr_fill_xflags(struct fileattr *fa, u32 xflags) fa->flags |= FS_DAX_FL; if (fa->fsx_xflags & FS_XFLAG_PROJINHERIT) fa->flags |= FS_PROJINHERIT_FL; + if (fa->fsx_xflags & FS_XFLAG_VERITY) + fa->flags |= FS_VERITY_FL; } EXPORT_SYMBOL(fileattr_fill_xflags); @@ -511,6 +513,8 @@ void fileattr_fill_flags(struct fileattr *fa, u32 flags) fa->fsx_xflags |= FS_XFLAG_DAX; if (fa->flags & FS_PROJINHERIT_FL) fa->fsx_xflags |= FS_XFLAG_PROJINHERIT; + if (fa->flags & FS_VERITY_FL) + fa->fsx_xflags |= FS_XFLAG_VERITY; } EXPORT_SYMBOL(fileattr_fill_flags); @@ -641,6 +645,13 @@ static int fileattr_set_prepare(struct inode *inode, !(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode))) return -EINVAL; + /* + * Verity cannot be set through FS_IOC_FSSETXATTR/FS_IOC_SETFLAGS. + * See FS_IOC_ENABLE_VERITY + */ + if (fa->fsx_xflags & FS_XFLAG_VERITY) + return -EINVAL; + /* Extent size hints of zero turn off the flags. */ if (fa->fsx_extsize == 0) fa->fsx_xflags &= ~(FS_XFLAG_EXTSIZE | FS_XFLAG_EXTSZINHERIT); diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h index 48ad69f7722e..6e63ea832d4f 100644 --- a/include/uapi/linux/fs.h +++ b/include/uapi/linux/fs.h @@ -140,6 +140,7 @@ struct fsxattr { #define FS_XFLAG_FILESTREAM 0x00004000 /* use filestream allocator */ #define FS_XFLAG_DAX 0x00008000 /* use DAX for IO */ #define FS_XFLAG_COWEXTSIZE 0x00010000 /* CoW extent size allocator hint */ +#define FS_XFLAG_VERITY 0x00020000 /* fs-verity sealed inode */ #define FS_XFLAG_HASATTR 0x80000000 /* no DIFLAG for this */ /* the read-only stuff doesn't really belong here, but any other place is From patchwork Mon Feb 12 16:58:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Albershteyn X-Patchwork-Id: 13553742 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8EE673D986 for ; Mon, 12 Feb 2024 17:00:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757202; cv=none; b=EejphYa7N32OS8e+vZzCBHMAfbVbH0w0ATHv0ohiinsCuZGJG2EX33Hz3Yv0MtQACPhlbRwnz8jb1ZcPwAu23enGwMW6/oImNk4slAdBmSaHi7PDHDtHDiV9J5bOKY3Kv4fjJd74t5+Cc4IV6hFoe5Wu4VncWF3id5X9UcCGp+o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757202; c=relaxed/simple; bh=J8eqmJ+xrgEjOXP2VKM/OiQv88UWMfaFDCsYsiGjLNY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=lmRzTh75fK44p9HWCfOZoHqUj+Cb667TAm7u1g0pCj/nINnls8cpqgHNPSjsvy8QuNvqY+s4EkZ9yofYizAFzPIR19fmpSpOH8TnbABoEWy+qfA2HuePowKLAbwQFZMOBG38YI9vs/vxJUBLwx4sS4Jz51ZQJsnoLHXEF+GMBiU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Sw2dT58X; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Sw2dT58X" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707757199; 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=Tj+M9muz5Mq0wRvQVjpVNnfnNXBZ0GExMp5ECK241aI=; b=Sw2dT58XLRNeLL/mlkQ0M2PqrS7XWsMJde2Umg8tCuVp9XkAxHgi12fy5tTMqiv2eW5JVA /iytxs8xg9zuH1yAI5UtTmpxfZvV/oUXSn5GoVmYDBYArcdUylhUNXfDQxltKJGSvc5efr XM+AD0A1zBlCSg7u/CnJFGyx21dFxxA= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-516-8oVgUL9VP12lbibhT-s_WQ-1; Mon, 12 Feb 2024 11:59:58 -0500 X-MC-Unique: 8oVgUL9VP12lbibhT-s_WQ-1 Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-55fc415b15aso3641678a12.0 for ; Mon, 12 Feb 2024 08:59:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707757196; x=1708361996; 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=Tj+M9muz5Mq0wRvQVjpVNnfnNXBZ0GExMp5ECK241aI=; b=myNMWw4nf126/4ROIdlf31fcD/MVEVVbM4ndVmAEfL+Xv6RjtBPjaqTyT28MgafI5/ S5xP/y5gW6VZRe+uiaY/KPirr6dGHi6S3A8q5f8AdXdWSWj8PWNGIO4ea6JPsFMh6Sew o1hV6KjebfUrIw/H9witVrnrlmTKIYwdWKkb78cUQhIJUXlucNE/wC8WwRjSUFTzNedR r1Ur8ad+CE0Ms1udmO06uD7TLVC7kaJKWLfOIa7a1qmGllD/qwr73YFmSq54peRAo1tV l2IwG4pH0y00UFEf9t/s+VzXf7JpPOsP2Ulwt2jp6hvkbGWEU/U55LN3uUfoYvQ5ILBb 3NAA== X-Forwarded-Encrypted: i=1; AJvYcCWbncYya7Dg1x7JyAv+j6SH2y91pbLb6U7ifu/PX3gP9i1mPWQ5mpE71TXgxjFLWTYJt8TM3L7VjwJ3AJPzdUcNWYdUb6XCyzjl X-Gm-Message-State: AOJu0Yxe4Yeu98OWS2QHtvTKZPzYoMs+zowvyS9YUm0advP+J4HbSI/D KgItoHB/7jhC7T7KcsLf9Akw5j7YbQUJN6bdw2EQokjPzWMxI/TFk0OoBESv2/Waaf9+/54iKyW zqFd/EBdlc0D5bI6njQH0fyUtBXDXpcdTu+OXZjUpPXCuLSh3jOTqR+H8TJ5HvUKJ X-Received: by 2002:a05:6402:643:b0:561:a278:db1d with SMTP id u3-20020a056402064300b00561a278db1dmr67926edx.6.1707757196582; Mon, 12 Feb 2024 08:59:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IEtqgz4uDExeajTYum89SlbgYY0K3Z01N1uVXi9SYRLiSvtRtku9Z+tCv2eTqpRFWJ/gbf9fg== X-Received: by 2002:a05:6402:643:b0:561:a278:db1d with SMTP id u3-20020a056402064300b00561a278db1dmr67909edx.6.1707757196375; Mon, 12 Feb 2024 08:59:56 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCXd8xaYpRWEUrz+josrTDL3E9m0a+PSI6wgXDuVhsf3ik78yVwT2Ddbg3N5a663Pq2+tpp6LpEMQlBz08yajX0H7kOwxBeuZdhVdQPzfxc+WqGEDp4BbZLcDH7J/vo26O5JT9BJQYaQ5GHeJmXRxLSTy9tSrH3cdl3PvAgFyDxa7FiOozrc3PfBWwJFQdz6ZJWpICF6sP79f5bYix07U88Jvt8Gejd0cC7N Received: from thinky.redhat.com ([109.183.6.197]) by smtp.gmail.com with ESMTPSA id 14-20020a0564021f4e00b0056176e95a88sm2620261edz.32.2024.02.12.08.59.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 08:59:55 -0800 (PST) From: Andrey Albershteyn To: fsverity@lists.linux.dev, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, chandan.babu@oracle.com, djwong@kernel.org, ebiggers@kernel.org Cc: Andrey Albershteyn Subject: [PATCH v4 06/25] fsverity: pass log_blocksize to end_enable_verity() Date: Mon, 12 Feb 2024 17:58:03 +0100 Message-Id: <20240212165821.1901300-7-aalbersh@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240212165821.1901300-1-aalbersh@redhat.com> References: <20240212165821.1901300-1-aalbersh@redhat.com> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 XFS will need to know log_blocksize to remove the tree in case of an error. The size is needed to calculate offsets of particular Merkle tree blocks. Signed-off-by: Andrey Albershteyn --- fs/btrfs/verity.c | 4 +++- fs/ext4/verity.c | 3 ++- fs/f2fs/verity.c | 3 ++- fs/verity/enable.c | 6 ++++-- include/linux/fsverity.h | 4 +++- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/fs/btrfs/verity.c b/fs/btrfs/verity.c index 66e2270b0dae..84e9b1480241 100644 --- a/fs/btrfs/verity.c +++ b/fs/btrfs/verity.c @@ -621,6 +621,7 @@ static int btrfs_begin_enable_verity(struct file *filp) * @desc: verity descriptor to write out (NULL in error conditions) * @desc_size: size of the verity descriptor (variable with signatures) * @merkle_tree_size: size of the merkle tree in bytes + * @tree_blocksize: size of the Merkle tree block * * If desc is null, then VFS is signaling an error occurred during verity * enable, and we should try to rollback. Otherwise, attempt to finish verity. @@ -628,7 +629,8 @@ static int btrfs_begin_enable_verity(struct file *filp) * Returns 0 on success, negative error code on error. */ static int btrfs_end_enable_verity(struct file *filp, const void *desc, - size_t desc_size, u64 merkle_tree_size) + size_t desc_size, u64 merkle_tree_size, + unsigned int tree_blocksize) { struct btrfs_inode *inode = BTRFS_I(file_inode(filp)); int ret = 0; diff --git a/fs/ext4/verity.c b/fs/ext4/verity.c index 2f37e1ea3955..da2095a81349 100644 --- a/fs/ext4/verity.c +++ b/fs/ext4/verity.c @@ -189,7 +189,8 @@ static int ext4_write_verity_descriptor(struct inode *inode, const void *desc, } static int ext4_end_enable_verity(struct file *filp, const void *desc, - size_t desc_size, u64 merkle_tree_size) + size_t desc_size, u64 merkle_tree_size, + unsigned int tree_blocksize) { struct inode *inode = file_inode(filp); const int credits = 2; /* superblock and inode for ext4_orphan_del() */ diff --git a/fs/f2fs/verity.c b/fs/f2fs/verity.c index 4fc95f353a7a..b4461b9f47a3 100644 --- a/fs/f2fs/verity.c +++ b/fs/f2fs/verity.c @@ -144,7 +144,8 @@ static int f2fs_begin_enable_verity(struct file *filp) } static int f2fs_end_enable_verity(struct file *filp, const void *desc, - size_t desc_size, u64 merkle_tree_size) + size_t desc_size, u64 merkle_tree_size, + unsigned int tree_blocksize) { struct inode *inode = file_inode(filp); struct f2fs_sb_info *sbi = F2FS_I_SB(inode); diff --git a/fs/verity/enable.c b/fs/verity/enable.c index c284f46d1b53..04e060880b79 100644 --- a/fs/verity/enable.c +++ b/fs/verity/enable.c @@ -274,7 +274,8 @@ static int enable_verity(struct file *filp, * Serialized with ->begin_enable_verity() by the inode lock. */ inode_lock(inode); - err = vops->end_enable_verity(filp, desc, desc_size, params.tree_size); + err = vops->end_enable_verity(filp, desc, desc_size, params.tree_size, + params.block_size); inode_unlock(inode); if (err) { fsverity_err(inode, "%ps() failed with err %d", @@ -300,7 +301,8 @@ static int enable_verity(struct file *filp, rollback: inode_lock(inode); - (void)vops->end_enable_verity(filp, NULL, 0, params.tree_size); + (void)vops->end_enable_verity(filp, NULL, 0, params.tree_size, + params.block_size); inode_unlock(inode); goto out; } diff --git a/include/linux/fsverity.h b/include/linux/fsverity.h index 1eb7eae580be..ab7b0772899b 100644 --- a/include/linux/fsverity.h +++ b/include/linux/fsverity.h @@ -51,6 +51,7 @@ struct fsverity_operations { * @desc: the verity descriptor to write, or NULL on failure * @desc_size: size of verity descriptor, or 0 on failure * @merkle_tree_size: total bytes the Merkle tree took up + * @tree_blocksize: size of the Merkle tree block * * If desc == NULL, then enabling verity failed and the filesystem only * must do any necessary cleanups. Else, it must also store the given @@ -65,7 +66,8 @@ struct fsverity_operations { * Return: 0 on success, -errno on failure */ int (*end_enable_verity)(struct file *filp, const void *desc, - size_t desc_size, u64 merkle_tree_size); + size_t desc_size, u64 merkle_tree_size, + unsigned int tree_blocksize); /** * Get the verity descriptor of the given inode. From patchwork Mon Feb 12 16:58:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Albershteyn X-Patchwork-Id: 13553743 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D3D053EA93 for ; Mon, 12 Feb 2024 17:00:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757205; cv=none; b=tQT/avdbK758yomYwFPsacliTExEFzuD6f6L8tkZjSwxNMb5VDlOpRTkcHrGsmSSUs/Qq8xM8IolnE23vnhUf1Jng65L2uBPCxYSFczhs0MViDwEFZ7zsEBEFMWsMbm+dNY3d0SiCK+w7f8jJNrTtU/jMuxuFfrfiMiyYJ9WvaU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757205; c=relaxed/simple; bh=ykhQfKWuHsV04EnI2o5RitgAdbOcIAZZrnDV0B1Wz7o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HBKoT6+4vtaC8zXaPsq61WE8zBwPzYbI6Tu8SiPPCqaU+aKyq/DoPRfqGGwks7KPejk4dAHJO6R3s/0x2MpXzRYYwnkOf4Y2aOTxaDh+J5p/bWIJlNE0jA82MO4TlC8oJ+O4ITcaQw/y915afI+4MGfTUBpvAsjlQaDuLuQq0c8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Djh54c3u; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Djh54c3u" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707757201; 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=1rjcwZ0Rr2XiOc2/6/uRIjv653Za/HHrJ87P2SLK6dc=; b=Djh54c3uQyjukCDYySGC170JPC0iIVXl/jZbI3/gfCSrsbkpf8AW3bF0WMVerrUlnGWapQ +yt74qDtCruqW3BzZLrReh73cCeGRHFcsJAujzk9JYlGExi4opCW1g55DAhVmGa3H/Df+Q eRQUpH6gYwHIqwX394Xw7JqWBdnU3SQ= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-503-iiUrQJFVMBuPTBgWUBDA5w-1; Mon, 12 Feb 2024 11:59:59 -0500 X-MC-Unique: iiUrQJFVMBuPTBgWUBDA5w-1 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-a3c177d4fe7so111591966b.2 for ; Mon, 12 Feb 2024 08:59:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707757198; x=1708361998; 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=1rjcwZ0Rr2XiOc2/6/uRIjv653Za/HHrJ87P2SLK6dc=; b=FUsCOEkIvc0Sv9ruokP6agahoZ6yOc/gCYiL72VBJc1vMQG8mcQILnWECl1jsdfpix 9YAHuT1GlqdfXCQW0lJyw7Z5/NnBaShv8D9in3QCPtpjUG0RV824vn3xoaqsJoTV0aYu s+cFutru4qU3UUqVNMWWum0/T9OQagOQF+1LmdJJznKQYeO4Yb225siB2eLGbMQl/ixi 2d9miEDtwV62OIAY3oYXIDOaLhS2Ny7l5IDTqhljuTETUbhkJkNXvJ/SpoRaPYudghMc teALJzOdYr92MprUlUiZ263lPiCLvBWBvjd5pRP2fBG4auXnvVH/fQzrQ7mccYxa/Ipi L3Cg== X-Gm-Message-State: AOJu0YzxD18M4vDXUQgWyfJxfOKzF4exhA6AMFWoiNPtbBSHRM9Ckc9M JAfuVOvNnHe489/aKrqLmXtGUW7doJm9jBu9zwmlqKIxLCphapDLlwRlu0QCczcQsOcB6fQWjUc 81X5TJehoLSBOUBfyiiU1zGjkVp7kGCfDOp8H3mJD9dvLWWBPjIecjgSJ X-Received: by 2002:aa7:ce09:0:b0:561:d4f0:eb14 with SMTP id d9-20020aa7ce09000000b00561d4f0eb14mr1075069edv.24.1707757198156; Mon, 12 Feb 2024 08:59:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IGrV4HkefzeD/lUvcrVUp0NxzWYYoatrN1WUPjbxa5Ak0YKZMHd6cREY48MPKQV1piavId3wg== X-Received: by 2002:aa7:ce09:0:b0:561:d4f0:eb14 with SMTP id d9-20020aa7ce09000000b00561d4f0eb14mr1075053edv.24.1707757197684; Mon, 12 Feb 2024 08:59:57 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCXoL6yMAYidy/lOKRY2jPCMiORGPkk95YuL1jAOO6tNDyxcUsB4d9UtXuoZT8q5rUy2U0Lr+iRt791uvwUuvGhpt64KzZpG2EF3repx8hifvPytV0NLwughyrDoPid3EKCsskNtxMrKtoAA6JCt7wFpVJNwR77UiOGGL4awivMvbJ+7h65gk6ebsBlI8Y0Ik9hdyZBfrPVgfbjC8on5SyYor5LSJJmcwbym Received: from thinky.redhat.com ([109.183.6.197]) by smtp.gmail.com with ESMTPSA id 14-20020a0564021f4e00b0056176e95a88sm2620261edz.32.2024.02.12.08.59.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 08:59:56 -0800 (PST) From: Andrey Albershteyn To: fsverity@lists.linux.dev, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, chandan.babu@oracle.com, djwong@kernel.org, ebiggers@kernel.org Cc: Andrey Albershteyn Subject: [PATCH v4 07/25] fsverity: support block-based Merkle tree caching Date: Mon, 12 Feb 2024 17:58:04 +0100 Message-Id: <20240212165821.1901300-8-aalbersh@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240212165821.1901300-1-aalbersh@redhat.com> References: <20240212165821.1901300-1-aalbersh@redhat.com> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In the current implementation fs-verity expects filesystem to provide PAGEs filled with Merkle tree blocks. Then, when fs-verity is done with processing the blocks, reference to PAGE is freed. This doesn't fit well with the way XFS manages its memory. To allow XFS integrate fs-verity this patch changes fs-verity verification code to take Merkle tree blocks instead of PAGE reference. Then, adds a thin compatibility layer to work with both approaches. This way ext4, f2fs, and btrfs are still able to pass PAGE references and XFS can pass reference to Merkle tree blocks stored in XFS's buffer infrastructure. Another addition is invalidation functions which tells fs-verity to mark part of Merkle tree as not verified. These functions are used by filesystem to tell fs-verity to invalidate blocks which were evicted from memory. Depending on Merkle tree block size fs-verity is using either bitmap or PG_checked flag to track "verified" status of the blocks. With a Merkle tree block caching (XFS) there is no PAGE to flag it as verified. fs-verity always uses bitmap to track verified blocks for filesystems which use block caching. As verification function now works only with blocks - memory barriers, used for verified status updates, are moved from is_hash_block_verified() to fsverity_invalidate_page/range(). Depending on block or page caching, fs-verity clears bits in bitmap based on PG_checked or from filesystem call out. Further this patch allows filesystem to make additional processing on verified pages instead of just dropping a reference via fsverity_drop_block(). This will be used by XFS for internal buffer cache manipulation in further patches. The btrfs, ext4, and f2fs just drop the reference. As btrfs, ext4 and f2fs return page with Merkle tree blocks this patch also adds fsverity_read_merkle_tree_block() which wraps addressing blocks in the page. Signed-off-by: Andrey Albershteyn --- fs/verity/fsverity_private.h | 27 ++++ fs/verity/open.c | 8 +- fs/verity/read_metadata.c | 48 +++--- fs/verity/verify.c | 280 ++++++++++++++++++++++++----------- include/linux/fsverity.h | 69 +++++++++ 5 files changed, 316 insertions(+), 116 deletions(-) diff --git a/fs/verity/fsverity_private.h b/fs/verity/fsverity_private.h index b3506f56e180..72ac1cdd9e63 100644 --- a/fs/verity/fsverity_private.h +++ b/fs/verity/fsverity_private.h @@ -154,4 +154,31 @@ static inline void fsverity_init_signature(void) void __init fsverity_init_workqueue(void); +/** + * fsverity_drop_block() - drop block obtained with ->read_merkle_tree_block() + * @inode: inode in use for verification or metadata reading + * @block: block to be dropped + * + * Calls out back to filesystem if ->drop_block() is set, otherwise, drop the + * reference in the block->context. + */ +void fsverity_drop_block(struct inode *inode, + struct fsverity_blockbuf *block); + +/** + * fsverity_read_block_from_page() - general function to read Merkle tree block + * @inode: inode in use for verification or metadata reading + * @pos: byte offset of the block within the Merkle tree + * @block: block to read + * @num_ra_pages: number of pages to readahead, may be ignored + * + * Depending on fs implementation use read_merkle_tree_block() or + * read_merkle_tree_page() to read blocks. + */ +int fsverity_read_merkle_tree_block(struct inode *inode, + u64 pos, + struct fsverity_blockbuf *block, + unsigned int log_blocksize, + unsigned long num_ra_pages); + #endif /* _FSVERITY_PRIVATE_H */ diff --git a/fs/verity/open.c b/fs/verity/open.c index fdeb95eca3af..6e6922b4b014 100644 --- a/fs/verity/open.c +++ b/fs/verity/open.c @@ -213,7 +213,13 @@ struct fsverity_info *fsverity_create_info(const struct inode *inode, if (err) goto fail; - if (vi->tree_params.block_size != PAGE_SIZE) { + /* + * If fs passes Merkle tree blocks to fs-verity (e.g. XFS), then + * fs-verity should use hash_block_verified bitmap as there's no page + * to mark it with PG_checked. + */ + if (vi->tree_params.block_size != PAGE_SIZE || + inode->i_sb->s_vop->read_merkle_tree_block) { /* * When the Merkle tree block size and page size differ, we use * a bitmap to keep track of which hash blocks have been diff --git a/fs/verity/read_metadata.c b/fs/verity/read_metadata.c index f58432772d9e..7e153356e7bc 100644 --- a/fs/verity/read_metadata.c +++ b/fs/verity/read_metadata.c @@ -16,9 +16,10 @@ static int fsverity_read_merkle_tree(struct inode *inode, const struct fsverity_info *vi, void __user *buf, u64 offset, int length) { - const struct fsverity_operations *vops = inode->i_sb->s_vop; u64 end_offset; - unsigned int offs_in_page; + unsigned int offs_in_block; + const unsigned int block_size = vi->tree_params.block_size; + const u8 log_blocksize = vi->tree_params.log_blocksize; pgoff_t index, last_index; int retval = 0; int err = 0; @@ -26,42 +27,39 @@ static int fsverity_read_merkle_tree(struct inode *inode, end_offset = min(offset + length, vi->tree_params.tree_size); if (offset >= end_offset) return 0; - offs_in_page = offset_in_page(offset); - last_index = (end_offset - 1) >> PAGE_SHIFT; + offs_in_block = offset & (block_size - 1); + last_index = (end_offset - 1) >> log_blocksize; /* - * Iterate through each Merkle tree page in the requested range and copy - * the requested portion to userspace. Note that the Merkle tree block - * size isn't important here, as we are returning a byte stream; i.e., - * we can just work with pages even if the tree block size != PAGE_SIZE. + * Iterate through each Merkle tree block in the requested range and + * copy the requested portion to userspace. Note that we are returning + * a byte stream, so PAGE_SIZE & block_size are not important here. */ - for (index = offset >> PAGE_SHIFT; index <= last_index; index++) { + for (index = offset >> log_blocksize; index <= last_index; index++) { unsigned long num_ra_pages = min_t(unsigned long, last_index - index + 1, inode->i_sb->s_bdi->io_pages); unsigned int bytes_to_copy = min_t(u64, end_offset - offset, - PAGE_SIZE - offs_in_page); - struct page *page; - const void *virt; + block_size - offs_in_block); + struct fsverity_blockbuf block; - page = vops->read_merkle_tree_page(inode, index, num_ra_pages); - if (IS_ERR(page)) { - err = PTR_ERR(page); - fsverity_err(inode, - "Error %d reading Merkle tree page %lu", - err, index); + block.size = block_size; + if (fsverity_read_merkle_tree_block(inode, + index << log_blocksize, + &block, log_blocksize, + num_ra_pages)) { + fsverity_drop_block(inode, &block); + err = -EIO; break; } - virt = kmap_local_page(page); - if (copy_to_user(buf, virt + offs_in_page, bytes_to_copy)) { - kunmap_local(virt); - put_page(page); + if (copy_to_user(buf, block.kaddr + offs_in_block, bytes_to_copy)) { + fsverity_drop_block(inode, &block); err = -EFAULT; break; } - kunmap_local(virt); - put_page(page); + fsverity_drop_block(inode, &block); + block.kaddr = NULL; retval += bytes_to_copy; buf += bytes_to_copy; @@ -72,7 +70,7 @@ static int fsverity_read_merkle_tree(struct inode *inode, break; } cond_resched(); - offs_in_page = 0; + offs_in_block = 0; } return retval ? retval : err; } diff --git a/fs/verity/verify.c b/fs/verity/verify.c index 4fcad0825a12..414ec3321fe6 100644 --- a/fs/verity/verify.c +++ b/fs/verity/verify.c @@ -13,69 +13,18 @@ static struct workqueue_struct *fsverity_read_workqueue; /* - * Returns true if the hash block with index @hblock_idx in the tree, located in - * @hpage, has already been verified. + * Returns true if the hash block with index @hblock_idx in the tree has + * already been verified. */ -static bool is_hash_block_verified(struct fsverity_info *vi, struct page *hpage, +static bool is_hash_block_verified(struct fsverity_info *vi, + struct fsverity_blockbuf *block, unsigned long hblock_idx) { - unsigned int blocks_per_page; - unsigned int i; - - /* - * When the Merkle tree block size and page size are the same, then the - * ->hash_block_verified bitmap isn't allocated, and we use PG_checked - * to directly indicate whether the page's block has been verified. - * - * Using PG_checked also guarantees that we re-verify hash pages that - * get evicted and re-instantiated from the backing storage, as new - * pages always start out with PG_checked cleared. - */ + /* Merkle tree block size == PAGE_SIZE */ if (!vi->hash_block_verified) - return PageChecked(hpage); + return block->verified; - /* - * When the Merkle tree block size and page size differ, we use a bitmap - * to indicate whether each hash block has been verified. - * - * However, we still need to ensure that hash pages that get evicted and - * re-instantiated from the backing storage are re-verified. To do - * this, we use PG_checked again, but now it doesn't really mean - * "checked". Instead, now it just serves as an indicator for whether - * the hash page is newly instantiated or not. If the page is new, as - * indicated by PG_checked=0, we clear the bitmap bits for the page's - * blocks since they are untrustworthy, then set PG_checked=1. - * Otherwise we return the bitmap bit for the requested block. - * - * Multiple threads may execute this code concurrently on the same page. - * This is safe because we use memory barriers to ensure that if a - * thread sees PG_checked=1, then it also sees the associated bitmap - * clearing to have occurred. Also, all writes and their corresponding - * reads are atomic, and all writes are safe to repeat in the event that - * multiple threads get into the PG_checked=0 section. (Clearing a - * bitmap bit again at worst causes a hash block to be verified - * redundantly. That event should be very rare, so it's not worth using - * a lock to avoid. Setting PG_checked again has no effect.) - */ - if (PageChecked(hpage)) { - /* - * A read memory barrier is needed here to give ACQUIRE - * semantics to the above PageChecked() test. - */ - smp_rmb(); - return test_bit(hblock_idx, vi->hash_block_verified); - } - blocks_per_page = vi->tree_params.blocks_per_page; - hblock_idx = round_down(hblock_idx, blocks_per_page); - for (i = 0; i < blocks_per_page; i++) - clear_bit(hblock_idx + i, vi->hash_block_verified); - /* - * A write memory barrier is needed here to give RELEASE semantics to - * the below SetPageChecked() operation. - */ - smp_wmb(); - SetPageChecked(hpage); - return false; + return test_bit(hblock_idx, vi->hash_block_verified); } /* @@ -95,15 +44,15 @@ verify_data_block(struct inode *inode, struct fsverity_info *vi, const struct merkle_tree_params *params = &vi->tree_params; const unsigned int hsize = params->digest_size; int level; + int err; + int num_ra_pages; u8 _want_hash[FS_VERITY_MAX_DIGEST_SIZE]; const u8 *want_hash; u8 real_hash[FS_VERITY_MAX_DIGEST_SIZE]; /* The hash blocks that are traversed, indexed by level */ struct { - /* Page containing the hash block */ - struct page *page; - /* Mapped address of the hash block (will be within @page) */ - const void *addr; + /* Buffer containing the hash block */ + struct fsverity_blockbuf block; /* Index of the hash block in the tree overall */ unsigned long index; /* Byte offset of the wanted hash relative to @addr */ @@ -144,10 +93,8 @@ verify_data_block(struct inode *inode, struct fsverity_info *vi, unsigned long next_hidx; unsigned long hblock_idx; pgoff_t hpage_idx; - unsigned int hblock_offset_in_page; unsigned int hoffset; - struct page *hpage; - const void *haddr; + struct fsverity_blockbuf *block = &hblocks[level].block; /* * The index of the block in the current level; also the index @@ -161,33 +108,27 @@ verify_data_block(struct inode *inode, struct fsverity_info *vi, /* Index of the hash page in the tree overall */ hpage_idx = hblock_idx >> params->log_blocks_per_page; - /* Byte offset of the hash block within the page */ - hblock_offset_in_page = - (hblock_idx << params->log_blocksize) & ~PAGE_MASK; - /* Byte offset of the hash within the block */ hoffset = (hidx << params->log_digestsize) & (params->block_size - 1); - hpage = inode->i_sb->s_vop->read_merkle_tree_page(inode, - hpage_idx, level == 0 ? min(max_ra_pages, - params->tree_pages - hpage_idx) : 0); - if (IS_ERR(hpage)) { + num_ra_pages = level == 0 ? + min(max_ra_pages, params->tree_pages - hpage_idx) : 0; + err = fsverity_read_merkle_tree_block( + inode, hblock_idx << params->log_blocksize, block, + params->log_blocksize, num_ra_pages); + if (err) { fsverity_err(inode, - "Error %ld reading Merkle tree page %lu", - PTR_ERR(hpage), hpage_idx); + "Error %d reading Merkle tree block %lu", + err, hblock_idx); goto error; } - haddr = kmap_local_page(hpage) + hblock_offset_in_page; - if (is_hash_block_verified(vi, hpage, hblock_idx)) { - memcpy(_want_hash, haddr + hoffset, hsize); + if (is_hash_block_verified(vi, block, hblock_idx)) { + memcpy(_want_hash, block->kaddr + hoffset, hsize); want_hash = _want_hash; - kunmap_local(haddr); - put_page(hpage); + fsverity_drop_block(inode, block); goto descend; } - hblocks[level].page = hpage; - hblocks[level].addr = haddr; hblocks[level].index = hblock_idx; hblocks[level].hoffset = hoffset; hidx = next_hidx; @@ -197,8 +138,8 @@ verify_data_block(struct inode *inode, struct fsverity_info *vi, descend: /* Descend the tree verifying hash blocks. */ for (; level > 0; level--) { - struct page *hpage = hblocks[level - 1].page; - const void *haddr = hblocks[level - 1].addr; + struct fsverity_blockbuf *block = &hblocks[level - 1].block; + const void *haddr = block->kaddr; unsigned long hblock_idx = hblocks[level - 1].index; unsigned int hoffset = hblocks[level - 1].hoffset; @@ -213,12 +154,10 @@ verify_data_block(struct inode *inode, struct fsverity_info *vi, */ if (vi->hash_block_verified) set_bit(hblock_idx, vi->hash_block_verified); - else - SetPageChecked(hpage); + block->verified = true; memcpy(_want_hash, haddr + hoffset, hsize); want_hash = _want_hash; - kunmap_local(haddr); - put_page(hpage); + fsverity_drop_block(inode, block); } /* Finally, verify the data block. */ @@ -236,8 +175,7 @@ verify_data_block(struct inode *inode, struct fsverity_info *vi, params->hash_alg->name, hsize, real_hash); error: for (; level > 0; level--) { - kunmap_local(hblocks[level - 1].addr); - put_page(hblocks[level - 1].page); + fsverity_drop_block(inode, &hblocks[level - 1].block); } return false; } @@ -362,3 +300,165 @@ void __init fsverity_init_workqueue(void) if (!fsverity_read_workqueue) panic("failed to allocate fsverity_read_queue"); } + +/** + * fsverity_invalidate_range() - invalidate range of Merkle tree blocks + * @inode: inode to which this Merkle tree blocks belong + * @offset: offset into the Merkle tree + * @size: number of bytes to invalidate starting from @offset + * + * This function invalidates/clears "verified" state of all Merkle tree blocks + * in the Merkle tree within the range starting from 'offset' to 'offset + size'. + * + * Note! As this function clears fs-verity bitmap and can be run from multiple + * threads simultaneously, filesystem has to take care of operation ordering + * while invalidating Merkle tree and caching it. See fsverity_invalidate_page() + * as reference. + */ +void fsverity_invalidate_range(struct inode *inode, loff_t offset, + size_t size) +{ + struct fsverity_info *vi = inode->i_verity_info; + const unsigned int log_blocksize = vi->tree_params.log_blocksize; + unsigned int i; + pgoff_t index = offset >> log_blocksize; + unsigned int blocks = size >> log_blocksize; + + if (offset + size > vi->tree_params.tree_size) { + fsverity_err(inode, +"Trying to invalidate beyond Merkle tree (tree %lld, offset %lld, size %ld)", + vi->tree_params.tree_size, offset, size); + return; + } + + for (i = 0; i < blocks; i++) + clear_bit(index + i, vi->hash_block_verified); +} +EXPORT_SYMBOL_GPL(fsverity_invalidate_range); + +/* fsverity_invalidate_page() - invalidate Merkle tree blocks in the page + * @inode: inode to which this Merkle tree blocks belong + * @page: page which contains blocks which need to be invalidated + * @index: index of the first Merkle tree block in the page + * + * This function invalidates "verified" state of all Merkle tree blocks within + * the 'page'. + * + * When the Merkle tree block size and page size are the same, then the + * ->hash_block_verified bitmap isn't allocated, and we use PG_checked + * to directly indicate whether the page's block has been verified. This + * function does nothing in this case as page is invalidated by evicting from + * the memory. + * + * Using PG_checked also guarantees that we re-verify hash pages that + * get evicted and re-instantiated from the backing storage, as new + * pages always start out with PG_checked cleared. + */ +void fsverity_invalidate_page(struct inode *inode, struct page *page, + pgoff_t index) +{ + unsigned int blocks_per_page; + struct fsverity_info *vi = inode->i_verity_info; + const unsigned int log_blocksize = vi->tree_params.log_blocksize; + + /* + * If bitmap is not allocated, that means that fs-verity uses PG_checked + * to track verification status of the blocks. + */ + if (!vi->hash_block_verified) + return; + + /* + * When the Merkle tree block size and page size differ, we use a bitmap + * to indicate whether each hash block has been verified. + * + * However, we still need to ensure that hash pages that get evicted and + * re-instantiated from the backing storage are re-verified. To do + * this, we use PG_checked again, but now it doesn't really mean + * "checked". Instead, now it just serves as an indicator for whether + * the hash page is newly instantiated or not. If the page is new, as + * indicated by PG_checked=0, we clear the bitmap bits for the page's + * blocks since they are untrustworthy, then set PG_checked=1. + * + * Multiple threads may execute this code concurrently on the same page. + * This is safe because we use memory barriers to ensure that if a + * thread sees PG_checked=1, then it also sees the associated bitmap + * clearing to have occurred. Also, all writes and their corresponding + * reads are atomic, and all writes are safe to repeat in the event that + * multiple threads get into the PG_checked=0 section. (Clearing a + * bitmap bit again at worst causes a hash block to be verified + * redundantly. That event should be very rare, so it's not worth using + * a lock to avoid. Setting PG_checked again has no effect.) + */ + if (PageChecked(page)) { + /* + * A read memory barrier is needed here to give ACQUIRE + * semantics to the above PageChecked() test. + */ + smp_rmb(); + return; + } + + blocks_per_page = vi->tree_params.blocks_per_page; + index = round_down(index, blocks_per_page); + fsverity_invalidate_range(inode, index << log_blocksize, PAGE_SIZE); + /* + * A write memory barrier is needed here to give RELEASE + * semantics to the below SetPageChecked() operation. + */ + smp_wmb(); + SetPageChecked(page); +} + +void fsverity_drop_block(struct inode *inode, + struct fsverity_blockbuf *block) +{ + if (inode->i_sb->s_vop->drop_block) + inode->i_sb->s_vop->drop_block(block); + else { + struct page *page = (struct page *)block->context; + + /* Merkle tree block size == PAGE_SIZE; */ + if (block->verified) + SetPageChecked(page); + + kunmap_local(block->kaddr); + put_page(page); + } +} + +int fsverity_read_merkle_tree_block(struct inode *inode, + u64 pos, + struct fsverity_blockbuf *block, + unsigned int log_blocksize, + unsigned long num_ra_pages) +{ + struct page *page; + int err = 0; + unsigned long index = pos >> PAGE_SHIFT; + + if (inode->i_sb->s_vop->read_merkle_tree_block) + return inode->i_sb->s_vop->read_merkle_tree_block( + inode, pos, block, log_blocksize, num_ra_pages); + + page = inode->i_sb->s_vop->read_merkle_tree_page( + inode, index, num_ra_pages); + if (IS_ERR(page)) { + err = PTR_ERR(page); + fsverity_err(inode, + "Error %d reading Merkle tree page %lu", + err, index); + return PTR_ERR(page); + } + + fsverity_invalidate_page(inode, page, index); + /* + * For the block size == PAGE_SIZE case set ->verified. The PG_checked + * indicates whether block in the page is verified. + */ + block->verified = PageChecked(page); + block->kaddr = kmap_local_page(page) + (pos & (PAGE_SIZE - 1)); + block->context = page; + + return 0; +} diff --git a/include/linux/fsverity.h b/include/linux/fsverity.h index ab7b0772899b..fb2d4fccec0c 100644 --- a/include/linux/fsverity.h +++ b/include/linux/fsverity.h @@ -26,6 +26,36 @@ /* Arbitrary limit to bound the kmalloc() size. Can be changed. */ #define FS_VERITY_MAX_DESCRIPTOR_SIZE 16384 +/** + * struct fsverity_blockbuf - Merkle Tree block + * @kaddr: virtual address of the block's data + * @size: buffer size + * @verified: true if block is verified against Merkle tree + * @context: filesystem private context + * + * Buffer containing single Merkle Tree block. These buffers are passed + * - to filesystem, when fs-verity is building/writing merkel tree, + * - from filesystem, when fs-verity is reading merkle tree from a disk. + * Filesystems sets kaddr together with size to point to a memory which contains + * Merkle tree block. Same is done by fs-verity when Merkle tree is need to be + * written down to disk. + * + * While reading the tree, fs-verity calls ->read_merkle_tree_block followed by + * ->drop_block to let filesystem know that memory can be freed. + * + * For Merkle tree block == PAGE_SIZE, fs-verity sets verified flag to true if + * block in the buffer was verified. + * + * The context is optional. This field can be used by filesystem to passthrough + * state from ->read_merkle_tree_block to ->drop_block. + */ +struct fsverity_blockbuf { + void *kaddr; + unsigned int size; + bool verified; + void *context; +}; + /* Verity operations for filesystems */ struct fsverity_operations { @@ -107,6 +137,32 @@ struct fsverity_operations { pgoff_t index, unsigned long num_ra_pages); + /** + * Read a Merkle tree block of the given inode. + * @inode: the inode + * @pos: byte offset of the block within the Merkle tree + * @block: block buffer for filesystem to point it to the block + * @log_blocksize: size of the expected block + * @num_ra_pages: The number of pages with blocks that should be + * prefetched starting at @index if the page at @index + * isn't already cached. Implementations may ignore this + * argument; it's only a performance optimization. + * + * This can be called at any time on an open verity file. It may be + * called by multiple processes concurrently. + * + * As filesystem does caching of the blocks, this functions needs to tell + * fsverity which blocks are not valid anymore (were evicted from memory) + * by calling fsverity_invalidate_range(). + * + * Return: 0 on success, -errno on failure + */ + int (*read_merkle_tree_block)(struct inode *inode, + u64 pos, + struct fsverity_blockbuf *block, + unsigned int log_blocksize, + unsigned long num_ra_pages); + /** * Write a Merkle tree block to the given inode. * @@ -122,6 +178,16 @@ struct fsverity_operations { */ int (*write_merkle_tree_block)(struct inode *inode, const void *buf, u64 pos, unsigned int size); + + /** + * Release the reference to a Merkle tree block + * + * @page: the block to release + * + * This is called when fs-verity is done with a block obtained with + * ->read_merkle_tree_block(). + */ + void (*drop_block)(struct fsverity_blockbuf *block); }; #ifdef CONFIG_FS_VERITY @@ -175,6 +241,9 @@ int fsverity_ioctl_read_metadata(struct file *filp, const void __user *uarg); bool fsverity_verify_blocks(struct folio *folio, size_t len, size_t offset); void fsverity_verify_bio(struct bio *bio); void fsverity_enqueue_verify_work(struct work_struct *work); +void fsverity_invalidate_range(struct inode *inode, loff_t offset, size_t size); +void fsverity_invalidate_page(struct inode *inode, struct page *page, + pgoff_t index); #else /* !CONFIG_FS_VERITY */ From patchwork Mon Feb 12 16:58:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Albershteyn X-Patchwork-Id: 13553766 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0FBEC4F613 for ; Mon, 12 Feb 2024 17:05:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757510; cv=none; b=kqwRcBdQp7NaHe2FKwmrpKQooTC9fbsB4izUZXh7JjK26+Wxs76WZcBYSFpDu/wUV7PT9wFiFgItn1+2TG1CF71GHAVflTgUeDILs0Aa0qZ3B2dLwXprd+SZv8VZjozHbiuY/Y/61+TNN2eNSnrr9xQarE2cDYNPxEI4cF1M1WU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757510; c=relaxed/simple; bh=Q08TchXbWoihQ6fCDPoRO1eBKpAe+M20FpfPKv5WSZw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pBpIwkwPde4le+jC263xls6OmjeSZcEnzVCrumaeUeh3woBJvZnJJJ37UK6hbMuR9LVn3UuBjg0gJOjfl7w91UtmPcrsg6D38QsgOOZ/av7AtsFpSNUnJFeYfp6Iuu85+TUXpaF47wKxjwdwpNaOqVAy8HTKz/o3/FJbWHhKEFY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=VhCcC6qz; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="VhCcC6qz" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707757508; 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=crv7tlQVsJYaSE0CXLWFrc5tM7MlAUbMwi6wgSZcz7Q=; b=VhCcC6qznm5I6JF1HhgxWcEJbuqWd1u1RFbbZAtrPwHLCbzOvAdoOGxTaq3VmKI7dqGvXV Sa3RyXTSQdNHZiMsvGxG/F4vQGU5obLzTKzo+DtBiObYTe8SnaCOGftg0hSnucaTQqwavh IR2LfGPNSq5WGrGpz02AiS41oGGc2zY= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-320-stzW7F4DMpqDDg5xMzE1KQ-1; Mon, 12 Feb 2024 12:05:04 -0500 X-MC-Unique: stzW7F4DMpqDDg5xMzE1KQ-1 Received: by mail-ed1-f70.google.com with SMTP id 4fb4d7f45d1cf-561bc69fbe5so578281a12.2 for ; Mon, 12 Feb 2024 09:05:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707757198; x=1708361998; 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=crv7tlQVsJYaSE0CXLWFrc5tM7MlAUbMwi6wgSZcz7Q=; b=vKhW7I3MdL/CJlk6Bwdlfj8V+4QJ3SJXM/5rZNmGJbEYXyI0AhsDKc4eoU7wVulvYr uFXGvbrzaUptbTuD6MmWdKKohgCFK8u2/MJCIY8Ad0/PgUHIFMZwroNtLF+/JuZq0OH3 tsptlYWV8kP8FWVpoHfbcHQ7i+1nlQqs4eqFnEg6KuK+j6NL7ovVgONlAWgzadWuNSmV CDDLwc9nn7Z2dKJLu4r4V4Glt5pdYEtNNzsy46rXZhoVdhmSrnaqpeHBq1npIrB8HI7j AXhx0VJK3YNk7FVjC+aq5Ulw2NjKbqYP5s1nKS0BwsacG0OgECN3JsloL77TkrXxPr/r 4LQg== X-Forwarded-Encrypted: i=1; AJvYcCWwiaBFmp7hs9f8BUBcdqS6F3fhrgXFs0YxOkpW2pQTAVPGX/DvZkKsDOCEeJWyq1N/4APbfG2uVpEieCv2I4rKZ803+YJWPuoI X-Gm-Message-State: AOJu0YwskNk+JzxdNTw7o8PjHyrbCaTeP2QO5rHtJnEtXjmUVjPl6oSG eTIY+7IrgaK+VsDLUxWZO7StDHXiKqmN400V0NnQbL7pIVNDZjwSif+hz9+kSfzMLw9ilLQuMTm tnoDhcjg8DMNv4IIVE84VLfOXAzrnVtuyKyKFn+8aoq67JzP9G4Q4vFOP X-Received: by 2002:a05:6402:345c:b0:561:aa6:3976 with SMTP id l28-20020a056402345c00b005610aa63976mr5516172edc.9.1707757198653; Mon, 12 Feb 2024 08:59:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IEyUpx63MaPiRn9G9d80PqG5/lPqN+lnyfZ044mU8iFlZoxsi4myrnOKyNNVRWSMfwjy5f9cA== X-Received: by 2002:a05:6402:345c:b0:561:aa6:3976 with SMTP id l28-20020a056402345c00b005610aa63976mr5516157edc.9.1707757198461; Mon, 12 Feb 2024 08:59:58 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCUJHgORsjctOZtKHJJrXjpPkQj9xVQ8t62rizLdYxISuAgVKlsiORGXpyr2a1TZXip5eAkHUIKj1oM2JN9IrK2xES+fAztqn0P/sPcQrR0M1WfMRpPj9bwmv/MIMT/uG6Tq9KyekX5qr4Ds94g0nAWedC9yEessfRRcD8GkC+SHy/9h9nHaXhV8+3j5YtHPsK1BalYd8M6F2khs6Jl6gIUr2Uhk7sSYQVCX Received: from thinky.redhat.com ([109.183.6.197]) by smtp.gmail.com with ESMTPSA id 14-20020a0564021f4e00b0056176e95a88sm2620261edz.32.2024.02.12.08.59.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 08:59:58 -0800 (PST) From: Andrey Albershteyn To: fsverity@lists.linux.dev, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, chandan.babu@oracle.com, djwong@kernel.org, ebiggers@kernel.org Cc: Andrey Albershteyn Subject: [PATCH v4 08/25] fsverity: calculate readahead in bytes instead of pages Date: Mon, 12 Feb 2024 17:58:05 +0100 Message-Id: <20240212165821.1901300-9-aalbersh@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240212165821.1901300-1-aalbersh@redhat.com> References: <20240212165821.1901300-1-aalbersh@redhat.com> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Replace readahead unit from pages to bytes as fs-verity is now mainly works with blocks instead of pages. Signed-off-by: Andrey Albershteyn --- fs/verity/fsverity_private.h | 4 ++-- fs/verity/verify.c | 41 +++++++++++++++++++----------------- include/linux/fsverity.h | 6 +++--- 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/fs/verity/fsverity_private.h b/fs/verity/fsverity_private.h index 72ac1cdd9e63..2bf1f94d437c 100644 --- a/fs/verity/fsverity_private.h +++ b/fs/verity/fsverity_private.h @@ -170,7 +170,7 @@ void fsverity_drop_block(struct inode *inode, * @inode: inode in use for verification or metadata reading * @pos: byte offset of the block within the Merkle tree * @block: block to read - * @num_ra_pages: number of pages to readahead, may be ignored + * @ra_bytes: number of bytes to readahead, may be ignored * * Depending on fs implementation use read_merkle_tree_block() or * read_merkle_tree_page() to read blocks. @@ -179,6 +179,6 @@ int fsverity_read_merkle_tree_block(struct inode *inode, u64 pos, struct fsverity_blockbuf *block, unsigned int log_blocksize, - unsigned long num_ra_pages); + u64 ra_bytes); #endif /* _FSVERITY_PRIVATE_H */ diff --git a/fs/verity/verify.c b/fs/verity/verify.c index 414ec3321fe6..6f4ff420c075 100644 --- a/fs/verity/verify.c +++ b/fs/verity/verify.c @@ -39,13 +39,12 @@ static bool is_hash_block_verified(struct fsverity_info *vi, */ static bool verify_data_block(struct inode *inode, struct fsverity_info *vi, - const void *data, u64 data_pos, unsigned long max_ra_pages) + const void *data, u64 data_pos, u64 max_ra_bytes) { const struct merkle_tree_params *params = &vi->tree_params; const unsigned int hsize = params->digest_size; int level; int err; - int num_ra_pages; u8 _want_hash[FS_VERITY_MAX_DIGEST_SIZE]; const u8 *want_hash; u8 real_hash[FS_VERITY_MAX_DIGEST_SIZE]; @@ -92,9 +91,11 @@ verify_data_block(struct inode *inode, struct fsverity_info *vi, for (level = 0; level < params->num_levels; level++) { unsigned long next_hidx; unsigned long hblock_idx; - pgoff_t hpage_idx; unsigned int hoffset; struct fsverity_blockbuf *block = &hblocks[level].block; + u64 block_offset; + u64 ra_bytes = 0; + u64 tree_size; /* * The index of the block in the current level; also the index @@ -105,18 +106,20 @@ verify_data_block(struct inode *inode, struct fsverity_info *vi, /* Index of the hash block in the tree overall */ hblock_idx = params->level_start[level] + next_hidx; - /* Index of the hash page in the tree overall */ - hpage_idx = hblock_idx >> params->log_blocks_per_page; + /* Offset of the Merkle tree block into the tree */ + block_offset = hblock_idx << params->log_blocksize; /* Byte offset of the hash within the block */ hoffset = (hidx << params->log_digestsize) & (params->block_size - 1); - num_ra_pages = level == 0 ? - min(max_ra_pages, params->tree_pages - hpage_idx) : 0; + if (level == 0) { + tree_size = params->tree_pages << PAGE_SHIFT; + ra_bytes = min(max_ra_bytes, (tree_size - block_offset)); + } err = fsverity_read_merkle_tree_block( - inode, hblock_idx << params->log_blocksize, block, - params->log_blocksize, num_ra_pages); + inode, block_offset, block, + params->log_blocksize, ra_bytes); if (err) { fsverity_err(inode, "Error %d reading Merkle tree block %lu", @@ -182,7 +185,7 @@ verify_data_block(struct inode *inode, struct fsverity_info *vi, static bool verify_data_blocks(struct folio *data_folio, size_t len, size_t offset, - unsigned long max_ra_pages) + u64 max_ra_bytes) { struct inode *inode = data_folio->mapping->host; struct fsverity_info *vi = inode->i_verity_info; @@ -200,7 +203,7 @@ verify_data_blocks(struct folio *data_folio, size_t len, size_t offset, data = kmap_local_folio(data_folio, offset); valid = verify_data_block(inode, vi, data, pos + offset, - max_ra_pages); + max_ra_bytes); kunmap_local(data); if (!valid) return false; @@ -246,24 +249,24 @@ EXPORT_SYMBOL_GPL(fsverity_verify_blocks); void fsverity_verify_bio(struct bio *bio) { struct folio_iter fi; - unsigned long max_ra_pages = 0; + u64 max_ra_bytes = 0; if (bio->bi_opf & REQ_RAHEAD) { /* * If this bio is for data readahead, then we also do readahead * of the first (largest) level of the Merkle tree. Namely, - * when a Merkle tree page is read, we also try to piggy-back on - * some additional pages -- up to 1/4 the number of data pages. + * when a Merkle tree is read, we also try to piggy-back on + * some additional bytes -- up to 1/4 of data. * * This improves sequential read performance, as it greatly * reduces the number of I/O requests made to the Merkle tree. */ - max_ra_pages = bio->bi_iter.bi_size >> (PAGE_SHIFT + 2); + max_ra_bytes = bio->bi_iter.bi_size >> 2; } bio_for_each_folio_all(fi, bio) { if (!verify_data_blocks(fi.folio, fi.length, fi.offset, - max_ra_pages)) { + max_ra_bytes)) { bio->bi_status = BLK_STS_IOERR; break; } @@ -431,7 +434,7 @@ int fsverity_read_merkle_tree_block(struct inode *inode, u64 pos, struct fsverity_blockbuf *block, unsigned int log_blocksize, - unsigned long num_ra_pages) + u64 ra_bytes) { struct page *page; int err = 0; @@ -439,10 +442,10 @@ int fsverity_read_merkle_tree_block(struct inode *inode, if (inode->i_sb->s_vop->read_merkle_tree_block) return inode->i_sb->s_vop->read_merkle_tree_block( - inode, pos, block, log_blocksize, num_ra_pages); + inode, pos, block, log_blocksize, ra_bytes); page = inode->i_sb->s_vop->read_merkle_tree_page( - inode, index, num_ra_pages); + inode, index, (ra_bytes >> PAGE_SHIFT)); if (IS_ERR(page)) { err = PTR_ERR(page); fsverity_err(inode, diff --git a/include/linux/fsverity.h b/include/linux/fsverity.h index fb2d4fccec0c..7bb0e044c44e 100644 --- a/include/linux/fsverity.h +++ b/include/linux/fsverity.h @@ -143,8 +143,8 @@ struct fsverity_operations { * @pos: byte offset of the block within the Merkle tree * @block: block buffer for filesystem to point it to the block * @log_blocksize: size of the expected block - * @num_ra_pages: The number of pages with blocks that should be - * prefetched starting at @index if the page at @index + * @ra_bytes: The number of bytes that should be + * prefetched starting at @pos if the data at @pos * isn't already cached. Implementations may ignore this * argument; it's only a performance optimization. * @@ -161,7 +161,7 @@ struct fsverity_operations { u64 pos, struct fsverity_blockbuf *block, unsigned int log_blocksize, - unsigned long num_ra_pages); + u64 ra_bytes); /** * Write a Merkle tree block to the given inode. From patchwork Mon Feb 12 16:58:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Albershteyn X-Patchwork-Id: 13553744 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 601853F8D9 for ; Mon, 12 Feb 2024 17:00:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757208; cv=none; b=RB+3xkWVElBQ8jmYealaF2NRb5mVCbNTmlL05TT4eFjGNvGwPCaHj05L/Ai6b9ilE7WGNVwMRLkuES7Yw1ulGjUUDi+gpCfR21LxDFBGhTIvvqbE2oq1+P9hEn+Mr4L8rrjI5qDEasyqjdznYQDMlWUP+IjafV6CDOCoJII3Zww= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757208; c=relaxed/simple; bh=wpwwkUMQQ1oCVKokCsM4qLWIq0nv9cKIzEH2+0qCgCE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JXGi9u18Y38tfn+R4rtobfwgg56euT/sOB1qxexGNE9uhHNvGQ9C+0rljy62DHUXrJhmpNfZ7IPDrCj8fyjsF0xAdPkxFhJqhsxgktPtwjWvBZWR5jPm+f1OBzYqcpzJ9PrFjl2xxN9wc1SqzArs2tfahlNpBaDnlLaBP4RGIEg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=VZpP62te; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="VZpP62te" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707757205; 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=OS1TTVXUwoueTLFTvYK+vY3u9o7lEMipfR1U95f36dE=; b=VZpP62te6WMWmq8YWtX07DbjDQS99CR3+WYgwrZ/AcVfaA5jwBl2otWyR34yF0LFq7Trf7 R+kZoJzicYQ3uYFqcWNcDnp35nYAGLmtX/luOEJxztdo0NGLTFfNjjK/cLN/UzpJOWEBUW bFMFqX5bu1IguWfV+Rt9VCO5qYnsjc8= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-126-_RtT8siDOn-nhpq-PUcoVw-1; Mon, 12 Feb 2024 12:00:01 -0500 X-MC-Unique: _RtT8siDOn-nhpq-PUcoVw-1 Received: by mail-ed1-f71.google.com with SMTP id 4fb4d7f45d1cf-55ffc81c768so1814663a12.1 for ; Mon, 12 Feb 2024 09:00:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707757200; x=1708362000; 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=OS1TTVXUwoueTLFTvYK+vY3u9o7lEMipfR1U95f36dE=; b=pA2hLyDQbTrEh8yWCrAtOgSd7TDl47JGuPgh71RI3IOQZOyPRf3AkuMUtUmHux9k8Q ZZtpExWX1sECNLNPJgLQ7kfxpsGUvUKu305WpQjkvi5jMF0YER1g6k/QP00q1zRJOJAZ DPEOvUwMXLK4qujmTC7/7GyUeVqFtx3/mksqfryN7GcNiVpCg4c9Mcv6mj7yjr5/zIrl 1vSqgvyIAo+n3GWxjTJCVuGwcMEmaCE5Wq15iWWkcP6BcYodc+KByy6YyccjL/YjNIRA 7VXLtchf4rm6AgE7eW869tyhAJY2/49uSUc02vEfce6eKKUFBM3Fd/Lm8OQHZqgod67g TtZA== X-Forwarded-Encrypted: i=1; AJvYcCVFFcUQ+OaAITKrTXlvFPOsXv77RQn+Sm+y8SWFTrt9y6MwoElxrORX6lnSpD/ZpFgl8N7BOt8+U0YYdp35NKUKEYbDNJzCLesq X-Gm-Message-State: AOJu0YzcFKjZ41LjzvKP980mRIzmNbkI/AzHPDQsSRvppu/pu8GyAZA8 rcXI/MdQoJtoPQET/ZhD7QCc1OofbUbF9jVskKJtcLxvGH7mlbAS/Uwd5UPl44s/vQT3FvCBwJN RF18OxRSWYrQmbLi805+pHnXF6VEoJFwxAvrxZyKVv+LEiviPvkbLCHE1 X-Received: by 2002:a05:6402:340a:b0:560:d8f:7def with SMTP id k10-20020a056402340a00b005600d8f7defmr4952864edc.17.1707757200084; Mon, 12 Feb 2024 09:00:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IFXs4sVH479tj2ZtRasutF5KZELjjn6nPEsO6+MLMpUqOCGNpWr46bM8IgDBprWb0bvFS6oAQ== X-Received: by 2002:a05:6402:340a:b0:560:d8f:7def with SMTP id k10-20020a056402340a00b005600d8f7defmr4952856edc.17.1707757199839; Mon, 12 Feb 2024 08:59:59 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCX54n73+DMnZitQfTasX1dPQoZeopMMHvZHa+36is0tgm/fSeiwsLtpwj1J6UOZOo536zkHYgsslO4Qku0W9vVQXMzosV85pKyfKmah9GXD9tBY6bat7QItE1BveRvKIv4c60LeD6raZ+h07EBVXT6zMdwYkwSej4BYGiJCFa06ANz5vPJUol+eqA3YRdCbVaCX9LEhOgI9hV0DJTZr/hynSgC8tHQmKx3o Received: from thinky.redhat.com ([109.183.6.197]) by smtp.gmail.com with ESMTPSA id 14-20020a0564021f4e00b0056176e95a88sm2620261edz.32.2024.02.12.08.59.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 08:59:58 -0800 (PST) From: Andrey Albershteyn To: fsverity@lists.linux.dev, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, chandan.babu@oracle.com, djwong@kernel.org, ebiggers@kernel.org Cc: Andrey Albershteyn Subject: [PATCH v4 09/25] fsverity: add tracepoints Date: Mon, 12 Feb 2024 17:58:06 +0100 Message-Id: <20240212165821.1901300-10-aalbersh@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240212165821.1901300-1-aalbersh@redhat.com> References: <20240212165821.1901300-1-aalbersh@redhat.com> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 fs-verity previously had debug printk but it was removed. This patch adds trace points to the same places where printk were used (with a few additional ones). Signed-off-by: Andrey Albershteyn --- fs/verity/enable.c | 3 + fs/verity/fsverity_private.h | 2 + fs/verity/init.c | 1 + fs/verity/signature.c | 2 + fs/verity/verify.c | 10 ++ include/trace/events/fsverity.h | 184 ++++++++++++++++++++++++++++++++ 6 files changed, 202 insertions(+) create mode 100644 include/trace/events/fsverity.h diff --git a/fs/verity/enable.c b/fs/verity/enable.c index 04e060880b79..945eba0092ab 100644 --- a/fs/verity/enable.c +++ b/fs/verity/enable.c @@ -227,6 +227,8 @@ static int enable_verity(struct file *filp, if (err) goto out; + trace_fsverity_enable(inode, desc, ¶ms); + /* * Start enabling verity on this file, serialized by the inode lock. * Fail if verity is already enabled or is already being enabled. @@ -255,6 +257,7 @@ static int enable_verity(struct file *filp, fsverity_err(inode, "Error %d building Merkle tree", err); goto rollback; } + trace_fsverity_tree_done(inode, desc, ¶ms); /* * Create the fsverity_info. Don't bother trying to save work by diff --git a/fs/verity/fsverity_private.h b/fs/verity/fsverity_private.h index 2bf1f94d437c..4ac9786235b5 100644 --- a/fs/verity/fsverity_private.h +++ b/fs/verity/fsverity_private.h @@ -181,4 +181,6 @@ int fsverity_read_merkle_tree_block(struct inode *inode, unsigned int log_blocksize, u64 ra_bytes); +#include + #endif /* _FSVERITY_PRIVATE_H */ diff --git a/fs/verity/init.c b/fs/verity/init.c index cb2c9aac61ed..3769d2dc9e3b 100644 --- a/fs/verity/init.c +++ b/fs/verity/init.c @@ -5,6 +5,7 @@ * Copyright 2019 Google LLC */ +#define CREATE_TRACE_POINTS #include "fsverity_private.h" #include diff --git a/fs/verity/signature.c b/fs/verity/signature.c index 90c07573dd77..c1f08bb32ed1 100644 --- a/fs/verity/signature.c +++ b/fs/verity/signature.c @@ -53,6 +53,8 @@ int fsverity_verify_signature(const struct fsverity_info *vi, struct fsverity_formatted_digest *d; int err; + trace_fsverity_verify_signature(inode, signature, sig_size); + if (sig_size == 0) { if (fsverity_require_signatures) { fsverity_err(inode, diff --git a/fs/verity/verify.c b/fs/verity/verify.c index 6f4ff420c075..4375b0cd176e 100644 --- a/fs/verity/verify.c +++ b/fs/verity/verify.c @@ -57,6 +57,7 @@ verify_data_block(struct inode *inode, struct fsverity_info *vi, /* Byte offset of the wanted hash relative to @addr */ unsigned int hoffset; } hblocks[FS_VERITY_MAX_LEVELS]; + trace_fsverity_verify_block(inode, data_pos); /* * The index of the previous level's block within that level; also the * index of that block's hash within the current level. @@ -129,6 +130,9 @@ verify_data_block(struct inode *inode, struct fsverity_info *vi, if (is_hash_block_verified(vi, block, hblock_idx)) { memcpy(_want_hash, block->kaddr + hoffset, hsize); want_hash = _want_hash; + trace_fsverity_merkle_tree_block_verified(inode, + hblock_idx, + FSVERITY_TRACE_DIR_ASCEND); fsverity_drop_block(inode, block); goto descend; } @@ -160,6 +164,8 @@ verify_data_block(struct inode *inode, struct fsverity_info *vi, block->verified = true; memcpy(_want_hash, haddr + hoffset, hsize); want_hash = _want_hash; + trace_fsverity_merkle_tree_block_verified(inode, hblock_idx, + FSVERITY_TRACE_DIR_DESCEND); fsverity_drop_block(inode, block); } @@ -334,6 +340,8 @@ void fsverity_invalidate_range(struct inode *inode, loff_t offset, return; } + trace_fsverity_invalidate_blocks(inode, index, blocks); + for (i = 0; i < blocks; i++) clear_bit(index + i, vi->hash_block_verified); } @@ -440,6 +448,8 @@ int fsverity_read_merkle_tree_block(struct inode *inode, int err = 0; unsigned long index = pos >> PAGE_SHIFT; + trace_fsverity_read_merkle_tree_block(inode, pos, log_blocksize); + if (inode->i_sb->s_vop->read_merkle_tree_block) return inode->i_sb->s_vop->read_merkle_tree_block( inode, pos, block, log_blocksize, ra_bytes); diff --git a/include/trace/events/fsverity.h b/include/trace/events/fsverity.h new file mode 100644 index 000000000000..3cc429d21443 --- /dev/null +++ b/include/trace/events/fsverity.h @@ -0,0 +1,184 @@ +// SPDX-License-Identifier: GPL-2.0 +#undef TRACE_SYSTEM +#define TRACE_SYSTEM fsverity + +#if !defined(_TRACE_FSVERITY_H) || defined(TRACE_HEADER_MULTI_READ) +#define _TRACE_FSVERITY_H + +#include + +struct fsverity_descriptor; +struct merkle_tree_params; +struct fsverity_info; + +#define FSVERITY_TRACE_DIR_ASCEND (1ul << 0) +#define FSVERITY_TRACE_DIR_DESCEND (1ul << 1) +#define FSVERITY_HASH_SHOWN_LEN 20 + +TRACE_EVENT(fsverity_enable, + TP_PROTO(struct inode *inode, struct fsverity_descriptor *desc, + struct merkle_tree_params *params), + TP_ARGS(inode, desc, params), + TP_STRUCT__entry( + __field(ino_t, ino) + __field(u64, data_size) + __field(unsigned int, block_size) + __field(unsigned int, num_levels) + __field(u64, tree_size) + ), + TP_fast_assign( + __entry->ino = inode->i_ino; + __entry->data_size = desc->data_size; + __entry->block_size = params->block_size; + __entry->num_levels = params->num_levels; + __entry->tree_size = params->tree_size; + ), + TP_printk("ino %lu data size %llu tree size %llu block size %u levels %u", + (unsigned long) __entry->ino, + __entry->data_size, + __entry->tree_size, + __entry->block_size, + __entry->num_levels) +); + +TRACE_EVENT(fsverity_tree_done, + TP_PROTO(struct inode *inode, struct fsverity_descriptor *desc, + struct merkle_tree_params *params), + TP_ARGS(inode, desc, params), + TP_STRUCT__entry( + __field(ino_t, ino) + __field(unsigned int, levels) + __field(unsigned int, tree_blocks) + __field(u64, tree_size) + __array(u8, tree_hash, 64) + ), + TP_fast_assign( + __entry->ino = inode->i_ino; + __entry->levels = params->num_levels; + __entry->tree_blocks = + params->tree_size >> params->log_blocksize; + __entry->tree_size = params->tree_size; + memcpy(__entry->tree_hash, desc->root_hash, 64); + ), + TP_printk("ino %lu levels %d tree_blocks %d tree_size %lld root_hash %s", + (unsigned long) __entry->ino, + __entry->levels, + __entry->tree_blocks, + __entry->tree_size, + __print_hex(__entry->tree_hash, 64)) +); + +TRACE_EVENT(fsverity_verify_block, + TP_PROTO(struct inode *inode, u64 offset), + TP_ARGS(inode, offset), + TP_STRUCT__entry( + __field(ino_t, ino) + __field(u64, offset) + __field(unsigned int, block_size) + ), + TP_fast_assign( + __entry->ino = inode->i_ino; + __entry->offset = offset; + __entry->block_size = + inode->i_verity_info->tree_params.block_size; + ), + TP_printk("ino %lu data offset %lld data block size %u", + (unsigned long) __entry->ino, + __entry->offset, + __entry->block_size) +); + +TRACE_EVENT(fsverity_merkle_tree_block_verified, + TP_PROTO(struct inode *inode, u64 index, u8 direction), + TP_ARGS(inode, index, direction), + TP_STRUCT__entry( + __field(ino_t, ino) + __field(u64, index) + __field(u8, direction) + ), + TP_fast_assign( + __entry->ino = inode->i_ino; + __entry->index = index; + __entry->direction = direction; + ), + TP_printk("ino %lu block index %llu %s", + (unsigned long) __entry->ino, + __entry->index, + __entry->direction == 0 ? "ascend" : "descend") +); + +TRACE_EVENT(fsverity_invalidate_blocks, + TP_PROTO(struct inode *inode, u64 index, size_t blocks), + TP_ARGS(inode, index, blocks), + TP_STRUCT__entry( + __field(ino_t, ino) + __field(unsigned int, block_size) + __field(u64, offset) + __field(u64, index) + __field(size_t, blocks) + ), + TP_fast_assign( + __entry->ino = inode->i_ino; + __entry->block_size = inode->i_verity_info->tree_params.log_blocksize; + __entry->offset = index << __entry->block_size; + __entry->index = index; + __entry->blocks = blocks; + ), + TP_printk("ino %lu tree offset %llu block index %llu num blocks %zx", + (unsigned long) __entry->ino, + __entry->offset, + __entry->index, + __entry->blocks) +); + +TRACE_EVENT(fsverity_read_merkle_tree_block, + TP_PROTO(struct inode *inode, u64 offset, unsigned int log_blocksize), + TP_ARGS(inode, offset, log_blocksize), + TP_STRUCT__entry( + __field(ino_t, ino) + __field(u64, offset) + __field(u64, index) + __field(unsigned int, block_size) + ), + TP_fast_assign( + __entry->ino = inode->i_ino; + __entry->offset = offset; + __entry->index = offset >> log_blocksize; + __entry->block_size = 1 << log_blocksize; + ), + TP_printk("ino %lu tree offset %llu block index %llu block hize %u", + (unsigned long) __entry->ino, + __entry->offset, + __entry->index, + __entry->block_size) +); + +TRACE_EVENT(fsverity_verify_signature, + TP_PROTO(const struct inode *inode, const u8 *signature, size_t sig_size), + TP_ARGS(inode, signature, sig_size), + TP_STRUCT__entry( + __field(ino_t, ino) + __dynamic_array(u8, signature, sig_size) + __field(size_t, sig_size) + __field(size_t, sig_size_show) + ), + TP_fast_assign( + __entry->ino = inode->i_ino; + memcpy(__get_dynamic_array(signature), signature, sig_size); + __entry->sig_size = sig_size; + __entry->sig_size_show = (sig_size > FSVERITY_HASH_SHOWN_LEN ? + FSVERITY_HASH_SHOWN_LEN : sig_size); + ), + TP_printk("ino %lu sig_size %lu %s%s%s", + (unsigned long) __entry->ino, + __entry->sig_size, + (__entry->sig_size ? "sig " : ""), + __print_hex(__get_dynamic_array(signature), + __entry->sig_size_show), + (__entry->sig_size ? "..." : "")) +); + +#endif /* _TRACE_FSVERITY_H */ + +/* This part must be outside protection */ +#include From patchwork Mon Feb 12 16:58:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Albershteyn X-Patchwork-Id: 13553745 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 02BBE3D56B for ; Mon, 12 Feb 2024 17:00:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757208; cv=none; b=no1qGiypaG39YqHwRJvkDU3dVNXjBFqZULieTyh9uphLS/aEAijhkQ8U8Xs0kDd4X+5zBFq6DCrbAy5Z8bEkNUbNOWQgDb3FvukWUrSle86uoaYVJhnMgyj0JPFjOlEmYj3ur7wE11Z+onl8kay8em6wS8TIC2+O1SrtzXATs+8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757208; c=relaxed/simple; bh=gqPwTi/iI7+V5Msjzc3RNk/M6KJnaDdjZn8/50/WjMg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=D4L2+w94z27Cm5EhkaqRrNTGe5UmawedvOTlHdgIsb5G5OiKVQutSfsKS6qrsMkykYtXtY2VWFQD+aJMGf6ELjz+z85Dzwsz4G7lRUi36gmZsyjtr4/Md51RGjIvUYA1/YLjcuxZuPDha8b8jlSnQQdob44Pu7APAt1sVFcmyKU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=EZTHfbw0; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="EZTHfbw0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707757205; 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=+rOTZjO78lnXVnaORi03L3fAP8ZzltwHyB9rd8lOsoc=; b=EZTHfbw0AMEAA/2lc6A/YacCG+8J+loqiMdZnBTbD1NGWwg9fLgOf505mBzXugh0TZJ39H WzVQ1+mDF+sQMpJtRFqEuFrAPu4k6ehe+8Cytr3JkXP7i6FSd4wAROyJerd6MJnmeTJBQK CBPBXzNFWNBUmWKxC23NJJf8yvqm8Ag= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-34-VNT0T-TNO2y8VkI1bVY8Tw-1; Mon, 12 Feb 2024 12:00:03 -0500 X-MC-Unique: VNT0T-TNO2y8VkI1bVY8Tw-1 Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-55ffcfed2ffso4899181a12.0 for ; Mon, 12 Feb 2024 09:00:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707757201; x=1708362001; 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=+rOTZjO78lnXVnaORi03L3fAP8ZzltwHyB9rd8lOsoc=; b=vn2OBeZ99Zk8AvzCeibKGik//Muq4MrLmcTyJKHVu/loRup8HvZmo33GYqSU1zOHAJ yItSEFSqmxHDOgmtjNXr62xjavMzUGhRi3JclqTX7dG7yh0xfWxcLzBsd+O+6EvGTaod evut87YgWnYCgE4J3MiQkshOk1paiA24QX8sSPhM/YxpqrojIiT4Xg3E89rvvGhFjy2W 3uBz8W5XqxASZSvzBUigrkYwI181phYO9/39fjiAdZB1v3zWNJ3QtgT4WidDVMHOOrcR /YfM78CY32eQBRlcF4LZona0tLbxTwSJIAmGbctTfEmN2v5Bqtemg2upv99+ZxAsFnoV MTLw== X-Forwarded-Encrypted: i=1; AJvYcCUjQ978067/guVAMiSBGvuQZVdfbhoYvHBYqnOOBo3kCk1zT4Le+DfycrbSP7p/jTdoyibtmLJRxn2XCAb7c8T0imil6W7rvDgg X-Gm-Message-State: AOJu0YyaIfcwmfeGrIziml+YNr448PSdLy3bxBAGZuv4o/bUcpy/rXj7 TmHp6r2+DB5h3X9qhj0mPJl06FEEncqWv1brTWJvNIBz8fRw4VQICS/DmwXHc5K17mK3Ex5N9Hz GAL89j67D6ycw7Hjg9XmWuO5xUBN2dFL1mbEkX06XGBLT/pomJCBze9sC X-Received: by 2002:a05:6402:6c7:b0:561:4562:6187 with SMTP id n7-20020a05640206c700b0056145626187mr57889edy.12.1707757201524; Mon, 12 Feb 2024 09:00:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IEZ8SZf79gVOrdJ0iUSk5/4gUmg7Ux3jY3Tr4bex34FhvPUTKw5RxYr3uZN3CEUwPMXFTSt5A== X-Received: by 2002:a05:6402:6c7:b0:561:4562:6187 with SMTP id n7-20020a05640206c700b0056145626187mr57879edy.12.1707757201244; Mon, 12 Feb 2024 09:00:01 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWWYxbCTfNPhC0MnK6pSKt2cSwVhRAaS3e2KP3aw2uflsIVje+1GJjjdpw1Ig3E9PdGGN3xcnyzSIGbQi6Ld7Vw7/pwcSGBLovUV3Gsw73FuhBNk3sBabFRUGUtqRXi/HM03r4G0P3glfUTEWBtovChrPYze1thK5fK4HG0pUWKYR8emz6T1cgk+Yup/uB5RtWotrKbp+A39jZvpTJRh/Jh2oiAPy1Ab+1GXQ8fOeDEaY95/4U+ Received: from thinky.redhat.com ([109.183.6.197]) by smtp.gmail.com with ESMTPSA id 14-20020a0564021f4e00b0056176e95a88sm2620261edz.32.2024.02.12.08.59.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 09:00:00 -0800 (PST) From: Andrey Albershteyn To: fsverity@lists.linux.dev, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, chandan.babu@oracle.com, djwong@kernel.org, ebiggers@kernel.org Cc: Andrey Albershteyn , Christoph Hellwig Subject: [PATCH v4 10/25] iomap: integrate fsverity verification into iomap's read path Date: Mon, 12 Feb 2024 17:58:07 +0100 Message-Id: <20240212165821.1901300-11-aalbersh@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240212165821.1901300-1-aalbersh@redhat.com> References: <20240212165821.1901300-1-aalbersh@redhat.com> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This patch adds fsverity verification into iomap's read path. After BIO's io operation is complete the data are verified against fsverity's Merkle tree. Verification work is done in a separate workqueue. Even though fsverity can create its own workqueue, this patch allows filesystems to pass any workqueue for fs-verity verification work items. This is handy for XFS as fsverity's high priority global workqueue isn't the best fit (potential livelock, global cross-filesystem queue). The read path ioend iomap_read_ioend are stored side by side with BIOs if FS_VERITY is enabled. Signed-off-by: Andrey Albershteyn Signed-off-by: Christoph Hellwig --- fs/erofs/data.c | 4 +- fs/gfs2/aops.c | 4 +- fs/iomap/buffered-io.c | 102 ++++++++++++++++++++++++++++++++++++----- fs/xfs/xfs_aops.c | 4 +- fs/zonefs/file.c | 4 +- include/linux/iomap.h | 6 ++- 6 files changed, 103 insertions(+), 21 deletions(-) diff --git a/fs/erofs/data.c b/fs/erofs/data.c index c98aeda8abb2..462917830b50 100644 --- a/fs/erofs/data.c +++ b/fs/erofs/data.c @@ -356,12 +356,12 @@ int erofs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, */ static int erofs_read_folio(struct file *file, struct folio *folio) { - return iomap_read_folio(folio, &erofs_iomap_ops); + return iomap_read_folio(folio, &erofs_iomap_ops, NULL); } static void erofs_readahead(struct readahead_control *rac) { - return iomap_readahead(rac, &erofs_iomap_ops); + return iomap_readahead(rac, &erofs_iomap_ops, NULL); } static sector_t erofs_bmap(struct address_space *mapping, sector_t block) diff --git a/fs/gfs2/aops.c b/fs/gfs2/aops.c index 974aca9c8ea8..ede423796125 100644 --- a/fs/gfs2/aops.c +++ b/fs/gfs2/aops.c @@ -452,7 +452,7 @@ static int gfs2_read_folio(struct file *file, struct folio *folio) if (!gfs2_is_jdata(ip) || (i_blocksize(inode) == PAGE_SIZE && !folio_buffers(folio))) { - error = iomap_read_folio(folio, &gfs2_iomap_ops); + error = iomap_read_folio(folio, &gfs2_iomap_ops, NULL); } else if (gfs2_is_stuffed(ip)) { error = stuffed_read_folio(ip, folio); } else { @@ -527,7 +527,7 @@ static void gfs2_readahead(struct readahead_control *rac) else if (gfs2_is_jdata(ip)) mpage_readahead(rac, gfs2_block_map); else - iomap_readahead(rac, &gfs2_iomap_ops); + iomap_readahead(rac, &gfs2_iomap_ops, NULL); } /** diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 093c4515b22a..719c3dec9652 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -289,6 +290,7 @@ struct iomap_readpage_ctx { bool cur_folio_in_bio; struct bio *bio; struct readahead_control *rac; + struct workqueue_struct *wq; }; /** @@ -330,6 +332,57 @@ static inline bool iomap_block_needs_zeroing(const struct iomap_iter *iter, pos >= i_size_read(iter->inode); } +#ifdef CONFIG_FS_VERITY +struct iomap_fsverity_bio { + struct work_struct work; + struct bio bio; +}; +static struct bio_set iomap_fsverity_bioset; + +static void +iomap_read_fsverify_end_io_work(struct work_struct *work) +{ + struct iomap_fsverity_bio *fbio = + container_of(work, struct iomap_fsverity_bio, work); + + fsverity_verify_bio(&fbio->bio); + iomap_read_end_io(&fbio->bio); +} + +static void +iomap_read_fsverity_end_io(struct bio *bio) +{ + struct iomap_fsverity_bio *fbio = + container_of(bio, struct iomap_fsverity_bio, bio); + + INIT_WORK(&fbio->work, iomap_read_fsverify_end_io_work); + queue_work(bio->bi_private, &fbio->work); +} +#endif /* CONFIG_FS_VERITY */ + +static struct bio *iomap_read_bio_alloc(struct inode *inode, + struct block_device *bdev, int nr_vecs, gfp_t gfp, + struct workqueue_struct *wq) +{ + struct bio *bio; + +#ifdef CONFIG_FS_VERITY + if (fsverity_active(inode)) { + bio = bio_alloc_bioset(bdev, nr_vecs, REQ_OP_READ, gfp, + &iomap_fsverity_bioset); + if (bio) { + bio->bi_private = wq; + bio->bi_end_io = iomap_read_fsverity_end_io; + } + return bio; + } +#endif + bio = bio_alloc(bdev, nr_vecs, REQ_OP_READ, gfp); + if (bio) + bio->bi_end_io = iomap_read_end_io; + return bio; +} + static loff_t iomap_readpage_iter(const struct iomap_iter *iter, struct iomap_readpage_ctx *ctx, loff_t offset) { @@ -353,6 +406,12 @@ static loff_t iomap_readpage_iter(const struct iomap_iter *iter, if (iomap_block_needs_zeroing(iter, pos)) { folio_zero_range(folio, poff, plen); + if (fsverity_active(iter->inode) && + !fsverity_verify_blocks(folio, plen, poff)) { + folio_set_error(folio); + goto done; + } + iomap_set_range_uptodate(folio, poff, plen); goto done; } @@ -370,28 +429,29 @@ static loff_t iomap_readpage_iter(const struct iomap_iter *iter, !bio_add_folio(ctx->bio, folio, plen, poff)) { gfp_t gfp = mapping_gfp_constraint(folio->mapping, GFP_KERNEL); gfp_t orig_gfp = gfp; - unsigned int nr_vecs = DIV_ROUND_UP(length, PAGE_SIZE); if (ctx->bio) submit_bio(ctx->bio); if (ctx->rac) /* same as readahead_gfp_mask */ gfp |= __GFP_NORETRY | __GFP_NOWARN; - ctx->bio = bio_alloc(iomap->bdev, bio_max_segs(nr_vecs), - REQ_OP_READ, gfp); + + ctx->bio = iomap_read_bio_alloc(iter->inode, iomap->bdev, + bio_max_segs(DIV_ROUND_UP(length, PAGE_SIZE)), + gfp, ctx->wq); + /* * If the bio_alloc fails, try it again for a single page to * avoid having to deal with partial page reads. This emulates * what do_mpage_read_folio does. */ if (!ctx->bio) { - ctx->bio = bio_alloc(iomap->bdev, 1, REQ_OP_READ, - orig_gfp); + ctx->bio = iomap_read_bio_alloc(iter->inode, + iomap->bdev, 1, orig_gfp, ctx->wq); } if (ctx->rac) ctx->bio->bi_opf |= REQ_RAHEAD; ctx->bio->bi_iter.bi_sector = sector; - ctx->bio->bi_end_io = iomap_read_end_io; bio_add_folio_nofail(ctx->bio, folio, plen, poff); } @@ -405,7 +465,8 @@ static loff_t iomap_readpage_iter(const struct iomap_iter *iter, return pos - orig_pos + plen; } -int iomap_read_folio(struct folio *folio, const struct iomap_ops *ops) +int iomap_read_folio(struct folio *folio, const struct iomap_ops *ops, + struct workqueue_struct *wq) { struct iomap_iter iter = { .inode = folio->mapping->host, @@ -414,6 +475,7 @@ int iomap_read_folio(struct folio *folio, const struct iomap_ops *ops) }; struct iomap_readpage_ctx ctx = { .cur_folio = folio, + .wq = wq, }; int ret; @@ -471,6 +533,7 @@ static loff_t iomap_readahead_iter(const struct iomap_iter *iter, * iomap_readahead - Attempt to read pages from a file. * @rac: Describes the pages to be read. * @ops: The operations vector for the filesystem. + * @wq: Workqueue for post-I/O processing (only need for fsverity) * * This function is for filesystems to call to implement their readahead * address_space operation. @@ -482,7 +545,8 @@ static loff_t iomap_readahead_iter(const struct iomap_iter *iter, * function is called with memalloc_nofs set, so allocations will not cause * the filesystem to be reentered. */ -void iomap_readahead(struct readahead_control *rac, const struct iomap_ops *ops) +void iomap_readahead(struct readahead_control *rac, const struct iomap_ops *ops, + struct workqueue_struct *wq) { struct iomap_iter iter = { .inode = rac->mapping->host, @@ -491,6 +555,7 @@ void iomap_readahead(struct readahead_control *rac, const struct iomap_ops *ops) }; struct iomap_readpage_ctx ctx = { .rac = rac, + .wq = wq, }; trace_iomap_readahead(rac->mapping->host, readahead_count(rac)); @@ -1996,10 +2061,25 @@ iomap_writepages(struct address_space *mapping, struct writeback_control *wbc, } EXPORT_SYMBOL_GPL(iomap_writepages); +#define IOMAP_POOL_SIZE (4 * (PAGE_SIZE / SECTOR_SIZE)) + static int __init iomap_init(void) { - return bioset_init(&iomap_ioend_bioset, 4 * (PAGE_SIZE / SECTOR_SIZE), - offsetof(struct iomap_ioend, io_inline_bio), - BIOSET_NEED_BVECS); + int error; + + error = bioset_init(&iomap_ioend_bioset, IOMAP_POOL_SIZE, + offsetof(struct iomap_ioend, io_inline_bio), + BIOSET_NEED_BVECS); +#ifdef CONFIG_FS_VERITY + if (error) + return error; + + error = bioset_init(&iomap_fsverity_bioset, IOMAP_POOL_SIZE, + offsetof(struct iomap_fsverity_bio, bio), + BIOSET_NEED_BVECS); + if (error) + bioset_exit(&iomap_ioend_bioset); +#endif + return error; } fs_initcall(iomap_init); diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c index 813f85156b0c..7a6627404160 100644 --- a/fs/xfs/xfs_aops.c +++ b/fs/xfs/xfs_aops.c @@ -553,14 +553,14 @@ xfs_vm_read_folio( struct file *unused, struct folio *folio) { - return iomap_read_folio(folio, &xfs_read_iomap_ops); + return iomap_read_folio(folio, &xfs_read_iomap_ops, NULL); } STATIC void xfs_vm_readahead( struct readahead_control *rac) { - iomap_readahead(rac, &xfs_read_iomap_ops); + iomap_readahead(rac, &xfs_read_iomap_ops, NULL); } static int diff --git a/fs/zonefs/file.c b/fs/zonefs/file.c index 6ab2318a9c8e..d7a166bf15ac 100644 --- a/fs/zonefs/file.c +++ b/fs/zonefs/file.c @@ -112,12 +112,12 @@ static const struct iomap_ops zonefs_write_iomap_ops = { static int zonefs_read_folio(struct file *unused, struct folio *folio) { - return iomap_read_folio(folio, &zonefs_read_iomap_ops); + return iomap_read_folio(folio, &zonefs_read_iomap_ops, NULL); } static void zonefs_readahead(struct readahead_control *rac) { - iomap_readahead(rac, &zonefs_read_iomap_ops); + iomap_readahead(rac, &zonefs_read_iomap_ops, NULL); } /* diff --git a/include/linux/iomap.h b/include/linux/iomap.h index 96dd0acbba44..c7522eb3a8ea 100644 --- a/include/linux/iomap.h +++ b/include/linux/iomap.h @@ -262,8 +262,10 @@ int iomap_file_buffered_write_punch_delalloc(struct inode *inode, struct iomap *iomap, loff_t pos, loff_t length, ssize_t written, int (*punch)(struct inode *inode, loff_t pos, loff_t length)); -int iomap_read_folio(struct folio *folio, const struct iomap_ops *ops); -void iomap_readahead(struct readahead_control *, const struct iomap_ops *ops); +int iomap_read_folio(struct folio *folio, const struct iomap_ops *ops, + struct workqueue_struct *wq); +void iomap_readahead(struct readahead_control *, const struct iomap_ops *ops, + struct workqueue_struct *wq); bool iomap_is_partially_uptodate(struct folio *, size_t from, size_t count); struct folio *iomap_get_folio(struct iomap_iter *iter, loff_t pos, size_t len); bool iomap_release_folio(struct folio *folio, gfp_t gfp_flags); From patchwork Mon Feb 12 16:58:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Albershteyn X-Patchwork-Id: 13553746 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D89403D57A for ; Mon, 12 Feb 2024 17:00:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757209; cv=none; b=LMjRlOda5myVd7eNTBwidqHuwxBeHxPKDQJjnHwdPJ2o4mejAAj+RdVyVCcksSgq5H+zVs3HH4fS1DtAAhWitYtrVib3z1kW42JVcEI2tHnczmbGvyJ1h8gQZtD1oyoo8ApAL0oSg/RmTjn0i23P2+V37GD+xvlZzLnI0I0UmWA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757209; c=relaxed/simple; bh=vytFJhafSlNOFYEGf84JO8aTnuZyHLMQrT6EUAXU8QA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=SKVgle7q5jmZ9hA1rBMtCfdvY/AdYfS71r1dHsDcnJwc837DLtJwinJaMJdbF8042jvCc89hQYLwIwwp9o2JKQmQ+ebDrKO4TshDUTMn/AwKsqG1X1bBJ6GzgQ+ByHp5Dpu6+Fdl4qJDuUdIU/M1RMP8fmnzsn7VDm2+ZPhXaBc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Wdno7twC; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Wdno7twC" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707757206; 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=ebt0keKqegC1RQu3ybPvxOlJeNn/hqPElNtU8o7e1Xg=; b=Wdno7twCitCYJ65j9Bo/4lu+gWbogpl1R8FEMSQLRNOHchJwk7D5nny/1DIWgBNY1WaZTa +u48uri6rSuOguOPoX2jBT9GN5DJvkpybFbEN+wsro2zHT6xwx2itFcSiFx5EmccFRTol4 LfpEadV9u36qzV90hdNu0LL4saPZgLo= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-534-CjrMqpQIPdCsCdXiNgksRg-1; Mon, 12 Feb 2024 12:00:04 -0500 X-MC-Unique: CjrMqpQIPdCsCdXiNgksRg-1 Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-5605a2937d4so2492467a12.1 for ; Mon, 12 Feb 2024 09:00:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707757203; x=1708362003; 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=ebt0keKqegC1RQu3ybPvxOlJeNn/hqPElNtU8o7e1Xg=; b=Xch6bnq+chAXnt4XeJlvURqqJvSaqaGBe22dB8xyZBjaPXvopXbvee8Lj1om2mUjSr 8XYwIWZTqfv5H+TPxEFrwK8pLRYPKrIpbGCYbKxFnPBgTtDjY4vt91IafcsQ5nbFZNqT r4I5AJpkqxpLmz3hBKjsK48YGtDlDtLMZaQbtlnlw3iyr2CVtgceKprBHWOtfsBsSYAk 362fcVfh0g9hfXf52+C2FeYCTOzMkGKkOWEHhUPjYMgCtBCccdkDWULrnX7505rmparp 4P3tmOL1kO0ckfeaua/+5dkZD0qSgKW1oR50ZzkRKi64EIasnWutseCx/QGsty4yGwi7 05Hw== X-Forwarded-Encrypted: i=1; AJvYcCVNNFB4UN1UOHDFNX6v87Zu2H5MvEcMhFIl90TW5bjrhVGCT96xR92WGD/jO4u7TX9bmcx1W9562217EZj1VwT8xZnHhsLgZyXQ X-Gm-Message-State: AOJu0YzKG6ywtEbj4EmdYIOcVdCW0bBPytGIvnlNYFyqiBjedAMuMI/J NJHiKQwecBTwvnudHbNnhGX9B+775Yit7WoC7rh7O6ttWBysRz83/J9iljNEybR5hQsPP37rwQO JMvsOFI7G1+dr5/9odCnOiCVS+aiDYsVotR2oAkBWeKuPBp+ug5O71M5d X-Received: by 2002:aa7:d7c9:0:b0:560:58f:7148 with SMTP id e9-20020aa7d7c9000000b00560058f7148mr5859418eds.34.1707757203652; Mon, 12 Feb 2024 09:00:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IH5d7NhSXUd+Ka9mWVzMAjZ/5gYk1koRVf36bry7me67qozD1nqge7/dD2Vllab+yEamrtJ+g== X-Received: by 2002:aa7:d7c9:0:b0:560:58f:7148 with SMTP id e9-20020aa7d7c9000000b00560058f7148mr5859407eds.34.1707757203481; Mon, 12 Feb 2024 09:00:03 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCXv5yKVk4z2uZA0lhzKt7e5aAhzh2djpqVE42qk88sc1IcDfr7k1epqpOlxq9cCgGoiM3JkoS98ubqWE2iYwMMgVUDxjUqgmNwh7i/1FsrE94bZKrSmgASPboLl4u/cpkAlt0hBmWNoBgoyVk1UvAyqI6x3m9JJ7z73My/znP7Wo/ElrYulT1ky1ZcFmXukQBQRECf2gvpqKOfOYQAJ7Gz7L6peUHGquvy5 Received: from thinky.redhat.com ([109.183.6.197]) by smtp.gmail.com with ESMTPSA id 14-20020a0564021f4e00b0056176e95a88sm2620261edz.32.2024.02.12.09.00.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 09:00:01 -0800 (PST) From: Andrey Albershteyn To: fsverity@lists.linux.dev, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, chandan.babu@oracle.com, djwong@kernel.org, ebiggers@kernel.org Cc: Andrey Albershteyn Subject: [PATCH v4 11/25] xfs: add XBF_VERITY_SEEN xfs_buf flag Date: Mon, 12 Feb 2024 17:58:08 +0100 Message-Id: <20240212165821.1901300-12-aalbersh@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240212165821.1901300-1-aalbersh@redhat.com> References: <20240212165821.1901300-1-aalbersh@redhat.com> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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. XFS will store Merkle tree blocks in extended file attributes. When read extended attribute data is put into xfs_buf. fs-verity uses PG_checked flag to track status of the blocks in the page. This flag can has two meanings - page was re-instantiated and the only block in the page is verified. However, in XFS, the data in the buffer is not aligned with xfs_buf pages and we don't have a reference to these pages. Moreover, these pages are released when value is copied out in xfs_attr code. In other words, we can not directly mark underlying xfs_buf's pages as verified as it's done by fs-verity for other filesystems. One way to track that these pages were processed by fs-verity is to mark buffer as verified instead. If buffer is evicted the incore XBF_VERITY_SEEN flag is lost. When the xattr is read again xfs_attr_get() returns new buffer without the flag. The xfs_buf's flag is then used to tell fs-verity this buffer was cached or not. The second state indicated by PG_checked is if the only block in the PAGE is verified. This is not the case for XFS as there could be multiple blocks in single buffer (page size 64k block size 4k). This is handled by fs-verity bitmap. fs-verity is always uses bitmap for XFS despite of Merkle tree block size. The meaning of the flag is that value of the extended attribute in the buffer is processed by fs-verity. Signed-off-by: Andrey Albershteyn --- fs/xfs/xfs_buf.h | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/fs/xfs/xfs_buf.h b/fs/xfs/xfs_buf.h index b470de08a46c..8f418f726592 100644 --- a/fs/xfs/xfs_buf.h +++ b/fs/xfs/xfs_buf.h @@ -24,14 +24,15 @@ struct xfs_buf; #define XFS_BUF_DADDR_NULL ((xfs_daddr_t) (-1LL)) -#define XBF_READ (1u << 0) /* buffer intended for reading from device */ -#define XBF_WRITE (1u << 1) /* buffer intended for writing to device */ -#define XBF_READ_AHEAD (1u << 2) /* asynchronous read-ahead */ -#define XBF_NO_IOACCT (1u << 3) /* bypass I/O accounting (non-LRU bufs) */ -#define XBF_ASYNC (1u << 4) /* initiator will not wait for completion */ -#define XBF_DONE (1u << 5) /* all pages in the buffer uptodate */ -#define XBF_STALE (1u << 6) /* buffer has been staled, do not find it */ -#define XBF_WRITE_FAIL (1u << 7) /* async writes have failed on this buffer */ +#define XBF_READ (1u << 0) /* buffer intended for reading from device */ +#define XBF_WRITE (1u << 1) /* buffer intended for writing to device */ +#define XBF_READ_AHEAD (1u << 2) /* asynchronous read-ahead */ +#define XBF_NO_IOACCT (1u << 3) /* bypass I/O accounting (non-LRU bufs) */ +#define XBF_ASYNC (1u << 4) /* initiator will not wait for completion */ +#define XBF_DONE (1u << 5) /* all pages in the buffer uptodate */ +#define XBF_STALE (1u << 6) /* buffer has been staled, do not find it */ +#define XBF_WRITE_FAIL (1u << 7) /* async writes have failed on this buffer */ +#define XBF_VERITY_SEEN (1u << 8) /* buffer was processed by fs-verity */ /* buffer type flags for write callbacks */ #define _XBF_INODES (1u << 16)/* inode buffer */ @@ -65,6 +66,7 @@ typedef unsigned int xfs_buf_flags_t; { XBF_DONE, "DONE" }, \ { XBF_STALE, "STALE" }, \ { XBF_WRITE_FAIL, "WRITE_FAIL" }, \ + { XBF_VERITY_SEEN, "VERITY_SEEN" }, \ { _XBF_INODES, "INODES" }, \ { _XBF_DQUOTS, "DQUOTS" }, \ { _XBF_LOGRECOVERY, "LOG_RECOVERY" }, \ From patchwork Mon Feb 12 16:58:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Albershteyn X-Patchwork-Id: 13553747 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3934E3F9D5 for ; Mon, 12 Feb 2024 17:00:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757213; cv=none; b=IkNbrpXOXg7JXcVuR51wMW7K/Y7KbI0V72y83pdwyohEWEaKEN3/v8ubW6baGY8TKPVg7gjc/doB6bL9H/x4qeFJCXTFdxKvZdXXo1jfolyVXGwx4FrsIOQOetAlXDNnlURRbBef2oV+xZabRtVLXkZhTnwRiGnM15gti3l/DAM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757213; c=relaxed/simple; bh=7l53g4r9uK3eL4SXXr6ZAW/3PpM1Ss0BM47wmOGH+oU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=bM/nHx/zBBoPmOKQzB8n99U9r69bz9jEhOBZlIOgYjHaBjZ7TpOEKn/BmwU/r9hM5pCvlhHFY9gy+ipuHDeRt/XgOjCGSrrWZjG2jIChKOiWoCQG5Kfn+/CaqSx9kQdEHcp8AlK6VDVXOIqHQSyp26YMtSphdcmTRLi7GoIrHPE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=DpopBjY8; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="DpopBjY8" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707757211; 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=RflzGF+DQN60/OpUvC96cyl+K5968zvCI4MfQmmPzEc=; b=DpopBjY8GBRMtgjKO3euGSOPFa3Pnxwyiogu/0tvJ86j3pw7iYYzF8SHOtzdEwCA+Kl70q VtV1t3xwJiAgGvvuWJuK3VwH7RpjXL2p104H119VbjfswEkxUNngUBH2nudkvPFb9FwzH0 3LFDIEzlKdz4jfNiJOsHSRrBmL+eTHg= Received: from mail-lj1-f199.google.com (mail-lj1-f199.google.com [209.85.208.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-387-yXGIyriuMOmyA45S9_2tyA-1; Mon, 12 Feb 2024 12:00:07 -0500 X-MC-Unique: yXGIyriuMOmyA45S9_2tyA-1 Received: by mail-lj1-f199.google.com with SMTP id 38308e7fff4ca-2d09cf0adc1so34923341fa.0 for ; Mon, 12 Feb 2024 09:00:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707757206; x=1708362006; 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=RflzGF+DQN60/OpUvC96cyl+K5968zvCI4MfQmmPzEc=; b=hh++Pd+QOxP8q03yNQNWczbpIR7m7c8lisMf4MYdzuUBoC1xJ1rna29WgorzrT6KnT buyhWdpXcRSeUj2Jto6cnmShkPK78X2oEd2xR8RnaMfx76F6hbfK8LCMpz0Dyt0kyoPH mRX5bJAxpIl/0MDGRJO54uniiOtutmSaOEOQfLGN47deKXl06P/k9WN0AUpN2d3JP0O9 Qd16sV3K5LVSZm93my0g6t4W6GMMXJX+uRhlck1qqnqztFY7cxgdKMn2fWA9/kWCBdTR lHEMasSC4iV0yTY3edAisCnLpOdZnKNzDvgl/ntPQ9Xxd51t4sOIHABQNPsU9Vp7cmob AOsQ== X-Forwarded-Encrypted: i=1; AJvYcCUCq4oXDq4wMEDDDsFOBHnjZCp0+4wJewdMP41/0eKrdfkkfTZoZKj4fT6NDls8wL3YHXwvXJpvYA98gHXULK4KycGp1RnGIXWe X-Gm-Message-State: AOJu0YxEQTlPCD37vLXHycTYUFA22N7ohRqFa2ZrHc+gj6HhtUt8B/aw Aje6D7Ep0pj8JubgzqpG5mdaPVG4P68Cdd+UZhRvaRyTLWO2BC3rq3JI2lCl9FN4hIX+yjYgaiw pltLiJO/G6T5kLcknPeHAmOWgB9r51Bsypm9dzfrXcHeEm3V33tSNLrqV X-Received: by 2002:a2e:a714:0:b0:2d0:c3f8:d3b7 with SMTP id s20-20020a2ea714000000b002d0c3f8d3b7mr4320304lje.8.1707757205883; Mon, 12 Feb 2024 09:00:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IG72MY/zWOPQ2v6XwG+yAyFluuh1CkAYjSjeHPHCrF1ln3wDLd477OAaxYVkHR1fVJIi26RWQ== X-Received: by 2002:a2e:a714:0:b0:2d0:c3f8:d3b7 with SMTP id s20-20020a2ea714000000b002d0c3f8d3b7mr4320288lje.8.1707757205588; Mon, 12 Feb 2024 09:00:05 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCUCI5xWx6JvLyWfSAJ6Q4WFI2AndwXEgkjcWOi3n7UScazaiXlJQ3F+5O3ZEeLnF3mMvZUMM0Kqk2f6Elig3wKaA0R4H3TluAWPPO6pG3SjLSFg5pBrn8aRmVycUWixqOVOv+k7yfAnsc5xBH+B9zh0oK5WbAWxOLh7Eq3i2nz9PR12zhEnwLMV2j69+GVLpDZbKGuppdns9JNzBj4DslocMxNUPuwqDyFW Received: from thinky.redhat.com ([109.183.6.197]) by smtp.gmail.com with ESMTPSA id 14-20020a0564021f4e00b0056176e95a88sm2620261edz.32.2024.02.12.09.00.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 09:00:03 -0800 (PST) From: Andrey Albershteyn To: fsverity@lists.linux.dev, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, chandan.babu@oracle.com, djwong@kernel.org, ebiggers@kernel.org Cc: Andrey Albershteyn Subject: [PATCH v4 12/25] xfs: add XFS_DA_OP_BUFFER to make xfs_attr_get() return buffer Date: Mon, 12 Feb 2024 17:58:09 +0100 Message-Id: <20240212165821.1901300-13-aalbersh@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240212165821.1901300-1-aalbersh@redhat.com> References: <20240212165821.1901300-1-aalbersh@redhat.com> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 With XBF_VERITY_SEEN flag on xfs_buf XFS can track which buffers contain verified Merkle tree blocks. However, we also need to expose the buffer to pass a reference of underlying page to fs-verity. 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. Therefore, XFS will hold a reference to xfs_buf till fs-verity is verifying xfs_buf's content. 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 f9846df41669..8e3138af4a5f 100644 --- a/fs/xfs/libxfs/xfs_attr.c +++ b/fs/xfs/libxfs/xfs_attr.c @@ -252,6 +252,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( @@ -270,7 +272,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 6374bf107242..51aa5d5df76c 100644 --- a/fs/xfs/libxfs/xfs_attr_leaf.c +++ b/fs/xfs/libxfs/xfs_attr_leaf.c @@ -2449,6 +2449,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 706baf36e175..1534f4102a47 100644 --- a/fs/xfs/libxfs/xfs_da_btree.h +++ b/fs/xfs/libxfs/xfs_da_btree.h @@ -59,6 +59,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 */ @@ -93,6 +94,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" }, \ @@ -103,7 +105,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. From patchwork Mon Feb 12 16:58:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Albershteyn X-Patchwork-Id: 13553748 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8D0BE3F9CB for ; Mon, 12 Feb 2024 17:00:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757214; cv=none; b=nZGkJ+o3HEX1aMTWzRer57Uh0upjBdTaHzVz4cRfdc0I88lHP8CEtfx8msU+wpGXsZKgWRGRfJpXB8aJNnEr9LltSlbbRrcODVPLaXLFmI94EraRlloEgH1f09B//X5NPBXvuOEEun8fQGv2PCghUqEFMtFjD/kTgIiP8i2kZuc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757214; c=relaxed/simple; bh=hmR+S5AY0nRCFeAH5bAxDWzUXlpVSiwnk6LNs/KSvyE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=M9JpxCBIX0Ys1PGQMTrzYjx15k+5y7m12dCgvEwHJ0N6CjK3m8yvqYgmMO+Pgf2xMuQ6FAPolGuwB/32Mk9jZB7CvpXBIwBY8eiJ4A2UILerBvUgGhQyPbh+QtCpobJBBv1iqsFRBQU5ZswfL4LQhjmAztm3piyQTGVvTaQOQ6o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=bKjIc+FU; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="bKjIc+FU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707757210; 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=AmNNlJPhUFaXIob1BwyjdQcuVkHPCpZ8IwBssOpb1Po=; b=bKjIc+FUmjYDxF9pdtJE5JVxzTAaIRHkHDhdDO9SmTOnRNNcTMxvXdEU6wnYYOLGTwILDk hl5+jmRtsbU1JUQPSlSvnSz0qoTHAajrfkUolR7ZELPRYB8Uau0V4wA6cbE8VHXc4LttME E3BZsTxN9bscdN0tP37JSs5QbzVnPFM= Received: from mail-lj1-f200.google.com (mail-lj1-f200.google.com [209.85.208.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-626-AwQGyUsrPI6X2l4gKCju8A-1; Mon, 12 Feb 2024 12:00:08 -0500 X-MC-Unique: AwQGyUsrPI6X2l4gKCju8A-1 Received: by mail-lj1-f200.google.com with SMTP id 38308e7fff4ca-2d0cbdb1900so31943211fa.1 for ; Mon, 12 Feb 2024 09:00:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707757207; x=1708362007; 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=AmNNlJPhUFaXIob1BwyjdQcuVkHPCpZ8IwBssOpb1Po=; b=PgRatptX1jYsoE5TyfSKioopWIQDns6EfiOi71R7akyDw7+YgSvq/TOIin71yqaTlH mX7Dd73/LYWJl+XFGl+o9AlZ3jeKlNGamNONw0G3V/xnL9ZR42kAsmAlqBXqBSK46g5b 9p5ahVUyMCdPwj3cWa2az5edaS1CAwJ40Gbl4C14a2rMGW6oBNKEqwBSGC/dLE7RgCop qMJH2qhr+k6k3+ZxyhQndrMOgKabnB6KGusha898ireF6BjWDyHRurJiqLgTGrHFuYPF /G+excO+4U4d9D4PwMSUpKFkZjoLIF0xoehE/arfNz9DlxGN+XH+gsKRDDbfK3SvUMvl wlhA== X-Forwarded-Encrypted: i=1; AJvYcCVSHB933MY/rY/yg941FGqAg9qePQANsNlWexM/5fVLhcH7Pj7Xq7dWFftRxK3JclySCEAVnW4VTxJGUt7XkWzlid4lYTO3u8ys X-Gm-Message-State: AOJu0Yy8OErXgLr4LkuQVP6LGWLdqOKZFvvXflAEkDL8N9jwbI81bGOE rqTGBeA+hrh/FvwdTV9DaWfkYs+84gqkvBCva6F8AqlFcPtNKctpsJv5qpHzFHEuSDNvfgkmfKR qWoTXK3Z0SjSsKstj1rvT38vTD4GX9E4Mk6QY/tN++4aiLx5Qqy9r7sb9 X-Received: by 2002:a05:651c:cf:b0:2d0:cf14:c190 with SMTP id 15-20020a05651c00cf00b002d0cf14c190mr4346980ljr.50.1707757207047; Mon, 12 Feb 2024 09:00:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IHyrud5wesvlVfmqztFwgue5DmNAK+DEbeWoNwqXMq50tEhnxQmKL0df6lGsY5NyQZ3shEGHw== X-Received: by 2002:a05:651c:cf:b0:2d0:cf14:c190 with SMTP id 15-20020a05651c00cf00b002d0cf14c190mr4346969ljr.50.1707757206827; Mon, 12 Feb 2024 09:00:06 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWJTI843yXTJ0emfk+epBVW2Le2UXrN5BlrF0Bou7qm6A8KahxOqRBQllpGfPzXBzdoSauxL9r6u49ZS1kbiVX9NrgbkiV5CEXwk+11AVv9RHcJQVy+m4zL/XoXw+eNTH+a9VZoNpjdQfgdrvg9ZwU+YsvEBTPGfZG1m0DDZnEv4O3CXY70pYIHx8DTC6DQG25L7O5IP5wjNRbPzB0pEw7YGYCtNqXRWlTA Received: from thinky.redhat.com ([109.183.6.197]) by smtp.gmail.com with ESMTPSA id 14-20020a0564021f4e00b0056176e95a88sm2620261edz.32.2024.02.12.09.00.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 09:00:06 -0800 (PST) From: Andrey Albershteyn To: fsverity@lists.linux.dev, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, chandan.babu@oracle.com, djwong@kernel.org, ebiggers@kernel.org Cc: Andrey Albershteyn Subject: [PATCH v4 13/25] xfs: introduce workqueue for post read IO work Date: Mon, 12 Feb 2024 17:58:10 +0100 Message-Id: <20240212165821.1901300-14-aalbersh@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240212165821.1901300-1-aalbersh@redhat.com> References: <20240212165821.1901300-1-aalbersh@redhat.com> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 As noted by Dave there are two problems with using fs-verity's workqueue in XFS: 1. High priority workqueues are used within XFS to ensure that data IO completion cannot stall processing of journal IO completions. Hence using a WQ_HIGHPRI workqueue directly in the user data IO path is a potential filesystem livelock/deadlock vector. 2. The fsverity workqueue is global - it creates a cross-filesystem contention point. This patch adds per-filesystem, per-cpu workqueue for fsverity work. Signed-off-by: Andrey Albershteyn --- fs/xfs/xfs_aops.c | 15 +++++++++++++-- fs/xfs/xfs_linux.h | 1 + fs/xfs/xfs_mount.h | 1 + fs/xfs/xfs_super.c | 9 +++++++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c index 7a6627404160..70e444c151b2 100644 --- a/fs/xfs/xfs_aops.c +++ b/fs/xfs/xfs_aops.c @@ -548,19 +548,30 @@ xfs_vm_bmap( return iomap_bmap(mapping, block, &xfs_read_iomap_ops); } +static inline struct workqueue_struct * +xfs_fsverity_wq( + struct address_space *mapping) +{ + if (fsverity_active(mapping->host)) + return XFS_I(mapping->host)->i_mount->m_postread_workqueue; + return NULL; +} + STATIC int xfs_vm_read_folio( struct file *unused, struct folio *folio) { - return iomap_read_folio(folio, &xfs_read_iomap_ops, NULL); + return iomap_read_folio(folio, &xfs_read_iomap_ops, + xfs_fsverity_wq(folio->mapping)); } STATIC void xfs_vm_readahead( struct readahead_control *rac) { - iomap_readahead(rac, &xfs_read_iomap_ops, NULL); + iomap_readahead(rac, &xfs_read_iomap_ops, + xfs_fsverity_wq(rac->mapping)); } static int diff --git a/fs/xfs/xfs_linux.h b/fs/xfs/xfs_linux.h index d7873e0360f0..9c76e025b5d8 100644 --- a/fs/xfs/xfs_linux.h +++ b/fs/xfs/xfs_linux.h @@ -64,6 +64,7 @@ typedef __u32 xfs_nlink_t; #include #include #include +#include #include #include diff --git a/fs/xfs/xfs_mount.h b/fs/xfs/xfs_mount.h index 503fe3c7edbf..f64bf75f50d6 100644 --- a/fs/xfs/xfs_mount.h +++ b/fs/xfs/xfs_mount.h @@ -109,6 +109,7 @@ typedef struct xfs_mount { struct xfs_mru_cache *m_filestream; /* per-mount filestream data */ struct workqueue_struct *m_buf_workqueue; struct workqueue_struct *m_unwritten_workqueue; + struct workqueue_struct *m_postread_workqueue; struct workqueue_struct *m_reclaim_workqueue; struct workqueue_struct *m_sync_workqueue; struct workqueue_struct *m_blockgc_wq; diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c index 5a2512d20bd0..b2b6c1f24c42 100644 --- a/fs/xfs/xfs_super.c +++ b/fs/xfs/xfs_super.c @@ -553,6 +553,12 @@ xfs_init_mount_workqueues( if (!mp->m_unwritten_workqueue) goto out_destroy_buf; + mp->m_postread_workqueue = alloc_workqueue("xfs-pread/%s", + XFS_WQFLAGS(WQ_FREEZABLE | WQ_MEM_RECLAIM), + 0, mp->m_super->s_id); + if (!mp->m_postread_workqueue) + goto out_destroy_postread; + mp->m_reclaim_workqueue = alloc_workqueue("xfs-reclaim/%s", XFS_WQFLAGS(WQ_FREEZABLE | WQ_MEM_RECLAIM), 0, mp->m_super->s_id); @@ -586,6 +592,8 @@ xfs_init_mount_workqueues( destroy_workqueue(mp->m_reclaim_workqueue); out_destroy_unwritten: destroy_workqueue(mp->m_unwritten_workqueue); +out_destroy_postread: + destroy_workqueue(mp->m_postread_workqueue); out_destroy_buf: destroy_workqueue(mp->m_buf_workqueue); out: @@ -601,6 +609,7 @@ xfs_destroy_mount_workqueues( destroy_workqueue(mp->m_inodegc_wq); destroy_workqueue(mp->m_reclaim_workqueue); destroy_workqueue(mp->m_unwritten_workqueue); + destroy_workqueue(mp->m_postread_workqueue); destroy_workqueue(mp->m_buf_workqueue); } From patchwork Mon Feb 12 16:58:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Albershteyn X-Patchwork-Id: 13553749 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E8C3B3F9DE for ; Mon, 12 Feb 2024 17:00:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757214; cv=none; b=tMR67tr1BZVjTcobAlBwJsTzjieG+Nx+EGV3bLSSz/sfq9BgFbreNsZuGxs/zdNLloW8kTHkl7kJKR9a79OjfQJHOdisLXl21H2pjTknSSXDiSqPYuWcO8MjiV2gtNQKKoNXXflclNf4HgYX5BH1chAV8u18cLmWRfeNSVCHzBI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757214; c=relaxed/simple; bh=VFVpQAY1yHQkk5bXii9EmNF0UK6uzvEHbR0wcMktVt8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rSuRiQPAayTEYO5De/9507LtvsSEs2l3LCDl984ldn36n//F2X6tn5fAWJlVplDYkyLzEFnNHav1I54F/M390zVuWK6sGiA36QbHOmSRCIfr2Adrdl0kUYyxOcpmuI2AR9rWwHSW/rc/izfEbHtrdla9GtedZgRvaIefVZ8+NyI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=cN3VfuUL; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="cN3VfuUL" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707757212; 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=tiuisFhZ01Xx+frHUN8loKfI2Y8CDrnkd+/7+0mxXSk=; b=cN3VfuUL4UEPxMFO+lDYjofCd+o2C+la+EmnlBLOEbDOAgLbBLI+iTl6hpWA7dggvTO6H1 jqjZgqIlj1UaMBgRz8D2f0XFXVNptcvkXVepKIc/ijvAVeH7kqq5PXuPp6wR0IwTxCMYNJ t+NZmWunKEmSt8bS0Gtge8r8cVhwYGk= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-30-DorpCgAcM8uxCflEmLsIWw-1; Mon, 12 Feb 2024 12:00:10 -0500 X-MC-Unique: DorpCgAcM8uxCflEmLsIWw-1 Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-55ffcfed2ffso4899348a12.0 for ; Mon, 12 Feb 2024 09:00:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707757209; x=1708362009; 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=tiuisFhZ01Xx+frHUN8loKfI2Y8CDrnkd+/7+0mxXSk=; b=sq80C7NEo0JVvBiOTlOWoBWEBq3daLXR3XT9D4Jranbn4UEmhnWhldC3TORq08odqi ekITyfF/fuWZIG+GEAupO4UlfSKlNOIiNnd/24EyzS9il0wldkHCYR9BaGJ7zyJOxOSp 8mYT5Fjj5krsTdP8d78sI4yBl4st6uCCEvURFv0pYLtzihWv5+Ib3leciAmZDE10SdtO nwaV+cfIfAshRcG0fIyghsaRgalBp4WorC5bJy1C8l01FRXn/mXYWX0DZqSgTcIuCsf3 TR6A48+pOry/IZIQrz3PkDCV46MkCb6rOvwIUXuBESMMQO3+k+N8MDy3tfrQKAw4uG87 qHlg== X-Forwarded-Encrypted: i=1; AJvYcCXwHBuxTzQ5+6HYhloxId4IMXFshMz8jTAfbl0AzdnhsXCYPja9EmMEp3DnshpkRRi56wDwj9NeWaqnXH+arZYIm0MR50MYaH1I X-Gm-Message-State: AOJu0YySgu77ePS+yESfGwKIetv+acFK0gO7VsDDAg0XzZf7dN5NfBtS hVS414S0Gh12ruDF4p8CMqjhbqOw/NDYZJVBTs9l0rvQCJS/VittMnhfi0QudcbA8HCBpm0Pghe rxluunmftHgxrpSGnqiPCPHECa3ZtgMz+KhXU+7T1y+1ESCe0U5qYjVG8 X-Received: by 2002:a05:6402:4588:b0:561:3704:329c with SMTP id ig8-20020a056402458800b005613704329cmr56794edb.8.1707757209511; Mon, 12 Feb 2024 09:00:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IEuxzAP71PoZ30mFTqexOTp5LBYKtJ1+ia4lDX9BR+UnguJoMAMEB3bfsNjY6wGbLunlbH8qA== X-Received: by 2002:a05:6402:4588:b0:561:3704:329c with SMTP id ig8-20020a056402458800b005613704329cmr56785edb.8.1707757209289; Mon, 12 Feb 2024 09:00:09 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWJ95d5sD/ABfexBLVCukFXxEVdPLi2uxPrxq7h7b6O3r5tRvyWmiChUW+KM4oxHqBFYBWUnH72E7n0u80Zs611q5Fi612VDRRm7DoOPBaTIRABRrH4jviKk85ZoQQVlLdyUwnYHmTBJk81tLGwMWnm6xqpTXCO9x3/LCRXpxTZCFUeR8RtoofFPTwbSctB5lVaw/S7oQktEVdvGbcwHFXWj8nCQ9uGt64q Received: from thinky.redhat.com ([109.183.6.197]) by smtp.gmail.com with ESMTPSA id 14-20020a0564021f4e00b0056176e95a88sm2620261edz.32.2024.02.12.09.00.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 09:00:07 -0800 (PST) From: Andrey Albershteyn To: fsverity@lists.linux.dev, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, chandan.babu@oracle.com, djwong@kernel.org, ebiggers@kernel.org Cc: Andrey Albershteyn Subject: [PATCH v4 14/25] xfs: add attribute type for fs-verity Date: Mon, 12 Feb 2024 17:58:11 +0100 Message-Id: <20240212165821.1901300-15-aalbersh@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240212165821.1901300-1-aalbersh@redhat.com> References: <20240212165821.1901300-1-aalbersh@redhat.com> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The Merkle tree blocks and descriptor are stored in the extended attributes of the inode. Add new attribute type for fs-verity metadata. Add XFS_ATTR_INTERNAL_MASK to skip parent pointer and fs-verity attributes as those are only for internal use. While we're at it add a few comments in relevant places that internally visible attributes are not suppose to be handled via interface defined in xfs_xattr.c. Signed-off-by: Andrey Albershteyn Reviewed-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_da_format.h | 10 +++++++++- fs/xfs/libxfs/xfs_log_format.h | 1 + fs/xfs/xfs_ioctl.c | 5 +++++ fs/xfs/xfs_trace.h | 3 ++- fs/xfs/xfs_xattr.c | 10 ++++++++++ 5 files changed, 27 insertions(+), 2 deletions(-) diff --git a/fs/xfs/libxfs/xfs_da_format.h b/fs/xfs/libxfs/xfs_da_format.h index 1b79c4de90bc..05b82e5b64fa 100644 --- a/fs/xfs/libxfs/xfs_da_format.h +++ b/fs/xfs/libxfs/xfs_da_format.h @@ -704,14 +704,22 @@ struct xfs_attr3_leafblock { #define XFS_ATTR_ROOT_BIT 1 /* limit access to trusted attrs */ #define XFS_ATTR_SECURE_BIT 2 /* limit access to secure attrs */ #define XFS_ATTR_PARENT_BIT 3 /* parent pointer attrs */ +#define XFS_ATTR_VERITY_BIT 4 /* verity merkle tree and descriptor */ #define XFS_ATTR_INCOMPLETE_BIT 7 /* attr in middle of create/delete */ #define XFS_ATTR_LOCAL (1u << XFS_ATTR_LOCAL_BIT) #define XFS_ATTR_ROOT (1u << XFS_ATTR_ROOT_BIT) #define XFS_ATTR_SECURE (1u << XFS_ATTR_SECURE_BIT) #define XFS_ATTR_PARENT (1u << XFS_ATTR_PARENT_BIT) +#define XFS_ATTR_VERITY (1u << XFS_ATTR_VERITY_BIT) #define XFS_ATTR_INCOMPLETE (1u << XFS_ATTR_INCOMPLETE_BIT) #define XFS_ATTR_NSP_ONDISK_MASK \ - (XFS_ATTR_ROOT | XFS_ATTR_SECURE | XFS_ATTR_PARENT) + (XFS_ATTR_ROOT | XFS_ATTR_SECURE | XFS_ATTR_PARENT | \ + XFS_ATTR_VERITY) + +/* + * Internal attributes not exposed to the user + */ +#define XFS_ATTR_INTERNAL_MASK (XFS_ATTR_PARENT | XFS_ATTR_VERITY) /* * Alignment for namelist and valuelist entries (since they are mixed diff --git a/fs/xfs/libxfs/xfs_log_format.h b/fs/xfs/libxfs/xfs_log_format.h index eb7406c6ea41..8bc83d9645fe 100644 --- a/fs/xfs/libxfs/xfs_log_format.h +++ b/fs/xfs/libxfs/xfs_log_format.h @@ -973,6 +973,7 @@ struct xfs_icreate_log { #define XFS_ATTRI_FILTER_MASK (XFS_ATTR_ROOT | \ XFS_ATTR_SECURE | \ XFS_ATTR_PARENT | \ + XFS_ATTR_VERITY | \ XFS_ATTR_INCOMPLETE) /* diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c index f02b6e558af5..048d83acda0a 100644 --- a/fs/xfs/xfs_ioctl.c +++ b/fs/xfs/xfs_ioctl.c @@ -352,6 +352,11 @@ static unsigned int xfs_attr_filter( u32 ioc_flags) { + /* + * Only externally visible attributes should be specified here. + * Internally used attributes (such as parent pointers or fs-verity) + * should not be exposed to userspace. + */ if (ioc_flags & XFS_IOC_ATTR_ROOT) return XFS_ATTR_ROOT; if (ioc_flags & XFS_IOC_ATTR_SECURE) diff --git a/fs/xfs/xfs_trace.h b/fs/xfs/xfs_trace.h index 07e8a69f8e56..0dd78a43c1f1 100644 --- a/fs/xfs/xfs_trace.h +++ b/fs/xfs/xfs_trace.h @@ -84,7 +84,8 @@ struct xfs_perag; { XFS_ATTR_ROOT, "ROOT" }, \ { XFS_ATTR_SECURE, "SECURE" }, \ { XFS_ATTR_INCOMPLETE, "INCOMPLETE" }, \ - { XFS_ATTR_PARENT, "PARENT" } + { XFS_ATTR_PARENT, "PARENT" }, \ + { XFS_ATTR_VERITY, "VERITY" } DECLARE_EVENT_CLASS(xfs_attr_list_class, TP_PROTO(struct xfs_attr_list_context *ctx), diff --git a/fs/xfs/xfs_xattr.c b/fs/xfs/xfs_xattr.c index 364104e1b38a..e4c88dde4e44 100644 --- a/fs/xfs/xfs_xattr.c +++ b/fs/xfs/xfs_xattr.c @@ -20,6 +20,13 @@ #include +/* + * This file defines interface to work with externally visible extended + * attributes, such as those in user, system or security namespaces. This + * interface should not be used for internally used attributes (consider + * xfs_attr.c). + */ + /* * Get permission to use log-assisted atomic exchange of file extents. * @@ -244,6 +251,9 @@ xfs_xattr_put_listent( ASSERT(context->count >= 0); + if (flags & XFS_ATTR_INTERNAL_MASK) + return; + if (flags & XFS_ATTR_ROOT) { #ifdef CONFIG_XFS_POSIX_ACL if (namelen == SGI_ACL_FILE_SIZE && From patchwork Mon Feb 12 16:58:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Albershteyn X-Patchwork-Id: 13553751 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D907F3FB04 for ; Mon, 12 Feb 2024 17:00:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757219; cv=none; b=d2YrLD13h0K3IFxGKdWhmlfoU5NowCbFfzMtPRfSTD2g9oDH2D8yrWC8xRnaSB4KFwKW9Khp0KYKVcWJU4hZNho5B+jjxVlMPXlPibvHzZewwdmKlwUdBMprp8YvSQxJ1BsV8DSbu8VQQAJHI1qCQkFtsGPnSo9gYesdMRXFtCc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757219; c=relaxed/simple; bh=1ibjZZPlzIICrNjR9KHrVV/6aFSEbEoifUAOegz0qp0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=syN0W3SFw0X98P3B3mgNAV2HS8Yn+LdRY1da8OAOjVQ39dUwj4JcYhNYibRB4a/5EK5u1l+7xUpqPF78UJOlDleltT9djU/P/Fl9DUfOP/nKE1BJosvUpNUxUOFHuWYKf21PTJU3bJ5A5K6w4arURP3Oojco0RuAXYJi560xf6I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=ihyqcnu1; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ihyqcnu1" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707757217; 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=QJ4tEZc1B7qqsV4bfz01n/jViHsnzIbXDrJkDK06xlg=; b=ihyqcnu1Mf5020MZzyTVQgBKss6jQC/Oy+jvrGbezKKLtqHRSLIHjrJ/3Tozp2C41Aqtq9 1urnpgFiIQ9EjO00PmwZ3FtnEpvXtEOUvoFMRWzATScDOzIsQzf6oUcKONzp4hAHAQWz/3 dCSWwoNnkleZdVQWfWmUgK9ONojx2zI= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-330-NqtnWgf6NOeugi5D9jZ3mw-1; Mon, 12 Feb 2024 12:00:14 -0500 X-MC-Unique: NqtnWgf6NOeugi5D9jZ3mw-1 Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-55fe7a5330aso1895163a12.3 for ; Mon, 12 Feb 2024 09:00:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707757212; x=1708362012; 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=QJ4tEZc1B7qqsV4bfz01n/jViHsnzIbXDrJkDK06xlg=; b=lSlaMIwKQcAi4Ytg+NmtJnZyiogHkoh467sTK52789wlBrtZu/Kg82FXGWnKKRuAIq j0zMl/wyEkKCHFqD645rQ4gRIbb3iKc/XBcf8FaoOFspSCwW1lwYqlV8CNEkj8NiciH9 AhyVd6TDbY+iNEzXnfycNPJjpVU0QYO0TKMVjfAsancxYfnqjFmWCS3PWFUs65wK86qi aQ1yQJGnMaevPV6v05dYycfgSZcLQRIpSyNB8elv4CS4Am98aIQcmKGunKnUygUJqbUl PRxWZAdEC9vyO+09TOpyi0Kt3ajGcsEgqSXG4Mdf4N5azn3V+HQMz04/gkP0YE/0f2XU /CJA== X-Forwarded-Encrypted: i=1; AJvYcCVhFxm8S85ohwODO/wWR4KtRAFjYstZsDxvsN6LUfdI4nCbqkY0CSpGirkGmEBaacmSK3qCSwYAlovuv0Y1jq6+t2CCisFBGx/h X-Gm-Message-State: AOJu0Yx/8HwD5Jb8dKeK57nggI/6cV3O/gECTTkGBJGnY1IhLsiBbt6N Y8Zj1OoEH0BGGZ4Y2Lg4XelPTlT2h1vaIWC/Am7V7fnngM3gwrcpP/lfu6bbcGXR9cJtxHmNdZM L2xPHITdv2itfbJCltZ8lmWSH5TMwoRURFbiDlSdvC+JZ2vb5MySI8H2L X-Received: by 2002:aa7:d5c2:0:b0:560:cae:53f7 with SMTP id d2-20020aa7d5c2000000b005600cae53f7mr5267843eds.35.1707757212254; Mon, 12 Feb 2024 09:00:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IFtHWiUhFcZMOEIL20WFxm6YxAN9efCZM6AXt/SbYB3/Uod4FAFOPMud3uNt5aY1GfxgzC8Ng== X-Received: by 2002:aa7:d5c2:0:b0:560:cae:53f7 with SMTP id d2-20020aa7d5c2000000b005600cae53f7mr5267750eds.35.1707757210095; Mon, 12 Feb 2024 09:00:10 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWZwL63Q7TybuygEI8oPrsklBEsbINljyc7dI1P9zh0zKm43UvLoPSz6Voa45VYmbbg9YyikPKZfW1nu3FIqydRr0jb/4S0VGz0iq3/zOCRgrbmzCCg2NY6dWVJja1Nq09J5b1kg2Awn8IKxk7CIOK6rX+0feKGuxDpmCrjQuywbkD11kx4rVgurB6kBl5DVX1uIVvXSwajZcJHbIum+00H8Vm9jiAh1Uoj Received: from thinky.redhat.com ([109.183.6.197]) by smtp.gmail.com with ESMTPSA id 14-20020a0564021f4e00b0056176e95a88sm2620261edz.32.2024.02.12.09.00.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 09:00:09 -0800 (PST) From: Andrey Albershteyn To: fsverity@lists.linux.dev, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, chandan.babu@oracle.com, djwong@kernel.org, ebiggers@kernel.org Cc: Andrey Albershteyn Subject: [PATCH v4 15/25] xfs: make xfs_buf_get() to take XBF_* flags Date: Mon, 12 Feb 2024 17:58:12 +0100 Message-Id: <20240212165821.1901300-16-aalbersh@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240212165821.1901300-1-aalbersh@redhat.com> References: <20240212165821.1901300-1-aalbersh@redhat.com> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Allow passing XBF_* buffer flags from xfs_buf_get(). This will allow fs-verity to specify flag for increased buffer size. Signed-off-by: Andrey Albershteyn --- fs/xfs/libxfs/xfs_attr_remote.c | 2 +- fs/xfs/libxfs/xfs_sb.c | 2 +- fs/xfs/xfs_buf.h | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/fs/xfs/libxfs/xfs_attr_remote.c b/fs/xfs/libxfs/xfs_attr_remote.c index 72908e0e1c86..5762135dc2a6 100644 --- a/fs/xfs/libxfs/xfs_attr_remote.c +++ b/fs/xfs/libxfs/xfs_attr_remote.c @@ -521,7 +521,7 @@ xfs_attr_rmtval_set_value( dblkno = XFS_FSB_TO_DADDR(mp, map.br_startblock), dblkcnt = XFS_FSB_TO_BB(mp, map.br_blockcount); - error = xfs_buf_get(mp->m_ddev_targp, dblkno, dblkcnt, &bp); + error = xfs_buf_get(mp->m_ddev_targp, dblkno, dblkcnt, 0, &bp); if (error) return error; bp->b_ops = &xfs_attr3_rmt_buf_ops; diff --git a/fs/xfs/libxfs/xfs_sb.c b/fs/xfs/libxfs/xfs_sb.c index 5bb6e2bd6dee..f08108c9a297 100644 --- a/fs/xfs/libxfs/xfs_sb.c +++ b/fs/xfs/libxfs/xfs_sb.c @@ -1100,7 +1100,7 @@ xfs_update_secondary_sbs( error = xfs_buf_get(mp->m_ddev_targp, XFS_AG_DADDR(mp, pag->pag_agno, XFS_SB_DADDR), - XFS_FSS_TO_BB(mp, 1), &bp); + XFS_FSS_TO_BB(mp, 1), 0, &bp); /* * If we get an error reading or writing alternate superblocks, * continue. xfs_repair chooses the "best" superblock based diff --git a/fs/xfs/xfs_buf.h b/fs/xfs/xfs_buf.h index 8f418f726592..80566ee444f8 100644 --- a/fs/xfs/xfs_buf.h +++ b/fs/xfs/xfs_buf.h @@ -245,11 +245,12 @@ xfs_buf_get( struct xfs_buftarg *target, xfs_daddr_t blkno, size_t numblks, + xfs_buf_flags_t flags, struct xfs_buf **bpp) { DEFINE_SINGLE_BUF_MAP(map, blkno, numblks); - return xfs_buf_get_map(target, &map, 1, 0, bpp); + return xfs_buf_get_map(target, &map, 1, flags, bpp); } static inline int From patchwork Mon Feb 12 16:58:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Albershteyn X-Patchwork-Id: 13553750 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 33D053D998 for ; Mon, 12 Feb 2024 17:00:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757218; cv=none; b=h2FkCRnywSEAGt0vXoAzEE+gqaSCgcKw6Q7enP/bSMVhF2NUuyysHXv0QTVhEfXZzhb2hUMXuSe4HbaeMa6wrJHS+6o6CMypcjLC0Y2UUN4G3VVTHfcPPKrJP4ghnGBSfMbleho8QeoCaLMQBbMXfkD7kiJAyUn6nuZNzEbSFyM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757218; c=relaxed/simple; bh=wNIW/W+YCPZOMVmYt21a2Fgepob4iaeWS1zUwwO+tX4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tqHN3Z1x30JOKePELSp+appDffSloaTgPjO86FIMsmbtTUpnesVwNe0EOTuw2XMdbgt4lVFpFgqEkMGnqbBlLtPin1kH69Q/O9xjWvlIDS1cZ0nOLnD/8Ihz+1u+9VD7drgVHvlUFL1QqgUaWCuLD/wYIqa9AoSi5uB3VHEwwNw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=M/R/ehJK; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="M/R/ehJK" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707757216; 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=HjNaCcVPbGjsbiOXI+W7wF6VbX0l3c5qvi60YHzKwuo=; b=M/R/ehJK8nxtReQD9bRw5NRJ4PcNYgu9YEUk3ge6TVdiS809Chh7vbWdDmRaMVlr4qUXj2 SBTCBVXj7vUbVsPue8+sk51Fx2n8X3Oqe+b1A9DbTa2NsXbR3mYIuY3UIXwIL8i4wMWVjN +xiAbyH09mMWQZWu+vSyaxbpqabCXws= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-44-mqALMtT2MaySJBEzkr1ZdQ-1; Mon, 12 Feb 2024 12:00:14 -0500 X-MC-Unique: mqALMtT2MaySJBEzkr1ZdQ-1 Received: by mail-ed1-f71.google.com with SMTP id 4fb4d7f45d1cf-5605a2937d4so2492550a12.1 for ; Mon, 12 Feb 2024 09:00:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707757213; x=1708362013; 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=HjNaCcVPbGjsbiOXI+W7wF6VbX0l3c5qvi60YHzKwuo=; b=giyIRCFpZ8TeGqfZ0uwFx9uguaob9jweJg9gux0aEtrdmGGVCs1oWebnFLR7eijvxY UIBIgjHJwvF3gwa4rDw8So6yKO9Zy+JR/57+WnNAnZlJy08RfG8BmjXb+fKTSCgx38Sp gsNoUQbcR+2Ql7IKRPxL7Hdt7pWStoOwif0tN7OhX44wjzfsnAelIynn7slHAcaMjA8S Bpr55m/xG9fCKPgXvv2Q2skoqZ4/NwB/LdBS/8io3qoEl36dMpWegJwEt8KVM8FQdmA6 1pZrYsVNKmXBjD3/eTq5A6fNzVgCJLHPJBTEDLcWcuGlDNkIebhpFDGXuH5HOFkEkJXC itZg== X-Gm-Message-State: AOJu0YyW2dflGf3a6RVpW3ykLkDyQGopjoVE2UAqpWCLUV03LihyQIXx Kfl6hd5skVAavHg3pKv2pKV9/U+hHlC6yJoF82IKHjVFstlhHSvRhEWGAE6Q6xFs2qe8i6FktRX OHyH4gFh31Q8rJbNFsyolccoO3RTBjYT/yZxGIYrx4j/YJBOepZnkUicA X-Received: by 2002:a05:6402:340f:b0:560:c70f:9a0a with SMTP id k15-20020a056402340f00b00560c70f9a0amr5749017edc.1.1707757213607; Mon, 12 Feb 2024 09:00:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IGaVyoDnUYHyjbhnfm0ylTX+NNCK45Hn8iWWe9/m395Kzs+0F05MXh/leILB7t1EK6GC5zbnw== X-Received: by 2002:a05:6402:340f:b0:560:c70f:9a0a with SMTP id k15-20020a056402340f00b00560c70f9a0amr5748998edc.1.1707757213387; Mon, 12 Feb 2024 09:00:13 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVD8cj7TfTbKAJSOPfBbwNerkXbl4qtSTAJv587exJ1YNV30AX02UMtG7ezAhc0pcs6K0RJBtgByE/mknC7NxOtxFgDDxrlHdwvGmnwdtFpmutdySih3hgtJgKqHfd29qFzB3ut117WfLVCqLzImoBR+sXvwPO35RCReUKQfwL+nIsWpvz2UyFPLgBQ1A6Qz3nHw6tL3Hqqg9AN2rjL3RVO942AtvHYHzGP Received: from thinky.redhat.com ([109.183.6.197]) by smtp.gmail.com with ESMTPSA id 14-20020a0564021f4e00b0056176e95a88sm2620261edz.32.2024.02.12.09.00.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 09:00:12 -0800 (PST) From: Andrey Albershteyn To: fsverity@lists.linux.dev, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, chandan.babu@oracle.com, djwong@kernel.org, ebiggers@kernel.org Cc: Andrey Albershteyn Subject: [PATCH v4 16/25] xfs: add XBF_DOUBLE_ALLOC to increase size of the buffer Date: Mon, 12 Feb 2024 17:58:13 +0100 Message-Id: <20240212165821.1901300-17-aalbersh@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240212165821.1901300-1-aalbersh@redhat.com> References: <20240212165821.1901300-1-aalbersh@redhat.com> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 For fs-verity integration, XFS needs to supply kaddr'es of Merkle tree blocks to fs-verity core and track which blocks are already verified. One way to track verified status is to set xfs_buf flag (previously added XBF_VERITY_SEEN). When xfs_buf is evicted from memory we loose verified status. Otherwise, fs-verity hits the xfs_buf which is still in cache and contains already verified blocks. However, the leaf blocks which are read to the xfs_buf contains leaf headers. xfs_attr_get() allocates new pages and copies out the data without header. Those newly allocated pages with extended attribute data are not attached to the buffer anymore. Add new XBF_DOUBLE_ALLOC which makes xfs_buf allocates x2 memory for the buffer. Additional memory will be used for a copy of the attribute data but without any headers. Also, make xfs_attr_rmtval_get() to copy data to the buffer itself if XFS asked for fs-verity block. Signed-off-by: Andrey Albershteyn --- fs/xfs/libxfs/xfs_attr_remote.c | 26 ++++++++++++++++++++++++-- fs/xfs/xfs_buf.c | 6 +++++- fs/xfs/xfs_buf.h | 2 ++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/fs/xfs/libxfs/xfs_attr_remote.c b/fs/xfs/libxfs/xfs_attr_remote.c index 5762135dc2a6..1d32041412cc 100644 --- a/fs/xfs/libxfs/xfs_attr_remote.c +++ b/fs/xfs/libxfs/xfs_attr_remote.c @@ -392,12 +392,22 @@ xfs_attr_rmtval_get( int blkcnt = args->rmtblkcnt; int i; int offset = 0; + int flags = 0; + void *addr; trace_xfs_attr_rmtval_get(args); ASSERT(args->valuelen != 0); ASSERT(args->rmtvaluelen == args->valuelen); + /* + * We also check for _OP_BUFFER as we want to trigger on + * verity blocks only, not on verity_descriptor + */ + if (args->attr_filter & XFS_ATTR_VERITY && + args->op_flags & XFS_DA_OP_BUFFER) + flags = XBF_DOUBLE_ALLOC; + valuelen = args->rmtvaluelen; while (valuelen > 0) { nmap = ATTR_RMTVALUE_MAPSIZE; @@ -417,10 +427,21 @@ xfs_attr_rmtval_get( dblkno = XFS_FSB_TO_DADDR(mp, map[i].br_startblock); dblkcnt = XFS_FSB_TO_BB(mp, map[i].br_blockcount); error = xfs_buf_read(mp->m_ddev_targp, dblkno, dblkcnt, - 0, &bp, &xfs_attr3_rmt_buf_ops); + flags, &bp, &xfs_attr3_rmt_buf_ops); if (error) return error; + /* + * For fs-verity we allocated more space. That space is + * filled with the same xattr data but without leaf + * headers. Point args->value to that data + */ + if (flags & XBF_DOUBLE_ALLOC) { + addr = xfs_buf_offset(bp, BBTOB(bp->b_length)); + args->value = addr; + dst = addr; + } + error = xfs_attr_rmtval_copyout(mp, bp, args->dp->i_ino, &offset, &valuelen, &dst); @@ -521,7 +542,8 @@ xfs_attr_rmtval_set_value( dblkno = XFS_FSB_TO_DADDR(mp, map.br_startblock), dblkcnt = XFS_FSB_TO_BB(mp, map.br_blockcount); - error = xfs_buf_get(mp->m_ddev_targp, dblkno, dblkcnt, 0, &bp); + error = xfs_buf_get(mp->m_ddev_targp, dblkno, dblkcnt, + XBF_DOUBLE_ALLOC, &bp); if (error) return error; bp->b_ops = &xfs_attr3_rmt_buf_ops; diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c index 8e5bd50d29fe..2645e64f2439 100644 --- a/fs/xfs/xfs_buf.c +++ b/fs/xfs/xfs_buf.c @@ -328,6 +328,9 @@ xfs_buf_alloc_kmem( xfs_km_flags_t kmflag_mask = KM_NOFS; size_t size = BBTOB(bp->b_length); + if (flags & XBF_DOUBLE_ALLOC) + size *= 2; + /* Assure zeroed buffer for non-read cases. */ if (!(flags & XBF_READ)) kmflag_mask |= KM_ZERO; @@ -358,6 +361,7 @@ xfs_buf_alloc_pages( { gfp_t gfp_mask = __GFP_NOWARN; long filled = 0; + int mul = (bp->b_flags & XBF_DOUBLE_ALLOC) ? 2 : 1; if (flags & XBF_READ_AHEAD) gfp_mask |= __GFP_NORETRY; @@ -365,7 +369,7 @@ xfs_buf_alloc_pages( gfp_mask |= GFP_NOFS; /* Make sure that we have a page list */ - bp->b_page_count = DIV_ROUND_UP(BBTOB(bp->b_length), PAGE_SIZE); + bp->b_page_count = DIV_ROUND_UP(BBTOB(bp->b_length*mul), PAGE_SIZE); if (bp->b_page_count <= XB_PAGES) { bp->b_pages = bp->b_page_array; } else { diff --git a/fs/xfs/xfs_buf.h b/fs/xfs/xfs_buf.h index 80566ee444f8..8ca8760c401e 100644 --- a/fs/xfs/xfs_buf.h +++ b/fs/xfs/xfs_buf.h @@ -33,6 +33,7 @@ struct xfs_buf; #define XBF_STALE (1u << 6) /* buffer has been staled, do not find it */ #define XBF_WRITE_FAIL (1u << 7) /* async writes have failed on this buffer */ #define XBF_VERITY_SEEN (1u << 8) /* buffer was processed by fs-verity */ +#define XBF_DOUBLE_ALLOC (1u << 9) /* double allocated space */ /* buffer type flags for write callbacks */ #define _XBF_INODES (1u << 16)/* inode buffer */ @@ -67,6 +68,7 @@ typedef unsigned int xfs_buf_flags_t; { XBF_STALE, "STALE" }, \ { XBF_WRITE_FAIL, "WRITE_FAIL" }, \ { XBF_VERITY_SEEN, "VERITY_SEEN" }, \ + { XBF_DOUBLE_ALLOC, "DOUBLE_ALLOC" }, \ { _XBF_INODES, "INODES" }, \ { _XBF_DQUOTS, "DQUOTS" }, \ { _XBF_LOGRECOVERY, "LOG_RECOVERY" }, \ From patchwork Mon Feb 12 16:58:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Albershteyn X-Patchwork-Id: 13553752 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4F34E3F9D8 for ; Mon, 12 Feb 2024 17:00:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757220; cv=none; b=NrW8J5xsCp9Cd4U1Czdd++0siBHXjfdQNC32RPeNKDT5xsmRGSSpXkVZ4XXME8DyYgzoY/yhLUnfiAgddzrnXGlKUDR/B5UT6n4GJ9o5Rir52gJ23c2WLg6LjFuhjO+Ho+U3zlDgMDkikSJLQNkBH+aDHqvc7wP8kYGhr2p8aXA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757220; c=relaxed/simple; bh=pVmlSRKI77dHrm8r3OHykDJVeVPxd3lIODzreg53UVg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=oyeEAUyF2IY6ld0Tv3gvYQBnyLewpwxmn8pkyoJxHBAHK0wiN0fFV4GN3Pk5VhP5tKqMq/wQXYNR2deux/PHDWEJAVrTY1zBCEcpxkSSJZhQj5Y3mNDSlwu1WbL6HoUTcGKhpjHCthPfftALAi2v38DNjMDlbL0UKsm86ejT+wE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=ZRGOlrf/; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ZRGOlrf/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707757217; 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=fphYrB6sUkyfpqUcwfmVchz36DNELZ1YDE/WUi+9F/o=; b=ZRGOlrf/I679Ns/kvv1wwtq3L1Ibm/jN8q15BlcQvbTRXa8GdxL0wL8kweF0DLOc9x4kqK Y52DzI+VlNIH5jbezzLVZcSwvqhcfqAm78YHynWPvXmHt6DE+GThxq2qKkZQ6ePlTOeHZ4 6L2opcJC7rJ0XtljrzKoPrLYyPkG8uo= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-355-_gnBnqBIPxeOvcqZZCAQ3Q-1; Mon, 12 Feb 2024 12:00:15 -0500 X-MC-Unique: _gnBnqBIPxeOvcqZZCAQ3Q-1 Received: by mail-ed1-f70.google.com with SMTP id 4fb4d7f45d1cf-56001d4c9c8so2107775a12.0 for ; Mon, 12 Feb 2024 09:00:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707757214; x=1708362014; 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=fphYrB6sUkyfpqUcwfmVchz36DNELZ1YDE/WUi+9F/o=; b=UdqbONM91/FrwPb3UvW6rHnB4y6JPiR0lbhjbwSnLxpbOrSdzZMLAJ4acuAZhOR2wZ eqP6CWcD7QS5ox7JJp/9VEtDPK62vUGqA/jhsfUjq6p+9r2Req1NutwJGmUaC3vEr8sX Fh8CE/FYC6MFFp9Mo/1RHwjpILUnjTtP53vsMWAiHB0UTJGKbk1/M0r0AfsZxxY/L4CN 8k04gf/F87/3A/5rGtkWU1ehco2fY7LnXMZbSjrsfyQVYzr9TuYaBCJs9tC6YvHQiT1N KSnMyuSFH+1Aj1SiASLQS/howHnQTCjWOiJjHAPmqi1+8iwdGi4TGAVwdDoilw2HLBAp dpNA== X-Gm-Message-State: AOJu0YxpKVHdjAuEFMCB7ENhF0J6w6qc2lX+yy/Dwgzo1kucuBrTBBbN 4y+QUp7qEKBQBEvgDAwS/P2uqDom3KQ0WmGc5Rk8Px0/eo6gQWG8dx2iDzs7kZJWAPKXqa8AneO IdlbtQ3FOfZQvWwAy9O4Qi0GceESWmBMoSDLH/Z6vKJE6LvdWWW0QGmFw X-Received: by 2002:a05:6402:3182:b0:561:9653:339b with SMTP id di2-20020a056402318200b005619653339bmr3101059edb.6.1707757214748; Mon, 12 Feb 2024 09:00:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IGwXyTc1WDID6ZK3dghl3ZVDvmLmjzfMuJagmfzU9Q45OSVgWpX4Xn14kp782bIiAYg+O5YzQ== X-Received: by 2002:a05:6402:3182:b0:561:9653:339b with SMTP id di2-20020a056402318200b005619653339bmr3101050edb.6.1707757214474; Mon, 12 Feb 2024 09:00:14 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWr/msPaoxmdV6je+9fjRcJyx0FORnDgMNTVsrKDBO77lk7qytfj7mACy32Wl5c1ILnbEJUGH70jkuuGtrgPTPFmH97wlyoLBwoUYry2j/rOtyJJkiPAHDWtAdQHX3SGTTZjk4fe0n+nH0SNee1OfRhzqnoBPcVAKkUUtlvn1LThhagniTPFQUxltPDo73CsbJsqbvP59ndRbiCO3y/FNlMUtbBk5L2Blyq Received: from thinky.redhat.com ([109.183.6.197]) by smtp.gmail.com with ESMTPSA id 14-20020a0564021f4e00b0056176e95a88sm2620261edz.32.2024.02.12.09.00.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 09:00:13 -0800 (PST) From: Andrey Albershteyn To: fsverity@lists.linux.dev, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, chandan.babu@oracle.com, djwong@kernel.org, ebiggers@kernel.org Cc: Andrey Albershteyn Subject: [PATCH v4 17/25] xfs: add fs-verity ro-compat flag Date: Mon, 12 Feb 2024 17:58:14 +0100 Message-Id: <20240212165821.1901300-18-aalbersh@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240212165821.1901300-1-aalbersh@redhat.com> References: <20240212165821.1901300-1-aalbersh@redhat.com> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To mark inodes with fs-verity enabled the new XFS_DIFLAG2_VERITY flag will be added in further patch. This requires ro-compat flag to let older kernels know that fs with fs-verity can not be modified. Signed-off-by: Andrey Albershteyn Reviewed-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_format.h | 1 + fs/xfs/libxfs/xfs_sb.c | 2 ++ fs/xfs/xfs_mount.h | 2 ++ 3 files changed, 5 insertions(+) diff --git a/fs/xfs/libxfs/xfs_format.h b/fs/xfs/libxfs/xfs_format.h index 382ab1e71c0b..e36718c93539 100644 --- a/fs/xfs/libxfs/xfs_format.h +++ b/fs/xfs/libxfs/xfs_format.h @@ -353,6 +353,7 @@ xfs_sb_has_compat_feature( #define XFS_SB_FEAT_RO_COMPAT_RMAPBT (1 << 1) /* reverse map btree */ #define XFS_SB_FEAT_RO_COMPAT_REFLINK (1 << 2) /* reflinked files */ #define XFS_SB_FEAT_RO_COMPAT_INOBTCNT (1 << 3) /* inobt block counts */ +#define XFS_SB_FEAT_RO_COMPAT_VERITY (1 << 4) /* fs-verity */ #define XFS_SB_FEAT_RO_COMPAT_ALL \ (XFS_SB_FEAT_RO_COMPAT_FINOBT | \ XFS_SB_FEAT_RO_COMPAT_RMAPBT | \ diff --git a/fs/xfs/libxfs/xfs_sb.c b/fs/xfs/libxfs/xfs_sb.c index f08108c9a297..dcb6b15714b1 100644 --- a/fs/xfs/libxfs/xfs_sb.c +++ b/fs/xfs/libxfs/xfs_sb.c @@ -163,6 +163,8 @@ xfs_sb_version_to_features( features |= XFS_FEAT_REFLINK; if (sbp->sb_features_ro_compat & XFS_SB_FEAT_RO_COMPAT_INOBTCNT) features |= XFS_FEAT_INOBTCNT; + if (sbp->sb_features_ro_compat & XFS_SB_FEAT_RO_COMPAT_VERITY) + features |= XFS_FEAT_VERITY; if (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_FTYPE) features |= XFS_FEAT_FTYPE; if (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_SPINODES) diff --git a/fs/xfs/xfs_mount.h b/fs/xfs/xfs_mount.h index f64bf75f50d6..5de007989b71 100644 --- a/fs/xfs/xfs_mount.h +++ b/fs/xfs/xfs_mount.h @@ -290,6 +290,7 @@ typedef struct xfs_mount { #define XFS_FEAT_BIGTIME (1ULL << 24) /* large timestamps */ #define XFS_FEAT_NEEDSREPAIR (1ULL << 25) /* needs xfs_repair */ #define XFS_FEAT_NREXT64 (1ULL << 26) /* large extent counters */ +#define XFS_FEAT_VERITY (1ULL << 27) /* fs-verity */ /* Mount features */ #define XFS_FEAT_NOATTR2 (1ULL << 48) /* disable attr2 creation */ @@ -353,6 +354,7 @@ __XFS_HAS_FEAT(inobtcounts, INOBTCNT) __XFS_HAS_FEAT(bigtime, BIGTIME) __XFS_HAS_FEAT(needsrepair, NEEDSREPAIR) __XFS_HAS_FEAT(large_extent_counts, NREXT64) +__XFS_HAS_FEAT(verity, VERITY) /* * Mount features From patchwork Mon Feb 12 16:58:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Albershteyn X-Patchwork-Id: 13553754 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2A4423FB38 for ; Mon, 12 Feb 2024 17:00:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757223; cv=none; b=Di2uvEih7CjXauE1YVXE/JRvjrR+DBeBAdu9qjPGqrJlzz++VsehvLFxks0041YjMFBG583wfDW8Lb0oX+bsFB33lMGcfejbh2gvqH+WUp/ljrsjZ9yJcLpa6tdX0CFmdgJEyS8651JAgHVtSFRGaewc7trY7cmxWLHIBRsSBFg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757223; c=relaxed/simple; bh=5efDprULe6taPXbMIbssh9R9ZTvpV1+LRg5VBOs1ncI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pohK08IAHYIJkn2DqSfiKGebpp3dTyrBOOkYZN9CjumAcJii/+yyIM/8ppTUeRz7Gf4GCMR0yZRxGlka6343eHOZ+Np0ND38evRLMvPygJR7S1qlpN1Ov1mcxX/uVz4nTr8TDeFrwH/x0C0+ShSPHf/aOZjJ80oYNMw1JdSNK7k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Ysb3ajjK; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Ysb3ajjK" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707757220; 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=JU0n6o39Qx9ylv78PJjsl41s62AUUJ55j4stQvjouKk=; b=Ysb3ajjKo3S+Iqnowizd6q9R1/Npbvaqw/82CFyPo68yjEQ1RulhGtnzQDyBWNhR070B6V BBoY+6BkK/fWD/5qEJuqK+FIzLD7B/uFVy+6WDrajp26xNhEKEZGQVAhWczpNNZk86ypu7 WrV1dzy28BPhF1FNjhGP/xoakFsny7M= Received: from mail-lf1-f69.google.com (mail-lf1-f69.google.com [209.85.167.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-210-LgsQzD6jPuONEOOMpTgrxg-1; Mon, 12 Feb 2024 12:00:17 -0500 X-MC-Unique: LgsQzD6jPuONEOOMpTgrxg-1 Received: by mail-lf1-f69.google.com with SMTP id 2adb3069b0e04-51151b8de86so3093976e87.1 for ; Mon, 12 Feb 2024 09:00:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707757216; x=1708362016; 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=JU0n6o39Qx9ylv78PJjsl41s62AUUJ55j4stQvjouKk=; b=O/VXJFMzpUTlF+fTSTbaeO7beoqnQdLzb40vpTSUcxhqxyitqp+E6y8j4oofhU5d08 bL0O6Lx1DdsEugaJmDLvfStCYWd2SK+Nkeg3AH1czwv/d3rQ/OEQ2D1PrZ5pvs77tm3J vxnJKlIdW294yTcdkv+WLjsA+WDk8YoD2AT26iZcGMCybffi/3r2od68mTw9StIetZoU sC2On3XepihGesAFage4LuHimoaBk3jsy1xANCTfF5vhgRb5LLVXxroQUkFG1vFs8CaJ gPaS2dSR4uoRpdneeI0/T5UPdQIZdxhJlKTA32wzZLZFy7jNoy5e29yq8wH3iQR2mpKu HYDA== X-Forwarded-Encrypted: i=1; AJvYcCUxe1caXdRiPaBpaE6Ki3i5yI/YKAtOSbtRQLyMYHYnUl9cIwCpoP88td21vjwZpUF4e+MQygTn+oZUKUBnZFlU1SBV2FR5Aqz7 X-Gm-Message-State: AOJu0Yzwl3Uk85S1pgcIHf1hSJXePUMCH2k6AGTisv+czwqu8ra6+gfk eTumjCCfa8EpCV6fVlJN9hFTNwPlNIhnPIE5od2JjDeymlUa832Opyc4f6k03Wo9W/kcoy4fQbN CJjV2+IGjmEtLph1yI1KTOxuXkwdvhUiQglcwyTZuwf/ewrYSo9SaDfLk X-Received: by 2002:a2e:a586:0:b0:2d0:b758:93a5 with SMTP id m6-20020a2ea586000000b002d0b75893a5mr5900126ljp.18.1707757216126; Mon, 12 Feb 2024 09:00:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IGWfgm/7xQWafBoXVO5m9B2+ecerqMNgmsVK2YVSO0I9LtMY6feCLDnkZOBYsU2n0tsoz4y0g== X-Received: by 2002:a2e:a586:0:b0:2d0:b758:93a5 with SMTP id m6-20020a2ea586000000b002d0b75893a5mr5900112ljp.18.1707757215872; Mon, 12 Feb 2024 09:00:15 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVn/DPoAemeqvTkQ5zPfLy0hfJFjk4TKK9KhFtVG/UOJ0tl9rOXnZCBL8KZ35eC5xFC6HRbtaADDRpp9DzBfnmNOnXh/NJJ2tH4savAB+mNHahiaMS1HqsVSp99kIhOulubeOW05Q8flG8Rj8GTfbLcvB7+d6vIzEk3qyIoCg29wS/er+jC/w7fwJlPStbzeOShAmMTlvX7WCihOqzG7zVA6CevqmamhlIf Received: from thinky.redhat.com ([109.183.6.197]) by smtp.gmail.com with ESMTPSA id 14-20020a0564021f4e00b0056176e95a88sm2620261edz.32.2024.02.12.09.00.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 09:00:14 -0800 (PST) From: Andrey Albershteyn To: fsverity@lists.linux.dev, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, chandan.babu@oracle.com, djwong@kernel.org, ebiggers@kernel.org Cc: Andrey Albershteyn Subject: [PATCH v4 18/25] xfs: add inode on-disk VERITY flag Date: Mon, 12 Feb 2024 17:58:15 +0100 Message-Id: <20240212165821.1901300-19-aalbersh@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240212165821.1901300-1-aalbersh@redhat.com> References: <20240212165821.1901300-1-aalbersh@redhat.com> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add flag to mark inodes which have fs-verity enabled on them (i.e. descriptor exist and tree is built). Signed-off-by: Andrey Albershteyn --- fs/xfs/libxfs/xfs_format.h | 4 +++- fs/xfs/xfs_inode.c | 2 ++ fs/xfs/xfs_iops.c | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/fs/xfs/libxfs/xfs_format.h b/fs/xfs/libxfs/xfs_format.h index e36718c93539..ea78b595aa97 100644 --- a/fs/xfs/libxfs/xfs_format.h +++ b/fs/xfs/libxfs/xfs_format.h @@ -1086,16 +1086,18 @@ static inline void xfs_dinode_put_rdev(struct xfs_dinode *dip, xfs_dev_t rdev) #define XFS_DIFLAG2_COWEXTSIZE_BIT 2 /* copy on write extent size hint */ #define XFS_DIFLAG2_BIGTIME_BIT 3 /* big timestamps */ #define XFS_DIFLAG2_NREXT64_BIT 4 /* large extent counters */ +#define XFS_DIFLAG2_VERITY_BIT 5 /* inode sealed by fsverity */ #define XFS_DIFLAG2_DAX (1 << XFS_DIFLAG2_DAX_BIT) #define XFS_DIFLAG2_REFLINK (1 << XFS_DIFLAG2_REFLINK_BIT) #define XFS_DIFLAG2_COWEXTSIZE (1 << XFS_DIFLAG2_COWEXTSIZE_BIT) #define XFS_DIFLAG2_BIGTIME (1 << XFS_DIFLAG2_BIGTIME_BIT) #define XFS_DIFLAG2_NREXT64 (1 << XFS_DIFLAG2_NREXT64_BIT) +#define XFS_DIFLAG2_VERITY (1 << XFS_DIFLAG2_VERITY_BIT) #define XFS_DIFLAG2_ANY \ (XFS_DIFLAG2_DAX | XFS_DIFLAG2_REFLINK | XFS_DIFLAG2_COWEXTSIZE | \ - XFS_DIFLAG2_BIGTIME | XFS_DIFLAG2_NREXT64) + XFS_DIFLAG2_BIGTIME | XFS_DIFLAG2_NREXT64 | XFS_DIFLAG2_VERITY) static inline bool xfs_dinode_has_bigtime(const struct xfs_dinode *dip) { diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index 1fd94958aa97..6289a0c49780 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -629,6 +629,8 @@ xfs_ip2xflags( flags |= FS_XFLAG_DAX; if (ip->i_diflags2 & XFS_DIFLAG2_COWEXTSIZE) flags |= FS_XFLAG_COWEXTSIZE; + if (ip->i_diflags2 & XFS_DIFLAG2_VERITY) + flags |= FS_XFLAG_VERITY; } if (xfs_inode_has_attr_fork(ip)) diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c index a0d77f5f512e..8972274b8bc0 100644 --- a/fs/xfs/xfs_iops.c +++ b/fs/xfs/xfs_iops.c @@ -1242,6 +1242,8 @@ xfs_diflags_to_iflags( flags |= S_NOATIME; if (init && xfs_inode_should_enable_dax(ip)) flags |= S_DAX; + if (xflags & FS_XFLAG_VERITY) + flags |= S_VERITY; /* * S_DAX can only be set during inode initialization and is never set by From patchwork Mon Feb 12 16:58:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Albershteyn X-Patchwork-Id: 13553753 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3217A3D97F for ; Mon, 12 Feb 2024 17:00:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757222; cv=none; b=idVZXBa5GDbwQtgvv8VGDD1LwouehSd7EvILshzSnjcNOB+cfLhVehNeyDUV0T54FpPxGp5A/2eDRsX/9Hi52x86fpGE6yqBbqEsKb9w5ycGYdHYSf0Y1Szm1t+a+H7eLUEvCE83WAYVsWDeuNYnSssB4m5Q157Nw4DMmjJB5pY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757222; c=relaxed/simple; bh=uRpqcFHztW6mv8ys9x1B06hDBwaQZHF8LlWlh4KeXNk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=s7ooPe5GcOjSyQD/d4hXMdrSjW1Hmi77cZMAgbiD9Qltu1RJZBNt9oOOaNzkbuqmvbAx0i4mWSvAGjIR162ID52oJJAOGhdJInw6Ilnt0chSdEiTCE3S/NcQ+yd37fwNPBRm9ep6SjxS3U7L9PKFtT1PO11QBnW4WZAfbK/4hBs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=g102msEZ; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="g102msEZ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707757220; 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=K4IPa0qcdOfoZGhIk7o1SuO7zkizJ6265PJwpzaMwSg=; b=g102msEZB4hRAdgJUPM5KNYeyuJMPKnJCkywbU54e0GjXyDzK56OUGHfH+IsmxTPZP9d/f AA8kL0Q6B+ngOG3NMHtHnWFhEAu3eGSELDm7h0nggF6amn4UwMq1xya13MPLLY1vzxGza4 1NvXqWDIyd+Lp0MJJ87sCNofQFU7L7g= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-333-VtNtiaKeMJCx1Bm16d5vaw-1; Mon, 12 Feb 2024 12:00:18 -0500 X-MC-Unique: VtNtiaKeMJCx1Bm16d5vaw-1 Received: by mail-ed1-f71.google.com with SMTP id 4fb4d7f45d1cf-5600db7aa23so1995983a12.1 for ; Mon, 12 Feb 2024 09:00:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707757217; x=1708362017; 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=K4IPa0qcdOfoZGhIk7o1SuO7zkizJ6265PJwpzaMwSg=; b=jvpBA00ntMTHW9ny3sZJSxvN0gc+AbTYhnDM0JDgKUzfpjTKtsNtN5pHcqiTUI/ImU Ox0T38PlcHf3XyB7JtbhiMZ8Xm65zoTSWom/tmve/3Y5uqr8lAhh1R2AsEBE7rssjpe6 n5uVfjyOA7J3UQupqd5I+L8MHQgzBvx1iIsbkKJD+roa/ebo5jrvmAcsO6IrfBSIyAtb NnLbQBdtU3DaIFI0KycE1LHlIbicWl9M5s02wIf8BoSnkx+1PZkVTVPbAUVFz/rGTBTm JD+xBFG8OUrhVsKlaF5lxrC6tmpE/6fWWj2YRGmO3xlq3tFN/WvliNZkQppNtfZqzivJ gpWQ== X-Forwarded-Encrypted: i=1; AJvYcCVYDYlA5F9MzjdPUQAEY96/+55Q7ZZw+kBL6zPp1LW7KrywXSJVHcBNyN1w9+ptXjIAPCeJxtF236ueTov2AT0RojNnh6E050ki X-Gm-Message-State: AOJu0Yz337eC2gREUXEdQ9BOUMjWRRHiN4+xlKNQx9AuF/IzH7oP/5hD axud83dqd/juCA3YZ+Dji7bBZKKbpqEipdlZRJjaO23DZpF+Zhn+XwzQqjkFTauXwcAl2zEacuP Q4QayABGN1fSrOhFibQmxtmSFLOK1+GvBlizwX2L7lQzdJYlLyBcmV892 X-Received: by 2002:aa7:c38d:0:b0:561:dd88:cffc with SMTP id k13-20020aa7c38d000000b00561dd88cffcmr465747edq.28.1707757217465; Mon, 12 Feb 2024 09:00:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IHksA5ai7JOoS0uklOVKI1iGk/wOmBYywj8HWtXzARiX88G09MpjFmNbBH4phxpiPQJH/VdNw== X-Received: by 2002:aa7:c38d:0:b0:561:dd88:cffc with SMTP id k13-20020aa7c38d000000b00561dd88cffcmr465738edq.28.1707757217252; Mon, 12 Feb 2024 09:00:17 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCXR1m0bOpBoqPXPgXXYaM9xtNMBrhn4WE1Pg/SJk4bnMQdTF9h8ffsK3KWu15iaJi6Z23nltfiz5dIXnKMptfo4UjJ0x/eI7CWd4H2jF97ZLwCYDKHPNU2p2YlMAanXkf+nNaNF0xypLv5AaDh61uecKausA88SdVC6PnzrvLFKxQbUkiSyZ3hdYGSeHT4kr6p3yDrqqsiA5JLSxLyJaGGrWGufxilwbyNg Received: from thinky.redhat.com ([109.183.6.197]) by smtp.gmail.com with ESMTPSA id 14-20020a0564021f4e00b0056176e95a88sm2620261edz.32.2024.02.12.09.00.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 09:00:16 -0800 (PST) From: Andrey Albershteyn To: fsverity@lists.linux.dev, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, chandan.babu@oracle.com, djwong@kernel.org, ebiggers@kernel.org Cc: Andrey Albershteyn Subject: [PATCH v4 19/25] xfs: initialize fs-verity on file open and cleanup on inode destruction Date: Mon, 12 Feb 2024 17:58:16 +0100 Message-Id: <20240212165821.1901300-20-aalbersh@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240212165821.1901300-1-aalbersh@redhat.com> References: <20240212165821.1901300-1-aalbersh@redhat.com> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 fs-verity will read and attach metadata (not the tree itself) from a disk for those inodes which already have fs-verity enabled. Signed-off-by: Andrey Albershteyn --- fs/xfs/xfs_file.c | 8 ++++++++ fs/xfs/xfs_super.c | 2 ++ 2 files changed, 10 insertions(+) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index e33e5e13b95f..ed36cd088926 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -31,6 +31,7 @@ #include #include #include +#include static const struct vm_operations_struct xfs_file_vm_ops; @@ -1228,10 +1229,17 @@ xfs_file_open( struct inode *inode, struct file *file) { + int error = 0; + if (xfs_is_shutdown(XFS_M(inode->i_sb))) return -EIO; file->f_mode |= FMODE_NOWAIT | FMODE_BUF_RASYNC | FMODE_BUF_WASYNC | FMODE_DIO_PARALLEL_WRITE | FMODE_CAN_ODIRECT; + + error = fsverity_file_open(inode, file); + if (error) + return error; + return generic_file_open(inode, file); } diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c index b2b6c1f24c42..4737101edab9 100644 --- a/fs/xfs/xfs_super.c +++ b/fs/xfs/xfs_super.c @@ -48,6 +48,7 @@ #include #include #include +#include static const struct super_operations xfs_super_operations; @@ -672,6 +673,7 @@ xfs_fs_destroy_inode( ASSERT(!rwsem_is_locked(&inode->i_rwsem)); XFS_STATS_INC(ip->i_mount, vn_rele); XFS_STATS_INC(ip->i_mount, vn_remove); + fsverity_cleanup_inode(inode); xfs_inode_mark_reclaimable(ip); } From patchwork Mon Feb 12 16:58:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Albershteyn X-Patchwork-Id: 13553755 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1AE823FB35 for ; Mon, 12 Feb 2024 17:00:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757223; cv=none; b=pkFl+zOtYfUr6jZhrTui6BtIYyapuUTzj9QSDgoB367btuimSX045GTDefBOVnXXQhxB7A1A15TuuQcXA9SV07ArbCsMLOruHZa+QP+oB5+iyfGWI69EeECf6jjUeFDTJab1HKu13kGGmOkeD3OiK4NJcqOuC2zE4o5vFTErMkY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757223; c=relaxed/simple; bh=vdHiY+5n22LurY8Opd20329Jh2sRmadcybRUqQPyIPs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=QTAd8VJivJRhVbxH1KSOKQl0Vib+nYHSLgmcUhzwMuJQGqqYgRyfUA05k2RTpDmNySW9K1LGj1//oeHHyXavs34WhjU3JqY56asgqvYBZhmOYDZAF/X3beKYOZQ8M/CC9C2fMGtE67FnTUXh7dL/5IZPB9fcSLF2QCMueEzO4vQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=VMT+PA8m; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="VMT+PA8m" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707757221; 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=dJCZCHIXGjyZyLUGP8rE/I4QvbwAG0uLO2o/5Ew8lzA=; b=VMT+PA8mgO3pCC+jtm+qf/KWNv72sVbeqOT/671+St4jmJ0Ehs9THMaT9N+rrWB+x8B5fo /mMrSoT7u3zQA3PtpnC/gHpL0JbEo+CD3zqTQJ0Eag3B+cDzo7l6Ylyb/FZO5MBgYJvcAT rqe41IkRYovUKiWIBWrGYGeVz9jvzdw= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-607-BbmM3ffFNOe73ibHgFYhzg-1; Mon, 12 Feb 2024 12:00:19 -0500 X-MC-Unique: BbmM3ffFNOe73ibHgFYhzg-1 Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-5605c7b1f34so3810515a12.1 for ; Mon, 12 Feb 2024 09:00:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707757218; x=1708362018; 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=dJCZCHIXGjyZyLUGP8rE/I4QvbwAG0uLO2o/5Ew8lzA=; b=LY+xdHFCP/i5B3l40UxEHVwv5XV/RRFQ3pCQYf1RGSy507msSnjThdZ9kpfK8G0MDx BkcWzyhnq/ey6iXmIalre5vwC7httiom0Nqb6Kf9h8bKUZiNh92yhbjZ0YBy8zxFBICQ Enh0gxXiL4fe7bRtIGEMY/1znvBMYKEgCIhHhG5Ni6j2mc8H1T4psKfCPmlegFPp5hVK hr1Z1t8UMR8zBovb1OyWJ2UfeqRGRVY/Qqgj6FLU0wMfqAczqJgfcgWescBMVm4YIHyt TnLiv77Yk7tMmfP3LV6jRZuH5kuPoNLuMMTarWJHZdOQDONVvl/foKmlipPvgxzBEKTJ IDFA== X-Gm-Message-State: AOJu0YwgtO+NifwnDmHmuhzzYM9h4KU9VVE027H0Ds4EMeod6ZC9a62r 47Z5w6yf23ZaV6Jc4h+3NBhMxSQVZRbYX1adW1h3JqrA8VfO90dIGvMnolk3c76qnzmyBUGcFbx JIrsYtnGbSPVBjS5ngaOP07utSJmSrRKD6lEibqJ7fZR7Ep9GGNpB2Af3 X-Received: by 2002:a05:6402:194b:b0:55f:d6b9:245f with SMTP id f11-20020a056402194b00b0055fd6b9245fmr81611edz.6.1707757218598; Mon, 12 Feb 2024 09:00:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IEu9oz4kqazMkidIDc3OUaR2AIuDA+GdBkSrnXsXdYN1B/OVQMbeN2XlXF0/dFPIuNCyt2esg== X-Received: by 2002:a05:6402:194b:b0:55f:d6b9:245f with SMTP id f11-20020a056402194b00b0055fd6b9245fmr81598edz.6.1707757218421; Mon, 12 Feb 2024 09:00:18 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCX8qHo9KFTFqx7ffS+BaQUSAi3Ftf56a5RyK3q9a4EYYj9+86aRggYimde3QhhRm33PiYHGgj7kNkzhhEsugmBNpWsi1icmAgylRr/h8p1RapPYuLxTDAlrSRUjc60PQto5qCyrEP3V2pzQKbUURXsWdrlcSV9NVR3+GoKHqeQKhrkIlIb0ivzRDOeqUhRshgvoZj3vznkzGwz47of+OthOjOLnc7ISms8s Received: from thinky.redhat.com ([109.183.6.197]) by smtp.gmail.com with ESMTPSA id 14-20020a0564021f4e00b0056176e95a88sm2620261edz.32.2024.02.12.09.00.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 09:00:17 -0800 (PST) From: Andrey Albershteyn To: fsverity@lists.linux.dev, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, chandan.babu@oracle.com, djwong@kernel.org, ebiggers@kernel.org Cc: Andrey Albershteyn Subject: [PATCH v4 20/25] xfs: don't allow to enable DAX on fs-verity sealsed inode Date: Mon, 12 Feb 2024 17:58:17 +0100 Message-Id: <20240212165821.1901300-21-aalbersh@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240212165821.1901300-1-aalbersh@redhat.com> References: <20240212165821.1901300-1-aalbersh@redhat.com> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 fs-verity doesn't support DAX. Forbid filesystem to enable DAX on inodes which already have fs-verity enabled. The opposite is checked when fs-verity is enabled, it won't be enabled if DAX is. Signed-off-by: Andrey Albershteyn --- fs/xfs/xfs_iops.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c index 8972274b8bc0..4cf6b317d018 100644 --- a/fs/xfs/xfs_iops.c +++ b/fs/xfs/xfs_iops.c @@ -1214,6 +1214,8 @@ xfs_inode_should_enable_dax( return false; if (!xfs_inode_supports_dax(ip)) return false; + if (ip->i_diflags2 & XFS_DIFLAG2_VERITY) + return false; if (xfs_has_dax_always(ip->i_mount)) return true; if (ip->i_diflags2 & XFS_DIFLAG2_DAX) From patchwork Mon Feb 12 16:58:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Albershteyn X-Patchwork-Id: 13553757 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B581A44C87 for ; Mon, 12 Feb 2024 17:00:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757229; cv=none; b=Be/03Pz3r6gkZZp4+5vZ1ZpOxp7MmfAwN3TOYgP4oN+GvRXGwUdTrEJ1MkWxE9mtRqCZpMQElSTPTset52hLC24f1NEmBWTa1WjWJuddylVoPEnR4I+KUmlHllXRcs38Doy456loWhkDcPiPWH08xqpJqCtm4S8nqXAePSKPJDU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757229; c=relaxed/simple; bh=L31YpI5cHGwgxPGXiju5BCSchrSCFM+W/kdnKuUSicg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Uf24vOENG0UfpBsUzQT5trH5JnPO0jh2qDtxx3zxHWg1XhjLO8mt4bI22qZwef53F8G9fOZHZk7X5jfjvyqXmTFaF5oIJ1iqfEzWWcCLRUKT4T7Au914UDS9IjKny4O4G15Ht3Kk7e56nrQ0dkjpzMTM93qOkrW5z0UuaYHdcjg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=IAaxb/WD; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="IAaxb/WD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707757226; 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=v8DMtYJWCVCHSCEWBZfbGi3INfqAeJCCNzs6AgTs1hw=; b=IAaxb/WDfSq92hkuS/U795Sm7JBGRReZT/jzoGJgyWxX0SMYjmYK4HM16IXNoFgP4Jfu9V 0gXsOpZZRPoo16E0SaTn9L3mYSh4u5TUyUbKA61uLVYB/O/i8zaVsom5yVBNc5mY80Ur58 AkZEUiCoXb7rA9efq5TFTPhYf38yNB4= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-101-MxPM6WA9NBepQeB0w95ubA-1; Mon, 12 Feb 2024 12:00:23 -0500 X-MC-Unique: MxPM6WA9NBepQeB0w95ubA-1 Received: by mail-ed1-f71.google.com with SMTP id 4fb4d7f45d1cf-561601cca8eso9944a12.3 for ; Mon, 12 Feb 2024 09:00:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707757220; x=1708362020; 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=v8DMtYJWCVCHSCEWBZfbGi3INfqAeJCCNzs6AgTs1hw=; b=CYJUrUYHV3kSEPRLiHQSdfTvqVGXVoDkTXo/7PgTf8t4JMf2O3rSG+1vpVAHpbjye4 kWieNwVTQwFU4NiEUe6MOKruKT0NIzmdPZEjJ+Dt6uJ9GpzQQ3PRXKLIRHFR2KXcEmMi SADGzrzggQP1c5dRyN0JRIixHSoaOSEifzHptktWJCEoJ57EwWfsCm9iygLsjUqKPHF0 QFbxL5rPj/6Qulwx0LftyoGc/6VlS1V7NPy8aKOftOZ9TIJCAKlDD8v3g0n/gqiKk4u6 hElpSircTkWfcovlPex3ICOOzZ0OV2lxBoukqHU+72/G9xCxsJOIxqZCBrDb4ToiDFru 2wYw== X-Gm-Message-State: AOJu0YwtY4ddIcYxLKf2/Ce235bLLEePmDm8M6jrwKaA7Fz6BrHtf1o8 j/K+2rA41X68bc7yhCOlatf1smSpKKFYl6e5KS07jIoKDK7GWiDZgV380QUBRItg9/0pFkbNHFE C2Bcxxp6HR9CKiFB8bRMVInjxvQO4X9Ubgy8OGVVoDeYjXH7rEFIKvF6Y X-Received: by 2002:aa7:c71a:0:b0:560:4e6:c442 with SMTP id i26-20020aa7c71a000000b0056004e6c442mr4968905edq.1.1707757219861; Mon, 12 Feb 2024 09:00:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IHdqLzEkltOhv90/mdAnBYzqC7IUdmnma0K+szge3JGNVz0tYyEgI2sp8chHtI9P5lmUmCjVA== X-Received: by 2002:aa7:c71a:0:b0:560:4e6:c442 with SMTP id i26-20020aa7c71a000000b0056004e6c442mr4968893edq.1.1707757219573; Mon, 12 Feb 2024 09:00:19 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCV3N3pdtpy2jDzzn9qjG81jBQ/X5sQeRIfOLG26RPUaUSSngS8BpTycQ3WIoFOMcO1xf9fGHYsQ94U8TsvWWVkCU0bbz6k8resLyTmPIDI5OyfbJpA2iDbStA3VZbVuuwCWj0Pl2k/t2JENFurvj357mNiz0AQE7dVAMsSi0pfW6BEUDkievBaQHTIkytdug4eYIOID5DxYHpZ/cNdPZgzsTnz9sQ8Gv1PX Received: from thinky.redhat.com ([109.183.6.197]) by smtp.gmail.com with ESMTPSA id 14-20020a0564021f4e00b0056176e95a88sm2620261edz.32.2024.02.12.09.00.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 09:00:18 -0800 (PST) From: Andrey Albershteyn To: fsverity@lists.linux.dev, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, chandan.babu@oracle.com, djwong@kernel.org, ebiggers@kernel.org Cc: Andrey Albershteyn Subject: [PATCH v4 21/25] xfs: disable direct read path for fs-verity files Date: Mon, 12 Feb 2024 17:58:18 +0100 Message-Id: <20240212165821.1901300-22-aalbersh@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240212165821.1901300-1-aalbersh@redhat.com> References: <20240212165821.1901300-1-aalbersh@redhat.com> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The direct path is not supported on verity files. Attempts to use direct I/O path on such files should fall back to buffered I/O path. Signed-off-by: Andrey Albershteyn --- fs/xfs/xfs_file.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index ed36cd088926..011c311efe22 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -281,7 +281,8 @@ xfs_file_dax_read( struct kiocb *iocb, struct iov_iter *to) { - struct xfs_inode *ip = XFS_I(iocb->ki_filp->f_mapping->host); + struct inode *inode = iocb->ki_filp->f_mapping->host; + struct xfs_inode *ip = XFS_I(inode); ssize_t ret = 0; trace_xfs_file_dax_read(iocb, to); @@ -334,10 +335,18 @@ xfs_file_read_iter( if (IS_DAX(inode)) ret = xfs_file_dax_read(iocb, to); - else if (iocb->ki_flags & IOCB_DIRECT) + else if (iocb->ki_flags & IOCB_DIRECT && !fsverity_active(inode)) ret = xfs_file_dio_read(iocb, to); - else + else { + /* + * In case fs-verity is enabled, we also fallback to the + * buffered read from the direct read path. Therefore, + * IOCB_DIRECT is set and need to be cleared (see + * generic_file_read_iter()) + */ + iocb->ki_flags &= ~IOCB_DIRECT; ret = xfs_file_buffered_read(iocb, to); + } if (ret > 0) XFS_STATS_ADD(mp, xs_read_bytes, ret); From patchwork Mon Feb 12 16:58:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Albershteyn X-Patchwork-Id: 13553758 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1DA0040C0C for ; Mon, 12 Feb 2024 17:00:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757229; cv=none; b=LWd6NBqKeJNommm1aV0JY6dN1wEqurR1Gpm3pl1J8bmyXTmG6eKKeoueJ8pAKG8pSJhW3NDf+fhZ3DbeZiIUSmgsu1KqPZWf2jYV6aj2Nz4xT8DS/YGW7f+AHU6AywtrzkTdRsqbQ2rdbGmOV6IiTTiHIeYYXqH2HXnpkRFxzjw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757229; c=relaxed/simple; bh=VnjsHo4Y6j3Os0lRrKhmxm+4dLplQwwZ36sDmgJhpgs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=s/t8XiLT/TuVriBCDG5GQFj3DACH5OBqTKQCPucogjS1bAphGid+01yCehS4rUJy351eQ5vzOIoQ6OBgPg4jzZbJVLsIhJIpPG+VaIM/Hg6YmMjdcFJoEa1zWoMGol3Igy+NGtuDQP07W+qLsChTV/aTDxg4tBK/fiWkCTByVwE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=A1/Rq9ri; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="A1/Rq9ri" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707757225; 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=GzchNGKoFobK7llDJm/tZqiDm2BbLLigfLyOHeOEr7s=; b=A1/Rq9riElWUQ0niQqLsiVlrvGu1rL/H6JZI/4ZL/C4MIuJTgfAzUXwxlMHuykQSO6TzSE emKBvUMA9s5gAFHEl4vvxz1PgT8+Cozsa6TsHy5S9D8VoSzMaOZmCrDKOtwOtVe/GmswQE Af8hepEuQGQDWAFaHLcBQDrWyFRHdJQ= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-171-q91t3CdWP_ivGfJZbZmoiA-1; Mon, 12 Feb 2024 12:00:23 -0500 X-MC-Unique: q91t3CdWP_ivGfJZbZmoiA-1 Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-560fc724014so1826079a12.2 for ; Mon, 12 Feb 2024 09:00:23 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707757221; x=1708362021; 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=GzchNGKoFobK7llDJm/tZqiDm2BbLLigfLyOHeOEr7s=; b=AjgVBKYsAsQ659TP9IYLh1voo8q+grRh939pIOXk4mPiayBF1j3LYJ2WOqjYl5uqY6 acDgWs3i/7Kvhr99hCZthSWdaxavomuzUDozT/Huyy2cYdApDG4OmgHkFGwQ1DqNphDR KSvEnbVwc87KFw4VcSthlqW3DN+T8XpPgXMBiWQBfA+N71I9BYCN2+sV1OuYMDrxBNwb PDbavbprQsNXqXph/7A21CBgxdPAXyiJ146x0kfKnVQRLRy/8/vbbiVZ93fJ3RZlHckq kOp4+xwYlVhKsm+Hn4YG41NRiZ8nHWv1yfNcKX1c2tmxQtkhzrM7o9QNIA6BDI2LhbRu OIWg== X-Forwarded-Encrypted: i=1; AJvYcCWU8UBKMLabZc5cZ7HhSSEVTseLAl07+V5Spaog05td+ntjFCj9YMh3U+95FrSohBrjUH8uuyejvO6XTKqquy3hvDnfmMCcALVR X-Gm-Message-State: AOJu0Yw/zbU4jplVvG+uaedxwEMg0BBI7OjSBtsr5SbA8FD7UoaKnJiF FvTSCD/kBfcTDTXS6dth/j0j8VatmFOOdAlgT3JLX6VXNJyDmRjRxGoUXhy1aqV29YYmvBJLo3L wdKRJyBV/it8xAg4VhCucFZ1XatOk+i11uK1FgO9lyrDwkU+ZGY9EW46J X-Received: by 2002:a05:6402:1a45:b0:560:c6a8:e7c8 with SMTP id bf5-20020a0564021a4500b00560c6a8e7c8mr5875744edb.10.1707757221307; Mon, 12 Feb 2024 09:00:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IGX39I2I1YFhEWZVMudXvWVUL3MsOgUAoMzpGndxKPXsNLi1R0cCMXNiUVm5TDavI0BmxGdVw== X-Received: by 2002:a05:6402:1a45:b0:560:c6a8:e7c8 with SMTP id bf5-20020a0564021a4500b00560c6a8e7c8mr5875726edb.10.1707757220988; Mon, 12 Feb 2024 09:00:20 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCU0i0lMxRc0jlvJ5/NDg6bCy36fon95WEaDVUEmbuIQA0hXVfSENkhbpbMg2EWtbigkrL1UCdhkgQSUvdY1X686C+jT5WdWrpL9jskq4H8tzsE1mAm1vTS3KyCBvkNcAZbq5yOFmGU/9CTzmhqIcpKBSg+NZRdIERkPinEJ0PzSVuSe+89jHRFJhndpcKEew/iaX6aTSXBSxzpqs9ef0htWlr9NHqS497g9 Received: from thinky.redhat.com ([109.183.6.197]) by smtp.gmail.com with ESMTPSA id 14-20020a0564021f4e00b0056176e95a88sm2620261edz.32.2024.02.12.09.00.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 09:00:19 -0800 (PST) From: Andrey Albershteyn To: fsverity@lists.linux.dev, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, chandan.babu@oracle.com, djwong@kernel.org, ebiggers@kernel.org Cc: Andrey Albershteyn Subject: [PATCH v4 22/25] xfs: add fs-verity support Date: Mon, 12 Feb 2024 17:58:19 +0100 Message-Id: <20240212165821.1901300-23-aalbersh@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240212165821.1901300-1-aalbersh@redhat.com> References: <20240212165821.1901300-1-aalbersh@redhat.com> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add integration with fs-verity. The XFS store fs-verity metadata in the extended file attributes. The metadata consist of verity descriptor and Merkle tree blocks. The descriptor is stored under "vdesc" extended attribute. The Merkle tree blocks are stored under binary indexes which are offsets into the Merkle tree. When fs-verity is enabled on an inode, the XFS_IVERITY_CONSTRUCTION flag is set meaning that the Merkle tree is being build. The initialization ends with storing of verity descriptor and setting inode on-disk flag (XFS_DIFLAG2_VERITY). The verification on read is done in read path of iomap. Signed-off-by: Andrey Albershteyn --- fs/xfs/Makefile | 1 + fs/xfs/libxfs/xfs_attr.c | 13 ++ fs/xfs/libxfs/xfs_attr_leaf.c | 17 +- fs/xfs/libxfs/xfs_attr_remote.c | 8 +- fs/xfs/libxfs/xfs_da_format.h | 27 +++ fs/xfs/libxfs/xfs_ondisk.h | 4 + fs/xfs/xfs_inode.h | 3 +- fs/xfs/xfs_super.c | 8 + fs/xfs/xfs_verity.c | 348 ++++++++++++++++++++++++++++++++ fs/xfs/xfs_verity.h | 33 +++ 10 files changed, 455 insertions(+), 7 deletions(-) create mode 100644 fs/xfs/xfs_verity.c create mode 100644 fs/xfs/xfs_verity.h diff --git a/fs/xfs/Makefile b/fs/xfs/Makefile index 8be90c685b0b..207a64f47a71 100644 --- a/fs/xfs/Makefile +++ b/fs/xfs/Makefile @@ -131,6 +131,7 @@ xfs-$(CONFIG_XFS_POSIX_ACL) += xfs_acl.o xfs-$(CONFIG_SYSCTL) += xfs_sysctl.o xfs-$(CONFIG_COMPAT) += xfs_ioctl32.o xfs-$(CONFIG_EXPORTFS_BLOCK_OPS) += xfs_pnfs.o +xfs-$(CONFIG_FS_VERITY) += xfs_verity.o # notify failure ifeq ($(CONFIG_MEMORY_FAILURE),y) diff --git a/fs/xfs/libxfs/xfs_attr.c b/fs/xfs/libxfs/xfs_attr.c index 8e3138af4a5f..21ad25bddd5d 100644 --- a/fs/xfs/libxfs/xfs_attr.c +++ b/fs/xfs/libxfs/xfs_attr.c @@ -27,6 +27,7 @@ #include "xfs_attr_item.h" #include "xfs_xattr.h" #include "xfs_parent.h" +#include "xfs_verity.h" struct kmem_cache *xfs_attr_intent_cache; @@ -1526,6 +1527,18 @@ xfs_attr_namecheck( if (flags & XFS_ATTR_PARENT) return xfs_parent_namecheck(mp, name, length, flags); + if (flags & XFS_ATTR_VERITY) { + /* Merkle tree pages are stored under u64 indexes */ + if (length == sizeof(struct xfs_fsverity_merkle_key)) + return true; + + /* Verity descriptor blocks are held in a named attribute. */ + if (length == XFS_VERITY_DESCRIPTOR_NAME_LEN) + return true; + + return false; + } + /* * MAXNAMELEN includes the trailing null, but (name/length) leave it * out, so use >= for the length check. diff --git a/fs/xfs/libxfs/xfs_attr_leaf.c b/fs/xfs/libxfs/xfs_attr_leaf.c index 51aa5d5df76c..28274d57ba9b 100644 --- a/fs/xfs/libxfs/xfs_attr_leaf.c +++ b/fs/xfs/libxfs/xfs_attr_leaf.c @@ -29,6 +29,7 @@ #include "xfs_log.h" #include "xfs_ag.h" #include "xfs_errortag.h" +#include "xfs_verity.h" /* @@ -518,7 +519,12 @@ xfs_attr_copy_value( return -ERANGE; } - if (!args->value) { + /* + * We don't want to allocate memory for fs-verity Merkle tree blocks + * (fs-verity descriptor is fine though). They will be stored in + * underlying xfs_buf + */ + if (!args->value && !xfs_verity_merkle_block(args)) { args->value = kvmalloc(valuelen, GFP_KERNEL | __GFP_NOLOCKDEP); if (!args->value) return -ENOMEM; @@ -537,7 +543,14 @@ xfs_attr_copy_value( */ if (!value) return -EINVAL; - memcpy(args->value, value, valuelen); + /* + * We won't copy Merkle tree block to the args->value as we want it be + * in the xfs_buf. And we didn't allocate any memory in args->value. + */ + if (xfs_verity_merkle_block(args)) + args->value = value; + else + memcpy(args->value, value, valuelen); return 0; } diff --git a/fs/xfs/libxfs/xfs_attr_remote.c b/fs/xfs/libxfs/xfs_attr_remote.c index 1d32041412cc..dafb27fb3527 100644 --- a/fs/xfs/libxfs/xfs_attr_remote.c +++ b/fs/xfs/libxfs/xfs_attr_remote.c @@ -22,6 +22,7 @@ #include "xfs_attr_remote.h" #include "xfs_trace.h" #include "xfs_error.h" +#include "xfs_verity.h" #define ATTR_RMTVALUE_MAPSIZE 1 /* # of map entries at once */ @@ -401,11 +402,10 @@ xfs_attr_rmtval_get( ASSERT(args->rmtvaluelen == args->valuelen); /* - * We also check for _OP_BUFFER as we want to trigger on - * verity blocks only, not on verity_descriptor + * For fs-verity we want additional space in the xfs_buf. This space is + * used to copy xattr value without leaf headers (crc header). */ - if (args->attr_filter & XFS_ATTR_VERITY && - args->op_flags & XFS_DA_OP_BUFFER) + if (xfs_verity_merkle_block(args)) flags = XBF_DOUBLE_ALLOC; valuelen = args->rmtvaluelen; diff --git a/fs/xfs/libxfs/xfs_da_format.h b/fs/xfs/libxfs/xfs_da_format.h index 05b82e5b64fa..4d28a64f8cd7 100644 --- a/fs/xfs/libxfs/xfs_da_format.h +++ b/fs/xfs/libxfs/xfs_da_format.h @@ -903,4 +903,31 @@ struct xfs_parent_name_rec { */ #define XFS_PARENT_DIRENT_NAME_MAX_SIZE (MAXNAMELEN - 1) +/* + * fs-verity attribute name format + * + * Merkle tree blocks are stored under extended attributes of the inode. The + * name of the attributes are offsets into merkle tree. + */ +struct xfs_fsverity_merkle_key { + __be64 merkleoff; +}; + +static inline void +xfs_fsverity_merkle_key_to_disk(struct xfs_fsverity_merkle_key *key, loff_t pos) +{ + key->merkleoff = cpu_to_be64(pos); +} + +static inline loff_t +xfs_fsverity_name_to_block_offset(unsigned char *name) +{ + struct xfs_fsverity_merkle_key key = { + .merkleoff = *(__be64 *)name + }; + loff_t offset = be64_to_cpu(key.merkleoff); + + return offset; +} + #endif /* __XFS_DA_FORMAT_H__ */ diff --git a/fs/xfs/libxfs/xfs_ondisk.h b/fs/xfs/libxfs/xfs_ondisk.h index 81885a6a028e..39209943c474 100644 --- a/fs/xfs/libxfs/xfs_ondisk.h +++ b/fs/xfs/libxfs/xfs_ondisk.h @@ -194,6 +194,10 @@ xfs_check_ondisk_structs(void) XFS_CHECK_VALUE(XFS_DQ_BIGTIME_EXPIRY_MIN << XFS_DQ_BIGTIME_SHIFT, 4); XFS_CHECK_VALUE(XFS_DQ_BIGTIME_EXPIRY_MAX << XFS_DQ_BIGTIME_SHIFT, 16299260424LL); + + /* fs-verity descriptor xattr name */ + XFS_CHECK_VALUE(strlen(XFS_VERITY_DESCRIPTOR_NAME), + XFS_VERITY_DESCRIPTOR_NAME_LEN); } #endif /* __XFS_ONDISK_H */ diff --git a/fs/xfs/xfs_inode.h b/fs/xfs/xfs_inode.h index 97f63bacd4c2..97fa5155fcba 100644 --- a/fs/xfs/xfs_inode.h +++ b/fs/xfs/xfs_inode.h @@ -342,7 +342,8 @@ static inline bool xfs_inode_has_large_extent_counts(struct xfs_inode *ip) * inactivation completes, both flags will be cleared and the inode is a * plain old IRECLAIMABLE inode. */ -#define XFS_INACTIVATING (1 << 13) +#define XFS_INACTIVATING (1 << 13) +#define XFS_IVERITY_CONSTRUCTION (1 << 14) /* merkle tree construction */ /* Quotacheck is running but inode has not been added to quota counts. */ #define XFS_IQUOTAUNCHECKED (1 << 14) diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c index 4737101edab9..3bb4dba3f1ca 100644 --- a/fs/xfs/xfs_super.c +++ b/fs/xfs/xfs_super.c @@ -30,6 +30,7 @@ #include "xfs_filestream.h" #include "xfs_quota.h" #include "xfs_sysfs.h" +#include "xfs_verity.h" #include "xfs_ondisk.h" #include "xfs_rmap_item.h" #include "xfs_refcount_item.h" @@ -1531,6 +1532,9 @@ xfs_fs_fill_super( sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP | QTYPE_MASK_PRJ; #endif sb->s_op = &xfs_super_operations; +#ifdef CONFIG_FS_VERITY + sb->s_vop = &xfs_verity_ops; +#endif /* * Delay mount work if the debug hook is set. This is debug @@ -1740,6 +1744,10 @@ xfs_fs_fill_super( goto out_filestream_unmount; } + if (xfs_has_verity(mp)) + xfs_alert(mp, + "EXPERIMENTAL fs-verity feature in use. Use at your own risk!"); + error = xfs_mountfs(mp); if (error) goto out_filestream_unmount; diff --git a/fs/xfs/xfs_verity.c b/fs/xfs/xfs_verity.c new file mode 100644 index 000000000000..dfa05cf6518c --- /dev/null +++ b/fs/xfs/xfs_verity.c @@ -0,0 +1,348 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2023 Red Hat, Inc. + */ +#include "xfs.h" +#include "xfs_shared.h" +#include "xfs_format.h" +#include "xfs_da_format.h" +#include "xfs_da_btree.h" +#include "xfs_trans_resv.h" +#include "xfs_mount.h" +#include "xfs_inode.h" +#include "xfs_log_format.h" +#include "xfs_attr.h" +#include "xfs_verity.h" +#include "xfs_bmap_util.h" +#include "xfs_log_format.h" +#include "xfs_trans.h" +#include "xfs_attr_leaf.h" + +/* + * Make fs-verity invalidate verified status of Merkle tree block + */ +static void +xfs_verity_put_listent( + struct xfs_attr_list_context *context, + int flags, + unsigned char *name, + int namelen, + int valuelen) +{ + /* + * Verity descriptor is smaller than 1024; verity block min size is + * 1024. Exclude verity descriptor + */ + if (valuelen < 1024) + return; + + fsverity_invalidate_range(VFS_I(context->dp), + xfs_fsverity_name_to_block_offset(name), + valuelen); +} + +/* + * Iterate over extended attributes in the bp to invalidate Merkle tree blocks + */ +static int +xfs_invalidate_blocks( + struct xfs_inode *ip, + struct xfs_buf *bp) +{ + struct xfs_attr_list_context context; + + memset(&context, 0, sizeof(context)); + context.dp = ip; + context.resynch = 0; + context.buffer = NULL; + context.bufsize = 0; + context.firstu = 0; + context.attr_filter = XFS_ATTR_VERITY; + context.put_listent = xfs_verity_put_listent; + + return xfs_attr3_leaf_list_int(bp, &context); +} + +static int +xfs_get_verity_descriptor( + struct inode *inode, + void *buf, + size_t buf_size) +{ + struct xfs_inode *ip = XFS_I(inode); + int error = 0; + struct xfs_da_args args = { + .dp = ip, + .attr_filter = XFS_ATTR_VERITY, + .name = (const uint8_t *)XFS_VERITY_DESCRIPTOR_NAME, + .namelen = XFS_VERITY_DESCRIPTOR_NAME_LEN, + .value = buf, + .valuelen = buf_size, + }; + + /* + * The fact that (returned attribute size) == (provided buf_size) is + * checked by xfs_attr_copy_value() (returns -ERANGE) + */ + error = xfs_attr_get(&args); + if (error) + return error; + + return args.valuelen; +} + +static int +xfs_begin_enable_verity( + struct file *filp) +{ + struct inode *inode = file_inode(filp); + struct xfs_inode *ip = XFS_I(inode); + int error = 0; + + ASSERT(xfs_isilocked(ip, XFS_IOLOCK_EXCL)); + + if (IS_DAX(inode)) + return -EINVAL; + + if (xfs_iflags_test_and_set(ip, XFS_IVERITY_CONSTRUCTION)) + return -EBUSY; + + return error; +} + +static int +xfs_drop_merkle_tree( + struct xfs_inode *ip, + u64 merkle_tree_size, + unsigned int tree_blocksize) +{ + struct xfs_fsverity_merkle_key name; + int error = 0; + u64 offset = 0; + struct xfs_da_args args = { + .dp = ip, + .whichfork = XFS_ATTR_FORK, + .attr_filter = XFS_ATTR_VERITY, + .op_flags = XFS_DA_OP_REMOVE, + .namelen = sizeof(struct xfs_fsverity_merkle_key), + /* NULL value make xfs_attr_set remove the attr */ + .value = NULL, + }; + + if (!merkle_tree_size) + return 0; + + args.name = (const uint8_t *)&name.merkleoff; + for (offset = 0; offset < merkle_tree_size; offset += tree_blocksize) { + xfs_fsverity_merkle_key_to_disk(&name, offset); + error = xfs_attr_set(&args); + if (error) + return error; + } + + args.name = (const uint8_t *)XFS_VERITY_DESCRIPTOR_NAME; + args.namelen = XFS_VERITY_DESCRIPTOR_NAME_LEN; + error = xfs_attr_set(&args); + + return error; +} + +static int +xfs_end_enable_verity( + struct file *filp, + const void *desc, + size_t desc_size, + u64 merkle_tree_size, + unsigned int tree_blocksize) +{ + struct inode *inode = file_inode(filp); + struct xfs_inode *ip = XFS_I(inode); + struct xfs_mount *mp = ip->i_mount; + struct xfs_trans *tp; + struct xfs_da_args args = { + .dp = ip, + .whichfork = XFS_ATTR_FORK, + .attr_filter = XFS_ATTR_VERITY, + .attr_flags = XATTR_CREATE, + .name = (const uint8_t *)XFS_VERITY_DESCRIPTOR_NAME, + .namelen = XFS_VERITY_DESCRIPTOR_NAME_LEN, + .value = (void *)desc, + .valuelen = desc_size, + }; + int error = 0; + + ASSERT(xfs_isilocked(ip, XFS_IOLOCK_EXCL)); + + /* fs-verity failed, just cleanup */ + if (desc == NULL) + goto out; + + error = xfs_attr_set(&args); + if (error) + goto out; + + /* Set fsverity inode flag */ + error = xfs_trans_alloc_inode(ip, &M_RES(mp)->tr_ichange, + 0, 0, false, &tp); + if (error) + goto out; + + /* + * Ensure that we've persisted the verity information before we enable + * it on the inode and tell the caller we have sealed the inode. + */ + ip->i_diflags2 |= XFS_DIFLAG2_VERITY; + + xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); + xfs_trans_set_sync(tp); + + error = xfs_trans_commit(tp); + xfs_iunlock(ip, XFS_ILOCK_EXCL); + + if (!error) + inode->i_flags |= S_VERITY; + +out: + if (error) + WARN_ON_ONCE(xfs_drop_merkle_tree(ip, merkle_tree_size, + tree_blocksize)); + + xfs_iflags_clear(ip, XFS_IVERITY_CONSTRUCTION); + return error; +} + +static int +xfs_read_merkle_tree_block( + struct inode *inode, + u64 pos, + struct fsverity_blockbuf *block, + unsigned int log_blocksize, + u64 ra_bytes) +{ + struct xfs_inode *ip = XFS_I(inode); + struct xfs_fsverity_merkle_key name; + int error = 0; + struct xfs_da_args args = { + .dp = ip, + .attr_filter = XFS_ATTR_VERITY, + .op_flags = XFS_DA_OP_BUFFER, + .namelen = sizeof(struct xfs_fsverity_merkle_key), + .valuelen = (1 << log_blocksize), + }; + xfs_fsverity_merkle_key_to_disk(&name, pos); + args.name = (const uint8_t *)&name.merkleoff; + + error = xfs_attr_get(&args); + if (error) + goto out; + + if (!args.valuelen) + return -ENODATA; + + /* + * The more detailed reasoning for the memory barriers below is the same + * as described in fsverity_invalidate_page(). Memory barriers are used + * to force operation ordering on clearing bitmap in + * fsverity_invalidate_range() and settings XBF_VERITY_SEEN flag. But as + * XFS doesn't use neither PAGEs to store the blocks nor PG_checked that + * function can not be used directly. + */ + if (!(args.bp->b_flags & XBF_VERITY_SEEN)) { + /* + * A read memory barrier is needed here to give ACQUIRE + * semantics to the above check. + */ + smp_rmb(); + /* + * fs-verity is not aware if buffer was evicted from the memory. + * Make fs-verity invalidate verfied status of all blocks in the + * buffer. + * + * Single extended attribute can contain multiple Merkle tree + * blocks: + * - leaf with inline data -> invalidate all blocks in the leaf + * - remote value -> invalidate single block + * + * For example, leaf on 64k system with 4k/1k filesystem will + * contain multiple Merkle tree blocks. + * + * Only remote value buffers would have XBF_DOUBLE_ALLOC flag + */ + if (args.bp->b_flags & XBF_DOUBLE_ALLOC) + fsverity_invalidate_range(inode, pos, args.valuelen); + else { + error = xfs_invalidate_blocks(ip, args.bp); + if (error) + goto out; + } + } + + /* + * A write memory barrier is needed here to give RELEASE + * semantics to the below flag. + */ + smp_wmb(); + args.bp->b_flags |= XBF_VERITY_SEEN; + + block->kaddr = args.value; + block->size = args.valuelen; + block->context = args.bp; + + return error; + +out: + kmem_free(args.value); + if (args.bp) + xfs_buf_rele(args.bp); + return error; +} + +static int +xfs_write_merkle_tree_block( + struct inode *inode, + const void *buf, + u64 pos, + unsigned int size) +{ + struct xfs_inode *ip = XFS_I(inode); + struct xfs_fsverity_merkle_key name; + struct xfs_da_args args = { + .dp = ip, + .whichfork = XFS_ATTR_FORK, + .attr_filter = XFS_ATTR_VERITY, + .attr_flags = XATTR_CREATE, + .namelen = sizeof(struct xfs_fsverity_merkle_key), + .value = (void *)buf, + .valuelen = size, + }; + + xfs_fsverity_merkle_key_to_disk(&name, pos); + args.name = (const uint8_t *)&name.merkleoff; + + return xfs_attr_set(&args); +} + +static void +xfs_drop_block( + struct fsverity_blockbuf *block) +{ + struct xfs_buf *bp; + + ASSERT(block != NULL); + bp = (struct xfs_buf *)block->context; + + ASSERT(bp->b_flags & XBF_VERITY_SEEN); + + xfs_buf_rele(bp); + + kunmap_local(block->kaddr); +} + +const struct fsverity_operations xfs_verity_ops = { + .begin_enable_verity = &xfs_begin_enable_verity, + .end_enable_verity = &xfs_end_enable_verity, + .get_verity_descriptor = &xfs_get_verity_descriptor, + .read_merkle_tree_block = &xfs_read_merkle_tree_block, + .write_merkle_tree_block = &xfs_write_merkle_tree_block, + .drop_block = &xfs_drop_block, +}; diff --git a/fs/xfs/xfs_verity.h b/fs/xfs/xfs_verity.h new file mode 100644 index 000000000000..0de6c66fdb1a --- /dev/null +++ b/fs/xfs/xfs_verity.h @@ -0,0 +1,33 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2022 Red Hat, Inc. + */ +#ifndef __XFS_VERITY_H__ +#define __XFS_VERITY_H__ + +#include "xfs.h" +#include "xfs_da_format.h" +#include "xfs_da_btree.h" +#include + +#define XFS_VERITY_DESCRIPTOR_NAME "vdesc" +#define XFS_VERITY_DESCRIPTOR_NAME_LEN 5 + +static inline bool +xfs_verity_merkle_block( + struct xfs_da_args *args) +{ + if (!(args->attr_filter & XFS_ATTR_VERITY)) + return false; + + if (!(args->op_flags & XFS_DA_OP_BUFFER)) + return false; + + return true; +} + +#ifdef CONFIG_FS_VERITY +extern const struct fsverity_operations xfs_verity_ops; +#endif /* CONFIG_FS_VERITY */ + +#endif /* __XFS_VERITY_H__ */ From patchwork Mon Feb 12 16:58:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Albershteyn X-Patchwork-Id: 13553756 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5362941775 for ; Mon, 12 Feb 2024 17:00:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757228; cv=none; b=Xe+ZU/SBsLPLUTby7U0kcWl+FJjPr0tD4z+Iii1/jTTvh6KT5Us5r0acoYEdCKrUrWRK6VGXPn5OphRbw2fQAFB1tdCmM9tRKSI9F5uVIkeDPwOeeflpb+/Ek9p4IGpwDDiWL1HXaJIEDapTP3t0o7pTYogWLgAFHeBsCOnyNbM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757228; c=relaxed/simple; bh=QdzJQ1kBU4GhtNmWFv/v5q2u9OPK6bqQ8YoEEN+UHm4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GvJolZ8TbCE0Djd3ihPIF5CadxCrJ340jfaTNTZJwSQULJz2vz38UharhGwGqMXcFjy80eb4PO91S82/YbI285CS1ncIAy2Khtq/zls58AUiABVVaInf78XLLS3W8gBhe27L23c3FikG1nK6Rg+/qVf2ai8FhyvY9qG5Eaet6VE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=JgW9LGCn; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="JgW9LGCn" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707757226; 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=CCVu6C3sA7ElU4nB0aYXUKm+yvCdjGTpJNzXHRX3ZOA=; b=JgW9LGCnZDiFFS+5oFXz9kfjQzIUQJlFgpFprnFoUh7qloSO3DWO+vVsjDZ99Y3Iah/GLF aeW8/qrUhC1mWLwBVqNdT0wdk91++mzg6Ojs4xaPu2QQClZ5YwrAU0l7fD1U3HKBosmQn+ xuGxd0ns4RYoiXM3ns/CadIJ4DQ+YPI= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-668-e6_y9y2YO_WEX7yAEBp6rw-1; Mon, 12 Feb 2024 12:00:24 -0500 X-MC-Unique: e6_y9y2YO_WEX7yAEBp6rw-1 Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-56001d4c9c8so2107868a12.0 for ; Mon, 12 Feb 2024 09:00:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707757223; x=1708362023; 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=CCVu6C3sA7ElU4nB0aYXUKm+yvCdjGTpJNzXHRX3ZOA=; b=QanXXI2h/8E0/WoYsCqXa1lPoP2DB70yu4ZteHoHS5ICOTfTwlP8bYFeY9WlZUZ77j WmyJcaTb5v8TBVem9U5t4g3KlA0E4zqpRBFbP3wjVd6cZghJExiw/knVrs8/gaLq7C0c mPFdAA9rXs2A4e5meK1J1Myxxehr7JhXcRQdVOMC9SNQQ/za9BdmrcyURuJFM2LWgoXj ih4lSLkpXzVj2HYw3FKI2NZyG4lOffyUuhBbVMMrbqYOinoKW8liZO33dCfXxWTi1UJV K75IEUvV/MM3hw5Z9opqMOvP2JFr2iTyZgtjJe3+vqJofisuWjLnILEhpOLdPMMLsMUH 82rQ== X-Gm-Message-State: AOJu0Yw7zfil8a2uOgoSQ7/Qqg2T6iC87GDxtw0teylyGiJOcPeqGYnA iDQ6xa3gmh4k6gBZyx+ok1zUeXGbZa0FZDtrk7/4QwEJLwuK127JyKu1xnkshC7knpNOVweWtRx 1Fe5Dfct2qmwl9mo9Il3K+O/2xIjhcfg7sRoGxO/vOQzoLKv34aUyYwRR X-Received: by 2002:a50:fa86:0:b0:55f:fd61:b08f with SMTP id w6-20020a50fa86000000b0055ffd61b08fmr5444430edr.4.1707757223185; Mon, 12 Feb 2024 09:00:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IGX4QsV2jwPgEK3ppOb+fAmuTGxzi5pj46ICsgxsM5V1RWud/SUlTZ9QaiHLZpC1sd63X9YYw== X-Received: by 2002:a50:fa86:0:b0:55f:fd61:b08f with SMTP id w6-20020a50fa86000000b0055ffd61b08fmr5444416edr.4.1707757223016; Mon, 12 Feb 2024 09:00:23 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVbixGwNn2/iQes+rCvgVp/F3RjBSehosjFCAIvdLXWSMONtUscMUhdVZvz2ojDIXeQtTNHdhZ8OVZwgnN/hd7k6GmI5Ryp54qW3fmznAn2ASgRznKnI1XzfIgGrVB3dwYWfYVzmpZ0hy2OW2vDHkBCu2jmZU1UIQXfV1xRLXQkWg38QoXASDkPImLM3obGk9jg3wyKszAXbZUxea+dMcCgzt2VQyuH8wp/ Received: from thinky.redhat.com ([109.183.6.197]) by smtp.gmail.com with ESMTPSA id 14-20020a0564021f4e00b0056176e95a88sm2620261edz.32.2024.02.12.09.00.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 09:00:22 -0800 (PST) From: Andrey Albershteyn To: fsverity@lists.linux.dev, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, chandan.babu@oracle.com, djwong@kernel.org, ebiggers@kernel.org Cc: Andrey Albershteyn Subject: [PATCH v4 23/25] xfs: make scrub aware of verity dinode flag Date: Mon, 12 Feb 2024 17:58:20 +0100 Message-Id: <20240212165821.1901300-24-aalbersh@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240212165821.1901300-1-aalbersh@redhat.com> References: <20240212165821.1901300-1-aalbersh@redhat.com> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 fs-verity adds new inode flag which causes scrub to fail as it is not yet known. Signed-off-by: Andrey Albershteyn Reviewed-by: Darrick J. Wong --- fs/xfs/scrub/attr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/xfs/scrub/attr.c b/fs/xfs/scrub/attr.c index 9a1f59f7b5a4..ae4227cb55ec 100644 --- a/fs/xfs/scrub/attr.c +++ b/fs/xfs/scrub/attr.c @@ -494,7 +494,7 @@ xchk_xattr_rec( /* Retrieve the entry and check it. */ hash = be32_to_cpu(ent->hashval); badflags = ~(XFS_ATTR_LOCAL | XFS_ATTR_ROOT | XFS_ATTR_SECURE | - XFS_ATTR_INCOMPLETE | XFS_ATTR_PARENT); + XFS_ATTR_INCOMPLETE | XFS_ATTR_PARENT | XFS_ATTR_VERITY); if ((ent->flags & badflags) != 0) xchk_da_set_corrupt(ds, level); if (ent->flags & XFS_ATTR_LOCAL) { From patchwork Mon Feb 12 16:58:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Albershteyn X-Patchwork-Id: 13553759 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 92C6E45945 for ; Mon, 12 Feb 2024 17:00:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757230; cv=none; b=ructvGIov9TnTBIDpVtpqKuJ76/4k5i7zGLExAixjiVa4hNqxHfZiO+OttSotXttmv/yGjB5oP1OlDqr4XG8m0ve+68OiF1wXPmUU/JR5rRuKu0WngOnIL/CTq8APxjY3I8tDx84ExpSD/Yrjq9/A+e+1bFH1rCYciFYbujEVI4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757230; c=relaxed/simple; bh=3huMSuptuBha2CwG1y0/SfdkyV9jIivWktDsQLKbc70=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=PqyHRRy99q5xmMPmP4pzFDpaqb8gpV5GX08J0Dw0BenZRlDO2/VsIawV88oI2oGBy32Jg/YV8zxeNH9dnv611PybfJv6GlPmLGaM4cQWF+3ib0gts+DFSKxxJPSZqm2VzdbRCpMbaq1a4ubwd4ZsyztCPfgek8HC5ZuW37A14bI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Hk4cq2CS; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Hk4cq2CS" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707757227; 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=O/7GvRpwmqndoF+ccNvwmWywMN3/sSl/624LXUp5jis=; b=Hk4cq2CSlOy6a2/vfb3Av9fU+RSWtD8IGDCXD3O8UKG6N7GzFexOXv43IHIWLSaXQV5AeD Q2TCUyl4cqDtcipDJ8rNJZVci9Ng0aEwmYNVwSDHwVQRs6ZymZzaDsCEey+xOjv/RjSMmv C96pq+F9sXTeglX09n1hX7/HV0HTDTA= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-36-66rEke76PoqvAHPqIoOtXw-1; Mon, 12 Feb 2024 12:00:25 -0500 X-MC-Unique: 66rEke76PoqvAHPqIoOtXw-1 Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-55fc415b15aso3642192a12.0 for ; Mon, 12 Feb 2024 09:00:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707757224; x=1708362024; 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=O/7GvRpwmqndoF+ccNvwmWywMN3/sSl/624LXUp5jis=; b=DtPxthUvaH29X6BWSdJDqqMLAGSJSqTxvPP+imBSat8dHUUrF7iqe9KA+JZZngokSw /AsY6qgjbmPfwC242jAA5Bu/uevkg9qeUYvQrozO+13G+7rh/2aDRPXbt02DU04KxEaw kn1uzLWGfAA3SRR2ZAkFXeDrF0cOKseHkk1odAbcu/CM3DDzr5Sra+LOiaD3iTSVlExU Cnk0IwjO5MC3pJkOuCVS+1SLXuEzXr4YqgWPJ3pvkKPZOfqCPiR98UwBKjtagKy0w/Yc MNCMk/5Kd/3tYShDuEggwmA2jUI017/k1OtQstiZYodsoYGI7rCVQ0/TZBLSS8bIKXku 2gug== X-Forwarded-Encrypted: i=1; AJvYcCVHlgf+I8hFzPXkzqd0kis/tnU6yZ3SBuX+Dd1+7Adt8CgYxH3D/sIjvfsiae09XTMxp7nHAeuV5ety8nEc8py03iIwjySBtVaO X-Gm-Message-State: AOJu0Yy8TEhd6721RAZLrJ8rG7lN7egzpZ1q7Ft3LjetMfmgFgZqCYBx 26av6iYNyi+uzqTMGeubHplpYwBjZXI6hdfqjIFZqFbiBNZWSaSi2BITwQLN6P1S+NuRr1N+GEq yNzpu6iRAHnpVgvZCdjMwFFlXJM3SAv3dxYIUQAvE5NaMl9Kj4QpNRVGd X-Received: by 2002:a05:6402:2405:b0:55f:cc6d:29b5 with SMTP id t5-20020a056402240500b0055fcc6d29b5mr52470eda.21.1707757224284; Mon, 12 Feb 2024 09:00:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IH42HIFL/dxKgR7EyOrBhc7xXCpi26qG+Fua//JDh3CFnZGhulP1ThwFDEDHGR3MncapDV1sg== X-Received: by 2002:a05:6402:2405:b0:55f:cc6d:29b5 with SMTP id t5-20020a056402240500b0055fcc6d29b5mr52460eda.21.1707757224085; Mon, 12 Feb 2024 09:00:24 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCUY6g9lFbfToZ6KmsvUog3OF70TqTeRgGoC22qmpr2jCPKLvbuFVjIq05EHMUe49MvRMFzVuy29Mh6GJIT6KrIM8cjQ7qF2q5tZa1yNTy1oj9j/AInK7bE+csVY6aVl+btLiGQ+1+sPxkGqT/bsGmYuD94elGcJQZvp0Mbu/COh91A4Guz98UtLS/1F6UUbm+YLFurg6FjBkxzzLYFk5j8Y18gMWHLOeKMK Received: from thinky.redhat.com ([109.183.6.197]) by smtp.gmail.com with ESMTPSA id 14-20020a0564021f4e00b0056176e95a88sm2620261edz.32.2024.02.12.09.00.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 09:00:23 -0800 (PST) From: Andrey Albershteyn To: fsverity@lists.linux.dev, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, chandan.babu@oracle.com, djwong@kernel.org, ebiggers@kernel.org Cc: Andrey Albershteyn Subject: [PATCH v4 24/25] xfs: add fs-verity ioctls Date: Mon, 12 Feb 2024 17:58:21 +0100 Message-Id: <20240212165821.1901300-25-aalbersh@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240212165821.1901300-1-aalbersh@redhat.com> References: <20240212165821.1901300-1-aalbersh@redhat.com> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add fs-verity ioctls to enable, dump metadata (descriptor and Merkle tree pages) and obtain file's digest. Signed-off-by: Andrey Albershteyn --- fs/xfs/xfs_ioctl.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c index 048d83acda0a..5d64e11bf056 100644 --- a/fs/xfs/xfs_ioctl.c +++ b/fs/xfs/xfs_ioctl.c @@ -43,6 +43,7 @@ #include #include #include +#include /* * xfs_find_handle maps from userspace xfs_fsop_handlereq structure to @@ -2174,6 +2175,22 @@ xfs_file_ioctl( return error; } + case FS_IOC_ENABLE_VERITY: + if (!xfs_has_verity(mp)) + return -EOPNOTSUPP; + return fsverity_ioctl_enable(filp, (const void __user *)arg); + + case FS_IOC_MEASURE_VERITY: + if (!xfs_has_verity(mp)) + return -EOPNOTSUPP; + return fsverity_ioctl_measure(filp, (void __user *)arg); + + case FS_IOC_READ_VERITY_METADATA: + if (!xfs_has_verity(mp)) + return -EOPNOTSUPP; + return fsverity_ioctl_read_metadata(filp, + (const void __user *)arg); + default: return -ENOTTY; } From patchwork Mon Feb 12 16:58:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Albershteyn X-Patchwork-Id: 13553760 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AB1F44596E for ; Mon, 12 Feb 2024 17:00:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757230; cv=none; b=mKWeu/ou87WWTJpJYR+BFR5mx+MtT6AjRtY70j+KgCGyRzBFplkdl5HdxeFox+A/JSVtww/FFHZuNxoYwLe3LDH8ULf1YaH6MNmrY9xUxRUnC+6/yITfHbwGOtwk7q+GL0Qf7VexJypYfFsVl/gc2klRi/46POvNWBOwoe94pK8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707757230; c=relaxed/simple; bh=YOeOw6KtPMpEfhCDXm/Z9NhM8n2QAyzwIfav1+RaVLc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TIpV1YobEdzuSJzqdT4qJGqZTrV7sOkhEp2Dps8etFvOTW96s5vixDhwyJVRe7xllGrRTaqr7BuINRrfagOG5oLjyWM+q/Gp2z8J3RxcwmYAQBfu2Y58c4mutwQqqlRpTNnV60DB2S4yPpTnpnwhuDCUVN8Haw1qRfUnm13elbc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=HeVzG6ZD; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="HeVzG6ZD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707757227; 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=9e7oB1ZKkqE1/ExZ0FRyhaGlyLumWOw/BjQhwlJ8uVw=; b=HeVzG6ZD6r+QZkdyxX79L+niT9h9AzMpxFsnRAtYz3BfdDFrCTlBSz4FdLsL27nk0QWmga Apm96JyJjnMKoeMISolI4vqsaW0LxUnVZMjuvC2B07AQreZ+qOo4niAl0P+fVYKjh3+EGJ D1j0MpJTjv/beZDxn8U2D0fT5cN9i4k= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-220-K1sCvspyMreRic8bScy19A-1; Mon, 12 Feb 2024 12:00:26 -0500 X-MC-Unique: K1sCvspyMreRic8bScy19A-1 Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-5605a2937d4so2492632a12.1 for ; Mon, 12 Feb 2024 09:00:26 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707757225; x=1708362025; 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=9e7oB1ZKkqE1/ExZ0FRyhaGlyLumWOw/BjQhwlJ8uVw=; b=Rda4Y5yjm8/qCFJQktXtrBzjywUNMH90GZpCmn/xEyc5KsssCcc3ipAbUb9su51Vis AJ5JVyTC4Cgtg+12XJMAIfZXSXhNrfd7VKiBZ2A6rBDH40Q1gPz9Uw56C+o7OEZ6+gzd RwK8W150u8Hn549sOU1CngU0mv8BBpA/6UKnP9p0zOooE23rDOk4pOW4Sby4s6RNMwB+ agnunpHD0UC7W9YCHgSldBHNeKNdW03+63Ocow9BdFQkPcMllE5SMJibPONNHjJ9Yhkv BRbsDO36n5ebm52wVA8fbsNkLJjUdX55N85Wp80BDTtkln8nN81fr3HcDw73Xwmplu1e S4kA== X-Gm-Message-State: AOJu0YyfAQV/P0BEDWew+VXvV7wD1IZ8KCJQmJhUNYneRgjE74S+wEEB b9LfWAk2bT6fjHaIYbv/EFjr1uIv6V9zrodb7So05XPwEyzogvGnHvc3ZeGtzuAI7DYNNHXPHlL kf/LJoYvxTwaYZceXy7EEWCyveD7tuMFd5sZKEtlnmdtn8TMSwC2opImP X-Received: by 2002:a05:6402:b86:b0:561:8bc4:b05f with SMTP id cf6-20020a0564020b8600b005618bc4b05fmr3774681edb.0.1707757225308; Mon, 12 Feb 2024 09:00:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IFvE/KNVEA8sjxOeGFkeZw+80fBpxWhXZhf/YA0PJnuhaTIDH6fJT1TzvZ1+/5L6O1QV86bRA== X-Received: by 2002:a05:6402:b86:b0:561:8bc4:b05f with SMTP id cf6-20020a0564020b8600b005618bc4b05fmr3774674edb.0.1707757225103; Mon, 12 Feb 2024 09:00:25 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCUxhzEnZsbrIW5ntwlAso9rR1RXR6wMwsKLEZAURItKAlHxOTZpXXk//KErSQyBEO5t4xpAXZ0vDqA8X2RcFIRn9WnYwXDIqu0P7/Uu3jI+3Xltem4uDRgS1XTxukmgySaw5GZN7IDa1Vy6tlSgmkVRkyb2IOkF9bpHxYkammVkHBpqRcckWFuXKg8cP+kXzYsWYvz3HRagDyByWyBO6s3AHde6Xr/froZ0 Received: from thinky.redhat.com ([109.183.6.197]) by smtp.gmail.com with ESMTPSA id 14-20020a0564021f4e00b0056176e95a88sm2620261edz.32.2024.02.12.09.00.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 09:00:24 -0800 (PST) From: Andrey Albershteyn To: fsverity@lists.linux.dev, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, chandan.babu@oracle.com, djwong@kernel.org, ebiggers@kernel.org Cc: Andrey Albershteyn Subject: [PATCH v4 25/25] xfs: enable ro-compat fs-verity flag Date: Mon, 12 Feb 2024 17:58:22 +0100 Message-Id: <20240212165821.1901300-26-aalbersh@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240212165821.1901300-1-aalbersh@redhat.com> References: <20240212165821.1901300-1-aalbersh@redhat.com> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Finalize fs-verity integration in XFS by making kernel fs-verity aware with ro-compat flag. Signed-off-by: Andrey Albershteyn --- fs/xfs/libxfs/xfs_format.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/fs/xfs/libxfs/xfs_format.h b/fs/xfs/libxfs/xfs_format.h index ea78b595aa97..0cb5bf9142b7 100644 --- a/fs/xfs/libxfs/xfs_format.h +++ b/fs/xfs/libxfs/xfs_format.h @@ -355,10 +355,11 @@ xfs_sb_has_compat_feature( #define XFS_SB_FEAT_RO_COMPAT_INOBTCNT (1 << 3) /* inobt block counts */ #define XFS_SB_FEAT_RO_COMPAT_VERITY (1 << 4) /* fs-verity */ #define XFS_SB_FEAT_RO_COMPAT_ALL \ - (XFS_SB_FEAT_RO_COMPAT_FINOBT | \ - XFS_SB_FEAT_RO_COMPAT_RMAPBT | \ - XFS_SB_FEAT_RO_COMPAT_REFLINK| \ - XFS_SB_FEAT_RO_COMPAT_INOBTCNT) + (XFS_SB_FEAT_RO_COMPAT_FINOBT | \ + XFS_SB_FEAT_RO_COMPAT_RMAPBT | \ + XFS_SB_FEAT_RO_COMPAT_REFLINK | \ + XFS_SB_FEAT_RO_COMPAT_INOBTCNT| \ + XFS_SB_FEAT_RO_COMPAT_VERITY) #define XFS_SB_FEAT_RO_COMPAT_UNKNOWN ~XFS_SB_FEAT_RO_COMPAT_ALL static inline bool xfs_sb_has_ro_compat_feature(