From: Steven Sistare <steven.sistare@oracle.com>
To: Jason Wang <jasowang@redhat.com>
Cc: virtualization@lists.linux-foundation.org,
linux-kernel@vger.kernel.org,
"Michael S. Tsirkin" <mst@redhat.com>,
Si-Wei Liu <si-wei.liu@oracle.com>,
Eugenio Perez Martin <eperezma@redhat.com>,
Xie Yongji <xieyongji@bytedance.com>,
Stefano Garzarella <sgarzare@redhat.com>
Subject: Re: [PATCH V3 3/3] vdpa_sim: flush workers on suspend
Date: Tue, 21 May 2024 09:39:12 -0400 [thread overview]
Message-ID: <46f91e76-6f88-4f83-8854-10baed4e82c9@oracle.com> (raw)
In-Reply-To: <CACGkMEur=CoU1GgxNdweu-SfuutSN-a+LaHLkdtoWYJMnE+LOg@mail.gmail.com>
On 5/20/2024 10:32 PM, Jason Wang wrote:
> On Mon, May 20, 2024 at 11:21 PM Steve Sistare
> <steven.sistare@oracle.com> wrote:
>>
>> Flush to guarantee no workers are running when suspend returns.
>> Add a lock to enforce ordering between clearing running, flushing,
>> and posting new work in vdpasim_kick_vq. It must be a spin lock
>> because vdpasim_kick_vq may be reached va eventfd_write.
>>
>> Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
>> ---
>> drivers/vdpa/vdpa_sim/vdpa_sim.c | 16 ++++++++++++++--
>> drivers/vdpa/vdpa_sim/vdpa_sim.h | 1 +
>> 2 files changed, 15 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c
>> index 8ffea8430f95..67ed49d95bf0 100644
>> --- a/drivers/vdpa/vdpa_sim/vdpa_sim.c
>> +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c
>> @@ -322,7 +322,7 @@ static u16 vdpasim_get_vq_size(struct vdpa_device *vdpa, u16 idx)
>> return VDPASIM_QUEUE_MAX;
>> }
>>
>> -static void vdpasim_kick_vq(struct vdpa_device *vdpa, u16 idx)
>> +static void vdpasim_do_kick_vq(struct vdpa_device *vdpa, u16 idx)
>> {
>> struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
>> struct vdpasim_virtqueue *vq = &vdpasim->vqs[idx];
>> @@ -337,6 +337,15 @@ static void vdpasim_kick_vq(struct vdpa_device *vdpa, u16 idx)
>> vdpasim_schedule_work(vdpasim);
>> }
>>
>> +static void vdpasim_kick_vq(struct vdpa_device *vdpa, u16 idx)
>> +{
>> + struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
>> +
>> + spin_lock(&vdpasim->kick_lock);
>> + vdpasim_do_kick_vq(vdpa, idx);
>> + spin_unlock(&vdpasim->kick_lock);
>> +}
>> +
>> static void vdpasim_set_vq_cb(struct vdpa_device *vdpa, u16 idx,
>> struct vdpa_callback *cb)
>> {
>> @@ -520,8 +529,11 @@ static int vdpasim_suspend(struct vdpa_device *vdpa)
>> struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
>>
>> mutex_lock(&vdpasim->mutex);
>> + spin_lock(&vdpasim->kick_lock);
>> vdpasim->running = false;
>> + spin_unlock(&vdpasim->kick_lock);
>> mutex_unlock(&vdpasim->mutex);
>> + kthread_flush_work(&vdpasim->work);
>>
>> return 0;
>> }
>> @@ -537,7 +549,7 @@ static int vdpasim_resume(struct vdpa_device *vdpa)
>> if (vdpasim->pending_kick) {
>> /* Process pending descriptors */
>> for (i = 0; i < vdpasim->dev_attr.nvqs; ++i)
>> - vdpasim_kick_vq(vdpa, i);
>> + vdpasim_do_kick_vq(vdpa, i);
>>
>> vdpasim->pending_kick = false;
>> }
>> diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.h b/drivers/vdpa/vdpa_sim/vdpa_sim.h
>> index bb137e479763..5eb6ca9c5ec5 100644
>> --- a/drivers/vdpa/vdpa_sim/vdpa_sim.h
>> +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.h
>> @@ -75,6 +75,7 @@ struct vdpasim {
>> bool pending_kick;
>> /* spinlock to synchronize iommu table */
>> spinlock_t iommu_lock;
>> + spinlock_t kick_lock;
>
> It looks to me this is not initialized?
Yup, I lost that line while fiddling with different locking schemes.
Thanks, will fix in V4.
@@ -236,6 +236,7 @@ struct vdpasim *vdpasim_create(struct vdpasim_dev_attr
*dev_attr,
mutex_init(&vdpasim->mutex);
spin_lock_init(&vdpasim->iommu_lock);
+ spin_lock_init(&vdpasim->kick_lock);
With that fix, does this patch earn your RB?
- Steve
>> };
>>
>> struct vdpasim *vdpasim_create(struct vdpasim_dev_attr *attr,
>> --
>> 2.39.3
>>
>
next prev parent reply other threads:[~2024-05-21 13:39 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-20 15:20 [PATCH V3 0/3] " Steve Sistare
2024-05-20 15:21 ` [PATCH V3 1/3] vhost-vdpa: " Steve Sistare
2024-05-21 2:28 ` Jason Wang
2024-05-21 13:38 ` Steven Sistare
2024-05-22 3:41 ` Jason Wang
2024-05-20 15:21 ` [PATCH V3 2/3] vduse: suspend Steve Sistare
2024-05-21 2:30 ` Jason Wang
2024-05-21 13:38 ` Steven Sistare
2024-05-22 3:40 ` Jason Wang
2024-05-20 15:21 ` [PATCH V3 3/3] vdpa_sim: flush workers on suspend Steve Sistare
2024-05-21 2:32 ` Jason Wang
2024-05-21 13:39 ` Steven Sistare [this message]
2024-05-22 3:39 ` Jason Wang
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=46f91e76-6f88-4f83-8854-10baed4e82c9@oracle.com \
--to=steven.sistare@oracle.com \
--cc=eperezma@redhat.com \
--cc=jasowang@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--cc=sgarzare@redhat.com \
--cc=si-wei.liu@oracle.com \
--cc=virtualization@lists.linux-foundation.org \
--cc=xieyongji@bytedance.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®