From nobody Wed Dec 17 04:11:32 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 437FF24C66A for ; Fri, 21 Feb 2025 17:06:45 +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=1740157607; cv=none; b=bZcJyXfrfr2z3xG16ES8cdzSAUag1R7gmtj7ndO5UPIsF7BYqNfNGW2PXTZWsAS6JHp9nlQ1oAsK7a/jfkrNLIstuL/Eg00xBeh29ZMG1N8a4+JqjeSyAZMCZZwgWlqzyTfDubKvnuB9D8HIu/AuCUnBsl5KGRQihZqKDQ2IV+g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740157607; c=relaxed/simple; bh=Vv1NbWzviFFjkYgnApafB6eSlQ9qebhWbyappYi4ZZ8=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=CWEjnSkZUCxHoOXR5G8SNEXgp0fXY5zgyog+vI8dzDr4+1soVkae74LGw+pVUgXxE2r2vi9M3vQGxPPeoYchzblQGwZ6kQdSqMzIWbLxuswoUgHQAgU6elB35+7DZf9n5Js8SWcnkPh0WweXRPyGdupiEHEiJ3rwqpkCF0SDVbQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none 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=ORYGxAQw; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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="ORYGxAQw" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740157605; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=g4qurRJRnurJ/JqIrxC646pXKHyUVnPnjlMlPbACT6o=; b=ORYGxAQwL8H3xoEXT4mrI1VgHvdLQzePk38rscJVELASb5QvRSeFnc31bPBV5tsi2sM0iH Lq3uUNi1wle15BtVxOKn9+4fdOQZACaKP4q3gqklaIA2jZtbLVf+RoHS7DmyNcKxokAvee m4Kfd0bkXb5cc8bwKehb4zjJeccToVk= Received: from mx-prod-mc-08.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-299-_Rt6RXfyPg6UTI3PrSKIAQ-1; Fri, 21 Feb 2025 12:06:42 -0500 X-MC-Unique: _Rt6RXfyPg6UTI3PrSKIAQ-1 X-Mimecast-MFC-AGG-ID: _Rt6RXfyPg6UTI3PrSKIAQ_1740157601 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 13B5C1800570; Fri, 21 Feb 2025 17:06:41 +0000 (UTC) Received: from eperezma-thinkpadt480s.rmtes.csb (unknown [10.44.32.170]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A0814180087E; Fri, 21 Feb 2025 17:06:35 +0000 (UTC) From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: Xuan Zhuo , Stefan Hajnoczi , Hanna Reitz , linux-kernel@vger.kernel.org, German Maglione , virtualization@lists.linux.dev, Stefano Garzarella , yama@redhat.com, Vivek Goyal , Miklos Szeredi , mst@redhat.com, Jason Wang Subject: [RFC v2 1/5] vduse: add virtio_fs to allowed dev id Date: Fri, 21 Feb 2025 18:06:22 +0100 Message-ID: <20250221170626.261687-2-eperezma@redhat.com> In-Reply-To: <20250221170626.261687-1-eperezma@redhat.com> References: <20250221170626.261687-1-eperezma@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 A VDUSE device that implements virtiofs device works fine just by adding the device id to the whitelist. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang --- drivers/vdpa/vdpa_user/vduse_dev.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vd= use_dev.c index 7ae99691efdf..6a9a37351310 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -144,6 +144,7 @@ static struct workqueue_struct *vduse_irq_bound_wq; static u32 allowed_device_id[] =3D { VIRTIO_ID_BLOCK, VIRTIO_ID_NET, + VIRTIO_ID_FS, }; =20 static inline struct vduse_dev *vdpa_to_vduse(struct vdpa_device *vdpa) --=20 2.48.1 From nobody Wed Dec 17 04:11:32 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 868D224BCF0 for ; Fri, 21 Feb 2025 17:06:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740157614; cv=none; b=jJNWHdTEXV8AXEU34e6kVYnnrXJnpoFHeiW/81u2YaEqsx2KvAJ+RiUqKQqgIwJDfb6j77bddxncwaGyUSDIsqoz1UWc258BIL7DYumEDL4ga3nk5QhRRS3fGQV3mLFfC8kphR53Ro9cxyMVcY/NSZ6+IelKe2dGngGeamotPi0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740157614; c=relaxed/simple; bh=dnyKyQdiAx+MIOYtEQwBaG4Tg9AZ5Ml83AH45CcpJZY=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UKFH3di04cRf310y0wXrdsfsGSKnm9XRjteunCuNqmUqE1RMIUC7pHMRMNUpn+VTAaOllhSi4Dab3H9oyhM0NLKXK5ZJB5lDe8lpd3K+mBm88Iup7tjrlEbYMtEwr6FkzFJ9mcyQitPG6rlPkEOSFS/C2Tm4brRBUxbmsJDKij4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none 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=A1KKycWR; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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="A1KKycWR" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740157611; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5vMNLyiGqRYP1Ao1e0bTH1gSI7/Qklv2j4DCuws+D/c=; b=A1KKycWRhjrrhVLqA7SyUT2MuhWBMhPQYFTAHUkfJ+9FG3bgSiHSK/LdWfcQgsu5XJJUMl kmlYYCjFlb0jf0/RiwTdRQbJAjxsnXIp1woKX2i9aUMJ4Qaap/D+BGs3FufEV+KR007/nO bHBGfAvW9elJ+fm4bNGp6kC6WYJJvHo= Received: from mx-prod-mc-03.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-562-u025uieMMiurFWwQ6NPVOA-1; Fri, 21 Feb 2025 12:06:47 -0500 X-MC-Unique: u025uieMMiurFWwQ6NPVOA-1 X-Mimecast-MFC-AGG-ID: u025uieMMiurFWwQ6NPVOA_1740157606 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2844418E6952; Fri, 21 Feb 2025 17:06:46 +0000 (UTC) Received: from eperezma-thinkpadt480s.rmtes.csb (unknown [10.44.32.170]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9E55B1800358; Fri, 21 Feb 2025 17:06:41 +0000 (UTC) From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: Xuan Zhuo , Stefan Hajnoczi , Hanna Reitz , linux-kernel@vger.kernel.org, German Maglione , virtualization@lists.linux.dev, Stefano Garzarella , yama@redhat.com, Vivek Goyal , Miklos Szeredi , mst@redhat.com, Jason Wang Subject: [RFC v2 2/5] virtiofs: Move stack sg to fuse_req Date: Fri, 21 Feb 2025 18:06:23 +0100 Message-ID: <20250221170626.261687-3-eperezma@redhat.com> In-Reply-To: <20250221170626.261687-1-eperezma@redhat.com> References: <20250221170626.261687-1-eperezma@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 We need to move the map and unmap out of virtiofs queue lock. We need to store the unmap sgs to call virtqueue_unmap_sgs, so use the request itself. TODO: We need to store the forget sgs too. In my tests it is not called so we're safe. Find a way to force-call it. Signed-off-by: Eugenio P=C3=A9rez --- fs/fuse/fuse_i.h | 7 +++++++ fs/fuse/virtio_fs.c | 45 +++++++++++++++++++++------------------------ 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h index fee96fe7887b..0a77e28d8da6 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -434,6 +435,12 @@ struct fuse_req { #if IS_ENABLED(CONFIG_VIRTIO_FS) /** virtio-fs's physically contiguous buffer for in and out args */ void *argbuf; + + /** virtio-fs's pre-mapped stuff */ + struct scatterlist sg_inline_data[6]; /* optimization for short requests = */ + struct scatterlist *sg; + unsigned int out_sgs; + unsigned int in_sgs; #endif =20 /** fuse_mount this request belongs to */ diff --git a/fs/fuse/virtio_fs.c b/fs/fuse/virtio_fs.c index 82afe78ec542..1344c5782a7c 100644 --- a/fs/fuse/virtio_fs.c +++ b/fs/fuse/virtio_fs.c @@ -1377,14 +1377,10 @@ static int virtio_fs_enqueue_req(struct virtio_fs_v= q *fsvq, { /* requests need at least 4 elements */ struct scatterlist *stack_sgs[6]; - struct scatterlist stack_sg[ARRAY_SIZE(stack_sgs)]; struct scatterlist **sgs =3D stack_sgs; - struct scatterlist *sg =3D stack_sg; struct virtqueue *vq; struct fuse_args *args =3D req->args; unsigned int argbuf_used =3D 0; - unsigned int out_sgs =3D 0; - unsigned int in_sgs =3D 0; unsigned int total_sgs; unsigned int i; int ret; @@ -1392,11 +1388,13 @@ static int virtio_fs_enqueue_req(struct virtio_fs_v= q *fsvq, struct fuse_pqueue *fpq; =20 /* Does the sglist fit on the stack? */ + /* TODO replace magic 6 by a macro */ + req->sg =3D req->sg_inline_data; total_sgs =3D sg_count_fuse_req(req); - if (total_sgs > ARRAY_SIZE(stack_sgs)) { + if (total_sgs > 6) { sgs =3D kmalloc_array(total_sgs, sizeof(sgs[0]), gfp); - sg =3D kmalloc_array(total_sgs, sizeof(sg[0]), gfp); - if (!sgs || !sg) { + req->sg =3D kmalloc_array(total_sgs, sizeof(req->sg[0]), gfp); + if (!sgs || !req->sg) { ret =3D -ENOMEM; goto out; } @@ -1408,26 +1406,25 @@ static int virtio_fs_enqueue_req(struct virtio_fs_v= q *fsvq, goto out; =20 /* Request elements */ - sg_init_one(&sg[out_sgs++], &req->in.h, sizeof(req->in.h)); - out_sgs +=3D sg_init_fuse_args(&sg[out_sgs], req, - (struct fuse_arg *)args->in_args, - args->in_numargs, args->in_pages, - req->argbuf, &argbuf_used); + sg_init_one(&req->sg[req->out_sgs++], &req->in.h, sizeof(req->in.h)); + req->out_sgs +=3D sg_init_fuse_args(&req->sg[req->out_sgs], req, + (struct fuse_arg *)args->in_args, + args->in_numargs, args->in_pages, + req->argbuf, &argbuf_used); =20 /* Reply elements */ if (test_bit(FR_ISREPLY, &req->flags)) { - sg_init_one(&sg[out_sgs + in_sgs++], + sg_init_one(&req->sg[req->out_sgs + req->in_sgs++], &req->out.h, sizeof(req->out.h)); - in_sgs +=3D sg_init_fuse_args(&sg[out_sgs + in_sgs], req, - args->out_args, args->out_numargs, - args->out_pages, - req->argbuf + argbuf_used, NULL); + req->in_sgs +=3D sg_init_fuse_args(&req->sg[req->out_sgs + req->in_sgs],= req, + args->out_args, args->out_numargs, + args->out_pages, + req->argbuf + argbuf_used, NULL); } =20 - WARN_ON(out_sgs + in_sgs !=3D total_sgs); - for (i =3D 0; i < total_sgs; i++) - sgs[i] =3D &sg[i]; + sgs[i] =3D &req->sg[i]; + WARN_ON(req->out_sgs + req->in_sgs !=3D total_sgs); =20 spin_lock(&fsvq->lock); =20 @@ -1438,7 +1435,7 @@ static int virtio_fs_enqueue_req(struct virtio_fs_vq = *fsvq, } =20 vq =3D fsvq->vq; - ret =3D virtqueue_add_sgs(vq, sgs, out_sgs, in_sgs, req, GFP_ATOMIC); + ret =3D virtqueue_add_sgs(vq, sgs, req->out_sgs, req->in_sgs, req, GFP_AT= OMIC); if (ret < 0) { spin_unlock(&fsvq->lock); goto out; @@ -1467,10 +1464,10 @@ static int virtio_fs_enqueue_req(struct virtio_fs_v= q *fsvq, kfree(req->argbuf); req->argbuf =3D NULL; } - if (sgs !=3D stack_sgs) { + if (ret < 0 && req->sg !=3D req->sg_inline_data) + kfree(req->sg); + if (sgs !=3D stack_sgs) kfree(sgs); - kfree(sg); - } =20 return ret; } --=20 2.48.1 From nobody Wed Dec 17 04:11:32 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 49D9224C683 for ; Fri, 21 Feb 2025 17:07:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740157623; cv=none; b=LI2CInXbEHhXyCWMBKf1YcnJl748HAS7MO0+Oo4e9w3oKi17HRyd6WgDktySF55i+Jt0bIIYuS6JbUzCAOXtxVhp2m6OOSW3RTwav1DeBGn2upZVPIIRsKzLR4wywN3A1wo9EVCEotX0dTL/dd5S6ACJPEHeyGNRR1Y8rMbuHzo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740157623; c=relaxed/simple; bh=R2pHPtQbZxMeE8vsZFIHnNQdPLF23xfHO+AwC7CTpog=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=EYDZXUMp7eijSL9k5O5jgLwzMD5UZoegZyFBRGcG8ei23/iADrVyEnH/XaD0RbzdOTqKMr+uBFz9sAJVryQj3COo74EGgIdWCDFWeFT5OjyVxcfmZtGFRcldwFLv2DPb4gKI1C+r0kSM8lUUTpbtMXzPTD7jgP0l9GaMoehwak0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none 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=LN9EzxvJ; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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="LN9EzxvJ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740157620; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yKpHdC3+C0gWAiFeQvQHPEenqVM4VXEfdc+nfLPbzg4=; b=LN9EzxvJPQ9ROJ/S+6Iul6/pQADYPSkfhtU4eny38i78gJyvpHsXhPNI15piDWt//Bf9gy hCWNHmm1EJgmtvaIHs9aw+vocawmVsHFz06ufByuMyQ1Nm4Ts8fqhufxxU4wNf3WYhCSpG al8sz87ToczgC1vXNxfklKlbxlRQqg8= 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-654-qeDPwVdyNaiNa6U3es7YEw-1; Fri, 21 Feb 2025 12:06:53 -0500 X-MC-Unique: qeDPwVdyNaiNa6U3es7YEw-1 X-Mimecast-MFC-AGG-ID: qeDPwVdyNaiNa6U3es7YEw_1740157612 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 E7C9C190F9E9; Fri, 21 Feb 2025 17:06:51 +0000 (UTC) Received: from eperezma-thinkpadt480s.rmtes.csb (unknown [10.44.32.170]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DB4711800941; Fri, 21 Feb 2025 17:06:46 +0000 (UTC) From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: Xuan Zhuo , Stefan Hajnoczi , Hanna Reitz , linux-kernel@vger.kernel.org, German Maglione , virtualization@lists.linux.dev, Stefano Garzarella , yama@redhat.com, Vivek Goyal , Miklos Szeredi , mst@redhat.com, Jason Wang Subject: [RFC v2 3/5] virtio_ring: add api for premapped out and in buffer chain Date: Fri, 21 Feb 2025 18:06:24 +0100 Message-ID: <20250221170626.261687-4-eperezma@redhat.com> In-Reply-To: <20250221170626.261687-1-eperezma@redhat.com> References: <20250221170626.261687-1-eperezma@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Commit 3ef66af31fea ("virtio_ring: introduce add api for premapped") add functions to add premapped input or output chains to a virtqueue. Add a generic one that supports out+in buffers chains. Signed-off-by: Eugenio P=C3=A9rez --- drivers/virtio/virtio_ring.c | 35 +++++++++++++++++++++++++++++++++++ include/linux/virtio.h | 7 +++++++ 2 files changed, 42 insertions(+) diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index fdd2d2b07b5a..7ef1f37e025f 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -2318,6 +2318,41 @@ int virtqueue_add_sgs(struct virtqueue *_vq, } EXPORT_SYMBOL_GPL(virtqueue_add_sgs); =20 +/** + * virtqueue_add_sgs_premapped - expose buffers to other end + * @_vq: the struct virtqueue we're talking about. + * @sgs: array of terminated scatterlists. + * @out_sgs: the number of scatterlists readable by other side + * @in_sgs: the number of scatterlists which are writable (after readable = ones) + * @data: the token identifying the buffer. + * @gfp: how to do memory allocations (if necessary). + * + * Caller must ensure we don't call this with other virtqueue operations + * at the same time (except where noted). + * + * Returns zero or a negative error (ie. ENOSPC, ENOMEM, EIO). + */ +int virtqueue_add_sgs_premapped(struct virtqueue *_vq, + struct scatterlist *sgs[], + unsigned int out_sgs, + unsigned int in_sgs, + void *data, + gfp_t gfp) +{ + unsigned int i, total_sg =3D 0; + + /* Count them first. */ + for (i =3D 0; i < out_sgs + in_sgs; i++) { + struct scatterlist *sg; + + for (sg =3D sgs[i]; sg; sg =3D sg_next(sg)) + total_sg++; + } + return virtqueue_add(_vq, sgs, total_sg, out_sgs, in_sgs, + data, NULL, true, gfp); +} +EXPORT_SYMBOL_GPL(virtqueue_add_sgs_premapped); + /** * virtqueue_add_outbuf - expose output buffers to other end * @vq: the struct virtqueue we're talking about. diff --git a/include/linux/virtio.h b/include/linux/virtio.h index 4d16c13d0df5..7f61f66ddaa2 100644 --- a/include/linux/virtio.h +++ b/include/linux/virtio.h @@ -74,6 +74,13 @@ int virtqueue_add_sgs(struct virtqueue *vq, void *data, gfp_t gfp); =20 +int virtqueue_add_sgs_premapped(struct virtqueue *vq, + struct scatterlist *sgs[], + unsigned int out_sgs, + unsigned int in_sgs, + void *data, + gfp_t gfp); + struct device *virtqueue_dma_dev(struct virtqueue *vq); =20 bool virtqueue_kick(struct virtqueue *vq); --=20 2.48.1 From nobody Wed Dec 17 04:11:32 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 54ED824BCF0 for ; Fri, 21 Feb 2025 17:07:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740157623; cv=none; b=XKd8LbcuVpWRKYmoXdy6iM3eJ+WpIwgiwrFFcsL58NGJytNHAOVm/BBGAPrcLEq8klYXwzSRxBjwaRs6Eonjo10i/LYirRtJ9xKCauhjvS1YnUWJ5/ZWaD5NiaZkphYtXlW7aagSFM3Jjw+NtFzd/UDicUir62EznlKDx+BNdP8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740157623; c=relaxed/simple; bh=dmXZwGs+K9cXy4OVhaZVpVlHINi/95qyv6S5WYJHnRw=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=dNybu32BRvkON2T2dNszjm4Q2E0wb2X4PtrQEtH6y+Y9P/uHM6GF3pEzVYFRgDKsA8t2C1lftsaO7cvgMy+bQVHOCLLLHcqNZ/5ls7jR+lZIW9PqHyaC6lDJd0kZyQ8aLOM8HJYqr+Nc+4Kuai4jQem3RvtOBSWQNNk0oh/+OY0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none 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=KpKaVx//; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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="KpKaVx//" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740157620; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DdFhks9dEBucFBSdGlrdrm2YLeGCqTXN1StzLlcWwlU=; b=KpKaVx//jjKZSEXwCXrBk9hezbVM4wyRPsGPyDza0rPJH+zPAWCbsqwdC0RtBCZPg+OnOc u+Z1jaStdgbfiqDFFpESR7W2lo407YIw51Wrut3ZiG5tROMPeHmfDTzQoy8LhkR/cpaVB6 4/YtXc8U4MaoMMYWnhawrZxDo3HpZe4= Received: from mx-prod-mc-08.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-518-m0a4VAWSOIaZmlHfhpDBIA-1; Fri, 21 Feb 2025 12:06:59 -0500 X-MC-Unique: m0a4VAWSOIaZmlHfhpDBIA-1 X-Mimecast-MFC-AGG-ID: m0a4VAWSOIaZmlHfhpDBIA_1740157617 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4A9A61800878; Fri, 21 Feb 2025 17:06:57 +0000 (UTC) Received: from eperezma-thinkpadt480s.rmtes.csb (unknown [10.44.32.170]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id AA946180087E; Fri, 21 Feb 2025 17:06:52 +0000 (UTC) From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: Xuan Zhuo , Stefan Hajnoczi , Hanna Reitz , linux-kernel@vger.kernel.org, German Maglione , virtualization@lists.linux.dev, Stefano Garzarella , yama@redhat.com, Vivek Goyal , Miklos Szeredi , mst@redhat.com, Jason Wang Subject: [RFC v2 4/5] virtiofs: perform DMA operations out of the spinlock Date: Fri, 21 Feb 2025 18:06:25 +0100 Message-ID: <20250221170626.261687-5-eperezma@redhat.com> In-Reply-To: <20250221170626.261687-1-eperezma@redhat.com> References: <20250221170626.261687-1-eperezma@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 This is useful for some setups like swiotlb or VDUSE where the DMA operations are expensive and/or need to be performed with a write lock. After applying this patch, fio read test goes from 1124MiB/s to 1191MiB/s. Signed-off-by: Eugenio P=C3=A9rez --- fs/fuse/virtio_fs.c | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/fs/fuse/virtio_fs.c b/fs/fuse/virtio_fs.c index 1344c5782a7c..e19c78f2480e 100644 --- a/fs/fuse/virtio_fs.c +++ b/fs/fuse/virtio_fs.c @@ -836,8 +836,19 @@ static void virtio_fs_requests_done_work(struct work_s= truct *work) =20 /* End requests */ list_for_each_entry_safe(req, next, &reqs, list) { + unsigned int total_sgs =3D req->out_sgs + req->in_sgs; + list_del_init(&req->list); =20 + for (unsigned int i =3D 0; i < total_sgs; ++i) { + enum dma_data_direction dir =3D (i < req->out_sgs) ? + DMA_TO_DEVICE : DMA_FROM_DEVICE; + dma_unmap_page(vq->vdev->dev.parent, + sg_dma_address(&req->sg[i]), + sg_dma_len(&req->sg[i]), dir); + + } + /* blocking async request completes in a worker context */ if (req->args->may_block) { struct virtio_fs_req_work *w; @@ -1426,6 +1437,24 @@ static int virtio_fs_enqueue_req(struct virtio_fs_vq= *fsvq, sgs[i] =3D &req->sg[i]; WARN_ON(req->out_sgs + req->in_sgs !=3D total_sgs); =20 + // TODO can we change this ptr out of the lock? + vq =3D fsvq->vq; + // TODO handle this and following errors + for (i =3D 0; i < total_sgs; i++) { + struct page *page =3D sg_page(&req->sg[i]); + enum dma_data_direction dir =3D (i < req->out_sgs) ? + DMA_TO_DEVICE : DMA_FROM_DEVICE; + dma_addr_t dma_addr =3D dma_map_page(vq->vdev->dev.parent, page, + req->sg[i].offset, req->sg[i].length, dir); + + if (dma_mapping_error(vq->vdev->dev.parent, dma_addr)) { + ret =3D -ENOMEM; + goto out; + } + sg_dma_address(&req->sg[i]) =3D dma_addr; + sg_dma_len(&req->sg[i]) =3D req->sg[i].length; + } + spin_lock(&fsvq->lock); =20 if (!fsvq->connected) { @@ -1434,8 +1463,8 @@ static int virtio_fs_enqueue_req(struct virtio_fs_vq = *fsvq, goto out; } =20 - vq =3D fsvq->vq; - ret =3D virtqueue_add_sgs(vq, sgs, req->out_sgs, req->in_sgs, req, GFP_AT= OMIC); + ret =3D virtqueue_add_sgs_premapped(vq, sgs, req->out_sgs, + req->in_sgs, req, GFP_ATOMIC); if (ret < 0) { spin_unlock(&fsvq->lock); goto out; @@ -1460,6 +1489,13 @@ static int virtio_fs_enqueue_req(struct virtio_fs_vq= *fsvq, virtqueue_notify(vq); =20 out: + for (unsigned int j =3D 0; ret && j < total_sgs; ++j) { + enum dma_data_direction dir =3D (j < req->out_sgs) ? + DMA_TO_DEVICE : DMA_FROM_DEVICE; + dma_unmap_page(vq->vdev->dev.parent, + sg_dma_address(&req->sg[j]), + sg_dma_len(&req->sg[j]), dir); + } if (ret < 0 && req->argbuf) { kfree(req->argbuf); req->argbuf =3D NULL; --=20 2.48.1 From nobody Wed Dec 17 04:11:32 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 CC8B824C694 for ; Fri, 21 Feb 2025 17:07:08 +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=1740157630; cv=none; b=V3BqaVE5IlF90ooXytUINT14tY7ukMLCo1DYijAFMoWEG7oCl+4qj99NgCJ1jiKhzbjYgfu/oYb7wgmPDOvcHbeWpW0qBWBHx+AwwyBzTmm8PM+Z5wLRBstyJBi7n0s4kKd8gtVzjC76DL3gy9559atm5mCmElZshvhPsVbF/IQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740157630; c=relaxed/simple; bh=kk51s7J3anVkFfT7F/aodbxST59c5FZiYH2rR7cImhk=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RZkogCcWmvGPQz50NxjDm4SI+f7eiQwygUrbwO/8CKv6M2Uwl8LL4L+aNCauKLWXB6h89mSZd11fiPMs4fSzB655DA9xM841P7uUGfa9AvtCnxEuR1onrrQz2nqYyaA8G1b4KeT7OCG4K0/m/O50EqRSvsbRygmUNXBNfLOLYQ0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none 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=DbuGiDjU; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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="DbuGiDjU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740157627; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5VKeHk03WHwQgaZaTfgIKUzZliixkLtjHpWevmfgD1Q=; b=DbuGiDjUkB0j5jrudUc1ayFyzUiK73zHM7+lcYGfnmL+RdrHXP/qR3dvwsLu2tnheC4iZT eSfHqQDl+Y/wFp5B13pzJ2Ebr9Z1J8Gc4jtjgYJdAcqOSoLDhvyrxn0gMYKdigF2kQfe9v 7e6Xxhq16hMG7X+aK2IRdsH/oW9VJ0c= Received: from mx-prod-mc-03.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-479-P476CK1tOI2mKZv3PlzE8Q-1; Fri, 21 Feb 2025 12:07:03 -0500 X-MC-Unique: P476CK1tOI2mKZv3PlzE8Q-1 X-Mimecast-MFC-AGG-ID: P476CK1tOI2mKZv3PlzE8Q_1740157622 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5BE6618D95F3; Fri, 21 Feb 2025 17:07:02 +0000 (UTC) Received: from eperezma-thinkpadt480s.rmtes.csb (unknown [10.44.32.170]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D9AD51800358; Fri, 21 Feb 2025 17:06:57 +0000 (UTC) From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: Xuan Zhuo , Stefan Hajnoczi , Hanna Reitz , linux-kernel@vger.kernel.org, German Maglione , virtualization@lists.linux.dev, Stefano Garzarella , yama@redhat.com, Vivek Goyal , Miklos Szeredi , mst@redhat.com, Jason Wang Subject: [RFC v2 5/5] virtiofs: Disable notifications more aggresively Date: Fri, 21 Feb 2025 18:06:26 +0100 Message-ID: <20250221170626.261687-6-eperezma@redhat.com> In-Reply-To: <20250221170626.261687-1-eperezma@redhat.com> References: <20250221170626.261687-1-eperezma@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Disable notifications right before scheduling, instead of waiting until the work is running. After applying this patch, fio read test goes from 1191MiB/s to 1263.14Mib/s Signed-off-by: Eugenio P=C3=A9rez --- fs/fuse/virtio_fs.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/fuse/virtio_fs.c b/fs/fuse/virtio_fs.c index e19c78f2480e..3d6981c0f3c3 100644 --- a/fs/fuse/virtio_fs.c +++ b/fs/fuse/virtio_fs.c @@ -915,6 +915,8 @@ static void virtio_fs_vq_done(struct virtqueue *vq) =20 dev_dbg(&vq->vdev->dev, "%s %s\n", __func__, fsvq->name); =20 + /* Shceduled, don't send more notifications */ + virtqueue_disable_cb(vq); schedule_work(&fsvq->done_work); } =20 --=20 2.48.1