From patchwork Wed Apr 3 08:59:40 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 233318 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id BF36E2C0148 for ; Wed, 3 Apr 2013 19:59:29 +1100 (EST) Received: from localhost ([::1]:38933 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UNJXU-0001oa-2e for incoming@patchwork.ozlabs.org; Wed, 03 Apr 2013 04:59:28 -0400 Received: from eggs.gnu.org ([208.118.235.92]:43725) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UNJWs-0001hF-Ek for qemu-devel@nongnu.org; Wed, 03 Apr 2013 04:58:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UNJWp-0004PH-PX for qemu-devel@nongnu.org; Wed, 03 Apr 2013 04:58:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:24874) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UNJWp-0004P2-HZ for qemu-devel@nongnu.org; Wed, 03 Apr 2013 04:58:47 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r338wkDv002431 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 3 Apr 2013 04:58:46 -0400 Received: from redhat.com (vpn1-6-164.ams2.redhat.com [10.36.6.164]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id r338wiiZ000585; Wed, 3 Apr 2013 04:58:44 -0400 Date: Wed, 3 Apr 2013 11:59:40 +0300 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org, kvm@vger.kernel.org, pbonzini@redhat.com, gleb@redhat.com, mtosatti@redhat.com Message-ID: <011d95472efb8a8afebb3c41f9aa9ec01ff1c990.1364979441.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mutt-Fcc: =sent X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 3/4] kvm: support non datamatch ioeventfd X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Adding restrictions just adds code. Signed-off-by: Michael S. Tsirkin --- kvm-all.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/kvm-all.c b/kvm-all.c index 589e37c..ce823f9 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -501,21 +501,24 @@ int kvm_check_extension(KVMState *s, unsigned int extension) } static int kvm_set_ioeventfd_mmio(int fd, uint32_t addr, uint32_t val, - bool assign, uint32_t size) + bool assign, uint32_t size, bool datamatch) { int ret; struct kvm_ioeventfd iofd; - iofd.datamatch = val; + iofd.datamatch = datamatch ? val : 0; iofd.addr = addr; iofd.len = size; - iofd.flags = KVM_IOEVENTFD_FLAG_DATAMATCH; + iofd.flags = 0; iofd.fd = fd; if (!kvm_enabled()) { return -ENOSYS; } + if (datamatch) { + iofd.flags |= KVM_IOEVENTFD_FLAG_DATAMATCH; + } if (!assign) { iofd.flags |= KVM_IOEVENTFD_FLAG_DEASSIGN; } @@ -530,19 +533,22 @@ static int kvm_set_ioeventfd_mmio(int fd, uint32_t addr, uint32_t val, } static int kvm_set_ioeventfd_pio(int fd, uint16_t addr, uint16_t val, - bool assign, uint32_t size) + bool assign, uint32_t size, bool datamatch) { struct kvm_ioeventfd kick = { - .datamatch = val, + .datamatch = datamatch ? val : 0, .addr = addr, + .flags = KVM_IOEVENTFD_FLAG_PIO, .len = size, - .flags = KVM_IOEVENTFD_FLAG_DATAMATCH | KVM_IOEVENTFD_FLAG_PIO, .fd = fd, }; int r; if (!kvm_enabled()) { return -ENOSYS; } + if (datamatch) { + kick.flags |= KVM_IOEVENTFD_FLAG_DATAMATCH; + } if (!assign) { kick.flags |= KVM_IOEVENTFD_FLAG_DEASSIGN; } @@ -571,7 +577,7 @@ static int kvm_check_many_ioeventfds(void) if (ioeventfds[i] < 0) { break; } - ret = kvm_set_ioeventfd_pio(ioeventfds[i], 0, i, true, 2); + ret = kvm_set_ioeventfd_pio(ioeventfds[i], 0, i, true, 2, true); if (ret < 0) { close(ioeventfds[i]); break; @@ -582,7 +588,7 @@ static int kvm_check_many_ioeventfds(void) ret = i == ARRAY_SIZE(ioeventfds); while (i-- > 0) { - kvm_set_ioeventfd_pio(ioeventfds[i], 0, i, false, 2); + kvm_set_ioeventfd_pio(ioeventfds[i], 0, i, false, 2, true); close(ioeventfds[i]); } return ret; @@ -802,10 +808,8 @@ static void kvm_mem_ioeventfd_add(MemoryListener *listener, int fd = event_notifier_get_fd(e); int r; - assert(match_data && section->size <= 8); - r = kvm_set_ioeventfd_mmio(fd, section->offset_within_address_space, - data, true, section->size); + data, true, section->size, match_data); if (r < 0) { abort(); } @@ -820,7 +824,7 @@ static void kvm_mem_ioeventfd_del(MemoryListener *listener, int r; r = kvm_set_ioeventfd_mmio(fd, section->offset_within_address_space, - data, false, section->size); + data, false, section->size, match_data); if (r < 0) { abort(); } @@ -834,10 +838,8 @@ static void kvm_io_ioeventfd_add(MemoryListener *listener, int fd = event_notifier_get_fd(e); int r; - assert(match_data && section->size <= 8); - r = kvm_set_ioeventfd_pio(fd, section->offset_within_address_space, - data, true, section->size); + data, true, section->size, match_data); if (r < 0) { abort(); } @@ -853,7 +855,7 @@ static void kvm_io_ioeventfd_del(MemoryListener *listener, int r; r = kvm_set_ioeventfd_pio(fd, section->offset_within_address_space, - data, false, section->size); + data, false, section->size, match_data); if (r < 0) { abort(); }