Skip to content

Commit

Permalink
Committing changes to address netvsc WITNESS failures. Converted
Browse files Browse the repository at this point in the history
a malloc to NOWAIT.  Converted main netvsc lock to spin variant of
sx_lock.  Removed critical_enter() that appears to be unnecessary.
  • Loading branch information
sjac committed Jun 26, 2012
1 parent 20f3968 commit 4eff1cf
Showing 2 changed files with 18 additions and 16 deletions.
7 changes: 3 additions & 4 deletions sys/dev/hyperv/netvsc/hv_net_vsc.h
Original file line number Diff line number Diff line change
@@ -39,8 +39,7 @@
#include <sys/types.h>
#include <sys/param.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/sema.h>
#include <sys/sx.h>

#include <dev/hyperv/include/hyperv.h>

@@ -917,7 +916,7 @@ typedef struct netvsc_packet_ {
*/
STAILQ_ENTRY(netvsc_packet_) mylist_entry;
struct hv_device *device;
hv_bool_uint8_t is_data_pkt; /* One byte */
hv_bool_uint8_t is_data_pkt; /* One byte */
xfer_page_packet *xfer_page_pkt;

/* Completion */
@@ -965,7 +964,7 @@ typedef struct hn_softc {
uint8_t hn_unit;
int hn_carrier;
int hn_if_flags;
struct mtx hn_lock;
struct sx hn_lock;
/* vm_offset_t hn_vaddr; */
int hn_initdone;
/* int hn_xc; */
27 changes: 15 additions & 12 deletions sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*-
* Copyright (c) 2010-2012 Citrix Inc.
* Copyright (c) 2009-2012 Microsoft Corp.
* Copyright (c) 2012 NetApp Inc.
* Copyright (c) 2010-2012 Citrix Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -133,12 +133,13 @@ struct netvsc_driver_context {
uint32_t drv_inited;
};

/* Now sx spin lock, as mutexes do not play well with semaphores */
#define SN_LOCK_INIT(_sc, _name) \
mtx_init(&(_sc)->hn_lock, _name, MTX_NETWORK_LOCK, MTX_DEF)
#define SN_LOCK(_sc) mtx_lock(&(_sc)->hn_lock)
#define SN_LOCK_ASSERT(_sc) mtx_assert(&(_sc)->hn_lock, MA_OWNED)
#define SN_UNLOCK(_sc) mtx_unlock(&(_sc)->hn_lock)
#define SN_LOCK_DESTROY(_sc) mtx_destroy(&(_sc)->hn_lock)
sx_init_flags(&(_sc)->hn_lock, _name, SX_NOADAPTIVE)
#define SN_LOCK(_sc) sx_xlock(&(_sc)->hn_lock)
#define SN_LOCK_ASSERT(_sc) sx_assert(&(_sc)->hn_lock, SA_XLOCKED)
#define SN_UNLOCK(_sc) sx_xunlock(&(_sc)->hn_lock)
#define SN_LOCK_DESTROY(_sc) sx_destroy(&(_sc)->hn_lock)


/*
@@ -384,9 +385,11 @@ hn_start_locked(struct ifnet *ifp)
num_frags += net_drv_obj->additional_request_page_buf_cnt;

/* Allocate a netvsc packet based on # of frags. */
/* Changed to M_NOWAIT to avoid sleep under spin lock */
buf = malloc(HV_NV_PACKET_OFFSET_IN_BUF +
sizeof(netvsc_packet) + (num_frags * sizeof(hv_vmbus_page_buffer)) +
net_drv_obj->request_ext_size, M_DEVBUF, M_ZERO | M_WAITOK);
sizeof(netvsc_packet) +
(num_frags * sizeof(hv_vmbus_page_buffer)) +
net_drv_obj->request_ext_size, M_DEVBUF, M_ZERO | M_NOWAIT);
if (buf == NULL) {
return (ENOMEM);
}
@@ -395,7 +398,8 @@ hn_start_locked(struct ifnet *ifp)
*(vm_offset_t *)buf = HV_NV_SC_PTR_OFFSET_IN_BUF;

packet->extension = (void *)((unsigned long)packet +
sizeof(netvsc_packet) + (num_frags * sizeof(hv_vmbus_page_buffer)));
sizeof(netvsc_packet) +
(num_frags * sizeof(hv_vmbus_page_buffer)));

/* Set up the rndis header */
packet->page_buf_count = num_frags;
@@ -427,9 +431,8 @@ hn_start_locked(struct ifnet *ifp)
packet->compl.send.send_completion_tid = (uint64_t)m_head;

retry_send:
critical_enter(); /* Fixme: KYS: Why? */
/* Removed critical_enter(), does not appear necessary */
ret = hv_rf_on_send(device_ctx, packet);
critical_exit();

if (ret == 0) {
ifp->if_opackets++;
@@ -679,7 +682,7 @@ hn_start(struct ifnet *ifp)

sc = ifp->if_softc;
SN_LOCK(sc);
(void)hn_start_locked(ifp);
hn_start_locked(ifp);
SN_UNLOCK(sc);
}

0 comments on commit 4eff1cf

Please sign in to comment.