From patchwork Tue Mar 23 17:55:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12158935 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=-16.0 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 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 B2CF9C433EB for ; Tue, 23 Mar 2021 17:56:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 874BC619CA for ; Tue, 23 Mar 2021 17:56:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231382AbhCWR4M (ORCPT ); Tue, 23 Mar 2021 13:56:12 -0400 Received: from mail-dm6nam12on2060.outbound.protection.outlook.com ([40.107.243.60]:2016 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231189AbhCWRzk (ORCPT ); Tue, 23 Mar 2021 13:55:40 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GAOf+1oGSRelp7WIo7pnputZ90iY0QGLXpcAs/Sb8iZFpa4eG0/W6z1uQfsPnMXnz9zg8vFZbwZy0A66z6Szce49CaN1CluEGcJJCPXY1nXkFepUfITKb1zhuoWjnN3WZuJnS35lX0cV7vV/lWPbXKPdTQb5bfNHyNanmXTx52uZtid1GyHeewG+hj0+45K+QMkVGt5OtrC6eHJAji6T5D3CLfpVFylE/9VzhYxKtwq5IENpnLu/j5AOWwdCTVaV9Tc+ni7sCVDRufd7qDSKaHcS1UrVw48vL5sbAQRW6xVKisZPOo60jGX//xCdbDcB0RincfQl8zUMG0BoxlVMWw== 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=N/HAznt68F6rbDQYGOO9tCbMJ1b8NHhHjawE7ou1i1U=; b=CUIKaTcCFWcJh9IsM9UFoebH0PvCmbZDM+lmMFTF6asrxpz+Sjy1l5p1tRDOX04OwEP9TwBHLqrd3VuKggtEpRMMPHQFDUHdWGswZWWSFCw7rknUhQIeArDo1Zb5l/JQTRVulC8I1Y2JZ5YxZRqAtBxx96az2NHA7nBZZgcyq55moQT01AJsHTxtDJfbKVWsOS0+weX7ImiZYsc1K0DexbwpC5F2lzC+GAAmn18V+FzhhSOIgQ20PMBppjDbgULdzMRFksT4CGI+NgHFiYH2ZWi9q4yzNMr0C23dprjBAS/jYiP111jVC+06mpkzo5cVOL06Ru3gCW80h85yQGz74w== 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=N/HAznt68F6rbDQYGOO9tCbMJ1b8NHhHjawE7ou1i1U=; b=A5F0+ZAuS+cDjIlzXXjEJH/sFy+2gY2odHdvpqwK5C+R1X7nb+pqnz2TbBneB9lz7Ry5IXMzw9FOl4Ru/Yjdint67GXqgVn5dd4emEQq/DrtzEvZSkuj5v5tiGSnukPAIcuhR/n6sEvyWPwPSXheSOSIwKW48TbvRPp2yycLXAEOKpVlex7Rhv5Modwm0BhX1tBy9xtMtMyPB8BvFzZm4dpO52EkgrHOB0f7iGGMrqgJJUxswfWVqttGy2gW6+KQlBfmzE+Rg+wkOgL8z17VJvfPNCHzYpJAA3zW49zCKBehaOSGpi3klYpowxl6EA0Zvd82irVUcoCMnABtVHs+Fw== 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 DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) by DM6PR12MB4483.namprd12.prod.outlook.com (2603:10b6:5:2a2::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3955.25; Tue, 23 Mar 2021 17:55:38 +0000 Received: from DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87]) by DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87%6]) with mapi id 15.20.3955.027; Tue, 23 Mar 2021 17:55:38 +0000 From: Jason Gunthorpe To: kvm@vger.kernel.org, Kirti Wankhede Cc: Alex Williamson , "Raj, Ashok" , Dan Williams , Christoph Hellwig , Gerd Hoffmann , Leon Romanovsky , Max Gurtovoy , Tarun Gupta Subject: [PATCH 01/18] vfio/mdev: Fix missing static's on MDEV_TYPE_ATTR's Date: Tue, 23 Mar 2021 14:55:18 -0300 Message-Id: <1-v1-7dedf20b2b75+4f785-vfio2_jgg@nvidia.com> In-Reply-To: <0-v1-7dedf20b2b75+4f785-vfio2_jgg@nvidia.com> References: X-Originating-IP: [206.223.160.26] X-ClientProxiedBy: BL0PR0102CA0012.prod.exchangelabs.com (2603:10b6:207:18::25) To DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (206.223.160.26) by BL0PR0102CA0012.prod.exchangelabs.com (2603:10b6:207:18::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3955.18 via Frontend Transport; Tue, 23 Mar 2021 17:55:36 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lOlFf-001cgQ-5W; Tue, 23 Mar 2021 14:55:35 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1afceb6a-6a7c-459f-de89-08d8ee24dd17 X-MS-TrafficTypeDiagnostic: DM6PR12MB4483: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:213; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KepQ0snNw0jlpS+gT3NzUfpbMYHvJBeEfFUVNLsB/cGmhj9q25S/i7xdyLGzg1odGmDswEtZx9JOyIZSe661FmDNzecK2ahBZuoO54RCdLZp4sDIDFMdbftfqmubi/G11+h2hntzsgQ0HUHxVY38g5Y8rIlbJzJxlPLasf7T41Qn1rlnlLjwuouOZmXtFHNgYXvBcY7WdMBWwaWSomnQ3AIrSQz2xvqlTAAbW6Tks3y+N/qN8eiwJu7QGEUN/4MHln7PLWvyO0pxBt0yayoNtOpLDvspm0iSdyEZRutz2Cl5YW0ROrR2EKzV5Dnnk8+YtxFo4Jp5cUJ47e4BlrQUUt3IGg9lvMkuLsxoOyVvV73W+N3jPKxyRcgcI6sOdJzLo4HovescAflVWxY+vN0azAAFuDfHgX2in6vi353Ds8i2QXlYoH/ew5MnNS/ZwaK+Wj5kLpcH7L0P4YXgiyD2EvU908XpUonDXfGxalmbiVKOw5XtqadBNWJePsZFsnK6hooNovjz7oIbeFVwD9nEGua7TmSB9aQLG+kOD5HdpD9W45EFGNqAmGGdDQbmMUw5O0JpdfYyTtj13zaNTl0SEV1NqO+Al2MWUYOzoKepKl1L1hvokEzSQGIzhy0WO+goZzMGWbcG6yszPVfvpdRK7a0c+feooyHMVAJz9lypGhkV6FWS0mRcdffPN0a3EtUD X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3834.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(366004)(39860400002)(136003)(396003)(346002)(186003)(26005)(36756003)(37006003)(5660300002)(38100700001)(66946007)(4326008)(66476007)(6666004)(2906002)(66556008)(54906003)(6636002)(478600001)(86362001)(316002)(8936002)(426003)(9746002)(6862004)(9786002)(107886003)(8676002)(2616005)(83380400001)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: nnOPZuHZ8jAf5Ds+zjNvWAlcGMh7HMAgpmgSDtR87fE6+SPvMpE8zQ//EsZXgw5GyZV1NxSWMvbmpfiAertzhQ5LNLDh69YHLfgC4BMcRBYJkHakbCqCRENm7gBGcEpJoEIGquvEm2Ex06wRbwoOdPEEYQ+1Se9+bph9EPKNej3DzIKbs/nmrgB6Jw6U+kl8jVaPL46SOs2Frdez6YW5Yo1gELii0x2VY+gySc0kk/IQ/iopnJZt/oQH+bp1uIJOy0J5Rp2C2isADZBoLWvBD2OMcrbv5K1oFymhekTxLVftlsO6xlRZde9UymV4lEyRPiiZ0wI9axvM5WbNEzXhmtfWsdbJJG1UduuCSU0DYGCsEi/TVaozUyWKZ9S08lmNVCpa+whALQI1ka50sVa/v8BlwxtMIUsdr/hjfICZu8VOJnRWORFyLF2Uk2OI9rcX/F5C0pKbNKW0xMk+aYFrCRBKEBs6ZQO+KBIEl1IrhGGbcpK71MWwSf9ZWoN3okkv4Zj1vcWap26Cs6Xm7DcL9bVVsz1Ad0byzrtwD5JxMjl8x+aXdtlGaDqFNAvMiJ0pD7JzT0Gj8gbDMe3y2xjvfdcqwee9kGoip19hrj8gA8mDuGO+ptAGJNaQnL71mfcepXURM/iyQGVBu2oD3hm61g2yMjQHVYAEurMOzbvM2+Nb4oI3XsFX+Gzh2OjDPKje5stkw/xoi1TTBNUgOI8wrctdYXRNQP3jilgX/ltiCHqn5lhx859K0tt7uzg95pGpggL+cEGdCF5Hu4SYzRpon+A98vK4UpUT3e0ZFeFnfHQq2sRHIHcbonRolJHyw0FVNp2oY4KICzwzlzax1X7v8/C06dpfNbHHXxZTVRvjYhKL4ogbe3gaaRrieAlvHOwdKtVefUyx7ssAGIuGcPZIJjOjQoiKGiBG89oCHi3DEJt2MdLq7HhIxamFZcZtKj531WumvZl/cRQbKvqTjf/xq4tc8xi/FeKCW3h6N/mjMBeOPQrY6/crq5GuZkAANDJbt4A4eM0Wsq+o9sJEKJFg2Pl9lHb1LkEm8AcNZGg5FTPZdWkshUxfYT0/7thSehaVawLAkCWlWk3pPooQev4Nxi6FAJQ09pUf4EApTT44p+3R5pF8HbjwWBn7g5u58/h6EDlz0IjBwT+h/sL24iTfjPXKF6sW+RiVPagykQHrd7+Y/CryKOX0vmHLgPHkHFiBytnbZ4uyNGSCiAA85HSTGe8j88+S5XWmBU237wQbbRAFoXo7MYGKku7QcHUSQC9bu7XvDZB9el/5vLJteOPWCAXEmWjKDIp456uHzF/LIYrnimMKtT/GPPIlHniISQvN X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1afceb6a-6a7c-459f-de89-08d8ee24dd17 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2021 17:55:37.0976 (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: qfsNatRpr2oLcF4ky/N4/TvregiI6OJp3AVGzE6YGdbGCeA2HaBk66PPzpARXSk+ X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4483 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org These should always be prefixed with static, otherwise compilation will fail on non-modular builds with ld: samples/vfio-mdev/mbochs.o:(.data+0x2e0): multiple definition of `mdev_type_attr_name'; samples/vfio-mdev/mdpy.o:(.data+0x240): first defined here Fixes: a5e6e6505f38 ("sample: vfio bochs vbe display (host device for bochs-drm)") Fixes: d61fc96f47fd ("sample: vfio mdev display - host device") Signed-off-by: Jason Gunthorpe --- samples/vfio-mdev/mbochs.c | 10 +++++----- samples/vfio-mdev/mdpy.c | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/samples/vfio-mdev/mbochs.c b/samples/vfio-mdev/mbochs.c index e03068917273d4..365afbe2dea558 100644 --- a/samples/vfio-mdev/mbochs.c +++ b/samples/vfio-mdev/mbochs.c @@ -1334,7 +1334,7 @@ static const struct attribute_group mdev_dev_group = { .attrs = mdev_dev_attrs, }; -const struct attribute_group *mdev_dev_groups[] = { +static const struct attribute_group *mdev_dev_groups[] = { &mdev_dev_group, NULL, }; @@ -1344,7 +1344,7 @@ name_show(struct kobject *kobj, struct device *dev, char *buf) { return sprintf(buf, "%s\n", kobj->name); } -MDEV_TYPE_ATTR_RO(name); +static MDEV_TYPE_ATTR_RO(name); static ssize_t description_show(struct kobject *kobj, struct device *dev, char *buf) @@ -1354,7 +1354,7 @@ description_show(struct kobject *kobj, struct device *dev, char *buf) return sprintf(buf, "virtual display, %d MB video memory\n", type ? type->mbytes : 0); } -MDEV_TYPE_ATTR_RO(description); +static MDEV_TYPE_ATTR_RO(description); static ssize_t available_instances_show(struct kobject *kobj, struct device *dev, char *buf) @@ -1364,14 +1364,14 @@ available_instances_show(struct kobject *kobj, struct device *dev, char *buf) return sprintf(buf, "%d\n", count); } -MDEV_TYPE_ATTR_RO(available_instances); +static MDEV_TYPE_ATTR_RO(available_instances); static ssize_t device_api_show(struct kobject *kobj, struct device *dev, char *buf) { return sprintf(buf, "%s\n", VFIO_DEVICE_API_PCI_STRING); } -MDEV_TYPE_ATTR_RO(device_api); +static MDEV_TYPE_ATTR_RO(device_api); static struct attribute *mdev_types_attrs[] = { &mdev_type_attr_name.attr, diff --git a/samples/vfio-mdev/mdpy.c b/samples/vfio-mdev/mdpy.c index 9894693f3be178..d4ec2b52ca49a1 100644 --- a/samples/vfio-mdev/mdpy.c +++ b/samples/vfio-mdev/mdpy.c @@ -658,7 +658,7 @@ static const struct attribute_group mdev_dev_group = { .attrs = mdev_dev_attrs, }; -const struct attribute_group *mdev_dev_groups[] = { +static const struct attribute_group *mdev_dev_groups[] = { &mdev_dev_group, NULL, }; @@ -668,7 +668,7 @@ name_show(struct kobject *kobj, struct device *dev, char *buf) { return sprintf(buf, "%s\n", kobj->name); } -MDEV_TYPE_ATTR_RO(name); +static MDEV_TYPE_ATTR_RO(name); static ssize_t description_show(struct kobject *kobj, struct device *dev, char *buf) @@ -679,21 +679,21 @@ description_show(struct kobject *kobj, struct device *dev, char *buf) type ? type->width : 0, type ? type->height : 0); } -MDEV_TYPE_ATTR_RO(description); +static MDEV_TYPE_ATTR_RO(description); static ssize_t available_instances_show(struct kobject *kobj, struct device *dev, char *buf) { return sprintf(buf, "%d\n", max_devices - mdpy_count); } -MDEV_TYPE_ATTR_RO(available_instances); +static MDEV_TYPE_ATTR_RO(available_instances); static ssize_t device_api_show(struct kobject *kobj, struct device *dev, char *buf) { return sprintf(buf, "%s\n", VFIO_DEVICE_API_PCI_STRING); } -MDEV_TYPE_ATTR_RO(device_api); +static MDEV_TYPE_ATTR_RO(device_api); static struct attribute *mdev_types_attrs[] = { &mdev_type_attr_name.attr, From patchwork Tue Mar 23 17:55:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12158937 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=-16.0 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 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 2E190C433FB for ; Tue, 23 Mar 2021 17:56:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1D876619CD for ; Tue, 23 Mar 2021 17:56:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231426AbhCWR4W (ORCPT ); Tue, 23 Mar 2021 13:56:22 -0400 Received: from mail-bn8nam12on2077.outbound.protection.outlook.com ([40.107.237.77]:36673 "EHLO NAM12-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231338AbhCWRzq (ORCPT ); Tue, 23 Mar 2021 13:55:46 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZAB9gnNgjPwOf8c+ckGKi3irbdxKxWR86W/4Gu+U3IecaFre4W8NFr7aCCywuM5MsYmSKiIUHYJhl5MEkxhzY0PuWu72x2j3YhUGEDQJM7+mfirBcNFcpJ7OTZDlHafxoiEjB/HBIz4svDglh+MXaH9rBq750mfytu12wdyQKFzazfmqD2Vl+Tg+razUGR0+GIwgc+7eGlj2YTizTEw4nosAPR+K/CvVljDsD4TkWLj65/qJdeQLyHEmgGsMSQ7aITEfUSAzErQydGRvFwXx556DDmalzoFWTJDrOoJUHzfivbuElP2/EyOwc5ukZSgl356mkKbxadXsHg2tX3sq0g== 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=rN+SzwthwoTDPJovcRyTFOvgz1yqbotPudBWjrbNd1k=; b=jf9ARZN63jnRuIIuRMjOOV1KqwtvpYZQT3xk+1mTCTLaGyM8VJN5xRYZwZAuwv+K2nZaj6WN478jFzpqhBSX14/oRhmQdeFPcE2K2TbrpuSZ/kD166U+t7epy2m5bVpPyjCE/lbVxWuxc1mqoRlpm9eecEDQM5dAaVXSMp/dE79F63BuYg9tNFKxjuaNtnOmVFcJYLtIDcrUVAUyUbpsRNmxqCFTBaebe2zs+38bXiaVPf3s0m55gZsbU5itqVkRKq2vTtJZ1Uz1aDadfohbRVEidnOTJo5OvN3PSQhsuZbKSLxQrqxz9ofp2Xz3qf8xFJUS9hd07BW9wdPXlRG/Xw== 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=rN+SzwthwoTDPJovcRyTFOvgz1yqbotPudBWjrbNd1k=; b=DEWAFWOXtcPiDGA99uN5DxgzTyqXBfTqVO/0cUVmlYn8FU/5QuOuNEQRKycMzJes+k/eQzZAKs7qSXqrFG7RJE4FjbSCA2Mx5P6G5PC4282QuerkPEbS+DYT295+PoMVOi7p2rGNCuiHf76XLabVKBpAbu6K1eQTodZpiv3Enp7gLRvVNAPmpZOLTp0kyz6f0sdAOpLAqJAFULYrd6OObpTP/OtILTXRLf8FR4K0FozQc/obTORjrlabojd5kzMgVfq/yGwcwt+PynqZN406W9Me95hvdTZ8c33hQPhOQGsan9PPyQRJFG6qNNDRQRBIIlvNeKpmclTr7ATBN71Tvg== Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) by DM6PR12MB4943.namprd12.prod.outlook.com (2603:10b6:5:1bc::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3955.18; Tue, 23 Mar 2021 17:55:44 +0000 Received: from DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87]) by DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87%6]) with mapi id 15.20.3955.027; Tue, 23 Mar 2021 17:55:43 +0000 From: Jason Gunthorpe To: Alex Williamson , Cornelia Huck , Jonathan Corbet , kvm@vger.kernel.org, Kirti Wankhede , linux-doc@vger.kernel.org Cc: "Raj, Ashok" , Dan Williams , Christoph Hellwig , Leon Romanovsky , Max Gurtovoy , Tarun Gupta Subject: [PATCH 02/18] vfio/mdev: Add missing typesafety around mdev_device Date: Tue, 23 Mar 2021 14:55:19 -0300 Message-Id: <2-v1-7dedf20b2b75+4f785-vfio2_jgg@nvidia.com> In-Reply-To: <0-v1-7dedf20b2b75+4f785-vfio2_jgg@nvidia.com> References: X-Originating-IP: [206.223.160.26] X-ClientProxiedBy: BL0PR0102CA0007.prod.exchangelabs.com (2603:10b6:207:18::20) To DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (206.223.160.26) by BL0PR0102CA0007.prod.exchangelabs.com (2603:10b6:207:18::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.24 via Frontend Transport; Tue, 23 Mar 2021 17:55:40 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lOlFf-001cgU-7Z; Tue, 23 Mar 2021 14:55:35 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a382bd8f-cad8-4c58-2806-08d8ee24df5c X-MS-TrafficTypeDiagnostic: DM6PR12MB4943: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YeV6d8+BSjTwxwDx9x6ju3gmdzBNOXC2IW3KSVm0dqNJtATEg8fxLieM7PFdBPOMNPdKGblCb9OigFdphb+fnFTFpDIP2q79vtTRtUBToaaOYxrD9uigab+ZdFVSD3ySXAVX+zqpVHuhpaSwKlJRz0xudX2UV3RD5V98qK2fQT0AYxm//Glj8BzyuIx2WqjhpW8DbUNG2anQciMEnqy80ZNeO3HpkII9wB+MtYLTlllzAKFvzH68S4MX34Bv8FVXYQh4ApaN9vW7wWeOKsBxJtobXrd11oNjJriiP+hIzsVsG1P7jYRsuJ27ECtSMeg0BPqRaCdtvi34HVRSJppzXBU+H7bibt8hgnyeFFQpRjP5QqMsAcHe5lamKTaK7riPoCSKmBr1FGxkpbhtzbB5kcAYTY+LZEq9xC7V3BdBdPWkYneAU91s1O/l45+dFQPLgk8iB+kdbQpdfncxBLlKPG/z30GMLxx2kMPJ2A+2wGcUGCJdLyQHP4O3gvP+FJUSyw6DuwDXKARrJThkJtya/LXVcXlvC6FKoEyS96Tb+uOcW5e2HBGa8/aVvP/M2f/NlRkmc2HtrakfRugmOW4/oPkhqFTLi42rMrByWAM2VNPtcX1JmOK+8/qEuDdz8shjt/9J8MBBAfQFis2goUbx8IZBlWLOM/Xsv8zEFYlEe8M= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3834.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(39860400002)(136003)(376002)(366004)(346002)(66476007)(186003)(107886003)(6666004)(8936002)(110136005)(36756003)(426003)(86362001)(54906003)(83380400001)(2616005)(38100700001)(30864003)(66946007)(5660300002)(478600001)(9746002)(66556008)(8676002)(4326008)(2906002)(26005)(316002)(9786002)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: mR5AcRZsXSeUyx46Z3+EZ01WUN9kvTwjkYtPQji9HWG666+lNNmz4tU4Q5qp0MlR0ahDo3OEmU+RqU7Xrr469kIq01Tawnbmm1E6k3b375StE/Fgj8/yh7VaH3G9m3f5t+U+Pgf39FKGWK+alo8BXY0yxTviR+32GZ9IF1OFM/CTXwcdOQjvsLAjrRSPei2ZkXrCknXlo2QkPvzz0KA3YdO6++Vv5X5vkQMWd3HBftNhQqJtlFL7Ddobzt6jXKqy+pwmb84v51gakj1DF13GKq2YYTGFqnmRzw9HCaDQgLU4LdD2LPIX3x1n4be7whYzSgmAHxplqEkfH486IlXeAb5qo19FC0+HAUt6qJ+lDJPmZ4H88hsj8euBxJprU0qT70cakawkWltIV7jFWtU2F7fwkrreY0IeAJ0as28Mru7Rt3YnWICcPvtB4yfgTkMvgqE2RQOOdFv1HaicJyWHCo/Sa/q8mI6U3oBPb+mj8Ml1CktN+iTV1sc+dmiD38Zju4Uy/h3O/ui04RQimQpO3aL7bW24KZ3SxQ6pYiQMUGmf0SSRSzletEDq0x1FbzYQ1nbzK+nLiVPCsYjgOYHxO2Whsj0EbwAp9PTgGnyilksJlpPuT3TB0gLdtXRrmYzafK3VOFVao7blxmCHfHRuG147ySk5cR8LQ8hRetnCkeSXvwH0aGJoVN2AETdVDY/hxlnC2wiSRYWHbr5LR8Jr+Of41iai5kDfSb7caylmiiHK+KtY+sjJ8iVcmG+6dWuPFz+Wp7g/CqfEwcjsGPuokGzB2OlXYh/lbFlwP1zaGQJKxNhAjgD6Rf91/NYS69Thb33HA+DpjAedzpH+VcjABU84CnGK8OTHqj1uySDAlj56XjOGvI9faI+36/kZfzNmFe03UPb516VZiK9ybxvuL09a2CP2xOLomW1PqkhvkNwb2Uqs3PS/RKl17pDuPKpliUrs9dcXmDg9hDM8FM2zQsyUmcbCIn+Ap5odvPAFq69OCZDrkD5EzHtm1p7xQPqOd89z3Ud7aWdeZzjY+VJTnNGG280zif6CdZegE5jCn/920FnimYTazKJOxTWsYygfrGKlwT0JAycNqRlwFA1dOF7knz44HBnwvCK43MSKFOIqaKXYE2CtyioszuvVRPdj8/R7s+/kMd4r4BVdQ9SABG9mRFB+wxvO6Hd108CFHxODFmdISr5kJbAgEAmdOCl8U7Dv0vjCpcLXjFp2a8BLKHgIwOFirA3JGWeP7r7sDPWb3nJCR10ShAzRwMfxn57OfEcGt13XK5QLu+lriKKO3hL0fSUznm+QGAHsUFtXrOkgRWqOICo1xG9wLZB5OjOY X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: a382bd8f-cad8-4c58-2806-08d8ee24df5c X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2021 17:55:41.2584 (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: jrGnUrJ8KzjkS3YZGuyZvHhJSlW+8Gr+oN3RvsdIJmc7TPQ5rYiCgYNMF2/0NXx7 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4943 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The mdev API should accept and pass a 'struct mdev_device *' in all places, not pass a 'struct device *' and cast it internally with to_mdev_device(). Particularly in its struct mdev_driver functions, the whole point of a bus's struct device_driver wrapper is to provide type safety compared to the default struct device_driver. Further, the driver core standard is for bus drivers to expose their device structure in their public headers that can be used with container_of() inlines and '&foo->dev' to go between the class levels, and '&foo->dev' to be used with dev_err/etc driver core helper functions. Move 'struct mdev_device' to mdev.h Once done this allows moving some one instruction exported functions to static inlines, which in turns allows removing one of the two grotesque symbol_get()'s related to mdev in the core code. Signed-off-by: Jason Gunthorpe Reviewed-by: Kevin Tian Reviewed-by: Cornelia Huck --- .../driver-api/vfio-mediated-device.rst | 4 +- drivers/vfio/mdev/mdev_core.c | 64 ++----------------- drivers/vfio/mdev/mdev_driver.c | 4 +- drivers/vfio/mdev/mdev_private.h | 23 +------ drivers/vfio/mdev/mdev_sysfs.c | 26 ++++---- drivers/vfio/mdev/vfio_mdev.c | 7 +- drivers/vfio/vfio_iommu_type1.c | 25 ++------ include/linux/mdev.h | 58 +++++++++++++---- 8 files changed, 83 insertions(+), 128 deletions(-) diff --git a/Documentation/driver-api/vfio-mediated-device.rst b/Documentation/driver-api/vfio-mediated-device.rst index 25eb7d5b834ba3..c43c1dc3333373 100644 --- a/Documentation/driver-api/vfio-mediated-device.rst +++ b/Documentation/driver-api/vfio-mediated-device.rst @@ -105,8 +105,8 @@ structure to represent a mediated device's driver:: */ struct mdev_driver { const char *name; - int (*probe) (struct device *dev); - void (*remove) (struct device *dev); + int (*probe) (struct mdev_device *dev); + void (*remove) (struct mdev_device *dev); struct device_driver driver; }; diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c index 6de97d25a3f87d..057922a1707e04 100644 --- a/drivers/vfio/mdev/mdev_core.c +++ b/drivers/vfio/mdev/mdev_core.c @@ -33,36 +33,6 @@ struct device *mdev_parent_dev(struct mdev_device *mdev) } EXPORT_SYMBOL(mdev_parent_dev); -void *mdev_get_drvdata(struct mdev_device *mdev) -{ - return mdev->driver_data; -} -EXPORT_SYMBOL(mdev_get_drvdata); - -void mdev_set_drvdata(struct mdev_device *mdev, void *data) -{ - mdev->driver_data = data; -} -EXPORT_SYMBOL(mdev_set_drvdata); - -struct device *mdev_dev(struct mdev_device *mdev) -{ - return &mdev->dev; -} -EXPORT_SYMBOL(mdev_dev); - -struct mdev_device *mdev_from_dev(struct device *dev) -{ - return dev_is_mdev(dev) ? to_mdev_device(dev) : NULL; -} -EXPORT_SYMBOL(mdev_from_dev); - -const guid_t *mdev_uuid(struct mdev_device *mdev) -{ - return &mdev->uuid; -} -EXPORT_SYMBOL(mdev_uuid); - /* Should be called holding parent_list_lock */ static struct mdev_parent *__find_parent_device(struct device *dev) { @@ -107,7 +77,7 @@ static void mdev_device_remove_common(struct mdev_device *mdev) int ret; type = to_mdev_type(mdev->type_kobj); - mdev_remove_sysfs_files(&mdev->dev, type); + mdev_remove_sysfs_files(mdev, type); device_del(&mdev->dev); parent = mdev->parent; lockdep_assert_held(&parent->unreg_sem); @@ -122,12 +92,10 @@ static void mdev_device_remove_common(struct mdev_device *mdev) static int mdev_device_remove_cb(struct device *dev, void *data) { - if (dev_is_mdev(dev)) { - struct mdev_device *mdev; + struct mdev_device *mdev = mdev_from_dev(dev); - mdev = to_mdev_device(dev); + if (mdev) mdev_device_remove_common(mdev); - } return 0; } @@ -332,7 +300,7 @@ int mdev_device_create(struct kobject *kobj, if (ret) goto add_fail; - ret = mdev_create_sysfs_files(&mdev->dev, type); + ret = mdev_create_sysfs_files(mdev, type); if (ret) goto sysfs_fail; @@ -354,13 +322,11 @@ int mdev_device_create(struct kobject *kobj, return ret; } -int mdev_device_remove(struct device *dev) +int mdev_device_remove(struct mdev_device *mdev) { - struct mdev_device *mdev, *tmp; + struct mdev_device *tmp; struct mdev_parent *parent; - mdev = to_mdev_device(dev); - mutex_lock(&mdev_list_lock); list_for_each_entry(tmp, &mdev_list, next) { if (tmp == mdev) @@ -390,24 +356,6 @@ int mdev_device_remove(struct device *dev) return 0; } -int mdev_set_iommu_device(struct device *dev, struct device *iommu_device) -{ - struct mdev_device *mdev = to_mdev_device(dev); - - mdev->iommu_device = iommu_device; - - return 0; -} -EXPORT_SYMBOL(mdev_set_iommu_device); - -struct device *mdev_get_iommu_device(struct device *dev) -{ - struct mdev_device *mdev = to_mdev_device(dev); - - return mdev->iommu_device; -} -EXPORT_SYMBOL(mdev_get_iommu_device); - static int __init mdev_init(void) { return mdev_bus_register(); diff --git a/drivers/vfio/mdev/mdev_driver.c b/drivers/vfio/mdev/mdev_driver.c index 0d3223aee20b83..44c3ba7e56d923 100644 --- a/drivers/vfio/mdev/mdev_driver.c +++ b/drivers/vfio/mdev/mdev_driver.c @@ -48,7 +48,7 @@ static int mdev_probe(struct device *dev) return ret; if (drv && drv->probe) { - ret = drv->probe(dev); + ret = drv->probe(mdev); if (ret) mdev_detach_iommu(mdev); } @@ -62,7 +62,7 @@ static int mdev_remove(struct device *dev) struct mdev_device *mdev = to_mdev_device(dev); if (drv && drv->remove) - drv->remove(dev); + drv->remove(mdev); mdev_detach_iommu(mdev); diff --git a/drivers/vfio/mdev/mdev_private.h b/drivers/vfio/mdev/mdev_private.h index 74c2e541146999..bb60ec4a8d9d21 100644 --- a/drivers/vfio/mdev/mdev_private.h +++ b/drivers/vfio/mdev/mdev_private.h @@ -24,23 +24,6 @@ struct mdev_parent { struct rw_semaphore unreg_sem; }; -struct mdev_device { - struct device dev; - struct mdev_parent *parent; - guid_t uuid; - void *driver_data; - struct list_head next; - struct kobject *type_kobj; - struct device *iommu_device; - bool active; -}; - -static inline struct mdev_device *to_mdev_device(struct device *dev) -{ - return container_of(dev, struct mdev_device, dev); -} -#define dev_is_mdev(d) ((d)->bus == &mdev_bus_type) - struct mdev_type { struct kobject kobj; struct kobject *devices_kobj; @@ -57,11 +40,11 @@ struct mdev_type { int parent_create_sysfs_files(struct mdev_parent *parent); void parent_remove_sysfs_files(struct mdev_parent *parent); -int mdev_create_sysfs_files(struct device *dev, struct mdev_type *type); -void mdev_remove_sysfs_files(struct device *dev, struct mdev_type *type); +int mdev_create_sysfs_files(struct mdev_device *mdev, struct mdev_type *type); +void mdev_remove_sysfs_files(struct mdev_device *mdev, struct mdev_type *type); int mdev_device_create(struct kobject *kobj, struct device *dev, const guid_t *uuid); -int mdev_device_remove(struct device *dev); +int mdev_device_remove(struct mdev_device *dev); #endif /* MDEV_PRIVATE_H */ diff --git a/drivers/vfio/mdev/mdev_sysfs.c b/drivers/vfio/mdev/mdev_sysfs.c index 917fd84c1c6f24..6a5450587b79e9 100644 --- a/drivers/vfio/mdev/mdev_sysfs.c +++ b/drivers/vfio/mdev/mdev_sysfs.c @@ -225,6 +225,7 @@ int parent_create_sysfs_files(struct mdev_parent *parent) static ssize_t remove_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { + struct mdev_device *mdev = to_mdev_device(dev); unsigned long val; if (kstrtoul(buf, 0, &val) < 0) @@ -233,7 +234,7 @@ static ssize_t remove_store(struct device *dev, struct device_attribute *attr, if (val && device_remove_file_self(dev, attr)) { int ret; - ret = mdev_device_remove(dev); + ret = mdev_device_remove(mdev); if (ret) return ret; } @@ -248,34 +249,37 @@ static const struct attribute *mdev_device_attrs[] = { NULL, }; -int mdev_create_sysfs_files(struct device *dev, struct mdev_type *type) +int mdev_create_sysfs_files(struct mdev_device *mdev, struct mdev_type *type) { + struct kobject *kobj = &mdev->dev.kobj; int ret; - ret = sysfs_create_link(type->devices_kobj, &dev->kobj, dev_name(dev)); + ret = sysfs_create_link(type->devices_kobj, kobj, dev_name(&mdev->dev)); if (ret) return ret; - ret = sysfs_create_link(&dev->kobj, &type->kobj, "mdev_type"); + ret = sysfs_create_link(kobj, &type->kobj, "mdev_type"); if (ret) goto type_link_failed; - ret = sysfs_create_files(&dev->kobj, mdev_device_attrs); + ret = sysfs_create_files(kobj, mdev_device_attrs); if (ret) goto create_files_failed; return ret; create_files_failed: - sysfs_remove_link(&dev->kobj, "mdev_type"); + sysfs_remove_link(kobj, "mdev_type"); type_link_failed: - sysfs_remove_link(type->devices_kobj, dev_name(dev)); + sysfs_remove_link(type->devices_kobj, dev_name(&mdev->dev)); return ret; } -void mdev_remove_sysfs_files(struct device *dev, struct mdev_type *type) +void mdev_remove_sysfs_files(struct mdev_device *mdev, struct mdev_type *type) { - sysfs_remove_files(&dev->kobj, mdev_device_attrs); - sysfs_remove_link(&dev->kobj, "mdev_type"); - sysfs_remove_link(type->devices_kobj, dev_name(dev)); + struct kobject *kobj = &mdev->dev.kobj; + + sysfs_remove_files(kobj, mdev_device_attrs); + sysfs_remove_link(kobj, "mdev_type"); + sysfs_remove_link(type->devices_kobj, dev_name(&mdev->dev)); } diff --git a/drivers/vfio/mdev/vfio_mdev.c b/drivers/vfio/mdev/vfio_mdev.c index ae7e322fbe3c26..91b7b8b9eb9cb8 100644 --- a/drivers/vfio/mdev/vfio_mdev.c +++ b/drivers/vfio/mdev/vfio_mdev.c @@ -124,9 +124,8 @@ static const struct vfio_device_ops vfio_mdev_dev_ops = { .request = vfio_mdev_request, }; -static int vfio_mdev_probe(struct device *dev) +static int vfio_mdev_probe(struct mdev_device *mdev) { - struct mdev_device *mdev = to_mdev_device(dev); struct vfio_device *vdev; int ret; @@ -144,9 +143,9 @@ static int vfio_mdev_probe(struct device *dev) return 0; } -static void vfio_mdev_remove(struct device *dev) +static void vfio_mdev_remove(struct mdev_device *mdev) { - struct vfio_device *vdev = dev_get_drvdata(dev); + struct vfio_device *vdev = dev_get_drvdata(&mdev->dev); vfio_unregister_group_dev(vdev); kfree(vdev); diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index 4bb162c1d649b3..90b45ff1d87a7b 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -1923,28 +1923,13 @@ static bool vfio_iommu_has_sw_msi(struct list_head *group_resv_regions, return ret; } -static struct device *vfio_mdev_get_iommu_device(struct device *dev) -{ - struct device *(*fn)(struct device *dev); - struct device *iommu_device; - - fn = symbol_get(mdev_get_iommu_device); - if (fn) { - iommu_device = fn(dev); - symbol_put(mdev_get_iommu_device); - - return iommu_device; - } - - return NULL; -} - static int vfio_mdev_attach_domain(struct device *dev, void *data) { + struct mdev_device *mdev = to_mdev_device(dev); struct iommu_domain *domain = data; struct device *iommu_device; - iommu_device = vfio_mdev_get_iommu_device(dev); + iommu_device = mdev_get_iommu_device(mdev); if (iommu_device) { if (iommu_dev_feature_enabled(iommu_device, IOMMU_DEV_FEAT_AUX)) return iommu_aux_attach_device(domain, iommu_device); @@ -1957,10 +1942,11 @@ static int vfio_mdev_attach_domain(struct device *dev, void *data) static int vfio_mdev_detach_domain(struct device *dev, void *data) { + struct mdev_device *mdev = to_mdev_device(dev); struct iommu_domain *domain = data; struct device *iommu_device; - iommu_device = vfio_mdev_get_iommu_device(dev); + iommu_device = mdev_get_iommu_device(mdev); if (iommu_device) { if (iommu_dev_feature_enabled(iommu_device, IOMMU_DEV_FEAT_AUX)) iommu_aux_detach_device(domain, iommu_device); @@ -2008,9 +1994,10 @@ static bool vfio_bus_is_mdev(struct bus_type *bus) static int vfio_mdev_iommu_device(struct device *dev, void *data) { + struct mdev_device *mdev = to_mdev_device(dev); struct device **old = data, *new; - new = vfio_mdev_get_iommu_device(dev); + new = mdev_get_iommu_device(mdev); if (!new || (*old && *old != new)) return -EINVAL; diff --git a/include/linux/mdev.h b/include/linux/mdev.h index 27eb383cb95de0..52f7ea19dd0f56 100644 --- a/include/linux/mdev.h +++ b/include/linux/mdev.h @@ -10,7 +10,21 @@ #ifndef MDEV_H #define MDEV_H -struct mdev_device; +struct mdev_device { + struct device dev; + struct mdev_parent *parent; + guid_t uuid; + void *driver_data; + struct list_head next; + struct kobject *type_kobj; + struct device *iommu_device; + bool active; +}; + +static inline struct mdev_device *to_mdev_device(struct device *dev) +{ + return container_of(dev, struct mdev_device, dev); +} /* * Called by the parent device driver to set the device which represents @@ -19,12 +33,17 @@ struct mdev_device; * * @dev: the mediated device that iommu will isolate. * @iommu_device: a pci device which represents the iommu for @dev. - * - * Return 0 for success, otherwise negative error value. */ -int mdev_set_iommu_device(struct device *dev, struct device *iommu_device); +static inline void mdev_set_iommu_device(struct mdev_device *mdev, + struct device *iommu_device) +{ + mdev->iommu_device = iommu_device; +} -struct device *mdev_get_iommu_device(struct device *dev); +static inline struct device *mdev_get_iommu_device(struct mdev_device *mdev) +{ + return mdev->iommu_device; +} /** * struct mdev_parent_ops - Structure to be registered for each parent device to @@ -126,16 +145,25 @@ struct mdev_type_attribute mdev_type_attr_##_name = \ **/ struct mdev_driver { const char *name; - int (*probe)(struct device *dev); - void (*remove)(struct device *dev); + int (*probe)(struct mdev_device *dev); + void (*remove)(struct mdev_device *dev); struct device_driver driver; }; #define to_mdev_driver(drv) container_of(drv, struct mdev_driver, driver) -void *mdev_get_drvdata(struct mdev_device *mdev); -void mdev_set_drvdata(struct mdev_device *mdev, void *data); -const guid_t *mdev_uuid(struct mdev_device *mdev); +static inline void *mdev_get_drvdata(struct mdev_device *mdev) +{ + return mdev->driver_data; +} +static inline void mdev_set_drvdata(struct mdev_device *mdev, void *data) +{ + mdev->driver_data = data; +} +static inline const guid_t *mdev_uuid(struct mdev_device *mdev) +{ + return &mdev->uuid; +} extern struct bus_type mdev_bus_type; @@ -146,7 +174,13 @@ int mdev_register_driver(struct mdev_driver *drv, struct module *owner); void mdev_unregister_driver(struct mdev_driver *drv); struct device *mdev_parent_dev(struct mdev_device *mdev); -struct device *mdev_dev(struct mdev_device *mdev); -struct mdev_device *mdev_from_dev(struct device *dev); +static inline struct device *mdev_dev(struct mdev_device *mdev) +{ + return &mdev->dev; +} +static inline struct mdev_device *mdev_from_dev(struct device *dev) +{ + return dev->bus == &mdev_bus_type ? to_mdev_device(dev) : NULL; +} #endif /* MDEV_H */ From patchwork Tue Mar 23 17:55:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12158975 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=-16.0 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 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 47DA1C433C1 for ; Tue, 23 Mar 2021 18:04:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F15A761992 for ; Tue, 23 Mar 2021 18:04:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231178AbhCWSDj (ORCPT ); Tue, 23 Mar 2021 14:03:39 -0400 Received: from mail-mw2nam10on2052.outbound.protection.outlook.com ([40.107.94.52]:63748 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230370AbhCWSDJ (ORCPT ); Tue, 23 Mar 2021 14:03:09 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VhFHLF8aqHmWRFIIyAYgWA1zTQh3syOHZJ1t6lRdqMFf3csgtlI8BgcRmYAv1QOEPqabSZGgEdkdlxoydiTAaiPrnmSWRGOEMcX/lHnEc3QrdytEEufo48ZM2mnBOwQx6LSMyaItH19r9QlmHjBz+kiQEs6U6XcBAUBLU2XDvpTDEHf2ypGPtppbvZghVgupqrecARVSLm64G3ChqfeZDlHhe2hwvt+mReQ2b2ywTamo87qsVP+4e/rwj8I7v6jtn8zO/Do727y9/GPYTabN3AdSqmoNvpq0UVbYzsnQHNZq55hraIYfQ72kmAYvf1RaylE1cBQsh3BeBrero+is0w== 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=ybq9AmUWfapy1CJMdY7w8M+5olrUXBj9cUudQd/NxN4=; b=jbSZ9EoaYra2UYxIWPk20MWvysfF81lpwB7FUbWPL1MI50dB/ytD325M7OpjiZB5v/1q4rl2AwiAWGeCpEy8jCoqfFu1I5HLrT8qIdAXfZ/WJPr2vTn5rM3ypXMXe4o7IKwt/3Epgjgylwqjc3DVn92fn6zwtd4Tampxlkk6alx4cFqvWdH0FKSZjMtu8LfvoY6R2XAWV3Fv18YjCNFTmXOo+lyyKoCwFI7Re6PIbc0uJ3WHrVTZOHB6s6TsC9uJkktLOFb9DTJQeWcH76A3ui752zXNPR+27w61Hlv+BhWF/5+8LbZoEzmpeaxN8c42ntgD7XenezInEsncZvnK4w== 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=ybq9AmUWfapy1CJMdY7w8M+5olrUXBj9cUudQd/NxN4=; b=lgzTFMR+kMoXxkC+W148oSc7irP+EGs3Mg3nnmwNVgDDBLPx6zSP/iSDHRiH4bozJI2s/cHZxr2YSD+OXsssMqKML4KCwc6CbskxIjuoBs6aeUqxcJKjrDFIsmWaH82Qyjh7ZeoEDj6PB5Ud853OrTstb1nzRv9Kbd+U90feXLfg+XKeu6vgNwk2Dt+FpFDexCqU+WyOC2pjBkWjuPYruXjqKEy0CXdmuxcSJSKysTfrXLWgKZopE4Ql3GV02pTG6AIc3VhNQe/FucuVbBPyfjKaZ5Sv/3riT7ysjLthYcozJhPcy4fYRbyrPotljyABVfWbofEXhWfeZMiF5R4tCA== Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) by DM6PR12MB4266.namprd12.prod.outlook.com (2603:10b6:5:21a::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.24; Tue, 23 Mar 2021 18:03:07 +0000 Received: from DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87]) by DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87%6]) with mapi id 15.20.3955.027; Tue, 23 Mar 2021 18:03:07 +0000 From: Jason Gunthorpe To: Alex Williamson , Cornelia Huck , Jonathan Corbet , kvm@vger.kernel.org, Kirti Wankhede , linux-doc@vger.kernel.org Cc: "Raj, Ashok" , Dan Williams , Christoph Hellwig , Leon Romanovsky , Max Gurtovoy , Tarun Gupta Subject: [PATCH 03/18] vfio/mdev: Simplify driver registration Date: Tue, 23 Mar 2021 14:55:20 -0300 Message-Id: <3-v1-7dedf20b2b75+4f785-vfio2_jgg@nvidia.com> In-Reply-To: <0-v1-7dedf20b2b75+4f785-vfio2_jgg@nvidia.com> References: X-Originating-IP: [206.223.160.26] X-ClientProxiedBy: MN2PR15CA0065.namprd15.prod.outlook.com (2603:10b6:208:237::34) To DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (206.223.160.26) by MN2PR15CA0065.namprd15.prod.outlook.com (2603:10b6:208:237::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.24 via Frontend Transport; Tue, 23 Mar 2021 18:03:07 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lOlFf-001cgY-9F; Tue, 23 Mar 2021 14:55:35 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 18ec7ee6-db53-4207-c2fb-08d8ee25e9ad X-MS-TrafficTypeDiagnostic: DM6PR12MB4266: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: j2/n7nIMx3Kh2E40tf7Nj1Fq3svEvGC/KZJsw9kiNOp7d9hfvzPoux0jg05nN69cd/VP+u8DhgJ9DKRxbDkmgSQ2Pwno6HtHSEcBF1xjlYoyfb9197rO6x8j6pcXlLEq8L0vvurbGGp/ZJs/CWTADyk9TsOu+NHD1g7Gt2iKfbE1RLZIIrBZgB/2d4md34Ml4Qz6DtTkl1iJUmzyDUGaXPUMYD/Gm1XbuJbKmfpNX1HZSajbTi/svhlLAfW/lMlRgLMbgvOKMAbuZKFEGCFWY6BDiO4MhWH1Jzkisa1vLzFBYAEy0jbAiAjIDJwvmk5UaB8fTb96x9i71Vfncd7xXQn+GNoJxdIvPnQ9exADtXi/Sl+DcFAO6U2cHYnDI+DhGAK+kaL0FXJ/RYglKTlnWz2UfJ5hLYPAe8cd/bCp56K6eyl5R3Y4zQFDfgI0VlZB8WtJ0V0LVxm6rAeIpUJf/mTT77DuTGYp9EUNKNz4g8ePiAT390de27qcmaDctzeGI68/3YoPS8aSUZ5p6HRXaDvDKPPG/+yxzbjbdaySUKAxPIJv/oHmQhLCyzl3a/oGbU2AeYHRjHXjKBq1hBwqOqY7fKxHXPCQxQpUZFluw1hc1Kj5wRkuMwu7KlMjRoq8Yw+gwzI7nA25sCqbwkQ70gprjpAuR6PWfgnMb71zyzM= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3834.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(136003)(39850400004)(376002)(366004)(346002)(66556008)(66946007)(2906002)(66476007)(110136005)(83380400001)(86362001)(54906003)(38100700001)(316002)(9746002)(9786002)(8676002)(186003)(478600001)(26005)(36756003)(426003)(4326008)(2616005)(6666004)(107886003)(5660300002)(8936002)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: KMKzB0t63+ab8tdubSJwyWY44Zi2dzW0SldgyGtQFQxy/ZNEJb2FBlXEXl84NTP+vOELhqx+DVs8Qz0i7ffX3SCGEE0F+VHJa3BFu2u1g+lhuEu2yA9vAAStW48+YXc8UDJLS6gK1jKuRwfwb0Oko+6xtmkNEvb1wxu0uwBsDfP8LbuwqHTUvFkO2mhWQsSSYPR3MZfIjPrnOxoR6aRXT3GzcWU0rRB5cpgM+QyNro20eRb5dd9GV3noBgDeLup2jTOXIG74pW1742FDDEHxcPqI2mYVzG24/66oDB+K3FeMn4s+fD3n2bNCf7ntrBqTU/fQL37rVOLs4rqi9CeK2JFiPwaxwdbB5+/+CkZHLT6mzgwnbrGFN75ooFWmOJM4YlugRrp3U7f43ZxdXDmm4K+i68RFhj7Iu51MOCJasSuPqhTOgYtaG0L6h/7GqQarTxg/T2CDse5+8lUBGsZRAywF1Bshf+Lvq9qXZ5wE443aKWOyKOXsLWF+vdUVMotl6ex8sDGBBnP6BpVHHlNAT2rak1yXLMl1XH0jtbRc4DSgH/hYWkdOHhVbKJoqUyB0eDWFsHhUETJcAIhvg5E/o7+69qdwj6x0TuJMXqtUo6+PeRMgfbC1tNjY/QQB6mEzzq93dp/CeIGLfZvXDmiMmCheZxq3TqBqNh5SCMakUw8w2y1ZsPtF5Hot1IC5/KLt0wigDGGc1sqsKBsmMDWZi+4xhkor7lJ1B4XsOJ2GbldAA9MWSO00fGunKruXteBzDwEyh4sfjoS1aXL0Xj4Sq/qS2fYzAUngkIG0OoOgoOynJe94YDEXtJyn4byE5q3Y30/ObTDHExUQ9eA3v7Jah8zmWlQ1RFpRkeREzFgy4wgbmG6KdrTJRbnHHV/Xikjg7PUuf3oLz+2w3sQkVqoM76WCVSewAIJU31p47a5XI84xY/D7rABZpP1XmP1MDedRMD5ZaXXra8K0mt5UpbamA4mF2KT7wN78iQTAuRdamFHRmeovsWidUahK1sbW+XYdf/16oM7+ZuXjGFFueNJKaUDMIBWEmEDcp/hBiO+GQlsMSVolukxbQ08tWcfbOSnIrs4JI1wV7KD8QXmlAi3RmKijFA1HIXYp0Uu6iIrdS6SHbutGAsDYv9GGLFQX3It4lSEzWkWKz2W98EvnVfx4kDXrDxtWRvXa0Fq6Q0del+4YD/i4QRZgM8kwP6F8CzDSBN0suZm1JIwupMTHVjBDcibMrg0XmWa1ldrhTSHlG78w289RY7+XgoJ0kIt78fBhCEBjV2FaCQJPtWiPwWiNc0JqbZVZQDoslaqC5+pa9MNJkIBLvEkp4qt7JgA4hztb X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 18ec7ee6-db53-4207-c2fb-08d8ee25e9ad X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2021 18:03:07.6823 (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: unMfUKmiIFeblyQ1r3MYoKVNsr6E87sAlnNCPb8U0+5M88PToDDqmIqHYTgrYo/8 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4266 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This is only done once, we don't need to generate code to initialize a structure stored in the ELF .data segment. Fill in the three required .driver members directly instead of copying data into them during mdev_register_driver(). Further the to_mdev_driver() function doesn't belong in a public header, just inline it into the two places that need it. Finally, we can now clearly see that 'drv' derived from dev->driver cannot be NULL, firstly because the driver core forbids it, and secondly because NULL won't pass through the container_of(). Remove the dead code. Signed-off-by: Jason Gunthorpe Reviewed-by: Christoph Hellwig Reviewed-by: Kevin Tian Reviewed-by: Cornelia Huck --- Documentation/driver-api/vfio-mediated-device.rst | 5 +---- drivers/vfio/mdev/mdev_driver.c | 15 +++++++-------- drivers/vfio/mdev/vfio_mdev.c | 8 ++++++-- include/linux/mdev.h | 6 +----- 4 files changed, 15 insertions(+), 19 deletions(-) diff --git a/Documentation/driver-api/vfio-mediated-device.rst b/Documentation/driver-api/vfio-mediated-device.rst index c43c1dc3333373..1779b85f014e2f 100644 --- a/Documentation/driver-api/vfio-mediated-device.rst +++ b/Documentation/driver-api/vfio-mediated-device.rst @@ -98,13 +98,11 @@ structure to represent a mediated device's driver:: /* * struct mdev_driver [2] - Mediated device's driver - * @name: driver name * @probe: called when new device created * @remove: called when device removed * @driver: device driver structure */ struct mdev_driver { - const char *name; int (*probe) (struct mdev_device *dev); void (*remove) (struct mdev_device *dev); struct device_driver driver; @@ -115,8 +113,7 @@ to register and unregister itself with the core driver: * Register:: - extern int mdev_register_driver(struct mdev_driver *drv, - struct module *owner); + extern int mdev_register_driver(struct mdev_driver *drv); * Unregister:: diff --git a/drivers/vfio/mdev/mdev_driver.c b/drivers/vfio/mdev/mdev_driver.c index 44c3ba7e56d923..041699571b7e55 100644 --- a/drivers/vfio/mdev/mdev_driver.c +++ b/drivers/vfio/mdev/mdev_driver.c @@ -39,7 +39,8 @@ static void mdev_detach_iommu(struct mdev_device *mdev) static int mdev_probe(struct device *dev) { - struct mdev_driver *drv = to_mdev_driver(dev->driver); + struct mdev_driver *drv = + container_of(dev->driver, struct mdev_driver, driver); struct mdev_device *mdev = to_mdev_device(dev); int ret; @@ -47,7 +48,7 @@ static int mdev_probe(struct device *dev) if (ret) return ret; - if (drv && drv->probe) { + if (drv->probe) { ret = drv->probe(mdev); if (ret) mdev_detach_iommu(mdev); @@ -58,10 +59,11 @@ static int mdev_probe(struct device *dev) static int mdev_remove(struct device *dev) { - struct mdev_driver *drv = to_mdev_driver(dev->driver); + struct mdev_driver *drv = + container_of(dev->driver, struct mdev_driver, driver); struct mdev_device *mdev = to_mdev_device(dev); - if (drv && drv->remove) + if (drv->remove) drv->remove(mdev); mdev_detach_iommu(mdev); @@ -79,16 +81,13 @@ EXPORT_SYMBOL_GPL(mdev_bus_type); /** * mdev_register_driver - register a new MDEV driver * @drv: the driver to register - * @owner: module owner of driver to be registered * * Returns a negative value on error, otherwise 0. **/ -int mdev_register_driver(struct mdev_driver *drv, struct module *owner) +int mdev_register_driver(struct mdev_driver *drv) { /* initialize common driver fields */ - drv->driver.name = drv->name; drv->driver.bus = &mdev_bus_type; - drv->driver.owner = owner; /* register with core */ return driver_register(&drv->driver); diff --git a/drivers/vfio/mdev/vfio_mdev.c b/drivers/vfio/mdev/vfio_mdev.c index 91b7b8b9eb9cb8..cc9507ed85a181 100644 --- a/drivers/vfio/mdev/vfio_mdev.c +++ b/drivers/vfio/mdev/vfio_mdev.c @@ -152,14 +152,18 @@ static void vfio_mdev_remove(struct mdev_device *mdev) } static struct mdev_driver vfio_mdev_driver = { - .name = "vfio_mdev", + .driver = { + .name = "vfio_mdev", + .owner = THIS_MODULE, + .mod_name = KBUILD_MODNAME, + }, .probe = vfio_mdev_probe, .remove = vfio_mdev_remove, }; static int __init vfio_mdev_init(void) { - return mdev_register_driver(&vfio_mdev_driver, THIS_MODULE); + return mdev_register_driver(&vfio_mdev_driver); } static void __exit vfio_mdev_exit(void) diff --git a/include/linux/mdev.h b/include/linux/mdev.h index 52f7ea19dd0f56..cb771c712da0f4 100644 --- a/include/linux/mdev.h +++ b/include/linux/mdev.h @@ -137,21 +137,17 @@ struct mdev_type_attribute mdev_type_attr_##_name = \ /** * struct mdev_driver - Mediated device driver - * @name: driver name * @probe: called when new device created * @remove: called when device removed * @driver: device driver structure * **/ struct mdev_driver { - const char *name; int (*probe)(struct mdev_device *dev); void (*remove)(struct mdev_device *dev); struct device_driver driver; }; -#define to_mdev_driver(drv) container_of(drv, struct mdev_driver, driver) - static inline void *mdev_get_drvdata(struct mdev_device *mdev) { return mdev->driver_data; @@ -170,7 +166,7 @@ extern struct bus_type mdev_bus_type; int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops); void mdev_unregister_device(struct device *dev); -int mdev_register_driver(struct mdev_driver *drv, struct module *owner); +int mdev_register_driver(struct mdev_driver *drv); void mdev_unregister_driver(struct mdev_driver *drv); struct device *mdev_parent_dev(struct mdev_device *mdev); From patchwork Tue Mar 23 17:55:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12158945 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=-16.0 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 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 533D9C433F7 for ; Tue, 23 Mar 2021 17:56:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2E9D3619C8 for ; Tue, 23 Mar 2021 17:56:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231433AbhCWR4X (ORCPT ); Tue, 23 Mar 2021 13:56:23 -0400 Received: from mail-bn8nam12on2077.outbound.protection.outlook.com ([40.107.237.77]:36673 "EHLO NAM12-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231318AbhCWRzp (ORCPT ); Tue, 23 Mar 2021 13:55:45 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HmJv8veTe2IMV8pTmKr64BR8DkrG/ZpwxSAita+3Sx+UBXGLph2CTj7bE+kA23LsobOmUWba/VEhhY26IyR45tlFcwbhiSoD/fMTnV6t+zIgI3cAiIM2FoDYSdBZjdd6CKfT8CiL0FgVUj2YBMHCd1vA0KPghqfbK4fGc1osAZbJlliudFQ8ey1iUZMQEL1IIJ/gFKuoj6GFUIpsvoC3swssKenwahitpS84kkvFoHCUXiMNXQKeiKbqtcp6shPRTuelZa+Wbxcf57MyKe9ZaiCjNszQGOx0S7fkpPVikw996GZzcU+UUY6vQks9bRcmDBZoO8serUspzm49CABtaQ== 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=OdX5m0sjsG9ybbyIjyfC40NWPaxyira/8qCtol2gmZg=; b=BisNEjKbmF/J5apZhGDFh4t0tp3jCETIloMseMWxBDJRCXIH3xTzTOi+OYlN/GL6/FS/iWeuIy85bwKhQ5zBfcAznD2JnGlGAqXW52+kq+6S7KKaWb39wkn9gMfFkc4dQeUHJF9aw9qjqM3pZe3G51Zd0Tz3eWDI+kAVkgP7EnF9SJ/WkTBMi28eE3JR94kdiYtZL6IKqIWECRNWuTB4VTfgjLX90qYX34SthQCmJwsilVBiHBUrJVWfJ/0R4/a4+PdK2LHBI5TKjnpFC54Kf0sIfTf6lDh+0fy5QZPwRJDyRhVtTtB/d4cs54bC0rp70F/MUD7cWDwkiBoEK7WVxQ== 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=OdX5m0sjsG9ybbyIjyfC40NWPaxyira/8qCtol2gmZg=; b=ZlQ+etOQQdAUO9343H7kgxkyM2fPNuRJBsO3H/RIKq3Px18nB5eKSN3Mreh2OWw1X3Oxw6amngAj0Y0TQJ+KZpQJERRQxSTrBYabIURpaeHOLPrVImAmBvUGmwKNMBHAkZ9Nctl1dR9gkf3KuobUgZGus51fVTCXf6vFvfi7Fcd9UrWaRuXbfJF+0esaFyeuWTOUIcNrZO2mdOuQ/DO9sR3dIzt7bppUcbL8Evb5qqoKvJt1FFwJFEZVB/o7Rq/hZqwXjfs4I8ZnBIktslq4Ch4b+HwKNZj7AAOk7WsnTvq/fcH/djDdS4UOc1rYdH6ChoB3yXrvRiryTEr8LmafUA== Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) by DM6PR12MB4943.namprd12.prod.outlook.com (2603:10b6:5:1bc::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3955.18; Tue, 23 Mar 2021 17:55:43 +0000 Received: from DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87]) by DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87%6]) with mapi id 15.20.3955.027; Tue, 23 Mar 2021 17:55:43 +0000 From: Jason Gunthorpe To: Alex Williamson , Cornelia Huck , kvm@vger.kernel.org, Kirti Wankhede Cc: "Raj, Ashok" , Dan Williams , Christoph Hellwig , Leon Romanovsky , Max Gurtovoy , Tarun Gupta Subject: [PATCH 04/18] vfio/mdev: Use struct mdev_type in struct mdev_device Date: Tue, 23 Mar 2021 14:55:21 -0300 Message-Id: <4-v1-7dedf20b2b75+4f785-vfio2_jgg@nvidia.com> In-Reply-To: <0-v1-7dedf20b2b75+4f785-vfio2_jgg@nvidia.com> References: X-Originating-IP: [206.223.160.26] X-ClientProxiedBy: MN2PR18CA0014.namprd18.prod.outlook.com (2603:10b6:208:23c::19) To DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (206.223.160.26) by MN2PR18CA0014.namprd18.prod.outlook.com (2603:10b6:208:23c::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.24 via Frontend Transport; Tue, 23 Mar 2021 17:55:39 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lOlFf-001cgc-Av; Tue, 23 Mar 2021 14:55:35 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d0a28af4-dc40-48ff-f1bc-08d8ee24def0 X-MS-TrafficTypeDiagnostic: DM6PR12MB4943: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5236; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: PucYBGKYrWxlOp3aVZG2NjcI80k1Cry3TqSa8ZOcP4InNg+4W1e8mrV44CpqM4Dgu9yNveerkQdNzVr6Gmv6gUQpaedBnDPdDDBoJROz+nFhYRnFKZ/YxxwrQ9/6P3pHOmLY9RLblIQp0RNUpX3/0WePJmbm0bQVztE3Ym1V2HhDm2dAO1wah+AErlH9/8T/IA1ilviMf7FExxuHnzsdndWEtyEBMu1dBjmGvlTB+EYRWTB5JfkqyVsej9G6LQU/x6SC+THdpL7BdgBEl/2HyBJbEwrJD+CMGyxbtmcNPTLSBnMNKGAwVMod1UOoOsqN1Uhty+LKjfjlTMSNPqN2iUqH2ZPQAUWBSvK5Qvhmg3yWzP2/5yPMbO35jMataVAL6ZF22XOZD56p6mZxu7Km3CV84c3vnac4T9JMgQlgq42iaut3wuVD00BD4v/jwPiW2SvioyqBZbJH4DnJDeLSJEIMg0qEYju0XgMp6jTrtQ/aCmpzvetjpy5kR9a5CzI+nGZsWjA1clobrVjAYcLIxhjTZDZoiHRhq5SE99ug9llYqQb1vB8gwBuQf7aXpTHHhfF0YlDj45ZSpDPDEKqGpg0jaBLMtjZnLz00pmkuajGyq4sbsobrJV+xpjPe7QkvPyhnGQ+TDozh2uWI9i1TcQwZyhgQmFTGQrgMIhc79nI= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3834.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(39860400002)(136003)(376002)(366004)(346002)(66476007)(186003)(107886003)(6666004)(8936002)(110136005)(36756003)(426003)(86362001)(54906003)(83380400001)(2616005)(38100700001)(66946007)(5660300002)(478600001)(9746002)(66556008)(8676002)(4326008)(2906002)(26005)(316002)(9786002)(6636002)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: j5pw9UDA/S/YtKRqZaTHMoaYJgppSI2BjxE73JO9F5CLikjpbCB9UT+Jj3E1bzpZEM29QEF9Kf64339c1C3gt1uqYOLhjRwnoVfBXJoTR277zlQJBmIU8oSLkTHyJ32PYb/PdzH8NY9O5qhUd2PeYGrO7V0mRctYfSlq32LwSo78FsMI6B8a+z250k/Hi/MZvlyVmRCRICz1TofCm5eylqjVTjy3lRGn/Wd8td/hFsxptACEYTJ2S6RGCdXXt5FbJ2w+qTYCYu0N/npjlBUDHgVibBVZUjH9qbhDaKpQ1BpHFfmGxXgpPDpURzi7/xl1o73dVl41roK32dorm9XiL0+DETaYZ2gmvQhQlr5SVNiRBbYJkFb/0mCSH/yaQ128adMmo5ZbeyPFBZqkyZMzBWirSC//8dWU49cMXsT1quxT+cnPt1U4hKGuT90fOyaLPDt9TEJQeP3Iw77Wih6c5YRyoI2a+cjmibq8NrYqvIZqz8zYY3il9Uh+PxdxLySUf13VgkIeS6hRSrHT+jc5Z62u3mCcrsQjPlBsxV7m48rML+C/FMODIMf5x0AtChCg5bqv/b29ROafyM3MajZJUCQuBh4M/eoeFLCpAfm2+xdS+l9Kx2Jvm4Zi4tgwTsCVeztJ5KnsePqrAglT77G9WX3m00xQDVPYsXpi8VTH2pks6V4Q329r6SaMUZ8G7tpb0cH9M1CiA0MM0enCqWS1RK1+Ep5QHPTCPfG3Q12noIciq+VmlodG0xXmuFAAXKZLZIeLEIPGNL1W+6z7NSEhz9/XBpUyY7Q0PIjSwvzQIZpDErzAZLgwk61j+6bqy5QRbJioODeSUvDKylKLMhTIbi5iOkLwhhOsL/R+gVuDq6lkZNGVOzAFkvrgMGZ4qkDs1ldPtr0N3FksR5XJCXuMmqS6It9VtE2LFFCneGX34X5WDqNUowmaTAiu5+0n3KG872OBSjKN0kezSTj9jTdnCs32R6xk76HmRGNXQyPqDuehq8VG87tEzyoNLJyjSR/LfJBJXTwLZzX3dGqDGNTSF8SkhhpDgultuw0YZmt7a1h/u+iPZLkKh3Elc+lQnI3G0riTfEhgF5vef7QGEJBkh4DxvrK7u50KDRrzl6bGd1ROwgfz8zLj6hmCTrWO0LqpSubfKVDrvtwFJtIPsh9mz3aBGEpe1PI1tnT/Q0UmdiSthtdS98LOhCOWzkZZw/1ySMIvTkz6dJ39gXKecWBVPuYQ3x0pfGXuoW5SuzGN79tzkvGL/qMA88t4SC3nmTXFDedgESiZoaSQmJ4mp+h0on1lY+rHbuRQpYqMIorNiU53BJQBl8lZOtB/EduqVGkZ X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: d0a28af4-dc40-48ff-f1bc-08d8ee24def0 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2021 17:55:40.3768 (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: 2UDJXyDB+AOSvS0bkAC2JCbDjEg3sT5lS1g//Da5hKvy/irC/qeaND3H1xZMIbXp X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4943 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The kobj pointer in mdev_device is actually pointing at a struct mdev_type. Use the proper type so things are understandable. There are a number of places that are confused and passing both the mdev and the mtype as function arguments, fix these to derive the mtype directly from the mdev to remove the redundancy. Signed-off-by: Jason Gunthorpe Reviewed-by: Christoph Hellwig Reviewed-by: Kevin Tian Reviewed-by: Cornelia Huck --- drivers/vfio/mdev/mdev_core.c | 16 ++++++---------- drivers/vfio/mdev/mdev_private.h | 7 +++---- drivers/vfio/mdev/mdev_sysfs.c | 15 ++++++++------- include/linux/mdev.h | 4 +++- 4 files changed, 20 insertions(+), 22 deletions(-) diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c index 057922a1707e04..5ca0efa5266bad 100644 --- a/drivers/vfio/mdev/mdev_core.c +++ b/drivers/vfio/mdev/mdev_core.c @@ -73,11 +73,9 @@ static void mdev_put_parent(struct mdev_parent *parent) static void mdev_device_remove_common(struct mdev_device *mdev) { struct mdev_parent *parent; - struct mdev_type *type; int ret; - type = to_mdev_type(mdev->type_kobj); - mdev_remove_sysfs_files(mdev, type); + mdev_remove_sysfs_files(mdev); device_del(&mdev->dev); parent = mdev->parent; lockdep_assert_held(&parent->unreg_sem); @@ -241,13 +239,11 @@ static void mdev_device_release(struct device *dev) mdev_device_free(mdev); } -int mdev_device_create(struct kobject *kobj, - struct device *dev, const guid_t *uuid) +int mdev_device_create(struct mdev_type *type, const guid_t *uuid) { int ret; struct mdev_device *mdev, *tmp; struct mdev_parent *parent; - struct mdev_type *type = to_mdev_type(kobj); parent = mdev_get_parent(type->parent); if (!parent) @@ -285,14 +281,14 @@ int mdev_device_create(struct kobject *kobj, } device_initialize(&mdev->dev); - mdev->dev.parent = dev; + mdev->dev.parent = parent->dev; mdev->dev.bus = &mdev_bus_type; mdev->dev.release = mdev_device_release; dev_set_name(&mdev->dev, "%pUl", uuid); mdev->dev.groups = parent->ops->mdev_attr_groups; - mdev->type_kobj = kobj; + mdev->type = type; - ret = parent->ops->create(kobj, mdev); + ret = parent->ops->create(&type->kobj, mdev); if (ret) goto ops_create_fail; @@ -300,7 +296,7 @@ int mdev_device_create(struct kobject *kobj, if (ret) goto add_fail; - ret = mdev_create_sysfs_files(mdev, type); + ret = mdev_create_sysfs_files(mdev); if (ret) goto sysfs_fail; diff --git a/drivers/vfio/mdev/mdev_private.h b/drivers/vfio/mdev/mdev_private.h index bb60ec4a8d9d21..debf27f95b4f10 100644 --- a/drivers/vfio/mdev/mdev_private.h +++ b/drivers/vfio/mdev/mdev_private.h @@ -40,11 +40,10 @@ struct mdev_type { int parent_create_sysfs_files(struct mdev_parent *parent); void parent_remove_sysfs_files(struct mdev_parent *parent); -int mdev_create_sysfs_files(struct mdev_device *mdev, struct mdev_type *type); -void mdev_remove_sysfs_files(struct mdev_device *mdev, struct mdev_type *type); +int mdev_create_sysfs_files(struct mdev_device *mdev); +void mdev_remove_sysfs_files(struct mdev_device *mdev); -int mdev_device_create(struct kobject *kobj, - struct device *dev, const guid_t *uuid); +int mdev_device_create(struct mdev_type *kobj, const guid_t *uuid); int mdev_device_remove(struct mdev_device *dev); #endif /* MDEV_PRIVATE_H */ diff --git a/drivers/vfio/mdev/mdev_sysfs.c b/drivers/vfio/mdev/mdev_sysfs.c index 6a5450587b79e9..321b4d13ead7b8 100644 --- a/drivers/vfio/mdev/mdev_sysfs.c +++ b/drivers/vfio/mdev/mdev_sysfs.c @@ -67,7 +67,7 @@ static ssize_t create_store(struct kobject *kobj, struct device *dev, if (ret) return ret; - ret = mdev_device_create(kobj, dev, &uuid); + ret = mdev_device_create(to_mdev_type(kobj), &uuid); if (ret) return ret; @@ -249,16 +249,17 @@ static const struct attribute *mdev_device_attrs[] = { NULL, }; -int mdev_create_sysfs_files(struct mdev_device *mdev, struct mdev_type *type) +int mdev_create_sysfs_files(struct mdev_device *mdev) { struct kobject *kobj = &mdev->dev.kobj; int ret; - ret = sysfs_create_link(type->devices_kobj, kobj, dev_name(&mdev->dev)); + ret = sysfs_create_link(mdev->type->devices_kobj, kobj, + dev_name(&mdev->dev)); if (ret) return ret; - ret = sysfs_create_link(kobj, &type->kobj, "mdev_type"); + ret = sysfs_create_link(kobj, &mdev->type->kobj, "mdev_type"); if (ret) goto type_link_failed; @@ -271,15 +272,15 @@ int mdev_create_sysfs_files(struct mdev_device *mdev, struct mdev_type *type) create_files_failed: sysfs_remove_link(kobj, "mdev_type"); type_link_failed: - sysfs_remove_link(type->devices_kobj, dev_name(&mdev->dev)); + sysfs_remove_link(mdev->type->devices_kobj, dev_name(&mdev->dev)); return ret; } -void mdev_remove_sysfs_files(struct mdev_device *mdev, struct mdev_type *type) +void mdev_remove_sysfs_files(struct mdev_device *mdev) { struct kobject *kobj = &mdev->dev.kobj; sysfs_remove_files(kobj, mdev_device_attrs); sysfs_remove_link(kobj, "mdev_type"); - sysfs_remove_link(type->devices_kobj, dev_name(&mdev->dev)); + sysfs_remove_link(mdev->type->devices_kobj, dev_name(&mdev->dev)); } diff --git a/include/linux/mdev.h b/include/linux/mdev.h index cb771c712da0f4..349e8ac1fe3382 100644 --- a/include/linux/mdev.h +++ b/include/linux/mdev.h @@ -10,13 +10,15 @@ #ifndef MDEV_H #define MDEV_H +struct mdev_type; + struct mdev_device { struct device dev; struct mdev_parent *parent; guid_t uuid; void *driver_data; struct list_head next; - struct kobject *type_kobj; + struct mdev_type *type; struct device *iommu_device; bool active; }; From patchwork Tue Mar 23 17:55:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12158947 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=-16.0 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 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 EC741C433F2 for ; Tue, 23 Mar 2021 17:56:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C64A0619CA for ; Tue, 23 Mar 2021 17:56:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231401AbhCWR4R (ORCPT ); Tue, 23 Mar 2021 13:56:17 -0400 Received: from mail-dm6nam10on2067.outbound.protection.outlook.com ([40.107.93.67]:16865 "EHLO NAM10-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231265AbhCWRzm (ORCPT ); Tue, 23 Mar 2021 13:55:42 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Wwmh4dILIE/gqofpXAUD7x+MckWC8aDskKlNcCrvbbjzF9dgoSEaVtsh2wb6FtYR3hLNYB9rZVSiN6Ahd5dxdjSNzYC5X/ZUVIEL1/jcqjWohJ0fePMr4rm07rxmaNfDw84nMkPBRq7zDwC7zKqqxzP9RBjOshv9PzRaP9woJ9DCZY3bjYrDZgePdJzqw1GVNpQ1gl0IEYupapcjH5B343xD5MkKagt/Dc1KOoWFXwkNx5T/qI4+NIcGkKVJTMOVlk54M5AAQgdTbhnai58E7iMxKg36AezlwgBZgca1EFz0Sn5uSoitZefzczPtiUAHbWaCOPU369um0jVb3mInxg== 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=6zWkoa+pW27gbbX1iiE5kbluK6tMuu5mXSd1YE/2nio=; b=FvPOdyXqSl+R4LJierkESPK+S/2R3sFQCUf9BNCGTBXQd2g1XC62UDCFz27EKSaGo7SD1aZbRnlLrh45OaSVZ09KM0xuhvtEtoNzXWMEmHbuUk9/ZhQaqW/p2ZRHPAB9BDP46Ky7oXgSvNmdkXaJvgWqbAiYXlrgXqfNtmaZ6+G16o75X2EAauUkrLqpkf2dXNAMhKBZ026IcztHTfU4Szps3Jih20lD4J/iwlKAd3XBWEkCF5pc73dqAil3V34u2s9PSIz8Jy1du0KVrARCoyHlEdp0uzh7Pvyc7pP4/NwHOnmcMEQmE5x7KhrhREd0IX0d97k4N8WWa8DgWqTCWg== 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=6zWkoa+pW27gbbX1iiE5kbluK6tMuu5mXSd1YE/2nio=; b=j1tJx92/ep1MbBMN1sxFXz6Usj3h9Lu+fsOotbN/H1+yIYKosYSJhDQh+Gu+jmzEy/uxefUj/UZhRx+RlAjk3PT9WNitnn1wwtUnp01AYDTIAaqWcVw8nhtX20pKz1Ct9qRZA/7p4hGvRfKHQ8qjzqQnTyBEE1KXlvZG7X8akukXkB0n/ea89s/PkDcUrqFwWTdDzkHmWGMJA0IzlWCSaVPUoBMhXM01b29q9o4CvY3+AbwF3cSTURDFw6nlG6oVk/5D+DNeI5rDlwQX8aCzyoQ43/Ywubc7ZQv0D458HvbjUuTZ6A2zClD8DvO76XjSXCuJwUygkR/s8ALSRgfZAg== Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) by DM6PR12MB4299.namprd12.prod.outlook.com (2603:10b6:5:223::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3955.18; Tue, 23 Mar 2021 17:55:41 +0000 Received: from DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87]) by DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87%6]) with mapi id 15.20.3955.027; Tue, 23 Mar 2021 17:55:41 +0000 From: Jason Gunthorpe To: Cornelia Huck , kvm@vger.kernel.org Cc: Alex Williamson , "Raj, Ashok" , Dong Jia Shi , Neo Jia , Dan Williams , Christoph Hellwig , Jike Song , Kirti Wankhede , Leon Romanovsky , Max Gurtovoy , Tarun Gupta Subject: [PATCH 05/18] vfio/mdev: Do not allow a mdev_type to have a NULL parent pointer Date: Tue, 23 Mar 2021 14:55:22 -0300 Message-Id: <5-v1-7dedf20b2b75+4f785-vfio2_jgg@nvidia.com> In-Reply-To: <0-v1-7dedf20b2b75+4f785-vfio2_jgg@nvidia.com> References: X-Originating-IP: [206.223.160.26] X-ClientProxiedBy: BL0PR0102CA0036.prod.exchangelabs.com (2603:10b6:207:18::49) To DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (206.223.160.26) by BL0PR0102CA0036.prod.exchangelabs.com (2603:10b6:207:18::49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.24 via Frontend Transport; Tue, 23 Mar 2021 17:55:38 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lOlFf-001cgh-Cq; Tue, 23 Mar 2021 14:55:35 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 76454c62-caed-4124-5652-08d8ee24de0c X-MS-TrafficTypeDiagnostic: DM6PR12MB4299: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:619; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: h+IYBBYhevqf9OgPMcuL6teeCixYXZrhFmBb0+Vx8mGYWFidgNA5U6apiQYSGtN7o3YsNch+WwpuC0KOAZabPL4xj2Clx2/EEzSHnuuBZAW9upA63EpX8+BDBBedvyx5gwWfUAHGDReNkWUApxXaEcl9C4JNArdFTpvsCWwD+k6x4SbL9/kYKn+jsdIaMBDWk7iGtkaNCC4ikJjiBO88GRH7xcLoF8xEQDGLg0cN8+dYi1/+5Bj3ZKzmDO6oERE99HJ/h3SJxNtACW8Qg9EPs6pAFSwlnv+O1wr9hGsGgB8E+odcRw3iLKyX10P7B+DXU8ZrXsWzCYMmAkvFtr8iE8rGPTaeJvnMTmD0vUV/HZdgW/KKWkBt2Jo6DBjvpewphW7PYWq98czG7EuRPv7qsm0nnknzwvtP3EGRiF3472jYVIcF5YBgP7dJUJROJBYTyeNRRokMbEcnFe8F2zTFvzYNwJJzbfweacmCz/DwAN41x+CyKd21G65rU7H0lfQplvSmh7XtaNSwq/t5uvfr36kYdhO2QN0jU+TY3Buwqlbghl+GXg1hh35Cmm/AqvnYKBpov1FSVtSg9G8DJJhi8gltvanKWbb7pHP8GR0YL4M55HzpKb7M03V1tnIw1+WzRxRi3yimw2k4apoeFkoeikWyc1/wPLEjj7NOzbSiLRM5ioefNUvuWzm1oKgITsXS X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3834.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(366004)(376002)(136003)(346002)(39860400002)(83380400001)(86362001)(66476007)(66946007)(316002)(4326008)(54906003)(426003)(186003)(478600001)(107886003)(66556008)(2616005)(26005)(2906002)(9786002)(9746002)(38100700001)(5660300002)(8936002)(36756003)(6666004)(8676002)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: I87vg6UyLmFkdXb8mh/drqe876zy+yHTNeNnn43awaaRa6b3/4K9GGuykORcoO0xyJGCiKph7DLSpgOjCeZ/TS5GvyUtHeBsk5/gUGR8LvgL7XM3Tb0zOXPkdpmf144wTIhRjqY9fqmnaXjbyvILVSLXi1Hm58GfPj0vSKsBIuzTTbdHaFoqjNwNLPrlNneNv0ZPRQ257R0whOVPhjznfQrvTdVvKnw4IEOPvSdG83IBb/m7RhI+iXdd2mQUy4P6eGHkWgJ4BSPIMNKMnYXaNnCsFDjK9a7djOigOdjUASfSNgZX1IgxLqeVLK63EtMxEmlr8+VUn2mQtOLP1i+FZvyoVjSD+3OSs985DCLAtGjx0JWqRtcQY9dbjrjlvWm5wG0QAZb5rhhMqau9GGp9y2XT0U/x6sSZRAIpm5oXQ4JtcmIGoPvAXN0m2fDJYBX065iA3Kwsyc752ySR7Q7KKi+tFa61TzMpPzDO4LMcM/cQkN13hBC5ISNJKD5B6RcmpWt8bHXaEpe2LRo9onH1OtE4M/jiN20kyil1RJ2UfodrtL5x0Zzl2TtlRFfUUBUu5bGxeBIOKlzz8mgfsUV6mN02E0s96zZ586kwCzBsgUvXd/h0jqxbKoKF3R8I2gmebMXBulnspWlXJODNz8Dgt+jigMYqcFgHq4w4XkKE9sgysywRDG2iU6UcKvMGQJX+klzg4F9cqDlC0x/L46Vzb9Gb4IBtryMQasJPnIK9BMcLaKg0PB0QpWAQoSO3g55sZ0TvgWP5D9dnT8c6BiNZPaHLxR71gH4zeg03WdrwP4uOz5meJdD/YYjqyD2SiDJrN33DP0Om/hHCUCpy8dKrd/za8yIKR10EWmgeD6a7Xgw+ukTSNJhZSuWZo4Ty7ALEfIMkDIK5LRbbdFnv0VMfGBsXDcVI8SgvYh9RIR53M7mpSzQnOvwvWQP98PmHF8yuiankvXOdwCRf3g3mb1qiIhk8/+EGHoGXOg4NTJWISndSnW3JjXguAB7S5e9RpTY9I9I7WtNgiNr+FdQthkO5JUBRmbz+FKsNwHWlvpSNu0XZ9/zCRf1QNBiCcKAWs/7mH0EiwgIH9Q8DjIiAIKMiJExN6QcErIbUOpct0Iv37FI5wgbOsvZbE9HzHReUIzSasYtiAHMgXl7PwN1JvM1uOCsnrkaaODFFsI/MEFBWBoKKwj7SNemw/wr2QRw1J5FS2+E1AC6745g36byhRKQQMKdZXGhXRHrbC6ah58BfsH3MC29Fcw0y1UiGiI1Jm+uxIv/s4uCeawB4Ix9vBmzrRHxla4gMDgCfrQHQbniG53TmTAJUs7SMyT7Q99LQpBH3 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 76454c62-caed-4124-5652-08d8ee24de0c X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2021 17:55:38.9286 (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: FZ+/hfIqLOhKiYCA2CvLSka1YBewIfEoqb3IW2RoAIXnrpjQWTAlw3vu0XSj6KF9 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4299 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org There is a small race where the parent is NULL even though the kobj has already been made visible in sysfs. For instance the attribute_group is made visible in sysfs_create_files() and the mdev_type_attr_show() does: ret = attr->show(kobj, type->parent->dev, buf); Which will crash on NULL parent. Move the parent setup to before the type pointer leaves the stack frame. Fixes: 7b96953bc640 ("vfio: Mediated device Core driver") Signed-off-by: Jason Gunthorpe Reviewed-by: Christoph Hellwig Reviewed-by: Kevin Tian Reviewed-by: Max Gurtovoy Reviewed-by: Cornelia Huck --- drivers/vfio/mdev/mdev_sysfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/vfio/mdev/mdev_sysfs.c b/drivers/vfio/mdev/mdev_sysfs.c index 321b4d13ead7b8..5219cdd6dbbc49 100644 --- a/drivers/vfio/mdev/mdev_sysfs.c +++ b/drivers/vfio/mdev/mdev_sysfs.c @@ -105,6 +105,7 @@ static struct mdev_type *add_mdev_supported_type(struct mdev_parent *parent, return ERR_PTR(-ENOMEM); type->kobj.kset = parent->mdev_types_kset; + type->parent = parent; ret = kobject_init_and_add(&type->kobj, &mdev_type_ktype, NULL, "%s-%s", dev_driver_string(parent->dev), @@ -132,7 +133,6 @@ static struct mdev_type *add_mdev_supported_type(struct mdev_parent *parent, } type->group = group; - type->parent = parent; return type; attrs_failed: From patchwork Tue Mar 23 17:55:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12158929 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=-16.0 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 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 554D8C433E6 for ; Tue, 23 Mar 2021 17:56:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0D39A619D9 for ; Tue, 23 Mar 2021 17:56:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231364AbhCWR4J (ORCPT ); Tue, 23 Mar 2021 13:56:09 -0400 Received: from mail-dm6nam12on2060.outbound.protection.outlook.com ([40.107.243.60]:2016 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230486AbhCWRzj (ORCPT ); Tue, 23 Mar 2021 13:55:39 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=How0YWmmKs2DQR7NiBPqh5AIVYKf8tMKOgMezENqGzHc/X9RTJ8AzBvE3GMdvsCtiaoOltfPdznV9PakM81GR/dH0vtx6O2ZyHoC6CrJ5o/Q1IIVs1C/hB5RhCcsOg1ClTU2ukaX6+m99ChmZK5bxZLkMPGMcg8WRlWo2XgqW3DRl5mQbvcKJet5Dw30gHnnVq5LIJhIfkAWWNGawYeJEymGMN3e7VUqfnSsTenUvZBV3d7k9sznQKQuX0QjCSEbGMIDDOKDOnZOW18dq3DfUIUNbMdezzQaxI0PpD0r6zc+Mkt6KaGUb17wU1+cq5pV3qH8y2q9nyQOwZn9qLFOZg== 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=TtGBYQPbWyayp2ZCBthrWYuQ+1NmWl04bzwa25ti5cI=; b=TMOUFgkdjwSTuJ5HRCPShsZSD0vZYNDhM2e3YST0BTdTk67MVRByS4s+v/7PKh1A9eOIjN34o7HywbJ9pIvWuhUZz3LPTzTBB45WaSYM80Y6tepOHRZT5QSxs0nJrQNIPTYNJo/INQzCduENppkkBFRr+6OkHNbUQBOXTk31Px9C7OV7U8wDr2CATVy2FKCuvWjPfL6F5SjfDxQp0zSWFb1LmBM21fR+v3OacbPK7JeZ4NDoaQIjSqH7Is3HVLwWbLGAv7R25fDkSaRqJiki6KWrkvypWCvLUToJoPzZcLdmbhxtTDuwle07kjjg1lVmc4GbDmwXrlPZls+ULECNfw== 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=TtGBYQPbWyayp2ZCBthrWYuQ+1NmWl04bzwa25ti5cI=; b=JCBcDSYmrnc6ROJu1ZCdtVMnNBwHyKahGAmVcjS0fYivZVsQWOasmFeTyioxT38iBOWUqaHUZ8KRcO4NAPX1LbojuaxFWz/a81UaSDY/nsjvR0ZxMmF3akIDo+FuXjJZnZbvqrnap88lax63B9S3NsHISKq4Jtjxu6Lthaq5s7M5V9Z5U+Q0x1zWO/2OkPWnb1bylbZS/r5IMcOl7VRUAibGmC15q+DCptR1kHTZvCR/tjDfWgAfc+wtK6fHenLkJNwH86vaUNzUK8VZrWkjrubJfoR+yBbzNw+gMp17+JADQw71Rto5kPIiCzKD/GqbqpxaXsecOWat2Up1duklAw== Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) by DM6PR12MB4483.namprd12.prod.outlook.com (2603:10b6:5:2a2::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3955.25; Tue, 23 Mar 2021 17:55:37 +0000 Received: from DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87]) by DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87%6]) with mapi id 15.20.3955.027; Tue, 23 Mar 2021 17:55:37 +0000 From: Jason Gunthorpe To: Alex Williamson , Cornelia Huck , kvm@vger.kernel.org, Kirti Wankhede Cc: "Raj, Ashok" , Dan Williams , Christoph Hellwig , Leon Romanovsky , Max Gurtovoy , Tarun Gupta Subject: [PATCH 06/18] vfio/mdev: Expose mdev_get/put_parent to mdev_private.h Date: Tue, 23 Mar 2021 14:55:23 -0300 Message-Id: <6-v1-7dedf20b2b75+4f785-vfio2_jgg@nvidia.com> In-Reply-To: <0-v1-7dedf20b2b75+4f785-vfio2_jgg@nvidia.com> References: X-Originating-IP: [206.223.160.26] X-ClientProxiedBy: BLAPR03CA0019.namprd03.prod.outlook.com (2603:10b6:208:32b::24) To DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (206.223.160.26) by BLAPR03CA0019.namprd03.prod.outlook.com (2603:10b6:208:32b::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.24 via Frontend Transport; Tue, 23 Mar 2021 17:55:36 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lOlFf-001cgk-EH; Tue, 23 Mar 2021 14:55:35 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f874ecbd-f97e-4060-4267-08d8ee24dd17 X-MS-TrafficTypeDiagnostic: DM6PR12MB4483: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4303; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: USwgDIJjHjeysg+iGkHEkEC/jNkpht/ZOWdSAHTC0Lorz5KN/d0AeQn5CNNbrztKTcvT1eErhbqFJ4rjqKWgc28CqRdqo+3nUTCfEtous0g8rVY4PI/OGk1ywRkHuHXROeI+Isi/1xjp3pd4jiGnWt+NuFTqc+NJuZvwG+7osFHEhHmsrCUOKbC57pY4nO78tUYX/9lcErl84smlqT1KgWgPQazI14SelUSuuCcW3jt2305CGkOlGhieqeyuESnWfr53E1wn411Sw15rtAaK0w8kLOx6I7SxfATPJHhzfx47B30jDsVOEo0ZHplT12QtO7CoFP6mYIpoyspk06x9v3qDjOIWBO5JJrgCXcyeXSQ150zO4+Wqz5EnSNpWULvksEk2xU1a7W+2BZNW+qZajQf1QVPezo3tTToJSfRftGAVJLvpOF/E4t9qHd6DO/DW8iqG0Ts1LRyKQj1kYN6Ed7bFfBNgcD/2zZtrkrIZxWaambeTYh7CB7Culx8sB5idNFAObUP4H/xsryUfe/ulRqWRY82vA6LmkMhCrikUeNhx51T6Thb5iF5iQ1Q2uYHYhY0pgW6m6aFVZlLXtrYK2268Nk9IrdrCDotivMP0uZXFlDUxaleg7h2KUTt5+Rfk9qiQSZJvMaS/JDL1Yk3HDYpOpX2nIIyGoRZ79tvAzzwot/3fj04YTdCHmKyNiU8X X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3834.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(366004)(39860400002)(136003)(396003)(346002)(186003)(26005)(36756003)(110136005)(5660300002)(38100700001)(66946007)(4326008)(66476007)(6666004)(2906002)(66556008)(54906003)(6636002)(478600001)(86362001)(316002)(8936002)(426003)(9746002)(9786002)(107886003)(8676002)(2616005)(83380400001)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: aVsDFZKkfC2Y2jfS6ojG/ASoBIiP96SeIZGFB1svNt4Q6N7FvVDFMhJIJ9q4YIUemdkCxihJz/HHZg8cnn4Dx2fUrFJg/7CEx17kxlE82Co1SxDl9PLeXK3HZnY6k3jHKEVYgZXBxA7TrVxDZT0DP3FoYw3ZIJ6ysKteucs0yLlSXVCCbdtZbxJEcmUsIgKYySUaqvf390tMREh2ny8duDR/9h+H0l0o1JVwNv/SgugNnCiU23Fl8uluf02u+e/8KTBvbIhY548fl11yeHG+LZN8lS/Tf5wNBFUpTWDl92AGCrWF4h2jrzVPXRxDzbsoBQVe2dIu9vKxMT0MRkm9//kDc50kCFgMIiLcKkIwEQLzYofwIvTM/1gT4lxykQ3pnT/5NZUa6FKQpJJv/f9hthqYm6gKVXYoKfzbYpm7nivtEvCRYB4zM2Hc+kBbluus1MzzJXI9Hr3H/R6tLNmsyLw5eudD2HFGR7a24baYc+Q0Hgku7HM8ut5+9tZfdRyfTiYOMNvr4z9obdJBe4J9J8I0ejZLdz6hp8GbNRl8E1UflCpUb6tfiVeNm3b5yyL2vZe1ouBZZRCmDccNe0ERwRqrKnrKgUWY12+RAooZJ0Pjxepcr5SbKApTbOhwl44FpDymE/AA+1GmCwDqQqTplcs4naHfzdJuIPnah2/yhdoY8Q+2wNwvj3inxI+Xot1PSyDAFc/GOFtp0kVNbaZLywU+S2oxxFnQboUAKLxBygWAcrpZOx0rRv87N2OMdP7QIwa91wtTfUEcQui2l2x2fpJredX6jklUBNRARCZR0sYBWoUqbOHbpHiCvSRrNyOhPtZJH42yEDU7UAzMIygHS93k/RK3bgUTXAf1cuSZzDW0FmA64gz8gWfyq5kh+ZE0aqn9uPoMXjEARZVVk6UBKMdJL3ftgGhC9mBD2wAt8VWNPl3K4OtfB7wiEPQyD0XXpknNSrAn6cz0xzwoEFbHJcXvVabmwLG4VBiBw+YvQB/hbA0OX7zzBBXuthEcLfi5wjvHiP9d3LSBTP0WDHlleRcfHZh8L41pyMqL/nc8iRHDRLZGvLgbtm6f/PyKRkCnhYQEl5ri+x1zfDuVbOGq75hjDjM4b9XXC91nhlT4tK6/bHF3ypBeCqjDFi95h/Se2hBmBNmGCBqg5Bjx5wexWSW+JxS/UZOeWimOmr1kjyJLhYSWSXvEoMYEwFcTAAXCMo4NEhjE668z/UpZYOGXkduOkq7Iuq24+Ck2qOkyDHE/YBjqWn+Uag9yHFDEoyUrDpt8PLJi0saDy8sckloIBUfgf4LRfBLjZO1iXkIvgnH04V1gdn7jl29RMBtfY+3B X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: f874ecbd-f97e-4060-4267-08d8ee24dd17 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2021 17:55:37.0436 (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: 5lL8T1102bnCnWlvCKnh2zuYVlrs5Cn/0fferNLxW2h8+RH9q9SKn95D7iCabt/L X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4483 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The next patch will use these in mdev_sysfs.c While here remove the now dead code checks for NULL, a mdev_type can never have a NULL parent. Signed-off-by: Jason Gunthorpe Reviewed-by: Christoph Hellwig Reviewed-by: Kevin Tian Reviewed-by: Cornelia Huck --- drivers/vfio/mdev/mdev_core.c | 23 +++-------------------- drivers/vfio/mdev/mdev_private.h | 12 ++++++++++++ 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c index 5ca0efa5266bad..7ec21c907397a5 100644 --- a/drivers/vfio/mdev/mdev_core.c +++ b/drivers/vfio/mdev/mdev_core.c @@ -45,7 +45,7 @@ static struct mdev_parent *__find_parent_device(struct device *dev) return NULL; } -static void mdev_release_parent(struct kref *kref) +void mdev_release_parent(struct kref *kref) { struct mdev_parent *parent = container_of(kref, struct mdev_parent, ref); @@ -55,20 +55,6 @@ static void mdev_release_parent(struct kref *kref) put_device(dev); } -static struct mdev_parent *mdev_get_parent(struct mdev_parent *parent) -{ - if (parent) - kref_get(&parent->ref); - - return parent; -} - -static void mdev_put_parent(struct mdev_parent *parent) -{ - if (parent) - kref_put(&parent->ref, mdev_release_parent); -} - /* Caller must hold parent unreg_sem read or write lock */ static void mdev_device_remove_common(struct mdev_device *mdev) { @@ -243,12 +229,9 @@ int mdev_device_create(struct mdev_type *type, const guid_t *uuid) { int ret; struct mdev_device *mdev, *tmp; - struct mdev_parent *parent; - - parent = mdev_get_parent(type->parent); - if (!parent) - return -EINVAL; + struct mdev_parent *parent = type->parent; + mdev_get_parent(parent); mutex_lock(&mdev_list_lock); /* Check for duplicate */ diff --git a/drivers/vfio/mdev/mdev_private.h b/drivers/vfio/mdev/mdev_private.h index debf27f95b4f10..10eccc35782c4d 100644 --- a/drivers/vfio/mdev/mdev_private.h +++ b/drivers/vfio/mdev/mdev_private.h @@ -46,4 +46,16 @@ void mdev_remove_sysfs_files(struct mdev_device *mdev); int mdev_device_create(struct mdev_type *kobj, const guid_t *uuid); int mdev_device_remove(struct mdev_device *dev); +void mdev_release_parent(struct kref *kref); + +static inline void mdev_get_parent(struct mdev_parent *parent) +{ + kref_get(&parent->ref); +} + +static inline void mdev_put_parent(struct mdev_parent *parent) +{ + kref_put(&parent->ref, mdev_release_parent); +} + #endif /* MDEV_PRIVATE_H */ From patchwork Tue Mar 23 17:55:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12158923 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=-16.0 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 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 AED13C433E3 for ; Tue, 23 Mar 2021 17:56:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8A44B619AE for ; Tue, 23 Mar 2021 17:56:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231309AbhCWR4I (ORCPT ); Tue, 23 Mar 2021 13:56:08 -0400 Received: from mail-dm6nam12on2060.outbound.protection.outlook.com ([40.107.243.60]:2016 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230173AbhCWRzi (ORCPT ); Tue, 23 Mar 2021 13:55:38 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Um0o/Pj9GunasrPRGTbq2j9j4xyeYJ9GQJa6ehhkcUwobKdC87S7T9LBkBCN3Q+4ndYLQTUqL2AiMGzUDKf1P4ykB4ytXvsG2YNryj86k0rS7H31jKoEYCzSt81ngHvSToJZXc5AAxmupbr33Fzaya12LQtVObw3gfXBM5Zy3qMZaui1v8/b32wlWXEJik/58aQHcRa7Wvh/MMzhFf7SZxHKanB/81KTxne4lWavJHArYKNkXhYew+9YS6OSY4topLcHUgPZHwIGUmXXoqKNKF9kMMYtAKgL9cab+MtDNUKe2EnkwlmRwq6Pbc+Qk7HI/m+Wc01A6MdmG1xYkc9G7A== 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=4PIbC/wFdKQFR4fPcnPRmuAGeheqBomLveTHM5nKmSQ=; b=GzkdCF44+ALypCGX2MxTdLL+x8X3+tjm5E1EGQ66K7ov+wvujVj6O2Bc+53YYY3uKi7Mia9ldr9NvKI1RYXtVwwmrb6e4aN7QISls4DUzMwD8MTq5JPkg6ewtx3kxUiNgZSZ5EHKuo3yw6VQtBA7EcOjVVb/covBUh+ySHdR91TM3JZi5kq/GordVzSabM9cWNiN9E6wykgQ9AuntLwTvw8tfHHusKUQ1bwQ62LMOnjgWFK/eiuN0BrCnRDUeofnWWfesdlS8YkfPIYr+/IA6lr2D5GqmgGtgVhRfhdB4SopIS7WMwVg5sZk/cg9iKgfKS1o1raTDOc9ds7US900WA== 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=4PIbC/wFdKQFR4fPcnPRmuAGeheqBomLveTHM5nKmSQ=; b=eAShh+5FFHzDI8ZOo9ZOHe9/E/Uga7ZXC74obqKmbvUgCJF7IMB3RJODgob1arzroTRf9kKiEfu5s092ahUU8ebJEiFQvpT4Jn85aMnfYVsVYNJ3JWkDQy1W3RfYp/WSFzvfHqu6RiI1y4Q65f1szqYpNjdBkJ9PZQSa/Dv+grA4cLE+sqSBe232SiDF+saX9zD/2cPyfcy62+9Ve56QM7JhcNTTdnp+dvvDSgVOk337mqyxgHgUOLguH0t1Nf5orq5qeQ6lHNFNCN3B8yZ69GT4Ho37I1GD/vPOnIh6mV++TYnzCPkdWw9LuyoRs+BUjr14XW2jYkUc4X5oV3+VWQ== Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) by DM6PR12MB4483.namprd12.prod.outlook.com (2603:10b6:5:2a2::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3955.25; Tue, 23 Mar 2021 17:55:37 +0000 Received: from DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87]) by DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87%6]) with mapi id 15.20.3955.027; Tue, 23 Mar 2021 17:55:37 +0000 From: Jason Gunthorpe To: Alex Williamson , Cornelia Huck , kvm@vger.kernel.org, Kirti Wankhede Cc: "Raj, Ashok" , Dan Williams , Christoph Hellwig , Leon Romanovsky , Max Gurtovoy , Tarun Gupta Subject: [PATCH 07/18] vfio/mdev: Add missing reference counting to mdev_type Date: Tue, 23 Mar 2021 14:55:24 -0300 Message-Id: <7-v1-7dedf20b2b75+4f785-vfio2_jgg@nvidia.com> In-Reply-To: <0-v1-7dedf20b2b75+4f785-vfio2_jgg@nvidia.com> References: X-Originating-IP: [206.223.160.26] X-ClientProxiedBy: BL0PR0102CA0030.prod.exchangelabs.com (2603:10b6:207:18::43) To DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (206.223.160.26) by BL0PR0102CA0030.prod.exchangelabs.com (2603:10b6:207:18::43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3955.18 via Frontend Transport; Tue, 23 Mar 2021 17:55:36 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lOlFf-001cgo-FL; Tue, 23 Mar 2021 14:55:35 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c88f8c67-cb33-4298-6109-08d8ee24dd12 X-MS-TrafficTypeDiagnostic: DM6PR12MB4483: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2276; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Mx/hdbMzTw/bWFNtJQLyhGedtPAb66XAgk6BVT9uNP+c6hj5z6sskLOCK0U1/tj8knHW/vKXvAMA/TpTHJaW6DBalBrPwdy+d7MyStd13s4cnNxrG2i4sAWI+cEKrtnIgNdsTjyCImbDPgrsQme8AlC4ADh9Z+wYhwRocvfeGBkQj1nOXzWCgMcZrvcwVcmWW+P6v8p5Xt6TkAMk6Ea2V6Qx0NZXgd5bSr3IfPN8yfl7CuYGGER9e8MpKXL/FCpQKrCe1ooHQnnx/kseKj8i23Kb2O0rpcUp7lQUwF5w8zUhmnu/a4W6svwbSl5yIC+VVN23tKx2XnXkCIZvGx4/a1bf2cEIpx3ZhI1WNd2H1XRtMt8pHl089ljWEkWki4MSPbG7Z1R91Qxe/vIwXSwIGo3nvfABA4UXcXr2AfPnh28rupSHN29/l0IT5aunVfvfF8r7mSu0akwQ2wGxJnJ0kAj154OH2zgOaW5f5W70uB5w+t+zyXvwdUCuIHanCc7YmVEdRyrkjFWYd312DQHtoL1keXKXugzPCmxSeNiCq1bpJUfzXZVOuEiMFq0XY5Q9HEjHSe2vBZXGej8O+Ay64+Y9HuEOmsQubvEss2rHPRR380ZghpgpaDdXL8Q5/YMs0e77hfm+aL953mOHVKOZSk6FDZcNB0uOzTQ9w5dT/aXRMpKMhmL6OS38rm6OrbvB X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3834.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(366004)(39860400002)(136003)(396003)(346002)(186003)(26005)(36756003)(110136005)(5660300002)(38100700001)(66946007)(4326008)(66476007)(6666004)(2906002)(66556008)(54906003)(6636002)(478600001)(86362001)(316002)(8936002)(426003)(9746002)(9786002)(107886003)(8676002)(2616005)(83380400001)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 3dwmTcRTsUCiW9vIsntlFq2lfWd+4savseEybF8zFiEz2Va5P5AM/+c/Z54KHouQG3jyGmpgbc2Turly1fXuQ5q3wNgDGj1/2deQuyCrFxfwuq+J8ow/s2VFzC8VdGvyZLeft8ro7i/oKIg/9N74lc/7/SnCSpnNKnoQl+nCei9uVBjau1uQzj/ctItnPwWQIYy0I/a5SGMUjX921yptP2eK+ivJPtUMOGPMbpGM94gDzadxeaBvJ5KOOmG4RTcthpkasyG572MLFQtG2wmZ6amROnwatem/fZ4Q1cG2KBeekZROMU5FlUAxCcIfpAYksP2RiCInJS9T7fE8shHnNnogDr1TxW6NV42QHzmNF5Gco7YRRq2QWSMJ3djZLrDemofzsrBsv3+nH3q+rcDeqF5L3YF5+NGyou/+fSdQl1zDCWIidRHI86dzIaKc5V7Mbv29EPv/WB4Pqf/LJXnjpJgXZALIYqMrUwWlEqSUrfCBTeGE77+p74lmbnFJHUGxTcfjphP894vsjiZRb+4kMdSPeP4EeZlyQvJbGnCxq8Q9YNeHmf4p3LwpIBpKnHC8Y2JhFHosYaaY8D5P4v9GQ/iEHrpogg8DiWsvlmQZPlwIwKXnuBGfjT+7XM6jqgjnAYn7UF8RmmZzpivGsso7shVo1Ns1qSWlNvY0FJtoii+WvBAiwe9w6gmpe0s8H94OWZv0GmwOqq9C15d5v0ALmyrxeZuVZ10ouq1cbGFbI74fq7W1AYUoUzljyxePQ1ENQjvpO0ZwpdgRJ0TslV0eHIeVQtzMUlykvYZlvtIMkdsW1QMaPsA7zM3OR/x19wfgorvuLFK6L8Rj9z0SjqvqiuyOMktbfxQucrJKM8ZPQ1teBs7mehdQ/V8Lq5HCHoa3ppgAY4lo13Y5CqCe/qtu5dDoB+C2dOAGxAD0F2YMyOoLPSm+gcZCrhKOw9F9+ECA5qmUL9ihpE98vtuAyQ0EAZ9bf6WL8XYiEpxerw6zAN4YjPjbtBAOD2XqA4V1SKbJ+VF7g2mwhvkdtUvl5VxupYF7X8RFX5Pd0xJX3r+/bSKbvJAbOocxKt2JUkxyh7TqDMUlI8745heRF6p50Vo/1NGgBYzYQVg6dwZfr9AfSXnuhvlBEDQ+pegs3T2zELIdn2NeTzZLA0Wu6iXH8oZhwWCv51zRwqkLCa+pf0TQZ0B9sBTE6MUoVOyuhOzn9C2OjHEmwCjpduQNqLDsyy3TjDyf7DhkWyshSv44XlxVzDmef6EnrOnsVJCso7ZU1JlLIiluRgGGUMVlzQnWyX2HIT58LBpOia6urcGD53hBx9tr03luG6quV+K44fwJ3Eat X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: c88f8c67-cb33-4298-6109-08d8ee24dd12 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2021 17:55:36.9756 (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: XCdcBOv4ECl3AzC2O4FPxhUswWk6D36gW+jzDHwRqy3IVUG40Cjd/x4maPGk1u97 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4483 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org struct mdev_type holds a pointer to the kref'd object struct mdev_parent, but doesn't hold the kref. The lifetime of the parent becomes implicit because parent_remove_sysfs_files() is supposed to remove all the access before the parent can be freed, but this is very hard to reason about. Make it obviously correct by adding the missing get. Signed-off-by: Jason Gunthorpe Reviewed-by: Christoph Hellwig Reviewed-by: Kevin Tian Reviewed-by: Cornelia Huck --- drivers/vfio/mdev/mdev_sysfs.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/vfio/mdev/mdev_sysfs.c b/drivers/vfio/mdev/mdev_sysfs.c index 5219cdd6dbbc49..d43775bd0ba340 100644 --- a/drivers/vfio/mdev/mdev_sysfs.c +++ b/drivers/vfio/mdev/mdev_sysfs.c @@ -81,6 +81,8 @@ static void mdev_type_release(struct kobject *kobj) struct mdev_type *type = to_mdev_type(kobj); pr_debug("Releasing group %s\n", kobj->name); + /* Pairs with the get in add_mdev_supported_type() */ + mdev_put_parent(type->parent); kfree(type); } @@ -106,6 +108,8 @@ static struct mdev_type *add_mdev_supported_type(struct mdev_parent *parent, type->kobj.kset = parent->mdev_types_kset; type->parent = parent; + /* Pairs with the put in mdev_type_release() */ + mdev_get_parent(parent); ret = kobject_init_and_add(&type->kobj, &mdev_type_ktype, NULL, "%s-%s", dev_driver_string(parent->dev), From patchwork Tue Mar 23 17:55:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12158933 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=-16.0 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 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 B4F85C433F1 for ; Tue, 23 Mar 2021 17:56:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A39FD619C8 for ; Tue, 23 Mar 2021 17:56:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231394AbhCWR4N (ORCPT ); Tue, 23 Mar 2021 13:56:13 -0400 Received: from mail-dm6nam12on2063.outbound.protection.outlook.com ([40.107.243.63]:64608 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231241AbhCWRzm (ORCPT ); Tue, 23 Mar 2021 13:55:42 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TJ2XJvp6SjRp7IiiBLl6DLtsi0yewb7d1/uZPV//2LplQ6jXUNA/ia40n2YddlLsIGqZ+p69ykPvztyndOQ5FTV0j4ZwXk5g25SZuYB10PY3Bvd/usSQD5gyRlIPB3x8JfU9OSF70XFiAh/+6ywgfyPKIyHncwTo7m/L3CgdGCI34ObQg0QzZPw5v8MQEoy0Q1F/MSsRF0eN2jfcODhuJ3P2dBKieGvIzv+78v6WQfgkEdzjHmStcxWl05GMe+jjYbcv4E5lV7drCf91OXEO/HlbcLr2P3VNBK1/R9b4TmZyhbg6MSHwj+jDBSVEcbozLy8GL1xi6ualNtLxJwK2yA== 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=JH0Dx0MLYbD2JA4072HoG+3YqcnhwH6zFLk5giWFPfY=; b=jdQJePkx0p8X7HPqu+q0AyYZ0qcSHpDXVqA2zQGkZhK+y5G9r6/d5CL/aZf46gV1Hhct035fy8TY9Oic6NpuTcWlV/iFy8LHxnB5uoGvdsONIY8qZPju/ZTLXaAxYF9Bmhn5R21Sy5HoU+cHM2aKTtzf0Lx99RDAD9sGHxwfKEyajceJNX5m0e8wbBLfDpQcgLj3eF0kAoi7Bb4TiuSwjkBLfJXHhem4qZnnx3AaOSQvuR1e0/a7KcZJ2irQiESYCkTLOPy24EAYwzT27io9/pKtwbuXnZqOlTXZy7EE3G0aD4dHKLyU1NJyNxBOmF16J2xzUIectcXMfWSI3J0GHQ== 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=JH0Dx0MLYbD2JA4072HoG+3YqcnhwH6zFLk5giWFPfY=; b=Yc7CbC2RmMWsVAj6RqPfmwtkWTzlEeDsQoSnaQf9cY7VwMWApua3qeXycLRWd89+pdwh2d4vKuVum7BujPKxm3L4mXHNakt3nx3tQW2YGcPlOeV9X/IQ53Kd7I6WdQvRhVZon2pGpJ2VlwdiNUYo3jEywFNmxJIR03Vjr9cVVJpI8NJ5vecLcuztsGYE+OiDb109378/BvO1bxXJvmc+WMWKVErxiAVfMmMmM15pbK5/Jj/muE/4TPF7ihYjTJHMYbsBX6uUlnz5aiwVkA+ZmHgcIyly5MB3UCR0/4v83HSYQ6Kh+hdsvWmbMtczgTf8LTpiM2Ga2BcQcvPTCfKGDQ== Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) by DM6PR12MB4483.namprd12.prod.outlook.com (2603:10b6:5:2a2::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3955.25; Tue, 23 Mar 2021 17:55:41 +0000 Received: from DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87]) by DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87%6]) with mapi id 15.20.3955.027; Tue, 23 Mar 2021 17:55:41 +0000 From: Jason Gunthorpe To: Alex Williamson , Cornelia Huck , kvm@vger.kernel.org, Kirti Wankhede Cc: "Raj, Ashok" , Dan Williams , Christoph Hellwig , Leon Romanovsky , Max Gurtovoy , Tarun Gupta Subject: [PATCH 08/18] vfio/mdev: Reorganize mdev_device_create() Date: Tue, 23 Mar 2021 14:55:25 -0300 Message-Id: <8-v1-7dedf20b2b75+4f785-vfio2_jgg@nvidia.com> In-Reply-To: <0-v1-7dedf20b2b75+4f785-vfio2_jgg@nvidia.com> References: X-Originating-IP: [206.223.160.26] X-ClientProxiedBy: BL0PR0102CA0035.prod.exchangelabs.com (2603:10b6:207:18::48) To DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (206.223.160.26) by BL0PR0102CA0035.prod.exchangelabs.com (2603:10b6:207:18::48) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3955.18 via Frontend Transport; Tue, 23 Mar 2021 17:55:38 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lOlFf-001cgs-GP; Tue, 23 Mar 2021 14:55:35 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 46a45c89-bb0b-43b4-85bc-08d8ee24de11 X-MS-TrafficTypeDiagnostic: DM6PR12MB4483: 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: Xq8ihY2L1LcF2jNcD2OrmOCBr2aVuQ1jFLDr1Z1XNIFB9G/oqoGeyjRh+ej22sSQ+5vozSCErOlazg11mniofygUbuRrqzwc6aLlX/B29gQI+/gyeo9LTy1SQ/NxCMDUdOlzPobjJzrQeiPEokI7uVace8agRPeBOtQj1GDuSLYPFy8TA9zqrL1dQeFAofHT5vOtd0vv8Db2fM4zwswvQOo3yzWSNOUXmJM8Xh5Wlxff08EvvdNJtQNRZqB+tw6CgCI+QeR0vrZAX4di8GKZp+VXQl1uTwtfHz8hqTQzZRZsbvo2oSmO5hgXE75C/A8p6Ywv1aHThM7xfpJHQEDWv1liA15pw/57oDOksvHc6ju3mDbMmr18117mi6UNi1U1gya1rcwetpeCD88j8Qb4D9r9EJMaLDKsnlOrAgygGoaMRyaoIaFljU8fzSucuSZg33GHz0Qx8yx6v11Go0iXYiZILH+XYRdsFe8WPzqpxjZMTwfRm1LtI3SMyrVz/CAsheqEpw4+3TjLx8TjlLbYljdJaGlDcKfN+Px8EO51oLSSyjYwWpB0zpigo9KETtbeYyIfp5NUYmPPn3lBW3lKfSRG4p39j4nbV4qPyl6AVrsDvZrmyJmCBo8dUUj/dYhQVvJj5nk6uY5cCeoP2VwGwYuRUucGPLxKUaryj+QrSD5goiH9hEaVwgfaVWdX7Peh X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3834.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(366004)(39860400002)(136003)(396003)(346002)(186003)(26005)(36756003)(110136005)(5660300002)(38100700001)(66946007)(4326008)(66476007)(6666004)(2906002)(66556008)(54906003)(6636002)(478600001)(86362001)(316002)(8936002)(426003)(9746002)(9786002)(107886003)(8676002)(2616005)(83380400001)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 7j6l6lFwaraownRhtDk8AasjmH85meW0dzZvK535LrtBBEGSc4RPzxLmDOlw/Xx8cH7MU40vgMBne59CG2moWURNF86snb0za0IC1d9v1Xz9wiPQoYrbAhS0jZQkDMXhgrDSIBaWTmtulqAOo/8767l4EKtJM2VkbJm5zES18y+e7vV1iwiYy1ctwq4TjqHnNyGRWmDATjod1yL+am6Lsjs54xLZl7HpSSeHDli5/AL0ByK6E5csBEWxxWZmyamiyLl+WhuiedRddYfY+8KjS4BRLR/DQSbyhj/JKLNLD/Tt+UCIgkWPvnUWgpV/U2p8Q2kIv4ftTxy+2N1H0WArSKYvcxvtZ5i0JejUC6p2guKBiK1rTPNGADAg42kbiomISuAqozUqVKzuf9FypVokNKHGgUwj2jOpx+FXLUW70GBuF1kNo/nJzEEsSvp9KUS8e+JXCW/rHPDevDoarzIgE6ALYLzuFOB9su5eNvA1YOX5i87aE/3QCrwYmHKgfAHGZGbGMP1suIHVKJuBg9xE3jQspThx3SaKpPu2LhziGwn0wv6WbNyclNb41QiGzkSVmCgp4IW1vXgn8vS9z7U+/ke2Ud6huqpNxXnlIwg7OrzgrOT4stvd6THldjIN0ZteGDFlszaRBiI9ca4PYalBFQNjLJgCHLLMAPrkhfRbjwNYX5OIbT/2Fiml97oW9cJ9AOLOsKwz+Yd4N/BL8SLvbtGPobxegj90TZg4JWDTVT5bRjb8OAed9lEI1cRByfaMKe7ZsTPyA8Ce9kYllz9u4R7/HqUtswTbeKc6ZbuFBKIDFP0lAqFRW5XtCPL5MU2PsD3etkYIMlZlXJE9xMUQwee4u1ZAg6YTy9VR81hrq0CL/5ckmonHm006rT7IKG61gw+p7/WEbW02zsvxkSVHfXEExz5RVdL3u8ckGQ+7U/XGuEs6zxCB3MQb/aO5Y0zidw2lef/mLy55Qdbz7LVBTPqflGSocoaobhwaolxKEb8WrZXuaMk6DDEFyoLF/EJbdXursZCRRv045eKC9StBCiDxq9K5vS0P3jsZf0kXJletQQ1yqNVZMaZUJBq2Soa0+/deTXIHty1oo/FWFnKldDKNKv/A5bVULUFNu4ElOVkNhQn/UKh+zkkGc33+NuZqojBhkn3OPmfAIOduA7gFjKKGdL/TMbC3Ky3RbASZKpSnDsRElbERTgGYvU7gu9Mi+jlEKVmPuDSlErVFXh6RNRosmBFl6SA5iT6Qyi6//dUgyIEPx2+W5yPZVufONnSqSPDcssdWzBKsRDy47sqG8rSqYUjJJPSCg5DKLmX+9ACLR3FjW+rThYLe0BPklXh8 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 46a45c89-bb0b-43b4-85bc-08d8ee24de11 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2021 17:55:38.7957 (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: LUqmKmUO076nw1lGr7eFAM25yyZ0zriHkyAlBeumfHNpM8mrgJx91RcWWnSc+fix X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4483 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Once the memory for the struct mdev_device is allocated it should immediately be device_initialize()'d and filled in so that put_device() can always be used to undo the allocation. Place the mdev_get/put_parent() so that they are clearly protecting the mdev->parent pointer. Move the final put to the release function so that the lifetime rules are trivial to understand. Remove mdev_device_free() as the release function via device_put() is now usable in all cases. Signed-off-by: Jason Gunthorpe Reviewed-by: Christoph Hellwig Reviewed-by: Kevin Tian Reviewed-by: Cornelia Huck --- drivers/vfio/mdev/mdev_core.c | 46 +++++++++++++++-------------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c index 7ec21c907397a5..517b6fd351b63a 100644 --- a/drivers/vfio/mdev/mdev_core.c +++ b/drivers/vfio/mdev/mdev_core.c @@ -71,7 +71,6 @@ static void mdev_device_remove_common(struct mdev_device *mdev) /* Balances with device_initialize() */ put_device(&mdev->dev); - mdev_put_parent(parent); } static int mdev_device_remove_cb(struct device *dev, void *data) @@ -208,8 +207,13 @@ void mdev_unregister_device(struct device *dev) } EXPORT_SYMBOL(mdev_unregister_device); -static void mdev_device_free(struct mdev_device *mdev) +static void mdev_device_release(struct device *dev) { + struct mdev_device *mdev = to_mdev_device(dev); + + /* Pairs with the get in mdev_device_create() */ + mdev_put_parent(mdev->parent); + mutex_lock(&mdev_list_lock); list_del(&mdev->next); mutex_unlock(&mdev_list_lock); @@ -218,59 +222,50 @@ static void mdev_device_free(struct mdev_device *mdev) kfree(mdev); } -static void mdev_device_release(struct device *dev) -{ - struct mdev_device *mdev = to_mdev_device(dev); - - mdev_device_free(mdev); -} - 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; - mdev_get_parent(parent); mutex_lock(&mdev_list_lock); /* Check for duplicate */ list_for_each_entry(tmp, &mdev_list, next) { if (guid_equal(&tmp->uuid, uuid)) { mutex_unlock(&mdev_list_lock); - ret = -EEXIST; - goto mdev_fail; + return -EEXIST; } } mdev = kzalloc(sizeof(*mdev), GFP_KERNEL); if (!mdev) { mutex_unlock(&mdev_list_lock); - ret = -ENOMEM; - goto mdev_fail; + return -ENOMEM; } + device_initialize(&mdev->dev); + mdev->dev.parent = parent->dev; + mdev->dev.bus = &mdev_bus_type; + mdev->dev.release = mdev_device_release; + mdev->dev.groups = parent->ops->mdev_attr_groups; + mdev->type = type; + mdev->parent = parent; + /* Pairs with the put in mdev_device_release() */ + mdev_get_parent(parent); + guid_copy(&mdev->uuid, uuid); list_add(&mdev->next, &mdev_list); mutex_unlock(&mdev_list_lock); - mdev->parent = parent; + dev_set_name(&mdev->dev, "%pUl", uuid); /* Check if parent unregistration has started */ if (!down_read_trylock(&parent->unreg_sem)) { - mdev_device_free(mdev); ret = -ENODEV; goto mdev_fail; } - device_initialize(&mdev->dev); - mdev->dev.parent = parent->dev; - mdev->dev.bus = &mdev_bus_type; - mdev->dev.release = mdev_device_release; - dev_set_name(&mdev->dev, "%pUl", uuid); - mdev->dev.groups = parent->ops->mdev_attr_groups; - mdev->type = type; - ret = parent->ops->create(&type->kobj, mdev); if (ret) goto ops_create_fail; @@ -295,9 +290,8 @@ int mdev_device_create(struct mdev_type *type, const guid_t *uuid) parent->ops->remove(mdev); ops_create_fail: up_read(&parent->unreg_sem); - put_device(&mdev->dev); mdev_fail: - mdev_put_parent(parent); + put_device(&mdev->dev); return ret; } From patchwork Tue Mar 23 17:55:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12158927 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=-16.0 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 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 5C333C433EA for ; Tue, 23 Mar 2021 17:56:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3797B619C7 for ; Tue, 23 Mar 2021 17:56:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231376AbhCWR4L (ORCPT ); Tue, 23 Mar 2021 13:56:11 -0400 Received: from mail-eopbgr690085.outbound.protection.outlook.com ([40.107.69.85]:23427 "EHLO NAM04-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231214AbhCWRzk (ORCPT ); Tue, 23 Mar 2021 13:55:40 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=flUvhaSqRseJUhqfP1NHX7/daGcFwTVSVMdmbm/Fb0H3hrBm2LSpUNPYZXPEfqu64sezdFqT0Ina0fCgovF1jTV/RELE9CQc32jFK7XL9ubQtByyxIaXb2titQ6iuVNTY0YgfyOhW1JZ7A24Ehdb6il2dnSWnKlMfD5VCxWN77Lx5KHl4Z/5rFwBg4daPpjXfRqptNIZUUItpEpoJoyzVZFVhreZsP3q1VJ10GofXXf5U1yJDP8MoleebY05zjRhjk1TGX1ZhTjHih75iESmDf/PL8GC/uzXyFAfnw3s8rjLTTtirQVJtpGtddX+qoSMcR0CpUv0oaXPcts1oF8xbw== 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=ETm9Coh7g03O/Saim5zxYpivmGUONCqTvBnD+Qp7bJU=; b=A9thg2Uom0Nc/Wdl0VvOvfkKykbilw4xrdDrBcFFJAgTXyCTfNH+iv6znxTgAOZipJ8L2Hv1qX43TmfJ17G82CdpCZPOGlDO3X7yrOn4zH9C8Ky2GseMsLSOHHAPLlVqNg7yZjs5Q7/PsOGi7vIGR1kdO/C3jQCz2SsP5UxI81wT0kRGpJ8r6iMDp6kwNTkic4nwOMmdoAynvA1hBIVkBciUbwHPRix+DE5PB1lZ67YOeMcKbPJb73RT9IFaI/s6UbrLDAk9MFasOQKp9QqQAdi9wGZUY8w8TOX0cQw4hel6YnPv+ftbLZc3Xw2iPeDBPI6vj4E+DCjpvUmsJWjsGA== 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=ETm9Coh7g03O/Saim5zxYpivmGUONCqTvBnD+Qp7bJU=; b=AeHJLSki61bVyhkQ4MLB/0wU8Qaw2wBLT4J2vF4EpNRwpYOqGjKQVTi75x0gSfKlR4MJoSSowZUXcBa8KeVT6AGTlXyIFKthVV/12tiif/7RwoEkJl77tnXo08zmNotTGVlJS9XOI6L894+51kH6NwrQMvck31+9vKhCSrjX2+2qxYSQ7/lMPq4GDEml3uKop2gCqQx0O8BURN3HlIdupOUt5YPcTVXEqeVCDcyx8nwtrqv32MEwzyD54VJOkO7mXM+7iUrpLN/z4fz0J5OzyTd9jbUTRBjzxCu6fR+0RTVUkqzVHOOrpDeFNrKvoXXLAtkhLSYpp9QgJSt/XV6fTA== Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) by DM6PR12MB3932.namprd12.prod.outlook.com (2603:10b6:5:1c1::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3955.23; Tue, 23 Mar 2021 17:55:39 +0000 Received: from DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87]) by DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87%6]) with mapi id 15.20.3955.027; Tue, 23 Mar 2021 17:55:39 +0000 From: Jason Gunthorpe To: Cornelia Huck , kvm@vger.kernel.org Cc: Alex Williamson , "Raj, Ashok" , Dong Jia Shi , Neo Jia , Dan Williams , Christoph Hellwig , Jike Song , Kirti Wankhede , Leon Romanovsky , Max Gurtovoy , Tarun Gupta Subject: [PATCH 09/18] vfio/mdev: Add missing error handling to dev_set_name() Date: Tue, 23 Mar 2021 14:55:26 -0300 Message-Id: <9-v1-7dedf20b2b75+4f785-vfio2_jgg@nvidia.com> In-Reply-To: <0-v1-7dedf20b2b75+4f785-vfio2_jgg@nvidia.com> References: X-Originating-IP: [206.223.160.26] X-ClientProxiedBy: MN2PR18CA0009.namprd18.prod.outlook.com (2603:10b6:208:23c::14) To DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (206.223.160.26) by MN2PR18CA0009.namprd18.prod.outlook.com (2603:10b6:208:23c::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3955.18 via Frontend Transport; Tue, 23 Mar 2021 17:55:37 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lOlFf-001cgx-Hl; Tue, 23 Mar 2021 14:55:35 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fcb63f99-ff48-4ed4-de21-08d8ee24dd66 X-MS-TrafficTypeDiagnostic: DM6PR12MB3932: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4714; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cekHjntakZv9GOAl4+2DsPN08VZBeWX37c2v5K9ztzr2HSMNG/4XSKh0DWEZ9nH7jtOkAOH/12CjxnYHw5fTLPB7fHlLTJb6g6lHeLkezIUQCk7fkQrNLTtGZ6mHTkeY/wlTTPX1WMa4MdXzCZDYNUYWjBmQy3vM2xwmRzoEwUAnorcLFB1TbJBSRi75a3Yh4Aj++rCWJ+ERJjJ8MCAoeB7M8W+JuGmfxQ6nr3sMdMiPjmtTesPH0F7BDB91Db0UFFSNmovIAQ7OF59hbHKzk7I7Gs5g8L7l4+8f8DO+st/U5+LGtmBhf4AbS7OVoX5TfjOV5Ats6XxO6Mq71CSheutyO1n89hiIjLpg+EXuJKjt0XAPmaIW7G1oU+Dy2EB/bvfIfNHMFxxkxQEDLihKAVrr4KJWGtrDPZOGgNcWS30FOxHADTxoN2ENXlEpOQbMQJi7WLHKI75zpViig+QESi7bLDflNc79DutU7Y33hQBro7awNNCd7flWYyCxz6qbVCm4y4zgt548qE9fluPU6lYhcBWaCi/KDRgYRnZxsTCzSZ4eppEx8S9ABQQkva3tZ1LDFwl6nF9Os1FBWYG8QNhXahWZdeQRaNmKeWUo8j+1egAy/umZM/O1dTLMnn/91ImZOZhDgTvR60Vpzh6IE12551wV0e6jbwCjDEBWJaB5c1TL3O95x9e0O9LDghBj X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3834.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(136003)(366004)(39840400004)(396003)(346002)(2616005)(6666004)(9786002)(478600001)(66556008)(86362001)(8936002)(107886003)(66946007)(83380400001)(9746002)(66476007)(26005)(5660300002)(54906003)(4744005)(8676002)(316002)(2906002)(4326008)(186003)(38100700001)(426003)(36756003)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: tVgdF3qF66mntBoVNhr1QHmJAj42OA2m5BSW+0iFAUjUN/mvNRqiRDdejjFkLKz/ilpg/cGopmAceGjElII1WcxXD2Souytrx2Y9tU+bdJBY5exLWRSPYqvyP5m6ftS26BE6UZQc1/28LGQegSfVdnZ+E3UQS9vgP1WUZXoeei3oQhLFbHP9GlciECSDntzd1M4GHtKcRh1Jt3rk9X58lsgWga+AO/Q1fFPDWdWZvXt0unVQt6tEg8uZJZyDYX2x2CQkAa50l7cW4q2xPmV2SWe8ig2TjA6iqLCtNz7eCfqcV/O/I6cAmeGc1z7ALDJwxD8Rtxbs8bkVRxgr5To0LqzUF7E+wTx572Ebe4H5YonQRUsnWHuYlFI4oDB+o3C+bQRIXdZTeavAwhSmNzFqLNYpYdaNWKzWYfAqUZygmUmmqK/hPiLAxo48KRiHboNfaje4GDLZofdD1wBZ/C0inY8Nwhccyc1TYVxOvfxFbpL3hFArM1yVo6SENbR5B8myuv8JqGXz00svRTkjznI2NOIm8dmaEa1XJl+x1AgXDMrdgSCvcXo+gI6armhDeTgful2Fnl1C1IBoYoRcy4eDdk4WZZZyNIcYVZWLbdEzWD7FdMw71j01oodi3y8uVFnjWZZZMqysRCgpFfAGBPpCYpFFiHUmBSiZVpc9QosNDRXUam8uibN1AB3+BjxBZa2gEju8n5LwUnfBJvP0QztcA/F8aI+TldR5coGUPM2ypE77Nsz3QJ0RV5NthIde8SoVXlmmkuWAk0UcnhUzs4Jn6LJSVWbQd+28q42i6Y8vIV/twwIHHEeC6ka0d5qmAQMSm7iPfHEjxVGMQquxhFLFRr/61+DG4aGzJb5C+PLz9yEXON6WzWt/VK/7Kq6qCRFZGBRauBf27d0jtyuYdBctdDbTEt6JGS32H5HalZHh5POvvYRcBAMPnNKVV+jgAOKqFtDdw0PECAbfQ3B0O+qVEz6ffnsKGsTmmAX0j7bsEEn+/D2Ciu3x6S8gqqGMcrwRqGFR2gIKBRKC6Ug129lepONqC3wjtd6ZkT4her2QNWOdf+2U6/9cPrvRT88Jxk2LJdj69UQmQMN3mh1biD25j+rACb2ss1leAJS042PrMfRRNmEpiLKqh8eMMz8eQGDNdoDSu2xWGc8b1RgNsj73NLZpwg2/2aov9WXR66I2DmzoW/RNQhgkVwAizKWcmaQnc33qLcIMvNnNhPAwQPWzS2PHw+PpmypcO8F4CmHgIlxJ3tIUBdMTh/sds550HLdeetwJVc+3Rp6ixNmeBT5IPLmcHYEn1A3rsQCK+tZ83jePYCm//xa8Xqyqh68L46zd X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: fcb63f99-ff48-4ed4-de21-08d8ee24dd66 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2021 17:55:37.6043 (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: E9wKwToahgWmh7RhJ+N58WRXuzH2/yaNE2q2GNvAkgRc89L0xca9N/cUaGY4N8f4 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3932 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This can fail, and seems to be a popular target for syzkaller error injection. Check the error return and unwind with put_device(). Fixes: 7b96953bc640 ("vfio: Mediated device Core driver") Signed-off-by: Jason Gunthorpe Reviewed-by: Christoph Hellwig Reviewed-by: Kevin Tian Reviewed-by: Max Gurtovoy Reviewed-by: Cornelia Huck --- drivers/vfio/mdev/mdev_core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c index 517b6fd351b63a..4b5e372ed58f26 100644 --- a/drivers/vfio/mdev/mdev_core.c +++ b/drivers/vfio/mdev/mdev_core.c @@ -258,7 +258,9 @@ int mdev_device_create(struct mdev_type *type, const guid_t *uuid) list_add(&mdev->next, &mdev_list); mutex_unlock(&mdev_list_lock); - dev_set_name(&mdev->dev, "%pUl", uuid); + ret = dev_set_name(&mdev->dev, "%pUl", uuid); + if (ret) + goto mdev_fail; /* Check if parent unregistration has started */ if (!down_read_trylock(&parent->unreg_sem)) { From patchwork Tue Mar 23 17:55:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12158939 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=-16.0 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 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 1B586C433F4 for ; Tue, 23 Mar 2021 17:56:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E9DE2619C8 for ; Tue, 23 Mar 2021 17:56:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231420AbhCWR4T (ORCPT ); Tue, 23 Mar 2021 13:56:19 -0400 Received: from mail-bn8nam12on2077.outbound.protection.outlook.com ([40.107.237.77]:36673 "EHLO NAM12-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231313AbhCWRzo (ORCPT ); Tue, 23 Mar 2021 13:55:44 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KzrQOABJ2XpTAt546SbXiLkGrku9Sp0hOircyu5a7jYzpfGkOdAqqzB0WNWfVvi3dq+erY00adfsTohJ44WiKh/dcEbDkPmqjQ5F0ulktjYgP33EKAprJ44tBNcR3ak1dKzkS6F9Jk8dA91EPAUAvHC2g/RhYs6PJDgSz4g3OhkbWf+c/RMaf4ZsbzrdATlpn4j5sTNFGIi3Sbuq4S1kiU7lbq2SKH2T5tC43fGDrQDpWW/cvZQcwwEhuExTiG1Hq0Vh1ar4qmJhQvUZ7o8Rk2X1X7bZVBlXhCWhFnIblZm8bW9b0T38pkrCqYYrg0SDhyK5C3KrbpM7GvQTHH7RUw== 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=x/nI+FB4N5ClW/A+/83ogRuYqSicWeFW0aES/FV0WQ0=; b=G32aWHDCJDHe6mOeFldU29C3CU27TaeYfNiWfhB1nMJ5eDWNwU0teJEkBD0XiLbs3/cYMa6gbXgqmGXGlCL+ucjLpGndwuP0RO2xSx0/EC3oXQmfG52M0izz9T8KcARURSH2iLJNCwidpZQAMOftanqhpI9nd1aMKz2iYUP/h+PPl898a+/8ihHKugKUsTfKiBQNc9K1eiGmOW5PBEU7x2XmI5+Xfe3Vfz1DTg0Fqkg0oEyHYDiBDl080QBhbry5z5R074QiZgbP1GvqJBgeFlDmsMZOI42ZtLNx9MWh1GIzYfmgIIrnG6uTuJ+NZnJFspQ14YTsuzjjghAhAk0KTg== 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=x/nI+FB4N5ClW/A+/83ogRuYqSicWeFW0aES/FV0WQ0=; b=K3BhO7OOdj3eaUGy5+lT/EWgSltRqc3jWcFYR9qjm0X6N+aaZXTIZwvBUlwv2aCBHHsoQJgFDIsV3jfuOZaS9/QOHjNFzLwaJw6z6JSjuTDdVq3ukaV/HAF884976x5XO4iCsK0t7sFu1O+M03rUm5YvuKDCwFQeYvR31wT1WGPbr48lDTcDebmVldelPYuPdkru0P1N6xd1si/tmHgVncYIGuuJZOLmzSPqEfujV/CwMzBZYoMMsVveIbplxqV3+UD3Zy3ABxu3WGcKiUXQ2e70nJMGvdzXE7x1PO3ezieSYhwINsFIrWQMIsxCbfX9BKjw3YqDbOq6q4BA3D1DRQ== Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) by DM6PR12MB4943.namprd12.prod.outlook.com (2603:10b6:5:1bc::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3955.18; Tue, 23 Mar 2021 17:55:42 +0000 Received: from DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87]) by DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87%6]) with mapi id 15.20.3955.027; Tue, 23 Mar 2021 17:55:42 +0000 From: Jason Gunthorpe To: Alex Williamson , Cornelia Huck , kvm@vger.kernel.org, Kirti Wankhede Cc: "Raj, Ashok" , Dan Williams , Christoph Hellwig , Leon Romanovsky , Max Gurtovoy , Tarun Gupta Subject: [PATCH 10/18] vfio/mdev: Remove duplicate storage of parent in mdev_device Date: Tue, 23 Mar 2021 14:55:27 -0300 Message-Id: <10-v1-7dedf20b2b75+4f785-vfio2_jgg@nvidia.com> In-Reply-To: <0-v1-7dedf20b2b75+4f785-vfio2_jgg@nvidia.com> References: X-Originating-IP: [206.223.160.26] X-ClientProxiedBy: MN2PR18CA0018.namprd18.prod.outlook.com (2603:10b6:208:23c::23) To DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (206.223.160.26) by MN2PR18CA0018.namprd18.prod.outlook.com (2603:10b6:208:23c::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.24 via Frontend Transport; Tue, 23 Mar 2021 17:55:39 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lOlFf-001ch0-JK; Tue, 23 Mar 2021 14:55:35 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: dee73a02-fd27-41cc-7f56-08d8ee24dec3 X-MS-TrafficTypeDiagnostic: DM6PR12MB4943: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9Gkk5SfM6tYMatJ0hzlZ7kEHSaGF5a6WxRKu18EDBtkUoHrIsZQ5bBAw1RzraFSx+KCvqgL0JH4akEOU+9pxUrYhz99afXjbW4RoJRvcAWNrAARrHT1fc7XXFoIQNUZ8+h1dwGoGVuchSbbgQ+4La/JUtPQJzX5oq14a7uasYk6gnCW4W8GCcswvaI80YWaA/dEliSCVDLTN704kgGiNiU7pVpxXpZAtVI6LprsffY7/NYNrWOCgLXYnC6MAkct4550t0KU19F2Evnh/3VkXQRMoKTZrpiFntgk+cjSl0NFYgL7wxOa2mgcfxusIdq8VBg7343a9MB11QU8l2vAE4ndLI0wCkWX6CYbrBSlkHraLELNvCNGvAp/fN6o8synEVUbQn82MCh5n3IaEjfipI9o9l5LogNw6PoR5C+rfV99MoI/z2XwU0Wq3q50/VH63i4CKEnpfVupc6TrH85hOgVnoqYu+daFk4Jwe+cRX2b11HGllhZcy0+MXE75vq3Snds1Mv1j7Y6Fuyd9MPMfpHuOHz+vUu3wBjlJITG37t5Jnrlg6hqIQR30xcAkQJVckywTJz2aKeYrGz98P0rxH7RvEE5OXBBJtr9HKz52BA/eFLmpDY0HpSRSgk+H8dIpzFm0ynVxCfjb33keO+U0MxyBkoY5WOI43OevaMp72yrA= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3834.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(39860400002)(136003)(376002)(366004)(346002)(66476007)(186003)(107886003)(6666004)(8936002)(110136005)(36756003)(426003)(86362001)(54906003)(83380400001)(2616005)(38100700001)(66946007)(5660300002)(478600001)(9746002)(66556008)(8676002)(4326008)(2906002)(26005)(316002)(9786002)(6636002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: epUy1rTfTlW63rZc7GUAXHNZ9S3O8Iti4dTAek9N/fFW9oFNrQyjGuU+ZlAqKkx8qWdToUMi+1NVCVl7vcZwR/3q8D+wi/tefLZ/+7y6CMMrXi1jHdGYDhchmm8GhMu55yAn75ONr1vyaOM5cwIU5KR8HnFdCN45p3L9MYk/fUWBCYfRzAx2yWCXOO443JrqHAfxRqVHciLe0A7opurPLJCLcaGMdrdyRALrfHZRQgb7+mRvOL1qjC4nAXyz+Wm70SEn2T4x3+tOYkaSEblJe1VxzlzVsm6v/ubUfxZdO1Q/E4nOJUJWxLkUcqNQ04FblEx+DAunsGZ5xWYmYuBjfHCCV9XX1dY1axhIUGDdzOm80U9QesT5Hj3SLHxvtSbd0WILC+ENjXHJkiN90hciJWGZN/5FI1q1n5EBj9GRJGZ537aor9wVC0BCOYvea9hFlojsqPA0hnGEmF3ydqY8wPeZSGpoob18F6a8ydA6DIhpSkNwpugT9+ORDHDo6P+aX4/Ncn8MY/psOZu6DAqVB0/ExKW1WHCu67/Fa08paSDUiRQLH9r21HmcJcO4UOk0FcpBmPeuqULtnq55Jg4iVxr0Z2LOlO6dWYziLn7VZA9t8q10oyBgOLDKxrXPc4y9XckDzkpIGrvw1V6S12Pf4phUTiwukyiJFi5NWWFXVqgowbu2JQQx9ul50huXO5RpGZpwU3K6yynpDmvJmkOzfclH6OTzjA7MCyIVbA7grsdH0w/JpgXIJmEpq9YokpHuUGH+rLp7eWqvxnAiNEMSPYMo6uY/zk404iiwUhRF7Dgd2Ff0cDHF+ePi73Hryk53CkGoi/8SMYOfL/2vgG30VFAtSmGj0cEo6zSiUfCKIPoF1gCMYKTYwI2Fll9Q2LITl/UlYotCwOELc4hZjOEOEHGm10/M1QHzvU+UpsavtZ4culC2lWZ+KVrB1nfBG6b9DfcnShUC4MY5ieC6K7yd7fqaZhXB2pYWc+TAIDgKHysnys1vO0QhcgvhHz7U/RvWJRPpsTF+6x+8g0dvMavxQO5URc9rDHYlrHW5Qf2ogr+peDjF7dWoSSViG1vssVGxtwn7gesWnjqVHgEv8CpI1C4Ok8CC9vSvIJgCzVxtHyeGGyy3kGqGnHKIOysUmYZm1ZY6Lk4IurUy/tdwAPXdI8yPoJkRGFgd6b9sWn1IIbviAcpz3Zx2QF5aixdOqsfe8UM0ibjIAHnZVB2Wnns3f+feXImHnxA6vif/K2OWIEzSjDNS3iXNhh0B/EZq8u8eaulJ1BTE19AdnbdOKbJNAOcSkjWAYJ9A4ky2jePOe07gVAsYCy8jh+ulZHcBAvqj X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: dee73a02-fd27-41cc-7f56-08d8ee24dec3 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2021 17:55:40.0210 (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: WmSv7ruPJ9W3VVBlP2YJRRSCgtfzdLOuGK2zbZnM5Z21DlGAc7eyPUNfferw+YJX X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4943 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org mdev_device->type->parent is the same thing. The struct mdev_device was relying on the kref on the mdev_parent to also indirectly hold a kref on the mdev_type pointer. Now that the type holds a kref on the parent we can directly kref the mdev_type and remove this implicit relationship. Signed-off-by: Jason Gunthorpe Reviewed-by: Christoph Hellwig Reviewed-by: Cornelia Huck --- drivers/vfio/mdev/mdev_core.c | 13 +++++-------- drivers/vfio/mdev/vfio_mdev.c | 14 +++++++------- include/linux/mdev.h | 1 - 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c index 4b5e372ed58f26..493df3da451339 100644 --- a/drivers/vfio/mdev/mdev_core.c +++ b/drivers/vfio/mdev/mdev_core.c @@ -29,7 +29,7 @@ static DEFINE_MUTEX(mdev_list_lock); struct device *mdev_parent_dev(struct mdev_device *mdev) { - return mdev->parent->dev; + return mdev->type->parent->dev; } EXPORT_SYMBOL(mdev_parent_dev); @@ -58,12 +58,11 @@ void mdev_release_parent(struct kref *kref) /* Caller must hold parent unreg_sem read or write lock */ static void mdev_device_remove_common(struct mdev_device *mdev) { - struct mdev_parent *parent; + struct mdev_parent *parent = mdev->type->parent; int ret; mdev_remove_sysfs_files(mdev); device_del(&mdev->dev); - parent = mdev->parent; lockdep_assert_held(&parent->unreg_sem); ret = parent->ops->remove(mdev); if (ret) @@ -212,7 +211,7 @@ static void mdev_device_release(struct device *dev) struct mdev_device *mdev = to_mdev_device(dev); /* Pairs with the get in mdev_device_create() */ - mdev_put_parent(mdev->parent); + kobject_put(&mdev->type->kobj); mutex_lock(&mdev_list_lock); list_del(&mdev->next); @@ -250,9 +249,8 @@ int mdev_device_create(struct mdev_type *type, const guid_t *uuid) mdev->dev.release = mdev_device_release; mdev->dev.groups = parent->ops->mdev_attr_groups; mdev->type = type; - mdev->parent = parent; /* Pairs with the put in mdev_device_release() */ - mdev_get_parent(parent); + kobject_get(&type->kobj); guid_copy(&mdev->uuid, uuid); list_add(&mdev->next, &mdev_list); @@ -300,7 +298,7 @@ int mdev_device_create(struct mdev_type *type, const guid_t *uuid) int mdev_device_remove(struct mdev_device *mdev) { struct mdev_device *tmp; - struct mdev_parent *parent; + struct mdev_parent *parent = mdev->type->parent; mutex_lock(&mdev_list_lock); list_for_each_entry(tmp, &mdev_list, next) { @@ -321,7 +319,6 @@ int mdev_device_remove(struct mdev_device *mdev) mdev->active = false; mutex_unlock(&mdev_list_lock); - parent = mdev->parent; /* Check if parent unregistration has started */ if (!down_read_trylock(&parent->unreg_sem)) return -ENODEV; diff --git a/drivers/vfio/mdev/vfio_mdev.c b/drivers/vfio/mdev/vfio_mdev.c index cc9507ed85a181..922729071c5a8e 100644 --- a/drivers/vfio/mdev/vfio_mdev.c +++ b/drivers/vfio/mdev/vfio_mdev.c @@ -24,7 +24,7 @@ static int vfio_mdev_open(struct vfio_device *core_vdev) { struct mdev_device *mdev = to_mdev_device(core_vdev->dev); - struct mdev_parent *parent = mdev->parent; + struct mdev_parent *parent = mdev->type->parent; int ret; @@ -44,7 +44,7 @@ static int vfio_mdev_open(struct vfio_device *core_vdev) static void vfio_mdev_release(struct vfio_device *core_vdev) { struct mdev_device *mdev = to_mdev_device(core_vdev->dev); - struct mdev_parent *parent = mdev->parent; + struct mdev_parent *parent = mdev->type->parent; if (likely(parent->ops->release)) parent->ops->release(mdev); @@ -56,7 +56,7 @@ static long vfio_mdev_unlocked_ioctl(struct vfio_device *core_vdev, unsigned int cmd, unsigned long arg) { struct mdev_device *mdev = to_mdev_device(core_vdev->dev); - struct mdev_parent *parent = mdev->parent; + struct mdev_parent *parent = mdev->type->parent; if (unlikely(!parent->ops->ioctl)) return -EINVAL; @@ -68,7 +68,7 @@ static ssize_t vfio_mdev_read(struct vfio_device *core_vdev, char __user *buf, size_t count, loff_t *ppos) { struct mdev_device *mdev = to_mdev_device(core_vdev->dev); - struct mdev_parent *parent = mdev->parent; + struct mdev_parent *parent = mdev->type->parent; if (unlikely(!parent->ops->read)) return -EINVAL; @@ -81,7 +81,7 @@ static ssize_t vfio_mdev_write(struct vfio_device *core_vdev, loff_t *ppos) { struct mdev_device *mdev = to_mdev_device(core_vdev->dev); - struct mdev_parent *parent = mdev->parent; + struct mdev_parent *parent = mdev->type->parent; if (unlikely(!parent->ops->write)) return -EINVAL; @@ -93,7 +93,7 @@ static int vfio_mdev_mmap(struct vfio_device *core_vdev, struct vm_area_struct *vma) { struct mdev_device *mdev = to_mdev_device(core_vdev->dev); - struct mdev_parent *parent = mdev->parent; + struct mdev_parent *parent = mdev->type->parent; if (unlikely(!parent->ops->mmap)) return -EINVAL; @@ -104,7 +104,7 @@ static int vfio_mdev_mmap(struct vfio_device *core_vdev, static void vfio_mdev_request(struct vfio_device *core_vdev, unsigned int count) { struct mdev_device *mdev = to_mdev_device(core_vdev->dev); - struct mdev_parent *parent = mdev->parent; + struct mdev_parent *parent = mdev->type->parent; if (parent->ops->request) parent->ops->request(mdev, count); diff --git a/include/linux/mdev.h b/include/linux/mdev.h index 349e8ac1fe3382..fb582adda28a9b 100644 --- a/include/linux/mdev.h +++ b/include/linux/mdev.h @@ -14,7 +14,6 @@ struct mdev_type; struct mdev_device { struct device dev; - struct mdev_parent *parent; guid_t uuid; void *driver_data; struct list_head next; From patchwork Tue Mar 23 17:55:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12158949 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=-16.0 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 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 8BF4AC433C1 for ; Tue, 23 Mar 2021 17:56:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 68D8C619CD for ; Tue, 23 Mar 2021 17:56:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231455AbhCWR40 (ORCPT ); Tue, 23 Mar 2021 13:56:26 -0400 Received: from mail-bn8nam12on2077.outbound.protection.outlook.com ([40.107.237.77]:36673 "EHLO NAM12-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231346AbhCWRzt (ORCPT ); Tue, 23 Mar 2021 13:55:49 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SNzg0+deYmfPwb4gcYuRRRi1s+1TD1dd8tD1uECer0hBrHB+PoU2yniYk0FiCiuPkNoadO8b7a1DlAIeDNH2t3lLcmxq9HwIGzbxrSEgw+kWtGAVPuNKGSc1ZvfwQd9AdDSSfBuTa2Zd7gKEhQdSK+0HSbPp8b0S1ELNT9QtzJBvkR/VIZpfuh2Y37/VingBWMrjABEH5plm9wWjsaV2OmfgFMo0ep0+Hmpz36M39h7Cdqt2rk4P/8KFequTHZ6MCo8DJvxShvsje8leJDRHArmx235lu6gV+1rbgU3midhK8Ay5T3eAgGQR5Wx9hmAPUVfXGxLZVidO/vWEflzyRQ== 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=U9FBnjMLFzAP/yExmLNlHOzDYDAey6bBAxCyU9pQQbA=; b=MYydW4uf6EEjK7cbSzng7iOk61NPVzx4WIkocfVRODfAS32B+8fegKe/nFZQyZ+Fa0sHU2BfU7zLv20sJ1ZtuKHqSLuFys1Gl2c6l2ARuZmfZw7mw2AyzQ33NI2IJYDsQfY8Q8Ah62MESA/E94gsEp4UPOaF3TA0gMi4E8ELGolL+VAwybMxTQ0ssGMnvDa/QiTOcQYoCgQyUwp+sP+7YzCe6lPJNWFRwwQ6meJixxmThDKS2TsojygqBjGSAKXKx43BRmvziJR3njeBLcFslw/Pz9mFQa9vnMnZYDtRSiTF3L4ovM6dI18z0ZdlYBss93wA7xAAvTJR9KkfQl9Jpg== 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=U9FBnjMLFzAP/yExmLNlHOzDYDAey6bBAxCyU9pQQbA=; b=dV5fAeF0k3AkYgc3imd8nIJQHZ7Df+KqDz2cJbdGVEjwrn0XEpgFaaw5tO78iVRqMbiKT8/BqMmCL29m8Wchblym4vajMs8ACmMauCtaBMit1Oi/w3xg3TUmasljK7TDFvGMTARosND/oS55Ib/jezsHQngGXbPh2G8oMnhwiks5ksp2g4zcSB/nS3F3vf0q2ZfB15oEDmD4EnrQuKFEF+wGgKop0v10qY8dA6YCyO/NaZARJn2EooBuJJJAcAhkjRwMkeSga68mJth//g2Ajdv6LzOYWxG/5rPOOQ69HYHHQyKhVaJZSgvJDgWGLFMklBlyB4S2WH59SEltRaB9yw== Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) by DM6PR12MB4943.namprd12.prod.outlook.com (2603:10b6:5:1bc::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3955.18; Tue, 23 Mar 2021 17:55:45 +0000 Received: from DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87]) by DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87%6]) with mapi id 15.20.3955.027; Tue, 23 Mar 2021 17:55:45 +0000 From: Jason Gunthorpe To: Alex Williamson , Cornelia Huck , kvm@vger.kernel.org, Kirti Wankhede Cc: "Raj, Ashok" , Dan Williams , Christoph Hellwig , Leon Romanovsky , Max Gurtovoy , Tarun Gupta Subject: [PATCH 11/18] vfio/mdev: Add mdev/mtype_get_type_group_id() Date: Tue, 23 Mar 2021 14:55:28 -0300 Message-Id: <11-v1-7dedf20b2b75+4f785-vfio2_jgg@nvidia.com> In-Reply-To: <0-v1-7dedf20b2b75+4f785-vfio2_jgg@nvidia.com> References: X-Originating-IP: [206.223.160.26] X-ClientProxiedBy: BLAPR03CA0009.namprd03.prod.outlook.com (2603:10b6:208:32b::14) To DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (206.223.160.26) by BLAPR03CA0009.namprd03.prod.outlook.com (2603:10b6:208:32b::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3955.18 via Frontend Transport; Tue, 23 Mar 2021 17:55:42 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lOlFf-001ch4-Kr; Tue, 23 Mar 2021 14:55:35 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 241cac25-3bfe-4334-5351-08d8ee24e035 X-MS-TrafficTypeDiagnostic: DM6PR12MB4943: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:146; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /w9MN2Xgq4xU6W6SdR5K8k+HGwSx709F42BkLmRzA+Y+8D7RxoJc9qp3PZXf8T672Koq3HB0apkZ6AysNLH7Tba1Xb+HGOFpYzO1UdMgim6dhrMmql2zttCf3Z2UYd8yJNerRBPxHyIkOxi7z6XTYVnv50JhMjSeI2OfVm2YCTYzVbnYN2y+bUBnQCifVy/1rGqawKrRZXAScM17wrntBx1FaBShjz7D5ZQerRht5oeHUS6X+rQaZOsGNGNIHr/w/+B34jpzp9GY9vkg5hcTeWww5xPs8GKsOKgiVcGrqn3kaDomZ6MrnenvU9N3gABRQxqLTFqornQ3PU9BZoXSJTcedKjVpF9X/JL/WNDlRSf4nE8+pm2I2w6iwGjk1eCNIBNuE2BvwTmUM1yt5yl/WzU5i4lV7G2g+sNFPRGXwI/xGMmfXy8KP1tIDcX/Uw2eoeKOUdBje6kDKfqYIL94Ix9yIWGCo6DHPebANsCTnJ1HhS/rYe9xMMz+FTAk3GjQkklYIrhEM5MUX5iTtIyGwCBDAlLpCsaDwjDsU/eFCFqfiB2nZfOCikm6ZpdNoAFCHSlMbffbn32tiy98PlhYObq46PDtVqeGa+a6wUdBMz16qfSuUDppnd70ufHNEUyJ6rE3D+9wSSqE0qA9JMxD8Q== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3834.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(39860400002)(136003)(376002)(366004)(346002)(66476007)(186003)(107886003)(6666004)(8936002)(110136005)(36756003)(426003)(86362001)(54906003)(83380400001)(2616005)(38100700001)(66946007)(5660300002)(478600001)(9746002)(66556008)(8676002)(4326008)(2906002)(26005)(316002)(9786002)(6636002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: pNrj5QrilV7zkBUHZ1A9P7wbkDKTCRWjAil5Va7j+KS0LSDahN7JpPLJQ3XmyVJ2hFKNZi1nZ6dOQxzojjWcMwp6UCz3blJeCuk7ntpeCTGX/t/LKM9Kmv7gJi20R6OTPfmAqd4U/XQNo7gv3XoNnKIjEMBMMlV/a+9yT7s2+PAwZwUHTuSYighijS0qkXvww5bBKtrEFn5UJpb+H9L4HJu803UYus0aMTLP/TuDZCjmtQN7RLhBmubV52AB17LUOcqxSGHS9SSbut5Z93oRatL2w6ffzF28JVWoxI4XVyzVE0jvSKcqsznRUXUFvXmKdQhk6wcVd+zZI4SZjeNlkt+6h9zuGFyBEApyaTbi3slfMPkekkkYXJANT5Km2fTpwgT8PcKl2cIqoN6SDozcQ18STdtzHlAlDQUAClX3ZMuKDeW3GdSu6VWsSSeF6y+6G+IkT9q5qmvhSKNMxaMfTdK2exxI9g2JLa4qACxRV+tSD5H42S2Ei0xrtGWBRhQ5pKT7lDKNXOjh9kWCxYJGc7i7/6sIRZxqAFqsPYhLBM9DWtaXJrmmv7qi0rHl2vpsQEIB9WA2/tvOAiD/IP3IBmB/bPFGZqGMxXBg7wJgDLPuWCf0LdNKE0hCwLiFevyOeV7HiyRvLywirjsP/31rUoBWTl+KvLIHL/zbCqGMwMDSRshLg27r8CWGUHhMuDEbQbXf41bQigPFXrUk7//jRR4Rdz4gytNg6N0i4N+Vhryq8xjIgkogmRZJyLgW5MulAZ8DiqxK9q99J+CGGB5+FN1/s/P5RHefsEcn3a2+lAIEuZ05D8MU02GtUpy+yJoibNgmPx0Bh6cRUMKc/sD4RS0A1AX6IBquY8ic8me2sVEPVe/5fuUYRhgqggQAJvhIK0tp2yPiASFAOz0b/u0XXvsjId4za9pO8gB2M4gOevmsAzkqshRnkQ7yXubeCIVP602LSvGS/PgjmS8AStaCvQ6YnGxvi8mtNNMwdWWFCYBXkxMQ/NS9MKJoYzx9vldS6Rumsj/TcP0nUMc9Nnvuaau8s068/MNd9ErPjzgFAKzCqHs1b86iVUzey2lo4uem14ZoOHBwbEuupDSlhp4tzwafvHQSpmKS+yBC8tk2ChokH0CXw1NNcw2r+Y2pumg/S5g+czf9ks1p4fr1q/z/BR+t+JrcmCYtTXRvYVJqEzPiPMKzd8wp2exfUlYTa6+XspU08yBrivcdPpvjHw13luhlCOdx/faIBSG2jgldgt3yVmoi55n0e7pwQLYJ2Ze7G0zgeqmFuZUDIhy86X6LMLkL0f22uqJuByBWv1NJo7lm8MhiNkbiHuOZt+K7jYCO X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 241cac25-3bfe-4334-5351-08d8ee24e035 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2021 17:55:42.2458 (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: Fo/pI1puB5VYVvbJyPAHgQ1qMuEkTDRi4c10XoO/oA32VYX4gZSPDYFnpzAPH+Ip X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4943 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This returns the index in the supported_type_groups array that is associated with the mdev_type attached to the struct mdev_device or its containing struct kobject. Each mdev_device can be spawned from exactly one mdev_type, which in turn originates from exactly one supported_type_group. Drivers are using weird string calculations to try and get back to this index, providing a direct access to the index removes a bunch of wonky driver code. mdev_type->group can be deleted as the group is obtained using the type_group_id. Signed-off-by: Jason Gunthorpe Reviewed-by: Christoph Hellwig Reviewed-by: Kevin Tian Reviewed-by: Cornelia Huck --- drivers/vfio/mdev/mdev_core.c | 20 ++++++++++++++++++++ drivers/vfio/mdev/mdev_private.h | 2 +- drivers/vfio/mdev/mdev_sysfs.c | 15 +++++++++------ include/linux/mdev.h | 3 +++ 4 files changed, 33 insertions(+), 7 deletions(-) diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c index 493df3da451339..3ba5e9464b4d20 100644 --- a/drivers/vfio/mdev/mdev_core.c +++ b/drivers/vfio/mdev/mdev_core.c @@ -33,6 +33,26 @@ struct device *mdev_parent_dev(struct mdev_device *mdev) } EXPORT_SYMBOL(mdev_parent_dev); +/* + * Return the index in supported_type_groups that this mdev_device was created + * from. + */ +unsigned int mdev_get_type_group_id(struct mdev_device *mdev) +{ + return mdev->type->type_group_id; +} +EXPORT_SYMBOL(mdev_get_type_group_id); + +/* + * Used in mdev_type_attribute sysfs functions to return the index in the + * supported_type_groups that the sysfs is called from. + */ +unsigned int mtype_get_type_group_id(struct kobject *mtype_kobj) +{ + return container_of(mtype_kobj, struct mdev_type, kobj)->type_group_id; +} +EXPORT_SYMBOL(mtype_get_type_group_id); + /* Should be called holding parent_list_lock */ static struct mdev_parent *__find_parent_device(struct device *dev) { diff --git a/drivers/vfio/mdev/mdev_private.h b/drivers/vfio/mdev/mdev_private.h index 10eccc35782c4d..a656cfe0346c33 100644 --- a/drivers/vfio/mdev/mdev_private.h +++ b/drivers/vfio/mdev/mdev_private.h @@ -29,7 +29,7 @@ struct mdev_type { struct kobject *devices_kobj; struct mdev_parent *parent; struct list_head next; - struct attribute_group *group; + unsigned int type_group_id; }; #define to_mdev_type_attr(_attr) \ diff --git a/drivers/vfio/mdev/mdev_sysfs.c b/drivers/vfio/mdev/mdev_sysfs.c index d43775bd0ba340..91ecccdc2f2ec6 100644 --- a/drivers/vfio/mdev/mdev_sysfs.c +++ b/drivers/vfio/mdev/mdev_sysfs.c @@ -92,9 +92,11 @@ static struct kobj_type mdev_type_ktype = { }; static struct mdev_type *add_mdev_supported_type(struct mdev_parent *parent, - struct attribute_group *group) + unsigned int type_group_id) { struct mdev_type *type; + struct attribute_group *group = + parent->ops->supported_type_groups[type_group_id]; int ret; if (!group->name) { @@ -110,6 +112,7 @@ static struct mdev_type *add_mdev_supported_type(struct mdev_parent *parent, type->parent = parent; /* Pairs with the put in mdev_type_release() */ mdev_get_parent(parent); + type->type_group_id = type_group_id; ret = kobject_init_and_add(&type->kobj, &mdev_type_ktype, NULL, "%s-%s", dev_driver_string(parent->dev), @@ -135,8 +138,6 @@ static struct mdev_type *add_mdev_supported_type(struct mdev_parent *parent, ret = -ENOMEM; goto attrs_failed; } - - type->group = group; return type; attrs_failed: @@ -151,8 +152,11 @@ static struct mdev_type *add_mdev_supported_type(struct mdev_parent *parent, static void remove_mdev_supported_type(struct mdev_type *type) { + struct attribute_group *group = + type->parent->ops->supported_type_groups[type->type_group_id]; + sysfs_remove_files(&type->kobj, - (const struct attribute **)type->group->attrs); + (const struct attribute **)group->attrs); kobject_put(type->devices_kobj); sysfs_remove_file(&type->kobj, &mdev_type_attr_create.attr); kobject_del(&type->kobj); @@ -166,8 +170,7 @@ static int add_mdev_supported_type_groups(struct mdev_parent *parent) for (i = 0; parent->ops->supported_type_groups[i]; i++) { struct mdev_type *type; - type = add_mdev_supported_type(parent, - parent->ops->supported_type_groups[i]); + type = add_mdev_supported_type(parent, i); if (IS_ERR(type)) { struct mdev_type *ltype, *tmp; diff --git a/include/linux/mdev.h b/include/linux/mdev.h index fb582adda28a9b..41e91936522394 100644 --- a/include/linux/mdev.h +++ b/include/linux/mdev.h @@ -46,6 +46,9 @@ static inline struct device *mdev_get_iommu_device(struct mdev_device *mdev) return mdev->iommu_device; } +unsigned int mdev_get_type_group_id(struct mdev_device *mdev); +unsigned int mtype_get_type_group_id(struct kobject *mtype_kobj); + /** * struct mdev_parent_ops - Structure to be registered for each parent device to * register the device to mdev module. From patchwork Tue Mar 23 17:55:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12158943 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=-16.0 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 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 6BA9AC43445 for ; Tue, 23 Mar 2021 17:56:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 56457619CC for ; Tue, 23 Mar 2021 17:56:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231449AbhCWR4Z (ORCPT ); Tue, 23 Mar 2021 13:56:25 -0400 Received: from mail-bn8nam12on2077.outbound.protection.outlook.com ([40.107.237.77]:36673 "EHLO NAM12-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231344AbhCWRzs (ORCPT ); Tue, 23 Mar 2021 13:55:48 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IeAtgEGMNKgao8LCsLj2kC6rLGk7+AWYl8hifFrGqx6oKnuRfpdFif6Yo6vd2Qc+YsG9HSXAptRddHEnV3M+YMOjj7Rx6D/dFQjwqADqRuwi/AuUEPpjVo3pnfRk7vg2ASW8QivvrfryJkx/I3qH8WAK5URlSw+HxKsXxdyrwcHkwEdjXFLzQ4EDK63qDIDuE5Qofgl6etcSdoWoUBW0IEjxuDAZkZZxne9ve24zPzcn7kYlDRF9gGA5tX/7URsHcvpb0w/TaXMjxfifNk5xju7q14yDqRAgXwneZEl83If9RkHxMlF1qnNt2wqtfIkyeasiVTcGQG1SQZF+7LnFpA== 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=Tkys9WcGQ4F+7Lx5xg8CqqbE0vhRjctcm0xqW+9IFTs=; b=BbUQIKkF1J6j4i1Icn9ss1v21DIevSgT5OBsfKejZotKm6XPnYVh64e43r+SUIem3OjA7y+BLW12Jp3IEDpEeLPzjpPTP2fFfWpJ/j/pFK3BWDu6lVdkjMh/c45N+6evLT55v2aALCFHGmJrZ1V86PkTeiqX9+mnsDSWLkNeVasI7pwWuCk/yyeAaizyFmnNaO1wMIKJDcfKxi0XAWc/cbwfHvMo0ULS4ShrNX4D81rn8+nc80nldyRg4d7JZPwAp1tfqi+tNUQ854rkoG73LsDLp7GcFJWziEdp4tHbozTONdYvHvIkfvQ9V6xH7ZoF8xPLZ2LBh0itZ98iD3X7bg== 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=Tkys9WcGQ4F+7Lx5xg8CqqbE0vhRjctcm0xqW+9IFTs=; b=sFnnUxmBrlMWX7/eTdAcQ7b4WrVkqqF0b+4hZZoyONzyPCX9IcyuPhKfJtFFjddsHDPIaBgLDcddLgWw1Cd6x4X+NbWFsZ9ZyTdAe6EyXR4T2Mtb63GewC+p+zwvq4BDVCTybk38b3SySVsXluGGR9hFZHP5uUxuigGZfXwV+2d8BhfrWiEdobegN10J9hWEm5MARgvOVJq1N+L9pfGOJptRUS+RPr3MGAUlNFt8MR1HNCidq2l9cZBvgQp8i2NpMOxQ9hqrR5sTFRQHpjFGLZaLOoEF5L/6SbwpeC+4Wyaew+PUVB24/d96KP1BBSpR8GTW/6/rDxnHzEnK2f4vqw== 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 DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) by DM6PR12MB4943.namprd12.prod.outlook.com (2603:10b6:5:1bc::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3955.18; Tue, 23 Mar 2021 17:55:45 +0000 Received: from DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87]) by DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87%6]) with mapi id 15.20.3955.027; Tue, 23 Mar 2021 17:55:45 +0000 From: Jason Gunthorpe To: kvm@vger.kernel.org, Kirti Wankhede Cc: "Raj, Ashok" , Dan Williams , Christoph Hellwig , Leon Romanovsky , Max Gurtovoy , Tarun Gupta Subject: [PATCH 12/18] vfio/mtty: Use mdev_get_type_group_id() Date: Tue, 23 Mar 2021 14:55:29 -0300 Message-Id: <12-v1-7dedf20b2b75+4f785-vfio2_jgg@nvidia.com> In-Reply-To: <0-v1-7dedf20b2b75+4f785-vfio2_jgg@nvidia.com> References: X-Originating-IP: [206.223.160.26] X-ClientProxiedBy: BL0PR0102CA0029.prod.exchangelabs.com (2603:10b6:207:18::42) To DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (206.223.160.26) by BL0PR0102CA0029.prod.exchangelabs.com (2603:10b6:207:18::42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3955.18 via Frontend Transport; Tue, 23 Mar 2021 17:55:41 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lOlFf-001ch8-Lt; Tue, 23 Mar 2021 14:55:35 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9af3552b-7214-450f-f1a3-08d8ee24e011 X-MS-TrafficTypeDiagnostic: DM6PR12MB4943: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:298; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: q9WcALfC8p/Sydg7/xK7THkVUqZtpz0Hm8ObVLf0AOjLtWJkDCJW90kOggkJnnc59ansHhLQHISIgtLku55vreIisLmUdM54iA/VXh29W2+xl5ifOWZvqGGNpXrKUOOcoMKAXmiMau1McbgTKi5T6GOvCebDtPIWILg9L57lgePQXashCmG6+waqRcAajHjfTiNZWNYeHlgcRZB2gCcJDX2KFTiaAuO3KS1SrMCPIJFfGYbHBhRaWHMBpWL3UtYAJIy5QPIXYWdF6SDiJMn8bJUtCW6dAgOFClqEtSx9ZB1DwQKTUQIVfSABFlgJv+1IoZ4rSvPVf7gd/NXo1VkhgYFA26puU+yNSX9ZecIe/6flA7dA4HjYy8j4OQHDy7ZzanDS6h1iS6qiV+e8kcDj78haZne1LchbcfFqbZRy7WM2eopIsGSyqElvLC0ZJazvl09fI+SUplxn1CiK6icWqThUs3Aq+lAbHqBpM1z5LnGddd8Ip/k7lli8LWGMSdOBJ/r5nj/ien/uVLm7AAiUF06nXPiRsyV+zEN6NOQ85I5BSWmhvcH3qFgNQUURk9ldpdvYy98prrF8FOYCUJXCgCJUy3UuQEULEXr4pi0dgNZ3St8g4Jp1wan7sWXVNOQp/EY2RsFsXse5r5lQGMprfQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3834.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(39860400002)(136003)(376002)(366004)(346002)(37006003)(66476007)(186003)(107886003)(6666004)(8936002)(36756003)(426003)(86362001)(54906003)(83380400001)(2616005)(38100700001)(66946007)(5660300002)(478600001)(9746002)(6862004)(66556008)(8676002)(4326008)(2906002)(26005)(316002)(9786002)(6636002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: rKL57SxSxuqMkyzI07CaBnTI9vNuR/HQKPL4vZHPtdU4UuYyrtklMM+kQTVj/jR3x2PgRHn8CMEmX1FOBIG/fmFoUuxQNK3E/F+lkHT/Zi1np71kDTDGc6gYONsDxL4SeHH4tYmiLQDc5ZbxwiuXJ5AqI5r8qjwlQL+OuNNjPeBhkBNnPaTgT3MIsL86/NZUrAy++X9GrHGg0waFDLG3OpcGmA+dqJFwwqZl1TudChMsQo0q4ciQ3F9AXocDVz7B7uI+RaMwpCwxm2sO2cV9nVpG4AYXkXKUiwod+cQASmH5NyZk0T9g8yzRty81mEYzrZ4NL0lBz0zCB4+ywtUGWL9dwE/6wEElgg3wE81/+5OL1WCHifZRQfvOnf7Dzg1/89al31g0pcOucBIathPWri+fE4XRI1q4vHKHCzB1MfRXAkAouSMW6O5Tb8Lv75Qb9G4M76iKSIu6q2fw6A9TTDRLF3yyrvls20zq4s7wJgo7pD5Nsy3m0hV2ymby58TuIKcHItx79hsudD39sigeT1bc3PpGf/VJ8sDZPmG6MmXm2RklhGiugJfXipQdxbplyVl9+0UQPSjIPFYEqHok+BAQDP02+hxvC259vcHxI5/anVHsKeC/f+jGJFC7spBBp2+p4b+k5MGBNH0vrcwur+uP318mpY4ynZaYXqpRrLBqV9CwiqczIx4ydVD2yQwmXxGLI+y/vPqWbj8MKVP/lYDEEETUTphujucIW1hkaQ73gNGAyR91iZ99VMR8vjtwmqM5fTpVLJ6Y6xUTfHvrY3bm+XQ9bvNz1E9sKVuyEk3U617ZR8gWyuRcc1YY+vPlTtOX6Ozr7MsAP+jsMuAxbOP7ldW1F9CmfO2Upk4CrrVcrGqRY75f+K7c5ZHyDrLapIE8xnRaNFL0qCtLAVUVb5jtXs467yZJSd8KUaQ52v20VEo708OuEA+X/KJBXSe27SeY0ObJeBq3IUzo2QikYEfkq+0lwNmGMxAEh6yDPob4Nr9fey/8of91anNR+YoK1RhqV3Q0/Iehr9Q54YdfI3Wfy4lkVXxPxoNlFVA/Olk2BFvP6W7C6/4V3R+tFLeleqoOdk8xbg618as9nwkji1i8zicEeH5jHNU5x2yBtABSAFW9WDGwsTxk3VqBGSMaQZIZk9WOdAxBYfPSyqCO8E+4EGCQiF3JXhzxB57bnGVP/nln2JU6HO8wElQNJzTVzE8FBgrMUw0d8DLll479q16ooqI8ZSqrJthYqpKsjK+MUIrK8EANHy9zBG5rkuPeXbL51w57xZKOs3hGn0IDKSs/ZGDk6jRdp3Ae5cAg8wd6/fNYPXZ6C9BCFYtcsHkK X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9af3552b-7214-450f-f1a3-08d8ee24e011 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2021 17:55:42.0599 (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: gSnrNiTlaUFkZl/3ESUAlqKlauInMyAPQ2YoQN+OJUblZMRlo6+IrTyejBXn+snY X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4943 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The type_group_id directly gives the single or dual port index, no need for string searching. Signed-off-by: Jason Gunthorpe Reviewed-by: Christoph Hellwig --- samples/vfio-mdev/mtty.c | 50 ++++++---------------------------------- 1 file changed, 7 insertions(+), 43 deletions(-) diff --git a/samples/vfio-mdev/mtty.c b/samples/vfio-mdev/mtty.c index ce84a300a4dafd..191a587a8d5ab1 100644 --- a/samples/vfio-mdev/mtty.c +++ b/samples/vfio-mdev/mtty.c @@ -711,23 +711,7 @@ static ssize_t mdev_access(struct mdev_device *mdev, u8 *buf, size_t count, static int mtty_create(struct kobject *kobj, struct mdev_device *mdev) { struct mdev_state *mdev_state; - char name[MTTY_STRING_LEN]; - int nr_ports = 0, i; - - if (!mdev) - return -EINVAL; - - for (i = 0; i < 2; i++) { - snprintf(name, MTTY_STRING_LEN, "%s-%d", - dev_driver_string(mdev_parent_dev(mdev)), i + 1); - if (!strcmp(kobj->name, name)) { - nr_ports = i + 1; - break; - } - } - - if (!nr_ports) - return -EINVAL; + int nr_ports = mdev_get_type_group_id(mdev) + 1; mdev_state = kzalloc(sizeof(struct mdev_state), GFP_KERNEL); if (mdev_state == NULL) @@ -1311,18 +1295,11 @@ static const struct attribute_group *mdev_dev_groups[] = { static ssize_t name_show(struct kobject *kobj, struct device *dev, char *buf) { - char name[MTTY_STRING_LEN]; - int i; - const char *name_str[2] = {"Single port serial", "Dual port serial"}; + static const char *name_str[2] = { "Single port serial", + "Dual port serial" }; - for (i = 0; i < 2; i++) { - snprintf(name, MTTY_STRING_LEN, "%s-%d", - dev_driver_string(dev), i + 1); - if (!strcmp(kobj->name, name)) - return sprintf(buf, "%s\n", name_str[i]); - } - - return -EINVAL; + return sysfs_emit(buf, "%s\n", + name_str[mtype_get_type_group_id(kobj)]); } static MDEV_TYPE_ATTR_RO(name); @@ -1330,22 +1307,9 @@ static MDEV_TYPE_ATTR_RO(name); static ssize_t available_instances_show(struct kobject *kobj, struct device *dev, char *buf) { - char name[MTTY_STRING_LEN]; - int i; struct mdev_state *mds; - int ports = 0, used = 0; - - for (i = 0; i < 2; i++) { - snprintf(name, MTTY_STRING_LEN, "%s-%d", - dev_driver_string(dev), i + 1); - if (!strcmp(kobj->name, name)) { - ports = i + 1; - break; - } - } - - if (!ports) - return -EINVAL; + unsigned int ports = mtype_get_type_group_id(kobj) + 1; + int used = 0; list_for_each_entry(mds, &mdev_devices_list, next) used += mds->nr_ports; From patchwork Tue Mar 23 17:55:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12158931 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=-16.0 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 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 A022DC433E9 for ; Tue, 23 Mar 2021 17:56:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5A049619D7 for ; Tue, 23 Mar 2021 17:56:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231372AbhCWR4K (ORCPT ); Tue, 23 Mar 2021 13:56:10 -0400 Received: from mail-dm6nam12on2064.outbound.protection.outlook.com ([40.107.243.64]:33344 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231233AbhCWRzl (ORCPT ); Tue, 23 Mar 2021 13:55:41 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lPcqXLo5mSFiSqY5RXix6njmklYfm7wuCE4HTIpyp4BJRmQJ1Gd7EZrmMhj1BrdIV7vur8hq5jkeneg6j6+JhdCb9pdBCmdEH3p+W9SyqO5V3AvORJ3iuXXsREwfbGaPz8lUQI7vt7KV0/bqupJJaFZ8ezDqpNlqArwC/JqYttcWjEaPt+cspUx8eKE3ZDnkljG1PxSl9MalvjGVMZF+46cObUFPB8i9rdd1RPRER4NdtSwr/4sYoPd7YrFWa91vceQ8loyFS+OCStUzyNft40oVKxwj0szFi923DiZGQynONy48w7XCMdwZLpCr0p+qR/C2wWMEBHYS1cN9WSzl8A== 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=+dG+ZJxYRtxo+uI1CX4c3eqjEmj+WO7rw943voWo+Wc=; b=U6CxoX3YjKTBBHthOu+WYvqpPuLLTO134bGDjd2qES8nIYKXgyHPqEsnNBXF7qQj1iU9gmQTdcGoVU89E3QCJ2EEJ0qCyzJM7bd/87+RFEpl605C3DP/JU1gTd3xdU5CZ08ikqD2hEwmwKwht4toN1akKvDsTHthACqOiCQFX21a5M2ydbP71khd6KETfYKWk8QxmAi95S2MUwefJo0JW7x1/v3Aoik/lSja9TCked1jCqSf47oPaHFtpL/RpcDx8TPAFKMHxPG+9JS4I+04nnUqjDxi1U3iXWat+PhJLtiHwsXbsF5WaEHKCE67a7QIAerZ36TKuqrnP4+8Swr51A== 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=+dG+ZJxYRtxo+uI1CX4c3eqjEmj+WO7rw943voWo+Wc=; b=UjxCey+4zQFnD+aefvwSay4SjXKVMLV51Rv8cbszzNeVBWc2+tYZ6tthh+3Ap68jg/q37vKjedIh2r+GkaO4YzIRlxsbwQm1cGp9svPHEdPyTgyKkknoUWrAIel+H4+rGX6jARMlQo3IZq9G37q2scHSLoyx5OEHSD6LUI9f2iFFmW0EemLS53taZnf1ozirrZaz7Gxl46Z5L7Q510rFdC4oh3QmGFW/KLNbklxFZK8UNiqorL1BQAYeJH45mh1y4eilvAUlcYpq/7XPFj2uegO8p1MGgfHBk5esTVH7B/cIxOb71VobMqsKA4JAaCmT/lFzcmcrl89rFbYo9xBAnA== 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 DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) by DM6PR12MB4483.namprd12.prod.outlook.com (2603:10b6:5:2a2::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3955.25; Tue, 23 Mar 2021 17:55:40 +0000 Received: from DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87]) by DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87%6]) with mapi id 15.20.3955.027; Tue, 23 Mar 2021 17:55:40 +0000 From: Jason Gunthorpe To: kvm@vger.kernel.org, Kirti Wankhede Cc: "Raj, Ashok" , Dan Williams , Christoph Hellwig , Leon Romanovsky , Max Gurtovoy , Tarun Gupta Subject: [PATCH 13/18] vfio/mdpy: Use mdev_get_type_group_id() Date: Tue, 23 Mar 2021 14:55:30 -0300 Message-Id: <13-v1-7dedf20b2b75+4f785-vfio2_jgg@nvidia.com> In-Reply-To: <0-v1-7dedf20b2b75+4f785-vfio2_jgg@nvidia.com> References: X-Originating-IP: [206.223.160.26] X-ClientProxiedBy: BL1PR13CA0196.namprd13.prod.outlook.com (2603:10b6:208:2be::21) To DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (206.223.160.26) by BL1PR13CA0196.namprd13.prod.outlook.com (2603:10b6:208:2be::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.22 via Frontend Transport; Tue, 23 Mar 2021 17:55:38 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lOlFf-001chD-Mr; Tue, 23 Mar 2021 14:55:35 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c37309dd-badc-42c4-cf5d-08d8ee24de13 X-MS-TrafficTypeDiagnostic: DM6PR12MB4483: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:446; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: k55bfNtl/VpJCggpP2c1PZMw4NNQmTT8QsIB/aMs3E2c4Rx6BCpQcrZn+KMUgnwY6UjMrKzw+iQPz2LGse+euftAkf/QnkotjLTSpG6IQeLJ7v23NUvjl/48IuHfddaCtk4Mxypv66IWvWl98QhLpS6UOJskmaU4vh8YSmu6Ta/1CgpUuv2nhVVNyuRLa37ApKV+7DKy9qsQIGLPnZ2si8wC1eAaivfvH+WQ7nryqbtAuzSLNwKzW7VB7x5p6qSF8Utfagi77kMmO/i12zdEr7NDVpEz6T8Zd7P4RlhSJr0HpGxmeSsiCp00x0Die/NrpYDSt4DZeG9cbALWIPxaAKI/U04naCP6FNAycQzH92iP0Gk2y+JHlpTErvECgLmvRpPDGQgzMUGQ2S0POWTQMOEc+Nd6AYdXI4TZXXM+SwZCdbQStrkaTFSVzOl4G+s89KQY7W4/33WfdjCSAkzIOKkWyytN+Vt79p7+U2xjlwTtt6jOsOEsZswLxsK7/clwzG5dysxWtMZ2C86ZwuHI2+oXGdpARh/qBOjfv9HeCmix0yhsfMBu7fMVJQaO7j8VgSednAxw9rXeDY/yOwU4If8Nm1k7tlwg5oUPCQ06p6ymkOzzJbWmlPUCUqTt+bcn2WXGVBt/8r7nEf0dhSFIw2grftTlsurbobpFNimGScg= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3834.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(366004)(39860400002)(136003)(396003)(346002)(186003)(26005)(36756003)(37006003)(5660300002)(38100700001)(66946007)(4326008)(66476007)(6666004)(2906002)(66556008)(54906003)(6636002)(478600001)(86362001)(316002)(8936002)(426003)(9746002)(6862004)(9786002)(107886003)(8676002)(2616005)(83380400001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: ljG2fpKxOD6qGT4u1gjEKuC3YquesfIhLSMsJD9uHErW+8c35AYM9AL7K85LB7db8ufg7eM7vO3RjX6Wgx9wSp1lUtbNXrozANfaCb1ZyRjpXNYxCDEtsLa9cjSBVSfOwNkEertvaeosK5EuzqAkp9KLqcSUkgkWnylY2uUnc7yxYD7+GSgZDGAxVIxMs7AI4JAsGDJ0p/nEeeu/JwiuSqyyR+cIjthor+/LT0PMrwGbsQt1vuBNIiFziiR9ZkI0JF0q4jxPLWwGAPiLdeFHyU20vvYfjyMrzwoS9+pOLkYDu9ITgNhXX/F5r4ik3D/8steqDMS1kJBy/xhEihmHSlunMxMQoVA+xY8PJegpj4pd0kYXKZVaEmqUfa+HLo/VM+9+aEp1KIv88yk+Z1+AXRhInPmSxqF3HzHhdZPUeTnbg8EsRDUTPsWF36yz1hVVajFinf/v/hjDH/p5ty0qtKnUDChQtONyVSxtwSh5XJ3jFFHVHt3PBmVjW0lXLaLlc1PdAL/jz3ie7f08v+1rgpXPvFXaFyCwQ1lGkHJLeDnIDZDotNickyGroska0rILUb49Ly+zhvml27Ysij8PnqBshhIutgkQiI/xbV8IIrEFN+pNiYNWlBVB45mR5YjDlQI6UmQYRUDeZarpEREoySSJDtrbE/yO7kosATQceD57Cp41ixy+H0RRYDQrIxPlQeGIm00i4/2lSKNj9gVlDJgDoJxFi5FX6bji9qsaBJlnl01iP6JHvcKSQnGi4Knz/jm2I9gLNcVmFslPuaz8dzV0yW2ssteOEKyzLK8cPb1V3E+raw6rFK+gSbg+py23VJ/Y+yT3/K8ScQfdzGI10CenXLcibNQMaqUZi68/FHN4zbab26t08sZlcYjNtoWfu2RVsYD+xnLai1Iw0uNqBB3cPl1yxOiYswYrNz6dNGMl3mgHdSkPKF1fSNVDUgPkw+dbk66Dp6HFxKi5kZNyqGxFA9Uh7kskrLe5Oj28K+Kt7ahGUbAt+augCgxUU3ZcG1TUvh6bhc17MJxuy0YFLq6QuWjwh+zeD+1iyHvM05SxbZS4ULIqlnOFhmNXCMZ45CiGP17Klg3bplh96jRMIaQURqQKCja3l7+qm9zVMYUHUmsVob+Z8aPrP6R7+QdLWivw8WrwL/dVRTzpJxQgbmKHJK6UNPBLinv1ZiAW+dFbQ90lRiaZ4lZRLofvondzJf0sE/+3Uhpg9mbNAdyGNqiv85FI+2Ychq5SKzSG5EgGlSNkRFOKMJwAZZOa0luY8obgJAgIVHi/OIqzTYrO/t5IFfy3cl6iZfKIiMHuGQvXzggGMzbB39d2ebH4RRfS X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: c37309dd-badc-42c4-cf5d-08d8ee24de13 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2021 17:55:38.7877 (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: vu1KhjNPFpKBTcACtBggEKNlWZzYHQTMKXwfUiTu+6G74Gum9RpyQybFO93IOMOp X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4483 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The mdpy_types array is parallel to the supported_type_groups array, so the type_group_id indexes both. Instead of doing string searching just directly index with type_group_id in all places. Signed-off-by: Jason Gunthorpe Reviewed-by: Christoph Hellwig --- samples/vfio-mdev/mdpy.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/samples/vfio-mdev/mdpy.c b/samples/vfio-mdev/mdpy.c index d4ec2b52ca49a1..08c15f9f06a880 100644 --- a/samples/vfio-mdev/mdpy.c +++ b/samples/vfio-mdev/mdpy.c @@ -99,16 +99,6 @@ struct mdev_state { void *memblk; }; -static const struct mdpy_type *mdpy_find_type(struct kobject *kobj) -{ - int i; - - for (i = 0; i < ARRAY_SIZE(mdpy_types); i++) - if (strcmp(mdpy_types[i].name, kobj->name) == 0) - return mdpy_types + i; - return NULL; -} - static void mdpy_create_config_space(struct mdev_state *mdev_state) { STORE_LE16((u16 *) &mdev_state->vconfig[PCI_VENDOR_ID], @@ -228,7 +218,8 @@ static int mdpy_reset(struct mdev_device *mdev) static int mdpy_create(struct kobject *kobj, struct mdev_device *mdev) { - const struct mdpy_type *type = mdpy_find_type(kobj); + 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; @@ -246,8 +237,6 @@ static int mdpy_create(struct kobject *kobj, struct mdev_device *mdev) return -ENOMEM; } - if (!type) - type = &mdpy_types[0]; fbsize = roundup_pow_of_two(type->width * type->height * type->bytepp); mdev_state->memblk = vmalloc_user(fbsize); @@ -256,8 +245,8 @@ static int mdpy_create(struct kobject *kobj, struct mdev_device *mdev) kfree(mdev_state); return -ENOMEM; } - dev_info(dev, "%s: %s (%dx%d)\n", - __func__, kobj->name, type->width, type->height); + dev_info(dev, "%s: %s (%dx%d)\n", __func__, type->name, type->width, + type->height); mutex_init(&mdev_state->ops_lock); mdev_state->mdev = mdev; @@ -673,7 +662,8 @@ static MDEV_TYPE_ATTR_RO(name); static ssize_t description_show(struct kobject *kobj, struct device *dev, char *buf) { - const struct mdpy_type *type = mdpy_find_type(kobj); + const struct mdpy_type *type = + &mdpy_types[mtype_get_type_group_id(kobj)]; return sprintf(buf, "virtual display, %dx%d framebuffer\n", type ? type->width : 0, From patchwork Tue Mar 23 17:55:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12158953 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=-16.0 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 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 C7B54C433ED for ; Tue, 23 Mar 2021 17:56:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B5704619AE for ; Tue, 23 Mar 2021 17:56:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231400AbhCWR4P (ORCPT ); Tue, 23 Mar 2021 13:56:15 -0400 Received: from mail-bn8nam12on2077.outbound.protection.outlook.com ([40.107.237.77]:36673 "EHLO NAM12-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231289AbhCWRzn (ORCPT ); Tue, 23 Mar 2021 13:55:43 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Aen986qm/mKOyEs+xrwTELOcTEUxcYIlfx7vxoFVIy+R9B6U0an9bPKyHD7DFTx7uEjr0kx8zYxEd5bBGugEI2c2nURJLT/ZOI+pciJ9Mbz1UsgI8GLt4BfGo1vUy9hTlgcRTb5m7jLMy1V0g2bSltT8vShQoRqWqI6fLksuTV9aWTGAekinPTq6MnFws7cNATZxSbC0bjyjEoxpsba61RE0moT0LgENN4YdpFFH4BisIFLCwOhMJRIyElmELO0EPi4SV1hUjHaDGdOk1UAS/f8o8G72P8blPlfQ9kZ4zxwiqME6RIY9hvzQmaOTw+BVlb72Si63QB39UaY2Jus8Hg== 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=HixjnyqaX6yVAxduJa8LIeWJcCZOnXIo9+8W1iRdeaI=; b=Fckra1BMybYXWYNTr82q4ifUABVaZe0OVsJ4pIL/WMqAYALnf475EjjigXlDQqmHWhjdm29iZ8cYVpdWApVo/bJ393f6i77ds23FgR0oMSPsFzMxspjerDj+rwlkCJXAgge7ysfmK3QjnyL87D10vnAm87jpp6tW5Zr81VIkr4ObEWsM8H6zLSTVWxrQtdBGEjPJIcB3gAPd5ubIgaFNZIfjr2CwdrlVtlJuZALUnQWsNB4+Cikxmkkxn7maP3C4uYuQjtYNGYQcaW6d2RLpXQiunrMKBx/OQ7VbHWJSJ3JQk6kB+YbJjIUh/7wz8OACMyFeFcskYhCazPuM3zhvuA== 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=HixjnyqaX6yVAxduJa8LIeWJcCZOnXIo9+8W1iRdeaI=; b=ljtjnF+HtyqXFAq13qSDYp+dLll3gAxvCjBPR9eMe5iOJdHBhCKnYREHEzMeOX+H9oN9Z7mMjWCSrx+27KLzJ2fbVs+Pmz5qofugfebBOGAPcUr/ADeo2pHzLqiloKGbLqs8l84aO3reEaVDlz7cmsIBKMsl1WpFR9MmObO6x1jKRd3Ro7powegmRux8nYxca7UB1OngYYxM4TE5xQAFg0PEPs/h4NG7I5/S5LnBmTTQuIFyYGdXwmORiDDfbLgdSOhaMx1gCosqQdDtczQl1QNETxLv45pvlaPpYxHLLPBicfkEykNcKC8pLCO0acdKDTQYlbN4ICICYF1PzhKv6g== 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 DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) by DM6PR12MB4943.namprd12.prod.outlook.com (2603:10b6:5:1bc::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3955.18; Tue, 23 Mar 2021 17:55:42 +0000 Received: from DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87]) by DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87%6]) with mapi id 15.20.3955.027; Tue, 23 Mar 2021 17:55:42 +0000 From: Jason Gunthorpe To: kvm@vger.kernel.org, Kirti Wankhede Cc: "Raj, Ashok" , Dan Williams , Christoph Hellwig , Leon Romanovsky , Max Gurtovoy , Tarun Gupta Subject: [PATCH 14/18] vfio/mbochs: Use mdev_get_type_group_id() Date: Tue, 23 Mar 2021 14:55:31 -0300 Message-Id: <14-v1-7dedf20b2b75+4f785-vfio2_jgg@nvidia.com> In-Reply-To: <0-v1-7dedf20b2b75+4f785-vfio2_jgg@nvidia.com> References: X-Originating-IP: [206.223.160.26] X-ClientProxiedBy: BL1PR13CA0188.namprd13.prod.outlook.com (2603:10b6:208:2be::13) To DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (206.223.160.26) by BL1PR13CA0188.namprd13.prod.outlook.com (2603:10b6:208:2be::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.10 via Frontend Transport; Tue, 23 Mar 2021 17:55:39 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lOlFf-001chG-Nn; Tue, 23 Mar 2021 14:55:35 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a4fef12f-07cd-4541-0517-08d8ee24de88 X-MS-TrafficTypeDiagnostic: DM6PR12MB4943: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:446; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 69NXHs7RazqQfzPDh2hTDIYFPN4bUUUxxZpTHWNgQcFRNTCUUyKJr7jcO1qafsEHcvd/cJiwO7ucGtIbjaji2UKfmafEm+5ljjcz9KhyIkIrd1eKUeMYBS67LLB7H0CIDyxKz8UELPmIWEvZnRAU2Tag3eWyc7DTkifSuoiOQECI6mSSqEZLv+Si9WbrtIkzTrMEPZstpbmHLATCX/AClYw8mn5C8x/ESSU9YOwN1jaSouNMkc2n9/xkbE96LF72baxOVPSmo/0W3mZCkcA0cEIDUqcEvj/ilU3HJuUP+pCQ4+2vTjXtak/h6vloT11TOGhH+YX01xR7IbaKFFvG+Yf99zTKZl7MqecSf1szv7YZSss9RHn3I6U8A3q0ICJFXzfYT2Vr+wrLTJtC5ECvjCKPNgiY+9GAonXAqVNRxyfbKy6jiw13mCxZOux2HWI/EA9G7hhdyKblyk+hadR1TQ5n+iUdVx37azI3H1RGo2Og1pG3S5Fl0Uwu3lpHBIdbKvJqsuFgkmdu4nxLmhA7B8ckgdQ+jiLv/2bQ1A7OfEDa2YiJG5OajWO6gnfwKiRdD/MkQdwTK2ExFaypxfl3kRi5lFukzuxtRqj9toeOEqC0U4+7aBB6Tzp7m1egow5r34Ezy+rnTfpfCmIwvRZUMVBTe83Oarw45RaXk1wVaio= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3834.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(39860400002)(136003)(376002)(366004)(346002)(37006003)(66476007)(186003)(107886003)(6666004)(8936002)(36756003)(426003)(86362001)(54906003)(83380400001)(2616005)(38100700001)(66946007)(5660300002)(478600001)(9746002)(6862004)(66556008)(8676002)(4326008)(2906002)(26005)(316002)(9786002)(6636002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: kLHHY0DaKz1VC9vjtZF6VdzwNInaETArjLsSpivz4ajed0LwN3HLkdIfkWIe50+1q1a5NeoyrjOJRweWZ+XkOKN31mxhPEXM62mD/jRvvik3XZR/mP9XkxDrx3JGcV9BIWpbVjtOOOFrQhjvmxkxz1u5Umg1O5oQG+CthJ19FMHffQPi1iY2Ob0UubPAGcE5M/FAqdDimr+FNHQjBpP2S5Ix4CQzn8Bua8ri+JYUmLyB6KZpQTNil8uzDu4lsa83OqvJRPGIRj60W1EKaCYvXqbe8qLFXLuJcf0osu4YimlZ+VzvyIigFpPPDqKpW/mv51rHWtC9Ko2xvB9KwtsInrxyFMWuYOrAzfuWRNFb0KFUTOH9gplrt4GOYjQbUyGKgPgcEq1FHkB6GNzTxIrLoZW8Z+uFzeBasfPtOFGqFwVr0DGCAM1tsjMcGmcXLvgFOzND0vxKmQ1iNmyh10+ajVTy7tCtqe/dROKfUHikKGVNM+ETiMaxfU4ggj6zuBtTAnscAYED9GvMdcoOz81HLLyEJozgqWf+ocbMorZRxg9GwU6gkbRyxj8hX7ti4yf5SjJm9ilG1YcF+AdMzT7kTTfId+Y6H1n6E+kYqZDiUxfFVj8yDapYySxmW63VwitefLTeHe4EkGFIl3MOgJAzhxsOiMz60ULU23QUknc3Ldg64q7tm51LrqgXs80n6HFN8hOTqe6qi//ARSpXdpykTtw8glJX2UQmkBDRiDqd7fRcRiox68F6VjxejNBK2b3sesaak3WOrx1LOUjt2doseiAeu65vifBUMnLsQn7hoJwY/UbQf8AJ4nVrdNGTUJbWfP5hbsb3pkVeJ6s/DMrdnL597LlRzTHEJA9OkO/PrvFPtByUJBR6DMiJSvN7UTiPNwrzdORoJTKN+Uy9kx+T1t/7LL7XkI6hgP0ah5mjJjj+7DJlnaZBLdE5lnq3k9a7uCyIBV9O28Zg4uVARXqcS2MOzstz8V0aFpNvJyizuk38HlGwHi2bYsJsdIG4OJCovjEm95QnGgzKMmOyO32U7+1dS8Da/ExPfm3Dl5H5QSUxJmjABzFUISypXtPBf2Yi5dacrzVUphxcLQvadOmO/lJi33XZ3Flkmhkh+aePjT2JIlTeLoak9oy0EPxnr67LpQ6U0lK4syynyr12Z4z7vz206ipCtsVPyM0CrneusR2y1ssB4HVK0GUH610f/zznH9M1CAArUS4HpZNEcCnyh6OpFCa6oUqVgFdx2JtfLjQiPMONonUVXUoU0LEIMTWznwEtxW9mF+wOGDz0opb/jVtFzD2krABQ7ieDR4qlxhJXKqCIiqi1NUCBX9oso/W4 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: a4fef12f-07cd-4541-0517-08d8ee24de88 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2021 17:55:39.5373 (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: e9TE71FvXX7S/ZgNGj62zojWfmkJ+3ovYsQ5W2YBjubjzcZJLa1SkTHrwCaMZAYY X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4943 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The mbochs_types array is parallel to the supported_type_groups array, so the type_group_id indexes both. Instead of doing string searching just directly index with type_group_id in all places. Signed-off-by: Jason Gunthorpe Reviewed-by: Christoph Hellwig --- samples/vfio-mdev/mbochs.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/samples/vfio-mdev/mbochs.c b/samples/vfio-mdev/mbochs.c index 365afbe2dea558..a1af30df10a2ee 100644 --- a/samples/vfio-mdev/mbochs.c +++ b/samples/vfio-mdev/mbochs.c @@ -205,16 +205,6 @@ static struct page *__mbochs_get_page(struct mdev_state *mdev_state, static struct page *mbochs_get_page(struct mdev_state *mdev_state, pgoff_t pgoff); -static const struct mbochs_type *mbochs_find_type(struct kobject *kobj) -{ - int i; - - for (i = 0; i < ARRAY_SIZE(mbochs_types); i++) - if (strcmp(mbochs_types[i].name, kobj->name) == 0) - return mbochs_types + i; - return NULL; -} - static void mbochs_create_config_space(struct mdev_state *mdev_state) { STORE_LE16((u16 *) &mdev_state->vconfig[PCI_VENDOR_ID], @@ -518,7 +508,8 @@ static int mbochs_reset(struct mdev_device *mdev) static int mbochs_create(struct kobject *kobj, struct mdev_device *mdev) { - const struct mbochs_type *type = mbochs_find_type(kobj); + const struct mbochs_type *type = + &mbochs_types[mdev_get_type_group_id(mdev)]; struct device *dev = mdev_dev(mdev); struct mdev_state *mdev_state; @@ -544,7 +535,7 @@ static int mbochs_create(struct kobject *kobj, struct mdev_device *mdev) goto err_mem; dev_info(dev, "%s: %s, %d MB, %ld pages\n", __func__, - kobj->name, type->mbytes, mdev_state->pagecount); + type->name, type->mbytes, mdev_state->pagecount); mutex_init(&mdev_state->ops_lock); mdev_state->mdev = mdev; @@ -1349,7 +1340,8 @@ static MDEV_TYPE_ATTR_RO(name); static ssize_t description_show(struct kobject *kobj, struct device *dev, char *buf) { - const struct mbochs_type *type = mbochs_find_type(kobj); + const struct mbochs_type *type = + &mbochs_types[mtype_get_type_group_id(kobj)]; return sprintf(buf, "virtual display, %d MB video memory\n", type ? type->mbytes : 0); @@ -1359,7 +1351,8 @@ static MDEV_TYPE_ATTR_RO(description); static ssize_t available_instances_show(struct kobject *kobj, struct device *dev, char *buf) { - const struct mbochs_type *type = mbochs_find_type(kobj); + const struct mbochs_type *type = + &mbochs_types[mtype_get_type_group_id(kobj)]; int count = (max_mbytes - mbochs_used_mbytes) / type->mbytes; return sprintf(buf, "%d\n", count); From patchwork Tue Mar 23 17:55:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12158925 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=-16.0 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 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 D951FC433E5 for ; Tue, 23 Mar 2021 17:56:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B699E619C6 for ; Tue, 23 Mar 2021 17:56:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231366AbhCWR4J (ORCPT ); Tue, 23 Mar 2021 13:56:09 -0400 Received: from mail-eopbgr690085.outbound.protection.outlook.com ([40.107.69.85]:23427 "EHLO NAM04-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231206AbhCWRzl (ORCPT ); Tue, 23 Mar 2021 13:55:41 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ltzQOiW522Y4dkHdAL3BqxM6IIQPyb09MgiEHo7tyal0IA46LbeAr7XMu6QPlixNIphmzSyEYOq+7J2xw7xbTER6Gppw+h4ODQl9uaHPmmpgN+JmxzU8xLY51uW90yoMm9c19dYrdBeeDYmQW7gIlMlaxxKh6AxxhAXTCj62A17/RyQQKY+eRY0taNaCp5utg0+REaxjuBjcXiA+W2s3m4x/xUsdBmAHMeNrux7GkI7dmPZ3TfYUzSkfoQhkaVr/LJrk9Mex20bsmpSaET7bsnAUIPmHigqF80PZuWoNYBMtJ8UtFmnLFarfDF/8bkZjEhQtMnaCD6LC6FuK9q2mlA== 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=yhnSqc0n+mNNMJCgBL2mzcTzmW+ce6iSPtXfQNgWPcA=; b=kkjWhAPK0qyw7g0ghPa6LwDdqqLW9cIDZiI9x6lsqpNF1xD3dJlQkYWO5XQ6Ro/s/x1n+cOUVQ6NZqE3BDa/r1EO7bo7uNIyn0iqFeq4ApCSLlSAxDy1cNMrheQkKL6bFCcoA4lWWZ5YHRa3mlB/colmFwwVNtNYGq3sjRzRzx6nenL8Lq7Nlm24ozhCjS7Bu0fPY35S3f5U5MNSdBVZN73eYmGYizcFZGXR+I44menAB4FZBjby0rcqfwG6qN3DdXWK+DO+9rW9O06mNFjZ3ao8KMyqSaGJc5JPqLoMIuvWv3PtsJkxoG/ir7ssx6HO7K33zXltaQDYlz0sHzvrDQ== 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=yhnSqc0n+mNNMJCgBL2mzcTzmW+ce6iSPtXfQNgWPcA=; b=NVeI1Jdmlz6Bp3sLOcPO5DnlwWVTjuKp4ow02VJAWvFNifTU2x9gm/wIWf0Tq1OTtAjk9jGxtBQdkbVRaaY4tHeeFiyT7Zj5oh4besZrQo5+s3EO8R9Q1tNGzAc1t7LXcMoGKLXkLqCgYuoCe2VeIxITGUkaIgHoS3ne48ILKTKQHIESv/jCXdskcTKxKazbXVibG+U65U4fsxPbW3wa/hawShKS73JitFw34SI1J6EulLYG+nnxhycbvKIjgjath5aKvNCgUN08hL9ncMdemQNfoHOljOJHzxkI7pFOZhwf1dTqDwVmMlwduJtYZwQSeOXml06jz5CCJVx8FYpNQA== Authentication-Results: linux.ie; dkim=none (message not signed) header.d=none;linux.ie; dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) by DM6PR12MB3932.namprd12.prod.outlook.com (2603:10b6:5:1c1::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3955.23; Tue, 23 Mar 2021 17:55:39 +0000 Received: from DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87]) by DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87%6]) with mapi id 15.20.3955.027; Tue, 23 Mar 2021 17:55:39 +0000 From: Jason Gunthorpe To: David Airlie , Tony Krowiak , Alex Williamson , Christian Borntraeger , Cornelia Huck , Daniel Vetter , dri-devel@lists.freedesktop.org, Eric Farman , Harald Freudenberger , Vasily Gorbik , Heiko Carstens , intel-gfx@lists.freedesktop.org, intel-gvt-dev@lists.freedesktop.org, Jani Nikula , Joonas Lahtinen , kvm@vger.kernel.org, Kirti Wankhede , linux-s390@vger.kernel.org, Peter Oberparleiter , Halil Pasic , Pierre Morel , Rodrigo Vivi , Vineeth Vijayan , Zhenyu Wang , Zhi Wang Cc: "Raj, Ashok" , Dan Williams , Christoph Hellwig , Leon Romanovsky , Max Gurtovoy , Tarun Gupta Subject: [PATCH 17/18] vfio/mdev: Remove kobj from mdev_parent_ops->create() Date: Tue, 23 Mar 2021 14:55:34 -0300 Message-Id: <17-v1-7dedf20b2b75+4f785-vfio2_jgg@nvidia.com> In-Reply-To: <0-v1-7dedf20b2b75+4f785-vfio2_jgg@nvidia.com> References: X-Originating-IP: [206.223.160.26] X-ClientProxiedBy: BL0PR0102CA0029.prod.exchangelabs.com (2603:10b6:207:18::42) To DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (206.223.160.26) by BL0PR0102CA0029.prod.exchangelabs.com (2603:10b6:207:18::42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3955.18 via Frontend Transport; Tue, 23 Mar 2021 17:55:37 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lOlFf-001chT-Sg; Tue, 23 Mar 2021 14:55:35 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6fe83c2a-9440-40b3-3c68-08d8ee24dd7a X-MS-TrafficTypeDiagnostic: DM6PR12MB3932: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cvWuYBLSeBhpQK5P6xQZWZ4Jj15CkkIG6HzQxVExVZMFR/F+vF4uJRtuNxkS66qE5t1XQNA/c5cyP4Q6VGrFbXilKVwe5e8BrHfnqca0n76h0cyj3RDC4O03khjox+sM2DFC7NKgGzQJyuQobmJpZcBFon1Hx7gf8Pu/8bUjvkZcsdFDmo+SkURY1ogIz0TYN5LpySgkEhcp6I7RUBtifuZ7VERjut7LDRQN6Qd8DQXcJPJZr8MIe7w1og9ubT4GoAHzi2NGaI9+3Tyi1vT6pBTVVnAiA9Vl7DRnpwL3RE3EQgi3tvSQV4aAAEXMG3P6IJH9nh3tx06c0JHxaD9+yFekGhsOcNg+xv/r11myJ7/2yvyeIWHiA3NJX1lOsYUbGRlmGEB/I+QlGGwjy+2odiR4mgXT0RTpaGZdib8moLpnrbNqqQ4qxhkqwSJNQhNrYurx9BGYouXIZeVS2SlAJxj/Pd6hoGbDtLLNXBruTQ5GlsvwE5H5ILFkq3ydO7rGoA6ibbwjeia6YuvBi3VWMo/dS/Xt5rdiqYppbNuk8q1A0Wibfl99r6efol4/d3PgZiUrjLPnOxUECJzErEqcVMxkLhz2TAPwn3BhcmI84aBL3pgsHgnrx+7ir8tT1JzZ6AO5J8FFbAOF8obRBzhkXMtSeEJeWNnStFkTGz/pQPqDqcTbQ6uYYHgdFqcmrGnn X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3834.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(136003)(366004)(39840400004)(396003)(346002)(2616005)(9786002)(478600001)(66556008)(86362001)(8936002)(107886003)(66946007)(83380400001)(9746002)(66476007)(26005)(921005)(5660300002)(54906003)(8676002)(316002)(2906002)(4326008)(186003)(38100700001)(426003)(7416002)(36756003)(110136005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: ytix0lNIz13iTRqUP3z9vwM9VyqRrkvZYjLUnAODMzzFJRMyb2FFDFm0acciUucxU2EPVKsbbP97glCbnrx9/IkC1/5ZwyfEmZJ1hTGcDWL7Mm3D/kyzRVimyJ7HQeADExQqXqrs+fA4fccy8WqtRASdNo2HUNz+C7nPMHMCh4/jCB7zlgL0qOBzZOPcRZxbtWDCoWTlwKvgqjQpJOWFitmy4K+d3cdbkm47FKP0Rpe/9mp2mwW5YDOSgnHLFUGw5TsDmYRqOTyQ7vVkVrBp3+a6bU2Gpim2Qh3G5WtW6fjXxxTAqvvwdFSeUb/0cjsI2h/HB2JAsA77e7rKembLomHGHll6f8UdlrDbwKmLD8z6MYadPXcF+85GXYV4I9CAluZFSX1+eAVP31Pz2bpBpUFH2XJKZ7JjhpauEntnp52n9c0NfgrSWkOA+GAcFof4ievuXOIAdPNJAwAffQiQxgOMDTx0mu52XlyBopdkV6/7BxDzwJrq/pGWA4blRv7/wdfqSoOwR62MdM9H4iwF5sV/SvbpR6ARgDFG31uSm+jUZNIm3FSCA8BtifpFMd1ddFzH67um15FefUXP1TvwPaGer7svouEpIM8QsM3169sfhNhud8tFJ/bpeG3qoJCM7kUACUqk9N0m/x8DjbKmHAAQuiUxmwEjvJis5gRSH42yGvse7C28XU/FRl2rLtKY6xyjdUyl05Km6/2Z9GqEsBJ1KEfTruri5ZWCcJzmyMryfEty25eMk6AALi0dZ/Ann9FZgrj+hcJUpNwjJnSrYtD/YPATDXV+tn5QyI3Pgdm+RZ8gTv0IPWhD7V78Y44+iJUWNDRnwn8MfjHJ4xghO02iKPP4SFW55P6h5TjbDwINmXjrh3ht5mrje+PUMYDQ4yaWRH7+NWmpv5sX1m7MTH8ZV6YV4+Wak1blxr3X28kjrmk4xuWITUFX/25DS4WjWBu3kP5fA6tuK5TKDPgQVpWL46uUHw2SPx07aKryE1IpCypb18gPC1uM8S4N3kTLKXpbsiWCSG0NreWxiDpmij+xCy8r0+n9FajvpHBdaleld9RA94yr9EcEVYGb3qBA8UGrJgxNE0IUdWTCmqDrBPE+Zm7e6iv6eIRGmwNElaHGmkHFqe/5CyfXUvrIM5LnWGLFF94xnrn8E8pE/XGeHyChgik0tIFAppd80sdpuWxRnWn24TFNGYNoSTOCTXWksrOsCxcWdAjCliVnz+BQyRsnjv4IVAnCmvrV/2YTftHdutK0kNhHmTe/ZK0Fsi6PU57cm6pLPzjCj1jy+TCrP/K+uuCDlRCc5gRIr+Dli15XLrjxXvmAJiVrSqAJLOdK X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6fe83c2a-9440-40b3-3c68-08d8ee24dd7a X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2021 17:55:37.7102 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: vbJDDUsMiQ/E56qJl3xN/slkyqbUaugEScUmOz9kV9BXHNPtWzaaOMel2FJTFkH2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3932 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The kobj here is a type-erased version of mdev_type, which is already stored in the struct mdev_device being passed in. It was only ever used to compute the type_group_id, which is now extracted directly from the mdev. Signed-off-by: Jason Gunthorpe Reviewed-by: Christoph Hellwig Reviewed-by: Kevin Tian Reviewed-by: Cornelia Huck --- drivers/gpu/drm/i915/gvt/kvmgt.c | 2 +- drivers/s390/cio/vfio_ccw_ops.c | 2 +- drivers/s390/crypto/vfio_ap_ops.c | 2 +- drivers/vfio/mdev/mdev_core.c | 2 +- include/linux/mdev.h | 3 +-- samples/vfio-mdev/mbochs.c | 2 +- samples/vfio-mdev/mdpy.c | 2 +- samples/vfio-mdev/mtty.c | 2 +- 8 files changed, 8 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c b/drivers/gpu/drm/i915/gvt/kvmgt.c index 16e1e4a38aa1f6..6bf176e8426e63 100644 --- a/drivers/gpu/drm/i915/gvt/kvmgt.c +++ b/drivers/gpu/drm/i915/gvt/kvmgt.c @@ -689,7 +689,7 @@ static void kvmgt_put_vfio_device(void *vgpu) vfio_device_put(vdev->vfio_device); } -static int intel_vgpu_create(struct kobject *kobj, struct mdev_device *mdev) +static int intel_vgpu_create(struct mdev_device *mdev) { struct intel_vgpu *vgpu = NULL; struct intel_vgpu_type *type; diff --git a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_ops.c index 68106be4ba7a19..06a82ec136080c 100644 --- a/drivers/s390/cio/vfio_ccw_ops.c +++ b/drivers/s390/cio/vfio_ccw_ops.c @@ -110,7 +110,7 @@ static struct attribute_group *mdev_type_groups[] = { NULL, }; -static int vfio_ccw_mdev_create(struct kobject *kobj, struct mdev_device *mdev) +static int vfio_ccw_mdev_create(struct mdev_device *mdev) { struct vfio_ccw_private *private = dev_get_drvdata(mdev_parent_dev(mdev)); diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c index 41fc2e4135fe18..6d75ed07bcd49d 100644 --- a/drivers/s390/crypto/vfio_ap_ops.c +++ b/drivers/s390/crypto/vfio_ap_ops.c @@ -322,7 +322,7 @@ static void vfio_ap_matrix_init(struct ap_config_info *info, matrix->adm_max = info->apxa ? info->Nd : 15; } -static int vfio_ap_mdev_create(struct kobject *kobj, struct mdev_device *mdev) +static int vfio_ap_mdev_create(struct mdev_device *mdev) { struct ap_matrix_mdev *matrix_mdev; diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c index 3ba5e9464b4d20..71455812cb84cf 100644 --- a/drivers/vfio/mdev/mdev_core.c +++ b/drivers/vfio/mdev/mdev_core.c @@ -286,7 +286,7 @@ int mdev_device_create(struct mdev_type *type, const guid_t *uuid) goto mdev_fail; } - ret = parent->ops->create(&type->kobj, mdev); + ret = parent->ops->create(mdev); if (ret) goto ops_create_fail; diff --git a/include/linux/mdev.h b/include/linux/mdev.h index 41e91936522394..c3a800051d6146 100644 --- a/include/linux/mdev.h +++ b/include/linux/mdev.h @@ -61,7 +61,6 @@ unsigned int mtype_get_type_group_id(struct kobject *mtype_kobj); * @create: Called to allocate basic resources in parent device's * driver for a particular mediated device. It is * mandatory to provide create ops. - * @kobj: kobject of type for which 'create' is called. * @mdev: mdev_device structure on of mediated device * that is being created * Returns integer: success (0) or error (< 0) @@ -107,7 +106,7 @@ struct mdev_parent_ops { const struct attribute_group **mdev_attr_groups; struct attribute_group **supported_type_groups; - int (*create)(struct kobject *kobj, struct mdev_device *mdev); + int (*create)(struct mdev_device *mdev); int (*remove)(struct mdev_device *mdev); int (*open)(struct mdev_device *mdev); void (*release)(struct mdev_device *mdev); diff --git a/samples/vfio-mdev/mbochs.c b/samples/vfio-mdev/mbochs.c index a1af30df10a2ee..ac4d0dc2490705 100644 --- a/samples/vfio-mdev/mbochs.c +++ b/samples/vfio-mdev/mbochs.c @@ -506,7 +506,7 @@ static int mbochs_reset(struct mdev_device *mdev) return 0; } -static int mbochs_create(struct kobject *kobj, struct mdev_device *mdev) +static int mbochs_create(struct mdev_device *mdev) { const struct mbochs_type *type = &mbochs_types[mdev_get_type_group_id(mdev)]; diff --git a/samples/vfio-mdev/mdpy.c b/samples/vfio-mdev/mdpy.c index 08c15f9f06a880..da88fd7dd42329 100644 --- a/samples/vfio-mdev/mdpy.c +++ b/samples/vfio-mdev/mdpy.c @@ -216,7 +216,7 @@ static int mdpy_reset(struct mdev_device *mdev) return 0; } -static int mdpy_create(struct kobject *kobj, struct mdev_device *mdev) +static int mdpy_create(struct mdev_device *mdev) { const struct mdpy_type *type = &mdpy_types[mdev_get_type_group_id(mdev)]; diff --git a/samples/vfio-mdev/mtty.c b/samples/vfio-mdev/mtty.c index 191a587a8d5ab1..f2e36c06ac6aa2 100644 --- a/samples/vfio-mdev/mtty.c +++ b/samples/vfio-mdev/mtty.c @@ -708,7 +708,7 @@ static ssize_t mdev_access(struct mdev_device *mdev, u8 *buf, size_t count, return ret; } -static int mtty_create(struct kobject *kobj, struct mdev_device *mdev) +static int mtty_create(struct mdev_device *mdev) { struct mdev_state *mdev_state; int nr_ports = mdev_get_type_group_id(mdev) + 1; From patchwork Tue Mar 23 17:55:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12158941 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=-16.0 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 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 2642BC433F8 for ; Tue, 23 Mar 2021 17:56:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 07EEB619C6 for ; Tue, 23 Mar 2021 17:56:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231424AbhCWR4V (ORCPT ); Tue, 23 Mar 2021 13:56:21 -0400 Received: from mail-bn8nam12on2077.outbound.protection.outlook.com ([40.107.237.77]:36673 "EHLO NAM12-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231316AbhCWRzo (ORCPT ); Tue, 23 Mar 2021 13:55:44 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LWlunjek235B2U0Gc4fc++vxKmZ+6FdUJj2ObP5b36DPhXXm1Oz+mAHimC5xRqlWK86DEgWXKEiRNGit2z9W34s0sjZjQRn+OA9H7yfzupk5rk1Gl0MtpER5bmQtSud3oShvnV7cPxy9kIpu1rBgAKwb1DoKV0YamCake5Dr+WCEPvox+iCsGHgVfUSkXmX8/UJpgGwjTau9A8MECVcuENEqY67eTb17gYyWMw66HzCCdH01aQ3wJx6fjtCNBXl7ZzMAG3qpGnyuIPlVzg9P5IulB8h2i+35Ecvr+UuxgqOFkB2CsnX6ty8Ko3pdZwQOGshhpxzbFmxLIWmv5QrzzQ== 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=8A7BxrPoq9ucCPHa022cU2jcTVY8lETztMgoYJweAkY=; b=JRGmYBiyokOkrI7KwKRQnYLX0P4eTN7h0mXlXAUcJQ0cukkCQCwzQG1ytLxK6DdkUm8dR9/5aETx1j2N410Q9G2S18ePPcSqx32iatVjYTFatjSzp+tANQ5X/fjirRXplJSsCBIfvNBikPLOR+6PrkwVjjQ0OaTK3tTugRQ+Htx3pwxdazpdJKQlal18BHEUYOOyUkq8KRJOabe3HFNFHFJurUYPCiWXlnroZ3QMPx6PzxVmD7/6+OZbE6382Z18iFBkmrRAegoR1hQw3MfbrV50FsJRFVaftwbViZzLPUlHzM6Ipen6Ae+46lDm2OdGEh0aTVqgWNeDOGHeglaZhQ== 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=8A7BxrPoq9ucCPHa022cU2jcTVY8lETztMgoYJweAkY=; b=QmW1KAMm72FpHRRGpID0AW75rZ+4WrqBPIr/dgPdoGTGJY5O+c3vm0dQDC4cyf4tlG4aIs090/o4wT1gT7qqk/T8lgyNmLaJlJVykvR05iJNaFbZ6Hwvo42Ohhfzto52kCj6lTu+FuTNv+FXHXCBpQUGVYzlv0p8n+mPfp77Vf/r80yET6GkzhAjnY7BgJhoRWUR2e71v2LQCdIpRi+EEX62HhXS2Qw5/Ewqes0d+5hjsGnfCCtdnpvasvhPJRNXLCpKDeyBpl/i/z9rAKstjujCbHoJoXI6OKnQLYO8HNjP4XuP5vELRNX9SNmCzVCBz+wn6AMX++onFG2dLRNVLw== Authentication-Results: linux.ie; dkim=none (message not signed) header.d=none;linux.ie; dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) by DM6PR12MB4943.namprd12.prod.outlook.com (2603:10b6:5:1bc::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3955.18; Tue, 23 Mar 2021 17:55:43 +0000 Received: from DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87]) by DM6PR12MB3834.namprd12.prod.outlook.com ([fe80::1c62:7fa3:617b:ab87%6]) with mapi id 15.20.3955.027; Tue, 23 Mar 2021 17:55:43 +0000 From: Jason Gunthorpe To: David Airlie , Tony Krowiak , Alex Williamson , Christian Borntraeger , Cornelia Huck , Daniel Vetter , dri-devel@lists.freedesktop.org, Eric Farman , Harald Freudenberger , Vasily Gorbik , Heiko Carstens , intel-gfx@lists.freedesktop.org, intel-gvt-dev@lists.freedesktop.org, Jani Nikula , Joonas Lahtinen , kvm@vger.kernel.org, Kirti Wankhede , linux-s390@vger.kernel.org, Peter Oberparleiter , Halil Pasic , Pierre Morel , Rodrigo Vivi , Vineeth Vijayan , Zhenyu Wang , Zhi Wang Cc: "Raj, Ashok" , Dan Williams , Christoph Hellwig , Leon Romanovsky , Max Gurtovoy , Tarun Gupta Subject: [PATCH 18/18] vfio/mdev: Correct the function signatures for the mdev_type_attributes Date: Tue, 23 Mar 2021 14:55:35 -0300 Message-Id: <18-v1-7dedf20b2b75+4f785-vfio2_jgg@nvidia.com> In-Reply-To: <0-v1-7dedf20b2b75+4f785-vfio2_jgg@nvidia.com> References: X-Originating-IP: [206.223.160.26] X-ClientProxiedBy: MN2PR18CA0015.namprd18.prod.outlook.com (2603:10b6:208:23c::20) To DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (206.223.160.26) by MN2PR18CA0015.namprd18.prod.outlook.com (2603:10b6:208:23c::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.24 via Frontend Transport; Tue, 23 Mar 2021 17:55:39 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lOlFf-001chX-UB; Tue, 23 Mar 2021 14:55:35 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 21d446ec-a206-4ed5-6992-08d8ee24dec4 X-MS-TrafficTypeDiagnostic: DM6PR12MB4943: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:949; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tPp9VMFVOIvXCRsVkV6SWORMvw918omC61F2wHIlfSFd27o3tEnyW5HS39mQ1JHf2d/efboY75HF8uPtamaOwJ2SuJB92yTk+RKxsE2/0/8vJ3PRaEyoruNV1JFN+2Rug1GW3B6/X4h16ZWxRX8o5Xd5dvGvTQpL5m+YHjkPLVYgqFvN6szn8cEPHnWHrPUgToB3toJGUq46vCuVlWFAEffrad17uTr3cPJZuFbtJnUwg+A5LJ5CMm1AcjvHSqMoK19aAyf5AGx8EVJU9zquhFYlynyv7yswJAbLzftcGtidYDhmKgjcuQz6CW0us+hpSqySz5eCjIzFRwNhCUdhf9aMTCr5nk//85dr0iJKGaLakksaG+tuW329EnxNZf+5tIrgQL5AkUZK3c9tj0FSQYmXjxeeR04OldeTHTuYk/DwmprsdFzjYyB0c7ulTNniEe81OrdnDYedam22CnBJ16ycNi58Trdcq0A16sfBxPB7dZR2tzuniAcM6vpycKT34K9ay/EFiIVc+COG7JQ1etw0CFPwz94rV+zDZeJwZlg49PveUyKp1di8gdybxwl03D5o1nf4uyvx4k+jF4DCJ1ac36UNnFAoLwmEqCf6xYNZzNvQvriOO9GoljvX9tzZVp/1IYLrDMDF1GxLzjhVlhZEfat0Ng5L7dkvonCTCgQ= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3834.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(39860400002)(136003)(376002)(366004)(346002)(66476007)(186003)(107886003)(8936002)(110136005)(36756003)(426003)(86362001)(54906003)(83380400001)(2616005)(38100700001)(30864003)(921005)(7416002)(66946007)(5660300002)(478600001)(9746002)(66556008)(8676002)(4326008)(2906002)(26005)(316002)(9786002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: S4YkBffW/fJ36ABKRhabNaF+WMxeX4MQwG+fV+AHy2iq0tZlt5kTf6p03+23qRohZR76erjRWoRlwNtmNgINGLExY7O9b0BPI+mq2wbqp0ZgAfr0QFfEx/Pdo1+ZDdubLN7vLAbXFRq6YuT8vuHLy6NNWbu20Zle5GBrfYl2203bJnv9qIheI/6zRhdsYxGcXlDcjzIpZr/0qUbBW+2qsy7bozsbl7jR3kd0Zvx37WAmgnfEoo15DBQwJMryY451/035NvX/eysf5TYPxzIsXslLAD/KSnUIl89+xeUfcGVFg0yo5xW7rx/7xWhDaNPhBCf+jthSo9IXxHvfWbSWGPZUH++lKl3PIc7kegDR24Oqz0eDlB7th2/eSaciV7x7jVT7Fs1TFqCM5hcc4ac8ub/rLiQljuJW9lkkSz6OEvkLoeUHNgu6EJMuKwWklDFDuRN9HGMzyfu0Y2o4YPadFvwpVvHtSJ+VuEYcqHGnbdCWxD7H9St0lsQzpXKVZ8yFeMznQu7ydzg7TzeIAQitcGflSIvROOt5R1LuUwOVjVZLI/+S7V2ImBjjqtwTsuPuNejVzekmbV7TovAOPrZ5sCBGhN7TBOQIBBeBUD4QwLznHY6n3yR8NeJIM/xdkZOUUmj9jcCcFhuikUJkE7jyyw3h87DTqlGgRQBwf7xoBW+SeOF5As1n2o9uYcfGQCO4bXGWYvqLaaYHCOPiUOtyJu+yZLSpvwcw+QgcV71Pp1dcYJbuBH61ekMDZDtKPu/p1+qw+2MJn9n1/wykJffKYpZOYKYxkvoGIl4O/TCtVvH34QqSf/o2xmrEtS0d/MVyUI2OBweb1aGu4oFO8gNvlpvFgOoKouvxxDu8qHgfJ1U2wVDXWf/NCOllYc/uNMYtZzNb/lkADaUpygpnyYIwMiNGieQjcMlyN3hS5UHA6QBXpKiwoyvwHAJkeUuG2eioeCC8EMxdQO88mcXcw+7Zb/ZBS/cwNTTNpQmt1sHEZmFVK40yNx8EnEFqHkDwRZfMOw+pSbEqc8RrZdFEFV3OG6OmwX2T/d45n4TIw7IfUBLBMKklQxkhS+BpxsLsXFnaselKtS7V+fdg140XaS10yokAc/MRz0iYgeTbXtf9EKK+zbJB86F+pD0IwXtmVNNQA9rMozGm0ViOKKK+yYzxsxBFVvB9TBfxv8Fl+4yTGxT12uG+FTwHw/va1B831whJi1iOz5PXd6w/KB4m8z4RIyWGvb8V9FM8zhFThsTGQxvVuoJl1R8SN4Rhk941gMHOGjtGfoX4Nc4l7jONYsijmQN0I7Hho6zKkOOw8swHBFmmxVfNarkoWNuwdqKnUW+X X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 21d446ec-a206-4ed5-6992-08d8ee24dec4 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2021 17:55:40.1160 (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: 5LMmCK1i6W5o3+ppBugFku0FXuNHbycE3fWaJ0IKo/s9yY9F0kxhKygpwHy0+z6g X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4943 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The driver core standard is to pass in the properly typed object, the properly typed attribute and the buffer data. It stems from the root kobject method: ssize_t (*show)(struct kobject *kobj, struct kobj_attribute *attr,..) Each subclass of kobject should provide their own function with the same signature but more specific types, eg struct device uses: ssize_t (*show)(struct device *dev, struct device_attribute *attr,..) In this case the existing signature is: ssize_t (*show)(struct kobject *kobj, struct device *dev,..) Where kobj is a 'struct mdev_type *' and dev is 'mdev_type->parent->dev'. Change the mdev_type related sysfs attribute functions to: ssize_t (*show)(struct mdev_type *mtype, struct mdev_type_attribute *attr,..) In order to restore type safety and match the driver core standard There are no current users of 'attr', but if it is ever needed it would be hard to add in retroactively, so do it now. Signed-off-by: Jason Gunthorpe Reviewed-by: Christoph Hellwig Reviewed-by: Kevin Tian Reviewed-by: Cornelia Huck --- drivers/gpu/drm/i915/gvt/gvt.c | 21 +++++++++++---------- drivers/s390/cio/vfio_ccw_ops.c | 15 +++++++++------ drivers/s390/crypto/vfio_ap_ops.c | 12 +++++++----- drivers/vfio/mdev/mdev_core.c | 14 ++++++++++++-- drivers/vfio/mdev/mdev_sysfs.c | 11 ++++++----- include/linux/mdev.h | 11 +++++++---- samples/vfio-mdev/mbochs.c | 26 +++++++++++++++----------- samples/vfio-mdev/mdpy.c | 24 ++++++++++++++---------- samples/vfio-mdev/mtty.c | 18 +++++++++--------- 9 files changed, 90 insertions(+), 62 deletions(-) diff --git a/drivers/gpu/drm/i915/gvt/gvt.c b/drivers/gpu/drm/i915/gvt/gvt.c index 4b47a18e9dfa0f..3703814a669b46 100644 --- a/drivers/gpu/drm/i915/gvt/gvt.c +++ b/drivers/gpu/drm/i915/gvt/gvt.c @@ -54,14 +54,15 @@ intel_gvt_find_vgpu_type(struct intel_gvt *gvt, unsigned int type_group_id) return &gvt->types[type_group_id]; } -static ssize_t available_instances_show(struct kobject *kobj, - struct device *dev, char *buf) +static ssize_t available_instances_show(struct mdev_type *mtype, + struct mdev_type_attribute *attr, + char *buf) { struct intel_vgpu_type *type; unsigned int num = 0; - void *gvt = kdev_to_i915(dev)->gvt; + void *gvt = kdev_to_i915(mtype_get_parent_dev(mtype))->gvt; - type = intel_gvt_find_vgpu_type(gvt, mtype_get_type_group_id(kobj)); + type = intel_gvt_find_vgpu_type(gvt, mtype_get_type_group_id(mtype)); if (!type) num = 0; else @@ -70,19 +71,19 @@ static ssize_t available_instances_show(struct kobject *kobj, return sprintf(buf, "%u\n", num); } -static ssize_t device_api_show(struct kobject *kobj, struct device *dev, - char *buf) +static ssize_t device_api_show(struct mdev_type *mtype, + struct mdev_type_attribute *attr, char *buf) { return sprintf(buf, "%s\n", VFIO_DEVICE_API_PCI_STRING); } -static ssize_t description_show(struct kobject *kobj, struct device *dev, - char *buf) +static ssize_t description_show(struct mdev_type *mtype, + struct mdev_type_attribute *attr, char *buf) { struct intel_vgpu_type *type; - void *gvt = kdev_to_i915(dev)->gvt; + void *gvt = kdev_to_i915(mtype_get_parent_dev(mtype))->gvt; - type = intel_gvt_find_vgpu_type(gvt, mtype_get_type_group_id(kobj)); + type = intel_gvt_find_vgpu_type(gvt, mtype_get_type_group_id(mtype)); if (!type) return 0; diff --git a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_ops.c index 06a82ec136080c..74fe21eceb66cc 100644 --- a/drivers/s390/cio/vfio_ccw_ops.c +++ b/drivers/s390/cio/vfio_ccw_ops.c @@ -71,23 +71,26 @@ static int vfio_ccw_mdev_notifier(struct notifier_block *nb, return NOTIFY_DONE; } -static ssize_t name_show(struct kobject *kobj, struct device *dev, char *buf) +static ssize_t name_show(struct mdev_type *mtype, + struct mdev_type_attribute *attr, char *buf) { return sprintf(buf, "I/O subchannel (Non-QDIO)\n"); } static MDEV_TYPE_ATTR_RO(name); -static ssize_t device_api_show(struct kobject *kobj, struct device *dev, - char *buf) +static ssize_t device_api_show(struct mdev_type *mtype, + struct mdev_type_attribute *attr, char *buf) { return sprintf(buf, "%s\n", VFIO_DEVICE_API_CCW_STRING); } static MDEV_TYPE_ATTR_RO(device_api); -static ssize_t available_instances_show(struct kobject *kobj, - struct device *dev, char *buf) +static ssize_t available_instances_show(struct mdev_type *mtype, + struct mdev_type_attribute *attr, + char *buf) { - struct vfio_ccw_private *private = dev_get_drvdata(dev); + struct vfio_ccw_private *private = + dev_get_drvdata(mtype_get_parent_dev(mtype)); return sprintf(buf, "%d\n", atomic_read(&private->avail)); } diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c index 6d75ed07bcd49d..cdc5edb0074690 100644 --- a/drivers/s390/crypto/vfio_ap_ops.c +++ b/drivers/s390/crypto/vfio_ap_ops.c @@ -366,15 +366,17 @@ static int vfio_ap_mdev_remove(struct mdev_device *mdev) return 0; } -static ssize_t name_show(struct kobject *kobj, struct device *dev, char *buf) +static ssize_t name_show(struct mdev_type *mtype, + struct mdev_type_attribute *attr, char *buf) { return sprintf(buf, "%s\n", VFIO_AP_MDEV_NAME_HWVIRT); } static MDEV_TYPE_ATTR_RO(name); -static ssize_t available_instances_show(struct kobject *kobj, - struct device *dev, char *buf) +static ssize_t available_instances_show(struct mdev_type *mtype, + struct mdev_type_attribute *attr, + char *buf) { return sprintf(buf, "%d\n", atomic_read(&matrix_dev->available_instances)); @@ -382,8 +384,8 @@ static ssize_t available_instances_show(struct kobject *kobj, static MDEV_TYPE_ATTR_RO(available_instances); -static ssize_t device_api_show(struct kobject *kobj, struct device *dev, - char *buf) +static ssize_t device_api_show(struct mdev_type *mtype, + struct mdev_type_attribute *attr, char *buf) { return sprintf(buf, "%s\n", VFIO_DEVICE_API_AP_STRING); } diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c index 71455812cb84cf..9ef1d5bed8069f 100644 --- a/drivers/vfio/mdev/mdev_core.c +++ b/drivers/vfio/mdev/mdev_core.c @@ -47,12 +47,22 @@ EXPORT_SYMBOL(mdev_get_type_group_id); * Used in mdev_type_attribute sysfs functions to return the index in the * supported_type_groups that the sysfs is called from. */ -unsigned int mtype_get_type_group_id(struct kobject *mtype_kobj) +unsigned int mtype_get_type_group_id(struct mdev_type *mtype) { - return container_of(mtype_kobj, struct mdev_type, kobj)->type_group_id; + return mtype->type_group_id; } EXPORT_SYMBOL(mtype_get_type_group_id); +/* + * Used in mdev_type_attribute sysfs functions to return the parent struct + * device + */ +struct device *mtype_get_parent_dev(struct mdev_type *mtype) +{ + return mtype->parent->dev; +} +EXPORT_SYMBOL(mtype_get_parent_dev); + /* Should be called holding parent_list_lock */ static struct mdev_parent *__find_parent_device(struct device *dev) { diff --git a/drivers/vfio/mdev/mdev_sysfs.c b/drivers/vfio/mdev/mdev_sysfs.c index 91ecccdc2f2ec6..9b0f1a8757a0df 100644 --- a/drivers/vfio/mdev/mdev_sysfs.c +++ b/drivers/vfio/mdev/mdev_sysfs.c @@ -26,7 +26,7 @@ static ssize_t mdev_type_attr_show(struct kobject *kobj, ssize_t ret = -EIO; if (attr->show) - ret = attr->show(kobj, type->parent->dev, buf); + ret = attr->show(type, attr, buf); return ret; } @@ -39,7 +39,7 @@ static ssize_t mdev_type_attr_store(struct kobject *kobj, ssize_t ret = -EIO; if (attr->store) - ret = attr->store(&type->kobj, type->parent->dev, buf, count); + ret = attr->store(type, attr, buf, count); return ret; } @@ -48,8 +48,9 @@ static const struct sysfs_ops mdev_type_sysfs_ops = { .store = mdev_type_attr_store, }; -static ssize_t create_store(struct kobject *kobj, struct device *dev, - const char *buf, size_t count) +static ssize_t create_store(struct mdev_type *mtype, + struct mdev_type_attribute *attr, const char *buf, + size_t count) { char *str; guid_t uuid; @@ -67,7 +68,7 @@ static ssize_t create_store(struct kobject *kobj, struct device *dev, if (ret) return ret; - ret = mdev_device_create(to_mdev_type(kobj), &uuid); + ret = mdev_device_create(mtype, &uuid); if (ret) return ret; diff --git a/include/linux/mdev.h b/include/linux/mdev.h index c3a800051d6146..1fb34ea394ad46 100644 --- a/include/linux/mdev.h +++ b/include/linux/mdev.h @@ -47,7 +47,8 @@ static inline struct device *mdev_get_iommu_device(struct mdev_device *mdev) } unsigned int mdev_get_type_group_id(struct mdev_device *mdev); -unsigned int mtype_get_type_group_id(struct kobject *mtype_kobj); +unsigned int mtype_get_type_group_id(struct mdev_type *mtype); +struct device *mtype_get_parent_dev(struct mdev_type *mtype); /** * struct mdev_parent_ops - Structure to be registered for each parent device to @@ -123,9 +124,11 @@ struct mdev_parent_ops { /* interface for exporting mdev supported type attributes */ struct mdev_type_attribute { struct attribute attr; - ssize_t (*show)(struct kobject *kobj, struct device *dev, char *buf); - ssize_t (*store)(struct kobject *kobj, struct device *dev, - const char *buf, size_t count); + ssize_t (*show)(struct mdev_type *mtype, + struct mdev_type_attribute *attr, char *buf); + ssize_t (*store)(struct mdev_type *mtype, + struct mdev_type_attribute *attr, const char *buf, + size_t count); }; #define MDEV_TYPE_ATTR(_name, _mode, _show, _store) \ diff --git a/samples/vfio-mdev/mbochs.c b/samples/vfio-mdev/mbochs.c index ac4d0dc2490705..861c76914e7639 100644 --- a/samples/vfio-mdev/mbochs.c +++ b/samples/vfio-mdev/mbochs.c @@ -1330,37 +1330,41 @@ static const struct attribute_group *mdev_dev_groups[] = { NULL, }; -static ssize_t -name_show(struct kobject *kobj, struct device *dev, char *buf) +static ssize_t name_show(struct mdev_type *mtype, + struct mdev_type_attribute *attr, char *buf) { - return sprintf(buf, "%s\n", kobj->name); + const struct mbochs_type *type = + &mbochs_types[mtype_get_type_group_id(mtype)]; + + return sprintf(buf, "%s\n", type->name); } static MDEV_TYPE_ATTR_RO(name); -static ssize_t -description_show(struct kobject *kobj, struct device *dev, char *buf) +static ssize_t description_show(struct mdev_type *mtype, + struct mdev_type_attribute *attr, char *buf) { const struct mbochs_type *type = - &mbochs_types[mtype_get_type_group_id(kobj)]; + &mbochs_types[mtype_get_type_group_id(mtype)]; return sprintf(buf, "virtual display, %d MB video memory\n", type ? type->mbytes : 0); } static MDEV_TYPE_ATTR_RO(description); -static ssize_t -available_instances_show(struct kobject *kobj, struct device *dev, char *buf) +static ssize_t available_instances_show(struct mdev_type *mtype, + struct mdev_type_attribute *attr, + char *buf) { const struct mbochs_type *type = - &mbochs_types[mtype_get_type_group_id(kobj)]; + &mbochs_types[mtype_get_type_group_id(mtype)]; int count = (max_mbytes - mbochs_used_mbytes) / type->mbytes; return sprintf(buf, "%d\n", count); } static MDEV_TYPE_ATTR_RO(available_instances); -static ssize_t device_api_show(struct kobject *kobj, struct device *dev, - char *buf) +static ssize_t device_api_show(struct mdev_type *mtype, + struct mdev_type_attribute *attr, char *buf) { return sprintf(buf, "%s\n", VFIO_DEVICE_API_PCI_STRING); } diff --git a/samples/vfio-mdev/mdpy.c b/samples/vfio-mdev/mdpy.c index da88fd7dd42329..885b88ea20e234 100644 --- a/samples/vfio-mdev/mdpy.c +++ b/samples/vfio-mdev/mdpy.c @@ -652,18 +652,21 @@ static const struct attribute_group *mdev_dev_groups[] = { NULL, }; -static ssize_t -name_show(struct kobject *kobj, struct device *dev, char *buf) +static ssize_t name_show(struct mdev_type *mtype, + struct mdev_type_attribute *attr, char *buf) { - return sprintf(buf, "%s\n", kobj->name); + const struct mdpy_type *type = + &mdpy_types[mtype_get_type_group_id(mtype)]; + + return sprintf(buf, "%s\n", type->name); } static MDEV_TYPE_ATTR_RO(name); -static ssize_t -description_show(struct kobject *kobj, struct device *dev, char *buf) +static ssize_t description_show(struct mdev_type *mtype, + struct mdev_type_attribute *attr, char *buf) { const struct mdpy_type *type = - &mdpy_types[mtype_get_type_group_id(kobj)]; + &mdpy_types[mtype_get_type_group_id(mtype)]; return sprintf(buf, "virtual display, %dx%d framebuffer\n", type ? type->width : 0, @@ -671,15 +674,16 @@ description_show(struct kobject *kobj, struct device *dev, char *buf) } static MDEV_TYPE_ATTR_RO(description); -static ssize_t -available_instances_show(struct kobject *kobj, struct device *dev, char *buf) +static ssize_t available_instances_show(struct mdev_type *mtype, + struct mdev_type_attribute *attr, + char *buf) { return sprintf(buf, "%d\n", max_devices - mdpy_count); } static MDEV_TYPE_ATTR_RO(available_instances); -static ssize_t device_api_show(struct kobject *kobj, struct device *dev, - char *buf) +static ssize_t device_api_show(struct mdev_type *mtype, + struct mdev_type_attribute *attr, char *buf) { return sprintf(buf, "%s\n", VFIO_DEVICE_API_PCI_STRING); } diff --git a/samples/vfio-mdev/mtty.c b/samples/vfio-mdev/mtty.c index f2e36c06ac6aa2..b9b24be4abdab7 100644 --- a/samples/vfio-mdev/mtty.c +++ b/samples/vfio-mdev/mtty.c @@ -1292,23 +1292,24 @@ static const struct attribute_group *mdev_dev_groups[] = { NULL, }; -static ssize_t -name_show(struct kobject *kobj, struct device *dev, char *buf) +static ssize_t name_show(struct mdev_type *mtype, + struct mdev_type_attribute *attr, char *buf) { static const char *name_str[2] = { "Single port serial", "Dual port serial" }; return sysfs_emit(buf, "%s\n", - name_str[mtype_get_type_group_id(kobj)]); + name_str[mtype_get_type_group_id(mtype)]); } static MDEV_TYPE_ATTR_RO(name); -static ssize_t -available_instances_show(struct kobject *kobj, struct device *dev, char *buf) +static ssize_t available_instances_show(struct mdev_type *mtype, + struct mdev_type_attribute *attr, + char *buf) { struct mdev_state *mds; - unsigned int ports = mtype_get_type_group_id(kobj) + 1; + unsigned int ports = mtype_get_type_group_id(mtype) + 1; int used = 0; list_for_each_entry(mds, &mdev_devices_list, next) @@ -1319,9 +1320,8 @@ available_instances_show(struct kobject *kobj, struct device *dev, char *buf) static MDEV_TYPE_ATTR_RO(available_instances); - -static ssize_t device_api_show(struct kobject *kobj, struct device *dev, - char *buf) +static ssize_t device_api_show(struct mdev_type *mtype, + struct mdev_type_attribute *attr, char *buf) { return sprintf(buf, "%s\n", VFIO_DEVICE_API_PCI_STRING); }