From patchwork Tue Apr 6 19:40: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: 12185791 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 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 F2A15C43460 for ; Tue, 6 Apr 2021 19:40:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C3E67613DF for ; Tue, 6 Apr 2021 19:40:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235085AbhDFTk5 (ORCPT ); Tue, 6 Apr 2021 15:40:57 -0400 Received: from mail-bn7nam10on2075.outbound.protection.outlook.com ([40.107.92.75]:17062 "EHLO NAM10-BN7-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S234185AbhDFTk4 (ORCPT ); Tue, 6 Apr 2021 15:40:56 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=E2pB7Jmali0pSRayHDMfJ778tZc1x6b0LjIHvzTlkkuCFKG2xZ16tF3Lb9eNKSk5OeyeuzuTuud588XdUBRsv5E518apsZff5WgTdxSTGtMs0swZSEupdVWwYMJWXNMRYJ1amNIZQslsJp9hE/I52fzVcHG32fhEmSw08YhIIOx9I1pgr2jhZU2Sm66M1XA7zCZlvaXMRGKRM/1eOAQsO4S0egWhYvh+1bF6vQQF/3gCTLwv4PkTo1R/9a0dZ1IiE5FnXSlYdwX/EKG+AZ8emEdvbKfIuHIDb556tL9WlrnTgCZwNW9Zm06qWQlVUYg8RyE/T0w3TFwFwyEIHcB94Q== 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=jRKwuIDiB/9LGr712gfvhhC3/mHbTfvih7aqjvLh+bM=; b=Vi0Q/93dgJDy2+hp9qpDFopNl9vH+fEZBJQI/gBfhuJK65wO6UuxZEtp+Kt1Z3sRITsx12wlbsjDQKc3L6S+jv/3bPExQ6tyeFE9Tss9iuqT3WlxYmqMzMPG/LVavR+2U9byao/GYI6lUwUiia8wlDeSanKAOQ+2q2eIIki6zhk9MngzngI4qs6iVljQsGAAxy05qEx9v4CgL55v/CkCBY4hbjfS+QLqgTLLAiIXx1vVJAlHuucTfudyI/ecX1wUGH1mxvt1RHvLFt2eQxFZd3L9Xp7VWoP2TunxBz0uG0IG65vGsMKYRMmR7UkClKWoMp5nHcuPaJmj4jtiES7RNw== 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=jRKwuIDiB/9LGr712gfvhhC3/mHbTfvih7aqjvLh+bM=; b=LgA5OokNvoKMOb/lci/6IcdwwlQfFWN9nF3UKbskGifWL1cCaTz2H31NxxTf6vj8VdkN9ul5WqttwCYNq/JSTCud6aU/cjJ/ml9GIPO8ZjToVZkHxf0N9dKCjLuOwTq8QnnSbaFVGfF7DLnjykEn05Wvg+qlsAAC5WSqSTB8BcIg44yYm/3jRj8jrMdczJtr2tC/LrCGMDmUCu471cS5hIBV6cyBpgrnizkf3iVMKW57rbc6sg7969F3o7nzPiXVTXMYtg9sAk6eD4v4zFyom9ZaE7SRXabxSAbKQreMwGrd3UrR/MXkm0+k7eDucZZH7Hhqo9lG+lU5GvXHPzCe7Q== 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 DM6PR12MB2859.namprd12.prod.outlook.com (2603:10b6:5:15d::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.27; Tue, 6 Apr 2021 19:40: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.3999.032; Tue, 6 Apr 2021 19:40:43 +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 v2 01/18] vfio/mdev: Fix missing static's on MDEV_TYPE_ATTR's Date: Tue, 6 Apr 2021 16:40:24 -0300 Message-Id: <1-v2-d36939638fc6+d54-vfio2_jgg@nvidia.com> In-Reply-To: <0-v2-d36939638fc6+d54-vfio2_jgg@nvidia.com> References: X-Originating-IP: [142.162.115.133] X-ClientProxiedBy: BL1PR13CA0281.namprd13.prod.outlook.com (2603:10b6:208:2bc::16) 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 (142.162.115.133) by BL1PR13CA0281.namprd13.prod.outlook.com (2603:10b6:208:2bc::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.8 via Frontend Transport; Tue, 6 Apr 2021 19:40:42 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lTrZ3-001mWr-SG; Tue, 06 Apr 2021 16:40:41 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1d000c5f-37f3-444d-1d92-08d8f933dd9d X-MS-TrafficTypeDiagnostic: DM6PR12MB2859: 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: Lf86X3ZS/gVWpOJJMzLJ/bdJ6R19Z8lwJOx4YBrVIhY5doZEmY3KonlBaQO9Ug82SHUH9uOXlCmis3pHA7/CZ+mtt6+Sgshj9APwD1CRQRqhsbkUy7BWDZ+ODVbY0sClRX6CiyZWr4KPas01erYrKwiUjWRvcQhL0dEXqv5xDQfnQVjr3wLTIqg41hhyGb1htGsMehnfbNRx7FleEeBvGOQWtAfaQZqs3Mo5lSDRxy+KufvVsUW8pywe6CTHdpX2rACXPilAhlc8kCnkQzrKtHUqNkqC8VdUcs0A20PMezne9fUCROLxUapcB5urEBPgW/WnIG+VcztJjGkdWsvvSNH4qZFjOUZP4rH7rNIDVYa5FNkgI1cQuBLeOhtAs3GtDsGAiSCIVvlGz0n34NZTpVKgYo/7npglP9VXcswNDZSYKE0kKGPuMdjBrN7h/UsdZ07aYYXansOmWCnj+77F6XqusYrvI+hjcBy/BqJZnzZrmTV5CDC/AWfUs0b+PLyw0aeeMXy4i3l43PPgEtrc8ZHBM5EloXAGu/XNmfJxFm1/53phabCteAl3xCZ1IG2USVF7CnforwhFfy/8wFh3sneG7Z+c9K9rZDlH1yIxjmh2O8LLPXJ9nH2qRqvifRGEYS5rBKH0YZ3q2eXUhgwKh++TLNhTqjmEd+dj/K5vCREkG8vYgQ3mln1/xUDugtzg 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)(39860400002)(376002)(346002)(366004)(136003)(396003)(54906003)(86362001)(2616005)(26005)(8936002)(38100700001)(6862004)(66476007)(37006003)(426003)(66946007)(5660300002)(316002)(36756003)(66556008)(6636002)(2906002)(6666004)(107886003)(83380400001)(186003)(478600001)(4326008)(8676002)(9746002)(9786002)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: SgTnkydsReckRq+A6YCNPdgOaBlF5ozA+LRA43Lnt0CBwxDlnj2L82splB0BP/vhXD5Osbx+mjniJrfu9BZPPx1uSJDOHRp2dPsN4rpFiJ6Xc1WRtg1XqpPnNHrB+MCHzPXMT9YbpwP0eg9MAar/MEvcVt73tHhAFSpk9s5qNvSQY8bMmYy6vMC85ZEf/5MknTjMiPyMokIuROShvc/bAyOeKX6/NBaTqC/zOMncvv5Mtll8ZtUVzFbNJpenuXJqIm0LBcVUeBZNN0g7AoiDiDFu+vfX9iCbRL+InnKEy2trgCiaFZdS4TzN416PNUTb6CJJMJJzeXvCoz4uhVQwyBbWM+7faigPVleZWzjRDOkFDO9W7sXnRz28BOQ6zETTkV0xhRhJ2Mj9tBr3/Sss56bGpdNySzNq0UFPCfSePBO993tUk7eINubsTS67OYm5c0JUNjUjElRPehTkT+ZvkgLKCWa1jo5SQAFVwpaY0EbVkWfiQgMMQ/r0RF4R4TrZtsdrGe2cCcTNDel7gDQQT+oWub4zJZDa83Zm1biURD04DW1YgCBwadlwE0+Bc0WgjNRZW/2h8W5CM6Y1azFcp1nhi7RCbRi3xzrsJHUuBkWT36MVtfQl1gVWiuoIup1KsGJa9+57ADxZ8DvTmP0fF9cPBMEJMv8ckwyQ+/iB1pbT92+/UjVAvBAQ1aze37hokvLSbGWsjerZxAYKWh2wLMgMPBhMsexHOPHtLVyPOta4KrEULSL8sc9l9EOvtke/A12R5b5VvvV76p/thCv03VN4wn50zW6qZYaZXVdLKGIE/zuwfzy/4op5gC2RnqykmvxJiT9SY2V3CwfQJ//aa58qZ2ttSuqNbYftiLYfBgut2ECIlnQld80e3VdmdaVufHLKfxUSx9FvUUzP8UHa+ecB0Gr+ahfhuNs/xj69PjmjgbudQG0G/s9z4WH8zKrBj8dUyjNy+v3AeP8CGjUUyxQ0+IQT8FMvYnud1viO99vv56OBrxDBQ53jea+CxtTVXsS2tmsAdX3ssBRhAuphaozVRaTlM7P76z4x51wmaN62CdaRUprz9yuI1KxLvxrJu7qfUBmP376Cj/ODrD+TiXN7aHG8/wJ+QE6mq9sMHwE8TrCKt1JLBveEIZ4Uo2zbc4urhpKE1xtaa6XLxvkeV6hizcfJUDlltXjDWYxQ/DIxzfQqd07U+qY0wpRG0HGY0E3wd+zUmvbawe71bGJZd+if/gKKklU9GSgJqT8L44Ed0//1PLd51ZOpg29EKPYFD4CVrFsI+xTmBhsIbMTi9dcAwsOTezGDk2hb+UHDQN52k5OBrcaJORpKhRvswq3/dfv2tBzFdGPDA8XwCKhxig== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1d000c5f-37f3-444d-1d92-08d8f933dd9d X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Apr 2021 19:40:43.2633 (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: 2I37RVnG7WQLnzLcEEtFKkCCPsERgX1+qDOE7nChPE4EpeGvUUbyB9tqo59c8HFM X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB2859 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 Reviewed-by: Christoph Hellwig --- 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 Apr 6 19:40: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: 12185789 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 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 58DFDC433ED for ; Tue, 6 Apr 2021 19:40:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 111DA613DE for ; Tue, 6 Apr 2021 19:40:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234481AbhDFTk4 (ORCPT ); Tue, 6 Apr 2021 15:40:56 -0400 Received: from mail-bn7nam10on2075.outbound.protection.outlook.com ([40.107.92.75]:17062 "EHLO NAM10-BN7-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S233580AbhDFTkz (ORCPT ); Tue, 6 Apr 2021 15:40:55 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lSRq8ufvY5FLLF3OhLNODvrkjymq6zz0L+Ey47AAv6K698vxlQDSPYSZ9xK71cf13vI0rwQumrurYpatuuaFlAWHsZJxup/7Hb0h1C+U3/SOlG9CnBPYaprdf3BRWw53Bhosr33gLirNt6PZFBCTCrcL+a7gXa0QZv1AXEzf0djCvNGOdSrs0SEXkSHNrBL6esSprogpyeUenwJ6fUmqfCwWPrO7C5sa2oawGokC+ORoQo9EgB8xEgBMS1CzXG+A7KRIZwmtaS8EGb49wU4Oau2RTIWyH3mr+LMpJtQUZMLHKRdqm8MRyQikar0UQUYoH+YLrbZFXru+T/e/mTQ1sw== 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=bOJWN4xU4gR1K4Wp33Z1KyHP+Vcgdf0li6vbPshndkY=; b=jkQHiYlhTyyWMHlCojc7m9wAVa7f9HMtBaCDI+T5qNFbWdABlZDgCYREeikSjzxtoQpGLjYm/Vepq4NAy62sUEoiUjKrsMV2zliXNg1xruMM+OWg5qdZlKu1awaOVpxGIuZzFlEsikeUZO5ttZV/DRFopH9WS6E0Bz9dTIqzlWW/FwRn5ogtFr24303+msMk/i16prR+WsMx9ovb7UW0qn/SYezdsdhqJzFhgwqzWndjX/eE2tUTLv3US9QMYGEkqnsg1deg4mcM2f+G9bmWhif8JK/kLZHW1+/fb/TeUDREQhXsTEy/nMyh9bGDWTP6hm/ab2E1IbtyV/90O4PgdQ== 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=bOJWN4xU4gR1K4Wp33Z1KyHP+Vcgdf0li6vbPshndkY=; b=IAMZXDySMxdx0wfMx9g73tTh79GULDbd0/XOO50JycdpnG61Rf+JBgrE1fbayLbAh6EYViBInmnyzeK/+QxYHmqNxGVKspeBD6M8dhwsn+U8g9dXG8vR7ia8WR1tvyZGqIjeg2lwVuPg+fM/txSRGzcbNqZdxPFFL8lS7T+0GF3vVkjZMutlRYMUwzz15dx99WzdTNUemymtf82eGXLQwBlbfFEuAWQ1/2fPek0v719lmuBtboKSJnH+OkLDjUQyCPQEnFFXsck/lRxvWy5xBdrf7rmBSAP6ki6M2u/ibSEeNrc4roxTwEEWLPyY3MQ6Whq0KthAl6FPa8izJ5vt8Q== 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 DM6PR12MB2859.namprd12.prod.outlook.com (2603:10b6:5:15d::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.27; Tue, 6 Apr 2021 19:40: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.3999.032; Tue, 6 Apr 2021 19:40:44 +0000 From: Jason Gunthorpe To: kvm@vger.kernel.org Cc: Alex Williamson , "Raj, Ashok" , Dong Jia Shi , Neo Jia , Cornelia Huck , Dan Williams , Christoph Hellwig , Jike Song , Kevin Tian , Kirti Wankhede , Leon Romanovsky , Max Gurtovoy , Tarun Gupta Subject: [PATCH v2 02/18] vfio/mdev: Do not allow a mdev_type to have a NULL parent pointer Date: Tue, 6 Apr 2021 16:40:25 -0300 Message-Id: <2-v2-d36939638fc6+d54-vfio2_jgg@nvidia.com> In-Reply-To: <0-v2-d36939638fc6+d54-vfio2_jgg@nvidia.com> References: X-Originating-IP: [142.162.115.133] X-ClientProxiedBy: MN2PR16CA0021.namprd16.prod.outlook.com (2603:10b6:208:134::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 (142.162.115.133) by MN2PR16CA0021.namprd16.prod.outlook.com (2603:10b6:208:134::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16 via Frontend Transport; Tue, 6 Apr 2021 19:40:43 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lTrZ3-001mWw-Tc; Tue, 06 Apr 2021 16:40:41 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ca04e93c-c053-4ed8-9ee3-08d8f933dda9 X-MS-TrafficTypeDiagnostic: DM6PR12MB2859: 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: EWcKZaDywqUMQJs3qgdKJyGyfA/In3pqnErG1vmRnP49RVszkDMpK7LxQndxavP6GDvUhlw8f1QdKmqDaow4GKIgEUI8pHthXUfU+OfsB2N1/x+5LRPSvLL0nXTUSmCLA2OXpjTRnvY2Yr1PgX0Do1xqKVXvmNhzyUneUt0uZBYAcitzhejBaJ9M7/smLxqYtQOpdM0p033kFXorv+XKIHg/OM8xguuXHqW+1PWkJn3tsIGzehtHEoBLvzVvwMFS7AurzkokaIqOH9PVcGxzHTo6U6SCJRevwzBX+DNEfUC02sYWKLc0OJJPAW6yLQljVoTyxmI2XNRYBbm3lboftS8zDWeUFvLwIvHNt6yEYkoZndSTRoRRNrxkRa6ovRMtAfHAv1GJb4xMDbgy4LCFf0VD31xUMFzHuqehYwxa1siIufpbmHlJaddTwARteiyJsz/1xg1VJDRyhdgKKFFTvEVYjkrSqhecFnPHY7WX8Gc2CbYntzXSYuC4wOJsu8SO6+jZbqaYRAtAyyXsV318qj0fZf0eAi1xBa2IryiqGonrh8go8cLLGvTHtlnZWREihBocW0ZNo0DVOT0DcUhsRrJ8I9qVFAcny3B2zJPpXH0HQyxDhe8r2hMafBMsQ1cYcFpe18XjH++cQ8tLbMPr9LMynEthAkipMBQpdlk51zLAUKu4+1yBMJL6rEwvD2V/ 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)(39860400002)(376002)(346002)(366004)(136003)(396003)(54906003)(86362001)(6916009)(2616005)(26005)(8936002)(38100700001)(66476007)(426003)(66946007)(5660300002)(316002)(36756003)(66556008)(2906002)(6666004)(107886003)(83380400001)(186003)(478600001)(4326008)(8676002)(9746002)(9786002)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: PHuY36xmkiTovtL2g3Z84ups4GO9UH0ugnbX//Cyz+g5Tr0F/HlPV0qd9+VB9EoPEiDGEYmqJTaT2/VuaJr4VTFQSkVZgthp1wE73/ltJzM2c1iZL2W38rdCJRFtRw2aVYZSovF1NhM39kW2JQukFRvw7xJ9ZWB62BguG2/khxLLu8l4QlZThoXO9PUzI4K9yKHNfIPmT6UGTqCrlbowVCWugjpqneXKlb05UOobUYbrB6YUb30qu1pizvgqKtm6HsHBzDnLlKyHRxPS3IOVpBcgODqtabnxfJ3Kfy9S9Itp8jBIdtd0c2/fE4UAv9QIIaBx73ZMisc9OUOMYIaizHyqtUfgozlZiuZRfbIdNf6M0qnJY8xuTJmy0qe2UmvVMvq9Q3YMEY21ab+TInb0bDNAuLx9Z5Vp6ONGe8saRCBwKqkUbQrtacngp9ABjP6BAN23g3i+AXiUozWx79jlJiDS5TDcdvDMmgucWKaG/39MMs3/uuUDy7r1I9XB28GXb+xOtooriI/kCIV0N/Gr6aicfJotPIhvgK6IzcLynXm3VAfgkn3p/yZpZ+XzdpTQLEc//24rzW9zvz4uKqAtjop1zcJ4XpN3kI3w+6UMr1z+Qf6d2Y0nAAsnzv2KjcgkCN30Kx8HF/swtyH72/61vbk4zTzBRE5TY5ELNYvyjxCtzjnVstuqfo8J/oUGDyKVIAPUKRs0//+tPNVKL3vS/PHkmZgIiBxHEO4kC9ECvj/hyfLG+ywh9HII0tqk9CV0D1IR+zNSl42Na5CRE4p5mmM63oUERL3fWTGapbHDNewvln3H8p6eI/wXREDHQcOKAISXsq4VkkFlAucKN93dRfAz/0RMPvkqeAt/L2Hcf04UAwYMU7jgyWAEwSgwDBtXf581+lniL+CeKWssJfBDCAyOL/c/eJi/VkT+4k8a0AjV5P97Vn0u+l+UD7oHcIUfZCy7HSoU+uykHzsi43mqzI6bLwD69cfiNzlfrDe+vDTNsD93tQuvHjWQbqBD9X88v+VwrOVDiNBt41ccxazk10ihPI/dWEZdNeGQF3BUxhkHKpL9eGcdER7pFTmc2CO/HtDqgtiag6A9bk/omfr3Ow15mdNGDnSgX6wXUbcQ9F4PxfRFX1XY9sljjsw7I0gezekm/6lVqv3tkfglcrVlvqGMKlrTcFUMiS+a+q1YahMPcgUEsLR4fgnVSgpUdbMBWmhcJIg7vXXZ30bZ2nVP0FprupVp1tK/g3HoFYI/fMFESRvHvsxlK0cLLRk0+5U+X1cTY/PeBTVaKrUdR1Wmq72uLiF7So6kDmZmXcoYwc0bxLbKhIPA3yd4tLl1UfiCQeX/EWVt26KzSQg1wj+Rvg== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: ca04e93c-c053-4ed8-9ee3-08d8f933dda9 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Apr 2021 19:40:43.4712 (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: HS/0YhJGv4ysAj/xd79sLN1JZmcVdcPolAncNhg79FMsE1q875XRSuTozHq3I0Zc X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB2859 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") Reviewed-by: Christoph Hellwig Reviewed-by: Kevin Tian Reviewed-by: Max Gurtovoy Reviewed-by: Cornelia Huck Signed-off-by: Jason Gunthorpe --- 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 917fd84c1c6f24..367ff5412a3879 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 Apr 6 19:40: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: 12185809 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 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 616F6C43460 for ; Tue, 6 Apr 2021 19:41:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 39E8161158 for ; Tue, 6 Apr 2021 19:41:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244935AbhDFTlJ (ORCPT ); Tue, 6 Apr 2021 15:41:09 -0400 Received: from mail-eopbgr760073.outbound.protection.outlook.com ([40.107.76.73]:37142 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S244919AbhDFTlB (ORCPT ); Tue, 6 Apr 2021 15:41:01 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Q5tTlin1FPUd1t99bSg1c+jSW494OixGC1K7ySUAZ+CGO+QKuUBucJ3BHwH9ZWecAVBFP7yVpfPgl2DA7VW2BmTfcFnQpZLFYEr9wZYXd9LdColCsjOFBFm/0TvHDVSiNfK3H8/P/pQs5qmPozkMM9MUXxHEtTRt5KV6elPqysFjRI5ET3dHpFWUWS+pqC9AMeskyaIUKa2DUKjo616loWPB10ezwXXqAu6fmGjacWcisHow6JUx+pBgSjQbbqosZi16fS8IYTKYsmQi+S03rksLuSKr70qFSkQpyFXS/bQmVBLDFUvMhv+h5RoRLR2uaSnp6O94HzyqBTy4eCmYPA== 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=0FQj00VVNg6rlFwj6jhe1iw9BZC/IV+c6ye6Z6XpS20=; b=aau8rw4gtfPfYnHmDXz1QTRoC8p5fjrc+uJLuwX+bn4VZQTxppbMLDWdys82cO6JGCYGbs2wrNWEbVIz71lMtQiWgHW+fovND++E/NVQDrGviGhaXp+bTUDs8eobIkUf/QEtbXLqJw0PBeigNFvxtuJq648aWCuPSkrfiMypJC82JY5TliKhycA9tdoGxeYpco7mi851bmodfV/L6AJhQc2Qj28BvgzmUt2WLg4oWNLhByvR7zSUW6C3TV+7E6QNgEFpPSztOw7QyhydO9XSbUW1RibtQCpN7OpgvOUbDetwaaA6piVd7gfojUa8iqvsDuI9B4NCJN9oNw1OkMSSIA== 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=0FQj00VVNg6rlFwj6jhe1iw9BZC/IV+c6ye6Z6XpS20=; b=g1uzu8DQ2VaRXrzn1YCzcwbTdV+YW1kjJSNwVd2x9TDSI5Pnu8V3ZITYx1MylyBRZzOoo/MbPZViYJyr4aQqwesGe63N/RQZBbrU7mvR0/wCRTZWw/BhDACDdSIbHAHp/kmtZbB8vxiw3cUqmDZSG10TXHjgBTjF3jK7EGCPdR7CWquwa+q6+X4d7ipBrYO1ZAzmVh9bSGTPiFbzuMd3K5heB1iWrcP/8t+HbeOJLUuGG0wsh9WRUMsBWcxUX5O3VNDPLL/sa28u3R4XrbjZqRmi/RbJM83Q0Fbw7BxC1LefAifXYxkTSeqDPhSRbHwPAjw3yggcDgTK/anwTp9VlQ== 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 DM5PR12MB1546.namprd12.prod.outlook.com (2603:10b6:4:8::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16; Tue, 6 Apr 2021 19:40:52 +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.3999.032; Tue, 6 Apr 2021 19:40:51 +0000 From: Jason Gunthorpe To: Alex Williamson , Jonathan Corbet , kvm@vger.kernel.org, Kirti Wankhede , linux-doc@vger.kernel.org Cc: "Raj, Ashok" , Cornelia Huck , Dan Williams , Christoph Hellwig , Kevin Tian , Leon Romanovsky , Max Gurtovoy , Tarun Gupta Subject: [PATCH v2 03/18] vfio/mdev: Add missing typesafety around mdev_device Date: Tue, 6 Apr 2021 16:40:26 -0300 Message-Id: <3-v2-d36939638fc6+d54-vfio2_jgg@nvidia.com> In-Reply-To: <0-v2-d36939638fc6+d54-vfio2_jgg@nvidia.com> References: X-Originating-IP: [142.162.115.133] X-ClientProxiedBy: MN2PR16CA0014.namprd16.prod.outlook.com (2603:10b6:208:134::27) 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 (142.162.115.133) by MN2PR16CA0014.namprd16.prod.outlook.com (2603:10b6:208:134::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.27 via Frontend Transport; Tue, 6 Apr 2021 19:40:47 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lTrZ3-001mX0-Uf; Tue, 06 Apr 2021 16:40:41 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 401a96d6-dba8-4aa4-8ebf-08d8f933e013 X-MS-TrafficTypeDiagnostic: DM5PR12MB1546: 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: XtRAI6XCe5057WVp/d/PjuXdLVcerwuui4H2Qh/NF9q63LzI77UwVsCTqzrRM83rB/jt1/xg+WsV7v59jfma9lQzXI925/Z5qNCD8kgW1efDkBFfkCb4h35ELjnvhCXUzh9IS1RovEEATcdXYuW5auH2n8u+dPVfzbxRYO8PQFtY6W6rykZXk4x4venqzRy30x6b4oMwZmouCDhAntewuDJachxSErO7fnou46qWsXZUqUOBkZ3yDccPFNQNuGjLB9TI7HJgFiNv0bdi227YJQJhKQkdFYRCkoeZpv0rpJKvJ1eZGs/8DTn7Jqq+QXGYVJPRWlaXIha/lSKsGKeLCM7V5TWgpzb4tsfOHcuWncSDIXSmgVtt9ku7r5jGvDSQlJrG2oSUgfTwMAUKRVIBXJhqJKK2a3ucRfjhNrYevrxSlOOahHqd/ceAi/YzhuZm9OH1aYJQ/I8/YKn3Am8FDqHs3gdmg8AqTRgRvd7aj3wX32FkdGlHvw9cHxqqBPUVEZmqhy+qyKtg5ZAh91/1ygeTqFtNDmLcbP2UO/y8skI9xG6ikkn8FMl6s+/O1lXowalSc/ENNVRev1SjgAAzvDAU8q9bgSY8NV0Oo0cBtNmpZ8qpSU8/zOYYUxW5KQbqvXOyjxSQl1r92+ezdlOLyLYc99oXl1F7GwZ8v1EK0ooAHDkpSBiN5py9ki7FSxJl 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)(346002)(39860400002)(376002)(366004)(316002)(86362001)(5660300002)(8676002)(186003)(66946007)(4326008)(8936002)(66556008)(66476007)(2906002)(30864003)(38100700001)(83380400001)(9786002)(478600001)(54906003)(426003)(36756003)(9746002)(2616005)(6666004)(110136005)(107886003)(26005)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: p9V3rMW8D3dCqc1kUxPuCStRfyhXlJBVghP12yLeOa1+LhMhd0p3+7L7dooG9iuMqsPSHkfWkcRLV0aTuR/Nkjo6+m2MEigqE7gEyL1ikTJFC3x4xp88z3JJIbJd8ivTwt1RG/1XaZ1JBXt7hEXjhO0LWzGeadrfaHTfGuykAMoc1EI5O8WplXJiDjo9xMPts3mPTAJEECQO88CokSgQ9xkFl0N4L3vb/txufy7ECzl7T+QdPYT4jlYZyWPCZdPsmxEyoOWXP8xkAtOMGbDOZTGUzs8lsv4PHxSX9rIxzeR/lHTybk8Wyp/7jOvwL4qz4/zwMOj6/FMkAEVFl1OZrgYhvWznwPfY7YODW7JtZbWz9t6PnzPslezwDpkrgDZYfNKB/l/LKMwwE4w425Kf3X75OIYKd/SsxBw7ut5Nq7IcLbCYfI2K8muSM3ZVqxk1/LLIae1h57oirFg98NIiA6QsCb3Vqdc2/bJJuKu15mCCG2DxtLFXivWe9oJC3TNXohkGk4qtlT6621ifO1Pr4ddsnG6sM2DanPaYkWbBPdGq6Ygadv3mP2kxO+lHavwk2tFcVBLtK/53TRY/w5vCouJSbp/M+xJKLid4pZRxt13MlK/foX9XzcqQ/9HaIQ0xVUX/occ01TNt3iOSrWDj8HbuwMiOzIYqMG0I8/1G5euuUHPPn0xh0OPdYY0QUFF6wDTP/z7553WiJK9xxHZsjuXoGL8Xt48QhL/wjaTLVXHBgY4JJaGwwHeqy8geV4jOtM1lwjXDJdtcSHNdsT+e9OUWhOdBuyDNEewxrYKIFoM3z8vRr/PLv0axq8VvUAtBnSy6MN76pyhL3BXNzut1Xy0GZYLSZuBwb5aOOlApdrwwjOErZMDhLS6I/uIFkwF25Yp+i7ZWZjzCcjNk7sRVmHDamjooG/yljPEPtq0JPoRgJTSatXjnNvc1vV0K2neAloYi4t5Xn8+bFywUndOIGp22umKH06itos43vkP4jD5XpWvg4EXYH3p2s+Hn1fnR0+zzd+YY9Xs9pFA3OqzBd5eyk7XQW5bxOEFwRiy5lhpp35DozUWJduLSU9A2qxbWnCBD97EbAnGYhhQ26Jt2hbYfXmfVCklqEjaWAQjYg2Dbstw8AXz45SPwHSwYw7jIbG8jOJuatnzgNJJCPLP/tvAUoVuyP/HojmTFBqWhkZqUHhLMGfHCVvtszXObiuU+YCD+VFDQQoU2U8Aw3kNAgPfYAM8vkc7m4ynV+HHxjQ6vQRAu+/bPf3p5g5yyJMhEUbjb4/v4EicGW/vQEV2/nrKE5yBBDvmjvRGNSELqweeJDVLWo8O7TwnsMStoQYadswFzHyGt0F6ClGIsmG+0Qw== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 401a96d6-dba8-4aa4-8ebf-08d8f933e013 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Apr 2021 19:40:47.8357 (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: TsbparaVvv0Ss7Fimx2EbOWg09ae59KpNrt5YopQal7+Bd186+anuEj2TtunpNaO X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1546 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. Reviewed-by: Kevin Tian Reviewed-by: Cornelia Huck Signed-off-by: Jason Gunthorpe Reviewed-by: Christoph Hellwig --- .../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 367ff5412a3879..18114f3e090a2a 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 be444407664af7..51749b73075885 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -1927,28 +1927,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); @@ -1961,10 +1946,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); @@ -2012,9 +1998,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 Apr 6 19:40: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: 12185813 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 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 9A2C3C433B4 for ; Tue, 6 Apr 2021 19:41:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 74E72613DE for ; Tue, 6 Apr 2021 19:41:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244939AbhDFTlN (ORCPT ); Tue, 6 Apr 2021 15:41:13 -0400 Received: from mail-bn8nam11on2061.outbound.protection.outlook.com ([40.107.236.61]:28513 "EHLO NAM11-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S244933AbhDFTlD (ORCPT ); Tue, 6 Apr 2021 15:41:03 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Y0qNXX4b7Bi0lFOBCKYyQe1u6UJrJO/KYg0tmY1YuKACoZPeuJt5pdHKrq+O1bqfQS5SdjhB3F5fNVsMkl8JaX00OH2Uqbha/pRSTJsMTil4qKf5C+u4syXcfLEDubTOnDAtfISf6+srUkMzOYVnNZLksBM5ZGfcgYJ1WO7qzUImKdAkYc1g3wWlfu+iHyzqpvMUoIg92XHiJQ09ZaIIUJmumTOy3by/oggrMcyVwV5NrsFiJSKiwTK+sAVqhzjGewmTtZrU+3F2vZXHPVZdp6kjKhM65eGb3RJlIoMqH3Z2rnv63JreWJ8zkZZFMyrTRZAPYIAx2KeJ1ziTWV+yjQ== 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=frn6N4i+YIjRyVdYhcrr5xAtvOnEgR1psIwGgwgPxCA=; b=h63i/e6Qk7k2b8txjI23TMvGnDSCT7SrBgbz7oR60Nx+wT1KSOBtVHgA+yTnDWvWKPg638DXQyjuFqwOJTUXI42U7U6WiEXgy63xMzavGoFBDdXRA+Z2cRXapZURGqs1d3dHmMO6vxJ8GOIBkPAukA3xmKjIJjd7Hjip4n1Vb1SXxmbWGFDS9rFLShqjw1NXS2J6VLgbxF1stvNcyogb32Cl2blhbfB70eV0DnZDq3f174NcfNTok6J223OzFXJ39jLO/HjQ3E1jgFXRmfSXq342zdOaXUjMJTfXta1O6eTM6i2825skZ5pJS9OP/Fcc3LsTwW/PEfVHRId1IpYMsw== 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=frn6N4i+YIjRyVdYhcrr5xAtvOnEgR1psIwGgwgPxCA=; b=pyRTn0hB64stbWdIK9jFkF+cOdG/K7txVtXTKaVvZB2+KGYsDe4f64RrW62M/OZILhigAafnduFf0h8ygoVEO7H6nAP62ubcLi8+XLYeQNriqWEHeQMhZu+jJkBPci6EwSpx/RNoyFZItR+L+ZVdWbmqCw0H8XqFEnghcYsjCQs5w0Ydq9yZKLxPJKTT0hktlKTqO7djeZORLfcYK5fu5U4yjN91JWf9cCCK4kN8nEaNSriZgi0O8P03ES+eOtdIRN7LD90jdo0Yer5HdXwSJekM4mxqLyCEJHLIcc3k7ZdMHIjgtRofnJcnb8gDy04TMre8JcO+i13vCX33Z7k+bA== 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 DM6PR12MB4235.namprd12.prod.outlook.com (2603:10b6:5:220::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.27; Tue, 6 Apr 2021 19:40:52 +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.3999.032; Tue, 6 Apr 2021 19:40:52 +0000 From: Jason Gunthorpe To: Alex Williamson , Jonathan Corbet , kvm@vger.kernel.org, Kirti Wankhede , linux-doc@vger.kernel.org Cc: "Raj, Ashok" , Cornelia Huck , Dan Williams , Christoph Hellwig , Kevin Tian , Leon Romanovsky , Max Gurtovoy , Tarun Gupta Subject: [PATCH v2 04/18] vfio/mdev: Simplify driver registration Date: Tue, 6 Apr 2021 16:40:27 -0300 Message-Id: <4-v2-d36939638fc6+d54-vfio2_jgg@nvidia.com> In-Reply-To: <0-v2-d36939638fc6+d54-vfio2_jgg@nvidia.com> References: X-Originating-IP: [142.162.115.133] X-ClientProxiedBy: MN2PR16CA0034.namprd16.prod.outlook.com (2603:10b6:208:134::47) 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 (142.162.115.133) by MN2PR16CA0034.namprd16.prod.outlook.com (2603:10b6:208:134::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16 via Frontend Transport; Tue, 6 Apr 2021 19:40:48 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lTrZ3-001mX4-WC; Tue, 06 Apr 2021 16:40:42 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 607cc7b5-b3a3-4908-c5ed-08d8f933e123 X-MS-TrafficTypeDiagnostic: DM6PR12MB4235: 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: 72G2QqYTZo1tK8SJkQvEK7+k+BtNOKtKzLcpLcE1L8JJ7Un2eAt8zLav4kf87yfrypXMVRUetv8kE8aSk2k/2kMgqSGvpcOYuPPSl4I9rCyZ/KUprFiwW4XLzurbBChaLhekrSylJm40NB8z7V+zmI08RC69bZZcV2YFVDB3V8MawynetwrjV8PLMyVx05SVO9S0e6RP4n8v466G2ZERFGtGSk9qephHT/1jnNz2RNfvwXNXAUsBIDd539RV87JHMIolystmfv7Q7+Wl8p7ED7tvqu2xAPW9M5M4bKz/tbh98fee2jKDb8vTyE9dTl3cMyKVjIZ0bYMnCiPFEo/9KyEGXypPrJaPTHualYrjhVenvhihCq9NLiXiSgrY4nVQrF8QVLuo/Gsxj/LOxDlfZA1kaQjROgp7x03xs0czTK01HgD8gV9ImCM5JLrNcbt1H/wALDoXOahJoACI8ahoNsVllSerJOolPoRWwVUtMZQTKLcVFrsSsPd+hd9Q8+lFuReaoUfgcUrU8WWgu39pBMD0njnz1WqsWOO3HTFNf5UoOBeKk2Uk9tQXjlbKm+C40nB/aHrrCl0R+VWN8wnQvgtOR4vLO/ut80SS+FnQW0IdTs8+2CO5qhOw3JxVfnbLGCKIhwsTzVN4AzjceeQCqFDW8RESikEobTBbWVTqaqKeHsta5FtHWPvDq/TNHe26 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)(346002)(376002)(366004)(396003)(136003)(39860400002)(478600001)(54906003)(8676002)(2906002)(86362001)(66556008)(83380400001)(6666004)(5660300002)(38100700001)(8936002)(2616005)(66476007)(316002)(426003)(110136005)(107886003)(36756003)(26005)(9786002)(9746002)(186003)(66946007)(4326008)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: zFgZMD+7ZTRVXNQqt2yWTiKv62cPgvriLBb8GtxaRISTDbQM/ef4olYtsoWJfEe4QX0OK1MgwmZsLQCPiVtqKBvjWWSRwlzUj4Bpea/jqKhLy+kr2ig8IxzwqD8Ahe9AmagxvTddRakM46Qh2BAGOR2WpQa7pjNOyV8uMR4IzwiYXzphiNEzcdK2g6EMA+xztq7t0RE3oDTUPvwi07l3MRKVBPBjPACwFRWfDGC/XUl3k3+poBf7Iro6Tf6SrNBp/LqOK9NytAcFE81k9PCXzMv2ym6X/ZoydevVUJQFVdZ8MYwltOqkLiYPjfpDZgzEWafoEoADVHDn1sPI9733EH/PVTJfkJzI/UXDUeiYRbE2vTUJoTXH+Hj94KX9PYhJAmxVsEL/PEQ4kmo1fyIHaUFDFeBm5LaHsvfG0TrAFKrUUaKiH43uxwhfDl4mTd70Y1ww1VkVf8Y3mwQXgb/H9ydrxjDpa0DJRvSzv4GNTHBn01K3FeaiIMNhLAZQs8Z9dZeMkg9zisvUkFdItzmSo9WWEMVJTB9uVmlxtJ0v0RrWghrQ9TUh6rrK6PhD0vZeXkDKcUMA4AqfOiTCm7AY4owDQHu4gpqm3kbnVTvdek7ljekliPz0Oy1d/9qjXvAiaMgpKBR0AK/KkVpO3BLQ87uGN/wFa4XliGefCiX7O+ltqyyoV4mIA8Xe68OKj/fj/W7CaDJiqCpsNKdig+m/FOqoxqu+JoIZicADH4K2EpvM/MJagk3RITM6jgFNUOsLxXYjZiEKS/2EuzPlRvaZwgzAw1Zw0MPScwBpP4ZB/5UrumIL2Qapkvui5fKLZYmFodGIUw4l7ip70A5NvU2WV2mPjgZ/K+SqA2Py8RZdRBHcXFX50r/ZP0gMD+vtWBV38Hz5WF50CHE5gy37znUIbf5HX5UyjcaXesyZyzDAmQh4g1CPsEMRcRphKj90yC9i9cLgx+y873dfv9En6BF7w3Uf9iQWRM99zcW0aPd5EnegmIOP9hI5IobFBEotYHC8pTLKTApGQQ/rhbV4XDlDRH2ABGzJQKsIeevaKea3lTAnU0futtk6GfLn9B0qDhWyQTBtE1vF5VDMoG5+nvxEgMUnAJ93DYJrSC0oCBf/rgWOA7JWVoWh5gSrNdHmGbTj+wyz2sqEAqHCjEyGHmtvqCxSL8q2hOkZEWkW/2OpyeNhVo/SgtBOZlpPNSLluHL4VOxlc5KSlslzgsbHmIcFzodXJPSARX06GxWrNTwYPPuJzPt1I+XcApfJpdwCgo4SeedDua6WycOJE2V7roUcbTIO4RedTl5FO99gHjFGMlvkFbu0JrTkGiy7lq6EA1C5O1/210J7/2pejTPiQzFVPg== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 607cc7b5-b3a3-4908-c5ed-08d8f933e123 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Apr 2021 19:40:49.4168 (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: AWVZmTcGfsYIHpsNnT6NHPmZ6rFymshZ/zKCi0gRYVCvhKmN1SvjyAiKTLlpJ2qr X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4235 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. Reviewed-by: Christoph Hellwig Reviewed-by: Kevin Tian Reviewed-by: Cornelia Huck Signed-off-by: Jason Gunthorpe --- 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 Apr 6 19:40: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: 12185843 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 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 53081C433B4 for ; Tue, 6 Apr 2021 20:07:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 25AAE613CF for ; Tue, 6 Apr 2021 20:07:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347163AbhDFUHp (ORCPT ); Tue, 6 Apr 2021 16:07:45 -0400 Received: from mail-bn8nam11on2053.outbound.protection.outlook.com ([40.107.236.53]:34721 "EHLO NAM11-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1347152AbhDFUHk (ORCPT ); Tue, 6 Apr 2021 16:07:40 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=N+3mZx1ik3emvqw7AkGcOEbMnxs/1x0pvVovKVm0N8UeIuO7KEb+iAAKN+zRKW1bjQQlOpWPxeJK3+Sf3xnHX4/Mi/e8EZ9J/WcYdJSP6165UrzutdHame0pL1h1pLWXymXEuhNyilrTjDDwZQdJOj0RC91rp1r9/lZDduIsio7/nJzTTXRqRjCxRCMpLFQk7qNc7yVn/Ucuvv9TsCw8wByRf3+QKFi8e0+fWtWw5l32hddCoNPT/Pk4li4jhwsxjJEI68IX3t4cCBQZD7k/nh3AYoKxTtz/MsUTaMMNSZ/Bc2hf5WDyqlsic8m2ai8NN1ZNHL7EwI9Ry6sV+VgT5w== 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=UI/atQnQogvyBJhXJaBBwTUAQKs19OgDMKMYAcuZY8o=; b=XVA2IOMCq84dYXgGaT4J3Lgxy1HfKH7PiVpD6Exwr+vv04uIAprlSo70qIkYKNTrSTlVajGz0f9cIf9MvN6jsGdGBSP5G/4LxMi7hKsn9alDBsNzTEw1eFJxBH4oEumbRKm45qeozEPm1hgkdPXbtpFxJN5XGF7Grt4xOQCZX7xYr7/x3xMKPvswtBz1156CX9ccqKq4Qz9IlRqjW+r2hdfW+zLCM10qdvw7FtHkugYwwAzQD8DIRWabtAiHSEQbdae5iZO4oDDehtoCcdaZ8l8hBuwoZFPaOEmtkSYTG3KMpU4LAUlIwNUGjQjGyjuWSw9k1db9DaUR/K0hiBVq0w== 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=UI/atQnQogvyBJhXJaBBwTUAQKs19OgDMKMYAcuZY8o=; b=YGD6YALCxlOPfGF3KxhNsv9y4/OjpdCFwVLYRnaewL/mj/LVjOK9bhrEOJNzsl9WsfqetCEdHciWGTn5tagr9/XprhMpUmoym6uOnneUx9kVYUyPtyM+JXDXC1wM4gAscynf6iB08pnM6L39cgyNutlv+EDWyp76pd1SkGrJi2WqIrOMx2K57ZKHiGfbTHJxPF6WES++HlqFakFr+MhdmTTCZmeylNc17AP4fC/fv7P2e0oYkUBbTIRYgRXOPc5EMTkSLN7ci71DdEN9APnsc2pGzlIP0b+jcieZQ5QTz43sOmDDLu681RJnrvlJe9mi4FoI94oMAlXWlDryLVqCtQ== 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 DM5PR12MB1883.namprd12.prod.outlook.com (2603:10b6:3:113::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.27; Tue, 6 Apr 2021 20:07:29 +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.3999.032; Tue, 6 Apr 2021 20:07:29 +0000 From: Jason Gunthorpe To: Alex Williamson , kvm@vger.kernel.org, Kirti Wankhede Cc: "Raj, Ashok" , Cornelia Huck , Dan Williams , Christoph Hellwig , Kevin Tian , Leon Romanovsky , Max Gurtovoy , Tarun Gupta Subject: [PATCH v2 05/18] vfio/mdev: Use struct mdev_type in struct mdev_device Date: Tue, 6 Apr 2021 16:40:28 -0300 Message-Id: <5-v2-d36939638fc6+d54-vfio2_jgg@nvidia.com> In-Reply-To: <0-v2-d36939638fc6+d54-vfio2_jgg@nvidia.com> References: X-Originating-IP: [142.162.115.133] X-ClientProxiedBy: MN2PR08CA0001.namprd08.prod.outlook.com (2603:10b6:208:239::6) 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 (142.162.115.133) by MN2PR08CA0001.namprd08.prod.outlook.com (2603:10b6:208:239::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16 via Frontend Transport; Tue, 6 Apr 2021 20:07:29 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lTrZ4-001mX8-1e; Tue, 06 Apr 2021 16:40:42 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 71dffbda-dad4-491a-234b-08d8f9379b00 X-MS-TrafficTypeDiagnostic: DM5PR12MB1883: 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: dWpoB+3c0wGaZxSiRFhsJPU7A7UDFy62LP6Lw1ZXaMm3ju/xeXoWg1olbrksfk/JFjI4AZJc4Lrmxro5+C2YE00CbDpK8LRxVekOGr+VWjFaAUOvfeJaxXRuRU99GEIV5rwtom8P2l6V3NlR08woI/5Y9bzwj3iQwmtCkz8D/Zg1m7cVVBv2vO0zXdDasOjVFxqxg/b97j+CGk5i9rLalnOcF4peZ8yQdFwTkmmA4B8fYz0m1tMubLTGbcCOZ31/CqzKzONeTzVVAs+XpLHe18XiUGxOUj4nJlY6zHbqS9h5+zLabSmxVWKmg5N5U/xmhJ1sSRltw+NMTIY1PUZX9AGpOaqao6Y2A9PAyIRuduaDpP15QkDdA6UHibIY2iq27tKeqCvw03wz/Tzk3J2+7aUPSbKmsLLcUpatKSIvYhOCaZNwwwJF8TyVkz8gxmIk3aYXIDdw1GS6DIAovOCYvZ2zuPc1Y6w27WjzqoZV46CB/kmeGkxafqtk/+wjkR1lGXvG5b9HKr9y6eCT9yWBcQDwg2KBjhZoBUkA3JZCQHhDnqYHPSTAai0DACshWtAKBwX2uEoNvVut183dL4QKSxcAuTVhANqU4JrzySHhaquKQDuLpUpnzZEZc0mptjwu/YgLsj3o82Bbx7r7FLpxMIc8jAKhX/KazjhOEj7gfBD781R/3UMGV7Hh1z6aMwcr 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)(39860400002)(366004)(346002)(396003)(6666004)(6636002)(38100700001)(186003)(86362001)(8676002)(8936002)(2906002)(2616005)(316002)(54906003)(478600001)(110136005)(9746002)(83380400001)(26005)(66556008)(5660300002)(66946007)(107886003)(9786002)(4326008)(36756003)(426003)(66476007)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: g4cvrWtDRm326ZEwOkADKEnzDr2bvPh3TNDJVNechh93V9ri2HE4hUT8vrmYzqrnhHblkE9FdryUt3QZIn7P49iM6MMRJQoZhZOBpD4A/U7RTQ53AONp5LkKchOgFE3BF1RCpwa2eu6cEjRpx00aCzDhqLayPDPQZJqFUmxtJW11jTWcf8uTI9cbjW27Qb3na5QOT+Tj2tvCKo/NI4sYreJyoHCHtxUnnZXFEO6ahW+Pqi5RWyVrYkUYJSoGp/ETACRpzty7uYaADLE/ilg2k40uMPMxcujBdx9M7FCcquVCXDlYJtW5bXpPUiZpZQjafg7pPIC+7qvRE7Q0E42YusWGxWfsefS0qrGhjwbDF9q4qup6vcvMPHumwiGXMQQoMxYBaSUPDE5vjUZzvCgTGRDgzcWWuHZQtQMbFx50IXHA8n2tAdpd5H/Yf5q+m7i8ruCNTSUl9NCpxDzBYBFljqqohuYKBG36ZtAaQgemSIoJVmZno47WBgmX+kTItiddPF2cAmYII28fczJOKVGpQYFcmSinxCs+rqRf2rZMs6d8c21DWnL/25/1g+B2K1dJ1NwmcXvbDVsqCeDBNlGbkVEoQZO3ZW5ISk13jui/u1XBRj2b1t+Mfar+cuedF3YdqmqO/ENHJWOhFmlgL+qVa0ezOVp4j3eUemH2kKHK2X33Rsrx8nt1gzcsKk9Yvf5gjoa//z6+jgm/b5844pG8fv6NKEUsXWTynB/xTRVFAx6oztVGDFbfjLDdVf+P9RPQJIvVs37uSIjlzRjsKsIY5tVo9LhOROP2HFblDz+SreOiMbG/CQrUgDiJKdEDEgqvvUKoLx5YgrgzJfWWdW8PgOCEFW4feFPEhYzav2eVhBeFPgT/BrSlhoV198pzNoL+1o+UheYC7h3QpaB7VPFXJp3CEiQ1K0CxOhiO5IyIZuXEnm9RbdChDp7+D1QueQFlrWV9Bs+4GKT7jJf21JspcVkemXLHZOcXtEalyltJTRfn6qB0BZ03bgnWms5y4TEIGXb1M5tyaqVmghVU71guWqqb/6PGWB1sztOzcrfp3sG+HuxNNyPsTtYnykX8q0Lk/Za+mdIdqt7x+QnbMrxPSijkHCcXoIpleFjZTB+s83gmUYMTEw58QbjCWMv5ErpZ0+4JttfxpQ6Y9djPO8xZNeWGjTWj4Adqxg5Nw1yGpDiZ7lni+f8bq9FXx3O5avvYI2+qdywmxvLweYomgp1aweFgTH8bRbjugqeUFg7A4DIrKxS2mHHlU+KtaXpu+ICQgw6qwNwDI4fxDlhSh7lcTq12K217dsvBRI6VmbTw/UkzNwsS+qTMzIA0LnRbfJdW491pXD2MmWO+IIYyklFYmg== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 71dffbda-dad4-491a-234b-08d8f9379b00 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Apr 2021 20:07:29.3979 (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: lmjD6GDJy/UD+TnDyIGDxnZL4r4pGnrdrCTblZHK4gvH/W2rRjHibFWmqcjLSfrJ X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1883 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. Reviewed-by: Christoph Hellwig Reviewed-by: Kevin Tian Reviewed-by: Cornelia Huck Signed-off-by: Jason Gunthorpe --- drivers/vfio/mdev/mdev_core.c | 16 ++++++---------- drivers/vfio/mdev/mdev_private.h | 7 +++---- drivers/vfio/mdev/mdev_sysfs.c | 11 ++++++----- include/linux/mdev.h | 4 +++- 4 files changed, 18 insertions(+), 20 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 18114f3e090a2a..bcfe48d56e8a9e 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,8 +249,9 @@ 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 mdev_type *type = mdev->type; struct kobject *kobj = &mdev->dev.kobj; int ret; @@ -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 Apr 6 19:40: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: 12185799 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 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 4CC70C4360C for ; Tue, 6 Apr 2021 19:40:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0F4BB613DE for ; Tue, 6 Apr 2021 19:40:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242771AbhDFTlB (ORCPT ); Tue, 6 Apr 2021 15:41:01 -0400 Received: from mail-bn8nam11on2061.outbound.protection.outlook.com ([40.107.236.61]:28513 "EHLO NAM11-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S235234AbhDFTk6 (ORCPT ); Tue, 6 Apr 2021 15:40:58 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DF8Z7pUWlY95h2fa4EacFZN5SmhKZgd1w8xwSxZoq/lWOjux1WejBVE5lKCycZVLdOh8PKQanMxJR+u2N/mZm84hLW8pA2ocYR2XkQafxKxeVudkb+d7c9CPzTm4MLBPS3rNugEp8ThLI7Otj15ERIPHB6RYiuVq8BocH63TE6GHzNJulwy0MHacFMthZegQirV/BOp9ecGntsSb4iyr7fzriGMuxiK6B8HuoOTxzs+doKk8XM92hhhQ2PbVz2ve+5u9eh9HxQD/Pauk/ox0CAI08HTlc95s2cEBFiKxO3AksTSU6cW4B3L+UrZSgAQqM3Ze/CFb6LGp1FUp0GaUHw== 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=0EThwu+N8z8edP7jiWd3LH+J3xAYs2vWsRfmw4C+N8c=; b=nSMNDx4DaefATUtwL6/aK25QRVlAHJpC5tzWctaTB/5+dT9bf1uhPJbAn/za+iMlkr399ri/pvXYth9EhLJZ8tplSs7mSP0E8Wsep4HNnVsMFQNVS815RQmMl4Kfg1FJsA1hJrbxHdZzJ2zCFZFxRwH90O4/MTK4SlKU/OTNhHJWB8ygtfRhFuJhDnJA33SZVAPTD0NG9BytvStNbdj9RDv0T3cuovFDQGhaGhVSYanm5wqO4bLVnMyewedxUW/om2y2VAbnJ5HOc+zDCtvKpDfSrEwBmqD+zn2jv4ldOaGl6rHTkHpGESakWmn3Zvdq04RT01c8742TUPf2ja0Shw== 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=0EThwu+N8z8edP7jiWd3LH+J3xAYs2vWsRfmw4C+N8c=; b=EqOVsExl+sXx2kVOJnhsFfB389dVRe2sXNEMvAKMC6PbNZcZ7KFjrjxkE3oEwLeSG3fECFv4KuiUcuJqK60caEKyajqIAl1ZYHihRL1g/13yDn9M9RxHDQuaK9Y7Fiak2GcG4b4Meswx0mikpAra/JCf02QsewLhcMTA2gdM41GampAhbmKyEDQrvUFAUc30AQomvBacQV6eT/00hDGne44LulEAWhmI7NZIawjl01bU4r2QJet7+Usw4NrM51ZG+gI1i0sRY2So+Ej5EzkhSsolPNDedRf4Y/iZFatHG1d40wfmgfSFu1ruCJeCYmbv6eG+YGgZhU5Rcvq1n0w/sw== 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 DM6PR12MB4235.namprd12.prod.outlook.com (2603:10b6:5:220::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.27; Tue, 6 Apr 2021 19:40:48 +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.3999.032; Tue, 6 Apr 2021 19:40:48 +0000 From: Jason Gunthorpe To: Alex Williamson , kvm@vger.kernel.org, Kirti Wankhede Cc: "Raj, Ashok" , Cornelia Huck , Dan Williams , Christoph Hellwig , Kevin Tian , Leon Romanovsky , Max Gurtovoy , Tarun Gupta Subject: [PATCH v2 06/18] vfio/mdev: Expose mdev_get/put_parent to mdev_private.h Date: Tue, 6 Apr 2021 16:40:29 -0300 Message-Id: <6-v2-d36939638fc6+d54-vfio2_jgg@nvidia.com> In-Reply-To: <0-v2-d36939638fc6+d54-vfio2_jgg@nvidia.com> References: X-Originating-IP: [142.162.115.133] X-ClientProxiedBy: MN2PR16CA0020.namprd16.prod.outlook.com (2603:10b6:208:134::33) 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 (142.162.115.133) by MN2PR16CA0020.namprd16.prod.outlook.com (2603:10b6:208:134::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16 via Frontend Transport; Tue, 6 Apr 2021 19:40:44 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lTrZ4-001mXB-33; Tue, 06 Apr 2021 16:40:42 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ec2fd02a-9e02-43c0-8d7f-08d8f933de68 X-MS-TrafficTypeDiagnostic: DM6PR12MB4235: 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: l4i5xRas3Ah9rOThqImW2hpF2lyhDO2HER4ewqJHP78/aRVWW9476bZp1ley15HKQMQ0JmUyXrldaOWMJNbjtwuXuYEoHlwij0nHqF9eOkmF1+4i/hlkGXZJfIpRIvZMClmxHHI2UuCk2UlmVMy1U0DKNmhyjxdKk+idDfJnCmZElvF/UC9F4KoZshPpbuwXh1XCEquijpJ7OOFP77HSbB5J715o6ndn/PDpz0tbNR1D3pdwBZIRikxqnf9T6j0vNyMKEX0K3odi8arLbzvOyOmvAbiZrODXTUE7QHs0T0AMA4jS6WMcdJjLq9kpSCn8f5H3U5F6HhgD7qgyqwcGJQsda2jrMMETqlwG0SGKT/NHGpHGWW0HPAF2Cf/XnWIzEFrnO9cnTUI6PxldEwaV808OwqWYbVI7MdsW4FM1Q06MhUlWrfNUzuLJZl/ptfwrgQ7mGMrCRn6VGleGe6IAnokygJacIlI4wJcy/RZmE/2bSt2oLKEEDI6NImgRL3QqWl474g+OGNgYGxFXS1JAsANrOrAceB8Wm8CmaUIQDn3t+AsjIoDV4ANkLpdybXjQ2RugX6iQH0ld3h1b1/S8QCEwKU00qxbKvWtA0G6jqYOHXcYoTbTDqkJFVwStWbx+AvwlCNS/ZTyiTAfMea//+p9825bXSUQWSHRzXuBWZlGNVcTNdGVlj0juIuXFMmTB 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)(346002)(376002)(366004)(396003)(136003)(39860400002)(478600001)(54906003)(8676002)(2906002)(86362001)(66556008)(6636002)(83380400001)(6666004)(5660300002)(38100700001)(8936002)(2616005)(66476007)(316002)(426003)(110136005)(107886003)(36756003)(26005)(9786002)(9746002)(186003)(66946007)(4326008)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: ciSpyJ1el7COqPEhnTlwPGXxemVL3+dahV+5TLKrl/SQBOyCW7X7Ll7imK4yUbh87qY5534kZ4/0Ew5hqJPGHL2pJjz2AK36Trg1hLoD24nL01ApU4f/ovg81Iv4cnVAgzLR31TpKPRYhULSX5NGsR53g/4z0N86Qse9TaFsdurhJjWygI2iOrEj4UKuQ8zsGUst67n8r72znl3A5FFRoxeAFHRcV5dbVKp5vY9WiDuOUmwPndQ21rKcNBWTmp1pJ63SyhbVHFKCTZVxjQJq1sNiHj51sqdODU46LS/Ru4PjiPHZJK7VmHWaZHFTi6y7qdVcIpa+iV5niEeZyRuquiN8ht2J+NKp5jiSg+2qKYQR3zwLDYeSADWPl5sXsrPRHImIE15viMJPLMb7dVGTK7usaKuLE6dK0PDnWUyBCTxjCi1sGDJMlh1395geN4BGH6EoR5ire9bWzmM1MFke17F0ObRiJsp3Y0LuhNeeo3DMAY2jfZMxIAmcmVohK1g9GThX3GaA2qExBSd6sGY0xtNjaEotV8/Ldu7n+xiJSm8L2VdjL3ySjkHufo6f0aPgmwvB9jjZytkDHPXK624wounBuv5iPDZBQy1WiEvXsHIazQANaiOjbTpKFTCOIDOi521JvAdnzPbCrxNkbQZ5bkJmXjNRNzRs3EpCTGBWg5tDWSWj4kQVgCnftcAauqSrhiwg/BrmpakVYhyagEWT/xQ/SvLYVWxuCj8GZ3zDMnEVyzGPtrteA8B00qM/yWtzF83jD/jMniRTNO6uHjd2G8tRLv6P5iy+KcwLzbSI45Ai57QHsJY1ARHERZLIgaoXGg0dvxfhBISLyExz1Y9rPARO/Gg56w3ppwXEihqCWlb+Wev4M1Y+RfDkPNnGMDIqQS3/whU+bp7Jg8pVWfagosb+7Ma21yuU6azfPyC2bgY1vt8XJPm4VOQcrNM3k+eV8we5rtw/av7leCa9nKxOcZs4OSYqlsdDk4UvioH7uu3r53gLCTyxCdOKKnSDm2yBAf/BmmkyceyMwxvm674P1rj4Vxl1zp5It/To4Rhv1XpXRs5oqlfAcHclr5XpQVDtQbZHgum1vsitT0ev1ddl44+7yxv8GZo6Z6nx9uhp0ioWCoVOxfA88ayOiJDm87Z9RC4DaFYkH2q/0CZHjtO3ydXRrnLKvxNIVUAqSmOmet38xTd7XiYIDLV0yegMHfHb0Kp2UvLGoqnbD5JC0BqbIwGVeyGQfgkNwDeSM4i+1Jkqa1sdbJ65JSFVmw8XcmrRs2Hb852YSNQXhpS0NHzOy4cUoGAQMt+o6M0jxqUFMOzN3WI/7GI/uFTcFUdsKw6vZpEQw5nLpJ5xQjYeVab9xg== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: ec2fd02a-9e02-43c0-8d7f-08d8f933de68 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Apr 2021 19:40:45.0073 (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: DdmhO/L3zDan0dHHnGr371ISDozgkqEdbn+x4ZF53zYTkDOYlrJw7BU4CtKtqfMP X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4235 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. Reviewed-by: Christoph Hellwig Reviewed-by: Kevin Tian Reviewed-by: Cornelia Huck Signed-off-by: Jason Gunthorpe --- 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 Apr 6 19:40: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: 12185839 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 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 5F4E9C433B4 for ; Tue, 6 Apr 2021 20:07:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 230EF613CF for ; Tue, 6 Apr 2021 20:07:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234411AbhDFUHj (ORCPT ); Tue, 6 Apr 2021 16:07:39 -0400 Received: from mail-bn8nam11on2053.outbound.protection.outlook.com ([40.107.236.53]:34721 "EHLO NAM11-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1347149AbhDFUHh (ORCPT ); Tue, 6 Apr 2021 16:07:37 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DCacJ3EOr3mWx4gAbghnB54UO6rBcF5/ghuqV734/wV958X9F+32Zitr9G/jTU3h5vFYbpdEKWbE/mec8iq+Sqj/BFjtwImQrfF1zPQPWNKTUzqk5ZGsoSsafWZ69+JiCw7q9me8/EBmGftJ58ZoqKn9UROpddEFz3nB716i96+m/kTgLViLAl1tz9dXBl9cSBNiWsGetIBdJ6VZXxRTu9xRIbvm7P9DU0yvDEd6LpdsAB23JhiNTNyYvEcM+lHGXjf7+rpkh+ViNLkuRJgP5+K0oFp8YnGtpgFPw7nbN3HB/pCJqC9DhiAWAYAA613y9huvy7/36PHPtOovcEqC9A== 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=lAph3M+4Huf7UqPA+3JHi9cZqLg6Aofx1WeYrRL74vU=; b=A17EC3OTH87LAxfbobTklF6fOOj+1brtAFTgeG5SGw0sCMMzBXFx/8xTZ4/n0AE5wo28QkaPglkY7S6RTDkGJJq2o+5ubdx3aJxXPzHr19T8qpYdCzY9K+66uoPdlDAMEn6IwI7P+tqVBdyZgqp62OZm5pAXBmTPZkeE7RHevvNCw6/LwvvSxIR76MMJSnGpzRjiZaH/fYvOxBwMajIL6Diz8XzMG5BHRRThbKqR43IItVlw4WCCQi07hmeF9M01n7KlppLsqjajYpEMpJm8GNSUM/vdBgKmbDt4M1fx819hZAlyWwkLSIGslVOTc0XhoWKMtWCwNn2vYMz/ZrC/AA== 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=lAph3M+4Huf7UqPA+3JHi9cZqLg6Aofx1WeYrRL74vU=; b=CDcifajT82/81Nsw1M1xYsKCGLmVF8kZRveXBMUVUXfYcnWrRbKCP2VfYRIF5JFUIJXpqfIQQEuZY7B4aNeSE6ic56EKLRwv7SHSwPnKG162i/V/lypHqE3u/tmOrxqFKU/JAneOHreL7ebmuCVoSPpQ1YlgePeiPpLhR1va9hgBLzIl85Cbe/CxzTeWgvmgbzU8pLtH7e7RceIgHZYpWnouDS1OqSVSa7uiQnuSWqAA58p+xPsbwZHFx6naRt+TVJ0YbOHlpH356Rgx+zohL/mW8j/nn8ZV/SNDvlwMekddvPu7ek1LvgGdeAENgFCiXMZyVE3VobouQdjdVMle5Q== 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 DM5PR12MB1883.namprd12.prod.outlook.com (2603:10b6:3:113::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.27; Tue, 6 Apr 2021 20:07:25 +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.3999.032; Tue, 6 Apr 2021 20:07:25 +0000 From: Jason Gunthorpe To: Alex Williamson , kvm@vger.kernel.org, Kirti Wankhede Cc: "Raj, Ashok" , Cornelia Huck , Dan Williams , Christoph Hellwig , Kevin Tian , Leon Romanovsky , Max Gurtovoy , Tarun Gupta Subject: [PATCH v2 07/18] vfio/mdev: Add missing reference counting to mdev_type Date: Tue, 6 Apr 2021 16:40:30 -0300 Message-Id: <7-v2-d36939638fc6+d54-vfio2_jgg@nvidia.com> In-Reply-To: <0-v2-d36939638fc6+d54-vfio2_jgg@nvidia.com> References: X-Originating-IP: [142.162.115.133] X-ClientProxiedBy: MN2PR20CA0009.namprd20.prod.outlook.com (2603:10b6:208:e8::22) 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 (142.162.115.133) by MN2PR20CA0009.namprd20.prod.outlook.com (2603:10b6:208:e8::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16 via Frontend Transport; Tue, 6 Apr 2021 20:07:24 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lTrZ4-001mXG-48; Tue, 06 Apr 2021 16:40:42 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fd2ac6d8-94e6-4bae-5b94-08d8f9379847 X-MS-TrafficTypeDiagnostic: DM5PR12MB1883: 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: sy1sWkitdUw6fLA3pyX9Bj29wANS0itwE9pgdh22EDVoAOZTOfx6qWTBlSGIaRG8CEVHG54t0/OhT0PpRCVbh66Jb8mpYDiTwnuTm0Ts54lLx1zeFa4vPnH/wYGh+Qe1PpmyNM+KQcQr4Ul/1arSAti/yjzchLkkogl5v2vpw8Nj4To7Yrggn+HALcLUhbyj0r1eQARlRxof6ecOfcZ5KurHtY5aejRD5KMzivLq1/fa2OGbh4v3iKgF9SUtyn1UIzV67x5uLJmwMi+rdND4oUkFDg3QM3eK+/NjDm0OvZg/pt4XiJ7gkZEI8NYCzsHGYsveNvpK0MDmqtIh3KIEE1GgJBT8ikfzKn1GxfmsljysjaS4/6zuiVym+og42K6VqIDwe05lgNREPO2SNl5AiAnIHj+pJbMmP5eKKgtj01JT78fg01zE0kcNlpnv/kdiDig3GLLVJCewRFPp1neXDqn03v1g2ZQVj/vUZs76IeBfhfaFkt7q4Wq5RXt/xPO4KsRdX4ZikVEB4q1dElDb5bKVbaPYu8U8/tMttpGd1nz8yios1v8TNnNfjiykKNUYK6isCPimhwQXgbq4Oy37gQwoSa858pDb7op37b5g+kIQfaoen8vWKDoaQbl7AebILTxoHsUHopmk2Zt/1ccm5NITFx4IEg0uxrVGLgw1OUPs//0SQ1sM9Ah2UzOVOaFb 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)(39860400002)(366004)(346002)(396003)(6666004)(6636002)(38100700001)(186003)(86362001)(8676002)(8936002)(2906002)(2616005)(316002)(54906003)(478600001)(110136005)(9746002)(83380400001)(26005)(66556008)(5660300002)(66946007)(107886003)(9786002)(4326008)(36756003)(426003)(66476007)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: pcIq32IA53fpdHdyTe2tRLvFoqwjnYBTFqBpaX3nZmqNu1pog5RkoWkZiRfTNsLIyzI484Jt0flTfhjJXsB7kl7+C8rNqLaWU+hdaCavigQr/V785pU/iUiA/L3YtSrTz8AK69KpOO5JSenvkL0axaHulGRxwGSupP2mmEFH38tVQseFw2eAb2Hi/1asJtAa29+ktA1oFO95E0Zn9xzd17W1c/Y+v11xLD1aoO+0Y6WpfOl0pd0WjFqoi7houDIqeFugJW7z7NyzKKvT9fnHUP51q6TpYM3mjojG2sL+yQDNQhsf3E3l1JTSp1ktVF+TPL+KuwA5AszVxmq8Sf+sH5BRn8HG4nWXruU9xxZROayOxd38VHYu5hk/vHraPgaiTt7XMQIUrMEC3BZHJAizXXIbJyfbfqfRO7aoiUMaEPZl0BrayiZp1oOieHP/Q6ilZ3NNIuRfYldfUUX3t98W0Fi7bmsWfz8snP3TPbOCp4jm0Nde0dUWiJ7K6TPZieb7em5edpr1wJ8vDaYL3hLkyrO17DiyK+gjvo4kIpe5dHE44graJLz+sEC1/OnwdyNVPl+4M7WL9N7zy4bhCuSRDlEoxFvnqNCkqMOciiSpH0l7YarTturVhHEIbBTfuEhSk5uc6n3d2Jr5nwTyeojXeEB1q32GM+PdifHAy23s8ehHHm3Jn2OYEEIpNuDmx4rQgWZOmBrS3s8XuMv7g2FFfFEvNMVd1xAlIrNnb4jw0MKo8DNjaCRUKA1c2NcF+lpA2CnWgB199SlZ/3PlYMpPFv01L5IW1DA77H8oNMljpd3vi5TvgzK+ehgK1N0JnaJqntsip7Oe3PxlZ8MTZtEY8PzCac3n9uiKbwRa33T6rU2iScHcR994VQ9HmOxaRzP5cG7/vamuwZeaFkXGyxWhoRYg68Hey000c6Xa78XM3MHX2+6+An7Xa2Sk9kTeYg4Y25TWPQ4iTcVwjyX0ZcLWqAvRsqbqfRy2SetmOSIzpX6oYmh/obulxfopn4K1hs4BxSRtd12SDw4gLK2iWfkmji5cuwwQMoCu2Z7xeixWm8br21aaZPWX4Q5EoKsWFKByxM/0zdLuwXEE8z3FGlyGWoz7LCFfn5eZaqSs7A/yxszE22l9SJ+ni+AetCEXDuIDY0LIvvFIYloQLQZgoqoYWXJIWi8zuaBCq2hp39p21FI0Fv0IhsqXEGO6cngcfLF7XpRr/j+C8+94vyPW+ha2Hve4HK+EpEmrwZy94T39M9xa7PWMRTiDFPFezZYR4Mll0VKmrT4niRfW1/0O9kNq0lVPg+Gh8fDfkP8ZRDtc5E3MC1CnvtcJI4XHKAwR8J3UCUWejm+B2YUeRk7/dnIT8w== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: fd2ac6d8-94e6-4bae-5b94-08d8f9379847 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Apr 2021 20:07:25.4631 (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: Vxq7viQAr8ga0skf863SzRB53ts2b9Kb3qDjBJku50RgIfK6GfwqeqRK/pRqBnef X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1883 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. Reviewed-by: Christoph Hellwig Reviewed-by: Kevin Tian Reviewed-by: Cornelia Huck Signed-off-by: Jason Gunthorpe --- 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 bcfe48d56e8a9e..8c169d12ba7dbb 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 Apr 6 19:40: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: 12185805 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 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 18A09C43460 for ; Tue, 6 Apr 2021 19:41:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D0D6D613DF for ; Tue, 6 Apr 2021 19:40:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244959AbhDFTlG (ORCPT ); Tue, 6 Apr 2021 15:41:06 -0400 Received: from mail-bn8nam11on2061.outbound.protection.outlook.com ([40.107.236.61]:28513 "EHLO NAM11-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S244906AbhDFTlA (ORCPT ); Tue, 6 Apr 2021 15:41:00 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aZt18h4i1OqkF8J297eelqzB3fqodXfRRw2/wZpjxi4hmg+vJW1u6S/1SqfRnXQKtLoiC9kI0xJS7aP/D0OctZF31CD1J2FuV4AWoX2KD1F/zV5y4O0U3sIc6BaTtzfL3ljOec70VoSvFrplWzZAlWj4o9M18a+2yjadon5HDx1DRNbBWkaM/nXnlWp0QJp2GGmmRsPAAaUfxPo5/anRncs+NvnqZKEHi7iBIe0QoTKCo6QAuzcuK2gUUSJ/f9G11vIwGvUEojiRfmw4ft9BCSganR14iaUSy04LTm+Srw+80KSEUbhPkWn9KPNhiYfQO9bI7vGSqLUSeyUiUolw6w== 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=KdyikCyh8+bLONJpcS0zgptCbWcNF4yIX+TOYuX6Xsw=; b=HATk4zHH8Hd66Y0nmxfe5O1b5Lv98Z8xY67q0MENz/QEkPLUD46d55SiImx+ihujdyOdKMe6UDYA2IyEtDAQH9lf8kq2RbpoknUJPU1OBr2TRZhUuc3iihUnr1U493pItRSY3mzNmzhrZSXXRf+lIbTnuMENjRb4WzdO3mzE5yACifJSI4qBUzk6iCTNtjkGDnzVTz+yUZHTFXqBNrOiHzAu1EYkrn0CP/uTw9I9ZGzDiHHPsJJkrXeEFSZqd92zj1LblXh4QtBj7uB249/mE/+V/lD7KBB5YG8nVeHrcdYOG2fgwphqITR2ymaS/lA4IQ15e/YcEQb4Yqvfw3xuHQ== 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=KdyikCyh8+bLONJpcS0zgptCbWcNF4yIX+TOYuX6Xsw=; b=AwJLSSq+urYOf4nKfl7anpLXLGrR6BqNQwDqNXA2WJT+ulghSRkubeQzktuDF5mDqvlQwr4cBU9sZzsZxttUhm7ZwTauRN1FKXxJuGapYGpr5H1PU0YDSga9I7wxbw4ZXpRn55foXLOj069jTIdyA5cgjgZYfK7Ktfy5RBQkklxFDzCNz5U3Zb6znKkuwfih+fvOdveVwwXLT7tHCdW2u6WUu2PkujgdsIVbG+x0iJOQLZfkzKOKKggGrLBtWns+9nl0qcZwA8Ajy0MwtF1pinNxkXaueDW2V87AmkSxwHD+K6tf11+iM5ki0iJXjkTyoo5pNLcY9kw1Q5d7SteQgA== 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 DM6PR12MB4235.namprd12.prod.outlook.com (2603:10b6:5:220::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.27; Tue, 6 Apr 2021 19:40:50 +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.3999.032; Tue, 6 Apr 2021 19:40:50 +0000 From: Jason Gunthorpe To: Alex Williamson , kvm@vger.kernel.org, Kirti Wankhede Cc: "Raj, Ashok" , Cornelia Huck , Dan Williams , Christoph Hellwig , Kevin Tian , Leon Romanovsky , Max Gurtovoy , Tarun Gupta Subject: [PATCH v2 08/18] vfio/mdev: Reorganize mdev_device_create() Date: Tue, 6 Apr 2021 16:40:31 -0300 Message-Id: <8-v2-d36939638fc6+d54-vfio2_jgg@nvidia.com> In-Reply-To: <0-v2-d36939638fc6+d54-vfio2_jgg@nvidia.com> References: X-Originating-IP: [142.162.115.133] X-ClientProxiedBy: BL1PR13CA0148.namprd13.prod.outlook.com (2603:10b6:208:2bb::33) 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 (142.162.115.133) by BL1PR13CA0148.namprd13.prod.outlook.com (2603:10b6:208:2bb::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.8 via Frontend Transport; Tue, 6 Apr 2021 19:40:45 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lTrZ4-001mXK-5E; Tue, 06 Apr 2021 16:40:42 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1f765d9b-def9-4180-feb0-08d8f933df21 X-MS-TrafficTypeDiagnostic: DM6PR12MB4235: 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: j16lpe+/FD3qvsdLVE5MRlMjDZ/36Kw5PXGIsB89Gek+WX1ftkESp6P6Fas5K8gpdjFCziSO7XwSSYWDS4Jfz2Z+IHoPocyUK/fYGQrAXLPnCX2TMi7ImyTbhInfCFbG1UQauY3kq9NN8oW6d/cp1J0BrTFfcAEvVUYjU70aZVLFdHFs/lJDxAQvs2RRM0/7MYLrAbm3X5jNr6rMbMxr4Am5IWnPcH2VYhgZlz2X/+WSOv+FXC3R7rP/di0SwiujpUYWz0Dsw0UWr9PJwGfYAOiLYDTeyKJ7P+y8SMv73QndiIQYtDcvEc0A+xcFLNRCNE1WfPF7+mjcdSK+cvTvcGK6yx5Dp41nftvTiUkQGAbxWT9ra8gx37iioMcyQC/2MpODm39l3SNiHpTO3t6Rtx9ejQ6Ck0aas4A4LVvn3ErhaejHzoUUgwCkH1VpHZeO6G0Gqx8k3d39YVgaNjJCWKzKjkVKtnlPDvnbaSvrlVWwBqAk5HaXECJj6jx5T1QcIL6+5fr2Se9c4hMptzy/5+rFJW9MIpEd6UYKDHdwBwUafoOn+GaebUEREfv8IaOMsxAZK6/mN8StmXtzUxrDtwCPsHUJg7RTeNaxjJb0XsBMYcA6mCXuIISYBCY+dP6hj6cxDA2nOLW3dCC2PY3bsY6AxtJo/9J++CGg1qOtlxXb/ls9nSVkmvWy8B76jQYM 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)(346002)(376002)(366004)(396003)(136003)(39860400002)(478600001)(54906003)(8676002)(2906002)(86362001)(66556008)(6636002)(83380400001)(6666004)(5660300002)(38100700001)(8936002)(2616005)(66476007)(316002)(426003)(110136005)(107886003)(36756003)(26005)(9786002)(9746002)(186003)(66946007)(4326008)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: h9mnEjIWxd2/3FJ3DgNj1b4p7ulhVKoxS65WKxRGP0cKWp7hvUAgt+JqEoA9uPKfPHDEivSyOjl0cJNPCzYt5SWWb5Siw4a144DEuKRUp4hp7yJiUKRxCnDFRQwywijXIFi1M5Vr8ihhg0LFo3CubYTZJUX/0gtS5vypoReEMhoRGOdtPnYsF9Rht8wIHpfTEmjWADGUD4jhRpgT0mi2pYBAa9Y10Jn2QIEtUd6/hyv3NHs9fh4QUmeNiVwU+PEuE9nBV6bsgW7y/fb5pAziYHurZMhAUbItTmC4m4P7EDFJfgf7UQt5KbaeuSF4j0TpvkEHD6/G2F0dJcwO/p97Lvumj2nGZttpXdyfv5QkuQVxUGf05EO6cRwq1TVK7XOQEij0+nehwVW0pblxmVEaGbY6+8G6H4FNECFUYy6Jpl1K6lDL9FN/hDltu2gdI2Ae/dNB2B/YPG+W5FesYICp2dhtfPrT3GBF+VEUneMYbrSk967bM/3bVSQJqnxikQOVojIDj8u8XN5KBD4Ah3m71SSkPrJ4ssKrHFsZyxSYIZhPAmiRxaG77QkNyPnKOLXjvcSkAGkWWmTd6yFeYTTGKrMrjkNa5wGNw3Nm6AN/uKbc+a5fMwJB/eE+m/fi9K9CU4aJ4HIOOgNUr5XbQNUw7SctqBhylw4NzXWMGkLsDayiLtT95MY0r6NMCQZXc8xSZb/9nSJtdW3dGSvJp6M4aQoxngjhKWJjBUPWIuSMSXwvENlzmd64WPvilgxB3os+VN5GI5YS4n22IUO2SmRMBQFrJp4ybmM9EXAYOXGgFplbr4BS6jnXRjs0YGc1GQhdgKVm7WGUz8QqVXrHOyQb35QgyksdByQOqxCWmhH3QDaoiNfHG3aPb3tUKAGmqCI2Q9GwOda2J+C1wl1z1ow91z05iUgZZqrbiQ/g9ZsDujl2PiR5HXsnsOwsVxOUawRaOQOYkFIp7eP5jvJPN5gAOPv0SbY4ncjH8sagZCUrjF9BzfUmP2iTVEfxm9zB46LlkxGtEFwB5Xh02xxfelLuq/RTfK6ghP0OnVatBy2wnStkB3ImcU0ALXnF7PscgYhgmkV4yAdQfhY35ZxLSllhw7bhXkGN4+GKPB+jtXVtuZJ8eWOsbXBk18S/Gk9WXVgCKayLe2PH7zRzubzXhW9+j6Mo9gVhA10cxWULpOE+jOWRQNXOY+MwHAmXiW8Oq/hSYiQdirtNVf3eL6GoheylHeIM8ofvxjn4Yre+sXoTbwCHpLGYvRjlFkhr8glJKLVfwC7145mrABXTCqtCxwjMaccioF6RMkwKbZbQFV6ZiUfWr+CXdRIUW5dT7UphEjF0X1H+YUzE2u/LNKFxo6sIgg== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1f765d9b-def9-4180-feb0-08d8f933df21 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Apr 2021 19:40:46.5764 (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: WYVhN3IMyEi9OJLdaDfhviLxwcDOoL0z1gnNLU+8tunQEEmee4Jgxy567IQWowVu X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4235 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. Update the goto labels to follow the normal convention. Remove mdev_device_free() as the release function via device_put() is now usable in all cases. Reviewed-by: Christoph Hellwig Reviewed-by: Kevin Tian Reviewed-by: Cornelia Huck Signed-off-by: Jason Gunthorpe --- drivers/vfio/mdev/mdev_core.c | 60 ++++++++++++++++------------------- 1 file changed, 27 insertions(+), 33 deletions(-) diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c index 7ec21c907397a5..f7559835b0610f 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,70 +222,61 @@ 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; + goto out_put_device; } - 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; + goto out_unlock; ret = device_add(&mdev->dev); if (ret) - goto add_fail; + goto out_remove; ret = mdev_create_sysfs_files(mdev); if (ret) - goto sysfs_fail; + goto out_del; mdev->active = true; dev_dbg(&mdev->dev, "MDEV: created\n"); @@ -289,15 +284,14 @@ int mdev_device_create(struct mdev_type *type, const guid_t *uuid) return 0; -sysfs_fail: +out_del: device_del(&mdev->dev); -add_fail: +out_remove: parent->ops->remove(mdev); -ops_create_fail: +out_unlock: up_read(&parent->unreg_sem); +out_put_device: put_device(&mdev->dev); -mdev_fail: - mdev_put_parent(parent); return ret; } From patchwork Tue Apr 6 19:40:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12185795 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 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 2D9F3C433B4 for ; Tue, 6 Apr 2021 19:40:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DF85E613DE for ; Tue, 6 Apr 2021 19:40:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244915AbhDFTlA (ORCPT ); Tue, 6 Apr 2021 15:41:00 -0400 Received: from mail-mw2nam10on2073.outbound.protection.outlook.com ([40.107.94.73]:54032 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S235032AbhDFTk5 (ORCPT ); Tue, 6 Apr 2021 15:40:57 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cfbPpJiat9bST4GziGqhtwNdaFel3xtWs04OhQ2BlNPaWRmF1KQvWvTuoIWd5h+0THupJIIMJrRqbpVBTBRIGPp0ayralr18pfp7g/28WOMoBSNTIAbUBx4QsNK0dwclMWwjQXseszv4itVZ16P/kaf9wFko2gyZ1w1QncnT9pQJH/sRhHGU6F0dS2lQqOxx0S+UkaV1MWukHDn00xRJ1mg4ffR3QGznXjNfRlwO9ZpUo51whypq7/Qs8jlTWB3tmwbuvXcpYF6vWnz9LcFDzUCzfPMj8j7J8IbkU5Fp3bL2UPkTuCktv1sprjlK/gP9DYMbdUHhypSMJYyO9jHUEA== 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=LSRdrvt55b4sprMaz3bT72yodWqW13fHhTN3k5Mj700=; b=WkeQ72kSepRJP+WBFoZETwihhTuSfzak7A178B/p8ybxkLee1l0Lzm/3ewelymIj0JciYy2VJhbg0wypJWVeEdOSomgPrsBtdJvWIIOAY7sUKpD7QX4w0GZG/ZccbTedHHFRMw20oBQB3InUeBsYhgnKF7FNLMKN5iVEGOHaE48GGbGJN7wpPtow8Wxe0elwYprB10ry3G9EIdUgse8D0bLT6ZZNJaokzz0yZEQIMLq3otKn1OYMULE/STs7WIMdVcDEtpQaRFbBjPCOZljOABcG1L77GbI2J0XA2uAbOKn9hoNMmNo9aL4+4NhKrzNCKMAN7UNpaSbFx4e5H9TW6Q== 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=LSRdrvt55b4sprMaz3bT72yodWqW13fHhTN3k5Mj700=; b=rBMK04FATIgoAsWjseAOGg/S9qVBR9k720cVdpeN7ZX50O75Y82HkiC6ceytybItBtt6B3V1OWsOTiNrE9MSmCjBE6LYDXo5WEt68aaDg8zsX9apGU9oQBMopACwWwcAPkKUvTlG+rgHgW+NpYuOtx5xw1s/c+ghtX8+lBB+1/f3F4EA4oEjsG1Qq9+TpYwXzfUBLr1UTIkFahG/e0qC8VKF4PgbM8u3YDAzqwd7HWMcSgU6VClB6yB0/XW8IJUS38OZ4ePHtRq2mz/opaNqRpaZa0gyd6BF7HxM+8TkTJqdVeHwTEVKdK/8Pc5G8RVtwW6yelpjsU+ZsvKDipIJYQ== 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 DM6PR12MB3515.namprd12.prod.outlook.com (2603:10b6:5:15f::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.28; Tue, 6 Apr 2021 19:40:47 +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.3999.032; Tue, 6 Apr 2021 19:40:47 +0000 From: Jason Gunthorpe To: kvm@vger.kernel.org Cc: Alex Williamson , "Raj, Ashok" , Dong Jia Shi , Neo Jia , Cornelia Huck , Dan Williams , Christoph Hellwig , Jike Song , Kevin Tian , Kirti Wankhede , Leon Romanovsky , Max Gurtovoy , Tarun Gupta Subject: [PATCH v2 09/18] vfio/mdev: Add missing error handling to dev_set_name() Date: Tue, 6 Apr 2021 16:40:32 -0300 Message-Id: <9-v2-d36939638fc6+d54-vfio2_jgg@nvidia.com> In-Reply-To: <0-v2-d36939638fc6+d54-vfio2_jgg@nvidia.com> References: X-Originating-IP: [142.162.115.133] X-ClientProxiedBy: MN2PR12CA0035.namprd12.prod.outlook.com (2603:10b6:208:a8::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 (142.162.115.133) by MN2PR12CA0035.namprd12.prod.outlook.com (2603:10b6:208:a8::48) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.29 via Frontend Transport; Tue, 6 Apr 2021 19:40:44 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lTrZ4-001mXO-6S; Tue, 06 Apr 2021 16:40:42 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 26a95afb-d2f6-4646-333c-08d8f933de5c X-MS-TrafficTypeDiagnostic: DM6PR12MB3515: 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: KlUZlGdd3f73OXZ9nddGmK7UqoSGz/CBjjxf5K9PkBNsdEszrJ3Bgwo5JU7SqnYHxye8Mrqt/TDpa8WtPPTYpdLs+7uZKNsiWWBnA3/jv+KgeOJY82W/rbOFGrELxpoGssE/fYe8DMXeqENwFsKJJYcAyrzeaL8y9o9cqRlY+YTf67U0UvNqfc2QWEnLPHnGbskGRT7nL+2P6xMYkhoV6uBOfucXOwf5wljLsNik9mCT9VCgvJx/YFYYMGnlUYr8Vvtm6dRyvrubytv1JZpqONvyKtYVe9MhdkNEQeUp7lWn+Nx1VLbt6KyThI9Q7x/+GSE78z3rI8whzrjfOuMfBqNIpYl4bzSKnXjtZyVcMVPgoHunT6/+9hm93qKEsJE/QUoxDuthI2QDdQn4IrtlWy/uGERGAdyr7eggAMjPmCuDshDhoA8nOUhV0owWZcllLeSNhks1o3w1mTOaWI2ARzTWR1jxpu1o0CgdRdZ8XMVdSJxxgpkK450j6oMnMTuaP2rrSQ/JfRtOZQrXZz9BIRSMdTzgEXHqu1DJM84adwrjBy6WhvnsoSRSxIIiAB0oNdK9a0cdSpQC+Drpo50+IjiUF/pra7oLKAX/9vLNRi+uHQsvjJnYIdz9MGJuZTw3IAa0ZtIzNnM+Tsacag+tQHVJnBvstnTEWct5srCAj+M1jTiIlOBP8HS/DtbTOTHd 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)(346002)(136003)(396003)(39860400002)(376002)(366004)(6916009)(9786002)(54906003)(6666004)(316002)(83380400001)(86362001)(8676002)(26005)(426003)(186003)(66476007)(66946007)(2616005)(38100700001)(66556008)(107886003)(5660300002)(4326008)(9746002)(2906002)(478600001)(8936002)(36756003)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: vz1sSPvxDKJ9iUijrVYYDjK+lZnZd/7u+BjvtXQoVpd7aRqSnQKct7y2q98cqhu/KkVbsePiYsH1lb1mM3c7la8ImKyKumxeEsHYzNcIGrqWnJumegMj26m4CXENTk01+YvDHBn4gjY4Jaz+8twtVLkwbcBmV556rndmTUUN7l/1YSNSmY9mxmP3ejKjiOEjVkKTfXO6lr/ncIfwq9g+499C6NCry68MGy2ZYTe1NI95gkt45q5heI+560TEqIjBWYfnAlMy2BYaiGiL3k7+pMbmYssHLFbcAm/Q1N0tWFdMwn7crRwfv1ooJWVX+72ro576taIhHCKP0BvfnW/JU6n5uUA2cXiAvqy1yyqtkM65E9efapN3DR9VvXroQTDY9FjDVBCpwH58kE9HV8HG3HUu2YOgNkZTZVP6OAuiHdZ/57m9kfsyAKl5MHWebWRfmODmyHghcmhF/MDBiJMWzYV3vkZjdFP7OU0ZXWxitYUW9KS3xsmb0pBJO3EozcqiKjajoqyF5Ysd+PXXHePTSsz2lN+mDqGqqtHPZIxybG/Y/KQmdvqMWZTfrwegGOpapqKx2dyNVPHGxz+IA1InX/pm3NF2SohafJlVGMniETsfpYy/7RJ2dM0mYBo5TOoaSov7faDP3WaIoNGO+cx2rsS9DutK0dnT1+I0BCsqO+QRAsrtIdTxRmjMVexzySN2KV1hT+wju60u35M4sHs2SFFxT2LgQqPtCRYHzMojI3m3Qy3OFHIidSQ9qZOFwFKqFUSutv7eCepnHKzPr2vtaYLMUtfk2LGWQ0HmEF/i/q3X7hD5uDb7BqAPl6bhMEAvGZfTPdCAISzWuZN4QVS3mv5WlkIYcdXkyIQII3jGSg0y8POffL6PHTZyV8Wuo8OP9xD3X8kOj+aiCIpTgfnXznmE0hlI4r6ujSys3AO9EadHeUs/9hEDvC0kjboppZ4NLJJCITTYpEOO0ID/nb0xP7fToNxfUDCWBd9vIxVX6DHLB1gaqyzOqG5YQ/5VQuePYNR9p0Qhm86kzNQZqGEWUIAzV9meaRDldG3ZihoxuhxADaXCArUf4cp9YI+4ALI5Y1lRuGvHaVzSeOl09JczSid6mHmg+zm9zGWNLZRzkqUbVk2ZOAOdcHjfpaMl0DxpQUNq9STfc2MeX7hTaKwHMS+8SZIwZMvHhCyL3aAAKlZfakr7aB2gNsjGLIQ6GZ1oJX9HOlgx2vILasxhJztbo0X3wQX3rm3zh+QgpuzaXl3iNUKKHhwPZHmq/bEocVEB/W6L/7rO2HqsgaIR72E+hkdABQI6i4O+0t6lddSTrThIztLlsvOHRC45ZLWvM2SzL2RpRLpAhUF9YSR55qcIuQ== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 26a95afb-d2f6-4646-333c-08d8f933de5c X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Apr 2021 19:40:44.3477 (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: 9NOH6pqMxqIh0m2pY7+gUC5x1Lvujvfub89N+AFG+0GwUJ9wieQPji3f2I15gk5i X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3515 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") Reviewed-by: Christoph Hellwig Reviewed-by: Kevin Tian Reviewed-by: Max Gurtovoy Reviewed-by: Cornelia Huck Signed-off-by: Jason Gunthorpe --- 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 f7559835b0610f..4caedb3d4fbf32 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 out_put_device; /* Check if parent unregistration has started */ if (!down_read_trylock(&parent->unreg_sem)) { From patchwork Tue Apr 6 19:40:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12185841 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 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 7D8B0C433ED for ; Tue, 6 Apr 2021 20:07:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4C532613CC for ; Tue, 6 Apr 2021 20:07:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347149AbhDFUHn (ORCPT ); Tue, 6 Apr 2021 16:07:43 -0400 Received: from mail-bn8nam11on2053.outbound.protection.outlook.com ([40.107.236.53]:34721 "EHLO NAM11-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1347153AbhDFUHi (ORCPT ); Tue, 6 Apr 2021 16:07:38 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aOURRhmtqRLDHKm8AimTmp1Ubgr20/UvclC+iKp8CNEWTOlb7l9uhYzbQ0jCNDP864NXJUfGZrmVuP/TlIeZ57gjnah2PxP2Hr9rtMw+zASoLNnMwGtLpViQtxNjz7ZDkLhUYc67yT8GM/hmLo9AZwjeFHPS6yxzaIhRor/3fO62vaRNrNwx/mzKQllQWbSuI8zU4tjDLbAJZJ1eTWX30bVgl+XV/YI3iknzUwM1IuBh8Kf3/Hw2KLz0H7szus2C+KN67xksiRaJpsxVqxvRYMr9r52O7BJ0TP3EBikeoZ6BWRJWRi8+Khls4DeK75Pag3dRzz5tOuFi/01EbtBWNw== 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=JNeIevVOOYi+k3r5FquCyHpMmhxjxVAf4smmFRs/swk=; b=XpjhfoocrGVf+U2Ak6ahzNB7gViSOdjnh7ksFInzBtwj4YN3RqfAsngUPDZCaTzm5+btJcQPYI7JlRR3ZD/wNt8CbiJMYYvoSOkUQU0mMcCTWl8WSYcFCG4jXf6sJpkcLJXREAR2rc2hySA/gm3WKnIhkQAx6b60dogR3zTsLt5EClToSgYRhBVxOSIeRtuPDJ5a/4Pw6tpISf6mQJZrEgAb/KrT0831zyDdwb4x6ATvUddItP0NUJEXcSu1BQMuc/0Zx7X4f6iaUhBxemh+Wkh6Nwka+W8b8VFqQ+v5Prcmv7FILl5sK2W5gk0GCdP29Qdd8FbjRTClZicYPemdDw== 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=JNeIevVOOYi+k3r5FquCyHpMmhxjxVAf4smmFRs/swk=; b=N42RDP+hOqTWuha7rSy2uVdOvB5Z4efWKrzVi7mlylZcVnA8mL6ZwHsensrrKmaMUyY6lDyQ0DIaXfJl3U0QOkspCNGudkMw48mPdV7npuFbDH4ev1LdE1M7ZdXrgtUQ0J9dudlhsOJp5dP4RpKRNBUUrlN+hLeaXZWFC2HOnaLP5N5loV4DelnkJ3LRE3DCVXUQON5LktaPlHum+x8kRo9FtQYoLeXJ0Yk1f395nos4r+CoRGejEIwJ1rlE1BluUYtjaTDGADiMZtZ/tb0nrHOnumvBXkDb6DQ/H9QUdVZLxH6Cr/vhQxKyIcCFKFbOgs9Sbefqk+54tCcbBrRt/g== 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 DM5PR12MB1883.namprd12.prod.outlook.com (2603:10b6:3:113::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.27; Tue, 6 Apr 2021 20:07:27 +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.3999.032; Tue, 6 Apr 2021 20:07:27 +0000 From: Jason Gunthorpe To: Alex Williamson , kvm@vger.kernel.org, Kirti Wankhede Cc: "Raj, Ashok" , Cornelia Huck , Dan Williams , Christoph Hellwig , Leon Romanovsky , Max Gurtovoy , Tarun Gupta Subject: [PATCH v2 10/18] vfio/mdev: Remove duplicate storage of parent in mdev_device Date: Tue, 6 Apr 2021 16:40:33 -0300 Message-Id: <10-v2-d36939638fc6+d54-vfio2_jgg@nvidia.com> In-Reply-To: <0-v2-d36939638fc6+d54-vfio2_jgg@nvidia.com> References: X-Originating-IP: [142.162.115.133] X-ClientProxiedBy: BL0PR1501CA0001.namprd15.prod.outlook.com (2603:10b6:207:17::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 (142.162.115.133) by BL0PR1501CA0001.namprd15.prod.outlook.com (2603:10b6:207:17::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16 via Frontend Transport; Tue, 6 Apr 2021 20:07:27 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lTrZ4-001mXS-7c; Tue, 06 Apr 2021 16:40:42 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d5bbe004-b898-478c-18dd-08d8f93799dc X-MS-TrafficTypeDiagnostic: DM5PR12MB1883: 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: u1UQClBS9yEH64fzjIB6MeXJejBCUqpfRsN4/1leSF9sVfoRuJYY1z6BR72tjSA352kq3pG9oE54xy/MsxmT1l14kzdz9hR73J2GS+/ZWb93MyBn8OPSAaV7eFcMQ0EgleXdPj0Nmop39mMRf/A+5BKI61nc383BwgPXzXJYx6/kxQcutqKJNaS0Z6EpQFta02y3gQJNAcJtBG8Q+5Q3fNb/Gd47FddphIYp1EGm7Z+zDQ3xtBBuh5FrmuSwHhHgXBsdskqza7cxu0nzJscwb8cgPckeyBckN2jMCBEB9ptUiTOYZYx7qzSlFPO9OwbpOOCQUQrp43Ef36xIc148lfkVMDA/DWSztryjg7GXxZaKvtyxAxzxyCESFuZKkKB0RBzz4LaMReJJBpGd+6jAt57DLq3/5tQr4begO45bsr7Z4AqMuXIdIyq8lIu+fDpjjVmISUdd5VXxED0o82OillWfreFKQSTyIp72m/wFumr3D56+2C01gxzAiAoqbQ+BWbHraMeLup0Un6bw5oLi+PO+roLznmkU/UG9CNB2FAbZ0rhnouwHKgg1LqdLFH5VHke1qXpLHcdW81MgaELryeCgbIFs6SUgAC2DVJN+ZwMr7XQMho3o0veEa454SZIKVYvCURXdPDS6KOXorHt+g3KSuKB9gh10vJy9z+spV/A= 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)(39860400002)(366004)(346002)(396003)(6666004)(6636002)(38100700001)(186003)(86362001)(8676002)(8936002)(2906002)(2616005)(316002)(54906003)(478600001)(110136005)(9746002)(83380400001)(26005)(66556008)(5660300002)(66946007)(107886003)(9786002)(4326008)(36756003)(426003)(66476007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: Xx5qOVWs4k6NyyoKeSgiewrKWBJKXEWTkQ4OohTI4IrrV8Jb5ewzqm3sSiW+CPiIAbG8tjfCPmyAM3OS9nICu7rL47lMJTxJCDIlk3PPiscPRlnZLKYuCRBIhpNM6oqRTgx3z3l/GRCMrdx8TblehRfqMcgVWnCB4xupxiAJvJLD466M5m+h18tN8sGWTwG9XKD79xDukB4iRXyupX69ngnXYp7YvfIOsNUTdyjIo/w1hmR5NMA+e3mlG4aPCwhxSiiFIrI9iq/edqIdLqkp+uBUz1M4/f2Uu3eWu3zRpqQi295wc2sRemMPdyju+ryQHRHKDAtNjq/OwpOfxmNJGMdSw4+ciKjC2HTp7MJCDhL2hECT+capI59f36WP8HnD/WyPi6FCm457Zn8lMDVTBaYX5NzcDD1iJgqmF0kwDx4nG8TxQETDcnUqu1lZNClXpmq5qE/9L2SAkzmiGLAYNCD1aaWHiMh+2tYQ4Xx4Lp2FYNaE+e9uhPWBouP2i3SF74j/S07DRxW/kKfxizlv286z+4rMjpN3CaRNlysrnc3/I5Ij5rvcKvgjjSmVP0KnvStpbxG+zJU5Yruelwoyp8WkzzA714UqZahI6RLOWdqMKZeQVFzCX9/gtJ6wwfydZVnXZ9yHkJWRVIl0rYIAP38qNG7YjW9y8OpaCqZ3c+IuwCbzl0Am2cOF7YJz4Kqxa5slUPnFd0DgfCQ6nYYvtT7NZTx5aXxt8CXIElYRA2H7isMIg6rfEAF3fgAUm920m8Z6U88zybbJfSjUPm5JpUy7IdFchyn/jZTpgKg/Jsk74dZ6nQqgdPtsJyusEup6fL2NhFwB1B2qzb1oOwGqfK1UIYjfXDS6Gp27kvSr33tSL3dFq8v/jIoUAi4fYdqCXr44FkXvZ+ghZm1shao/vNdiLlyhHEqFWlAbb55G84ZTDNXBs+RL2razHOBzl+2++K2aYWFCPNWZH1y+ehfKycZTQ7b1X8zl0Mi9pXQErZhdy1jBYj89h9hz7HuskTEN1Fmf40fakc5P6XAK71rGth/9mOnEY9V3gNw2eMp1864CYTjyeZbt0Pb/AvMQYJOWZJIzdm443BtAXrFMaY+2rvKZ1By/L15r9qlQ8Zolf/SpvP5eJTtHfLMudqRaZl/Srz7SG6jXdXtVorqdfs5pRGWQdgdJH4Git2IqwBP8hcJOh6+5MX+zZ7Sd9sjEEnwoMRczV/bMwaQK7F/jphmqrOwOGeOHQoMO4F6gTMwvY1ocUgZ1Rgg9q27OBLy18v5erOQG5ToZ+d+v2y2LXwbAFjj7TgMQdFPG2JZiNqMNsFgW7xSj1RU4NLVXT7sAgq7V1iH334cwBtKkiKMGetrHMg== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: d5bbe004-b898-478c-18dd-08d8f93799dc X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Apr 2021 20:07:27.7978 (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: 1QGZApkSrJEnu4l878/4iijEqzHuYX+5Cgw9lsb/ml6qxHOHW0AUpxpz8rl2QOXx X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1883 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. Reviewed-by: Christoph Hellwig Reviewed-by: Cornelia Huck Signed-off-by: Jason Gunthorpe --- 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 4caedb3d4fbf32..2a20bdaf614214 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 Apr 6 19:40: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: 12185811 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 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 6A09BC433ED for ; Tue, 6 Apr 2021 19:41:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 459B961158 for ; Tue, 6 Apr 2021 19:41:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244951AbhDFTlL (ORCPT ); Tue, 6 Apr 2021 15:41:11 -0400 Received: from mail-bn8nam11on2061.outbound.protection.outlook.com ([40.107.236.61]:28513 "EHLO NAM11-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S244900AbhDFTlB (ORCPT ); Tue, 6 Apr 2021 15:41:01 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oEIdr4HjyjyCMjPQoMngwnNN1jeHh9Pn8Ri1Z/BllJ6ZUPiAKxPHEDjTn92x2yXjIlBMBHNI5STq1ipu8ujaXfRbB1OPsYGEMxyWqWEhhVIKOgYWqolF2MeHPJr7dAtmsrDNO4hV8YBrQU47ToanoTyHpAUMCybX0mhmSVkLdnhvmFbUufduTuxaT/fccd1JspmIeMo4MxL0aRR4vZ7aHeYIEUvmUqhMWl/vbQ6IpQKJP6SVzM/24NiA2bR2qYHw9Q4xr3Aul7reEYEth0sV6ZZwH+aYVimh8BUzv5M3C+MTRn/Ra+aEsKLHVm4VOORGdOM+j1x5MspQs+fv1Mfceg== 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=LFfOLtysUKX8PIQOEis5KrnOR9QGQJ2cl4hV2Lh8w2Q=; b=n8/T3OY/x68/voKw1rsNg5oK/ye5cGW8QEfTl4Ijw8GLKrerUeCWjtwZK3JP13fSdKkRliQgxh/JoUvU9MalK3RcX0nia2xCFJnn7YMoUDYa33MSC6rLjvLIKyVS8E6UqqWFIAAGmI1BSvfm4g0NGLwTK8bXCHElmtQy0AoH9YoFLwPhotcwM+f8s/lkMLeFJ3L5aEHkE2t1YI9RYARoCrMewoRRnXF2/wVOw+khqXILtZsdYKJIs8AMCGjoXhGu3q73TbD46eFlc1ZP/qODE35uyn8vEQqIBOmZF/PHhvZ1IA4mE4c8dF/A3VASYiggAyYxN7raW1l9nybLDcaZaw== 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=LFfOLtysUKX8PIQOEis5KrnOR9QGQJ2cl4hV2Lh8w2Q=; b=CvnXXOlCg1AutoSxoi1YwoKjkktlu76imSApb5mE3NlUnWASCn3SxIgt1NNNrXIE+rTcrZN1zFaDCGNBdvO7tKGJ0jlF8Wim+isRDJxzxs+UPXHbQtpE2XobJqVhlaTFf0Fg6Y6j+171bIeZ5jMuPhnB2syHgCtYrCdBJ5x93D0V/rADQvIC+vmvRZECNMisNPghP6JrejBoE2nHYKFD3nywfJqZoBdWHWJcL12uic9e3S4Fyp/h8tDdcKtiiOg1nOSOH14u0e6AzXlFDeCYSF0WldErbmKifzDehYOqdWvW1/pZOGa/c1JZCXBLk05P9lnWGwfAnBxjambgFPiQ3w== 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 DM6PR12MB4235.namprd12.prod.outlook.com (2603:10b6:5:220::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.27; Tue, 6 Apr 2021 19:40:51 +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.3999.032; Tue, 6 Apr 2021 19:40:51 +0000 From: Jason Gunthorpe To: Alex Williamson , kvm@vger.kernel.org, Kirti Wankhede Cc: "Raj, Ashok" , Cornelia Huck , Dan Williams , Christoph Hellwig , Kevin Tian , Leon Romanovsky , Max Gurtovoy , Tarun Gupta Subject: [PATCH v2 11/18] vfio/mdev: Add mdev/mtype_get_type_group_id() Date: Tue, 6 Apr 2021 16:40:34 -0300 Message-Id: <11-v2-d36939638fc6+d54-vfio2_jgg@nvidia.com> In-Reply-To: <0-v2-d36939638fc6+d54-vfio2_jgg@nvidia.com> References: X-Originating-IP: [142.162.115.133] X-ClientProxiedBy: BL1PR13CA0296.namprd13.prod.outlook.com (2603:10b6:208:2bc::31) 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 (142.162.115.133) by BL1PR13CA0296.namprd13.prod.outlook.com (2603:10b6:208:2bc::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.9 via Frontend Transport; Tue, 6 Apr 2021 19:40:47 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lTrZ4-001mXW-8g; Tue, 06 Apr 2021 16:40:42 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 38d6b32b-ba1a-46fd-751b-08d8f933e00d X-MS-TrafficTypeDiagnostic: DM6PR12MB4235: 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: hltK18RrOPbergo0xSqnhNUDK2/hDO2Nq61DSS6cN2GgTS+FuPUzpLT8irGu4WeKRo78n0jGNmoTMb9EWmrCt/OSTOswYCM/08kYVWNjKG9F8+fTabe/2bABHW9obzOyOP3A/Pq7fcYhlhvVVhzbN7v8WE6lVAVWbhAMBhKXj5+P3saizh11NBY7oz1vZeVSDD5sS7SiVs0yoDXh2aKa/N6Uof9AImmJPWPLU5h3a4A/LR+qWcII4JwjYSscJoNph5AcTnMT/T4Q/UsHQyjiPtXHLLtJp/mQg21dmR2/tzKB2dB8HKNgO1J17CCGGQG7Be7Tmh2V0UocCpRHSIcKZIiRCh0wMptpepvfpMvBYbDY3D/mrQUG5Gh1NuGxhIHyGae3Z4UUkHgNUfOMaMt+O1UhowwpyQ6j1lVCsTj1TebB8yUAfENTm6YmSmgpHRs3/zZjxjKaCmy8ZL62QAGMiZnY53WtbIrWs4MKX69DlhfpSZVrGYBaUgOl5JS4nurGeWwoeQVotGxXQ6c4+BGMf1lLiJNIUm3Nq0XIAjFwxe9wQMh632C34yAZ0CrKUfeWrqlk5NnhOMJqcyOnoCHPLZGJW3A1OjIH1cVBgONwp3uzLReXDaJVeoCy6wT9HYbc4ipk0Veu8k2tIdyD9OiPBw== 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)(346002)(376002)(366004)(396003)(136003)(39860400002)(478600001)(54906003)(8676002)(2906002)(86362001)(66556008)(6636002)(83380400001)(6666004)(5660300002)(38100700001)(8936002)(2616005)(66476007)(316002)(426003)(110136005)(107886003)(36756003)(26005)(9786002)(9746002)(186003)(66946007)(4326008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: RWWpmTB6wZsXpqV3a2T0Yy+v1SyHu4drWyTCLKpGwO/OiMWl87/aIl5dzA4YcOPmVZXFXO8PqL6jLIsxNThiIlWwFbEFxrE1H8tSFCGX01x/ubHQ3RQw2ieChXvtbQuWR6wBaCdVvbDEDQ60Ujm6E6KolvRQFF7FV6dPVZGE3sc8rHZp4fsmmNBJZQB3TXsebPRGYzMpYxvu6D5CuNsfTiPqprro+DgwBb4bCctfUgsWLw9aKMO7SMt2kQh88kHNCuuiBGfhCO1Lx1YVHYIWK8rTeymrsyk5Z1ETX9iSbyrcmX4ov/TkC9pj2xpH7rNUCIHldsP1evW3aSpR7A9RDjxR1sjpEoqm/R0lxaDzOgCRDPtKBcGoEuy2GdUdk/xPMHb6+V+G/EHNZOSf72QarY5x+CxW0oYffwIiqgLmuWPK6/z9P/2KvOVXLTGinlBwAtIjWDiP+kErgAWX1pAWziXaSVw85h/V6r4yH7XgfQzjKOMpw/8zy+aoJNFkeUcO7dMn8kN8HgiUc37FIim5eDR2MqRpgShWOwHMirVIeV/lsYH9sq/QdlXfDtg9bHcozkdgfaYetOm7oMWaTSfE0zFeDideH23KbZmmaxPthTdydIhtxRDy+GYuWPG2G+HOKoF/Y1+01IDmRAmvyFIhV5lBjnVTmlN6mgf21UKRf/sNzdVV5Q+Z2Ai8JiFK3ngHNmDOjbwqOpvgjcsFkBFFhSPr8zd0U+Eo07kbk3HsoiWzpFC2brxr1cT2YOwOQxdiRAMBqnWx2WAoRvIZe58ajpEimWqbnbcOLNt6R0dqz/ku3F93rRenccqN0yOsZg2giqrYM5bo8TVXX+Tc8kgxGmewEAI12ziZUomJi0Aiy09bEfzEXMQ+fLK9UUu4YcmBdN5F+gx6MR5IK3LjmBPKc/cU0cGzmWx+pDv4VYH1eZ8AZyfZDqX7EcU4Mgv1ZZvyPps8cLNR8LJvT5RmAMsjqKjyXHIRbMN3XkFnl2EPsv9N0gvDzBdNe8F5NbpgLft6jqLVfVV6oJUg5MMMkAfqPtU2dyewUw1iSy6osLLLWhXYHPQoyzSlpHS0c3xIa5fweiyEwJVf8X/+hY/GV/l7SMXDceIdhZvS2d1M2vm+jzsUrCfAoyDmnEGltu2NKvh7EaKxunehN6W3IXVTIs8MFa+jRw7v5J9/dHIsA2fXPkqFa/ND0XG4jjnfuuOLFOvz8PkVdUDXG7LZDMbhwezw6Sp5uW4sE29kWeCqNLiBd89Pboy2SJjVmh4+QQXJRqJ9lgrwRfnA9huR0jsSTrG8OiKkyMCBLMB7ZxZ+VoPo/KLcle9l04EfXMn4t5aX7OeerZl120VM9qh18JryRMTLgQ== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 38d6b32b-ba1a-46fd-751b-08d8f933e00d X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Apr 2021 19:40:47.6808 (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: Gx25yH/JHNuR8PC+Sa4gORFKDNK2j0rnHpZcisujurHJFhxjhA/GdtNRytJ5WqQL X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4235 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. Reviewed-by: Christoph Hellwig Reviewed-by: Kevin Tian Reviewed-by: Cornelia Huck Signed-off-by: Jason Gunthorpe --- 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 2a20bdaf614214..5ae06f951a0998 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 8c169d12ba7dbb..712fbc78b12e2d 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 Apr 6 19:40: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: 12185803 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 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 9B34EC43470 for ; Tue, 6 Apr 2021 19:40:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6F195613DF for ; Tue, 6 Apr 2021 19:40:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244952AbhDFTlF (ORCPT ); Tue, 6 Apr 2021 15:41:05 -0400 Received: from mail-bn8nam11on2061.outbound.protection.outlook.com ([40.107.236.61]:28513 "EHLO NAM11-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S242678AbhDFTk7 (ORCPT ); Tue, 6 Apr 2021 15:40:59 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jbuYIMwnWonqZR4dLf1NO5VNFUr7W2KU/mpEUC+o2IA9BN7OiDI56IIcrje3u3+W1kfTq8KpGLgQ4S+jdVXd17AT+MKARRgn+Gwnr2XN4snI/VJib6i3MWliDbA6GU5saBqqaX2Nads8hZkIW69t9iuBYaMpoplNjC4cyCnxFJrvT1gM7Ew0Ra3KfwwlES1NVCX/SANgKZmi5cNEEvrwn2ngydzSM5DOPMEGOYpqwu6pyBfvMI2qp0pnDmFG0mDilUvfztNYdi4IlnKMkaYgLpbP8YbUxQdm7YSWeivtoys85TUzQEJT0L2RiPfqqqcvBdI0wz4mJ4in3PVgyF36eA== 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=KJY1v+XlYCTjZlIiEJ2Xtq8V6wPAp2Rn19LM+ZDbatI=; b=S/hf9s08XT6szQpZbR7uUSuEIbMH1WzgSvLTAYAGM+xflRHcBnP2Eloz1DJ8qJ+F0NT2DND20uUUCpP4J4dt97tnqOj8r0RYx3uaZBBwwNidorbwzRQpZ5Fn9pDt2teGkXxcQlDGUV/D2QV7E9r9Pbu2cofIvOVNqqJ6K2xgcZvQBXlTXDlYsXeBn2zW2MvbZujjcoLEk47L4RTdTvc3MQ9bq/4bkqSfgS/3/ZExdYKCBFlHXvuSkLkh9BcroSIXrxnNbDKs5jJAl/H8eObAMah//PuTUGHZOZth9wirJdd+ZybpJqiufC5UV4chVWRMw+CzHrN4C5zJLlB/8OC87A== 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=KJY1v+XlYCTjZlIiEJ2Xtq8V6wPAp2Rn19LM+ZDbatI=; b=K9adWXW97cmN+MmQA5XgUJxYYZ0KhLrQ8lDrL30XPO1rqiE98t7BW5AubYB9BuYtGGBHelBsYm435gzYknFqO1TJh1NHBrR6vppA6xeyWZz/ds1FfJGK+f2FzE0oJzr8JxcMBob7GkCcDSoIvkwOYFV9JfJeN19grKevIB6UL4y9tVxj9DwlejnhoF+Ek6UZPQ+ui8znzvEegJ5zbXFL2OEWHxu6GFieloOAsQJRGbBD2/VNvJu05tacevNmp/wWXTViK+o10B/zcXvFr+ajNRGwGiNI5b1X3d2GU/ZkuWtN+oN98BlwtAeDxXcPbYNv5fvaKHdWAIQtmQwI8vrSQQ== 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 DM6PR12MB4235.namprd12.prod.outlook.com (2603:10b6:5:220::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.27; Tue, 6 Apr 2021 19:40:50 +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.3999.032; Tue, 6 Apr 2021 19:40:50 +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 v2 12/18] vfio/mtty: Use mdev_get_type_group_id() Date: Tue, 6 Apr 2021 16:40:35 -0300 Message-Id: <12-v2-d36939638fc6+d54-vfio2_jgg@nvidia.com> In-Reply-To: <0-v2-d36939638fc6+d54-vfio2_jgg@nvidia.com> References: X-Originating-IP: [142.162.115.133] X-ClientProxiedBy: BL1PR13CA0281.namprd13.prod.outlook.com (2603:10b6:208:2bc::16) 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 (142.162.115.133) by BL1PR13CA0281.namprd13.prod.outlook.com (2603:10b6:208:2bc::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.8 via Frontend Transport; Tue, 6 Apr 2021 19:40:45 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lTrZ4-001mXa-9c; Tue, 06 Apr 2021 16:40:42 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 40da97d6-73e7-491c-784b-08d8f933df20 X-MS-TrafficTypeDiagnostic: DM6PR12MB4235: 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: BjhntGBWS6Qz6N0xmWV/hZwzt91i/sB6UGWSOupSnVW90XsyYLg9kZZfhbFFeZDhRwFwXq5sMuUh+M/FwM1fy78GxUXw+LE9r5JRoyedKUJI6VNHH1EBslIMKjmaW58WGAPbvISrHyjVdBKSFhiowRNe0xoWnvBgRy0gcTVHSZS808ikMEN263Rd/VcW1aSUOvKtPqQ/17Ob/UzvqkfGFPCgX/x5pYmsE4+EUgX0SW6CIYaDyZF4T5SPyP/ev+jCv7SVEXgTDf6wexmpHhy3b1D6Ih6rNGojZrTTEdevlQtXqzb31Wv+zZP7q5Rl4yGg3kVPajuJZvluYlBaft0auRkHWOxvbAYMG2L5fY5WE6idzgNdWlk/8B6rJwsW3PibJLJt0konRyicUGoh95hCzv/obu67t2gfwmKzVe9ShfRod+Tkp7AlM0+UQL2IqHMS+n/V3kuFWS1eVJbN6Vi1p5rCUagx5swkXuRhJuoMSQ7AUOOG6TqC1KuPwtwvxVP9CjR55b77Cc10+68dSWi8XwH2zd7gc0Va+YxiAwKxL8rYz4hCo+mX8l66eeVZj3O03Ncw56MdfE30TI0D2U1boEVxFj3FhWER6u1ABf758zhEQzQoovI5XpA2SyT/fu0R/XYB5bIHb4GCjCFajhbpP7u4WuREfvzTX6cDE9KRU+o= 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)(346002)(376002)(366004)(396003)(136003)(39860400002)(478600001)(54906003)(8676002)(2906002)(86362001)(66556008)(6636002)(83380400001)(6666004)(5660300002)(38100700001)(8936002)(2616005)(66476007)(316002)(426003)(107886003)(36756003)(26005)(9786002)(9746002)(186003)(66946007)(37006003)(4326008)(6862004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: nSoEqHs4F2Eui2AxD+QNFLwfKFF54IXxYyYGoESJnMA5FQMCZtRKYWBU3XqT/WXFGTR3tFUMVY3BO86uQZ3l8ePT9cwMToTSFXWsTP4nJIJCMj4qADhrx1x0ag8i1Zovj14iQfroQDJN7BkM2xrvSJ/SXy89ijURcHPG1NBLwGLiSXs2bMDmUGM1W5U1A8bltJw7E5jj7+gYyyxlOSUXo+0ais/J9m2uZJZbdePs6+6JhKrK8h2CAMp2SvGETE0unxyDNXU/IdIi9jr0TeOskVhXQqRk0eC72rUUYo7rjkx9gTBzjcKzsm27pWhc1Z2pcDGfk8jgdEUj7I1OTwiBzjvGlaELdqDZisLJzVuLGgeFPOQs0zwGF4hKyNA3k8ZRnEy0UPyc0j8Ds7vB079npT/jkEu+uT7uNRc9BsP27z88uAyxnf5ELL24vATBXptWGsm72bkX+orwcFnAbmnZBrX/WaSTXki0V46PVCsae2R3Q116z5Csx2LiqBxr8pa7YuPAjfz2Nubn1lSB/VWiDEgUqFmoHNVbQMN/ZK/kQMRZse8lS5X0/HUVJUJcAvOweuBi2eCi5Kk2l4JonUIdyOVUHUdaT1SOaFC0cgmJ5x8RmzUn5M7p43xQylrI30jkpzhXy4q8EnIPUSDP1d1eqP39m+uOdjPgH6rJtPLrxt/ByKvHEmbJLygNV9dP3D9ChQP3ugpLgepMt7AllLAUq+51bB0qAVTVJPqSVDXkkGDFImFe1VLHo4eGs/l6ZJLS4pfxNKwpvXwb3LELzEC4+QbAMKmS4ut24SWod8Dw0YFiQ4x9gv2Gtft2RVPQOaZH83wpP8w0hGww0UUTdghIhghVOlY7uSu1txZG97loto9xR3gszxnW3a3MkzYfyOwwBcy2QIrVNkLv0wD+nqDzDktSc52ECd2QRhtjwh9TSztDrUtZ5jDZLumw76fqaWJvnD8rdO9jI8pNA8hQhFIdzs10O8cEXM1KV1+eyCewmTF6GftlpXeNcRYXF75gkLPeoV0QsWeI40nGxQP61/DCBwWvLQl3AkrgAly+b5azAl9kmmoMKu0zAbhiq+2IXDTlT1LUXT34OBYWakbIXtXiky+0m6fXoMm0zTqs6FWLS6Gqs0x1N90T8xDcZD9XCUU8weVYJD8NJWYY2f8+a9vIRd+3lJC7UNUDVQp5IC9tV8oKExBk4z09tyH4OpOvnxCnjeFwMLd6LjPz0AxKSyIG1NxbKRJvevOavbBeeuT4oHA+SLELpcwSr9QfgRdpMQGJj36cjR+q9e6pLACsan8lXtf9ftwmEBcYC2ZHe6DYG94uEJ1fFMX7VBgtYdNiYaIR+RcjfmCvPQjs969JEpw8iA== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 40da97d6-73e7-491c-784b-08d8f933df20 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Apr 2021 19:40:46.4625 (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: NGyNkm7+7HrB7hnp6p6FHwsckWaGeX/7ug44IV3LrPIZkxL5clW6YhNsIsSX1YHO X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4235 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. Reviewed-by: Christoph Hellwig Signed-off-by: Jason Gunthorpe --- 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 Apr 6 19:40:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12185801 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 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 E88C2C43460 for ; Tue, 6 Apr 2021 19:40:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B7A19613DF for ; Tue, 6 Apr 2021 19:40:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244932AbhDFTlC (ORCPT ); Tue, 6 Apr 2021 15:41:02 -0400 Received: from mail-bn8nam11on2061.outbound.protection.outlook.com ([40.107.236.61]:28513 "EHLO NAM11-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S235424AbhDFTk6 (ORCPT ); Tue, 6 Apr 2021 15:40:58 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kv7hkYvm4GsEhpAtD1JpeT5psO2eCBBdWUcWM1cfJ2IVY+aFC80hytcu2+16K9eaYKSny4KH847RIQspiwol75757KqmJUMGX0qYkhPhYG9EN9JOiY1CM1tqBeKRJu94RCOhkr5yvbCEX4Zoa1zHpr3KrE2Z0I+OTiq8Zddh1X+aIEbSS32wQgrbL37Hi9apAnhumH8LbXyHOtQvbzcwhNR2L4O/V17Eni1uLwQOwjMglX7S/SqmU3BiWbga8DQnzLIRBcHIuForZGtWdb5GA2jEENHj6ip63ZOpWloEI6HnGTTKExblTwWuQaZPHxwtBnS7rwxcBjlwnZOSZqITWA== 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=NcIiMWSepG5xkNLmediyrsbbka1WWxMuSvIo2oTYikg=; b=fUdyy93nAE8CpZXGq/TYocrafNu2sdjzP9tWdsmCkhitLY7C1UyIn+Dub97e96ATKa2Z4kC7Plzwj/wB+oQdfMKcM6Ztr5EB2PowJlyEMog2dw67+RUZ0WPoJMwy/QVz/M3rjnZ5slwMY/DTIruK9tclyxHDsFfHMmV6jBg40dqWMyoP2fpdajxegN5CHLRDg05rQcIY2Ap1u607GxjaLuIb7AScJ0MVOMG+JGxq0/sFMlBg5B5UWRQNoS7en4Vzl2PpeLT+Dwbl3pMaB8merrPtTbkI6G7WM2YkgxCmvzQn8KUPRu/RjuRV/ps3JMc1GvCoC+qwwDaHZggn/jyT0w== 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=NcIiMWSepG5xkNLmediyrsbbka1WWxMuSvIo2oTYikg=; b=SF+CpBf0UPvIlQL95N6krVVaen1oiPL3BS0ETTLGw0qsjepSBjCg1FUhg4XvLMWF6jaTB1U4H/rMwtlRqRGprn9Hnunl2dnukuoLdlpFpOdcyEzR2Fk4g7JRJFb+sY17z4Iy/RALg+U7N/sSQU8U4UmudrMok7CArXwfmzElUyQuosNDNujK4DzNcXZn02ngd4/uhtx4UZKMW6C8UhGE96CX/h0lkVcqNecKh6HUr3iVsEqXHBx6FqI1KLI2/BTvKk5+1udbOiVM7dWscnt7KWazoCiycKZssZOp5NdYDnvYNFMNOZEPjPtjS3vox1cvhUX4/8t6CFzG6am+2z9Ysg== 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 DM6PR12MB4235.namprd12.prod.outlook.com (2603:10b6:5:220::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.27; Tue, 6 Apr 2021 19:40:49 +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.3999.032; Tue, 6 Apr 2021 19:40:49 +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 v2 13/18] vfio/mdpy: Use mdev_get_type_group_id() Date: Tue, 6 Apr 2021 16:40:36 -0300 Message-Id: <13-v2-d36939638fc6+d54-vfio2_jgg@nvidia.com> In-Reply-To: <0-v2-d36939638fc6+d54-vfio2_jgg@nvidia.com> References: X-Originating-IP: [142.162.115.133] X-ClientProxiedBy: BL1PR13CA0137.namprd13.prod.outlook.com (2603:10b6:208:2bb::22) 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 (142.162.115.133) by BL1PR13CA0137.namprd13.prod.outlook.com (2603:10b6:208:2bb::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.8 via Frontend Transport; Tue, 6 Apr 2021 19:40:45 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lTrZ4-001mXe-Ac; Tue, 06 Apr 2021 16:40:42 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c843c9d8-62bd-4594-c280-08d8f933df19 X-MS-TrafficTypeDiagnostic: DM6PR12MB4235: 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: 0C0ghdNeVvq5+k78pSKOK1X1N1q0ppnY2Fs0As45HIypvqRZ1B6aYDAtrW7rv96VkSgWt3vKNnSujTY0/cfyhoNv7pDlneW0EYXRfp7B9Njy9sktfRRwupD/Nw0tR04H80OPW46hiuLGZqGiCcde8RvR5NLLBsHpiH+DwzAf1NqKUEyjqeVY0rsUJkAYkE7gSk3MLJOnjc81hilumMWHozfKgiX2xL6y0osR6ph0IbGOLJHawNuVfrqDEBrCnuzX2U+ATb13KVxoSlWUMFNBxGhTGpQzSvYemKUbYyY+VLfGTgU5jawkD/ZRrBH+xohYodCLAWv15ipoYtM5Lakkz+ge9zTh2Zu+Oj9v9oDksAMNUu8aoYaDG/aI00Fj4YQbpRPxhFk8fZ30aIijrwxnFyifleKGzYPfNLtMXccSeWrK/h+UFEguicJLaJXsQ2VwWqUKSAJ1CNxPMv0xJaMsWRVavoQbv/tt5v8IrTklDvNEDZb7xVqg+GVMxfzl5WEyKfGjI2PrMcgssTdIn7Nh4nXUhfZae+IP0SSeg1Lu7WjSlgfIPMgryZ77W9CDHZlq076EVH8myFDVxuSicbQ9hwFmLnMx92NOc6sXu1BZQmf7bvVjk/rPCCpBn9tSceDAQKoEYDqJjVmpPUO1lp3qsXM55x0UZdwO+u8MiKLi8uU= 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)(346002)(376002)(366004)(396003)(136003)(39860400002)(478600001)(54906003)(8676002)(2906002)(86362001)(66556008)(6636002)(83380400001)(6666004)(5660300002)(38100700001)(8936002)(2616005)(66476007)(316002)(426003)(107886003)(36756003)(26005)(9786002)(9746002)(186003)(66946007)(37006003)(4326008)(6862004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: CHtgf/4qR0tH82fgFx023CkFI/s/wEQ26NvQpfphFiUgq7yubUJCWMbL+cb5bh9cVV9OhXZnT6GpyLXDbWe74fbsYOHpl1YKIORQJWmSQmAGUlaPEpADm7hBaOWqO560bbtUcADgKZKo1CVrFsX/2J6p3byQWrWNQHKFTC/XB5EnXafYSLtW6Q49ufqGYdvYkmvt/PKTVopNoSE6lDJnGzucPH8MjfLwmxwhhC45CPr3Hiu/yb3jwyk782/mKBZLWT40/HNA7C0buijh9g0ZK2yDgbo9UWbGzvHShkSIyqt+wEkCttyWBBHcCNZCn9KJ4rCu2IPmlaZlt3Ltjts32ULXbAeVcOcwSvoKDgeJ5Cn+xnmAEDGhwskrsRd2AE3/Tyy3qbpmNI8In7zBp+ifZdRH7WmWvf5IdPYcv4smrjuoho4vq20YTgUQJ9kWajuOmBgjmx1TNVvfVdc4JEXsWjlpOoVBQF3PPhOAiaPSH8eJ2mc/MHggjyhqEsPMs5iwxE4A82Z4D+Qjf/UKIxUKkopAvkRWvAG40jlYnLaBhL5d2uHaUMOMAuSr18oq3QaqvHhkPeFYCOcXqLCROEd8y4ebFGAKSRP+esXLgAnJFoK/bCSmg1294Dpvw0RPj8WhJyy7plUbYNuMhq76pFQxA5JNLOqrwxnfECNb4LnKa/PHfqcT0KEcPVeRQtGCtKwAgj4NOo4ZTFTnENk+85dSIcN7Rp5l6YSDtPon6ZXNqQiQnbHSYLl6EDzyoMPfFXHOh7laMyS+ekMqNVGKlWlZ2dnRZzdTYp4vpQw+3vCwVs/RT4kbfFPaZ1/0xY3pfBDyEAeH+HyQSyWQybj8a6eXOhLZuxqpvP2W2yAEaRwbcLn6b2iI5sT6fIsC0vW/I09ZbPWWyUXywvyKu0nDvIM6I8jDK4MXJmFpJS4dJUX1nHTrb4mHxszY0XrAzRw/30CDtV20UvKG90qck4oVr7XHcR5BPs20x+/vAZoQ+PFLPsAtN8GHoNPM5wl6QPbUwKMKxvwA202ljBsfgBwcbwM804Z3lAedElIa/ozv7zMOz0PuQOHNLNoIqOG8cRpri0uJZXv0oOpZeBxAP29WE8QxqSS+tlr4OWvp/lZDzk0HIVFvLgOi70BbCl95Bc3aaUWswvwg1owZaETNCDyW0E4dKmSn3ijbiaNZ3tD2xbXajmMup5SFKaSsMZ8vDogvRtrKRttKfVFW4PQiZln5rE9Fw9hGGgKIJNUtjf+QDTPA9bAhPUFecAxrAwW3U36S0H6nlflTJ5W1HIuCE2oV6Mksuh0Kv2HpANCegfffHfalodXf8NBMRgq6e7b30d2lDsZWmQ0TMsKFN0JxnTPXlYiMIw== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: c843c9d8-62bd-4594-c280-08d8f933df19 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Apr 2021 19:40:45.7869 (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: Jq4JXiKW4OenKKJvIUgLzCUYWLFM3RUXOHbfilvbnnf04QQ74PoPuLyq7n17bt0/ X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4235 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. Reviewed-by: Christoph Hellwig Signed-off-by: Jason Gunthorpe --- 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 Apr 6 19:40:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12185807 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 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 4C9A6C433B4 for ; Tue, 6 Apr 2021 19:41:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 12D26613DF for ; Tue, 6 Apr 2021 19:41:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244917AbhDFTlI (ORCPT ); Tue, 6 Apr 2021 15:41:08 -0400 Received: from mail-bn8nam11on2061.outbound.protection.outlook.com ([40.107.236.61]:28513 "EHLO NAM11-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S235032AbhDFTlA (ORCPT ); Tue, 6 Apr 2021 15:41:00 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FWFb8OqxkAewOHhmLwK+Xga+szDSQYjwQimqMpMUYpqAIaTTx53+c6mTDU79d+8HkmUZfX/Wk5aUzeuozW9pbbHuA/2D/WAJ84qDgvgCpoFrV8lijgTHRqM8HZXhf2VcGFX1587EKP3buCvnAaWe1sgspgkRB0h6qN7yErfp2KrPq9MW6Uqx6oIFmBuTW+r4pjWjAPFRggs2LuUMXwlSRdkZNZP3Ung7OoUJAJZycgiEiKJ4rMMmJEJ4b2f/W1g2TO8t/Pmff8RYjKU3EwK5HfHtLJTd6mEG+ew1ng7/RXosoI1GU614Y+nIgULX5wwJQelfLbPBCd5F01zgJnbe+w== 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=gPUQK6SRzWAqaSFa435Ur46M+774ajpZWQ7Q4vd7U5I=; b=S9iyAFTxV9afupZvIMngz5n/nUrVTZ2uXM+O7wNsSEwO8eZdNHd8TbDG2N7dwIh3ajAPAqJbq1VbVol2LibN62Sq6IuT2CpzETIKfXHjm502GYwQyw+oeue480MXShWhEc9S4dSUo4AEfpn8NBx/Y2fDoJQEINBpz6My3GVHPKj6ZSK2pGa6VmDmrcNqDXDYoSxp6iYJNC1a6e5aW0dGMoXUwGciMPE7gdi7tHB2Hv0z4SXODSdU5yQBE8iVQObtm5uPwSjx2wdE2X4pYeKoDmeAQIDSCLyHkrX+fUJiGLgY6YNa+6HbjAsE6FU92rHOiUENFlekwqa6LW+9ctXoPg== 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=gPUQK6SRzWAqaSFa435Ur46M+774ajpZWQ7Q4vd7U5I=; b=gb0MMGf6tvj8i7lJUKrKkLUwswLJ2xK9wejyMpdTm7sd0gt05GAVRk741Q4mY0jXCE/j5ki+RLRO7jKlhdVGRwt/9r/VaSHSm9eo74HPqWIOr46BZzfWWbKiU+Ljb1tWgnv0avKTPvLfFDhm7QMvymgG/3jxr0Lk3eKVwRWkjfQxG9GSEtiDaF+mo4fMIaokbtFcqr8jqhcV+bOZ3AR0N15zymGrWpet9HcmGEBhUEPgYrsMID+pTGtP3Rq0JU3aBieeW3wzdTRA3PMBjm2te+4TgGUHGDwDG8AsoNubY2xkMwX9k3CQR6+Y35fsV+StzZog0C0FQo/g85H6UCFVUA== 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 DM6PR12MB4235.namprd12.prod.outlook.com (2603:10b6:5:220::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.27; Tue, 6 Apr 2021 19:40:51 +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.3999.032; Tue, 6 Apr 2021 19:40:51 +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 v2 14/18] vfio/mbochs: Use mdev_get_type_group_id() Date: Tue, 6 Apr 2021 16:40:37 -0300 Message-Id: <14-v2-d36939638fc6+d54-vfio2_jgg@nvidia.com> In-Reply-To: <0-v2-d36939638fc6+d54-vfio2_jgg@nvidia.com> References: X-Originating-IP: [142.162.115.133] X-ClientProxiedBy: BLAP220CA0021.NAMP220.PROD.OUTLOOK.COM (2603:10b6:208:32c::26) 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 (142.162.115.133) by BLAP220CA0021.NAMP220.PROD.OUTLOOK.COM (2603:10b6:208:32c::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.28 via Frontend Transport; Tue, 6 Apr 2021 19:40:46 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lTrZ4-001mXi-BX; Tue, 06 Apr 2021 16:40:42 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2fcd1cbc-455a-4d1f-4082-08d8f933dfd6 X-MS-TrafficTypeDiagnostic: DM6PR12MB4235: 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: WSHZNzqw4cLYIM2NkfC3Yj4SgLx5PYAyqUZ5TJigawoERXCiPQK2s2OMGvFTqVYIQ6p4acNtiCfIco86E0JOo9GbNZJGPB0ees04G32w+p1pNXHqYEER4/HI9KONVUAG9vvI2l/7ZDMTocgLJe/PKLmCClsN/79JCQ2reD0f/VIbZKeQhSzy8FrZOT2zIFJyjsdXEoAULOc0YGVjsPfeacyr3ymSwHJ6MnIb2IWKSdezxZ+2V1HepIAp3G1iuJ/8uNHOXtvwTK+UV/JdWmRE4n2ZcsiYGaxP0L5tBIo+mLkwysro9S5FWvgSMb1QQVndNxLp4JJMh1gNw4RyrPBlqWg5UvW+Cmn/2jkg2UD3LH0m3k3mk4MJRsKFIM/hR3awoMeo8IMR1QAra0qdK0kr63OSUg+f6mDrE3uYNn2Ofu/koott6NLMwVE3dy8cbDguIXOTvgMdNgc0lV9MxVfKybyUHp6h4Skqg35yICrmIQUTFSb/qbbyeEV2gG+9ajXwAmxGdcL2boQBoiRyLUr3Alw5c+z7/uHAaKbc697tdarkDuaoyemQOedeyeH7Rh6aTsfikHf2kl3RZPQmVlrFwqWZvoo4dBPQ/DBZjJZEBYKkclvEDwsSzG+Ff0PObBLzUZivubNhv3uGm21g9INWWrPP94nucHgw8H3OqUnZWZo= 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)(346002)(376002)(366004)(396003)(136003)(39860400002)(478600001)(54906003)(8676002)(2906002)(86362001)(66556008)(6636002)(83380400001)(6666004)(5660300002)(38100700001)(8936002)(2616005)(66476007)(316002)(426003)(107886003)(36756003)(26005)(9786002)(9746002)(186003)(66946007)(37006003)(4326008)(6862004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: dUat6f0JCAdHd2r71ksT+49i5RVIJZn8NUfk8p+EKcM2AT3y1x4YFRcExuySF2K59Pt4P5Cv2P6xzilIVbZKqmjE7BvPWrwBY5oVilhuFKOWthVI7N9gA3KW4LwLvVQELxDKOwezq7Ovo8kcJtBqmSrZfkC4exeZO8sXiw5km94zydPwzqBVO5gFQBWOojOZ/WokzxeH3AfmHqjR8CdtXQIcB1a55k8RSngGxtOEpfNsHvoM4n83OS9l8X+eH/I59SuhG0lM6X8dw69OhO3DFRBG/i824EzNCFOE0OyTplR+WLBBmRnNwmpaHxvol4+FVdKVHjCkpQOK6Wu4qbcINRfY8oUBbnjOw6f3WOL9SBCKraNeNnUrmjwvn3e1cdoScBlZHEjwsbz3FcXrTEiwY2RW2ibapBa2XoaliuKYjtu+o4FdPHwj6gvG7J3xib8otCpvT7o5xHnSX+VtfZZdjRTkPv6IHu81a1dWSxn3hKT4tcDMVNOPdhiabJeHv8967cOariTHOz7RbUBuZvrDSFMrmR8GDEOANSn+Q6r6Sdem7M3cu/jWDXK4AysW5SJKG3UvxR8+a2zfORX1Lw8uAdPpqcBuo2FNce5mhUghPrw8LQGAfB/ORSMaBFpsf2TsqdfkeAvzayj3k6y8Ra3L6eNXJBZ6oAHdkmpNcs8++P6SNhGvgVF0yFe0ibPvaWLTGAsOQBAMXpX2otBRzP/h/x0UkXPkBhv7sFkM3jJAD0LCs4CDwgtAVN7VJEwITBtWGOz2mBTADs8bqQ54kpc/aFsinVdOxXwYjrw4ItFaHpfl9JpTJmaUAaURqzrB3I0cxVP5HSQMW6mlpfAtGV7u877ub1ChFY1Uj+gMPHButdqVxMy4MInre82aYAqFLcErwVYjmLIWb8NLwzqC6am/KiTlJunn4qr4AOnlvU5dAax0YJyJwD6HzBRguRVkhSeTBdXryA3KVPss8spfCNMhAkzL0xg6Iu03/OeKUHRV6jhwKvat6Ra1WLFIqZ9B+xLBooHYdLudBl5b1hqJAmjMVkr2l3ReQGnlZpQSeId7slhA81W9w8kElKdt5vNCRIzKFrILYMiyr1xlIwCmo/vETueLUvVF68PMlsHUu0ImyEZDOE/qUh7f0S7MwSmA/f9MLfI8hPQOTp8PymcchsAzHJdPoIp64cdbM+M8qzs2rViRlK7siS70XfpCf5IJ07VlNeWqr15214X9rSDzpEddi2v5eFDHnrQswJjH4IEGgu6TydtSBxft+jK8kJ37QGB1M06ru4vJpAp4WqS5CmVVicSxHiA3qE2I0g3Ffkwzdgb2ZtNnpAdSoMrAEuSsiPVVpuIFDI3j+q6f+nVb3kmrPw== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2fcd1cbc-455a-4d1f-4082-08d8f933dfd6 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Apr 2021 19:40:46.8532 (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: a+lrh5745gowm+V2FSxt4YkSPAIEXTA7xyKysW8GyXAhxmINpPWffVv/2jJlLfal X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4235 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. Reviewed-by: Christoph Hellwig Signed-off-by: Jason Gunthorpe --- 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 Apr 6 19:40:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12185837 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 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 1F4FBC433ED for ; Tue, 6 Apr 2021 20:07:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DD20C613C4 for ; Tue, 6 Apr 2021 20:07:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347148AbhDFUHe (ORCPT ); Tue, 6 Apr 2021 16:07:34 -0400 Received: from mail-bn8nam11on2073.outbound.protection.outlook.com ([40.107.236.73]:26272 "EHLO NAM11-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S234411AbhDFUHd (ORCPT ); Tue, 6 Apr 2021 16:07:33 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hKaYyFNLaNQOZEemqx+qlQ2n20kZ67guoxSFxYDvegm5fE0bFGBLZ0aPdJdhUpLMyFoogLJN3ZlL7UuRyQx2UTdHMAvYM2lUoDZHPN7QSHrGzDXa/O1QwmrFH8dtPmhNtJ0MO/J0K7QuZ+Z0C4kziNl78juXYLgiSaRjCiAfjWr+XmuMYMk+w31ax8EE57R55+4pvhkGRZRdUs0aPzrlOyqT9mtMtzuXkkO2NSl59bj4nP1yANpgYOXJ5KLbcjzhk1xrxhjFjJ6aQCDG5WYIM74JmoVz4QRqZTX54LQZqcErhS+eQ9GaNYl1a+xqcHOwaM5nALTuSbrSFegOfrslkw== 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=pQz5KvjjX7thR+DVlFOXa9VeJSk7pPDIRbsC+KXJL14=; b=ClC5PWnLYp1OBqo0VtByrW2B4eTLQGly9ybavPgbQtTn61nrG6XrpQYyDg4POULQIR/seiCblMTeRSMTnWuWRWKQt3hulpv0D3CqvuoqIp/bNdLhnmXpnwsMR2e8XfLI0GB0DVClyf4w32bBSaiCqdixT9WNiVXRDtOCbDU84JjDRcgiNawDcwnQTIlb2KTZW8ig3pAkXug4bLHNV5OZ5HHSCVap5l8cq4hlDFVYUnDD0XsnOPHufe4cjh3Nw33E0FxgEBxlQijXZO+WB69u2g/6bPg0LqgNz3g+/4OWzlc7g+bYCIjVF2WTEfM64CFh9EggBZrZG4V+JBK2eIA8Zw== 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=pQz5KvjjX7thR+DVlFOXa9VeJSk7pPDIRbsC+KXJL14=; b=QfFr32B9vMcAbiYck7Hr/4oP8Mc2U/jn6+qRnC0xkB739fliwPRUqs/xlHedbgTEZQ8/r1Z7qhUCOBvJoam04j7dSGNxZjJFp+y7FldSsX23a3AuB99OAAlKHQA6hWEGlHP1CxDR5HXxeQ1WIhvPIN8IacEZd9MWUo4O1ZAqbsTIMCiXSUdPTaelIL0L0N/MtbZ9o0ZVcIXSi9hlWjTmkN4zrInIub89XjhKDP9XS2FRij+v6nlNVrxMFo+8CyvKCSzHYadtJOAz60meRfr+WEHao+Vzb2ePk2RRtwN+AwNhm7LW+EzaOrzaawCTvujfojVv7cto+jEudje2L0dxTw== 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 DM5PR12MB1883.namprd12.prod.outlook.com (2603:10b6:3:113::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.27; Tue, 6 Apr 2021 20:07:23 +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.3999.032; Tue, 6 Apr 2021 20:07:23 +0000 From: Jason Gunthorpe To: David Airlie , Tony Krowiak , Alex Williamson , Christian Borntraeger , 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" , Cornelia Huck , Dan Williams , Christoph Hellwig , Kevin Tian , Leon Romanovsky , Max Gurtovoy , Tarun Gupta Subject: [PATCH v2 17/18] vfio/mdev: Remove kobj from mdev_parent_ops->create() Date: Tue, 6 Apr 2021 16:40:40 -0300 Message-Id: <17-v2-d36939638fc6+d54-vfio2_jgg@nvidia.com> In-Reply-To: <0-v2-d36939638fc6+d54-vfio2_jgg@nvidia.com> References: X-Originating-IP: [142.162.115.133] X-ClientProxiedBy: BL0PR03CA0027.namprd03.prod.outlook.com (2603:10b6:208:2d::40) 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 (142.162.115.133) by BL0PR03CA0027.namprd03.prod.outlook.com (2603:10b6:208:2d::40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.28 via Frontend Transport; Tue, 6 Apr 2021 20:07:22 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lTrZ4-001mXu-G3; Tue, 06 Apr 2021 16:40:42 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c16b43ec-dcd5-4cc6-a792-08d8f9379728 X-MS-TrafficTypeDiagnostic: DM5PR12MB1883: 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: 12ZzVD5Lr87fpvFfZOj3vtlSDl8Zw/a4G1+IEhgYYx2uhlo0YZfJh1FVE+rR0GAcg/tFihwHSCNSUs3m7YDiMrV8vqtwNALKWjroboaAyhpYICb+MctRc9lmDkXUIhQLUN1dhJUtTcYmlJPAs4ukBUHivJ/ttOL9bxQomEyY3ZZFdKPzZFWwioqsBwkcyXzcsA4sNTiZ+NBdWIVFmwThlvc1NnR6pTYFEobcv4zJ6XY40tLFGf+48Hn/w9FXZ0wrdWc03EaG/jhP7T2HSf1/m2ulYxFy9CWUHfK1wOwN5dvyCXzT6nIVfjZqyM25O0GQNy6+pBGWob2abtRNjPdXcmetBA9/BrIM/FTd7XDpaNusIR8GxfakZFzQuGMhlXHP5TxVW/7WRmyWPGEXnzm5uUmgpaJLLuowJr2Ob57xyacSwoPIqyhhdj77xLEuxU263RP/Fc8OSXSppd03P7+Ut0GLznHD9LBnx9EzwlKUYaVpHYFVOkYRv/cR7B65/wYNMtnezy6ewoGs11seYrzTGY7cXzH4uBBiSsZts8Upj4WP8XxqEaW5Bejt01Iw8vfUaC/gyBFjC28Od+c4t7MvA2F5fE2k/ZoVI6gGp5t97GSnB78EIeDeALfADmUhCS7OYCdiBOScG3VnAdJY5Z6BVNK5Q2Zns7zoWdyLdT5C0xAnaIyV8VClZjtZLILYtoL4 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)(39860400002)(366004)(346002)(396003)(38100700001)(186003)(86362001)(8676002)(8936002)(2906002)(2616005)(316002)(7416002)(54906003)(478600001)(110136005)(9746002)(83380400001)(26005)(66556008)(5660300002)(66946007)(107886003)(9786002)(4326008)(36756003)(921005)(426003)(66476007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: GGibTQ8RLskmI4XO6PdQDP97SIeXXTeK0Sw6sDdYWElf2x/uRfvrwXXYvqifgMsBqRb2mvrYv/eautLS5iVXPPvs1HB/4/D/c7mdVt7CMYceM+TnvNY9rFDMa4N2JzRIz+scV+xwfkG1FeVCvP8OWIx4aa9wWJQtN1eTl46TBejt4gCicnsGBll7dvpne4Wsm1ZJwLYKboKQiHM4pKUZ/MSzztdJKsjb4mlfpndYpGu0W6RNy1g6u2iGgXnTf83Tw1kgUv28AN2oTnYooIpj7WPe5tDVcuBseVp82A7eXnaLkyLsZ2aBfHYUH6dVJlCfjapYnZ6UGsllrD5DnBcdZ1TL5TggWpwPuaIJmmdgfYgCGcU/1c0D8499ijVAi7B+12XBbA+zy0pQoCxbPVENz+1Wa/bA1GQl9TaqN4t3fCzoOF5c6KqKH7KpS/MYFfs2FCXzyaUnrNMZADwovLMjAe9Uc7sUUOlWP/iGtGHW43YvNhjF0m5pVBZhQAjyJB8mZnYRmH1fpmbCXteeFI6ytVwf2TKhaoM4gT7TAMtgIjMiS+uALsyS5AXsZZc0Z8uul4d0nalZqWjdfvYxLfhyc3ZTTCbNm5pyKIFmuWVlxx0NaMIRwGja7zmXpQIrDGjqbP0cFGxITmIpE0x5/T4GKrBMltoelaCEo4USzaTqjHAFoL1xjoe6l7Vul3Rxjm5S9vAkO5JUWwoUrb16NICCUjVQvvGVnsFhLs2Weoi8HOCe1fFSWxuG7ARLhfe75DY1M+/xgLThPbjIRV8gSf9cplx2NGrkQepaKssmqgV/vmgFW6Q54ivob0Vyo4MFI/PnbEGVEprrkOBloS83Bge/KROc9BIQXU9o9eqleT71+iQWYks4qY9i4j3MLadbOVg7iK/nCqgtoJIj5ymcz6HwdDMt8+HBmGqUPqf7Tx0Cie//np/s16q9LkdGj6wfAxK7pjFYmDhZIRjSlW1b3sJOiVN6UIaz/l7sIwINXlNX7RQJ0lwBQgxwdVKmyWrCyGpxiDrYCiH3kjDBVYMvZKSUvRiitYiaJ5iPcNQa4yhms3+1dWRW2Bw62+KE3IfG0PzDDTQkMANtuZz3w0SMhzA1WCxE+u1yjiIkinmx+F2TI/0XWVSsaQCTVjVtopz3j781mid5aZd+oR4+Pue3nXwa9WnZxiXaBA0Do1KxKzKsML4cxL6D14oCdBgIkKAm1xWbgn5Pmgxn8GnR5d8LRZxy+i1OFAXO0L6kSpuZGdkNZtcpIC3SxpY7mHVKpZMctp2P/Bi37UXVfGDu8z+mfT3EsOaWWHeByXg711Vk9ueqOOCI76CbMQadF6YI0lbjasIr++8czRnZlfna2OZaEcFz/Q== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: c16b43ec-dcd5-4cc6-a792-08d8f9379728 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Apr 2021 20:07:23.1174 (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: EAt7p3spiPjS8SsQNFCHDz03CNjrL6DLOxk65OD541zQJcWthTd27IOHWxHpQ0Sw X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1883 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. Reviewed-by: Kevin Tian Reviewed-by: Cornelia Huck Reviewed-by: Christoph Hellwig Signed-off-by: Jason Gunthorpe --- 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 767ac41686fe2f..10407cf67583c6 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 1ffdd411201cd6..d319152dd484a2 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 5ae06f951a0998..10eff33ce1f263 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 out_put_device; } - ret = parent->ops->create(&type->kobj, mdev); + ret = parent->ops->create(mdev); if (ret) goto out_unlock; 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 Apr 6 19:40:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12185793 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 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 A1ED0C43462 for ; Tue, 6 Apr 2021 19:40:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 727AE61158 for ; Tue, 6 Apr 2021 19:40:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235160AbhDFTk5 (ORCPT ); Tue, 6 Apr 2021 15:40:57 -0400 Received: from mail-mw2nam10on2073.outbound.protection.outlook.com ([40.107.94.73]:54032 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S234674AbhDFTk4 (ORCPT ); Tue, 6 Apr 2021 15:40:56 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gQ/WC9ASzH2rvyk15sNfrhPLzKP6Ry+iuBXoRfbPMCadEeiunu74DAlXJprlkFi12FP8N7vPWBa+c+xm4tobFi6tmy//tgUdFZ2+RMweodRqATN6bhLx13YaLgHOVpLuJC0wbJRTIreay3sryDPK5URHCRdxqkz5v4KI5wyJuoNz+xH7teQkF+mzJ/+wgKSMGhW0xWnWdFO/Cu85vN6pPuVfQs4mCtrJWwYhk5ltznbGhZLYFnHq0NtHJCOqAGSdpJWaMyyPA1pYkkMPeKdQPz2vn+SLFvWZ+BIsQ0EM+Dz17Yf+hk5fSpzrsBzaGTOkRl1SdzRe6JjywecxFWJ5Fg== 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=uoTSSo2mx2JDguO98N5mVfmZp8fU/kZU2AK7qmfO63E=; b=dds+terChKSrBajzIDVFnmTivcNktrdETj32zv4iHRow+gbkuScSFA8cD6CDJCvX6E2gVj+0qnieuE8V0zjgdsiuVTwJN1Z+djkklrc8w8cFpnCTZXMbL7No3LZauyowUkuTDT6e0KW8YrLqh/bbxj031VhhqgCTgox/2B98v0y4soCN+wSENbZMrrpWB3LDo8W7YmxyUYIiEXDHTTgbUmljWJkgmJsauSCAVC1wfjdGwgfX8KTKvaLZr/hvgufKsPGW4wbx2tvaKyiqqfJsU+fgTkfzid7rJ5FKpk3hpRtYwaenMEd9OYtw46Jr/olIaoUCfNmdp7JBT1cCQSeGzA== 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=uoTSSo2mx2JDguO98N5mVfmZp8fU/kZU2AK7qmfO63E=; b=MqMRCrqej1HWwxLNr6MXMttUblKZtaal19fgRpmTwdvqbTvsEO4JFXSgjJdI76uw49BWWqd1BHFc7eccIobzPlI1OXO8bX7l1Q4krE5NMa4xGPMhtZR7B2uW5g8+zDE5hL3BD4VctMopW6KeuK0G8ai/CrZ+FowmlsrSQnt65QLlrZndvTkbwUWmRR7C9RqCL2yPjGeex2k/sEGIgGYaDGcLLfk2pQ94zrU8EBmHh/8aBtha1NUIt1tQGh4laIprAteEJ7iIhEsU1EiLlxfllv1FMEFmCwGuaIgthqT815Vb6DVYstSN0Dsp3l36Hi8JGUEkzckVd7xLOF3HJVJPCg== 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 DM6PR12MB3515.namprd12.prod.outlook.com (2603:10b6:5:15f::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.28; Tue, 6 Apr 2021 19:40:46 +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.3999.032; Tue, 6 Apr 2021 19:40:45 +0000 From: Jason Gunthorpe To: David Airlie , Tony Krowiak , Alex Williamson , Christian Borntraeger , 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" , Cornelia Huck , Dan Williams , Christoph Hellwig , Kevin Tian , Leon Romanovsky , Max Gurtovoy , Tarun Gupta Subject: [PATCH v2 18/18] vfio/mdev: Correct the function signatures for the mdev_type_attributes Date: Tue, 6 Apr 2021 16:40:41 -0300 Message-Id: <18-v2-d36939638fc6+d54-vfio2_jgg@nvidia.com> In-Reply-To: <0-v2-d36939638fc6+d54-vfio2_jgg@nvidia.com> References: X-Originating-IP: [142.162.115.133] X-ClientProxiedBy: MN2PR16CA0002.namprd16.prod.outlook.com (2603:10b6:208:134::15) 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 (142.162.115.133) by MN2PR16CA0002.namprd16.prod.outlook.com (2603:10b6:208:134::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16 via Frontend Transport; Tue, 6 Apr 2021 19:40:43 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lTrZ4-001mXy-HM; Tue, 06 Apr 2021 16:40:42 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3e38573e-dc31-42d5-0ca4-08d8f933de16 X-MS-TrafficTypeDiagnostic: DM6PR12MB3515: 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: Db7K+JErXl0Kd4wEDxsxs7uM9L5m7KtAfaHh0FA5p0hwodW3oLmI1a/CD40sf/XF9Yy54kPG8ELybolAO0QaVCrOKTUxhakYZl8kuBBt8bFKkhsSRWJSQV0l3X+SQioPHl+f+8PPud7+vhey6t1d7VN4YBxv99ps8NkpvOR97HklqWJW9nuGV99P9Mff5AE+jfHEzxgBO3m94x+q7a3Bj4YvRtPKXNI4l/rsI6gKQf+x6IgiYhDXYbLIDYImPN6C8Zq+QSFGOXTyt8u6cpv5JDvqdUClmVprN2LxeZzmnBv54rMZSds8qW6yM56xo3KkW4OpAiXS46idDy3YhWH0JklhrewjenP3wtdTq7DJoJDgPrHqRV6EvwveTjrnvavA/1nnw91uHIyA/MqZEmbJJEqu1uhfr71kiqk9IM7DNi3bVEy3DWBAtI9LL2BMaUFCTOyTXw2TmLPV/MxVlCGizWrKE4kwry16apiPK8BMN3X8wlfN3ksTnewbWhLxbPn+2YQSAC7LF5U/f6RM23UYzdta68hKaO/hyfsctTpLKCQ1dTlyPPIlaR1W1bvWYnaxOiSJq2TlvE2NMbkFYR4S+/BHSBCwmHtX1v3tcGC2t1a/HCDp78Idi97Oxx3EqqNhwvpYDZVrZDULIgCa2kE9U8Cw1NTGYmQFBl2+xI+a6OI= 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)(346002)(136003)(396003)(39860400002)(376002)(366004)(9786002)(54906003)(316002)(110136005)(83380400001)(86362001)(8676002)(26005)(426003)(186003)(66476007)(66946007)(2616005)(7416002)(38100700001)(66556008)(107886003)(5660300002)(4326008)(9746002)(2906002)(478600001)(30864003)(8936002)(36756003)(921005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: E+QjFWxhWfvCanJy9MoQjJucRJHPZ88I/xPBVLcZXEp6dXgvlNrL6ToJ1NaS3qrkOMlam9CDyLwj4lrxxVSlJPZNfaFPM9pPh600gRVztsHiGN3wQSDsLrV1Eep4VTCS1KaydIrd4YqbEnBrpMYS4mEmVQh+AvJMrC4sDvQDf3S6UtTEWaq0jEL8GchJBePPQUrhPbapy1JI1R9g3T0mDBy+AakA0qp6m4A4GxQkIYk3UiL6L8B1iKPD6yLIihOU5guO8QELt0TmV/wAk0sRmToJK67gaxT+KGVl4mm6ksUFEgPcEG3Iz6UKb8g8gcNocypVN3zjpL55SCHWC7h48tnyMdjHn1Msje8nb2pILwyIc7Ma9ATIwF+yXrirI2rC2X0QbwqcW39hLm6YGNsQcFuHElcaIXbNL+KXbg7aXVct/l5y5JcnTEpRDK8SbLCicOA9w+tFiGARxRIruAPwBn4nV5731GiDB2hHlMi/NEFHfA3TKbLDHR4rJNg9jd+KYQHJ1Jr+n+mCge2NoPYWPLZy0Slg49rKs/r1pdIBf5tFHyJ9jkqzPDpBEncL7qZma6u+CgYqguxyDR6i5fUQFN+RXoGHgSICFawWRndIGi4rvjDO/B96zu9WIxE8eug1+pN/lMJT81540RZkQ5/2+XDV1VNVfh1XgoN3/Ghhc4hkkSr2tWp4r8PPDmpFImQyTyz1nd45FHjc/dkivo9+rsNm4SlVV3fT7n//67fjuWAin/RlI6tLLFY6SBfVeb8kBpGY8XX3Gn9jyrDP2mE9Jm9VpU6WaxcL/q0JjMiiyUMUR1FJPWbyKXwayp6g93M7ecSxoPQXRbKnfIgHU3MSCTLxXz2lnCb2pz93hvOF9qYeOQIz1/YATVg2Fq4GrwEIXQMdPNNjtSNY6qsDMjtGRcsbcwok//gZ48PTysScf36h2mfu8otOd4rDTskSLpZmC63jC8CKe/+ZvXVQF0UL8aHpUtO4F/CMsD4bkP5NplVhd72FhM/mqOrkEfhDHvjm/1JoPJPm9Mt6vWtUJqv+deS1n/9m/QKVSgAFm8/cjXIaIMh4lnljZB329UNIDHiYVsjxcWEsNlE+b3v9/TB2PaY2RtDoF5m36D6X6BMj6jIGoeb/uT8/yYIU12NXmq2iGCXipiDgLvoRLoTUBIxzHeyY0ZMUmeKHtKBfDmkkzOR8hijjEwiZ6YJdH8D2lyjVn1TciPg5uslm31zCM4YTXXOwhh7H1dd57xbEyElXfpG6qYmWeF+bl+QUzzMgB1DJKM2HUHHJu3mXxUoVLeZ4tZvwnizvX1jKWChF6GmjN+maJi3fEDeoLandg+OkG7VSUpvCJaXAU+gxtaLrgel+fA== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3e38573e-dc31-42d5-0ca4-08d8f933de16 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Apr 2021 19:40:44.1298 (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: SIOfr0N9BGi1+nxRDUA3BjnHate2SY6qiGnA1PWFlNr4sDiBLcf8l5MCojQfex05 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3515 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. Reviewed-by: Kevin Tian Reviewed-by: Cornelia Huck Reviewed-by: Christoph Hellwig Signed-off-by: Jason Gunthorpe --- 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 10407cf67583c6..491a64c61fff1a 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 d319152dd484a2..0ce00c9311d378 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 10eff33ce1f263..2a85d6fcb7ddd0 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 712fbc78b12e2d..f5cf1931c54e48 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); }