scsi: storvsc: Use blk_mq_unique_tag() to generate requestIDs
Subsystems (5)
PATCH v2 1/1 scsi: storvsc: Use blk_mq_unique_tag() to generate requestIDs
Use blk_mq_unique_tag() to generate requestIDs for StorVSC, avoiding all issues with allocating enough entries in the VMbus requestor.
---
Changes since v1[1]:
- add Reviewed-by: tags
- rebase on hyperv-next
[1] https://lkml.kernel.org/r/[email protected]
drivers/hv/channel.c | 14 ++--- drivers/hv/ring_buffer.c | 14 +++-- drivers/net/hyperv/netvsc.c | 8 ++- drivers/net/hyperv/rndis_filter.c | 2 + drivers/scsi/storvsc_drv.c | 94 +++++++++++++++++++++---------- include/linux/hyperv.h | 13 ++++- 6 files changed, 95 insertions(+), 50 deletions(-)
drivers/hv/channel.c +6 -8
@@ -1124,15 +1124,14 @@ EXPORT_SYMBOL_GPL(vmbus_recvpacket_raw);* vmbus_next_request_id - Returns a new request id. It is also * the index at which the guest memory address is stored. * Uses a spin lock to avoid race conditions. -* @rqstor: Pointer to the requestor struct +* @channel: Pointer to the VMbus channel struct * @rqst_add: Guest memory address to be stored in the array */ -u64 vmbus_next_request_id (struct vmbus_requestor *rqstor,u64 rqst_addr) +u64 vmbus_next_request_id (struct vmbus_channel *channel,u64 rqst_addr) { +struct vmbus_requestor *rqstor = &channel->requestor;unsigned long flags;u64 current_id; -const struct vmbus_channel *channel = - container_of(rqstor, const struct vmbus_channel, requestor);/* Check rqstor has been initialized */ if (!channel->rqstor_size)
@@ -1166,16 +1165,15 @@ EXPORT_SYMBOL_GPL(vmbus_next_request_id);/* * vmbus_request_addr - Returns the memory address stored at @trans_id * in @rqstor. Uses a spin lock to avoid race conditions. -* @rqstor: Pointer to the requestor struct +* @channel: Pointer to the VMbus channel struct * @trans_id: Request id sent back from Hyper-V. Becomes the requestor's * next request id. */ -u64 vmbus_request_addr (struct vmbus_requestor *rqstor,u64 trans_id) +u64 vmbus_request_addr (struct vmbus_channel *channel,u64 trans_id) { +struct vmbus_requestor *rqstor = &channel->requestor;unsigned long flags;u64 req_addr; -const struct vmbus_channel *channel = - container_of(rqstor, const struct vmbus_channel, requestor);/* Check rqstor has been initialized */ if (!channel->rqstor_size)
drivers/hv/ring_buffer.c +8 -6
@@ -321,11 +321,12 @@ int hv_ringbuffer_write(struct vmbus_channel *channel,*/ if (desc->flags ==VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED ) { - rqst_id =vmbus_next_request_id (&channel->requestor, requestid); -if (rqst_id ==VMBUS_RQST_ERROR ) { -spin_unlock_irqrestore (&outring_info->ring_lock, flags); -pr_err ("No request id available\n" ); -return -EAGAIN ; +if (channel->next_request_id_callback !=NULL ) { + rqst_id = channel->next_request_id_callback (channel, requestid); +if (rqst_id ==VMBUS_RQST_ERROR ) { +spin_unlock_irqrestore (&outring_info->ring_lock, flags); +return -EAGAIN ; + } } } desc =hv_get_ring_buffer (outring_info) + old_write;
@@ -353,7 +354,8 @@ int hv_ringbuffer_write(struct vmbus_channel *channel,if (channel->rescind) {if (rqst_id !=VMBUS_NO_RQSTOR ) {/* Reclaim request ID to avoid leak of IDs */ -vmbus_request_addr (&channel->requestor, rqst_id); +if (channel->request_addr_callback !=NULL ) + channel->request_addr_callback (channel, rqst_id); }return -ENODEV ; }
drivers/net/hyperv/netvsc.c +5 -3
@@ -730,7 +730,7 @@ static void netvsc_send_tx_complete(struct net_device *ndev,int queue_sends;u64 cmd_rqst; - cmd_rqst =vmbus_request_addr (&channel->requestor, (u64 )desc->trans_id); + cmd_rqst = channel->request_addr_callback (channel, (u64 )desc->trans_id);if (cmd_rqst ==VMBUS_RQST_ERROR ) {netdev_err (ndev,"Incorrect transaction id\n" );return ;
@@ -790,8 +790,8 @@ static void netvsc_send_completion(struct net_device *ndev,/* First check if this is a VMBUS completion without data payload */ if (!msglen) { - cmd_rqst =vmbus_request_addr (&incoming_channel->requestor, - (u64 )desc->trans_id); + cmd_rqst = incoming_channel->request_addr_callback (incoming_channel, + (u64 )desc->trans_id);if (cmd_rqst ==VMBUS_RQST_ERROR ) {netdev_err (ndev,"Invalid transaction id\n" );return ;
@@ -1602,6 +1602,8 @@ struct netvsc_device *netvsc_device_add(struct hv_device *device, netvsc_poll, NAPI_POLL_WEIGHT);/* Open the channel */ + device->channel->next_request_id_callback = vmbus_next_request_id; + device->channel->request_addr_callback = vmbus_request_addr; device->channel->rqstor_size =netvsc_rqstor_size (netvsc_ring_bytes); device->channel->max_pkt_size =NETVSC_MAX_PKT_SIZE ;
drivers/net/hyperv/rndis_filter.c +2 -0
@@ -1259,6 +1259,8 @@ static void netvsc_sc_open(struct vmbus_channel *new_sc)/* Set the channel before opening.*/ nvchan->channel = new_sc; + new_sc->next_request_id_callback = vmbus_next_request_id; + new_sc->request_addr_callback = vmbus_request_addr; new_sc->rqstor_size =netvsc_rqstor_size (netvsc_ring_bytes); new_sc->max_pkt_size =NETVSC_MAX_PKT_SIZE ;
drivers/scsi/storvsc_drv.c +63 -31
152 lines not on this page · raw message
include/linux/hyperv.h +11 -2
@@ -783,7 +783,11 @@ struct vmbus_requestor {#define VMBUS_NO_RQSTOR U64_MAX#define VMBUS_RQST_ERROR (U64_MAX - 1) +/* NetVSC-specific */ #define VMBUS_RQST_ID_NO_RESPONSE (U64_MAX - 2) +/* StorVSC-specific */ +#define VMBUS_RQST_INIT (U64_MAX - 2) +#define VMBUS_RQST_RESET (U64_MAX - 3)struct vmbus_device {u16 dev_type;
@@ -1013,6 +1017,11 @@ struct vmbus_channel {u32 fuzz_testing_interrupt_delay;u32 fuzz_testing_message_delay; +/* callback to generate a request ID from a request address */ +u64 (*next_request_id_callback)(struct vmbus_channel *channel,u64 rqst_addr); +/* callback to retrieve a request address from a request ID */ +u64 (*request_addr_callback)(struct vmbus_channel *channel,u64 rqst_id); +/* request/transaction ids for VMBus */ struct vmbus_requestor requestor;u32 rqstor_size;
@@ -1021,8 +1030,8 @@ struct vmbus_channel {u32 max_pkt_size; }; -u64 vmbus_next_request_id (struct vmbus_requestor *rqstor,u64 rqst_addr); -u64 vmbus_request_addr (struct vmbus_requestor *rqstor,u64 trans_id); +u64 vmbus_next_request_id (struct vmbus_channel *channel,u64 rqst_addr); +u64 vmbus_request_addr (struct vmbus_channel *channel,u64 trans_id);static inline bool is_hvsock_channel (const struct vmbus_channel *c) {
Signature · 1 line
2.25.1
Andrea,
Quoted 2 lines
Use
blk_mq_unique_tag()to generate requestIDs for StorVSC, avoiding all issues with allocating enough entries in the VMbus requestor.
Dropped v1 from the SCSI staging tree. OK with this change going through hv if that is easier.
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering
Wei Liu
maintainerQuoted 10 lines · Martin K. Petersen
Andrea,
Quoted 2 lines
Use
blk_mq_unique_tag()to generate requestIDs for StorVSC, avoiding all issues with allocating enough entries in the VMbus requestor.Dropped v1 from the SCSI staging tree. OK with this change going through hv if that is easier.
Thanks Martin.
Quoted 3 lines
Signature · 2 lines
-- Martin K. Petersen Oracle Linux Engineering