From patchwork Tue Jun 8 00:55: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: 12305005 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E731CC47094 for ; Tue, 8 Jun 2021 00:56:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C91AE61285 for ; Tue, 8 Jun 2021 00:56:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231288AbhFHA5w (ORCPT ); Mon, 7 Jun 2021 20:57:52 -0400 Received: from mail-mw2nam10on2041.outbound.protection.outlook.com ([40.107.94.41]:6904 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231278AbhFHA5s (ORCPT ); Mon, 7 Jun 2021 20:57:48 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OVlkVhRF0HldTeAGok4gPVy/2rWJLo40bsTz3NOSg0Jz+7XUA6tTv3SnN8Q3Ar7SKXDoPAXldOab6Pijs9p4J0wCDkZg/PheYuB4qBFGOwrg424UKFGZixLlRQQX0aWD6fgGjRyVrG4k7d3TbDxVhqiTa5lD++kn3AuqxsPEzne5l4vRfVZM5T21xGjKdU7uCJ0O4Xq1PhhxFymgj/sQjMWuSpG5DqjaoRe7+4xC3rFVPQVm5LXfaiMFJ+R2nXxCZVFjuRtLWk3xjr/t6fardMBqrRti1FDeo4FNEo4+7iABk3s1i6h4F3rOr/6xGeq+Bewq93FDhH5FyBApFkwkZA== 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-SenderADCheck; bh=HHtG1v4SqkIDAudWISprU490krVZpy6TNBLpeMuNLyk=; b=k4z1GkhLIwBA1XkxQntGsmnY+CVM1SuW5WDSMEJ8vlzImqXGuvx5yela1UjjvJXQBjZwjrPjqfL+cRthcvMe8SEH9TOYYOv1ECnrnnqhs1i0h0K5D9QQ4BKP3bGTac1oxj7Ac4wM6WfUNCCW4CLY0RhOGQ1lcPiA2b4pIcilr5MqtbZxKn87pkMvfs7HaoM3kHgQECGOUNfjYWo08bHu034HP+r2ZmH/Z29VAfeDCne0/VLRy9QGoPWSKPuAVq+2eElRP3AypD7RBa4LVxYYWn98Gxd2YQSu+tveCLe1kzwcRLwSyaPXIjcjRI96Q6ZnaKIyOCaCZ/aBK9Y4TgVGHg== 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=HHtG1v4SqkIDAudWISprU490krVZpy6TNBLpeMuNLyk=; b=p9H5tiZ8SGVqsLJqaqHiS4EKBryDodot4dvN3HrBuh2oIexD4B6ySz8QEoZmgKpaeUYPxE4U38LcV+m5spb11p7lZ5obenfsy3e9HFB7L4R/cWq8OsyOYEkLZO5rc7wXUz/YYcdDRplKGqwyhg/qD2EE5mYlszJijYqco1zBzxNpStzZo6aVTgz4gXuFWkRz0JbsEAMMu6YiGpMSHpY5seILO3q2IqFjTJYPB/XKNjwC/IGygmpdD6dT4cH0qK5i3X2iAhM5chsxy//60xyIC8UJqc9eauiBZMyv7xYdEwxn79RFtGSpCOzs6IAAif5I14TfvZsNpW6dw/mlN6UucQ== Authentication-Results: linuxfoundation.org; dkim=none (message not signed) header.d=none;linuxfoundation.org; dmarc=none action=none header.from=nvidia.com; Received: from BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) by BL1PR12MB5095.namprd12.prod.outlook.com (2603:10b6:208:31b::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.24; Tue, 8 Jun 2021 00:55:56 +0000 Received: from BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::3d51:a3b9:8611:684e]) by BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::3d51:a3b9:8611:684e%6]) with mapi id 15.20.4195.030; Tue, 8 Jun 2021 00:55:55 +0000 From: Jason Gunthorpe To: Greg Kroah-Hartman , kvm@vger.kernel.org, "Rafael J. Wysocki" Subject: [PATCH 01/10] driver core: Do not continue searching for drivers if deferred probe is used Date: Mon, 7 Jun 2021 21:55:43 -0300 Message-Id: <1-v1-324b2038f212+1041f1-vfio3a_jgg@nvidia.com> In-Reply-To: <0-v1-324b2038f212+1041f1-vfio3a_jgg@nvidia.com> References: X-Originating-IP: [47.55.113.94] X-ClientProxiedBy: MN2PR12CA0027.namprd12.prod.outlook.com (2603:10b6:208:a8::40) To BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (47.55.113.94) by MN2PR12CA0027.namprd12.prod.outlook.com (2603:10b6:208:a8::40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.22 via Frontend Transport; Tue, 8 Jun 2021 00:55:54 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lqQ24-003eKK-EI; Mon, 07 Jun 2021 21:55:52 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 32df214a-5582-4c7f-79c6-08d92a182b3c X-MS-TrafficTypeDiagnostic: BL1PR12MB5095: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:595; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Pi4ZpU3EM8CZLNfiKXT74QE8Bt1E8weECxwgiB86ZXt00pWfp3nKfnGuH96k3jQxZp64aAfvr73Wrz2aKb1vbX1bGJqNWZEmotiJ/LMpv1blb2riB3YnndAA8hve1irWCCrcqC55Tdyo4SPW+f1x/hwwNLFgfDWdF6Z33Ejxm/H3cExII04RUPMrRjnnzUz8yZVdGXAjiB5FSYgjC7sS6lIyck8GrCxLgCLz2AfIIIFvohBZsNcAvDkUnvdbKS16AGSn019xGV8XIPOSWsKuivuUie3/9t+kxfUH7cc4xDxa/5lPr/kGTDm9bKy7A47qqdbeGWLf5DIh/psUcq1pewirwNWo+indiy09Kwaa+r1iubCs8mUXP4TjOOluCt2rtn0VEDYlI1AXPQTJMHBi9LoYKvAgLq5HAKFJUR368vfBstAGPhDtiAyti+PT+71VuK+2phVvP5aP17YF4Hl8gpq7uO0H4XksJneVA26XPtB2ZnHcC/nIV4DgJ8CWaF0wTy61il0U9Rk9fEhc81ZrYioIoP/APQTtAqbvOIvS7rk9CRAKM1QM7Ihwlz6pUWmg6phGFk5IuOToWQPogknktBPY1qTLSFrG+GQnKeNrhcxkLl3GP+Jcy3g8XkbPvxRSYC9NTmG5iCJr4g0T5EXTOtssd4fHSDoqLsVYpU+N/m8= 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)(39860400002)(376002)(136003)(346002)(366004)(396003)(110136005)(2616005)(86362001)(9746002)(66556008)(2906002)(36756003)(186003)(9786002)(478600001)(426003)(66476007)(83380400001)(8936002)(8676002)(26005)(66946007)(5660300002)(316002)(38100700002)(6666004)(4216001)(51383001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: uiYmmLq1D1GdVHElxBbhOO9foh87swFGLf62U1l4yORIV0srz/J3zPuo0/WYx+++aHMtimnHvBkxFt/AWCLOowO6LMwkxYjvYGXOFZMRPdujV8NPTYasKtBMgke9LL/iwinme+sbPyqw5WU0drJoqrjF2s/iDpiXyU+mKf1Q+H8PTd95Z/+WceDmzYcFvGzSlkooo64WTL2Wa0N6CDrB/7zJU65XVOQ2QtZAT4pY22B4G5uGzKeNqpNJmATn/T/gWsyKXDdG8FXWccF3ZfbRqHBOuoBu5Krqp5Dk72TcFo++VkGJQPwMk9zj7bwSRb12nYycEEbKxfcBE1UPhZBrWjRXfvVdQq65nI1Cazr2mHvjyR4CX73Ufvs/xvlWWRyn2C6e4sZzer3z9dR1+3VlCf0Axz/IAe/XOSn/K1ejQ1SInDrFtW2oHF7PceGQ32kO5a7OThpbJH2IWKd6gaVbB8FkE3MvPSsG0FMKoRzM1/uU7wFpUK/fLmbYLCZkqgNx/tCJAtmvNvEAHfyvQvpnSt6M1Td8hBDGq18DslwpVnEACtpoS56kzLKZYih6lwWoJgEM424Gg4JEN/BcoHwx18aDk6MV4xjrkFwTz0a/+63M4zV7kKsrmcoQ9oIyP3TTmkDY20LrDKkAA5x98mN8UyTs+HA9la3gW6kXo2yElXnmCuzi+iTY0v1SgBmrDgAhmVBvsOwF4jVUfClTUEXlRAbsc20jDyt3KidxpH8aM1buvVeFDW4maUheXXu7GKq3y09+6pt1PNqE3R8FOGgANAjbJLGpvwRsGoDPtHtoIpb9cmH2kCzSgdN+CFMxCNZUxlh/MxG4LOZrzXOJ+P7ZcAp4AkAjmBAKHvleQkYMvUwKmW2ruBXhCMndc7np+sLtwUvu8OuBEHA2Hz2V31aG7uQ9LdWfAFjTeMTcpGjE8hVp0X2dxxQALXTXI0/HwvQwE7iBIqrOpEBS7aNJdaaK0iX8vqiNz1O2YNG0/jWG0NiAbY3zCHTqIpTl0P9TUwjnwT/6vFkBNKiKvqYoi0/Zy03sRNSu4faM59mAA1CDDGvh/KJZclzaVDOuB+LzvHqo6CB5ysgRExeyIBFuZ4/igwbLbp1zTRAKWEXmwj6qlgRHJ/qHHJ9cJm1wSosiX6MTYzm82W9lVru8+y/saf/fzkhy3bRv0x/HASH37TiqTFP5rpAk9575eb+iICMiz8ZwpWyDFOFddztBiPvdtiDaz7Mck3Q4zWe2qivAJkhn7Wv63cQz1sVWwBWXyx+VhGq9JubloTbtO3Zve6pPmCvoyJ8Cgj+Ath7O9bkhKsuwMjwd2WgSvx4D6TiXvZUEiKAQ X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 32df214a-5582-4c7f-79c6-08d92a182b3c X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jun 2021 00:55:54.4642 (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: fpdv0zCe7y8PAawg/rApjscDsiJang5VvWw+Cj+EKWjJq0sLvh7POk9s/phvktZV X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5095 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Once a driver has been matched and probe() returns with -EPROBE_DEFER the device is added to a deferred list and will be retried later. At this point __device_attach_driver() should stop trying other drivers as we have "matched" this driver and already scheduled another probe to happen later. Return the -EPROBE_DEFER from really_probe() instead of squashing it to zero. This is similar to the code at the top of the function which directly returns -EPROBE_DEFER. It is not really a bug as, AFAIK, we don't actually have cases where multiple drivers can bind. Signed-off-by: Jason Gunthorpe Reviewed-by: Christoph Hellwig --- drivers/base/dd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/base/dd.c b/drivers/base/dd.c index ecd7cf848daff7..9d79a139290271 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -656,7 +656,7 @@ static int really_probe(struct device *dev, struct device_driver *drv) /* Driver requested deferred probing */ dev_dbg(dev, "Driver %s requests probe deferral\n", drv->name); driver_deferred_probe_add_trigger(dev, local_trigger_count); - break; + goto done; case -ENODEV: case -ENXIO: pr_debug("%s: probe of %s rejects match %d\n", From patchwork Tue Jun 8 00:55: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: 12304995 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62AF7C47094 for ; Tue, 8 Jun 2021 00:55:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4CC4861285 for ; Tue, 8 Jun 2021 00:55:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231235AbhFHA5r (ORCPT ); Mon, 7 Jun 2021 20:57:47 -0400 Received: from mail-bn8nam12on2067.outbound.protection.outlook.com ([40.107.237.67]:45339 "EHLO NAM12-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230266AbhFHA5q (ORCPT ); Mon, 7 Jun 2021 20:57:46 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DpRHwTKFQwNAonIVpXscHQ0Pxdl6N0EPGDU+48pJOr4t6GsoCgik3ORJGjDXSTnhwDX5hQoQZJv4na9wT3S4ps4O+f+UyGphrmPc93a9wMHana3p+D5vkIqzTT0orkvyZhPxINHO44Wb/uQ6j09J7gvF6mfR49HY39WTudRtpPVD0SMsHLeIWEx3DCXe9u2SLq7VYGMseBfmV5IYHrUNpbZ9Qg5YklgyZSihyYTi4ozWDs591VehfU3c69ibiUQy9wSfh57K1rCY5pukEi2yo+ABd4j504h+d6antxR800GnXO/cqQVpNRJLOEyke4iRxfUoUplZNdzZDwGX/Lk9Eg== 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-SenderADCheck; bh=9XNqK5gMVn9TXVQ/donIWzsg/nEgmHcimerldaIVuko=; b=W/hWs7hWm4yiVNc08cYBIm//nakMq4ysuPooUmxpS98tfvWZXx2fsayHWWTFOozGdIMYkcESLvNET/SoOQq6glNKQ5R+adC4V6x5AMwCCfkUGrgXluVK4DSrPkJ/wcg9aFYXY+3EnO1A5OcrZBXr6HcoRZTxigo0K1DhDTFnqDik1ZKUQv4DwiFfEF+vxKyu0Jci2eq1W2kx23eKFjfHwALJpwRUn3JF7PCZn6I/Bxh9C3SOwMdIfBSlBUANKV5EG016XHiQzXeCcO8EDVo0Oga9veVCq1lQfqxA+oHPWlKruWa6AFT8olo4Dz4DFw18Ii78sjO9axvBkfQPIYgOMg== 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=9XNqK5gMVn9TXVQ/donIWzsg/nEgmHcimerldaIVuko=; b=MxluVSnU9nJxSGhU+VoM/70EyPoyCFH3jfiMuctpgpRtHjgTGuMqn/OkxKvMr/VKJvxMFeOgAMxO6zjcf00GDeOfnrxia6kH37oirHrAX1YEeKx4I1reK4B8MmJ/yOk/8kxlh/JVsV9F1Uyvc8cv6DMaSMCFdy1km7GdAw7GdUjrq5yZ/S02VnEcTkRG8LC7qemgxCF1NMdJ7TLzczO683goU/QGW4gyrUxWYwsmpKoNW9jjq8jvs4rljinM5jTXT4170Iw5CQ/QuDB20A8r4J8BXc0UGf040jBP6GP+eFvI/4R3KfLg4ErINuT57vNZNFsP9gBxnCB1Un3tv/iKMA== Authentication-Results: linuxfoundation.org; dkim=none (message not signed) header.d=none;linuxfoundation.org; dmarc=none action=none header.from=nvidia.com; Received: from BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) by BL0PR12MB5539.namprd12.prod.outlook.com (2603:10b6:208:1c3::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.20; Tue, 8 Jun 2021 00:55:53 +0000 Received: from BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::3d51:a3b9:8611:684e]) by BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::3d51:a3b9:8611:684e%6]) with mapi id 15.20.4195.030; Tue, 8 Jun 2021 00:55:53 +0000 From: Jason Gunthorpe To: Greg Kroah-Hartman , kvm@vger.kernel.org, "Rafael J. Wysocki" Subject: [PATCH 02/10] driver core: Pull required checks into driver_probe_device() Date: Mon, 7 Jun 2021 21:55:44 -0300 Message-Id: <2-v1-324b2038f212+1041f1-vfio3a_jgg@nvidia.com> In-Reply-To: <0-v1-324b2038f212+1041f1-vfio3a_jgg@nvidia.com> References: X-Originating-IP: [47.55.113.94] X-ClientProxiedBy: MN2PR12CA0019.namprd12.prod.outlook.com (2603:10b6:208:a8::32) To BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (47.55.113.94) by MN2PR12CA0019.namprd12.prod.outlook.com (2603:10b6:208:a8::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.20 via Frontend Transport; Tue, 8 Jun 2021 00:55:53 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lqQ24-003eKO-FI; Mon, 07 Jun 2021 21:55:52 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4561265d-7898-4826-a48c-08d92a182aa3 X-MS-TrafficTypeDiagnostic: BL0PR12MB5539: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2733; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3qZ7Tz+LI4BZxJTRy1chLpKDu61VEUcr0wsi1XVP26xp6sjO++bZKDzRbFtJYJkMI83zNfqg70LSMw7qnG1T/zwVaK1m0A7Mb8LIIIl2gjG0qwQ3+/mNAhVj2fa++Wy/6ZdL7NKZZYmk2LslRoVtEevFPW4fBF7JPqLz24B+rVrk/Z1VQ+C0zk3mtRQaQj4mdMWCgwOipOG+syg6mTpgeVJ7ey/WgeRAZJcPmPeRt8W4xs7BbCZLtj2zLX4kOmhkG8ldx2dN60wlRr+InHp5cfDpgaLMHuaRYNzM/EWLsArWlLwIiVgvMO/F5+ndcRKoN4pR+zEscnvvaS0sGPq2frwJypU7CNeN0CIdOuJcIAHm4syJSSQGORP4pE4R2QpmvVvkxEmEj7k2Myw7+GGVv84u9j75uV1OoBHmsRuWOxDT5C/ndzpRKoSLZBtcv85pq+TUNDOyWiC4RAzw9JdNFund676rQOkEP/NeUa4wUK1sNM+jwHeemB5MInkKrKDGz98vPkH/bdLmwM96PSxbs3I95h91rHPqz/YQnCs0I+HTw79p5eLoHyO7y/7BeZ6Zc2AsLWZi9VfkZdM+4FHeLerF33ayJNis5ELxsiXac9ekqFmraLMomgdXqWbCItMDrGhyApnfYy7aFisSYj/jIw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL0PR12MB5506.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(136003)(366004)(396003)(39860400002)(346002)(376002)(9786002)(186003)(26005)(36756003)(316002)(110136005)(8936002)(478600001)(9746002)(2906002)(6666004)(86362001)(83380400001)(66946007)(426003)(38100700002)(2616005)(5660300002)(8676002)(66476007)(66556008)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: mbAdlOKuFhiwV6v+CqQfBnik4xRlv+76zodXBzglIIXS44wBr+tGDG1nn19to6jtDih45QxoceAkO2KTBRsFa2WQB/w+LR/KCajcOxN99aewrYZpcP1ngJjSWnKV/z+NbBMhrW+/VQ85xmiBagWZuTTmiv3L/k2I57xjT7Jlrp41vt97RRZiIN/vf16qJxuikmaKlyifPc3p7o+lsJJV+ic/KEWhzEa8yFqv2t/AVqvWPWAFcjecyBRwePd4QCpe3Kg5gU/v2WQYTR0Yy622FrogYi81iKASrOpGqbHO2VfluXexO9OGeiyF5+vAeZN3nb5/roFSq1R43GzaIy7DGHfjKl0f51fUEuGjCALeBbKfpqBgTkmXEHHvoJetxPv07QuMntoBzPB1Vctv7hH7uR6SVoHVXx8zl8LLLsKUZqm3O3dxZjajHfWFVfDTJuWzdQjIKof0UBekVCOiGSMCj3TJ8zsC0hcvvDS9xyaQg3SK7oS91ICxip/Chb6r28UxVRiHvbciCVK59+x31x8kMg/8QuzVoYNFEDPgOTpM0Z5rE4t/syGCvETLrDZ39JYJMe/r8IadvktcAN6cD3aLy5ec7+rO5Nekjx62WmTJlKwZzQykENMmv/Z8F4RQ+nJ6tb9VJJtAvEpDYmpOF26roTs91xtS7umpkTWLH/fRAY6GMTaCM65myOpjIKfxIXPLYiF1WBMbHuh21RxaE5Q2n0eVCdjHGLr8taE64OAN0AyuVB1uiIN7M7FDsH+2lihhBFbgsxsYBErIOSv171kBtGiII6eL5dF0a9e3xwuS+ixUmK7Xq26fRl8l4GXS3kBLHwWrO+7d4Q0j4hXWzSSB5n27wicyBwa/vDdCDExtM48mRXn95eLRjuM9Mlpx+lC+jeccCRZenXQe5uL7JkdawBRJkFFnlapegpeVR9pXCTH1n+rkNCEKIt4FGY66SjLKFkgJgsHazSzJiFU/K0IRZNG0d3BcMZ+bUj+PjipCMLn9gVelhtrZxNxUB3FmbnFDuGcJkSBcK1h8b+xUYEKW8+eGx7b+adnYsE2M5wDTl1r8lSeOJHsG8xPjnMmvZB2DdSNnIV3aYZ5QYBnwsv6Yyin83WkmsW01cHFRkjYYNoreurKbynIALuQ131m5u8GLIC7UBLTBJQ+DBKuSmQkMbWjluw7eZW/otFezUzv6LMUbqsS/paQtW1A+IoYjrrVJsCPSTDs6vybS1FZRqcwv0yw1mwH/KQlykqYUmskHpI4Y9ir47oI/jZcpyP4TZnCnqHOPFqFdZ+zjkNW+dZp6ZP53Mq4t4/Hiswq06lqzHahEeRhiacTd3ZSGqksYWyi6 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4561265d-7898-4826-a48c-08d92a182aa3 X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jun 2021 00:55:53.4735 (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: PA7vnBQmsLJujZuHeGBWy43OxTFnKpXd/8tTYA0KBoyY8LUJk7gc46pxYPlCHWp2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB5539 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Checking if the dev is dead or if the dev is already bound is a required precondition to invoking driver_probe_device(). All the call chains leading here duplicate these checks. Add it directly to driver_probe_device() so the precondition is clear and remove the checks from device_driver_attach() and __driver_attach_async_helper(). The other call chain going through __device_attach_driver() does have these same checks but they are inlined into logic higher up the call stack and can't be removed. Preserve the sysfs uAPI behavior for store of succeeding if any driver is already bound, but consistently fail if the device is unregistered or dead. Done in preparation for the next patches which will add additional callers to driver_probe_device(). Signed-off-by: Jason Gunthorpe --- drivers/base/dd.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/drivers/base/dd.c b/drivers/base/dd.c index 9d79a139290271..c1a92cff159873 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -733,8 +733,9 @@ EXPORT_SYMBOL_GPL(wait_for_device_probe); * @drv: driver to bind a device to * @dev: device to try to bind to the driver * - * This function returns -ENODEV if the device is not registered, - * 1 if the device is bound successfully and 0 otherwise. + * This function returns -ENODEV if the device is not registered, -EBUSY if it + * already has a driver, and 1 if the device is bound successfully and 0 + * otherwise. * * This function must be called with @dev lock held. When called for a * USB interface, @dev->parent lock must be held as well. @@ -745,8 +746,10 @@ static int driver_probe_device(struct device_driver *drv, struct device *dev) { int ret = 0; - if (!device_is_registered(dev)) + if (dev->p->dead || !device_is_registered(dev)) return -ENODEV; + if (dev->driver) + return -EBUSY; dev->can_match = true; pr_debug("bus: '%s': %s: matched device %s with driver %s\n", @@ -1032,10 +1035,10 @@ int device_driver_attach(struct device_driver *drv, struct device *dev) __device_driver_lock(dev, dev->parent); /* - * If device has been removed or someone has already successfully - * bound a driver before us just skip the driver probe call. + * If device someone has already successfully bound a driver before us + * just skip the driver probe call. */ - if (!dev->p->dead && !dev->driver) + if (!dev->driver) ret = driver_probe_device(drv, dev); __device_driver_unlock(dev, dev->parent); @@ -1047,19 +1050,11 @@ static void __driver_attach_async_helper(void *_dev, async_cookie_t cookie) { struct device *dev = _dev; struct device_driver *drv; - int ret = 0; + int ret; __device_driver_lock(dev, dev->parent); - drv = dev->p->async_driver; - - /* - * If device has been removed or someone has already successfully - * bound a driver before us just skip the driver probe call. - */ - if (!dev->p->dead && !dev->driver) - ret = driver_probe_device(drv, dev); - + ret = driver_probe_device(drv, dev); __device_driver_unlock(dev, dev->parent); dev_dbg(dev, "driver %s async attach completed: %d\n", drv->name, ret); From patchwork Tue Jun 8 00:55: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: 12304997 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 07405C47082 for ; Tue, 8 Jun 2021 00:55:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E67FF6127A for ; Tue, 8 Jun 2021 00:55:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231268AbhFHA5s (ORCPT ); Mon, 7 Jun 2021 20:57:48 -0400 Received: from mail-bn8nam12on2067.outbound.protection.outlook.com ([40.107.237.67]:45339 "EHLO NAM12-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230382AbhFHA5r (ORCPT ); Mon, 7 Jun 2021 20:57:47 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ejZBAud7PTObkNgCU9gqlDNQpk8VlB/FMsnExclLV7t28x2yQdmKtAL5xZKVjoBlYVwAZ+pzm3deHiitHd3tF4+RDUDItxM6WKOFpiWhH3iB5s5aSI7y1+e0PiGAAkIX3BEiGpCLEFtT5lrzRnebX6mCgvmJJPpzTsz1pE0owLWQU+PVA0HqjsyexYKiuihmD84EoH189hjc8KI/hwXog2aX1oBvlUGHd9uUtM/QAOZiF0FBlwqY/wmgfpgiHZEFgQxZHbAxvDoZqh0vG8tood4cRiNUUcUgPobrk77V/u6u5V4rCO+WOIUwKUrnsoXddCZJH32Ast554JKj1p9c3A== 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-SenderADCheck; bh=6zNscrwBy7BNIkufnTIHhgPEyqlaxu8hhfxhrGbQUbI=; b=HjwPT9AuQAjy3V8+TZl1D/Xz3Bqo+bvMLNBbexMm36HLhgZwkY7QZgo1EZwgAgV8ayNOwFhqIL+OLQ85DTMu2Pd1SkWL+xDgjwD0xdZuEXTynhrT9UqWHJlaGSSDDhgL22htNDCJI6AV50FXafeBaf/hPM01JAo+fX3PNEin678OmyJRu3Id4+82XjRczgzL9DsOnNP19AtTucGpzxfzTibLGjP8Kew+61Bkn8qHfSzZMI+WNKUyb8W9wy8ZoPCsulnioQRw7mhiBHoU8fKjoL5AMRQY6IKDg0VVbDMWx3JaxqTCmOBP1Yl+Ll4TuHIFORh7fLI8VEWjqHcpHXEAvA== 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=6zNscrwBy7BNIkufnTIHhgPEyqlaxu8hhfxhrGbQUbI=; b=gdclbAT7HjQyj58adlAt6Fn+j4Qygz2hskXvDDRMwGwnCTOKsotAdqiqgDfzcm5g/HZKYT97yoCN1sQOvpJbJg3hNi+8ffjGvOtBcOJ602g/wsZ7v4zI1PPA/kmCwGhW1riRhGVsLDx5AcULu9JNUQiJem4mUy23MTEzKP6hGJrZjRJoFty349QaZ/cHWlaONrQQax81dFXRZQAzhtoHECIHhZLqEiRojNSXt19YE/q6xwbiwcwyujK6rWLtDKTWbP/267Z7oWSDs/fz6W1SlHvEs0AXxvALJRLTOCK7lrnqPKUV6WbXa3jpZbr6M9SFFSWqFsylFw0rlid3CI3TbA== Authentication-Results: linuxfoundation.org; dkim=none (message not signed) header.d=none;linuxfoundation.org; dmarc=none action=none header.from=nvidia.com; Received: from BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) by BL0PR12MB5539.namprd12.prod.outlook.com (2603:10b6:208:1c3::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.20; Tue, 8 Jun 2021 00:55:54 +0000 Received: from BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::3d51:a3b9:8611:684e]) by BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::3d51:a3b9:8611:684e%6]) with mapi id 15.20.4195.030; Tue, 8 Jun 2021 00:55:54 +0000 From: Jason Gunthorpe To: Greg Kroah-Hartman , kvm@vger.kernel.org, "Rafael J. Wysocki" Subject: [PATCH 03/10] driver core: Flow the return code from ->probe() through to sysfs bind Date: Mon, 7 Jun 2021 21:55:45 -0300 Message-Id: <3-v1-324b2038f212+1041f1-vfio3a_jgg@nvidia.com> In-Reply-To: <0-v1-324b2038f212+1041f1-vfio3a_jgg@nvidia.com> References: X-Originating-IP: [47.55.113.94] X-ClientProxiedBy: BL1PR13CA0390.namprd13.prod.outlook.com (2603:10b6:208:2c0::35) To BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (47.55.113.94) by BL1PR13CA0390.namprd13.prod.outlook.com (2603:10b6:208:2c0::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4219.9 via Frontend Transport; Tue, 8 Jun 2021 00:55:53 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lqQ24-003eKS-G7; Mon, 07 Jun 2021 21:55:52 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8eb56a3e-8ba6-4017-364c-08d92a182aa1 X-MS-TrafficTypeDiagnostic: BL0PR12MB5539: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1388; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RGiR1ViV2OPj9I/oHXlFe9ny2w2BXZw5NdWodO0FflOB8Cja3bVgXZQCTIaqqd8LXhhNgsCKUhJfFApS35raAacb/115ReqZD+hyItZpaLWEKcq7CPutVtLA6NK7gfOZpi1a7Z51Uui57V7PbHIZYHQhflxGZxEU7qsVaUBKRd6DDpq+V4poeO18PcRFFGiC+W6cHxHH1ljr2LsyQRse2j0JBvH3NK8t+/u4ZGBslUvwq6tsbOGmg9MF5diQtfhMuBTj4+qktUmpEonHv5IeMDfd4t8WFAjHvxHnL76KTebScwyVkpi28ywT6eOntgPD9/S2rdMFlGbtXpC1g/Q3tilt6bLrVYw2dGP0m0iZ2ABfbsuSzAhbHKAUm3yYNpaigT/vFvWc8wJ07gfmSd2ahrwvm1yL33GwDi0hFNna6OUA5Z3zSrxdT7sHfeQGDlb+u30N9JEQ8jsqmqPD5bXbJ+cZepTb76T4Jgp+WkGDkgPcnVzgPvJh4uySuA/LwIkrcPxPf0NpQfqZbfUODhvtrtTtLyhGSUVqA8u/9V3Asw+Aa1aIsMa++vRbdqETFQNGH5ppJN7DFf1BBX5JpnCSmBcqkyL1tjysoxbP9su5v+sQ0vU0vasvxcWHg43uy/HNGUWS6snA4hpHV8Jp9ainFA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL0PR12MB5506.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(136003)(366004)(396003)(39860400002)(346002)(376002)(9786002)(186003)(26005)(36756003)(316002)(110136005)(8936002)(478600001)(9746002)(2906002)(6666004)(86362001)(83380400001)(66946007)(426003)(38100700002)(2616005)(5660300002)(8676002)(66476007)(66556008)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: QkikBmtc12/NPrFiDL5q1Pi4TYTS03SbesPC5cfVw5/MrhlZL9Q1O+52ItTirmMc0NkYwfsGZQPbd2P/sQqXEVd/u2GEdZwWMwFUK2/yipkbp+H2hsSe1sL8CqrXOhZmaiqbTIKZ9vXjLgudQTghVl1I32OtUQ50DqLuyU20l786lbaE/2Zc7kp+K77LoFUlLco5/EyaXXtmc41bykX0MWdu3K+APIEl0k9WF2e7qkQUe74mwSEZy56PGIAFipB1VJLBRVtlKFIfZZTfzWLoFco+C7gEowmzv10aB7mpFJNFbf905VgnXsiWJBiaA+zen/qtZVgfX+AMbswP8hHgIl73r3Ao6f35SXwKHtPazeQToWbhT06V+YyPO3TsF3s/ZYhj77kxrY7BVAEDgLg3rNZaRD+wRbcs6PRYCAMR7rcYvlnFqB/jy/P5QAZrsQsfJ4CqtRwjOxowV/SzUjITJ8kNnHj6f0KmMNjgUA878Y1e0IWpike64FPOsJSnrz9fbkvdB0VviEEq9ezQ1bjMD9q9OTqnvz0tK6bu9+Ufbo0VQqmiRJlEq6UyXO64SGK720HNsY0HtJwchTqJ7Uw08HQLmXke2RI/ZxyFFb3yLw5KoQLQfUun8chwOenJca+ITvyteTTz1D2D4S/UZhhUTBQ5p60wV3X6BBpzHtWZoiYgL6cQVlf66OeBOwLHFrtjgjRTSTWcyHjngnaIgXiwMW+Ka1wPestvLHz7IUhTs3zck4wkPa0h/GJta81D2Bj5Cj8oNsEG/SBeS0421ML/caJEohkht+KPlvFwdqW02aqxcxMy77aEPnvw6ezhuLlF4tGUyInKU0JYn4Z6X3i9KoMaBi8Ta1/7sed1T//BaFwjinqX122ViUYN61c7GK83CWsvXz0/5/1pGB4QX629Ghtft4GzPZDPNov81ECLI37muevmCd0ss84g0udrxreKooFBEC0PXGltGc+QIzLAAsNEyemb4SaI4o00cEi7tJ9EtSRi8/TnRBVpcSDMhpgH56ld36F1Ht+CUjNXbsXvM49aah/7jljtXlhLRBROugJHFNLJFYJuYz8JPRZDtxTlLLCUywDzGw9ZhSb+uGD7beJ5dAaOcaX+N+eyO1aJJCa16njvrmGYbzH6bNazbrhNXT2l22UAXN4rwUKien/RWusQBkDzGtP5Cu7uhaO6lcxAwDa/CMdomO4JqTpAQ2SnAQ4pb4n+H6M0UpzwmrVt7hjIHGwytxMOXXeg8fY0w/Ik53xrhidYI9QDrE2z8SHxCs28FJL6834aDoA4otSZfqe+1iT1d/yRzudYyfUHLA7upJb48yxta/MX++ndkn+K X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8eb56a3e-8ba6-4017-364c-08d92a182aa1 X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jun 2021 00:55:53.4944 (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: 64AE8JFHOtLBCX21Zo+itqY64Ipxs/b44MNAekbVdK5xSxwZTlVQ/MQuPf6J3fGr X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB5539 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Currently really_probe() returns 1 on success and 0 if the probe() call fails. This return code arrangement is designed to be useful for __device_attach_driver() which is walking the device list and trying every driver. 0 means to keep trying. However, it is not useful for the other places that call through to really_probe() that do actually want to see the probe() return code. For instance bind_store() would be better to return the actual error code from the driver's probe method, not discarding it and returning -ENODEV. Reorganize things so that really_probe() always returns an error code on failure and 0 on success. Move the special code for device list walking into the walker callback __device_attach_driver() and trigger it based on an output flag from really_probe(). Update the rest of the API surface to return a normal -ERR or 0 on success. Signed-off-by: Jason Gunthorpe --- drivers/base/bus.c | 6 +---- drivers/base/dd.c | 61 ++++++++++++++++++++++++++++++---------------- 2 files changed, 41 insertions(+), 26 deletions(-) diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 36d0c654ea6124..03591f82251302 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -212,13 +212,9 @@ static ssize_t bind_store(struct device_driver *drv, const char *buf, dev = bus_find_device_by_name(bus, NULL, buf); if (dev && dev->driver == NULL && driver_match_device(drv, dev)) { err = device_driver_attach(drv, dev); - - if (err > 0) { + if (!err) { /* success */ err = count; - } else if (err == 0) { - /* driver didn't accept device */ - err = -ENODEV; } } put_device(dev); diff --git a/drivers/base/dd.c b/drivers/base/dd.c index c1a92cff159873..7fb58e6219b255 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -513,7 +513,13 @@ static ssize_t state_synced_show(struct device *dev, } static DEVICE_ATTR_RO(state_synced); -static int really_probe(struct device *dev, struct device_driver *drv) +enum { + /* Set on output if the -ERR has come from a probe() function */ + PROBEF_DRV_FAILED = 1 << 0, +}; + +static int really_probe(struct device *dev, struct device_driver *drv, + unsigned int *flags) { int ret = -EPROBE_DEFER; int local_trigger_count = atomic_read(&deferred_trigger_count); @@ -574,12 +580,16 @@ static int really_probe(struct device *dev, struct device_driver *drv) if (dev->bus->probe) { ret = dev->bus->probe(dev); - if (ret) + if (ret) { + *flags |= PROBEF_DRV_FAILED; goto probe_failed; + } } else if (drv->probe) { ret = drv->probe(dev); - if (ret) + if (ret) { + *flags |= PROBEF_DRV_FAILED; goto probe_failed; + } } if (device_add_groups(dev, drv->dev_groups)) { @@ -621,7 +631,6 @@ static int really_probe(struct device *dev, struct device_driver *drv) dev->pm_domain->sync(dev); driver_bound(dev); - ret = 1; pr_debug("bus: '%s': %s: bound device %s to driver %s\n", drv->bus->name, __func__, dev_name(dev), drv->name); goto done; @@ -656,7 +665,7 @@ static int really_probe(struct device *dev, struct device_driver *drv) /* Driver requested deferred probing */ dev_dbg(dev, "Driver %s requests probe deferral\n", drv->name); driver_deferred_probe_add_trigger(dev, local_trigger_count); - goto done; + break; case -ENODEV: case -ENXIO: pr_debug("%s: probe of %s rejects match %d\n", @@ -667,11 +676,6 @@ static int really_probe(struct device *dev, struct device_driver *drv) pr_warn("%s: probe of %s failed with error %d\n", drv->name, dev_name(dev), ret); } - /* - * Ignore errors returned by ->probe so that the next driver can try - * its luck. - */ - ret = 0; done: atomic_dec(&probe_count); wake_up_all(&probe_waitqueue); @@ -681,13 +685,14 @@ static int really_probe(struct device *dev, struct device_driver *drv) /* * For initcall_debug, show the driver probe time. */ -static int really_probe_debug(struct device *dev, struct device_driver *drv) +static int really_probe_debug(struct device *dev, struct device_driver *drv, + unsigned int *flags) { ktime_t calltime, rettime; int ret; calltime = ktime_get(); - ret = really_probe(dev, drv); + ret = really_probe(dev, drv, flags); rettime = ktime_get(); pr_debug("probe of %s returned %d after %lld usecs\n", dev_name(dev), ret, ktime_us_delta(rettime, calltime)); @@ -732,17 +737,18 @@ EXPORT_SYMBOL_GPL(wait_for_device_probe); * driver_probe_device - attempt to bind device & driver together * @drv: driver to bind a device to * @dev: device to try to bind to the driver + * @flags: PROBEF flags input/output * * This function returns -ENODEV if the device is not registered, -EBUSY if it - * already has a driver, and 1 if the device is bound successfully and 0 - * otherwise. + * already has a driver, and 0 if the device is bound successfully. * * This function must be called with @dev lock held. When called for a * USB interface, @dev->parent lock must be held as well. * * If the device has a parent, runtime-resume the parent before driver probing. */ -static int driver_probe_device(struct device_driver *drv, struct device *dev) +static int driver_probe_device(struct device_driver *drv, struct device *dev, + unsigned int *flags) { int ret = 0; @@ -761,9 +767,9 @@ static int driver_probe_device(struct device_driver *drv, struct device *dev) pm_runtime_barrier(dev); if (initcall_debug) - ret = really_probe_debug(dev, drv); + ret = really_probe_debug(dev, drv, flags); else - ret = really_probe(dev, drv); + ret = really_probe(dev, drv, flags); pm_request_idle(dev); if (dev->parent) @@ -847,6 +853,7 @@ static int __device_attach_driver(struct device_driver *drv, void *_data) struct device_attach_data *data = _data; struct device *dev = data->dev; bool async_allowed; + int flags = 0; int ret; ret = driver_match_device(drv, dev); @@ -870,7 +877,17 @@ static int __device_attach_driver(struct device_driver *drv, void *_data) if (data->check_async && async_allowed != data->want_async) return 0; - return driver_probe_device(drv, dev); + ret = driver_probe_device(drv, dev, &flags); + if (ret) { + /* + * Ignore errors returned by ->probe so that the next driver can + * try its luck. + */ + if (flags & PROBEF_DRV_FAILED) + return 0; + return ret; + } + return 1; } static void __device_attach_async_helper(void *_dev, async_cookie_t cookie) @@ -1026,10 +1043,11 @@ static void __device_driver_unlock(struct device *dev, struct device *parent) * @dev: Device to attach it to * * Manually attach driver to a device. Will acquire both @dev lock and - * @dev->parent lock if needed. + * @dev->parent lock if needed. Returns 0 on success, -ERR on failure. */ int device_driver_attach(struct device_driver *drv, struct device *dev) { + unsigned int flags = 0; int ret = 0; __device_driver_lock(dev, dev->parent); @@ -1039,7 +1057,7 @@ int device_driver_attach(struct device_driver *drv, struct device *dev) * just skip the driver probe call. */ if (!dev->driver) - ret = driver_probe_device(drv, dev); + ret = driver_probe_device(drv, dev, &flags); __device_driver_unlock(dev, dev->parent); @@ -1050,11 +1068,12 @@ static void __driver_attach_async_helper(void *_dev, async_cookie_t cookie) { struct device *dev = _dev; struct device_driver *drv; + unsigned int flags = 0; int ret; __device_driver_lock(dev, dev->parent); drv = dev->p->async_driver; - ret = driver_probe_device(drv, dev); + ret = driver_probe_device(drv, dev, &flags); __device_driver_unlock(dev, dev->parent); dev_dbg(dev, "driver %s async attach completed: %d\n", drv->name, ret); From patchwork Tue Jun 8 00:55: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: 12305009 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C43F2C48BCD for ; Tue, 8 Jun 2021 00:56:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B2D6661287 for ; Tue, 8 Jun 2021 00:56:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231338AbhFHA5y (ORCPT ); Mon, 7 Jun 2021 20:57:54 -0400 Received: from mail-bn8nam12on2067.outbound.protection.outlook.com ([40.107.237.67]:45339 "EHLO NAM12-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231295AbhFHA5v (ORCPT ); Mon, 7 Jun 2021 20:57:51 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ljuUipffp4LeVbQGCJ7sq6yptLpboKdO72Hi82ggs2Q4pg5SDFE09ykigRYswAK8t2Ur53BWfuUk4H6sgsFnirgQMuHXqXVmVxzrSBASg/jg6j8XVuNXAYASuU+wrH6YngHF9hZX4Fngu9EDb0ovo3nQipNNb46Ex7FpYp6W7jryjaC9lA7DSWFZcVM+y3r1tZzcLPqGTaeCApXoux0VhAsg2N0rw2+IeWUh9uonXWUMEkeIRw/YGtfhNZTLIdXJY5ljppWKfYhX2vPFAy3ncPpw92TIpBLyqRBU1azthzdoUZ2SOqqKkITggcu68lh61g9ji372KLYb1BO8NmOuXg== 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-SenderADCheck; bh=bJ8tRREbXzciCpeaClAgBQMttdC4ihdILwMxB1U0lM8=; b=edfucHWQFMjWcXhJpOWR5VJnUzea1IxvDAXe/UmwDXyIBOan7UeT+lZ1NMY5UJ0QBpI9dQtv5erRmc21t+91RfWbkd+kp4kXix9FM8msafJsD+ZfsiCKIYzIdoT7rqQ47sh2lDC2Igb2cLu6WMMeASVWcaQxqEpQGtZMqJPOpiNeOCdw3ME334Sq3ZHruikpk5aXZRMmTWxk6Hld0bjNhm02drRfX0qz0+0vBgq/IRvcf0jK/Vu/pxiw5MpCDjYA7PrIXTL+X7ysElJ3LG0B4QgNWl5SodE6m98Kci2h/Tw207xzekFAgw9jtGvNLww4Sq8OkMb5sbgo5Mi7I9aiIA== 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=bJ8tRREbXzciCpeaClAgBQMttdC4ihdILwMxB1U0lM8=; b=XLvdfGIL7F1D/zYUeSPlNGlYnb8s76q+CBw5rw4bErs5FhX2Kz41/jfqe445cVsT+p6VaJJP9ZkTXoJCCfjstsO7OXPeSgt7pDlOV8cpugyUzmi7ggsWHZXZF2rvmbkTYTWGa3OiPId1UoymWc0yGNlc2E9bhcI7dv+Fw+qiIVVzfLWdsH1+9eAJps0Ro5W36C/ic7cAzMkkzV1EAudcj2QyPqer8bPZwRiUo3lCKgkK+c6RGpSab/Z0xY8OHlqTIXjtziobeuR60nDsXwC3j7kWtNA0dWrGxpJ/z3rfT2zz9jx/NAxAqbMx9NzIrYlKLi+clLGgaPPqHqDKOlXEqg== Authentication-Results: linuxfoundation.org; dkim=none (message not signed) header.d=none;linuxfoundation.org; dmarc=none action=none header.from=nvidia.com; Received: from BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) by BL0PR12MB5539.namprd12.prod.outlook.com (2603:10b6:208:1c3::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.20; Tue, 8 Jun 2021 00:55:55 +0000 Received: from BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::3d51:a3b9:8611:684e]) by BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::3d51:a3b9:8611:684e%6]) with mapi id 15.20.4195.030; Tue, 8 Jun 2021 00:55:55 +0000 From: Jason Gunthorpe To: Greg Kroah-Hartman , kvm@vger.kernel.org, "Rafael J. Wysocki" Subject: [PATCH 04/10] driver core: Don't return EPROBE_DEFER to userspace during sysfs bind Date: Mon, 7 Jun 2021 21:55:46 -0300 Message-Id: <4-v1-324b2038f212+1041f1-vfio3a_jgg@nvidia.com> In-Reply-To: <0-v1-324b2038f212+1041f1-vfio3a_jgg@nvidia.com> References: X-Originating-IP: [47.55.113.94] X-ClientProxiedBy: BL1PR13CA0252.namprd13.prod.outlook.com (2603:10b6:208:2ba::17) To BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (47.55.113.94) by BL1PR13CA0252.namprd13.prod.outlook.com (2603:10b6:208:2ba::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4219.12 via Frontend Transport; Tue, 8 Jun 2021 00:55:54 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lqQ24-003eKW-H5; Mon, 07 Jun 2021 21:55:52 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7d3d86a3-815d-4f0e-e3a9-08d92a182b21 X-MS-TrafficTypeDiagnostic: BL0PR12MB5539: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:972; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TzH+9m6RLUz+cd5Vbvqj3/iwnsm9o/U4gCmbxC/XORCiC8SGyHfbv5WV6ryeBwtyC0VVH67ucOivj/2igYQjjc7j7He5TzonBD5n1TOISZlHwkWo1IHO7VYM0oI29eZhChk/iquVFDtAZYQLN8Hq8Uy8PywKLbZqd1i/zrxQzKsgM7aHbOvfCvZ6D2AxPq5Pi1E+JsskQM4cWuKPbOOs8A0Ob5wGlfP4wErhUoneamsY8CYE4MucKSjkAqk+jvyJyrG1OEdapotUAytOyGOTB1NkkGSKTue3QgerZzxPVbjkshxxwDtvR+3XbH90X35kn3G7kHBfrNx+XAylYYPHTNAua+213vNPGCDfE9TvriaIMu+OZn0wy/3punVlHqN31iIIXYud1AdbZJRKKtgfj3V7nGpA3PsUvIYv3BnydrXKbCLlaYj7C3nKonNNVHG0wN/HYQTvfYEoOKYfajUH1beIP5QpGIcbcoxnJS11E7AYa4qRmOxN6m/4SEDyixG/f1sd0hazs2ZlGaFav+JtA5IKp8okzmOPWCT0y7v2XDGgHANvlZKx0GtWpP3b79wj6xSH7TlwOe3BDHBJe+R7+R/gDvScP1uJX73u1JKyrG83R4dI8fX+L0LboDiN/0SuiptIAqtNinMoAY03mmDnGQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL0PR12MB5506.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(136003)(366004)(396003)(39860400002)(346002)(376002)(9786002)(186003)(26005)(36756003)(316002)(110136005)(8936002)(478600001)(9746002)(2906002)(6666004)(86362001)(83380400001)(66946007)(426003)(38100700002)(2616005)(5660300002)(8676002)(66476007)(66556008)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: p7ybQ9PyDWdaFK525m0ZmP7cJiuFp0q1hY5M4DTY4JxSg8Z86wv1mLMxzK0d0rftVcFFhsgahedzTGFW/r6gv6tSdzAhEKL1oHHPuFCcOMllqRbc2jYslcD5t3eK+MiYZEZdlwxzQyEp2kEwbz7JfhifKznpSASEr0nCGCEJTTHiDe2uM6w/Sdm0YPmT0aHhRXKJ94ImGg9dIFylzcMID0w/zgbAXAFCpoXtM9gKFSvB1bqc9xY6iJWh7aufLYaIvFSrRgiOp1M+1PJt4V/DCXYiz54ydLkR1clsNrCokpnsUXAk4ra2bXpvbKH8Xh7ZH8eaAdP++WPbtI/PYbJCgZOWC/0XWK68uuW0Gp9I7jOiD/DKMkeNN3hJ3kaJDvJHIh+7JpIILN9PQ9sj1tgK0sDbPGCfFeCPkvqD07DtJJGIfDMBTyaUi6jAviQ3pGHrpgSVuCz2qLnj7zOqo77hwj/7hDZ2CNiCy6BVHZHCpH6BGB4oYVPr/l49B7Eo8bcoI/jKaWeaWOmsnDOcw6TkKYRuMPE9JkSPmRIZ9/YjjJiyRZ2DdxieqZiZ8PSHMtw+xfwbZGFHzqV3N7t+5n5PtBgWw+aWhbkjB+yIm37tTk2gQ/VJJ0Yv5zQasorltYGVNtQeBiJPaoyMYjrCnJIlBsu3bQmg3YVy6XVwWM8MrMGYHsrSG9u0JAxUMwlPnNBV5W4BxbvwL1wgVzELE+wP369897t9U99JVW17Zqkd7ZsasH6y4vupaP7FnT2JaDWyERwjz71fI3ig+z8sW35huxW+i1LaP/M53r1G2p2iFVzjXu8q1QBIyvrlGdCuIZQIxy5l4SsgGur5xI1UMlTzjHRM/cmgXVWgMKDS4/B6DNpUpuEhGiODNhkY8kIaaM843HqlV1VeEnqVxCqEtADBd/daNmdcZT/RCTJL3D6Zkfhtwwv+LGAM8ZkQ/dsUwuurRiNmh16McPEi9XX9VYoUNN36kz1U9vQq7FHjHnoQ3SBdxmqLamq1f0f1yfBgBj8atuJjiAVYS+WxdnKicKy/EwdEN+MT2iBZhKcFjc0SvtPv5pspSY/43ZwqP6d+EkOnLkbR4tmjWlFES4OnOhKhBWaPoBE1j5ta544yhl7mTudnjVR3oMre6xD7hnDBZ/EqJWmEagf6ivKJ0wZlwhA5g5s/qkg9jd27+yBwaf71ljFh2Iav3+jUtyV+BJyJVROGflZg9kOIr2MiJi57E0JEVKCaVUDVVbT+E6hI9jcBVTwkcpje5mkCMFszr/DguAZ8pnENkZiOQlOFy59hWCZfE+xDDWRylvtAPzuz1m+q2O9N+zsz2LSzPV2kpnlLj0F/ X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7d3d86a3-815d-4f0e-e3a9-08d92a182b21 X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jun 2021 00:55:54.3098 (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: /By7hb9n+YM7byv1iXwLXmmJYXzFKlIlHzN/U2Yueo1MX9WO1oGSzYtbIHw+CwJ2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB5539 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org EPROBE_DEFER is an internal kernel error code and it should not be leaked to userspace via the bind_store() sysfs. Userspace doesn't have this constant and cannot understand it. Further, it doesn't really make sense to have userspace trigger a deferred probe via bind_store(), which could eventually succeed, while simultaneously returning an error back. Resolve this by preventing EPROBE_DEFER from triggering a deferred probe and simply relay the whole situation back to userspace as a normal -EAGAIN code. Put this in the device_driver_attach() so the EPROBE_DEFER remains contained to dd.c and the probe() implementations. Signed-off-by: Jason Gunthorpe --- drivers/base/dd.c | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/drivers/base/dd.c b/drivers/base/dd.c index 7fb58e6219b255..edda7aad43a3f7 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -516,12 +516,17 @@ static DEVICE_ATTR_RO(state_synced); enum { /* Set on output if the -ERR has come from a probe() function */ PROBEF_DRV_FAILED = 1 << 0, + /* + * Set on input to call driver_deferred_probe_add() if -EPROBE_DEFER + * is returned + */ + PROBEF_SCHEDULE_DEFER = 1 << 1, }; static int really_probe(struct device *dev, struct device_driver *drv, unsigned int *flags) { - int ret = -EPROBE_DEFER; + int ret; int local_trigger_count = atomic_read(&deferred_trigger_count); bool test_remove = IS_ENABLED(CONFIG_DEBUG_TEST_DRIVER_REMOVE) && !drv->suppress_bind_attrs; @@ -533,15 +538,18 @@ static int really_probe(struct device *dev, struct device_driver *drv, * wait_for_device_probe() right after that to avoid any races. */ dev_dbg(dev, "Driver %s force probe deferral\n", drv->name); - driver_deferred_probe_add(dev); - return ret; + if (*flags & PROBEF_SCHEDULE_DEFER) + driver_deferred_probe_add(dev); + return -EPROBE_DEFER; } ret = device_links_check_suppliers(dev); - if (ret == -EPROBE_DEFER) - driver_deferred_probe_add_trigger(dev, local_trigger_count); - if (ret) + if (ret) { + if (ret == -EPROBE_DEFER && *flags & PROBEF_SCHEDULE_DEFER) + driver_deferred_probe_add_trigger(dev, + local_trigger_count); return ret; + } atomic_inc(&probe_count); pr_debug("bus: '%s': %s: probing driver %s with device %s\n", @@ -664,7 +672,9 @@ static int really_probe(struct device *dev, struct device_driver *drv, case -EPROBE_DEFER: /* Driver requested deferred probing */ dev_dbg(dev, "Driver %s requests probe deferral\n", drv->name); - driver_deferred_probe_add_trigger(dev, local_trigger_count); + if (*flags & PROBEF_SCHEDULE_DEFER) + driver_deferred_probe_add_trigger(dev, + local_trigger_count); break; case -ENODEV: case -ENXIO: @@ -853,7 +863,7 @@ static int __device_attach_driver(struct device_driver *drv, void *_data) struct device_attach_data *data = _data; struct device *dev = data->dev; bool async_allowed; - int flags = 0; + int flags = PROBEF_SCHEDULE_DEFER; int ret; ret = driver_match_device(drv, dev); @@ -1043,7 +1053,9 @@ static void __device_driver_unlock(struct device *dev, struct device *parent) * @dev: Device to attach it to * * Manually attach driver to a device. Will acquire both @dev lock and - * @dev->parent lock if needed. Returns 0 on success, -ERR on failure. + * @dev->parent lock if needed. Returns 0 on success, -ERR on failure. If + * EPROBE_DEFER is returned from probe() then no background probe is scheduled + * and -EAGAIN will be returned. */ int device_driver_attach(struct device_driver *drv, struct device *dev) { @@ -1061,6 +1073,8 @@ int device_driver_attach(struct device_driver *drv, struct device *dev) __device_driver_unlock(dev, dev->parent); + if (ret == -EPROBE_DEFER) + return -EAGAIN; return ret; } @@ -1068,7 +1082,7 @@ static void __driver_attach_async_helper(void *_dev, async_cookie_t cookie) { struct device *dev = _dev; struct device_driver *drv; - unsigned int flags = 0; + unsigned int flags = PROBEF_SCHEDULE_DEFER; int ret; __device_driver_lock(dev, dev->parent); @@ -1083,6 +1097,7 @@ static void __driver_attach_async_helper(void *_dev, async_cookie_t cookie) static int __driver_attach(struct device *dev, void *data) { + unsigned int flags = PROBEF_SCHEDULE_DEFER; struct device_driver *drv = data; int ret; @@ -1128,7 +1143,9 @@ static int __driver_attach(struct device *dev, void *data) return 0; } - device_driver_attach(drv, dev); + __device_driver_lock(dev, dev->parent); + driver_probe_device(drv, dev, &flags); + __device_driver_unlock(dev, dev->parent); return 0; } From patchwork Tue Jun 8 00:55: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: 12305003 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D833C48BD1 for ; Tue, 8 Jun 2021 00:56:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 78C9361287 for ; Tue, 8 Jun 2021 00:56:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231321AbhFHA5w (ORCPT ); Mon, 7 Jun 2021 20:57:52 -0400 Received: from mail-bn8nam12on2067.outbound.protection.outlook.com ([40.107.237.67]:45339 "EHLO NAM12-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231283AbhFHA5t (ORCPT ); Mon, 7 Jun 2021 20:57:49 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CE/4gVUC8HXSzhwNOc0k1ASMLaUpPBxdX//IeF1/oc2ImOBfwBdCW6QL0s/HMWKcNe5LS3dAue/aCmHjMKwHg2J+7cs8ozS1CBnYny2RcVMkUJYCVdK5BK4UHjJYPLYu6NKWloLjrBUDGSt6m9J6u5JzTQXpOx++HGL4aJsbbD6Fum8/WwIGqIjxSt5EcgpmKQmPTV3OJSEzkaauuByxb/+JI+297Bb10epJMkwAAIzKrmSAxJIuxjho1lfl+D7lQAH0EgU0Q3IT7zgOSaRRWF+D2Dmbgg/qUH5FClB1nxk+iN6NH0GdZBFayroo6uge1IKd11MwiKbfr2cmnDY3/g== 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-SenderADCheck; bh=0Ix+R4jEwhvzrwBmdWPBSZUKcnvnwI9m1C6x8Q1R8Xk=; b=BCW6QdSkFgDRmhG5NGq6QBLfHGmGr+/xUxFH+JlY97E7kzXLRNLV3wI9DYpIHdNH3bG4Y6WTNqHiFB/7RnFTlrl2Rcb8ojhknafLka5wjvwlSnp9ae5/j6B/A2V+6MmPSm+qybXbW/AZeZlTLcr9xzE8ylucfMH+bjoOaGj1e0Z8q99pyNOw7el5z0nSktz61MI46IFcxzCcHcg5TBwb6GbyNM+4cuy9P0fJteECxH+ZY0ooJhJx+xumBoY55PU/9XWiHmk19ViQQVqeLWPGO+m0zJpKfxCBv7XBOQoQsVvCWSMQQFVoUdJdHiKK59b4l2Spv6W+y99XVvEz9Th8BA== 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=0Ix+R4jEwhvzrwBmdWPBSZUKcnvnwI9m1C6x8Q1R8Xk=; b=RCn2+n9Dmc6OxEoAHeLYXP/Kkc312KbuWICVuE72hUa2gVRA/+pD+Yvz7csf5b6ZIyS8QbqC8JelR0bNbyNwu1VF07F6e/2eupGTku7q8yw1Ltqj4WD+6868XBGUhf6VDdb05ETvp5sXUpYCP36YkdfRslv4wg3DQrkVGLBKGHG4CG7JiB3KeTEskQzSfp286mGFgMKNzfsLiW9CuUJxJII9EAShjj5Zsa7BU60Kjc9i6cGtrdV832Y1jwyfMT9NnXTmw19J8pgAbaKgPw8w6P3X3gkggLWTVwHji6um/1ueQCSUz8gUYRBgrgtYBFI++xGkmpMa2v1T/fEe5tr/Ig== Authentication-Results: linuxfoundation.org; dkim=none (message not signed) header.d=none;linuxfoundation.org; dmarc=none action=none header.from=nvidia.com; Received: from BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) by BL0PR12MB5539.namprd12.prod.outlook.com (2603:10b6:208:1c3::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.20; Tue, 8 Jun 2021 00:55:55 +0000 Received: from BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::3d51:a3b9:8611:684e]) by BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::3d51:a3b9:8611:684e%6]) with mapi id 15.20.4195.030; Tue, 8 Jun 2021 00:55:55 +0000 From: Jason Gunthorpe To: Greg Kroah-Hartman , kvm@vger.kernel.org, "Rafael J. Wysocki" Subject: [PATCH 05/10] driver core: Export device_driver_attach() Date: Mon, 7 Jun 2021 21:55:47 -0300 Message-Id: <5-v1-324b2038f212+1041f1-vfio3a_jgg@nvidia.com> In-Reply-To: <0-v1-324b2038f212+1041f1-vfio3a_jgg@nvidia.com> References: X-Originating-IP: [47.55.113.94] X-ClientProxiedBy: BL1PR13CA0259.namprd13.prod.outlook.com (2603:10b6:208:2ba::24) To BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (47.55.113.94) by BL1PR13CA0259.namprd13.prod.outlook.com (2603:10b6:208:2ba::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4219.11 via Frontend Transport; Tue, 8 Jun 2021 00:55:54 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lqQ24-003eKa-IM; Mon, 07 Jun 2021 21:55:52 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d62b007d-91ea-4c67-00bd-08d92a182b1f X-MS-TrafficTypeDiagnostic: BL0PR12MB5539: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6790; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RzdSBAmRk88MUGHREpp1vZy3Th05Z1vMAULe2500BAbTJnlzFb2D3SdAoGIWZoQuPIUVchimNa0idOEwkOexuajYVp8mfQmVkxBAIRGfKWtlFio1mmVzapq/idofwVIwZaTY3XtZyJs7JFUWI1WgbITYwmkNqDfyYABm7pdRW/1P4MqQSFrjfNclhZWJ4dBBj6wW6gLbPcLT3caH+PNSbcgDMZ6SYpjmO/6Lx4zJditZZumsqHbctk6VPmk5zu59MNO8Rls6Nk2/dfk5lk5THeWPoY4qqUR+Tn5LHkz7nwhjmR+Iqr1dwWg+rk2/cAu7wf6b9oODZNQm2fPzobTZqrt9RjbKCX3YgQT44rHVWiqOWC62VUzQa31t7Jx0sZEQN4HOpwgR25Yl8/O0zT6N1D3nuglN16/u+WD6o/0agweB0ltibe3akCNKofUj2gozTRkzLIHviitftqOwtKFQbfJDAwE7I5uXxjmVpinAn/u1Ub14wQI+6U8Bj4RgzFfrXwPfN1xJwt2R2072xQDiceBliiWrTO/3EDkr0h1AnYF+xnh8ajwDMpvtnGz58tJacrg1gskP1yiJ1WWWcZ2N3n/Ch6cDdj6WnEQjOvZQW/mqHBZ33rGNil14duBTDwZtuIDGTMlogopZkykvoKHrWg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL0PR12MB5506.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(136003)(366004)(396003)(39860400002)(346002)(376002)(9786002)(186003)(26005)(36756003)(316002)(110136005)(8936002)(478600001)(9746002)(2906002)(6666004)(86362001)(83380400001)(66946007)(426003)(38100700002)(2616005)(5660300002)(8676002)(66476007)(66556008)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: srDRx+WmPss1c55RBAO/xotQMOfBYeB5DeBcFgME2rbW/dduuFosDQTqTcwcHoHUqiB+YZ5RYO3FKTWy2Sq4tHVxbu4Vi1AQV8lL9GbwaZX8VnSDngYr38s/EiIcXpY96WyPUcrgE2R2uyx908czokHXlaVLzmGS4NfdXVFMieH0WopMZ+MHZ4HkvuIzDTonjCxXMz12ADHZjVgQrXtw6Cu7VKSKIXlzzWrp0Bc/2GmEVn7XzaS3D27utH7cajcnG5uXXYGJfboXbXIBJqFpSOxsmcP6X1+u/rIY2Jfmxb2iD1TgjTfUHjTQhfJSCVj+vYydpUnXrW5RJF2+FbiK43T06lKFEcJWpLiw2DiK387kyYwXhrx5WAkKYrYz5f6TB/foB5ZrqNJ6YuIgkxoO4RLZwrTdjXFE4nXMeviu+fGt/wK0Qp/nQ2LEAOBTwQVS+YXiqjwWDFYSueIU/cH8s7+IAo1nASIxt93INmQu90o4EyWIfYmBVSGCeffMJTrPrOGG8PY9y9rHHcU+JwIgokEHFgc/ltNwhs14rvOw67Fs6gvnBWboYW+5kowF7sRm3BfN8f0laMH/EH+KXvk/cVoMJjDT2rwab0hzbr6jE/BspFA8WDK5+wDLawOo3iKnb81xmOgRFkpPh1OTalloIZIOW62lbyHezDKFzhaXRiYNpMu0Eepx1kLVzKVptQw6Dz81oEBTyEZ16Kr4PvFPzNWy0yvzyzmdEbmwI0okpkQzfFNBO+BC7/Aoxx4f1Gn2QCcvIEemahzhX0xuAf+BZ6qyFCKA9EEFYXYGdV76jDdKibvd+NH25PE8wFVm5PV8W/T2Iari2+wgYDx9rvUni1U5ks8ejsH8rN9ZOvv8UL0ZckRY8QTJWyEQ+fCMv9Mtw0OvhR0unjRBfOCuAn9RyOojCd5NPkWWEcyw5IBqAQ9EbCXMgPXggkh2qbHkXdIsvN/HCwn2Yeg2tkMkSyU7YYAeEcUqHCIyXnqn7VEw6p01r3+bpPS1HPL+PmgOea/z/MAH9Z6kR+jsax88q5nZeA6LcyVRjhVIMO5YF8a6n/ouOPBXooRY6LdoMnbO1Wjr7pfq3VTRZ4FFAXYeLYEzqJD71m/CgRZrfLLFrsAXcMPFo0ynJuv1H0XCobF+9CQkKTEskJAB167cWujLjol8NPOTesH9DMq/wvezN5YWEW5II4w6gFF5ft/jBKJE4LEGtwNQoRyfZzKXXvwyupKnmrBMMJ0qI5YhTdO5GYoNxAHJ0wpTHSPRyqvd5e3iGbQ9r//ehw5w/jQCEovm0rxQ0NNxmGuAq7CKtQC6xKlLsCkJdsV60RDEBVxqKGd5dtwD X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: d62b007d-91ea-4c67-00bd-08d92a182b1f X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jun 2021 00:55:54.2182 (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: LrUR60jv2/cEZa1ZYBkhlamV5eMrR1VZZGtVzDO5cwVCA1o8cInrmSqy9F6P06Rd X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB5539 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This is intended as a replacement API for device_bind_driver(). It has at least the following benefits: - Internal locking. Few of the users of device_bind_driver() follow the locking rules - Calls device driver probe() internally. Notably this means that devm support for probe works correctly as probe() error will call devres_release_all() - struct device_driver -> dev_groups is supported - Simplified calling convention, no need to manually call probe(). The general usage is for situations that already know what driver to bind and need to ensure the bind is synchronized with other logic. Call device_driver_attach() after device_add(). If probe() returns a failure then this will be preserved up through to the error return of device_driver_attach(). Signed-off-by: Jason Gunthorpe --- drivers/base/base.h | 1 - drivers/base/dd.c | 3 +++ include/linux/device.h | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/base/base.h b/drivers/base/base.h index e5f9b7e656c34b..404db83ee5ecb5 100644 --- a/drivers/base/base.h +++ b/drivers/base/base.h @@ -152,7 +152,6 @@ extern int driver_add_groups(struct device_driver *drv, const struct attribute_group **groups); extern void driver_remove_groups(struct device_driver *drv, const struct attribute_group **groups); -int device_driver_attach(struct device_driver *drv, struct device *dev); void device_driver_detach(struct device *dev); extern char *make_class_name(const char *name, struct kobject *kobj); diff --git a/drivers/base/dd.c b/drivers/base/dd.c index edda7aad43a3f7..9a5792527326b7 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -471,6 +471,8 @@ static void driver_sysfs_remove(struct device *dev) * (It is ok to call with no other effort from a driver's probe() method.) * * This function must be called with the device lock held. + * + * Callers should prefer to use device_driver_attach() instead. */ int device_bind_driver(struct device *dev) { @@ -1077,6 +1079,7 @@ int device_driver_attach(struct device_driver *drv, struct device *dev) return -EAGAIN; return ret; } +EXPORT_SYMBOL_GPL(device_driver_attach); static void __driver_attach_async_helper(void *_dev, async_cookie_t cookie) { diff --git a/include/linux/device.h b/include/linux/device.h index 38a2071cf77685..d03544f04aa9ee 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -847,6 +847,8 @@ static inline void *dev_get_platdata(const struct device *dev) * Manual binding of a device to driver. See drivers/base/bus.c * for information on use. */ +int __must_check device_driver_attach(struct device_driver *drv, + struct device *dev); int __must_check device_bind_driver(struct device *dev); void device_release_driver(struct device *dev); int __must_check device_attach(struct device *dev); From patchwork Tue Jun 8 00:55: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: 12305007 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 45BA8C48BCF for ; Tue, 8 Jun 2021 00:56:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2D37661263 for ; Tue, 8 Jun 2021 00:56:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231327AbhFHA5x (ORCPT ); Mon, 7 Jun 2021 20:57:53 -0400 Received: from mail-mw2nam10on2041.outbound.protection.outlook.com ([40.107.94.41]:6904 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231287AbhFHA5u (ORCPT ); Mon, 7 Jun 2021 20:57:50 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mq/kkIus3mEbqcU3RRjOpRsd8QMlnXa02ornTdlAZOijPA0hSyFzUfVp52YFzlbaC7ZKidZFZE5uUpu2w+3xPVu/SbeEZZcLKTcAOAcyqbT7Vv4DXY9nn+gtlMaIE5yoRE9EZJAz1SK0SzOVVIdKt3PzteatHiG3f3N7K9qgGT4QAamp28RKkZLERLuP8ZS6ZEQjw2U2bY6C0bJlCyDdM/EFpUZa1H88qtZ615FCFL9O4TcLRntDkRde1ZWcE9mMxB71RejOgvigCDMHzSE6MDQM0ZLNhcbPQ65WasRjFo4CwwDs5ToJGvSo6Pvsb4cUXonM+ZWUSjNm1brT0jAMvQ== 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-SenderADCheck; bh=KbNUseuZfVmjOEc5NUfvlTUktAPBtyinUwz8YfOVMPg=; b=KGGJdRNbdntqYj8BPKk07scmLjSVvsrBrAdZjGNjSwTtHME7yCXbKG8NKQmqGUTVdYU0HBRANqItNGigCEEelf6hA+CZfeV7W8wcPhCA21smswVeYsM8IIetoWnfzWEL0Mezo7VP0fonmxYqwo0x2LnfdCv3WI+b8tfRUhNHoy6w4W5RFz2JOciS1BRt61CmfaiqHtcuBd28pGOnHUL+B1i0zLiPXurDuH21/PVBFJLue+ex7LJIcyeAD/ArQsVaG1e5iRcxdml3MuEspVOj0T3TeP9O6tB05QhAMkGs+sQxw4Uyf9FV1NcYfnBNdcQmGwQzHtO2/1iB5DCfiDZpJg== 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=KbNUseuZfVmjOEc5NUfvlTUktAPBtyinUwz8YfOVMPg=; b=YSdGL3kZVdxaUYYvcHBAI5MPDLdLCCi4hhlcKwuz1HPUo0P0S29I+Gwmle/NL0c/5xw9FcAv2EiRGNUHykAx/zajRogtRWiM8XIchfVn7MIDYoJ2WQ0j5CxWrxOdIusLddIRbm1SwEYmQ2BMri3z6k3IEtgW1zZhOkm3RVoHiHvLP4R54a9NRrqCbMtXs46FofyQKMSSYpypsvahXS4z0Di/jnNIMAODd9GOKWInvdpGw1dmo4E+r2ivq4HPa/vcz9YZwD1gVRC4Ik1UkHS0UkfMXKnmdMFoxV+zH9oVbZooC/NFyemOIMD98nA7NhXSRR6YEwznUn3Cqbgdwc6LeQ== 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 BL1PR12MB5095.namprd12.prod.outlook.com (2603:10b6:208:31b::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.24; Tue, 8 Jun 2021 00:55:56 +0000 Received: from BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::3d51:a3b9:8611:684e]) by BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::3d51:a3b9:8611:684e%6]) with mapi id 15.20.4195.030; Tue, 8 Jun 2021 00:55: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, Vasily Gorbik , Heiko Carstens , intel-gfx@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, Halil Pasic , Rodrigo Vivi Subject: [PATCH 06/10] vfio/mdev: Remove CONFIG_VFIO_MDEV_DEVICE Date: Mon, 7 Jun 2021 21:55:48 -0300 Message-Id: <6-v1-324b2038f212+1041f1-vfio3a_jgg@nvidia.com> In-Reply-To: <0-v1-324b2038f212+1041f1-vfio3a_jgg@nvidia.com> References: X-Originating-IP: [47.55.113.94] X-ClientProxiedBy: MN2PR12CA0027.namprd12.prod.outlook.com (2603:10b6:208:a8::40) To BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (47.55.113.94) by MN2PR12CA0027.namprd12.prod.outlook.com (2603:10b6:208:a8::40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.22 via Frontend Transport; Tue, 8 Jun 2021 00:55:54 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lqQ24-003eKf-Jw; Mon, 07 Jun 2021 21:55:52 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7939e776-df59-4890-810c-08d92a182b52 X-MS-TrafficTypeDiagnostic: BL1PR12MB5095: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VGR42DYmEGs4GTGIsT5gaXSTcx0PZ4WIhi9EqscIvIOG9iMGEAc4XAIdDZlKYfrrmOcp5LWxDiBtSbs9GpnCkDT5OSvn/bfT1afRjnzi6nK0dapHvvwGKH2GaeBtlHeN4QwW+k4R1RZQDh44wqPjIAxO6DsKEioTofF6NKaFyqH1SWWoAUevUqvxSXzQ5pRbJzV18MgMYar++wC0P1bIfb3HpEQ5nkVM2BnCA5HH8TqEReKTrkzU9KovoLOKmVaEE+b0mUVvjVu54uuzmsgV4mbQVc3VRSAUgf1igrYyeZ24YWj23uw+mnTK5DRg7xEhjifWvkJhF03lWC8cA0yYTHDUpn0gB4/0sX/goVbT1Gals5B05QN+x9pbYGEMXRIQHqqqJtNUfxP1eDtWnGbJla5REZLOFtCwHOI24w7NGT0DwSMBWqCO318ZNaf4mFQcXqyANy/4s5Q7Sl56nKWZapGT9JJFqmR5zeve6cSVCDB+HQMrsux+8F0krFiFKn7anZ+tosZ/7Z98XoZ81GSSC/AY+rV0npObPxGXte/ZUKEig6Xf+LikD0Bt7IQeoyMvF0kK38aYuV57sjey6g2D3ZEwBcV2ogWkNO6jwigQ0vTn9y8Hmy8H3t/x6aEx/sopxi/PoGOQkUtfV0Mb2Kobk1qdW1DGFKH9Z3O9C5nbTGs= 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)(39860400002)(376002)(136003)(346002)(366004)(396003)(110136005)(2616005)(86362001)(9746002)(66556008)(2906002)(36756003)(186003)(921005)(9786002)(478600001)(426003)(66476007)(83380400001)(8936002)(8676002)(26005)(66946007)(5660300002)(316002)(38100700002)(6666004)(7416002)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: gRt1PpQQ2kRrvz4ElF3VaHbWNq5l5lWbNwUNH+dYXSGw3omgD1GGylZjvvZtfXbYNrkvXpo8o6L2DsHyhJsZ0zdx/Umqkcn65DVzoeTjBX7hXgvkvDYeloIcG+Gvj6BzH2KjWbwThFS60Kl/02qsoJLcD+OuxnIzlMWTkzPhkVYB073Xw2jtNuMoYBL4AOfW7NyOW5O9MJCmYWtELujbN1r6SxwY7ooqhvCpd5E/p8rxoC1lLyLav33rJ2HGdFpE9oHY/Mq17mDTs7euqlz4f84L7WSKtYypLu3tenVS1B03U/Zu32HHbuAyhgNGRubv2j0kzFHdF8Ge72oZK9jp2qhzuhCaILV6SY/QX6DJUt7RnKswp/S+rTxihXeuV/ZmbRuXPS3Lbb86aiqUPfy9lSA2oDFmqrvcn7LvA/+hArE86NjkYwEDokG/ZDrPbwE7usKhMxxrDsnr/jPc/L4pCH6mSkTyqPm4yWfb2xHbbWbbrgu+W+L2Kpe/Y2H8wTsgAcFhAwcDxWlFcmSCXQLJ4PID3RIf6ye9hPevdaZkf903sBRW7uuGQycgzE0qdEB7fVDqdrSz0sBZidNQClsrauCW03fDCwBlwNIRRiHm7F2LejnNUl5Y6B1TLRfXZZq4hnP4InOTficakHt+wPPcFQcpJZfAMhLKZrwnJxcHiU1vNkVOaR+fj45XaJCNntUvkxlU8Kna80TGKMIdgQ+ilIPwcjYY1kkE+QwdVI20ZuHV7kEIJFfb7aRbHcbGdY4Z1vD1gUoexUv0HDFmRifMEc0fikF7AjCi7PQadZqjaDf52e9Dg1PPPpFiJu1GzwFPgA0eCEPds+oMLZuPHtwhAV7hH0WCobjQ850ERmtNlEw8ps95n4jDcCiHQmASn2mk6vXbckFBQNGwxTyr+GP1oWPFZ5axRzsKYJ/XLyzHX46tTBcPoXLyW6NTj84V0iwFFUuQZtyyiLQ37aoI+3CwyQo7lxcWmj4hz0+v17HCQBLZxaHETgTjZi8juzJnWD0r5sLJ5xrrn4obSRFD9VWMduzj8zV+grVlEAg3JX4Q72IYFR90rjOzB6lumGwBNEuEC1qLdVbCuG4+tAdNmlYrJrwtKR50kqhjBhLkHOMLYVQXcExC/t5GkBH6NWYj3onGLV+xrwlou95ywW38OmNgktgUuW/41yDiNyHyb/KGHbYVJ2YtmcmmW2pjuzzBtVAOX63jkOKhA19nivVPdyYiTwMi6Ga4AJtIjccIXiofXLu/UsDjbImRgRk9/HcjQME3LF0ceJ4OEGtq1m7w77ZOt//dGZfCqSCBN5Pvqhq5htpCGHr5zTKYhbh64ZHxj8Ii X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7939e776-df59-4890-810c-08d92a182b52 X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jun 2021 00:55:54.6245 (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: TTbb6Ss7UtjIqAOXQuYZAEyb5q3lbmmh+5pl5NwgfgNdo9kUW0JtpVsFESagjd7o X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5095 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org For some reason the vfio_mdev shim mdev_driver has its own module and kconfig. As the next patch requires access to it from mdev.ko merge the two modules together and remove VFIO_MDEV_DEVICE. A later patch deletes this driver entirely. Signed-off-by: Jason Gunthorpe Reviewed-by: Christoph Hellwig Reviewed-by: Cornelia Huck --- Documentation/s390/vfio-ap.rst | 1 - arch/s390/Kconfig | 2 +- drivers/gpu/drm/i915/Kconfig | 2 +- drivers/vfio/mdev/Kconfig | 7 ------- drivers/vfio/mdev/Makefile | 3 +-- drivers/vfio/mdev/mdev_core.c | 16 ++++++++++++++-- drivers/vfio/mdev/mdev_private.h | 2 ++ drivers/vfio/mdev/vfio_mdev.c | 24 +----------------------- samples/Kconfig | 6 +++--- 9 files changed, 23 insertions(+), 40 deletions(-) diff --git a/Documentation/s390/vfio-ap.rst b/Documentation/s390/vfio-ap.rst index e15436599086b7..f57ae621f33e89 100644 --- a/Documentation/s390/vfio-ap.rst +++ b/Documentation/s390/vfio-ap.rst @@ -514,7 +514,6 @@ These are the steps: * S390_AP_IOMMU * VFIO * VFIO_MDEV - * VFIO_MDEV_DEVICE * KVM If using make menuconfig select the following to build the vfio_ap module:: diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig index b4c7c34069f81a..ea63fd22e1198a 100644 --- a/arch/s390/Kconfig +++ b/arch/s390/Kconfig @@ -768,7 +768,7 @@ config VFIO_CCW config VFIO_AP def_tristate n prompt "VFIO support for AP devices" - depends on S390_AP_IOMMU && VFIO_MDEV_DEVICE && KVM + depends on S390_AP_IOMMU && VFIO_MDEV && KVM depends on ZCRYPT help This driver grants access to Adjunct Processor (AP) devices diff --git a/drivers/gpu/drm/i915/Kconfig b/drivers/gpu/drm/i915/Kconfig index 69f57ca9c68d73..9ab1cecd69b2a0 100644 --- a/drivers/gpu/drm/i915/Kconfig +++ b/drivers/gpu/drm/i915/Kconfig @@ -126,7 +126,7 @@ config DRM_I915_GVT_KVMGT tristate "Enable KVM/VFIO support for Intel GVT-g" depends on DRM_I915_GVT depends on KVM - depends on VFIO_MDEV && VFIO_MDEV_DEVICE + depends on VFIO_MDEV default n help Choose this option if you want to enable KVMGT support for diff --git a/drivers/vfio/mdev/Kconfig b/drivers/vfio/mdev/Kconfig index 5da27f2100f9bd..763c877a1318bc 100644 --- a/drivers/vfio/mdev/Kconfig +++ b/drivers/vfio/mdev/Kconfig @@ -9,10 +9,3 @@ config VFIO_MDEV See Documentation/driver-api/vfio-mediated-device.rst for more details. If you don't know what do here, say N. - -config VFIO_MDEV_DEVICE - tristate "VFIO driver for Mediated devices" - depends on VFIO && VFIO_MDEV - default n - help - VFIO based driver for Mediated devices. diff --git a/drivers/vfio/mdev/Makefile b/drivers/vfio/mdev/Makefile index 101516fdf3753e..ff9ecd80212503 100644 --- a/drivers/vfio/mdev/Makefile +++ b/drivers/vfio/mdev/Makefile @@ -1,6 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only -mdev-y := mdev_core.o mdev_sysfs.o mdev_driver.o +mdev-y := mdev_core.o mdev_sysfs.o mdev_driver.o vfio_mdev.o obj-$(CONFIG_VFIO_MDEV) += mdev.o -obj-$(CONFIG_VFIO_MDEV_DEVICE) += vfio_mdev.o diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c index 2a85d6fcb7ddd0..ff8c1a84516698 100644 --- a/drivers/vfio/mdev/mdev_core.c +++ b/drivers/vfio/mdev/mdev_core.c @@ -360,11 +360,24 @@ int mdev_device_remove(struct mdev_device *mdev) static int __init mdev_init(void) { - return mdev_bus_register(); + int rc; + + rc = mdev_bus_register(); + if (rc) + return rc; + rc = mdev_register_driver(&vfio_mdev_driver); + if (rc) + goto err_bus; + return 0; +err_bus: + mdev_bus_unregister(); + return rc; } static void __exit mdev_exit(void) { + mdev_unregister_driver(&vfio_mdev_driver); + if (mdev_bus_compat_class) class_compat_unregister(mdev_bus_compat_class); @@ -378,4 +391,3 @@ MODULE_VERSION(DRIVER_VERSION); MODULE_LICENSE("GPL v2"); MODULE_AUTHOR(DRIVER_AUTHOR); MODULE_DESCRIPTION(DRIVER_DESC); -MODULE_SOFTDEP("post: vfio_mdev"); diff --git a/drivers/vfio/mdev/mdev_private.h b/drivers/vfio/mdev/mdev_private.h index 6999c89db7b162..afbad7b0a14a17 100644 --- a/drivers/vfio/mdev/mdev_private.h +++ b/drivers/vfio/mdev/mdev_private.h @@ -37,6 +37,8 @@ struct mdev_type { #define to_mdev_type(_kobj) \ container_of(_kobj, struct mdev_type, kobj) +extern struct mdev_driver vfio_mdev_driver; + int parent_create_sysfs_files(struct mdev_parent *parent); void parent_remove_sysfs_files(struct mdev_parent *parent); diff --git a/drivers/vfio/mdev/vfio_mdev.c b/drivers/vfio/mdev/vfio_mdev.c index 922729071c5a8e..d5b4eede47c1a5 100644 --- a/drivers/vfio/mdev/vfio_mdev.c +++ b/drivers/vfio/mdev/vfio_mdev.c @@ -17,10 +17,6 @@ #include "mdev_private.h" -#define DRIVER_VERSION "0.1" -#define DRIVER_AUTHOR "NVIDIA Corporation" -#define DRIVER_DESC "VFIO based driver for Mediated device" - static int vfio_mdev_open(struct vfio_device *core_vdev) { struct mdev_device *mdev = to_mdev_device(core_vdev->dev); @@ -151,7 +147,7 @@ static void vfio_mdev_remove(struct mdev_device *mdev) kfree(vdev); } -static struct mdev_driver vfio_mdev_driver = { +struct mdev_driver vfio_mdev_driver = { .driver = { .name = "vfio_mdev", .owner = THIS_MODULE, @@ -160,21 +156,3 @@ static struct mdev_driver vfio_mdev_driver = { .probe = vfio_mdev_probe, .remove = vfio_mdev_remove, }; - -static int __init vfio_mdev_init(void) -{ - return mdev_register_driver(&vfio_mdev_driver); -} - -static void __exit vfio_mdev_exit(void) -{ - mdev_unregister_driver(&vfio_mdev_driver); -} - -module_init(vfio_mdev_init) -module_exit(vfio_mdev_exit) - -MODULE_VERSION(DRIVER_VERSION); -MODULE_LICENSE("GPL v2"); -MODULE_AUTHOR(DRIVER_AUTHOR); -MODULE_DESCRIPTION(DRIVER_DESC); diff --git a/samples/Kconfig b/samples/Kconfig index b5a1a7aa7e23ab..b0503ef058d334 100644 --- a/samples/Kconfig +++ b/samples/Kconfig @@ -154,14 +154,14 @@ config SAMPLE_UHID config SAMPLE_VFIO_MDEV_MTTY tristate "Build VFIO mtty example mediated device sample code -- loadable modules only" - depends on VFIO_MDEV_DEVICE && m + depends on VFIO_MDEV && m help Build a virtual tty sample driver for use as a VFIO mediated device config SAMPLE_VFIO_MDEV_MDPY tristate "Build VFIO mdpy example mediated device sample code -- loadable modules only" - depends on VFIO_MDEV_DEVICE && m + depends on VFIO_MDEV && m help Build a virtual display sample driver for use as a VFIO mediated device. It is a simple framebuffer and supports @@ -178,7 +178,7 @@ config SAMPLE_VFIO_MDEV_MDPY_FB config SAMPLE_VFIO_MDEV_MBOCHS tristate "Build VFIO mdpy example mediated device sample code -- loadable modules only" - depends on VFIO_MDEV_DEVICE && m + depends on VFIO_MDEV && m select DMA_SHARED_BUFFER help Build a virtual display sample driver for use as a VFIO From patchwork Tue Jun 8 00:55: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: 12305011 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 18DDBC47082 for ; Tue, 8 Jun 2021 00:56:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0473B6127A for ; Tue, 8 Jun 2021 00:56:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231347AbhFHA5z (ORCPT ); Mon, 7 Jun 2021 20:57:55 -0400 Received: from mail-mw2nam10on2041.outbound.protection.outlook.com ([40.107.94.41]:6904 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231312AbhFHA5w (ORCPT ); Mon, 7 Jun 2021 20:57:52 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BJJIyiBJqGw3rHohzPZaAgGLbDkutkMf1Ove7fuHFqt1JDaaEqGqLE0G5hE5qwHgT70Kjnqs1dGaGAOjqDc4nX8ZSw/L7tcvtze/u8maSJ32adH4qZBe8A2TDe/dfFIqdiZn+J/XJuYvNSNAQC5EJPhD9ocF/pgOwngwxJnZkoeI2n/VWlOFIiDDLEu/zp1MupvhlW16MNQAmCpBMmp5sSdcFZeILiOGT6bB/cSgPU5nzE60FzPkzyYvqONeiMhrblnFdX7ox0mbr8obSDiBu663QjI/Zv5C2jeWCldwkeOJW3u0ZI/3lKGgiZVT+wII5xTvMDv2OJCDel1UfFM4ig== 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-SenderADCheck; bh=vDTfNFaZujEsiIadzqsEi24VY7P/+itStba7KX2NQCQ=; b=ciAhMK679UNQzRyr9fNzglR+FNd34SOneO8jZdYHw8dfXUdak76ATXXwnmJ91KCUFM4YI8r91xh7CrIUa0yqrryQrrDbvvUDx82Xw6Ef3mSUXn+TqkkDeuJZy4GS+T4tOnjXu8K8xSz8rsX26fM766n+DxoNKxzczb85ZnJ3hCNol99APYjilTdQMI8qdUyqss5abmF2RiBBcit3xDnUobIoU3HN5LxlGGBDlBot/sypYrQw+HBOGDCPgoWPE07pa/USeEseey5l7HAFkR/ylWl3mduvNBcHfXuEeE1aIPv4Ii1FZMXkxdVvsfpR+ttG2QUQM+Mnh5KgdkjVdqNEiA== 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=vDTfNFaZujEsiIadzqsEi24VY7P/+itStba7KX2NQCQ=; b=uke3z7k/R70t7L6llwlC0f3xE1qVOIUDkim8MRdcij+T2b920QOv1LysPnrDX4mHnm/sZXo+kGjRbNArHOLxsAMEIVFqtN4/x1+Vgrick1Vsnh+oUcoWt5qiKyYiYG8PUEE/ZC53jQPNCBnz+I454qFB0fNMAOPqVUHBRNAa6iMpTzdkDLZbnJc7JWqIZX1IrGVtO6xJuG7s74r6BgefdaVYwQBq+dgwueEEszsCyz85ltUGxHOe1XjBPyIgYn+jMw+gSjc2nRih/iL1bUTb4OP2rGRZYZXgy6B4iNSS91/NhWtHTUqrjh/w7D+bRohhpqyFkXhvRXmVeW4YExYoSg== Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=nvidia.com; Received: from BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) by BL1PR12MB5095.namprd12.prod.outlook.com (2603:10b6:208:31b::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.24; Tue, 8 Jun 2021 00:55:57 +0000 Received: from BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::3d51:a3b9:8611:684e]) by BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::3d51:a3b9:8611:684e%6]) with mapi id 15.20.4195.030; Tue, 8 Jun 2021 00:55:57 +0000 From: Jason Gunthorpe To: Alex Williamson , Cornelia Huck , kvm@vger.kernel.org, Kirti Wankhede Subject: [PATCH 07/10] vfio/mdev: Allow the mdev_parent_ops to specify the device driver to bind Date: Mon, 7 Jun 2021 21:55:49 -0300 Message-Id: <7-v1-324b2038f212+1041f1-vfio3a_jgg@nvidia.com> In-Reply-To: <0-v1-324b2038f212+1041f1-vfio3a_jgg@nvidia.com> References: X-Originating-IP: [47.55.113.94] X-ClientProxiedBy: BL1PR13CA0258.namprd13.prod.outlook.com (2603:10b6:208:2ba::23) To BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (47.55.113.94) by BL1PR13CA0258.namprd13.prod.outlook.com (2603:10b6:208:2ba::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4219.11 via Frontend Transport; Tue, 8 Jun 2021 00:55:55 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lqQ24-003eKi-L3; Mon, 07 Jun 2021 21:55:52 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8fe5deee-59b6-447f-1aca-08d92a182bcd X-MS-TrafficTypeDiagnostic: BL1PR12MB5095: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9We0iM/Xjr1OTDZ7fw9jY24Mvnye9vmqXALWmQiPOuWI+KyvBLdrTAFPzD4CecIBVv0XAv4tDK5yvZvnpuqobqaJz7kfhJtg+BXI2eDEUcZnLfXZ8eT5I+PO1d9HtR82OZU9LVCAd9Xw0zJlrqJZ44pxYr5Y0HbwdFyOu+oGZor5CXx6zK+Mqok3uEj0aznTn/iNJFlQBPKGCjBq4H3bPuFoiBV14Z1ZMu8xDok+cfCoRyjHPu9Tn8RrIOdrAdCwBQUlyaIWgktVIrX/SKaUYCI4+om0KjRr4hVtTX1xoY1li7lLbjfXrNRJUwQaAqeqIXCW+ES9bSGZc2WZgIczThCmYxJy125PI7cIzh4Cp9XTRb6AOFS9lWtz98y3R+vgQrj36Uw0vYQ3qaqTx+5EgU3JtFbcZIke0NK3HWvbsSaL/y+zN6Smez1Rml35BMvR9n7Km7ItChi8FXAyX+d+RqPIgaxADwM3AGKwmYbXbAK7ioks59nh61ViScXgiJHNVO7Ox9qNeQ2MAFyCn/2qz0furSI9BbyYfrFQfP/2VDSmgoeeiytP4v7g4wPan/wc2GV2Dtr3U0hAW6pCCw4iBoAXqo31lYLYgUpKaBkZhIVSPBZk43nIJW8mPD8uwsICxQNMDS06Pw+uXzhSmiMb9w== 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)(39860400002)(376002)(136003)(346002)(366004)(396003)(110136005)(2616005)(86362001)(9746002)(66556008)(2906002)(36756003)(186003)(9786002)(478600001)(426003)(6636002)(66476007)(83380400001)(8936002)(8676002)(26005)(66946007)(5660300002)(316002)(38100700002)(6666004)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: GnfRjeSj28V+zoYf9xroJNrDbyxLofh/uwdhcfPyGH1Bej/rSLoOgT8eUkMdL45Spcm4k2QD8IO2/3kP/QbqkjhLXEdBHY9SMe/4IohMqaj1o8TATY5Sye5+PTMJJbFUHpzxex+EU4VSVj/LW5DZfxi5fXAEXa7USrtwAvFFuwTA1x6Wh99YdqTI2h9ov8bAM2aQBisVUZUg4OtFj5TOZIERgZXEY/38Wg7qkXnHTny0KAqikA5VjThBxBGKBZ7xU4+D9jAEbaOn7lPGXCMMT3b67Ou0XcpaQAfPkt3TKKmGnqS8R8IRVhpBDxUTdThzJUsGNK1N+GMp/ExJtaseRKqHbB6ipjuWN+q4H/6LY1I+b7u7qLO7VafSwn1i9C8/IgZ8FDLPEmS7NjGfHFO5kd62WPJG/5dITg6bvzrFRI+pfMfmic04Vq2cvPig5WhtHRz8yv52xcmXrC4oHL2xymjBv2r3Ptt05z2cWcW/VaH5jp8nLKSTC3cALaOt12qCh+5vBqC11qwlKPc5wHJBfSM7SI35/60bnv5fyUw4djCJRL5BRk5GNvlLjeI0mfVs3KKsqXP+VE702mfqAxH9N860lGqa/yi7GretzoUN7U4OshDLc5t1xayRJOFY0jSX3VnuFdx7IiE0tVJfsmk9+I/zgET30DBActReujjNqF0XNJKBEO3O3N4ugIQyfbyivuNHzcFb+HTnEkntfdB4fDOr8vjQh5x00TjMlVQ7+O1p2a6uiGM4QeLf5KNbnt7FhLx8K9dYdc1EqMOuvlUP8ZD1+8nWU7w+GoTbn4p6751MtLYKvCPQ6AkgKx0bNLKYmmT8EliHQaausPkex7iO/NpubicXmoZRaRU3dOHh8U+RKbKiL7dJJAypDZvl3xLIKa9KZAQSxm6PJM8ZatEEDsQYNLsVARHWepfETJ9n6Nj5EiJHar7f2bl63cbk4eHPEzTSdB4w1sk7N/ak58soFU/X1l4aaMHBnmYwfAKnaydhT1fD0wkCqY8UnxzoY1LeN6bmgym7HtpW1GM07BACs0NwLsENFhSAV1dXHP8ubvMacVSIsrm4XHfMOKQA0zus+R30lZax9IPPd9QWZ+7k8S9cSlItKUudnRk+3Sd4m9nITrHqi6Hq4jcYNnjNZL8bozMYQXziDcJ9TvPDPCdLajLHeWnvgcGH4fbBi37oj7MFl4HyGRHjhAdfIcNWmoko+ZMJeP6dAjrLr/Tcx2fi50/STFzMGaoUOJkVDBo3oCAbnPxDQKGXCcEPWCpZVrZcEzL3EW6cmdYn/26+PleLo3+nk3pGNcue9WEUDFD+6g9FVPyN8SN63Baddpz/qvCb X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8fe5deee-59b6-447f-1aca-08d92a182bcd X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jun 2021 00:55:55.3592 (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: JjviFUH2SCFDooMjbaWKzgZPfx/y49j9aqNHejjUiAUD+SmUAOQAAGVSZqctcHV7 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5095 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This allows a mdev driver to opt out of using vfio_mdev.c, instead the driver will provide a 'struct mdev_driver' and register directly with the driver core. Much of mdev_parent_ops becomes unused in this mode: - create()/remove() are done via the mdev_driver probe()/remove() - mdev_attr_groups becomes mdev_driver driver.dev_groups - Wrapper function callbacks are replaced with the same ones from struct vfio_device_ops Signed-off-by: Jason Gunthorpe Reviewed-by: Christoph Hellwig --- drivers/vfio/mdev/mdev_core.c | 30 ++++++++++++++++++++++-------- drivers/vfio/mdev/mdev_driver.c | 10 ++++++++++ include/linux/mdev.h | 2 ++ 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c index ff8c1a84516698..e4581ec093a6a6 100644 --- a/drivers/vfio/mdev/mdev_core.c +++ b/drivers/vfio/mdev/mdev_core.c @@ -94,9 +94,11 @@ static void mdev_device_remove_common(struct mdev_device *mdev) mdev_remove_sysfs_files(mdev); device_del(&mdev->dev); lockdep_assert_held(&parent->unreg_sem); - ret = parent->ops->remove(mdev); - if (ret) - dev_err(&mdev->dev, "Remove failed: err=%d\n", ret); + if (parent->ops->remove) { + ret = parent->ops->remove(mdev); + if (ret) + dev_err(&mdev->dev, "Remove failed: err=%d\n", ret); + } /* Balances with device_initialize() */ put_device(&mdev->dev); @@ -127,7 +129,9 @@ 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->create || !ops->remove || !ops->supported_type_groups) + if (!ops || !ops->supported_type_groups) + return -EINVAL; + if (!ops->device_driver && (!ops->create || !ops->remove)) return -EINVAL; dev = get_device(dev); @@ -256,6 +260,7 @@ int mdev_device_create(struct mdev_type *type, const guid_t *uuid) int ret; struct mdev_device *mdev, *tmp; struct mdev_parent *parent = type->parent; + struct mdev_driver *drv = parent->ops->device_driver; mutex_lock(&mdev_list_lock); @@ -296,14 +301,22 @@ int mdev_device_create(struct mdev_type *type, const guid_t *uuid) goto out_put_device; } - ret = parent->ops->create(mdev); - if (ret) - goto out_unlock; + if (parent->ops->create) { + ret = parent->ops->create(mdev); + if (ret) + goto out_unlock; + } ret = device_add(&mdev->dev); if (ret) goto out_remove; + if (!drv) + drv = &vfio_mdev_driver; + ret = device_driver_attach(&drv->driver, &mdev->dev); + if (ret) + goto out_del; + ret = mdev_create_sysfs_files(mdev); if (ret) goto out_del; @@ -317,7 +330,8 @@ int mdev_device_create(struct mdev_type *type, const guid_t *uuid) out_del: device_del(&mdev->dev); out_remove: - parent->ops->remove(mdev); + if (parent->ops->remove) + parent->ops->remove(mdev); out_unlock: up_read(&parent->unreg_sem); out_put_device: diff --git a/drivers/vfio/mdev/mdev_driver.c b/drivers/vfio/mdev/mdev_driver.c index 041699571b7e55..c368ec824e2b5c 100644 --- a/drivers/vfio/mdev/mdev_driver.c +++ b/drivers/vfio/mdev/mdev_driver.c @@ -71,10 +71,20 @@ static int mdev_remove(struct device *dev) return 0; } +static int mdev_match(struct device *dev, struct device_driver *drv) +{ + /* + * No drivers automatically match. Drivers are only bound by explicit + * device_driver_attach() + */ + return 0; +} + struct bus_type mdev_bus_type = { .name = "mdev", .probe = mdev_probe, .remove = mdev_remove, + .match = mdev_match, }; EXPORT_SYMBOL_GPL(mdev_bus_type); diff --git a/include/linux/mdev.h b/include/linux/mdev.h index 1fb34ea394ad46..3a38598c260559 100644 --- a/include/linux/mdev.h +++ b/include/linux/mdev.h @@ -55,6 +55,7 @@ struct device *mtype_get_parent_dev(struct mdev_type *mtype); * register the device to mdev module. * * @owner: The module owner. + * @device_driver: Which device driver to probe() on newly created devices * @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 @@ -103,6 +104,7 @@ struct device *mtype_get_parent_dev(struct mdev_type *mtype); **/ struct mdev_parent_ops { struct module *owner; + struct mdev_driver *device_driver; const struct attribute_group **dev_attr_groups; const struct attribute_group **mdev_attr_groups; struct attribute_group **supported_type_groups; From patchwork Tue Jun 8 00:55: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: 12305013 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AD259C48BE0 for ; Tue, 8 Jun 2021 00:56:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 996206127A for ; Tue, 8 Jun 2021 00:56:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231325AbhFHA5y (ORCPT ); Mon, 7 Jun 2021 20:57:54 -0400 Received: from mail-mw2nam10on2041.outbound.protection.outlook.com ([40.107.94.41]:6904 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231296AbhFHA5w (ORCPT ); Mon, 7 Jun 2021 20:57:52 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GRMl+Ej/mOfxiMDf62M3pePMgbhzlUzbGlABL8wWNFwAHLItQKh4G3FFtVBIt4MY2adn1Sa0UX82sZbRsC+DMNasF6z1h//cJAawaXdA3pkuZHlU3xB4aQH1kMEZHJGYRIazk52c3cnktJB6cH3XG1GKHjBuYZqjUdN8Hgya6exH+yrAasaminPqfRh40m0BgaqESaACOYG2Udy34R4E8v3fyvJvCXwfaVdJQ76+MIYjzJDzTbhWTmpTn11IAuiic0VzKR2lYp9BqUaZwGM4psO+Jy0SFD/q4fXrCejBX67K5DWaVtpn9GbDS1oNoKSPBL7uz1xHusOYIPDuYJu6uQ== 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-SenderADCheck; bh=6NiwbjTB/rf9sR4ZC2VUsBPwx5YVyjuS3PbGxjNeKkA=; b=OJl72Zj8qILd68O55hZA2SxQI4VZFnNncoiD7fnSvebzRgPMmxDZ3+OWAC0fuRRNlgrMMJqc2CjZeZEBcHTkv4mabRAM74WOYTlnXYuFiznhvAAnkt+JeCzjUgJ37ZmX31fWgS+xVAjGKYzEJclRMXgc+kNh0Gjvwi7Hv5OM8OCKJXN1zSaP+Ciny4x/JswcEA/p4gXsXjckRMOyyjl/TDTvxKcaXkm+h+F3AccZobM4zeVpkEZK3Vn4I7lx4J1V6WcquYYtYMLOdnWPNp8HKCbzrLccpW18sIAEaRBk8aUEW5AWpkYgSdedbupqfHAk9IFdZvcmfnf3gC7k2RzCPg== 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=6NiwbjTB/rf9sR4ZC2VUsBPwx5YVyjuS3PbGxjNeKkA=; b=Vl7wi1C/m8C1FzrxJMEYnEMwoA6jVbtck4iArB8udXnWxOs87L1iA0gFj/FsbWFyIwEiyBMua6R6lq0+Jp0MRLm+9aNzXzfYQr+CFR7k4vCwTIVTjlq8rMvrHOVvRwczEP62e7DJdxZnc4AcFMhRs8JlmdtNndVdm4XijjKUaRFUvX7Amlj27Wzxbr9CKIFvVX7Om23LeHe2FCWVOiEs0EXaayZ0H3nMrcUdaLtv/yKBDXjcuPNA4DNT7xHVec7Ka7Doyy/fezj/cGqyH9zyHOXQcbTtgP+QTe74CybuKW+23lBghleCSaP0WPCGyc6BejwWErJLPOWP0NkHw+SuPA== Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=nvidia.com; Received: from BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) by BL1PR12MB5095.namprd12.prod.outlook.com (2603:10b6:208:31b::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.24; Tue, 8 Jun 2021 00:55:56 +0000 Received: from BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::3d51:a3b9:8611:684e]) by BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::3d51:a3b9:8611:684e%6]) with mapi id 15.20.4195.030; Tue, 8 Jun 2021 00:55:56 +0000 From: Jason Gunthorpe To: kvm@vger.kernel.org, Kirti Wankhede Cc: Christoph Hellwig Subject: [PATCH 08/10] vfio/mtty: Convert to use vfio_register_group_dev() Date: Mon, 7 Jun 2021 21:55:50 -0300 Message-Id: <8-v1-324b2038f212+1041f1-vfio3a_jgg@nvidia.com> In-Reply-To: <0-v1-324b2038f212+1041f1-vfio3a_jgg@nvidia.com> References: X-Originating-IP: [47.55.113.94] X-ClientProxiedBy: BL1PR13CA0254.namprd13.prod.outlook.com (2603:10b6:208:2ba::19) To BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (47.55.113.94) by BL1PR13CA0254.namprd13.prod.outlook.com (2603:10b6:208:2ba::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4219.9 via Frontend Transport; Tue, 8 Jun 2021 00:55:54 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lqQ24-003eKn-Ly; Mon, 07 Jun 2021 21:55:52 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: bae6a26a-d497-4f19-000d-08d92a182b62 X-MS-TrafficTypeDiagnostic: BL1PR12MB5095: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:431; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: oLgTx+9BTgfyQGl/Usqu7VctYsWJFL5ETcC0YWQBr/vRAgSoHfuKQDaf66VuXCVrsZUMniNInEQIw0pLZCeXebgmZHzPFEBZxGsM1fyYOwwyRpGX+jqtQ3LEdk5ikONKUyaiReHWdNULDEpD20BNs6PwivtojOjHoDI2TEibR9uyyLJF97iqpxQHelwNNJURINIZlrhV6AkXaqF1AIsqjx1X/QRyJgcNLgiA+y31FPfYcGe050doXRtI1gSloEupVPWuuk+9NnPr5ZLro3Ds6HAuVjPOAN8XRJuKR9jNTkaEDeo0RIoXSMFDx9cfqDpNyDqz3JcygSCTSqx2LGI++P1teJXm2wzxC5KlLvZ+AHo5DBxqPADTuMLWPMkK4pDqZudAMkBjcfprwTEBz79VwsenKp4Iip+DrB2D+aNtxpeXP72RiN+a8GNrwhbieRKcQmTdmWcQrS4OB9gjYBWDFU6dwsI9iruSvRco9VGVkGfB3Cv3C8J76oHLLGd9zN+59L0nTnaQsXMQuMP9wu/kUOENq41d84GVK2EEy91CiXiviEJv5Xs4NfDDPXhmaOEDbootvYVeDW0KHjDx4nFG25kYD6kL/MgNrFVBUDFE1louZG46uhFt/pybaUXrx8jUI/4VaiWBkFVHtE8wPM1z4g== 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)(39860400002)(376002)(136003)(346002)(366004)(396003)(2616005)(86362001)(9746002)(6862004)(66556008)(2906002)(37006003)(30864003)(36756003)(186003)(9786002)(4326008)(478600001)(426003)(6636002)(66476007)(83380400001)(8936002)(8676002)(26005)(66946007)(5660300002)(316002)(38100700002)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: r+Y5A/wrGfS9PMAt7LZOU14UXScpBOJThq0gWyE1v6nApNrQtJaQ32FAD+W2lMD4MGbyy05LPH9fOtyPj+l4GPtA+C9kbR7sAZVRO4cWtWxHILQo3OHkfJJFr8I+fIlJdEAd0b73k0PCug+fZ7M8bcS3nqzMPCCiVdgGvhb4R6bHmpxu/23SC07LGuqW6WFZVDdo91gOXDsBFyn9M8FWIIByQL2HQu4o8Q0rxhCepQKza77IYFDimpbmup0D2coL0Ad9ZmsUYuNOT511ScSOS52HUmEzoxrpgQgRQguDtq5OuqUbKMgh95GBXgCtPN3WshqMJJw6QoSpKcSEgAx8j/n9U6EBp0lYirTSTMnmgu+uLe+TnHfBzwRqXqHCiy4bq2ZkjTwInaoyMPkQG6x+T1pKH9QTmmAYaUbyPFe7yrhqrIzJNJ1y2sRX3+kokUaxegx67xcZ7hPf9k75oeymFF5QwLF1o7JVQsvfUjiEo+12AsdCW4IOKH2nv6fkmokZgpCTwia3wOxwO+EsYVJ6BLbqqia4BsqWkN0IoVSPKj6RS8dDMPXCylo+EIBwmrYQOEiYpVoNwUp4ZqEGCt1yd+9cvzEHG5tJbbG5CTTQZ7HBmUBTDgQs3keDEPDLLMY/1YPGCFiArfgvKvvUfKMtvdaZek2+AoHD0TMnHX/YD8VfonA5wF8mZ35LJEvA7fO61km2fzoavpZbm8nuCreP+Or1stprsEwghCKFCQL7BynsUNvWH6PqiLJFefCewGJLKSdeoVR0GCe1KJIjb2ho41BkZfOPw+UIMAJ9+6kJi8mWXUWX+ATk9uDZyILheC6kipw4A8fLIE0BwHl90bxI+dFe/GNLfCQs4H677m6+HvTICS1q5iG9RNT2etYaLC3/yN0+NuPkBGLs9IdwIp4aHyTY60vMuEbxeIbVuhOY2kv/zb+JODSMEY9XTC3mtUBSG/oGyrdjSYQd2shIVtaHnhgW2MfpQBxm5dVhGnVug58t2Xtr4IxXCJd85I3ECUsoJTnarhuCGeyj3s7keg/kikTN/DYR+QwQyMmXQxWuFBav7l3HNG5b3IQ9uXDzgO4wRS0tpA3AZ2d3FlLOzggdpAnKixg8dbft0SUENIRUqghB9Mk3MixD0NawtPFDgCcEcFcCL9y4Ryq5Aazd35KpHIbGuJdMCApACzCfr4RL52C5s3BKW0BaRQLR3dC0tjx1zarrcIv/Vc0geOvUodCetChBbZ3yvTMRWNE93FqDkhkq/YnaUU3819OHbXhUWuRBt9tVWA/W0EzKlcJfFXCsAgRDKz3MJKSc2Q125APY/vMiQy334SJa59RbKWLeSZN0 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: bae6a26a-d497-4f19-000d-08d92a182b62 X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jun 2021 00:55:54.7290 (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: f8x7m7lry3X2upuCYe82N1zq2ta1B0SRVBcDtFq5wKqwJP7DAUD0vr9F65oIn+hY X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5095 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This is straightforward conversion, the mdev_state is actually serving as the vfio_device and we can replace all the mdev_get_drvdata()'s and the wonky dead code with a simple container_of() Reviewed-by: Christoph Hellwig Signed-off-by: Jason Gunthorpe --- samples/vfio-mdev/mtty.c | 185 ++++++++++++++++++--------------------- 1 file changed, 83 insertions(+), 102 deletions(-) diff --git a/samples/vfio-mdev/mtty.c b/samples/vfio-mdev/mtty.c index b9b24be4abdab7..d2a168420b775d 100644 --- a/samples/vfio-mdev/mtty.c +++ b/samples/vfio-mdev/mtty.c @@ -127,6 +127,7 @@ struct serial_port { /* State of each mdev device */ struct mdev_state { + struct vfio_device vdev; int irq_fd; struct eventfd_ctx *intx_evtfd; struct eventfd_ctx *msi_evtfd; @@ -150,6 +151,8 @@ static const struct file_operations vd_fops = { .owner = THIS_MODULE, }; +static const struct vfio_device_ops mtty_dev_ops; + /* function prototypes */ static int mtty_trigger_interrupt(struct mdev_state *mdev_state); @@ -631,22 +634,15 @@ static void mdev_read_base(struct mdev_state *mdev_state) } } -static ssize_t mdev_access(struct mdev_device *mdev, u8 *buf, size_t count, +static ssize_t mdev_access(struct mdev_state *mdev_state, u8 *buf, size_t count, loff_t pos, bool is_write) { - struct mdev_state *mdev_state; unsigned int index; loff_t offset; int ret = 0; - if (!mdev || !buf) - return -EINVAL; - - mdev_state = mdev_get_drvdata(mdev); - if (!mdev_state) { - pr_err("%s mdev_state not found\n", __func__); + if (!buf) return -EINVAL; - } mutex_lock(&mdev_state->ops_lock); @@ -708,15 +704,18 @@ static ssize_t mdev_access(struct mdev_device *mdev, u8 *buf, size_t count, return ret; } -static int mtty_create(struct mdev_device *mdev) +static int mtty_probe(struct mdev_device *mdev) { struct mdev_state *mdev_state; int nr_ports = mdev_get_type_group_id(mdev) + 1; + int ret; mdev_state = kzalloc(sizeof(struct mdev_state), GFP_KERNEL); if (mdev_state == NULL) return -ENOMEM; + vfio_init_group_dev(&mdev_state->vdev, &mdev->dev, &mtty_dev_ops); + mdev_state->nr_ports = nr_ports; mdev_state->irq_index = -1; mdev_state->s[0].max_fifo_size = MAX_FIFO_SIZE; @@ -731,7 +730,6 @@ static int mtty_create(struct mdev_device *mdev) mutex_init(&mdev_state->ops_lock); mdev_state->mdev = mdev; - mdev_set_drvdata(mdev, mdev_state); mtty_create_config_space(mdev_state); @@ -739,50 +737,40 @@ static int mtty_create(struct mdev_device *mdev) list_add(&mdev_state->next, &mdev_devices_list); mutex_unlock(&mdev_list_lock); + ret = vfio_register_group_dev(&mdev_state->vdev); + if (ret) { + kfree(mdev_state); + return ret; + } + dev_set_drvdata(&mdev->dev, mdev_state); return 0; } -static int mtty_remove(struct mdev_device *mdev) +static void mtty_remove(struct mdev_device *mdev) { - struct mdev_state *mds, *tmp_mds; - struct mdev_state *mdev_state = mdev_get_drvdata(mdev); - int ret = -EINVAL; + struct mdev_state *mdev_state = dev_get_drvdata(&mdev->dev); + vfio_unregister_group_dev(&mdev_state->vdev); mutex_lock(&mdev_list_lock); - list_for_each_entry_safe(mds, tmp_mds, &mdev_devices_list, next) { - if (mdev_state == mds) { - list_del(&mdev_state->next); - mdev_set_drvdata(mdev, NULL); - kfree(mdev_state->vconfig); - kfree(mdev_state); - ret = 0; - break; - } - } + list_del(&mdev_state->next); mutex_unlock(&mdev_list_lock); - return ret; + kfree(mdev_state->vconfig); + kfree(mdev_state); } -static int mtty_reset(struct mdev_device *mdev) +static int mtty_reset(struct mdev_state *mdev_stte) { - struct mdev_state *mdev_state; - - if (!mdev) - return -EINVAL; - - mdev_state = mdev_get_drvdata(mdev); - if (!mdev_state) - return -EINVAL; - pr_info("%s: called\n", __func__); return 0; } -static ssize_t mtty_read(struct mdev_device *mdev, char __user *buf, +static ssize_t mtty_read(struct vfio_device *vdev, char __user *buf, size_t count, loff_t *ppos) { + struct mdev_state *mdev_state = + container_of(vdev, struct mdev_state, vdev); unsigned int done = 0; int ret; @@ -792,7 +780,7 @@ static ssize_t mtty_read(struct mdev_device *mdev, char __user *buf, if (count >= 4 && !(*ppos % 4)) { u32 val; - ret = mdev_access(mdev, (u8 *)&val, sizeof(val), + ret = mdev_access(mdev_state, (u8 *)&val, sizeof(val), *ppos, false); if (ret <= 0) goto read_err; @@ -804,7 +792,7 @@ static ssize_t mtty_read(struct mdev_device *mdev, char __user *buf, } else if (count >= 2 && !(*ppos % 2)) { u16 val; - ret = mdev_access(mdev, (u8 *)&val, sizeof(val), + ret = mdev_access(mdev_state, (u8 *)&val, sizeof(val), *ppos, false); if (ret <= 0) goto read_err; @@ -816,7 +804,7 @@ static ssize_t mtty_read(struct mdev_device *mdev, char __user *buf, } else { u8 val; - ret = mdev_access(mdev, (u8 *)&val, sizeof(val), + ret = mdev_access(mdev_state, (u8 *)&val, sizeof(val), *ppos, false); if (ret <= 0) goto read_err; @@ -839,9 +827,11 @@ static ssize_t mtty_read(struct mdev_device *mdev, char __user *buf, return -EFAULT; } -static ssize_t mtty_write(struct mdev_device *mdev, const char __user *buf, +static ssize_t mtty_write(struct vfio_device *vdev, const char __user *buf, size_t count, loff_t *ppos) { + struct mdev_state *mdev_state = + container_of(vdev, struct mdev_state, vdev); unsigned int done = 0; int ret; @@ -854,7 +844,7 @@ static ssize_t mtty_write(struct mdev_device *mdev, const char __user *buf, if (copy_from_user(&val, buf, sizeof(val))) goto write_err; - ret = mdev_access(mdev, (u8 *)&val, sizeof(val), + ret = mdev_access(mdev_state, (u8 *)&val, sizeof(val), *ppos, true); if (ret <= 0) goto write_err; @@ -866,7 +856,7 @@ static ssize_t mtty_write(struct mdev_device *mdev, const char __user *buf, if (copy_from_user(&val, buf, sizeof(val))) goto write_err; - ret = mdev_access(mdev, (u8 *)&val, sizeof(val), + ret = mdev_access(mdev_state, (u8 *)&val, sizeof(val), *ppos, true); if (ret <= 0) goto write_err; @@ -878,7 +868,7 @@ static ssize_t mtty_write(struct mdev_device *mdev, const char __user *buf, if (copy_from_user(&val, buf, sizeof(val))) goto write_err; - ret = mdev_access(mdev, (u8 *)&val, sizeof(val), + ret = mdev_access(mdev_state, (u8 *)&val, sizeof(val), *ppos, true); if (ret <= 0) goto write_err; @@ -896,19 +886,11 @@ static ssize_t mtty_write(struct mdev_device *mdev, const char __user *buf, return -EFAULT; } -static int mtty_set_irqs(struct mdev_device *mdev, uint32_t flags, +static int mtty_set_irqs(struct mdev_state *mdev_state, uint32_t flags, unsigned int index, unsigned int start, unsigned int count, void *data) { int ret = 0; - struct mdev_state *mdev_state; - - if (!mdev) - return -EINVAL; - - mdev_state = mdev_get_drvdata(mdev); - if (!mdev_state) - return -EINVAL; mutex_lock(&mdev_state->ops_lock); switch (index) { @@ -1024,21 +1006,13 @@ static int mtty_trigger_interrupt(struct mdev_state *mdev_state) return ret; } -static int mtty_get_region_info(struct mdev_device *mdev, +static int mtty_get_region_info(struct mdev_state *mdev_state, struct vfio_region_info *region_info, u16 *cap_type_id, void **cap_type) { unsigned int size = 0; - struct mdev_state *mdev_state; u32 bar_index; - if (!mdev) - return -EINVAL; - - mdev_state = mdev_get_drvdata(mdev); - if (!mdev_state) - return -EINVAL; - bar_index = region_info->index; if (bar_index >= VFIO_PCI_NUM_REGIONS) return -EINVAL; @@ -1073,8 +1047,7 @@ static int mtty_get_region_info(struct mdev_device *mdev, return 0; } -static int mtty_get_irq_info(struct mdev_device *mdev, - struct vfio_irq_info *irq_info) +static int mtty_get_irq_info(struct vfio_irq_info *irq_info) { switch (irq_info->index) { case VFIO_PCI_INTX_IRQ_INDEX: @@ -1098,8 +1071,7 @@ static int mtty_get_irq_info(struct mdev_device *mdev, return 0; } -static int mtty_get_device_info(struct mdev_device *mdev, - struct vfio_device_info *dev_info) +static int mtty_get_device_info(struct vfio_device_info *dev_info) { dev_info->flags = VFIO_DEVICE_FLAGS_PCI; dev_info->num_regions = VFIO_PCI_NUM_REGIONS; @@ -1108,19 +1080,13 @@ static int mtty_get_device_info(struct mdev_device *mdev, return 0; } -static long mtty_ioctl(struct mdev_device *mdev, unsigned int cmd, +static long mtty_ioctl(struct vfio_device *vdev, unsigned int cmd, unsigned long arg) { + struct mdev_state *mdev_state = + container_of(vdev, struct mdev_state, vdev); int ret = 0; unsigned long minsz; - struct mdev_state *mdev_state; - - if (!mdev) - return -EINVAL; - - mdev_state = mdev_get_drvdata(mdev); - if (!mdev_state) - return -ENODEV; switch (cmd) { case VFIO_DEVICE_GET_INFO: @@ -1135,7 +1101,7 @@ static long mtty_ioctl(struct mdev_device *mdev, unsigned int cmd, if (info.argsz < minsz) return -EINVAL; - ret = mtty_get_device_info(mdev, &info); + ret = mtty_get_device_info(&info); if (ret) return ret; @@ -1160,7 +1126,7 @@ static long mtty_ioctl(struct mdev_device *mdev, unsigned int cmd, if (info.argsz < minsz) return -EINVAL; - ret = mtty_get_region_info(mdev, &info, &cap_type_id, + ret = mtty_get_region_info(mdev_state, &info, &cap_type_id, &cap_type); if (ret) return ret; @@ -1184,7 +1150,7 @@ static long mtty_ioctl(struct mdev_device *mdev, unsigned int cmd, (info.index >= mdev_state->dev_info.num_irqs)) return -EINVAL; - ret = mtty_get_irq_info(mdev, &info); + ret = mtty_get_irq_info(&info); if (ret) return ret; @@ -1218,25 +1184,25 @@ static long mtty_ioctl(struct mdev_device *mdev, unsigned int cmd, return PTR_ERR(data); } - ret = mtty_set_irqs(mdev, hdr.flags, hdr.index, hdr.start, + ret = mtty_set_irqs(mdev_state, hdr.flags, hdr.index, hdr.start, hdr.count, data); kfree(ptr); return ret; } case VFIO_DEVICE_RESET: - return mtty_reset(mdev); + return mtty_reset(mdev_state); } return -ENOTTY; } -static int mtty_open(struct mdev_device *mdev) +static int mtty_open(struct vfio_device *vdev) { pr_info("%s\n", __func__); return 0; } -static void mtty_close(struct mdev_device *mdev) +static void mtty_close(struct vfio_device *mdev) { pr_info("%s\n", __func__); } @@ -1351,18 +1317,31 @@ static struct attribute_group *mdev_type_groups[] = { NULL, }; +static const struct vfio_device_ops mtty_dev_ops = { + .name = "vfio-mdev", + .open = mtty_open, + .release = mtty_close, + .read = mtty_read, + .write = mtty_write, + .ioctl = mtty_ioctl, +}; + +static struct mdev_driver mtty_driver = { + .driver = { + .name = "mtty", + .owner = THIS_MODULE, + .mod_name = KBUILD_MODNAME, + .dev_groups = mdev_dev_groups, + }, + .probe = mtty_probe, + .remove = mtty_remove, +}; + static const struct mdev_parent_ops mdev_fops = { .owner = THIS_MODULE, + .device_driver = &mtty_driver, .dev_attr_groups = mtty_dev_groups, - .mdev_attr_groups = mdev_dev_groups, .supported_type_groups = mdev_type_groups, - .create = mtty_create, - .remove = mtty_remove, - .open = mtty_open, - .release = mtty_close, - .read = mtty_read, - .write = mtty_write, - .ioctl = mtty_ioctl, }; static void mtty_device_release(struct device *dev) @@ -1393,12 +1372,16 @@ static int __init mtty_dev_init(void) pr_info("major_number:%d\n", MAJOR(mtty_dev.vd_devt)); + ret = mdev_register_driver(&mtty_driver); + if (ret) + goto err_cdev; + mtty_dev.vd_class = class_create(THIS_MODULE, MTTY_CLASS_NAME); if (IS_ERR(mtty_dev.vd_class)) { pr_err("Error: failed to register mtty_dev class\n"); ret = PTR_ERR(mtty_dev.vd_class); - goto failed1; + goto err_driver; } mtty_dev.dev.class = mtty_dev.vd_class; @@ -1407,28 +1390,25 @@ static int __init mtty_dev_init(void) ret = device_register(&mtty_dev.dev); if (ret) - goto failed2; + goto err_class; ret = mdev_register_device(&mtty_dev.dev, &mdev_fops); if (ret) - goto failed3; + goto err_device; mutex_init(&mdev_list_lock); INIT_LIST_HEAD(&mdev_devices_list); + return 0; - goto all_done; - -failed3: - +err_device: device_unregister(&mtty_dev.dev); -failed2: +err_class: class_destroy(mtty_dev.vd_class); - -failed1: +err_driver: + mdev_unregister_driver(&mtty_driver); +err_cdev: cdev_del(&mtty_dev.vd_cdev); unregister_chrdev_region(mtty_dev.vd_devt, MINORMASK + 1); - -all_done: return ret; } @@ -1439,6 +1419,7 @@ static void __exit mtty_dev_exit(void) device_unregister(&mtty_dev.dev); idr_destroy(&mtty_dev.vd_idr); + mdev_unregister_driver(&mtty_driver); cdev_del(&mtty_dev.vd_cdev); unregister_chrdev_region(mtty_dev.vd_devt, MINORMASK + 1); class_destroy(mtty_dev.vd_class); From patchwork Tue Jun 8 00:55: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: 12305001 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER, SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 60F69C47082 for ; Tue, 8 Jun 2021 00:56:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4A5E86127A for ; Tue, 8 Jun 2021 00:56:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231289AbhFHA5v (ORCPT ); Mon, 7 Jun 2021 20:57:51 -0400 Received: from mail-bn8nam12on2067.outbound.protection.outlook.com ([40.107.237.67]:45339 "EHLO NAM12-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230382AbhFHA5s (ORCPT ); Mon, 7 Jun 2021 20:57:48 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=axB0rpglgF1w5W0X1hDmb/V6QI9pvbLcHCM7BPNwifmBnSqklAoesUGPibK3nw25Egeh/Q97XvBEbWLUrYreL1JqE/PFbxtu3LG/Zb2O9mLT1HnP8SV8i8PHmc+1GxVsJEPQb/Gy+L0xmLWuSyENsG3FE8OFW5IWj7xdkfvnvTD7RkIIws359LlQatV8StWkeQqhJ0HbVsxtYmgdk0P051ljIZMZoHnLY/6GvRBsD4pRzzZKp/33w4sbHnQYY0/uErNmDCv+/ll8VnU4cqDv6PNsEnG6Rw5P64Xiw9s7ZXlxvh3p7SBjLZ5llE0FLNDIyWMgMboOT0SS4azC3jXcrw== 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-SenderADCheck; bh=Ubxl09Oh9RRiYUvs16zc906Eu8pK4TldYGiGc+CiB1Q=; b=Mudej4q5/GJg3OAY9NmiLWSD94UptJI/CdqOve4xBaVGdOTMQ7zy0BKBjWtXUB11V04jZoUyaWPwrIKLESotDoP0cVfn9fPxEr7jtLytPUSris3+ZCs8Kb0TCsVTgAzqQEq1B/B6GI3vzezo7UqeIBdpqeibjG4Pwjz4XNgd3Ej+ZyGLi0RKFWbE1uFTZaaEPPUKk4rCmWcb1/X3Gt6r3jkSq/eZP18b+t41oiGlKCYAF6+XIr96K8p5FMJ20MmUViW+DU9SPPiMB1hpSck9tXLNkMu/FKMRHu6KA2IwUtv0kBGaG2i97m0maeyttIIPp0TOwX1ggtCU5sWRCQbW6g== 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=Ubxl09Oh9RRiYUvs16zc906Eu8pK4TldYGiGc+CiB1Q=; b=IITJyky4KtflY7ApeKPCEP/+Fmi6fO40om0zouBSMy4Q7Su2w8VSI5es9MGzGnWRSocKLqHp2wxzNhcsxuhHgUEpPqv5FvogBuBexxljoRRnwLoTHhIjtER24A5/VmbSv+Nr4qF0v+h5HTgwFOrSYNA/PWg2/u42I8+xUiNg7U2b6181OADEOI1y4ITgTTtv7XW+nqyBpUsTX5HUww2mK6enDxRS7/8TGDWgC+GWqE81nyhB/pEvq95hre8qYLfvhlGuFwlskNCFKa1PcP1eUneG+wJyfk8RCALHet7kz311JdmrRXGlVaGytIXw1fVSjg5y08oau3G3kJnX5ff3gA== Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=nvidia.com; Received: from BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) by BL0PR12MB5539.namprd12.prod.outlook.com (2603:10b6:208:1c3::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.20; Tue, 8 Jun 2021 00:55:54 +0000 Received: from BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::3d51:a3b9:8611:684e]) by BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::3d51:a3b9:8611:684e%6]) with mapi id 15.20.4195.030; Tue, 8 Jun 2021 00:55:54 +0000 From: Jason Gunthorpe To: kvm@vger.kernel.org, Kirti Wankhede Cc: Christoph Hellwig Subject: [PATCH 09/10] vfio/mdpy: Convert to use vfio_register_group_dev() Date: Mon, 7 Jun 2021 21:55:51 -0300 Message-Id: <9-v1-324b2038f212+1041f1-vfio3a_jgg@nvidia.com> In-Reply-To: <0-v1-324b2038f212+1041f1-vfio3a_jgg@nvidia.com> References: X-Originating-IP: [47.55.113.94] X-ClientProxiedBy: MN2PR12CA0028.namprd12.prod.outlook.com (2603:10b6:208:a8::41) To BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (47.55.113.94) by MN2PR12CA0028.namprd12.prod.outlook.com (2603:10b6:208:a8::41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.20 via Frontend Transport; Tue, 8 Jun 2021 00:55:53 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lqQ24-003eKr-N8; Mon, 07 Jun 2021 21:55:52 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 36d26fbc-cf28-49fe-0f9d-08d92a182afc X-MS-TrafficTypeDiagnostic: BL0PR12MB5539: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:126; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: UGp4lPOe37JHot7q3IBEv97spkw6aNHkEN9ktvCrVKzCSzBTQS0JFDw3WDvLBWw3ZwGGSUnJ27cubQL+N+WqQ/MDWDlHZO0o17iYSwf2F1dZ4whPViJ9iASBzFJiw9TYVoAqIaDVNMkmB+HMQCLtJj7ugGqNG9r94NsMSy91T8DDAocPBkQa/hKXBsDd/ec2bx06JqbE7XA91q22HwP5lMZcp8ACgG/0UBl/m0W2BJJe/dQY44tUFHTNIY8Bqb/mvhCA87WlEdnUa/ZRAYgDGq+Tn+FudKfBcS6poE+ldHpliTiwH30mJWQMeKuh3GSZTVQ74ABPwGU4A8Jxi7SM4A4LValMV7GQ0wrpEsqWEumBotx3r+WEY8lcGU5gU9WHkU4ahzAkcMrq/9ow31FRML9yTzP3n6d9FgMcwAl4O/mixTaNmnvhu/XQU68yTSNgJbdOH2Rn+tKFloNzd+cWFZThLyfJXj9mym94ltX4JdL7EYwco/V2qZ0PN/XgitBARQ8SNkKPYAI+DvBpA4uBA14RJFrSsFvJkugVRcm5aWiFmGZuX/49rSXwDHHUK6J/fbZRz7cMNDJ6ZU+1S7zfJj9gsa1FtIkx2Vs10DRbHS/DKTfPBNdBzqIR5oUmDOXD7SEWUTPB3C5zxJWv+ELrFg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL0PR12MB5506.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(136003)(366004)(396003)(39860400002)(346002)(376002)(9786002)(186003)(26005)(6862004)(36756003)(37006003)(316002)(8936002)(478600001)(4326008)(9746002)(2906002)(6636002)(86362001)(83380400001)(66946007)(426003)(38100700002)(2616005)(5660300002)(8676002)(66476007)(30864003)(66556008)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: AreQYkTmCxHH2IC2edjRttFFG8VyrHlnANXHzYs1ydfnnqHkoY+ZgNlhoFuuew7uqoEcjcjPMsvNtIP1JrYudKJADutmm40oqvJyTA49uWJ1icCM48+aQthdww1H+hSF5RiXtjSRop0uVXljRrwCUyxZjwWSN4HoA5+Zc4Yco3ptMJ3yy2cGJYh5/Oa8aY2N6Ac6DOvvy94OANTB/63NNlP1njOntaQiYuv8qZjQMqyFJDWNj/Y29fs9Ivtoc6U4on7Nty2gDq5w9TAjouICL1K0nABI755c2r8+yCZEkHVB7oIv7M7SlVhk+CD9RJ4VQ00e8+MP5TJWAK4tFZ1IWRV9hFF+gBjtmm4SKOmGbSo0qYMjEJoR6X9+dyi1wARP0H7FWYKXfvv6Eg1ykNHYjZD4FGUNtBQ8J7pxmGlmxHcT5vYcYkvoFMgjP4ASf8WBHyGOMkAgUZtJzMTW9mYm9c4tDJX29ONqPwwyyz0q7cp30Tght2PXbxKJQC0R74VedthuiWhN6MiyLR0vramWWT+MaRdNDC/0SEw8Yf3WxBzLoO7BO9OZS9+18XXDjIIA7jX5++RNUX4vhix5kpSjmQ/gG4fc6IrRJcVQ8DT2xMmMZVgBdk4hbKZD5Q9Ri6E83AOzg0ehZofe+qRKYqpuFjFSFm1X92UEQ2N/qDJgFfT9wyHtPfOhLem6iPzK7D5/tsht0/1NPrp0qHqz8Q7dTMskTyjvXmXRA9pRL0cH0ksmCMtWxVc+R7bLpF41YgDQYHh2P2C43xA7j/oRKm1CJOD9JbJHyhScTBClCJAlBl0bwqKZRCG80qWE1tcj4qtpokA3PX8CxPzD+GLF+hMZwbIUbawd7d3KhvR0KPZpY0z9xq8eEtMDU4ZtF6CftNLUWyvBNCjCdPTTtHKWaowpxdVIN11xNDi6OS4Ea2XnHe2WYs4YX5Gv8voZ0/XmMUjfSWTxV/IzjYwCKiRM4795G/hR3cHpA8teuKPufVHnpaTgbdr1OeUEHRfGhY14F+z5kUxNRueiy07k0J3CVPSU7al+eDZt5GRczdxtU8/vTRoFmp4nAgs7f8LQjdPnCMVnK7jAxKRJjpzAuyu3CtJyE4okbrgk/HLi3EPZiEFYG6u4MY77pn1hD4lKrmIy+wbtMp3umZ9oh6BwS6vNom96RpXVc9GTiviwXCqy8LVx661nhNWQHTk2wSnFFfpuAFRy65ou/O+VaGXT5XMrnykXJpy9EbANu5l8MHnflX8lkWBZsZxmC66COq1peG0zqRIJpDSexTdUHrLwTndj+yXWPa9cEGGSFb5torVcQZ5mKNr69RS25hBDwJ+fXTKl8aHO X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 36d26fbc-cf28-49fe-0f9d-08d92a182afc X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jun 2021 00:55:54.0301 (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: FsnViTCb/bDmfFbTpCzJLShCHSc7WZF4ApbDOsTE1jzymvxYwXkL4HIijqhmPcbU X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB5539 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This is straightforward conversion, the mdev_state is actually serving as the vfio_device and we can replace all the mdev_get_drvdata()'s and the wonky dead code with a simple container_of(). Reviewed-by: Christoph Hellwig Signed-off-by: Jason Gunthorpe --- samples/vfio-mdev/mdpy.c | 159 ++++++++++++++++++++++----------------- 1 file changed, 88 insertions(+), 71 deletions(-) diff --git a/samples/vfio-mdev/mdpy.c b/samples/vfio-mdev/mdpy.c index e889c1cf8fd1cd..7e9c9df0f05bac 100644 --- a/samples/vfio-mdev/mdpy.c +++ b/samples/vfio-mdev/mdpy.c @@ -85,9 +85,11 @@ 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 */ struct mdev_state { + struct vfio_device vdev; u8 *vconfig; u32 bar_mask; struct mutex ops_lock; @@ -162,11 +164,9 @@ static void handle_pci_cfg_write(struct mdev_state *mdev_state, u16 offset, } } -static ssize_t mdev_access(struct mdev_device *mdev, char *buf, size_t count, - loff_t pos, bool is_write) +static ssize_t mdev_access(struct mdev_state *mdev_state, char *buf, + size_t count, loff_t pos, bool is_write) { - struct mdev_state *mdev_state = mdev_get_drvdata(mdev); - struct device *dev = mdev_dev(mdev); int ret = 0; mutex_lock(&mdev_state->ops_lock); @@ -187,8 +187,9 @@ static ssize_t mdev_access(struct mdev_device *mdev, char *buf, size_t count, memcpy(buf, mdev_state->memblk, count); } else { - dev_info(dev, "%s: %s @0x%llx (unhandled)\n", - __func__, is_write ? "WR" : "RD", pos); + dev_info(mdev_state->vdev.dev, + "%s: %s @0x%llx (unhandled)\n", __func__, + is_write ? "WR" : "RD", pos); ret = -1; goto accessfailed; } @@ -202,9 +203,8 @@ static ssize_t mdev_access(struct mdev_device *mdev, char *buf, size_t count, return ret; } -static int mdpy_reset(struct mdev_device *mdev) +static int mdpy_reset(struct mdev_state *mdev_state) { - struct mdev_state *mdev_state = mdev_get_drvdata(mdev); u32 stride, i; /* initialize with gray gradient */ @@ -216,13 +216,14 @@ static int mdpy_reset(struct mdev_device *mdev) return 0; } -static int mdpy_create(struct mdev_device *mdev) +static int mdpy_probe(struct mdev_device *mdev) { const struct mdpy_type *type = &mdpy_types[mdev_get_type_group_id(mdev)]; struct device *dev = mdev_dev(mdev); struct mdev_state *mdev_state; u32 fbsize; + int ret; if (mdpy_count >= max_devices) return -ENOMEM; @@ -230,6 +231,7 @@ static int mdpy_create(struct mdev_device *mdev) mdev_state = kzalloc(sizeof(struct mdev_state), GFP_KERNEL); if (mdev_state == NULL) return -ENOMEM; + vfio_init_group_dev(&mdev_state->vdev, &mdev->dev, &mdpy_dev_ops); mdev_state->vconfig = kzalloc(MDPY_CONFIG_SPACE_SIZE, GFP_KERNEL); if (mdev_state->vconfig == NULL) { @@ -250,36 +252,41 @@ static int mdpy_create(struct mdev_device *mdev) mutex_init(&mdev_state->ops_lock); mdev_state->mdev = mdev; - mdev_set_drvdata(mdev, mdev_state); - mdev_state->type = type; mdev_state->memsize = fbsize; mdpy_create_config_space(mdev_state); - mdpy_reset(mdev); + mdpy_reset(mdev_state); mdpy_count++; + + ret = vfio_register_group_dev(&mdev_state->vdev); + if (ret) { + kfree(mdev_state); + return ret; + } + dev_set_drvdata(&mdev->dev, mdev_state); return 0; } -static int mdpy_remove(struct mdev_device *mdev) +static void mdpy_remove(struct mdev_device *mdev) { - struct mdev_state *mdev_state = mdev_get_drvdata(mdev); - struct device *dev = mdev_dev(mdev); + struct mdev_state *mdev_state = dev_get_drvdata(&mdev->dev); - dev_info(dev, "%s\n", __func__); + dev_info(&mdev->dev, "%s\n", __func__); - mdev_set_drvdata(mdev, NULL); + vfio_unregister_group_dev(&mdev_state->vdev); vfree(mdev_state->memblk); kfree(mdev_state->vconfig); kfree(mdev_state); mdpy_count--; - return 0; } -static ssize_t mdpy_read(struct mdev_device *mdev, char __user *buf, +static ssize_t mdpy_read(struct vfio_device *vdev, char __user *buf, size_t count, loff_t *ppos) { + struct mdev_state *mdev_state = + container_of(vdev, struct mdev_state, vdev); unsigned int done = 0; int ret; @@ -289,8 +296,8 @@ static ssize_t mdpy_read(struct mdev_device *mdev, char __user *buf, if (count >= 4 && !(*ppos % 4)) { u32 val; - ret = mdev_access(mdev, (char *)&val, sizeof(val), - *ppos, false); + ret = mdev_access(mdev_state, (char *)&val, sizeof(val), + *ppos, false); if (ret <= 0) goto read_err; @@ -301,7 +308,7 @@ static ssize_t mdpy_read(struct mdev_device *mdev, char __user *buf, } else if (count >= 2 && !(*ppos % 2)) { u16 val; - ret = mdev_access(mdev, (char *)&val, sizeof(val), + ret = mdev_access(mdev_state, (char *)&val, sizeof(val), *ppos, false); if (ret <= 0) goto read_err; @@ -313,7 +320,7 @@ static ssize_t mdpy_read(struct mdev_device *mdev, char __user *buf, } else { u8 val; - ret = mdev_access(mdev, (char *)&val, sizeof(val), + ret = mdev_access(mdev_state, (char *)&val, sizeof(val), *ppos, false); if (ret <= 0) goto read_err; @@ -336,9 +343,11 @@ static ssize_t mdpy_read(struct mdev_device *mdev, char __user *buf, return -EFAULT; } -static ssize_t mdpy_write(struct mdev_device *mdev, const char __user *buf, +static ssize_t mdpy_write(struct vfio_device *vdev, const char __user *buf, size_t count, loff_t *ppos) { + struct mdev_state *mdev_state = + container_of(vdev, struct mdev_state, vdev); unsigned int done = 0; int ret; @@ -351,7 +360,7 @@ static ssize_t mdpy_write(struct mdev_device *mdev, const char __user *buf, if (copy_from_user(&val, buf, sizeof(val))) goto write_err; - ret = mdev_access(mdev, (char *)&val, sizeof(val), + ret = mdev_access(mdev_state, (char *)&val, sizeof(val), *ppos, true); if (ret <= 0) goto write_err; @@ -363,7 +372,7 @@ static ssize_t mdpy_write(struct mdev_device *mdev, const char __user *buf, if (copy_from_user(&val, buf, sizeof(val))) goto write_err; - ret = mdev_access(mdev, (char *)&val, sizeof(val), + ret = mdev_access(mdev_state, (char *)&val, sizeof(val), *ppos, true); if (ret <= 0) goto write_err; @@ -375,7 +384,7 @@ static ssize_t mdpy_write(struct mdev_device *mdev, const char __user *buf, if (copy_from_user(&val, buf, sizeof(val))) goto write_err; - ret = mdev_access(mdev, (char *)&val, sizeof(val), + ret = mdev_access(mdev_state, (char *)&val, sizeof(val), *ppos, true); if (ret <= 0) goto write_err; @@ -393,9 +402,10 @@ static ssize_t mdpy_write(struct mdev_device *mdev, const char __user *buf, return -EFAULT; } -static int mdpy_mmap(struct mdev_device *mdev, struct vm_area_struct *vma) +static int mdpy_mmap(struct vfio_device *vdev, struct vm_area_struct *vma) { - struct mdev_state *mdev_state = mdev_get_drvdata(mdev); + struct mdev_state *mdev_state = + container_of(vdev, struct mdev_state, vdev); if (vma->vm_pgoff != MDPY_MEMORY_BAR_OFFSET >> PAGE_SHIFT) return -EINVAL; @@ -409,16 +419,10 @@ static int mdpy_mmap(struct mdev_device *mdev, struct vm_area_struct *vma) return remap_vmalloc_range(vma, mdev_state->memblk, 0); } -static int mdpy_get_region_info(struct mdev_device *mdev, +static int mdpy_get_region_info(struct mdev_state *mdev_state, struct vfio_region_info *region_info, u16 *cap_type_id, void **cap_type) { - struct mdev_state *mdev_state; - - mdev_state = mdev_get_drvdata(mdev); - if (!mdev_state) - return -EINVAL; - if (region_info->index >= VFIO_PCI_NUM_REGIONS && region_info->index != MDPY_DISPLAY_REGION) return -EINVAL; @@ -447,15 +451,13 @@ static int mdpy_get_region_info(struct mdev_device *mdev, return 0; } -static int mdpy_get_irq_info(struct mdev_device *mdev, - struct vfio_irq_info *irq_info) +static int mdpy_get_irq_info(struct vfio_irq_info *irq_info) { irq_info->count = 0; return 0; } -static int mdpy_get_device_info(struct mdev_device *mdev, - struct vfio_device_info *dev_info) +static int mdpy_get_device_info(struct vfio_device_info *dev_info) { dev_info->flags = VFIO_DEVICE_FLAGS_PCI; dev_info->num_regions = VFIO_PCI_NUM_REGIONS; @@ -463,11 +465,9 @@ static int mdpy_get_device_info(struct mdev_device *mdev, return 0; } -static int mdpy_query_gfx_plane(struct mdev_device *mdev, +static int mdpy_query_gfx_plane(struct mdev_state *mdev_state, struct vfio_device_gfx_plane_info *plane) { - struct mdev_state *mdev_state = mdev_get_drvdata(mdev); - if (plane->flags & VFIO_GFX_PLANE_TYPE_PROBE) { if (plane->flags == (VFIO_GFX_PLANE_TYPE_PROBE | VFIO_GFX_PLANE_TYPE_REGION)) @@ -496,14 +496,13 @@ static int mdpy_query_gfx_plane(struct mdev_device *mdev, return 0; } -static long mdpy_ioctl(struct mdev_device *mdev, unsigned int cmd, +static long mdpy_ioctl(struct vfio_device *vdev, unsigned int cmd, unsigned long arg) { int ret = 0; unsigned long minsz; - struct mdev_state *mdev_state; - - mdev_state = mdev_get_drvdata(mdev); + struct mdev_state *mdev_state = + container_of(vdev, struct mdev_state, vdev); switch (cmd) { case VFIO_DEVICE_GET_INFO: @@ -518,7 +517,7 @@ static long mdpy_ioctl(struct mdev_device *mdev, unsigned int cmd, if (info.argsz < minsz) return -EINVAL; - ret = mdpy_get_device_info(mdev, &info); + ret = mdpy_get_device_info(&info); if (ret) return ret; @@ -543,7 +542,7 @@ static long mdpy_ioctl(struct mdev_device *mdev, unsigned int cmd, if (info.argsz < minsz) return -EINVAL; - ret = mdpy_get_region_info(mdev, &info, &cap_type_id, + ret = mdpy_get_region_info(mdev_state, &info, &cap_type_id, &cap_type); if (ret) return ret; @@ -567,7 +566,7 @@ static long mdpy_ioctl(struct mdev_device *mdev, unsigned int cmd, (info.index >= mdev_state->dev_info.num_irqs)) return -EINVAL; - ret = mdpy_get_irq_info(mdev, &info); + ret = mdpy_get_irq_info(&info); if (ret) return ret; @@ -590,7 +589,7 @@ static long mdpy_ioctl(struct mdev_device *mdev, unsigned int cmd, if (plane.argsz < minsz) return -EINVAL; - ret = mdpy_query_gfx_plane(mdev, &plane); + ret = mdpy_query_gfx_plane(mdev_state, &plane); if (ret) return ret; @@ -604,12 +603,12 @@ static long mdpy_ioctl(struct mdev_device *mdev, unsigned int cmd, return -EINVAL; case VFIO_DEVICE_RESET: - return mdpy_reset(mdev); + return mdpy_reset(mdev_state); } return -ENOTTY; } -static int mdpy_open(struct mdev_device *mdev) +static int mdpy_open(struct vfio_device *vdev) { if (!try_module_get(THIS_MODULE)) return -ENODEV; @@ -617,7 +616,7 @@ static int mdpy_open(struct mdev_device *mdev) return 0; } -static void mdpy_close(struct mdev_device *mdev) +static void mdpy_close(struct vfio_device *vdev) { module_put(THIS_MODULE); } @@ -626,8 +625,7 @@ static ssize_t resolution_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct mdev_device *mdev = mdev_from_dev(dev); - struct mdev_state *mdev_state = mdev_get_drvdata(mdev); + struct mdev_state *mdev_state = dev_get_drvdata(dev); return sprintf(buf, "%dx%d\n", mdev_state->type->width, @@ -716,18 +714,30 @@ static struct attribute_group *mdev_type_groups[] = { NULL, }; +static const struct vfio_device_ops mdpy_dev_ops = { + .open = mdpy_open, + .release = mdpy_close, + .read = mdpy_read, + .write = mdpy_write, + .ioctl = mdpy_ioctl, + .mmap = mdpy_mmap, +}; + +static struct mdev_driver mdpy_driver = { + .driver = { + .name = "mdpy", + .owner = THIS_MODULE, + .mod_name = KBUILD_MODNAME, + .dev_groups = mdev_dev_groups, + }, + .probe = mdpy_probe, + .remove = mdpy_remove, +}; + static const struct mdev_parent_ops mdev_fops = { .owner = THIS_MODULE, - .mdev_attr_groups = mdev_dev_groups, + .device_driver = &mdpy_driver, .supported_type_groups = mdev_type_groups, - .create = mdpy_create, - .remove = mdpy_remove, - .open = mdpy_open, - .release = mdpy_close, - .read = mdpy_read, - .write = mdpy_write, - .ioctl = mdpy_ioctl, - .mmap = mdpy_mmap, }; static const struct file_operations vd_fops = { @@ -752,11 +762,15 @@ static int __init mdpy_dev_init(void) cdev_add(&mdpy_cdev, mdpy_devt, MINORMASK + 1); pr_info("%s: major %d\n", __func__, MAJOR(mdpy_devt)); + ret = mdev_register_driver(&mdpy_driver); + if (ret) + goto err_cdev; + mdpy_class = class_create(THIS_MODULE, MDPY_CLASS_NAME); if (IS_ERR(mdpy_class)) { pr_err("Error: failed to register mdpy_dev class\n"); ret = PTR_ERR(mdpy_class); - goto failed1; + goto err_driver; } mdpy_dev.class = mdpy_class; mdpy_dev.release = mdpy_device_release; @@ -764,19 +778,21 @@ static int __init mdpy_dev_init(void) ret = device_register(&mdpy_dev); if (ret) - goto failed2; + goto err_class; ret = mdev_register_device(&mdpy_dev, &mdev_fops); if (ret) - goto failed3; + goto err_device; return 0; -failed3: +err_device: device_unregister(&mdpy_dev); -failed2: +err_class: class_destroy(mdpy_class); -failed1: +err_driver: + mdev_unregister_driver(&mdpy_driver); +err_cdev: cdev_del(&mdpy_cdev); unregister_chrdev_region(mdpy_devt, MINORMASK + 1); return ret; @@ -788,6 +804,7 @@ static void __exit mdpy_dev_exit(void) mdev_unregister_device(&mdpy_dev); device_unregister(&mdpy_dev); + mdev_unregister_driver(&mdpy_driver); cdev_del(&mdpy_cdev); unregister_chrdev_region(mdpy_devt, MINORMASK + 1); class_destroy(mdpy_class); From patchwork Tue Jun 8 00:55:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12305015 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ADF3CC48BE6 for ; Tue, 8 Jun 2021 00:56:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8D92E61263 for ; Tue, 8 Jun 2021 00:56:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231352AbhFHA5z (ORCPT ); Mon, 7 Jun 2021 20:57:55 -0400 Received: from mail-mw2nam10on2041.outbound.protection.outlook.com ([40.107.94.41]:6904 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231326AbhFHA5x (ORCPT ); Mon, 7 Jun 2021 20:57:53 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bkI9xYpmhR14Fbt3hmvdWUvo2aIDNci0wqAnzMceWpizpvcL6sR1E1KsFeVpCjtUJ7aH8HEiDZeU8jzvrsqfX6LkZtyNEvNOpI5nlbFjdp+OoP5XaeGAXYZ05H50yMXDjyrCeg/wA8rlfV830nT77yQZzEasvQrWWGmMeX3C5nR7mvMkKQNYr4kWBgEHVZljvWHkJrJP2QbFNnp5EIdYr8Z3WBxgwZpk7mZJJ4nGrIqWdZXbaoP4Lzw1DkDlK8JKxfudW/tNWWPbdBRqSecthQWJhANnEt8DY3apc60PrI8wQY6ijG3sw2PTWZMNf2z55XK5gwTXoFKsFLmTjPHA/g== 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-SenderADCheck; bh=QZhPBpz/6THlXJs8mcNWgMUSX5lyq896uZnrk4Padc8=; b=WiMS+XMluw6HJjZw6odIVy91Kt0MsXYeYFVNqh/ChPDQ2YKMwWfxT035MDYPnyHgSwb5iO8quuBlKMw+ZC+SqYEDKedz2ErtOkKjnJ+o43JDeCgVkKD6bHWzzMqU/nG2evZJCmXEqy0zEj9vDH8Kpv+BZK7XjyR2cADtDjfVPldfLzRjzv6RQHkFdQRecEfx0aNsiqY3ZBQUMNqUchFRT8gfsANBAw8Ts1vM/Pnivu/SJ0qq9yDsaUmQ14M+BTy5yeAbQ8vf536RKxUSNu+3jJhtZnlv5RoR2IxDGUouiysd+0jOJRbrjCfvDgQHOXp0LHp2bfpdZnbMTpLG2v2iRQ== 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=QZhPBpz/6THlXJs8mcNWgMUSX5lyq896uZnrk4Padc8=; b=Cdssu2m2rHgLBv6Vep691ToyeQcObRRWAbnhIaSBhfxwjnoOaTv2Ri8jCRKj26pgmmpWTGs/sNfq/6PHlGF5FNAU83mN30Tic6jRbO5mBymNdHHpdg41QWanB2907ojTMySbJ6H0JTAVJkX+4RRv7q4HhkbspGouM1hOydHhplB2Tc1YX8QG8Ljk1jLiwcPAUTIes7JAPq0qKv8OKxyYwqvwKOzq+usi5M7tDs/6T5pSajSmuAKe6rmbFoOFptZxNc9eiUuCdqYBnwTzr9TqcdHNDnD7JR7jA626LkrVyrqbVadamCigD/X/Y8JQK+5VZ5nZDh07FoTWlNFLTu8D6g== Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=nvidia.com; Received: from BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) by BL1PR12MB5095.namprd12.prod.outlook.com (2603:10b6:208:31b::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.24; Tue, 8 Jun 2021 00:55:57 +0000 Received: from BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::3d51:a3b9:8611:684e]) by BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::3d51:a3b9:8611:684e%6]) with mapi id 15.20.4195.030; Tue, 8 Jun 2021 00:55:57 +0000 From: Jason Gunthorpe To: kvm@vger.kernel.org, Kirti Wankhede Cc: Christoph Hellwig Subject: [PATCH 10/10] vfio/mbochs: Convert to use vfio_register_group_dev() Date: Mon, 7 Jun 2021 21:55:52 -0300 Message-Id: <10-v1-324b2038f212+1041f1-vfio3a_jgg@nvidia.com> In-Reply-To: <0-v1-324b2038f212+1041f1-vfio3a_jgg@nvidia.com> References: X-Originating-IP: [47.55.113.94] X-ClientProxiedBy: MN2PR13CA0029.namprd13.prod.outlook.com (2603:10b6:208:160::42) To BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (47.55.113.94) by MN2PR13CA0029.namprd13.prod.outlook.com (2603:10b6:208:160::42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4219.9 via Frontend Transport; Tue, 8 Jun 2021 00:55:55 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lqQ24-003eKv-OJ; Mon, 07 Jun 2021 21:55:52 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ca815663-d4ba-42f3-697e-08d92a182be5 X-MS-TrafficTypeDiagnostic: BL1PR12MB5095: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:198; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MwD5eiJGoYYvVsZXEfyi/M7iyhQmVrkHZxbEw4EnWBGGNgqSriTIhbLuYsRrgkipL9ejsL2wfM5fbVUnUyY88OXNdxUOus+3c16WI3w+81lw4yEWFH4p041v5q5XoatJDZVOD3zvVhQuN3kx80bUGO0hZrsEohfvny0EnPwk5Tf9oheXcvEJJGqhkAPlhdAxvH0Ox8reNzVI9hr5CiXwHG68yq/woWWIcbM2ApHrpCFXpNV+cjM9NF1rtwNictWVAYCaa5IOXYWV4Dfp6nks+3pP8niIo6zsdU+bvLGKkBrAQs5LbnkoOaJhPNsmemm0eHPmoEVBqAOkZRlpAHja6WPle3sytAJGYfvc8504vW4nOU3YbMBL8dXH4SNXpY5O0VfXADwaU3zKJiksFjSHBrMTbpIK/jaXJV211GdMWbRRWs6iW80W/bbUTp7zibgz97AgYwneonkSuMXpqFeoN0CUW+KpCEU6MrryzI1F/8xrVKj57Nz7heInsLpgTm8U3HE4zSxfhRA+W8lr3A0L/ty8ZhpFYtlXcrvP9rq5Cf1JXnsydmdPIu+YgCpqrCYDgzn2nrwP1Mdi3njYEPn55Q9ceiuCITsATnVryj3Dlbw= 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)(39860400002)(376002)(136003)(346002)(366004)(396003)(2616005)(86362001)(9746002)(6862004)(66556008)(2906002)(37006003)(30864003)(36756003)(186003)(9786002)(4326008)(478600001)(426003)(6636002)(66476007)(83380400001)(8936002)(8676002)(26005)(66946007)(5660300002)(316002)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: lROJEOwxqtXBhYz7DCu3ZH0+hR3LNjNMuAiAA1s5PTR4lVo3PzhsjH5X2YPLP4ZycL03eHoPOdYd1B2KfICd84ZQReGPrWrLLu/mQfdGAPHr56SgezWhiIlKehywaGRcq4o125RkdreZB6hW0u1EPhdTTefGaDxhhKaSxKvRTOq0P4hOJZG07QmE/888ZRjqYVGmwUzICJnzGIiG963xnqQXF8IAmAvTigrEXv3JOVMnokPqVEaLuGtLjk1pzwjZ+2rf9AeULykB2wsSHxgkNfqHe5ls7qiS+3oh5i2a7uwkS/9cn6vdtCVKiPcFT9fnXp1QKd0vsDbhoR9Gd5+0Ju0PF1R259ahBlDNMM6Mz/idhAQTMU42ICUmLBCYVJf/C49Vmmlv4NNgy1bmNlGz/HYbpqvxIbuBpJyZv4W7k4w+OqOe/WO+N6n9748g3jiD9e3nP2rpM9XYdpjp3TFXP1ReEC0YJCuTYHqRNHVqZIpNMQ0tkDZINTPJlDuIlw96/fCUfVyV9zSH+lO1QL47I1SN1bFvb97j1F2JApTym9qLuTluG0DkZipGD2dMORdNhPmuSFqzJPHY//vhsut/dlAE6jtMJ9DTAOJPXWZlqR7T20kUe0BmfQov7UuB3ClG2c0SftodfSzeb4Uh0X9davOv2aqWkf/MjQj08pZ6wIcKmzb7QnMgwlxSIMs1DpJFYVV4KQhR1JMN3L+XzjeS2JXdpakJU059tVsVn9H+IOXYIfKV34PCMKPYYHGXA0UZ115oDhIzuL3VZEbQ+iLYjdt1DYAJjyM6Ix6prPUYPpJNIvg8Tw3ba9J1dfnHRistnPSuDDLW8EES+SeP+YY6XCoLZ357sbzhtGyuuusACaxh9jLI4rkeOZDJSPz396nrO8M7oYzITsL65KpkIWrFGepJGD1Nb63DzHLX/oLHwNk0e0BlC538ub3jFXyl+L2C81KnsEov31DNZrddO1x1SZdLADInHO9VfE/PMVZjOwibgHXJvOw5QCu+dkON2aFxcwAqufshbnBKYQ0Ej+ZoC8Zfu7Hb/iySNvTKw1fbL9BfCiO+LujLRdT2PBvgwfusohcJQxYsfajLuKFWS9Wfg6HTTJpEmV7AQkxoLEguSwZO053xmnMBS61qVwLRLqKhQ8wuGieoYbSRfZKXmbJAkjjf1xOvHz/r8fSLhpUdeEkhl/bchVMKCVY2q/+no4m0B7Nph+QQp2+4aQdXH0Sh5WaJAcH5R7WK1631NjCwLUWvnbk/Z1vPUPxS5MaXNgxolUHRLQKUAI1m+vhDDeERdFvCjGX6WwjtQpzwtk8Dajp4ycMAScwieNZhJOPEeGAI X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: ca815663-d4ba-42f3-697e-08d92a182be5 X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jun 2021 00:55:55.5693 (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: DfIccK6ABdjI9SECoYbImHA6yKjRlu3tvsUdJr1TgRPBYQvXZ8Kbr2vStcpkPeMW X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5095 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This is straightforward conversion, the mdev_state is actually serving as the vfio_device and we can replace all the mdev_get_drvdata()'s and the wonky dead code with a simple container_of(). Reviewed-by: Christoph Hellwig Signed-off-by: Jason Gunthorpe --- samples/vfio-mdev/mbochs.c | 163 +++++++++++++++++++++---------------- 1 file changed, 91 insertions(+), 72 deletions(-) diff --git a/samples/vfio-mdev/mbochs.c b/samples/vfio-mdev/mbochs.c index 881ef9a7296f23..6c0f229db36a1a 100644 --- a/samples/vfio-mdev/mbochs.c +++ b/samples/vfio-mdev/mbochs.c @@ -130,6 +130,7 @@ static struct class *mbochs_class; static struct cdev mbochs_cdev; static struct device mbochs_dev; static int mbochs_used_mbytes; +static const struct vfio_device_ops mbochs_dev_ops; struct vfio_region_info_ext { struct vfio_region_info base; @@ -160,6 +161,7 @@ struct mbochs_dmabuf { /* State of each mdev device */ struct mdev_state { + struct vfio_device vdev; u8 *vconfig; u64 bar_mask[3]; u32 memory_bar_mask; @@ -425,11 +427,9 @@ static void handle_edid_blob(struct mdev_state *mdev_state, u16 offset, memcpy(buf, mdev_state->edid_blob + offset, count); } -static ssize_t mdev_access(struct mdev_device *mdev, char *buf, size_t count, - loff_t pos, bool is_write) +static ssize_t mdev_access(struct mdev_state *mdev_state, char *buf, + size_t count, loff_t pos, bool is_write) { - struct mdev_state *mdev_state = mdev_get_drvdata(mdev); - struct device *dev = mdev_dev(mdev); struct page *pg; loff_t poff; char *map; @@ -478,7 +478,7 @@ static ssize_t mdev_access(struct mdev_device *mdev, char *buf, size_t count, put_page(pg); } else { - dev_dbg(dev, "%s: %s @0x%llx (unhandled)\n", + dev_dbg(mdev_state->vdev.dev, "%s: %s @0x%llx (unhandled)\n", __func__, is_write ? "WR" : "RD", pos); ret = -1; goto accessfailed; @@ -493,9 +493,8 @@ static ssize_t mdev_access(struct mdev_device *mdev, char *buf, size_t count, return ret; } -static int mbochs_reset(struct mdev_device *mdev) +static int mbochs_reset(struct mdev_state *mdev_state) { - struct mdev_state *mdev_state = mdev_get_drvdata(mdev); u32 size64k = mdev_state->memsize / (64 * 1024); int i; @@ -506,12 +505,13 @@ static int mbochs_reset(struct mdev_device *mdev) return 0; } -static int mbochs_create(struct mdev_device *mdev) +static int mbochs_probe(struct mdev_device *mdev) { const struct mbochs_type *type = &mbochs_types[mdev_get_type_group_id(mdev)]; struct device *dev = mdev_dev(mdev); struct mdev_state *mdev_state; + int ret = -ENOMEM; if (type->mbytes + mbochs_used_mbytes > max_mbytes) return -ENOMEM; @@ -519,6 +519,7 @@ static int mbochs_create(struct mdev_device *mdev) mdev_state = kzalloc(sizeof(struct mdev_state), GFP_KERNEL); if (mdev_state == NULL) return -ENOMEM; + vfio_init_group_dev(&mdev_state->vdev, &mdev->dev, &mbochs_dev_ops); mdev_state->vconfig = kzalloc(MBOCHS_CONFIG_SPACE_SIZE, GFP_KERNEL); if (mdev_state->vconfig == NULL) @@ -537,7 +538,6 @@ static int mbochs_create(struct mdev_device *mdev) mutex_init(&mdev_state->ops_lock); mdev_state->mdev = mdev; - mdev_set_drvdata(mdev, mdev_state); INIT_LIST_HEAD(&mdev_state->dmabufs); mdev_state->next_id = 1; @@ -547,32 +547,38 @@ static int mbochs_create(struct mdev_device *mdev) mdev_state->edid_regs.edid_offset = MBOCHS_EDID_BLOB_OFFSET; mdev_state->edid_regs.edid_max_size = sizeof(mdev_state->edid_blob); mbochs_create_config_space(mdev_state); - mbochs_reset(mdev); + mbochs_reset(mdev_state); mbochs_used_mbytes += type->mbytes; + + ret = vfio_register_group_dev(&mdev_state->vdev); + if (ret) + goto err_mem; + dev_set_drvdata(&mdev->dev, mdev_state); return 0; err_mem: kfree(mdev_state->vconfig); kfree(mdev_state); - return -ENOMEM; + return ret; } -static int mbochs_remove(struct mdev_device *mdev) +static void mbochs_remove(struct mdev_device *mdev) { - struct mdev_state *mdev_state = mdev_get_drvdata(mdev); + struct mdev_state *mdev_state = dev_get_drvdata(&mdev->dev); mbochs_used_mbytes -= mdev_state->type->mbytes; - mdev_set_drvdata(mdev, NULL); + vfio_unregister_group_dev(&mdev_state->vdev); kfree(mdev_state->pages); kfree(mdev_state->vconfig); kfree(mdev_state); - return 0; } -static ssize_t mbochs_read(struct mdev_device *mdev, char __user *buf, +static ssize_t mbochs_read(struct vfio_device *vdev, char __user *buf, size_t count, loff_t *ppos) { + struct mdev_state *mdev_state = + container_of(vdev, struct mdev_state, vdev); unsigned int done = 0; int ret; @@ -582,7 +588,7 @@ static ssize_t mbochs_read(struct mdev_device *mdev, char __user *buf, if (count >= 4 && !(*ppos % 4)) { u32 val; - ret = mdev_access(mdev, (char *)&val, sizeof(val), + ret = mdev_access(mdev_state, (char *)&val, sizeof(val), *ppos, false); if (ret <= 0) goto read_err; @@ -594,7 +600,7 @@ static ssize_t mbochs_read(struct mdev_device *mdev, char __user *buf, } else if (count >= 2 && !(*ppos % 2)) { u16 val; - ret = mdev_access(mdev, (char *)&val, sizeof(val), + ret = mdev_access(mdev_state, (char *)&val, sizeof(val), *ppos, false); if (ret <= 0) goto read_err; @@ -606,7 +612,7 @@ static ssize_t mbochs_read(struct mdev_device *mdev, char __user *buf, } else { u8 val; - ret = mdev_access(mdev, (char *)&val, sizeof(val), + ret = mdev_access(mdev_state, (char *)&val, sizeof(val), *ppos, false); if (ret <= 0) goto read_err; @@ -629,9 +635,11 @@ static ssize_t mbochs_read(struct mdev_device *mdev, char __user *buf, return -EFAULT; } -static ssize_t mbochs_write(struct mdev_device *mdev, const char __user *buf, +static ssize_t mbochs_write(struct vfio_device *vdev, const char __user *buf, size_t count, loff_t *ppos) { + struct mdev_state *mdev_state = + container_of(vdev, struct mdev_state, vdev); unsigned int done = 0; int ret; @@ -644,7 +652,7 @@ static ssize_t mbochs_write(struct mdev_device *mdev, const char __user *buf, if (copy_from_user(&val, buf, sizeof(val))) goto write_err; - ret = mdev_access(mdev, (char *)&val, sizeof(val), + ret = mdev_access(mdev_state, (char *)&val, sizeof(val), *ppos, true); if (ret <= 0) goto write_err; @@ -656,7 +664,7 @@ static ssize_t mbochs_write(struct mdev_device *mdev, const char __user *buf, if (copy_from_user(&val, buf, sizeof(val))) goto write_err; - ret = mdev_access(mdev, (char *)&val, sizeof(val), + ret = mdev_access(mdev_state, (char *)&val, sizeof(val), *ppos, true); if (ret <= 0) goto write_err; @@ -668,7 +676,7 @@ static ssize_t mbochs_write(struct mdev_device *mdev, const char __user *buf, if (copy_from_user(&val, buf, sizeof(val))) goto write_err; - ret = mdev_access(mdev, (char *)&val, sizeof(val), + ret = mdev_access(mdev_state, (char *)&val, sizeof(val), *ppos, true); if (ret <= 0) goto write_err; @@ -754,9 +762,10 @@ static const struct vm_operations_struct mbochs_region_vm_ops = { .fault = mbochs_region_vm_fault, }; -static int mbochs_mmap(struct mdev_device *mdev, struct vm_area_struct *vma) +static int mbochs_mmap(struct vfio_device *vdev, struct vm_area_struct *vma) { - struct mdev_state *mdev_state = mdev_get_drvdata(mdev); + struct mdev_state *mdev_state = + container_of(vdev, struct mdev_state, vdev); if (vma->vm_pgoff != MBOCHS_MEMORY_BAR_OFFSET >> PAGE_SHIFT) return -EINVAL; @@ -963,7 +972,7 @@ mbochs_dmabuf_find_by_id(struct mdev_state *mdev_state, u32 id) static int mbochs_dmabuf_export(struct mbochs_dmabuf *dmabuf) { struct mdev_state *mdev_state = dmabuf->mdev_state; - struct device *dev = mdev_dev(mdev_state->mdev); + struct device *dev = mdev_state->vdev.dev; DEFINE_DMA_BUF_EXPORT_INFO(exp_info); struct dma_buf *buf; @@ -991,15 +1000,10 @@ static int mbochs_dmabuf_export(struct mbochs_dmabuf *dmabuf) return 0; } -static int mbochs_get_region_info(struct mdev_device *mdev, +static int mbochs_get_region_info(struct mdev_state *mdev_state, struct vfio_region_info_ext *ext) { struct vfio_region_info *region_info = &ext->base; - struct mdev_state *mdev_state; - - mdev_state = mdev_get_drvdata(mdev); - if (!mdev_state) - return -EINVAL; if (region_info->index >= MBOCHS_NUM_REGIONS) return -EINVAL; @@ -1047,15 +1051,13 @@ static int mbochs_get_region_info(struct mdev_device *mdev, return 0; } -static int mbochs_get_irq_info(struct mdev_device *mdev, - struct vfio_irq_info *irq_info) +static int mbochs_get_irq_info(struct vfio_irq_info *irq_info) { irq_info->count = 0; return 0; } -static int mbochs_get_device_info(struct mdev_device *mdev, - struct vfio_device_info *dev_info) +static int mbochs_get_device_info(struct vfio_device_info *dev_info) { dev_info->flags = VFIO_DEVICE_FLAGS_PCI; dev_info->num_regions = MBOCHS_NUM_REGIONS; @@ -1063,11 +1065,9 @@ static int mbochs_get_device_info(struct mdev_device *mdev, return 0; } -static int mbochs_query_gfx_plane(struct mdev_device *mdev, +static int mbochs_query_gfx_plane(struct mdev_state *mdev_state, struct vfio_device_gfx_plane_info *plane) { - struct mdev_state *mdev_state = mdev_get_drvdata(mdev); - struct device *dev = mdev_dev(mdev); struct mbochs_dmabuf *dmabuf; struct mbochs_mode mode; int ret; @@ -1121,18 +1121,16 @@ static int mbochs_query_gfx_plane(struct mdev_device *mdev, done: if (plane->drm_plane_type == DRM_PLANE_TYPE_PRIMARY && mdev_state->active_id != plane->dmabuf_id) { - dev_dbg(dev, "%s: primary: %d => %d\n", __func__, - mdev_state->active_id, plane->dmabuf_id); + dev_dbg(mdev_state->vdev.dev, "%s: primary: %d => %d\n", + __func__, mdev_state->active_id, plane->dmabuf_id); mdev_state->active_id = plane->dmabuf_id; } mutex_unlock(&mdev_state->ops_lock); return 0; } -static int mbochs_get_gfx_dmabuf(struct mdev_device *mdev, - u32 id) +static int mbochs_get_gfx_dmabuf(struct mdev_state *mdev_state, u32 id) { - struct mdev_state *mdev_state = mdev_get_drvdata(mdev); struct mbochs_dmabuf *dmabuf; mutex_lock(&mdev_state->ops_lock); @@ -1154,9 +1152,11 @@ static int mbochs_get_gfx_dmabuf(struct mdev_device *mdev, return dma_buf_fd(dmabuf->buf, 0); } -static long mbochs_ioctl(struct mdev_device *mdev, unsigned int cmd, - unsigned long arg) +static long mbochs_ioctl(struct vfio_device *vdev, unsigned int cmd, + unsigned long arg) { + struct mdev_state *mdev_state = + container_of(vdev, struct mdev_state, vdev); int ret = 0; unsigned long minsz, outsz; @@ -1173,7 +1173,7 @@ static long mbochs_ioctl(struct mdev_device *mdev, unsigned int cmd, if (info.argsz < minsz) return -EINVAL; - ret = mbochs_get_device_info(mdev, &info); + ret = mbochs_get_device_info(&info); if (ret) return ret; @@ -1197,7 +1197,7 @@ static long mbochs_ioctl(struct mdev_device *mdev, unsigned int cmd, if (outsz > sizeof(info)) return -EINVAL; - ret = mbochs_get_region_info(mdev, &info); + ret = mbochs_get_region_info(mdev_state, &info); if (ret) return ret; @@ -1220,7 +1220,7 @@ static long mbochs_ioctl(struct mdev_device *mdev, unsigned int cmd, (info.index >= VFIO_PCI_NUM_IRQS)) return -EINVAL; - ret = mbochs_get_irq_info(mdev, &info); + ret = mbochs_get_irq_info(&info); if (ret) return ret; @@ -1243,7 +1243,7 @@ static long mbochs_ioctl(struct mdev_device *mdev, unsigned int cmd, if (plane.argsz < minsz) return -EINVAL; - ret = mbochs_query_gfx_plane(mdev, &plane); + ret = mbochs_query_gfx_plane(mdev_state, &plane); if (ret) return ret; @@ -1260,19 +1260,19 @@ static long mbochs_ioctl(struct mdev_device *mdev, unsigned int cmd, if (get_user(dmabuf_id, (__u32 __user *)arg)) return -EFAULT; - return mbochs_get_gfx_dmabuf(mdev, dmabuf_id); + return mbochs_get_gfx_dmabuf(mdev_state, dmabuf_id); } case VFIO_DEVICE_SET_IRQS: return -EINVAL; case VFIO_DEVICE_RESET: - return mbochs_reset(mdev); + return mbochs_reset(mdev_state); } return -ENOTTY; } -static int mbochs_open(struct mdev_device *mdev) +static int mbochs_open(struct vfio_device *vdev) { if (!try_module_get(THIS_MODULE)) return -ENODEV; @@ -1280,9 +1280,10 @@ static int mbochs_open(struct mdev_device *mdev) return 0; } -static void mbochs_close(struct mdev_device *mdev) +static void mbochs_close(struct vfio_device *vdev) { - struct mdev_state *mdev_state = mdev_get_drvdata(mdev); + struct mdev_state *mdev_state = + container_of(vdev, struct mdev_state, vdev); struct mbochs_dmabuf *dmabuf, *tmp; mutex_lock(&mdev_state->ops_lock); @@ -1306,8 +1307,7 @@ static ssize_t memory_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct mdev_device *mdev = mdev_from_dev(dev); - struct mdev_state *mdev_state = mdev_get_drvdata(mdev); + struct mdev_state *mdev_state = dev_get_drvdata(dev); return sprintf(buf, "%d MB\n", mdev_state->type->mbytes); } @@ -1398,18 +1398,30 @@ static struct attribute_group *mdev_type_groups[] = { NULL, }; +static const struct vfio_device_ops mbochs_dev_ops = { + .open = mbochs_open, + .release = mbochs_close, + .read = mbochs_read, + .write = mbochs_write, + .ioctl = mbochs_ioctl, + .mmap = mbochs_mmap, +}; + +static struct mdev_driver mbochs_driver = { + .driver = { + .name = "mbochs", + .owner = THIS_MODULE, + .mod_name = KBUILD_MODNAME, + .dev_groups = mdev_dev_groups, + }, + .probe = mbochs_probe, + .remove = mbochs_remove, +}; + static const struct mdev_parent_ops mdev_fops = { .owner = THIS_MODULE, - .mdev_attr_groups = mdev_dev_groups, + .device_driver = &mbochs_driver, .supported_type_groups = mdev_type_groups, - .create = mbochs_create, - .remove = mbochs_remove, - .open = mbochs_open, - .release = mbochs_close, - .read = mbochs_read, - .write = mbochs_write, - .ioctl = mbochs_ioctl, - .mmap = mbochs_mmap, }; static const struct file_operations vd_fops = { @@ -1434,11 +1446,15 @@ static int __init mbochs_dev_init(void) cdev_add(&mbochs_cdev, mbochs_devt, MINORMASK + 1); pr_info("%s: major %d\n", __func__, MAJOR(mbochs_devt)); + ret = mdev_register_driver(&mbochs_driver); + if (ret) + goto err_cdev; + mbochs_class = class_create(THIS_MODULE, MBOCHS_CLASS_NAME); if (IS_ERR(mbochs_class)) { pr_err("Error: failed to register mbochs_dev class\n"); ret = PTR_ERR(mbochs_class); - goto failed1; + goto err_driver; } mbochs_dev.class = mbochs_class; mbochs_dev.release = mbochs_device_release; @@ -1446,19 +1462,21 @@ static int __init mbochs_dev_init(void) ret = device_register(&mbochs_dev); if (ret) - goto failed2; + goto err_class; ret = mdev_register_device(&mbochs_dev, &mdev_fops); if (ret) - goto failed3; + goto err_device; return 0; -failed3: +err_device: device_unregister(&mbochs_dev); -failed2: +err_class: class_destroy(mbochs_class); -failed1: +err_driver: + mdev_unregister_driver(&mbochs_driver); +err_cdev: cdev_del(&mbochs_cdev); unregister_chrdev_region(mbochs_devt, MINORMASK + 1); return ret; @@ -1470,6 +1488,7 @@ static void __exit mbochs_dev_exit(void) mdev_unregister_device(&mbochs_dev); device_unregister(&mbochs_dev); + mdev_unregister_driver(&mbochs_driver); cdev_del(&mbochs_cdev); unregister_chrdev_region(mbochs_devt, MINORMASK + 1); class_destroy(mbochs_class);