From patchwork Fri Nov 17 21:15:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13459592 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D30E0C5ACB3 for ; Fri, 17 Nov 2023 21:18:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 62B118D005A; Fri, 17 Nov 2023 16:18:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5CF0A8D001C; Fri, 17 Nov 2023 16:18:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 422C68D005A; Fri, 17 Nov 2023 16:18:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 302248D001C for ; Fri, 17 Nov 2023 16:18:15 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 105A4B61D5 for ; Fri, 17 Nov 2023 21:18:15 +0000 (UTC) X-FDA: 81468709350.05.24D50CE Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf23.hostedemail.com (Postfix) with ESMTP id 618F714001B for ; Fri, 17 Nov 2023 21:18:13 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=KMPPN2tO; spf=pass (imf23.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700255893; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=5Qasw+3DRr0CW1YV8TSL9wIAaCWlUGU8d7+6bcjpE3Y=; b=CyJudMxgYzuMBEfjXsSQlphEKmzFQ3wOpY2a846TuSI2Vi/cWNTAVISAiC43nZufCKQaBD 0d97KnJPs+IwFatZ97L7LwjwL36fzxm4UfYMLKp6/UvMAjNiN/or7Z1mKL6LyY5P3823mE Xyb7hk6G0hpzAAA+dBIGo8yYBAvreUI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700255893; a=rsa-sha256; cv=none; b=JXVYh8YF5g5tgpJsm4e4MkzDmdhIysRJi5ojWITifsaxPQ+5kGUmjHKg60eLlDIIyRB0Ym YxNGh5uS8mhmae4AACvGO/Ops8SPMKNCxaNGmjmJsnZTfBPiry3/Gx66Czh1IMSX4mlvJV lwTwpuxCCXiDesTLNRb6FfX6SpsWKJ0= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=KMPPN2tO; spf=pass (imf23.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700255892; 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=KMPPN2tONXGg8a7D0Fe0dPuF0YoQ0CGhxYKepz5AUE8YRVW6+Nwd1bkWppdG4n6H0Vyz8q Tj/IsUSjOHVjACpHXhC+uTtyiKEMY0vsLd5swgh5kzQqOugAQSXRYKoG1Sj62Jo/EIId85 VqTTJd0ThECWWd798Rs477RFf69F1T8= 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 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 X-Rspamd-Queue-Id: 618F714001B X-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Pu4 aIM4CkSmHR8GYDIanJbo62/eD+6Grpi+VqtuBgWioOx/J0gndcEAmo1+GntDb5J1YKhEPoKy8+cCs3F+0YIGRF0EgEOhbiEs25ONBsO9pRNY92jbrGYmDi5aReTXSKixJKwQLpN640CuZcDLM6KQhjritGSoBZBfP1q5twB11XmIonCfh8VprT/vPaF28xqoVqJVnLg5y575TBnFPCKuA/Hda+O4NPqJFg7H8dW/LoQMRQgkm1fhJcX4QBWVUUSJimy0oz7+4VpBA67GvNk6i4GIuUuCjBKiHExLx8hNiqF0VvkQ= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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