public inbox for linux-s390@vger.kernel.org
 help / color / mirror / Atom feed
From: Tony Krowiak <akrowiak@linux.ibm.com>
To: Halil Pasic <pasic@linux.ibm.com>
Cc: linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org,
	borntraeger@de.ibm.com, cohuck@redhat.com,
	pasic@linux.vnet.ibm.com, jjherne@linux.ibm.com, jgg@nvidia.com,
	alex.williamson@redhat.com, kwankhede@nvidia.com,
	frankja@linux.ibm.com, david@redhat.com, imbrenda@linux.ibm.com,
	hca@linux.ibm.com
Subject: Re: [PATCH] s390/vfio-ap: do not open code locks for VFIO_GROUP_NOTIFY_SET_KVM notification
Date: Thu, 15 Jul 2021 10:38:54 -0400	[thread overview]
Message-ID: <0e5fae99-762e-8060-c9ed-36674effa68b@linux.ibm.com> (raw)
In-Reply-To: <20210715154451.3f0c264e.pasic@linux.ibm.com>



On 7/15/21 9:44 AM, Halil Pasic wrote:
> On Wed,  7 Jul 2021 11:41:56 -0400
> Tony Krowiak <akrowiak@linux.ibm.com> wrote:
>
> First sorry for being this late with having a more serious look at the
> code.
>
>
>> @@ -270,6 +270,9 @@ static struct ap_queue_status vfio_ap_irq_enable(struct vfio_ap_queue *q,
>>    * We take the matrix_dev lock to ensure serialization on queues and
>>    * mediated device access.
>>    *
>> + * Note: This function must be called with a read lock held on
>> + *	 vcpu->kvm->arch.crypto.pqap_hook_rwsem.
>> + *
>
> That is a fine synchronization for the pqap_hook, but I don't think it
> is sufficient for everything.
>
>
>>    * Return 0 if we could handle the request inside KVM.
>>    * otherwise, returns -EOPNOTSUPP to let QEMU handle the fault.
>>    */
>> @@ -287,22 +290,12 @@ static int handle_pqap(struct kvm_vcpu *vcpu)
>>   		return -EOPNOTSUPP;
>>
>>   	apqn = vcpu->run->s.regs.gprs[0] & 0xffff;
>> -	mutex_lock(&matrix_dev->lock);
> Here you drop a matrix_dev->lock critical section. And then
> you do all the interesting stuff. E.g.
> q = vfio_ap_get_queue(matrix_mdev, apqn);
> and
> vfio_ap_irq_enable(q, status & 0x07, vcpu->run->s.regs.gprs[2]);.
> Since in vfio_ap_get_queue() we do the check if the queue belongs
> to the given guest, and examine the matrix (apm, aqm) I suppose
> that needs to be done holding a lock that protects the matrix,
> and to my best knowledge this is still matrix_dev->lock. It would
> probably make sense to convert matrix_dev->lock into an rw_semaphore,
> or to introduce a some new rwlock which protects less state in the
> future, but right now AFAICT it is still matrix_dev->lock.
>
> So I don't think this patch should pass review.

Good catch. In an earlier patch review, Jason G suggested locking the 
kvm->lock
mutex outside of the kvm_arch_crypto_set_masks() and 
kvm_arch_crypto_clear_masks()
functions to resolve the lockdep splat resulting from locking the 
matrix_dev->lock
mutex prior to the kvm->lock mutex. I believe this will allow me to remove
the kvm_busy/wait queue scenario without introducing a new rwsem.

>
> Regards,
> Halil
>
>>   	if (!vcpu->kvm->arch.crypto.pqap_hook)
>>   		goto out_unlock;
>>   	matrix_mdev = container_of(vcpu->kvm->arch.crypto.pqap_hook,
>>   				   struct ap_matrix_mdev, pqap_hook);
>>
>> -	/*
>> -	 * If the KVM pointer is in the process of being set, wait until the
>> -	 * process has completed.
>> -	 */
>> -	wait_event_cmd(matrix_mdev->wait_for_kvm,
>> -		       !matrix_mdev->kvm_busy,
>> -		       mutex_unlock(&matrix_dev->lock),
>> -		       mutex_lock(&matrix_dev->lock));
>> -
>>   	/* If the there is no guest using the mdev, there is nothing to do */
>>   	if (!matrix_mdev->kvm)
>>   		goto out_unlock;


      reply	other threads:[~2021-07-15 14:39 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-07 15:41 [PATCH] s390/vfio-ap: do not open code locks for VFIO_GROUP_NOTIFY_SET_KVM notification Tony Krowiak
2021-07-12 13:42 ` Tony Krowiak
2021-07-12 23:38 ` Halil Pasic
2021-07-13 13:48   ` Tony Krowiak
2021-07-13 16:45     ` Halil Pasic
2021-07-13 17:05       ` Jason Gunthorpe
2021-07-13 19:04         ` Tony Krowiak
2021-07-13 19:21           ` Jason Gunthorpe
2021-07-14 13:25             ` Tony Krowiak
2021-07-14 17:56               ` Christian Borntraeger
2021-07-14 18:43                 ` Jason Gunthorpe
2021-07-14 19:02                 ` Alex Williamson
2021-07-15 11:31         ` Halil Pasic
2021-07-15 14:57           ` Jason Gunthorpe
2021-07-13 18:47       ` Tony Krowiak
2021-07-15 13:44 ` Halil Pasic
2021-07-15 14:38   ` Tony Krowiak [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=0e5fae99-762e-8060-c9ed-36674effa68b@linux.ibm.com \
    --to=akrowiak@linux.ibm.com \
    --cc=alex.williamson@redhat.com \
    --cc=borntraeger@de.ibm.com \
    --cc=cohuck@redhat.com \
    --cc=david@redhat.com \
    --cc=frankja@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=imbrenda@linux.ibm.com \
    --cc=jgg@nvidia.com \
    --cc=jjherne@linux.ibm.com \
    --cc=kwankhede@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=pasic@linux.ibm.com \
    --cc=pasic@linux.vnet.ibm.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