From patchwork Wed Apr 4 17:53:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 10322979 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 576D56032A for ; Wed, 4 Apr 2018 17:52:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 45FCE28FB1 for ; Wed, 4 Apr 2018 17:52:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4473728FAE; Wed, 4 Apr 2018 17:52:09 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 080742912F for ; Wed, 4 Apr 2018 17:51:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751262AbeDDRvW (ORCPT ); Wed, 4 Apr 2018 13:51:22 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:47446 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750890AbeDDRvV (ORCPT ); Wed, 4 Apr 2018 13:51:21 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9664B80D; Wed, 4 Apr 2018 10:51:21 -0700 (PDT) Received: from e106794-lin.cambridge.arm.com (e106794-lin.cambridge.arm.com [10.1.211.47]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id E9C033F25D; Wed, 4 Apr 2018 10:51:20 -0700 (PDT) From: Jean-Philippe Brucker To: kvm@vger.kernel.org Cc: Will.Deacon@arm.com Subject: [PATCH kvmtool 1/3] ioeventfd: Always add a new event to the list Date: Wed, 4 Apr 2018 18:53:52 +0100 Message-Id: <20180404175354.4887-1-jean-philippe.brucker@arm.com> X-Mailer: git-send-email 2.16.2 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP With vhost, the USER_POLL flags isn't passed to ioeventfd__add_event, the function returns early and doesn't add the new event to the used_ioevents list. As a result ioeventfd__del_event doesn't remove the KVM event or free the structure. Always add the event to the list. Signed-off-by: Jean-Philippe Brucker --- ioeventfd.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/ioeventfd.c b/ioeventfd.c index bce68619bd17..186ac703e365 100644 --- a/ioeventfd.c +++ b/ioeventfd.c @@ -154,18 +154,17 @@ int ioeventfd__add_event(struct ioevent *ioevent, int flags) goto cleanup; } - if (!(flags & IOEVENTFD_FLAG_USER_POLL)) - return 0; - - epoll_event = (struct epoll_event) { - .events = EPOLLIN, - .data.ptr = new_ioevent, - }; - - r = epoll_ctl(epoll_fd, EPOLL_CTL_ADD, event, &epoll_event); - if (r) { - r = -errno; - goto cleanup; + if (flags & IOEVENTFD_FLAG_USER_POLL) { + epoll_event = (struct epoll_event) { + .events = EPOLLIN, + .data.ptr = new_ioevent, + }; + + r = epoll_ctl(epoll_fd, EPOLL_CTL_ADD, event, &epoll_event); + if (r) { + r = -errno; + goto cleanup; + } } list_add_tail(&new_ioevent->list, &used_ioevents);