Skip to contentSkip to conversation

vhost: use bvec_kmap_local in {get,put}u16_iotlb

PATCH In review Christoph Hellwig 2 participants 2 messages Feb 22, 2022 – Feb 23, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vhost: use bvec_kmap_local in {get,put}u16_iotlb

Using local kmaps slightly reduces the chances to stray writes, and the bvec interface cleans up the code a little bit.

---
 drivers/vhost/vringh.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)
drivers/vhost/vringh.c +8 -10
index 14e2043d76852..0f22a83fd09af 100644
@@ -1173,7 +1173,7 @@ static inline int getu16_iotlb(const struct vringh *vrh,
 			       u16 *val, const __virtio16 *p)
 {
 	struct bio_vec iov;
-	void *kaddr, *from;
+	void *kaddr;
 	int ret;
 
 	/* Atomic read is needed for getu16 */
@@ -1182,10 +1182,9 @@ static inline int getu16_iotlb(const struct vringh *vrh,
 	if (ret < 0)
 		return ret;
 
-	kaddr = kmap_atomic(iov.bv_page);
-	from = kaddr + iov.bv_offset;
-	*val = vringh16_to_cpu(vrh, READ_ONCE(*(__virtio16 *)from));
-	kunmap_atomic(kaddr);
+	kaddr = bvec_kmap_local(&iov);
+	*val = vringh16_to_cpu(vrh, READ_ONCE(*(__virtio16 *)kaddr));
+	kunmap_local(kaddr);
 
 	return 0;
 }
@@ -1194,7 +1193,7 @@ static inline int putu16_iotlb(const struct vringh *vrh,
 			       __virtio16 *p, u16 val)
 {
 	struct bio_vec iov;
-	void *kaddr, *to;
+	void *kaddr;
 	int ret;
 
 	/* Atomic write is needed for putu16 */
@@ -1203,10 +1202,9 @@ static inline int putu16_iotlb(const struct vringh *vrh,
 	if (ret < 0)
 		return ret;
 
-	kaddr = kmap_atomic(iov.bv_page);
-	to = kaddr + iov.bv_offset;
-	WRITE_ONCE(*(__virtio16 *)to, cpu_to_vringh16(vrh, val));
-	kunmap_atomic(kaddr);
+	kaddr = bvec_kmap_local(&iov);
+	WRITE_ONCE(*(__virtio16 *)kaddr, cpu_to_vringh16(vrh, val));
+	kunmap_local(kaddr);
 
 	return 0;
 }
Signature · 1 line
2.30.2
Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Christoph Hellwig

Using local kmaps slightly reduces the chances to stray writes, and the bvec interface cleans up the code a little bit.

Quoted 57 lines
---
 drivers/vhost/vringh.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)
drivers/vhost/vringh.c +8 -11
index 14e2043d76852..0f22a83fd09af 100644
@@ -1173,7 +1173,7 @@ static inline int getu16_iotlb(const struct vringh *vrh,
                               u16 *val, const __virtio16 *p)
 {
        struct bio_vec iov;
-       void *kaddr, *from;
+       void *kaddr;
        int ret;
 
        /* Atomic read is needed for getu16 */
@@ -1182,10 +1182,9 @@ static inline int getu16_iotlb(const struct vringh *vrh,
        if (ret < 0)
                return ret;
 
-       kaddr = kmap_atomic(iov.bv_page);
-       from = kaddr + iov.bv_offset;
-       *val = vringh16_to_cpu(vrh, READ_ONCE(*(__virtio16 *)from));
-       kunmap_atomic(kaddr);
+       kaddr = bvec_kmap_local(&iov);
+       *val = vringh16_to_cpu(vrh, READ_ONCE(*(__virtio16 *)kaddr));
+       kunmap_local(kaddr);
 
        return 0;
 }
@@ -1194,7 +1193,7 @@ static inline int putu16_iotlb(const struct vringh *vrh,
                               __virtio16 *p, u16 val)
 {
        struct bio_vec iov;
-       void *kaddr, *to;
+       void *kaddr;
        int ret;
 
        /* Atomic write is needed for putu16 */
@@ -1203,10 +1202,9 @@ static inline int putu16_iotlb(const struct vringh *vrh,
        if (ret < 0)
                return ret;
 
-       kaddr = kmap_atomic(iov.bv_page);
-       to = kaddr + iov.bv_offset;
-       WRITE_ONCE(*(__virtio16 *)to, cpu_to_vringh16(vrh, val));
-       kunmap_atomic(kaddr);
+       kaddr = bvec_kmap_local(&iov);
+       WRITE_ONCE(*(__virtio16 *)kaddr, cpu_to_vringh16(vrh, val));
+       kunmap_local(kaddr);
 
        return 0;
 }
--

2.30.2