From nobody Tue Dec 2 02:05:59 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1C9B335CBDE for ; Thu, 20 Nov 2025 15:26:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763652364; cv=none; b=WcnmrHBmBOlu+hdOnEG439CN+lnt7OQF/iV7irem8fE2+vejusVEOmtrNIg5zwcmVA9MJwuWuHsIVS0giCiTtNbwMZCojJGLNQZd+R/cU/+5sIj9nTruU9JPKmCT2tpOPBki4usc2hw9TK9qE3ipvDNx5JW5FiiuDQZnLzZ0z4s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763652364; c=relaxed/simple; bh=G4WtfUHfe59KgmRpeJ4mvYNIPIHMLtln9T3CQEk4oDU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=D1VQBaW+fcxfNTBJ/k7BjGe4LiG6W14yrxqeHJGW+qRO2E+kzSmZtnt425KqObAM99Q0oKkdQFk6cb3c315RHlsgN4Rx4S876hlWLJePPg/4F9Mo33yz0gKaxGX/51d5jihNO4bUqw8R/HJX3kRLXHNzbEV7U63ncilGNDeI6SE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=ED5u4FxE; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ED5u4FxE" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763652362; 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=sNWziFLEVxIAmo/02nskhsnGj6FZ+fwKxmFFp0fAZqQ=; b=ED5u4FxEY8F9Z4WlFwDi9fTHn3gEo4H6ciL9O7Ii7tS9AZhFMSCekIPTZtGTWu8daSEHho y3vakz5vo8tXxiW0vngNyX3ypQqNtnj7U67KanHPzr0Fi4cOgolJ2TKC5g77A+W96vBz2y cGvpCpZcHxBuT0SRnDys3PqWsXpnXTQ= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-547-PmTtdz8KMl6CuIS4jOHxTw-1; Thu, 20 Nov 2025 10:26:00 -0500 X-MC-Unique: PmTtdz8KMl6CuIS4jOHxTw-1 X-Mimecast-MFC-AGG-ID: PmTtdz8KMl6CuIS4jOHxTw_1763652355 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5C4CF182A136; Thu, 20 Nov 2025 15:25:41 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.5]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5349330044DD; Thu, 20 Nov 2025 15:25:38 +0000 (UTC) From: David Howells To: Steve French Cc: David Howells , Paulo Alcantara , Shyam Prasad N , linux-cifs@vger.kernel.org, netfs@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Tom Talpey Subject: [PATCH v2 2/9] cifs: Use netfs_alloc/free_folioq_buffer() Date: Thu, 20 Nov 2025 15:25:15 +0000 Message-ID: <20251120152524.2711660-3-dhowells@redhat.com> In-Reply-To: <20251120152524.2711660-1-dhowells@redhat.com> References: <20251120152524.2711660-1-dhowells@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" Use netfs_alloc/free_folioq_buffer() rather than doing its own version. Signed-off-by: David Howells cc: Steve French cc: Paulo Alcantara cc: Shyam Prasad N cc: Tom Talpey (RDMA, smbdirect) cc: linux-cifs@vger.kernel.org cc: netfs@lists.linux.dev cc: linux-fsdevel@vger.kernel.org --- fs/smb/client/smb2ops.c | 73 ++++++----------------------------------- 1 file changed, 10 insertions(+), 63 deletions(-) diff --git a/fs/smb/client/smb2ops.c b/fs/smb/client/smb2ops.c index 4b005a7adce0..7ace6d4d305b 100644 --- a/fs/smb/client/smb2ops.c +++ b/fs/smb/client/smb2ops.c @@ -4484,61 +4484,6 @@ crypt_message(struct TCP_Server_Info *server, int nu= m_rqst, return rc; } =20 -/* - * Clear a read buffer, discarding the folios which have the 1st mark set. - */ -static void cifs_clear_folioq_buffer(struct folio_queue *buffer) -{ - struct folio_queue *folioq; - - while ((folioq =3D buffer)) { - for (int s =3D 0; s < folioq_count(folioq); s++) - if (folioq_is_marked(folioq, s)) - folio_put(folioq_folio(folioq, s)); - buffer =3D folioq->next; - kfree(folioq); - } -} - -/* - * Allocate buffer space into a folio queue. - */ -static struct folio_queue *cifs_alloc_folioq_buffer(ssize_t size) -{ - struct folio_queue *buffer =3D NULL, *tail =3D NULL, *p; - struct folio *folio; - unsigned int slot; - - do { - if (!tail || folioq_full(tail)) { - p =3D kmalloc(sizeof(*p), GFP_NOFS); - if (!p) - goto nomem; - folioq_init(p, 0); - if (tail) { - tail->next =3D p; - p->prev =3D tail; - } else { - buffer =3D p; - } - tail =3D p; - } - - folio =3D folio_alloc(GFP_KERNEL|__GFP_HIGHMEM, 0); - if (!folio) - goto nomem; - - slot =3D folioq_append_mark(tail, folio); - size -=3D folioq_folio_size(tail, slot); - } while (size > 0); - - return buffer; - -nomem: - cifs_clear_folioq_buffer(buffer); - return NULL; -} - /* * Copy data from an iterator to the folios in a folio queue buffer. */ @@ -4564,7 +4509,7 @@ void smb3_free_compound_rqst(int num_rqst, struct smb_rqst *rqst) { for (int i =3D 0; i < num_rqst; i++) - cifs_clear_folioq_buffer(rqst[i].rq_buffer); + netfs_free_folioq_buffer(rqst[i].rq_buffer); } =20 /* @@ -4599,8 +4544,10 @@ smb3_init_transform_rq(struct TCP_Server_Info *serve= r, int num_rqst, new->rq_nvec =3D old->rq_nvec; =20 if (size > 0) { - buffer =3D cifs_alloc_folioq_buffer(size); - if (!buffer) + size_t cur_size =3D 0; + rc =3D netfs_alloc_folioq_buffer(NULL, &buffer, &cur_size, + size, GFP_NOFS); + if (rc < 0) goto err_free; =20 new->rq_buffer =3D buffer; @@ -4932,7 +4879,7 @@ static void smb2_decrypt_offload(struct work_struct *= work) } =20 free_pages: - cifs_clear_folioq_buffer(dw->buffer); + netfs_free_folioq_buffer(dw->buffer); cifs_small_buf_release(dw->buf); kfree(dw); } @@ -4970,9 +4917,9 @@ receive_encrypted_read(struct TCP_Server_Info *server= , struct mid_q_entry **mid, dw->len =3D len; len =3D round_up(dw->len, PAGE_SIZE); =20 - rc =3D -ENOMEM; - dw->buffer =3D cifs_alloc_folioq_buffer(len); - if (!dw->buffer) + size_t cur_size =3D 0; + rc =3D netfs_alloc_folioq_buffer(NULL, &dw->buffer, &cur_size, len, GFP_N= OFS); + if (rc < 0) goto discard_data; =20 iov_iter_folio_queue(&iter, ITER_DEST, dw->buffer, 0, 0, len); @@ -5033,7 +4980,7 @@ receive_encrypted_read(struct TCP_Server_Info *server= , struct mid_q_entry **mid, } =20 free_pages: - cifs_clear_folioq_buffer(dw->buffer); + netfs_free_folioq_buffer(dw->buffer); free_dw: kfree(dw); return rc;