From patchwork Fri Oct 1 17:52: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: 12531331 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3CD32C4167E for ; Fri, 1 Oct 2021 17:53: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 0EC6D61A10 for ; Fri, 1 Oct 2021 17:53:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 0EC6D61A10 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 A45096EE95; Fri, 1 Oct 2021 17:52:57 +0000 (UTC) Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2083.outbound.protection.outlook.com [40.107.94.83]) by gabe.freedesktop.org (Postfix) with ESMTPS id 760656EE91; Fri, 1 Oct 2021 17:52:56 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=C8NfjF6lZu93qHmmNgx4tRumUUwvJpDWPrlMGvyGiJ6YHppD3dzF09c9UUrqU0+XOw+VLzdD88DLJB68ua4r/P5Qp+SR5W1HckNpnMzwQJbqjP4GYfIX7kfgvlc797hjjEIVMtIUb7YloJPy/VVaZ5yB3kabHn0CojFCTAR3e1pRH4bCBLyOuhsa0QPteZi/z6KKdALHn4Fb1C57ZhEf+52EuoJQqnB6zfBuivH4k2hQh3p3xNLcpeSE32QyhM1twtRRuqPDA9fw2b51k9dq2GsiGUSFNIoXSvIHX1yUTqJQWP4MzEs3QPdNYFSGBq5AJWRHxilUp0QqboVUbvaMuw== 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:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=T3h60LbB9T2bw+FmiqhpUTI2SUnXhU19LuBMGoKf83U=; b=KvnoNx1lLm3mquWP13tw0xqVdj96nvGNYcDaTJkpkEfgsY9bXzeXR1rglFGEHmIuWdz6Db/mFBoLXeUFpLfufMdqckDzdVXbJgPJp3Z5zloEgRIRidx1bt/XmJ2PTStQWh7vs0WaqEViF+WvaaYHw8TQhR6QcQiEm9RUIEiUFUwpdZ3WAq5RLKRh8h48sGEccofd0RTcpFoMAp7MIROi7FLiPOD6qQQHetD4z7wuuDedPO+CnttarrApttB8RiXP8fyWy8mDeP0nC5PhJ9aLQHvW9DhvaKMiRKs4bGUwwREwVbc8NjH3ksQZR8qtMGqN6nJKeZqc4DASjqGGG18Pxg== 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=T3h60LbB9T2bw+FmiqhpUTI2SUnXhU19LuBMGoKf83U=; b=sohRkCQsthXoAP2kdZjxKl8Pm2tm4OOn+7fzd50dHD7TD72LOGYdGBJWOzv8p3icypjwY4Pb+vYgzgn66fwKtDIP70vyPAIi7fC5+XCKSwhoSvRUa3UN1Nj0vvWqqg95wTASQpxKDjYoGXU31QE9A+iRdYzSA254DY+y+aDNt9GpVEW+Vd64nn9j3R0LWf9NqTyCBAGculskhGFw5ah9s2DP618MmoWB3AUwywQLGDonZEga0shF/RJUAoc95pzxYpHmII8ttDhGxt3EODu9XZjuVTkt2o6qN7ePh7iALLKlhTgO0FzPSjzwV1gAbreepVNCTKvJ3S+1119jly+/9Q== 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 BL1PR12MB5126.namprd12.prod.outlook.com (2603:10b6:208:312::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.15; Fri, 1 Oct 2021 17:52: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.4566.019; Fri, 1 Oct 2021 17:52:53 +0000 From: Jason Gunthorpe To: David Airlie , Tony Krowiak , Alex Williamson , Christian Borntraeger , Cornelia Huck , Jonathan Corbet , 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-doc@vger.kernel.org, linux-s390@vger.kernel.org, Matthew Rosato , Peter Oberparleiter , Halil Pasic , Rodrigo Vivi , Vineeth Vijayan , Zhenyu Wang , Zhi Wang Cc: Christoph Hellwig , Christoph Hellwig Subject: [PATCH v3 01/10] vfio/ccw: Remove unneeded GFP_DMA Date: Fri, 1 Oct 2021 14:52:42 -0300 Message-Id: <1-v3-57c1502c62fd+2190-ccw_mdev_jgg@nvidia.com> In-Reply-To: <0-v3-57c1502c62fd+2190-ccw_mdev_jgg@nvidia.com> References: X-ClientProxiedBy: BL1PR13CA0411.namprd13.prod.outlook.com (2603:10b6:208:2c2::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 BL1PR13CA0411.namprd13.prod.outlook.com (2603:10b6:208:2c2::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.7 via Frontend Transport; Fri, 1 Oct 2021 17:52:52 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1mWMiK-009890-0L; Fri, 01 Oct 2021 14:52:52 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c4df22c1-9842-4489-11c8-08d985044aa4 X-MS-TrafficTypeDiagnostic: BL1PR12MB5126: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2089; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1mcHjGiHJ8JmWzJgqh63htCHRwPWm4tasgW7nWj0YAFftK/iDpLDI7ei6ZM+9qO4oAHcXTSr/TNuVSo4Qbh8Vf7mnJkBvQD1gl+scBEUCpc1i3a2FKgv7oog72JEudHl+1KulPbRff/A6XYI+YRMhvGYWuXhHzOivSOa85Rs0VYxpf1terqnarMj6JjR34Qvth0ID07ISiEZ/VaWwnAcEFT+7ikseSBjQRY23+TbMP2eS2MW6HPVlRvEo0+w7oRNSGhgIH4sS30j0sQuTBr5Vz9JX5X2MiPito9U1bubJynkxNGHGtTr1e6fenBbyidOT+upRyqUSOGm7jvWl1zoFcX35bz4Ne8HWyGyx8uoQIYQn+OUs6n3/X1zZoxtZL7mfKpkDkSg/YMmffZFfwYQ0QxTlX5/1BltgrrCoYUvv+4xDo4yo+7i8N+vPTPHQU9pw56NMFaONGdUGe2CpKb9UgZPeMK3dvmX92X4/6jcJInmDQCXoBIeIyYOWjf1Kp86S2Np4rniDhuL7wGVNQv0Qg1hAYjDPFysm9eMBIu7MFRjPjEynQ22CsHYSo0aTVp8yEwjQ35IxN97PbiVow7MoVTrFTFfTy4s4rYhRNp3xH7HAGQjtbI/QsopzaauY0xZAxHTZ/aev67k1D4qNqqSYHH/eP8PqQOI6saNAZz21CdGrf9MBs1irRZ96b4FsMhIU+AMyl4w4Vq9ZohC4Qp52SDolu0q9UsWvocgaYdASTE= 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)(508600001)(921005)(2616005)(26005)(83380400001)(6666004)(186003)(426003)(9746002)(2906002)(86362001)(9786002)(38100700002)(4326008)(36756003)(8676002)(66556008)(66946007)(110136005)(54906003)(316002)(7416002)(4744005)(5660300002)(8936002)(66476007)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: T1mqXLARw9nCuZeMG45C1g6tYW6zAxw0Edj52oYrAvWswcGR1dTWFPm0fJ5qSlI/D3aEJEhg2Ai7qvCXhurULQsF/MUp+y2SFvV4HH1bwV9w+jFNeW3mIa63COsFASpVZWiieiArf+wymAYLpjuUynFbPDh119b+xWSo4vdHtusIT0Trkxn54bfkPMpHyom5T2iZ7eS6gDGv4Clt8Xd3/fZVgUrDl+oRzvOwIllMuYkUyNzXsIdKnEKXqBjy2pMprEy56NO0IroZ6GB6EMb8qL3ioKXEGEFHtV126i9lEFKijyfuyQ3EdKgDBpqRS9RQRMDR+v9sVkodGaRp+HgVgq/3XH7TZcZ8XCw8Vp48gMK8GP9gqC+FkEnMqQcw0JNx9QLb87I5t2M+7bXyvppZEdPs0t2a6gYe4OOXzy2ldE/niyB/T3g+S//n7JTlBxPzdoInNx9UN3LwpCkwn2LL5hGsUdM/7GVw5I7sIGX9Kpy6A4PNfmDptaUIvzfXQy/Vp/cOhAW2AK6e3+c8ux20wLq66oWOX9O9RZEWmG5ECggHQFXmacQN20w41JR5XnBVecEpV9AoltV9d6JjZWTcR127rE0oe+DPL/wEbP3RUR7JK6UQ1W7R+no+O6c7sP5stc/kElOBLE8lMfMHjokNhD3TaSHTQu5jzewmTPIb1sbwV7f2wwblk+bEEOuMPGVKbDmForOTVzJWPsHdMpMCOX/BhjSameRtZI6qe8bavczzXEAhGAEDS50fS1EZDa7epDTi0N+9BYA6GUB0NdZOV3QRZuYFrKDgtlXLQIXDMgJ4yYT64m5aDldHCoqQHpkZf5sr7ff+7oMk5cAGdmU8yfJV8Nhr3RlpDo6ibrgjk2yPw/vkoQ9yisf7TrX0wVScjJimELYFJMCw4MsovaoA3NBxk330Q0JulE0CKXmeX2GgS14XNppL5NsU+YiT88CLJwTymXh1WLwDXdxL2B+C56zl7IdLb5HsxN89KK6B/zzyyKtxk9/LGAO1Tx5/H+Sz9BCgzHxvVu2uInBM/1lQ5ihYlJ6z/wjdh2RRjHkbSXzX0YF3mnKvjbLsi8frogJUUex2ZNFUpuS4qF+ksVOjvs9wk/egqnEYiiX8lt9p10ic4EFvRIDJp+c+quNYbvKHBjjN1IfUAofHFOxGxohmaIzjdIzFisCBrPplfi9yP/Lh/HE0EfMFke40Xm46f1Tt+HH0B44d32bpVPBw1c1mSGwbZX3iq/ws0lqAe4ITj05vlqVz/kgPK124pD15C5RtMLokobz6zcwmoGixt1N4BZKA35oFPflEYtzpRQQVmI+8hYTkQQ47EIhU8knF7lxwD16zOUfF5wjHk08IUltkcA== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: c4df22c1-9842-4489-11c8-08d985044aa4 X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Oct 2021 17:52:53.0296 (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: krAd+ZCZhpxQZgULtYYczwDhfiB0wDJH1Fb4X78bnQRNpAVRQ2fXCzq9hC1P04Cn X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5126 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Since the ccw_io_region was split out of the private the allocation no longer needs the GFP_DMA. Remove it. Reported-by: Christoph Hellwig Fixes: c98e16b2fa12 ("s390/cio: Convert ccw_io_region to pointer") Signed-off-by: Jason Gunthorpe Reviewed-by: Matthew Rosato Reviewed-by: Eric Farman --- drivers/s390/cio/vfio_ccw_drv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/s390/cio/vfio_ccw_drv.c b/drivers/s390/cio/vfio_ccw_drv.c index 76099bcb765b45..371558ec92045d 100644 --- a/drivers/s390/cio/vfio_ccw_drv.c +++ b/drivers/s390/cio/vfio_ccw_drv.c @@ -161,7 +161,7 @@ static int vfio_ccw_sch_probe(struct subchannel *sch) return -ENODEV; } - private = kzalloc(sizeof(*private), GFP_KERNEL | GFP_DMA); + private = kzalloc(sizeof(*private), GFP_KERNEL); if (!private) return -ENOMEM; From patchwork Fri Oct 1 17:52: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: 12531339 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D2700C433EF for ; Fri, 1 Oct 2021 17:53:21 +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 A039C61A8E for ; Fri, 1 Oct 2021 17:53:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org A039C61A8E 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 A11456EEA7; Fri, 1 Oct 2021 17:53:00 +0000 (UTC) Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2059.outbound.protection.outlook.com [40.107.94.59]) by gabe.freedesktop.org (Postfix) with ESMTPS id 796E06EE94; Fri, 1 Oct 2021 17:52:57 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ja5oLVQG+d4lHvrz9d9b94sh4TUn7mhlwX0rtdZAMYdaEIeYEixuXniDxy1783vjZzU7kTSzDZxyXwbOQXaZTh4culfJ+51xNxTGN3on1QgKzTz9yK3u9xqn8lHPZfm7IyNMeetrwa2axrmehgGm/ZuBoTIx2rx/fdcGOlQa9G0q5gekKNscWkH3tF0e0DXdKWi1V1i5poHsTn+V5jAtBS78FwBsG8eV9bkdghLcE9ut12lToHdisx4JUzDpwrt5RrL4R4lnKFPPzZG2JsbQ4j3iGEaHwgiw7lT8AQSUSKC5omBEWa8bClxgPbyP/+LCpsNnOEdIJpvzv+X2lSJDxA== 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:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=YTh6ZUm2PrgORCNyCbn+2r3MpGIT/x7JNE9sdNM2aA8=; b=hv11hZzKoABxKudnyI74NBAwHIFDJ5YRUPJfjuY2d3aU380gFZTaELeyG5ssQ+XrFzAknvs5YumCXookENBRnXdMKdFEGCzkUkEBglyayIUG9MhgYLlNVtpFVPvpc1HJ4BIjlM9UuDw4guXTM92UauO5rI1iGzo9GDXEcWo1g/k1Idm45VvZXtKIPywPhSntLlFnFH0+ylB8ruKO+uknoymXuXTBGSc08b0VuSbbcxiZXu+0C7u+hTsMN9Mt5fkfSmqomVHHZla52DFrHhmV0eSdBemBTcibIgoiCgujNQU9wkKhPzsrPNpgAJMX25B5DsHnk6NVWcjX0I9dUeB18Q== 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=YTh6ZUm2PrgORCNyCbn+2r3MpGIT/x7JNE9sdNM2aA8=; b=K7HkYFW7jun+CwGwq0fl53dyXWIUuWhXUDMdjBgJg61RSRUFoXva92FsHn9wlCn0d7E/HutYzBQCsRh5prdJZPALmWLZrzWWA/K4VavcdttJc5BzxQ+ktEkNfVCTwY8IdihLLLt1NBb5cA374SU38cTDumWGsNJ4uNE/if8jI6vuo/X7kB/IStAgIUKf4GS0ZOQvV8QR5AwCZYIj966a4IOwW8g1wfChsp7XJx9ckygUTrArbX7Ea8U87QdNOJMR44hlcQLoeHhJ1ywtth8dtzqYw6ylBj0Rb7TTDx4GrZrvykek7RVD2vU9aReEgyNNC6dine/s5LAAYavVE5dSZg== 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 BL1PR12MB5207.namprd12.prod.outlook.com (2603:10b6:208:318::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.14; Fri, 1 Oct 2021 17:52:56 +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.4566.019; Fri, 1 Oct 2021 17:52:56 +0000 From: Jason Gunthorpe To: David Airlie , Tony Krowiak , Alex Williamson , Christian Borntraeger , Cornelia Huck , Jonathan Corbet , 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-doc@vger.kernel.org, linux-s390@vger.kernel.org, Matthew Rosato , Peter Oberparleiter , Halil Pasic , Rodrigo Vivi , Vineeth Vijayan , Zhenyu Wang , Zhi Wang Cc: Christoph Hellwig , Christoph Hellwig Subject: [PATCH v3 02/10] vfio/ccw: Use functions for alloc/free of the vfio_ccw_private Date: Fri, 1 Oct 2021 14:52:43 -0300 Message-Id: <2-v3-57c1502c62fd+2190-ccw_mdev_jgg@nvidia.com> In-Reply-To: <0-v3-57c1502c62fd+2190-ccw_mdev_jgg@nvidia.com> References: X-ClientProxiedBy: BLAPR03CA0120.namprd03.prod.outlook.com (2603:10b6:208:32a::35) 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 BLAPR03CA0120.namprd03.prod.outlook.com (2603:10b6:208:32a::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.14 via Frontend Transport; Fri, 1 Oct 2021 17:52:53 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1mWMiK-009894-1G; Fri, 01 Oct 2021 14:52:52 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4f54df12-0501-4ed7-f9c4-08d985044b2a X-MS-TrafficTypeDiagnostic: BL1PR12MB5207: 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: EJiL5d5lrpuqAOIFj2wG6wJ0TQYuk6i/EO9wxI3f6dHR3cgsFXDke20wz/XqNcHsyYlltwxfzLEFtyYDkd958188Sz7iUhEJpIbngMGcxpefcVTnNoE6tNd1tK0YgyDZkg5d6fMNuZJunNkeNH1Dlrv8tM/YNHk8YAP+5ZDfKUA4lO4yDdo5TNbKfeswuRpwM3IpkGZ1UhoIiuSq6YTfurVFzGDOvgbkAZP6UsIh6UATRe5YuF2X5dAuvQTiHG1dZ/9gZpjyPxMDKk5n3bm4riJ29MSHKkpUQlHb6ZalBtiHnui82+br0qtxtp6Do18TNs/3QnAIkN7N0sX5Q5xt/Ln+chmkLB3ASGZhZCTlufupQQ0KgUMgnrADTpEHxER2MIQ84zPo9KtMV8s0eqWH4hGJUvnQaikBFTjw3Jr+xB3MITjHbpYvO/LZzzReVid2jqH681F2wrdNAeZHoq89bxhA1OqwtICdaZLZEBUIidgB61Lk9pcNvH9qXkuO8SoTX/Lyglz8ZHTB3Bt/pxXEc1QShum1PqSq8A9v8T/k3AgbVqoxOAGvfAdIJKZbFaOZxpD0Oifpt5K2Pz45AoNohnf74H/E28vC72G+NZVsUxsUJnw5Z2iW/FhT87L/b0BSTfUhC9A6GbwXZt//5hmgTnBEh9GKRmNv5XPGwHjGCHIjYiRjtvmNKgmjTSmfX+5+dDhM8BGYvsY2UQ2GQKJ/Aw== 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)(66946007)(2906002)(83380400001)(66556008)(8676002)(38100700002)(66476007)(5660300002)(2616005)(508600001)(426003)(9786002)(26005)(186003)(6666004)(9746002)(54906003)(36756003)(7416002)(4326008)(110136005)(86362001)(8936002)(921005)(316002)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: PJqfE9lx2vWXLo9xJiO7ojLm2MA89maNkUlO6vr/UTYBz5a3S6Fw52zAziw2bOGDKIzUoFCtk9ryFRAOPfc+wNnEGXMXDIN/8h1T/mgR1SuKaC6IHCg28Y4366Wu8wrrZGB0P/EBVQi9d/G3hd35Xu0KxHo5jh2v30QLo9TrkauoKeMjl2HxuWObQaVS0CN4I2pa5ruEg44wxn//GThNE7+vIV/Cou3pywg4IHzNwtLiN0yjMQQqSLIs4NkK3AycH3AECYjeUyt3l95jFOI/to1UUTj/U/w78eS2b2zi1Zxr4dZ0PhYBu6fX/leAPtpsaq6yHP1khe+pP7F9sNZEAzYHXu2Ev8rY2aNfzZ4IGTWZ3wMYaUHVZnl1wkwyw2DDmRy33co05g8UwujNxn+9CDb3aqLupK9ICKbXqv0mvM/iWXi7TPuWJeAgywxzwWUQB6GyvqUKVf2n+wgCXlaefiZzfAv4f7zQEF7Mr6e47jBhNuzxI1nyDrg5AusN3MgoYlexRIPeFfSv/JejCYfscENqYUYWjmeFuvdj7sF8qRUbHVe0hSR3e2VsVDe753A5PgpCN7A1nkUYggq+gb9RfrHCpH35v2sFGebuviHga2V3PTHrlwd0ut8JM0+wuwb3rYgkjLzMYYhyFG4ZLWr7MtcW6csCrSeIN/Uym4GTtkOq4K5B4uh0+DrbJkoNizfGKLz8XArcMLmhcbY0O79D95T9v8z5prGyXCpGe9kpc3dvvkwQ1O2CfGuyImGIgSVAmMhFnS5eWVO7UlPAd+5AuqiaYXmatL9dhTqRY6r7k9fPemX1RerdTjvZtkY48ZauzEa2SrYNjGxvMtx1cxNjrqB8Z2+M6DmSsyEnO0kitYTComJ6JWpPYIc8Wq3cAY3Y5k4PwSjQoMOKlcTBu5K51mZhjn8iERXeS+pH8YQUuxYSFTywnzMSBVJcimyVlNctgRpNcUY9EoJEVzDu6R6I4MzpC4m5zKDBjzkGzbH1G+SKcncTx2F8jSWKg/QYeBIF45TKqIwERu9qRNoV7pWUww9CCkv5cd7B1bfvjGXLgLqMx0hEwld9xJIVbBWgISt82uRZdGUa3XNK4NgaVvkwyymKUf7h3pXBapTegMIJtJ6403XM4JYfZDamSL+loNvYam9LbCFds1uVSi61fzBYdSn/ScKXHGU5Nh8D0btAN6gh8yWG4QMNY6nz2C19sXTx4PGdPy6YVTYgiEWcVKkhOHkNZ3TWX88Y0SCo9ouzsmyPQuLAK5J/A4fF5b/oPtlWCt6TvNNEHPC+2l28NjxsT7Yxfd6LcvM6NwtLeIY7g2RNilW11R9tMJcUOMbEs3lZ X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4f54df12-0501-4ed7-f9c4-08d985044b2a X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Oct 2021 17:52:53.9018 (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: aT83wcHhlLaiQc4MP99HGsApswU6MsocYsvyoThAZ4/N/UAV0SDd0zIpdcrqDGNj X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5207 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Makes the code easier to understand what is memory lifecycle and what is other stuff. Reviewed-by: Eric Farman Signed-off-by: Jason Gunthorpe Reviewed-by: Matthew Rosato --- 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 371558ec92045d..e32678a71644fb 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); + 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); - 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 void 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 Fri Oct 1 17:52: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: 12531343 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4516DC4332F for ; Fri, 1 Oct 2021 17:53:30 +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 1A13261A10 for ; Fri, 1 Oct 2021 17:53:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 1A13261A10 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 3F06B6EE9B; Fri, 1 Oct 2021 17:52:58 +0000 (UTC) Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2059.outbound.protection.outlook.com [40.107.94.59]) by gabe.freedesktop.org (Postfix) with ESMTPS id 596C16EE8E; Fri, 1 Oct 2021 17:52:56 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LX+HuVp/Qd/ivPr4rSYU/SjZS8gVMcpcrlU9fTy2iOYnpfsYH3mqyWn2UpgZEZNh20ZeNksBwvOof3MOrkJBCZSnTWO+BEjKvc+05L60T18twzm9tiX+FsAA/5Ur3nDtqm7JC/8ZXFna7QG7/owrRdV/C9fi3XcjKJpwjRfyrNFmzuM8+KMGFH+kq1bNgP3iRh/fKx2PKtvnA8bIuooM6DJlJ8F5jtWGkVR74giTUUaA7kvIB5HabyfP05L1Dh61Jd97oPPFgXJHJJ+GTWYzd4x0DFmeY9A+yPYsvkW85cttD9KffO/XHug34h8Qyy71sdHd1sGzqal3PEg/UPIm6A== 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:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=IYcXEm6RVhMLVup7gQaCrlAlylWOGFSxlS3RrQwdBjY=; b=aLbX0zpvz5hfD/dKZHPUb/H3SX/QVl9JvaLoEPUI4CmDhQeeH6VrIxdWfVbITmkW6LUfe8qf9fefH3l66QYKphwbFN3mhbDBHnzuOG689YkSNHxpYEqMy2a5DuMNu08RHRKpy2u1KtHl5ln0XtU7KZ5Fs7BLhCXJ/HFHIWNSTCIRQl56gA+pGGiPHOeJRpCGeTNtPIR92Eoz89tL/+uqF+GrpBLT+w0Q/nAN6j7TJ/1NC4OvlfhsYCnh2+Po3VNymZZJyvZbnL9Ilo9J7U7mnkGvxCXD3ofLV7CTZvXLEi0mAk25tCEAyApPc2/1BtGbHvMiSsHXYUcYrUzsDFWJYw== 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=IYcXEm6RVhMLVup7gQaCrlAlylWOGFSxlS3RrQwdBjY=; b=MCUAtE5zNZxAQDZ7JrWOfRRoiE8FFpbpgcGHoVDlYZNyl6NYnW6dmNjTdeRxDjIcKYvXidGT9uZQQU80asrEqE8J/n4Re2Tk0pdtL+7NpQAMOUlGxCPTb/WWaL3on/HuVG7XxbQC+oQSTZbhhukcTtERZJLSe1EQyYvIC1raGLpUfN4iE712oP6/JQkgcGuShgISyaDAjEaMesf+85WOjmB6tmBziDmuUobrRhMUgr37gh8GhWMGtutYCL1NruTBzSdqMqpvJAp2nx8IfYWzVPR82rzybI79+Ofpl8ttozg9qOp6TYXT7RBOB/BOHnZDrhOBuNTvNNOxsL8mvO3UDg== 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 BL1PR12MB5207.namprd12.prod.outlook.com (2603:10b6:208:318::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.14; Fri, 1 Oct 2021 17:52: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.4566.019; Fri, 1 Oct 2021 17:52:54 +0000 From: Jason Gunthorpe To: David Airlie , Tony Krowiak , Alex Williamson , Christian Borntraeger , Cornelia Huck , Jonathan Corbet , 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-doc@vger.kernel.org, linux-s390@vger.kernel.org, Matthew Rosato , Peter Oberparleiter , Halil Pasic , Rodrigo Vivi , Vineeth Vijayan , Zhenyu Wang , Zhi Wang Cc: Christoph Hellwig , Christoph Hellwig Subject: [PATCH v3 03/10] vfio/ccw: Pass vfio_ccw_private not mdev_device to various functions Date: Fri, 1 Oct 2021 14:52:44 -0300 Message-Id: <3-v3-57c1502c62fd+2190-ccw_mdev_jgg@nvidia.com> In-Reply-To: <0-v3-57c1502c62fd+2190-ccw_mdev_jgg@nvidia.com> References: X-ClientProxiedBy: BL1PR13CA0399.namprd13.prod.outlook.com (2603:10b6:208:2c2::14) 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 BL1PR13CA0399.namprd13.prod.outlook.com (2603:10b6:208:2c2::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.9 via Frontend Transport; Fri, 1 Oct 2021 17:52:52 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1mWMiK-009898-2K; Fri, 01 Oct 2021 14:52:52 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5710eaea-f8de-4be8-e471-08d985044aa5 X-MS-TrafficTypeDiagnostic: BL1PR12MB5207: 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: 7RFr9a7tSDQJu8zOr8nV8T+21vzPeiC84X/O187j3A8CWBMoV9V8i8Y4ZRhkkyKBVRpPyyFwXFYoDbaCeM7dkG11jS+oDBPEcrqLvzC/bk0i051hyuOSvgp+nHd9LgvqZZswtqoX34xikAIYHGOBrPk42s/mOL2XERsgCOqUg9FzXLpSNBzlygCtwHr65uzisI9+sZuS9XihllLb7u1fY86KlG5lC3Zy6H+lpxDyD6+4DcMaj4f3AlfU3VTGgUErywJAXi0U5cFzNVtGDMsOFJVKrcSuUV58v4bQp1FOEXRu0Xj7F8DrS3VrIsRn4YTFoiZcJPTgeDE8c3lc+QZVw5ltDNhoVpYrTgK6xz1GBujIV5kxFac+5MRAMtP4t2K6N61f0y+MRhTPeiKDa//pp8Tt2ui+JQol/Iwg33s3DUzlqbY3GHK/5yw7V/rZZNyWpLBjzqUCtH+RkzRuZQKJnm376NoV/8K7jGWb2UeNrn+x1SSjdilDN9/kUkARFxSi7XnhFmmx5v9Apb+Dw7qSoBl40Z9GrlBaDhCuXN6JU4Feo5tJf+HL4qJFDTfkbNfq2aGbEqI+I8bGjWM576T7i/aPHPOzz8L9ahpFoUcepBZc/Z9LzngTGeXNTnaqqOtJfNc0la26ZEd6AD/6QhMDMZ69PN/TYq8cFCB4nakPYcpaV2taTQKIwSMUwaVCwi8fER820ZLE4HutmZq/sT6VqHs5wmrO45M8GlA+K02X2GU= 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)(66946007)(2906002)(83380400001)(66556008)(8676002)(38100700002)(66476007)(5660300002)(2616005)(508600001)(426003)(9786002)(26005)(186003)(6666004)(9746002)(54906003)(36756003)(7416002)(4326008)(110136005)(86362001)(8936002)(921005)(316002)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: D1NUdkulg324xn3cS+L8y+ldfLvOwHTasKc7pBW8ki0d9BEIyNJcGj7xCCXh7VR7XNE1kJW4Q2pscYVQeIg4NTXscBuR4m0SIuIGhrH4oRUfU5GJG4Oq5R5ek8Kn8ic/XH1MRg19CoduoPMvPD0YGWa1BpmcU+bsP2iB4ySRpcbhOT8LLQ9EH1DPTawKY0p0Gn82XHIzzL0BFckYH9q7qZVBvlpAJ/wbjoSjdCMWnE6Z0uHmk9ZcZZCJ86plt3x50vIsHnt1OtooZkU3vSfXHpKXkHjI5EG+9biETemGvpWO1TXS7Ujd0mjlRhtFiOIX2ZEG87wAm3NcXkvaIWjUSB9CqtJiPbygkKRxX7wjqBBNrlRjLpPCbCPfosLTrw5QKbBwykZ2zMqQmzDfCix+lezVkyVLuqL8ULpQOmd7iBSF8cNmPEs0PsyO6N9FWUTi/OGHosLnjCSGXr863tEe7yDGdDNBpFJtNjA7RFQXrD0899tJbNsR2gH1yLY/Ypbd0p5N/pVqZIX4V0XOUgR0sttHPF6W0RJAuQqcNHcTHgVK/QthY8OoFXsqOlt/Vj0wooIkbD9PcT0210h5yku2gQolXlp8v0dfRHlEZgBn2Il4JlctDTz+A+Mbhx+KMgl/XPiD6DKTRG0YNJchovLuyi62ItsvSQHWS3eGYOjKyccK2UOHTHb+7yKmvJqjp31lsUPoGwerl3CSd0RUP8UcQZzQhkUil4IW/z5lM286YexWzLOzIoir+pPTHnSjIKeCA12oQD+OPaz6Y4nA/pyi5R2U5jrbBCV74UE2i83LVgRdY8dKsqo39ICAgJCJluszxZC4fi+YJDGKPpM74jfnx9fklaE9njgMugXFMLUyo1ntxY8Glq9p+imyb2K/nLpluKAr8wJ7297UAkrAwGIx+wQvCItk1xwE9neD1cUd5f3r3GMoLJTu2UbIOIevGEFZBJl01X0CLmjh0rcEN+6hSyiNAxtd3DzpMxQp872YGmaXbUElYOHcbCRF+Xq0whRcb+e2NsTN/E6A5K7pAu9bXZbdrLMzkEqiUwwW206WQyGohsODEhK7BeWv96Bis4YVvqGp7gfd3PllVYA/A0eNnINGHkz5JBe8oRuO1+5c5aLjfEMl5Az5vlcJYD6RjswXDbKqfbelcHsze3vp68RhIp3ayVwSI7t90U28HFFtt010+/PxBW04HoPStq27K2EG/U5YyzERsTu7V9Hv7xaxRILgHbaE6xyCwVTzJo1eF7q2WtBhfAUP1H6nzPVKlAJwULPEnQIzvliV5tlzlHZlNbr3XrB2dGi2JjhqUayVvswJBhphGpUWWnsd/tySmaip/9nLtU1+53l0pGzOMPB6dQ== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5710eaea-f8de-4be8-e471-08d985044aa5 X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Oct 2021 17:52:53.0466 (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: UT2S9d3MkdhJkBZm3BDCPtqHH5MjGgVNyo8dhgbYGR/Y++P0z6NyQEpCBjJzCVId X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5207 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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. Reviewed-by: Christoph Hellwig Reviewed-by: Cornelia Huck Reviewed-by: Eric Farman Signed-off-by: Jason Gunthorpe --- 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 Fri Oct 1 17:52: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: 12531335 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25C99C433FE for ; Fri, 1 Oct 2021 17:53:17 +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 EBBA361A10 for ; Fri, 1 Oct 2021 17:53:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org EBBA361A10 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 28E976EE99; Fri, 1 Oct 2021 17:52:58 +0000 (UTC) Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2059.outbound.protection.outlook.com [40.107.94.59]) by gabe.freedesktop.org (Postfix) with ESMTPS id EF24A6EE8E; Fri, 1 Oct 2021 17:52:56 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Af552iG898c5YqGxVVeudiaOpp5Pcgyhvm8L7n94fEAKtKFKYi9hEyDumj3h+aRkclZeFOclRlC8aEM2LD1IAoaLcFwtkFJIo1+agUKhm87nMQvbpwiqdETBgB5Qx03XIeMJrkvDqRKppT2rzDtrBTUkRiyyTu7W16QNWxNqMuVUCF5DRVrzHhHlgOhB/TLfveqhaYNrcGMtDDEWGYm0jbdoB78NtIA73s5dRrCjJaWolgUpYonSFm8OCCYYdzrhBz44FnzG7uA7UeiuykH+NkVongGmrHlIxVf8MNaHTIL3WkxKz3t7upNr+NPjbrFgH6dOCDsXPJspbsXMX+KJpw== 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:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=cdC4E8yZ8e1Iko3PPF8d683FmazY5roIrUlwq/k3ghw=; b=MsJVrlKjnmpRgX4oDeuSUgHUpHCXl8qi34hhIBpNS79zomIvFKHhMG5mzTMrq4RRz2yeK1bbb47DBST+9oDvyC9Q/c8u5Sie2LHhb64ypq307ZD9NMzhB/Fie6k4aNDg97Vnkrjg4aI2TXdTS4wv9+fCdgd1//cZurwTA/1HhealS//0pjdYmV3zXFONOLnxs+oFylD8eBBJo+yRZf7rODVMrSDnCa15V1VNUcubSn/V5BSEi3qZXuNNoQfOD4FJ54VUvbDNBcIxJs5JNi3bsG8WXmJB1O4aRIUG3G9cEdm1zIBlN6jVXTcA423qHbJF5uwf5InBgTVtVeZZLTc6EA== 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=cdC4E8yZ8e1Iko3PPF8d683FmazY5roIrUlwq/k3ghw=; b=MwfYkaS9WYDimhWdDP3KtHPR/D0Cp+534epVDmwto/LBNmX4L/h3jMrv7K9kOUiiS9KL5R+lEy0djEaH44lvp5GCATIagJh5Q9dm5ddoi3A3UWZcpwMmc71VhD+bcARPimqh5Bcuig7b+eZcEFJUbmV9et1GDsKDOvk9Wn4E0EQ/iicmp8V/QDLOUBtvuPaum6GeJAMArmG8WA/l3lBZqbfj+Jdu0qzhLtw7wkzVtYOpqCkPdG7JVylHIYVjsH7exetfoDCPcIQ8uY+h+izzaJ3RLwKu2rBonUUGRF4WDbQdP6/j21lOP1ohb16vpnhoDu5UyNlOd16uZCIBbiKueQ== 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 BL1PR12MB5207.namprd12.prod.outlook.com (2603:10b6:208:318::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.14; Fri, 1 Oct 2021 17:52:55 +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.4566.019; Fri, 1 Oct 2021 17:52:55 +0000 From: Jason Gunthorpe To: David Airlie , Tony Krowiak , Alex Williamson , Christian Borntraeger , Cornelia Huck , Jonathan Corbet , 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-doc@vger.kernel.org, linux-s390@vger.kernel.org, Matthew Rosato , Peter Oberparleiter , Halil Pasic , Rodrigo Vivi , Vineeth Vijayan , Zhenyu Wang , Zhi Wang Cc: Christoph Hellwig , Christoph Hellwig Subject: [PATCH v3 04/10] vfio/ccw: Convert to use vfio_register_emulated_iommu_dev() Date: Fri, 1 Oct 2021 14:52:45 -0300 Message-Id: <4-v3-57c1502c62fd+2190-ccw_mdev_jgg@nvidia.com> In-Reply-To: <0-v3-57c1502c62fd+2190-ccw_mdev_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR19CA0059.namprd19.prod.outlook.com (2603:10b6:208:19b::36) 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 MN2PR19CA0059.namprd19.prod.outlook.com (2603:10b6:208:19b::36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.15 via Frontend Transport; Fri, 1 Oct 2021 17:52:53 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1mWMiK-00989D-3V; Fri, 01 Oct 2021 14:52:52 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c7f91251-5575-4337-d682-08d985044ae0 X-MS-TrafficTypeDiagnostic: BL1PR12MB5207: 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: q/heFFRQg4DuHGnjn4k+qAam3mggCwkgGvyuH2kDT8kDj2TBdJvE39i+9Esj6JyZrgf2/perzFGooWqA/kyv+Anlt0OpfwLXlMMdWsaZ0bNl0jXN3G+r/vFZ4QhsA6CkN+GfSBP66yVGbam9k5H7oqxUQrjHuNmIe66vejl0zjLX8WoaJpWqcL1TftFh1B7UHiwJb7RWVYYXizy+9abkjk8PE27vGvfIWXSuwsABhRXiGlE7sRFYZQxV2EYgIWHVysadCFJbO29CBnSe+5AkerXy0yfxPCR/g0TALQPdKIJoMv3TDfPHqnzgWtAs4gE1WOmbNdhIuMtLW1JKgs3iU4wiYm5adHkbGrpRcLyXs0xBP1VvuFX/gPBwnD4ThIlIMWPc3Occ1QHieLxhuFC/hA5o6N5J+rHg6nZ+6pUjFWYnVaZhyHdllsJERmkNsI+kmIuXzsAgVSVQuysAe/HMJtwPvZGNkIZfaxb5AVjBr2KEvpYbmeSHU7KkEVeMBnzKiy43f1EgeU2cnuxlQjy3LyhAngV6JW+6zTSOQlkp+70j25ntVKQVAHmWzdKfJVHJfuD+bp7PFa8fkm7eEn1qlgw9f3TGkfz3QUBdF7Pf7KRx5WmRlPcT9wZue4/S+5Pm7ZsSkDM7rwLXnVRxa3CSqsDPYE900AOeCU0iWzR9XZq0A9n+99Of+vpZgxEUlG4Wm6+Yamox0hGWca67kc2v/A== 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)(66946007)(2906002)(83380400001)(66556008)(8676002)(38100700002)(66476007)(5660300002)(2616005)(508600001)(426003)(9786002)(26005)(186003)(6666004)(9746002)(54906003)(36756003)(7416002)(4326008)(110136005)(86362001)(8936002)(921005)(30864003)(316002)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: aHTAhoMrxd3CwIejBkop3m0y08UgVydX7EOWhCzdwJXbQh9czbO8YYrgfWrMU/1erMxoQZUeWaM6eQXWA65OKojNs9vfZSx51f+NoF5VBmhwcrGQKadKTIQJTWU4IvRKWPT5pHMeBD9QYREawS+lDM0gxHf08CnKwGz/n/e6ijd1xCDZyq11ywUg2CYrsHXh2cLO8Dw0fhiawZ24Zg8fY42DGQNTtXjGFLnL4NVGIiSPUCvHxOmUAXth5mt41e5R3cW8jowwPKekt44QH1nKO5MFfruwgFlGv+qzF/4LcAK86IhQIn+HiwZZ9DXH0o5w8KET6yV8yRxtavn7U2NRLsDrtBuQtRKP2KwlMD0VKe7syt804B2CVYhKXc80dSSrlEJP8u2vzaPsWbUiV/TItzJNWDB9qE6ZXwWxp/sb8j9J/TQ9sJuJxWBqP120yvfmPnlvtL8Mo7p8oqIOOTZXHdt7uLIM1rpKTqCZHM8yjUEzWmQw0uKF7yeimRkIcVUHATRxAuLKgnKZNyh56wIJQeInTwTHGThiVAoR9YQ82SPVLzGFXQDjnbEIw8B5WjStu1Qyz7Xy6HuHSn0UKNhReoHzmf3CqyqhmooflWE3cCfDSea8JpWugOfFbA4GsL4mGwBcOplWZqKckxDJi4gS9ZgmvbBpFDKF5BSrS18Apr0ZO4bQnZPMy2c6nIjzsJCMUjfoHh34izguMcbgPfAQHdCKONP/+yfiAzUKzzomFskDqItI/Mnysy7vvRUU5DC81hPH9lCfegTn/BTBs2JdcbkFt9E3EG2g8mzPBfd52I2VlbUvJNuljIE/b00+T/3iENvHpnIkhyAVDqOXvJCHfppshMdx4TLAjMOIziS1npJD/ny13c1sz4ZD2DAIsuFgktEjdUys2QGxHKaW0sZ+/hzz+8vmlhrRr78StcUAVkgfxpFWM3f2eUw4KwLkPI226imC7IRAhNMu4irOFv6J5Ah+NOrW/iRh0TX9kUFwvIUjMPCrGzRNGZKdBH8w2Ld+Sq7x2Oq35pAiTUZBMiKOJxXQTsFWU4q5Kmjy2O1o75Cl1oN2/sX9sRksB/BzJPCFBz7zu5XbyvQ8jNn2m1b8VRVmrrmgpdNNzdxVnY19ahPUOVeVL4tUM3zAJloeBjPOGVr6X3mSFFo7vm9BLaFnBLSvMUsECVmnWVD2l6wHvxVTMu+4SS6l+cTJSMBzY8p1G19e4QEhkQeY3jmyJp4hTBIwWsF/tOlz2B1Zw14ipdR6nQFTdPCBMWgnWm7dbt4GoWhfmMy0YuGaQhM2GY4xZAIGgnVEXGnRAVyPZWEn9aTj2QIwqB5a46jnNqUMtFEw X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: c7f91251-5575-4337-d682-08d985044ae0 X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Oct 2021 17:52:53.4249 (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: M+fPTCRa65nJafn/C1pTR3NjAqS/eg/UA12DZ7rv6hGJ4PlAG5PJIGukFxiGsgPv X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5207 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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 Reviewed-by: Eric Farman --- 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 e32678a71644fb..0407427770955d 100644 --- a/drivers/s390/cio/vfio_ccw_drv.c +++ b/drivers/s390/cio/vfio_ccw_drv.c @@ -468,7 +468,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", @@ -477,7 +477,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", @@ -486,7 +486,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", @@ -496,7 +496,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", @@ -506,19 +506,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) { css_driver_unregister(&vfio_ccw_sch_driver); + mdev_unregister_driver(&vfio_ccw_mdev_driver); isc_unregister(VFIO_CCW_ISC); vfio_ccw_destroy_regions(); destroy_workqueue(vfio_ccw_work_q); diff --git a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_ops.c index 1edbea9de0ec42..d8589afac272f1 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_emulated_iommu_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 Fri Oct 1 17:52: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: 12531341 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D1549C433FE for ; Fri, 1 Oct 2021 17:53:23 +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 A164861A10 for ; Fri, 1 Oct 2021 17:53:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org A164861A10 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 4CE266EE92; Fri, 1 Oct 2021 17:53:00 +0000 (UTC) Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2059.outbound.protection.outlook.com [40.107.94.59]) by gabe.freedesktop.org (Postfix) with ESMTPS id 948C16EE92; Fri, 1 Oct 2021 17:52:56 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=U1q7TCl6oy7osFxSPwhe040ECIysm52tuoq++obWwbzUoGNocD+my+uZPGJDm4HPL6Cf7vCFln7Bt+2fM9JlB0X19j3zeUjCW2kiyIw//wY08D4RUC+WsTr5pqxTqV3dTifZZZbdvoyWvxfkGSpsapUUZC8GurwZ5JFmcoZhyNgDUzRt/PU5xQIDOfbPZZCxMZE8mAeqpfFC0uE3S+rkHOc45CCSd/oIxsk4B9nTI4d2Vp7l29uSqQpwdud2sgPkexe37zE01QRkmZ5Vk3eNRGWd77GYIy3k7BuHTunnrUqIMf7tNpkpvQq6smlccyO3aWMGO4O1X+2WaO14FawZxA== 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:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=FHkDyqEPmy21hChJ8MCQtskGVs1kfkcX+9TnjmpacNA=; b=TuNd6tnJqQjwgZxu8scdWqp1wTLDCJbnn2KfOruo3ZPvMF2d/ZBSFWg2/OtYLzqSjSOxpXDhEVXsUsEKo2LV9EPVJvPVTAerEoJxlz1DH4Yi2ETu/2mToJsVL+3Z8ikca5mhFkYqIk2d2GS0QEm6UTNTwlbUZZOWEG52FWMqcFbec2e/3VwfiffWbKhyQD+lYAv6bwanumhXJ4kdPSnrz0dFF7gusaD4WyQLtwxPvIElsBSEzh3DQlGpsHIY0ATVwxyFXPHkiV969oG8DzkA0O/uNWOBKGiAFD3/rP0mQlUCtNZpuKGKMGH5V2LfTcRUtOOZEUOEeScYh/L3kKBUFg== 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=FHkDyqEPmy21hChJ8MCQtskGVs1kfkcX+9TnjmpacNA=; b=k36xRRhtCCnJtP4FDhCmhMCVCAdEbC5s/NuPPGYCN3xF3hxpzxDYEav0oU9EWLgHO1AH2XxMdHCZ9qm/tlIQbgQazejWyUhxL/Nl8VS0HQ2II64jiH2Es8FVbCbTo6ODSkEtoxpY/X6Ff1EPHyoOYNsqt0RiI6/rT1bRsnmYWkXdpwTjrYvYAO6e9ydO75RsE+2rwmKaCih+ugvubIojXKiole4qLk799m0wrWsKl79iUza7yxKWimNSJWKH0Vk2Gauzf2UKSTicyVz7T9plDtL0HB8/3m1P6E1fnA0pNgnK5zGAn8XqiiWtT6nQGemPlZAiR8Jbqde7mX6mAVwqIQ== 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 BL1PR12MB5207.namprd12.prod.outlook.com (2603:10b6:208:318::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.14; Fri, 1 Oct 2021 17:52: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.4566.019; Fri, 1 Oct 2021 17:52:54 +0000 From: Jason Gunthorpe To: David Airlie , Tony Krowiak , Alex Williamson , Christian Borntraeger , Cornelia Huck , Jonathan Corbet , 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-doc@vger.kernel.org, linux-s390@vger.kernel.org, Matthew Rosato , Peter Oberparleiter , Halil Pasic , Rodrigo Vivi , Vineeth Vijayan , Zhenyu Wang , Zhi Wang Cc: Christoph Hellwig , Christoph Hellwig Subject: [PATCH v3 05/10] vfio/ccw: Make the FSM complete and synchronize it to the mdev Date: Fri, 1 Oct 2021 14:52:46 -0300 Message-Id: <5-v3-57c1502c62fd+2190-ccw_mdev_jgg@nvidia.com> In-Reply-To: <0-v3-57c1502c62fd+2190-ccw_mdev_jgg@nvidia.com> References: X-ClientProxiedBy: BLAPR03CA0115.namprd03.prod.outlook.com (2603:10b6:208:32a::30) 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 BLAPR03CA0115.namprd03.prod.outlook.com (2603:10b6:208:32a::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.15 via Frontend Transport; Fri, 1 Oct 2021 17:52:52 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1mWMiK-00989H-4j; Fri, 01 Oct 2021 14:52:52 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 632b5ca3-7e87-400e-d51f-08d985044abc X-MS-TrafficTypeDiagnostic: BL1PR12MB5207: 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: IpQ/I9z0CVIS56lcRrXMDVK4OfqVkrcBWrc1oiYEPNreuJCF3KiEFuI2t7XSipxV5y8CzvgGbRcbZ/awfuQ1VXzgFzXpxijQduERl330iT8JdlOTpKWMWQxGP0bNhZAkDXU+MR71bgILSx12HrNZC2LyTlD93bm77OZU/V4VT6NYJOuLL3Tz+on9RmcgyP/rJmD+IDOmr55HHCJrPYs+0omKj6FQOIpRaLua/UL3WP1HxcnRDrpwW9qM4ADrNHeofAeirP2/tB12J+9wOmZ05W29i7yQ/bEy414FOf/c0B8GFhA+yYJ1FXD/f1sXFJimcec4CvXa13If2r1EJtZCF/tOl8kl8dZnUmD3VRqdVcaOSMfcfj8BxNs0oc6gmhwNsYDOqiO7ThVL+8Bi5RkR48bJFsV9k8gNJqvuJn7BmXMcKQiMwAMlNcB7B6I2u4tLLignlgZB3b9BeOCDkTxuhHZFLlHbk0trsfQZtyEToxGE6YsjiGenNfn7uKAepLkGfy0wgWt3jWPzlPsuF5oyqUsYCQqlzldsMN6uqNSPNmBW332EESDBF2vd2bpISBrT706tWdaW5phjo9yGGu+bzp1Jj3YU3DkZkkVZK3GK+AJrSeWoVpcsCip6zEoGpJK6LbG8D4yZkQydljDSAcSAEmhajlbLKut2wjCUISZgFN2fOb2WmoC/+qCK7fPLvxZoAioXRKKIkwcyKalrFxAx+/F+f1G5Cpr3Pn+ep9b2usw= 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)(66946007)(2906002)(83380400001)(66556008)(8676002)(38100700002)(66476007)(5660300002)(2616005)(508600001)(426003)(9786002)(26005)(186003)(6666004)(9746002)(54906003)(36756003)(7416002)(4326008)(110136005)(86362001)(8936002)(921005)(30864003)(316002)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: l1a64hqyoObK/fZfqhldxw2w8ihFO7pWKydW82lHfxFHQGlwIdRHmQQi8cwgIQY5cqhlMi13y4mufYotWmkKmABwPKdhD1zL7HQEdDDEE40koMipAIRh879mqQdUrh/Fed+/UY3Pw3mD+86+dXgzqIf+oSUd73X5fR2M5vLunxkqWgtP51PBz8cCxD3dN7aDXKPSssvpR2HDfhgNVaDItC/QPaK+zDfLIM0Ymszsz4RfpDBwjLg8eU9/dUBGTmrqLk9FuQnP4N+QyQwp5IWmdS32G2tdne2sL0QmCwMsDqa3V/QSRp65HtvPpaDcFONGrk8XU+vOI94+rFOLsyQJoY4MJhu0SVEtAiUW7bZeWtieXICCWE+CW7Dem3KF2QQyZziOlSf2G+TyDWXdulSxx1pUrjZoZi7JORU1ls8QxbtAYrQdgJrvSura3DG0lNdPt5jc5Vbj5lsm3N8fUqZd122zzw+ALXXvDogJh6Yt56u0h67/+9X/RZ8C1RNT/LueFtFVW1BR39zLqXDKFWesOUQPvFC77JFMHdcUztHYWnwCkugaAjcNxpALXVR+w7ZEkyWh1Mq59C+/xOvfbius/dFAM/R5e5PISv8AG6UzpAgBoRbSSLpIFbavnPxnyegY8IOHXn/J/TgeBgwgiY0Q7eAsyX9C9G6zKGu0gRWCiP+bBsab92sr8B9lBu1Seg388To4kA8KwXSO2U4kmoXLuEwqtpkBLIw72+jfanFROURUG5bC4kUCr/kZRZdnbLLr7wAERBO2/2SNoyLTnQcOGoqbzMaKmU6i/h4ykYmk8uWWur3fFadQeQUz3JbItyJVLQdcnQwqY8NOC3WMRJseZHMYXk/85J56qYETAenHJkyUUZoxYVwxhlnyoj0ITz4sgBGtTf2nWfDK02JnQ44DM2zYiwqzdAkX1RwDs5QZW1uTlHsYS4LhdQEUhgDi5zaePDNyjVkZtl2mHD13lhUeLsX4/apWp3cr28dMcBXYtp+AoeQCjp9Ql5KSBjXlFQqTk+1by0fdsLzPr9UMDAu18AB5/chH7YZuPyYxg5PkUj1EHDGcl10+7gm+WbRTpYkwkrI/fHjb59nuWWgsSSaImXnjXpT8cyLx0fp4C1SBz8yGJsrTwZXE8WeXwhkzoIYrPCxAEDnGQ/z0MpvMuBa+LZIGWDpdqSO3BSJVpaCOpsrcNkxY3miO+lXVJ8pzu1Km/k6ZxY8VGXDlQL0WbLnNI8ed5XIFtnc7DFXPzQzrwyGhr0xuJMeqRZrebcLG1dBpScSzxqNdKO1ptMywuRdSDk8JAPkOMK6C56f35qhJJUXYpMEDXSPnEKmCbJy+QyBBGbmo14uJbfAX/eYheL4oOw== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 632b5ca3-7e87-400e-d51f-08d985044abc X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Oct 2021 17:52:53.2317 (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: PZ838l19+HDm3RbyhGBFH/oHM0weVAF+E6s//+7pOP2iEFwz0V7DbunKNMhBz0w0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5207 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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 | 110 +++++++++++++++++++++++++--- drivers/s390/cio/vfio_ccw_ops.c | 49 ++++--------- drivers/s390/cio/vfio_ccw_private.h | 12 +-- 4 files changed, 125 insertions(+), 120 deletions(-) diff --git a/drivers/s390/cio/vfio_ccw_drv.c b/drivers/s390/cio/vfio_ccw_drv.c index 0407427770955d..769edbbd164313 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 void 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); @@ -280,7 +223,10 @@ static void 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); } /** @@ -307,16 +253,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..64ff1a5e3cb475 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,121 @@ 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 int flush_sch(struct vfio_ccw_private *private) +{ + struct subchannel *sch = private->sch; + DECLARE_COMPLETION_ONSTACK(completion); + int iretry, ret = 0; + + 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); + return ret; + } + + /* + * 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); + return ret; +} + +static void fsm_close(struct vfio_ccw_private *private, + enum vfio_ccw_event event) +{ + struct subchannel *sch = private->sch; + int ret; + + spin_lock_irq(sch->lock); + if (!sch->schib.pmcw.ena) + goto err_unlock; + ret = cio_disable_subchannel(sch); + if (ret == -EBUSY) + ret = flush_sch(private); + 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_OPEN] = fsm_nop, + [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 d8589afac272f1..bd4d08afa3e4dc 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 Fri Oct 1 17:52: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: 12531347 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D836EC433EF for ; Fri, 1 Oct 2021 17:53: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 A436461ABB for ; Fri, 1 Oct 2021 17:53:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org A436461ABB 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 8F8AD6EEBD; Fri, 1 Oct 2021 17:53:03 +0000 (UTC) Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2059.outbound.protection.outlook.com [40.107.94.59]) by gabe.freedesktop.org (Postfix) with ESMTPS id 294676EE91; Fri, 1 Oct 2021 17:52:57 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cogXvKqXFA1sEFHEzgpUDot76lctGXejklMwU6GuryebrA+3we3QRU4325mfePbu4FLYDPiQsTKZIg9qYeKm4K8Kcjc4ls3SDofcwH9WMz1RlbA4LjebVTJL0RJ2G51hQF/SG94f0P7/0UArDLFyMrfyGpRvgy8W1H3wVgPIqtVRowswqa6hJUv7JilNtnCuY7uzUl8XxvKAeuqmyHWICqmCCq1vuQQp5WdG7NEA+qGXspHLPaHGGawLi2OB0ugXHlyiigsww/EnXtQZe0qAg0LrSGouhg/bByc0RvewdiDVkhDbsr3v7pav0CruAJlLRbzbdc13s9cBhEAb5fbXdQ== 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:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=CsGMr5LHVaWbM8ZmJ+WXqcS4MozvEdilF4vXkB3vl1M=; b=GE6ZUV1OTnpSZ7iW2+IAUuuMXvwvLWcagv2Bl8SaDUUyZDDmpeRveSaaOOzp9f6LQc2leytRmiiZZ7ua2EqXyEUMjaAURfg9R9uOP3o4xGKQik30s1gLpD5GBSUsMSulsrLN4owVm4VHhd7hd8GQG3ML0Qr4FZ5sStbos2YH6I0hNwKaJbWYTMFbC/SX4PKUsCTkC5ppsJpVDtubI9lajp3UXcqI0wnzNFxALIOOlLq52Z+piSa81tFdorCMQLHjdixqn+mu4Qejj/VkjwwEARYAQQxjnLM9X6DixSWi2DL8piZojhXkpS5jOpBc9FeIoD7dZ+cdy2fmt+ZCiomziA== 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=CsGMr5LHVaWbM8ZmJ+WXqcS4MozvEdilF4vXkB3vl1M=; b=WOSbXDXeoZGifHofADBD71iZiII8eTU+ZkpYfd+PH/+0oRhWqY9DBc706qgXd0C3FUSYEnNfKiS0L/u0BfymSAWuXs7qB+6vTHLq+tCG+O5yV3nGNC76jKZOr8+YL61o15sa1zeTGxrSTjdUzyKaj1zLAGfQIvhnvPdQimln9FycyAyCJdvcUhuBMCsKOJzJvNTNmP7FO4cNejQPt5bCaWotIFYaMd01jHTLqx295OFb3vvnxg36BiMbOPt0D4UYj944vkW1fRywpv8FfGUa0orqqYZvJy4n0nbL3h6ujnyUR/Eh1Xn6ifpQDijY6BniVtTR4eCA2/kx/Jaem5Kafw== 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 BL1PR12MB5207.namprd12.prod.outlook.com (2603:10b6:208:318::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.14; Fri, 1 Oct 2021 17:52:55 +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.4566.019; Fri, 1 Oct 2021 17:52:55 +0000 From: Jason Gunthorpe To: David Airlie , Tony Krowiak , Alex Williamson , Christian Borntraeger , Cornelia Huck , Jonathan Corbet , 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-doc@vger.kernel.org, linux-s390@vger.kernel.org, Matthew Rosato , Peter Oberparleiter , Halil Pasic , Rodrigo Vivi , Vineeth Vijayan , Zhenyu Wang , Zhi Wang Cc: Christoph Hellwig , Christoph Hellwig Subject: [PATCH v3 06/10] vfio/mdev: Consolidate all the device_api sysfs into the core code Date: Fri, 1 Oct 2021 14:52:47 -0300 Message-Id: <6-v3-57c1502c62fd+2190-ccw_mdev_jgg@nvidia.com> In-Reply-To: <0-v3-57c1502c62fd+2190-ccw_mdev_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR07CA0005.namprd07.prod.outlook.com (2603:10b6:208:1a0::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 MN2PR07CA0005.namprd07.prod.outlook.com (2603:10b6:208:1a0::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.20 via Frontend Transport; Fri, 1 Oct 2021 17:52:53 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1mWMiK-00989K-68; Fri, 01 Oct 2021 14:52:52 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 18be6b34-073a-403e-bd5c-08d985044af4 X-MS-TrafficTypeDiagnostic: BL1PR12MB5207: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:854; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2RWc/Uzg0cYe9KgWWpP/+oPyZdcCCwEYlncETgjjttAQ9CRmGJBEV8Ckovgxs9ZKQQKuHz8H307T+ffAEermH6KRdAl4XyUp0gYZApn7QnIWceinJMhTzL9/uv9g5PRSVge7RCzCYHjRQK/o3zbxhpS6KlBlYsVXWKnf5WlxtoRrYNdoQGYciqAympmO7LBY4J3hOafP0fcxnw6KOl85Qr84LgIoFo4B0YD3Lre2SVZrgVuJvqwmRTBRpYpuH16ihrccK+AYA8lic9IR8cRNeWj5/SgHdp9gEBeETOQhXg9b7Mr1BqAB3Qh8kR7PmwdDwWyQrGewojh4/ef1OusQvO+RyC6yQ+W2WJB6PYFfSodKrP9O214cqH8fiSI/04u65pX4gn4Cj8VkRx2s7cYPig8Xf2q0V2yg8HYqKHW9H0h5mVo7AQdDbb+rktLagTMTIqeVnokln2yBg1whAw6P7QXcWB6B8okVyJjMoCoVTZVKMuXohl+k1w+cRX4JJSG+uYnNpo1WO7ZhWzRhA3Vsw2OTdM1c/hKRv8TzMJWiIbBkKjVPGkjTnd6UGRfht71iYy2gNLwZ0iqcWZWEsZtXT+jNu0fwXjNHsnzEIjaCPO2bIEUc223tsteE6yGSUFx3BT//r61zbLz0hc1KxhQ2Gt82B7KfdRn4WKnsIJ/yqfxL3xk3cRCROqF2kd3pwkc6rne9QGPBiZtX4SWGBMdtDA== 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)(66946007)(2906002)(83380400001)(66556008)(8676002)(38100700002)(66476007)(5660300002)(2616005)(508600001)(426003)(9786002)(26005)(186003)(6666004)(9746002)(54906003)(36756003)(7416002)(4326008)(110136005)(86362001)(8936002)(921005)(30864003)(316002)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: YWuc43/RDIfHx3txlmFMNdITSziUNxaIJ0cPc9sXnfdWyb0JJqdzbLOclncK65w57JpTIIoT6zLq4sRK/4kiHKpCIOyrQGKcfGfdTsGdc6ajYiecxvQCrlgkKhDRB45OIZeGVeidtG/IJT9VCeRJaJeikHRVWVtbc+Cgy9NaU3u6988yTGHhxWqFFxvueuBHEB1oMgZFAqJfyXle/gu9OkLT7+aYy3T2QFH+VAFSrQ2Uwlad3U8ePd3BumfJQmdIinieNj00HFiMkBNMZlLhpGrCKr8UzTePfBZm62gYhB3SB+72Q1xPAtSHppU49eI6ZuAmeFoL64kg+4CJXRYLUS+U/K+5EyAt+e/ilQmjpRkIZE6FhOL/vGHWPDxRbZvHz3H5YKAYsoY/vBxoFwFisSBbbtCyg4PaqcKFVgnXDp8ZGRAF/ZxIk0XrXOV+llPhjhfcg41Q89CF++ERutMB3glTtl7PlBOor6r0R3p7yyyuHO4EXER2aThUZX28hTXOKFFMdRHceAbGiBGIFiG7cM9qgOykQMPQz18x19TVwifrghTUfOZm+/dAgqjPa2nE5hO6XdIEFIYSD6PitNdHFrYpk/ckkc4pKKFFgEbgSD0Ek1knX5ryaHUVeWudE7AEFNBl1ehprbsAWKZ7XlcaDVLMJHN68387SYwAz285Yc5kAPu1ZwRSJWIcm5m2a0RjKLM5N5q1TETUBTyLtXf6ZykHd4U6999WpeJfOAhKz8orhkLU1/gpCw27YuMmJ7qHKRdaQjOlCDKfcp2QDOMuejOP4LFSedYtMJWC2/BB2h/l+7D/jDai1T1AxYH/RUTxygGsQMkc/ae37wPMBA8bxTfegBWXG2mCDSDKE0LNpYuHWQ8MmbbRD5nobePd/+rqwsNg+qXqGOiYNxsGF6/o3fHXuHaLEwOOvg4COqIoKVXpBDmRzDJtcJ1OYllMcgzq1cjyGpOJ3pRvIlzyasAv26+uYTfxu7aKZOc5GMWUIrTNhfag+p6YhoqYXAFhixgqtnC962vUnLiQMQj845PcAPRDgyUiKczDotpVdGdAw6qplBmbHo0REeuK18YsDE2eeV5ucy90TsUfwvtCxJcQeUZyUwPX0o8xLNN1GaigB3n1eHdnvQY2vpTzOV9+UahM+FghtoDtDKVIu3GY3yRQss+iGxC5P5yOpR88ZxfvGXQe5vKPpXsgak4LtZB0vlQ6dIoP82eoEvFOtznzWJ0NCddc2XW0gqhURK4RWDVC3hXs6LgHxF+wCuayBH71snb0uBlUk0AxH8fRqfZkybg/o5jIVUOYxRsbqRJbJjUnfdanb5EacxCaORoiax6oXtE9 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 18be6b34-073a-403e-bd5c-08d985044af4 X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Oct 2021 17:52:53.6310 (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: 9DE58mJWO2JSkaZbcwPfL9QNZQBv5w+O2Q2CKa/2CjGBO3f3YKRwKnm+1RL2ae99 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5207 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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 --- .../driver-api/vfio-mediated-device.rst | 4 ++- 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 +------ 10 files changed, 36 insertions(+), 59 deletions(-) diff --git a/Documentation/driver-api/vfio-mediated-device.rst b/Documentation/driver-api/vfio-mediated-device.rst index 9f26079cacae35..f410a1cd98bb06 100644 --- a/Documentation/driver-api/vfio-mediated-device.rst +++ b/Documentation/driver-api/vfio-mediated-device.rst @@ -137,6 +137,7 @@ The structures in the mdev_parent_ops structure are as follows: * mdev_attr_groups: attributes of the mediated device * supported_config: attributes to define supported configurations * device_driver: device driver to bind for mediated device instances +* device_api: String to pass through the sysfs file below The mdev_parent_ops also still has various functions pointers. Theses exist for historical reasons only and shall not be used for new drivers. @@ -225,7 +226,8 @@ Directories and files under the sysfs for Each Physical Device * device_api This attribute should show which device API is being created, for example, - "vfio-pci" for a PCI device. + "vfio-pci" for a PCI device. The core code maintins this sysfs using the + device_api member of mdev_parent_ops. * available_instances 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 bd4d08afa3e4dc..a7f642be9c8898 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 2341425f69675a..f80246b30aff30 100644 --- a/drivers/s390/crypto/vfio_ap_ops.c +++ b/drivers/s390/crypto/vfio_ap_ops.c @@ -401,17 +401,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, }; @@ -1387,6 +1379,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 15d03f6532d073..8a5fc5d54f9b76 100644 --- a/include/linux/mdev.h +++ b/include/linux/mdev.h @@ -36,6 +36,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 @@ -80,6 +81,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; @@ -108,11 +110,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 cd41bec5fdeb39..1c5b51390b3a87 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 fe5d43e797b6d3..402a7ebe656371 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 a0e1a469bd47af..5dc1b6a4c02cbc 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 Fri Oct 1 17:52: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: 12531345 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19C53C433F5 for ; Fri, 1 Oct 2021 17:53:32 +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 DD2EC61A8E for ; Fri, 1 Oct 2021 17:53:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org DD2EC61A8E 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 AE3AF6EEAA; Fri, 1 Oct 2021 17:53:01 +0000 (UTC) Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2059.outbound.protection.outlook.com [40.107.94.59]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9F0F16EE8E; Fri, 1 Oct 2021 17:52:57 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eKXmE51OEucY70dQE6XTSadOJgnbwo20CAeB1IInSRAxOvYHpbUDNimqqmyZQrtfRSqnPrvFq0RHGIZf9LYtdiO7XVXUiGxcVeXK+21Wrd/hJJnlsfHSO3ncXgwF85IajcFhVUHSsE5OWll6AfhWNQlXXzMXuLPSWQiLmSuzi9EiDsEAqBu8nze7hZmsN9xJCys8sT0yOFXii9KJwvQ8gHR4/AtFNYmKsaeYgAzT8wTt8jHTZKes4keLvLS7mML9qLBrPKtifVNq+YgH/ksW36CZ5TGz88k2QF97JkWmHtsX034DTUcvSD3Gn2ReBloO8l59rxKtZtuM/pOKo2TIGA== 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:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=DCXsO4GSdk6PAZWLTIFUG529WdD+pJohNewSmaMy2Po=; b=A/gTIIndL/CO1NN5eMzfnRWffuGCJvSUyJXHANta2nsX51GkgbaNynbwuARXKcfaMj+hvOrD0iGRoC52Js6Zr/LBX1pGehfGNCjuwjq1rgH1/s4tgQhuoYuwHq4H+aP89dYalGdVWAWxlKKHi0H+1gxdeL34L5iAoDBs3Q8sUq9XJhpssItzgNc9D3WA0s4EDi+AhzLbxz/aPKDWxWRUV1O196Nj7XMqFLn0qsaE0UUuaW+ODJ483df3oQ8riCiLTojHPZXVW32k7dbkvy2Fm9WUWFXzYIsMF+3xKeaa3+7YWIelzUo75wckgd1ARqYnuJPQEFZXKnKDg4/ce7j96w== 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=DCXsO4GSdk6PAZWLTIFUG529WdD+pJohNewSmaMy2Po=; b=Z37IcHP/jUl5xXFxmlJSEbU6HQvlbU/Z51lldj4mrO2dtgxgSKcv+T93zMcMTZNTzy6NIZW4mlxdGj18gf2KDsCC0Ppyc47nOQGrfQdDGzF3ky5RJ9DT9uASueNSwZ/eXSp1AOFEhIXsBAfzv/tiB/oWGUGdW6DLT7lZ5yyN1J9Kep2DfvfzrLBrOWMePr2RduA+AgNhsn5voEtNSba8CIr4UVT9z8V8Zvp/sFtNJHBxHANLdffO45eW41pVQ2OfkmHXYeoAvpwRqeH/lXUtJ23zjobbWvAYX3r2as4tb2EVrxHh2kPRImJyp1vXRuNeiIHKeNWNeAK3a6nktm3+8g== 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 BL1PR12MB5207.namprd12.prod.outlook.com (2603:10b6:208:318::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.14; Fri, 1 Oct 2021 17:52:56 +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.4566.019; Fri, 1 Oct 2021 17:52:56 +0000 From: Jason Gunthorpe To: David Airlie , Tony Krowiak , Alex Williamson , Christian Borntraeger , Cornelia Huck , Jonathan Corbet , 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-doc@vger.kernel.org, linux-s390@vger.kernel.org, Matthew Rosato , Peter Oberparleiter , Halil Pasic , Rodrigo Vivi , Vineeth Vijayan , Zhenyu Wang , Zhi Wang Cc: Christoph Hellwig , Christoph Hellwig Subject: [PATCH v3 07/10] vfio/mdev: Add mdev available instance checking to the core Date: Fri, 1 Oct 2021 14:52:48 -0300 Message-Id: <7-v3-57c1502c62fd+2190-ccw_mdev_jgg@nvidia.com> In-Reply-To: <0-v3-57c1502c62fd+2190-ccw_mdev_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR07CA0022.namprd07.prod.outlook.com (2603:10b6:208:1a0::32) 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 MN2PR07CA0022.namprd07.prod.outlook.com (2603:10b6:208:1a0::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.13 via Frontend Transport; Fri, 1 Oct 2021 17:52:53 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1mWMiK-00989P-7L; Fri, 01 Oct 2021 14:52:52 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1726f3fe-189c-408a-219e-08d985044b43 X-MS-TrafficTypeDiagnostic: BL1PR12MB5207: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:356; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BazDlNGmlp3/Ku1oBKM4z9SX+x+PfSutY58I3bHrDCV4+qZtwyJAFkZm868WLoZu+t7/XSpX+5uwNpVMkl+bQKl5hxdFNQClrdSP6/Iabq6bmNmzUBmDNSyyfAXJlC/ePwE70RKGkCQUIHvervOc2JaYsvSQ8VpEs3l1+ptE2+7TNpnfLWr7qWLATDXtKe4cGi0tg5xibOXLIi0diGcA3F/bR50B4czXIhXRzXx7J5gP+ZjVbTl2K+WuY6/d1K5oJZD/f04yWdcwNRYam8E0J5053scjt854KtVJyel3fPoID9opjR2aqtPv1H6SLzGlbtGf+Vuwms2Q8H8xaX8oGO5FT/qcOX/qXMOM42VT8IzSiXKGGyinWVyf5qopJ1j93Sdb5RZ5C/c4/8CZERHRzwlzc4Rhs/5OWEyMCUacXJ3K634TfuPBKrDSgS3mn0KxhUcO8SKxmkX35aNjer8P8xbsmGE/+iI2bmLAfu4Y+JeHNNhRhAaOGTHpx1BTh+VXI4zwkTgBlcVQuz/+wK8eEWZ6tXhiouUwb4yqux58pf2vFUiBQqOIUKIA/HDkSxuGiR4Rvdd6PPfxifXlVZgPxy4n4ODLvDDBssP5oyU6A/OxFtsPRlhNCJke4t+aTQUsJsg6La0r3iMjkBfseBy4HYp+JvIYciFbVVJU3mHzOhLVjUCafFyiegMjTqzUQLEW5KvR2Cer5HfjozXTwAF5m1wFmTsirK2X/JL3hq4gX5k= 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)(66946007)(2906002)(83380400001)(66556008)(8676002)(38100700002)(66476007)(5660300002)(2616005)(508600001)(426003)(9786002)(26005)(186003)(6666004)(9746002)(54906003)(36756003)(7416002)(4326008)(110136005)(86362001)(8936002)(921005)(30864003)(316002)(131093003)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: olS/ANbK1wIhj2D+DoKU0ohvU6yLublMACkdNa3VjiYdLGXPPv5O0NiF9jSGxgSd9OSaHYDVbP6mF0ZiAzyWg2zYHInqVFCaQeBbFT/o5r5ayL90Gyz/FYQNK1gr10iBi9Ms0XSy+9W3QTAYOT5oux97IWdV3hDEPvnuGLbvivrLBL8QZciunTL4pb8GCOQjkYf0BRLrJ7jPl/MguTAcPrDI+2MK/cGQI/lpfPTK4aUigfpnCo6MBEer4QtevjeFTq91AUPFXA6sebDcEt89nA80e5f+7UTjDT2V9gZm1Wd4SdDyv/ZE+nWGLi/6/Cbi39bJeEVaYqiKRwdDiJYs3aUDzImAaiikawX2ahzrJ7r/Gnc92TEWenTpfenIW5ahNFcEjANKPz43GihhZK6ArtCGhDylgTvDmFPnNuSQsSl5oj7Muq9oRKwAVo1zQgmellVYwzI/EQnPLg6docp7j1P8K2ytWXLOqhSs9I6xKsCq8qJYdS/q8UN1AY2OB2wDwKB5VpuPMnNf4ARZhq1pimHORXq9qbfpn71uTtECH7d1qZBaRv+BoYe8AAtmGkNLIK3yHA8PmkCVE/ZLhwrptOUnrbr4X5jnKuBNUhALp40QFILj0TUX0dtqEM3GcLAezFe14COJJVMtj4VyH9kUZhV2W7ZNIEu18/0Dv4Gn+4qlbIl6eRhhkvs9Zr0f9tCv+4BmF92FotrI+wERxFPFkvlPrJeden3qvUemO+VDdl9efJFcdTtmHKgb4wqImlH7c4jvEsU906raIuFkX8hptLY4nQA6vNJ1tf28vhDAluyauO9Cb2q7T3H2XYv+U2tszZ9RuGFh8a+yo8EivJwOkwqveI8bCGJQnyFyLxRR2sz3SCreuHq6kNJLxwdPRkEllO1RDNuvnDp3ej9Qfyugs1pW0p/e87ROTXWpeX0f9R112y8PsYerUGmqESF933DDM4PvYXMezjVdnWgR0+TKXrLM9z9zCB5HX96JHeUzjFgHklkKtMPBFK6JFQe9FIY/MRxqicqy7mCiCArPaGTfbk1QlOS6CEdnLhgH0Kv9FEflW0iWX7SEegxccoJEPTUldQnIH/vIJj1Jdhm0d74LqJHDpM9e7/7QrtKM3SJfz3S/XONaGo6JvkxXmVqZ7+RKkVm98jeRdBA3sKQ+QMakUZB85Rq3lOVoQJibLoJaBBjs35vqhG8gyjzRtF4pJcdukisrSidxNjPZuv72ONtgKTJ5IvRvLduo+FCU8zE9gHPZfWRvvhCqJV0ppfnm2FQCIg8z3eQFNXiGEfFrDYYmy+sHdX1JuNK4qE0UZzdX1k05En9a/O0AAUt3qVYPttg2 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1726f3fe-189c-408a-219e-08d985044b43 X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Oct 2021 17:52:54.0840 (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: LT5WgRo5U8/Mme1QwUSEEWb9/7jqDaW5ex4H+mdIaYh6F4oZ7eml4fGLXi0QyPdJ X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5207 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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. Reviewed-by: Christoph Hellwig Signed-off-by: Jason Gunthorpe --- .../driver-api/vfio-mediated-device.rst | 4 +- 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 +++-------- 11 files changed, 76 insertions(+), 65 deletions(-) diff --git a/Documentation/driver-api/vfio-mediated-device.rst b/Documentation/driver-api/vfio-mediated-device.rst index f410a1cd98bb06..a4f7f1362fa8a5 100644 --- a/Documentation/driver-api/vfio-mediated-device.rst +++ b/Documentation/driver-api/vfio-mediated-device.rst @@ -106,6 +106,7 @@ structure to represent a mediated device's 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); }; A mediated bus driver for mdev should use this structure in the function calls @@ -232,7 +233,8 @@ Directories and files under the sysfs for Each Physical Device * available_instances This attribute should show the number of devices of type that can be - created. + created. Drivers can supply a get_available() function pointer to have the + core code create and maintain this sysfs automatically. * [device] diff --git a/drivers/s390/cio/vfio_ccw_drv.c b/drivers/s390/cio/vfio_ccw_drv.c index 769edbbd164313..df9e1e265bca1a 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 a7f642be9c8898..97df5c711736c4 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_emulated_iommu_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 f80246b30aff30..b6eaee24f798a8 100644 --- a/drivers/s390/crypto/vfio_ap_ops.c +++ b/drivers/s390/crypto/vfio_ap_ops.c @@ -333,14 +333,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); @@ -363,8 +358,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; } @@ -380,7 +373,6 @@ static void vfio_ap_mdev_remove(struct mdev_device *mdev) mutex_unlock(&matrix_dev->lock); vfio_uninit_group_dev(&matrix_mdev->vdev); kfree(matrix_mdev); - atomic_inc(&matrix_dev->available_instances); } static ssize_t name_show(struct mdev_type *mtype, @@ -391,20 +383,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, }; @@ -1359,6 +1339,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, @@ -1374,6 +1359,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 = { @@ -1387,8 +1373,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..bb27ca0db948ca 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 && 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 8a5fc5d54f9b76..7cadbbac7de9d0 100644 --- a/include/linux/mdev.h +++ b/include/linux/mdev.h @@ -120,12 +120,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 402a7ebe656371..d7da6ed3565705 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_emulated_iommu_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 Fri Oct 1 17:52: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: 12531337 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BAF98C433F5 for ; Fri, 1 Oct 2021 17:53:19 +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 8A14561ABF for ; Fri, 1 Oct 2021 17:53:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 8A14561ABF 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 2CA416EE9A; Fri, 1 Oct 2021 17:52:58 +0000 (UTC) Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2059.outbound.protection.outlook.com [40.107.94.59]) by gabe.freedesktop.org (Postfix) with ESMTPS id BAB7D6EE94; Fri, 1 Oct 2021 17:52:56 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=K6Ipy6g2Ie+f6Ai/fFNvknLR6/JkJvTNGWNdcup+9kcHUWs3FSCbqztUkNEixgpOpaKcgoBCpbAOj7KTFMUJsfyTjQ8H3M1tqipIrz6QZCZtVrW5x7Uv05VsgyLZBcOJXMROQvFu7brysVTIiBI0wNqxd1JV8VKmTokqc4US4D4uUrrWkHO7di3SVC5tIpCGeTH8kuQbq0jqZgLuwALbAymgYm7s/84s8E19a5BFaBkgHyHq/O1n8vIYl2YhRTIBVki2cBe0OIO5SH44f+aEMOI28TLKBK0irRwOUhAieDdjBOr0U6pcQtYMNUNI1T7Iru2m/TDLrYfYBaD+KSC8Fg== 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:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=PnU/Ra9GYlpNTkD0q2RzRENCFZ4Unu7Hu4BQ42Gp1ls=; b=LQsB18vOGQXMuCQGRkAW2l9X2q3WjX1qp9c4Z4bNjIHrAsI2tt7cDZB6ljfXw5jCnS/nINDRgcuByHEkkyA+R98xSRTvp7FHb6Neh55omGh92v9ZFEiI7oQoSrKbNTFvp0h1c1UDoNsJhCVukdn/OLL15HNdlkbzUjpkukUSiala4BFStdOjOWymUUtoyRmENUHZTeV9Lq1m8OIALhOngPxKVXZvZk63OvSof3y11PxQM+/DHW5CxOwxTt5oJ8/gsA5roRHwsfFNqOgTSvVXYrsdPaV3t32ny/fAT7yYVVk2yo/LeJIrGF2zGGTPQe0GxhIPHl+OvDdwBzg7j01D1g== 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=PnU/Ra9GYlpNTkD0q2RzRENCFZ4Unu7Hu4BQ42Gp1ls=; b=Q6UbFWLX+0StiTPzPXQ9JBj8jHjB3vKa9xfj382WVLOuSwZlgHfJ4y9Pd6g212C3cpQ3s2eHmHBKLXJFFysMFB4TlEME8f8kcbFghZaYdYUzcnVg+8GWS4EhjQpKBEh0V4JFid8quLAkHW2FrqvjeNemljxaLdZd7mrPza9i56RDmoXyWOfyqKPyPwWrmTroyigLJFWAZ3iCeSlyUSX0LOTb6WRcjleSDY1xweWs3C5SCNVG20X+ja74imWsHTZIEBX5wiHWRBppA+1+GHzMSd0fZOTu2rMKh3MVb+mDb8Z5TEUrNWS28UlMfP6niys13Yg3xykCIN6vM9JEhQlCXA== 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 BL1PR12MB5207.namprd12.prod.outlook.com (2603:10b6:208:318::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.14; Fri, 1 Oct 2021 17:52: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.4566.019; Fri, 1 Oct 2021 17:52:54 +0000 From: Jason Gunthorpe To: David Airlie , Tony Krowiak , Alex Williamson , Christian Borntraeger , Cornelia Huck , Jonathan Corbet , 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-doc@vger.kernel.org, linux-s390@vger.kernel.org, Matthew Rosato , Peter Oberparleiter , Halil Pasic , Rodrigo Vivi , Vineeth Vijayan , Zhenyu Wang , Zhi Wang Cc: Christoph Hellwig , Christoph Hellwig Subject: [PATCH v3 08/10] vfio/ccw: Remove private->mdev Date: Fri, 1 Oct 2021 14:52:49 -0300 Message-Id: <8-v3-57c1502c62fd+2190-ccw_mdev_jgg@nvidia.com> In-Reply-To: <0-v3-57c1502c62fd+2190-ccw_mdev_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR19CA0037.namprd19.prod.outlook.com (2603:10b6:208:19b::14) 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 MN2PR19CA0037.namprd19.prod.outlook.com (2603:10b6:208:19b::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.14 via Frontend Transport; Fri, 1 Oct 2021 17:52:53 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1mWMiK-00989T-8q; Fri, 01 Oct 2021 14:52:52 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1285b966-72f5-41c3-9583-08d985044adc X-MS-TrafficTypeDiagnostic: BL1PR12MB5207: 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: 0RUFtOnw+nb7NwoEm/ZOGP2fbmeVa81IqTLoBjWl//6ujYodfMYklukz3zxNQTa279UudTCJqB6KydWVGXevJJCtLrvEBgsQj59zMfHEmLusm+ML8DppSuTEjxygFzk3oSfAMKChEtG8RAu+GQMi+OUfMTuoJbMd9PKowtJFw4RLWl15NQXou3/waJMrlwCf8wtx4H55ZcCkdolHlR47NAY4oDHLLCQGWLKaWNbRBsQUNHJN772asyEedD88rQCf2wuy7xKtohW8NNaTgzvP0yNS/b+I/TDvz2aAigUtfAOOr/h8SdHZu23FaKxnQDJN2XdfSmUPK8sZdL3c6sobDpy/dg6HuVGEoKIKzMF8GJM9rZ71macIBU9sl5U1K0AlQnx6V9vXQC8GWaxJXdQT/Kn58RT0g7RuVfdIj0/3584EQxnnPH/1LUlINxOoAoKdIFK8QaqWXab6R/MC7C016kPS4tlWojBhmLnD3Zv/J49CSjVqpNRZKqOG2+5iJkNJM6VXEE2S13WRkXy8lQmOK1OeofVAMyat5TCICAqX5NG+CdmQaf3j2A+NSb1wu5pJG7aIPx9YKuWR1CStVG7osOzVJD7hwy5xvzO7LgiMsFx3IF6/lqPAi9UvD1Sk+6P93RRN+LO8xrj5ctuCb8EIXiAVxMq2cFD7CYcBoIee6P6tZBraJhogYktPlhZfeIi8P0qPfsJb7B9hjBpmqGCUSw== 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)(66946007)(2906002)(83380400001)(66556008)(8676002)(38100700002)(66476007)(5660300002)(2616005)(508600001)(426003)(9786002)(26005)(186003)(6666004)(9746002)(54906003)(36756003)(7416002)(4326008)(110136005)(86362001)(8936002)(921005)(316002)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: HTNy42KQ1GtmeJ3YXsJTZtb21vpiP8v+KozxBmjzIz2boHSBYiuyN2G253MTGuaJZGD8gQ2hnZQ1XBmj631hRerwuN+OrLGMrfSrABcoaR5ZqwldllFzdNgczLfMaEQQTbYJ+f+2FThOrgGvVk3Exck8cK7pShOpoqYcm+1rEWjEnOjppswgriA4tEvunaRlbG1gdK3nUN8FrMlpF91dPx4nyXSw6caj2UgXtqbCIbbYnTahAJWKYNQ9wSDdbsbQ68gfM1KSJh5FULK46uWne+qPGUr/KKykn9iuZf0R0cXoVMoD/Zy+oz7aJoxIdzO31QqqI4v8KndDmDtYPNw/pcyKOhgwgMgxk+aRBKTkxHP9VFpZjIVSa4bDsgvydxX0XYqel9h0sUsDx1gUzntd9WNMvUylET6qOChZu1DBYLiYB4C8NcGKEbsO7kHTGvPOzvqk7/zcHdp3lCynzQU7Z/RtbptHz6MWHSvJRF0qHlTOakJDO1hKUWoq45yIcWCpTxhiHrJPO1Zztf2tzXyUueYDX8VXyTVoRQBI9GMZVV5ag/mURm8TguB7qO4isSL5qJC6f8LsZi914oI5hu9xeoLZYekGZlFe/3vyJGVNQPPuiouDzKgBO+EcPF/00jUgf6hjHnZIQPJxi8gzycyCyVRZdR5hoql8SyFDA0w5Gvu8KsMSWu4skcEqHYnXZdsQ6EuuJvnPPDT2r7G9Wpri6tIiUqWp7jvSI2iLF0RjIKq7uhq4CrfBekDWplkG1Yjvh8KrgmMpGmERoTwV6ZOy+IgzPVu8VV3wJYABFL0CQVLyyoaEc1BzfHwMdVQZ6/VhHcBh3330GEhLvPEuKyKh8qTx4Y0rPWJLFmc8j7XaRWmDzat8j/VuIvseYcbhK17HY5CDlS6uO5XRH0hf9D8rYstiXcGZ/ZtTcQHlVl6lzZd762fPnQTfJY8chGOx82NTc0n4xrwW8yRz8JpfKXoc4KZxLn8XpgZ7zXk3+Zm0U5SVwQp20JETUpo4ZyzrQGytKtg7n4e8HfHbEh1bFCK1ZFqVMUadZ++KF8BdDI13/wnTiA1H/Ta7k3XX+PKGoYN+k6O5C0OTFM+uBhULm2lNX3Kd7jwTCtzp8nlNw6yMVn7xIjno77Q24qHVyc29bYogWxUn8rC2JfxSWFARSXbJJSSz3Htx4oHUCLRWrBNTD7J7WkhBMFXDTL6WuKnEsErLB4CJjb27x/Ii59S5t22Ahxnzn8a13HQDQJkIHmi46YKDRRMQO2y+AXdO53T4TyLbaGrjwXAYAl4C6JZLIk9WC5YmFGDPbjycotlD5dqPv+LH3jygvLjsj8uTRJe3DXJP X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1285b966-72f5-41c3-9583-08d985044adc X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Oct 2021 17:52:53.4050 (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: PNf28XyIH9gX4nywHDFg7Ww3y8NODWZd3lxd4q/hf129IiTygCfD/K1JLV8eYRE3 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5207 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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 df9e1e265bca1a..18ad047811d111 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) @@ -302,8 +302,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 64ff1a5e3cb475..0d4d4f425befac 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 97df5c711736c4..68aae25a0a4be0 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_emulated_iommu_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 7cadbbac7de9d0..0ce1bb3dabd00c 100644 --- a/include/linux/mdev.h +++ b/include/linux/mdev.h @@ -138,10 +138,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 Fri Oct 1 17:52:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12531351 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 69255C433FE for ; Fri, 1 Oct 2021 17:53:39 +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 39CA561ABE for ; Fri, 1 Oct 2021 17:53:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 39CA561ABE 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 BD5626EF33; Fri, 1 Oct 2021 17:53:04 +0000 (UTC) Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2059.outbound.protection.outlook.com [40.107.94.59]) by gabe.freedesktop.org (Postfix) with ESMTPS id C6DB86EE91; Fri, 1 Oct 2021 17:52:57 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UAN3eEvmouxom6sBnP1fYmZCYrFj5CXX51Df9aV1CqiorxxAQ5poalBZ9az30DwgxQQrux6qX1vigvyExOVxHVRZNpCv8h93+iEOqkKIaodyugfJSSScFah+BfUGdD5DpZrnZWR/Sp5gdvJL/iUEMBv8e3Rcn2NzLevl6oBHEkMhhibpcIa/XnKd4ZQsF/ovrwXvmMBLBdWcNjQMr8DniaunQn9ElgeYJhrNUj2kPk9QWRRphwC2islla6I8usLRWqOgOZfVlHaWXKmKjp1yTkIp8FBZjhldSH60LGwJAa0BWz22s5g9s539L5mY7j+f8pQzLVunKpXOs91U314HkQ== 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:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=nq9RsKauE4liZ2b8voAMWsI1xnwsEPP5+8gl3p4Fi2k=; b=ce/9io+9FrhonIY/PBYa88dFy4B/8dglETDsHF5dUNt7ClZ1pSoMv602YcZmJ/ls17tHycQA29L11zrQR6AnHdTol2w3BlFVYRyxP8qLTpNYBwC0TkYdupH8nyojp3Fr/GykY44qCCHv0C/ulqYoFk2uSKUEjjnglHqmHvYPpXhxgg3H6JMcSepuRgjykxd26u0OpD/RQPhVL2L2ec3i53/M2viQyLsIUh/gD+4bYGKhfI/nsmuZsPAKawAyB46KOVaoYvbzhYhM9UjHfPHgjz2BapIQLXHh407ppWvN+Xik6UPShiAakLap/j5xpjYBp7MaA/75YP2IkBgtoR+CFw== 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=nq9RsKauE4liZ2b8voAMWsI1xnwsEPP5+8gl3p4Fi2k=; b=Wx5v6D+BZN2BuVynu2WvBzIZm899Tfmm13TbLDh7MIJLjsbSKCazo0aMsCmXS59KbicnHe/LNpWanBe0LF7JRCiZdeH0Gx6UiX5J8d9w02nwp0ERwR8WHxKsIzIRZOtiCSm4vSZ6Tdy+1mD93EFgFxWQMH9OibEJhGTEe3e+CZeTO+j/MSOmbyI8/Y9ET3aoLWY7s5hETwgRvsup8ZQ7xksEMR7S4B89KEn/04CTtdfUOajTBPtL+Rr2odZE5Xy8H2hKtqg+G0FBlt78u99JGyL1x2mtIRLz+9imxkRWuNLFNsUcyYlCd9ukhnwKfv7nDOrIey6m/oM9BGgnQ3BY4g== 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 BL1PR12MB5207.namprd12.prod.outlook.com (2603:10b6:208:318::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.14; Fri, 1 Oct 2021 17:52:56 +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.4566.019; Fri, 1 Oct 2021 17:52:56 +0000 From: Jason Gunthorpe To: David Airlie , Tony Krowiak , Alex Williamson , Christian Borntraeger , Cornelia Huck , Jonathan Corbet , 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-doc@vger.kernel.org, linux-s390@vger.kernel.org, Matthew Rosato , Peter Oberparleiter , Halil Pasic , Rodrigo Vivi , Vineeth Vijayan , Zhenyu Wang , Zhi Wang Cc: Christoph Hellwig , Christoph Hellwig Subject: [PATCH v3 09/10] vfio: Export vfio_device_try_get() Date: Fri, 1 Oct 2021 14:52:50 -0300 Message-Id: <9-v3-57c1502c62fd+2190-ccw_mdev_jgg@nvidia.com> In-Reply-To: <0-v3-57c1502c62fd+2190-ccw_mdev_jgg@nvidia.com> References: X-ClientProxiedBy: BL1PR13CA0407.namprd13.prod.outlook.com (2603:10b6:208:2c2::22) 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 BL1PR13CA0407.namprd13.prod.outlook.com (2603:10b6:208:2c2::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.7 via Frontend Transport; Fri, 1 Oct 2021 17:52:54 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1mWMiK-00989W-9w; Fri, 01 Oct 2021 14:52:52 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: bcc5c726-814b-426d-5d15-08d985044b61 X-MS-TrafficTypeDiagnostic: BL1PR12MB5207: 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: DipFmQ2OQz0F3RPeXrCn/+2MqLwdpTufsBpNLFcfNr3FCq6C/1XrzSQ/sGpAQp3Zu9fQt6qmPw5Xa3xPPN8/Uu40xGb63RUj0XKJxLh8lijgLKcFZxyOszLJ9cjUW91CBZ/MaBq8pWbW1k3ZtPgoOoYnFDISzfGCZMX5K54B761rjpnhPW5TYGarLGw+McQtp87oqM7eAZWIYCgGDVNLT1+1zeERT/2Wy41AxllDJUCY3Q1EMQ/bmdtnnSbAFjvrHLIdjir93Sr+GdM3Bcwg7jJKjkH+RAMpcpD4Jtu9648VXYMd7HoB1UDQyWzOyANdvpdAw9EQ3emeFav+y14U/yPPq025EgNtfwxVjSGSCCvWKYHRTlZkKfazckZqJ+JPXmJbeJqcsvakFS4AnT8Rr0R/VvYBVIqWUUdzQC5peviHlQpiwnOrtm1gOs/2G/Vs44U8ijww/95LVH8PnityBB+AnZhjHZWGQaJyvd6/yK9jHK7PmTjvF6otUqYO55VUFYS8xXIW1iR/HyOUFkcmhCK3nh4w0Bch3hBR5/XcdVCEfUb5yze6hNivahZ1wfPaSVF4V6ZM19gnHfZSOGGMHYc4lH8TcxggllTtpooLAAwk5XURJA1W52XqFtogDaEAJXv5fpqejsG8ijoezK7Q0grAhToaMovGeH0UVavtXZrCS9F4ECf6gw2Ur5Jbi8WhWSyEyZOjKiMgTxdT64YQwg== 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)(66946007)(2906002)(83380400001)(66556008)(8676002)(38100700002)(66476007)(5660300002)(2616005)(508600001)(426003)(9786002)(26005)(186003)(9746002)(54906003)(36756003)(7416002)(4326008)(110136005)(86362001)(8936002)(921005)(316002)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: BtWWtbzNTe8bN97utlLOrGgGbStEWhzmkKz0KHVOSdfyBh5RgUFJ4Pu+2/4uTRRBhXu2H3VeS4FYNq7RXkv/meTVdEgblUrNfxxfnDnOUFt99JYdfnHfqJEd1kTLTPC2W2UtqVKpPBsRRUw8F4V8N0BdICAjOafAJkAfupDShxnAXF7z7zy44DJlfdqA5+Wd1htGg03JWSAjF8o3K6jkGfe69khWWsjNylf3CiMNy7Uge5xsG33XNU2va+LwhelkB6LKPDEYXLz9RuNbxRt880DdrClt66Vl86ZS55rxV/UungNc9C3Lupuy5pYkPMTiNHKqiFqXRKPl0oXvJN/+J3NfT4hkOaMUGg4c22JKLnJV3MFEL31p4Vpfwf2n6Ip5a8zUR0jfXsrL0FYtews0nPGlbXABRTTIlwZ92gR/IRQPaP7684ciabHB5b3gK1CXANQfwGqYlOnJkZ3SBNVKrHpsah1A02Aw8TmPsSBBXw05R4Qf0QPJbD2f/jc5xQD4lq9zN/KLQ/l508ecEH+MdZMsWoQcMPOjZqU7RoajRgBFnmbIfKQbBSWZL7WVDEK7r6aoMvtD+kl1kzZvbXLJKTG/qbA/QOyTGpyiPeI8typmsVbizOIWpauXqaX5JHB3RNln5MgyyND+W8RHBast4nG8c8PpAU5IQ1qHmjBXD0E+hx9zxMxI6w0Mol+6Xz8UKNn+syxAd6xu2soG1VX/qFQDpahw4hSmkQzgjOn5pcqpyXbv1NUe5ETZhB0ky/eCM4Gr6KMkVW1K+fCTmBpcq5dZQI6IZ1p2FN44U98dtcHVv2hvNA7QZsXsZNcXh8J5jPQAbk4yJKTtyQz39hUy9bRU+iU+dJX0a27ohIOFCsbyDjXvOysqMxbn1CqA10vvFrcpqarMe1hFzzCsJ6kMI20MUa16xWtjMRL0dpmD9SEWzxPgNlhEkA+SdMtqJKsbzZZKCMU9NOdAuGmWuVBrcIlQzhiKWBRNQC9vcc7qJFwuDPBZPpwxwQTF/b5h9f/iv6EkHBcArH70SAjWGJHMnVpUKdQ6ji1ZZMzTLzCKAkkWWdN0vA6nwAijzjSI2D0x5szTHqQiwPRYbbb4o2jJr3ddZy+hUdRapPk/M2aFGtCov4sV32n1HOxcqUyH7qQaWgwSPynOW0YooLZq1LmzHW1qMRiNE4p3RpkjtFXzT3LLC04+ZGNPnFm8LLUxv2ULiQ4e5t5OxtqPoThryJNsXlQgKM2kOp/F0J77L8juzg/bKOwu9//BqylDKCCu1teycr9r8KoLheMoysGpyjFsLpIBadle+KIVqw/8YB0IU0nAalADaNOU4aE0GT3hWfnu X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: bcc5c726-814b-426d-5d15-08d985044b61 X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Oct 2021 17:52:54.1995 (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: 8X5I49welgH7KCraYTgdgtGeIChMwPBwm/cSsdiTJkC/C9R/ylHz6HDlI4yR8H7a X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5207 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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 08b27b64f0f935..44adf112e3b5dd 100644 --- a/drivers/vfio/vfio.c +++ b/drivers/vfio/vfio.c @@ -554,10 +554,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 76191d7abed185..f99e4b2d9b45f0 100644 --- a/include/linux/vfio.h +++ b/include/linux/vfio.h @@ -78,6 +78,7 @@ int vfio_register_group_dev(struct vfio_device *device); int vfio_register_emulated_iommu_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 Fri Oct 1 17:52:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12531349 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DA552C433EF for ; Fri, 1 Oct 2021 17:53:37 +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 B1D3B61ABB for ; Fri, 1 Oct 2021 17:53:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B1D3B61ABB 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 5E2576EF38; Fri, 1 Oct 2021 17:53:05 +0000 (UTC) Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2059.outbound.protection.outlook.com [40.107.94.59]) by gabe.freedesktop.org (Postfix) with ESMTPS id 501DA6EE92; Fri, 1 Oct 2021 17:52:57 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=E/ZC2tf4jdBKfBWdnZ71Neq0JkUpk4teiu5CvdnI0R85Zg2Ful01PAi2eYP16OK0J5Po8y4xm5E8Xs3q1kZ4STwHVxCap1LO6lz54UAr6cZxPUsjnAl3y33wYPosOlvJIsUlhWnHIwy5196/KiAF/euYNHl7u6CbWJZ7oszAc5XHve0LAKYi4ervEVbmZUx2wTnQjNSID0HwU7LxEoc1P+wQIXNBEDUNpNGNnYTjN/hQkVc6MMQPdB9z1TlncvwqrnP+mTxUusle2mqto0ra/DmZRqZ+e1/LbhD+DrIzPeOZZ8ORC/ZNID/RQS3mJuXV3qEKy8aFgmB/WZvc2yEo2Q== 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:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=qdJYkQFGtlcO2xO0G8alywJKE1dQhnzZz8ywW9PbMtg=; b=VM6vmJfLgBkNjgr9CzdltZ1AsMuyHcgLa3Q+6YzETsunRoynBiBR7HyvWjmvCydijhkt6w1qF8Woc0VfD5etUKqnAOMns1lZk5ME5ZsKIOaJKYHbMsKnWDblE0VFkpULVfwEqvw7ZrCfTlKzs74c8Z/Pug1lRbzr6fIGXtfpf3bdMFRgnnTATCV4Rm39j+snLBNnOVjlOcij3v4c/lzpX26hmvLu77lT12iQNBHkwWnNlytXk7njNXbvdY+J6Io4Pmg95sEYfLLccV1utB1Noxfm+wGahrJoibOXWjy/r0qdeh0qSmpljnTWvHjyBEck/oHh2/MjdZdsVcs6LJ3SVw== 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=qdJYkQFGtlcO2xO0G8alywJKE1dQhnzZz8ywW9PbMtg=; b=ma9Gl0gZq6JqDLBjVyq0UKPJywi7FyNEuHoE2dC7TjVhTwbWORZ6iJu4gRY9MlbFoH/WTfc09NRoWD661P/6GI6MV1WDMTHeZzxLkrT9zG9ZqImM/kAaNoS3qAiZKvFMO8utZYGUFsDqrKXhg3dTAc6aR0J2hkyrSrndPd0SztKkfa3wMckNUXOaCU0EqBMNcuc1Jcwkq8DHimMqWfcPzXbt7KLrs+y6ne6pm3H2p/AFcnmm8Mm4+KTXHf8PLrkLg+tcGrPN1J33ye9sZbYgOynBsTdEz61iHlOl9cDeHs2Ft7e0c5nRo1YP65VQkXWMgDIqMnYXB3+Kj8SeZpTpnw== 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 BL1PR12MB5207.namprd12.prod.outlook.com (2603:10b6:208:318::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.14; Fri, 1 Oct 2021 17:52:55 +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.4566.019; Fri, 1 Oct 2021 17:52:55 +0000 From: Jason Gunthorpe To: David Airlie , Tony Krowiak , Alex Williamson , Christian Borntraeger , Cornelia Huck , Jonathan Corbet , 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-doc@vger.kernel.org, linux-s390@vger.kernel.org, Matthew Rosato , Peter Oberparleiter , Halil Pasic , Rodrigo Vivi , Vineeth Vijayan , Zhenyu Wang , Zhi Wang Cc: Christoph Hellwig , Christoph Hellwig Subject: [PATCH v3 10/10] vfio/ccw: Move the lifecycle of the struct vfio_ccw_private to the mdev Date: Fri, 1 Oct 2021 14:52:51 -0300 Message-Id: <10-v3-57c1502c62fd+2190-ccw_mdev_jgg@nvidia.com> In-Reply-To: <0-v3-57c1502c62fd+2190-ccw_mdev_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR07CA0030.namprd07.prod.outlook.com (2603:10b6:208:1a0::40) 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 MN2PR07CA0030.namprd07.prod.outlook.com (2603:10b6:208:1a0::40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.14 via Frontend Transport; Fri, 1 Oct 2021 17:52:53 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1mWMiK-00989b-Az; Fri, 01 Oct 2021 14:52:52 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c107206e-8f2d-4760-ff3e-08d985044b10 X-MS-TrafficTypeDiagnostic: BL1PR12MB5207: 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: YlQCUbCeA/y5wpSyBYjumGq6PrjrmzG99Bs5lPPwp8MDl4kFXed/HM/di/Z0aP0yb/MhNP/BBNKo2yAY6N/bgFRlSUh8X4hnaRApzkfsCG5j4JGmyKc75DNj4N/egloBMekI4iTLYC2gm28ft45T8GodGrdoF1IKO443QMvNT+wonShK1TroYD2duUFN/I+sV8oRKcuMzorU9SQaXpzilF58g1TvQ4AG2sxlF1/4os4LC+NtvpgkrclEQ+SRuWNJcEtuKYZbvvFKxPfVnPU/NejC24PQMUoSXipQ5dhkB/0Sn7RbQX8aGG6koFagg2MFOUO4nafQYWVRIiGnspv62coEeu28FZ8/kNuYuzWst0jeXvjUzQVwnHvG24R+saKK54YpzR0Ay+dgru/tTkW6l0a5oXhFiE6C3Xeff4eQUEfUUalUulf+1V1+TPeJZGI/ZPDAg4RYSD/EmDflvLLwg9bko7LeM/aJNhEr8pn/nu3SqG1ANJnsD5OIDkeVykRZjdpkRYJujwSVsku3NiQ0IpsDrlTruvrU8SqAseRc4KyM8hjQaTGcQrICSZ3cq9ne+GwcxdAFmLhOatWDBFdd4mJERO7o2TiINrCGqYiASwgB57CLd0qu93ZG4jNwaCO7chFzuB8XVvbeZLOHeTXIW+Lcqj9IjJeYrYBDyZu4cthrKtlma1Trv0DjRaHZTJmM 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)(66946007)(2906002)(83380400001)(66556008)(8676002)(38100700002)(66476007)(5660300002)(2616005)(508600001)(426003)(9786002)(26005)(186003)(9746002)(54906003)(36756003)(7416002)(4326008)(110136005)(86362001)(8936002)(921005)(30864003)(316002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: BA0adI8Pr1QYQuVhJAamhVwzBD6yorXXoemeGjpXMUkl8xI8a0J4+PZSkH5i8ps6s973lqFG0CELH5AHYqIbvMRod6f8U81Ahk21ARbrJZzUXGjp4zMk8jh8DpCZGoiff09NCFmzmstpfNzfPM8xxi8p6rCs0LWeTFXihhMNgyNr9fwUWqp9oTwMgUi9wXK9MSWS/tppAPogeOV2EwmQ7wOTU28mbFoWV/MXGO1EWJ2c3bdLgDeF7k69otOmLMJVSijVjX/jBoeo1J+47A6qHih7e+kiW65gAFiE4QhQUczTUV/xcJ9YXxd6Jw6ba7D8ek56ItstjcIBFygz4+G7WTI+whLHesHrzRn7Qf53krJoDGhY9vS92WTqq6S+rZ8szVubTILhOC7ruK8CYvN1iXEdURq2G4GzAj2Md8SqHX+rK4FYRlszJgMgZchqVHVyEAEpx5vNDSuK/hHREGKptAjRRKW7pP5EgpqKjS7EBYgF6f2u3ov+nmMEpqkqZH1U4dHc9QOtXlgIvzH+gN8L/9SqE2w4LvXRkryLo9+ctku7n9mvUluTxznrl6oR9BDYxqqADXjaRXani62kq1ch4zcK6B1/UqDJxTQzrKfgYdxpkR412hm+tWNiWyTTvABpDBiC4PgqaaOqYBaCWCmvE7+T4MmwIuC3rpFWM2J50jm78tSNXuMIwuuIyYG308YjonJ/zM1nFL4xmbfAw03WHuW//hDWde/WEwU0AMTVzhFGFe3X9p8gH9CkUmw0xEHmNvTqR7AwSicMQbEnsaUPiWePXAUkCzhuXOm/c21HbMKuLTvarQepEVWCciXQaVTJ1GxuIMbrCXB0sJBJZWrti4mTIhqZpASAMTHINqNb8m88lPBNArnfggyW2/1APVVKj9A3ZiI8whRVGNNuZ2pjk1Jj51ocEKtCtUetegmrIaMcRKxQPUj+qIODWE12FfGrj92pBGDbT9K+G5b/uQ5l2OpM1QP9k6CebwkHbZbnB38XVobuWcdHma8H/OPwZ3CTLvHhm4n0y0gt7jQAUe2DOc7zr8mRKuGog3PoK85w365xhN6G/vv/75ZoLRfRt43mN6h7xr9yTCq3/FrnvRot2crts/rDo0fRc7WmL6HGwZ/Ruof+ap2GHbDi4XJB5RFADfH0+mZeIL6HaQsnQK5IOmXuzbqM1DVsypHcHMusS+PqS+UZGhjzWCsYeo0BgdVivl4vOXNcD3PJVreJB52M2ti+SG9I1Rd6AF0Wo4SU5qMf1kqij7YkQvETzs8LOy2/obpDqR+Datl2WGt2w3pkp78+E8qAcFTH04aicdThM2zFLj6nuU4lYnZlI284men9 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: c107206e-8f2d-4760-ff3e-08d985044b10 X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Oct 2021 17:52:53.7973 (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: 7wQ9oUMFtSrKcakP2GqFUXq075t/XKwIaUMpCJUOBCQH7QepIwLTzzL2PcQBlPd2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5207 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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 18ad047811d111..c5582fc9c46c9e 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 void 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, @@ -222,10 +214,14 @@ static void 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); } /** @@ -240,14 +236,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; @@ -260,7 +256,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; } @@ -294,7 +290,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; @@ -307,8 +303,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: @@ -338,6 +336,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 68aae25a0a4be0..414b11ea7eebf9 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_emulated_iommu_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.