Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp805128rdb; Fri, 17 Nov 2023 13:19:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IGORrRBBcYS+xJyITCuG6O6/cYCUuB9uejbJXMfMT4ja1UlGJbnP4n5+TRVqpa0kb4Fj2V4 X-Received: by 2002:a17:90b:3852:b0:27d:8a04:f964 with SMTP id nl18-20020a17090b385200b0027d8a04f964mr324303pjb.24.1700255994821; Fri, 17 Nov 2023 13:19:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700255994; cv=none; d=google.com; s=arc-20160816; b=MK6Eui+acglHlJLsAQn/hrCeoo88n2eGyzhtN95IzjGBRJ9WjGeH05zi60ddfOCEph Mzo2XdbM5RrNnV5PpOSTThxwR7ClYukCLkCbgF1SCZfslF71XVJ4wubWC6n2g4L60v5N 4ZaYmL13XxvirbgKVQpre5fRC4dWSZ62FYu9lVChjPibaUGO5kZfaA/lJVd+iaLJzi9Y TGoD1R6fWZVAJvEwaWcoV4aQ+5Xzjity0tNUpT1gUhMZfjQO1H9tfQiSShtbkeJEoRO+ d7x1/3EJTd63IOBfMozj/qYb/mxMjrbJIN7T7NgpviiF3NY1/a2Rytz72wrbYTFc/Lg8 qBkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5Qasw+3DRr0CW1YV8TSL9wIAaCWlUGU8d7+6bcjpE3Y=; fh=lVY/c7gYUTDnyYYKKvGQU3Q29dA69hck6eN/HP5dBQ0=; b=z86bIBneCX9VyOJnWuVbE8w2R9c6XNvknUEaOtD/B7yJlxEeh8em1AYoCaIQsxYgV4 LNtZ2yfNvp1fqPBxZHWjGMuHqGck4OjyCw2yaAJviRNgcBdThz9m7iukm3N22Qp+awfO f7UG6m5HE9gOk91dqEGPt9ZStsXe2uTIlp840lntGhlmroczL57Y+ERflDylyjnzkEfh y/ow9iOBCrwedpL7PZUYw0pRT4N0I01kpGoF1F0W0GF9KM+aUZuGHQeuKpl96KoKQ/ZL tItzB+fnq5pMbsTMru1RdNLpRZskBfsRCAD5yNpQXg9zRRzMjiiHBaW+0K1DcfwF7OrL Llpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dcTCBZdf; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id mq16-20020a17090b381000b0028098007c8csi5507602pjb.84.2023.11.17.13.19.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 13:19:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dcTCBZdf; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id DEF2C82CA0C3; Fri, 17 Nov 2023 13:19:52 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346314AbjKQVTl (ORCPT + 99 others); Fri, 17 Nov 2023 16:19:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346336AbjKQVTZ (ORCPT ); Fri, 17 Nov 2023 16:19:25 -0500 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 6B911170F for ; Fri, 17 Nov 2023 13:18:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700255893; 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=5Qasw+3DRr0CW1YV8TSL9wIAaCWlUGU8d7+6bcjpE3Y=; b=dcTCBZdfDP3xInv6XUFCARp1O/Qj6IN9fnCe+XngHXJTPS6CRbjlBr2enxfTjARFiUsqj9 l0eEiq0aUeCl45esDPH/9uJR/8hy6VjE7t8PFFdMs5w6edlWWnmLBa5ptxuDnVN6W65a6m 8BhcWUerPk2h9vpKRI3PIqn3HyY8n1Q= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-453-rAZg2Yx3M1y0duiuqxkUIg-1; Fri, 17 Nov 2023 16:18:08 -0500 X-MC-Unique: rAZg2Yx3M1y0duiuqxkUIg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (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 BD1A33C0C48C; Fri, 17 Nov 2023 21:18:06 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 29E541121306; Fri, 17 Nov 2023 21:18:04 +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 , 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 v2 35/51] netfs: Support decryption on ubuffered/DIO read Date: Fri, 17 Nov 2023 21:15:27 +0000 Message-ID: <20231117211544.1740466-36-dhowells@redhat.com> In-Reply-To: <20231117211544.1740466-1-dhowells@redhat.com> References: <20231117211544.1740466-1-dhowells@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 17 Nov 2023 13:19:53 -0800 (PST) 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 fbecfd9b3174..447a67301329 100644 --- a/fs/netfs/internal.h +++ b/fs/netfs/internal.h @@ -193,6 +193,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; +} + /*****************************************************************************/ /* * debug tracing