PERFORCE change 180301 for review

Alexandre Fiveg afiveg at FreeBSD.org
Mon Jun 28 18:33:38 UTC 2010


http://p4web.freebsd.org/@@180301?ac=10

Change 180301 by afiveg at cottonmouth on 2010/06/28 18:33:18

	bugfix: ringmap_open(): after contigmalloc the pointer to the freed memory region should be set to NULL

Affected files ...

.. //depot/projects/soc2010/ringmap/current/contrib/libpcap/pcap.c#4 edit
.. //depot/projects/soc2010/ringmap/current/contrib/libpcap/ringmap_pcap.c#6 edit
.. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_hw.h#6 edit
.. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/if_lem.c#14 edit
.. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/if_lem.h#12 edit
.. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/ringmap_8254.c#13 edit
.. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/ringmap_8254.h#11 edit
.. //depot/projects/soc2010/ringmap/current/sys/net/ringmap.c#17 edit
.. //depot/projects/soc2010/ringmap/current/sys/net/ringmap.h#17 edit
.. //depot/projects/soc2010/ringmap/scripts/build_ringmap.sh#2 edit
.. //depot/projects/soc2010/ringmap/scripts/set_ringmap.sh#2 edit

Differences ...

==== //depot/projects/soc2010/ringmap/current/contrib/libpcap/pcap.c#4 (text+ko) ====


==== //depot/projects/soc2010/ringmap/current/contrib/libpcap/ringmap_pcap.c#6 (text+ko) ====

@@ -117,7 +117,14 @@
 	bus_addr_t nic_statspp,	rspp;
 
 	RINGMAP_FUNC_DEBUG(start);
+
+	if ( p == NULL ){
+		RINGMAP_ERROR(NULL pointer to the pcap structure);
+		return (-1);
+	}
 	
+	p->ring = NULL;
+
 	/* Open mem device for mmaping of kernel memory regions in space of our process */
 	if ((devmem_fd = open("/dev/mem", O_RDWR)) == -1){
 		perror("/dev/mem");
@@ -262,6 +269,11 @@
 
 	RINGMAP_FUNC_DEBUG(start);
 
+	if ( (p == NULL) || (p->ring == NULL) ){
+		RINGMAP_FUNC_DEBUG(NULL pointer. Debugging is needed!);
+		goto out;
+	}
+
 	for (i = 0; i < SLOTS_NUMBER; i++){
 		tmp_res = munmap((void *)p->ring->slot[i].mbuf.user, 
 							sizeof(struct mbuf));
@@ -293,6 +305,7 @@
 			perror("close()");
 	}
 
+out:
 	RINGMAP_FUNC_DEBUG(end);
 }
 
@@ -348,6 +361,13 @@
 		}
 
 		curr_slot = R_MODULO(SW_TAIL(ring) + 1);
+		if (!(ring->slot[curr_slot].is_ok)) {
+#ifdef __RINGMAP_DEB
+			printf("Slot %d was not accepted by driver!\n");
+#endif 
+			goto out;
+		}
+		ring->cur_slot_user = curr_slot;
 
 		mb = (struct mbuf *)U_MBUF(ring, curr_slot);
 
@@ -357,6 +377,10 @@
 
 		(*callback)(user, &pkthdr, datap);
 
+out:
+		ring->slot[curr_slot].is_ok = 0;
+		ring->slot[curr_slot].filtered = 0;
+
 		INC_TAIL(ring);
 		ring->pkt_counter++;
 

==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_hw.h#6 (text+ko) ====


==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/if_lem.c#14 (text+ko) ====

@@ -1384,7 +1384,7 @@
 	if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
 #ifdef RINGMAP
 		if ((adapter->rm != NULL) && (adapter->rm->ring != NULL))
-			adapter->rm->funcs->delayed_interrupt(context);
+			adapter->rm->funcs->delayed_isr(context);
 #endif
 		if (lem_rxeof(adapter, adapter->rx_process_limit) != 0)
 			taskqueue_enqueue(adapter->tq, &adapter->rxtx_task);
@@ -1448,7 +1448,7 @@
 			(adapter->rm->ring != NULL) &&
 			(adapter->rm->ring->td != NULL))
 	{
-		adapter->rm->funcs->interrupt(arg);
+		adapter->rm->funcs->isr(arg);
 	}
 #endif
 
@@ -3577,6 +3577,12 @@
 
 		if (accept_frame) {
 
+#ifdef RINGMAP
+			if ((adapter->rm != NULL) && (adapter->rm->ring != NULL))
+				adapter->rm->funcs->delayed_isr_per_packet(adapter->rm->ring, 
+					i);
+#endif
+
 #ifndef RINGMAP
 		/* Do not allocate memory for new mbufs and packets. Work in ring */
 			if (lem_get_buf(adapter, i) != 0) {

==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/if_lem.h#12 (text+ko) ====


==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/ringmap_8254.c#13 (text+ko) ====

@@ -29,12 +29,29 @@
 void rm_8254_delayed_interrupt(void *);
 int rm_8254_print_ring_pointers(struct adapter *);
 void rm_8254_sync_head_tail(device_t, struct ring *);
+void rm_8254_delayed_interrupt_per_packet(struct ring *, int);
 
 extern devclass_t em_devclass;
 extern void	lem_enable_intr(struct adapter *);
 extern void	lem_disable_intr(struct adapter *);
 
 
+void 
+rm_8254_delayed_interrupt_per_packet(struct ring *ring, int slot_num)
+{
+	RINGMAP_INTR(start);
+	ring->cur_slot_kern = slot_num;
+	ring->slot[slot_num].is_ok = 1;
+	ring->slot[slot_num].intr_num = ring->interrupts_counter;
+
+#ifdef RINGMAP_TIMESTAMP
+	ring->slot[slot_num].ts.tv_sec = ring->last_ts.tv_sec;
+	ring->slot[slot_num].ts.tv_usec = ring->last_ts.tv_usec;
+#endif 
+
+	RINGMAP_INTR(end);
+}
+
 /* 
  * This function synchronize the tail and head hardware registers
  * with head and tail software varibles, that are visible from 

==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/ringmap_8254.h#11 (text+ko) ====


==== //depot/projects/soc2010/ringmap/current/sys/net/ringmap.c#17 (text+ko) ====

@@ -51,6 +51,8 @@
 extern void rm_8254_interrupt(void *);
 extern void rm_8254_delayed_interrupt(void *);
 extern void rm_8254_sync_head_tail(device_t, struct ring *);
+extern void rm_8254_delayed_interrupt_per_packet(struct ring *, int);
+
 
 d_open_t	ringmap_open;
 d_close_t	ringmap_close;
@@ -112,13 +114,15 @@
 			RINGMAP_FUNC_DEBUG(Controller Type: 8254);
 			
 			rm->funcs->set_ringmap_to_adapter = 
-									rm_8254_set_ringmap_to_adapter;
+				rm_8254_set_ringmap_to_adapter;
 			rm->funcs->enable_intr  		= rm_8254_enable_intr;
 			rm->funcs->disable_intr 		= rm_8254_disable_intr;
 			rm->funcs->init_slots 			= rm_8254_init_slots;
-			rm->funcs->interrupt 			= rm_8254_interrupt;
+			rm->funcs->isr		 			= rm_8254_interrupt;
+			rm->funcs->delayed_isr			= rm_8254_delayed_interrupt;
+			rm->funcs->delayed_isr_per_packet = 
+				rm_8254_delayed_interrupt_per_packet;
 			rm->funcs->sync_head_tail 		= rm_8254_sync_head_tail;
-			rm->funcs->delayed_interrupt	= rm_8254_delayed_interrupt;
 
 			get_ringmap_p = rm_8254_get_ringmap_p;
 			get_device_p  =	rm_8254_get_device_p;
@@ -256,7 +260,7 @@
 	rm = get_ringmap_p(get_device_p(cdev));
 	if (rm == NULL) {
 		RINGMAP_ERROR(Null pointer to ringmap structure);
-		return (ENODEV);
+		return (EIO);
 	}
 	
 	/**
@@ -264,14 +268,14 @@
 	 **/
 	if (!atomic_cmpset_int(&rm->open_cnt, 0, 1)){
 		RINGMAP_ERROR(Sorry! Can not open device more then one time!);
-		err = ENODEV;
-		goto end;
+		atomic_readandclear_int(&rm->open_cnt); 
+		return (EIO);
 	}
 
 	if (rm->dev == NULL){
 		RINGMAP_ERROR(Null pointer to device structure of adapter);
-		err = ENODEV;
-		goto end;
+		atomic_readandclear_int(&rm->open_cnt); 
+		return (EIO);
 	}
 
 	/* 
@@ -283,8 +287,9 @@
 			M_DEVBUF, M_ZERO, 0, -1L, PAGE_SIZE, 0);
 	if (ring == NULL) { 
 		RINGMAP_ERROR(Can not allocate space for ring structure); 
-		err = ENODEV;
-		goto end;
+
+		atomic_readandclear_int(&rm->open_cnt); 
+		return (EIO);
 	}
 	rm->ring 	= ring;
 
@@ -304,19 +309,17 @@
 	if (rm->funcs->init_slots(rm->ring, rm->dev) == -1){ 
 		RINGMAP_ERROR(The ring is not initialized. Device will not be opened!);
 		contigfree(rm->ring, sizeof(struct ring), M_DEVBUF);
-		err = ENODEV;
+		rm->ring = NULL;
+		
+		atomic_readandclear_int(&rm->open_cnt); 
+		err = EIO;
 	}	
 
 	rm->funcs->enable_intr(rm->dev); 
 
-end:
-
-	atomic_readandclear_int(&rm->open_cnt); 
-
 	RINGMAP_FUNC_DEBUG(end);
 
 	return (err);
-
 }
 
 

==== //depot/projects/soc2010/ringmap/current/sys/net/ringmap.h#17 (text+ko) ====

@@ -66,6 +66,9 @@
 	/* 1 - if accepted by (bpf) filter */
 	int filtered;
 
+	/* 1 if accepted by driver and contains no errors */
+	int is_ok;
+
 	/* 
 	 * Next fields are for statistics:
 	 */
@@ -137,6 +140,9 @@
 	/* Counts number of hardware interrupts */
 	unsigned long long interrupts_counter;
 
+	unsigned int volatile cur_slot_kern;
+	unsigned int volatile cur_slot_user;
+
 	/* 
 	 * Number of received packets. This variable should be changed  only in
 	 * user-space. We want to count the packets, that was seen by user-space
@@ -184,40 +190,47 @@
 
 struct ringmap_functions {
 
-/* 
- * Set pointer to the ringmap structure into the adapters
- * driver structure. 
- */
+	/* 
+	 * Set pointer to the ringmap structure into the adapters
+	 * driver structure. 
+	 */
 	int (*set_ringmap_to_adapter)(device_t, struct ringmap*);
 
-/*
- * In some situations it is safe to disable 
- * interrupts on adapter. 
- */
+	/*
+	 * In some situations it is safe to disable 
+	 * interrupts on adapter. 
+	 */
 	void (*enable_intr)(device_t);
 	void (*disable_intr)(device_t);
 
-/*
- * Initialize the ring slots with pointers to the 
- * mbufs, packets buffers and descriptors.
- */
+	/*
+	 * Initialize the ring slots with pointers to the 
+	 * mbufs, packets buffers and descriptors.
+	 */
 	int (*init_slots)(struct ring *, device_t);
 
-/*
- * This function should be calld from ISR. It should contain 
- * the very fast executable operations (don't sleep!). 
- */
-	void (*interrupt)(void *);
+	/*
+	 * This function should be calld from ISR. It should contain 
+	 * the very fast executable operations (don't sleep!). 
+	 */
+	void (*isr)(void *);
 
-/*
- * This function should be calld from delayed interrupt 
- * function. It can contain operations that must not be 
- * very fast.
- */
-	void (*delayed_interrupt)(void *);
+	/*
+	 * This function should be calld from delayed interrupt 
+	 * function. It can contain operations that must not be 
+	 * very fast.
+	 */
+	void (*delayed_isr)(void *);
 
+	/*
+	 * The native driver should have cycle for checking 
+	 * the the packets that was transfered in the RAM from 
+	 * network adapter. The function delayed_isr_per_packet()
+	 * should be called from this cycle, so it will be called 
+	 * per packet.
+	 */
+	void (*delayed_isr_per_packet)(struct ring *, int);
 
-
 /* 
  * This function synchronize the tail and head hardware registers
  * with head and tail software varibles, that are visible from 
@@ -365,7 +378,7 @@
 #define ERR_PREFIX 		"--> RINGMAP ERROR: " 
 #define WARN_PREFIX 	"--> RINGMAP WARN: "
 #define IOCTL_PREFIX 	"--> RINGMAP IOCTL: "
-#define INTR_PREFIX 	"--> RINGMAP IOCTL: "
+#define INTR_PREFIX 	"--> RINGMAP INTR: "
 
 #define RINGMAP_ERROR(x) 	\
 	printf(ERR_PREFIX "[%s]: "  #x "\n", __func__);

==== //depot/projects/soc2010/ringmap/scripts/build_ringmap.sh#2 (text+ko) ====


==== //depot/projects/soc2010/ringmap/scripts/set_ringmap.sh#2 (text+ko) ====

@@ -38,12 +38,12 @@
 echo
 
 sleep 1
-sync
 
 echo
-echo "===> Install ringmap-libpcap:"
+echo "===> Install ringmap-libpcap:" && sleep 1
 echo
 install_libpcap || { echo "Error by installing libpcap" ; exit 1 ; }
 echo
 
+sync
 exit 0


More information about the p4-projects mailing list