From nobody Wed Oct 1 23:35:07 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 555A630CDA0 for ; Mon, 29 Sep 2025 16:52:28 +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=1759164751; cv=none; b=KMSu+4D/xhqmcXRi/dhihE/FHZ4wK9YHhOOT3TpXSEXaT0XgsyhIQKvPzpoWBHf9Z0jiPAU5mzsXBwTMTqkokMhaVa1k0aye6LqVgr+pdiAaxjRdtQyJmAOCssozxuGNGiKevD3fVzcthzpXjY9QcQUOLtgOUPu04ZA8LCiH1vk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759164751; c=relaxed/simple; bh=etPbGRB35rlVSzRq4ea9HZnVBp0EPEvgDfe8kSjMhdU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Egk9KJF8P3hYuqF1/6jTyQIDN+COffz0+V6GXQhrUZS1bHIeQ7BzuanxCrhJIgurVYXkRtRJpvkJ4VaeJ7gZ/tYaEtWJBKSMLVJfrAcJo7i/nhX+VpdsOzVVvw5GnFHX6Ktijhd+uwFDMhptBMmIH/n2AWiCpi+9thAcrsWpmAs= 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=Spie5thr; arc=none smtp.client-ip=170.10.133.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="Spie5thr" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1759164747; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oP+8CDcAq3Wjvx2LUhHgK9n6B25GSyvD5xx1gm6HKtc=; b=Spie5thronf6hoRt2hBM7gTuHfPnO/Nu71f/o1515mDLigOiFSaj+IGSecOhBMgV7LzLxA qgMPmkLglWE2waInc++mRyCJ8zZBwXQV17dBthYPiNKkJR9uPcEfe1LLQtLkEHUhJv21Rv uF2OKltkqsI4bRJ5rw1PkBjP0Jg2jPI= Received: from mx-prod-mc-01.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-574-O3Hnno4mP7Wfq8WofpehSQ-1; Mon, 29 Sep 2025 12:52:24 -0400 X-MC-Unique: O3Hnno4mP7Wfq8WofpehSQ-1 X-Mimecast-MFC-AGG-ID: O3Hnno4mP7Wfq8WofpehSQ_1759164743 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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 82459195608E; Mon, 29 Sep 2025 16:52:23 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.45.226.47]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C3FD130001A4; Mon, 29 Sep 2025 16:52:19 +0000 (UTC) From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: "Michael S . Tsirkin " Cc: linux-kernel@vger.kernel.org, Xuan Zhuo , Laurent Vivier , jasowang@redhat.com, Yongji Xie , =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Stefano Garzarella , Cindy Lu , Maxime Coquelin , virtualization@lists.linux.dev Subject: [PATCH v6 1/7] vduse: make domain_lock an rwlock Date: Mon, 29 Sep 2025 18:52:07 +0200 Message-ID: <20250929165213.2896034-2-eperezma@redhat.com> In-Reply-To: <20250929165213.2896034-1-eperezma@redhat.com> References: <20250929165213.2896034-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.4 It will be used in a few more scenarios read-only so make it more scalable. Suggested-by: Xie Yongji Acked-by: Jason Wang Reviewed-by: Xie Yongji Signed-off-by: Eugenio P=C3=A9rez --- v6: Not including linux/rwlock.h directly. v2: New in v2. --- drivers/vdpa/vdpa_user/vduse_dev.c | 41 +++++++++++++++--------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vd= use_dev.c index e7bced0b5542..321092bfb2a6 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -117,7 +118,7 @@ struct vduse_dev { struct vduse_umem *umem; struct mutex mem_lock; unsigned int bounce_size; - struct mutex domain_lock; + rwlock_t domain_lock; }; =20 struct vduse_dev_msg { @@ -1176,9 +1177,9 @@ static long vduse_dev_ioctl(struct file *file, unsign= ed int cmd, if (entry.start > entry.last) break; =20 - mutex_lock(&dev->domain_lock); + read_lock(&dev->domain_lock); if (!dev->domain) { - mutex_unlock(&dev->domain_lock); + read_unlock(&dev->domain_lock); break; } spin_lock(&dev->domain->iotlb_lock); @@ -1193,7 +1194,7 @@ static long vduse_dev_ioctl(struct file *file, unsign= ed int cmd, entry.perm =3D map->perm; } spin_unlock(&dev->domain->iotlb_lock); - mutex_unlock(&dev->domain_lock); + read_unlock(&dev->domain_lock); ret =3D -EINVAL; if (!f) break; @@ -1346,10 +1347,10 @@ static long vduse_dev_ioctl(struct file *file, unsi= gned int cmd, sizeof(umem.reserved))) break; =20 - mutex_lock(&dev->domain_lock); + write_lock(&dev->domain_lock); ret =3D vduse_dev_reg_umem(dev, umem.iova, umem.uaddr, umem.size); - mutex_unlock(&dev->domain_lock); + write_unlock(&dev->domain_lock); break; } case VDUSE_IOTLB_DEREG_UMEM: { @@ -1363,10 +1364,10 @@ static long vduse_dev_ioctl(struct file *file, unsi= gned int cmd, if (!is_mem_zero((const char *)umem.reserved, sizeof(umem.reserved))) break; - mutex_lock(&dev->domain_lock); + write_lock(&dev->domain_lock); ret =3D vduse_dev_dereg_umem(dev, umem.iova, umem.size); - mutex_unlock(&dev->domain_lock); + write_unlock(&dev->domain_lock); break; } case VDUSE_IOTLB_GET_INFO: { @@ -1385,9 +1386,9 @@ static long vduse_dev_ioctl(struct file *file, unsign= ed int cmd, sizeof(info.reserved))) break; =20 - mutex_lock(&dev->domain_lock); + read_lock(&dev->domain_lock); if (!dev->domain) { - mutex_unlock(&dev->domain_lock); + read_unlock(&dev->domain_lock); break; } spin_lock(&dev->domain->iotlb_lock); @@ -1402,7 +1403,7 @@ static long vduse_dev_ioctl(struct file *file, unsign= ed int cmd, info.capability |=3D VDUSE_IOVA_CAP_UMEM; } spin_unlock(&dev->domain->iotlb_lock); - mutex_unlock(&dev->domain_lock); + read_unlock(&dev->domain_lock); if (!map) break; =20 @@ -1425,10 +1426,10 @@ static int vduse_dev_release(struct inode *inode, s= truct file *file) { struct vduse_dev *dev =3D file->private_data; =20 - mutex_lock(&dev->domain_lock); + write_lock(&dev->domain_lock); if (dev->domain) vduse_dev_dereg_umem(dev, 0, dev->domain->bounce_size); - mutex_unlock(&dev->domain_lock); + write_unlock(&dev->domain_lock); spin_lock(&dev->msg_lock); /* Make sure the inflight messages can processed after reconncection */ list_splice_init(&dev->recv_list, &dev->send_list); @@ -1647,7 +1648,7 @@ static struct vduse_dev *vduse_dev_create(void) =20 mutex_init(&dev->lock); mutex_init(&dev->mem_lock); - mutex_init(&dev->domain_lock); + rwlock_init(&dev->domain_lock); spin_lock_init(&dev->msg_lock); INIT_LIST_HEAD(&dev->send_list); INIT_LIST_HEAD(&dev->recv_list); @@ -1805,7 +1806,7 @@ static ssize_t bounce_size_store(struct device *devic= e, int ret; =20 ret =3D -EPERM; - mutex_lock(&dev->domain_lock); + write_lock(&dev->domain_lock); if (dev->domain) goto unlock; =20 @@ -1821,7 +1822,7 @@ static ssize_t bounce_size_store(struct device *devic= e, dev->bounce_size =3D bounce_size & PAGE_MASK; ret =3D count; unlock: - mutex_unlock(&dev->domain_lock); + write_unlock(&dev->domain_lock); return ret; } =20 @@ -2045,11 +2046,11 @@ static int vdpa_dev_add(struct vdpa_mgmt_dev *mdev,= const char *name, if (ret) return ret; =20 - mutex_lock(&dev->domain_lock); + write_lock(&dev->domain_lock); if (!dev->domain) dev->domain =3D vduse_domain_create(VDUSE_IOVA_SIZE - 1, dev->bounce_size); - mutex_unlock(&dev->domain_lock); + write_unlock(&dev->domain_lock); if (!dev->domain) { put_device(&dev->vdev->vdpa.dev); return -ENOMEM; @@ -2059,10 +2060,10 @@ static int vdpa_dev_add(struct vdpa_mgmt_dev *mdev,= const char *name, ret =3D _vdpa_register_device(&dev->vdev->vdpa, dev->vq_num); if (ret) { put_device(&dev->vdev->vdpa.dev); - mutex_lock(&dev->domain_lock); + write_lock(&dev->domain_lock); vduse_domain_destroy(dev->domain); dev->domain =3D NULL; - mutex_unlock(&dev->domain_lock); + write_unlock(&dev->domain_lock); return ret; } =20 --=20 2.51.0