From patchwork Wed Aug 14 20:38:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13763962 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 262B7C3DA4A for ; Wed, 14 Aug 2024 20:40:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B6F126B00AB; Wed, 14 Aug 2024 16:40:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B1BC26B00AC; Wed, 14 Aug 2024 16:40:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 996E36B00AD; Wed, 14 Aug 2024 16:40:57 -0400 (EDT) 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 797F96B00AB for ; Wed, 14 Aug 2024 16:40:57 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 3807F12118E for ; Wed, 14 Aug 2024 20:40:57 +0000 (UTC) X-FDA: 82452020154.24.329C898 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf05.hostedemail.com (Postfix) with ESMTP id 540E0100023 for ; Wed, 14 Aug 2024 20:40:55 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UIWYoXu2; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf05.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723667996; a=rsa-sha256; cv=none; b=iZdClUtc6YKitSxXBm0bTmT68zbvi0X8AZ5QK5E/kMU3LuVVUSMCMi/x8ufw7LRZvDG1ej s80c8G7RhnBIVN3/Glxv812aC6Jl1I5uDEWusHJc4vTPoqxZeYqXaxCVZ9V2DW03yJZBlo uFu4e6AjwZi1yKjOhGZiLD2dOwGNxRQ= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UIWYoXu2; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf05.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723667996; 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=1RZCIFt1nFHOn2K81N2VwRb0JQpc16vDcy/7plWa8pc=; b=f6y1vXJjr8MNzLqG6UKf+KkduFgBWNZAGC+AV7r5uRRCDt2KdYZzitZ09c3dsCTAIoymS9 ELCUUMCeeJFDoVuSPnaB90jpq85pogYgZeuJVJ8El58tjmUtXMgK2SZdf/Aj1JL5sKJcFa 2iufgFpVAllkWNBS/m/xdUY3cAP4Inw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1723668054; 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=1RZCIFt1nFHOn2K81N2VwRb0JQpc16vDcy/7plWa8pc=; b=UIWYoXu2t7KFn2U7imDP2GkvlrP5IS2UBbm0K8kLUAEe3L8fAyJDmVWbQpaIRmeTNBzPwO B2EgaRalUcO0j+QL2evdMDjhkA38O+5vYdr3KafRsuJTFUqBGkkbq490sCwNeBoSJxbVUu VUMN0Uv+clrYPrPUA5n4rAN2TA0FMbE= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-641-02X665vNNgu4MYu1Px-cDA-1; Wed, 14 Aug 2024 16:40:51 -0400 X-MC-Unique: 02X665vNNgu4MYu1Px-cDA-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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 mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8BCED1955F65; Wed, 14 Aug 2024 20:40:48 +0000 (UTC) Received: from warthog.procyon.org.uk.com (unknown [10.42.28.30]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5F4AD196BE80; Wed, 14 Aug 2024 20:40:42 +0000 (UTC) From: David Howells To: Christian Brauner , Steve French , Matthew Wilcox Cc: David Howells , Jeff Layton , Gao Xiang , Dominique Martinet , Marc Dionne , Paulo Alcantara , Shyam Prasad N , Tom Talpey , Eric Van Hensbergen , Ilya Dryomov , netfs@lists.linux.dev, 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-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Steve French , Enzo Matsumiya Subject: [PATCH v2 14/25] cifs: Provide the capability to extract from ITER_FOLIOQ to RDMA SGEs Date: Wed, 14 Aug 2024 21:38:34 +0100 Message-ID: <20240814203850.2240469-15-dhowells@redhat.com> In-Reply-To: <20240814203850.2240469-1-dhowells@redhat.com> References: <20240814203850.2240469-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 540E0100023 X-Stat-Signature: ucyu7rpmpornar13jdonuik7ukbdk473 X-Rspam-User: X-HE-Tag: 1723668055-715476 X-HE-Meta: U2FsdGVkX1/jAZBEeSIIYJI74ex2+jTxGBv0OsG9fdZTiIWCOcGjoDN3jOym9G3xwnzbyEbvZ64z1+YMyIfTF9oGwS2ZPQtItxbOdBQcgwDo75MDNQcG93SKL1wtfMiM071C58EmRoyILIhVCtXqymDEB9j7Nhwntjc7vpdOT53rhGkcQErJwgNyzibchERRda5ifC++X412rd/gXLp9WQTNI2UELfoJIDx0+HbCJD4FF/jvoTKjElsSXJK1/gyHNXboIMUSMy+nkkhB6J0Re/MdcuP/6xyK2L9Gc7VCMYrnIrPFAeqqIJrcxlcdDc9DmS+FTVXKrpIW9mVCRPav7yBB+H6Y6YF3UXtOnGgogburbw84OcH4U2g9GY+XpQXfW0tnur4Ik6LRtCf+AXFJGR4x9Ak0UV23oBQGu7CiBS5DkF8bBC/nup5B2px2nY9gCDHcK+N1HZNh9GNq5GcZgYEMgH/Ovd6hTqIs01uhGmtvRRL+bMgfrOtgfIwR7gPzG+LW7phD/GtCIV3iDDbfyjB3X503Xpt3N2XBaWeBGRTUdByRHsXVvYHaUhDhP6jUBp2p6AaB6l4F/BSAAkzLj5QM8q/iquTYpI5xk5yJPjbiEyGk+r1WUvkloVpadlg8b7Etin7VgOJeIqV8ohDq1dpX/EsRS8g3rg73Ui+o2jpXp43JiUz+TUWs9zPtLnzsx4Ooq3sIrnGQaSKOmhqiUuuhwqj1rBwESLbnutGrmnXOL7Od+HH6TlGOp3QHDa3lhoA8vK0dW7FEuyIzoUWy4zGSJ17i3Jc9+YbxAxSlDpzIzlUBMySyJ3hyNw93s+roD2JtiSM8tmDL4bQypTt0+W0OtOGqsmzxyIdbyACJKmbEJMUWh0EzpEI7KR21awI2yeEyL1OJSAnhvWY4QXqpuRQ/VMw7ZY4Vz28Rh3ARUvn3Bt7Ltni20MUs9tbXdMR5s/AcVK5LliWyDkspDXI BsW15E7D u44EBPe/sQXuQevdhHNlAZqpM8JHwyfH8d18d/F2AaWNBKfor6u1MM3SnpRt/BEBAs4Mzs9kgZdb4talzkE+lVW2L4l0SEKufr5GAe8bEqQ/z2m/SBY3FUb++wAMYgjZe7zhhTNTSjYWZe8uYx6m9/GtW4lsA9VKdMHBrf0fzmP88fCt4kAg6fGZ7ZxSThUyirFC2a14X9oEay1JT27FuOP3vURLANgktO69I/x1jvZ7Ex9lJAxLg0pIfJmfaaidLZkFiTr+8M4zGWhCxMEknp7Hn9PaTb/Dkd2trG5/E9Pvte9g13r3fnKcq560hPN0fNKV/WuR/bXdBlJFXcKThVzAmcWYazLKDnI+YevfKxJA7JYmnCasuewevgn4MTk7EoFeGFcB8MGSPOWUMkaT+H7pk3pKC/Gieb/qvoDJlfYrrlcYygeRatUAUk4UfQdTSv0vPOtQJM7LBUx+lVnVO4vo74Naf/jQmD5HQ3BYxPFqALEyVBF2abx2RXYZR3Z4VCCude8fl6VWAkonm40R6zyL9Yvib1vsSymq1bLA8kckvVT2GpA5bJzqhhYdB8G/Nh76UKQgUupwkfmE= 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: Make smb_extract_iter_to_rdma() extract page fragments from an ITER_FOLIOQ iterator into RDMA SGEs. Signed-off-by: David Howells cc: Steve French cc: Paulo Alcantara cc: Tom Talpey cc: Enzo Matsumiya cc: linux-cifs@vger.kernel.org --- fs/smb/client/smbdirect.c | 71 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 68 insertions(+), 3 deletions(-) diff --git a/fs/smb/client/smbdirect.c b/fs/smb/client/smbdirect.c index 7bcc379014ca..c946b38ca825 100644 --- a/fs/smb/client/smbdirect.c +++ b/fs/smb/client/smbdirect.c @@ -6,6 +6,7 @@ */ #include #include +#include #include "smbdirect.h" #include "cifs_debug.h" #include "cifsproto.h" @@ -2463,6 +2464,8 @@ static ssize_t smb_extract_bvec_to_rdma(struct iov_iter *iter, start = 0; } + if (ret > 0) + iov_iter_advance(iter, ret); return ret; } @@ -2519,6 +2522,65 @@ static ssize_t smb_extract_kvec_to_rdma(struct iov_iter *iter, start = 0; } + if (ret > 0) + iov_iter_advance(iter, ret); + return ret; +} + +/* + * Extract folio fragments from a FOLIOQ-class iterator and add them to an RDMA + * list. The folios are not pinned. + */ +static ssize_t smb_extract_folioq_to_rdma(struct iov_iter *iter, + struct smb_extract_to_rdma *rdma, + ssize_t maxsize) +{ + const struct folio_queue *folioq = iter->folioq; + unsigned int slot = iter->folioq_slot; + ssize_t ret = 0; + size_t offset = iter->iov_offset; + + BUG_ON(!folioq); + + if (slot >= folioq_nr_slots(folioq)) { + folioq = folioq->next; + if (WARN_ON_ONCE(!folioq)) + return -EIO; + slot = 0; + } + + do { + struct folio *folio = folioq_folio(folioq, slot); + size_t fsize = folioq_folio_size(folioq, slot); + + if (offset < fsize) { + size_t part = umin(maxsize - ret, fsize - offset); + + if (!smb_set_sge(rdma, folio_page(folio, 0), offset, part)) + return -EIO; + + offset += part; + ret += part; + } + + if (offset >= fsize) { + offset = 0; + slot++; + if (slot >= folioq_nr_slots(folioq)) { + if (!folioq->next) { + WARN_ON_ONCE(ret < iter->count); + break; + } + folioq = folioq->next; + slot = 0; + } + } + } while (rdma->nr_sge < rdma->max_sge || maxsize > 0); + + iter->folioq = folioq; + iter->folioq_slot = slot; + iter->iov_offset = offset; + iter->count -= ret; return ret; } @@ -2563,6 +2625,8 @@ static ssize_t smb_extract_xarray_to_rdma(struct iov_iter *iter, } rcu_read_unlock(); + if (ret > 0) + iov_iter_advance(iter, ret); return ret; } @@ -2590,6 +2654,9 @@ static ssize_t smb_extract_iter_to_rdma(struct iov_iter *iter, size_t len, case ITER_KVEC: ret = smb_extract_kvec_to_rdma(iter, rdma, len); break; + case ITER_FOLIOQ: + ret = smb_extract_folioq_to_rdma(iter, rdma, len); + break; case ITER_XARRAY: ret = smb_extract_xarray_to_rdma(iter, rdma, len); break; @@ -2598,9 +2665,7 @@ static ssize_t smb_extract_iter_to_rdma(struct iov_iter *iter, size_t len, return -EIO; } - if (ret > 0) { - iov_iter_advance(iter, ret); - } else if (ret < 0) { + if (ret < 0) { while (rdma->nr_sge > before) { struct ib_sge *sge = &rdma->sge[rdma->nr_sge--];