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 E38A1A0562; Fri, 19 Mar 2021 10:16:32 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 65F77140F61; Fri, 19 Mar 2021 10:16:32 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mails.dpdk.org (Postfix) with ESMTP id 7B1B6140F44 for ; Fri, 19 Mar 2021 10:16:30 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616145389; 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=HmStBsgeAKIfu9FQlqQMH6p4qrMPIpZZuCigfjw0qMY=; b=E7IDGoQy1WkywJBaFBHq09czBMFqCLlXsKN69VMPeT9QM9P49C/+ZiQFwrIeRedRgAvzSO BXKg1apSqlWu7Js4MXpTkr3HY4eaW0ZaBkJ+YxIJG4yCwKosUm/NT5cYYd5MF8bFVUTf+Q 0lraAA18gX4GWXt2BJ1FGhCzs9tILAU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-249-xFfcjkzLO6WTUEuwXK8kIA-1; Fri, 19 Mar 2021 05:16:27 -0400 X-MC-Unique: xFfcjkzLO6WTUEuwXK8kIA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 42D7D189CD07; Fri, 19 Mar 2021 09:16:26 +0000 (UTC) Received: from [10.36.110.37] (unknown [10.36.110.37]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 07A2A60CCB; Fri, 19 Mar 2021 09:16:24 +0000 (UTC) To: Keiichi Watanabe , dev@dpdk.org Cc: dgreid@chromium.org, chirantan@chromium.org, Chenbo Xia References: <20210202091039.3353569-1-keiichiw@chromium.org> From: Maxime Coquelin Message-ID: <63a57aa5-e409-7ca4-b0b6-2eb79dd7d55a@redhat.com> Date: Fri, 19 Mar 2021 10:16:23 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.0 MIME-Version: 1.0 In-Reply-To: <20210202091039.3353569-1-keiichiw@chromium.org> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=maxime.coquelin@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [PATCH] examples/vhost_blk: check protocol feature before get inflight info 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 Sender: "dev" Hi Keiichi, On 2/2/21 10:10 AM, Keiichi Watanabe wrote: > Avoid calling rte_vhost_get_vhost_ring_inflight() and > rte_vhost_get_vring_base_from_inflight() when > VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD is not set. > > Signed-off-by: Keiichi Watanabe > --- > examples/vhost_blk/vhost_blk.c | 22 +++++++++++++++++----- > lib/librte_vhost/rte_vhost.h | 13 +++++++++++++ > lib/librte_vhost/vhost.c | 14 ++++++++++++++ > 3 files changed, 44 insertions(+), 5 deletions(-) > > diff --git a/examples/vhost_blk/vhost_blk.c b/examples/vhost_blk/vhost_blk.c > index 7ea60863d..9f3e157a0 100644 > --- a/examples/vhost_blk/vhost_blk.c > +++ b/examples/vhost_blk/vhost_blk.c > @@ -603,10 +603,10 @@ new_device(int vid) > struct vhost_blk_ctrlr *ctrlr; > struct vhost_blk_queue *vq; > char path[PATH_MAX]; > - uint64_t features; > + uint64_t features, protocol_features; > pthread_t tid; > int i, ret; > - bool packed_ring; > + bool packed_ring, inflight_shmfd; > > ret = rte_vhost_get_ifname(vid, path, PATH_MAX); > if (ret) { > @@ -631,6 +631,15 @@ new_device(int vid) > } > packed_ring = !!(features & (1ULL << VIRTIO_F_RING_PACKED)); > > + ret = rte_vhost_get_negotiated_protocol_features( > + vid, &protocol_features); > + if (ret) { > + fprintf(stderr, > + "Failed to get the negotiated protocol features\n"); > + return -1; > + } > + inflight_shmfd = !!(features & (1ULL << VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)); > + > /* Disable Notifications and init last idx */ > for (i = 0; i < NUM_OF_BLK_QUEUES; i++) { > vq = &ctrlr->queues[i]; > @@ -641,10 +650,13 @@ new_device(int vid) > assert(rte_vhost_get_vring_base(ctrlr->vid, i, > &vq->last_avail_idx, > &vq->last_used_idx) == 0); > - assert(rte_vhost_get_vhost_ring_inflight(ctrlr->vid, i, > - &vq->inflight_ring) == 0); > > - if (packed_ring) { > + if (inflight_shmfd) > + assert(rte_vhost_get_vhost_ring_inflight( > + ctrlr->vid, i, > + &vq->inflight_ring) == 0); > + > + if (packed_ring && inflight_shmfd) { > /* for the reconnection */ > assert(rte_vhost_get_vring_base_from_inflight( > ctrlr->vid, i, > diff --git a/lib/librte_vhost/rte_vhost.h b/lib/librte_vhost/rte_vhost.h > index 010f16086..2744374af 100644 > --- a/lib/librte_vhost/rte_vhost.h > +++ b/lib/librte_vhost/rte_vhost.h > @@ -567,6 +567,19 @@ rte_vhost_driver_get_queue_num(const char *path, uint32_t *queue_num); > */ > int rte_vhost_get_negotiated_features(int vid, uint64_t *features); > > +/** > + * Get the protocol feature bits after negotiation > + * > + * @param vid > + * Vhost device ID > + * @param protocol_features > + * A pointer to store the queried protocol feature bits > + * @return > + * 0 on success, -1 on failure > + */ > +int rte_vhost_get_negotiated_protocol_features(int vid, > + uint64_t *protocol_features); > + > /* Register callbacks. */ > int rte_vhost_driver_callback_register(const char *path, > struct vhost_device_ops const * const ops); > diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c > index efb136edd..61189ce93 100644 > --- a/lib/librte_vhost/vhost.c > +++ b/lib/librte_vhost/vhost.c > @@ -868,6 +868,20 @@ rte_vhost_get_negotiated_features(int vid, uint64_t *features) > return 0; > } > > +int > +rte_vhost_get_negotiated_protocol_features(int vid, > + uint64_t *protocol_features) > +{ > + struct virtio_net *dev; > + > + dev = get_device(vid); > + if (dev == NULL || protocol_features == NULL) > + return -1; > + > + *protocol_features = dev->protocol_features; > + return 0; > +} > + > int > rte_vhost_get_mem_table(int vid, struct rte_vhost_memory **mem) > { > The Vhost lib part should be in a dedicated patch and new API should be added in its version.map as experimental. Thanks, Maxime