From nobody Mon May 6 05:29:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linux.ibm.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1547038595448594.9364011630853; Wed, 9 Jan 2019 04:56:35 -0800 (PST) Received: from localhost ([127.0.0.1]:58108 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ghDPO-0004XG-By for importer@patchew.org; Wed, 09 Jan 2019 07:56:34 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41822) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ghDKn-0000Y2-7H for qemu-devel@nongnu.org; Wed, 09 Jan 2019 07:51:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ghDAs-0004C6-4Y for qemu-devel@nongnu.org; Wed, 09 Jan 2019 07:41:36 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:42096 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 1ghDAq-0004B0-ED for qemu-devel@nongnu.org; Wed, 09 Jan 2019 07:41:32 -0500 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id x09CXoPG026555 for ; Wed, 9 Jan 2019 07:41:30 -0500 Received: from e06smtp04.uk.ibm.com (e06smtp04.uk.ibm.com [195.75.94.100]) by mx0a-001b2d01.pphosted.com with ESMTP id 2pwe91rdaf-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 09 Jan 2019 07:41:30 -0500 Received: from localhost by e06smtp04.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 9 Jan 2019 12:41:28 -0000 Received: from b06cxnps3075.portsmouth.uk.ibm.com (9.149.109.195) by e06smtp04.uk.ibm.com (192.168.101.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 9 Jan 2019 12:41:24 -0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x09CfMsL59637900 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 9 Jan 2019 12:41:23 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D00FD4C052; Wed, 9 Jan 2019 12:41:22 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 86CA54C050; Wed, 9 Jan 2019 12:41:22 +0000 (GMT) Received: from morel-ThinkPad-W530.boeblingen.de.ibm.com (unknown [9.152.224.140]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 9 Jan 2019 12:41:22 +0000 (GMT) From: Pierre Morel To: walling@linux.ibm.com Date: Wed, 9 Jan 2019 13:41:18 +0100 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1547037680-21458-1-git-send-email-pmorel@linux.ibm.com> References: <1547037680-21458-1-git-send-email-pmorel@linux.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 19010912-0016-0000-0000-000002428065 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19010912-0017-0000-0000-0000329C999B Message-Id: <1547037680-21458-2-git-send-email-pmorel@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-01-09_07:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1901090106 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 v1 1/3] vfio: Linux header placeholder 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: thuth@redhat.com, david@redhat.com, cohuck@redhat.com, qemu-devel@nongnu.org, pasic@linux.ibm.com, borntraeger@de.ibm.com, qemu-s390x@nongnu.org, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This is a place holder for VFIO.h as changed by the Linux patch associated with this QEMU series. Signed-off-by: Pierre Morel --- linux-headers/linux/vfio.h | 65 ++++++++++++++++++++++++++++++++++++++++++= +--- 1 file changed, 62 insertions(+), 3 deletions(-) diff --git a/linux-headers/linux/vfio.h b/linux-headers/linux/vfio.h index ceb6453..54c4fcb 100644 --- a/linux-headers/linux/vfio.h +++ b/linux-headers/linux/vfio.h @@ -9,8 +9,8 @@ * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. */ -#ifndef VFIO_H -#define VFIO_H +#ifndef _UAPIVFIO_H +#define _UAPIVFIO_H =20 #include #include @@ -303,6 +303,56 @@ struct vfio_region_info_cap_type { #define VFIO_REGION_SUBTYPE_INTEL_IGD_HOST_CFG (2) #define VFIO_REGION_SUBTYPE_INTEL_IGD_LPC_CFG (3) =20 +#define VFIO_REGION_TYPE_GFX (1) +#define VFIO_REGION_SUBTYPE_GFX_EDID (1) + +/** + * struct vfio_region_gfx_edid - EDID region layout. + * + * Set display link state and EDID blob. + * + * The EDID blob has monitor information such as brand, name, serial + * number, physical size, supported video modes and more. + * + * This special region allows userspace (typically qemu) set a virtual + * EDID for the virtual monitor, which allows a flexible display + * configuration. + * + * For the edid blob spec look here: + * https://en.wikipedia.org/wiki/Extended_Display_Identification_Data + * + * On linux systems you can find the EDID blob in sysfs: + * /sys/class/drm/${card}/${connector}/edid + * + * You can use the edid-decode ulility (comes with xorg-x11-utils) to + * decode the EDID blob. + * + * @edid_offset: location of the edid blob, relative to the + * start of the region (readonly). + * @edid_max_size: max size of the edid blob (readonly). + * @edid_size: actual edid size (read/write). + * @link_state: display link state (read/write). + * VFIO_DEVICE_GFX_LINK_STATE_UP: Monitor is turned on. + * VFIO_DEVICE_GFX_LINK_STATE_DOWN: Monitor is turned off. + * @max_xres: max display width (0 =3D=3D no limitation, readonly). + * @max_yres: max display height (0 =3D=3D no limitation, readonly). + * + * EDID update protocol: + * (1) set link-state to down. + * (2) update edid blob and size. + * (3) set link-state to up. + */ +struct vfio_region_gfx_edid { + __u32 edid_offset; + __u32 edid_max_size; + __u32 edid_size; + __u32 max_xres; + __u32 max_yres; + __u32 link_state; +#define VFIO_DEVICE_GFX_LINK_STATE_UP 1 +#define VFIO_DEVICE_GFX_LINK_STATE_DOWN 2 +}; + /* * The MSIX mappable capability informs that MSIX data of a BAR can be mma= pped * which allows direct access to non-MSIX registers which happened to be w= ithin @@ -619,6 +669,15 @@ struct vfio_iommu_type1_info { __u32 flags; #define VFIO_IOMMU_INFO_PGSIZES (1 << 0) /* supported page sizes info */ __u64 iova_pgsizes; /* Bitmap of supported page sizes */ +#define VFIO_IOMMU_INFO_CAPABILITIES (1 << 1) /* support capabilities inf= o */ + __u64 cap_offset; /* Offset within info struct of first cap */ +}; + +#define VFIO_IOMMU_INFO_CAP_DMA 1 +struct vfio_iommu_cap_dma { + struct vfio_info_cap_header header; + __u64 dma_start; + __u64 dma_end; }; =20 #define VFIO_IOMMU_GET_INFO _IO(VFIO_TYPE, VFIO_BASE + 12) @@ -818,4 +877,4 @@ struct vfio_iommu_spapr_tce_remove { =20 /* ***************************************************************** */ =20 -#endif /* VFIO_H */ +#endif /* _UAPIVFIO_H */ --=20 2.7.4 From nobody Mon May 6 05:29:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linux.ibm.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 154703870706234.36056181371339; Wed, 9 Jan 2019 04:58:27 -0800 (PST) Received: from localhost ([127.0.0.1]:58657 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ghDR4-000604-72 for importer@patchew.org; Wed, 09 Jan 2019 07:58:18 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41822) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ghDKm-0000Y2-6C for qemu-devel@nongnu.org; Wed, 09 Jan 2019 07:51:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ghDAs-0004Cf-6j for qemu-devel@nongnu.org; Wed, 09 Jan 2019 07:41:36 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:41952) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ghDAq-0004B7-E4 for qemu-devel@nongnu.org; Wed, 09 Jan 2019 07:41:34 -0500 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id x09CXowL045772 for ; Wed, 9 Jan 2019 07:41:30 -0500 Received: from e06smtp04.uk.ibm.com (e06smtp04.uk.ibm.com [195.75.94.100]) by mx0a-001b2d01.pphosted.com with ESMTP id 2pwepfq73v-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 09 Jan 2019 07:41:30 -0500 Received: from localhost by e06smtp04.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 9 Jan 2019 12:41:28 -0000 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp04.uk.ibm.com (192.168.101.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 9 Jan 2019 12:41:25 -0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x09CfO1n52363304 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 9 Jan 2019 12:41:24 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2FE344C058; Wed, 9 Jan 2019 12:41:24 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DC2054C040; Wed, 9 Jan 2019 12:41:23 +0000 (GMT) Received: from morel-ThinkPad-W530.boeblingen.de.ibm.com (unknown [9.152.224.140]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 9 Jan 2019 12:41:23 +0000 (GMT) From: Pierre Morel To: walling@linux.ibm.com Date: Wed, 9 Jan 2019 13:41:19 +0100 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1547037680-21458-1-git-send-email-pmorel@linux.ibm.com> References: <1547037680-21458-1-git-send-email-pmorel@linux.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 19010912-0016-0000-0000-000002428067 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19010912-0017-0000-0000-0000329C999D Message-Id: <1547037680-21458-3-git-send-email-pmorel@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-01-09_07:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=907 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1901090106 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PATCH v1 2/3] vfio/pci: Get real IOMMU information from container 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: thuth@redhat.com, david@redhat.com, cohuck@redhat.com, qemu-devel@nongnu.org, pasic@linux.ibm.com, borntraeger@de.ibm.com, qemu-s390x@nongnu.org, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" When the vfio_iommu_type1 supports the VFIO_IOMMU_INFO_CAPABILITIES and the capability ID VFIO_IOMMU_INFO_CAP_DMA we can use an ioctl to retrieve this information from the real IOMMU device. Let's use this information to add the host window associated with the container. Signed-off-by: Pierre Morel --- hw/vfio/common.c | 73 +++++++++++++++++++++++++++++++++++++++++++---------= ---- 1 file changed, 56 insertions(+), 17 deletions(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 7c185e5a..fd7e991 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -1036,6 +1036,61 @@ static void vfio_put_address_space(VFIOAddressSpace = *space) } } =20 +static void vfio_iommu_type1_get_info(int fd, VFIOContainer *container) +{ + struct vfio_iommu_type1_info *info; + size_t argsz =3D sizeof(*info); + struct vfio_info_cap_header *hdr; + struct vfio_iommu_cap_dma *dma_info; + int ret =3D 0; + + info =3D g_malloc0(argsz); + +retry: + info->argsz =3D argsz; + info->flags =3D VFIO_IOMMU_INFO_CAPABILITIES; + + ret =3D ioctl(fd, VFIO_IOMMU_GET_INFO, info); + /* Ignore errors */ + if (ret) { + goto out; + } + if (!(info->flags & VFIO_IOMMU_INFO_PGSIZES)) { + info->iova_pgsizes =3D 4096; + } + + if (info->argsz > argsz) { + argsz =3D info->argsz; + info =3D g_realloc(info, argsz); + + goto retry; + } + if (info->argsz !=3D argsz) { + goto out; + } + /* Now we have the capabilities */ + hdr =3D (struct vfio_info_cap_header *)((unsigned char *)info + + sizeof(struct vfio_iommu_type1_i= nfo) + + info->cap_offset); + do { + dma_info =3D (struct vfio_iommu_cap_dma *) (hdr); + if (hdr->id =3D=3D VFIO_IOMMU_INFO_CAP_DMA) { + vfio_host_win_add(container, 0, + dma_info->dma_end - dma_info->dma_start, + info->iova_pgsizes); + container->pgsizes =3D info->iova_pgsizes; + return; + } + hdr =3D (struct vfio_info_cap_header *)((unsigned char *) dma_info= + + hdr->next); + } while (hdr->next); +out: + /* Assume 4k IOVA page size */ + vfio_host_win_add(container, 0, (hwaddr)-1, 4096); + container->pgsizes =3D 4096; + return; +} + static int vfio_connect_container(VFIOGroup *group, AddressSpace *as, Error **errp) { @@ -1104,7 +1159,6 @@ static int vfio_connect_container(VFIOGroup *group, A= ddressSpace *as, if (ioctl(fd, VFIO_CHECK_EXTENSION, VFIO_TYPE1_IOMMU) || ioctl(fd, VFIO_CHECK_EXTENSION, VFIO_TYPE1v2_IOMMU)) { bool v2 =3D !!ioctl(fd, VFIO_CHECK_EXTENSION, VFIO_TYPE1v2_IOMMU); - struct vfio_iommu_type1_info info; =20 ret =3D ioctl(group->fd, VFIO_GROUP_SET_CONTAINER, &fd); if (ret) { @@ -1121,22 +1175,7 @@ static int vfio_connect_container(VFIOGroup *group, = AddressSpace *as, goto free_container_exit; } =20 - /* - * FIXME: This assumes that a Type1 IOMMU can map any 64-bit - * IOVA whatsoever. That's not actually true, but the current - * kernel interface doesn't tell us what it can map, and the - * existing Type1 IOMMUs generally support any IOVA we're - * going to actually try in practice. - */ - info.argsz =3D sizeof(info); - ret =3D ioctl(fd, VFIO_IOMMU_GET_INFO, &info); - /* Ignore errors */ - if (ret || !(info.flags & VFIO_IOMMU_INFO_PGSIZES)) { - /* Assume 4k IOVA page size */ - info.iova_pgsizes =3D 4096; - } - vfio_host_win_add(container, 0, (hwaddr)-1, info.iova_pgsizes); - container->pgsizes =3D info.iova_pgsizes; + vfio_iommu_type1_get_info(fd, container); } else if (ioctl(fd, VFIO_CHECK_EXTENSION, VFIO_SPAPR_TCE_IOMMU) || ioctl(fd, VFIO_CHECK_EXTENSION, VFIO_SPAPR_TCE_v2_IOMMU)) { struct vfio_iommu_spapr_tce_info info; --=20 2.7.4 From nobody Mon May 6 05:29:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linux.ibm.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1547038574529355.6758108571727; Wed, 9 Jan 2019 04:56:14 -0800 (PST) Received: from localhost ([127.0.0.1]:58031 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ghDP3-0004J0-Em for importer@patchew.org; Wed, 09 Jan 2019 07:56:13 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42034) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ghDKl-0000tI-OH for qemu-devel@nongnu.org; Wed, 09 Jan 2019 07:51:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ghDAs-0004CE-5c for qemu-devel@nongnu.org; Wed, 09 Jan 2019 07:41:36 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:52858 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 1ghDAq-0004BI-F2 for qemu-devel@nongnu.org; Wed, 09 Jan 2019 07:41:33 -0500 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id x09CYHFq121897 for ; Wed, 9 Jan 2019 07:41:31 -0500 Received: from e06smtp07.uk.ibm.com (e06smtp07.uk.ibm.com [195.75.94.103]) by mx0b-001b2d01.pphosted.com with ESMTP id 2pwejsy26k-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 09 Jan 2019 07:41:31 -0500 Received: from localhost by e06smtp07.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 9 Jan 2019 12:41:29 -0000 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp07.uk.ibm.com (192.168.101.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 9 Jan 2019 12:41:27 -0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x09CfPdv197040 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 9 Jan 2019 12:41:25 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7BC194C05A; Wed, 9 Jan 2019 12:41:25 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3CDC14C04A; Wed, 9 Jan 2019 12:41:25 +0000 (GMT) Received: from morel-ThinkPad-W530.boeblingen.de.ibm.com (unknown [9.152.224.140]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 9 Jan 2019 12:41:25 +0000 (GMT) From: Pierre Morel To: walling@linux.ibm.com Date: Wed, 9 Jan 2019 13:41:20 +0100 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1547037680-21458-1-git-send-email-pmorel@linux.ibm.com> References: <1547037680-21458-1-git-send-email-pmorel@linux.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 19010912-0028-0000-0000-000003367CC5 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19010912-0029-0000-0000-000023F38D86 Message-Id: <1547037680-21458-4-git-send-email-pmorel@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-01-09_07:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1901090106 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 v1 3/3] s390x/pci: Reporting the host aperture to the guest 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: thuth@redhat.com, david@redhat.com, cohuck@redhat.com, qemu-devel@nongnu.org, pasic@linux.ibm.com, borntraeger@de.ibm.com, qemu-s390x@nongnu.org, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The S390 PCI driver in the guest needs to know the IOMMU aperture associated with the zPCI real device in the host through Start DMA and End DMA value in the response to the Get Function Group information query. Let's report these SDMA and EDMA using the value we got from the host through the real IOMMU associated with the VFIO container. Signed-off-by: Pierre Morel --- hw/s390x/s390-pci-bus.c | 2 +- hw/s390x/s390-pci-bus.h | 3 +++ hw/s390x/s390-pci-inst.c | 20 +++++++++++++++++--- hw/vfio/common.c | 4 +++- include/hw/vfio/vfio-common.h | 3 +++ 5 files changed, 27 insertions(+), 5 deletions(-) diff --git a/hw/s390x/s390-pci-bus.c b/hw/s390x/s390-pci-bus.c index 27963b2..29177ac 100644 --- a/hw/s390x/s390-pci-bus.c +++ b/hw/s390x/s390-pci-bus.c @@ -551,7 +551,7 @@ static void s390_pci_iommu_replay(IOMMUMemoryRegion *io= mmu, return; } =20 -static S390PCIIOMMU *s390_pci_get_iommu(S390pciState *s, PCIBus *bus, +S390PCIIOMMU *s390_pci_get_iommu(S390pciState *s, PCIBus *bus, int devfn) { uint64_t key =3D (uintptr_t)bus; diff --git a/hw/s390x/s390-pci-bus.h b/hw/s390x/s390-pci-bus.h index 1f7f9b5..951a3d8 100644 --- a/hw/s390x/s390-pci-bus.h +++ b/hw/s390x/s390-pci-bus.h @@ -276,6 +276,8 @@ typedef struct S390PCIIOMMU { IOMMUMemoryRegion iommu_mr; bool enabled; uint64_t g_iota; + uint64_t sdma; + uint64_t edma; uint64_t pba; uint64_t pal; GHashTable *iotlb; @@ -344,5 +346,6 @@ S390PCIBusDevice *s390_pci_find_dev_by_target(S390pciSt= ate *s, const char *target); S390PCIBusDevice *s390_pci_find_next_avail_dev(S390pciState *s, S390PCIBusDevice *pbdev); +S390PCIIOMMU *s390_pci_get_iommu(S390pciState *s, PCIBus *bus, int devfn); =20 #endif diff --git a/hw/s390x/s390-pci-inst.c b/hw/s390x/s390-pci-inst.c index 7b61367..5125c1b 100644 --- a/hw/s390x/s390-pci-inst.c +++ b/hw/s390x/s390-pci-inst.c @@ -19,6 +19,7 @@ #include "exec/memory-internal.h" #include "qemu/error-report.h" #include "sysemu/hw_accel.h" +#include "hw/vfio/vfio-common.h" =20 #ifndef DEBUG_S390PCI_INST #define DEBUG_S390PCI_INST 0 @@ -31,6 +32,16 @@ } \ } while (0) =20 +void vfio_s390_iommu_setup(VFIOContainer *container, uint64_t min, + uint64_t max, uint64_t pgsize) +{ + S390PCIIOMMU *iommu; + + iommu =3D container_of(container->space->as, S390PCIIOMMU, as); + iommu->sdma =3D min; + iommu->edma =3D max; +} + static void s390_set_status_code(CPUS390XState *env, uint8_t r, uint64_t status_code) { @@ -153,6 +164,7 @@ int clp_service_call(S390CPU *cpu, uint8_t r2, uintptr_= t ra) uint8_t cc =3D 0; CPUS390XState *env =3D &cpu->env; S390pciState *s =3D s390_get_phb(); + S390PCIIOMMU *iommu; int i; =20 if (env->psw.mask & PSW_MASK_PSTATE) { @@ -279,8 +291,10 @@ int clp_service_call(S390CPU *cpu, uint8_t r2, uintptr= _t ra) resquery->bar_size[i]); } =20 - stq_p(&resquery->sdma, ZPCI_SDMA_ADDR); - stq_p(&resquery->edma, ZPCI_EDMA_ADDR); + iommu =3D s390_pci_get_iommu(s, pci_get_bus(pbdev->pdev), + PCI_FUNC(pbdev->pdev->devfn)); + stq_p(&resquery->sdma, iommu->sdma); + stq_p(&resquery->edma, iommu->edma); stl_p(&resquery->fid, pbdev->fid); stw_p(&resquery->pchid, 0); stw_p(&resquery->ug, 1); @@ -860,7 +874,7 @@ static int reg_ioat(CPUS390XState *env, S390PCIIOMMU *i= ommu, ZpciFib fib, =20 pba &=3D ~0xfff; pal |=3D 0xfff; - if (pba > pal || pba < ZPCI_SDMA_ADDR || pal > ZPCI_EDMA_ADDR) { + if (pba > pal || pba < iommu->sdma || pal > iommu->edma) { s390_program_interrupt(env, PGM_OPERAND, 6, ra); return -EINVAL; } diff --git a/hw/vfio/common.c b/hw/vfio/common.c index fd7e991..906b208 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -1045,7 +1045,6 @@ static void vfio_iommu_type1_get_info(int fd, VFIOCon= tainer *container) int ret =3D 0; =20 info =3D g_malloc0(argsz); - retry: info->argsz =3D argsz; info->flags =3D VFIO_IOMMU_INFO_CAPABILITIES; @@ -1079,6 +1078,8 @@ retry: dma_info->dma_end - dma_info->dma_start, info->iova_pgsizes); container->pgsizes =3D info->iova_pgsizes; + vfio_s390_iommu_setup(container, dma_info->dma_start, + dma_info->dma_end, info->iova_pgsizes); return; } hdr =3D (struct vfio_info_cap_header *)((unsigned char *) dma_info= + @@ -1088,6 +1089,7 @@ out: /* Assume 4k IOVA page size */ vfio_host_win_add(container, 0, (hwaddr)-1, 4096); container->pgsizes =3D 4096; + vfio_s390_iommu_setup(container, 0, (hwaddr)-1, 4096); return; } =20 diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 1b434d0..2c8bea8 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -198,4 +198,7 @@ int vfio_spapr_create_window(VFIOContainer *container, int vfio_spapr_remove_window(VFIOContainer *container, hwaddr offset_within_address_space); =20 +void vfio_s390_iommu_setup(VFIOContainer *container, uint64_t min, + uint64_t max, uint64_t pgsize); + #endif /* HW_VFIO_VFIO_COMMON_H */ --=20 2.7.4