From patchwork Wed Oct 4 13:49:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre Morel X-Patchwork-Id: 9984745 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 C08BF6028E for ; Wed, 4 Oct 2017 13:51:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B4B6628A7E for ; Wed, 4 Oct 2017 13:51:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A9B5128AE2; Wed, 4 Oct 2017 13:51:10 +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 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 2E5FF28A7E for ; Wed, 4 Oct 2017 13:51:10 +0000 (UTC) Received: from localhost ([::1]:35301 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzk4r-00069e-CN for patchwork-qemu-devel@patchwork.kernel.org; Wed, 04 Oct 2017 09:51:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55464) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzk3i-00068N-Fy for qemu-devel@nongnu.org; Wed, 04 Oct 2017 09:49:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dzk3e-0003n6-F1 for qemu-devel@nongnu.org; Wed, 04 Oct 2017 09:49:58 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:54834) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dzk3e-0003m0-0r for qemu-devel@nongnu.org; Wed, 04 Oct 2017 09:49:54 -0400 Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v94Dn3Kk005413 for ; Wed, 4 Oct 2017 09:49:50 -0400 Received: from e06smtp10.uk.ibm.com (e06smtp10.uk.ibm.com [195.75.94.106]) by mx0a-001b2d01.pphosted.com with ESMTP id 2dcwe4vtg3-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 04 Oct 2017 09:49:50 -0400 Received: from localhost by e06smtp10.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 4 Oct 2017 14:49:47 +0100 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp10.uk.ibm.com (192.168.101.140) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 4 Oct 2017 14:49:45 +0100 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v94Dni4I17891486; Wed, 4 Oct 2017 13:49:44 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 61A2B4C046; Wed, 4 Oct 2017 14:45:50 +0100 (BST) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1D6FB4C040; Wed, 4 Oct 2017 14:45:50 +0100 (BST) Received: from morel-ThinkPad-W530.boeblingen.de.ibm.com (unknown [9.145.179.43]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 4 Oct 2017 14:45:50 +0100 (BST) From: Pierre Morel To: qemu-devel@nongnu.org Date: Wed, 4 Oct 2017 15:49:37 +0200 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1507124979-8880-1-git-send-email-pmorel@linux.vnet.ibm.com> References: <1507124979-8880-1-git-send-email-pmorel@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17100413-0040-0000-0000-000003DF57AF X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17100413-0041-0000-0000-000025E0C2B1 Message-Id: <1507124979-8880-4-git-send-email-pmorel@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-10-04_06:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000 definitions=main-1710040194 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PATCH v1 3/5] s390x/intc: Emulate Adapter Interrupt Suppression 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: borntraeger@de.ibm.com, pasic@linux.vnet.ibm.com, cohuck@redhat.com, zyimin@linux.vnet.ibm.com, agraf@suse.de Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Emulate the Adapter Interrupt Suppression in the KVM FLIC interface when the kernel does not support AIS. When the kernel KVM does not support AIS, we can not support VFIO PCI devices but we still can support emulated devices if we emulate AIS inside QEMU. Let's emulate AIS, allowing to use emulated PCI devices without KVM AIS support. Signed-off-by: Pierre Morel --- hw/intc/s390_flic.c | 3 +- hw/intc/s390_flic_kvm.c | 76 ++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 64 insertions(+), 15 deletions(-) diff --git a/hw/intc/s390_flic.c b/hw/intc/s390_flic.c index 6eaf178..33a7cde 100644 --- a/hw/intc/s390_flic.c +++ b/hw/intc/s390_flic.c @@ -185,8 +185,7 @@ static void s390_flic_common_realize(DeviceState *dev, Error **errp) " (%d > %d)", max_batch, ADAPTER_ROUTES_MAX_GSI); return; } - - fs->ais_supported = s390_has_feat(S390_FEAT_ADAPTER_INT_SUPPRESSION); + fs->ais_supported = false; } static void s390_flic_class_init(ObjectClass *oc, void *data) diff --git a/hw/intc/s390_flic_kvm.c b/hw/intc/s390_flic_kvm.c index 7ead17a..fd1aa22 100644 --- a/hw/intc/s390_flic_kvm.c +++ b/hw/intc/s390_flic_kvm.c @@ -33,6 +33,8 @@ typedef struct KVMS390FLICState { uint32_t fd; bool clear_io_supported; + uint8_t simm; + uint8_t nimm; } KVMS390FLICState; DeviceState *s390_flic_kvm_create(void) @@ -164,11 +166,24 @@ static int kvm_s390_modify_ais_mode(S390FLICState *fs, uint8_t isc, .addr = (uint64_t)&req, }; - if (!fs->ais_supported) { - return -ENOSYS; + if (fs->ais_supported) { + return ioctl(flic->fd, KVM_SET_DEVICE_ATTR, &attr) ? -errno : 0; } - return ioctl(flic->fd, KVM_SET_DEVICE_ATTR, &attr) ? -errno : 0; + /* Kernel does not support AIS, emulate it here */ + switch (mode) { + case SIC_IRQ_MODE_ALL: + flic->simm &= ~AIS_MODE_MASK(isc); + flic->nimm &= ~AIS_MODE_MASK(isc); + break; + case SIC_IRQ_MODE_SINGLE: + flic->simm |= AIS_MODE_MASK(isc); + flic->nimm &= ~AIS_MODE_MASK(isc); + break; + default: + return -EINVAL; + } + return 0; } static int kvm_s390_inject_airq(S390FLICState *fs, uint8_t type, @@ -180,12 +195,23 @@ static int kvm_s390_inject_airq(S390FLICState *fs, uint8_t type, .group = KVM_DEV_FLIC_AIRQ_INJECT, .attr = id, }; + uint32_t io_int_word = (isc << 27) | IO_INT_WORD_AI; - if (!fs->ais_supported) { - return -ENOSYS; + if (fs->ais_supported) { + return ioctl(flic->fd, KVM_SET_DEVICE_ATTR, &attr) ? -errno : 0; } - return ioctl(flic->fd, KVM_SET_DEVICE_ATTR, &attr) ? -errno : 0; + /* Kernel does not support AIS, emulate it here */ + if (flags && (flic->nimm & AIS_MODE_MASK(isc))) { + return 0; + } + + s390_io_interrupt(0, 0, 0, io_int_word); + + if (flags && (flic->simm & AIS_MODE_MASK(isc))) { + flic->nimm |= AIS_MODE_MASK(isc); + } + return 0; } /** @@ -557,6 +583,32 @@ static void kvm_s390_flic_realize(DeviceState *dev, Error **errp) test_attr.group = KVM_DEV_FLIC_CLEAR_IO_IRQ; flic_state->clear_io_supported = !ioctl(flic_state->fd, KVM_HAS_DEVICE_ATTR, test_attr); + /* To support ais we need all these three FLIC attributes */ + test_attr.group = KVM_DEV_FLIC_AISM; + ret = !ioctl(flic_state->fd, KVM_HAS_DEVICE_ATTR, test_attr); + flic_state->parent_obj.ais_supported &= ret; + + test_attr.group = KVM_DEV_FLIC_AIRQ_INJECT; + ret = !ioctl(flic_state->fd, KVM_HAS_DEVICE_ATTR, test_attr); + flic_state->parent_obj.ais_supported &= ret; + + test_attr.group = KVM_DEV_FLIC_AISM_ALL; + ret &= !ioctl(flic_state->fd, KVM_HAS_DEVICE_ATTR, test_attr); + flic_state->parent_obj.ais_supported &= ret; + + /* For buggy kernels we need to really test that the attribute is supported */ + { + struct kvm_s390_ais_req req = { + .mode = SIC_IRQ_MODE_ALL, + }; + struct kvm_device_attr attr = { + .group = KVM_DEV_FLIC_AISM, + .addr = (uint64_t)&req, + }; + ret = !ioctl(flic_state->fd, KVM_SET_DEVICE_ATTR, &attr); + } + flic_state->parent_obj.ais_supported &= ret; + return; fail: error_propagate(errp, errp_local); @@ -578,13 +630,11 @@ static void kvm_s390_flic_reset(DeviceState *dev) flic_disable_wait_pfault(flic); - if (fs->ais_supported) { - for (isc = 0; isc <= MAX_ISC; isc++) { - rc = kvm_s390_modify_ais_mode(fs, isc, SIC_IRQ_MODE_ALL); - if (rc) { - error_report("Failed to reset ais mode for isc %d: %s", - isc, strerror(-rc)); - } + for (isc = 0; isc <= MAX_ISC; isc++) { + rc = kvm_s390_modify_ais_mode(fs, isc, SIC_IRQ_MODE_ALL); + if (rc) { + error_report("Failed to reset ais mode for isc %d: %s", + isc, strerror(-rc)); } }