netvsc: need rcu_derefence when accessing internal device info
The netvsc_device structure should be accessed by rcu_dereference in the send path. Change arguments to netvsc_send() to make this easier to do correctly. Remove no longer needed hv_device_to_netvsc_device. Signed-off-by: Stephen Hemminger <sthemmin@microsoft.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
committed by
David S. Miller
parent
9749fed5d4
commit
2a926f7912
@@ -183,10 +183,12 @@ struct rndis_device {
|
|||||||
/* Interface */
|
/* Interface */
|
||||||
struct rndis_message;
|
struct rndis_message;
|
||||||
struct netvsc_device;
|
struct netvsc_device;
|
||||||
|
struct net_device_context;
|
||||||
|
|
||||||
struct netvsc_device *netvsc_device_add(struct hv_device *device,
|
struct netvsc_device *netvsc_device_add(struct hv_device *device,
|
||||||
const struct netvsc_device_info *info);
|
const struct netvsc_device_info *info);
|
||||||
void netvsc_device_remove(struct hv_device *device);
|
void netvsc_device_remove(struct hv_device *device);
|
||||||
int netvsc_send(struct hv_device *device,
|
int netvsc_send(struct net_device_context *ndc,
|
||||||
struct hv_netvsc_packet *packet,
|
struct hv_netvsc_packet *packet,
|
||||||
struct rndis_message *rndis_msg,
|
struct rndis_message *rndis_msg,
|
||||||
struct hv_page_buffer **page_buffer,
|
struct hv_page_buffer **page_buffer,
|
||||||
@@ -790,12 +792,6 @@ net_device_to_netvsc_device(struct net_device *ndev)
|
|||||||
return ((struct net_device_context *)netdev_priv(ndev))->nvdev;
|
return ((struct net_device_context *)netdev_priv(ndev))->nvdev;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline struct netvsc_device *
|
|
||||||
hv_device_to_netvsc_device(struct hv_device *device)
|
|
||||||
{
|
|
||||||
return net_device_to_netvsc_device(hv_get_drvdata(device));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* NdisInitialize message */
|
/* NdisInitialize message */
|
||||||
struct rndis_initialize_request {
|
struct rndis_initialize_request {
|
||||||
u32 req_id;
|
u32 req_id;
|
||||||
|
|||||||
@@ -822,13 +822,15 @@ static inline void move_pkt_msd(struct hv_netvsc_packet **msd_send,
|
|||||||
msdp->count = 0;
|
msdp->count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int netvsc_send(struct hv_device *device,
|
/* RCU already held by caller */
|
||||||
|
int netvsc_send(struct net_device_context *ndev_ctx,
|
||||||
struct hv_netvsc_packet *packet,
|
struct hv_netvsc_packet *packet,
|
||||||
struct rndis_message *rndis_msg,
|
struct rndis_message *rndis_msg,
|
||||||
struct hv_page_buffer **pb,
|
struct hv_page_buffer **pb,
|
||||||
struct sk_buff *skb)
|
struct sk_buff *skb)
|
||||||
{
|
{
|
||||||
struct netvsc_device *net_device = hv_device_to_netvsc_device(device);
|
struct netvsc_device *net_device = rcu_dereference(ndev_ctx->nvdev);
|
||||||
|
struct hv_device *device = ndev_ctx->device_ctx;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
struct netvsc_channel *nvchan;
|
struct netvsc_channel *nvchan;
|
||||||
u32 pktlen = packet->total_data_buflen, msd_len = 0;
|
u32 pktlen = packet->total_data_buflen, msd_len = 0;
|
||||||
@@ -840,7 +842,7 @@ int netvsc_send(struct hv_device *device,
|
|||||||
bool xmit_more = (skb != NULL) ? skb->xmit_more : false;
|
bool xmit_more = (skb != NULL) ? skb->xmit_more : false;
|
||||||
|
|
||||||
/* If device is rescinded, return error and packet will get dropped. */
|
/* If device is rescinded, return error and packet will get dropped. */
|
||||||
if (unlikely(net_device->destroy))
|
if (unlikely(!net_device || net_device->destroy))
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
|
||||||
/* We may race with netvsc_connect_vsp()/netvsc_init_buf() and get
|
/* We may race with netvsc_connect_vsp()/netvsc_init_buf() and get
|
||||||
|
|||||||
@@ -505,8 +505,8 @@ static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net)
|
|||||||
|
|
||||||
/* timestamp packet in software */
|
/* timestamp packet in software */
|
||||||
skb_tx_timestamp(skb);
|
skb_tx_timestamp(skb);
|
||||||
ret = netvsc_send(net_device_ctx->device_ctx, packet,
|
|
||||||
rndis_msg, &pb, skb);
|
ret = netvsc_send(net_device_ctx, packet, rndis_msg, &pb, skb);
|
||||||
if (likely(ret == 0))
|
if (likely(ret == 0))
|
||||||
return NETDEV_TX_OK;
|
return NETDEV_TX_OK;
|
||||||
|
|
||||||
|
|||||||
@@ -243,7 +243,7 @@ static int rndis_filter_send_request(struct rndis_device *dev,
|
|||||||
pb[0].len;
|
pb[0].len;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = netvsc_send(net_device_ctx->device_ctx, packet, NULL, &pb, NULL);
|
ret = netvsc_send(net_device_ctx, packet, NULL, &pb, NULL);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user