From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 7A8DFA0540; Wed, 21 Sep 2022 11:41:20 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6A2D840F17; Wed, 21 Sep 2022 11:41:20 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id 1C2874014F for ; Wed, 21 Sep 2022 11:41:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663753277; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AEQeMZXh9U/2+k9frNdKrt77T9Y5C4W9gX1TUVkUeAo=; b=KRO1VVRPAWL9UhZmdcuFIngxRgkwQRBj/FusL4CR9zBcLR9KOPhufnpDzL+8fQe/P2ieqW wdBiXwBZxnDlS+kQF9IC5JcR6nfR4lmda4nibYybpbiZIE5i2IQXDgWB0GKqSZYbC1k+oU fxPKBcO/5d48A9P7weh/UubHv7h8upw= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-411-C-YbQahmO8qPaTNH_1EVVA-1; Wed, 21 Sep 2022 05:41:14 -0400 X-MC-Unique: C-YbQahmO8qPaTNH_1EVVA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3A466185A79C; Wed, 21 Sep 2022 09:41:14 +0000 (UTC) Received: from [10.39.208.16] (unknown [10.39.208.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 516FE2024CBF; Wed, 21 Sep 2022 09:41:13 +0000 (UTC) Message-ID: Date: Wed, 21 Sep 2022 11:41:11 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.0 Subject: Re: [PATCH] vhost: use try_lock in rte_vhost_vring_call To: "Liu, Changpeng" , "dev@dpdk.org" Cc: "Xia, Chenbo" References: <20220906022225.17215-1-changpeng.liu@intel.com> <2a63f996-84f4-434f-1b19-5dd035870e9d@redhat.com> From: Maxime Coquelin In-Reply-To: X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On 9/20/22 10:43, Liu, Changpeng wrote: > > >> -----Original Message----- >> From: Maxime Coquelin >> Sent: Tuesday, September 20, 2022 4:13 PM >> To: Liu, Changpeng ; dev@dpdk.org >> Cc: Xia, Chenbo >> Subject: Re: [PATCH] vhost: use try_lock in rte_vhost_vring_call >> >> >> >> On 9/20/22 09:45, Liu, Changpeng wrote: >>> >>> >>>> -----Original Message----- >>>> From: Maxime Coquelin >>>> Sent: Tuesday, September 20, 2022 3:35 PM >>>> To: Liu, Changpeng ; dev@dpdk.org >>>> Cc: Xia, Chenbo >>>> Subject: Re: [PATCH] vhost: use try_lock in rte_vhost_vring_call >>>> >>>> >>>> >>>> On 9/20/22 09:29, Liu, Changpeng wrote: >>>>> Hi Maxime, >>>>> >>>>>> -----Original Message----- >>>>>> From: Maxime Coquelin >>>>>> Sent: Tuesday, September 20, 2022 3:19 PM >>>>>> To: Liu, Changpeng ; dev@dpdk.org >>>>>> Cc: Xia, Chenbo >>>>>> Subject: Re: [PATCH] vhost: use try_lock in rte_vhost_vring_call >>>>>> >>>>>> >>>>>> >>>>>> On 9/6/22 04:22, Changpeng Liu wrote: >>>>>>> Note that this function is in data path, so the thread context >>>>>>> may not same as socket messages processing context, by using >>>>>>> try_lock here, users can have another try in case of VQ's access >>>>>>> lock is held by `vhost-events` thread. >>>>>>> >>>>>>> Signed-off-by: Changpeng Liu >>>>>>> --- >>>>>>> lib/vhost/vhost.c | 6 +++++- >>>>>>> 1 file changed, 5 insertions(+), 1 deletion(-) >>>>>>> >>>>>>> diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c >>>>>>> index 60cb05a0ff..072d2acb7b 100644 >>>>>>> --- a/lib/vhost/vhost.c >>>>>>> +++ b/lib/vhost/vhost.c >>>>>>> @@ -1329,7 +1329,11 @@ rte_vhost_vring_call(int vid, uint16_t vring_idx) >>>>>>> if (!vq) >>>>>>> return -1; >>>>>>> >>>>>>> - rte_spinlock_lock(&vq->access_lock); >>>>>>> + if (!rte_spinlock_trylock(&vq->access_lock)) { >>>>>>> + VHOST_LOG_CONFIG(dev->ifname, DEBUG, >>>>>>> + "failed to kick guest, virtqueue busy.\n"); >>>>>>> + return -1; >>>>>>> + } >>>>>>> >>>>>>> if (vq_is_packed(dev)) >>>>>>> vhost_vring_call_packed(dev, vq); >>>>>> >>>>>> I think that's problematic, because it will break other applications >>>>>> that currently rely on the API to block until the call is done. >>>>>> >>>>>> Just some internal DPDK usage of this API: >>>>>> ./drivers/vdpa/ifc/ifcvf_vdpa.c:871: rte_vhost_vring_call(internal->vid, >>>>>> qid); >>>>>> ./examples/vhost/virtio_net.c:236: rte_vhost_vring_call(dev->vid, >> queue_id); >>>>>> ./examples/vhost/virtio_net.c:446: rte_vhost_vring_call(dev->vid, >> queue_id); >>>>>> ./examples/vhost_blk/vhost_blk.c:99: >>>>>> rte_vhost_vring_call(task->ctrlr->vid, vq->id); >>>>>> ./examples/vhost_blk/vhost_blk.c:134: >>>>>> rte_vhost_vring_call(task->ctrlr->vid, vq->id); >>>>>> >>>>>> This change will break all the above uses. >>>>>> >>>>>> And that's not counting external projects. >>>>>> >>>>>> ou should better introduce a new API that does not block. >>>>> Could you add a new API to do this? >>>> > >>>>> I think we can use the new API in SPDK as a workaround, note that SPDK >> project >>>> is blocked for >>>>> a while which can't be used with DPDK 22.05 or newer. >>>> >>>> DPDK v22.05? >>>> What is the commit introducing the regression? >>> Here is the commit introducing this issue >>> c5736998305d ("vhost: fix missing virtqueue lock protection") >>> Bugzilla ID: 1015 >> >> Ok, it cannot be reverted, as it prevents some undefined >> behaviors/crashes. >> >>>> >>>> Note that if we introduce a new API, it won't be backported to stable >>>> branches. >>> I understand, but do we have better idea in short time? we're planning >>> to release SPDK 22.09 recently. >> >> You can have another thread that sends the call? > We already use two threads to do this. Here is the example for existing code in SPDK: > > DPDK vhost-events thread SPDK thread > > SET_VRING_KICK VQ1 ----> Start polling VQ1 > Reply to DPDK <---- Done > SET_VRING_KICK VQ2 ----> thread is blocked on VQ's access lock, SPDK thread can't provide reply message > > For example, we can just return for SET_VRING_KICK VQ2 message without checking SPDK thread, but this leave > uncertain replies to VM. I'm sorry but you will have to find a workaround while v22.11 is out and you can consume it. We can neither backport new API nor we can break all the other applications not handling locking failure. Regarding the new API for v22.11, I should be named something like rte_vhost_vring_call_nonblock(), and ideally should return some like -EAGAIN instead of -1 o that the applications can distinguish between a real failure and a need for retry. Regards, Maxime >> >>>> >>>> >>>>> Vhost-blk and scsi devices are not same with vhost-net, we need to cover >>>> SeaBIOS and VM >>>>> cases, so we need to start processing vrings after 1 vring is ready. >>>>>> >>>>>> Regards, >>>>>> Maxime >>>>> >>> >