From patchwork Thu Jan 11 03:04:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dong Jia Shi X-Patchwork-Id: 858750 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zH9jt1YGqz9t3k for ; Thu, 11 Jan 2018 14:05:38 +1100 (AEDT) Received: from localhost ([::1]:34117 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eZTBQ-0004LK-7g for incoming@patchwork.ozlabs.org; Wed, 10 Jan 2018 22:05:36 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44032) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eZTAW-0004IB-FG for qemu-devel@nongnu.org; Wed, 10 Jan 2018 22:04:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eZTAR-0002Gs-Gf for qemu-devel@nongnu.org; Wed, 10 Jan 2018 22:04:40 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:34346) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eZTAR-0002Fu-8p for qemu-devel@nongnu.org; Wed, 10 Jan 2018 22:04:35 -0500 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w0B34KtX040365 for ; Wed, 10 Jan 2018 22:04:32 -0500 Received: from e35.co.us.ibm.com (e35.co.us.ibm.com [32.97.110.153]) by mx0a-001b2d01.pphosted.com with ESMTP id 2fdxxqskk1-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 10 Jan 2018 22:04:31 -0500 Received: from localhost by e35.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 10 Jan 2018 20:04:31 -0700 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; Wed, 10 Jan 2018 20:04:28 -0700 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 w0B34Sk68323494; Wed, 10 Jan 2018 20:04:28 -0700 Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1796F7804D; Wed, 10 Jan 2018 20:04:28 -0700 (MST) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP id 707897803F; Wed, 10 Jan 2018 20:04:26 -0700 (MST) From: Dong Jia Shi To: linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org, kvm@vger.kernel.org, qemu-devel@nongnu.org, qemu-s390x@nongnu.org Date: Thu, 11 Jan 2018 04:04:19 +0100 X-Mailer: git-send-email 2.13.5 In-Reply-To: <20180111030421.31418-1-bjsdjshi@linux.vnet.ibm.com> References: <20180111030421.31418-1-bjsdjshi@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18011103-0012-0000-0000-0000159529C4 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008357; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000245; SDB=6.00973252; UDB=6.00493123; IPR=6.00753202; BA=6.00005772; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00018971; XFM=3.00000015; UTC=2018-01-11 03:04:30 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18011103-0013-0000-0000-000051023042 Message-Id: <20180111030421.31418-2-bjsdjshi@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2018-01-11_02:, , 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 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1801110036 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [RFC PATCH 1/3] vfio: ccw: introduce schib region X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: borntraeger@de.ibm.com, bjsdjshi@linux.vnet.ibm.com, cohuck@redhat.com, pmorel@linux.vnet.ibm.com, pasic@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This introduces a new region for vfio-ccw to provide subchannel information for user space. Signed-off-by: Dong Jia Shi --- drivers/s390/cio/vfio_ccw_fsm.c | 21 ++++++++++ drivers/s390/cio/vfio_ccw_ops.c | 79 +++++++++++++++++++++++++++---------- drivers/s390/cio/vfio_ccw_private.h | 3 ++ include/uapi/linux/vfio.h | 1 + include/uapi/linux/vfio_ccw.h | 6 +++ 5 files changed, 90 insertions(+), 20 deletions(-) diff --git a/drivers/s390/cio/vfio_ccw_fsm.c b/drivers/s390/cio/vfio_ccw_fsm.c index c30420c517b1..be081ccabea3 100644 --- a/drivers/s390/cio/vfio_ccw_fsm.c +++ b/drivers/s390/cio/vfio_ccw_fsm.c @@ -172,6 +172,22 @@ static void fsm_irq(struct vfio_ccw_private *private, complete(private->completion); } +static void fsm_update_subch(struct vfio_ccw_private *private, + enum vfio_ccw_event event) +{ + struct subchannel *sch; + + sch = private->sch; + if (cio_update_schib(sch)) { + private->schib_region.cc = 3; + return; + } + + private->schib_region.cc = 0; + memcpy(private->schib_region.schib_area, &sch->schib, + sizeof(sch->schib)); +} + /* * Device statemachine */ @@ -180,25 +196,30 @@ fsm_func_t *vfio_ccw_jumptable[NR_VFIO_CCW_STATES][NR_VFIO_CCW_EVENTS] = { [VFIO_CCW_EVENT_NOT_OPER] = fsm_nop, [VFIO_CCW_EVENT_IO_REQ] = fsm_io_error, [VFIO_CCW_EVENT_INTERRUPT] = fsm_disabled_irq, + [VFIO_CCW_EVENT_UPDATE_SUBCH] = fsm_update_subch, }, [VFIO_CCW_STATE_STANDBY] = { [VFIO_CCW_EVENT_NOT_OPER] = fsm_notoper, [VFIO_CCW_EVENT_IO_REQ] = fsm_io_error, [VFIO_CCW_EVENT_INTERRUPT] = fsm_irq, + [VFIO_CCW_EVENT_UPDATE_SUBCH] = fsm_update_subch, }, [VFIO_CCW_STATE_IDLE] = { [VFIO_CCW_EVENT_NOT_OPER] = fsm_notoper, [VFIO_CCW_EVENT_IO_REQ] = fsm_io_request, [VFIO_CCW_EVENT_INTERRUPT] = fsm_irq, + [VFIO_CCW_EVENT_UPDATE_SUBCH] = fsm_update_subch, }, [VFIO_CCW_STATE_BOXED] = { [VFIO_CCW_EVENT_NOT_OPER] = fsm_notoper, [VFIO_CCW_EVENT_IO_REQ] = fsm_io_busy, [VFIO_CCW_EVENT_INTERRUPT] = fsm_irq, + [VFIO_CCW_EVENT_UPDATE_SUBCH] = fsm_update_subch, }, [VFIO_CCW_STATE_BUSY] = { [VFIO_CCW_EVENT_NOT_OPER] = fsm_notoper, [VFIO_CCW_EVENT_IO_REQ] = fsm_io_busy, [VFIO_CCW_EVENT_INTERRUPT] = fsm_irq, + [VFIO_CCW_EVENT_UPDATE_SUBCH] = fsm_update_subch, }, }; diff --git a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_ops.c index 41eeb57d68a3..9528fce2e7d9 100644 --- a/drivers/s390/cio/vfio_ccw_ops.c +++ b/drivers/s390/cio/vfio_ccw_ops.c @@ -13,6 +13,11 @@ #include "vfio_ccw_private.h" +#define VFIO_CCW_OFFSET_SHIFT 40 +#define VFIO_CCW_OFFSET_TO_INDEX(off) (off >> VFIO_CCW_OFFSET_SHIFT) +#define VFIO_CCW_INDEX_TO_OFFSET(index) ((u64)(index) << VFIO_CCW_OFFSET_SHIFT) +#define VFIO_CCW_OFFSET_MASK (((u64)(1) << VFIO_CCW_OFFSET_SHIFT) - 1) + static int vfio_ccw_mdev_reset(struct mdev_device *mdev) { struct vfio_ccw_private *private; @@ -168,14 +173,31 @@ static ssize_t vfio_ccw_mdev_read(struct mdev_device *mdev, loff_t *ppos) { struct vfio_ccw_private *private; - struct ccw_io_region *region; + void *region; + u32 index; + loff_t pos; + + index = VFIO_CCW_OFFSET_TO_INDEX(*ppos); + pos = (*ppos) & VFIO_CCW_OFFSET_MASK; + private = dev_get_drvdata(mdev_parent_dev(mdev)); - if (*ppos + count > sizeof(*region)) + switch (index) { + case VFIO_CCW_CONFIG_REGION_INDEX: + if (pos + count > sizeof(struct ccw_io_region)) + return -EINVAL; + region = &private->io_region; + break; + case VFIO_CCW_SCHIB_REGION_INDEX: + if (pos + count > sizeof(struct ccw_schib_region)) + return -EINVAL; + region = &private->schib_region; + vfio_ccw_fsm_event(private, VFIO_CCW_EVENT_UPDATE_SUBCH); + break; + default: return -EINVAL; + } - private = dev_get_drvdata(mdev_parent_dev(mdev)); - region = &private->io_region; - if (copy_to_user(buf, (void *)region + *ppos, count)) + if (copy_to_user(buf, region + pos, count)) return -EFAULT; return count; @@ -187,23 +209,35 @@ static ssize_t vfio_ccw_mdev_write(struct mdev_device *mdev, loff_t *ppos) { struct vfio_ccw_private *private; - struct ccw_io_region *region; - - if (*ppos + count > sizeof(*region)) - return -EINVAL; + u32 index; + loff_t pos; + index = VFIO_CCW_OFFSET_TO_INDEX(*ppos); + pos = (*ppos) & VFIO_CCW_OFFSET_MASK; private = dev_get_drvdata(mdev_parent_dev(mdev)); - if (private->state != VFIO_CCW_STATE_IDLE) - return -EACCES; - region = &private->io_region; - if (copy_from_user((void *)region + *ppos, buf, count)) - return -EFAULT; - - vfio_ccw_fsm_event(private, VFIO_CCW_EVENT_IO_REQ); - if (region->ret_code != 0) { - private->state = VFIO_CCW_STATE_IDLE; - return region->ret_code; + switch (index) { + case VFIO_CCW_CONFIG_REGION_INDEX: + { + struct ccw_io_region *region; + if (pos + count > sizeof(*region)) + return -EINVAL; + if (private->state != VFIO_CCW_STATE_IDLE) + return -EACCES; + region = &private->io_region; + if (copy_from_user((void *)region + *ppos, buf, count)) + return -EFAULT; + vfio_ccw_fsm_event(private, VFIO_CCW_EVENT_IO_REQ); + if (region->ret_code != 0) { + private->state = VFIO_CCW_STATE_IDLE; + return region->ret_code; + } + break; + } + case VFIO_CCW_SCHIB_REGION_INDEX: + return -EOPNOTSUPP; + default: + return -EINVAL; } return count; @@ -224,11 +258,16 @@ static int vfio_ccw_mdev_get_region_info(struct vfio_region_info *info, { switch (info->index) { case VFIO_CCW_CONFIG_REGION_INDEX: - info->offset = 0; + info->offset = VFIO_CCW_INDEX_TO_OFFSET(info->index); info->size = sizeof(struct ccw_io_region); info->flags = VFIO_REGION_INFO_FLAG_READ | VFIO_REGION_INFO_FLAG_WRITE; return 0; + case VFIO_CCW_SCHIB_REGION_INDEX: + info->offset = VFIO_CCW_INDEX_TO_OFFSET(info->index); + info->size = sizeof(struct ccw_schib_region); + info->flags = VFIO_REGION_INFO_FLAG_READ; + return 0; default: return -EINVAL; } diff --git a/drivers/s390/cio/vfio_ccw_private.h b/drivers/s390/cio/vfio_ccw_private.h index 78a66d96756b..460c8b90d834 100644 --- a/drivers/s390/cio/vfio_ccw_private.h +++ b/drivers/s390/cio/vfio_ccw_private.h @@ -28,6 +28,7 @@ * @mdev: pointer to the mediated device * @nb: notifier for vfio events * @io_region: MMIO region to input/output I/O arguments/results + * @schib_region: MMIO region of subchannel information * @cp: channel program for the current I/O operation * @irb: irb info received from interrupt * @scsw: scsw info @@ -42,6 +43,7 @@ struct vfio_ccw_private { struct mdev_device *mdev; struct notifier_block nb; struct ccw_io_region io_region; + struct ccw_schib_region schib_region; struct channel_program cp; struct irb irb; @@ -76,6 +78,7 @@ enum vfio_ccw_event { VFIO_CCW_EVENT_NOT_OPER, VFIO_CCW_EVENT_IO_REQ, VFIO_CCW_EVENT_INTERRUPT, + VFIO_CCW_EVENT_UPDATE_SUBCH, /* last element! */ NR_VFIO_CCW_EVENTS }; diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h index e3301dbd27d4..c60244debf71 100644 --- a/include/uapi/linux/vfio.h +++ b/include/uapi/linux/vfio.h @@ -457,6 +457,7 @@ enum { enum { VFIO_CCW_CONFIG_REGION_INDEX, + VFIO_CCW_SCHIB_REGION_INDEX, VFIO_CCW_NUM_REGIONS }; diff --git a/include/uapi/linux/vfio_ccw.h b/include/uapi/linux/vfio_ccw.h index 2ec5f367ff78..12508ef6e6fc 100644 --- a/include/uapi/linux/vfio_ccw.h +++ b/include/uapi/linux/vfio_ccw.h @@ -22,4 +22,10 @@ struct ccw_io_region { __u32 ret_code; } __packed; +struct ccw_schib_region { + __u8 cc; +#define SCHIB_AREA_SIZE 52 + __u8 schib_area[SCHIB_AREA_SIZE]; +} __packed; + #endif From patchwork Thu Jan 11 03:04:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dong Jia Shi X-Patchwork-Id: 858751 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zH9jx0W1Dz9t3h for ; Thu, 11 Jan 2018 14:05:41 +1100 (AEDT) Received: from localhost ([::1]:34119 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eZTBT-0004LS-3z for incoming@patchwork.ozlabs.org; Wed, 10 Jan 2018 22:05:39 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44049) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eZTAX-0004JA-Fl for qemu-devel@nongnu.org; Wed, 10 Jan 2018 22:04:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eZTAU-0002Ja-6E for qemu-devel@nongnu.org; Wed, 10 Jan 2018 22:04:41 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:53974 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 1eZTAU-0002J2-2X for qemu-devel@nongnu.org; Wed, 10 Jan 2018 22:04:38 -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 w0B34DZ5012629 for ; Wed, 10 Jan 2018 22:04:35 -0500 Received: from e36.co.us.ibm.com (e36.co.us.ibm.com [32.97.110.154]) by mx0b-001b2d01.pphosted.com with ESMTP id 2fdxuv9wwt-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 10 Jan 2018 22:04:35 -0500 Received: from localhost by e36.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 10 Jan 2018 20:04:34 -0700 Received: from b03cxnp08026.gho.boulder.ibm.com (9.17.130.18) by e36.co.us.ibm.com (192.168.1.136) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 10 Jan 2018 20:04:31 -0700 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 w0B34SxN12583364; Wed, 10 Jan 2018 20:04:31 -0700 Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0134E7803F; Wed, 10 Jan 2018 20:04:31 -0700 (MST) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP id 59FAB7804D; Wed, 10 Jan 2018 20:04:29 -0700 (MST) From: Dong Jia Shi To: linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org, kvm@vger.kernel.org, qemu-devel@nongnu.org, qemu-s390x@nongnu.org Date: Thu, 11 Jan 2018 04:04:20 +0100 X-Mailer: git-send-email 2.13.5 In-Reply-To: <20180111030421.31418-1-bjsdjshi@linux.vnet.ibm.com> References: <20180111030421.31418-1-bjsdjshi@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18011103-0020-0000-0000-00000D492D4D X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008357; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000245; SDB=6.00973252; UDB=6.00493124; IPR=6.00753202; BA=6.00005772; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00018971; XFM=3.00000015; UTC=2018-01-11 03:04:33 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18011103-0021-0000-0000-00005FA3977D Message-Id: <20180111030421.31418-3-bjsdjshi@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2018-01-11_02:, , 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 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1801110036 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [RFC PATCH 2/3] vfio: ccw: introduce channel path irq X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: borntraeger@de.ibm.com, bjsdjshi@linux.vnet.ibm.com, cohuck@redhat.com, pmorel@linux.vnet.ibm.com, pasic@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This introduces a new irq for vfio-ccw to provide channel path related event for userland. Signed-off-by: Dong Jia Shi --- drivers/s390/cio/vfio_ccw_ops.c | 29 +++++++++++++++++++++-------- drivers/s390/cio/vfio_ccw_private.h | 2 ++ include/uapi/linux/vfio.h | 1 + 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_ops.c index 9528fce2e7d9..972cfc8834fc 100644 --- a/drivers/s390/cio/vfio_ccw_ops.c +++ b/drivers/s390/cio/vfio_ccw_ops.c @@ -275,17 +275,20 @@ static int vfio_ccw_mdev_get_region_info(struct vfio_region_info *info, static int vfio_ccw_mdev_get_irq_info(struct vfio_irq_info *info) { - if (info->index != VFIO_CCW_IO_IRQ_INDEX) + switch (info->index) { + case VFIO_CCW_IO_IRQ_INDEX: + case VFIO_CCW_CHP_IRQ_INDEX: + info->count = 1; + info->flags = VFIO_IRQ_INFO_EVENTFD; + return 0; + default: return -EINVAL; - - info->count = 1; - info->flags = VFIO_IRQ_INFO_EVENTFD; - - return 0; + } } static int vfio_ccw_mdev_set_irqs(struct mdev_device *mdev, uint32_t flags, + unsigned index, void __user *data) { struct vfio_ccw_private *private; @@ -295,7 +298,17 @@ static int vfio_ccw_mdev_set_irqs(struct mdev_device *mdev, return -EINVAL; private = dev_get_drvdata(mdev_parent_dev(mdev)); - ctx = &private->io_trigger; + + switch (index) { + case VFIO_CCW_IO_IRQ_INDEX: + ctx = &private->io_trigger; + break; + case VFIO_CCW_CHP_IRQ_INDEX: + ctx = &private->chp_trigger; + break; + default: + return -EINVAL; + } switch (flags & VFIO_IRQ_SET_DATA_TYPE_MASK) { case VFIO_IRQ_SET_DATA_NONE: @@ -433,7 +446,7 @@ static ssize_t vfio_ccw_mdev_ioctl(struct mdev_device *mdev, return ret; data = (void __user *)(arg + minsz); - return vfio_ccw_mdev_set_irqs(mdev, hdr.flags, data); + return vfio_ccw_mdev_set_irqs(mdev, hdr.flags, hdr.index, data); } case VFIO_DEVICE_RESET: return vfio_ccw_mdev_reset(mdev); diff --git a/drivers/s390/cio/vfio_ccw_private.h b/drivers/s390/cio/vfio_ccw_private.h index 460c8b90d834..da86f82dd7b9 100644 --- a/drivers/s390/cio/vfio_ccw_private.h +++ b/drivers/s390/cio/vfio_ccw_private.h @@ -33,6 +33,7 @@ * @irb: irb info received from interrupt * @scsw: scsw info * @io_trigger: eventfd ctx for signaling userspace I/O results + * @chp_trigger: eventfd ctx for signaling userspace chp event * @io_work: work for deferral process of I/O handling */ struct vfio_ccw_private { @@ -50,6 +51,7 @@ struct vfio_ccw_private { union scsw scsw; struct eventfd_ctx *io_trigger; + struct eventfd_ctx *chp_trigger; struct work_struct io_work; } __aligned(8); diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h index c60244debf71..179a7492d53a 100644 --- a/include/uapi/linux/vfio.h +++ b/include/uapi/linux/vfio.h @@ -463,6 +463,7 @@ enum { enum { VFIO_CCW_IO_IRQ_INDEX, + VFIO_CCW_CHP_IRQ_INDEX, VFIO_CCW_NUM_IRQS }; From patchwork Thu Jan 11 03:04:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dong Jia Shi X-Patchwork-Id: 858755 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zH9my2f5rz9t3h for ; Thu, 11 Jan 2018 14:08:18 +1100 (AEDT) Received: from localhost ([::1]:34145 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eZTE0-0006qX-Al for incoming@patchwork.ozlabs.org; Wed, 10 Jan 2018 22:08:16 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44136) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eZTAc-0004LV-Be for qemu-devel@nongnu.org; Wed, 10 Jan 2018 22:04:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eZTAX-0002Mi-Ks for qemu-devel@nongnu.org; Wed, 10 Jan 2018 22:04:46 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:34552 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 1eZTAX-0002M8-Fm for qemu-devel@nongnu.org; Wed, 10 Jan 2018 22:04:41 -0500 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w0B34G9i143683 for ; Wed, 10 Jan 2018 22:04:39 -0500 Received: from e34.co.us.ibm.com (e34.co.us.ibm.com [32.97.110.152]) by mx0b-001b2d01.pphosted.com with ESMTP id 2fdxsca22f-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 10 Jan 2018 22:04:38 -0500 Received: from localhost by e34.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 10 Jan 2018 20:04:38 -0700 Received: from b03cxnp08026.gho.boulder.ibm.com (9.17.130.18) by e34.co.us.ibm.com (192.168.1.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 10 Jan 2018 20:04:34 -0700 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 w0B34Sxb12583364; Wed, 10 Jan 2018 20:04:34 -0700 Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DF14B78059; Wed, 10 Jan 2018 20:04:33 -0700 (MST) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP id 4386C78041; Wed, 10 Jan 2018 20:04:32 -0700 (MST) From: Dong Jia Shi To: linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org, kvm@vger.kernel.org, qemu-devel@nongnu.org, qemu-s390x@nongnu.org Date: Thu, 11 Jan 2018 04:04:21 +0100 X-Mailer: git-send-email 2.13.5 In-Reply-To: <20180111030421.31418-1-bjsdjshi@linux.vnet.ibm.com> References: <20180111030421.31418-1-bjsdjshi@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18011103-0016-0000-0000-000008182F2C X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008357; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000245; SDB=6.00973252; UDB=6.00493123; IPR=6.00753202; BA=6.00005772; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00018971; XFM=3.00000015; UTC=2018-01-11 03:04:36 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18011103-0017-0000-0000-00003CFE208D Message-Id: <20180111030421.31418-4-bjsdjshi@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2018-01-11_02:, , 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 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1801110036 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [RFC PATCH 3/3] vfio: ccw: handle chp event X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: borntraeger@de.ibm.com, bjsdjshi@linux.vnet.ibm.com, cohuck@redhat.com, pmorel@linux.vnet.ibm.com, pasic@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This adds channel path related event handler for vfio-ccw. This also signals userland when there is a chp event. Signed-off-by: Dong Jia Shi --- drivers/s390/cio/vfio_ccw_drv.c | 51 +++++++++++++++++++++++++++++++++++++ drivers/s390/cio/vfio_ccw_fsm.c | 22 ++++++++++++++++ drivers/s390/cio/vfio_ccw_private.h | 3 +++ 3 files changed, 76 insertions(+) diff --git a/drivers/s390/cio/vfio_ccw_drv.c b/drivers/s390/cio/vfio_ccw_drv.c index ea6a2d0b2894..5f01f3e6742d 100644 --- a/drivers/s390/cio/vfio_ccw_drv.c +++ b/drivers/s390/cio/vfio_ccw_drv.c @@ -17,6 +17,7 @@ #include +#include "chp.h" #include "ioasm.h" #include "css.h" #include "vfio_ccw_private.h" @@ -88,6 +89,15 @@ static void vfio_ccw_sch_io_todo(struct work_struct *work) private->state = VFIO_CCW_STATE_IDLE; } +static void vfio_ccw_sch_chp_todo(struct work_struct *work) +{ + struct vfio_ccw_private *private = + container_of(work, struct vfio_ccw_private, chp_work); + + if (private->chp_trigger) + eventfd_signal(private->chp_trigger, 1); +} + /* * Css driver callbacks */ @@ -130,6 +140,7 @@ static int vfio_ccw_sch_probe(struct subchannel *sch) goto out_disable; INIT_WORK(&private->io_work, vfio_ccw_sch_io_todo); + INIT_WORK(&private->chp_work, vfio_ccw_sch_chp_todo); atomic_set(&private->avail, 1); private->state = VFIO_CCW_STATE_STANDBY; @@ -202,6 +213,45 @@ static int vfio_ccw_sch_event(struct subchannel *sch, int process) return 0; } +static int vfio_ccw_sch_chp_event(struct subchannel *sch, + struct chp_link *link, int event) +{ + struct vfio_ccw_private *private = dev_get_drvdata(&sch->dev); + int mask = chp_ssd_get_mask(&sch->ssd_info, link); + + /* move these checks around? */ + if (!private || !mask) + return 0; + + if (cio_update_schib(sch)) + return -ENODEV; + + switch (event) { + case CHP_VARY_OFF: + sch->opm &= ~mask; + sch->lpm &= ~mask; + /* TODO: terminate current I/O on path. */ + break; + case CHP_VARY_ON: + sch->opm |= mask; + sch->lpm |= mask; + break; + case CHP_OFFLINE: + /* TODO: terminate current I/O on path. */ + break; + case CHP_ONLINE: + sch->lpm |= mask & sch->opm; + break; + default: + /* Not possible? */ + return 0; + } + + vfio_ccw_fsm_event(private, VFIO_CCW_EVENT_UPDATE_CHP); + + return 0; +} + static struct css_device_id vfio_ccw_sch_ids[] = { { .match_flags = 0x1, .type = SUBCHANNEL_TYPE_IO, }, { /* end of list */ }, @@ -219,6 +269,7 @@ static struct css_driver vfio_ccw_sch_driver = { .remove = vfio_ccw_sch_remove, .shutdown = vfio_ccw_sch_shutdown, .sch_event = vfio_ccw_sch_event, + .chp_event = vfio_ccw_sch_chp_event, }; static int __init vfio_ccw_sch_init(void) diff --git a/drivers/s390/cio/vfio_ccw_fsm.c b/drivers/s390/cio/vfio_ccw_fsm.c index be081ccabea3..c400021134cb 100644 --- a/drivers/s390/cio/vfio_ccw_fsm.c +++ b/drivers/s390/cio/vfio_ccw_fsm.c @@ -188,6 +188,23 @@ static void fsm_update_subch(struct vfio_ccw_private *private, sizeof(sch->schib)); } +static void fsm_update_chp(struct vfio_ccw_private *private, + enum vfio_ccw_event event) +{ + queue_work(vfio_ccw_work_q, &private->chp_work); + +} + +static void fsm_update_chp_busy(struct vfio_ccw_private *private, + enum vfio_ccw_event event) +{ + /* + * TODO: + * If we are having I/O on the current path, do + * extra handling? + */ +} + /* * Device statemachine */ @@ -197,29 +214,34 @@ fsm_func_t *vfio_ccw_jumptable[NR_VFIO_CCW_STATES][NR_VFIO_CCW_EVENTS] = { [VFIO_CCW_EVENT_IO_REQ] = fsm_io_error, [VFIO_CCW_EVENT_INTERRUPT] = fsm_disabled_irq, [VFIO_CCW_EVENT_UPDATE_SUBCH] = fsm_update_subch, + [VFIO_CCW_EVENT_UPDATE_CHP] = fsm_nop, }, [VFIO_CCW_STATE_STANDBY] = { [VFIO_CCW_EVENT_NOT_OPER] = fsm_notoper, [VFIO_CCW_EVENT_IO_REQ] = fsm_io_error, [VFIO_CCW_EVENT_INTERRUPT] = fsm_irq, [VFIO_CCW_EVENT_UPDATE_SUBCH] = fsm_update_subch, + [VFIO_CCW_EVENT_UPDATE_CHP] = fsm_update_chp, }, [VFIO_CCW_STATE_IDLE] = { [VFIO_CCW_EVENT_NOT_OPER] = fsm_notoper, [VFIO_CCW_EVENT_IO_REQ] = fsm_io_request, [VFIO_CCW_EVENT_INTERRUPT] = fsm_irq, [VFIO_CCW_EVENT_UPDATE_SUBCH] = fsm_update_subch, + [VFIO_CCW_EVENT_UPDATE_CHP] = fsm_update_chp, }, [VFIO_CCW_STATE_BOXED] = { [VFIO_CCW_EVENT_NOT_OPER] = fsm_notoper, [VFIO_CCW_EVENT_IO_REQ] = fsm_io_busy, [VFIO_CCW_EVENT_INTERRUPT] = fsm_irq, [VFIO_CCW_EVENT_UPDATE_SUBCH] = fsm_update_subch, + [VFIO_CCW_EVENT_UPDATE_CHP] = fsm_update_chp, }, [VFIO_CCW_STATE_BUSY] = { [VFIO_CCW_EVENT_NOT_OPER] = fsm_notoper, [VFIO_CCW_EVENT_IO_REQ] = fsm_io_busy, [VFIO_CCW_EVENT_INTERRUPT] = fsm_irq, [VFIO_CCW_EVENT_UPDATE_SUBCH] = fsm_update_subch, + [VFIO_CCW_EVENT_UPDATE_CHP] = fsm_update_chp_busy, }, }; diff --git a/drivers/s390/cio/vfio_ccw_private.h b/drivers/s390/cio/vfio_ccw_private.h index da86f82dd7b9..e3bdb90555fb 100644 --- a/drivers/s390/cio/vfio_ccw_private.h +++ b/drivers/s390/cio/vfio_ccw_private.h @@ -35,6 +35,7 @@ * @io_trigger: eventfd ctx for signaling userspace I/O results * @chp_trigger: eventfd ctx for signaling userspace chp event * @io_work: work for deferral process of I/O handling + * @chp_work: work for deferral process of chp event */ struct vfio_ccw_private { struct subchannel *sch; @@ -53,6 +54,7 @@ struct vfio_ccw_private { struct eventfd_ctx *io_trigger; struct eventfd_ctx *chp_trigger; struct work_struct io_work; + struct work_struct chp_work; } __aligned(8); extern int vfio_ccw_mdev_reg(struct subchannel *sch); @@ -81,6 +83,7 @@ enum vfio_ccw_event { VFIO_CCW_EVENT_IO_REQ, VFIO_CCW_EVENT_INTERRUPT, VFIO_CCW_EVENT_UPDATE_SUBCH, + VFIO_CCW_EVENT_UPDATE_CHP, /* last element! */ NR_VFIO_CCW_EVENTS };