RDMA: Add indication for in kernel API support to IB device

Drivers that do not provide kernel verbs support should not be used by ib
kernel clients at all.

In case a device does not implement all mandatory verbs for kverbs usage
mark it as a non kverbs provider and prevent its usage for all clients
except for uverbs.

The device is marked as a non kverbs provider using the 'kverbs_provider'
flag which should only be set by the core code.  The clients can choose
whether kverbs are requested for its usage using the 'no_kverbs_req' flag
which is currently set for uverbs only.

This patch allows drivers to remove mandatory verbs stubs and simply set
the callbacks to NULL. The IB device will be registered as a non-kverbs
provider. Note that verbs that are required for the device registration
process must be implemented.

Signed-off-by: Gal Pressman <galpress@amazon.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
This commit is contained in:
Gal Pressman 2019-01-22 10:08:22 +02:00 committed by Jason Gunthorpe
parent 459cc69fa4
commit 6780c4fa9d
3 changed files with 12 additions and 4 deletions

View File

@ -121,13 +121,12 @@ static int ib_device_check_mandatory(struct ib_device *device)
}; };
int i; int i;
device->kverbs_provider = true;
for (i = 0; i < ARRAY_SIZE(mandatory_table); ++i) { for (i = 0; i < ARRAY_SIZE(mandatory_table); ++i) {
if (!*(void **) ((void *) &device->ops + if (!*(void **) ((void *) &device->ops +
mandatory_table[i].offset)) { mandatory_table[i].offset)) {
dev_warn(&device->dev, device->kverbs_provider = false;
"Device is missing mandatory function %s\n", break;
mandatory_table[i].name);
return -EINVAL;
} }
} }
@ -325,6 +324,9 @@ static int add_client_context(struct ib_device *device, struct ib_client *client
{ {
struct ib_client_data *context; struct ib_client_data *context;
if (!device->kverbs_provider && !client->no_kverbs_req)
return -EOPNOTSUPP;
context = kmalloc(sizeof(*context), GFP_KERNEL); context = kmalloc(sizeof(*context), GFP_KERNEL);
if (!context) if (!context)
return -ENOMEM; return -ENOMEM;

View File

@ -1151,6 +1151,7 @@ static const struct file_operations uverbs_mmap_fops = {
static struct ib_client uverbs_client = { static struct ib_client uverbs_client = {
.name = "uverbs", .name = "uverbs",
.no_kverbs_req = true,
.add = ib_uverbs_add_one, .add = ib_uverbs_add_one,
.remove = ib_uverbs_remove_one .remove = ib_uverbs_remove_one
}; };

View File

@ -2565,6 +2565,8 @@ struct ib_device {
__be64 node_guid; __be64 node_guid;
u32 local_dma_lkey; u32 local_dma_lkey;
u16 is_switch:1; u16 is_switch:1;
/* Indicates kernel verbs support, should not be used in drivers */
u16 kverbs_provider:1;
u8 node_type; u8 node_type;
u8 phys_port_cnt; u8 phys_port_cnt;
struct ib_device_attr attrs; struct ib_device_attr attrs;
@ -2619,6 +2621,9 @@ struct ib_client {
const struct sockaddr *addr, const struct sockaddr *addr,
void *client_data); void *client_data);
struct list_head list; struct list_head list;
/* kverbs are not required by the client */
u8 no_kverbs_req:1;
}; };
struct ib_device *_ib_alloc_device(size_t size); struct ib_device *_ib_alloc_device(size_t size);