[PATCH v3 8/9] vhost_scsi: Add check for inherit_owner status

Cindy Lu posted 9 patches 1 year, 3 months ago
There is a newer version of this series
[PATCH v3 8/9] vhost_scsi: Add check for inherit_owner status
Posted by Cindy Lu 1 year, 3 months ago
The vhost_scsi VHOST_NEW_WORKER requires the inherit_owner
setting to be true. So we need to implement a check for this.

Signed-off-by: Cindy Lu <lulu@redhat.com>
---
 drivers/vhost/scsi.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c
index 006ffacf1c56..05290298b5ab 100644
--- a/drivers/vhost/scsi.c
+++ b/drivers/vhost/scsi.c
@@ -2083,6 +2083,11 @@ vhost_scsi_ioctl(struct file *f,
 			return -EFAULT;
 		return vhost_scsi_set_features(vs, features);
 	case VHOST_NEW_WORKER:
+		/*vhost-scsi VHOST_NEW_WORKER requires inherit_owner to be true*/
+		if (vs->dev.inherit_owner != true)
+			return -EFAULT;
+
+		fallthrough;
 	case VHOST_FREE_WORKER:
 	case VHOST_ATTACH_VRING_WORKER:
 	case VHOST_GET_VRING_WORKER:
-- 
2.45.0
Re: [PATCH v3 8/9] vhost_scsi: Add check for inherit_owner status
Posted by Mike Christie 1 year, 2 months ago
On 11/5/24 1:25 AM, Cindy Lu wrote:
> The vhost_scsi VHOST_NEW_WORKER requires the inherit_owner
> setting to be true. So we need to implement a check for this.
> 
> Signed-off-by: Cindy Lu <lulu@redhat.com>
> ---
>  drivers/vhost/scsi.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c
> index 006ffacf1c56..05290298b5ab 100644
> --- a/drivers/vhost/scsi.c
> +++ b/drivers/vhost/scsi.c
> @@ -2083,6 +2083,11 @@ vhost_scsi_ioctl(struct file *f,
>  			return -EFAULT;
>  		return vhost_scsi_set_features(vs, features);
>  	case VHOST_NEW_WORKER:
> +		/*vhost-scsi VHOST_NEW_WORKER requires inherit_owner to be true*/

The above comment is not really needed since we know it's
required from the check being added.

If you want to add a comment, I think it should describe why we
require it as that's not obvious from just looking at the check.

So maybe a more useful comment would be:

/*
 * vhost_tasks will account for worker threads under the parent's
 * NPROC value but kthreads do not. To avoid userspace overflowing
 * the system with worker threads inherit_owner must be true.
 */

> +		if (vs->dev.inherit_owner != true)

This check and the comment would apply to all vhost drivers so it
should go in vhost_worker_ioctl's VHOST_NEW_WORKER handling.


> +			return -EFAULT;
> +
> +		fallthrough;
>  	case VHOST_FREE_WORKER:
>  	case VHOST_ATTACH_VRING_WORKER:
>  	case VHOST_GET_VRING_WORKER: