From nobody Sun Feb 8 19:25:33 2026 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 148972104590098.21530488406052; Thu, 16 Mar 2017 20:24:05 -0700 (PDT) Received: from localhost ([::1]:46903 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1coiUm-0002RT-4x for importer@patchew.org; Thu, 16 Mar 2017 23:24:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56894) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1coiPL-0006Zx-8w for qemu-devel@nongnu.org; Thu, 16 Mar 2017 23:18:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1coiPG-0000Oj-Q4 for qemu-devel@nongnu.org; Thu, 16 Mar 2017 23:18:27 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:49407 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 1coiPG-0000OY-JX for qemu-devel@nongnu.org; Thu, 16 Mar 2017 23:18:22 -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 v2H3DqPK045667 for ; Thu, 16 Mar 2017 23:18:22 -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 2981f9wc4p-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 16 Mar 2017 23:18:21 -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:18:21 -0600 Received: from b03cxnp08027.gho.boulder.ibm.com (9.17.130.19) 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:18:17 -0600 Received: from b03ledav003.gho.boulder.ibm.com (b03ledav003.gho.boulder.ibm.com [9.17.130.234]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v2H3IFsJ10224118; Thu, 16 Mar 2017 20:18:15 -0700 Received: from b03ledav003.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CCBD66A03B; Thu, 16 Mar 2017 21:18:15 -0600 (MDT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by b03ledav003.gho.boulder.ibm.com (Postfix) with ESMTP id E13FF6A03F; Thu, 16 Mar 2017 21:18:13 -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:17:35 +0100 X-Mailer: git-send-email 2.8.4 In-Reply-To: <20170317031743.40128-1-bjsdjshi@linux.vnet.ibm.com> References: <20170317031743.40128-1-bjsdjshi@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17031703-0012-0000-0000-000013E30A14 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.00612585; 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:18:19 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17031703-0013-0000-0000-00004C413192 Message-Id: <20170317031743.40128-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-1703170025 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/16] vfio: ccw: handle ccw command request 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" We implement the basic ccw command handling infrastructure here: 1. Translate the ccw commands. 2. Issue the translated ccw commands to the device. 3. Once we get the execution result, update the guest SCSW with it. Acked-by: Pierre Morel Signed-off-by: Dong Jia Shi --- drivers/s390/cio/vfio_ccw_drv.c | 114 ++++++++++++++++++++++++++++++++= ++++ drivers/s390/cio/vfio_ccw_ops.c | 24 ++++++-- drivers/s390/cio/vfio_ccw_private.h | 14 +++++ 3 files changed, 148 insertions(+), 4 deletions(-) diff --git a/drivers/s390/cio/vfio_ccw_drv.c b/drivers/s390/cio/vfio_ccw_dr= v.c index b1f430a..b5971d3 100644 --- a/drivers/s390/cio/vfio_ccw_drv.c +++ b/drivers/s390/cio/vfio_ccw_drv.c @@ -11,9 +11,13 @@ #include #include #include +#include +#include =20 #include =20 +#include "ioasm.h" +#include "css.h" #include "vfio_ccw_private.h" =20 /* @@ -59,6 +63,109 @@ int vfio_ccw_sch_quiesce(struct subchannel *sch) return ret; } =20 +static int doing_io(struct vfio_ccw_private *private, u32 intparm) +{ + return (private->intparm =3D=3D intparm); +} + +static int vfio_ccw_sch_io_helper(struct vfio_ccw_private *private) +{ + struct subchannel *sch; + union orb *orb; + int ccode; + __u8 lpm; + u32 intparm; + + sch =3D private->sch; + + orb =3D cp_get_orb(&private->cp, (u32)(addr_t)sch, sch->lpm); + + /* Issue "Start Subchannel" */ + ccode =3D ssch(sch->schid, orb); + + switch (ccode) { + case 0: + /* + * Initialize device status information + */ + sch->schib.scsw.cmd.actl |=3D SCSW_ACTL_START_PEND; + break; + case 1: /* Status pending */ + case 2: /* Busy */ + return -EBUSY; + case 3: /* Device/path not operational */ + { + lpm =3D orb->cmd.lpm; + if (lpm !=3D 0) + sch->lpm &=3D ~lpm; + else + sch->lpm =3D 0; + + if (cio_update_schib(sch)) + return -ENODEV; + + return sch->lpm ? -EACCES : -ENODEV; + } + default: + return ccode; + } + + intparm =3D (u32)(addr_t)sch; + private->intparm =3D 0; + wait_event(private->wait_q, doing_io(private, intparm)); + + if (scsw_is_solicited(&private->irb.scsw)) + cp_update_scsw(&private->cp, &private->irb.scsw); + + return 0; +} + +/* Deal with the ccw command request from the userspace. */ +int vfio_ccw_sch_cmd_request(struct vfio_ccw_private *private) +{ + struct mdev_device *mdev =3D private->mdev; + union orb *orb; + union scsw *scsw =3D &private->scsw; + struct irb *irb =3D &private->irb; + struct ccw_io_region *io_region =3D &private->io_region; + int ret; + + memcpy(scsw, io_region->scsw_area, sizeof(*scsw)); + + if (scsw->cmd.fctl & SCSW_FCTL_START_FUNC) { + orb =3D (union orb *)io_region->orb_area; + + ret =3D cp_init(&private->cp, mdev_dev(mdev), orb); + if (ret) + return ret; + + ret =3D cp_prefetch(&private->cp); + if (ret) { + cp_free(&private->cp); + return ret; + } + + /* Start channel program and wait for I/O interrupt. */ + ret =3D vfio_ccw_sch_io_helper(private); + if (!ret) { + /* Get irb info and copy it to irb_area. */ + memcpy(io_region->irb_area, irb, sizeof(*irb)); + } + + cp_free(&private->cp); + } else if (scsw->cmd.fctl & SCSW_FCTL_HALT_FUNC) { + /* XXX: Handle halt. */ + ret =3D -EOPNOTSUPP; + } else if (scsw->cmd.fctl & SCSW_FCTL_CLEAR_FUNC) { + /* XXX: Handle clear. */ + ret =3D -EOPNOTSUPP; + } else { + ret =3D -EOPNOTSUPP; + } + + return ret; +} + /* * Sysfs interfaces */ @@ -113,12 +220,18 @@ static struct attribute_group vfio_subchannel_attr_gr= oup =3D { static void vfio_ccw_sch_irq(struct subchannel *sch) { struct vfio_ccw_private *private =3D dev_get_drvdata(&sch->dev); + struct irb *irb; =20 inc_irq_stat(IRQIO_CIO); =20 if (!private) return; =20 + irb =3D this_cpu_ptr(&cio_irb); + memcpy(&private->irb, irb, sizeof(*irb)); + private->intparm =3D (u32)(addr_t)sch; + wake_up(&private->wait_q); + if (private->completion) complete(private->completion); } @@ -156,6 +269,7 @@ static int vfio_ccw_sch_probe(struct subchannel *sch) if (ret) goto out_rm_group; =20 + init_waitqueue_head(&private->wait_q); atomic_set(&private->avail, 1); =20 return 0; diff --git a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_op= s.c index 6c06805..878c882 100644 --- a/drivers/s390/cio/vfio_ccw_ops.c +++ b/drivers/s390/cio/vfio_ccw_ops.c @@ -23,12 +23,25 @@ static int vfio_ccw_mdev_notifier(struct notifier_block= *nb, return NOTIFY_STOP; =20 /* - * TODO: * Vendor drivers MUST unpin pages in response to an * invalidation. */ - if (action =3D=3D VFIO_IOMMU_NOTIFY_DMA_UNMAP) - return NOTIFY_BAD; + if (action =3D=3D VFIO_IOMMU_NOTIFY_DMA_UNMAP) { + struct vfio_iommu_type1_dma_unmap *unmap =3D data; + struct subchannel *sch =3D private->sch; + + if (!cp_iova_pinned(&private->cp, unmap->iova)) + return NOTIFY_OK; + + if (vfio_ccw_sch_quiesce(sch)) + return NOTIFY_BAD; + + if (cio_enable_subchannel(sch, (u32)(unsigned long)sch)) + return NOTIFY_BAD; + + cp_free(&private->cp); + return NOTIFY_OK; + } =20 return NOTIFY_DONE; } @@ -167,7 +180,10 @@ static ssize_t vfio_ccw_mdev_write(struct mdev_device = *mdev, region =3D &private->io_region; if (copy_from_user((void *)region + *ppos, buf, count)) return -EFAULT; - region->ret_code =3D 0; + + region->ret_code =3D vfio_ccw_sch_cmd_request(private); + if (region->ret_code !=3D 0) + return region->ret_code; =20 return count; } diff --git a/drivers/s390/cio/vfio_ccw_private.h b/drivers/s390/cio/vfio_cc= w_private.h index 359e96b..79e5337 100644 --- a/drivers/s390/cio/vfio_ccw_private.h +++ b/drivers/s390/cio/vfio_ccw_private.h @@ -10,9 +10,11 @@ #ifndef _VFIO_CCW_PRIVATE_H_ #define _VFIO_CCW_PRIVATE_H_ =20 +#include #include =20 #include "css.h" +#include "vfio_ccw_cp.h" =20 /** * struct vfio_ccw_private @@ -22,6 +24,11 @@ * @mdev: pointer to the mediated device * @nb: notifier for vfio events * @io_region: MMIO region to input/output I/O arguments/results + * @wait_q: wait for interrupt + * @intparm: record current interrupt parameter, used for wait interrupt + * @cp: channel program for the current I/O operation + * @irb: irb info received from interrupt + * @scsw: scsw info */ struct vfio_ccw_private { struct subchannel *sch; @@ -30,11 +37,18 @@ struct vfio_ccw_private { struct mdev_device *mdev; struct notifier_block nb; struct ccw_io_region io_region; + + wait_queue_head_t wait_q; + u32 intparm; + struct channel_program cp; + struct irb irb; + union scsw scsw; } __aligned(8); =20 extern int vfio_ccw_mdev_reg(struct subchannel *sch); extern void vfio_ccw_mdev_unreg(struct subchannel *sch); =20 extern int vfio_ccw_sch_quiesce(struct subchannel *sch); +extern int vfio_ccw_sch_cmd_request(struct vfio_ccw_private *private); =20 #endif --=20 2.8.4