diff mbox series

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

Message ID 82414b0f-1b63-5509-7c1d-5bcc8239a3de@suse.com (mailing list archive)
State Accepted
Commit 53f131c284e83c29c227c0938926a82b2ed4d7ba
Headers show
Series xen-front-pgdir-shbuf: don't record wrong grant handle upon error | expand

Commit Message

Jan Beulich Feb. 23, 2021, 4:26 p.m. UTC
In order for subsequent unmapping to not mistakenly unmap handle 0,
record a perceived always-invalid one instead.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Juergen Gross <jgross@suse.com>
---
v2: Use INVALID_GRANT_HANDLE.

Comments

Oleksandr Andrushchenko Feb. 23, 2021, 6:28 p.m. UTC | #1
Hello, Jan!

On 2/23/21 6:26 PM, Jan Beulich wrote:
> In order for subsequent unmapping to not mistakenly unmap handle 0,
> record a perceived always-invalid one instead.
>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>
> Reviewed-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
> ---
> v2: Use INVALID_GRANT_HANDLE.
>
> --- a/drivers/xen/xen-front-pgdir-shbuf.c
> +++ b/drivers/xen/xen-front-pgdir-shbuf.c
> @@ -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) {
Boris Ostrovsky Feb. 24, 2021, 12:31 a.m. UTC | #2
On 2/23/21 1:28 PM, Oleksandr Andrushchenko wrote:
> Hello, Jan!
>
> On 2/23/21 6:26 PM, Jan Beulich wrote:
>> In order for subsequent unmapping to not mistakenly unmap handle 0,
>> record a perceived always-invalid one instead.
>>
>> Signed-off-by: Jan Beulich <jbeulich@suse.com>
>> Reviewed-by: Juergen Gross <jgross@suse.com>
> Reviewed-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>



Applied to for-linus-5.12b
diff mbox series

Patch

--- a/drivers/xen/xen-front-pgdir-shbuf.c
+++ b/drivers/xen/xen-front-pgdir-shbuf.c
@@ -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) {