All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mike Christie <michael.christie@oracle.com>
To: Stefano Garzarella <sgarzare@redhat.com>
Cc: stefanha@redhat.com, jasowang@redhat.com, mst@redhat.com,
	pbonzini@redhat.com, wh1sper@zju.edu.cn,
	virtualization@lists.linux-foundation.org
Subject: Re: [PATCH 1/1] vhost-scsi: Fix handling of multiple calls to vhost_scsi_set_endpoint
Date: Wed, 29 Jan 2025 10:51:23 -0600	[thread overview]
Message-ID: <466f4e29-5af3-4a51-9283-0f5c2ccb702c@oracle.com> (raw)
In-Reply-To: <bte2rkiy7tvefzanh6hsym3xawuyjznpcoevxcdifw7jqqep5r@vdanwnpihn27>

On 1/29/25 10:36 AM, Stefano Garzarella wrote:
>> diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c
>> index 9a4cbdc607fa..6bb64f3be7db 100644
>> --- a/drivers/vhost/scsi.c
>> +++ b/drivers/vhost/scsi.c
>> @@ -1828,14 +1828,19 @@ vhost_scsi_set_endpoint(struct vhost_scsi *vs,
>>         }
>>     }
>>
>> +    if (vs->vs_tpg) {
>> +        pr_err("vhost-scsi endpoint already set for %s.\n",
>> +               vs->vs_vhost_wwpn);
>> +        ret = -EEXIST;
>> +        goto out;
>> +    }
>> +
>>     len = sizeof(vs_tpg[0]) * VHOST_SCSI_MAX_TARGET;
>>     vs_tpg = kzalloc(len, GFP_KERNEL);
>>     if (!vs_tpg) {
>>         ret = -ENOMEM;
>>         goto out;
>>     }
>> -    if (vs->vs_tpg)
>> -        memcpy(vs_tpg, vs->vs_tpg, len);
>>
>>     mutex_lock(&vhost_scsi_mutex);
>>     list_for_each_entry(tpg, &vhost_scsi_list, tv_tpg_list) {
>> @@ -1851,12 +1856,6 @@ vhost_scsi_set_endpoint(struct vhost_scsi *vs,
>>         tv_tport = tpg->tport;
>>
>>         if (!strcmp(tv_tport->tport_name, t->vhost_wwpn)) {
>> -            if (vs->vs_tpg && vs->vs_tpg[tpg->tport_tpgt]) {
>> -                mutex_unlock(&tpg->tv_tpg_mutex);
>> -                mutex_unlock(&vhost_scsi_mutex);
>> -                ret = -EEXIST;
>> -                goto undepend;
>> -            }
>>             /*
>>              * In order to ensure individual vhost-scsi configfs
>>              * groups cannot be removed while in use by vhost ioctl,
>> @@ -1903,7 +1902,8 @@ vhost_scsi_set_endpoint(struct vhost_scsi *vs,
>>         }
>>         ret = 0;
>>     } else {
>> -        ret = -EEXIST;
>> +        ret = -ENODEV;
>> +        goto free_tpg;
>>     }
> 
> After this block there this code:
> 
>>
>>     /*
>      * Act as synchronize_rcu to make sure access to
>      * old vs->vs_tpg is finished.
>      */
>     vhost_scsi_flush(vs);
>     kfree(vs->vs_tpg);
>     vs->vs_tpg = vs_tpg;
>     goto out;
> 
> Should we adapt also that code, removing the kfree() and updating the comment?
> 
Yeah, I think I should. Will resend.

I think I originally was trying to make the patch smaller to make it easier
to backport but seeing it again I think it makes more sense to do the cleanup
in the same patch.

      reply	other threads:[~2025-01-29 16:51 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-21 21:31 [PATCH 1/1] vhost-scsi: Fix handling of multiple calls to vhost_scsi_set_endpoint Mike Christie
2025-01-28 18:56 ` Stefan Hajnoczi
2025-01-29 16:36 ` Stefano Garzarella
2025-01-29 16:51   ` Mike Christie [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=466f4e29-5af3-4a51-9283-0f5c2ccb702c@oracle.com \
    --to=michael.christie@oracle.com \
    --cc=jasowang@redhat.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=sgarzare@redhat.com \
    --cc=stefanha@redhat.com \
    --cc=virtualization@lists.linux-foundation.org \
    --cc=wh1sper@zju.edu.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.