From patchwork Sat Dec 15 01:26:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Qiang X-Patchwork-Id: 10731953 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B14CB14E2 for ; Sat, 15 Dec 2018 01:29:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 665212C9F6 for ; Sat, 15 Dec 2018 01:29:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5A5A82CA29; Sat, 15 Dec 2018 01:29:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8071C2CA1D for ; Sat, 15 Dec 2018 01:29:30 +0000 (UTC) Received: from localhost ([::1]:37125 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gXyll-0005Fw-OA for patchwork-qemu-devel@patchwork.kernel.org; Fri, 14 Dec 2018 20:29:29 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49953) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gXykZ-0005B0-8N for qemu-devel@nongnu.org; Fri, 14 Dec 2018 20:28:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gXykU-0003Me-92 for qemu-devel@nongnu.org; Fri, 14 Dec 2018 20:28:15 -0500 Received: from m12-13.163.com ([220.181.12.13]:55494) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gXykT-0003L4-Cb for qemu-devel@nongnu.org; Fri, 14 Dec 2018 20:28:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=9uiheijUBL6iX8+Kle gwuTrISrnD/t5S19mVFL7vMfY=; b=TD0AKobg32tEVdqoez3l3Oz4iTw6Ta2i0+ pz4ojhPzc/SH/H3l9U5xVDBqQX4+Wdo32qgNX3IN3vIw/IbF6klBpalM/zUCqgQN Di/HtAWlo2Bcm52QV2BFQmJj9VVpQ4GFdxlDZ/VMnVHSvAVlkgIKlzSDO5q2ev1X R33JCUfNY= Received: from localhost.localdomain (unknown [183.134.170.47]) by smtp9 (Coremail) with SMTP id DcCowABHyuiIWBRcdawzAA--.1809S3; Sat, 15 Dec 2018 09:27:43 +0800 (CST) From: Li Qiang To: thuth@redhat.com, lvivier@redhat.com, pbonzini@redhat.com, mst@redhat.com, peter.maydell@linaro.org, marcandre.lureau@redhat.com, berrange@redhat.com, jasowang@redhat.com Date: Fri, 14 Dec 2018 17:26:23 -0800 Message-Id: <20181215012625.73315-2-liq3ea@163.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181215012625.73315-1-liq3ea@163.com> References: <20181215012625.73315-1-liq3ea@163.com> X-CM-TRANSID: DcCowABHyuiIWBRcdawzAA--.1809S3 X-Coremail-Antispam: 1Uf129KBjvdXoWrZF45AF4xJw1kKFWkGw47twb_yoWxtrg_Za 13XFs7Wr47Cr1Y9r45Xw45AF43Jay7JF1xZa4ftFy7GF47tw13Ja1v9rn7JFyfWa13JF9F vws5tr10kF42qjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IUjG2MUUUUUU== X-Originating-IP: [183.134.170.47] X-CM-SenderInfo: 5oltjvrd6rljoofrz/xtbBaw8ebVettPeCLQAAsB X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 220.181.12.13 Subject: [Qemu-devel] [PATCH 1/3] tests: vhost-user-test: initialize 'fd' in chr_read X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Li Qiang , liq3ea@gmail.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Currentyly when processing VHOST_USER_SET_VRING_CALL if 'qemu_chr_fe_get_msgfds' get no fd, the 'fd' will be a stack uninitialized value. Signed-off-by: Li Qiang --- tests/vhost-user-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/vhost-user-test.c b/tests/vhost-user-test.c index 45d58d8ea2..86039e61e0 100644 --- a/tests/vhost-user-test.c +++ b/tests/vhost-user-test.c @@ -309,7 +309,7 @@ static void chr_read(void *opaque, const uint8_t *buf, int size) CharBackend *chr = &s->chr; VhostUserMsg msg; uint8_t *p = (uint8_t *) &msg; - int fd; + int fd = -1; if (s->test_fail) { qemu_chr_fe_disconnect(chr); From patchwork Sat Dec 15 01:26:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Qiang X-Patchwork-Id: 10731955 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D4131924 for ; Sat, 15 Dec 2018 01:29:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 87BE82C9E6 for ; Sat, 15 Dec 2018 01:29:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7C2C52CA1D; Sat, 15 Dec 2018 01:29:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2041C2C9E6 for ; Sat, 15 Dec 2018 01:29:29 +0000 (UTC) Received: from localhost ([::1]:37123 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gXylk-0005BN-Eg for patchwork-qemu-devel@patchwork.kernel.org; Fri, 14 Dec 2018 20:29:28 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49951) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gXykZ-0005Az-8H for qemu-devel@nongnu.org; Fri, 14 Dec 2018 20:28:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gXykU-0003Mk-9f for qemu-devel@nongnu.org; Fri, 14 Dec 2018 20:28:15 -0500 Received: from m12-13.163.com ([220.181.12.13]:55608) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gXykT-0003Lz-K4 for qemu-devel@nongnu.org; Fri, 14 Dec 2018 20:28:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=36hz3coVG0bJudF+fD pvL6mTiTtrlQ25CeShgRqagiU=; b=njkB0ZjXPT4uPLy/yfsPPOjSwNwqrsyYel nBduBu+fpQmG+eYAgP3c8guhHc5aDSpuhLZvjNyOsnBM+1ZWeYl8tX0uc4sLewVL 646lj6cx1SNW0x3AHuzwIQ8frX22FrafndjzO2HOn+Ps6sdKebpBLAS4+uS7TWMc UbNB0FZQA= Received: from localhost.localdomain (unknown [183.134.170.47]) by smtp9 (Coremail) with SMTP id DcCowABHyuiIWBRcdawzAA--.1809S4; Sat, 15 Dec 2018 09:27:45 +0800 (CST) From: Li Qiang To: thuth@redhat.com, lvivier@redhat.com, pbonzini@redhat.com, mst@redhat.com, peter.maydell@linaro.org, marcandre.lureau@redhat.com, berrange@redhat.com, jasowang@redhat.com Date: Fri, 14 Dec 2018 17:26:24 -0800 Message-Id: <20181215012625.73315-3-liq3ea@163.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181215012625.73315-1-liq3ea@163.com> References: <20181215012625.73315-1-liq3ea@163.com> X-CM-TRANSID: DcCowABHyuiIWBRcdawzAA--.1809S4 X-Coremail-Antispam: 1Uf129KBjvdXoW7Xr1kKryUtFyUGFy5XFWDArb_yoWkJrg_Aa 17JFZ7WFyUXF1q9ayUAw4FqrW3Ka13JF18XayrAF4xZryUKw13Gan5Zrn5Aay5ursrur93 ZrykAryUWr1akjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IUji0eJUUUUU== X-Originating-IP: [183.134.170.47] X-CM-SenderInfo: 5oltjvrd6rljoofrz/xtbBoREebVQHC1ED4QAAso X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 220.181.12.13 Subject: [Qemu-devel] [PATCH 2/3] vhost-user: add fds inf 'vhost_set_vring_file' in qtest X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Li Qiang , liq3ea@gmail.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Currently, the vhost-user-test assumes the eventfd is available. However it's not true because the accel is qtest. So the 'vhost_set_vring_file' will not add fds to the msg and the server side of vhost-user-test will be broken. This patch avoid this. Signed-off-by: Li Qiang --- hw/virtio/vhost-user.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index e09bed0e4a..3b666f093c 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -23,6 +23,7 @@ #include "migration/migration.h" #include "migration/postcopy-ram.h" #include "trace.h" +#include "sysemu/qtest.h" #include #include @@ -742,7 +743,7 @@ static int vhost_set_vring_file(struct vhost_dev *dev, .hdr.size = sizeof(msg.payload.u64), }; - if (ioeventfd_enabled() && file->fd > 0) { + if ((qtest_enabled() || ioeventfd_enabled()) && file->fd > 0) { fds[fd_num++] = file->fd; } else { msg.payload.u64 |= VHOST_USER_VRING_NOFD_MASK; From patchwork Sat Dec 15 01:26:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Qiang X-Patchwork-Id: 10731951 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8ACF71399 for ; Sat, 15 Dec 2018 01:29:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 33A3F2C9F6 for ; Sat, 15 Dec 2018 01:29:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 25A7F2CA60; Sat, 15 Dec 2018 01:29:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 205122C9F6 for ; Sat, 15 Dec 2018 01:29:29 +0000 (UTC) Received: from localhost ([::1]:37124 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gXylk-0005BO-Ow for patchwork-qemu-devel@patchwork.kernel.org; Fri, 14 Dec 2018 20:29:28 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49954) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gXykZ-0005B1-8L for qemu-devel@nongnu.org; Fri, 14 Dec 2018 20:28:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gXykV-0003Nd-P6 for qemu-devel@nongnu.org; Fri, 14 Dec 2018 20:28:15 -0500 Received: from m12-13.163.com ([220.181.12.13]:55668) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gXykV-0003MW-1v for qemu-devel@nongnu.org; Fri, 14 Dec 2018 20:28:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=HyQk4ackbckjxRsWO3 np1LMqXrC1YBfoAnh8qIKzdxY=; b=m2EeCJKs/RqffsbD8XNYQCNe+VLYDJP4T4 8xANKrF8XBRVG4GYgaDH/Z40I6sDVZNMuyBsF41gauisR3OSaqfmgOtNbA4f2obc RPzlWbVd+eyiYQ/xcv/cPqYkZvcs5L3xl9bwr3T67jv5TndAnf/90BWI0/yABHJq eKssT7dYw= Received: from localhost.localdomain (unknown [183.134.170.47]) by smtp9 (Coremail) with SMTP id DcCowABHyuiIWBRcdawzAA--.1809S5; Sat, 15 Dec 2018 09:27:46 +0800 (CST) From: Li Qiang To: thuth@redhat.com, lvivier@redhat.com, pbonzini@redhat.com, mst@redhat.com, peter.maydell@linaro.org, marcandre.lureau@redhat.com, berrange@redhat.com, jasowang@redhat.com Date: Fri, 14 Dec 2018 17:26:25 -0800 Message-Id: <20181215012625.73315-4-liq3ea@163.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181215012625.73315-1-liq3ea@163.com> References: <20181215012625.73315-1-liq3ea@163.com> X-CM-TRANSID: DcCowABHyuiIWBRcdawzAA--.1809S5 X-Coremail-Antispam: 1Uf129KBjvdXoW7Jw1kKF4kKw4fGr45KFyUJrb_yoW3uwc_GF W2yrs5XFyUZ3ySya4qg3y5AFZagrWrGrWxZF1aqryfXrn8u3Z8GF4UZryrWrsxWayxX3WU C34I9F43CFnxtjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IU820P3UUUUU== X-Originating-IP: [183.134.170.47] X-CM-SenderInfo: 5oltjvrd6rljoofrz/1tbiKRIebVXlo--C1AAAsy X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 220.181.12.13 Subject: [Qemu-devel] [PATCH 3/3] util: check the return value of fcntl in qemu_set_{block, nonblock} X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Li Qiang , liq3ea@gmail.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Assert that the return value is not an error. This is like commit 7e6478e7d4f for qemu_set_cloexec. Signed-off-by: Li Qiang --- util/oslib-posix.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/util/oslib-posix.c b/util/oslib-posix.c index c1bee2a581..4ce1ba9ca4 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -233,14 +233,18 @@ void qemu_set_block(int fd) { int f; f = fcntl(fd, F_GETFL); - fcntl(fd, F_SETFL, f & ~O_NONBLOCK); + assert(f != -1); + f = fcntl(fd, F_SETFL, f & ~O_NONBLOCK); + assert(f != -1); } void qemu_set_nonblock(int fd) { int f; f = fcntl(fd, F_GETFL); - fcntl(fd, F_SETFL, f | O_NONBLOCK); + assert(f != -1); + f = fcntl(fd, F_SETFL, f | O_NONBLOCK); + assert(f != -1); } int socket_set_fast_reuse(int fd)