Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp2400195ybh; Fri, 24 Jul 2020 11:45:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxsf/luyYKQkwHVLDCx6sjwO97/s/RteiqW1rNl95GkZXOY69nBCr09S7K2bVj4+/cb+DpI X-Received: by 2002:a05:6402:206d:: with SMTP id bd13mr3798419edb.57.1595616352489; Fri, 24 Jul 2020 11:45:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595616352; cv=none; d=google.com; s=arc-20160816; b=g6k9QloIkhMIzXv97gpI2KpoCSi8ehVjCDF6qlb+zFQOposESluJB+/Zc4JNgeGPNf bV6tZ0C97cPS/xGpCc7hkvQCl3hRaj+jF/NtiL4LIL+LqkK0q5+5l9+oLvDtyiUdSZk+ K0I70ob8qcP/6lNL4WBR9vp5RCWhA24BB7JKsHEaRAZT0BJm8Ek2vJWNvkAL96grIrM8 OXecdcAMKfTQKwU3br69T1q2Zp5wRwtwTANsMKqyDxKLSs/VeHj4QjUHjBzMZXlw75KQ 7Qi1AOVKFn00qwvlfvNUAd9wSfLWQWf7P3AOk0scHBcwTF68IaBugUlW20yNhxCHYVal CVRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=r8Pg6JmNaFN8fVBskJ954zlZvlkSSoV1f+xmIU4eJ8Y=; b=xFc7QWBpOR8LOISLgsIBsHyFzOtRSQXe96MhblYHkkMowclfzr6y+9KFBPx21Br4MZ luoTQCvsdl7fY8cEkRN7Tbb4kaptv1mIhj48n0N+LU/KTs4yr67XklGxyf084rbSOfzR 3PJuPd0x2Ip0XK2szQ4MKKJntuWIU2ZG/HCce+Pd0uMVU3SZyCMSLCLSkXt6GMx13M3O 2YLenNX85wR9UIpbChAkQjhfik9wDJpmlfg/qKkX6fInkM9PWGTZmtYDPOdJd5yMvoKl t1Ely5d8PA8h2846lIqmQOWw5TcfaFUx7FoBozViXHgjA6tPOa6dNDgvTg30bzY8+Qxh lbWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=WZxif6+6; 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 c15si1001510edw.265.2020.07.24.11.45.28; Fri, 24 Jul 2020 11:45:52 -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=WZxif6+6; 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 S1726870AbgGXSpT (ORCPT + 99 others); Fri, 24 Jul 2020 14:45:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726617AbgGXSpN (ORCPT ); Fri, 24 Jul 2020 14:45:13 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 813D2C0619E4 for ; Fri, 24 Jul 2020 11:45:13 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id v11so4325428ybm.22 for ; Fri, 24 Jul 2020 11:45:13 -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=r8Pg6JmNaFN8fVBskJ954zlZvlkSSoV1f+xmIU4eJ8Y=; b=WZxif6+6SPfu0xTeldRLQ3uzvhiQHHPuJ3wvszADxxQXo+kraJNCkoW2SjaTiCI/fA tjr/RHdHC2utCZI6gqsTf6bi248HQE4FH8OeQ3i5z7Mjm/erk6l9Hs4KAFgiNnGSoJzQ +wFpox/AoKBdgYO6JL/4Pt7vSNaTodsgMpvLea+xlBamKo2Zp7mdiwk8z3K+1O4pvHHT Zn4bWRPvpRwh7o3cHRLAUqjDHP0wki5gObcM3HhSBidRJ187n9QJXUzMC2M7ubEQa66B ltnFBglVcP3vBXxYW+dKa0oTYE+kv+oO/LBgR0e2hn6tgE0m1OcMFNfOm3F+WYqCTZ6H wMlQ== 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=r8Pg6JmNaFN8fVBskJ954zlZvlkSSoV1f+xmIU4eJ8Y=; b=ls/rmvMD3N+Y+q9F52zhlXxqAXuSw6+Fc/cQZ/3+Nx8DYglSa0RCCVPgWwwYDK49F6 hjDzvyexJLb17JR3VgKgEoYYHabCwv1/YeAXbeHa2eGcvEYkf0FT1ruNGGdMs9Q8Yb4h ylyr6sCAsuqqxcB60Lhgy+AuoVTh0p/kRF1JpjKkyJwXAs/54C1qK+bCkxVRXVXlT/r9 scacASBuVg5Ku+1O47wIwPHAov+aQSaIEW60I9FSW0bVQxkWXyE5BpCG2S+f0/JnXXg5 vJ9XpHP1BhOaQe6dAdxNtX7UZGa0q92pGPkqsdc6LREXYOWDj1UK/OEKdcHWVJpDxxEl wReQ== X-Gm-Message-State: AOAM533cSQ9Smze5ta2hu9gv3gZUTcpIndE7OZ/qKmKrhsLWXH1dh4nH p/yi2exrjZf1kdBe2pDL3G1prgleGHU= X-Received: by 2002:a25:6c8a:: with SMTP id h132mr17095635ybc.353.1595616312763; Fri, 24 Jul 2020 11:45:12 -0700 (PDT) Date: Fri, 24 Jul 2020 18:44:58 +0000 In-Reply-To: <20200724184501.1651378-1-satyat@google.com> Message-Id: <20200724184501.1651378-5-satyat@google.com> Mime-Version: 1.0 References: <20200724184501.1651378-1-satyat@google.com> X-Mailer: git-send-email 2.28.0.rc0.142.g3c755180ce-goog Subject: [PATCH v6 4/7] ext4: support direct I/O with fscrypt using blk-crypto From: Satya Tangirala To: linux-fscrypt@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-ext4@vger.kernel.org Cc: linux-xfs@vger.kernel.org, Eric Biggers , Satya Tangirala , Jaegeuk Kim Content-Type: text/plain; charset="UTF-8" Sender: linux-ext4-owner@vger.kernel.org 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 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 --- 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 2a01e31a032c..d534f72675d9 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 @@ -490,7 +492,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 44bad4bb8831..6725116ea348 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3445,6 +3445,13 @@ static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length, if (ret < 0) return ret; + /* + * 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.28.0.rc0.142.g3c755180ce-goog