From nobody Sat May 4 07:15:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489721170032288.08080238825744; Thu, 16 Mar 2017 20:26:10 -0700 (PDT) Received: from localhost ([::1]:46915 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1coiWm-0004Dx-J5 for importer@patchew.org; Thu, 16 Mar 2017 23:26:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57482) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1coiQd-0007ib-HB for qemu-devel@nongnu.org; Thu, 16 Mar 2017 23:19:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1coiQY-0000jm-KX for qemu-devel@nongnu.org; Thu, 16 Mar 2017 23:19:47 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:53953 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1coiQY-0000jY-Ev for qemu-devel@nongnu.org; Thu, 16 Mar 2017 23:19:42 -0400 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v2H3JAMC014810 for ; Thu, 16 Mar 2017 23:19:41 -0400 Received: from e33.co.us.ibm.com (e33.co.us.ibm.com [32.97.110.151]) by mx0b-001b2d01.pphosted.com with ESMTP id 297nkp1y3f-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 16 Mar 2017 23:19:41 -0400 Received: from localhost by e33.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 16 Mar 2017 21:19:41 -0600 Received: from b03cxnp08026.gho.boulder.ibm.com (9.17.130.18) by e33.co.us.ibm.com (192.168.1.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 16 Mar 2017 21:19:38 -0600 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp08026.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v2H3JaTL11469114; Thu, 16 Mar 2017 20:19:36 -0700 Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8905178038; Thu, 16 Mar 2017 21:19:36 -0600 (MDT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP id A426578041; Thu, 16 Mar 2017 21:19:34 -0600 (MDT) From: Dong Jia Shi To: kvm@vger.kernel.org, linux-s390@vger.kernel.org, qemu-devel@nongnu.org Date: Fri, 17 Mar 2017 04:19:18 +0100 X-Mailer: git-send-email 2.8.4 In-Reply-To: <20170317031928.40189-1-bjsdjshi@linux.vnet.ibm.com> References: <20170317031928.40189-1-bjsdjshi@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17031703-0008-0000-0000-0000077209DA X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00006796; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000206; SDB=6.00834931; UDB=6.00410081; IPR=6.00612586; BA=6.00005215; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00014684; XFM=3.00000013; UTC=2017-03-17 03:19:39 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17031703-0009-0000-0000-000040BC3E0C Message-Id: <20170317031928.40189-2-bjsdjshi@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-03-17_01:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1702020001 definitions=main-1703170026 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PATCH v4 01/11] vfio: linux-headers update for vfio-ccw 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: pasic@linux.vnet.ibm.com, pmorel@linux.vnet.ibm.com, borntraeger@de.ibm.com, alex.williamson@redhat.com, renxiaof@linux.vnet.ibm.com, cornelia.huck@de.ibm.com, bjsdjshi@linux.vnet.ibm.com, agraf@suse.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This is a placeholder for a linux-headers update. Signed-off-by: Dong Jia Shi --- linux-headers/linux/vfio.h | 17 +++++++++++++++++ linux-headers/linux/vfio_ccw.h | 28 ++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 linux-headers/linux/vfio_ccw.h diff --git a/linux-headers/linux/vfio.h b/linux-headers/linux/vfio.h index 531cb2e..39a1d3b 100644 --- a/linux-headers/linux/vfio.h +++ b/linux-headers/linux/vfio.h @@ -198,6 +198,7 @@ struct vfio_device_info { #define VFIO_DEVICE_FLAGS_PCI (1 << 1) /* vfio-pci device */ #define VFIO_DEVICE_FLAGS_PLATFORM (1 << 2) /* vfio-platform device */ #define VFIO_DEVICE_FLAGS_AMBA (1 << 3) /* vfio-amba device */ +#define VFIO_DEVICE_FLAGS_CCW (1 << 4) /* vfio-ccw device */ __u32 num_regions; /* Max region index + 1 */ __u32 num_irqs; /* Max IRQ index + 1 */ }; @@ -446,6 +447,22 @@ enum { VFIO_PCI_NUM_IRQS }; =20 +/* + * The VFIO-CCW bus driver makes use of the following fixed region and + * IRQ index mapping. Unimplemented regions return a size of zero. + * Unimplemented IRQ types return a count of zero. + */ + +enum { + VFIO_CCW_CONFIG_REGION_INDEX, + VFIO_CCW_NUM_REGIONS +}; + +enum { + VFIO_CCW_IO_IRQ_INDEX, + VFIO_CCW_NUM_IRQS +}; + /** * VFIO_DEVICE_GET_PCI_HOT_RESET_INFO - _IORW(VFIO_TYPE, VFIO_BASE + 12, * struct vfio_pci_hot_reset_info) diff --git a/linux-headers/linux/vfio_ccw.h b/linux-headers/linux/vfio_ccw.h new file mode 100644 index 0000000..4ee74ae --- /dev/null +++ b/linux-headers/linux/vfio_ccw.h @@ -0,0 +1,28 @@ +/* + * Interfaces for vfio-ccw + * + * Copyright IBM Corp. 2017 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License (version 2 only) + * as published by the Free Software Foundation. + * + * Author(s): Dong Jia Shi + */ + +#ifndef _VFIO_CCW_H_ +#define _VFIO_CCW_H_ + +#include + +struct ccw_io_region { +#define ORB_AREA_SIZE 12 + __u8 orb_area[ORB_AREA_SIZE]; +#define SCSW_AREA_SIZE 12 + __u8 scsw_area[SCSW_AREA_SIZE]; +#define IRB_AREA_SIZE 96 + __u8 irb_area[IRB_AREA_SIZE]; + __u32 ret_code; +} __packed; + +#endif --=20 2.8.4 From nobody Sat May 4 07:15:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489721640651433.63200850284295; Thu, 16 Mar 2017 20:34:00 -0700 (PDT) Received: from localhost ([::1]:46948 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1coieN-0003Df-3l for importer@patchew.org; Thu, 16 Mar 2017 23:33:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57510) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1coiQg-0007lY-Kv for qemu-devel@nongnu.org; Thu, 16 Mar 2017 23:19:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1coiQb-0000ke-Mr for qemu-devel@nongnu.org; Thu, 16 Mar 2017 23:19:50 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:55847) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1coiQb-0000kT-EP for qemu-devel@nongnu.org; Thu, 16 Mar 2017 23:19:45 -0400 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v2H3JBFj079045 for ; Thu, 16 Mar 2017 23:19:44 -0400 Received: from e33.co.us.ibm.com (e33.co.us.ibm.com [32.97.110.151]) by mx0a-001b2d01.pphosted.com with ESMTP id 297yyw9h9x-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 16 Mar 2017 23:19:44 -0400 Received: from localhost by e33.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 16 Mar 2017 21:19:42 -0600 Received: from b03cxnp08027.gho.boulder.ibm.com (9.17.130.19) by e33.co.us.ibm.com (192.168.1.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 16 Mar 2017 21:19:41 -0600 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v2H3JdW110486162; Thu, 16 Mar 2017 20:19:39 -0700 Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A935C7803F; Thu, 16 Mar 2017 21:19:39 -0600 (MDT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP id C461278038; Thu, 16 Mar 2017 21:19:37 -0600 (MDT) From: Dong Jia Shi To: kvm@vger.kernel.org, linux-s390@vger.kernel.org, qemu-devel@nongnu.org Date: Fri, 17 Mar 2017 04:19:19 +0100 X-Mailer: git-send-email 2.8.4 In-Reply-To: <20170317031928.40189-1-bjsdjshi@linux.vnet.ibm.com> References: <20170317031928.40189-1-bjsdjshi@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17031703-0008-0000-0000-0000077209DB X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00006796; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000206; SDB=6.00834931; UDB=6.00410081; IPR=6.00612586; BA=6.00005215; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00014684; XFM=3.00000013; UTC=2017-03-17 03:19:42 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17031703-0009-0000-0000-000040BC3E16 Message-Id: <20170317031928.40189-3-bjsdjshi@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-03-17_01:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1702020001 definitions=main-1703170026 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 v4 02/11] s390x/css: add s390-squash-mcss machine option 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: pasic@linux.vnet.ibm.com, pmorel@linux.vnet.ibm.com, borntraeger@de.ibm.com, alex.williamson@redhat.com, renxiaof@linux.vnet.ibm.com, cornelia.huck@de.ibm.com, bjsdjshi@linux.vnet.ibm.com, agraf@suse.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Xiao Feng Ren We want to support real (i.e. not virtual) channel devices even for guests that do not support MCSS-E (where guests may see devices from any channel subsystem image at once). As all virtio-ccw devices are in css 0xfe (and show up in the default css 0 for guests not activating MCSS-E), we need an option to squash both the virtio subchannels and e.g. passed-through subchannels from their real css (0-3, or 0 for hosts not activating MCSS-E) into the default css. This will be exploited in a later patch. Signed-off-by: Xiao Feng Ren Signed-off-by: Dong Jia Shi --- hw/s390x/s390-virtio-ccw.c | 23 +++++++++++++++++++++++ include/hw/s390x/s390-virtio-ccw.h | 1 + qemu-options.hx | 6 +++++- target/s390x/cpu.h | 10 ++++++++++ 4 files changed, 39 insertions(+), 1 deletion(-) diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c index 40914fd..a51f578 100644 --- a/hw/s390x/s390-virtio-ccw.c +++ b/hw/s390x/s390-virtio-ccw.c @@ -273,6 +273,21 @@ bool cpu_model_allowed(void) return true; } =20 +static inline bool machine_get_squash_mcss(Object *obj, Error **errp) +{ + S390CcwMachineState *ms =3D S390_CCW_MACHINE(obj); + + return ms->s390_squash_mcss; +} + +static inline void machine_set_squash_mcss(Object *obj, bool value, + Error **errp) +{ + S390CcwMachineState *ms =3D S390_CCW_MACHINE(obj); + + ms->s390_squash_mcss =3D value; +} + static inline void s390_machine_initfn(Object *obj) { object_property_add_bool(obj, "aes-key-wrap", @@ -290,6 +305,14 @@ static inline void s390_machine_initfn(Object *obj) "enable/disable DEA key wrapping using the CPACF wrapping key", NULL); object_property_set_bool(obj, true, "dea-key-wrap", NULL); + + object_property_add_bool(obj, "s390-squash-mcss", + machine_get_squash_mcss, + machine_set_squash_mcss, NULL); + object_property_set_description(obj, "s390-squash-mcss", + "enable/disable squashing subchannels into the default css", + NULL); + object_property_set_bool(obj, false, "s390-squash-mcss", NULL); } =20 static const TypeInfo ccw_machine_info =3D { diff --git a/include/hw/s390x/s390-virtio-ccw.h b/include/hw/s390x/s390-vir= tio-ccw.h index 6ecae00..28d98fa 100644 --- a/include/hw/s390x/s390-virtio-ccw.h +++ b/include/hw/s390x/s390-virtio-ccw.h @@ -28,6 +28,7 @@ typedef struct S390CcwMachineState { /*< public >*/ bool aes_key_wrap; bool dea_key_wrap; + bool s390_squash_mcss; } S390CcwMachineState; =20 typedef struct S390CcwMachineClass { diff --git a/qemu-options.hx b/qemu-options.hx index 8dd8ee3..22b5d11 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -42,7 +42,8 @@ DEF("machine", HAS_ARG, QEMU_OPTION_machine, \ " dea-key-wrap=3Don|off controls support for DEA key wr= apping (default=3Don)\n" " suppress-vmdesc=3Don|off disables self-describing mig= ration (default=3Doff)\n" " nvdimm=3Don|off controls NVDIMM support (default=3Dof= f)\n" - " enforce-config-section=3Don|off enforce configuration= section migration (default=3Doff)\n", + " enforce-config-section=3Don|off enforce configuration= section migration (default=3Doff)\n" + " s390-squash-mcss=3Don|off controls support for squash= ing into default css (default=3Doff)\n", QEMU_ARCH_ALL) STEXI @item -machine [type=3D]@var{name}[,prop=3D@var{value}[,...]] @@ -81,6 +82,9 @@ controls whether DEA wrapping keys will be created to all= ow execution of DEA cryptographic functions. The default is on. @item nvdimm=3Don|off Enables or disables NVDIMM support. The default is off. +@item s390-squash-mcss=3Don|off +Enables or disables squashing subchannels into the default css. +The default is off. @end table ETEXI =20 diff --git a/target/s390x/cpu.h b/target/s390x/cpu.h index 058ddad..c367891 100644 --- a/target/s390x/cpu.h +++ b/target/s390x/cpu.h @@ -1250,6 +1250,16 @@ static inline void s390_crypto_reset(void) } } =20 +static inline bool s390_get_squash_mcss(void) +{ + if (object_property_get_bool(OBJECT(qdev_get_machine()), "s390-squash-= mcss", + NULL)) { + return true; + } + + return false; +} + /* machine check interruption code */ =20 /* subclasses */ --=20 2.8.4 From nobody Sat May 4 07:15:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489721304688309.77214213876243; Thu, 16 Mar 2017 20:28:24 -0700 (PDT) Received: from localhost ([::1]:46924 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1coiYx-0006Ga-8f for importer@patchew.org; Thu, 16 Mar 2017 23:28:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57533) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1coiQj-0007nt-3W for qemu-devel@nongnu.org; Thu, 16 Mar 2017 23:19:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1coiQe-0000lG-KR for qemu-devel@nongnu.org; Thu, 16 Mar 2017 23:19:53 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:55858) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1coiQe-0000l1-AE for qemu-devel@nongnu.org; Thu, 16 Mar 2017 23:19:48 -0400 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v2H3JBRt085206 for ; Thu, 16 Mar 2017 23:19:47 -0400 Received: from e31.co.us.ibm.com (e31.co.us.ibm.com [32.97.110.149]) by mx0a-001b2d01.pphosted.com with ESMTP id 297mmyd3q5-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 16 Mar 2017 23:19:47 -0400 Received: from localhost by e31.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 16 Mar 2017 21:19:46 -0600 Received: from b03cxnp07029.gho.boulder.ibm.com (9.17.130.16) by e31.co.us.ibm.com (192.168.1.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 16 Mar 2017 21:19:44 -0600 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp07029.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v2H3Jgu217170896; Thu, 16 Mar 2017 20:19:42 -0700 Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C978C78047; Thu, 16 Mar 2017 21:19:42 -0600 (MDT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP id E48B278041; Thu, 16 Mar 2017 21:19:40 -0600 (MDT) From: Dong Jia Shi To: kvm@vger.kernel.org, linux-s390@vger.kernel.org, qemu-devel@nongnu.org Date: Fri, 17 Mar 2017 04:19:20 +0100 X-Mailer: git-send-email 2.8.4 In-Reply-To: <20170317031928.40189-1-bjsdjshi@linux.vnet.ibm.com> References: <20170317031928.40189-1-bjsdjshi@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17031703-8235-0000-0000-00000B240ACB X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00006796; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000206; SDB=6.00834930; UDB=6.00410081; IPR=6.00612586; BA=6.00005215; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00014684; XFM=3.00000013; UTC=2017-03-17 03:19:45 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17031703-8236-0000-0000-00003A6433C3 Message-Id: <20170317031928.40189-4-bjsdjshi@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-03-17_01:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=2 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1702020001 definitions=main-1703170026 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 v4 03/11] s390x/css: realize css_sch_build_schib 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: pasic@linux.vnet.ibm.com, pmorel@linux.vnet.ibm.com, borntraeger@de.ibm.com, alex.williamson@redhat.com, renxiaof@linux.vnet.ibm.com, cornelia.huck@de.ibm.com, bjsdjshi@linux.vnet.ibm.com, agraf@suse.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Xiao Feng Ren The S390 virtual css support already has a mechanism to build virtual Sub-Channel Information Block and provide virtual subchannels to the guest. However, to pass-through subchannels to a guest, we need to introduce a new mechanism to build its schib according to the real device information. Thus we realize a new css_sch_build_schib function to extract the path_masks, chpids, chpid type from sysfs. To reuse the existing code, we refactor css_add_virtual_chpid to css_add_chpid. Reviewed-by: Pierre Morel Signed-off-by: Xiao Feng Ren Signed-off-by: Dong Jia Shi --- hw/s390x/css.c | 153 +++++++++++++++++++++++++++++++++++++++++++++= +++- include/hw/s390x/css.h | 36 ++++++------ 2 files changed, 169 insertions(+), 20 deletions(-) diff --git a/hw/s390x/css.c b/hw/s390x/css.c index e32b2a4..a550cf7 100644 --- a/hw/s390x/css.c +++ b/hw/s390x/css.c @@ -13,6 +13,7 @@ #include "qapi/error.h" #include "qapi/visitor.h" #include "hw/qdev.h" +#include "qemu/error-report.h" #include "qemu/bitops.h" #include "exec/address-spaces.h" #include "cpu.h" @@ -1281,7 +1282,8 @@ bool css_schid_final(int m, uint8_t cssid, uint8_t ss= id, uint16_t schid) (MAX_SCHID + 1) / sizeof(unsigned long)); } =20 -static int css_add_virtual_chpid(uint8_t cssid, uint8_t chpid, uint8_t typ= e) +static int css_add_chpid(uint8_t cssid, uint8_t chpid, uint8_t type, + bool is_virt) { CssImage *css; =20 @@ -1295,7 +1297,7 @@ static int css_add_virtual_chpid(uint8_t cssid, uint8= _t chpid, uint8_t type) } css->chpids[chpid].in_use =3D 1; css->chpids[chpid].type =3D type; - css->chpids[chpid].is_virtual =3D 1; + css->chpids[chpid].is_virtual =3D is_virt; =20 css_generate_chp_crws(cssid, chpid); =20 @@ -1319,7 +1321,7 @@ void css_sch_build_virtual_schib(SubchDev *sch, uint8= _t chpid, uint8_t type) p->pam =3D 0x80; p->chpid[0] =3D chpid; if (!css->chpids[chpid].in_use) { - css_add_virtual_chpid(sch->cssid, chpid, type); + css_add_chpid(sch->cssid, chpid, type, true); } =20 memset(s, 0, sizeof(SCSW)); @@ -1911,3 +1913,148 @@ SubchDev *css_create_virtual_sch(CssDevId bus_id, E= rror **errp) css_subch_assign(sch->cssid, sch->ssid, schid, sch->devno, sch); return sch; } + +static int css_sch_get_chpids(SubchDev *sch, CssDevId *dev_id) +{ + char *fid_path; + FILE *fd; + uint32_t chpid[8]; + int i; + PMCW *p =3D &sch->curr_status.pmcw; + + fid_path =3D g_strdup_printf("/sys/bus/css/devices/%x.%x.%04x/chpids", + dev_id->cssid, dev_id->ssid, dev_id->devid); + fd =3D fopen(fid_path, "r"); + if (fd =3D=3D NULL) { + error_report("%s: open %s failed", __func__, fid_path); + g_free(fid_path); + return -EINVAL; + } + + if (fscanf(fd, "%x %x %x %x %x %x %x %x", + &chpid[0], &chpid[1], &chpid[2], &chpid[3], + &chpid[4], &chpid[5], &chpid[6], &chpid[7]) !=3D 8) { + fclose(fd); + g_free(fid_path); + return -EINVAL; + } + + for (i =3D 0; i < ARRAY_SIZE(p->chpid); i++) { + p->chpid[i] =3D chpid[i]; + } + + fclose(fd); + g_free(fid_path); + + return 0; +} + +static int css_sch_get_path_masks(SubchDev *sch, CssDevId *dev_id) +{ + char *fid_path; + FILE *fd; + uint32_t pim, pam, pom; + PMCW *p =3D &sch->curr_status.pmcw; + + fid_path =3D g_strdup_printf("/sys/bus/css/devices/%x.%x.%04x/pimpampo= m", + dev_id->cssid, dev_id->ssid, dev_id->devid); + fd =3D fopen(fid_path, "r"); + if (fd =3D=3D NULL) { + error_report("%s: open %s failed", __func__, fid_path); + g_free(fid_path); + return -EINVAL; + } + + if (fscanf(fd, "%x %x %x", &pim, &pam, &pom) !=3D 3) { + fclose(fd); + g_free(fid_path); + return -EINVAL; + } + + p->pim =3D pim; + p->pam =3D pam; + p->pom =3D pom; + fclose(fd); + g_free(fid_path); + + return 0; +} + +static int css_sch_get_chpid_type(uint8_t chpid, uint32_t *type, + CssDevId *dev_id) +{ + char *fid_path; + FILE *fd; + + fid_path =3D g_strdup_printf("/sys/devices/css%x/chp0.%02x/type", + dev_id->cssid, chpid); + fd =3D fopen(fid_path, "r"); + if (fd =3D=3D NULL) { + error_report("%s: open %s failed", __func__, fid_path); + g_free(fid_path); + return -EINVAL; + } + + if (fscanf(fd, "%x", type) !=3D 1) { + fclose(fd); + g_free(fid_path); + return -EINVAL; + } + + fclose(fd); + g_free(fid_path); + + return 0; +} + +/* + * We currently retrieve the real device information from sysfs to build t= he + * guest subchannel information block without considering the migration fe= ature. + * If migrate, it won't be sure to use the real device information directl= y, + * this point will be handled in the future. + */ +int css_sch_build_schib(SubchDev *sch, CssDevId *dev_id) +{ + CssImage *css =3D channel_subsys.css[sch->cssid]; + PMCW *p =3D &sch->curr_status.pmcw; + SCSW *s =3D &sch->curr_status.scsw; + uint32_t type; + int i, ret; + + /* We are dealing with I/O subchannels only. */ + assert(css !=3D NULL); + memset(p, 0, sizeof(PMCW)); + p->flags |=3D PMCW_FLAGS_MASK_DNV; + p->devno =3D sch->devno; + + /* Grab path mask from sysfs. */ + ret =3D css_sch_get_path_masks(sch, dev_id); + if (ret) { + return ret; + } + + /* Grab chpids from sysfs. */ + ret =3D css_sch_get_chpids(sch, dev_id); + if (ret) { + return ret; + } + + /* Build chpid type. */ + for (i =3D 0; i < ARRAY_SIZE(p->chpid); i++) { + if (p->chpid[i] && !css->chpids[p->chpid[i]].in_use) { + ret =3D css_sch_get_chpid_type(p->chpid[i], &type, dev_id); + if (ret) { + return ret; + } + css_add_chpid(sch->cssid, p->chpid[i], type, false); + } + } + + memset(s, 0, sizeof(SCSW)); + sch->curr_status.mba =3D 0; + for (i =3D 0; i < ARRAY_SIZE(sch->curr_status.mda); i++) { + sch->curr_status.mda[i] =3D 0; + } + + return 0; +} diff --git a/include/hw/s390x/css.h b/include/hw/s390x/css.h index c96c862..648ea2f 100644 --- a/include/hw/s390x/css.h +++ b/include/hw/s390x/css.h @@ -92,6 +92,24 @@ struct SubchDev { void *driver_data; }; =20 +/* + * Identify a device within the channel subsystem. + * Note that this can be used to identify either the subchannel or + * the attached I/O device, as there's always one I/O device per + * subchannel. + */ +typedef struct CssDevId { + uint8_t cssid; + uint8_t ssid; + uint16_t devid; + bool valid; +} CssDevId; + +extern PropertyInfo css_devid_propinfo; + +#define DEFINE_PROP_CSS_DEV_ID(_n, _s, _f) \ + DEFINE_PROP(_n, _s, _f, css_devid_propinfo, CssDevId) + typedef struct IndAddr { hwaddr addr; uint64_t map; @@ -113,6 +131,7 @@ bool css_devno_used(uint8_t cssid, uint8_t ssid, uint16= _t devno); void css_subch_assign(uint8_t cssid, uint8_t ssid, uint16_t schid, uint16_t devno, SubchDev *sch); void css_sch_build_virtual_schib(SubchDev *sch, uint8_t chpid, uint8_t typ= e); +int css_sch_build_schib(SubchDev *sch, CssDevId *dev_id); uint16_t css_build_subchannel_id(SubchDev *sch); void css_reset(void); void css_reset_sch(SubchDev *sch); @@ -154,23 +173,6 @@ int css_do_rsch(SubchDev *sch); int css_do_rchp(uint8_t cssid, uint8_t chpid); bool css_present(uint8_t cssid); #endif -/* - * Identify a device within the channel subsystem. - * Note that this can be used to identify either the subchannel or - * the attached I/O device, as there's always one I/O device per - * subchannel. - */ -typedef struct CssDevId { - uint8_t cssid; - uint8_t ssid; - uint16_t devid; - bool valid; -} CssDevId; - -extern PropertyInfo css_devid_propinfo; - -#define DEFINE_PROP_CSS_DEV_ID(_n, _s, _f) \ - DEFINE_PROP(_n, _s, _f, css_devid_propinfo, CssDevId) =20 /** * Create a subchannel for the given bus id. --=20 2.8.4 From nobody Sat May 4 07:15:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 148972124581960.4618168174685; Thu, 16 Mar 2017 20:27:25 -0700 (PDT) Received: from localhost ([::1]:46920 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1coiY0-0005Mx-9j for importer@patchew.org; Thu, 16 Mar 2017 23:27:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57566) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1coiQm-0007rA-L0 for qemu-devel@nongnu.org; Thu, 16 Mar 2017 23:20:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1coiQi-0000m4-6Z for qemu-devel@nongnu.org; Thu, 16 Mar 2017 23:19:56 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:51268 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1coiQh-0000lw-Vw for qemu-devel@nongnu.org; Thu, 16 Mar 2017 23:19:52 -0400 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v2H3JGbn055799 for ; Thu, 16 Mar 2017 23:19:51 -0400 Received: from e37.co.us.ibm.com (e37.co.us.ibm.com [32.97.110.158]) by mx0a-001b2d01.pphosted.com with ESMTP id 2981f9wdb9-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 16 Mar 2017 23:19:51 -0400 Received: from localhost by e37.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 16 Mar 2017 21:19:49 -0600 Received: from b03cxnp08026.gho.boulder.ibm.com (9.17.130.18) by e37.co.us.ibm.com (192.168.1.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 16 Mar 2017 21:19:47 -0600 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp08026.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v2H3Jkoj8978820; Thu, 16 Mar 2017 20:19:46 -0700 Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E94C47803F; Thu, 16 Mar 2017 21:19:45 -0600 (MDT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP id 10BAF78038; Thu, 16 Mar 2017 21:19:43 -0600 (MDT) From: Dong Jia Shi To: kvm@vger.kernel.org, linux-s390@vger.kernel.org, qemu-devel@nongnu.org Date: Fri, 17 Mar 2017 04:19:21 +0100 X-Mailer: git-send-email 2.8.4 In-Reply-To: <20170317031928.40189-1-bjsdjshi@linux.vnet.ibm.com> References: <20170317031928.40189-1-bjsdjshi@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17031703-0024-0000-0000-000016130AA5 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00006796; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000206; SDB=6.00834930; UDB=6.00410081; IPR=6.00612586; BA=6.00005215; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00014684; XFM=3.00000013; UTC=2017-03-17 03:19:48 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17031703-0025-0000-0000-000049853274 Message-Id: <20170317031928.40189-5-bjsdjshi@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-03-17_01:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=2 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1702020001 definitions=main-1703170026 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PATCH v4 04/11] s390x/css: realize css_create_sch 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: pasic@linux.vnet.ibm.com, pmorel@linux.vnet.ibm.com, borntraeger@de.ibm.com, alex.williamson@redhat.com, renxiaof@linux.vnet.ibm.com, cornelia.huck@de.ibm.com, bjsdjshi@linux.vnet.ibm.com, agraf@suse.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The S390 virtual css support already has a mechanism to create a virtual subchannel and provide it to the guest. However, to pass-through subchannels to a guest, we need to introduce a new mechanism to create the subchannel according to the real device information. Thus we reconstruct css_create_virtual_sch to a new css_create_sch function to handl all these cases and do allocation and initialization of the subchannel according to the device type and machine configuration. Reviewed-by: Pierre Morel Signed-off-by: Dong Jia Shi --- hw/s390x/css-bridge.c | 2 ++ hw/s390x/css.c | 45 ++++++++++++++++++++++++++++++++++++---= ---- hw/s390x/s390-virtio-ccw.c | 12 +++++++++--- hw/s390x/virtio-ccw.c | 6 +++++- include/hw/s390x/css-bridge.h | 1 + include/hw/s390x/css.h | 25 ++++++++++++++++-------- 6 files changed, 72 insertions(+), 19 deletions(-) diff --git a/hw/s390x/css-bridge.c b/hw/s390x/css-bridge.c index 9a7f7ee..14d3af4 100644 --- a/hw/s390x/css-bridge.c +++ b/hw/s390x/css-bridge.c @@ -17,6 +17,7 @@ #include "hw/s390x/css.h" #include "ccw-device.h" #include "hw/s390x/css-bridge.h" +#include "cpu.h" =20 /* * Invoke device-specific unplug handler, disable the subchannel @@ -103,6 +104,7 @@ VirtualCssBus *virtual_css_bus_init(void) /* Create bus on bridge device */ bus =3D qbus_create(TYPE_VIRTUAL_CSS_BUS, dev, "virtual-css"); cbus =3D VIRTUAL_CSS_BUS(bus); + cbus->squash_mcss =3D s390_get_squash_mcss(); =20 /* Enable hotplugging */ qbus_set_hotplug_handler(bus, dev, &error_abort); diff --git a/hw/s390x/css.c b/hw/s390x/css.c index a550cf7..01e88e1 100644 --- a/hw/s390x/css.c +++ b/hw/s390x/css.c @@ -1881,28 +1881,59 @@ PropertyInfo css_devid_propinfo =3D { .set =3D set_css_devid, }; =20 -SubchDev *css_create_virtual_sch(CssDevId bus_id, Error **errp) +SubchDev *css_create_sch(CssDevId bus_id, bool is_virtio, bool squash_mcss, + Error **errp) { uint16_t schid =3D 0; SubchDev *sch; =20 if (bus_id.valid) { - /* Enforce use of virtual cssid. */ - if (bus_id.cssid !=3D VIRTUAL_CSSID) { - error_setg(errp, "cssid %hhx not valid for virtual devices", - bus_id.cssid); + if (is_virtio !=3D (bus_id.cssid =3D=3D VIRTUAL_CSSID)) { + error_setg(errp, "cssid %hhx not valid for %s devices", + bus_id.cssid, + (is_virtio ? "virtio" : "non-virtio")); return NULL; } + } + + if (bus_id.valid) { + if (squash_mcss) { + bus_id.cssid =3D channel_subsys.default_cssid; + } else if (!channel_subsys.css[bus_id.cssid]) { + css_create_css_image(bus_id.cssid, false); + } + if (!css_find_free_subch_for_devno(bus_id.cssid, bus_id.ssid, bus_id.devid, &schid, errp)) { return NULL; } - } else { - bus_id.cssid =3D VIRTUAL_CSSID; + } else if (squash_mcss || is_virtio) { + bus_id.cssid =3D channel_subsys.default_cssid; + if (!css_find_free_subch_and_devno(bus_id.cssid, &bus_id.ssid, &bus_id.devid, &schid, errp)) { return NULL; } + } else { + for (bus_id.cssid =3D 0; bus_id.cssid < MAX_CSSID; ++bus_id.cssid)= { + if (bus_id.cssid =3D=3D VIRTUAL_CSSID) { + continue; + } + + if (!channel_subsys.css[bus_id.cssid]) { + css_create_css_image(bus_id.cssid, false); + } + + if (css_find_free_subch_and_devno(bus_id.cssid, &bus_id.ssid, + &bus_id.devid, &schid, + NULL)) { + break ; + } + if (bus_id.cssid =3D=3D MAX_CSSID) { + error_setg(errp, "Virtual channel subsystem is full!"); + return NULL; + } + } } =20 sch =3D g_malloc0(sizeof(*sch)); diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c index a51f578..d9f0911 100644 --- a/hw/s390x/s390-virtio-ccw.c +++ b/hw/s390x/s390-virtio-ccw.c @@ -135,10 +135,16 @@ static void ccw_init(MachineState *machine) kvm_s390_enable_css_support(s390_cpu_addr2state(0)); } /* - * Create virtual css and set it as default so that non mcss-e - * enabled guests only see virtio devices. + * Non mcss-e enabled guests only see the devices from the default + * css, which is determined by the value of the squash_mcss property. + * Note: we must not squash non virtio devices to css 0xFE, since + * it's reserved for virtio devices only. */ - ret =3D css_create_css_image(VIRTUAL_CSSID, true); + if (css_bus->squash_mcss) { + ret =3D css_create_css_image(0, true); + } else { + ret =3D css_create_css_image(VIRTUAL_CSSID, true); + } assert(ret =3D=3D 0); =20 /* Create VirtIO network adapters */ diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c index 00b3bde..c6ba8d1 100644 --- a/hw/s390x/virtio-ccw.c +++ b/hw/s390x/virtio-ccw.c @@ -680,9 +680,13 @@ static void virtio_ccw_device_realize(VirtioCcwDevice = *dev, Error **errp) { VirtIOCCWDeviceClass *k =3D VIRTIO_CCW_DEVICE_GET_CLASS(dev); CcwDevice *ccw_dev =3D CCW_DEVICE(dev); - SubchDev *sch =3D css_create_virtual_sch(ccw_dev->bus_id, errp); + DeviceState *parent =3D DEVICE(ccw_dev); + BusState *qbus =3D qdev_get_parent_bus(parent); + VirtualCssBus *cbus =3D VIRTUAL_CSS_BUS(qbus); + SubchDev *sch; Error *err =3D NULL; =20 + sch =3D css_create_sch(ccw_dev->bus_id, true, cbus->squash_mcss, errp); if (!sch) { return; } diff --git a/include/hw/s390x/css-bridge.h b/include/hw/s390x/css-bridge.h index 5a0203b..cf08604 100644 --- a/include/hw/s390x/css-bridge.h +++ b/include/hw/s390x/css-bridge.h @@ -28,6 +28,7 @@ typedef struct VirtualCssBridge { /* virtual css bus type */ typedef struct VirtualCssBus { BusState parent_obj; + bool squash_mcss; } VirtualCssBus; =20 #define TYPE_VIRTUAL_CSS_BUS "virtual-css-bus" diff --git a/include/hw/s390x/css.h b/include/hw/s390x/css.h index 648ea2f..2170d11 100644 --- a/include/hw/s390x/css.h +++ b/include/hw/s390x/css.h @@ -177,16 +177,25 @@ bool css_present(uint8_t cssid); /** * Create a subchannel for the given bus id. * - * If @p bus_id is valid, verify that it uses the virtual channel - * subsystem id and is not already in use, and find a free subchannel - * id for it. If @p bus_id is not valid, find a free subchannel id and - * device number across all subchannel sets. If either of the former - * actions succeed, allocate a subchannel structure, initialise it - * with the bus id, subchannel id and device number, register it with - * the CSS and return it. Otherwise return NULL. + * If @p bus_id is valid, and @p squash_mcss is true, verify that it is + * not already in use in the default css, and find a free devno from the + * default css image for it. + * If @p bus_id is valid, and @p squash_mcss is false, verify that it is + * not already in use, and find a free devno for it. + * If @p bus_id is not valid, and if either @p squash_mcss or @p is_virtio + * is true, find a free subchannel id and device number across all + * subchannel sets from the default css image. + * If @p bus_id is not valid, and if both @p squash_mcss and @p is_virtio + * are false, find a non-full css image and find a free subchannel id and + * device number across all subchannel sets from it. + * + * If either of the former actions succeed, allocate a subchannel structur= e, + * initialise it with the bus id, subchannel id and device number, register + * it with the CSS and return it. Otherwise return NULL. * * The caller becomes owner of the returned subchannel structure and * is responsible for unregistering and freeing it. */ -SubchDev *css_create_virtual_sch(CssDevId bus_id, Error **errp); +SubchDev *css_create_sch(CssDevId bus_id, bool is_virtio, bool squash_mcss, + Error **errp); #endif --=20 2.8.4 From nobody Sat May 4 07:15:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489721439422152.77862633393556; Thu, 16 Mar 2017 20:30:39 -0700 (PDT) Received: from localhost ([::1]:46932 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1coib8-0008W5-0y for importer@patchew.org; Thu, 16 Mar 2017 23:30:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57592) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1coiQq-0007vF-Pr for qemu-devel@nongnu.org; Thu, 16 Mar 2017 23:20:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1coiQl-0000p4-SB for qemu-devel@nongnu.org; Thu, 16 Mar 2017 23:20:00 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:45291 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1coiQl-0000ny-Lt for qemu-devel@nongnu.org; Thu, 16 Mar 2017 23:19:55 -0400 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v2H3JJBq008044 for ; Thu, 16 Mar 2017 23:19:55 -0400 Received: from e32.co.us.ibm.com (e32.co.us.ibm.com [32.97.110.150]) by mx0a-001b2d01.pphosted.com with ESMTP id 297seue3w3-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 16 Mar 2017 23:19:54 -0400 Received: from localhost by e32.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 16 Mar 2017 21:19:54 -0600 Received: from b03cxnp07028.gho.boulder.ibm.com (9.17.130.15) by e32.co.us.ibm.com (192.168.1.132) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 16 Mar 2017 21:19:50 -0600 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp07028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v2H3JnKH16318742; Thu, 16 Mar 2017 20:19:49 -0700 Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1701578041; Thu, 16 Mar 2017 21:19:49 -0600 (MDT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP id 30FB178043; Thu, 16 Mar 2017 21:19:47 -0600 (MDT) From: Dong Jia Shi To: kvm@vger.kernel.org, linux-s390@vger.kernel.org, qemu-devel@nongnu.org Date: Fri, 17 Mar 2017 04:19:22 +0100 X-Mailer: git-send-email 2.8.4 In-Reply-To: <20170317031928.40189-1-bjsdjshi@linux.vnet.ibm.com> References: <20170317031928.40189-1-bjsdjshi@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17031703-0004-0000-0000-000011CB0AA1 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00006796; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000206; SDB=6.00834931; UDB=6.00410082; IPR=6.00612586; BA=6.00005215; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00014684; XFM=3.00000013; UTC=2017-03-17 03:19:52 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17031703-0005-0000-0000-00007DE13923 Message-Id: <20170317031928.40189-6-bjsdjshi@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-03-17_01:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=2 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1702020001 definitions=main-1703170026 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PATCH v4 05/11] s390x/css: device support for s390-ccw passthrough 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: pasic@linux.vnet.ibm.com, pmorel@linux.vnet.ibm.com, borntraeger@de.ibm.com, alex.williamson@redhat.com, renxiaof@linux.vnet.ibm.com, cornelia.huck@de.ibm.com, bjsdjshi@linux.vnet.ibm.com, agraf@suse.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" In order to support subchannels pass-through, we introduce a s390 subchannel device called "s390-ccw" to hold the real subchannel info. The s390-ccw devices inherit from the abstract CcwDevice which connect to the existing virtual-css-bus. Signed-off-by: Dong Jia Shi --- hw/s390x/Makefile.objs | 1 + hw/s390x/s390-ccw.c | 125 +++++++++++++++++++++++++++++++++++++++++++++= ++++ hw/s390x/s390-ccw.h | 38 +++++++++++++++ 3 files changed, 164 insertions(+) create mode 100644 hw/s390x/s390-ccw.c create mode 100644 hw/s390x/s390-ccw.h diff --git a/hw/s390x/Makefile.objs b/hw/s390x/Makefile.objs index 41ac4ec..72a3d37 100644 --- a/hw/s390x/Makefile.objs +++ b/hw/s390x/Makefile.objs @@ -13,3 +13,4 @@ obj-y +=3D ccw-device.o obj-y +=3D s390-pci-bus.o s390-pci-inst.o obj-y +=3D s390-skeys.o obj-$(CONFIG_KVM) +=3D s390-skeys-kvm.o +obj-y +=3D s390-ccw.o diff --git a/hw/s390x/s390-ccw.c b/hw/s390x/s390-ccw.c new file mode 100644 index 0000000..9b6de68 --- /dev/null +++ b/hw/s390x/s390-ccw.c @@ -0,0 +1,125 @@ +/* + * s390 CCW Assignment Support + * + * Copyright 2017 IBM Corp + * Author(s): Dong Jia Shi + * Xiao Feng Ren + * Pierre Morel + * + * This work is licensed under the terms of the GNU GPL, version 2 + * or (at your option) any later version. See the COPYING file in the + * top-level directory. + */ +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "hw/sysbus.h" +#include "libgen.h" +#include "hw/s390x/css.h" +#include "hw/s390x/css-bridge.h" +#include "s390-ccw.h" + +static void s390_ccw_get_dev_info(S390CCWDevice *cdev, + char *sysfsdev, + Error **errp) +{ + char dev_path[PATH_MAX], *tmp; + unsigned int cssid, ssid, devid; + + if (!sysfsdev) { + error_setg(errp, "No host device provided"); + error_append_hint(errp, "Use -vfio-ccw,sysfsdev=3DPATH_TO_DEVICE\n= "); + return; + } + + if (!realpath(sysfsdev, dev_path)) { + error_setg(errp, "Host device '%s' not found", sysfsdev); + return; + } + + cdev->mdevid =3D g_strdup(basename(dev_path)); + + tmp =3D basename(dirname(dev_path)); + sscanf(tmp, "%2x.%1x.%4x", &cssid, &ssid, &devid); + + cdev->hostid.cssid =3D cssid; + cdev->hostid.ssid =3D ssid; + cdev->hostid.devid =3D devid; + cdev->hostid.valid =3D true; +} + +static void s390_ccw_realize(S390CCWDevice *cdev, char *sysfsdev, Error **= errp) +{ + CcwDevice *ccw_dev =3D CCW_DEVICE(cdev); + DeviceState *parent =3D DEVICE(ccw_dev); + BusState *qbus =3D qdev_get_parent_bus(parent); + VirtualCssBus *cbus =3D VIRTUAL_CSS_BUS(qbus); + SubchDev *sch; + int ret; + + s390_ccw_get_dev_info(cdev, sysfsdev, errp); + if (*errp) { + return; + } + + sch =3D css_create_sch(ccw_dev->bus_id, false, cbus->squash_mcss, errp= ); + if (!sch) { + return; + } + + sch->driver_data =3D cdev; + + ret =3D css_sch_build_schib(sch, &cdev->hostid); + if (ret) { + error_setg(errp, "%s: Failed to build initial schib: %d", + __func__, ret); + css_subch_assign(sch->cssid, sch->ssid, sch->schid, sch->devno, NU= LL); + g_free(sch); + return; + } + css_generate_sch_crws(sch->cssid, sch->ssid, sch->schid, + parent->hotplugged, 1); + + ccw_dev->sch =3D sch; + + return; +} + +static void s390_ccw_unrealize(S390CCWDevice *cdev, Error **errp) +{ + CcwDevice *ccw_dev =3D CCW_DEVICE(cdev); + SubchDev *sch =3D ccw_dev->sch; + + if (sch) { + css_subch_assign(sch->cssid, sch->ssid, sch->schid, sch->devno, NU= LL); + g_free(sch); + ccw_dev->sch =3D NULL; + } + + g_free(cdev->mdevid); +} + +static void s390_ccw_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + S390CCWDeviceClass *cdc =3D S390_CCW_DEVICE_CLASS(klass); + + dc->bus_type =3D TYPE_VIRTUAL_CSS_BUS; + cdc->realize =3D s390_ccw_realize; + cdc->unrealize =3D s390_ccw_unrealize; +} + +static const TypeInfo s390_ccw_info =3D { + .name =3D TYPE_S390_CCW, + .parent =3D TYPE_CCW_DEVICE, + .instance_size =3D sizeof(S390CCWDevice), + .class_size =3D sizeof(S390CCWDeviceClass), + .class_init =3D s390_ccw_class_init, + .abstract =3D true, +}; + +static void register_s390_ccw_type(void) +{ + type_register_static(&s390_ccw_info); +} + +type_init(register_s390_ccw_type) diff --git a/hw/s390x/s390-ccw.h b/hw/s390x/s390-ccw.h new file mode 100644 index 0000000..b58d8e9 --- /dev/null +++ b/hw/s390x/s390-ccw.h @@ -0,0 +1,38 @@ +/* + * s390 CCW Assignment Support + * + * Copyright 2017 IBM Corp. + * Author(s): Dong Jia Shi + * Xiao Feng Ren + * + * This work is licensed under the terms of the GNU GPL, version 2 or (at + * your option) any later version. See the COPYING file in the top-level + * directory. + */ + +#ifndef HW_S390_CCW_H +#define HW_S390_CCW_H + +#include "hw/s390x/ccw-device.h" + +#define TYPE_S390_CCW "s390-ccw" +#define S390_CCW_DEVICE(obj) \ + OBJECT_CHECK(S390CCWDevice, (obj), TYPE_S390_CCW) +#define S390_CCW_DEVICE_CLASS(klass) \ + OBJECT_CLASS_CHECK(S390CCWDeviceClass, (klass), TYPE_S390_CCW) +#define S390_CCW_DEVICE_GET_CLASS(obj) \ + OBJECT_GET_CLASS(S390CCWDeviceClass, (obj), TYPE_S390_CCW) + +typedef struct S390CCWDevice { + CcwDevice parent_obj; + CssDevId hostid; + char *mdevid; +} S390CCWDevice; + +typedef struct S390CCWDeviceClass { + CCWDeviceClass parent_class; + void (*realize)(S390CCWDevice *dev, char *sysfsdev, Error **errp); + void (*unrealize)(S390CCWDevice *dev, Error **errp); +} S390CCWDeviceClass; + +#endif --=20 2.8.4 From nobody Sat May 4 07:15:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489721591852813.030784715665; Thu, 16 Mar 2017 20:33:11 -0700 (PDT) Received: from localhost ([::1]:46945 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1coida-0002Hw-A4 for importer@patchew.org; Thu, 16 Mar 2017 23:33:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57648) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1coiQw-00080U-My for qemu-devel@nongnu.org; Thu, 16 Mar 2017 23:20:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1coiQr-0000rE-OZ for qemu-devel@nongnu.org; Thu, 16 Mar 2017 23:20:06 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:56212) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1coiQr-0000ql-ET for qemu-devel@nongnu.org; Thu, 16 Mar 2017 23:20:01 -0400 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v2H3JAUd078964 for ; Thu, 16 Mar 2017 23:20:00 -0400 Received: from e38.co.us.ibm.com (e38.co.us.ibm.com [32.97.110.159]) by mx0a-001b2d01.pphosted.com with ESMTP id 297yyw9hgw-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 16 Mar 2017 23:20:00 -0400 Received: from localhost by e38.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 16 Mar 2017 21:19:57 -0600 Received: from b03cxnp08028.gho.boulder.ibm.com (9.17.130.20) by e38.co.us.ibm.com (192.168.1.138) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 16 Mar 2017 21:19:53 -0600 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp08028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v2H3JpTi16253240; Thu, 16 Mar 2017 20:19:52 -0700 Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 37E9478038; Thu, 16 Mar 2017 21:19:52 -0600 (MDT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP id 5258A78041; Thu, 16 Mar 2017 21:19:50 -0600 (MDT) From: Dong Jia Shi To: kvm@vger.kernel.org, linux-s390@vger.kernel.org, qemu-devel@nongnu.org Date: Fri, 17 Mar 2017 04:19:23 +0100 X-Mailer: git-send-email 2.8.4 In-Reply-To: <20170317031928.40189-1-bjsdjshi@linux.vnet.ibm.com> References: <20170317031928.40189-1-bjsdjshi@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17031703-0028-0000-0000-0000073C0A57 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00006796; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000206; SDB=6.00834931; UDB=6.00410081; IPR=6.00612586; BA=6.00005215; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00014684; XFM=3.00000013; UTC=2017-03-17 03:19:55 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17031703-0029-0000-0000-0000345C31EE Message-Id: <20170317031928.40189-7-bjsdjshi@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-03-17_01:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=2 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1702020001 definitions=main-1703170026 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 v4 06/11] vfio/ccw: vfio based subchannel passthrough driver 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: pasic@linux.vnet.ibm.com, pmorel@linux.vnet.ibm.com, borntraeger@de.ibm.com, alex.williamson@redhat.com, renxiaof@linux.vnet.ibm.com, cornelia.huck@de.ibm.com, bjsdjshi@linux.vnet.ibm.com, agraf@suse.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Xiao Feng Ren We use the IOMMU_TYPE1 of VFIO to realize the subchannels passthrough, implement a vfio based subchannels passthrough driver called "vfio-ccw". Support qemu parameters in the style of: "-device vfio-ccw,sysfsdev=3D$mdev_file_path,devno=3Dxx.x.xxxx' Signed-off-by: Xiao Feng Ren Signed-off-by: Dong Jia Shi --- default-configs/s390x-softmmu.mak | 1 + hw/vfio/Makefile.objs | 1 + hw/vfio/ccw.c | 208 ++++++++++++++++++++++++++++++++++= ++++ include/hw/vfio/vfio-common.h | 1 + 4 files changed, 211 insertions(+) create mode 100644 hw/vfio/ccw.c diff --git a/default-configs/s390x-softmmu.mak b/default-configs/s390x-soft= mmu.mak index 36e15de..5576b0a 100644 --- a/default-configs/s390x-softmmu.mak +++ b/default-configs/s390x-softmmu.mak @@ -4,4 +4,5 @@ CONFIG_VIRTIO=3Dy CONFIG_SCLPCONSOLE=3Dy CONFIG_S390_FLIC=3Dy CONFIG_S390_FLIC_KVM=3D$(CONFIG_KVM) +CONFIG_VFIO_CCW=3D$(CONFIG_LINUX) CONFIG_WDT_DIAG288=3Dy diff --git a/hw/vfio/Makefile.objs b/hw/vfio/Makefile.objs index 05e7fbb..c3ab909 100644 --- a/hw/vfio/Makefile.objs +++ b/hw/vfio/Makefile.objs @@ -1,6 +1,7 @@ ifeq ($(CONFIG_LINUX), y) obj-$(CONFIG_SOFTMMU) +=3D common.o obj-$(CONFIG_PCI) +=3D pci.o pci-quirks.o +obj-$(CONFIG_VFIO_CCW) +=3D ccw.o obj-$(CONFIG_SOFTMMU) +=3D platform.o obj-$(CONFIG_VFIO_XGMAC) +=3D calxeda-xgmac.o obj-$(CONFIG_VFIO_AMD_XGBE) +=3D amd-xgbe.o diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c new file mode 100644 index 0000000..d5ff02f --- /dev/null +++ b/hw/vfio/ccw.c @@ -0,0 +1,208 @@ +/* + * vfio based subchannel assignment support + * + * Copyright 2017 IBM Corp. + * Author(s): Dong Jia Shi + * Xiao Feng Ren + * Pierre Morel + * + * This work is licensed under the terms of the GNU GPL, version 2 or(at + * your option) any version. See the COPYING file in the top-level + * directory. + */ + +#include +#include + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "hw/sysbus.h" +#include "hw/vfio/vfio.h" +#include "hw/vfio/vfio-common.h" +#include "hw/s390x/s390-ccw.h" +#include "hw/s390x/ccw-device.h" + +#define TYPE_VFIO_CCW "vfio-ccw" +typedef struct VFIOCCWDevice { + S390CCWDevice cdev; + VFIODevice vdev; +} VFIOCCWDevice; + +static void vfio_ccw_compute_needs_reset(VFIODevice *vdev) +{ + vdev->needs_reset =3D false; +} + +/* + * We don't need vfio_hot_reset_multi and vfio_eoi operationis for + * vfio_ccw device now. + */ +struct VFIODeviceOps vfio_ccw_ops =3D { + .vfio_compute_needs_reset =3D vfio_ccw_compute_needs_reset, +}; + +static void vfio_ccw_reset(DeviceState *dev) +{ + CcwDevice *ccw_dev =3D DO_UPCAST(CcwDevice, parent_obj, dev); + S390CCWDevice *cdev =3D DO_UPCAST(S390CCWDevice, parent_obj, ccw_dev); + VFIOCCWDevice *vcdev =3D DO_UPCAST(VFIOCCWDevice, cdev, cdev); + + ioctl(vcdev->vdev.fd, VFIO_DEVICE_RESET); +} + +static void vfio_put_device(VFIOCCWDevice *vcdev) +{ + g_free(vcdev->vdev.name); + vfio_put_base_device(&vcdev->vdev); +} + +static VFIOGroup *vfio_ccw_get_group(S390CCWDevice *cdev, char **path, + Error **errp) +{ + struct stat st; + int groupid; + GError *gerror =3D NULL; + + /* Check that host subchannel exists. */ + path[0] =3D g_strdup_printf("/sys/bus/css/devices/%x.%x.%04x", + cdev->hostid.cssid, + cdev->hostid.ssid, + cdev->hostid.devid); + if (stat(path[0], &st) < 0) { + error_setg(errp, "vfio: no such host subchannel %s", path[0]); + return NULL; + } + + /* Check that mediated device exists. */ + path[1] =3D g_strdup_printf("%s/%s", path[0], cdev->mdevid); + if (stat(path[0], &st) < 0) { + error_setg(errp, "vfio: no such mediated device %s", path[1]); + return NULL; + } + + /* Get the iommu_group patch as the interim variable. */ + path[2] =3D g_strconcat(path[1], "/iommu_group", NULL); + + /* Get the link file path of the device iommu_group. */ + path[3] =3D g_file_read_link(path[2], &gerror); + if (!path[3]) { + error_setg(errp, "vfio: error no iommu_group for subchannel"); + return NULL; + } + + /* Get the device groupid. */ + if (sscanf(basename(path[3]), "%d", &groupid) !=3D 1) { + error_setg(errp, "vfio: error reading %s:%m", path[3]); + return NULL; + } + + return vfio_get_group(groupid, &address_space_memory, errp); +} + +static void vfio_ccw_put_group(VFIOGroup *group, char **path) +{ + g_free(path); + vfio_put_group(group); +} + +static void vfio_ccw_realize(DeviceState *dev, Error **errp) +{ + VFIODevice *vbasedev; + VFIOGroup *group; + CcwDevice *ccw_dev =3D DO_UPCAST(CcwDevice, parent_obj, dev); + S390CCWDevice *cdev =3D DO_UPCAST(S390CCWDevice, parent_obj, ccw_dev); + VFIOCCWDevice *vcdev =3D DO_UPCAST(VFIOCCWDevice, cdev, cdev); + S390CCWDeviceClass *cdc =3D S390_CCW_DEVICE_GET_CLASS(cdev); + char *path[4] =3D {NULL, NULL, NULL, NULL}; + + /* Call the class init function for subchannel. */ + if (cdc->realize) { + cdc->realize(cdev, vcdev->vdev.sysfsdev, errp); + if (*errp) { + return; + } + } + + group =3D vfio_ccw_get_group(cdev, path, errp); + if (!group) { + goto out_group_err; + } + + vcdev->vdev.ops =3D &vfio_ccw_ops; + vcdev->vdev.type =3D VFIO_DEVICE_TYPE_CCW; + vcdev->vdev.name =3D g_strdup_printf("%x.%x.%04x", cdev->hostid.cssid, + cdev->hostid.ssid, cdev->hostid.dev= id); + QLIST_FOREACH(vbasedev, &group->device_list, next) { + if (strcmp(vbasedev->name, vcdev->vdev.name) =3D=3D 0) { + error_setg(errp, "vfio: subchannel %s has already been attache= d", + basename(path[0])); + goto out_device_err; + } + } + + if (vfio_get_device(group, cdev->mdevid, &vcdev->vdev, errp)) { + goto out_device_err; + } + + return; + +out_device_err: + vfio_ccw_put_group(group, path); +out_group_err: + if (cdc->unrealize) { + cdc->unrealize(cdev, errp); + } +} + +static void vfio_ccw_unrealize(DeviceState *dev, Error **errp) +{ + CcwDevice *ccw_dev =3D DO_UPCAST(CcwDevice, parent_obj, dev); + S390CCWDevice *cdev =3D DO_UPCAST(S390CCWDevice, parent_obj, ccw_dev); + VFIOCCWDevice *vcdev =3D DO_UPCAST(VFIOCCWDevice, cdev, cdev); + S390CCWDeviceClass *cdc =3D S390_CCW_DEVICE_GET_CLASS(cdev); + VFIOGroup *group =3D vcdev->vdev.group; + + if (cdc->unrealize) { + cdc->unrealize(cdev, errp); + } + + vfio_put_device(vcdev); + vfio_put_group(group); +} + +static Property vfio_ccw_properties[] =3D { + DEFINE_PROP_STRING("sysfsdev", VFIOCCWDevice, vdev.sysfsdev), + DEFINE_PROP_CSS_DEV_ID("devno", VFIOCCWDevice, cdev.parent_obj.bus_id), + DEFINE_PROP_END_OF_LIST(), +}; + +static const VMStateDescription vfio_ccw_vmstate =3D { + .name =3D TYPE_VFIO_CCW, + .unmigratable =3D 1, +}; + +static void vfio_ccw_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + + dc->props =3D vfio_ccw_properties; + dc->vmsd =3D &vfio_ccw_vmstate; + dc->desc =3D "VFIO-based subchannel assignment"; + dc->realize =3D vfio_ccw_realize; + dc->unrealize =3D vfio_ccw_unrealize; + dc->reset =3D vfio_ccw_reset; +} + +static const TypeInfo vfio_ccw_info =3D { + .name =3D TYPE_VFIO_CCW, + .parent =3D TYPE_S390_CCW, + .instance_size =3D sizeof(VFIOCCWDevice), + .class_init =3D vfio_ccw_class_init, +}; + +static void register_vfio_ccw_type(void) +{ + type_register_static(&vfio_ccw_info); +} + +type_init(register_vfio_ccw_type) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index c582de1..9521013 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -45,6 +45,7 @@ enum { VFIO_DEVICE_TYPE_PCI =3D 0, VFIO_DEVICE_TYPE_PLATFORM =3D 1, + VFIO_DEVICE_TYPE_CCW =3D 2, }; =20 typedef struct VFIOMmap { --=20 2.8.4 From nobody Sat May 4 07:15:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489721382013322.4092376081096; Thu, 16 Mar 2017 20:29:42 -0700 (PDT) Received: from localhost ([::1]:46928 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1coiaC-0007WC-Ov for importer@patchew.org; Thu, 16 Mar 2017 23:29:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57659) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1coiQx-00082q-VK for qemu-devel@nongnu.org; Thu, 16 Mar 2017 23:20:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1coiQt-0000rk-I3 for qemu-devel@nongnu.org; Thu, 16 Mar 2017 23:20:07 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:39215 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1coiQt-0000rc-CR for qemu-devel@nongnu.org; Thu, 16 Mar 2017 23:20:03 -0400 Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v2H3JDcS005969 for ; Thu, 16 Mar 2017 23:20:02 -0400 Received: from e37.co.us.ibm.com (e37.co.us.ibm.com [32.97.110.158]) by mx0b-001b2d01.pphosted.com with ESMTP id 297wd0h3eq-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 16 Mar 2017 23:20:02 -0400 Received: from localhost by e37.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 16 Mar 2017 21:20:00 -0600 Received: from b03cxnp08026.gho.boulder.ibm.com (9.17.130.18) by e37.co.us.ibm.com (192.168.1.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 16 Mar 2017 21:19:56 -0600 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp08026.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v2H3JtmF10092906; Thu, 16 Mar 2017 20:19:55 -0700 Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5759578038; Thu, 16 Mar 2017 21:19:55 -0600 (MDT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP id 7288478047; Thu, 16 Mar 2017 21:19:53 -0600 (MDT) From: Dong Jia Shi To: kvm@vger.kernel.org, linux-s390@vger.kernel.org, qemu-devel@nongnu.org Date: Fri, 17 Mar 2017 04:19:24 +0100 X-Mailer: git-send-email 2.8.4 In-Reply-To: <20170317031928.40189-1-bjsdjshi@linux.vnet.ibm.com> References: <20170317031928.40189-1-bjsdjshi@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17031703-0024-0000-0000-000016130AAE X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00006796; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000206; SDB=6.00834931; UDB=6.00410081; IPR=6.00612586; BA=6.00005215; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00014684; XFM=3.00000013; UTC=2017-03-17 03:19:58 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17031703-0025-0000-0000-00004985329A Message-Id: <20170317031928.40189-8-bjsdjshi@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-03-17_01:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=2 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1702020001 definitions=main-1703170026 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PATCH v4 07/11] vfio/ccw: get io region info 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: pasic@linux.vnet.ibm.com, pmorel@linux.vnet.ibm.com, borntraeger@de.ibm.com, alex.williamson@redhat.com, renxiaof@linux.vnet.ibm.com, cornelia.huck@de.ibm.com, bjsdjshi@linux.vnet.ibm.com, agraf@suse.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" vfio-ccw provides an MMIO region for I/O operations. We fetch its information via ioctls here, then we can use it performing I/O instructions and retrieving I/O results later on. Signed-off-by: Dong Jia Shi --- hw/vfio/ccw.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c index d5ff02f..1df2512 100644 --- a/hw/vfio/ccw.c +++ b/hw/vfio/ccw.c @@ -12,6 +12,7 @@ */ =20 #include +#include #include =20 #include "qemu/osdep.h" @@ -26,6 +27,9 @@ typedef struct VFIOCCWDevice { S390CCWDevice cdev; VFIODevice vdev; + uint64_t io_region_size; + uint64_t io_region_offset; + struct ccw_io_region *io_region; } VFIOCCWDevice; =20 static void vfio_ccw_compute_needs_reset(VFIODevice *vdev) @@ -50,6 +54,46 @@ static void vfio_ccw_reset(DeviceState *dev) ioctl(vcdev->vdev.fd, VFIO_DEVICE_RESET); } =20 +static void vfio_ccw_get_region(VFIOCCWDevice *vcdev, Error **errp) +{ + VFIODevice *vdev =3D &vcdev->vdev; + struct vfio_region_info *info; + int ret; + + /* Sanity check device */ + if (!(vdev->flags & VFIO_DEVICE_FLAGS_CCW)) { + error_setg(errp, "vfio: Um, this isn't a vfio-ccw device"); + return; + } + + if (vdev->num_regions < VFIO_CCW_CONFIG_REGION_INDEX + 1) { + error_setg(errp, "vfio: Unexpected number of the I/O region %u", + vdev->num_regions); + return; + } + + ret =3D vfio_get_region_info(vdev, VFIO_CCW_CONFIG_REGION_INDEX, &info= ); + if (ret) { + error_setg(errp, "vfio: Error getting config info: %d", ret); + return; + } + + vcdev->io_region_size =3D info->size; + if (sizeof(*vcdev->io_region) !=3D vcdev->io_region_size) { + error_setg(errp, "vfio: Unexpected size of the I/O region"); + return; + } + vcdev->io_region_offset =3D info->offset; + vcdev->io_region =3D g_malloc0(info->size); + + g_free(info); +} + +static void vfio_ccw_put_region(VFIOCCWDevice *vcdev) +{ + g_free(vcdev->io_region); +} + static void vfio_put_device(VFIOCCWDevice *vcdev) { g_free(vcdev->vdev.name); @@ -144,8 +188,15 @@ static void vfio_ccw_realize(DeviceState *dev, Error *= *errp) goto out_device_err; } =20 + vfio_ccw_get_region(vcdev, errp); + if (*errp) { + goto out_region_err; + } + return; =20 +out_region_err: + vfio_put_device(vcdev); out_device_err: vfio_ccw_put_group(group, path); out_group_err: @@ -166,6 +217,7 @@ static void vfio_ccw_unrealize(DeviceState *dev, Error = **errp) cdc->unrealize(cdev, errp); } =20 + vfio_ccw_put_region(vcdev); vfio_put_device(vcdev); vfio_put_group(group); } --=20 2.8.4 From nobody Sat May 4 07:15:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489721527833621.0876945245606; Thu, 16 Mar 2017 20:32:07 -0700 (PDT) Received: from localhost ([::1]:46942 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1coicY-0001HL-7Y for importer@patchew.org; Thu, 16 Mar 2017 23:32:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57720) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1coiR2-0008AT-Vc for qemu-devel@nongnu.org; Thu, 16 Mar 2017 23:20:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1coiQy-0000uy-0o for qemu-devel@nongnu.org; Thu, 16 Mar 2017 23:20:12 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:47989 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1coiQx-0000tn-RZ for qemu-devel@nongnu.org; Thu, 16 Mar 2017 23:20:07 -0400 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v2H3JCRA061900 for ; Thu, 16 Mar 2017 23:20:04 -0400 Received: from e33.co.us.ibm.com (e33.co.us.ibm.com [32.97.110.151]) by mx0b-001b2d01.pphosted.com with ESMTP id 297ym52gkk-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 16 Mar 2017 23:20:04 -0400 Received: from localhost by e33.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 16 Mar 2017 21:20:03 -0600 Received: from b03cxnp07029.gho.boulder.ibm.com (9.17.130.16) by e33.co.us.ibm.com (192.168.1.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 16 Mar 2017 21:20:00 -0600 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp07029.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v2H3Jwre15401264; Thu, 16 Mar 2017 20:19:58 -0700 Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7802F78041; Thu, 16 Mar 2017 21:19:58 -0600 (MDT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP id 92ABC78038; Thu, 16 Mar 2017 21:19:56 -0600 (MDT) From: Dong Jia Shi To: kvm@vger.kernel.org, linux-s390@vger.kernel.org, qemu-devel@nongnu.org Date: Fri, 17 Mar 2017 04:19:25 +0100 X-Mailer: git-send-email 2.8.4 In-Reply-To: <20170317031928.40189-1-bjsdjshi@linux.vnet.ibm.com> References: <20170317031928.40189-1-bjsdjshi@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17031703-0008-0000-0000-0000077209E7 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00006796; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000206; SDB=6.00834931; UDB=6.00410081; IPR=6.00612586; BA=6.00005215; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00014684; XFM=3.00000013; UTC=2017-03-17 03:20:01 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17031703-0009-0000-0000-000040BC3E58 Message-Id: <20170317031928.40189-9-bjsdjshi@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-03-17_01:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=2 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1702020001 definitions=main-1703170026 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PATCH v4 08/11] vfio/ccw: get irqs info and set the eventfd fd 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: pasic@linux.vnet.ibm.com, pmorel@linux.vnet.ibm.com, borntraeger@de.ibm.com, alex.williamson@redhat.com, renxiaof@linux.vnet.ibm.com, cornelia.huck@de.ibm.com, bjsdjshi@linux.vnet.ibm.com, agraf@suse.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" vfio-ccw resorts to the eventfd mechanism to communicate with userspace. We fetch the irqs info via the ioctl VFIO_DEVICE_GET_IRQ_INFO, register a event notifier to get the eventfd fd which is sent to kernel via the ioctl VFIO_DEVICE_SET_IRQS, then we can implement read operation once kernel sends the signal. Signed-off-by: Dong Jia Shi --- hw/vfio/ccw.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 102 insertions(+) diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c index 1df2512..bb41ede 100644 --- a/hw/vfio/ccw.c +++ b/hw/vfio/ccw.c @@ -22,6 +22,7 @@ #include "hw/vfio/vfio-common.h" #include "hw/s390x/s390-ccw.h" #include "hw/s390x/ccw-device.h" +#include "qemu/error-report.h" =20 #define TYPE_VFIO_CCW "vfio-ccw" typedef struct VFIOCCWDevice { @@ -30,6 +31,7 @@ typedef struct VFIOCCWDevice { uint64_t io_region_size; uint64_t io_region_offset; struct ccw_io_region *io_region; + EventNotifier io_notifier; } VFIOCCWDevice; =20 static void vfio_ccw_compute_needs_reset(VFIODevice *vdev) @@ -54,6 +56,98 @@ static void vfio_ccw_reset(DeviceState *dev) ioctl(vcdev->vdev.fd, VFIO_DEVICE_RESET); } =20 +static void vfio_ccw_io_notifier_handler(void *opaque) +{ + VFIOCCWDevice *vcdev =3D opaque; + + if (!event_notifier_test_and_clear(&vcdev->io_notifier)) { + return; + } +} + +static void vfio_ccw_register_io_notifier(VFIOCCWDevice *vcdev, Error **er= rp) +{ + VFIODevice *vdev =3D &vcdev->vdev; + struct vfio_irq_info *irq_info; + struct vfio_irq_set *irq_set; + size_t argsz; + int32_t *pfd; + + if (vdev->num_irqs < VFIO_CCW_IO_IRQ_INDEX + 1) { + error_setg(errp, "vfio: unexpected number of io irqs %u", + vdev->num_irqs); + return; + } + + argsz =3D sizeof(*irq_set); + irq_info =3D g_malloc0(argsz); + irq_info->index =3D VFIO_CCW_IO_IRQ_INDEX; + irq_info->argsz =3D argsz; + if (ioctl(vdev->fd, VFIO_DEVICE_GET_IRQ_INFO, + irq_info) < 0 || irq_info->count < 1) { + error_setg(errp, "vfio: Error getting irq info"); + goto get_error; + } + + if (event_notifier_init(&vcdev->io_notifier, 0)) { + error_setg(errp, "vfio: Unable to init event notifier for IO"); + goto get_error; + } + + argsz =3D sizeof(*irq_set) + sizeof(*pfd); + irq_set =3D g_malloc0(argsz); + irq_set->argsz =3D argsz; + irq_set->flags =3D VFIO_IRQ_SET_DATA_EVENTFD | + VFIO_IRQ_SET_ACTION_TRIGGER; + irq_set->index =3D VFIO_CCW_IO_IRQ_INDEX; + irq_set->start =3D 0; + irq_set->count =3D 1; + pfd =3D (int32_t *) &irq_set->data; + + *pfd =3D event_notifier_get_fd(&vcdev->io_notifier); + qemu_set_fd_handler(*pfd, vfio_ccw_io_notifier_handler, NULL, vcdev); + if (ioctl(vdev->fd, VFIO_DEVICE_SET_IRQS, irq_set)) { + error_setg(errp, "vfio: Failed to set up io notification"); + qemu_set_fd_handler(*pfd, NULL, NULL, vcdev); + event_notifier_cleanup(&vcdev->io_notifier); + goto set_error; + } + +set_error: + g_free(irq_set); + +get_error: + g_free(irq_info); +} + +static void vfio_ccw_unregister_io_notifier(VFIOCCWDevice *vcdev) +{ + struct vfio_irq_set *irq_set; + size_t argsz; + int32_t *pfd; + + argsz =3D sizeof(*irq_set) + sizeof(*pfd); + irq_set =3D g_malloc0(argsz); + irq_set->argsz =3D argsz; + irq_set->flags =3D VFIO_IRQ_SET_DATA_EVENTFD | + VFIO_IRQ_SET_ACTION_TRIGGER; + irq_set->index =3D VFIO_CCW_IO_IRQ_INDEX; + irq_set->start =3D 0; + irq_set->count =3D 1; + pfd =3D (int32_t *) &irq_set->data; + *pfd =3D -1; + + if (ioctl(vcdev->vdev.fd, VFIO_DEVICE_SET_IRQS, irq_set)) { + error_report("vfio: Failed to de-assign device io fd"); + } + + qemu_set_fd_handler(event_notifier_get_fd(&vcdev->io_notifier), + NULL, NULL, vcdev); + event_notifier_cleanup(&vcdev->io_notifier); + + g_free(irq_set); +} + static void vfio_ccw_get_region(VFIOCCWDevice *vcdev, Error **errp) { VFIODevice *vdev =3D &vcdev->vdev; @@ -193,8 +287,15 @@ static void vfio_ccw_realize(DeviceState *dev, Error *= *errp) goto out_region_err; } =20 + vfio_ccw_register_io_notifier(vcdev, errp); + if (*errp) { + goto out_notifier_err; + } + return; =20 +out_notifier_err: + vfio_ccw_put_region(vcdev); out_region_err: vfio_put_device(vcdev); out_device_err: @@ -217,6 +318,7 @@ static void vfio_ccw_unrealize(DeviceState *dev, Error = **errp) cdc->unrealize(cdev, errp); } =20 + vfio_ccw_unregister_io_notifier(vcdev); vfio_ccw_put_region(vcdev); vfio_put_device(vcdev); vfio_put_group(group); --=20 2.8.4 From nobody Sat May 4 07:15:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489721606949923.469438073009; Thu, 16 Mar 2017 20:33:26 -0700 (PDT) Received: from localhost ([::1]:46946 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1coidp-0002dp-Lr for importer@patchew.org; Thu, 16 Mar 2017 23:33:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57715) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1coiR2-00089w-8X for qemu-devel@nongnu.org; Thu, 16 Mar 2017 23:20:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1coiQx-0000ul-QO for qemu-devel@nongnu.org; Thu, 16 Mar 2017 23:20:12 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:51033) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1coiQx-0000tC-H8 for qemu-devel@nongnu.org; Thu, 16 Mar 2017 23:20:07 -0400 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v2H3Jl1D041087 for ; Thu, 16 Mar 2017 23:20:06 -0400 Received: from e38.co.us.ibm.com (e38.co.us.ibm.com [32.97.110.159]) by mx0a-001b2d01.pphosted.com with ESMTP id 2980w6q5tn-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 16 Mar 2017 23:20:06 -0400 Received: from localhost by e38.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 16 Mar 2017 21:20:05 -0600 Received: from b03cxnp08025.gho.boulder.ibm.com (9.17.130.17) by e38.co.us.ibm.com (192.168.1.138) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 16 Mar 2017 21:20:03 -0600 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp08025.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v2H3K1Wa11600358; Thu, 16 Mar 2017 20:20:01 -0700 Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8EA417803F; Thu, 16 Mar 2017 21:20:01 -0600 (MDT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP id B38B278041; Thu, 16 Mar 2017 21:19:59 -0600 (MDT) From: Dong Jia Shi To: kvm@vger.kernel.org, linux-s390@vger.kernel.org, qemu-devel@nongnu.org Date: Fri, 17 Mar 2017 04:19:26 +0100 X-Mailer: git-send-email 2.8.4 In-Reply-To: <20170317031928.40189-1-bjsdjshi@linux.vnet.ibm.com> References: <20170317031928.40189-1-bjsdjshi@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17031703-0028-0000-0000-0000073C0A63 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00006796; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000206; SDB=6.00834931; UDB=6.00410081; IPR=6.00612586; BA=6.00005215; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00014684; XFM=3.00000013; UTC=2017-03-17 03:20:04 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17031703-0029-0000-0000-0000345C3209 Message-Id: <20170317031928.40189-10-bjsdjshi@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-03-17_01:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1702020001 definitions=main-1703170026 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 v4 09/11] s390x/css: introduce and realize ccw-request callback 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: pasic@linux.vnet.ibm.com, pmorel@linux.vnet.ibm.com, borntraeger@de.ibm.com, alex.williamson@redhat.com, renxiaof@linux.vnet.ibm.com, cornelia.huck@de.ibm.com, bjsdjshi@linux.vnet.ibm.com, agraf@suse.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Xiao Feng Ren Introduce a new callback on subchannel to handle ccw-request. Realize the callback in vfio-ccw device. Besides, resort to the event notifier handler to handling the ccw-request results. 1. Pread the I/O results via MMIO region. 2. Update the scsw info to guest. 3. Inject an I/O interrupt to notify guest the I/O result. Signed-off-by: Xiao Feng Ren Signed-off-by: Dong Jia Shi --- hw/s390x/css.c | 4 +-- hw/s390x/s390-ccw.h | 1 + hw/vfio/ccw.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++= ++++ include/hw/s390x/css.h | 2 ++ 4 files changed, 78 insertions(+), 2 deletions(-) diff --git a/hw/s390x/css.c b/hw/s390x/css.c index 01e88e1..3be4ee8 100644 --- a/hw/s390x/css.c +++ b/hw/s390x/css.c @@ -238,7 +238,7 @@ uint16_t css_build_subchannel_id(SubchDev *sch) return css_do_build_subchannel_id(sch->cssid, sch->ssid); } =20 -static void css_inject_io_interrupt(SubchDev *sch) +void css_inject_io_interrupt(SubchDev *sch) { uint8_t isc =3D (sch->curr_status.pmcw.flags & PMCW_FLAGS_MASK_ISC) >>= 11; =20 @@ -647,7 +647,7 @@ static void copy_pmcw_to_guest(PMCW *dest, const PMCW *= src) dest->chars =3D cpu_to_be32(src->chars); } =20 -static void copy_scsw_to_guest(SCSW *dest, const SCSW *src) +void copy_scsw_to_guest(SCSW *dest, const SCSW *src) { dest->flags =3D cpu_to_be16(src->flags); dest->ctrl =3D cpu_to_be16(src->ctrl); diff --git a/hw/s390x/s390-ccw.h b/hw/s390x/s390-ccw.h index b58d8e9..4e2fa65 100644 --- a/hw/s390x/s390-ccw.h +++ b/hw/s390x/s390-ccw.h @@ -27,6 +27,7 @@ typedef struct S390CCWDevice { CcwDevice parent_obj; CssDevId hostid; char *mdevid; + int (*handle_request) (ORB *, SCSW *, void *); } S390CCWDevice; =20 typedef struct S390CCWDeviceClass { diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c index bb41ede..00ab285 100644 --- a/hw/vfio/ccw.c +++ b/hw/vfio/ccw.c @@ -47,6 +47,36 @@ struct VFIODeviceOps vfio_ccw_ops =3D { .vfio_compute_needs_reset =3D vfio_ccw_compute_needs_reset, }; =20 +static int vfio_ccw_handle_request(ORB *orb, SCSW *scsw, void *data) +{ + S390CCWDevice *cdev =3D data; + VFIOCCWDevice *vcdev =3D DO_UPCAST(VFIOCCWDevice, cdev, cdev); + struct ccw_io_region *region =3D vcdev->io_region; + int ret; + + QEMU_BUILD_BUG_ON(sizeof(region->orb_area) !=3D sizeof(ORB)); + QEMU_BUILD_BUG_ON(sizeof(region->scsw_area) !=3D sizeof(SCSW)); + QEMU_BUILD_BUG_ON(sizeof(region->irb_area) !=3D sizeof(IRB)); + + memset(region, 0, sizeof(*region)); + + memcpy(region->orb_area, orb, sizeof(ORB)); + memcpy(region->scsw_area, scsw, sizeof(SCSW)); + +again: + ret =3D pwrite(vcdev->vdev.fd, region, + vcdev->io_region_size, vcdev->io_region_offset); + if (ret !=3D vcdev->io_region_size) { + if (errno =3D=3D EAGAIN) { + goto again; + } + error_report("vfio-ccw: wirte I/O region failed with errno=3D%d", = errno); + return -errno; + } + + return region->ret_code; +} + static void vfio_ccw_reset(DeviceState *dev) { CcwDevice *ccw_dev =3D DO_UPCAST(CcwDevice, parent_obj, dev); @@ -59,10 +89,52 @@ static void vfio_ccw_reset(DeviceState *dev) static void vfio_ccw_io_notifier_handler(void *opaque) { VFIOCCWDevice *vcdev =3D opaque; + struct ccw_io_region *region =3D vcdev->io_region; + S390CCWDevice *cdev =3D S390_CCW_DEVICE(vcdev); + CcwDevice *ccw_dev =3D CCW_DEVICE(cdev); + SubchDev *sch =3D ccw_dev->sch; + SCSW *s =3D &sch->curr_status.scsw; + IRB irb; =20 if (!event_notifier_test_and_clear(&vcdev->io_notifier)) { return; } + + if (pread(vcdev->vdev.fd, region, + vcdev->io_region_size, vcdev->io_region_offset) =3D=3D -1) { + switch (errno) { + case ENODEV: + /* Generate a deferred cc 3 condition. */ + s->flags |=3D SCSW_FLAGS_MASK_CC; + s->ctrl &=3D ~SCSW_CTRL_MASK_STCTL; + s->ctrl |=3D (SCSW_STCTL_ALERT | SCSW_STCTL_STATUS_PEND); + goto read_err; + case EFAULT: + /* memory problem, generate channel data check */ + s->ctrl &=3D ~SCSW_ACTL_START_PEND; + s->cstat =3D SCSW_CSTAT_DATA_CHECK; + s->ctrl &=3D ~SCSW_CTRL_MASK_STCTL; + s->ctrl |=3D SCSW_STCTL_PRIMARY | SCSW_STCTL_SECONDARY | + SCSW_STCTL_ALERT | SCSW_STCTL_STATUS_PEND; + goto read_err; + default: + /* error, generate channel program check */ + s->ctrl &=3D ~SCSW_ACTL_START_PEND; + s->cstat =3D SCSW_CSTAT_PROG_CHECK; + s->ctrl &=3D ~SCSW_CTRL_MASK_STCTL; + s->ctrl |=3D SCSW_STCTL_PRIMARY | SCSW_STCTL_SECONDARY | + SCSW_STCTL_ALERT | SCSW_STCTL_STATUS_PEND; + goto read_err; + } + } + + memcpy(&irb, region->irb_area, sizeof(IRB)); + + /* Update control block via irb. */ + copy_scsw_to_guest(s, &irb.scsw); + +read_err: + css_inject_io_interrupt(sch); } =20 static void vfio_ccw_register_io_notifier(VFIOCCWDevice *vcdev, Error **er= rp) @@ -253,6 +325,7 @@ static void vfio_ccw_realize(DeviceState *dev, Error **= errp) S390CCWDeviceClass *cdc =3D S390_CCW_DEVICE_GET_CLASS(cdev); char *path[4] =3D {NULL, NULL, NULL, NULL}; =20 + cdev->handle_request =3D vfio_ccw_handle_request; /* Call the class init function for subchannel. */ if (cdc->realize) { cdc->realize(cdev, vcdev->vdev.sysfsdev, errp); diff --git a/include/hw/s390x/css.h b/include/hw/s390x/css.h index 2170d11..46cdf8c 100644 --- a/include/hw/s390x/css.h +++ b/include/hw/s390x/css.h @@ -133,6 +133,8 @@ void css_subch_assign(uint8_t cssid, uint8_t ssid, uint= 16_t schid, void css_sch_build_virtual_schib(SubchDev *sch, uint8_t chpid, uint8_t typ= e); int css_sch_build_schib(SubchDev *sch, CssDevId *dev_id); uint16_t css_build_subchannel_id(SubchDev *sch); +void copy_scsw_to_guest(SCSW *dest, const SCSW *src); +void css_inject_io_interrupt(SubchDev *sch); void css_reset(void); void css_reset_sch(SubchDev *sch); void css_queue_crw(uint8_t rsc, uint8_t erc, int chain, uint16_t rsid); --=20 2.8.4 From nobody Sat May 4 07:15:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489721751541628.1516405100544; Thu, 16 Mar 2017 20:35:51 -0700 (PDT) Received: from localhost ([::1]:46957 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1coig9-0004m0-7E for importer@patchew.org; Thu, 16 Mar 2017 23:35:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57788) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1coiR9-0008HP-GH for qemu-devel@nongnu.org; Thu, 16 Mar 2017 23:20:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1coiR5-0000z7-1w for qemu-devel@nongnu.org; Thu, 16 Mar 2017 23:20:19 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:56836) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1coiR4-0000yt-Mr for qemu-devel@nongnu.org; Thu, 16 Mar 2017 23:20:14 -0400 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v2H3JBNc054070 for ; Thu, 16 Mar 2017 23:20:13 -0400 Received: from e35.co.us.ibm.com (e35.co.us.ibm.com [32.97.110.153]) by mx0a-001b2d01.pphosted.com with ESMTP id 297vy32sh9-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 16 Mar 2017 23:20:13 -0400 Received: from localhost by e35.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 16 Mar 2017 21:20:09 -0600 Received: from b03cxnp07029.gho.boulder.ibm.com (9.17.130.16) by e35.co.us.ibm.com (192.168.1.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 16 Mar 2017 21:20:06 -0600 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp07029.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v2H3K4aB13304210; Thu, 16 Mar 2017 20:20:04 -0700 Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B023278056; Thu, 16 Mar 2017 21:20:04 -0600 (MDT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP id D3E4278047; Thu, 16 Mar 2017 21:20:02 -0600 (MDT) From: Dong Jia Shi To: kvm@vger.kernel.org, linux-s390@vger.kernel.org, qemu-devel@nongnu.org Date: Fri, 17 Mar 2017 04:19:27 +0100 X-Mailer: git-send-email 2.8.4 In-Reply-To: <20170317031928.40189-1-bjsdjshi@linux.vnet.ibm.com> References: <20170317031928.40189-1-bjsdjshi@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17031703-0012-0000-0000-000013E30A4C X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00006796; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000206; SDB=6.00834931; UDB=6.00410081; IPR=6.00612586; BA=6.00005215; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00014684; XFM=3.00000013; UTC=2017-03-17 03:20:08 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17031703-0013-0000-0000-00004C413307 Message-Id: <20170317031928.40189-11-bjsdjshi@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-03-17_01:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1702020001 definitions=main-1703170026 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 v4 10/11] s390x/css: ccw translation infrastructure 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: pasic@linux.vnet.ibm.com, pmorel@linux.vnet.ibm.com, borntraeger@de.ibm.com, alex.williamson@redhat.com, renxiaof@linux.vnet.ibm.com, cornelia.huck@de.ibm.com, bjsdjshi@linux.vnet.ibm.com, agraf@suse.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Xiao Feng Ren Implement a basic infrastructure of handling channel I/O instruction interception for passed through subchannels: 1. Branch the code path of instruction interception handling by SubChannel type. 2. For a passed-through subchannel, issue the ORB to kernel to do ccw translation and perform an I/O operation. 3. Assign different condition code based on the I/O result, or trigger a program check. Signed-off-by: Xiao Feng Ren Signed-off-by: Dong Jia Shi --- hw/s390x/css.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++= ---- hw/s390x/s390-ccw.c | 12 +++++++ hw/s390x/virtio-ccw.c | 1 + include/hw/s390x/css.h | 4 +++ target/s390x/ioinst.c | 9 ++++++ 5 files changed, 108 insertions(+), 6 deletions(-) diff --git a/hw/s390x/css.c b/hw/s390x/css.c index 3be4ee8..8598c82 100644 --- a/hw/s390x/css.c +++ b/hw/s390x/css.c @@ -503,7 +503,7 @@ static int css_interpret_ccw(SubchDev *sch, hwaddr ccw_= addr, return ret; } =20 -static void sch_handle_start_func(SubchDev *sch, ORB *orb) +static void sch_handle_start_func_virtual(SubchDev *sch, ORB *orb) { =20 PMCW *p =3D &sch->curr_status.pmcw; @@ -602,13 +602,57 @@ static void sch_handle_start_func(SubchDev *sch, ORB = *orb) =20 } =20 +static int sch_handle_start_func_passthrough(SubchDev *sch, ORB *orb) +{ + + PMCW *p =3D &sch->curr_status.pmcw; + SCSW *s =3D &sch->curr_status.scsw; + int ret; + + if (!(s->ctrl & SCSW_ACTL_SUSP)) { + assert(orb !=3D NULL); + p->intparm =3D orb->intparm; + } + + /* + * Only support prefetch enable mode. + * Only support 64bit addressing idal. + */ + if (!(orb->ctrl0 & ORB_CTRL0_MASK_PFCH) || + !(orb->ctrl0 & ORB_CTRL0_MASK_C64)) { + return -EINVAL; + } + + ret =3D s390_ccw_cmd_request(orb, s, sch->driver_data); + switch (ret) { + /* Currently we don't update control block and just return the cc code= . */ + case 0: + break; + case -EBUSY: + break; + case -ENODEV: + break; + case -EACCES: + /* Let's reflect an inaccessible host device by cc 3. */ + ret =3D -ENODEV; + break; + default: + /* All other return codes will trigger a program check, + * or set cc to 1. + */ + break; + }; + + return ret; +} + /* * On real machines, this would run asynchronously to the main vcpus. * We might want to make some parts of the ssch handling (interpreting * read/writes) asynchronous later on if we start supporting more than * our current very simple devices. */ -static void do_subchannel_work(SubchDev *sch, ORB *orb) +int do_subchannel_work_virtual(SubchDev *sch, ORB *orb) { =20 SCSW *s =3D &sch->curr_status.scsw; @@ -619,12 +663,45 @@ static void do_subchannel_work(SubchDev *sch, ORB *or= b) sch_handle_halt_func(sch); } else if (s->ctrl & SCSW_FCTL_START_FUNC) { /* Triggered by both ssch and rsch. */ - sch_handle_start_func(sch, orb); + sch_handle_start_func_virtual(sch, orb); } else { /* Cannot happen. */ - return; + return 0; } css_inject_io_interrupt(sch); + return 0; +} + +int do_subchannel_work_passthrough(SubchDev *sch, ORB *orb) +{ + int ret; + SCSW *s =3D &sch->curr_status.scsw; + + if (s->ctrl & SCSW_FCTL_CLEAR_FUNC) { + /* TODO: Clear handling */ + sch_handle_clear_func(sch); + ret =3D 0; + } else if (s->ctrl & SCSW_FCTL_HALT_FUNC) { + /* TODO: Halt handling */ + sch_handle_halt_func(sch); + ret =3D 0; + } else if (s->ctrl & SCSW_FCTL_START_FUNC) { + ret =3D sch_handle_start_func_passthrough(sch, orb); + } else { + /* Cannot happen. */ + return -ENODEV; + } + + return ret; +} + +static int do_subchannel_work(SubchDev *sch, ORB *orb) +{ + if (sch->do_subchannel_work) { + return sch->do_subchannel_work(sch, orb); + } else { + return -EINVAL; + } } =20 static void copy_pmcw_to_guest(PMCW *dest, const PMCW *src) @@ -943,8 +1020,7 @@ int css_do_ssch(SubchDev *sch, ORB *orb) s->ctrl |=3D (SCSW_FCTL_START_FUNC | SCSW_ACTL_START_PEND); s->flags &=3D ~SCSW_FLAGS_MASK_PNO; =20 - do_subchannel_work(sch, orb); - ret =3D 0; + ret =3D do_subchannel_work(sch, orb); =20 out: return ret; diff --git a/hw/s390x/s390-ccw.c b/hw/s390x/s390-ccw.c index 9b6de68..d91a8b2 100644 --- a/hw/s390x/s390-ccw.c +++ b/hw/s390x/s390-ccw.c @@ -18,6 +18,17 @@ #include "hw/s390x/css-bridge.h" #include "s390-ccw.h" =20 +int s390_ccw_cmd_request(ORB *orb, SCSW *scsw, void *data) +{ + S390CCWDevice *cdev =3D data; + + if (cdev->handle_request) { + return cdev->handle_request(orb, scsw, data); + } else { + return -ENOSYS; + } +} + static void s390_ccw_get_dev_info(S390CCWDevice *cdev, char *sysfsdev, Error **errp) @@ -67,6 +78,7 @@ static void s390_ccw_realize(S390CCWDevice *cdev, char *s= ysfsdev, Error **errp) } =20 sch->driver_data =3D cdev; + sch->do_subchannel_work =3D do_subchannel_work_passthrough; =20 ret =3D css_sch_build_schib(sch, &cdev->hostid); if (ret) { diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c index c6ba8d1..3338a04 100644 --- a/hw/s390x/virtio-ccw.c +++ b/hw/s390x/virtio-ccw.c @@ -702,6 +702,7 @@ static void virtio_ccw_device_realize(VirtioCcwDevice *= dev, Error **errp) sch->disable_cb =3D virtio_sch_disable_cb; sch->id.reserved =3D 0xff; sch->id.cu_type =3D VIRTIO_CCW_CU_TYPE; + sch->do_subchannel_work =3D do_subchannel_work_virtual; ccw_dev->sch =3D sch; dev->indicators =3D NULL; dev->revision =3D -1; diff --git a/include/hw/s390x/css.h b/include/hw/s390x/css.h index 46cdf8c..83dc711 100644 --- a/include/hw/s390x/css.h +++ b/include/hw/s390x/css.h @@ -88,6 +88,7 @@ struct SubchDev { /* transport-provided data: */ int (*ccw_cb) (SubchDev *, CCW1); void (*disable_cb)(SubchDev *); + int (*do_subchannel_work) (SubchDev *, ORB *); SenseId id; void *driver_data; }; @@ -144,6 +145,9 @@ void css_generate_chp_crws(uint8_t cssid, uint8_t chpid= ); void css_generate_css_crws(uint8_t cssid); void css_clear_sei_pending(void); void css_adapter_interrupt(uint8_t isc); +int s390_ccw_cmd_request(ORB *orb, SCSW *scsw, void *data); +int do_subchannel_work_virtual(SubchDev *sub, ORB *orb); +int do_subchannel_work_passthrough(SubchDev *sub, ORB *orb); =20 #define CSS_IO_ADAPTER_VIRTIO 1 int css_register_io_adapter(uint8_t type, uint8_t isc, bool swap, diff --git a/target/s390x/ioinst.c b/target/s390x/ioinst.c index 590bfa4..62a7771 100644 --- a/target/s390x/ioinst.c +++ b/target/s390x/ioinst.c @@ -244,6 +244,15 @@ void ioinst_handle_ssch(S390CPU *cpu, uint64_t reg1, u= int32_t ipb) case -EBUSY: cc =3D 2; break; + case -EFAULT: + /* + * TODO: + * I'm wondering whether there is something better + * to do for us here (like setting some device or + * subchannel status). + */ + program_interrupt(env, PGM_ADDRESSING, 4); + return; case 0: cc =3D 0; break; --=20 2.8.4 From nobody Sat May 4 07:15:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489721754763120.67572615094036; Thu, 16 Mar 2017 20:35:54 -0700 (PDT) Received: from localhost ([::1]:46960 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1coigD-0004ov-ID for importer@patchew.org; Thu, 16 Mar 2017 23:35:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57790) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1coiR9-0008Hn-Vs for qemu-devel@nongnu.org; Thu, 16 Mar 2017 23:20:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1coiR5-0000zO-JH for qemu-devel@nongnu.org; Thu, 16 Mar 2017 23:20:20 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:51191) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1coiR5-0000z0-AI for qemu-devel@nongnu.org; Thu, 16 Mar 2017 23:20:15 -0400 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v2H3Jlkj041014 for ; Thu, 16 Mar 2017 23:20:14 -0400 Received: from e32.co.us.ibm.com (e32.co.us.ibm.com [32.97.110.150]) by mx0a-001b2d01.pphosted.com with ESMTP id 2980w6q5wt-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 16 Mar 2017 23:20:14 -0400 Received: from localhost by e32.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 16 Mar 2017 21:20:12 -0600 Received: from b03cxnp08026.gho.boulder.ibm.com (9.17.130.18) by e32.co.us.ibm.com (192.168.1.132) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 16 Mar 2017 21:20:09 -0600 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp08026.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v2H3K7Vs11338082; Thu, 16 Mar 2017 20:20:08 -0700 Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D95FF78043; Thu, 16 Mar 2017 21:20:07 -0600 (MDT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP id 00C8D78041; Thu, 16 Mar 2017 21:20:05 -0600 (MDT) From: Dong Jia Shi To: kvm@vger.kernel.org, linux-s390@vger.kernel.org, qemu-devel@nongnu.org Date: Fri, 17 Mar 2017 04:19:28 +0100 X-Mailer: git-send-email 2.8.4 In-Reply-To: <20170317031928.40189-1-bjsdjshi@linux.vnet.ibm.com> References: <20170317031928.40189-1-bjsdjshi@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17031703-0004-0000-0000-000011CB0AAE X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00006796; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000206; SDB=6.00834931; UDB=6.00410082; IPR=6.00612586; BA=6.00005215; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00014684; XFM=3.00000013; UTC=2017-03-17 03:20:11 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17031703-0005-0000-0000-00007DE13979 Message-Id: <20170317031928.40189-12-bjsdjshi@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-03-17_01:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1702020001 definitions=main-1703170026 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 v4 11/11] vfio/ccw: update sense data if a unit check is pending 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: pasic@linux.vnet.ibm.com, pmorel@linux.vnet.ibm.com, borntraeger@de.ibm.com, alex.williamson@redhat.com, renxiaof@linux.vnet.ibm.com, cornelia.huck@de.ibm.com, bjsdjshi@linux.vnet.ibm.com, agraf@suse.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Concurrent-sense data is currently not delivered. This patch stores the concurrent-sense data to the subchannel if a unit check is pending and the concurrent-sense bit is enabled. Then a TSCH can retreive the right IRB data back to the guest. Signed-off-by: Dong Jia Shi --- hw/vfio/ccw.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c index 00ab285..b9e365a 100644 --- a/hw/vfio/ccw.c +++ b/hw/vfio/ccw.c @@ -94,6 +94,7 @@ static void vfio_ccw_io_notifier_handler(void *opaque) CcwDevice *ccw_dev =3D CCW_DEVICE(cdev); SubchDev *sch =3D ccw_dev->sch; SCSW *s =3D &sch->curr_status.scsw; + PMCW *p =3D &sch->curr_status.pmcw; IRB irb; =20 if (!event_notifier_test_and_clear(&vcdev->io_notifier)) { @@ -133,6 +134,12 @@ static void vfio_ccw_io_notifier_handler(void *opaque) /* Update control block via irb. */ copy_scsw_to_guest(s, &irb.scsw); =20 + /* If a uint check is pending, copy sense data. */ + if ((s->dstat & SCSW_DSTAT_UNIT_CHECK) && + (p->chars & PMCW_CHARS_MASK_CSENSE)) { + memcpy(sch->sense_data, irb.ecw, sizeof(irb.ecw)); + } + read_err: css_inject_io_interrupt(sch); } --=20 2.8.4