From patchwork Wed Nov 1 14:49:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Tu X-Patchwork-Id: 1857988 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SL90x2ysSz1yQ6 for ; Thu, 2 Nov 2023 01:50:41 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1qyCYG-0002NC-PL; Wed, 01 Nov 2023 14:50:36 +0000 Received: from mail-mw2nam12on2078.outbound.protection.outlook.com ([40.107.244.78] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1qyCXh-0001n6-Fi for kernel-team@lists.ubuntu.com; Wed, 01 Nov 2023 14:50:03 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lsMjqEXJYcEYtiqviHhjfIS8RlNQKfuXOS8S7UaLZTKTf7bfvBa6aDYW5qOzd70cprgbmJx0bRqZuExUlHU5Mz5Qi7w8CjB1q6WrE2maf3DcNN1u4XjkBsU5aQBuHnES+AmCTp3F0BHmUP5zLXTVkA67mj3ZXtDFqcyaKG4ClTl3nr7kRXKMXsRedd2tNgfegw4auSYr95F/8BubftfiHlNXo7Orl3tj3Is7Eg4IwZUJZoruS7rD1wLCfsM5PWGrJ5iAwv5+MsLbx5VR5q5gLdJcDPwofP/TGgQ8P/sWJ5gM+agk/xMy48IRFqmGGGFb/CxelSVFabnytYbGVBHmaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=bzcIXt63F04BSg9pZiqiAiqf+VncJ5W5P3i9XbLTJlY=; b=B8Kln33YsASgBNJsG9feyXybUWYwtEUaSwq7unZ4Z0Drkld5HsBXz0/EU2Fbhii6jpNDmIxvj2QKraRcgCYH1AZy0OpIqEGaa9WP/WlzQrklBZ3elv2A8vd4C/MS3Hqi8ImLTeUqIIkBNvKLEG8SDOY8Kob3DdQIL0LiQ24JmOzpbbh5tTyNibFhBsMzWsccieOADMgZXcJ5PeVlaHz1nmvHpfjXWIWs8D8871TGHT7x1Uip9uqXFiCQV1A6n2deipHTsv11xQDmbtNHG9/6e+CqFQLMLdNdz5UmRvJ+uz6U4CSiDasIefPyUjo0ilOSDDMLNehSRT4frS9GTXyAWg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) smtp.rcpttodomain=lists.ubuntu.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) Received: from CY8PR19CA0034.namprd19.prod.outlook.com (2603:10b6:930:6::24) by MN0PR12MB5956.namprd12.prod.outlook.com (2603:10b6:208:37f::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.28; Wed, 1 Nov 2023 14:49:58 +0000 Received: from CY4PEPF0000EE3D.namprd03.prod.outlook.com (2603:10b6:930:6:cafe::3c) by CY8PR19CA0034.outlook.office365.com (2603:10b6:930:6::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6954.19 via Frontend Transport; Wed, 1 Nov 2023 14:49:57 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by CY4PEPF0000EE3D.mail.protection.outlook.com (10.167.242.17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6954.19 via Frontend Transport; Wed, 1 Nov 2023 14:49:57 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Wed, 1 Nov 2023 07:49:55 -0700 Received: from drhqmail201.nvidia.com (10.126.190.180) by drhqmail203.nvidia.com (10.126.190.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Wed, 1 Nov 2023 07:49:55 -0700 Received: from witu-mlt.nvidia.com (10.127.8.13) by mail.nvidia.com (10.126.190.180) with Microsoft SMTP Server id 15.2.986.41 via Frontend Transport; Wed, 1 Nov 2023 07:49:55 -0700 From: William Tu To: Subject: [SRU][J:linux-bluefield][PATCH 5/7] net: devlink: add unlocked variants of devlink_region_create/destroy() functions Date: Wed, 1 Nov 2023 07:49:49 -0700 Message-ID: <20231101144951.26198-6-witu@nvidia.com> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) In-Reply-To: <20231101144951.26198-1-witu@nvidia.com> References: <20231101144951.26198-1-witu@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE3D:EE_|MN0PR12MB5956:EE_ X-MS-Office365-Filtering-Correlation-Id: 77e64351-3b3e-45c6-0986-08dbdae9d154 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cqlgn1lH4jaPsvYf3ubMQEl5D+OPQG3a+LLMXjDbW+fYFC27oKLhyKbFc/2vuTgVQFNeOw2jlf9DyNWO379TcSFj2GACrI9avvbPjVTY4Koz1uCItHNXpWouhZBgQ/7jV4Kj8jfhfs9CUmOU4dvGnIKiqLnVB1cJPHBmPqMWyxzvrTlJ01lWTH/9Wtj9ekA7Kb203CTYlCRwrCfTUHrL45NJYz8CdIcNArrkaI2ql+52gTnu2UC7hwLuNJMfZe2raigt8/fIWhQsOtPvxygQgOah/CCq/Axc5dZJM5DUbDBng6n1A+iAJj1AKEl3V4cyELAgO8mkhhA/llPvAk7fzb4k2jv6fOSEyUsqdD4gU7Dlf/bVFrmFJilcQiGKQ2usvYqZnCMkMGRZL1s0Mi8N0TYdPMYdNGQncDIzNfOC9GJ/qfwS3AlMxZXWYTwA3eSCDbvsYlxHvd89xrLm9XwCv+pWYaMART1l7D3Bz6bHjDsQYX8m40CLFF8DMFobdv4L0obK2IACYsB9UsHka9fYz9lBQQO6CZRF35m5jB1y0CkiZBEil5bclN9f8AgT+AhMBDJQ+9w8XlDzXERHTwBXapRHMkZNLjV5dSxexA6f1GB1jesa/DFASQFbd747uAWGahigETnsaYxji5s9gSIvFi6F7wS/10gFLAqMk/HKEDpuyXL0x5VlzErgBwTaBjKHiZpl0GX8U8gZXI+VWqz3oTAvwk0WUAm80UZsjpR8AEIt8/b/+Z8MxCOZDDJnm2kzlP6hzNJTaxMK3cq/K/t3TkLi6Q4+std+q8G9jk0PlB4= X-Forefront-Antispam-Report: CIP:216.228.118.233; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc7edge2.nvidia.com; CAT:NONE; SFS:(13230031)(4636009)(39860400002)(376002)(396003)(136003)(346002)(230922051799003)(64100799003)(82310400011)(186009)(1800799009)(451199024)(46966006)(40470700004)(36840700001)(83380400001)(7696005)(6666004)(966005)(478600001)(47076005)(107886003)(336012)(26005)(1076003)(2616005)(41300700001)(5660300002)(2906002)(54906003)(426003)(70206006)(8676002)(4326008)(316002)(8936002)(70586007)(36860700001)(86362001)(36756003)(82740400003)(7636003)(356005)(6916009)(40480700001)(40460700003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Nov 2023 14:49:57.6300 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 77e64351-3b3e-45c6-0986-08dbdae9d154 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.118.233]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EE3D.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB5956 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: vlad@nvidia.com, bodong@nvidia.com, majd@nvidia.com Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Jiri Pirko BugLink: https://bugs.launchpad.net/bugs/2042455 Add unlocked variants of devlink_region_create/destroy() functions to be used in drivers called-in with devlink->lock held. Signed-off-by: Jiri Pirko Reviewed-by: Moshe Shemesh Signed-off-by: Jakub Kicinski (cherry picked from commit eb0e9fa2c6355e744d3ea7d07d34d89a4735320e) Signed-off-by: William Tu --- include/net/devlink.h | 5 +++ net/core/devlink.c | 89 +++++++++++++++++++++++++++++-------------- 2 files changed, 66 insertions(+), 28 deletions(-) diff --git a/include/net/devlink.h b/include/net/devlink.h index b542f800d392..6076e5d17c14 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -1690,6 +1690,10 @@ int devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id, int devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id, union devlink_param_value init_val); void devlink_param_value_changed(struct devlink *devlink, u32 param_id); +struct devlink_region *devl_region_create(struct devlink *devlink, + const struct devlink_region_ops *ops, + u32 region_max_snapshots, + u64 region_size); struct devlink_region * devlink_region_create(struct devlink *devlink, const struct devlink_region_ops *ops, @@ -1698,6 +1702,7 @@ struct devlink_region * devlink_port_region_create(struct devlink_port *port, const struct devlink_port_region_ops *ops, u32 region_max_snapshots, u64 region_size); +void devl_region_destroy(struct devlink_region *region); void devlink_region_destroy(struct devlink_region *region); void devlink_port_region_destroy(struct devlink_region *region); diff --git a/net/core/devlink.c b/net/core/devlink.c index 17c9ba50a9b1..5c0bdf9201f4 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -11503,36 +11503,31 @@ void devlink_param_value_changed(struct devlink *devlink, u32 param_id) EXPORT_SYMBOL_GPL(devlink_param_value_changed); /** - * devlink_region_create - create a new address region + * devl_region_create - create a new address region * - * @devlink: devlink - * @ops: region operations and name - * @region_max_snapshots: Maximum supported number of snapshots for region - * @region_size: size of region + * @devlink: devlink + * @ops: region operations and name + * @region_max_snapshots: Maximum supported number of snapshots for region + * @region_size: size of region */ -struct devlink_region * -devlink_region_create(struct devlink *devlink, - const struct devlink_region_ops *ops, - u32 region_max_snapshots, u64 region_size) +struct devlink_region *devl_region_create(struct devlink *devlink, + const struct devlink_region_ops *ops, + u32 region_max_snapshots, + u64 region_size) { struct devlink_region *region; - int err = 0; + + devl_assert_locked(devlink); if (WARN_ON(!ops) || WARN_ON(!ops->destructor)) return ERR_PTR(-EINVAL); - devl_lock(devlink); - - if (devlink_region_get_by_name(devlink, ops->name)) { - err = -EEXIST; - goto unlock; - } + if (devlink_region_get_by_name(devlink, ops->name)) + return ERR_PTR(-EEXIST); region = kzalloc(sizeof(*region), GFP_KERNEL); - if (!region) { - err = -ENOMEM; - goto unlock; - } + if (!region) + return ERR_PTR(-ENOMEM); region->devlink = devlink; region->max_snapshots = region_max_snapshots; @@ -11543,12 +11538,32 @@ devlink_region_create(struct devlink *devlink, list_add_tail(®ion->list, &devlink->region_list); devlink_nl_region_notify(region, NULL, DEVLINK_CMD_REGION_NEW); - devl_unlock(devlink); return region; +} +EXPORT_SYMBOL_GPL(devl_region_create); -unlock: +/** + * devlink_region_create - create a new address region + * + * @devlink: devlink + * @ops: region operations and name + * @region_max_snapshots: Maximum supported number of snapshots for region + * @region_size: size of region + * + * Context: Takes and release devlink->lock . + */ +struct devlink_region * +devlink_region_create(struct devlink *devlink, + const struct devlink_region_ops *ops, + u32 region_max_snapshots, u64 region_size) +{ + struct devlink_region *region; + + devl_lock(devlink); + region = devl_region_create(devlink, ops, region_max_snapshots, + region_size); devl_unlock(devlink); - return ERR_PTR(err); + return region; } EXPORT_SYMBOL_GPL(devlink_region_create); @@ -11559,6 +11574,8 @@ EXPORT_SYMBOL_GPL(devlink_region_create); * @ops: region operations and name * @region_max_snapshots: Maximum supported number of snapshots for region * @region_size: size of region + * + * Context: Takes and release devlink->lock . */ struct devlink_region * devlink_port_region_create(struct devlink_port *port, @@ -11605,16 +11622,16 @@ devlink_port_region_create(struct devlink_port *port, EXPORT_SYMBOL_GPL(devlink_port_region_create); /** - * devlink_region_destroy - destroy address region + * devl_region_destroy - destroy address region * - * @region: devlink region to destroy + * @region: devlink region to destroy */ -void devlink_region_destroy(struct devlink_region *region) +void devl_region_destroy(struct devlink_region *region) { struct devlink *devlink = region->devlink; struct devlink_snapshot *snapshot, *ts; - devl_lock(devlink); + devl_assert_locked(devlink); /* Free all snapshots of region */ mutex_lock(®ion->snapshot_lock); @@ -11626,9 +11643,25 @@ void devlink_region_destroy(struct devlink_region *region) mutex_destroy(®ion->snapshot_lock); devlink_nl_region_notify(region, NULL, DEVLINK_CMD_REGION_DEL); - devl_unlock(devlink); kfree(region); } +EXPORT_SYMBOL_GPL(devl_region_destroy); + +/** + * devlink_region_destroy - destroy address region + * + * @region: devlink region to destroy + * + * Context: Takes and release devlink->lock . + */ +void devlink_region_destroy(struct devlink_region *region) +{ + struct devlink *devlink = region->devlink; + + devl_lock(devlink); + devl_region_destroy(region); + devl_unlock(devlink); +} EXPORT_SYMBOL_GPL(devlink_region_destroy); /**