Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1424553pxj; Fri, 4 Jun 2021 14:12:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyKdif8jY9FhP/MCqYLFJIgolhxfxG3IyT9IiQ3n/XNJDsGsjyO7wQyM5pNm4gWSLwNcejK X-Received: by 2002:a17:906:1c49:: with SMTP id l9mr6078724ejg.39.1622841124071; Fri, 04 Jun 2021 14:12:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622841124; cv=none; d=google.com; s=arc-20160816; b=oYP8yK3oCPWUux3hlPRocY6oM96gYxmd6GEfEgVmJ5mK82v5P7QJNN0WCJGn/pDDPG Vk9bLSBZBN7yhp3PnxA1ozugNcd2HMMBlPivEnetTRmshhdKFz6qUJfjWtbAIh46kGJa j1HNPqcLppfvdepeOwwwjec7yKg8EzkETRi1CFwakFxxLTPgv65YZg3S6YOvbA82URF+ mjvPriPOJmCOxfVN4i32GPwRLp7k2keAN3twtgSz21PHD8Nc2K8iZm+us8za6VqJ4KGY jQEXNI9xPp8+6tLuyP8WR1SJs87d8YkOZI39Hpw/fitIbgdg9q4M1bayi4D7Emn9Cln/ WDCA== 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:dkim-signature; bh=H6v2kY5YMxOOHLcLSDdX+aEzIdLNYM1I0EjO3txeols=; b=Ga9oWqMjnq6BZoVNCPdl15eNd9JGmxFstLnQePJNXa5gjhCuGlg7R4NB/kzG+8tkMb dlyI3LFaQd6AOiLbPuVjozBG2AGYqjEM74ct1r5iyjLhEgPMOeiNUtxOof1/Et2sLYQx SpltPXzB96bfrIovgWfkwfrsdlsLgFbSE40UW9ml1UqFVMji+ud6y6+759aewJAizHuv d33aQQ0CGJw8/6X1ILDNkSQM3vQV3fMHapTe155CXMcx50PUaqOHfKyPrcHa4n24NZNB wY1cKGqom8yM8qq6UjHGZyaMEjdcb94tlG8wsR289+qCayMWu4H8fGmdyJnj2WKWYpkJ P1Pw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=v1jZNkJY; 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 m9si5388057ejn.195.2021.06.04.14.11.33; Fri, 04 Jun 2021 14:12:04 -0700 (PDT) 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=v1jZNkJY; 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 S231512AbhFDVML (ORCPT + 99 others); Fri, 4 Jun 2021 17:12:11 -0400 Received: from mail-pg1-f202.google.com ([209.85.215.202]:47088 "EHLO mail-pg1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231488AbhFDVMK (ORCPT ); Fri, 4 Jun 2021 17:12:10 -0400 Received: by mail-pg1-f202.google.com with SMTP id v12-20020a63d54c0000b02902167d3d2f08so6667560pgi.13 for ; Fri, 04 Jun 2021 14:10:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=H6v2kY5YMxOOHLcLSDdX+aEzIdLNYM1I0EjO3txeols=; b=v1jZNkJYmY3AfKMvuvpfH3JJQcdV29JlvKaiWzw7Pj5dPY3hbHoKohjT3M1SqQ5FFz G/tUkYjzmPiXLBY61CpYrnU7ZI7tvTpp2CBXGHl/LyoFPLLKRvPxUy+N+cPRdapDxLeC Z8Eh4SoflqHue1COLbTamqv01t/mA8CE1LJwQOBgEgyAryAOTaY7MJlPrjluNTGeAint /gc5P2jZaZ3YZjQRytNEvbbEzCD+sJ/qkVZK7oysVmpkIMUsp5TFiGLVJL+HI3o0vFAa ewZH43cN3mTTq1bKsTBmIoWlxjxTnjXv2d97I3HYY+lA+lAakvigohnk7CHOmQBQGEy1 o3Fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=H6v2kY5YMxOOHLcLSDdX+aEzIdLNYM1I0EjO3txeols=; b=ltRtvTeBa9nVoi+NLhEKJ/snpOJeLFeIW7ZgMmg7gbiHLB+QNqYEIiDHjmwlRQgILX fxAa+gFA9qxVMi8r1GNRSa/zukeJwq6UQjMOum15xJsjczj+vkDKraivjsuqLOWe1JBm ODgDEv0rRJnhV1/fIEuO0gwhRpZNHQ4EAHgkYGnBbKXq+hhutBXzFQw6xGTlsXBQwRKH QPOx6AiThenwrsyQNTtKUE+e0kMcReX6Utr9Lz+tROeH21+uZmdBfNR0tn9pQnCZRHJ5 DBs1nwU9cv1iJn+Zq/t8NQVm3V6C4+Td/bZ1imJnQtYCkoIKfCq7rUjdiIqez/G7tSd/ YwUQ== X-Gm-Message-State: AOAM532o+kk0HIsoHSkmSkX89ZE7y2LxT1yuXN2XJBpXhBRuDKwBUYM9 IPPLcNZubJ+y2lFxSlYKt00VvGuQYbY= X-Received: from satyaprateek.c.googlers.com ([fda3:e722:ac3:10:24:72f4:c0a8:1092]) (user=satyat job=sendgmr) by 2002:a17:902:6acb:b029:fc:4d8c:cfba with SMTP id i11-20020a1709026acbb02900fc4d8ccfbamr6249435plt.29.1622840963331; Fri, 04 Jun 2021 14:09:23 -0700 (PDT) Date: Fri, 4 Jun 2021 21:09:06 +0000 In-Reply-To: <20210604210908.2105870-1-satyat@google.com> Message-Id: <20210604210908.2105870-8-satyat@google.com> Mime-Version: 1.0 References: <20210604210908.2105870-1-satyat@google.com> X-Mailer: git-send-email 2.32.0.rc1.229.g3e70b5a671-goog Subject: [PATCH v9 7/9] 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 816dedcbd541..a2898a496c4e 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 @@ -511,7 +513,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 fe6045a46599..fe8006efb5ef 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3481,6 +3481,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.32.0.rc1.229.g3e70b5a671-goog