Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp1075973rdg; Fri, 13 Oct 2023 09:28:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEnkfGa8ZxuPDzHe6D456TcJv+jrpb6cf0LpwkJAxngkG3OwrUH7JVwjudu6bGkDEd1JZJZ X-Received: by 2002:a05:6a20:da9e:b0:16c:b514:a4c2 with SMTP id iy30-20020a056a20da9e00b0016cb514a4c2mr22492568pzb.16.1697214510979; Fri, 13 Oct 2023 09:28:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697214510; cv=none; d=google.com; s=arc-20160816; b=eKXx887LY3j1qXstxA6gJYkCUbvCXXRF3jTkVeWSCGMgMmWrtYCZCC4SQ5wXfwdznH bJLCidaNJP8qVSNxp9MT2jc65mgVovZWo/1ydpQMhEIT9roG+/pFdpdKSmHE4gICazR5 a6+67WfJU3ckEb7kCNRQ5+HO+6GgIigtlf8kezJjmyjlmsmkQXSOzR+fpRVbnyQEgTrt NnDVCrtoNfmdAupkDUX/WWnh6CaeoHrEt4SqV5z82Kcp0pH7hwG4p+UJLW43kvtk/gr9 XelkjKmv/iutdOKqJrIDGFXkUP2FYJURGrvMVazvcaKwEV1QXYnTPLVb94/88TWpz0Bv QusA== 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=QdFa/dxqwrihf1ZMFwRJBWJsl8hSozQZEOt+FKZWmzU=; fh=QCasRecNkSMoqSQLnZiX89u33dCID3L05AOtURpI2pA=; b=uMLzr/zDJP1M9OCBXBXD8BBnOG0i8HemnXWh1WNOj/88FdSa53qHKTe3SGa8bzB3VR KLx6LPg+vblvAhChr1c4Bh+eg7uhfUuFfGetxcrJ69AhQRLwOX6s5kewhp4DHpJ3EPvz KwUTr7MGAQCC0kN6nT6RGo7aa0h2V2A3hdXAM9k4UhcLa8xEiY4hhSfpsf1ZoJK+zM2/ kIKHSsizliU0GHa/XGYyLUFOAQ8mpCdjGIV25m2oGdlMA1NUGfTmgZrXeAKjPGiwv+06 k5/WL29z8WisQMJGU9frHLlztdYcDtEhnpqKi7+mUJllR+7EZInUP01zXmKuIoJ9Fj0J J28g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=U4eahnmp; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id g20-20020a17090ace9400b00273f61d8773si374353pju.160.2023.10.13.09.28.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 09:28:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=U4eahnmp; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (Postfix) with ESMTP id 78CEE83CD967; Fri, 13 Oct 2023 09:28:28 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232786AbjJMQ2X (ORCPT + 99 others); Fri, 13 Oct 2023 12:28:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231489AbjJMQ1o (ORCPT ); Fri, 13 Oct 2023 12:27:44 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D605F268A for ; Fri, 13 Oct 2023 09:06:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697213202; 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=QdFa/dxqwrihf1ZMFwRJBWJsl8hSozQZEOt+FKZWmzU=; b=U4eahnmppgHhXfezVpYkpUtFvIwM3PKwf7eiVa0eHPBB3RF7+dkwtLOM/4MrxnAawvVu4k ouEmbFWBCoAstI/PqnChU5i4r5KlZv2WARZGJklCeT9PxHvZ8ug/ugZ1uciOhytMEvp3TL IvFQNRZCFWF2F822Lg9TbxZQxfC0jfE= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-354-bIkAoftxPQSMUL0pN1n9yw-1; Fri, 13 Oct 2023 12:06:38 -0400 X-MC-Unique: bIkAoftxPQSMUL0pN1n9yw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 76A6A1C09A56; Fri, 13 Oct 2023 16:06:37 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.226]) by smtp.corp.redhat.com (Postfix) with ESMTP id E310525C1; Fri, 13 Oct 2023 16:06:33 +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-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, linux-cachefs@redhat.com Subject: [RFC PATCH 37/53] netfs: Support decryption on ubuffered/DIO read Date: Fri, 13 Oct 2023 17:04:06 +0100 Message-ID: <20231013160423.2218093-38-dhowells@redhat.com> In-Reply-To: <20231013160423.2218093-1-dhowells@redhat.com> References: <20231013160423.2218093-1-dhowells@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email 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 (morse.vger.email [0.0.0.0]); Fri, 13 Oct 2023 09:28:28 -0700 (PDT) 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 8dc68a75d6cd..7dd37d3aff3f 100644 --- a/fs/netfs/internal.h +++ b/fs/netfs/internal.h @@ -196,6 +196,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