From patchwork Thu Feb 21 18:14:31 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cornelia Huck X-Patchwork-Id: 222391 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 6A81E2C02A9 for ; Fri, 22 Feb 2013 05:15:24 +1100 (EST) Received: from localhost ([::1]:56113 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U8afy-0003oy-G8 for incoming@patchwork.ozlabs.org; Thu, 21 Feb 2013 13:15:22 -0500 Received: from eggs.gnu.org ([208.118.235.92]:58231) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U8afc-0003cK-QO for qemu-devel@nongnu.org; Thu, 21 Feb 2013 13:15:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U8afU-00088P-6i for qemu-devel@nongnu.org; Thu, 21 Feb 2013 13:15:00 -0500 Received: from e06smtp18.uk.ibm.com ([195.75.94.114]:59804) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U8afT-000867-O3 for qemu-devel@nongnu.org; Thu, 21 Feb 2013 13:14:52 -0500 Received: from /spool/local by e06smtp18.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 21 Feb 2013 18:12:39 -0000 Received: from d06dlp03.portsmouth.uk.ibm.com (9.149.20.15) by e06smtp18.uk.ibm.com (192.168.101.148) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 21 Feb 2013 18:12:27 -0000 Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by d06dlp03.portsmouth.uk.ibm.com (Postfix) with ESMTP id BAEE21B0805B for ; Thu, 21 Feb 2013 18:14:35 +0000 (GMT) Received: from d06av08.portsmouth.uk.ibm.com (d06av08.portsmouth.uk.ibm.com [9.149.37.249]) by b06cxnps4074.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r1LIEQJ831785114 for ; Thu, 21 Feb 2013 18:14:26 GMT Received: from d06av08.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av08.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r1LIEZtd011587 for ; Thu, 21 Feb 2013 11:14:35 -0700 Received: from gondolin (dyn-9-152-224-122.boeblingen.de.ibm.com [9.152.224.122]) by d06av08.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r1LIEZqs011573; Thu, 21 Feb 2013 11:14:35 -0700 Date: Thu, 21 Feb 2013 19:14:31 +0100 From: Cornelia Huck To: "Michael S. Tsirkin" Message-ID: <20130221191431.4318f949@gondolin> In-Reply-To: <20130221163459.GA26543@redhat.com> References: <1361452380-50398-1-git-send-email-cornelia.huck@de.ibm.com> <1361452380-50398-4-git-send-email-cornelia.huck@de.ibm.com> <20130221143904.GC24738@redhat.com> <20130221162143.4813d6c5@gondolin> <20130221163459.GA26543@redhat.com> Organization: IBM Deutschland Research & Development GmbH Vorsitzende des Aufsichtsrats: Martina Koederitz =?UTF-8?B?R2VzY2jDpGZ0c2bDvGhydW5nOg==?= Dirk Wittkopp Sitz der Gesellschaft: =?UTF-8?B?QsO2Ymxpbmdlbg==?= Registergericht: Amtsgericht Stuttgart, HRB 243294 Mime-Version: 1.0 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13022118-6892-0000-0000-000004667568 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 195.75.94.114 Cc: linux-s390 , qemu-devel , KVM Subject: Re: [Qemu-devel] [RFC PATCH 3/3] KVM: s390: Hook up ioeventfds. 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 On Thu, 21 Feb 2013 18:34:59 +0200 "Michael S. Tsirkin" wrote: > On Thu, Feb 21, 2013 at 04:21:43PM +0100, Cornelia Huck wrote: > > On Thu, 21 Feb 2013 16:39:05 +0200 > > "Michael S. Tsirkin" wrote: > > > > > On Thu, Feb 21, 2013 at 02:13:00PM +0100, Cornelia Huck wrote: > > > > As s390 doesn't use memory writes for virtio notifcations, create > > > > a special kind of ioeventfd instead that hooks up into diagnose > > > > 0x500 (kvm hypercall) with function code 3 (virtio-ccw notification). > > > > > > > > Signed-off-by: Cornelia Huck > > > > > > Do we really have to put virtio specific stuff into kvm? > > > How about we add generic functionality to match GPRs > > > on a hypercall and signal an eventfd? > > > > Worth a try implementing that. > > > > > > > > Also, it's a bit unfortunate that this doesn't use > > > the io bus datastructure, long term the linked list handling > > > might become a bottleneck, using shared code this could maybe > > > benefit from performance optimizations there. > > > > The linked list stuff was more like an initial implementation that > > could be improved later. > > > > > io bus data structure currently has the ability to match on > > > two 64 bit fields (addr/datamatch) and a signed 32 bit one (length). > > > Isn't this sufficient for your purposes? > > > How about sticking subchannel id in address, vq in data match > > > and using io bus? > > > > I can give that a try. (I must admit that I didn't look at the iobus > > stuff in detail.) > > > > > > > > BTW maybe we could do this for the user interface too, > > > while I'm not 100% sure it's the cleanest thing to do > > > (or will work), it would certainly minimize the patchset. > > > > You mean integrating with the generic interface and dropping the new > > ARCH flag? > > Not sure about the flag but we could use the general structure > without an arch-specific format, if that's a good fit. > So I have something that seems to do what I want. I'll see if I can morph it into something presentable tomorrow. diff --git a/arch/s390/kvm/Kconfig b/arch/s390/kvm/Kconfig index b58dd86..3c43e30 100644 --- a/arch/s390/kvm/Kconfig +++ b/arch/s390/kvm/Kconfig @@ -22,6 +22,7 @@ config KVM select PREEMPT_NOTIFIERS select ANON_INODES select HAVE_KVM_CPU_RELAX_INTERCEPT + select HAVE_KVM_EVENTFD ---help--- Support hosting paravirtualized guest machines using the SIE virtualization capability on the mainframe. This should work diff --git a/arch/s390/kvm/Makefile b/arch/s390/kvm/Makefile index 3975722..8fe9d65 100644 --- a/arch/s390/kvm/Makefile +++ b/arch/s390/kvm/Makefile @@ -6,7 +6,7 @@ # it under the terms of the GNU General Public License (version 2 only) # as published by the Free Software Foundation. -common-objs = $(addprefix ../../../virt/kvm/, kvm_main.o) +common-objs = $(addprefix ../../../virt/kvm/, kvm_main.o eventfd.o) ccflags-y := -Ivirt/kvm -Iarch/s390/kvm diff --git a/arch/s390/kvm/diag.c b/arch/s390/kvm/diag.c index a390687..7fc195e 100644 --- a/arch/s390/kvm/diag.c +++ b/arch/s390/kvm/diag.c @@ -104,6 +104,20 @@ static int __diag_ipl_functions(struct kvm_vcpu *vcpu) return -EREMOTE; } +static int __diag_virtio_hypercall(struct kvm_vcpu *vcpu) +{ + int ret, idx; + u64 vq = vcpu->run->s.regs.gprs[3]; + + idx = srcu_read_lock(&vcpu->kvm->srcu); + ret = kvm_io_bus_write(vcpu->kvm, KVM_CSS_BUS, + vcpu->run->s.regs.gprs[2], + vcpu->run->s.regs.gprs[1], + &vq); + srcu_read_unlock(&vcpu->kvm->srcu, idx); + return ret; +} + int kvm_s390_handle_diag(struct kvm_vcpu *vcpu) { int code = (vcpu->arch.sie_block->ipb & 0xfff0000) >> 16; @@ -118,6 +132,8 @@ int kvm_s390_handle_diag(struct kvm_vcpu *vcpu) return __diag_time_slice_end_directed(vcpu); case 0x308: return __diag_ipl_functions(vcpu); + case 0x500: + return __diag_virtio_hypercall(vcpu); default: return -EOPNOTSUPP; } diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c index f822d36..04d2454 100644 --- a/arch/s390/kvm/kvm-s390.c +++ b/arch/s390/kvm/kvm-s390.c @@ -142,6 +142,7 @@ int kvm_dev_ioctl_check_extension(long ext) case KVM_CAP_ONE_REG: case KVM_CAP_ENABLE_CAP: case KVM_CAP_S390_CSS_SUPPORT: + case KVM_CAP_IOEVENTFD: r = 1; break; case KVM_CAP_NR_VCPUS: diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 3b768ef..59be516 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -148,6 +148,7 @@ struct kvm_io_bus { enum kvm_bus { KVM_MMIO_BUS, KVM_PIO_BUS, + KVM_CSS_BUS, KVM_NR_BUSES }; diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 9a2db57..1df0766 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -448,12 +448,14 @@ enum { kvm_ioeventfd_flag_nr_datamatch, kvm_ioeventfd_flag_nr_pio, kvm_ioeventfd_flag_nr_deassign, + kvm_ioeventfd_flag_nr_css, kvm_ioeventfd_flag_nr_max, }; #define KVM_IOEVENTFD_FLAG_DATAMATCH (1 << kvm_ioeventfd_flag_nr_datamatch) #define KVM_IOEVENTFD_FLAG_PIO (1 << kvm_ioeventfd_flag_nr_pio) #define KVM_IOEVENTFD_FLAG_DEASSIGN (1 << kvm_ioeventfd_flag_nr_deassign) +#define KVM_IOEVENTFD_FLAG_CSS (1 << kvm_ioeventfd_flag_nr_css) #define KVM_IOEVENTFD_VALID_FLAG_MASK ((1 << kvm_ioeventfd_flag_nr_max) - 1) diff --git a/virt/kvm/eventfd.c b/virt/kvm/eventfd.c index f0ced1a..57a06ff 100644 --- a/virt/kvm/eventfd.c +++ b/virt/kvm/eventfd.c @@ -576,6 +576,7 @@ struct _ioeventfd { u64 datamatch; struct kvm_io_device dev; bool wildcard; + bool is_css; }; static inline struct _ioeventfd * @@ -607,24 +608,27 @@ ioeventfd_in_range(struct _ioeventfd *p, gpa_t addr, int len, const void *val) /* otherwise, we have to actually compare the data */ - BUG_ON(!IS_ALIGNED((unsigned long)val, len)); - - switch (len) { - case 1: - _val = *(u8 *)val; - break; - case 2: - _val = *(u16 *)val; - break; - case 4: - _val = *(u32 *)val; - break; - case 8: + if (!p->is_css) { + BUG_ON(!IS_ALIGNED((unsigned long)val, len)); + + switch (len) { + case 1: + _val = *(u8 *)val; + break; + case 2: + _val = *(u16 *)val; + break; + case 4: + _val = *(u32 *)val; + break; + case 8: + _val = *(u64 *)val; + break; + default: + return false; + } + } else _val = *(u64 *)val; - break; - default: - return false; - } return _val == p->datamatch ? true : false; } @@ -679,25 +683,29 @@ static int kvm_assign_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args) { int pio = args->flags & KVM_IOEVENTFD_FLAG_PIO; - enum kvm_bus bus_idx = pio ? KVM_PIO_BUS : KVM_MMIO_BUS; + int css = args->flags & KVM_IOEVENTFD_FLAG_CSS; + enum kvm_bus bus_idx; struct _ioeventfd *p; struct eventfd_ctx *eventfd; int ret; - /* must be natural-word sized */ - switch (args->len) { - case 1: - case 2: - case 4: - case 8: - break; - default: - return -EINVAL; - } + bus_idx = pio ? KVM_PIO_BUS : css ? KVM_CSS_BUS: KVM_MMIO_BUS; + if (!css) { + /* must be natural-word sized */ + switch (args->len) { + case 1: + case 2: + case 4: + case 8: + break; + default: + return -EINVAL; + } - /* check for range overflow */ - if (args->addr + args->len < args->addr) - return -EINVAL; + /* check for range overflow */ + if (args->addr + args->len < args->addr) + return -EINVAL; + } /* check for extra flags that we don't understand */ if (args->flags & ~KVM_IOEVENTFD_VALID_FLAG_MASK) @@ -717,6 +725,7 @@ kvm_assign_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args) p->addr = args->addr; p->length = args->len; p->eventfd = eventfd; + p->is_css = css; /* The datamatch feature is optional, otherwise this is a wildcard */ if (args->flags & KVM_IOEVENTFD_FLAG_DATAMATCH) @@ -759,11 +768,13 @@ static int kvm_deassign_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args) { int pio = args->flags & KVM_IOEVENTFD_FLAG_PIO; - enum kvm_bus bus_idx = pio ? KVM_PIO_BUS : KVM_MMIO_BUS; + int css = args->flags & KVM_IOEVENTFD_FLAG_CSS; + enum kvm_bus bus_idx; struct _ioeventfd *p, *tmp; struct eventfd_ctx *eventfd; int ret = -ENOENT; + bus_idx = pio ? KVM_PIO_BUS : css ? KVM_CSS_BUS: KVM_MMIO_BUS; eventfd = eventfd_ctx_fdget(args->fd); if (IS_ERR(eventfd)) return PTR_ERR(eventfd);