Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp608936pxb; Thu, 21 Jan 2021 15:27:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJyw1MIXY7TNUE4wGSojfPBNHyPLqinFSor1j8n59ot//9qvtxdwtSIIAzGH/t0WttaSiQ3m X-Received: by 2002:a17:906:da02:: with SMTP id fi2mr1153871ejb.230.1611271652735; Thu, 21 Jan 2021 15:27:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611271652; cv=none; d=google.com; s=arc-20160816; b=CcqZDaVtD26l5+g+/GK9keKY9H63nYLnA7w7acaaHyZA1pRNhLOhazbEnsRO+H7qYi NWcA1mvhQWZ7P/k2P3G0qnaV2B5qduFi2OTzT3PPUcFeKukkGQ3kvNH8OuAYbZqEsr+4 lN1ozEeZpXbK09dWQAsOzTgIcwu1eu7mMbuKl4O6qJ9bwCyX6xf1k41ojkLwT62CC472 hy6ttF/MX+2Ll6PJ0Pu8uXqN6gIR+GSV9t+myYbr2gXuJuWCOVsLsZhZ1m0T60/nxxSQ tMEA+ppRQly4laykSTxPeQVuePZLeEhRxi7gRmKoZg/Escz2uEXJAf3XcGLU8kUA88Fq JSHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:sender:dkim-signature; bh=9aiKVbqQYlPIThgTQ82dzvRvheXuBHM9UbbX1NZZwXQ=; b=bgChUevjslmlY6ABfUkNLhBusuYn+vS4FNcqBoIXaEXGI3zCgwmwfaI4tqntgsTs8D tNOJ7pTw+3wu05sfdigoDvKyR1dQVHRYvMS+ZIJfVEWsq2yO7UKVqFGCqSziZNyVD+Xw KwugVDGd88jp0RVaf6rNm2CAAnNm70050KvgFdkGq0IrhYMsbya/LcnG4hCHFzsjMjVK Qx6i56jq9qNYlklMWcwslHXHKwvJmDw61+1wrlcgbLpmY8fM4OGLHug1vLHnWrpMekuI L4FeoMkwl45r7OMC/jVay1WTe++0b3n3D3Ms5YiwNYHfLN6g57/saCcYqKE/fo7xPYja SmzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=PDwCDzUe; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k27si2324823eje.568.2021.01.21.15.27.09; Thu, 21 Jan 2021 15:27:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=PDwCDzUe; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726213AbhAUXZL (ORCPT + 99 others); Thu, 21 Jan 2021 18:25:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726157AbhAUXG0 (ORCPT ); Thu, 21 Jan 2021 18:06:26 -0500 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E87AC061224 for ; Thu, 21 Jan 2021 15:03:51 -0800 (PST) Received: by mail-pg1-x54a.google.com with SMTP id e2so2170342pgg.10 for ; Thu, 21 Jan 2021 15:03:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=9aiKVbqQYlPIThgTQ82dzvRvheXuBHM9UbbX1NZZwXQ=; b=PDwCDzUeRrtiDbzP8R+ZzFNkDbG94q487W93Pzf3+343mIFOYQTDkuNfSKH3Njmgwk Y1YPBbC6QmPRr4Alpg0Kx5Fm+v1IdyCTm0Yg+e6vqeauAts8m3c9NJ8uXTDII+85pRDd 2zUYu2cZLlMKY7g0UyvFFR98CJuJd0CliHcYVfg1y0sE3TBQVxqi4Mn51kTipxxQG9lG SAQqsDMxW+8p4X4CfWdq2yc9jdOF0n7jVQ9JmayBBNV1rw54mgpTduxHdebVkhVQO2xM HGr4GC96GJ5HXmQ+RoPWclxW98DPjcCU93GdDJbQ7hQnKT4gdwYR/sa5P6nZIJsn4WW3 1bXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=9aiKVbqQYlPIThgTQ82dzvRvheXuBHM9UbbX1NZZwXQ=; b=GuaEkJjqAcd/LZjLsN2NfSIGfzBHjaYLyKy9MU2NeD4m6OmP5J+hJ0E/3dm1gAZl3N fM7EULfzjPQOw4jvND/Ohsqo9xapTvtlQzoiUraa/H6dCLHirCUKuG8vyA1FNIPfVlPZ 4GZfeNxt6pwuT0bsfyuzlR6HQu5kAws9NYuFNkHINOoksJlZFtV9Cp48y4RgUSXjaZ2o h9dnJJwRj+KQmBmYtw0udHs8mAx+CYW6RQy1X8nSelRGq7j7D7t4SbWvbB7+eZKp94bu 4I3Fy40XoJhqgQAY9vuriIZV+gQhvFYq+JCW5yCZSbuBUmlrFdl6Pug0GdypzXSsuc8q T0xQ== X-Gm-Message-State: AOAM532g+kX8lEOcal3RsykUD4fl06fTWhjJgJLbAE7fYlyhaaEC11fo o5PWfmXgAFfbIaexeDu8Sw9nfw3htB0= Sender: "satyat via sendgmr" X-Received: from satyaprateek.c.googlers.com ([fda3:e722:ac3:10:24:72f4:c0a8:1092]) (user=satyat job=sendgmr) by 2002:a62:37c7:0:b029:1aa:22ea:537d with SMTP id e190-20020a6237c70000b02901aa22ea537dmr1803778pfa.56.1611270230981; Thu, 21 Jan 2021 15:03:50 -0800 (PST) Date: Thu, 21 Jan 2021 23:03:34 +0000 In-Reply-To: <20210121230336.1373726-1-satyat@google.com> Message-Id: <20210121230336.1373726-7-satyat@google.com> Mime-Version: 1.0 References: <20210121230336.1373726-1-satyat@google.com> X-Mailer: git-send-email 2.30.0.280.ga3ce27912f-goog Subject: [PATCH v8 6/8] ext4: support direct I/O with fscrypt using blk-crypto From: Satya Tangirala To: "Theodore Y . Ts'o" , Jaegeuk Kim , Eric Biggers , Chao Yu , Jens Axboe , "Darrick J . Wong" Cc: linux-kernel@vger.kernel.org, linux-fscrypt@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-xfs@vger.kernel.org, linux-block@vger.kernel.org, linux-ext4@vger.kernel.org, Eric Biggers , Satya Tangirala Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Eric Biggers Wire up ext4 with fscrypt direct I/O support. Direct I/O with fscrypt is only supported through blk-crypto (i.e. CONFIG_BLK_INLINE_ENCRYPTION must have been enabled, the 'inlinecrypt' mount option must have been specified, and either hardware inline encryption support must be present or CONFIG_BLK_INLINE_ENCYRPTION_FALLBACK must have been enabled). Further, direct I/O on encrypted files is only supported when the *length* of the I/O is aligned to the filesystem block size (which is *not* necessarily the same as the block device's block size). fscrypt_limit_io_blocks() is called before setting up the iomap to ensure that the blocks of each bio that iomap will submit will have contiguous DUNs. Note that fscrypt_limit_io_blocks() is normally a no-op, as normally the DUNs simply increment along with the logical blocks. But it's needed to handle an edge case in one of the fscrypt IV generation methods. Signed-off-by: Eric Biggers Co-developed-by: Satya Tangirala Signed-off-by: Satya Tangirala Reviewed-by: Jaegeuk Kim Acked-by: Theodore Ts'o --- fs/ext4/file.c | 10 ++++++---- fs/ext4/inode.c | 7 +++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/fs/ext4/file.c b/fs/ext4/file.c index 349b27f0dda0..77681ba5e6cc 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -36,9 +36,11 @@ #include "acl.h" #include "truncate.h" -static bool ext4_dio_supported(struct inode *inode) +static bool ext4_dio_supported(struct kiocb *iocb, struct iov_iter *iter) { - if (IS_ENABLED(CONFIG_FS_ENCRYPTION) && IS_ENCRYPTED(inode)) + struct inode *inode = file_inode(iocb->ki_filp); + + if (!fscrypt_dio_supported(iocb, iter)) return false; if (fsverity_active(inode)) return false; @@ -61,7 +63,7 @@ static ssize_t ext4_dio_read_iter(struct kiocb *iocb, struct iov_iter *to) inode_lock_shared(inode); } - if (!ext4_dio_supported(inode)) { + if (!ext4_dio_supported(iocb, to)) { inode_unlock_shared(inode); /* * Fallback to buffered I/O if the operation being performed on @@ -495,7 +497,7 @@ static ssize_t ext4_dio_write_iter(struct kiocb *iocb, struct iov_iter *from) } /* Fallback to buffered I/O if the inode does not support direct I/O. */ - if (!ext4_dio_supported(inode)) { + if (!ext4_dio_supported(iocb, from)) { if (ilock_shared) inode_unlock_shared(inode); else diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index c173c8405856..e5407699ce92 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3482,6 +3482,13 @@ static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length, if (ret < 0) return ret; out: + /* + * When inline encryption is enabled, sometimes I/O to an encrypted file + * has to be broken up to guarantee DUN contiguity. Handle this by + * limiting the length of the mapping returned. + */ + map.m_len = fscrypt_limit_io_blocks(inode, map.m_lblk, map.m_len); + ext4_set_iomap(inode, iomap, &map, offset, length); return 0; -- 2.30.0.280.ga3ce27912f-goog