From patchwork Mon Oct 26 16:39:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Moreno X-Patchwork-Id: 82213 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 6D39AA04DD; Mon, 26 Oct 2020 17:41:48 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 4E27B354D; Mon, 26 Oct 2020 17:40:04 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by dpdk.org (Postfix) with ESMTP id A22672C15 for ; Mon, 26 Oct 2020 17:39:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603730396; 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=hsXsvli/f76Ou04a3sm1+WpOxa5Xsj6zxlSnLYwUWrA=; b=G8Cldyc5aFQTc8q5EXiLOpB37/76lFRGmNrWtgEfhfAQt589IyOvzjnHqj5xQepshi+VxB 8hhBk70w46oUCy6QeINomlEbnxxOdjXHwqP3A9NXQc1wv7A4gpriUCjbvbZ4xco+BuAWI9 54Jz2LLIkOr2yptszEY6Tati7y5cCCM= 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-541-HqE1kEGrP1W0LtH7vakfrw-1; Mon, 26 Oct 2020 12:39:54 -0400 X-MC-Unique: HqE1kEGrP1W0LtH7vakfrw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C6B0B8799EF; Mon, 26 Oct 2020 16:39:52 +0000 (UTC) Received: from amorenoz.users.ipa.redhat.com (ovpn-114-135.ams2.redhat.com [10.36.114.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4024162A15; Mon, 26 Oct 2020 16:39:51 +0000 (UTC) From: Adrian Moreno To: dev@dpdk.org Cc: yinan.wang@intel.com, patrick.fu@intel.com, chenbo.xia@intel.com, zhihong.wang@intel.com, maxime.coquelin@redhat.com, Adrian Moreno Date: Mon, 26 Oct 2020 17:39:27 +0100 Message-Id: <20201026163930.94032-4-amorenoz@redhat.com> In-Reply-To: <20201026163930.94032-1-amorenoz@redhat.com> References: <20201026163930.94032-1-amorenoz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=amorenoz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH v3 3/6] net/virtio-user: ignore result if STATUS is unsupported X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 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" GET/SET STATUS is an optional feature, so it may not be negotiated. In that case, the VIRTIO_GET_STATUS call will not update the status (given as a pointer argument). Failing to identify this case would lead to undefined behavior as the device status will be updated with the value of a stack-allocated variable. To fix this, return ENOTSUP if the feature is not supported and, in that case, don't update device status. Fixes: 44102e6298e7 ("net/virtio: check protocol feature in user backend") Cc: maxime.coquelin@redhat.com Cc stable@dpdk.org Signed-off-by: Adrian Moreno Reviewed-by: Maxime Coquelin --- drivers/net/virtio/virtio_user/vhost_user.c | 4 +-- .../net/virtio/virtio_user/virtio_user_dev.c | 28 +++++++++---------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/drivers/net/virtio/virtio_user/vhost_user.c b/drivers/net/virtio/virtio_user/vhost_user.c index 450d77e92..b93e65c60 100644 --- a/drivers/net/virtio/virtio_user/vhost_user.c +++ b/drivers/net/virtio/virtio_user/vhost_user.c @@ -281,7 +281,7 @@ vhost_user_sock(struct virtio_user_dev *dev, if (!(dev->status & VIRTIO_CONFIG_STATUS_FEATURES_OK) || (!(dev->protocol_features & (1ULL << VHOST_USER_PROTOCOL_F_STATUS)))) - return 0; + return -ENOTSUP; /* Fallthrough */ case VHOST_USER_GET_FEATURES: case VHOST_USER_GET_PROTOCOL_FEATURES: @@ -292,7 +292,7 @@ vhost_user_sock(struct virtio_user_dev *dev, if (!(dev->status & VIRTIO_CONFIG_STATUS_FEATURES_OK) || (!(dev->protocol_features & (1ULL << VHOST_USER_PROTOCOL_F_STATUS)))) - return 0; + return -ENOTSUP; if (has_reply_ack) msg.flags |= VHOST_USER_NEED_REPLY_MASK; diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c index 27814eadb..5a1e76006 100644 --- a/drivers/net/virtio/virtio_user/virtio_user_dev.c +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c @@ -818,15 +818,13 @@ virtio_user_send_status_update(struct virtio_user_dev *dev, uint8_t status) ret = dev->ops->send_request(dev, VHOST_USER_SET_STATUS, &status); else - return 0; + ret = -ENOTSUP; - if (ret) { + if (ret && ret != -ENOTSUP) { PMD_INIT_LOG(ERR, "VHOST_USER_SET_STATUS failed (%d): %s", ret, strerror(errno)); - return -1; } - - return 0; + return ret; } int @@ -849,17 +847,12 @@ virtio_user_update_status(struct virtio_user_dev *dev) err = dev->ops->send_request(dev, VHOST_USER_GET_STATUS, &status); } else { - return 0; - } - - if (err) { - PMD_INIT_LOG(ERR, "VHOST_USER_GET_STATUS failed (%d): %s", err, - strerror(errno)); - return -1; + err = -ENOTSUP; } - dev->status = status; - PMD_INIT_LOG(DEBUG, "Updated Device Status(0x%08x):\n" + if (!err) { + dev->status = status; + PMD_INIT_LOG(DEBUG, "Updated Device Status(0x%08x):\n" "\t-RESET: %u\n" "\t-ACKNOWLEDGE: %u\n" "\t-DRIVER: %u\n" @@ -875,5 +868,10 @@ virtio_user_update_status(struct virtio_user_dev *dev) !!(dev->status & VIRTIO_CONFIG_STATUS_FEATURES_OK), !!(dev->status & VIRTIO_CONFIG_STATUS_DEV_NEED_RESET), !!(dev->status & VIRTIO_CONFIG_STATUS_FAILED)); - return 0; + } else if (err != -ENOTSUP) { + PMD_INIT_LOG(ERR, "VHOST_USER_GET_STATUS failed (%d): %s", err, + strerror(errno)); + } + + return err; }