From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by dpdk.org (Postfix) with ESMTP id 2760B5B38 for ; Mon, 3 Sep 2018 12:11:01 +0200 (CEST) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20180903101100euoutp02fe414dd05ffce6a501500b0d55d776b1~Q3BYq_kjs1594815948euoutp02C for ; Mon, 3 Sep 2018 10:11:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20180903101100euoutp02fe414dd05ffce6a501500b0d55d776b1~Q3BYq_kjs1594815948euoutp02C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1535969460; bh=1c9tMCShJV6sX5DzlnK8A1z1hgg0U1LoI5jAw8h+r4I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fKV8d3eXUx4WNQmtE6n6fubhnpfe3Wdflqb5KcygOnZcndeQehdhdrsFkJQTToxCu BYLEFqMx7dUyXoVo6gePzpFpjh3u9Ue061AjSNESxpkYifoamVhBUWPGPliwZ82X16 pNT3DFd9JlUiSptOLAlmH5f06N8i1s/wRVbzQMEQ= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20180903101100eucas1p2b45803c15bde9b0cfb7e7f841fa466ae~Q3BYSGCSs2406224062eucas1p2Q; Mon, 3 Sep 2018 10:11:00 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 8C.A6.04806.3B80D8B5; Mon, 3 Sep 2018 11:10:59 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20180903101059eucas1p2030d1e9077a03bc5d0613ba0311e1eab~Q3BXc1AtS3196731967eucas1p2z; Mon, 3 Sep 2018 10:10:59 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20180903101059eusmtrp2ffa5b25cbf850121e88b9f37830c9b41~Q3BXL_s3x0319003190eusmtrp2S; Mon, 3 Sep 2018 10:10:59 +0000 (GMT) X-AuditID: cbfec7f5-79db79c0000012c6-18-5b8d08b3b62f Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id C5.71.04284.2B80D8B5; Mon, 3 Sep 2018 11:10:58 +0100 (BST) Received: from imaximets.rnd.samsung.ru (unknown [106.109.129.180]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20180903101058eusmtip263e521fa370521df1e9353535d7d1a97~Q3BWq9RVO3028330283eusmtip28; Mon, 3 Sep 2018 10:10:58 +0000 (GMT) From: Ilya Maximets To: dev@dpdk.org Cc: Maxime Coquelin , Tiwei Bie , Zhihong Wang , Ilya Maximets , stable@dpdk.org Date: Mon, 3 Sep 2018 13:12:24 +0300 X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180817113354.16140-1-i.maximets@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrIIsWRmVeSWpSXmKPExsWy7djP87qbOXqjDS6usrZ492k7k8WV9p/s Fsc697BY/Ov4w26xteE/k8Xmi5OYHNg8fi1YyuqxeM9LJo/3+66yefRtWcUYwBLFZZOSmpNZ llqkb5fAlfGw8TRjwR+dis0b4xsY76p0MXJySAiYSJxvnMDexcjFISSwglHiW/9GJgjnC6PE x83ToDKfGSU2r7/NBtPyaepyVojEckaJhlUvWSCcH4wS7e87mUCq2AR0JE6tPsIIYosICEh8 7lzMBlLELLCVUeLH9A/MIAlhAR+JGWe+gI1lEVCV+LWhnR1ihbzE6g0HgGo4ODgFbCSmb3AG 6ZUQeMwmcejSKrChvAJlEp8X9jKC1EgIuEjsOlcL0Sos8er4FqgxMhL/d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U0t7A0NDc2NzazUBLnPW9Q GSUkkJ5YkpqdmlqQWgTTx8TBKdXAqLFiHcN5drv5d5zMqr2cVxpKr9nme31SWtCRDcEmdzbk ODS8/cpv+kRn0doy7SrLtFmT6+fYBWhP8s1ObK4rrYjfK6XKvKuwN0jzz8zIa4JfVfbfmCnr pTX9XcfRDV4S3e8PP18jpW+p6fLyz6WpWouOBL55v7qKea108uOnsYuO61menuxwVYmlOCPR UIu5qDgRAHmk+yJmAgAA Message-Id: <20180903101059eucas1p2030d1e9077a03bc5d0613ba0311e1eab~Q3BXc1AtS3196731967eucas1p2z@eucas1p2.samsung.com> X-CMS-MailID: 20180903101059eucas1p2030d1e9077a03bc5d0613ba0311e1eab X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20180903101059eucas1p2030d1e9077a03bc5d0613ba0311e1eab X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20180903101059eucas1p2030d1e9077a03bc5d0613ba0311e1eab References: <20180817113354.16140-1-i.maximets@samsung.com> Subject: [dpdk-dev] [PATCH v2] vhost-user: drop connection on message handling failures 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: , X-List-Received-Date: Mon, 03 Sep 2018 10:11:02 -0000 There are a lot of cases where vhost-user massage handling could fail and end up in a fully not recoverable state. For example, allocation failures of shadow used ring and batched copy array are not recoverable and leads to the segmentation faults like this on the receiving/transmission path: Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 0x7f913fecf0 (LWP 43625)] in copy_desc_to_mbuf () at /lib/librte_vhost/virtio_net.c:760 760 batch_copy[vq->batch_copy_nb_elems].dst = This could be easily reproduced in case of low memory or big number of vhost-user ports. Fix that by propagating error to the upper layer which will end up with disconnection in case we can not report to the message sender when the error happens. Fixes: f689586bc060 ("vhost: shadow used ring update") Cc: stable@dpdk.org Signed-off-by: Ilya Maximets --- v2: * Patch changed to cover most of possible failures at once. [Tiwei Bie] lib/librte_vhost/vhost_user.c | 51 +++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index a2d4c9ffc..7997b890f 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -1012,7 +1012,7 @@ vhost_user_set_vring_call(struct virtio_net *dev, struct VhostUserMsg *pmsg) vq->callfd = file.fd; } -static void +static int vhost_user_set_vring_kick(struct virtio_net **pdev, struct VhostUserMsg *pmsg) { struct vhost_vring_file file; @@ -1030,7 +1030,7 @@ vhost_user_set_vring_kick(struct virtio_net **pdev, struct VhostUserMsg *pmsg) /* Interpret ring addresses only when ring is started. */ dev = translate_ring_addresses(dev, file.index); if (!dev) - return; + return -1; *pdev = dev; @@ -1047,6 +1047,7 @@ vhost_user_set_vring_kick(struct virtio_net **pdev, struct VhostUserMsg *pmsg) if (vq->kickfd >= 0) close(vq->kickfd); vq->kickfd = file.fd; + return 0; } static void @@ -1170,14 +1171,19 @@ vhost_user_get_protocol_features(struct virtio_net *dev, msg->size = sizeof(msg->payload.u64); } -static void +static int vhost_user_set_protocol_features(struct virtio_net *dev, uint64_t protocol_features) { - if (protocol_features & ~VHOST_USER_PROTOCOL_FEATURES) - return; + if (protocol_features & ~VHOST_USER_PROTOCOL_FEATURES) { + RTE_LOG(ERR, VHOST_CONFIG, + "(%d) received invalid protocol features.\n", + dev->vid); + return -1; + } dev->protocol_features = protocol_features; + return 0; } static int @@ -1655,8 +1661,6 @@ vhost_user_msg_handler(int vid, int fd) break; case VHOST_USER_SET_FEATURES: ret = vhost_user_set_features(dev, msg.payload.u64); - if (ret) - return -1; break; case VHOST_USER_GET_PROTOCOL_FEATURES: @@ -1664,14 +1668,14 @@ vhost_user_msg_handler(int vid, int fd) send_vhost_reply(fd, &msg); break; case VHOST_USER_SET_PROTOCOL_FEATURES: - vhost_user_set_protocol_features(dev, msg.payload.u64); + ret = vhost_user_set_protocol_features(dev, msg.payload.u64); break; case VHOST_USER_SET_OWNER: - vhost_user_set_owner(); + ret = vhost_user_set_owner(); break; case VHOST_USER_RESET_OWNER: - vhost_user_reset_owner(dev); + ret = vhost_user_reset_owner(dev); break; case VHOST_USER_SET_MEM_TABLE: @@ -1679,8 +1683,9 @@ vhost_user_msg_handler(int vid, int fd) break; case VHOST_USER_SET_LOG_BASE: - vhost_user_set_log_base(dev, &msg); - + ret = vhost_user_set_log_base(dev, &msg); + if (ret) + goto skip_to_reply; /* it needs a reply */ msg.size = sizeof(msg.payload.u64); send_vhost_reply(fd, &msg); @@ -1691,23 +1696,25 @@ vhost_user_msg_handler(int vid, int fd) break; case VHOST_USER_SET_VRING_NUM: - vhost_user_set_vring_num(dev, &msg); + ret = vhost_user_set_vring_num(dev, &msg); break; case VHOST_USER_SET_VRING_ADDR: - vhost_user_set_vring_addr(&dev, &msg); + ret = vhost_user_set_vring_addr(&dev, &msg); break; case VHOST_USER_SET_VRING_BASE: - vhost_user_set_vring_base(dev, &msg); + ret = vhost_user_set_vring_base(dev, &msg); break; case VHOST_USER_GET_VRING_BASE: - vhost_user_get_vring_base(dev, &msg); + ret = vhost_user_get_vring_base(dev, &msg); + if (ret) + goto skip_to_reply; msg.size = sizeof(msg.payload.state); send_vhost_reply(fd, &msg); break; case VHOST_USER_SET_VRING_KICK: - vhost_user_set_vring_kick(&dev, &msg); + ret = vhost_user_set_vring_kick(&dev, &msg); break; case VHOST_USER_SET_VRING_CALL: vhost_user_set_vring_call(dev, &msg); @@ -1726,10 +1733,10 @@ vhost_user_msg_handler(int vid, int fd) break; case VHOST_USER_SET_VRING_ENABLE: - vhost_user_set_vring_enable(dev, &msg); + ret = vhost_user_set_vring_enable(dev, &msg); break; case VHOST_USER_SEND_RARP: - vhost_user_send_rarp(dev, &msg); + ret = vhost_user_send_rarp(dev, &msg); break; case VHOST_USER_NET_SET_MTU: @@ -1750,7 +1757,7 @@ vhost_user_msg_handler(int vid, int fd) } skip_to_post_handle: - if (dev->extern_ops.post_msg_handle) { + if (!ret && dev->extern_ops.post_msg_handle) { uint32_t need_reply; ret = (*dev->extern_ops.post_msg_handle)( @@ -1770,6 +1777,10 @@ vhost_user_msg_handler(int vid, int fd) msg.payload.u64 = !!ret; msg.size = sizeof(msg.payload.u64); send_vhost_reply(fd, &msg); + } else if (ret) { + RTE_LOG(ERR, VHOST_CONFIG, + "vhost message handling failed.\n"); + return -1; } if (!(dev->flags & VIRTIO_DEV_RUNNING) && virtio_is_ready(dev)) { -- 2.17.1