From patchwork Fri May 17 16:16:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre Morel X-Patchwork-Id: 10948201 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0650476 for ; Fri, 17 May 2019 16:17:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E8FA727F86 for ; Fri, 17 May 2019 16:17:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DCD0528387; Fri, 17 May 2019 16:17:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 563F127F86 for ; Fri, 17 May 2019 16:17:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729460AbfEQQRB (ORCPT ); Fri, 17 May 2019 12:17:01 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:37486 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729458AbfEQQRB (ORCPT ); Fri, 17 May 2019 12:17:01 -0400 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x4HG7Ejl058619 for ; Fri, 17 May 2019 12:16:59 -0400 Received: from e06smtp01.uk.ibm.com (e06smtp01.uk.ibm.com [195.75.94.97]) by mx0a-001b2d01.pphosted.com with ESMTP id 2shyky9y1r-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 17 May 2019 12:16:59 -0400 Received: from localhost by e06smtp01.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 17 May 2019 17:16:57 +0100 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) by e06smtp01.uk.ibm.com (192.168.101.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Fri, 17 May 2019 17:16:53 +0100 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x4HGGqSq18743538 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 17 May 2019 16:16:52 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1313552067; Fri, 17 May 2019 16:16:52 +0000 (GMT) Received: from morel-ThinkPad-W530.boeblingen.de.ibm.com (unknown [9.145.153.112]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id 7F1D35206D; Fri, 17 May 2019 16:16:51 +0000 (GMT) From: Pierre Morel To: sebott@linux.vnet.ibm.com Cc: gerald.schaefer@de.ibm.com, pasic@linux.vnet.ibm.com, borntraeger@de.ibm.com, walling@linux.ibm.com, linux-s390@vger.kernel.org, iommu@lists.linux-foundation.org, joro@8bytes.org, linux-kernel@vger.kernel.org, alex.williamson@redhat.com, kvm@vger.kernel.org, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com, robin.murphy@arm.com Subject: [PATCH v2 1/4] s390: pci: Exporting access to CLP PCI function and PCI group Date: Fri, 17 May 2019 18:16:47 +0200 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1558109810-18683-1-git-send-email-pmorel@linux.ibm.com> References: <1558109810-18683-1-git-send-email-pmorel@linux.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 19051716-4275-0000-0000-00000335E464 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19051716-4276-0000-0000-0000384570A3 Message-Id: <1558109810-18683-2-git-send-email-pmorel@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-05-17_09:,, 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=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1905170098 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP For the generic implementation of VFIO PCI we need to retrieve the hardware configuration for the PCI functions and the PCI function groups. We modify the internal function using CLP Query PCI function and CLP query PCI function group so that they can be called from outside the S390 architecture PCI code and prefix the two functions with "zdev" to make clear that they can be called knowing only the associated zdevice. Signed-off-by: Pierre Morel Reviewed-by: Sebastian Ott --- arch/s390/include/asm/pci.h | 3 ++ arch/s390/pci/pci_clp.c | 70 +++++++++++++++++++++++---------------------- 2 files changed, 39 insertions(+), 34 deletions(-) diff --git a/arch/s390/include/asm/pci.h b/arch/s390/include/asm/pci.h index 305befd..e66b246 100644 --- a/arch/s390/include/asm/pci.h +++ b/arch/s390/include/asm/pci.h @@ -261,4 +261,7 @@ cpumask_of_pcibus(const struct pci_bus *bus) #endif /* CONFIG_NUMA */ +int zdev_query_pci_fngrp(struct zpci_dev *zdev, + struct clp_req_rsp_query_pci_grp *rrb); +int zdev_query_pci_fn(struct zpci_dev *zdev, struct clp_req_rsp_query_pci *rrb); #endif diff --git a/arch/s390/pci/pci_clp.c b/arch/s390/pci/pci_clp.c index 3a36b07..c57f675 100644 --- a/arch/s390/pci/pci_clp.c +++ b/arch/s390/pci/pci_clp.c @@ -113,31 +113,16 @@ static void clp_store_query_pci_fngrp(struct zpci_dev *zdev, } } -static int clp_query_pci_fngrp(struct zpci_dev *zdev, u8 pfgid) +int zdev_query_pci_fngrp(struct zpci_dev *zdev, + struct clp_req_rsp_query_pci_grp *rrb) { - struct clp_req_rsp_query_pci_grp *rrb; - int rc; - - rrb = clp_alloc_block(GFP_KERNEL); - if (!rrb) - return -ENOMEM; - memset(rrb, 0, sizeof(*rrb)); rrb->request.hdr.len = sizeof(rrb->request); rrb->request.hdr.cmd = CLP_QUERY_PCI_FNGRP; rrb->response.hdr.len = sizeof(rrb->response); - rrb->request.pfgid = pfgid; + rrb->request.pfgid = zdev->pfgid; - rc = clp_req(rrb, CLP_LPS_PCI); - if (!rc && rrb->response.hdr.rsp == CLP_RC_OK) - clp_store_query_pci_fngrp(zdev, &rrb->response); - else { - zpci_err("Q PCI FGRP:\n"); - zpci_err_clp(rrb->response.hdr.rsp, rc); - rc = -EIO; - } - clp_free_block(rrb); - return rc; + return clp_req(rrb, CLP_LPS_PCI); } static int clp_store_query_pci_fn(struct zpci_dev *zdev, @@ -174,32 +159,49 @@ static int clp_store_query_pci_fn(struct zpci_dev *zdev, return 0; } -static int clp_query_pci_fn(struct zpci_dev *zdev, u32 fh) +int zdev_query_pci_fn(struct zpci_dev *zdev, struct clp_req_rsp_query_pci *rrb) +{ + + memset(rrb, 0, sizeof(*rrb)); + rrb->request.hdr.len = sizeof(rrb->request); + rrb->request.hdr.cmd = CLP_QUERY_PCI_FN; + rrb->response.hdr.len = sizeof(rrb->response); + rrb->request.fh = zdev->fh; + + return clp_req(rrb, CLP_LPS_PCI); +} + +static int clp_query_pci(struct zpci_dev *zdev) { struct clp_req_rsp_query_pci *rrb; + struct clp_req_rsp_query_pci_grp *grrb; int rc; rrb = clp_alloc_block(GFP_KERNEL); if (!rrb) return -ENOMEM; - memset(rrb, 0, sizeof(*rrb)); - rrb->request.hdr.len = sizeof(rrb->request); - rrb->request.hdr.cmd = CLP_QUERY_PCI_FN; - rrb->response.hdr.len = sizeof(rrb->response); - rrb->request.fh = fh; - - rc = clp_req(rrb, CLP_LPS_PCI); - if (!rc && rrb->response.hdr.rsp == CLP_RC_OK) { - rc = clp_store_query_pci_fn(zdev, &rrb->response); - if (rc) - goto out; - rc = clp_query_pci_fngrp(zdev, rrb->response.pfgid); - } else { + rc = zdev_query_pci_fn(zdev, rrb); + if (rc || rrb->response.hdr.rsp != CLP_RC_OK) { zpci_err("Q PCI FN:\n"); zpci_err_clp(rrb->response.hdr.rsp, rc); rc = -EIO; + goto out; } + rc = clp_store_query_pci_fn(zdev, &rrb->response); + if (rc) + goto out; + + grrb = (struct clp_req_rsp_query_pci_grp *)rrb; + rc = zdev_query_pci_fngrp(zdev, grrb); + if (rc || grrb->response.hdr.rsp != CLP_RC_OK) { + zpci_err("Q PCI FGRP:\n"); + zpci_err_clp(grrb->response.hdr.rsp, rc); + rc = -EIO; + goto out; + } + clp_store_query_pci_fngrp(zdev, &grrb->response); + out: clp_free_block(rrb); return rc; @@ -219,7 +221,7 @@ int clp_add_pci_device(u32 fid, u32 fh, int configured) zdev->fid = fid; /* Query function properties and update zdev */ - rc = clp_query_pci_fn(zdev, fh); + rc = clp_query_pci(zdev); if (rc) goto error; From patchwork Fri May 17 16:16:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre Morel X-Patchwork-Id: 10948209 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5816D112C for ; Fri, 17 May 2019 16:17:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4696727F86 for ; Fri, 17 May 2019 16:17:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3A4712835B; Fri, 17 May 2019 16:17:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1E59627F86 for ; Fri, 17 May 2019 16:17:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729470AbfEQQRA (ORCPT ); Fri, 17 May 2019 12:17:00 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:32772 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729249AbfEQQRA (ORCPT ); Fri, 17 May 2019 12:17:00 -0400 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x4HG7FbY028304 for ; Fri, 17 May 2019 12:16:59 -0400 Received: from e06smtp02.uk.ibm.com (e06smtp02.uk.ibm.com [195.75.94.98]) by mx0a-001b2d01.pphosted.com with ESMTP id 2shxe7d4pa-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 17 May 2019 12:16:59 -0400 Received: from localhost by e06smtp02.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 17 May 2019 17:16:57 +0100 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) by e06smtp02.uk.ibm.com (192.168.101.132) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Fri, 17 May 2019 17:16:54 +0100 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x4HGGqDG47644828 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 17 May 2019 16:16:52 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AA34F52073; Fri, 17 May 2019 16:16:52 +0000 (GMT) Received: from morel-ThinkPad-W530.boeblingen.de.ibm.com (unknown [9.145.153.112]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id 2531B52071; Fri, 17 May 2019 16:16:52 +0000 (GMT) From: Pierre Morel To: sebott@linux.vnet.ibm.com Cc: gerald.schaefer@de.ibm.com, pasic@linux.vnet.ibm.com, borntraeger@de.ibm.com, walling@linux.ibm.com, linux-s390@vger.kernel.org, iommu@lists.linux-foundation.org, joro@8bytes.org, linux-kernel@vger.kernel.org, alex.williamson@redhat.com, kvm@vger.kernel.org, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com, robin.murphy@arm.com Subject: [PATCH v2 2/4] vfio: vfio_iommu_type1: Define VFIO_IOMMU_INFO_CAPABILITIES Date: Fri, 17 May 2019 18:16:48 +0200 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1558109810-18683-1-git-send-email-pmorel@linux.ibm.com> References: <1558109810-18683-1-git-send-email-pmorel@linux.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 19051716-0008-0000-0000-000002E7C7C9 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19051716-0009-0000-0000-0000225472E3 Message-Id: <1558109810-18683-3-git-send-email-pmorel@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-05-17_09:,, 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-1905170098 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We add a capabilities functionality to VFIO_IOMMU_GET_INFO. This will allow the VFIO_IOMMU_GET_INFO ioctl to retrieve IOMMU specific information. we define a new flag VFIO_IOMMU_INFO_CAPABILITIES in the vfio_iommu_type1_info structure and two Z-PCI specific capabilities: VFIO_IOMMU_INFO_CAP_QFN: to query Z-PCI function information VFIO_IOMMU_INFO_CAP_QGRP: to query for Z-PCI group information and we define the associated information structures. Signed-off-by: Pierre Morel --- include/uapi/linux/vfio.h | 67 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h index 8f10748..aed0e72 100644 --- a/include/uapi/linux/vfio.h +++ b/include/uapi/linux/vfio.h @@ -715,6 +715,73 @@ 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 info */ + __u64 cap_offset; /* Offset within info struct of first cap */ +}; + +/* + * The VFIO IOMMU INFO PCI function capability allows to retrieve + * Z-PCI function specific data needed by the VFIO user to provide + * them to the guest function's driver. + * + * The structures below define version 1 of this capability. + */ +#define VFIO_IOMMU_INFO_CAP_QFN 1 + +struct vfio_iommu_pci_function { + __u32 ignored; + __u32 format; /* Structure format */ + __u64 reserved1; + __u16 vfn; /* Virtual function number */ + __u8 u; /* utility string presence */ + __u8 gid; /* Function group */ + __u32 fid; /* Function identifier */ + __u8 bar_size[6]; /* Bar size */ + __u16 pchid; /* Physical channel ID */ + __u32 bar[6]; /* PCI Bar address */ + __u64 reserved2; + __u64 sdma; /* Start available DMA */ + __u64 edma; /* End available DMA */ + __u32 reserved3[11]; + __u32 uid; /* User's identifier */ + __u8 util_str[64]; /* Adapter specific utility string */ +}; + +struct vfio_iommu_type1_info_pcifn { + struct vfio_info_cap_header header; + struct vfio_iommu_pci_function response; +}; + +/* + * The VFIO IOMMU INFO PCI function group capability allows to retrieve + * information, specific to a group of Z-PCI functions, needed by + * the VFIO user to provide them to the guest function's driver. + * + * The structures below define version 1 of this capability. + */ +#define VFIO_IOMMU_INFO_CAP_QGRP 2 + +struct vfio_iommu_pci_function_group { + __u32 ignored; + __u32 format; /* Structure format */ + __u64 reserved1; + __u16 noi; /* Maximum number of interruptions */ + __u8 version; /* Version */ + __u8 flags; /* Flags */ +#define VFIO_IOMMU_ZPCI_REFRESH 0x01 +#define VFIO_IOMMU_ZPCI_FRAME 0x02 + __u16 maxstbl; /* Maximum store-block length */ + __u16 mui; /* Measurement block update interval */ + __u64 reserved3; + __u64 dasm; /* DMA Address space mask */ + __u64 msia; /* MSI Address */ + __u64 reserved4; + __u64 reserved5; +}; + +struct vfio_iommu_type1_info_pcifg { + struct vfio_info_cap_header header; + struct vfio_iommu_pci_function_group response; }; #define VFIO_IOMMU_GET_INFO _IO(VFIO_TYPE, VFIO_BASE + 12) From patchwork Fri May 17 16:16:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre Morel X-Patchwork-Id: 10948205 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8E1FE112C for ; Fri, 17 May 2019 16:17:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7CCAE27F86 for ; Fri, 17 May 2019 16:17:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 70D662835B; Fri, 17 May 2019 16:17:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 06FCA27F86 for ; Fri, 17 May 2019 16:17:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729198AbfEQQRN (ORCPT ); Fri, 17 May 2019 12:17:13 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:43564 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729464AbfEQQRB (ORCPT ); Fri, 17 May 2019 12:17:01 -0400 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x4HG7mKg117153 for ; Fri, 17 May 2019 12:17:00 -0400 Received: from e06smtp03.uk.ibm.com (e06smtp03.uk.ibm.com [195.75.94.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 2shxy9up2x-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 17 May 2019 12:17:00 -0400 Received: from localhost by e06smtp03.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 17 May 2019 17:16:57 +0100 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp03.uk.ibm.com (192.168.101.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Fri, 17 May 2019 17:16:55 +0100 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x4HGGrbY42139690 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 17 May 2019 16:16:53 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5B7E852057; Fri, 17 May 2019 16:16:53 +0000 (GMT) Received: from morel-ThinkPad-W530.boeblingen.de.ibm.com (unknown [9.145.153.112]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id BE01E52076; Fri, 17 May 2019 16:16:52 +0000 (GMT) From: Pierre Morel To: sebott@linux.vnet.ibm.com Cc: gerald.schaefer@de.ibm.com, pasic@linux.vnet.ibm.com, borntraeger@de.ibm.com, walling@linux.ibm.com, linux-s390@vger.kernel.org, iommu@lists.linux-foundation.org, joro@8bytes.org, linux-kernel@vger.kernel.org, alex.williamson@redhat.com, kvm@vger.kernel.org, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com, robin.murphy@arm.com Subject: [PATCH v2 3/4] s390: iommu: Adding get attributes for s390_iommu Date: Fri, 17 May 2019 18:16:49 +0200 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1558109810-18683-1-git-send-email-pmorel@linux.ibm.com> References: <1558109810-18683-1-git-send-email-pmorel@linux.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 19051716-0012-0000-0000-0000031CCC95 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19051716-0013-0000-0000-000021557328 Message-Id: <1558109810-18683-4-git-send-email-pmorel@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-05-17_09:,, 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=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1905170098 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We add the "get attributes" callback to the S390 iommu operations to retrieve the S390 specific attributes through the call of zPCI dedicated CLP functions. The caller can use the following attributes and retrieve: DOMAIN_ATTR_ZPCI_FN_SIZE: the size of the Z-PCI function attributes DOMAIN_ATTR_ZPCI_GRP_SIZE: the size of the Z-PCI function group attributes DOMAIN_ATTR_ZPCI_FN: the Z-PCI function attributes DOMAIN_ATTR_ZPCI_GRP: the Z-PCI function group attributes Signed-off-by: Pierre Morel --- drivers/iommu/s390-iommu.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++ include/linux/iommu.h | 4 +++ 2 files changed, 81 insertions(+) diff --git a/drivers/iommu/s390-iommu.c b/drivers/iommu/s390-iommu.c index 22d4db3..98082f0 100644 --- a/drivers/iommu/s390-iommu.c +++ b/drivers/iommu/s390-iommu.c @@ -363,6 +363,82 @@ void zpci_destroy_iommu(struct zpci_dev *zdev) iommu_device_sysfs_remove(&zdev->iommu_dev); } +struct zpci_dev *get_zpci(struct s390_domain *s390_domain) +{ + struct s390_domain_device *domain_device; + + domain_device = list_first_entry(&s390_domain->devices, + struct s390_domain_device, list); + if (!domain_device) + return NULL; + return domain_device->zdev; +} + +static int s390_domain_get_fn(struct iommu_domain *domain, void *data) +{ + struct zpci_dev *zdev; + struct clp_req_rsp_query_pci *rrb; + int rc; + + zdev = get_zpci(to_s390_domain(domain)); + if (!zdev) + return -ENODEV; + rrb = (struct clp_req_rsp_query_pci *) + __get_free_pages(GFP_KERNEL, get_order(CLP_BLK_SIZE)); + if (!rrb) + return -ENOMEM; + rc = zdev_query_pci_fn(zdev, rrb); + + if (!rc && rrb->response.hdr.rsp == CLP_RC_OK) + memcpy(data, &rrb->response, sizeof(struct clp_rsp_query_pci)); + else + rc = -EIO; + free_pages((unsigned long) rrb, get_order(CLP_BLK_SIZE)); + return rc; +} + +static int s390_domain_get_grp(struct iommu_domain *domain, void *data) +{ + struct zpci_dev *zdev; + struct clp_req_rsp_query_pci_grp *rrb; + int rc; + + zdev = get_zpci(to_s390_domain(domain)); + if (!zdev) + return -ENODEV; + rrb = (struct clp_req_rsp_query_pci_grp *) + __get_free_pages(GFP_KERNEL, get_order(CLP_BLK_SIZE)); + if (!rrb) + return -ENOMEM; + + rc = zdev_query_pci_fngrp(zdev, rrb); + if (!rc && rrb->response.hdr.rsp == CLP_RC_OK) + memcpy(data, &rrb->response, + sizeof(struct clp_rsp_query_pci_grp)); + else + rc = -EIO; + + free_pages((unsigned long) rrb, get_order(CLP_BLK_SIZE)); + return rc; +} + +static int s390_domain_get_attr(struct iommu_domain *domain, + enum iommu_attr attr, void *data) +{ + switch (attr) { + case DOMAIN_ATTR_ZPCI_FN_SIZE: + return sizeof(struct clp_rsp_query_pci); + case DOMAIN_ATTR_ZPCI_GRP_SIZE: + return sizeof(struct clp_rsp_query_pci_grp); + case DOMAIN_ATTR_ZPCI_FN: + return s390_domain_get_fn(domain, data); + case DOMAIN_ATTR_ZPCI_GRP: + return s390_domain_get_grp(domain, data); + default: + return -ENODEV; + } +} + static const struct iommu_ops s390_iommu_ops = { .capable = s390_iommu_capable, .domain_alloc = s390_domain_alloc, @@ -376,6 +452,7 @@ static const struct iommu_ops s390_iommu_ops = { .remove_device = s390_iommu_remove_device, .device_group = generic_device_group, .pgsize_bitmap = S390_IOMMU_PGSIZES, + .domain_get_attr = s390_domain_get_attr, }; static int __init s390_iommu_init(void) diff --git a/include/linux/iommu.h b/include/linux/iommu.h index ffbbc7e..ebdcac4 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -125,6 +125,10 @@ enum iommu_attr { DOMAIN_ATTR_FSL_PAMUV1, DOMAIN_ATTR_NESTING, /* two stages of translation */ DOMAIN_ATTR_DMA_USE_FLUSH_QUEUE, + DOMAIN_ATTR_ZPCI_FN_SIZE, + DOMAIN_ATTR_ZPCI_GRP_SIZE, + DOMAIN_ATTR_ZPCI_FN, + DOMAIN_ATTR_ZPCI_GRP, DOMAIN_ATTR_MAX, }; From patchwork Fri May 17 16:16:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre Morel X-Patchwork-Id: 10948203 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 738B676 for ; Fri, 17 May 2019 16:17:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 61AA927F86 for ; Fri, 17 May 2019 16:17:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 554892835B; Fri, 17 May 2019 16:17:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 33F0827F86 for ; Fri, 17 May 2019 16:17:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729496AbfEQQRD (ORCPT ); Fri, 17 May 2019 12:17:03 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:43604 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729481AbfEQQRC (ORCPT ); Fri, 17 May 2019 12:17:02 -0400 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x4HG7mwu117171 for ; Fri, 17 May 2019 12:17:01 -0400 Received: from e06smtp01.uk.ibm.com (e06smtp01.uk.ibm.com [195.75.94.97]) by mx0a-001b2d01.pphosted.com with ESMTP id 2shxy9up3d-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 17 May 2019 12:17:00 -0400 Received: from localhost by e06smtp01.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 17 May 2019 17:16:58 +0100 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp01.uk.ibm.com (192.168.101.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Fri, 17 May 2019 17:16:55 +0100 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x4HGGsMT44302506 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 17 May 2019 16:16:54 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 012E452059; Fri, 17 May 2019 16:16:54 +0000 (GMT) Received: from morel-ThinkPad-W530.boeblingen.de.ibm.com (unknown [9.145.153.112]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id 644E85206B; Fri, 17 May 2019 16:16:53 +0000 (GMT) From: Pierre Morel To: sebott@linux.vnet.ibm.com Cc: gerald.schaefer@de.ibm.com, pasic@linux.vnet.ibm.com, borntraeger@de.ibm.com, walling@linux.ibm.com, linux-s390@vger.kernel.org, iommu@lists.linux-foundation.org, joro@8bytes.org, linux-kernel@vger.kernel.org, alex.williamson@redhat.com, kvm@vger.kernel.org, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com, robin.murphy@arm.com Subject: [PATCH v2 4/4] vfio: vfio_iommu_type1: implement VFIO_IOMMU_INFO_CAPABILITIES Date: Fri, 17 May 2019 18:16:50 +0200 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1558109810-18683-1-git-send-email-pmorel@linux.ibm.com> References: <1558109810-18683-1-git-send-email-pmorel@linux.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 19051716-4275-0000-0000-00000335E465 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19051716-4276-0000-0000-0000384570A6 Message-Id: <1558109810-18683-5-git-send-email-pmorel@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-05-17_09:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=4 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=635 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1905170098 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We implement the capability interface for VFIO_IOMMU_GET_INFO. When calling the ioctl, the user must specify VFIO_IOMMU_INFO_CAPABILITIES to retrieve the capabilities and must check in the answer if capabilities are supported. The iommu get_attr callback will be used to retrieve the specific attributes and fill the capabilities. Currently two Z-PCI specific capabilities will be queried and filled by the underlying Z specific s390_iommu: VFIO_IOMMU_INFO_CAP_QFN for the PCI query function attributes and VFIO_IOMMU_INFO_CAP_QGRP for the PCI query function group. Other architectures may add new capabilities in the same way after enhancing the architecture specific IOMMU driver. Signed-off-by: Pierre Morel --- drivers/vfio/vfio_iommu_type1.c | 122 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 121 insertions(+), 1 deletion(-) diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index d0f731c..9435647 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -1658,6 +1658,97 @@ static int vfio_domains_have_iommu_cache(struct vfio_iommu *iommu) return ret; } +static int vfio_iommu_type1_zpci_fn(struct iommu_domain *domain, + struct vfio_info_cap *caps, size_t size) +{ + struct vfio_iommu_type1_info_pcifn *info_fn; + int ret; + + info_fn = kzalloc(size, GFP_KERNEL); + if (!info_fn) + return -ENOMEM; + + ret = iommu_domain_get_attr(domain, DOMAIN_ATTR_ZPCI_FN, + &info_fn->response); + if (ret < 0) + goto free_fn; + + info_fn->header.id = VFIO_IOMMU_INFO_CAP_QFN; + ret = vfio_info_add_capability(caps, &info_fn->header, size); + +free_fn: + kfree(info_fn); + return ret; +} + +static int vfio_iommu_type1_zpci_grp(struct iommu_domain *domain, + struct vfio_info_cap *caps, + size_t grp_size) +{ + struct vfio_iommu_type1_info_pcifg *info_grp; + int ret; + + info_grp = kzalloc(grp_size, GFP_KERNEL); + if (!info_grp) + return -ENOMEM; + + ret = iommu_domain_get_attr(domain, DOMAIN_ATTR_ZPCI_GRP, + (void *) &info_grp->response); + if (ret < 0) + goto free_grp; + info_grp->header.id = VFIO_IOMMU_INFO_CAP_QGRP; + ret = vfio_info_add_capability(caps, &info_grp->header, grp_size); + +free_grp: + kfree(info_grp); + return ret; +} + +int vfio_iommu_type1_caps(struct vfio_iommu *iommu, struct vfio_info_cap *caps, + size_t size) +{ + struct vfio_domain *d; + unsigned long total_size, fn_size, grp_size; + int ret; + + d = list_first_entry(&iommu->domain_list, struct vfio_domain, next); + if (!d) + return -ENODEV; + + /* First compute the size the user must provide */ + total_size = 0; + fn_size = iommu_domain_get_attr(d->domain, + DOMAIN_ATTR_ZPCI_FN_SIZE, NULL); + if (fn_size > 0) { + fn_size += sizeof(struct vfio_info_cap_header); + total_size += fn_size; + } + + grp_size = iommu_domain_get_attr(d->domain, + DOMAIN_ATTR_ZPCI_GRP_SIZE, NULL); + if (grp_size > 0) { + grp_size += sizeof(struct vfio_info_cap_header); + total_size += grp_size; + } + + if (total_size > size) { + /* Tell caller to call us with a greater buffer */ + caps->size = total_size; + return 0; + } + + if (fn_size) { + ret = vfio_iommu_type1_zpci_fn(d->domain, caps, fn_size); + if (ret) + return ret; + } + + if (grp_size) + ret = vfio_iommu_type1_zpci_grp(d->domain, caps, grp_size); + + return ret; +} + static long vfio_iommu_type1_ioctl(void *iommu_data, unsigned int cmd, unsigned long arg) { @@ -1679,6 +1770,8 @@ static long vfio_iommu_type1_ioctl(void *iommu_data, } } else if (cmd == VFIO_IOMMU_GET_INFO) { struct vfio_iommu_type1_info info; + struct vfio_info_cap caps = { .buf = NULL, .size = 0 }; + int ret; minsz = offsetofend(struct vfio_iommu_type1_info, iova_pgsizes); @@ -1688,7 +1781,34 @@ static long vfio_iommu_type1_ioctl(void *iommu_data, if (info.argsz < minsz) return -EINVAL; - info.flags = VFIO_IOMMU_INFO_PGSIZES; + if (info.flags & VFIO_IOMMU_INFO_CAPABILITIES) { + minsz = offsetofend(struct vfio_iommu_type1_info, + cap_offset); + if (info.argsz < minsz) + return -EINVAL; + ret = vfio_iommu_type1_caps(iommu, &caps, + info.argsz - sizeof(info)); + if (ret) + return ret; + } + if (caps.size) { + if (info.argsz < sizeof(info) + caps.size) { + info.argsz = sizeof(info) + caps.size; + info.cap_offset = 0; + } else { + if (copy_to_user((void __user *)arg + + sizeof(info), caps.buf, + caps.size)) { + kfree(caps.buf); + return -EFAULT; + } + + info.cap_offset = sizeof(info); + } + kfree(caps.buf); + } + + info.flags |= VFIO_IOMMU_INFO_PGSIZES; info.iova_pgsizes = vfio_pgsize_bitmap(iommu);