From patchwork Thu Sep 9 19:38:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12483751 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 86614C433F5 for ; Thu, 9 Sep 2021 19:38:57 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 47C6860724 for ; Thu, 9 Sep 2021 19:38:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 47C6860724 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id F39E76E902; Thu, 9 Sep 2021 19:38:54 +0000 (UTC) Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2069.outbound.protection.outlook.com [40.107.94.69]) by gabe.freedesktop.org (Postfix) with ESMTPS id B51326E902; Thu, 9 Sep 2021 19:38:53 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZV4BbcYxOpltNyhU8EkgLTA6ppag/sfzUYt6d+xyEFZJaWi7k/J0A+srBZOQ8BZJ+D4cPjTDzeytTwGXmoy5fByg72XGgCbfoOqjWSi9iWO3KQ61BgLNLaxLLLhU6COVSNgJkJX8YIDPVr/lsp8OspTWKCvYWXPaZV2YZH25/0mNlauHfpP0ZC3rl69zS1ysrIjgSXAkvTkzNnLBe6s7QK+m+SasprY5uhd7auVEtRTsNHq0oTx1PHEFVlduBg94RjB526GZFPKjBYU+ymq38G+Ky2bIItw+/l0gU65lgXdKc/gwkRb3FlclXBFwN1jkkd5QS91fPJkeiVKngton7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=t+aqtnffIc+ODHGNQ+ZcN7HzL9sugI+shny/gi5cWVI=; b=cOcECrOlf/ouX9sxILVhY6L3HHqMz++349czXMwgIqAwXCzRrUbfymKlORIDtq7mQ36Ghhy2k1ZylzBhqTNhUeX5dZSj3jVRvoAp51lKm8f4np0aF9wh5bYpE5v/GTfBQ/n7mi3ftcmylMy+DNSb0ZwP1w5iERp6IxrBGoXt3JTt/PfLmvFgtTFTCGenuPTsqbd77oHUgJwW309qLMLtrhrcnhBRC+orCpsHH5E9vPQtKhkMWTePq4wDp3INJkMPazzMbh2BrcVXMjryOTU5OPLWPo+yUU/qw3mOEoSX4mOGa2fno6puRLMkRFGrCM7aZZMTZR9rEgr5jRYkVfZ5aA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=t+aqtnffIc+ODHGNQ+ZcN7HzL9sugI+shny/gi5cWVI=; b=DEQgAjSQiPas9GodyYherLxQlGcvDhYuHHdIUZTedj+3u2S8iDJccFYHppc/imRCLgWUutNAlBkv2Lm8WPIY5dYXvoPhJpu1efsQGL2YMZiGv8rRoxVDprqP9Y9lKEH//JGLrlmRLNVq9cAa/GfAm3V+a4kq2NC98djqlA2wbkQ6gH3S70tu6esfgezlfuz7XSHa92etLUPFx24bfoj3wGfKSMiTi397btoVaXrnURPvHeJoIixi+ADgihL+UIyrXDxfneI8WcoDAhZ8+70Mo0qeZ2P+hqd9dhr0KPhU7dt5XEbEzNOZlvLbmmXajg0h+NdFfxXjgw83SSr68ebMyg== Authentication-Results: linux.ie; dkim=none (message not signed) header.d=none;linux.ie; dmarc=none action=none header.from=nvidia.com; Received: from BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) by BL0PR12MB5554.namprd12.prod.outlook.com (2603:10b6:208:1cd::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14; Thu, 9 Sep 2021 19:38:51 +0000 Received: from BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::e8af:232:915e:2f95]) by BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::e8af:232:915e:2f95%8]) with mapi id 15.20.4500.014; Thu, 9 Sep 2021 19:38:51 +0000 From: Jason Gunthorpe To: David Airlie , Tony Krowiak , Alex Williamson , Christian Borntraeger , Cornelia Huck , Daniel Vetter , dri-devel@lists.freedesktop.org, Eric Farman , Harald Freudenberger , Vasily Gorbik , Heiko Carstens , intel-gfx@lists.freedesktop.org, intel-gvt-dev@lists.freedesktop.org, Jani Nikula , Jason Herne , Joonas Lahtinen , kvm@vger.kernel.org, Kirti Wankhede , linux-s390@vger.kernel.org, Matthew Rosato , Peter Oberparleiter , Halil Pasic , Rodrigo Vivi , Vineeth Vijayan , Zhenyu Wang , Zhi Wang Cc: Christoph Hellwig Date: Thu, 9 Sep 2021 16:38:41 -0300 Message-Id: <1-v2-7d3a384024cf+2060-ccw_mdev_jgg@nvidia.com> In-Reply-To: <0-v2-7d3a384024cf+2060-ccw_mdev_jgg@nvidia.com> References: X-ClientProxiedBy: BL0PR0102CA0014.prod.exchangelabs.com (2603:10b6:207:18::27) To BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) MIME-Version: 1.0 Received: from mlx.ziepe.ca (142.162.113.129) by BL0PR0102CA0014.prod.exchangelabs.com (2603:10b6:207:18::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Thu, 9 Sep 2021 19:38:50 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1mOPsn-00FLEm-Er; Thu, 09 Sep 2021 16:38:49 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a03f67ff-0235-4be2-3ef3-08d973c972e6 X-MS-TrafficTypeDiagnostic: BL0PR12MB5554: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:785; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: iymeWsxLJn+yW2wA9SXFOULJHJB4n6It2iQ+aHsEezN+d0e6SIfO/zitVmGYTQyB1TanFXDQjrzBmoepbhck5NLaB4OB3A8+MtubPyicW/fisOLrcKErKifwNUydIqtKPwzNjj6it9AmKZnieQ4TrhRP5Yc1OgQ5kii1jXDpbCcrQIshEpzP8vWeJkkAZZScKv9uGxyGN8ZRHaorxLc70Vdsr12PRwsp3oFb1z1JvmlwzdBID9nQEOCo3CeTgzfDwbuwe3uvpcPMxyS3tVtM9tQ9EMJ0BNFgTNefDFl7ZGMIAd9x/5I7XZdFRFyFxYJamGExwpaw7ENvf+BRelyhJFfAwn6Vk+ie2ER4h45butQV97dDPzFlwAW34drlengpWXtO6EOjXqj7z+o/9vJSy5IL7YVAfv0Tcvy0PPlrpGq4Hzps6TBV4TWXDe2PhOUcob75lV4nOAwacU+WMUEXC/fi0znOhAtPNyKz0lyQK2/NZnWRQwXvonF61q7i4lleoa1Aa1KCtqDDYybT0W7PGoHeq5VnN3LLMfHHAjfXEotcoTAKpd2ODbWbjN8MkD2Y+gKoZRFmOHgRWkXkyGn50dCEtoSpiDeiyPB66mt/EKXFSgxSw8cAIGsLkWwIS3LslB/R3OUswu3CHRsal5/YOtJ2Z7+e3IZntvQmSJ4UhcRxpS1apvoUjUXGVstiJyNAGWbjMVc0rKUV5/SyP9YOlw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BL0PR12MB5506.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(7416002)(26005)(4326008)(2616005)(66556008)(921005)(66476007)(426003)(66946007)(9746002)(9786002)(5660300002)(186003)(83380400001)(86362001)(508600001)(8936002)(6666004)(110136005)(38100700002)(36756003)(316002)(8676002)(2906002)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ys1Qt640n+Gtp5z6GkIm0GpkINRpw8hap1axFqpOK93Fz4Kmo7JrDOvGcTAN+rB8zhTTHpWnqql37mmwr0I4+aUmELsRHJCz6gn4/jHC0T2qBHl/hiSp6BmP53OYeT5A71CyuEdadXdgYOVmGxlUFlqeZMsgm1vB7Bu/EXv71fibAYmJWpUPuPqhfMKbe8XkbJ7aMAQmet0fh86enA4teNtPNvpOhjfYQpr8T58tzMaZPNUcF02ZQjjH8h7lo4XKg8Z8XcWokkCst85/jkOQ1ffakUoX2sUWiD2gV/FBOqZWURcdW+2+Nci1/q4Glm6wnzajFgcANj+/FLUbDKqnx1Qp3NQhSpNoQNG5cyFfrFbYFCv+PgIFlEIPFN7CFPHFLqNXGTznEnmulSHf3hTYAN0CS+VLagdnoTc5K/yz/cnA01PkxG/feQMTR/ncbfiixz6zwih+FqhVjafNrRpMBL7h9Dxd6a/61O0ekkPw47lmlIM6IJDA+I+hpHdURZ8R6NNYfM5B00NyNU8ICY6qXTnqFiKa+vAuTgVdVhxFrlF5NbdoYwHmo5W/vJ6C0PHCofp05xP2lPyfGOCjSOB3/TTRApkGMwmVTVG8ISmznxLMo4Om36N4Dy4tWDf2Fxnhh1aNGK5SdmKlV0sOiDspbL1SzlAmaf9tb6c1BPFWcXncRcyz6OWCuqxg7LXVagvCrw43jCIER7IbwPwIv4W+eXRPZyWSc9SGeTDLxPicfOL11vvBYzTWTDatUKGo+CPu X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: a03f67ff-0235-4be2-3ef3-08d973c972e6 X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Sep 2021 19:38:50.6244 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 7PuTAAcT6OCdIXxlh/p7Qbt91D4vWrmUfUs9v5mQLkbTEziRYvRqRsp/2OLeJvBF X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB5554 Subject: [Intel-gfx] [PATCH v2 1/9] vfio/ccw: Use functions for alloc/free of the vfio_ccw_private X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Makes the code easier to understand what is memory lifecycle and what is other stuff. Signed-off-by: Jason Gunthorpe Reported-by: Christoph Hellwig Signed-off-by: Jason Gunthorpe Reviewed-by: Eric Farman --- drivers/s390/cio/vfio_ccw_drv.c | 137 ++++++++++++++++++-------------- 1 file changed, 78 insertions(+), 59 deletions(-) diff --git a/drivers/s390/cio/vfio_ccw_drv.c b/drivers/s390/cio/vfio_ccw_drv.c index 9b61e9b131ade0..1e8d3151e5480e 100644 --- a/drivers/s390/cio/vfio_ccw_drv.c +++ b/drivers/s390/cio/vfio_ccw_drv.c @@ -137,16 +137,80 @@ static void vfio_ccw_sch_irq(struct subchannel *sch) vfio_ccw_fsm_event(private, VFIO_CCW_EVENT_INTERRUPT); } -static void vfio_ccw_free_regions(struct vfio_ccw_private *private) +static struct vfio_ccw_private *vfio_ccw_alloc_private(struct subchannel *sch) { - if (private->crw_region) - kmem_cache_free(vfio_ccw_crw_region, private->crw_region); - if (private->schib_region) - kmem_cache_free(vfio_ccw_schib_region, private->schib_region); - if (private->cmd_region) - kmem_cache_free(vfio_ccw_cmd_region, private->cmd_region); - if (private->io_region) - kmem_cache_free(vfio_ccw_io_region, private->io_region); + struct vfio_ccw_private *private; + + private = kzalloc(sizeof(*private), GFP_KERNEL | GFP_DMA); + if (!private) + return ERR_PTR(-ENOMEM); + + private->sch = sch; + mutex_init(&private->io_mutex); + private->state = VFIO_CCW_STATE_NOT_OPER; + INIT_LIST_HEAD(&private->crw); + INIT_WORK(&private->io_work, vfio_ccw_sch_io_todo); + INIT_WORK(&private->crw_work, vfio_ccw_crw_todo); + atomic_set(&private->avail, 1); + + private->cp.guest_cp = kcalloc(CCWCHAIN_LEN_MAX, sizeof(struct ccw1), + GFP_KERNEL); + if (!private->cp.guest_cp) + goto out_free_private; + + private->io_region = kmem_cache_zalloc(vfio_ccw_io_region, + GFP_KERNEL | GFP_DMA); + if (!private->io_region) + goto out_free_cp; + + private->cmd_region = kmem_cache_zalloc(vfio_ccw_cmd_region, + GFP_KERNEL | GFP_DMA); + if (!private->cmd_region) + goto out_free_io; + + private->schib_region = kmem_cache_zalloc(vfio_ccw_schib_region, + GFP_KERNEL | GFP_DMA); + + if (!private->schib_region) + goto out_free_cmd; + + private->crw_region = kmem_cache_zalloc(vfio_ccw_crw_region, + GFP_KERNEL | GFP_DMA); + + if (!private->crw_region) + goto out_free_schib; + return private; + +out_free_schib: + kmem_cache_free(vfio_ccw_schib_region, private->schib_region); +out_free_cmd: + kmem_cache_free(vfio_ccw_cmd_region, private->cmd_region); +out_free_io: + kmem_cache_free(vfio_ccw_io_region, private->io_region); +out_free_cp: + kfree(private->cp.guest_cp); +out_free_private: + mutex_destroy(&private->io_mutex); + kfree(private); + return ERR_PTR(-ENOMEM); +} + +static void vfio_ccw_free_private(struct vfio_ccw_private *private) +{ + struct vfio_ccw_crw *crw, *temp; + + list_for_each_entry_safe(crw, temp, &private->crw, next) { + list_del(&crw->next); + kfree(crw); + } + + kmem_cache_free(vfio_ccw_crw_region, private->crw_region); + kmem_cache_free(vfio_ccw_schib_region, private->schib_region); + kmem_cache_free(vfio_ccw_cmd_region, private->cmd_region); + kmem_cache_free(vfio_ccw_io_region, private->io_region); + kfree(private->cp.guest_cp); + mutex_destroy(&private->io_mutex); + kfree(private); } static int vfio_ccw_sch_probe(struct subchannel *sch) @@ -161,53 +225,19 @@ static int vfio_ccw_sch_probe(struct subchannel *sch) return -ENODEV; } - private = kzalloc(sizeof(*private), GFP_KERNEL | GFP_DMA); - if (!private) - return -ENOMEM; + private = vfio_ccw_alloc_private(sch); + if (IS_ERR(private)) + return PTR_ERR(private); - private->cp.guest_cp = kcalloc(CCWCHAIN_LEN_MAX, sizeof(struct ccw1), - GFP_KERNEL); - if (!private->cp.guest_cp) - goto out_free; - - private->io_region = kmem_cache_zalloc(vfio_ccw_io_region, - GFP_KERNEL | GFP_DMA); - if (!private->io_region) - goto out_free; - - private->cmd_region = kmem_cache_zalloc(vfio_ccw_cmd_region, - GFP_KERNEL | GFP_DMA); - if (!private->cmd_region) - goto out_free; - - private->schib_region = kmem_cache_zalloc(vfio_ccw_schib_region, - GFP_KERNEL | GFP_DMA); - - if (!private->schib_region) - goto out_free; - - private->crw_region = kmem_cache_zalloc(vfio_ccw_crw_region, - GFP_KERNEL | GFP_DMA); - - if (!private->crw_region) - goto out_free; - - private->sch = sch; dev_set_drvdata(&sch->dev, private); - mutex_init(&private->io_mutex); spin_lock_irq(sch->lock); - private->state = VFIO_CCW_STATE_NOT_OPER; sch->isc = VFIO_CCW_ISC; ret = cio_enable_subchannel(sch, (u32)(unsigned long)sch); spin_unlock_irq(sch->lock); if (ret) goto out_free; - INIT_LIST_HEAD(&private->crw); - INIT_WORK(&private->io_work, vfio_ccw_sch_io_todo); - INIT_WORK(&private->crw_work, vfio_ccw_crw_todo); - atomic_set(&private->avail, 1); private->state = VFIO_CCW_STATE_STANDBY; ret = vfio_ccw_mdev_reg(sch); @@ -228,31 +258,20 @@ static int vfio_ccw_sch_probe(struct subchannel *sch) cio_disable_subchannel(sch); out_free: dev_set_drvdata(&sch->dev, NULL); - vfio_ccw_free_regions(private); - kfree(private->cp.guest_cp); - kfree(private); + vfio_ccw_free_private(private); return ret; } static int vfio_ccw_sch_remove(struct subchannel *sch) { struct vfio_ccw_private *private = dev_get_drvdata(&sch->dev); - struct vfio_ccw_crw *crw, *temp; vfio_ccw_sch_quiesce(sch); - - list_for_each_entry_safe(crw, temp, &private->crw, next) { - list_del(&crw->next); - kfree(crw); - } - vfio_ccw_mdev_unreg(sch); dev_set_drvdata(&sch->dev, NULL); - vfio_ccw_free_regions(private); - kfree(private->cp.guest_cp); - kfree(private); + vfio_ccw_free_private(private); VFIO_CCW_MSG_EVENT(4, "unbound from subchannel %x.%x.%04x\n", sch->schid.cssid, sch->schid.ssid, From patchwork Thu Sep 9 19:38:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12483757 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BA7DCC433F5 for ; Thu, 9 Sep 2021 19:39:10 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8A47B60724 for ; Thu, 9 Sep 2021 19:39:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 8A47B60724 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 603106E912; Thu, 9 Sep 2021 19:38:56 +0000 (UTC) Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2069.outbound.protection.outlook.com [40.107.94.69]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7F8E46E904; Thu, 9 Sep 2021 19:38:54 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZlUj6HWxRVhCTf/sfOTWjTrQiimpmtjs7sMoUaYt2IYsoh7aRYEgGtVfz2AZjIiC9TphKAOTpbAEdb65ea8mFE7FmLH6zgCmC58KNq0YoFDfkCKeHWDSyxQicp+NifUH0vRBBMIDyhPkneiDmT23bBRyMMu0erTRmGQT00Z0RZ8YJk+pPPpS7OF5itp+M6dgXgQ5Cdfxr8B9XPOHgvXpnEsbdLsS/6u1FCCermB6rSUEPUpOtKNNpOHnOfYm/BPYtJl8dUaV4HPhZId6VhJUw4prZHoajMKnmpkeTvLDI4cLTt1Ej+yfFrxLf8/UA/+S6JbB+v7MiEgTJb6XWMHl1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=PcKn49kuKzyqjQONMR21sMOn8A5Ij+fUrsNk+dyCDro=; b=IUYs7zAF+39GrZh5ZL8+f4qg2XbDDW4T+6G/25TikuuGcsfv63W3yFqFSjtMpLyAiyRDhXrrpEbB7oBOq0793/3ujhmWaboaM2Wvht7/K9JUqlCMfEjes6F+Zjo/mSMdyphb5AxuK5yzJWM/+8clKFaWspXWjTwlXhy2reH4mgbzhSNHHh6YtO/U5jMd8O+ryCsvb6B431Cp49/KQWZcD6K27lI6/ppkelqcc7nNjDhTP8P6YNVnn5e8Nwkh3Om5YXg3mSQiUD9SBh5Y8Is8U3hSu5btzyjHt6fnZ1bxgq4Qofh9pFcqXQjgmL+kAgBQKhO3KS3gWVg2F0s8vjCFfg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=PcKn49kuKzyqjQONMR21sMOn8A5Ij+fUrsNk+dyCDro=; b=TQ7aS/ulLqA6vYGwCFkQozo7uKpJKEDR00gIUILRFYD0BViU7E1MadWaVJw4sur1+vuZ57GiwWBVyCl5ftfTCo/XWL+67LZWpdeX2QYlu6xGOok998+GuENHjdOapVtgHpg2aXo1XKJhehTqsHk+VNdDMDAUxgWiPZEmmNlktXHDxHiUjnlfjMSDVGQruIeNJq/dgVbWhzNAg7Xu2xK6/yINF2mcsnVMOgs1u7at5PYwYbjfZpLaLg7j6jF9IFts3aMq4Uq5f5KSZW65DXLiZVNtDTEl6AisrUWVlkcOy3U3MOndsHfx25XNlb457c/ZXyv8jVPznYQ9rK6HkEcPYQ== Authentication-Results: linux.ie; dkim=none (message not signed) header.d=none;linux.ie; dmarc=none action=none header.from=nvidia.com; Received: from BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) by BL0PR12MB5554.namprd12.prod.outlook.com (2603:10b6:208:1cd::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14; Thu, 9 Sep 2021 19:38:52 +0000 Received: from BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::e8af:232:915e:2f95]) by BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::e8af:232:915e:2f95%8]) with mapi id 15.20.4500.014; Thu, 9 Sep 2021 19:38:52 +0000 From: Jason Gunthorpe To: David Airlie , Tony Krowiak , Alex Williamson , Christian Borntraeger , Cornelia Huck , Daniel Vetter , dri-devel@lists.freedesktop.org, Eric Farman , Harald Freudenberger , Vasily Gorbik , Heiko Carstens , intel-gfx@lists.freedesktop.org, intel-gvt-dev@lists.freedesktop.org, Jani Nikula , Jason Herne , Joonas Lahtinen , kvm@vger.kernel.org, Kirti Wankhede , linux-s390@vger.kernel.org, Matthew Rosato , Peter Oberparleiter , Halil Pasic , Rodrigo Vivi , Vineeth Vijayan , Zhenyu Wang , Zhi Wang Cc: Christoph Hellwig Date: Thu, 9 Sep 2021 16:38:42 -0300 Message-Id: <2-v2-7d3a384024cf+2060-ccw_mdev_jgg@nvidia.com> In-Reply-To: <0-v2-7d3a384024cf+2060-ccw_mdev_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR18CA0021.namprd18.prod.outlook.com (2603:10b6:208:23c::26) To BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) MIME-Version: 1.0 Received: from mlx.ziepe.ca (142.162.113.129) by MN2PR18CA0021.namprd18.prod.outlook.com (2603:10b6:208:23c::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Thu, 9 Sep 2021 19:38:51 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1mOPsn-00FLEq-Fv; Thu, 09 Sep 2021 16:38:49 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6be3502a-9954-4402-b6a5-08d973c97389 X-MS-TrafficTypeDiagnostic: BL0PR12MB5554: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5236; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qEdiFgo8Ek/4THUmz45dhziOFw8DYruptiFm3NykCOjxgWXFjTTwE/57hJMjDDiQ8aXLTfUpd5AGutqJ0FcpSNge9zXPt6CeLboC07WCXIR9ahzvntFfvYtuSoBOu1MkmXBKULy1NSmzQqtrSgZEJeHIuHGDt7dNfxOiAHGxnSRC446laX1nmay6tFNeJ49ofwwbgpKWa2X0zStbY9CryP9APUVpw1NhA+oR7o3VQVaC4/VDuM+T0DpN1PC/kQqkskZ7QidqwEja017FnBaXS29mBwn4/93DGBp+Mqv28rE9P/cF9KjNp4ghKeowaSAuxQg/yh4KR8kncwBXaftnndzctPmjcPnFt3nEHNAZk4wLiX9tQ8GfiTR2ADPGXO0KPlNfSPKDd3v7H5HOqhd8j7pVbJNewHaAeSJBLXzI7UaFJDlMykO8nX/iYnXembCny0WQ4CSADK5SzYjURqQLRH2xElMubZHK9ZKwDWyr5kLfe19VvH/2o804dgFtRvhPnVzACBmsuY3Hly/AR+YYtUjO9/xvzq403/DODiemzE1ckyPbR/ysg6TXa0M9N0GY+yZj+cA0jZ/NEqpZupRXwkpjrgpjpbdj4jFR8JHVNbiKWqHoGOWWVHjmQbJhWN2xVd7gzMIyIEkgSXo5QEEn3pjRWldsznp4dNRNBvfFwRNMN1boSzIKruRO41EuQdm+d3eycglIcKaRHiVh5xLXDQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BL0PR12MB5506.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(7416002)(26005)(4326008)(2616005)(66556008)(921005)(66476007)(426003)(66946007)(9746002)(9786002)(5660300002)(186003)(83380400001)(86362001)(508600001)(8936002)(6666004)(110136005)(38100700002)(36756003)(316002)(8676002)(2906002)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: g4ZffeerMxbZy8w/Zg1j3kLMhH4CwfQgxYd516szNWVRqZh9qwhPAFoV+OkdR9XwYOsYo1ixwBMxfWY+D/Wp+6M2T0/bJb2e7yLo3742hPlMblp3IJBLTCNVfw0RY0hogTcBnOJx83bfmxIiYYhhnM8AEmgeiKm0wy8J+Q0IMfchgVW8Z4cfR6ZlXb9gaPVc3QLIXGkiosQzqnp+6+nU0rmWIxxwF8guAvsjXV1ArPKG48sGKKS3RVmIeRt4XL7Q3o1JHZYZlbnzoeSKK8USMnkx2c0BSg7+jWSFzaPRQDjuRsO/ukga+QwCL6Q0uogVTtEpNQkCjteQmFJVimq4LWgJFk3LalIDim7jM/48AA8MT5retEsw44qEh+YHx2XW1agcgEcPV5PIBxhpe+NC428IjbqeP2kCBxaB5CfNWp1Smm2mpj/HYfG8Qbpk2wTVK4phTQqfyoF8QEDyiZVpF8cU67+YTnz0P+pFvuRM/AQdLMD00mflH/8HIPeth3pKJmgHsilzO1aAP9WXJffYQ1hp/xVbQwcAjMB5DycORtPRvV/oqsNTpc6gR/NC2O9JADO8NyvImUhZzctGXdQkX1tQmoEmmczgl92EDC+wl9iVUrODD1XqdyV6NpxPNNtPnIcdZWMbufOkF2WepMZzkiYckEy/tvnDtWj2fzECxMAjfpRGAtTPOpc5d7qxm6JXqllM3VMyMsmmwJEGCDd7lFTH3TiPNdOHvjx/Pm0zWQfOzEsl6ZLKVCXPpV7HU43D X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6be3502a-9954-4402-b6a5-08d973c97389 X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Sep 2021 19:38:51.6359 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: e8WnHvk53W37epO7m8DjNK7CWqdAdSSrUlh/ECxrsOFkpBRNLGR9ffSqx45z6ri4 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB5554 Subject: [Intel-gfx] [PATCH v2 2/9] vfio/ccw: Pass vfio_ccw_private not mdev_device to various functions X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" mdev_device should only be used in functions assigned to ops callbacks, interior functions should use the struct vfio_ccw_private instead of repeatedly trying to get it from the mdev. Signed-off-by: Jason Gunthorpe Reviewed-by: Christoph Hellwig Reviewed-by: Cornelia Huck Reviewed-by: Eric Farman --- drivers/s390/cio/vfio_ccw_ops.c | 37 +++++++++++++-------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_ops.c index 7f540ad0b568bc..1edbea9de0ec42 100644 --- a/drivers/s390/cio/vfio_ccw_ops.c +++ b/drivers/s390/cio/vfio_ccw_ops.c @@ -17,13 +17,11 @@ #include "vfio_ccw_private.h" -static int vfio_ccw_mdev_reset(struct mdev_device *mdev) +static int vfio_ccw_mdev_reset(struct vfio_ccw_private *private) { - struct vfio_ccw_private *private; struct subchannel *sch; int ret; - private = dev_get_drvdata(mdev_parent_dev(mdev)); sch = private->sch; /* * TODO: @@ -61,7 +59,7 @@ static int vfio_ccw_mdev_notifier(struct notifier_block *nb, if (!cp_iova_pinned(&private->cp, unmap->iova)) return NOTIFY_OK; - if (vfio_ccw_mdev_reset(private->mdev)) + if (vfio_ccw_mdev_reset(private)) return NOTIFY_BAD; cp_free(&private->cp); @@ -201,7 +199,7 @@ static void vfio_ccw_mdev_close_device(struct mdev_device *mdev) if ((private->state != VFIO_CCW_STATE_NOT_OPER) && (private->state != VFIO_CCW_STATE_STANDBY)) { - if (!vfio_ccw_mdev_reset(mdev)) + if (!vfio_ccw_mdev_reset(private)) private->state = VFIO_CCW_STATE_STANDBY; /* The state will be NOT_OPER on error. */ } @@ -311,12 +309,9 @@ static ssize_t vfio_ccw_mdev_write(struct mdev_device *mdev, return -EINVAL; } -static int vfio_ccw_mdev_get_device_info(struct vfio_device_info *info, - struct mdev_device *mdev) +static int vfio_ccw_mdev_get_device_info(struct vfio_ccw_private *private, + struct vfio_device_info *info) { - struct vfio_ccw_private *private; - - private = dev_get_drvdata(mdev_parent_dev(mdev)); info->flags = VFIO_DEVICE_FLAGS_CCW | VFIO_DEVICE_FLAGS_RESET; info->num_regions = VFIO_CCW_NUM_REGIONS + private->num_regions; info->num_irqs = VFIO_CCW_NUM_IRQS; @@ -324,14 +319,12 @@ static int vfio_ccw_mdev_get_device_info(struct vfio_device_info *info, return 0; } -static int vfio_ccw_mdev_get_region_info(struct vfio_region_info *info, - struct mdev_device *mdev, +static int vfio_ccw_mdev_get_region_info(struct vfio_ccw_private *private, + struct vfio_region_info *info, unsigned long arg) { - struct vfio_ccw_private *private; int i; - private = dev_get_drvdata(mdev_parent_dev(mdev)); switch (info->index) { case VFIO_CCW_CONFIG_REGION_INDEX: info->offset = 0; @@ -406,19 +399,16 @@ static int vfio_ccw_mdev_get_irq_info(struct vfio_irq_info *info) return 0; } -static int vfio_ccw_mdev_set_irqs(struct mdev_device *mdev, +static int vfio_ccw_mdev_set_irqs(struct vfio_ccw_private *private, uint32_t flags, uint32_t index, void __user *data) { - struct vfio_ccw_private *private; struct eventfd_ctx **ctx; if (!(flags & VFIO_IRQ_SET_ACTION_TRIGGER)) return -EINVAL; - private = dev_get_drvdata(mdev_parent_dev(mdev)); - switch (index) { case VFIO_CCW_IO_IRQ_INDEX: ctx = &private->io_trigger; @@ -524,6 +514,8 @@ static ssize_t vfio_ccw_mdev_ioctl(struct mdev_device *mdev, unsigned int cmd, unsigned long arg) { + struct vfio_ccw_private *private = + dev_get_drvdata(mdev_parent_dev(mdev)); int ret = 0; unsigned long minsz; @@ -540,7 +532,7 @@ static ssize_t vfio_ccw_mdev_ioctl(struct mdev_device *mdev, if (info.argsz < minsz) return -EINVAL; - ret = vfio_ccw_mdev_get_device_info(&info, mdev); + ret = vfio_ccw_mdev_get_device_info(private, &info); if (ret) return ret; @@ -558,7 +550,7 @@ static ssize_t vfio_ccw_mdev_ioctl(struct mdev_device *mdev, if (info.argsz < minsz) return -EINVAL; - ret = vfio_ccw_mdev_get_region_info(&info, mdev, arg); + ret = vfio_ccw_mdev_get_region_info(private, &info, arg); if (ret) return ret; @@ -603,10 +595,11 @@ 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, hdr.index, data); + return vfio_ccw_mdev_set_irqs(private, hdr.flags, hdr.index, + data); } case VFIO_DEVICE_RESET: - return vfio_ccw_mdev_reset(mdev); + return vfio_ccw_mdev_reset(private); default: return -ENOTTY; } From patchwork Thu Sep 9 19:38:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12483765 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 156DDC433FE for ; Thu, 9 Sep 2021 19:39:31 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D8A2B6103E for ; Thu, 9 Sep 2021 19:39:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D8A2B6103E Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 67EFE6E921; Thu, 9 Sep 2021 19:39:01 +0000 (UTC) Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2060.outbound.protection.outlook.com [40.107.92.60]) by gabe.freedesktop.org (Postfix) with ESMTPS id EB2346E90F; Thu, 9 Sep 2021 19:38:55 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dLeGwE9GtlwOBlK406oiGIJaHckbMKmYLdSqL/ZDFaOslTtizTemYRq38dPUGXTjx/RebsSHeyWb4KiwB7t/nfrwfzDQfrlYnrgGtLjZaN5PS4u2GEAFx0FRCOKDn9Y7cQ745p5ZZ5YSFz6Ul6Wgpwm7Uxhs26Pq6ykquXMZ2EgKxNtkH9w037GHbOPTBGorjDgqtdu1ZfTCcHkxns6ly8XiVn5gsqBDozdBBHrsSOdVJir40QrKN31vq9jGjbCx30XSfa0kfiVxodRskvsuzs3nNstygcIicGWOGhxDrDOpbPZLCtdNJH9q1xAq0XDP8QrgL5N4AE2QnLHLvg9HLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=R84WJaW/KAq/cpRdkgMXBI+GGVfkzaF7/nuR8H6jWxc=; b=axuPY1Ms6/pdxphyL6luFRVeTH3ltvq16yYgmUGfD0F8XKBG0sUk4xDtCKPu9NQuZIHxGlNJJwjFBBeiXucLpW3bBuHsm4l8eBGLeEPA4lEk7pzxGwRTS4cmdyAsmdcuOuNGvRf03ZeAr550X4Vtd8vaD0R6D2QavnPsjFFEl980HURP65/0aNg9oi9xWsZH6UtUOWMBrvXgnCgd40BGQeljybuamJmdiKqYi7VmQixzaLM2aqO190xpmoK3QkMwg9TTC2kISTN3H2Jy21lIp/VMFM+HEgQgbzLCB4f/l/VDlcJMzJ9Xxx+WeBa3aMs1l4C8d+bFzFcyDEevclWa3g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=R84WJaW/KAq/cpRdkgMXBI+GGVfkzaF7/nuR8H6jWxc=; b=pGO9pYbltptwlDc1KbrrMektgZlnh1C0fWOvNVCu2RDzmbnGRt9NrT/77q33/HKAeRokAMqqlAc2WY4Qw2SGaMqKkhU/WMek20QEGm/+XXpjw4OWyAOBjMSs7BjqdBZyDup0LNR3N66X4lwhpmYF9Q8R5Y3izn9nXXmS+N0Oo+t3x2jMxBW1hlCeFomL4GPk54t1eDlJ9t88luI+q2uxaz/o8BLg0D/bOqYTetvaHNnCrcRYzr3JQHOdtq6IsHhbXvz6CuBFal4frSS5QgPo3qmoet4ASS/BF7PSaKG9Cwt61JGFfW/lYSD3/5OjiPGGsguKwJt7tIDKoh7IVaWnNQ== Authentication-Results: linux.ie; dkim=none (message not signed) header.d=none;linux.ie; dmarc=none action=none header.from=nvidia.com; Received: from BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) by BL0PR12MB5507.namprd12.prod.outlook.com (2603:10b6:208:1c4::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14; Thu, 9 Sep 2021 19:38:53 +0000 Received: from BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::e8af:232:915e:2f95]) by BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::e8af:232:915e:2f95%8]) with mapi id 15.20.4500.014; Thu, 9 Sep 2021 19:38:53 +0000 From: Jason Gunthorpe To: David Airlie , Tony Krowiak , Alex Williamson , Christian Borntraeger , Cornelia Huck , Daniel Vetter , dri-devel@lists.freedesktop.org, Eric Farman , Harald Freudenberger , Vasily Gorbik , Heiko Carstens , intel-gfx@lists.freedesktop.org, intel-gvt-dev@lists.freedesktop.org, Jani Nikula , Jason Herne , Joonas Lahtinen , kvm@vger.kernel.org, Kirti Wankhede , linux-s390@vger.kernel.org, Matthew Rosato , Peter Oberparleiter , Halil Pasic , Rodrigo Vivi , Vineeth Vijayan , Zhenyu Wang , Zhi Wang Cc: Christoph Hellwig Date: Thu, 9 Sep 2021 16:38:43 -0300 Message-Id: <3-v2-7d3a384024cf+2060-ccw_mdev_jgg@nvidia.com> In-Reply-To: <0-v2-7d3a384024cf+2060-ccw_mdev_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR17CA0003.namprd17.prod.outlook.com (2603:10b6:208:15e::16) To BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) MIME-Version: 1.0 Received: from mlx.ziepe.ca (142.162.113.129) by MN2PR17CA0003.namprd17.prod.outlook.com (2603:10b6:208:15e::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Thu, 9 Sep 2021 19:38:52 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1mOPsn-00FLEv-H2; Thu, 09 Sep 2021 16:38:49 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 44696f37-1424-4133-d9b1-08d973c97422 X-MS-TrafficTypeDiagnostic: BL0PR12MB5507: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3044; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6NZnACsnv/9SqklFqOm7pWnKBtX01TsIls1Lmqz5T8j/QEbOi/wu/+QCKRGdiNmNL7IBMqanFBEOR278Pa54zIGjj3uPWx6DpLbDA0czBMT5WoF0Nx1n0rh1Trc/py1/reiIRzJAM4SYlvUNxQHwh+QuUF7J8oqwyXjbojxsZ0cpEV4oMJi1Meq8kT7XcGwhTiCFZEVIQbZW62JPOf6OrisM5n9rRPIrgAdtKZEzZpQNsoYUKRo8jjPMt9xXk/koRNPqeaULOiaAfPEmY8ZttA+Axx2Oqd4wvJwKV58aiFnWCbQi6TmR27x/OwyOBylzqsHF5RNhs5FdPD6nFLQBxzfuRIU4oLOHHgrcwSaXapei/ZnT2NW3dbRME7vGT+tQrs188uGr+AGkZW1Xh5of4GFuUpTbRkMaRmZjzRwRDbkw7pBtpvDLFVzL6qRtoVE6zfsYrQTELRURGMP+c02cxtD8eJaqMJWJr81xdaGNc/bSIZHq0mO6V0P6bayHtVC0FzFL0kCmlViKgowf/dSOXrsGL52pB3uOv84G3Da+uQaO5/1bZOXgs7xoodrli4XiLli6b/eztIWpGfANkQt39DmOzNiVskp0AbftwPj3R7pudHNTALrSg0DRSm+P8ssYbzG+b3WMKL28Pk/TqdyXQDjLkOpEScj7ccNFLLoi9ccv0dVacNdzlcRlxvjzr914qVFMFGJHYNpCTWCmG7d7qQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BL0PR12MB5506.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(136003)(39860400002)(376002)(346002)(366004)(396003)(8676002)(66476007)(478600001)(4326008)(66946007)(66556008)(30864003)(8936002)(921005)(5660300002)(186003)(26005)(86362001)(83380400001)(7416002)(2906002)(36756003)(426003)(2616005)(9746002)(9786002)(110136005)(6666004)(38100700002)(316002)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: GlJgKw6w6JWxx3N7HmUNQyrxNPUxSLH8yhUrhIoByIN3rXgUfhgl9pEJPk61ijNbO3RzSu+fih64jtP4I9pCqdWWhOLmM4JkrvUowB02qpJmyzbXboIoKB89NCoDWKhs5XT5+0MQqW7iVZsQtSS0+MG2SF/m7t2Ddqqs2Xa27X5BB5DyF1A22AGz6180xQPIwtUTK1T0/Gp6daHV/tUgLglgfSuMhjkidckkLZ9A0v6PAF2SYJwDIAu/XYTuzrzflGAkBruQtTgwrqo7NBRkZOo2Mzl0VUx9kimwTu8OX49OYFuhZlMgA0aE8TyiN2z5wZDnprz9gmL9uy6mxPzOpyaMa/EH2x0hhJjuwry/dTdcDaeSVNej5gr+LMb2SL9EKUUYqkbSr/4BEiuZ/QHGt7LqFCpyh2zsoLdVTgkRnfMed20Lm8DYA0jn0V/ykQOIRv+bQaavYPR97xPPMNOziRN5iiYIiifHJHXDQAlF7ktb6JnsbQC8wLeFmspqRu/R/xIeBvsm1IwnFPLLzPH9omT269CTq2iXRMTpk07dSL2AbEoIpp8SGRKGdlYwIeZJ4IprfHQEovQe+jdtMcsjc3qa0fETEdguXsvNHDl2gKHkSQXkGx8EmGCtD9tAC5uDWBZwyn8egggpScjPSYoNTDbFu+kYyobCwMkHvRBlIZz2bXuK9miG+Kuu6QtHZGQpnuqD/CWGHgpIsvEhBHFM3V4zqMU7UMiB1sIpjqNjJW0j86m0UGk5o50v8iTXNYOM X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 44696f37-1424-4133-d9b1-08d973c97422 X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Sep 2021 19:38:52.7102 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: G1UYxlCTBRwp8LdcgXG3GDtD5x3RX/6hfgnnGrGFxjugzdFN0dklCsr2+hU4XqE2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB5507 Subject: [Intel-gfx] [PATCH v2 3/9] vfio/ccw: Convert to use vfio_register_group_dev() X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" This is a more complicated conversion because vfio_ccw is sharing the vfio_device between both the mdev_device, its vfio_device and the css_driver. The mdev is a singleton, and the reason for this sharing is so the extra css_driver function callbacks to be delivered to the vfio_device implementation. This keeps things as they are, with the css_driver allocating the singleton, not the mdev_driver. Following patches work to clean this further. Embed the vfio_device in the vfio_ccw_private and instantiate it as a vfio_device when the mdev probes. The drvdata of both the css_device and the mdev_device point at the private, and container_of is used to get it back from the vfio_device. Signed-off-by: Jason Gunthorpe --- drivers/s390/cio/vfio_ccw_drv.c | 21 ++++-- drivers/s390/cio/vfio_ccw_ops.c | 107 +++++++++++++++++----------- drivers/s390/cio/vfio_ccw_private.h | 5 ++ 3 files changed, 85 insertions(+), 48 deletions(-) diff --git a/drivers/s390/cio/vfio_ccw_drv.c b/drivers/s390/cio/vfio_ccw_drv.c index 1e8d3151e5480e..396e815f81f8a4 100644 --- a/drivers/s390/cio/vfio_ccw_drv.c +++ b/drivers/s390/cio/vfio_ccw_drv.c @@ -469,7 +469,7 @@ static int __init vfio_ccw_sch_init(void) vfio_ccw_work_q = create_singlethread_workqueue("vfio-ccw"); if (!vfio_ccw_work_q) { ret = -ENOMEM; - goto out_err; + goto out_regions; } vfio_ccw_io_region = kmem_cache_create_usercopy("vfio_ccw_io_region", @@ -478,7 +478,7 @@ static int __init vfio_ccw_sch_init(void) sizeof(struct ccw_io_region), NULL); if (!vfio_ccw_io_region) { ret = -ENOMEM; - goto out_err; + goto out_regions; } vfio_ccw_cmd_region = kmem_cache_create_usercopy("vfio_ccw_cmd_region", @@ -487,7 +487,7 @@ static int __init vfio_ccw_sch_init(void) sizeof(struct ccw_cmd_region), NULL); if (!vfio_ccw_cmd_region) { ret = -ENOMEM; - goto out_err; + goto out_regions; } vfio_ccw_schib_region = kmem_cache_create_usercopy("vfio_ccw_schib_region", @@ -497,7 +497,7 @@ static int __init vfio_ccw_sch_init(void) if (!vfio_ccw_schib_region) { ret = -ENOMEM; - goto out_err; + goto out_regions; } vfio_ccw_crw_region = kmem_cache_create_usercopy("vfio_ccw_crw_region", @@ -507,19 +507,25 @@ static int __init vfio_ccw_sch_init(void) if (!vfio_ccw_crw_region) { ret = -ENOMEM; - goto out_err; + goto out_regions; } + ret = mdev_register_driver(&vfio_ccw_mdev_driver); + if (ret) + goto out_regions; + isc_register(VFIO_CCW_ISC); ret = css_driver_register(&vfio_ccw_sch_driver); if (ret) { isc_unregister(VFIO_CCW_ISC); - goto out_err; + goto out_driver; } return ret; -out_err: +out_driver: + mdev_unregister_driver(&vfio_ccw_mdev_driver); +out_regions: vfio_ccw_destroy_regions(); destroy_workqueue(vfio_ccw_work_q); vfio_ccw_debug_exit(); @@ -528,6 +534,7 @@ static int __init vfio_ccw_sch_init(void) static void __exit vfio_ccw_sch_exit(void) { + mdev_unregister_driver(&vfio_ccw_mdev_driver); css_driver_unregister(&vfio_ccw_sch_driver); isc_unregister(VFIO_CCW_ISC); vfio_ccw_destroy_regions(); diff --git a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_ops.c index 1edbea9de0ec42..3a66e4fb18244c 100644 --- a/drivers/s390/cio/vfio_ccw_ops.c +++ b/drivers/s390/cio/vfio_ccw_ops.c @@ -17,6 +17,8 @@ #include "vfio_ccw_private.h" +static const struct vfio_device_ops vfio_ccw_dev_ops; + static int vfio_ccw_mdev_reset(struct vfio_ccw_private *private) { struct subchannel *sch; @@ -111,10 +113,10 @@ static struct attribute_group *mdev_type_groups[] = { NULL, }; -static int vfio_ccw_mdev_create(struct mdev_device *mdev) +static int vfio_ccw_mdev_probe(struct mdev_device *mdev) { - struct vfio_ccw_private *private = - dev_get_drvdata(mdev_parent_dev(mdev)); + struct vfio_ccw_private *private = dev_get_drvdata(mdev->dev.parent); + int ret; if (private->state == VFIO_CCW_STATE_NOT_OPER) return -ENODEV; @@ -122,6 +124,10 @@ static int vfio_ccw_mdev_create(struct mdev_device *mdev) if (atomic_dec_if_positive(&private->avail) < 0) return -EPERM; + memset(&private->vdev, 0, sizeof(private->vdev)); + vfio_init_group_dev(&private->vdev, &mdev->dev, + &vfio_ccw_dev_ops); + private->mdev = mdev; private->state = VFIO_CCW_STATE_IDLE; @@ -130,19 +136,31 @@ static int vfio_ccw_mdev_create(struct mdev_device *mdev) private->sch->schid.ssid, private->sch->schid.sch_no); + ret = vfio_register_group_dev(&private->vdev); + if (ret) + goto err_atomic; + dev_set_drvdata(&mdev->dev, private); return 0; + +err_atomic: + vfio_uninit_group_dev(&private->vdev); + atomic_inc(&private->avail); + private->mdev = NULL; + private->state = VFIO_CCW_STATE_IDLE; + return ret; } -static int vfio_ccw_mdev_remove(struct mdev_device *mdev) +static void vfio_ccw_mdev_remove(struct mdev_device *mdev) { - struct vfio_ccw_private *private = - dev_get_drvdata(mdev_parent_dev(mdev)); + struct vfio_ccw_private *private = dev_get_drvdata(mdev->dev.parent); VFIO_CCW_MSG_EVENT(2, "mdev %pUl, sch %x.%x.%04x: remove\n", mdev_uuid(mdev), private->sch->schid.cssid, private->sch->schid.ssid, private->sch->schid.sch_no); + vfio_unregister_group_dev(&private->vdev); + if ((private->state != VFIO_CCW_STATE_NOT_OPER) && (private->state != VFIO_CCW_STATE_STANDBY)) { if (!vfio_ccw_sch_quiesce(private->sch)) @@ -150,23 +168,22 @@ static int vfio_ccw_mdev_remove(struct mdev_device *mdev) /* The state will be NOT_OPER on error. */ } + vfio_uninit_group_dev(&private->vdev); cp_free(&private->cp); private->mdev = NULL; atomic_inc(&private->avail); - - return 0; } -static int vfio_ccw_mdev_open_device(struct mdev_device *mdev) +static int vfio_ccw_mdev_open_device(struct vfio_device *vdev) { struct vfio_ccw_private *private = - dev_get_drvdata(mdev_parent_dev(mdev)); + container_of(vdev, struct vfio_ccw_private, vdev); unsigned long events = VFIO_IOMMU_NOTIFY_DMA_UNMAP; int ret; private->nb.notifier_call = vfio_ccw_mdev_notifier; - ret = vfio_register_notifier(mdev_dev(mdev), VFIO_IOMMU_NOTIFY, + ret = vfio_register_notifier(vdev->dev, VFIO_IOMMU_NOTIFY, &events, &private->nb); if (ret) return ret; @@ -187,15 +204,15 @@ static int vfio_ccw_mdev_open_device(struct mdev_device *mdev) out_unregister: vfio_ccw_unregister_dev_regions(private); - vfio_unregister_notifier(mdev_dev(mdev), VFIO_IOMMU_NOTIFY, + vfio_unregister_notifier(vdev->dev, VFIO_IOMMU_NOTIFY, &private->nb); return ret; } -static void vfio_ccw_mdev_close_device(struct mdev_device *mdev) +static void vfio_ccw_mdev_close_device(struct vfio_device *vdev) { struct vfio_ccw_private *private = - dev_get_drvdata(mdev_parent_dev(mdev)); + container_of(vdev, struct vfio_ccw_private, vdev); if ((private->state != VFIO_CCW_STATE_NOT_OPER) && (private->state != VFIO_CCW_STATE_STANDBY)) { @@ -206,8 +223,7 @@ static void vfio_ccw_mdev_close_device(struct mdev_device *mdev) cp_free(&private->cp); vfio_ccw_unregister_dev_regions(private); - vfio_unregister_notifier(mdev_dev(mdev), VFIO_IOMMU_NOTIFY, - &private->nb); + vfio_unregister_notifier(vdev->dev, VFIO_IOMMU_NOTIFY, &private->nb); } static ssize_t vfio_ccw_mdev_read_io_region(struct vfio_ccw_private *private, @@ -231,15 +247,14 @@ static ssize_t vfio_ccw_mdev_read_io_region(struct vfio_ccw_private *private, return ret; } -static ssize_t vfio_ccw_mdev_read(struct mdev_device *mdev, +static ssize_t vfio_ccw_mdev_read(struct vfio_device *vdev, char __user *buf, size_t count, loff_t *ppos) { + struct vfio_ccw_private *private = + container_of(vdev, struct vfio_ccw_private, vdev); unsigned int index = VFIO_CCW_OFFSET_TO_INDEX(*ppos); - struct vfio_ccw_private *private; - - private = dev_get_drvdata(mdev_parent_dev(mdev)); if (index >= VFIO_CCW_NUM_REGIONS + private->num_regions) return -EINVAL; @@ -284,15 +299,14 @@ static ssize_t vfio_ccw_mdev_write_io_region(struct vfio_ccw_private *private, return ret; } -static ssize_t vfio_ccw_mdev_write(struct mdev_device *mdev, +static ssize_t vfio_ccw_mdev_write(struct vfio_device *vdev, const char __user *buf, size_t count, loff_t *ppos) { + struct vfio_ccw_private *private = + container_of(vdev, struct vfio_ccw_private, vdev); unsigned int index = VFIO_CCW_OFFSET_TO_INDEX(*ppos); - struct vfio_ccw_private *private; - - private = dev_get_drvdata(mdev_parent_dev(mdev)); if (index >= VFIO_CCW_NUM_REGIONS + private->num_regions) return -EINVAL; @@ -510,12 +524,12 @@ void vfio_ccw_unregister_dev_regions(struct vfio_ccw_private *private) private->region = NULL; } -static ssize_t vfio_ccw_mdev_ioctl(struct mdev_device *mdev, +static ssize_t vfio_ccw_mdev_ioctl(struct vfio_device *vdev, unsigned int cmd, unsigned long arg) { struct vfio_ccw_private *private = - dev_get_drvdata(mdev_parent_dev(mdev)); + container_of(vdev, struct vfio_ccw_private, vdev); int ret = 0; unsigned long minsz; @@ -606,37 +620,48 @@ static ssize_t vfio_ccw_mdev_ioctl(struct mdev_device *mdev, } /* Request removal of the device*/ -static void vfio_ccw_mdev_request(struct mdev_device *mdev, unsigned int count) +static void vfio_ccw_mdev_request(struct vfio_device *vdev, unsigned int count) { - struct vfio_ccw_private *private = dev_get_drvdata(mdev_parent_dev(mdev)); - - if (!private) - return; + struct vfio_ccw_private *private = + container_of(vdev, struct vfio_ccw_private, vdev); + struct device *dev = vdev->dev; if (private->req_trigger) { if (!(count % 10)) - dev_notice_ratelimited(mdev_dev(private->mdev), + dev_notice_ratelimited(dev, "Relaying device request to user (#%u)\n", count); eventfd_signal(private->req_trigger, 1); } else if (count == 0) { - dev_notice(mdev_dev(private->mdev), + dev_notice(dev, "No device request channel registered, blocked until released by user\n"); } } +static const struct vfio_device_ops vfio_ccw_dev_ops = { + .open_device = vfio_ccw_mdev_open_device, + .close_device = vfio_ccw_mdev_close_device, + .read = vfio_ccw_mdev_read, + .write = vfio_ccw_mdev_write, + .ioctl = vfio_ccw_mdev_ioctl, + .request = vfio_ccw_mdev_request, +}; + +struct mdev_driver vfio_ccw_mdev_driver = { + .driver = { + .name = "vfio_ccw_mdev", + .owner = THIS_MODULE, + .mod_name = KBUILD_MODNAME, + }, + .probe = vfio_ccw_mdev_probe, + .remove = vfio_ccw_mdev_remove, +}; + static const struct mdev_parent_ops vfio_ccw_mdev_ops = { .owner = THIS_MODULE, + .device_driver = &vfio_ccw_mdev_driver, .supported_type_groups = mdev_type_groups, - .create = vfio_ccw_mdev_create, - .remove = vfio_ccw_mdev_remove, - .open_device = vfio_ccw_mdev_open_device, - .close_device = vfio_ccw_mdev_close_device, - .read = vfio_ccw_mdev_read, - .write = vfio_ccw_mdev_write, - .ioctl = vfio_ccw_mdev_ioctl, - .request = vfio_ccw_mdev_request, }; int vfio_ccw_mdev_reg(struct subchannel *sch) diff --git a/drivers/s390/cio/vfio_ccw_private.h b/drivers/s390/cio/vfio_ccw_private.h index b2c762eb42b9bb..7272eb78861244 100644 --- a/drivers/s390/cio/vfio_ccw_private.h +++ b/drivers/s390/cio/vfio_ccw_private.h @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -67,6 +68,7 @@ struct vfio_ccw_crw { /** * struct vfio_ccw_private + * @vdev: Embedded VFIO device * @sch: pointer to the subchannel * @state: internal state of the device * @completion: synchronization helper of the I/O completion @@ -90,6 +92,7 @@ struct vfio_ccw_crw { * @crw_work: work for deferral process of CRW handling */ struct vfio_ccw_private { + struct vfio_device vdev; struct subchannel *sch; int state; struct completion *completion; @@ -121,6 +124,8 @@ extern void vfio_ccw_mdev_unreg(struct subchannel *sch); extern int vfio_ccw_sch_quiesce(struct subchannel *sch); +extern struct mdev_driver vfio_ccw_mdev_driver; + /* * States of the device statemachine. */ From patchwork Thu Sep 9 19:38:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12483755 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6DDBDC433FE for ; Thu, 9 Sep 2021 19:39:09 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 39BB660724 for ; Thu, 9 Sep 2021 19:39:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 39BB660724 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 55E466E909; Thu, 9 Sep 2021 19:38:55 +0000 (UTC) Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2069.outbound.protection.outlook.com [40.107.94.69]) by gabe.freedesktop.org (Postfix) with ESMTPS id 296986E904; Thu, 9 Sep 2021 19:38:54 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hnGbT4N9jIRDVe39090iRJUlg1K8cGlXnYKWQHFILHnXWBgttrZLqHPJFCik4sksaSQ09gkxTN3q0iWxjqze3QRVzm4Hyk4FvIpNpyjtjA/LfNfS0b3rDBXQsFlUiy9wnf8bl3TMtXqOkoE0zGcnJ7Q8gv/P13XinaBKBP+mLb+NqmVyihmN01yGL4UGOdvPEzXgHfYkRMsoUVZMucbVLH+Q7IEQ6lUVpl1kyI0rdP9jg2jVj1wO7TVPEK2cobbhuExAjqT5p7R/jls8jQqLculUZx+9YTYAVnTPFntK7L6wb6S/R4inAo+irjXqiuCnv1GCBVRTaaQBvo1tZT/Ohw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=cQlUMg/ysqyvN7+hivtAZ1trIYACTCmWxQNAlxlEp+I=; b=hmZ1S3m6A9z8xvDm6i9iEDrldghzd75q+dySqSe/xMl7QFkldgWtTNKk3GqCVqYBelnXQOrCSUDekMM84m6XzpmH3Jz4TBq2qLDEQtcLXybaZ9+EcKZI7nVIQsQ7PZhrMreWt/knjL9MdNMvxLaYUq6EOCVV4vyLfvmju5iZkl0VunIaMyenptF8Sj3NsluqOQIBFgVD8/+vt5A8n0BZtLvXbHVIZ+HbLwooI78MiVAtXJfoTympY1WGOw6r5R1UtWqgcVe1qnIQN8NZCws1Ednt3tsIkGg2LLQH9Gv+7bkzSbn3ZGyGwQR429tQJsB9rGel/QbzQ9U2KGK5HFn0aw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cQlUMg/ysqyvN7+hivtAZ1trIYACTCmWxQNAlxlEp+I=; b=FpAovmLaK9gCq/qoUMOCjftqXiQMsxLy76xN3mHjiHLAYpVHiUOz9M/L2UsxkOVOyD7vxAWtqohKuB0xyjPl+kh7zShhQj/0Gf36Ax4aCB34fNiiH7uRxEj/cU26VV/r8Xe6qqXmHYNHAzVHvkhLG45HXadFzv4ZDodI02VNiIm0Mz4lGEmBOfFj2Nx3EtFJc9WSCXihMzy5Aj98bTcpAFYh0jM6VeGrHN/z4Iv9mpHpm+xqKbWoAWposOMCaY+Lnnm0czLKxAy39oRfLYiRkr0zQMcI0h6mGbxHK/dCCogpp/YAbCDkf1tWe9T/mm08n37Ee9ZT+n7KUBXAbutfOw== Authentication-Results: linux.ie; dkim=none (message not signed) header.d=none;linux.ie; dmarc=none action=none header.from=nvidia.com; Received: from BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) by BL0PR12MB5554.namprd12.prod.outlook.com (2603:10b6:208:1cd::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14; Thu, 9 Sep 2021 19:38:51 +0000 Received: from BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::e8af:232:915e:2f95]) by BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::e8af:232:915e:2f95%8]) with mapi id 15.20.4500.014; Thu, 9 Sep 2021 19:38:51 +0000 From: Jason Gunthorpe To: David Airlie , Tony Krowiak , Alex Williamson , Christian Borntraeger , Cornelia Huck , Daniel Vetter , dri-devel@lists.freedesktop.org, Eric Farman , Harald Freudenberger , Vasily Gorbik , Heiko Carstens , intel-gfx@lists.freedesktop.org, intel-gvt-dev@lists.freedesktop.org, Jani Nikula , Jason Herne , Joonas Lahtinen , kvm@vger.kernel.org, Kirti Wankhede , linux-s390@vger.kernel.org, Matthew Rosato , Peter Oberparleiter , Halil Pasic , Rodrigo Vivi , Vineeth Vijayan , Zhenyu Wang , Zhi Wang Cc: Christoph Hellwig Date: Thu, 9 Sep 2021 16:38:44 -0300 Message-Id: <4-v2-7d3a384024cf+2060-ccw_mdev_jgg@nvidia.com> In-Reply-To: <0-v2-7d3a384024cf+2060-ccw_mdev_jgg@nvidia.com> References: X-ClientProxiedBy: BL0PR02CA0024.namprd02.prod.outlook.com (2603:10b6:207:3c::37) To BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) MIME-Version: 1.0 Received: from mlx.ziepe.ca (142.162.113.129) by BL0PR02CA0024.namprd02.prod.outlook.com (2603:10b6:207:3c::37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Thu, 9 Sep 2021 19:38:50 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1mOPsn-00FLEy-JF; Thu, 09 Sep 2021 16:38:49 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 68699887-9b50-493f-65d8-08d973c972e6 X-MS-TrafficTypeDiagnostic: BL0PR12MB5554: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FT37us6Bxt1y+KLUGuj48+oyv3ZYxoXLg3lCHyxb6FI3OS7elSV8N9W6qFiLwcrGIbpgADYqkvRn/rH9dBKQPplnG5MXAKCLGUd0dkZmM8fi0EDUpAYIvKlLSBEr/UGZalpEeS3lvWPhFWog/ccVx/L5Tdvswv0iK0qm04vUS+Kq4vwhqmzOOO1og1K+LEomkXdND8p6QSbzzmBPPv33uieN56Zh9BwMK4sSwhC8uiKH2viK0hoDT/DByIg4Llj1ydodwa+zf83wj9Zr/NM0paTjj8UI0CyD8JQYNbvGeRq8RHfCCyt+atLSDyBA0HTo4A1heNaI0jhfzuAcQ+6aiQVZCdBDZqBYerinyAREW0d0OsyCMFnWC1vAoNMtCby0B8MDfT9zWTPw7lzM3T5OcorAWFQF0gDSMac7LKeziIZXqjGoGiRWrNlipCmKQmHHG3CMfGK1KNV0/UY4MO9USiey6iTHE5Lohpat/TYT6gpqm9q9tmgWiyUHwzvimsJAMaYCLakkWZKgmDEwCAoOByFePzWgnqpDsl0LCqK/qdIXG90UTVzvcXC8qxjJBIxIyy0iEFy09rrRBU0VrDSNa1sCKz2OsHYS1o9r+qTuOC76sVETXOm4nSq18qgfpPvXj7Iwo2mQCFqVdl46mAAy/Vz4wDVtSYGNWnTp3tc5U9YFtuTK4W2RBqQPGZpkJyD7ULAfeUKx+k+wVV/dlREdvg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BL0PR12MB5506.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(7416002)(26005)(4326008)(2616005)(66556008)(30864003)(921005)(66476007)(426003)(66946007)(9746002)(9786002)(5660300002)(186003)(83380400001)(86362001)(508600001)(8936002)(6666004)(110136005)(38100700002)(36756003)(316002)(8676002)(2906002)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 8rFtHuQzBehIwkWkx9VM5JpLNS2FLKUbNEUyslJa+fRT16Su9SzcoNDDdCE5JYHzU+U7EG7zcGHarjlJg021Ru1/E+rnDEp3qqlOf4c6GGiIaOJHRkH9941HczH3rQaSsqjJhaA1HdRZcnyn2RdJPfMNVe2vyiubwLR/mtkFhiuPnZuVaV+m77tVM/SHU8KFfetUOsQQTuT9FvapqE8IvOjdRLmqY3YtxmUVz+J0QVpj34z75TSBS1GF3g/Q2VfLNOupjdKxGk1BdiBwBdgzzqJZYD6da0mODDXnp1EREm5ZiqU7VHixCkq64RsFDnKcd3tewV0J5vGjaPUQS2yqlVHc1O+lwtWTr0nd/gpW5oZ6w4pegJ+1u4gPJSQvmCyEPSNSSuv5nHRhX8ddSI49bXXXbaREF6/Yv7R5qSFLyWSB4Jg4Uv1LT8G6GOrUUj/xKflz0G3f8NaoYR9LQxhj8galcN6cRMuRb09Mb7npqTAYFhqZFdUf/1j0zOaQNlwHdY+p1PIlQEnuNIcS/PkUJfPXA2MZMH5yLhOS9HkvHqhj20f1unKU5lXi9mmdN7ZW6VXo/k8aQpmsHBiiJPtfWn5fwqrdLThpnCl0f2Rphtt7SAaWIGbIGepDf0q6UWaZiKvr+2bjOQv6fGfsqWM+cTP9aHCydoIve5cjEIMZKKAcXFV4zrYEibwkylYTscgacKj64TBuU1Ca8Pd33xLiNBwKna0rSZau/dbJCQvQW/CvlmK4hh69/H3QgrspEtOK X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 68699887-9b50-493f-65d8-08d973c972e6 X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Sep 2021 19:38:50.7000 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ACDoJVM8SuHf5o3OjLfOl0vktI94u3Sa3aABf6FvMwanX54V08aPKi6/LvP+khir X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB5554 Subject: [Intel-gfx] [PATCH v2 4/9] vfio/ccw: Make the FSM complete and synchronize it to the mdev X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" The subchannel should be left in a quiescent state unless the VFIO device FD is opened. When the FD is opened bring the chanel to active and allow the VFIO device to operate. When the device FD is closed then quiesce the channel. To make this work the FSM needs to handle the transitions to/from open and closed so everything is sequenced. Rename state NOT_OPER to BROKEN and use it wheneven the driver has malfunctioned. STANDBY becomes CLOSED. The normal case FSM looks like: CLOSED -> IDLE -> PROCESS/PENDING* -> IDLE -> CLOSED With a possible branch off to BROKEN from any state. Once the device is in BROKEN it cannot be recovered other than be reloading the driver. Delete the triply redundant calls to vfio_ccw_sch_quiesce(). vfio_ccw_mdev_close_device() always leaves the subchannel quiescent. vfio_ccw_mdev_remove() cannot return until vfio_ccw_mdev_close_device() completes and vfio_ccw_sch_remove() cannot return until vfio_ccw_mdev_remove() completes. Have the FSM code take care of calling cp_free() when appropriate. Device reset becomes a CLOSE/OPEN sequence which now properly handles the situation if the device becomes BROKEN. Machine shutdown via vfio_ccw_sch_shutdown() now simply tries to close and leaves the device BROKEN (though arguably the bus should take care to quiet down the subchannel HW during shutdown, not the drivers) Signed-off-by: Jason Gunthorpe --- drivers/s390/cio/vfio_ccw_drv.c | 74 ++------------------ drivers/s390/cio/vfio_ccw_fsm.c | 104 ++++++++++++++++++++++++---- drivers/s390/cio/vfio_ccw_ops.c | 49 ++++--------- drivers/s390/cio/vfio_ccw_private.h | 12 ++-- 4 files changed, 119 insertions(+), 120 deletions(-) diff --git a/drivers/s390/cio/vfio_ccw_drv.c b/drivers/s390/cio/vfio_ccw_drv.c index 396e815f81f8a4..99f2823361718f 100644 --- a/drivers/s390/cio/vfio_ccw_drv.c +++ b/drivers/s390/cio/vfio_ccw_drv.c @@ -36,51 +36,6 @@ debug_info_t *vfio_ccw_debug_trace_id; /* * Helpers */ -int vfio_ccw_sch_quiesce(struct subchannel *sch) -{ - struct vfio_ccw_private *private = dev_get_drvdata(&sch->dev); - DECLARE_COMPLETION_ONSTACK(completion); - int iretry, ret = 0; - - spin_lock_irq(sch->lock); - if (!sch->schib.pmcw.ena) - goto out_unlock; - ret = cio_disable_subchannel(sch); - if (ret != -EBUSY) - goto out_unlock; - - iretry = 255; - do { - - ret = cio_cancel_halt_clear(sch, &iretry); - - if (ret == -EIO) { - pr_err("vfio_ccw: could not quiesce subchannel 0.%x.%04x!\n", - sch->schid.ssid, sch->schid.sch_no); - break; - } - - /* - * Flush all I/O and wait for - * cancel/halt/clear completion. - */ - private->completion = &completion; - spin_unlock_irq(sch->lock); - - if (ret == -EBUSY) - wait_for_completion_timeout(&completion, 3*HZ); - - private->completion = NULL; - flush_workqueue(vfio_ccw_work_q); - spin_lock_irq(sch->lock); - ret = cio_disable_subchannel(sch); - } while (ret == -EBUSY); -out_unlock: - private->state = VFIO_CCW_STATE_NOT_OPER; - spin_unlock_irq(sch->lock); - return ret; -} - static void vfio_ccw_sch_io_todo(struct work_struct *work) { struct vfio_ccw_private *private; @@ -147,7 +102,7 @@ static struct vfio_ccw_private *vfio_ccw_alloc_private(struct subchannel *sch) private->sch = sch; mutex_init(&private->io_mutex); - private->state = VFIO_CCW_STATE_NOT_OPER; + private->state = VFIO_CCW_STATE_CLOSED; INIT_LIST_HEAD(&private->crw); INIT_WORK(&private->io_work, vfio_ccw_sch_io_todo); INIT_WORK(&private->crw_work, vfio_ccw_crw_todo); @@ -231,18 +186,9 @@ static int vfio_ccw_sch_probe(struct subchannel *sch) dev_set_drvdata(&sch->dev, private); - spin_lock_irq(sch->lock); - sch->isc = VFIO_CCW_ISC; - ret = cio_enable_subchannel(sch, (u32)(unsigned long)sch); - spin_unlock_irq(sch->lock); - if (ret) - goto out_free; - - private->state = VFIO_CCW_STATE_STANDBY; - ret = vfio_ccw_mdev_reg(sch); if (ret) - goto out_disable; + goto out_free; if (dev_get_uevent_suppress(&sch->dev)) { dev_set_uevent_suppress(&sch->dev, 0); @@ -254,8 +200,6 @@ static int vfio_ccw_sch_probe(struct subchannel *sch) sch->schid.sch_no); return 0; -out_disable: - cio_disable_subchannel(sch); out_free: dev_set_drvdata(&sch->dev, NULL); vfio_ccw_free_private(private); @@ -266,7 +210,6 @@ static int vfio_ccw_sch_remove(struct subchannel *sch) { struct vfio_ccw_private *private = dev_get_drvdata(&sch->dev); - vfio_ccw_sch_quiesce(sch); vfio_ccw_mdev_unreg(sch); dev_set_drvdata(&sch->dev, NULL); @@ -281,7 +224,10 @@ static int vfio_ccw_sch_remove(struct subchannel *sch) static void vfio_ccw_sch_shutdown(struct subchannel *sch) { - vfio_ccw_sch_quiesce(sch); + struct vfio_ccw_private *private = dev_get_drvdata(&sch->dev); + + vfio_ccw_fsm_event(private, VFIO_CCW_EVENT_CLOSE); + vfio_ccw_fsm_event(private, VFIO_CCW_EVENT_BROKEN); } /** @@ -308,16 +254,10 @@ static int vfio_ccw_sch_event(struct subchannel *sch, int process) goto out_unlock; if (cio_update_schib(sch)) { - vfio_ccw_fsm_event(private, VFIO_CCW_EVENT_NOT_OPER); + vfio_ccw_fsm_event(private, VFIO_CCW_EVENT_BROKEN); rc = 0; goto out_unlock; } - - private = dev_get_drvdata(&sch->dev); - if (private->state == VFIO_CCW_STATE_NOT_OPER) { - private->state = private->mdev ? VFIO_CCW_STATE_IDLE : - VFIO_CCW_STATE_STANDBY; - } rc = 0; out_unlock: diff --git a/drivers/s390/cio/vfio_ccw_fsm.c b/drivers/s390/cio/vfio_ccw_fsm.c index e435a9cd92dacf..302215090b9ac7 100644 --- a/drivers/s390/cio/vfio_ccw_fsm.c +++ b/drivers/s390/cio/vfio_ccw_fsm.c @@ -12,6 +12,8 @@ #include #include +#include + #include "ioasm.h" #include "vfio_ccw_private.h" @@ -156,12 +158,12 @@ static int fsm_do_clear(struct vfio_ccw_private *private) return ret; } -static void fsm_notoper(struct vfio_ccw_private *private, - enum vfio_ccw_event event) +static void fsm_broken(struct vfio_ccw_private *private, + enum vfio_ccw_event event) { struct subchannel *sch = private->sch; - VFIO_CCW_TRACE_EVENT(2, "notoper"); + VFIO_CCW_TRACE_EVENT(2, "broken"); VFIO_CCW_TRACE_EVENT(2, dev_name(&sch->dev)); /* @@ -169,7 +171,8 @@ static void fsm_notoper(struct vfio_ccw_private *private, * Probably we should send the machine check to the guest. */ css_sched_sch_todo(sch, SCH_TODO_UNREG); - private->state = VFIO_CCW_STATE_NOT_OPER; + private->state = VFIO_CCW_STATE_BROKEN; + cp_free(&private->cp); } /* @@ -367,38 +370,115 @@ static void fsm_irq(struct vfio_ccw_private *private, complete(private->completion); } +static void fsm_open(struct vfio_ccw_private *private, + enum vfio_ccw_event event) +{ + struct subchannel *sch = private->sch; + int ret; + + spin_lock_irq(sch->lock); + sch->isc = VFIO_CCW_ISC; + ret = cio_enable_subchannel(sch, (u32)(unsigned long)sch); + if (ret) + private->state = VFIO_CCW_STATE_BROKEN; + else + private->state = VFIO_CCW_STATE_IDLE; + spin_unlock_irq(sch->lock); +} + +static void fsm_close(struct vfio_ccw_private *private, + enum vfio_ccw_event event) +{ + struct subchannel *sch = private->sch; + DECLARE_COMPLETION_ONSTACK(completion); + int iretry, ret = 0; + + spin_lock_irq(sch->lock); + if (!sch->schib.pmcw.ena) + goto err_unlock; + ret = cio_disable_subchannel(sch); + if (ret != -EBUSY) + goto err_unlock; + + iretry = 255; + do { + + ret = cio_cancel_halt_clear(sch, &iretry); + + if (ret == -EIO) { + pr_err("vfio_ccw: could not quiesce subchannel 0.%x.%04x!\n", + sch->schid.ssid, sch->schid.sch_no); + break; + } + + /* + * Flush all I/O and wait for + * cancel/halt/clear completion. + */ + private->completion = &completion; + spin_unlock_irq(sch->lock); + + if (ret == -EBUSY) + wait_for_completion_timeout(&completion, 3*HZ); + + private->completion = NULL; + flush_workqueue(vfio_ccw_work_q); + spin_lock_irq(sch->lock); + ret = cio_disable_subchannel(sch); + } while (ret == -EBUSY); + if (ret) + goto err_unlock; + private->state = VFIO_CCW_STATE_CLOSED; + spin_unlock_irq(sch->lock); + cp_free(&private->cp); + return; + +err_unlock: + spin_unlock_irq(sch->lock); + vfio_ccw_fsm_event(private, VFIO_CCW_EVENT_BROKEN); +} + /* * Device statemachine */ fsm_func_t *vfio_ccw_jumptable[NR_VFIO_CCW_STATES][NR_VFIO_CCW_EVENTS] = { - [VFIO_CCW_STATE_NOT_OPER] = { - [VFIO_CCW_EVENT_NOT_OPER] = fsm_nop, + [VFIO_CCW_STATE_BROKEN] = { + [VFIO_CCW_EVENT_BROKEN] = fsm_nop, [VFIO_CCW_EVENT_IO_REQ] = fsm_io_error, [VFIO_CCW_EVENT_ASYNC_REQ] = fsm_async_error, [VFIO_CCW_EVENT_INTERRUPT] = fsm_disabled_irq, + [VFIO_CCW_EVENT_CLOSE] = fsm_nop, }, - [VFIO_CCW_STATE_STANDBY] = { - [VFIO_CCW_EVENT_NOT_OPER] = fsm_notoper, + [VFIO_CCW_STATE_CLOSED] = { + [VFIO_CCW_EVENT_BROKEN] = fsm_broken, [VFIO_CCW_EVENT_IO_REQ] = fsm_io_error, [VFIO_CCW_EVENT_ASYNC_REQ] = fsm_async_error, - [VFIO_CCW_EVENT_INTERRUPT] = fsm_irq, + [VFIO_CCW_EVENT_INTERRUPT] = fsm_disabled_irq, + [VFIO_CCW_EVENT_OPEN] = fsm_open, + [VFIO_CCW_EVENT_CLOSE] = fsm_broken, }, [VFIO_CCW_STATE_IDLE] = { - [VFIO_CCW_EVENT_NOT_OPER] = fsm_notoper, + [VFIO_CCW_EVENT_BROKEN] = fsm_broken, [VFIO_CCW_EVENT_IO_REQ] = fsm_io_request, [VFIO_CCW_EVENT_ASYNC_REQ] = fsm_async_request, [VFIO_CCW_EVENT_INTERRUPT] = fsm_irq, + [VFIO_CCW_EVENT_OPEN] = fsm_broken, + [VFIO_CCW_EVENT_CLOSE] = fsm_close, }, [VFIO_CCW_STATE_CP_PROCESSING] = { - [VFIO_CCW_EVENT_NOT_OPER] = fsm_notoper, + [VFIO_CCW_EVENT_BROKEN] = fsm_broken, [VFIO_CCW_EVENT_IO_REQ] = fsm_io_retry, [VFIO_CCW_EVENT_ASYNC_REQ] = fsm_async_retry, [VFIO_CCW_EVENT_INTERRUPT] = fsm_irq, + [VFIO_CCW_EVENT_OPEN] = fsm_broken, + [VFIO_CCW_EVENT_CLOSE] = fsm_close, }, [VFIO_CCW_STATE_CP_PENDING] = { - [VFIO_CCW_EVENT_NOT_OPER] = fsm_notoper, + [VFIO_CCW_EVENT_BROKEN] = fsm_broken, [VFIO_CCW_EVENT_IO_REQ] = fsm_io_busy, [VFIO_CCW_EVENT_ASYNC_REQ] = fsm_async_request, [VFIO_CCW_EVENT_INTERRUPT] = fsm_irq, + [VFIO_CCW_EVENT_OPEN] = fsm_broken, + [VFIO_CCW_EVENT_CLOSE] = fsm_close, }, }; diff --git a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_ops.c index 3a66e4fb18244c..6e70620d5dfbc8 100644 --- a/drivers/s390/cio/vfio_ccw_ops.c +++ b/drivers/s390/cio/vfio_ccw_ops.c @@ -21,10 +21,6 @@ static const struct vfio_device_ops vfio_ccw_dev_ops; static int vfio_ccw_mdev_reset(struct vfio_ccw_private *private) { - struct subchannel *sch; - int ret; - - sch = private->sch; /* * TODO: * In the cureent stage, some things like "no I/O running" and "no @@ -33,15 +29,11 @@ static int vfio_ccw_mdev_reset(struct vfio_ccw_private *private) * There are still a lot more instructions need to be handled. We * should come back here later. */ - ret = vfio_ccw_sch_quiesce(sch); - if (ret) - return ret; - - ret = cio_enable_subchannel(sch, (u32)(unsigned long)sch); - if (!ret) - private->state = VFIO_CCW_STATE_IDLE; - - return ret; + vfio_ccw_fsm_event(private, VFIO_CCW_EVENT_CLOSE); + vfio_ccw_fsm_event(private, VFIO_CCW_EVENT_OPEN); + if (private->state == VFIO_CCW_STATE_BROKEN) + return -EINVAL; + return 0; } static int vfio_ccw_mdev_notifier(struct notifier_block *nb, @@ -118,9 +110,6 @@ static int vfio_ccw_mdev_probe(struct mdev_device *mdev) struct vfio_ccw_private *private = dev_get_drvdata(mdev->dev.parent); int ret; - if (private->state == VFIO_CCW_STATE_NOT_OPER) - return -ENODEV; - if (atomic_dec_if_positive(&private->avail) < 0) return -EPERM; @@ -129,7 +118,6 @@ static int vfio_ccw_mdev_probe(struct mdev_device *mdev) &vfio_ccw_dev_ops); private->mdev = mdev; - private->state = VFIO_CCW_STATE_IDLE; VFIO_CCW_MSG_EVENT(2, "mdev %pUl, sch %x.%x.%04x: create\n", mdev_uuid(mdev), private->sch->schid.cssid, @@ -146,7 +134,6 @@ static int vfio_ccw_mdev_probe(struct mdev_device *mdev) vfio_uninit_group_dev(&private->vdev); atomic_inc(&private->avail); private->mdev = NULL; - private->state = VFIO_CCW_STATE_IDLE; return ret; } @@ -160,16 +147,7 @@ static void vfio_ccw_mdev_remove(struct mdev_device *mdev) private->sch->schid.sch_no); vfio_unregister_group_dev(&private->vdev); - - if ((private->state != VFIO_CCW_STATE_NOT_OPER) && - (private->state != VFIO_CCW_STATE_STANDBY)) { - if (!vfio_ccw_sch_quiesce(private->sch)) - private->state = VFIO_CCW_STATE_STANDBY; - /* The state will be NOT_OPER on error. */ - } - vfio_uninit_group_dev(&private->vdev); - cp_free(&private->cp); private->mdev = NULL; atomic_inc(&private->avail); } @@ -181,6 +159,9 @@ static int vfio_ccw_mdev_open_device(struct vfio_device *vdev) unsigned long events = VFIO_IOMMU_NOTIFY_DMA_UNMAP; int ret; + if (private->state == VFIO_CCW_STATE_BROKEN) + return -EINVAL; + private->nb.notifier_call = vfio_ccw_mdev_notifier; ret = vfio_register_notifier(vdev->dev, VFIO_IOMMU_NOTIFY, @@ -200,6 +181,11 @@ static int vfio_ccw_mdev_open_device(struct vfio_device *vdev) if (ret) goto out_unregister; + vfio_ccw_fsm_event(private, VFIO_CCW_EVENT_OPEN); + if (private->state == VFIO_CCW_STATE_BROKEN) { + ret = -EINVAL; + goto out_unregister; + } return ret; out_unregister: @@ -214,14 +200,7 @@ static void vfio_ccw_mdev_close_device(struct vfio_device *vdev) struct vfio_ccw_private *private = container_of(vdev, struct vfio_ccw_private, vdev); - if ((private->state != VFIO_CCW_STATE_NOT_OPER) && - (private->state != VFIO_CCW_STATE_STANDBY)) { - if (!vfio_ccw_mdev_reset(private)) - private->state = VFIO_CCW_STATE_STANDBY; - /* The state will be NOT_OPER on error. */ - } - - cp_free(&private->cp); + vfio_ccw_fsm_event(private, VFIO_CCW_EVENT_CLOSE); vfio_ccw_unregister_dev_regions(private); vfio_unregister_notifier(vdev->dev, VFIO_IOMMU_NOTIFY, &private->nb); } diff --git a/drivers/s390/cio/vfio_ccw_private.h b/drivers/s390/cio/vfio_ccw_private.h index 7272eb78861244..5e98eacdf31074 100644 --- a/drivers/s390/cio/vfio_ccw_private.h +++ b/drivers/s390/cio/vfio_ccw_private.h @@ -122,16 +122,14 @@ struct vfio_ccw_private { extern int vfio_ccw_mdev_reg(struct subchannel *sch); extern void vfio_ccw_mdev_unreg(struct subchannel *sch); -extern int vfio_ccw_sch_quiesce(struct subchannel *sch); - extern struct mdev_driver vfio_ccw_mdev_driver; /* * States of the device statemachine. */ enum vfio_ccw_state { - VFIO_CCW_STATE_NOT_OPER, - VFIO_CCW_STATE_STANDBY, + VFIO_CCW_STATE_BROKEN, + VFIO_CCW_STATE_CLOSED, VFIO_CCW_STATE_IDLE, VFIO_CCW_STATE_CP_PROCESSING, VFIO_CCW_STATE_CP_PENDING, @@ -143,10 +141,12 @@ enum vfio_ccw_state { * Asynchronous events of the device statemachine. */ enum vfio_ccw_event { - VFIO_CCW_EVENT_NOT_OPER, + VFIO_CCW_EVENT_BROKEN, VFIO_CCW_EVENT_IO_REQ, VFIO_CCW_EVENT_INTERRUPT, VFIO_CCW_EVENT_ASYNC_REQ, + VFIO_CCW_EVENT_OPEN, + VFIO_CCW_EVENT_CLOSE, /* last element! */ NR_VFIO_CCW_EVENTS }; @@ -158,7 +158,7 @@ typedef void (fsm_func_t)(struct vfio_ccw_private *, enum vfio_ccw_event); extern fsm_func_t *vfio_ccw_jumptable[NR_VFIO_CCW_STATES][NR_VFIO_CCW_EVENTS]; static inline void vfio_ccw_fsm_event(struct vfio_ccw_private *private, - int event) + enum vfio_ccw_event event) { trace_vfio_ccw_fsm_event(private->sch->schid, private->state, event); vfio_ccw_jumptable[private->state][event](private, event); From patchwork Thu Sep 9 19:38:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12483763 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3D99C433FE for ; Thu, 9 Sep 2021 19:39:28 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C46DE60724 for ; Thu, 9 Sep 2021 19:39:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org C46DE60724 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A96956E91D; Thu, 9 Sep 2021 19:39:00 +0000 (UTC) Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2064.outbound.protection.outlook.com [40.107.94.64]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5154D6E908; Thu, 9 Sep 2021 19:38:55 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RyxCWfKiIitW/EmBA2m30aEHTPzc3q7CIuZisXfpVRTzAhRA9tXJEb7lBIyNYGXFsM10GD5Tsefk9ogQPS14fXQ8VZsZ8tUwSk+BaetHDY+B5HWTqjVp9oeALjhiod1v1ft5KqUNN/xcgHQ4xHU6tevR/jniUv/vjOuKjGz3ey/1E6Yt1fOgwf1ZQJHuaF8QSPRWoRf5VnCI61W45bzatYrQ0sLfgdr1ol0Pnq8cAvlDGm0I34YH4rqwnGioY5AYvjMx8H69/f7eFh07UdihEASkMJIZOZcTLMmInigvS3B02tUPC3LHp2Fvj3wvp2KcIC29VdCB7Co8nai9N+wy1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=x24yekDwXo9V2sGcnzrLRg4lnIWhgWoKXBFEXPGaQJY=; b=E/4fShjAR/zt7FWOws7i3kQee3FmMwYU8Yc8/crvA6HWGMaUWWSMv/ZLvA/Y2pUulbTRdN1fdik9KXsZ/Mx1mKEXHP0eAggA8VpgkVmcsmR2RdQUuj9kfAcP4EqMs8J8v2xqMVeFBu55qwiSRG98bxjoxDvG1bp96+tpDkHKEUcED+w/y0MiTJ8HxaRPX2aZkrAu2sUNQhnW8Cw2bJCf8W3CUZP9GFjUIe7BChjizki7RfEo18NRf0IXjvdqUXein0JsbiD8jj4Rp1LOV2FAHqL/4PqJW1rINNLsHQo6rvZqKZWilv0F6VEQT3aJxm/jundHd8VqfxYl10zEKuaplg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=x24yekDwXo9V2sGcnzrLRg4lnIWhgWoKXBFEXPGaQJY=; b=mBY+pOye0FDDxm2KA8nuOvpJeCz9zKW6hvFQcSXdmOhSoG5kpKaUSS+ArvHtwVz/LSAjdn7YOeIuppK0kZbiEs9uClB/6XdziIu/cFQBE1+Mb+o5c4oboxZj0xLtr7iyCzvsdxN9d01crv3DfP961+T8gDK47ka7/D5Y9GmKDNfJ3H+MHQfVETkUoRVPTyL8YjFP3RSNSz0g+jocmIDV004OM6IWQzJu7uspY8xhrjHumM3BM16C7JtMmwa2rp/m/RZr6dMl3/Z+xowedtOpkt64zjrwFGsb3h/eGam00VdRRsejmQ4qL5b1nAmlsLkYIWwdrpQm0AtLeRcQILzGjw== Authentication-Results: linux.ie; dkim=none (message not signed) header.d=none;linux.ie; dmarc=none action=none header.from=nvidia.com; Received: from BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) by BL0PR12MB5554.namprd12.prod.outlook.com (2603:10b6:208:1cd::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14; Thu, 9 Sep 2021 19:38:54 +0000 Received: from BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::e8af:232:915e:2f95]) by BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::e8af:232:915e:2f95%8]) with mapi id 15.20.4500.014; Thu, 9 Sep 2021 19:38:54 +0000 From: Jason Gunthorpe To: David Airlie , Tony Krowiak , Alex Williamson , Christian Borntraeger , Cornelia Huck , Daniel Vetter , dri-devel@lists.freedesktop.org, Eric Farman , Harald Freudenberger , Vasily Gorbik , Heiko Carstens , intel-gfx@lists.freedesktop.org, intel-gvt-dev@lists.freedesktop.org, Jani Nikula , Jason Herne , Joonas Lahtinen , kvm@vger.kernel.org, Kirti Wankhede , linux-s390@vger.kernel.org, Matthew Rosato , Peter Oberparleiter , Halil Pasic , Rodrigo Vivi , Vineeth Vijayan , Zhenyu Wang , Zhi Wang Cc: Christoph Hellwig Date: Thu, 9 Sep 2021 16:38:45 -0300 Message-Id: <5-v2-7d3a384024cf+2060-ccw_mdev_jgg@nvidia.com> In-Reply-To: <0-v2-7d3a384024cf+2060-ccw_mdev_jgg@nvidia.com> References: X-ClientProxiedBy: BL0PR0102CA0026.prod.exchangelabs.com (2603:10b6:207:18::39) To BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) MIME-Version: 1.0 Received: from mlx.ziepe.ca (142.162.113.129) by BL0PR0102CA0026.prod.exchangelabs.com (2603:10b6:207:18::39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Thu, 9 Sep 2021 19:38:52 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1mOPsn-00FLF2-L2; Thu, 09 Sep 2021 16:38:49 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f20e1b45-6278-4f5d-657b-08d973c9742e X-MS-TrafficTypeDiagnostic: BL0PR12MB5554: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:428; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BGr5zVi0oo08j5cJTK2I75bZBBxhPsAqkMkktZXKX6/bF3LW6A1ccq4wpcbP6NFeRKukzozm1YuiR7FRnOb4FIMoVhycoFQaV2kkBwMyTkiXBRKYqw8fKVOmrjm62NNXd5UBwiABISElXkuOynlhz0+ypJF0dIMU/N88PcynxjZif0qgBFI3c2BgqKrkKfAbHmN6hcJSIaQOCy6xAS+Rufi7pq0AtDTPMH+6XCglbZIKTUk5ZIbV/946XZsZ8aZ36jdMYfELKyufWRtisEpZyZ1jyQgwBjg6fYZ6s4nHnaQbvzn5Xeb2plncyDLKUD1lxHAKxfW90mClsC5FGGsJgfXMDzlSACAmTBjCS+lKYUN1DPurRMsmgSqi9vVfLL0K41a8S0rtGu8xdHtppkeEDIiybrXFYPBthkJ2x35tIW7i394YKlZ4Tyaz0lgnRgnURQm69QSeSEC6tr58ZrxiOdCBQ9FwOGJ++nwCuYuWqDABQ7CxjoGosgh1zwRLAtxK5zwYCCzgF+u9U7AQeW2Kb/acVlefcI8f5HlFsAyD8foEJOXU+6EtPLZfOuwJ+egt9SzlRe+Vd1+1YDsFE79MbeAFxUybuGUcUgapKyVtxmIi/vz0LsmynFUEoNCDCqoCws9EH1o6an7Mc3Ts/t+h1v21DeWpkqKuhkS84jujD7khB0CNn9Jsi11w/eWY4Xubc+JScOuizV7Y5gDQydfZoQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BL0PR12MB5506.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(7416002)(26005)(4326008)(2616005)(66556008)(30864003)(921005)(66476007)(426003)(66946007)(9746002)(9786002)(5660300002)(186003)(83380400001)(86362001)(508600001)(8936002)(6666004)(110136005)(38100700002)(36756003)(316002)(8676002)(2906002)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: m26eoeDd5se3KpMqTH0R7g6KuX8dcrlXL8h+hN4d7ka++SRwVubtYov9/d28GlulkOFwmNSpvwMHME3vRl55Y7wAK9RjqPcE6oLERZ2CudQQK92PsZ5sfaNtRsac7t8bmOgjwLwSP4dcWSWikrM5cGXsec34AHI3E3yx/8CMT9xP6wQ3dUNjp5AebojSWicR4MKDfjjQuRr8k4BcI6s+Q9/zGTadyqJdvAXpkvrfl1cYlG9XTjuu/c21D0I5mpDc5B6Y8+nRi9bpGuSiNInZBBT3VRH7cycQCbqe8NuQ/dWPhYiqIjy7IcSAnAqk/B8NSwkMtP3TrmQrYgtvSXW9vzsxvwXuGb9SnwOwbbfy7EZ1VhE1N/PoKntj6o+TjEFl3UptCyvXlc9nSZVAnunUyYq4oCHHaGVmqrSxcWpLFHKayrBdzSPAh2ZiOD+zUvcs7yBEcUS76ckSBbyK/ttJl81gB1ugV5zO0wNA6KGKxvEUINDWKxk5AUqfEA+FQSvSawrN+f4/qKuTWRdXs0EwUq9lpRRNB/s5B5LrYy/UnF3UQHN1wFX/FIZ59S7EvIqSJFmE4Bb8O44CMwfNpy6rHmAsTJ8dj24f6XggBCg4z4FAcLCehm0JB5Gll4F4kfdSp2i3vwiJFM61DNLeQMhxBgtXgtmQjwPzukPc/CnJU4SQq+TCF7bDLHW+AUOidicDMVpIqrLWXOEGqhOcqYNS0eJboczJNMLEMHndOGb1ay8V/dcAllf7NQsmpWXPxuFD X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: f20e1b45-6278-4f5d-657b-08d973c9742e X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Sep 2021 19:38:52.8576 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 3rXnHb1bOHVAIyqbibiaDiEGkbk9Ud5tjtNYdCFpvYv8fhZEaWSHW3ZS/llZHFtM X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB5554 Subject: [Intel-gfx] [PATCH v2 5/9] vfio/mdev: Consolidate all the device_api sysfs into the core code X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Every driver just emits a static string, simply feed it through the ops and provide a standard sysfs show function. Signed-off-by: Jason Gunthorpe --- drivers/gpu/drm/i915/gvt/kvmgt.c | 9 +-------- drivers/s390/cio/vfio_ccw_ops.c | 9 +-------- drivers/s390/crypto/vfio_ap_ops.c | 9 +-------- drivers/vfio/mdev/mdev_core.c | 2 +- drivers/vfio/mdev/mdev_sysfs.c | 27 ++++++++++++++++++++++++--- include/linux/mdev.h | 7 ++----- samples/vfio-mdev/mbochs.c | 9 +-------- samples/vfio-mdev/mdpy.c | 9 +-------- samples/vfio-mdev/mtty.c | 10 +--------- 9 files changed, 33 insertions(+), 58 deletions(-) diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c b/drivers/gpu/drm/i915/gvt/kvmgt.c index 7efa386449d104..d198cc3d132277 100644 --- a/drivers/gpu/drm/i915/gvt/kvmgt.c +++ b/drivers/gpu/drm/i915/gvt/kvmgt.c @@ -161,12 +161,6 @@ static ssize_t available_instances_show(struct mdev_type *mtype, return sprintf(buf, "%u\n", num); } -static ssize_t device_api_show(struct mdev_type *mtype, - struct mdev_type_attribute *attr, char *buf) -{ - return sprintf(buf, "%s\n", VFIO_DEVICE_API_PCI_STRING); -} - static ssize_t description_show(struct mdev_type *mtype, struct mdev_type_attribute *attr, char *buf) { @@ -187,12 +181,10 @@ static ssize_t description_show(struct mdev_type *mtype, } static MDEV_TYPE_ATTR_RO(available_instances); -static MDEV_TYPE_ATTR_RO(device_api); static MDEV_TYPE_ATTR_RO(description); static struct attribute *gvt_type_attrs[] = { &mdev_type_attr_available_instances.attr, - &mdev_type_attr_device_api.attr, &mdev_type_attr_description.attr, NULL, }; @@ -1750,6 +1742,7 @@ static const struct attribute_group *intel_vgpu_groups[] = { static struct mdev_parent_ops intel_vgpu_ops = { .mdev_attr_groups = intel_vgpu_groups, + .device_api = VFIO_DEVICE_API_PCI_STRING, .create = intel_vgpu_create, .remove = intel_vgpu_remove, diff --git a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_ops.c index 6e70620d5dfbc8..18a48d1f1e8fff 100644 --- a/drivers/s390/cio/vfio_ccw_ops.c +++ b/drivers/s390/cio/vfio_ccw_ops.c @@ -70,13 +70,6 @@ static ssize_t name_show(struct mdev_type *mtype, } static MDEV_TYPE_ATTR_RO(name); -static ssize_t device_api_show(struct mdev_type *mtype, - struct mdev_type_attribute *attr, char *buf) -{ - return sprintf(buf, "%s\n", VFIO_DEVICE_API_CCW_STRING); -} -static MDEV_TYPE_ATTR_RO(device_api); - static ssize_t available_instances_show(struct mdev_type *mtype, struct mdev_type_attribute *attr, char *buf) @@ -90,7 +83,6 @@ static MDEV_TYPE_ATTR_RO(available_instances); static struct attribute *mdev_types_attrs[] = { &mdev_type_attr_name.attr, - &mdev_type_attr_device_api.attr, &mdev_type_attr_available_instances.attr, NULL, }; @@ -640,6 +632,7 @@ struct mdev_driver vfio_ccw_mdev_driver = { static const struct mdev_parent_ops vfio_ccw_mdev_ops = { .owner = THIS_MODULE, .device_driver = &vfio_ccw_mdev_driver, + .device_api = VFIO_DEVICE_API_CCW_STRING, .supported_type_groups = mdev_type_groups, }; diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c index 54bb0c22e8020e..005c2a2b14af3f 100644 --- a/drivers/s390/crypto/vfio_ap_ops.c +++ b/drivers/s390/crypto/vfio_ap_ops.c @@ -400,17 +400,9 @@ static ssize_t available_instances_show(struct mdev_type *mtype, static MDEV_TYPE_ATTR_RO(available_instances); -static ssize_t device_api_show(struct mdev_type *mtype, - struct mdev_type_attribute *attr, char *buf) -{ - return sprintf(buf, "%s\n", VFIO_DEVICE_API_AP_STRING); -} - -static MDEV_TYPE_ATTR_RO(device_api); static struct attribute *vfio_ap_mdev_type_attrs[] = { &mdev_type_attr_name.attr, - &mdev_type_attr_device_api.attr, &mdev_type_attr_available_instances.attr, NULL, }; @@ -1399,6 +1391,7 @@ static struct mdev_driver vfio_ap_matrix_driver = { static const struct mdev_parent_ops vfio_ap_matrix_ops = { .owner = THIS_MODULE, .device_driver = &vfio_ap_matrix_driver, + .device_api = VFIO_DEVICE_API_AP_STRING, .supported_type_groups = vfio_ap_mdev_type_groups, }; diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c index b314101237fe22..c3018e8e6d3258 100644 --- a/drivers/vfio/mdev/mdev_core.c +++ b/drivers/vfio/mdev/mdev_core.c @@ -129,7 +129,7 @@ int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops) char *envp[] = { env_string, NULL }; /* check for mandatory ops */ - if (!ops || !ops->supported_type_groups) + if (!ops || !ops->supported_type_groups || !ops->device_api) return -EINVAL; if (!ops->device_driver && (!ops->create || !ops->remove)) return -EINVAL; diff --git a/drivers/vfio/mdev/mdev_sysfs.c b/drivers/vfio/mdev/mdev_sysfs.c index f5cf1931c54e48..d4b99440d19e9a 100644 --- a/drivers/vfio/mdev/mdev_sysfs.c +++ b/drivers/vfio/mdev/mdev_sysfs.c @@ -74,9 +74,30 @@ static ssize_t create_store(struct mdev_type *mtype, return count; } - static MDEV_TYPE_ATTR_WO(create); +static ssize_t device_api_show(struct mdev_type *mtype, + struct mdev_type_attribute *attr, char *buf) +{ + return sysfs_emit(buf, "%s\n", mtype->parent->ops->device_api); +} +static MDEV_TYPE_ATTR_RO(device_api); + +static struct attribute *mdev_types_std_attrs[] = { + &mdev_type_attr_create.attr, + &mdev_type_attr_device_api.attr, + NULL, +}; + +static struct attribute_group mdev_type_std_group = { + .attrs = mdev_types_std_attrs, +}; + +static const struct attribute_group *mdev_type_groups[] = { + &mdev_type_std_group, + NULL, +}; + static void mdev_type_release(struct kobject *kobj) { struct mdev_type *type = to_mdev_type(kobj); @@ -123,7 +144,7 @@ static struct mdev_type *add_mdev_supported_type(struct mdev_parent *parent, return ERR_PTR(ret); } - ret = sysfs_create_file(&type->kobj, &mdev_type_attr_create.attr); + ret = sysfs_create_groups(&type->kobj, mdev_type_groups); if (ret) goto attr_create_failed; @@ -144,7 +165,7 @@ static struct mdev_type *add_mdev_supported_type(struct mdev_parent *parent, attrs_failed: kobject_put(type->devices_kobj); attr_devices_failed: - sysfs_remove_file(&type->kobj, &mdev_type_attr_create.attr); + sysfs_remove_groups(&type->kobj, mdev_type_groups); attr_create_failed: kobject_del(&type->kobj); kobject_put(&type->kobj); diff --git a/include/linux/mdev.h b/include/linux/mdev.h index 68427e8fadebd6..7f1db354f45f14 100644 --- a/include/linux/mdev.h +++ b/include/linux/mdev.h @@ -56,6 +56,7 @@ struct device *mtype_get_parent_dev(struct mdev_type *mtype); * * @owner: The module owner. * @device_driver: Which device driver to probe() on newly created devices + * @device_api: String to return for the device_api sysfs * @dev_attr_groups: Attributes of the parent device. * @mdev_attr_groups: Attributes of the mediated device. * @supported_type_groups: Attributes to define supported types. It is mandatory @@ -100,6 +101,7 @@ struct device *mtype_get_parent_dev(struct mdev_type *mtype); struct mdev_parent_ops { struct module *owner; struct mdev_driver *device_driver; + const char *device_api; const struct attribute_group **dev_attr_groups; const struct attribute_group **mdev_attr_groups; struct attribute_group **supported_type_groups; @@ -128,11 +130,6 @@ struct mdev_type_attribute { size_t count); }; -#define MDEV_TYPE_ATTR(_name, _mode, _show, _store) \ -struct mdev_type_attribute mdev_type_attr_##_name = \ - __ATTR(_name, _mode, _show, _store) -#define MDEV_TYPE_ATTR_RW(_name) \ - struct mdev_type_attribute mdev_type_attr_##_name = __ATTR_RW(_name) #define MDEV_TYPE_ATTR_RO(_name) \ struct mdev_type_attribute mdev_type_attr_##_name = __ATTR_RO(_name) #define MDEV_TYPE_ATTR_WO(_name) \ diff --git a/samples/vfio-mdev/mbochs.c b/samples/vfio-mdev/mbochs.c index c313ab4d1f4e4e..abd889bc1f9dcf 100644 --- a/samples/vfio-mdev/mbochs.c +++ b/samples/vfio-mdev/mbochs.c @@ -1358,17 +1358,9 @@ static ssize_t available_instances_show(struct mdev_type *mtype, } static MDEV_TYPE_ATTR_RO(available_instances); -static ssize_t device_api_show(struct mdev_type *mtype, - struct mdev_type_attribute *attr, char *buf) -{ - return sprintf(buf, "%s\n", VFIO_DEVICE_API_PCI_STRING); -} -static MDEV_TYPE_ATTR_RO(device_api); - static struct attribute *mdev_types_attrs[] = { &mdev_type_attr_name.attr, &mdev_type_attr_description.attr, - &mdev_type_attr_device_api.attr, &mdev_type_attr_available_instances.attr, NULL, }; @@ -1417,6 +1409,7 @@ static struct mdev_driver mbochs_driver = { static const struct mdev_parent_ops mdev_fops = { .owner = THIS_MODULE, .device_driver = &mbochs_driver, + .device_api = VFIO_DEVICE_API_PCI_STRING, .supported_type_groups = mdev_type_groups, }; diff --git a/samples/vfio-mdev/mdpy.c b/samples/vfio-mdev/mdpy.c index 8d1a80a0722aa9..b81d7848619cae 100644 --- a/samples/vfio-mdev/mdpy.c +++ b/samples/vfio-mdev/mdpy.c @@ -670,17 +670,9 @@ static ssize_t available_instances_show(struct mdev_type *mtype, } static MDEV_TYPE_ATTR_RO(available_instances); -static ssize_t device_api_show(struct mdev_type *mtype, - struct mdev_type_attribute *attr, char *buf) -{ - return sprintf(buf, "%s\n", VFIO_DEVICE_API_PCI_STRING); -} -static MDEV_TYPE_ATTR_RO(device_api); - static struct attribute *mdev_types_attrs[] = { &mdev_type_attr_name.attr, &mdev_type_attr_description.attr, - &mdev_type_attr_device_api.attr, &mdev_type_attr_available_instances.attr, NULL, }; @@ -728,6 +720,7 @@ static struct mdev_driver mdpy_driver = { static const struct mdev_parent_ops mdev_fops = { .owner = THIS_MODULE, .device_driver = &mdpy_driver, + .device_api = VFIO_DEVICE_API_PCI_STRING, .supported_type_groups = mdev_type_groups, }; diff --git a/samples/vfio-mdev/mtty.c b/samples/vfio-mdev/mtty.c index 5983cdb16e3d1d..b473ecc7733f7d 100644 --- a/samples/vfio-mdev/mtty.c +++ b/samples/vfio-mdev/mtty.c @@ -1281,17 +1281,8 @@ static ssize_t available_instances_show(struct mdev_type *mtype, static MDEV_TYPE_ATTR_RO(available_instances); -static ssize_t device_api_show(struct mdev_type *mtype, - struct mdev_type_attribute *attr, char *buf) -{ - return sprintf(buf, "%s\n", VFIO_DEVICE_API_PCI_STRING); -} - -static MDEV_TYPE_ATTR_RO(device_api); - static struct attribute *mdev_types_attrs[] = { &mdev_type_attr_name.attr, - &mdev_type_attr_device_api.attr, &mdev_type_attr_available_instances.attr, NULL, }; @@ -1333,6 +1324,7 @@ static struct mdev_driver mtty_driver = { static const struct mdev_parent_ops mdev_fops = { .owner = THIS_MODULE, .device_driver = &mtty_driver, + .device_api = VFIO_DEVICE_API_PCI_STRING, .dev_attr_groups = mtty_dev_groups, .supported_type_groups = mdev_type_groups, }; From patchwork Thu Sep 9 19:38:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12483759 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 04B92C433EF for ; Thu, 9 Sep 2021 19:39:15 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C402E61059 for ; Thu, 9 Sep 2021 19:39:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org C402E61059 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AE2706E90E; Thu, 9 Sep 2021 19:38:57 +0000 (UTC) Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2060.outbound.protection.outlook.com [40.107.92.60]) by gabe.freedesktop.org (Postfix) with ESMTPS id 66E456E90A; Thu, 9 Sep 2021 19:38:55 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DHViGpAFKyXh1sLTZDhsmELznC410A6yu2qVTBl/tpsV7j/JbzdVU2sxchLiAd0KzJpv/GbecnV3UYt31bimLDs4pAMFnbmZsUcOPXcSx3d1IhW0ufivjyTpAPWUgWeT1P/ScA+a/FESUh3iQYPiA+y2f/tt8lz37jGFe2/iaXcL0nK7/Fh3Lg78NC++mEtwKRyLdakLY5OGvsmvlw/3CirTgeptgo+tWcG774dBjA8QD9R/y61nsDWH2SNiDbvGNgy1MoSw7ZMU1P5ADBi92Kxr8IqPp0Z4qmNceSqoKtoO34cLj99Mzc2lMflO47dr2kOYIA1H5jZdBbyezY8+bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=vLOFRwrfk6C+B7LsVn1Yr+1OfPjT1Qei/N+YURqHE4Y=; b=HZ3PymjZclt/fViGKtRc+WQaMRfbl5BvQCGAc90FTLm1Z1BlI7eZuIbwSs19Eri6yu5URoo3xamMB5zd/u6+6i5ZuSgyYEo/XQk1tapFKCC8D9ZtETokbbIpWXId+VgnPVzL3q3X+ryQgOQ4bAfieXg0v50K1oWcQUGd0HD3Dwro9+tTX+tzUZgwS+hScOzXIukk3khz9Ujcg+BboPN3HCuK1W0HcZkgTNKyvGFCvnE4YlsKkVQhofnUBtI5HuvJYQN66BOG7hVCpIyFca1dOVMjfEMtmDy9iiIvjJVZgJ6t8cs/YYKHmhzbyJHvzOpfI1wU/RUIsahe/WkJk8PELQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vLOFRwrfk6C+B7LsVn1Yr+1OfPjT1Qei/N+YURqHE4Y=; b=MMNPVpYrkAkBKw5JsX1qzrufneBWTsfENPrS5x1LDPDJtDlzdcNmfbzVe/HvRpROxUozWb2aZBjlhGhMVwZim7xvFFIuORbBlmDQxQtdUPPL+laC33JiWDmVS8TGEqkK4MD7SyLjnQTOL1+6ydnooyC+SPcLRng2a2LIkN0T4Qc5gJRBaqtDqnLGLuKfLqQ+EPkwzuog2uTcUh2CkDs6myYIZWS1Mz0dThubfOymw9AUIOMzVi1AFHMM2f9zqYqBTRX8FQpD2phkuqppPEmAAVxKaFQcEsQ4MZaeF/1YsURMHRKFU1+EnuFrcniMCOw+YdIcHLHdQ/EnxvXj10gWzw== Authentication-Results: linux.ie; dkim=none (message not signed) header.d=none;linux.ie; dmarc=none action=none header.from=nvidia.com; Received: from BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) by BL0PR12MB5507.namprd12.prod.outlook.com (2603:10b6:208:1c4::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14; Thu, 9 Sep 2021 19:38:53 +0000 Received: from BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::e8af:232:915e:2f95]) by BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::e8af:232:915e:2f95%8]) with mapi id 15.20.4500.014; Thu, 9 Sep 2021 19:38:53 +0000 From: Jason Gunthorpe To: David Airlie , Tony Krowiak , Alex Williamson , Christian Borntraeger , Cornelia Huck , Daniel Vetter , dri-devel@lists.freedesktop.org, Eric Farman , Harald Freudenberger , Vasily Gorbik , Heiko Carstens , intel-gfx@lists.freedesktop.org, intel-gvt-dev@lists.freedesktop.org, Jani Nikula , Jason Herne , Joonas Lahtinen , kvm@vger.kernel.org, Kirti Wankhede , linux-s390@vger.kernel.org, Matthew Rosato , Peter Oberparleiter , Halil Pasic , Rodrigo Vivi , Vineeth Vijayan , Zhenyu Wang , Zhi Wang Cc: Christoph Hellwig Date: Thu, 9 Sep 2021 16:38:46 -0300 Message-Id: <6-v2-7d3a384024cf+2060-ccw_mdev_jgg@nvidia.com> In-Reply-To: <0-v2-7d3a384024cf+2060-ccw_mdev_jgg@nvidia.com> References: X-ClientProxiedBy: BL0PR0102CA0035.prod.exchangelabs.com (2603:10b6:207:18::48) To BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) MIME-Version: 1.0 Received: from mlx.ziepe.ca (142.162.113.129) by BL0PR0102CA0035.prod.exchangelabs.com (2603:10b6:207:18::48) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Thu, 9 Sep 2021 19:38:51 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1mOPsn-00FLF6-MB; Thu, 09 Sep 2021 16:38:49 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6e500e94-74cc-441f-da18-08d973c97384 X-MS-TrafficTypeDiagnostic: BL0PR12MB5507: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:313; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2ITzcgDIMzSxHcID0+TD4hMWAHZfYCnbcBMe2Im2f2JxyUkdkJkgJio2k7LNBHBLyLlTEwrG3wNvN9B6jV2PFKhqcIVR1Hypvy8QaTPRpLtwluE+fiBwp64d3RGrNSdKbAUhTme8k2UjrDEc/vjsBR1b3X8Nics1ZMw1s4VB8zziLF3rXsNNzxNUMONrCWUIx52fugifSxwiblTUOeTukZa2XxSUIjxohkaYL4EQEalK+5HFaWHbT9W7ArquToiQ6gSHMPSJu6cSzLRu6KSlgs06ty0zIeLica2eF/yVdITxN05q5My/HoIKP9ptQ+gyLw6XY4bFR1OeLruAzqtPZdiU3OBT/rwT1BzU/WKJ66opsBvVkvxmLBbnF38yfbo54xFUu5nGZA9ZYIg7ziA4CQoVmpzgdZ7mjUgDGyUaUrPy1dhzkHnmgKONeI+BsvKAzz01+vJ2dtMojMfONejTda8jSUxL55GeIAweADoiEe7P6pQ9xRJkx14NdEjduehRmkMoS7Ul8uSvUg2Um35dZ1fTDVIeErDY6+kPCm5Zx19SocZ+VxqFRomOt1ZdS0oBaQypmuD92lacuIvaoF1gSZH4FHKD9M4X2bRUiIsTApUqv3udFZPQWKIP+J5Y2cGTHBAe54kjJOxkQmkL0WdCmhb1w0jdmFRI1CR2u8StjBwxW23AXjpKbohsjCn5zGZw1TwGUo61GhvG1ENxyeiKO1F6aVaRWOrJDmQ2+MacKrc= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BL0PR12MB5506.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(136003)(39860400002)(376002)(346002)(366004)(396003)(8676002)(66476007)(478600001)(4326008)(66946007)(66556008)(30864003)(8936002)(921005)(5660300002)(186003)(26005)(86362001)(83380400001)(7416002)(2906002)(36756003)(426003)(2616005)(9746002)(9786002)(110136005)(6666004)(38100700002)(316002)(131093003)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: pGawlb7jU2Mkp3c2yrC2FwmEmc+t9vhFHqNiYBAI8lAm34wZZrabIwEvYfb18IslMqdncdDGZoTgk+r0jB12BTbT67xSX0eJKgdNUEZdkKqUR3dfbjPNVU3y3KmRslqTbHyS0mTeZO38vNzslaBJzyfUq2eQ6kY/Uf4Srgkys/hEjAxUjHOXhAJVDJWlkMfYjzvOPP6B3kD8JSCtskE/ipkHziRFqe/wQZDyxrTFuzWel3TRLwTxHAte+j599TuVxY0GkV8WVzWjVrV1npl/bSGGvSdzENySBqjayMx+7xAH6mB/3DmVTvS9T60zLhXuic3Q9WjguN57wLcwd9sPEytT7k3/ka+olb9nuARrtI7eDO8XVFUzVsjYBhx3CtpUvGZOcsBZZVyYG89EPUucFRQZqskAcr2JiorbVSg6cpd9L5aqq8fcZeWLHQ00E3k/7cDybSyl/dBm1JlJnjB4cj3+6cKGz6ABzxPS3eS07r790iaTN8vs2IQSK24Y9wrS8L/EEntIOvaxKCXTanVk+OiYStMtmrppP5y3WjfXR0ZlCHUSKd/hNo5Sez4c0wECQFqIbV8MxMmmnVgnYwSWl5rauC+D3CTSXXdtKq3w/VEJoiwhRj/Y0/XYcCnk4aGdPEy6fiGAyU+PUox0idKkFQuebdt/UM+3D5bO8oI3mzQw/ZJ/TLiECXic3BOSK7J/h/M18K2ZFBQ0/SONdFplt5u8ygsW7yNZk5haI7WMihiTbnmGEKC540FeyeY17G/o X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6e500e94-74cc-441f-da18-08d973c97384 X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Sep 2021 19:38:51.7026 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: pJESOLhksMfQNHk0Y3HrITH0b/rIZibKzoqU3xDKpXJBI3vNX3JJNhXgW5xr8yAW X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB5507 Subject: [Intel-gfx] [PATCH v2 6/9] vfio/mdev: Add mdev available instance checking to the core X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Many of the mdev drivers use a simple counter for keeping track of the available instances. Move this code to the core code and store the counter in the mdev_type. Implement it using correct locking, fixing mdpy. Drivers provide a get_available() callback to set the number of available instances for their mtypes which is fixed at registration time. The core provides a standard sysfs attribute to return the available_instances. Signed-off-by: Jason Gunthorpe Reviewed-by: Christoph Hellwig --- drivers/s390/cio/vfio_ccw_drv.c | 1 - drivers/s390/cio/vfio_ccw_ops.c | 26 ++++++------------- drivers/s390/cio/vfio_ccw_private.h | 2 -- drivers/s390/crypto/vfio_ap_ops.c | 32 ++++++----------------- drivers/s390/crypto/vfio_ap_private.h | 2 -- drivers/vfio/mdev/mdev_core.c | 11 +++++++- drivers/vfio/mdev/mdev_private.h | 2 ++ drivers/vfio/mdev/mdev_sysfs.c | 37 +++++++++++++++++++++++++++ include/linux/mdev.h | 2 ++ samples/vfio-mdev/mdpy.c | 22 +++++----------- 10 files changed, 73 insertions(+), 64 deletions(-) diff --git a/drivers/s390/cio/vfio_ccw_drv.c b/drivers/s390/cio/vfio_ccw_drv.c index 99f2823361718f..de782e967a5474 100644 --- a/drivers/s390/cio/vfio_ccw_drv.c +++ b/drivers/s390/cio/vfio_ccw_drv.c @@ -106,7 +106,6 @@ static struct vfio_ccw_private *vfio_ccw_alloc_private(struct subchannel *sch) INIT_LIST_HEAD(&private->crw); INIT_WORK(&private->io_work, vfio_ccw_sch_io_todo); INIT_WORK(&private->crw_work, vfio_ccw_crw_todo); - atomic_set(&private->avail, 1); private->cp.guest_cp = kcalloc(CCWCHAIN_LEN_MAX, sizeof(struct ccw1), GFP_KERNEL); diff --git a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_ops.c index 18a48d1f1e8fff..38ab5c1f25ec09 100644 --- a/drivers/s390/cio/vfio_ccw_ops.c +++ b/drivers/s390/cio/vfio_ccw_ops.c @@ -70,20 +70,9 @@ static ssize_t name_show(struct mdev_type *mtype, } static MDEV_TYPE_ATTR_RO(name); -static ssize_t available_instances_show(struct mdev_type *mtype, - struct mdev_type_attribute *attr, - char *buf) -{ - struct vfio_ccw_private *private = - dev_get_drvdata(mtype_get_parent_dev(mtype)); - - return sprintf(buf, "%d\n", atomic_read(&private->avail)); -} -static MDEV_TYPE_ATTR_RO(available_instances); static struct attribute *mdev_types_attrs[] = { &mdev_type_attr_name.attr, - &mdev_type_attr_available_instances.attr, NULL, }; @@ -102,9 +91,6 @@ static int vfio_ccw_mdev_probe(struct mdev_device *mdev) struct vfio_ccw_private *private = dev_get_drvdata(mdev->dev.parent); int ret; - if (atomic_dec_if_positive(&private->avail) < 0) - return -EPERM; - memset(&private->vdev, 0, sizeof(private->vdev)); vfio_init_group_dev(&private->vdev, &mdev->dev, &vfio_ccw_dev_ops); @@ -118,13 +104,12 @@ static int vfio_ccw_mdev_probe(struct mdev_device *mdev) ret = vfio_register_group_dev(&private->vdev); if (ret) - goto err_atomic; + goto err_init; dev_set_drvdata(&mdev->dev, private); return 0; -err_atomic: +err_init: vfio_uninit_group_dev(&private->vdev); - atomic_inc(&private->avail); private->mdev = NULL; return ret; } @@ -141,7 +126,6 @@ static void vfio_ccw_mdev_remove(struct mdev_device *mdev) vfio_unregister_group_dev(&private->vdev); vfio_uninit_group_dev(&private->vdev); private->mdev = NULL; - atomic_inc(&private->avail); } static int vfio_ccw_mdev_open_device(struct vfio_device *vdev) @@ -610,6 +594,11 @@ static void vfio_ccw_mdev_request(struct vfio_device *vdev, unsigned int count) } } +static unsigned int vfio_ccw_get_available(struct mdev_type *mtype) +{ + return 1; +} + static const struct vfio_device_ops vfio_ccw_dev_ops = { .open_device = vfio_ccw_mdev_open_device, .close_device = vfio_ccw_mdev_close_device, @@ -627,6 +616,7 @@ struct mdev_driver vfio_ccw_mdev_driver = { }, .probe = vfio_ccw_mdev_probe, .remove = vfio_ccw_mdev_remove, + .get_available = vfio_ccw_get_available, }; static const struct mdev_parent_ops vfio_ccw_mdev_ops = { diff --git a/drivers/s390/cio/vfio_ccw_private.h b/drivers/s390/cio/vfio_ccw_private.h index 5e98eacdf31074..bbc97eb9d9c6fc 100644 --- a/drivers/s390/cio/vfio_ccw_private.h +++ b/drivers/s390/cio/vfio_ccw_private.h @@ -72,7 +72,6 @@ struct vfio_ccw_crw { * @sch: pointer to the subchannel * @state: internal state of the device * @completion: synchronization helper of the I/O completion - * @avail: available for creating a mediated device * @mdev: pointer to the mediated device * @nb: notifier for vfio events * @io_region: MMIO region to input/output I/O arguments/results @@ -96,7 +95,6 @@ struct vfio_ccw_private { struct subchannel *sch; int state; struct completion *completion; - atomic_t avail; struct mdev_device *mdev; struct notifier_block nb; struct ccw_io_region *io_region; diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c index 005c2a2b14af3f..737e8d137bd43b 100644 --- a/drivers/s390/crypto/vfio_ap_ops.c +++ b/drivers/s390/crypto/vfio_ap_ops.c @@ -332,14 +332,9 @@ static int vfio_ap_mdev_probe(struct mdev_device *mdev) struct ap_matrix_mdev *matrix_mdev; int ret; - if ((atomic_dec_if_positive(&matrix_dev->available_instances) < 0)) - return -EPERM; - matrix_mdev = kzalloc(sizeof(*matrix_mdev), GFP_KERNEL); - if (!matrix_mdev) { - ret = -ENOMEM; - goto err_dec_available; - } + if (!matrix_mdev) + return -ENOMEM; vfio_init_group_dev(&matrix_mdev->vdev, &mdev->dev, &vfio_ap_matrix_dev_ops); @@ -362,8 +357,6 @@ static int vfio_ap_mdev_probe(struct mdev_device *mdev) mutex_unlock(&matrix_dev->lock); vfio_uninit_group_dev(&matrix_mdev->vdev); kfree(matrix_mdev); -err_dec_available: - atomic_inc(&matrix_dev->available_instances); return ret; } @@ -378,7 +371,6 @@ static void vfio_ap_mdev_remove(struct mdev_device *mdev) list_del(&matrix_mdev->node); vfio_uninit_group_dev(&matrix_mdev->vdev); kfree(matrix_mdev); - atomic_inc(&matrix_dev->available_instances); mutex_unlock(&matrix_dev->lock); } @@ -390,20 +382,8 @@ static ssize_t name_show(struct mdev_type *mtype, static MDEV_TYPE_ATTR_RO(name); -static ssize_t available_instances_show(struct mdev_type *mtype, - struct mdev_type_attribute *attr, - char *buf) -{ - return sprintf(buf, "%d\n", - atomic_read(&matrix_dev->available_instances)); -} - -static MDEV_TYPE_ATTR_RO(available_instances); - - static struct attribute *vfio_ap_mdev_type_attrs[] = { &mdev_type_attr_name.attr, - &mdev_type_attr_available_instances.attr, NULL, }; @@ -1371,6 +1351,11 @@ static ssize_t vfio_ap_mdev_ioctl(struct vfio_device *vdev, return ret; } +static unsigned int vfio_ap_mdev_get_available(struct mdev_type *mtype) +{ + return MAX_ZDEV_ENTRIES_EXT; +} + static const struct vfio_device_ops vfio_ap_matrix_dev_ops = { .open_device = vfio_ap_mdev_open_device, .close_device = vfio_ap_mdev_close_device, @@ -1386,6 +1371,7 @@ static struct mdev_driver vfio_ap_matrix_driver = { }, .probe = vfio_ap_mdev_probe, .remove = vfio_ap_mdev_remove, + .get_available = vfio_ap_mdev_get_available, }; static const struct mdev_parent_ops vfio_ap_matrix_ops = { @@ -1399,8 +1385,6 @@ int vfio_ap_mdev_register(void) { int ret; - atomic_set(&matrix_dev->available_instances, MAX_ZDEV_ENTRIES_EXT); - ret = mdev_register_driver(&vfio_ap_matrix_driver); if (ret) return ret; diff --git a/drivers/s390/crypto/vfio_ap_private.h b/drivers/s390/crypto/vfio_ap_private.h index 77760e2b546fe6..dd87c84605bcb6 100644 --- a/drivers/s390/crypto/vfio_ap_private.h +++ b/drivers/s390/crypto/vfio_ap_private.h @@ -28,7 +28,6 @@ /** * ap_matrix_dev - the AP matrix device structure * @device: generic device structure associated with the AP matrix device - * @available_instances: number of mediated matrix devices that can be created * @info: the struct containing the output from the PQAP(QCI) instruction * mdev_list: the list of mediated matrix devices created * lock: mutex for locking the AP matrix device. This lock will be @@ -39,7 +38,6 @@ */ struct ap_matrix_dev { struct device device; - atomic_t available_instances; struct ap_config_info info; struct list_head mdev_list; struct mutex lock; diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c index c3018e8e6d3258..33a5e738867488 100644 --- a/drivers/vfio/mdev/mdev_core.c +++ b/drivers/vfio/mdev/mdev_core.c @@ -25,7 +25,7 @@ static DEFINE_MUTEX(parent_list_lock); static struct class_compat *mdev_bus_compat_class; static LIST_HEAD(mdev_list); -static DEFINE_MUTEX(mdev_list_lock); +DEFINE_MUTEX(mdev_list_lock); struct device *mdev_parent_dev(struct mdev_device *mdev) { @@ -245,6 +245,7 @@ static void mdev_device_release(struct device *dev) mutex_lock(&mdev_list_lock); list_del(&mdev->next); + mdev->type->available++; mutex_unlock(&mdev_list_lock); dev_dbg(&mdev->dev, "MDEV: destroying\n"); @@ -268,6 +269,14 @@ int mdev_device_create(struct mdev_type *type, const guid_t *uuid) } } + if (drv->get_available) { + if (!type->available) { + mutex_unlock(&mdev_list_lock); + return -EUSERS; + } + type->available--; + } + mdev = kzalloc(sizeof(*mdev), GFP_KERNEL); if (!mdev) { mutex_unlock(&mdev_list_lock); diff --git a/drivers/vfio/mdev/mdev_private.h b/drivers/vfio/mdev/mdev_private.h index afbad7b0a14a17..83586b07023334 100644 --- a/drivers/vfio/mdev/mdev_private.h +++ b/drivers/vfio/mdev/mdev_private.h @@ -29,6 +29,7 @@ struct mdev_type { struct kobject *devices_kobj; struct mdev_parent *parent; struct list_head next; + unsigned int available; unsigned int type_group_id; }; @@ -38,6 +39,7 @@ struct mdev_type { container_of(_kobj, struct mdev_type, kobj) extern struct mdev_driver vfio_mdev_driver; +extern struct mutex mdev_list_lock; int parent_create_sysfs_files(struct mdev_parent *parent); void parent_remove_sysfs_files(struct mdev_parent *parent); diff --git a/drivers/vfio/mdev/mdev_sysfs.c b/drivers/vfio/mdev/mdev_sysfs.c index d4b99440d19e9a..b3129dfc27ef7d 100644 --- a/drivers/vfio/mdev/mdev_sysfs.c +++ b/drivers/vfio/mdev/mdev_sysfs.c @@ -93,8 +93,41 @@ static struct attribute_group mdev_type_std_group = { .attrs = mdev_types_std_attrs, }; +/* mdev_type attribute used by drivers that have an get_available() op */ +static ssize_t available_instances_show(struct mdev_type *mtype, + struct mdev_type_attribute *attr, + char *buf) +{ + unsigned int available; + + mutex_lock(&mdev_list_lock); + available = mtype->available; + mutex_unlock(&mdev_list_lock); + + return sysfs_emit(buf, "%u\n", available); +} +static MDEV_TYPE_ATTR_RO(available_instances); +static umode_t available_instances_is_visible(struct kobject *kobj, + struct attribute *attr, int n) +{ + struct mdev_type *type = to_mdev_type(kobj); + + if (!type->parent->ops->device_driver->get_available) + return 0; + return attr->mode; +} +static struct attribute *mdev_types_name_attrs[] = { + &mdev_type_attr_available_instances.attr, + NULL, +}; +static struct attribute_group mdev_type_available_instances_group = { + .attrs = mdev_types_name_attrs, + .is_visible = available_instances_is_visible, +}; + static const struct attribute_group *mdev_type_groups[] = { &mdev_type_std_group, + &mdev_type_available_instances_group, NULL, }; @@ -136,6 +169,10 @@ static struct mdev_type *add_mdev_supported_type(struct mdev_parent *parent, mdev_get_parent(parent); type->type_group_id = type_group_id; + if (parent->ops->device_driver->get_available) + type->available = + parent->ops->device_driver->get_available(type); + ret = kobject_init_and_add(&type->kobj, &mdev_type_ktype, NULL, "%s-%s", dev_driver_string(parent->dev), group->name); diff --git a/include/linux/mdev.h b/include/linux/mdev.h index 7f1db354f45f14..819eaf98ffac73 100644 --- a/include/linux/mdev.h +++ b/include/linux/mdev.h @@ -140,12 +140,14 @@ struct mdev_type_attribute { * @probe: called when new device created * @remove: called when device removed * @driver: device driver structure + * @get_available: Return the max number of instances that can be created * **/ struct mdev_driver { int (*probe)(struct mdev_device *dev); void (*remove)(struct mdev_device *dev); struct device_driver driver; + unsigned int (*get_available)(struct mdev_type *mtype); }; static inline void *mdev_get_drvdata(struct mdev_device *mdev) diff --git a/samples/vfio-mdev/mdpy.c b/samples/vfio-mdev/mdpy.c index b81d7848619cae..2ea8694a0ddb19 100644 --- a/samples/vfio-mdev/mdpy.c +++ b/samples/vfio-mdev/mdpy.c @@ -84,7 +84,6 @@ static dev_t mdpy_devt; static struct class *mdpy_class; static struct cdev mdpy_cdev; static struct device mdpy_dev; -static u32 mdpy_count; static const struct vfio_device_ops mdpy_dev_ops; /* State of each mdev device */ @@ -225,9 +224,6 @@ static int mdpy_probe(struct mdev_device *mdev) u32 fbsize; int ret; - if (mdpy_count >= max_devices) - return -ENOMEM; - mdev_state = kzalloc(sizeof(struct mdev_state), GFP_KERNEL); if (mdev_state == NULL) return -ENOMEM; @@ -256,8 +252,6 @@ static int mdpy_probe(struct mdev_device *mdev) mdpy_create_config_space(mdev_state); mdpy_reset(mdev_state); - mdpy_count++; - ret = vfio_register_group_dev(&mdev_state->vdev); if (ret) goto err_mem; @@ -284,8 +278,6 @@ static void mdpy_remove(struct mdev_device *mdev) kfree(mdev_state->vconfig); vfio_uninit_group_dev(&mdev_state->vdev); kfree(mdev_state); - - mdpy_count--; } static ssize_t mdpy_read(struct vfio_device *vdev, char __user *buf, @@ -662,18 +654,10 @@ static ssize_t description_show(struct mdev_type *mtype, } static MDEV_TYPE_ATTR_RO(description); -static ssize_t available_instances_show(struct mdev_type *mtype, - struct mdev_type_attribute *attr, - char *buf) -{ - return sprintf(buf, "%d\n", max_devices - mdpy_count); -} -static MDEV_TYPE_ATTR_RO(available_instances); static struct attribute *mdev_types_attrs[] = { &mdev_type_attr_name.attr, &mdev_type_attr_description.attr, - &mdev_type_attr_available_instances.attr, NULL, }; @@ -706,6 +690,11 @@ static const struct vfio_device_ops mdpy_dev_ops = { .mmap = mdpy_mmap, }; +static unsigned int mdpy_get_available(struct mdev_type *mtype) +{ + return max_devices; +} + static struct mdev_driver mdpy_driver = { .driver = { .name = "mdpy", @@ -715,6 +704,7 @@ static struct mdev_driver mdpy_driver = { }, .probe = mdpy_probe, .remove = mdpy_remove, + .get_available = mdpy_get_available, }; static const struct mdev_parent_ops mdev_fops = { From patchwork Thu Sep 9 19:38:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12483753 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 01593C433F5 for ; Thu, 9 Sep 2021 19:39:08 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C01626103E for ; Thu, 9 Sep 2021 19:39:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org C01626103E Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 80A826E90C; Thu, 9 Sep 2021 19:38:55 +0000 (UTC) Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2069.outbound.protection.outlook.com [40.107.94.69]) by gabe.freedesktop.org (Postfix) with ESMTPS id 54D2C6E902; Thu, 9 Sep 2021 19:38:54 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FHPzDatLU9jmDmLGFuxJmRw/bnem1JKw0ZdNDxm4snQaYZepD18iR7KDn46TedErTT2d14s5A2AUYrgnQekl/zzduXIwNybsj+yOqSew56qIRK/X8fsfMe9OYvNnFHeE2W9i7buEZVdbD8gkDO06hfpSKt6TxWrwRkRleg95Zmws9leOqQXy9RJFgqNs9zDhDdG4MZdVXTVT/5VdvpC7KIB763vmdrKInZuxkxWY9JvF5PvKINd7MLl1KIPUkc7lxPY3tFt32WP+zmUmo3N1nulKXOV2v+xW5ILCrdzkZmEoVO1sqxQc5gv8mayFOUD5ijN3sBoPSDJUydVOBBZH6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=7sCNQ4vciCjpR4sYbGntkkTBay+aB9qscb688lFIPK4=; b=EGWACzl4X90Sc4TzoQNO3LodgzRBLlxP6FRE070wIgxV2YT9mSLPJY77BsbW83O3v2iAtSFozbXUv6V9UFL6Wzw1yYIiJDdyR2foYAIzf07EvceWvuURvz2sK/6zMevkzUTMu+nkbEpaztGShLFzxL8vZp2udKhpgZHdSK07FXtrGV1xCqWVO/49E2H031WqYNJET0XUfoIeIVzXbHDdiEEWEq0XVRL7zQH9wVtlll/8sWK5UlaK8aglgBU4cUQOCtk0JJ01xybMS1keUwwjyUCDp0ziMKKU+MTDrglYsh/W4FGppMdwBqGLFhIRwUiENICvKmkINBMnZM/jXVDttg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7sCNQ4vciCjpR4sYbGntkkTBay+aB9qscb688lFIPK4=; b=DW94s/pxKAakTLFbYhHWXkHUhfVj15nxz9fPB8pXb7+gyzRmeNnuOQMbJ/1P3EyqKAnaDKzqf6Nv0xUYm3JZaTL6y9gtMLSLqBYKAQBtK2+YIuybz6nbn9sNLCowYnZpuxo5nEGk8BaIMzHVULdPTZHHk7aiOl/cBvcLBid2MGQG5Ep4TGZiEZEJ3tSRzd2OP5caRBMqRDcvGIpO+gG5PgX5rUSTVV3M48l5KLC0EOlIwdx3P1wHrIOZdhKvdnFX25e3EEL3EyDAj8gysD/xqwMjgWZL5lGycCHXj19fuIcD+Tt5A2gCvx4MxiMXnzhE6x7Z/pm6dEDjrZuSj67WZw== Authentication-Results: linux.ie; dkim=none (message not signed) header.d=none;linux.ie; dmarc=none action=none header.from=nvidia.com; Received: from BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) by BL0PR12MB5554.namprd12.prod.outlook.com (2603:10b6:208:1cd::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14; Thu, 9 Sep 2021 19:38:52 +0000 Received: from BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::e8af:232:915e:2f95]) by BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::e8af:232:915e:2f95%8]) with mapi id 15.20.4500.014; Thu, 9 Sep 2021 19:38:52 +0000 From: Jason Gunthorpe To: David Airlie , Tony Krowiak , Alex Williamson , Christian Borntraeger , Cornelia Huck , Daniel Vetter , dri-devel@lists.freedesktop.org, Eric Farman , Harald Freudenberger , Vasily Gorbik , Heiko Carstens , intel-gfx@lists.freedesktop.org, intel-gvt-dev@lists.freedesktop.org, Jani Nikula , Jason Herne , Joonas Lahtinen , kvm@vger.kernel.org, Kirti Wankhede , linux-s390@vger.kernel.org, Matthew Rosato , Peter Oberparleiter , Halil Pasic , Rodrigo Vivi , Vineeth Vijayan , Zhenyu Wang , Zhi Wang Cc: Christoph Hellwig Date: Thu, 9 Sep 2021 16:38:47 -0300 Message-Id: <7-v2-7d3a384024cf+2060-ccw_mdev_jgg@nvidia.com> In-Reply-To: <0-v2-7d3a384024cf+2060-ccw_mdev_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR18CA0010.namprd18.prod.outlook.com (2603:10b6:208:23c::15) To BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) MIME-Version: 1.0 Received: from mlx.ziepe.ca (142.162.113.129) by MN2PR18CA0010.namprd18.prod.outlook.com (2603:10b6:208:23c::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Thu, 9 Sep 2021 19:38:50 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1mOPsn-00FLFA-NO; Thu, 09 Sep 2021 16:38:49 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e6194d36-aa59-4c3f-f7cf-08d973c9733e X-MS-TrafficTypeDiagnostic: BL0PR12MB5554: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1360; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zQh4fDLT1SVHI3bAnw2PlnXmRlUOMUX3VLM+CmRkHFkr3qcUrMBEEkazvTyKSHIJaKI0XGkVKUyAuFvm6q7PVGJDVARPRBUp82kDJFVMCl2kHY/cC6Zlt/mDMo/hG+WWghFh4/+OlQRYkzMVNxvAbxDH1zfEq1H+ysrcwBF4Cz9jS3iHKT+e8HmB0upHG2IG73AHi/4eQpeALKxuGyDpA/4dstXkYUR+h9v8qlVqGEOmyql+pFSWUOjVJJjYJZ79Xt8GCQUDTmbUB6le55iZDug7lVJvL/tFqTxzNZ412JdmIwPKUZS7g5cFAWMB8QdSBHmuGh97aPGn8FGCgt0YPe7X93o+F/ISk4+XWvz2cgoWlBdk1YHGEssAAmu8gfh9y/FTvOs8SKyCVBxrVZfBpTgOzqM0y/TjM8jEHA7MlsM5KTdCBxVvHaOLXrq+8okRBBi0LG5tOQLbfE47zf90+Y5xkI5E0Pe4SE0MlS8C50sZkTmA0AjxPNiqD+3ZLf7nMgEMcRaV3jk9zAxjcB6MYEbylCImy1Jz3AAGrWBPcRMm7jAarMjXFT9YsDfKvKmlwszabqRk1YxUof2+0yN3hXP0cF32zRUCygbprX1beabYbaa1zc3bBIScuO0qmqjkiIRde87GHpn7zmfjx1lCkH5wVHMEODmK/ZTcPXufVt92w+oT45zF0mrxKIyzMFRVp/1xU59r3lMGWu+QOfQ8zg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BL0PR12MB5506.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(7416002)(26005)(4326008)(2616005)(66556008)(921005)(66476007)(426003)(66946007)(9746002)(9786002)(5660300002)(186003)(83380400001)(86362001)(508600001)(8936002)(110136005)(38100700002)(36756003)(316002)(8676002)(2906002)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: k6NHNZSfPFd1UiN4j2At2f/rx1u5CjvQc9RP2wASqhyCakhf9effN0a8Z0q1aNQgU7k8nzdWTVq85iQ8jVRSp2lbvzQ/YGHLcixoq7Tus1M8ZAxdPIIF3nZRWxE015+NZ3bjkapqWgSBMiixbqi2hVNMTXcRa5Y+iHlgr7hPUtrrATId2qSe+CaYtESbzg4JQ5VKu9BPel6H3GDLNCy75sVKiOZCL6qO1JGWi8wF5LnDjuEcatGHBFDgEUtvk9w78XdQI0h6Z5Ek0WC+0+QxO6w5X7AI1Qjri8yrRTMSFO6u3YaJ3EYzTGq609GUGXe6tGRDLUBOZfQ1DVVKKqM/wmnz+0BKlzfG4PfQeu1MO2AsKIAO+1ulaIZTUHlv2k0dArmD+/MB98uhdqU74jsV007yApNf0OBjw832HQ0GjJcaBCGxKBLqPuySDhxnf31QGoK1QcRY4makxOpPRL8fsCdV3+DbXhzJrbIPG0sxLTj1kEcupRJUkONjlzJLER0xEYne2PoM1R3zv91WTf61C4TMQBEvBbOIHEd4M7JM5/WQqy+LTdu4tsX9Vw4X/VRCfgC9qUi1i2WOYFZMLLSAOfEU8XdYKadiL/vEyxFPR0gzoQljTZXL/qQYPnCtgPs4qoGtG5A5HzUydyx7qa/WPaS/KklF1aC5FH8xxwW/ZSDIXtMcc46imdw6Mv9m8k/3KNhOVPsBP1Kl2qf25zQUGOe9o4ddY5HfzYRFmcvEeGOhxycMSKw8lzydgubZCNRc X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: e6194d36-aa59-4c3f-f7cf-08d973c9733e X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Sep 2021 19:38:51.3601 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: XzAKlCaHi5ScoQfJ51Qv+5WpkmcKp/1haWzvwaevtu5U4+Rb0iPEdspGzfRHgtu5 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB5554 Subject: [Intel-gfx] [PATCH v2 7/9] vfio/ccw: Remove private->mdev X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Having a mdev pointer floating about in addition to a struct vfio_device is confusing. It is only used for three things: - Getting the mdev 'struct device *' - this is the same as private->vdev.dev - Printing the uuid of the mdev in logging. The uuid is also the dev_name of the mdev so this is the same string as dev_name(private->vdev.dev) - A weird attempt to fence the vfio_ccw_sch_io_todo() work. This work is only queued during states IDLE/PROCESSING/PENDING and flushed when entering CLOSED. Thus the work already cannot run when the mdev is NULL. Remove it. Signed-off-by: Jason Gunthorpe --- drivers/s390/cio/vfio_ccw_drv.c | 6 ++-- drivers/s390/cio/vfio_ccw_fsm.c | 48 +++++++++++++---------------- drivers/s390/cio/vfio_ccw_ops.c | 16 ++++------ drivers/s390/cio/vfio_ccw_private.h | 2 -- include/linux/mdev.h | 4 --- 5 files changed, 30 insertions(+), 46 deletions(-) diff --git a/drivers/s390/cio/vfio_ccw_drv.c b/drivers/s390/cio/vfio_ccw_drv.c index de782e967a5474..0e2edd96567a09 100644 --- a/drivers/s390/cio/vfio_ccw_drv.c +++ b/drivers/s390/cio/vfio_ccw_drv.c @@ -64,7 +64,7 @@ static void vfio_ccw_sch_io_todo(struct work_struct *work) * has finished. Do not overwrite a possible processing * state if the final interrupt was for HSCH or CSCH. */ - if (private->mdev && cp_is_finished) + if (cp_is_finished) private->state = VFIO_CCW_STATE_IDLE; if (private->io_trigger) @@ -303,8 +303,8 @@ static int vfio_ccw_chp_event(struct subchannel *sch, return 0; trace_vfio_ccw_chp_event(private->sch->schid, mask, event); - VFIO_CCW_MSG_EVENT(2, "%pUl (%x.%x.%04x): mask=0x%x event=%d\n", - mdev_uuid(private->mdev), sch->schid.cssid, + VFIO_CCW_MSG_EVENT(2, "%s (%x.%x.%04x): mask=0x%x event=%d\n", + dev_name(private->vdev.dev), sch->schid.cssid, sch->schid.ssid, sch->schid.sch_no, mask, event); diff --git a/drivers/s390/cio/vfio_ccw_fsm.c b/drivers/s390/cio/vfio_ccw_fsm.c index 302215090b9ac7..df1490943b20ec 100644 --- a/drivers/s390/cio/vfio_ccw_fsm.c +++ b/drivers/s390/cio/vfio_ccw_fsm.c @@ -245,7 +245,6 @@ static void fsm_io_request(struct vfio_ccw_private *private, union orb *orb; union scsw *scsw = &private->scsw; struct ccw_io_region *io_region = private->io_region; - struct mdev_device *mdev = private->mdev; char *errstr = "request"; struct subchannel_id schid = get_schid(private); @@ -258,32 +257,30 @@ static void fsm_io_request(struct vfio_ccw_private *private, /* Don't try to build a cp if transport mode is specified. */ if (orb->tm.b) { io_region->ret_code = -EOPNOTSUPP; - VFIO_CCW_MSG_EVENT(2, - "%pUl (%x.%x.%04x): transport mode\n", - mdev_uuid(mdev), schid.cssid, - schid.ssid, schid.sch_no); + VFIO_CCW_MSG_EVENT( + 2, "%s (%x.%x.%04x): transport mode\n", + dev_name(private->vdev.dev), schid.cssid, + schid.ssid, schid.sch_no); errstr = "transport mode"; goto err_out; } - io_region->ret_code = cp_init(&private->cp, mdev_dev(mdev), + io_region->ret_code = cp_init(&private->cp, private->vdev.dev, orb); if (io_region->ret_code) { - VFIO_CCW_MSG_EVENT(2, - "%pUl (%x.%x.%04x): cp_init=%d\n", - mdev_uuid(mdev), schid.cssid, - schid.ssid, schid.sch_no, - io_region->ret_code); + VFIO_CCW_MSG_EVENT(2, "%s (%x.%x.%04x): cp_init=%d\n", + dev_name(private->vdev.dev), + schid.cssid, schid.ssid, + schid.sch_no, io_region->ret_code); errstr = "cp init"; goto err_out; } io_region->ret_code = cp_prefetch(&private->cp); if (io_region->ret_code) { - VFIO_CCW_MSG_EVENT(2, - "%pUl (%x.%x.%04x): cp_prefetch=%d\n", - mdev_uuid(mdev), schid.cssid, - schid.ssid, schid.sch_no, - io_region->ret_code); + VFIO_CCW_MSG_EVENT( + 2, "%s (%x.%x.%04x): cp_prefetch=%d\n", + dev_name(private->vdev.dev), schid.cssid, + schid.ssid, schid.sch_no, io_region->ret_code); errstr = "cp prefetch"; cp_free(&private->cp); goto err_out; @@ -292,28 +289,25 @@ static void fsm_io_request(struct vfio_ccw_private *private, /* Start channel program and wait for I/O interrupt. */ io_region->ret_code = fsm_io_helper(private); if (io_region->ret_code) { - VFIO_CCW_MSG_EVENT(2, - "%pUl (%x.%x.%04x): fsm_io_helper=%d\n", - mdev_uuid(mdev), schid.cssid, - schid.ssid, schid.sch_no, - io_region->ret_code); + VFIO_CCW_MSG_EVENT( + 2, "%s (%x.%x.%04x): fsm_io_helper=%d\n", + dev_name(private->vdev.dev), schid.cssid, + schid.ssid, schid.sch_no, io_region->ret_code); errstr = "cp fsm_io_helper"; cp_free(&private->cp); goto err_out; } return; } else if (scsw->cmd.fctl & SCSW_FCTL_HALT_FUNC) { - VFIO_CCW_MSG_EVENT(2, - "%pUl (%x.%x.%04x): halt on io_region\n", - mdev_uuid(mdev), schid.cssid, + VFIO_CCW_MSG_EVENT(2, "%s (%x.%x.%04x): halt on io_region\n", + dev_name(private->vdev.dev), schid.cssid, schid.ssid, schid.sch_no); /* halt is handled via the async cmd region */ io_region->ret_code = -EOPNOTSUPP; goto err_out; } else if (scsw->cmd.fctl & SCSW_FCTL_CLEAR_FUNC) { - VFIO_CCW_MSG_EVENT(2, - "%pUl (%x.%x.%04x): clear on io_region\n", - mdev_uuid(mdev), schid.cssid, + VFIO_CCW_MSG_EVENT(2, "%s (%x.%x.%04x): clear on io_region\n", + dev_name(private->vdev.dev), schid.cssid, schid.ssid, schid.sch_no); /* clear is handled via the async cmd region */ io_region->ret_code = -EOPNOTSUPP; diff --git a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_ops.c index 38ab5c1f25ec09..23004e67c492f6 100644 --- a/drivers/s390/cio/vfio_ccw_ops.c +++ b/drivers/s390/cio/vfio_ccw_ops.c @@ -95,11 +95,9 @@ static int vfio_ccw_mdev_probe(struct mdev_device *mdev) vfio_init_group_dev(&private->vdev, &mdev->dev, &vfio_ccw_dev_ops); - private->mdev = mdev; - - VFIO_CCW_MSG_EVENT(2, "mdev %pUl, sch %x.%x.%04x: create\n", - mdev_uuid(mdev), private->sch->schid.cssid, - private->sch->schid.ssid, + VFIO_CCW_MSG_EVENT(2, "mdev %s, sch %x.%x.%04x: create\n", + dev_name(private->vdev.dev), + private->sch->schid.cssid, private->sch->schid.ssid, private->sch->schid.sch_no); ret = vfio_register_group_dev(&private->vdev); @@ -110,7 +108,6 @@ static int vfio_ccw_mdev_probe(struct mdev_device *mdev) err_init: vfio_uninit_group_dev(&private->vdev); - private->mdev = NULL; return ret; } @@ -118,14 +115,13 @@ static void vfio_ccw_mdev_remove(struct mdev_device *mdev) { struct vfio_ccw_private *private = dev_get_drvdata(mdev->dev.parent); - VFIO_CCW_MSG_EVENT(2, "mdev %pUl, sch %x.%x.%04x: remove\n", - mdev_uuid(mdev), private->sch->schid.cssid, - private->sch->schid.ssid, + VFIO_CCW_MSG_EVENT(2, "mdev %s, sch %x.%x.%04x: remove\n", + dev_name(private->vdev.dev), + private->sch->schid.cssid, private->sch->schid.ssid, private->sch->schid.sch_no); vfio_unregister_group_dev(&private->vdev); vfio_uninit_group_dev(&private->vdev); - private->mdev = NULL; } static int vfio_ccw_mdev_open_device(struct vfio_device *vdev) diff --git a/drivers/s390/cio/vfio_ccw_private.h b/drivers/s390/cio/vfio_ccw_private.h index bbc97eb9d9c6fc..67ee9c624393b0 100644 --- a/drivers/s390/cio/vfio_ccw_private.h +++ b/drivers/s390/cio/vfio_ccw_private.h @@ -72,7 +72,6 @@ struct vfio_ccw_crw { * @sch: pointer to the subchannel * @state: internal state of the device * @completion: synchronization helper of the I/O completion - * @mdev: pointer to the mediated device * @nb: notifier for vfio events * @io_region: MMIO region to input/output I/O arguments/results * @io_mutex: protect against concurrent update of I/O regions @@ -95,7 +94,6 @@ struct vfio_ccw_private { struct subchannel *sch; int state; struct completion *completion; - struct mdev_device *mdev; struct notifier_block nb; struct ccw_io_region *io_region; struct mutex io_mutex; diff --git a/include/linux/mdev.h b/include/linux/mdev.h index 819eaf98ffac73..ea59610d45fd89 100644 --- a/include/linux/mdev.h +++ b/include/linux/mdev.h @@ -158,10 +158,6 @@ static inline void mdev_set_drvdata(struct mdev_device *mdev, void *data) { mdev->driver_data = data; } -static inline const guid_t *mdev_uuid(struct mdev_device *mdev) -{ - return &mdev->uuid; -} extern struct bus_type mdev_bus_type; From patchwork Thu Sep 9 19:38:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12483767 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 03266C4332F for ; Thu, 9 Sep 2021 19:39:33 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CC6FE60724 for ; Thu, 9 Sep 2021 19:39:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org CC6FE60724 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7FDB26E922; Thu, 9 Sep 2021 19:39:01 +0000 (UTC) Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2064.outbound.protection.outlook.com [40.107.94.64]) by gabe.freedesktop.org (Postfix) with ESMTPS id 93F656E90D; Thu, 9 Sep 2021 19:38:55 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ROLO7gnZJYrdd1VNFm1iFTVf9wsmb6k3fMiGRFCD24JRGpypN9YTXuG08jzF9ul4k/MzuckZW0IrF7pooOZWcmWnyp3EiUdZIfanrEfTiOkZSx+BXgqSUwKHKdXmgu+UpzbfOxkVgzMApPKnA/AHZl6O782wie+gRbeB4PcRxUulEzoe3+gPvjWLQ/C3ZBTwYo0Mq1TlhEKeLEcs75+n7+5sFrgUks5wN7YOnK2kLSnzssk+TGgVPTIADQJo80ZQ4pPJkbiOIwTxeNUsbnA3QJzadgLmL+b3AZRI3uIs515q0z1SKdARUzXBJ6BWcJuJ9gV2A86WSjRwRTXAygL53Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=Yul/KtpqYFKamySxO1NsBA5ij/VLaZ6SLSt8ofa1xgw=; b=nCvs6nMlu1XaXTNWGUEDfOAxcda3hm8qyIuhlhlDTjjCPhdTlgC61w4XLqUl4Zsi2zS2ejYRorVJpUwxKUenOxO6WaEz4WK7nIyfREa8tuPIyRk6YxyZL+oF0QZjpcFkVfJj7gBG75Xy0KwI7ZH2ATp4oM5JENosNoIKVjjjpc8z31enJAGLxiysUVr8jMePugukHosROsd1jBHaUn8VcJ6CCSeREBI+f18t1k1SkmewDrdoiWQateg766/6jmMeHFHCYPQIGyqJiU9Cy+YCoO+AhksKA1pZmfKE8S9xLNQySaYz44f92N4LEkmcUjwJDWHCBQBk3ZN5Yee8ZI370A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Yul/KtpqYFKamySxO1NsBA5ij/VLaZ6SLSt8ofa1xgw=; b=OwX1KrMudH27pKzW4KromJVVFYN59bCFnnN4j0zSQLVkbUQ+kp7ZdKxgg3geIpquMPLzjvvoRhB69Zm1JIu/2bPIQkJwgjyVsdHEH6AWRCB8ZR23rGNSdkslnG17q+Si9c4eNtaKapKpv09nBjUCFz1cank/hjfROkRygjM4HTKm9LBLJ9JA8QADC/prpqsuEj3L3XGebfkkrcg851gdnW9W9gcXhqUoaomRunfSO6ekfMVm7m6mujeGy9x3fqtO/qh3zrc2z92oIUFuQy6tv8Y8/aYgn78eiO8VaUxwOqagEH3CfiwmhxIzPO4JEpmsb3e4LUYD9VMjpraUbwiRIA== Authentication-Results: linux.ie; dkim=none (message not signed) header.d=none;linux.ie; dmarc=none action=none header.from=nvidia.com; Received: from BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) by BL0PR12MB5554.namprd12.prod.outlook.com (2603:10b6:208:1cd::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14; Thu, 9 Sep 2021 19:38:54 +0000 Received: from BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::e8af:232:915e:2f95]) by BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::e8af:232:915e:2f95%8]) with mapi id 15.20.4500.014; Thu, 9 Sep 2021 19:38:54 +0000 From: Jason Gunthorpe To: David Airlie , Tony Krowiak , Alex Williamson , Christian Borntraeger , Cornelia Huck , Daniel Vetter , dri-devel@lists.freedesktop.org, Eric Farman , Harald Freudenberger , Vasily Gorbik , Heiko Carstens , intel-gfx@lists.freedesktop.org, intel-gvt-dev@lists.freedesktop.org, Jani Nikula , Jason Herne , Joonas Lahtinen , kvm@vger.kernel.org, Kirti Wankhede , linux-s390@vger.kernel.org, Matthew Rosato , Peter Oberparleiter , Halil Pasic , Rodrigo Vivi , Vineeth Vijayan , Zhenyu Wang , Zhi Wang Cc: Christoph Hellwig Date: Thu, 9 Sep 2021 16:38:48 -0300 Message-Id: <8-v2-7d3a384024cf+2060-ccw_mdev_jgg@nvidia.com> In-Reply-To: <0-v2-7d3a384024cf+2060-ccw_mdev_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR18CA0016.namprd18.prod.outlook.com (2603:10b6:208:23c::21) To BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) MIME-Version: 1.0 Received: from mlx.ziepe.ca (142.162.113.129) by MN2PR18CA0016.namprd18.prod.outlook.com (2603:10b6:208:23c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Thu, 9 Sep 2021 19:38:52 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1mOPsn-00FLFF-PU; Thu, 09 Sep 2021 16:38:49 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8fd5a0ce-7a36-4306-5998-08d973c9744a X-MS-TrafficTypeDiagnostic: BL0PR12MB5554: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:590; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: lbdGpiejsfCQCgFsWhi4P9nAaTvnZkr5C2ruVNibtWUShMiyTABr0QwoVBUEWi0513zK4jpTitAliIK40Khl87BX++nasoZ2IuW2JVNVltnlcXVlq4IuD934SlDEC/N1Za9fEFqHqBox0nP61ZvlawJ7N4JOi7JDuYdF6TMceZmr2SQZ/QmM3hdpjSFRmeBDZp2NRjNLYsFBsqdQJifTGIekpP6u+LP+VXYIUQs31u8pMPrJhP/4ncIjyFfwOMs5MZPQpIu0XQ8EfdSP5AVpC1kdM7khrJl+mSSOq7whJ2gAH3r9KZINjbgrmt8HflWq8f/FQrIUq/6O5x/X9H3rce7AiEbdJdIPQ4H7a47bvJb8M12M8ZNP8lrCzVAtVuQfYiO/ozMZ+DcHIH0nBFaReMOLZazv7MA+hVas9zO4mCGsRnp5ZSouLzGYcgji3Os6Zvw7ZSE3ioQMJqJp3BdlPW0+CXAnWKIc+cBJe7Fn/EiiJviJ5CoCpdMj2cLWeAELk3MQ25TmQfnwjvx4oQADk7V+s/tjRHeVeoiGz00i/WSQGemJAmCJr9EhR2+il1UsV+LxqCz0QdOaanA/6BN7zLu46hlmzWBprMNm3CE9lBz1zi6N+ZYn9NwAXI+M2BMjo7qqWsAml/Hv/i4USnfi8KZcoiewB6kx/abGdRWa4+8T81oal3QyJlVPSwzRMdV/yaAI10cY53KYQXIKveHJ2A== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BL0PR12MB5506.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(7416002)(26005)(4326008)(2616005)(66556008)(921005)(66476007)(426003)(66946007)(9746002)(9786002)(5660300002)(186003)(83380400001)(86362001)(508600001)(8936002)(110136005)(38100700002)(36756003)(316002)(8676002)(2906002)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: VlHgMe1+Sfy5kVcgiXTH50k4Z3y6WmCVPxJytzD09eALWxty+SA8tsC7Mq9dfvgBI3RCZk/RtZO9Ew1MgbGoF4aSbtmWougFiSqt22mUaO7i9rtiNHFOr6wsF6eJayfGQvKTfq7marHnmDvueiUj5QJOMc4trhSzvYQ9/5TtEVpHF+ijIKz16Gl5ByrgHOTA66BTGyfS8R02JXoTM8XMN20J0Man0VRqyDoGq8918DENGOBmM8ZluiaAPTk3NhSYMVrdHzUzjL6qNdMD3znHxLYY259VOGjlLiQ9KgtnGOH3jbAy+UKlU1UwR4mvJD6q6TT6E/ylKV8KQ/rRvxayZy6RDt/wczT0Ka1w6kjJmtmCwG0C2HgsgcoqOzguDJbbLMqVegZu7sYEN4BZWLlAiPOhuhDX3wAbVSMhCThDXjfmjRjUugzlZgJJz/wDNtPSHBmr/8qz6ddsyz72ynA42btziUtv0wco7pVf9e8ybRZLC4fEJh5OMD09vpzRRKzE7Mdme+QZuDQyxfDbJdeonUKXbuuoivA6sKC6/hB/3/wXeRUyILl7/4YrnhgWFU4yxgn/NgfXrfRN5ix6b8sA1RG9zIkzlWtFkyAZsT2clAWoz99V/hAsJJqxKgG42B6hnWcpyifyfvluFFdi6BgRqdg8OWqmntICAy6H8jKBLGo+hJHapHtTRXZpThPgnwUU2hbUl1hcy6ZvJOnM8UsXycBYRFmuTWsNw74r92Djdaw9wXhOevoH0OR4lmZ1NuRQ X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8fd5a0ce-7a36-4306-5998-08d973c9744a X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Sep 2021 19:38:53.0746 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: i9fmpd6qqpHKoLq7x0Sy6G/hML2FesEdVapCV0I6iMTKluAcUWiFNx7t189hW2Sy X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB5554 Subject: [Intel-gfx] [PATCH v2 8/9] vfio: Export vfio_device_try_get() X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" vfio_ccw will need it. Signed-off-by: Jason Gunthorpe --- drivers/vfio/vfio.c | 3 ++- include/linux/vfio.h | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c index c3ca33e513c8e9..e78278a0b98a96 100644 --- a/drivers/vfio/vfio.c +++ b/drivers/vfio/vfio.c @@ -603,10 +603,11 @@ void vfio_device_put(struct vfio_device *device) } EXPORT_SYMBOL_GPL(vfio_device_put); -static bool vfio_device_try_get(struct vfio_device *device) +bool vfio_device_try_get(struct vfio_device *device) { return refcount_inc_not_zero(&device->refcount); } +EXPORT_SYMBOL_GPL(vfio_device_try_get); static struct vfio_device *vfio_group_get_device(struct vfio_group *group, struct device *dev) diff --git a/include/linux/vfio.h b/include/linux/vfio.h index e65137a708f185..69df8bcc49aaf4 100644 --- a/include/linux/vfio.h +++ b/include/linux/vfio.h @@ -80,6 +80,7 @@ void vfio_uninit_group_dev(struct vfio_device *device); int vfio_register_group_dev(struct vfio_device *device); void vfio_unregister_group_dev(struct vfio_device *device); extern struct vfio_device *vfio_device_get_from_dev(struct device *dev); +bool vfio_device_try_get(struct vfio_device *device); extern void vfio_device_put(struct vfio_device *device); int vfio_assign_device_set(struct vfio_device *device, void *set_id); From patchwork Thu Sep 9 19:38:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12483769 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AD462C433F5 for ; Thu, 9 Sep 2021 19:39:33 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7D1C560724 for ; Thu, 9 Sep 2021 19:39:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 7D1C560724 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 055F56E904; Thu, 9 Sep 2021 19:39:02 +0000 (UTC) Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2060.outbound.protection.outlook.com [40.107.92.60]) by gabe.freedesktop.org (Postfix) with ESMTPS id BA2616E90E; Thu, 9 Sep 2021 19:38:55 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MMaOpTsM9iqlM1LD+2xQLcV89zAMjYbCe2aoRTDISIJMoV7so5Oi5ievZY02c4k6o8LuCPmcmA1bnOkJ6oxaeVxKmySvwct19OBdP5lCHeiEqnKx0DuT/uj/llmIF7Gw1nbsnODjRh3nAjIZ+M8VklzbroVDddi2dSUaUa+OXYbUF7wHBH5Mv1PX9q4qQQf4xDHmli9+BcUIINIZ4nHYKKtDai2jwIm0pFBxpG7ui2b3ry1kfrIhqbs27//4AKZXqz1fr9NdaqeTILxGWjz0o9rBdivN9QHeoegS0NtXe4IO0M+X8P2KNk7PjyQ3kXCmr/O6CG1fzr3ut+RX+dGpkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=edW555ZKC7E+6Hfo+HiK/LCIsHGD1iwGAluReyiMkeA=; b=CoicXXOZvhDRmW58pfsrN9kwh90942tOBtrl6X5Zvb2Trc2YE7ATWZ1+SZz0JQ/dziOiEQKXzW7YU2MrPPgFhWrTAeIz/0EPbH8bLjuHSw0i0jfecpei8BX6cC+4Jr/sRL3uBVXruhDJuRRqsVAcnZ2irnyDdgVv8rUabrZ6ywxZCf7uCqxJ8fktb9+i2/L1f0Qu2uNuFzvXedLYgciAI+AJhYM8Njqyip+lCn6rKCoNWgIupA4MQHLnOgoHYp/icf9SAEZX0vU5RlH8zZfW62G3d57DkI8mJBdvkIY/a5mvxAQIGf5hCPKmdr1z3yxHSTufV+RtZDesic0DtBJG/w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=edW555ZKC7E+6Hfo+HiK/LCIsHGD1iwGAluReyiMkeA=; b=Vvi2NPPGqztbwlBhC5hfbLHvvhi3g1vTRuOs/0rX/lrK28f3AQn9gE2lBkZDjXm36socXfTqGNe1P0m2iPdgn+gpaJeP6fbf/UQVq/oK3MFaaImDul58s6Ai/VcskheyX/NC+3IQ+YQ6aO9fJ0g0bYIMWyDoCr4nudlmdxpv/y4x/d8mBw2nJR4iVfdaj/xQ1qLiKCBTrrHOEb2oZV/d3nJ8iUosEe2PsCvuJlG1H8TW0TguBM7hW1aQ4kDILHsW7HPsKDSYXAfeEqe35G4EeKQGPdqV1fSXZ2DAILjybOydUWfa9KBxLLxNqIe+Xc1lvMBIriulG/KSpG/EYs77xw== Authentication-Results: linux.ie; dkim=none (message not signed) header.d=none;linux.ie; dmarc=none action=none header.from=nvidia.com; Received: from BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) by BL0PR12MB5507.namprd12.prod.outlook.com (2603:10b6:208:1c4::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14; Thu, 9 Sep 2021 19:38:53 +0000 Received: from BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::e8af:232:915e:2f95]) by BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::e8af:232:915e:2f95%8]) with mapi id 15.20.4500.014; Thu, 9 Sep 2021 19:38:53 +0000 From: Jason Gunthorpe To: David Airlie , Tony Krowiak , Alex Williamson , Christian Borntraeger , Cornelia Huck , Daniel Vetter , dri-devel@lists.freedesktop.org, Eric Farman , Harald Freudenberger , Vasily Gorbik , Heiko Carstens , intel-gfx@lists.freedesktop.org, intel-gvt-dev@lists.freedesktop.org, Jani Nikula , Jason Herne , Joonas Lahtinen , kvm@vger.kernel.org, Kirti Wankhede , linux-s390@vger.kernel.org, Matthew Rosato , Peter Oberparleiter , Halil Pasic , Rodrigo Vivi , Vineeth Vijayan , Zhenyu Wang , Zhi Wang Cc: Christoph Hellwig Date: Thu, 9 Sep 2021 16:38:49 -0300 Message-Id: <9-v2-7d3a384024cf+2060-ccw_mdev_jgg@nvidia.com> In-Reply-To: <0-v2-7d3a384024cf+2060-ccw_mdev_jgg@nvidia.com> References: X-ClientProxiedBy: BL0PR02CA0021.namprd02.prod.outlook.com (2603:10b6:207:3c::34) To BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) MIME-Version: 1.0 Received: from mlx.ziepe.ca (142.162.113.129) by BL0PR02CA0021.namprd02.prod.outlook.com (2603:10b6:207:3c::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Thu, 9 Sep 2021 19:38:51 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1mOPsn-00FLFI-Qw; Thu, 09 Sep 2021 16:38:49 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 72280b45-d93e-406e-4cb6-08d973c973a4 X-MS-TrafficTypeDiagnostic: BL0PR12MB5507: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:81; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SbjBNQcHsAW924s8dPPTmWhdpT0qGID3FfTqBH+wunr38RCSKdbk5MDkLrkiy1waARB1v1c8V/CX1/nRtMWWb5tjG0kuos1CCbzxuN7P19Pe+063XRsOBFuXMqs6CRWKiNUtUOAP8GC/UfPBQIia7H9CDRzmGnGdl0YYRzjIg0A80ovxdYSEsSS+iogN64TkeDHWZ+Ld/2QZ6Ixsc5oqBJ4nwcMkukcH7KjRR8vQUGuFi60Wk+Wc3ETkZayNUkU0+Kzz2wUv/1e9wsjVMMt6ews2t8vtT9fvubwHJjWBYTRvGTNYx4XwTZj06sJlXKDMes99Lm+6mNzErZ91WHAUdLvAGsR3Wra0PcgFYLB5lReeUqDx46bt4Xiz6w3RmRgqgwAHPslbQcwE56uoPsxrwo2NmVX0t9tkVt5EUxHwZPLbkoVh/1KkH/4f/QTzkIP3IqtvxBZblcDFzPpuoZWHqLIgzi+WwL6s4iDw+ZnafaSUrLZftz+l6rBKsBYNxd/YSHLi2urQHMXZG/w3bB6TwY8/ySBczd4RW0FENnaOXg6ACpwYG83c+zamyQsv7PkbE8C2h7slEmdZIr5i4SIDUUEWqoKxAayeMir9uPV74IHJvArZJfwo9OiSCaeKE16LgOhA1bQPrvgsjAMaDgrsnq0ucasurYoJRMKbGSRx97RwB4vrbWEwVvxYYXxnaE+WBy8yIfRYwsuwAyOua8+Fog== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BL0PR12MB5506.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(136003)(39860400002)(376002)(346002)(366004)(396003)(8676002)(66476007)(478600001)(4326008)(66946007)(66556008)(30864003)(8936002)(921005)(5660300002)(186003)(26005)(86362001)(83380400001)(7416002)(2906002)(36756003)(426003)(2616005)(9746002)(9786002)(110136005)(38100700002)(316002)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 3uSUx2dyD3VsgVQ59OzzsJ8eLCMqYitBd2anAH9zMKgEIxwJYilzYM8p4YNxnujSx6VYv1X6YfO1ds9+my8GTnYGMw5P5bjWwZZgyqg1Cz5vNZP1IadIChE78X75aAreZ7TBvNdapX8dMAPFiKTrIWyXx92yfnhPRQvr2B/y51XiqTTv51yQ/x5pE87jDeII6raIJPGHDISwEIsoby6ZVd+SmIpVsFdJC/Jlj1Lr/V/ZH0NTSXHp5Vx1vAdK4DEark/oUXoC8GKEo/vXZfU0ML2PCVk2joxToPsHd7PEq0ETH4AG2Ke3HeEFptAIIwQqwweoihmpdq3z/INokO3l+H72OS/PX4mbU9etNVqHYbmVNXyg2IzQjB5779E4Q7g4I5P1xFoq+wWrmlsYOkqXHmDOfoeo8sQKLSX7zZhZ+KCjNbT4ZYlP1bbb8Cy5Zx3V/i7sKphUJJADWvy/xThEZ1s8zaKIqvfw+oERQZuhluYU9TdisgNbbkcj1uTyuVLkUJipvbCZ8koXgxBlm1MKRvAmP07ryReMTky2eqgrRzQt7ARInBUMA6jJ6P6Gi/VES3/etWFn5upcH7jOuXWEgcJVdmgIgJvrojRmySUQRfOFUPAuH9alIZd8IQBs0CKlagNXILCyG/5lQUr4VzmOJbHac1/ayVpmB+nqQLQU3XQCogGLfnlsh1DoASchyFXiZdUyyMf38dSi2tvUC8JKWtE/IzatSJDQk9D9PjAj3pGI4scOc+GPO8kuAwCZBvye X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 72280b45-d93e-406e-4cb6-08d973c973a4 X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Sep 2021 19:38:51.9097 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Nk7rX8JsGB7oF72Kvl3oAOSwrEhwGU+jLBtx4PENO1/wukYubXq9oFrq988jQRDM X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB5507 Subject: [Intel-gfx] [PATCH v2 9/9] vfio/ccw: Move the lifecycle of the struct vfio_ccw_private to the mdev X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" The css_driver's main purpose is to create/destroy the mdev and relay the shutdown, irq, sch_event, and chp_event css_driver ops to the single created vfio_device, if it exists. Reframe the boundary where the css_driver domain switches to the vfio domain by using rcu to read and refcount the vfio_device out of the sch's drvdata. The mdev probe/remove will manage the drvdata of the parent. The vfio core code refcounting thus guarantees that when a css_driver callback is running the vfio_device is registered, simplifying the understanding of the whole lifecycle. Finally the vfio_ccw_private is allocated/freed during probe/remove of the mdev like any other vfio_device struct. Signed-off-by: Jason Gunthorpe --- drivers/s390/cio/vfio_ccw_drv.c | 67 ++++++++++++++--------------- drivers/s390/cio/vfio_ccw_ops.c | 40 +++++++---------- drivers/s390/cio/vfio_ccw_private.h | 23 +++++++++- 3 files changed, 69 insertions(+), 61 deletions(-) diff --git a/drivers/s390/cio/vfio_ccw_drv.c b/drivers/s390/cio/vfio_ccw_drv.c index 0e2edd96567a09..b86da53443bfd7 100644 --- a/drivers/s390/cio/vfio_ccw_drv.c +++ b/drivers/s390/cio/vfio_ccw_drv.c @@ -86,13 +86,19 @@ static void vfio_ccw_crw_todo(struct work_struct *work) */ static void vfio_ccw_sch_irq(struct subchannel *sch) { - struct vfio_ccw_private *private = dev_get_drvdata(&sch->dev); + struct vfio_ccw_private *private = vfio_ccw_get_priv(sch); + + /* IRQ should not be delivered after the mdev is destroyed */ + if (WARN_ON(!private)) + return; inc_irq_stat(IRQIO_CIO); vfio_ccw_fsm_event(private, VFIO_CCW_EVENT_INTERRUPT); + vfio_device_put(&private->vdev); } -static struct vfio_ccw_private *vfio_ccw_alloc_private(struct subchannel *sch) +struct vfio_ccw_private *vfio_ccw_alloc_private(struct mdev_device *mdev, + struct subchannel *sch) { struct vfio_ccw_private *private; @@ -100,6 +106,8 @@ static struct vfio_ccw_private *vfio_ccw_alloc_private(struct subchannel *sch) if (!private) return ERR_PTR(-ENOMEM); + vfio_init_group_dev(&private->vdev, &mdev->dev, + &vfio_ccw_dev_ops); private->sch = sch; mutex_init(&private->io_mutex); private->state = VFIO_CCW_STATE_CLOSED; @@ -145,11 +153,12 @@ static struct vfio_ccw_private *vfio_ccw_alloc_private(struct subchannel *sch) kfree(private->cp.guest_cp); out_free_private: mutex_destroy(&private->io_mutex); + vfio_uninit_group_dev(&private->vdev); kfree(private); return ERR_PTR(-ENOMEM); } -static void vfio_ccw_free_private(struct vfio_ccw_private *private) +void vfio_ccw_free_private(struct vfio_ccw_private *private) { struct vfio_ccw_crw *crw, *temp; @@ -164,14 +173,14 @@ static void vfio_ccw_free_private(struct vfio_ccw_private *private) kmem_cache_free(vfio_ccw_io_region, private->io_region); kfree(private->cp.guest_cp); mutex_destroy(&private->io_mutex); - kfree(private); + vfio_uninit_group_dev(&private->vdev); + kfree_rcu(private, rcu); } static int vfio_ccw_sch_probe(struct subchannel *sch) { struct pmcw *pmcw = &sch->schib.pmcw; - struct vfio_ccw_private *private; - int ret = -ENOMEM; + int ret; if (pmcw->qf) { dev_warn(&sch->dev, "vfio: ccw: does not support QDIO: %s\n", @@ -179,15 +188,9 @@ static int vfio_ccw_sch_probe(struct subchannel *sch) return -ENODEV; } - private = vfio_ccw_alloc_private(sch); - if (IS_ERR(private)) - return PTR_ERR(private); - - dev_set_drvdata(&sch->dev, private); - - ret = vfio_ccw_mdev_reg(sch); + ret = mdev_register_device(&sch->dev, &vfio_ccw_mdev_ops); if (ret) - goto out_free; + return ret; if (dev_get_uevent_suppress(&sch->dev)) { dev_set_uevent_suppress(&sch->dev, 0); @@ -198,22 +201,11 @@ static int vfio_ccw_sch_probe(struct subchannel *sch) sch->schid.cssid, sch->schid.ssid, sch->schid.sch_no); return 0; - -out_free: - dev_set_drvdata(&sch->dev, NULL); - vfio_ccw_free_private(private); - return ret; } static int vfio_ccw_sch_remove(struct subchannel *sch) { - struct vfio_ccw_private *private = dev_get_drvdata(&sch->dev); - - vfio_ccw_mdev_unreg(sch); - - dev_set_drvdata(&sch->dev, NULL); - - vfio_ccw_free_private(private); + mdev_unregister_device(&sch->dev); VFIO_CCW_MSG_EVENT(4, "unbound from subchannel %x.%x.%04x\n", sch->schid.cssid, sch->schid.ssid, @@ -223,10 +215,14 @@ static int vfio_ccw_sch_remove(struct subchannel *sch) static void vfio_ccw_sch_shutdown(struct subchannel *sch) { - struct vfio_ccw_private *private = dev_get_drvdata(&sch->dev); + struct vfio_ccw_private *private = vfio_ccw_get_priv(sch); + + if (!private) + return; vfio_ccw_fsm_event(private, VFIO_CCW_EVENT_CLOSE); vfio_ccw_fsm_event(private, VFIO_CCW_EVENT_BROKEN); + vfio_device_put(&private->vdev); } /** @@ -241,14 +237,14 @@ static void vfio_ccw_sch_shutdown(struct subchannel *sch) */ static int vfio_ccw_sch_event(struct subchannel *sch, int process) { - struct vfio_ccw_private *private = dev_get_drvdata(&sch->dev); + struct vfio_ccw_private *private = vfio_ccw_get_priv(sch); unsigned long flags; int rc = -EAGAIN; - spin_lock_irqsave(sch->lock, flags); - if (!device_is_registered(&sch->dev)) - goto out_unlock; + if (!private) + return -EAGAIN; + spin_lock_irqsave(sch->lock, flags); if (work_pending(&sch->todo_work)) goto out_unlock; @@ -261,7 +257,7 @@ static int vfio_ccw_sch_event(struct subchannel *sch, int process) out_unlock: spin_unlock_irqrestore(sch->lock, flags); - + vfio_device_put(&private->vdev); return rc; } @@ -295,7 +291,7 @@ static void vfio_ccw_queue_crw(struct vfio_ccw_private *private, static int vfio_ccw_chp_event(struct subchannel *sch, struct chp_link *link, int event) { - struct vfio_ccw_private *private = dev_get_drvdata(&sch->dev); + struct vfio_ccw_private *private = vfio_ccw_get_priv(sch); int mask = chp_ssd_get_mask(&sch->ssd_info, link); int retry = 255; @@ -308,8 +304,10 @@ static int vfio_ccw_chp_event(struct subchannel *sch, sch->schid.ssid, sch->schid.sch_no, mask, event); - if (cio_update_schib(sch)) + if (cio_update_schib(sch)) { + vfio_device_put(&private->vdev); return -ENODEV; + } switch (event) { case CHP_VARY_OFF: @@ -339,6 +337,7 @@ static int vfio_ccw_chp_event(struct subchannel *sch, break; } + vfio_device_put(&private->vdev); return 0; } diff --git a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_ops.c index 23004e67c492f6..04a10f37d64225 100644 --- a/drivers/s390/cio/vfio_ccw_ops.c +++ b/drivers/s390/cio/vfio_ccw_ops.c @@ -17,8 +17,6 @@ #include "vfio_ccw_private.h" -static const struct vfio_device_ops vfio_ccw_dev_ops; - static int vfio_ccw_mdev_reset(struct vfio_ccw_private *private) { /* @@ -88,26 +86,27 @@ static struct attribute_group *mdev_type_groups[] = { static int vfio_ccw_mdev_probe(struct mdev_device *mdev) { - struct vfio_ccw_private *private = dev_get_drvdata(mdev->dev.parent); + struct subchannel *sch = to_subchannel(mdev->dev.parent); + struct vfio_ccw_private *private; int ret; - memset(&private->vdev, 0, sizeof(private->vdev)); - vfio_init_group_dev(&private->vdev, &mdev->dev, - &vfio_ccw_dev_ops); + private = vfio_ccw_alloc_private(mdev, sch); + if (IS_ERR(private)) + return PTR_ERR(private); VFIO_CCW_MSG_EVENT(2, "mdev %s, sch %x.%x.%04x: create\n", - dev_name(private->vdev.dev), - private->sch->schid.cssid, private->sch->schid.ssid, - private->sch->schid.sch_no); + dev_name(private->vdev.dev), sch->schid.cssid, + sch->schid.ssid, sch->schid.sch_no); ret = vfio_register_group_dev(&private->vdev); if (ret) - goto err_init; + goto err_alloc; dev_set_drvdata(&mdev->dev, private); + dev_set_drvdata(&sch->dev, private); return 0; -err_init: - vfio_uninit_group_dev(&private->vdev); +err_alloc: + vfio_ccw_free_private(private); return ret; } @@ -120,8 +119,9 @@ static void vfio_ccw_mdev_remove(struct mdev_device *mdev) private->sch->schid.cssid, private->sch->schid.ssid, private->sch->schid.sch_no); + dev_set_drvdata(&private->sch->dev, NULL); vfio_unregister_group_dev(&private->vdev); - vfio_uninit_group_dev(&private->vdev); + vfio_ccw_free_private(private); } static int vfio_ccw_mdev_open_device(struct vfio_device *vdev) @@ -595,7 +595,7 @@ static unsigned int vfio_ccw_get_available(struct mdev_type *mtype) return 1; } -static const struct vfio_device_ops vfio_ccw_dev_ops = { +const struct vfio_device_ops vfio_ccw_dev_ops = { .open_device = vfio_ccw_mdev_open_device, .close_device = vfio_ccw_mdev_close_device, .read = vfio_ccw_mdev_read, @@ -615,19 +615,9 @@ struct mdev_driver vfio_ccw_mdev_driver = { .get_available = vfio_ccw_get_available, }; -static const struct mdev_parent_ops vfio_ccw_mdev_ops = { +const struct mdev_parent_ops vfio_ccw_mdev_ops = { .owner = THIS_MODULE, .device_driver = &vfio_ccw_mdev_driver, .device_api = VFIO_DEVICE_API_CCW_STRING, .supported_type_groups = mdev_type_groups, }; - -int vfio_ccw_mdev_reg(struct subchannel *sch) -{ - return mdev_register_device(&sch->dev, &vfio_ccw_mdev_ops); -} - -void vfio_ccw_mdev_unreg(struct subchannel *sch) -{ - mdev_unregister_device(&sch->dev); -} diff --git a/drivers/s390/cio/vfio_ccw_private.h b/drivers/s390/cio/vfio_ccw_private.h index 67ee9c624393b0..852ff94fc107d6 100644 --- a/drivers/s390/cio/vfio_ccw_private.h +++ b/drivers/s390/cio/vfio_ccw_private.h @@ -24,6 +24,8 @@ #include "css.h" #include "vfio_ccw_cp.h" +struct mdev_device; + #define VFIO_CCW_OFFSET_SHIFT 10 #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) @@ -69,6 +71,7 @@ struct vfio_ccw_crw { /** * struct vfio_ccw_private * @vdev: Embedded VFIO device + * @rcu: head for kfree_rcu() * @sch: pointer to the subchannel * @state: internal state of the device * @completion: synchronization helper of the I/O completion @@ -91,6 +94,7 @@ struct vfio_ccw_crw { */ struct vfio_ccw_private { struct vfio_device vdev; + struct rcu_head rcu; struct subchannel *sch; int state; struct completion *completion; @@ -115,10 +119,25 @@ struct vfio_ccw_private { struct work_struct crw_work; } __aligned(8); -extern int vfio_ccw_mdev_reg(struct subchannel *sch); -extern void vfio_ccw_mdev_unreg(struct subchannel *sch); +struct vfio_ccw_private *vfio_ccw_alloc_private(struct mdev_device *mdev, + struct subchannel *sch); +void vfio_ccw_free_private(struct vfio_ccw_private *private); extern struct mdev_driver vfio_ccw_mdev_driver; +extern const struct mdev_parent_ops vfio_ccw_mdev_ops; +extern const struct vfio_device_ops vfio_ccw_dev_ops; + +static inline struct vfio_ccw_private *vfio_ccw_get_priv(struct subchannel *sch) +{ + struct vfio_ccw_private *private; + + rcu_read_lock(); + private = dev_get_drvdata(&sch->dev); + if (private && !vfio_device_try_get(&private->vdev)) + private = NULL; + rcu_read_unlock(); + return private; +} /* * States of the device statemachine.