Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

IB/uverbs: Add create/destroy counters support

User space application which uses counters functionality, is expected to
allocate/release the counters resources by calling create/destroy verbs
and in turn get a unique handle that can be used to attach the counters to
its counted type.

Reviewed-by: Yishai Hadas <yishaih@mellanox.com>
Signed-off-by: Raed Salem <raeds@mellanox.com>
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>

authored by

Raed Salem and committed by
Leon Romanovsky
d9a5a644 fa9b1802

+118 -2
+1 -1
drivers/infiniband/core/Makefile
··· 36 36 rdma_core.o uverbs_std_types.o uverbs_ioctl.o \ 37 37 uverbs_ioctl_merge.o uverbs_std_types_cq.o \ 38 38 uverbs_std_types_flow_action.o uverbs_std_types_dm.o \ 39 - uverbs_std_types_mr.o 39 + uverbs_std_types_mr.o uverbs_std_types_counters.o
+1
drivers/infiniband/core/uverbs.h
··· 287 287 extern const struct uverbs_object_def UVERBS_OBJECT(UVERBS_OBJECT_XRCD); 288 288 extern const struct uverbs_object_def UVERBS_OBJECT(UVERBS_OBJECT_FLOW_ACTION); 289 289 extern const struct uverbs_object_def UVERBS_OBJECT(UVERBS_OBJECT_DM); 290 + extern const struct uverbs_object_def UVERBS_OBJECT(UVERBS_OBJECT_COUNTERS); 290 291 291 292 #define IB_UVERBS_DECLARE_CMD(name) \ 292 293 ssize_t ib_uverbs_##name(struct ib_uverbs_file *file, \
+2 -1
drivers/infiniband/core/uverbs_std_types.c
··· 302 302 &UVERBS_OBJECT(UVERBS_OBJECT_RWQ_IND_TBL), 303 303 &UVERBS_OBJECT(UVERBS_OBJECT_XRCD), 304 304 &UVERBS_OBJECT(UVERBS_OBJECT_FLOW_ACTION), 305 - &UVERBS_OBJECT(UVERBS_OBJECT_DM)); 305 + &UVERBS_OBJECT(UVERBS_OBJECT_DM), 306 + &UVERBS_OBJECT(UVERBS_OBJECT_COUNTERS)); 306 307 307 308 const struct uverbs_object_tree_def *uverbs_default_get_objects(void) 308 309 {
+100
drivers/infiniband/core/uverbs_std_types_counters.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB 2 + /* 3 + * Copyright (c) 2018, Mellanox Technologies inc. All rights reserved. 4 + * 5 + * This software is available to you under a choice of one of two 6 + * licenses. You may choose to be licensed under the terms of the GNU 7 + * General Public License (GPL) Version 2, available from the file 8 + * COPYING in the main directory of this source tree, or the 9 + * OpenIB.org BSD license below: 10 + * 11 + * Redistribution and use in source and binary forms, with or 12 + * without modification, are permitted provided that the following 13 + * conditions are met: 14 + * 15 + * - Redistributions of source code must retain the above 16 + * copyright notice, this list of conditions and the following 17 + * disclaimer. 18 + * 19 + * - Redistributions in binary form must reproduce the above 20 + * copyright notice, this list of conditions and the following 21 + * disclaimer in the documentation and/or other materials 22 + * provided with the distribution. 23 + * 24 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 25 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 26 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 27 + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 28 + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 29 + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 30 + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 31 + * SOFTWARE. 32 + */ 33 + 34 + #include "uverbs.h" 35 + #include <rdma/uverbs_std_types.h> 36 + 37 + static int uverbs_free_counters(struct ib_uobject *uobject, 38 + enum rdma_remove_reason why) 39 + { 40 + struct ib_counters *counters = uobject->object; 41 + 42 + if (why == RDMA_REMOVE_DESTROY && 43 + atomic_read(&counters->usecnt)) 44 + return -EBUSY; 45 + 46 + return counters->device->destroy_counters(counters); 47 + } 48 + 49 + static int UVERBS_HANDLER(UVERBS_METHOD_COUNTERS_CREATE)(struct ib_device *ib_dev, 50 + struct ib_uverbs_file *file, 51 + struct uverbs_attr_bundle *attrs) 52 + { 53 + struct ib_counters *counters; 54 + struct ib_uobject *uobj; 55 + int ret; 56 + 57 + /* 58 + * This check should be removed once the infrastructure 59 + * have the ability to remove methods from parse tree once 60 + * such condition is met. 61 + */ 62 + if (!ib_dev->create_counters) 63 + return -EOPNOTSUPP; 64 + 65 + uobj = uverbs_attr_get_uobject(attrs, UVERBS_ATTR_CREATE_COUNTERS_HANDLE); 66 + counters = ib_dev->create_counters(ib_dev, attrs); 67 + if (IS_ERR(counters)) { 68 + ret = PTR_ERR(counters); 69 + goto err_create_counters; 70 + } 71 + 72 + counters->device = ib_dev; 73 + counters->uobject = uobj; 74 + uobj->object = counters; 75 + atomic_set(&counters->usecnt, 0); 76 + 77 + return 0; 78 + 79 + err_create_counters: 80 + return ret; 81 + } 82 + 83 + static DECLARE_UVERBS_NAMED_METHOD(UVERBS_METHOD_COUNTERS_CREATE, 84 + &UVERBS_ATTR_IDR(UVERBS_ATTR_CREATE_COUNTERS_HANDLE, 85 + UVERBS_OBJECT_COUNTERS, 86 + UVERBS_ACCESS_NEW, 87 + UA_FLAGS(UVERBS_ATTR_SPEC_F_MANDATORY))); 88 + 89 + static DECLARE_UVERBS_NAMED_METHOD_WITH_HANDLER(UVERBS_METHOD_COUNTERS_DESTROY, 90 + uverbs_destroy_def_handler, 91 + &UVERBS_ATTR_IDR(UVERBS_ATTR_DESTROY_COUNTERS_HANDLE, 92 + UVERBS_OBJECT_COUNTERS, 93 + UVERBS_ACCESS_DESTROY, 94 + UA_FLAGS(UVERBS_ATTR_SPEC_F_MANDATORY))); 95 + 96 + DECLARE_UVERBS_NAMED_OBJECT(UVERBS_OBJECT_COUNTERS, 97 + &UVERBS_TYPE_ALLOC_IDR(0, uverbs_free_counters), 98 + &UVERBS_METHOD(UVERBS_METHOD_COUNTERS_CREATE), 99 + &UVERBS_METHOD(UVERBS_METHOD_COUNTERS_DESTROY)); 100 +
+14
include/uapi/rdma/ib_user_ioctl_cmds.h
··· 55 55 UVERBS_OBJECT_WQ, 56 56 UVERBS_OBJECT_FLOW_ACTION, 57 57 UVERBS_OBJECT_DM, 58 + UVERBS_OBJECT_COUNTERS, 58 59 }; 59 60 60 61 enum { ··· 130 129 131 130 enum uverbs_methods_mr { 132 131 UVERBS_METHOD_DM_MR_REG, 132 + }; 133 + 134 + enum uverbs_attrs_create_counters_cmd_attr_ids { 135 + UVERBS_ATTR_CREATE_COUNTERS_HANDLE, 136 + }; 137 + 138 + enum uverbs_attrs_destroy_counters_cmd_attr_ids { 139 + UVERBS_ATTR_DESTROY_COUNTERS_HANDLE, 140 + }; 141 + 142 + enum uverbs_methods_actions_counters_ops { 143 + UVERBS_METHOD_COUNTERS_CREATE, 144 + UVERBS_METHOD_COUNTERS_DESTROY, 133 145 }; 134 146 135 147 #endif