All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] s390/vfio-ap: Unregister the debug area on init failure
@ 2026-12-03 16:12 Haoxiang Li
  2026-12-03 16:21 ` sashiko-bot
  2026-12-03 17:06 ` Anthony Krowiak
  0 siblings, 2 replies; 5+ messages in thread
From: Haoxiang Li @ 2026-12-03 16:12 UTC (permalink / raw)
  To: akrowiak, pasic, jjherne, freude, dengler, hca, gor, agordeev,
	borntraeger, svens, mjrosato
  Cc: linux-s390, kvm, Haoxiang Li

vfio_ap_dbf_info_init() registers a debug area via debug_register().
However, vfio_ap_init() does not unregister it if any subsequent
initialization step fails, leaving the debug area registered.

Fix this by calling debug_unregister() after unwinding the resources
acquired during initialization.

Fixes: a084c44eaa6a ("s390-vfio-ap: introduces s390 kernel debug feature for vfio_ap device driver")
Signed-off-by: Haoxiang Li <haoxiang_li2024@163.com>
---
 drivers/s390/crypto/vfio_ap_drv.c | 30 +++++++++++++++++-------------
 1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/drivers/s390/crypto/vfio_ap_drv.c b/drivers/s390/crypto/vfio_ap_drv.c
index 8e69ed286bb9..9236c77e6a4c 100644
--- a/drivers/s390/crypto/vfio_ap_drv.c
+++ b/drivers/s390/crypto/vfio_ap_drv.c
@@ -173,28 +173,32 @@ static int __init vfio_ap_init(void)
 		return ret;
 
 	/* If there are no AP instructions, there is nothing to pass through. */
-	if (!ap_instructions_available())
-		return -ENODEV;
+	if (!ap_instructions_available()) {
+		ret = -ENODEV;
+		goto err_debug;
+	}
 
 	ret = vfio_ap_matrix_dev_create();
 	if (ret)
-		return ret;
+		goto err_debug;
 
 	ret = ap_driver_register(&vfio_ap_drv, THIS_MODULE, VFIO_AP_DRV_NAME);
-	if (ret) {
-		vfio_ap_matrix_dev_destroy();
-		return ret;
-	}
+	if (ret)
+		goto err_matrix;
 
 	ret = vfio_ap_mdev_register();
-	if (ret) {
-		ap_driver_unregister(&vfio_ap_drv);
-		vfio_ap_matrix_dev_destroy();
-
-		return ret;
-	}
+	if (ret)
+		goto err_ap_driver;
 
 	return 0;
+
+err_ap_driver:
+	ap_driver_unregister(&vfio_ap_drv);
+err_matrix:
+	vfio_ap_matrix_dev_destroy();
+err_debug:
+	debug_unregister(vfio_ap_dbf_info);
+	return ret;
 }
 
 static void __exit vfio_ap_exit(void)
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] s390/vfio-ap: Unregister the debug area on init failure
  2026-12-03 16:12 [PATCH] s390/vfio-ap: Unregister the debug area on init failure Haoxiang Li
@ 2026-12-03 16:21 ` sashiko-bot
  2026-12-03 17:06 ` Anthony Krowiak
  1 sibling, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-12-03 16:21 UTC (permalink / raw)
  To: Haoxiang Li
  Cc: linux-s390, Heiko Carstens, Vasily Gorbik, Alexander Gordeev,
	Christian Borntraeger

> vfio_ap_dbf_info_init() registers a debug area via debug_register().
> However, vfio_ap_init() does not unregister it if any subsequent
> initialization step fails, leaving the debug area registered.
> 
> Fix this by calling debug_unregister() after unwinding the resources
> acquired during initialization.
> 
> Fixes: a084c44eaa6a ("s390-vfio-ap: introduces s390 kernel debug feature for vfio_ap device driver")
> Signed-off-by: Haoxiang Li <haoxiang_li2024@163.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203161237.1025099-1-haoxiang_li2024@163.com?part=1

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] s390/vfio-ap: Unregister the debug area on init failure
  2026-12-03 16:12 [PATCH] s390/vfio-ap: Unregister the debug area on init failure Haoxiang Li
  2026-12-03 16:21 ` sashiko-bot
@ 2026-12-03 17:06 ` Anthony Krowiak
  2026-12-04  2:09   ` Haoxiang Li
  1 sibling, 1 reply; 5+ messages in thread
From: Anthony Krowiak @ 2026-12-03 17:06 UTC (permalink / raw)
  To: Haoxiang Li, pasic, jjherne, freude, dengler, hca, gor, agordeev,
	borntraeger, svens, mjrosato
  Cc: linux-s390, kvm



On 12/3/26 11:12 AM, Haoxiang Li wrote:
> vfio_ap_dbf_info_init() registers a debug area via debug_register().
> However, vfio_ap_init() does not unregister it if any subsequent
> initialization step fails, leaving the debug area registered.
> 
> Fix this by calling debug_unregister() after unwinding the resources
> acquired during initialization.

Why not just move the vfio_ap_dbf_info_init() call to the end of the
function? That would eliminate the need for the goto's

> 
> Fixes: a084c44eaa6a ("s390-vfio-ap: introduces s390 kernel debug feature for vfio_ap device driver")
> Signed-off-by: Haoxiang Li <haoxiang_li2024@163.com>
> ---
>   drivers/s390/crypto/vfio_ap_drv.c | 30 +++++++++++++++++-------------
>   1 file changed, 17 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/s390/crypto/vfio_ap_drv.c b/drivers/s390/crypto/vfio_ap_drv.c
> index 8e69ed286bb9..9236c77e6a4c 100644
> --- a/drivers/s390/crypto/vfio_ap_drv.c
> +++ b/drivers/s390/crypto/vfio_ap_drv.c
> @@ -173,28 +173,32 @@ static int __init vfio_ap_init(void)
>   		return ret;
>   
>   	/* If there are no AP instructions, there is nothing to pass through. */
> -	if (!ap_instructions_available())
> -		return -ENODEV;
> +	if (!ap_instructions_available()) {
> +		ret = -ENODEV;
> +		goto err_debug;
> +	}
>   
>   	ret = vfio_ap_matrix_dev_create();
>   	if (ret)
> -		return ret;
> +		goto err_debug;
>   
>   	ret = ap_driver_register(&vfio_ap_drv, THIS_MODULE, VFIO_AP_DRV_NAME);
> -	if (ret) {
> -		vfio_ap_matrix_dev_destroy();
> -		return ret;
> -	}
> +	if (ret)
> +		goto err_matrix;
>   
>   	ret = vfio_ap_mdev_register();
> -	if (ret) {
> -		ap_driver_unregister(&vfio_ap_drv);
> -		vfio_ap_matrix_dev_destroy();
> -
> -		return ret;
> -	}
> +	if (ret)
> +		goto err_ap_driver;
>   
>   	return 0;
> +
> +err_ap_driver:
> +	ap_driver_unregister(&vfio_ap_drv);
> +err_matrix:
> +	vfio_ap_matrix_dev_destroy();
> +err_debug:
> +	debug_unregister(vfio_ap_dbf_info);
> +	return ret;
>   }
>   
>   static void __exit vfio_ap_exit(void)


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] s390/vfio-ap: Unregister the debug area on init failure
  2026-12-03 17:06 ` Anthony Krowiak
@ 2026-12-04  2:09   ` Haoxiang Li
  2026-12-04  9:58     ` Anthony Krowiak
  0 siblings, 1 reply; 5+ messages in thread
From: Haoxiang Li @ 2026-12-04  2:09 UTC (permalink / raw)
  To: Anthony Krowiak
  Cc: pasic, jjherne, freude, dengler, hca, gor, agordeev, borntraeger,
	svens, mjrosato, linux-s390, kvm


Hi,
At 2026-12-04 01:06:21, "Anthony Krowiak" <akrowiak@linux.ibm.com> wrote:
>
>Why not just move the vfio_ap_dbf_info_init() call to the end of the
>function? That would eliminate the need for the goto's
>

Thanks for the suggestion!

Moving vfio_ap_dbf_info_init() to the end would work. But since
vfio_ap_dbf_info_init() can itself fail, we would still need to unwind
the previously acquired resources. I don't think this would
simplify the error handling much.

Best Regards,
Haoxiang Li

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] s390/vfio-ap: Unregister the debug area on init failure
  2026-12-04  2:09   ` Haoxiang Li
@ 2026-12-04  9:58     ` Anthony Krowiak
  0 siblings, 0 replies; 5+ messages in thread
From: Anthony Krowiak @ 2026-12-04  9:58 UTC (permalink / raw)
  To: linux-s390



On 12/3/26 9:09 PM, Haoxiang Li wrote:
> 
> Hi,
> At 2026-12-04 01:06:21, "Anthony Krowiak" <akrowiak@linux.ibm.com> wrote:
>>
>> Why not just move the vfio_ap_dbf_info_init() call to the end of the
>> function? That would eliminate the need for the goto's
>>
> 
> Thanks for the suggestion!
> 
> Moving vfio_ap_dbf_info_init() to the end would work. But since
> vfio_ap_dbf_info_init() can itself fail, we would still need to unwind
> the previously acquired resources. I don't think this would
> simplify the error handling much.

The previously acquired resources in the original code are unwound
at the point of failure, so the only change to the code would
be moving the vfio_ap_dbf_info_init() to the end. It's not a big
deal and if you choose to keep the patch as-is, I am fine with
that.

> 
> Best Regards,
> Haoxiang Li


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-12-04  9:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 16:12 [PATCH] s390/vfio-ap: Unregister the debug area on init failure Haoxiang Li
2026-12-03 16:21 ` sashiko-bot
2026-12-03 17:06 ` Anthony Krowiak
2026-12-04  2:09   ` Haoxiang Li
2026-12-04  9:58     ` Anthony Krowiak

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.