Skip to contentSkip to conversation

xen-front-pgdir-shbuf: don't record wrong grant handle upon error

PATCH Applied Jan Beulich 3 participants 3 messages Feb 23, 2021 – Feb 24, 2021 Xen hypervisor interface

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen-front-pgdir-shbuf: don't record wrong grant handle upon error

In order for subsequent unmapping to not mistakenly unmap handle 0, record a perceived always-invalid one instead.

---
v2: Use INVALID_GRANT_HANDLE.

drivers/xen/xen-front-pgdir-shbuf.c +9 -2
@@ -305,11 +305,18 @@ static int backend_map(struct xen_front_
 
 	/* Save handles even if error, so we can unmap. */
 	for (cur_page = 0; cur_page < buf->num_pages; cur_page++) {
-		buf->backend_map_handles[cur_page] = map_ops[cur_page].handle;
-		if (unlikely(map_ops[cur_page].status != GNTST_okay))
+		if (likely(map_ops[cur_page].status == GNTST_okay)) {
+			buf->backend_map_handles[cur_page] =
+				map_ops[cur_page].handle;
+		} else {
+			buf->backend_map_handles[cur_page] =
+				INVALID_GRANT_HANDLE;
+			if (!ret)
+				ret = -ENXIO;
 			dev_err(&buf->xb_dev->dev,
 				"Failed to map page %d: %d\n",
 				cur_page, map_ops[cur_page].status);
+		}
 	}
 
 	if (ret) {
Reviewed-by on v1 1/1
#1 lore raw

Hello, Jan!

Quoted 5 lines · Jan Beulich

In order for subsequent unmapping to not mistakenly unmap handle 0, record a perceived always-invalid one instead.

Quoted 26 lines

---
v2: Use INVALID_GRANT_HANDLE.

drivers/xen/xen-front-pgdir-shbuf.c +9 -2
@@ -305,11 +305,18 @@ static int backend_map(struct xen_front_
 
  	/* Save handles even if error, so we can unmap. */
  	for (cur_page = 0; cur_page < buf->num_pages; cur_page++) {
-		buf->backend_map_handles[cur_page] = map_ops[cur_page].handle;
-		if (unlikely(map_ops[cur_page].status != GNTST_okay))
+		if (likely(map_ops[cur_page].status == GNTST_okay)) {
+			buf->backend_map_handles[cur_page] =
+				map_ops[cur_page].handle;
+		} else {
+			buf->backend_map_handles[cur_page] =
+				INVALID_GRANT_HANDLE;
+			if (!ret)
+				ret = -ENXIO;
  			dev_err(&buf->xb_dev->dev,
  				"Failed to map page %d: %d\n",
  				cur_page, map_ops[cur_page].status);
+		}
  	}
 
  	if (ret) {