From 41398a2af7ff3f12e2f8ddfc5eec0a7646ef80dd Mon Sep 17 00:00:00 2001 From: Matthew Wilcox Date: Mon, 18 Feb 2019 14:23:02 -0500 Subject: [PATCH] scif: Convert scif_ports to XArray Signed-off-by: Matthew Wilcox --- drivers/misc/mic/scif/scif_main.c | 3 --- drivers/misc/mic/scif/scif_main.h | 3 --- drivers/misc/mic/scif/scif_ports.c | 42 ++++++++++++++++-------------- 3 files changed, 22 insertions(+), 26 deletions(-) diff --git a/drivers/misc/mic/scif/scif_main.c b/drivers/misc/mic/scif/scif_main.c index e2278bf9f11d..9989879679cc 100644 --- a/drivers/misc/mic/scif/scif_main.c +++ b/drivers/misc/mic/scif/scif_main.c @@ -259,7 +259,6 @@ static int _scif_init(void) mutex_init(&scif_info.eplock); spin_lock_init(&scif_info.rmalock); spin_lock_init(&scif_info.nb_connect_lock); - spin_lock_init(&scif_info.port_lock); mutex_init(&scif_info.conflock); mutex_init(&scif_info.connlock); mutex_init(&scif_info.fencelock); @@ -290,7 +289,6 @@ static int _scif_init(void) INIT_WORK(&scif_info.misc_work, scif_misc_handler); INIT_WORK(&scif_info.mmu_notif_work, scif_mmu_notif_handler); INIT_WORK(&scif_info.conn_work, scif_conn_handler); - idr_init(&scif_ports); return 0; free_sdev: scif_destroy_scifdev(); @@ -300,7 +298,6 @@ error: static void _scif_exit(void) { - idr_destroy(&scif_ports); kmem_cache_destroy(unaligned_cache); scif_destroy_scifdev(); } diff --git a/drivers/misc/mic/scif/scif_main.h b/drivers/misc/mic/scif/scif_main.h index bb3ab97d5b35..3d2d97f18ac1 100644 --- a/drivers/misc/mic/scif/scif_main.h +++ b/drivers/misc/mic/scif/scif_main.h @@ -47,7 +47,6 @@ enum scif_msg_state { * @eplock: Lock to synchronize listening, zombie endpoint lists * @connlock: Lock to synchronize connected and disconnected lists * @nb_connect_lock: Synchronize non blocking connect operations - * @port_lock: Synchronize access to SCIF ports * @uaccept: List of user acceptreq waiting for acceptreg * @listen: List of listening end points * @zombie: List of zombie end points with pending RMA's @@ -84,7 +83,6 @@ struct scif_info { struct mutex eplock; struct mutex connlock; spinlock_t nb_connect_lock; - spinlock_t port_lock; struct list_head uaccept; struct list_head listen; struct list_head zombie; @@ -197,7 +195,6 @@ struct scif_dev { extern bool scif_reg_cache_enable; extern bool scif_ulimit_check; extern struct scif_info scif_info; -extern struct idr scif_ports; extern struct bus_type scif_peer_bus; extern struct scif_dev *scif_dev; extern const struct file_operations scif_fops; diff --git a/drivers/misc/mic/scif/scif_ports.c b/drivers/misc/mic/scif/scif_ports.c index 547a71285069..6a5459db0ec3 100644 --- a/drivers/misc/mic/scif/scif_ports.c +++ b/drivers/misc/mic/scif/scif_ports.c @@ -6,13 +6,13 @@ * * Intel SCIF driver. */ -#include +#include #include "scif_main.h" #define SCIF_PORT_COUNT 0x10000 /* Ports available */ -struct idr scif_ports; +static DEFINE_XARRAY_ALLOC(scif_ports); /* * struct scif_port - SCIF port information @@ -29,21 +29,23 @@ struct scif_port { * to the global list. * @port : port # to be reserved. * - * @return : Allocated SCIF port #, or -ENOSPC if port unavailable. + * Return: Allocated SCIF port #, or -EBUSY if port unavailable. * On memory allocation failure, returns -ENOMEM. */ static int __scif_get_port(int start, int end) { - int id; + int err, id; struct scif_port *port = kzalloc(sizeof(*port), GFP_ATOMIC); if (!port) return -ENOMEM; - spin_lock(&scif_info.port_lock); - id = idr_alloc(&scif_ports, port, start, end, GFP_ATOMIC); - if (id >= 0) - port->ref_cnt++; - spin_unlock(&scif_info.port_lock); + err = xa_alloc(&scif_ports, &id, port, XA_LIMIT(start, end), + GFP_ATOMIC); + if (err < 0) { + kfree(port); + return err; + } + port->ref_cnt++; return id; } @@ -51,24 +53,24 @@ static int __scif_get_port(int start, int end) * scif_rsrv_port - Reserve a specified port # for SCIF. * @port : port # to be reserved. * - * @return : Allocated SCIF port #, or -ENOSPC if port unavailable. + * Return: Allocated SCIF port #, or -EBUSY if port unavailable. * On memory allocation failure, returns -ENOMEM. */ int scif_rsrv_port(u16 port) { - return __scif_get_port(port, port + 1); + return __scif_get_port(port, port); } /** * scif_get_new_port - Get and reserve any port # for SCIF in the range * SCIF_PORT_RSVD + 1 to SCIF_PORT_COUNT - 1. * - * @return : Allocated SCIF port #, or -ENOSPC if no ports available. + * Return: Allocated SCIF port #, or -EBUSY if no ports available. * On memory allocation failure, returns -ENOMEM. */ int scif_get_new_port(void) { - return __scif_get_port(SCIF_PORT_RSVD + 1, SCIF_PORT_COUNT); + return __scif_get_port(SCIF_PORT_RSVD + 1, SCIF_PORT_COUNT - 1); } /** @@ -83,11 +85,11 @@ void scif_get_port(u16 id) if (!id) return; - spin_lock(&scif_info.port_lock); - port = idr_find(&scif_ports, id); + xa_lock(&scif_ports); + port = xa_load(&scif_ports, id); if (port) port->ref_cnt++; - spin_unlock(&scif_info.port_lock); + xa_unlock(&scif_ports); } /** @@ -102,14 +104,14 @@ void scif_put_port(u16 id) if (!id) return; - spin_lock(&scif_info.port_lock); - port = idr_find(&scif_ports, id); + xa_lock(&scif_ports); + port = xa_load(&scif_ports, id); if (port) { port->ref_cnt--; if (!port->ref_cnt) { - idr_remove(&scif_ports, id); + xa_erase(&scif_ports, id); kfree(port); } } - spin_unlock(&scif_info.port_lock); + xa_unlock(&scif_ports); } -- 2.50.1