mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2025-01-17 10:46:33 +00:00
76631ffa2f
Previously the clients_lock was protecting the clients array against concurrent addition/removal of clients but was also accessed from IRQ context. This meant that it had to be a spinlock and that the add() and remove() callbacks in which clients need to do allocation and take mutexes can't be called under the clients_lock. To work around this these callbacks were moved to workqueues. This not only introduced significant complexity but is also subtly broken in at least one way. In ism_dev_init() and ism_dev_exit() clients[i]->tgt_ism is used to communicate the added/removed ISM device to the work function. While write access to client[i]->tgt_ism is protected by the clients_lock and the code waits that there is no pending add/remove work before and after setting clients[i]->tgt_ism this is not enough. The problem is that the wait happens based on per ISM device counters. Thus a concurrent ism_dev_init()/ism_dev_exit() for a different ISM device may overwrite a clients[i]->tgt_ism between unlocking the clients_lock and the subsequent wait for the work to finnish. Thankfully with the clients_lock no longer held in IRQ context it can be turned into a mutex which can be held during the calls to add()/remove() completely removing the need for the workqueues and the associated broken housekeeping including the per ISM device counters and the clients[i]->tgt_ism. Fixes: 89e7d2ba61b7 ("net/ism: Add new API for client registration") Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com> Signed-off-by: David S. Miller <davem@davemloft.net>
94 lines
2.2 KiB
C
94 lines
2.2 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
/*
|
|
* Internal Shared Memory
|
|
*
|
|
* Definitions for the ISM module
|
|
*
|
|
* Copyright IBM Corp. 2022
|
|
*/
|
|
#ifndef _ISM_H
|
|
#define _ISM_H
|
|
|
|
#include <linux/workqueue.h>
|
|
|
|
struct ism_dmb {
|
|
u64 dmb_tok;
|
|
u64 rgid;
|
|
u32 dmb_len;
|
|
u32 sba_idx;
|
|
u32 vlan_valid;
|
|
u32 vlan_id;
|
|
void *cpu_addr;
|
|
dma_addr_t dma_addr;
|
|
};
|
|
|
|
/* Unless we gain unexpected popularity, this limit should hold for a while */
|
|
#define MAX_CLIENTS 8
|
|
#define ISM_NR_DMBS 1920
|
|
|
|
struct ism_dev {
|
|
spinlock_t lock; /* protects the ism device */
|
|
struct list_head list;
|
|
struct pci_dev *pdev;
|
|
|
|
struct ism_sba *sba;
|
|
dma_addr_t sba_dma_addr;
|
|
DECLARE_BITMAP(sba_bitmap, ISM_NR_DMBS);
|
|
u8 *sba_client_arr; /* entries are indices into 'clients' array */
|
|
void *priv[MAX_CLIENTS];
|
|
|
|
struct ism_eq *ieq;
|
|
dma_addr_t ieq_dma_addr;
|
|
|
|
struct device dev;
|
|
u64 local_gid;
|
|
int ieq_idx;
|
|
|
|
struct ism_client *subs[MAX_CLIENTS];
|
|
};
|
|
|
|
struct ism_event {
|
|
u32 type;
|
|
u32 code;
|
|
u64 tok;
|
|
u64 time;
|
|
u64 info;
|
|
};
|
|
|
|
struct ism_client {
|
|
const char *name;
|
|
void (*add)(struct ism_dev *dev);
|
|
void (*remove)(struct ism_dev *dev);
|
|
void (*handle_event)(struct ism_dev *dev, struct ism_event *event);
|
|
/* Parameter dmbemask contains a bit vector with updated DMBEs, if sent
|
|
* via ism_move_data(). Callback function must handle all active bits
|
|
* indicated by dmbemask.
|
|
*/
|
|
void (*handle_irq)(struct ism_dev *dev, unsigned int bit, u16 dmbemask);
|
|
/* Private area - don't touch! */
|
|
u8 id;
|
|
};
|
|
|
|
int ism_register_client(struct ism_client *client);
|
|
int ism_unregister_client(struct ism_client *client);
|
|
static inline void *ism_get_priv(struct ism_dev *dev,
|
|
struct ism_client *client) {
|
|
return dev->priv[client->id];
|
|
}
|
|
|
|
static inline void ism_set_priv(struct ism_dev *dev, struct ism_client *client,
|
|
void *priv) {
|
|
dev->priv[client->id] = priv;
|
|
}
|
|
|
|
int ism_register_dmb(struct ism_dev *dev, struct ism_dmb *dmb,
|
|
struct ism_client *client);
|
|
int ism_unregister_dmb(struct ism_dev *dev, struct ism_dmb *dmb);
|
|
int ism_move(struct ism_dev *dev, u64 dmb_tok, unsigned int idx, bool sf,
|
|
unsigned int offset, void *data, unsigned int size);
|
|
u8 *ism_get_seid(void);
|
|
|
|
const struct smcd_ops *ism_get_smcd_ops(void);
|
|
|
|
#endif /* _ISM_H */
|