Skip to content

Commit 2a926f7

Browse files
shemmingerdavem330
authored andcommitted
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>
1 parent 9749fed commit 2a926f7

File tree

4 files changed

+11
-13
lines changed

4 files changed

+11
-13
lines changed

drivers/net/hyperv/hyperv_net.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,12 @@ struct rndis_device {
183183
/* Interface */
184184
struct rndis_message;
185185
struct netvsc_device;
186+
struct net_device_context;
187+
186188
struct netvsc_device *netvsc_device_add(struct hv_device *device,
187189
const struct netvsc_device_info *info);
188190
void netvsc_device_remove(struct hv_device *device);
189-
int netvsc_send(struct hv_device *device,
191+
int netvsc_send(struct net_device_context *ndc,
190192
struct hv_netvsc_packet *packet,
191193
struct rndis_message *rndis_msg,
192194
struct hv_page_buffer **page_buffer,
@@ -790,12 +792,6 @@ net_device_to_netvsc_device(struct net_device *ndev)
790792
return ((struct net_device_context *)netdev_priv(ndev))->nvdev;
791793
}
792794

793-
static inline struct netvsc_device *
794-
hv_device_to_netvsc_device(struct hv_device *device)
795-
{
796-
return net_device_to_netvsc_device(hv_get_drvdata(device));
797-
}
798-
799795
/* NdisInitialize message */
800796
struct rndis_initialize_request {
801797
u32 req_id;

drivers/net/hyperv/netvsc.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -822,13 +822,15 @@ static inline void move_pkt_msd(struct hv_netvsc_packet **msd_send,
822822
msdp->count = 0;
823823
}
824824

825-
int netvsc_send(struct hv_device *device,
825+
/* RCU already held by caller */
826+
int netvsc_send(struct net_device_context *ndev_ctx,
826827
struct hv_netvsc_packet *packet,
827828
struct rndis_message *rndis_msg,
828829
struct hv_page_buffer **pb,
829830
struct sk_buff *skb)
830831
{
831-
struct netvsc_device *net_device = hv_device_to_netvsc_device(device);
832+
struct netvsc_device *net_device = rcu_dereference(ndev_ctx->nvdev);
833+
struct hv_device *device = ndev_ctx->device_ctx;
832834
int ret = 0;
833835
struct netvsc_channel *nvchan;
834836
u32 pktlen = packet->total_data_buflen, msd_len = 0;
@@ -840,7 +842,7 @@ int netvsc_send(struct hv_device *device,
840842
bool xmit_more = (skb != NULL) ? skb->xmit_more : false;
841843

842844
/* If device is rescinded, return error and packet will get dropped. */
843-
if (unlikely(net_device->destroy))
845+
if (unlikely(!net_device || net_device->destroy))
844846
return -ENODEV;
845847

846848
/* We may race with netvsc_connect_vsp()/netvsc_init_buf() and get

drivers/net/hyperv/netvsc_drv.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,8 +505,8 @@ static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net)
505505

506506
/* timestamp packet in software */
507507
skb_tx_timestamp(skb);
508-
ret = netvsc_send(net_device_ctx->device_ctx, packet,
509-
rndis_msg, &pb, skb);
508+
509+
ret = netvsc_send(net_device_ctx, packet, rndis_msg, &pb, skb);
510510
if (likely(ret == 0))
511511
return NETDEV_TX_OK;
512512

drivers/net/hyperv/rndis_filter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ static int rndis_filter_send_request(struct rndis_device *dev,
243243
pb[0].len;
244244
}
245245

246-
ret = netvsc_send(net_device_ctx->device_ctx, packet, NULL, &pb, NULL);
246+
ret = netvsc_send(net_device_ctx, packet, NULL, &pb, NULL);
247247
return ret;
248248
}
249249

0 commit comments

Comments
 (0)