Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp1950744rdb; Thu, 7 Dec 2023 13:31:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IG/x+X8FpmV0s2EbMrEW3Y690xHcUX8XOAyCc6FcFZfxyghTLhbLDahRS3fIUZxg8iPlEfg X-Received: by 2002:a17:902:7842:b0:1d0:8876:7082 with SMTP id e2-20020a170902784200b001d088767082mr2546411pln.72.1701984704338; Thu, 07 Dec 2023 13:31:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701984704; cv=none; d=google.com; s=arc-20160816; b=UCPH7IWNW6IENrS/WqFsqeEiihshq5SuQH1jMcMmp8FW9ZynQ5Vb4a4V4XDZxLqJ4r HMcDPkdga6q7PKK4+vTC67tZhObA4f5tsfeGJG/b28H93Q47fPJIFJRqHqcRFUkDQoRj PV00jNpCY/5vdcEuulznQGXHStEOXa8taHUmpMM65vH4ai3V4bsBr7cnK6yxqijDS9VC QGayKQ+aLOTbA/eqOhH0LFH6G9fUfmnuhyRPcrIBxw0edVxtwzh8HsU4X5GwyGvRD78K v6sLCIfN1kgYhrdaBiLpwRgK5o/ZVm9i0dI1JRuWdkdr2iM1sBhLE6dzc1D4bysaZYZ2 ePzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=5weY3TAEZXAYDCmBDEVYygYM1kFM1iNPdRbIVf5ORpg=; fh=ib4gl95HfLmZdfX9QIMf3rTepWCH9JlNymcDKJTPhJg=; b=P7R4jV9nJgB0cPwwK6azQnXExSc0IKxsBCCwVqf3JlTinNFk/lSa5PVdU1Q948H5yd i8fDASDlUJS+4tOBe36IThmWVEqJWRLeDiQh76YzzRNI/vhDm3HjM9qbexsvynJq18cq KSAIjxcbuAg3PX0SkeBhVC4+Xwqozxirky6axeU8Gq+ojpJNU/pu0UTislKFiwy5ZhpM DKI+E5RmggeO1AFFDVQO4vo2CkrDQtqqnnNDWwdadW7H8JcerVZfUYvL4cYMfu5K5V/o g9Jy16WoKhkQU47b/Qk3X2ADHO0//1dpq7uRcJpkLXO+uSAzWbBQ2mL1FOT13qLrvjgB Qwig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HNFE21MJ; spf=pass (google.com: domain of linux-nfs+bounces-418-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-nfs+bounces-418-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id b18-20020a170903229200b001cfd0fe5125si370242plh.290.2023.12.07.13.31.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 13:31:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs+bounces-418-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HNFE21MJ; spf=pass (google.com: domain of linux-nfs+bounces-418-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-nfs+bounces-418-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id EC2ECB211FD for ; Thu, 7 Dec 2023 21:30:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F09A775418; Thu, 7 Dec 2023 21:25:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="HNFE21MJ" X-Original-To: linux-nfs@vger.kernel.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30D274203 for ; Thu, 7 Dec 2023 13:24:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701984268; 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=5weY3TAEZXAYDCmBDEVYygYM1kFM1iNPdRbIVf5ORpg=; b=HNFE21MJOlfvCvf7jDrkofaQdJEvCJK4J4ZWEDCTJBiWd72Z/9l9UCdaiWWzppjMwX3CSd a1lk/kazpvev1PZnjhyLpHQ2Pglj2XuE4g0ohAOw4iSnRcptoPS1BFlLm6gToSJ6cRS75C 5AsfdqSd/dSWs6BgYCyEmR+C/lIlG40= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-641-qyXwTIyJO_uXXDNIGmcfsw-1; Thu, 07 Dec 2023 16:24:26 -0500 X-MC-Unique: qyXwTIyJO_uXXDNIGmcfsw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A05CA870820; Thu, 7 Dec 2023 21:24:25 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.161]) by smtp.corp.redhat.com (Postfix) with ESMTP id 096233C2E; Thu, 7 Dec 2023 21:24:22 +0000 (UTC) From: David Howells To: Jeff Layton , Steve French Cc: David Howells , Matthew Wilcox , Marc Dionne , Paulo Alcantara , Shyam Prasad N , Tom Talpey , Dominique Martinet , Eric Van Hensbergen , Ilya Dryomov , Christian Brauner , linux-cachefs@redhat.com, linux-afs@lists.infradead.org, linux-cifs@vger.kernel.org, linux-nfs@vger.kernel.org, ceph-devel@vger.kernel.org, v9fs@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 39/59] netfs: Support decryption on ubuffered/DIO read Date: Thu, 7 Dec 2023 21:21:46 +0000 Message-ID: <20231207212206.1379128-40-dhowells@redhat.com> In-Reply-To: <20231207212206.1379128-1-dhowells@redhat.com> References: <20231207212206.1379128-1-dhowells@redhat.com> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 Support unbuffered and direct I/O reads from an encrypted file. This may require making a larger read than is required into a bounce buffer and copying out the required bits. We don't decrypt in-place in the user buffer lest userspace interfere and muck up the decryption. Signed-off-by: David Howells cc: Jeff Layton cc: linux-cachefs@redhat.com cc: linux-fsdevel@vger.kernel.org cc: linux-mm@kvack.org --- fs/netfs/direct_read.c | 10 ++++++++++ fs/netfs/internal.h | 17 +++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/fs/netfs/direct_read.c b/fs/netfs/direct_read.c index 52ad8fa66dd5..158719b56900 100644 --- a/fs/netfs/direct_read.c +++ b/fs/netfs/direct_read.c @@ -181,6 +181,16 @@ static ssize_t netfs_unbuffered_read_iter_locked(struct kiocb *iocb, struct iov_ iov_iter_advance(iter, orig_count); } + /* If we're going to do decryption or decompression, we're going to + * need a bounce buffer - and if the data is misaligned for the crypto + * algorithm, we decrypt in place and then copy. + */ + if (test_bit(NETFS_RREQ_CONTENT_ENCRYPTION, &rreq->flags)) { + if (!netfs_is_crypto_aligned(rreq, iter)) + __set_bit(NETFS_RREQ_CRYPT_IN_PLACE, &rreq->flags); + __set_bit(NETFS_RREQ_USE_BOUNCE_BUFFER, &rreq->flags); + } + /* If we're going to use a bounce buffer, we need to set it up. We * will then need to pad the request out to the minimum block size. */ diff --git a/fs/netfs/internal.h b/fs/netfs/internal.h index b6c142ef996a..7180e2931189 100644 --- a/fs/netfs/internal.h +++ b/fs/netfs/internal.h @@ -198,6 +198,23 @@ static inline void netfs_put_group_many(struct netfs_group *netfs_group, int nr) netfs_group->free(netfs_group); } +/* + * Check to see if a buffer aligns with the crypto unit block size. If it + * doesn't the crypto layer is going to copy all the data - in which case + * relying on the crypto op for a free copy is pointless. + */ +static inline bool netfs_is_crypto_aligned(struct netfs_io_request *rreq, + struct iov_iter *iter) +{ + struct netfs_inode *ctx = netfs_inode(rreq->inode); + unsigned long align, mask = (1UL << ctx->min_bshift) - 1; + + if (!ctx->min_bshift) + return true; + align = iov_iter_alignment(iter); + return (align & mask) == 0; +} + /* * fscache-cache.c */