Module Name:    src
Committed By:   msaitoh
Date:           Mon Jan 20 07:19:04 UTC 2020

Modified Files:
        src/sys/dev/pci/ixgbe: ix_txrx.c ixgbe.h ixgbe_netbsd.c

Log Message:
 Free jumbo mem structure correctly. Found by yamaguchi@ using with LOCKDEBUG.


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 src/sys/dev/pci/ixgbe/ix_txrx.c
cvs rdiff -u -r1.60 -r1.61 src/sys/dev/pci/ixgbe/ixgbe.h
cvs rdiff -u -r1.10 -r1.11 src/sys/dev/pci/ixgbe/ixgbe_netbsd.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/pci/ixgbe/ix_txrx.c
diff -u src/sys/dev/pci/ixgbe/ix_txrx.c:1.58 src/sys/dev/pci/ixgbe/ix_txrx.c:1.59
--- src/sys/dev/pci/ixgbe/ix_txrx.c:1.58	Mon Dec 16 02:50:54 2019
+++ src/sys/dev/pci/ixgbe/ix_txrx.c	Mon Jan 20 07:19:04 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: ix_txrx.c,v 1.58 2019/12/16 02:50:54 msaitoh Exp $ */
+/* $NetBSD: ix_txrx.c,v 1.59 2020/01/20 07:19:04 msaitoh Exp $ */
 
 /******************************************************************************
 
@@ -1681,6 +1681,10 @@ ixgbe_free_receive_buffers(struct rx_rin
 				rxbuf->pmap = NULL;
 			}
 		}
+
+		/* NetBSD specific. See ixgbe_netbsd.c */
+		ixgbe_jcl_destroy(adapter, rxr);
+
 		if (rxr->rx_buffers != NULL) {
 			free(rxr->rx_buffers, M_DEVBUF);
 			rxr->rx_buffers = NULL;

Index: src/sys/dev/pci/ixgbe/ixgbe.h
diff -u src/sys/dev/pci/ixgbe/ixgbe.h:1.60 src/sys/dev/pci/ixgbe/ixgbe.h:1.61
--- src/sys/dev/pci/ixgbe/ixgbe.h:1.60	Mon Dec 16 02:50:54 2019
+++ src/sys/dev/pci/ixgbe/ixgbe.h	Mon Jan 20 07:19:04 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe.h,v 1.60 2019/12/16 02:50:54 msaitoh Exp $ */
+/* $NetBSD: ixgbe.h,v 1.61 2020/01/20 07:19:04 msaitoh Exp $ */
 
 /******************************************************************************
   SPDX-License-Identifier: BSD-3-Clause
@@ -780,6 +780,7 @@ const struct sysctlnode *ixgbe_sysctl_in
 /* For NetBSD */
 void ixgbe_jcl_reinit(struct adapter *, bus_dma_tag_t, struct rx_ring *,
     int, size_t);
+void ixgbe_jcl_destroy(struct adapter *,  struct rx_ring *);
 
 #include "ixgbe_bypass.h"
 #include "ixgbe_fdir.h"

Index: src/sys/dev/pci/ixgbe/ixgbe_netbsd.c
diff -u src/sys/dev/pci/ixgbe/ixgbe_netbsd.c:1.10 src/sys/dev/pci/ixgbe/ixgbe_netbsd.c:1.11
--- src/sys/dev/pci/ixgbe/ixgbe_netbsd.c:1.10	Wed Sep  4 07:29:34 2019
+++ src/sys/dev/pci/ixgbe/ixgbe_netbsd.c	Mon Jan 20 07:19:04 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe_netbsd.c,v 1.10 2019/09/04 07:29:34 msaitoh Exp $ */
+/* $NetBSD: ixgbe_netbsd.c,v 1.11 2020/01/20 07:19:04 msaitoh Exp $ */
 /*
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -161,6 +161,22 @@ post_zalloc_err:
 	return NULL;
 }
 
+static void
+ixgbe_jcl_freeall(struct adapter *adapter, struct rx_ring *rxr)
+{
+	ixgbe_extmem_head_t *eh = &rxr->jcl_head;
+	ixgbe_extmem_t *em;
+	bus_dma_tag_t dmat = rxr->ptag->dt_dmat;
+
+	while ((em = ixgbe_getext(eh, 0)) != NULL) {
+		KASSERT(em->em_vaddr != NULL);
+		bus_dmamem_unmap(dmat, em->em_vaddr, em->em_size);
+		bus_dmamem_free(dmat, &em->em_seg, 1);
+		memset(em, 0, sizeof(*em));
+		kmem_free(em, sizeof(*em));
+	}
+}
+
 void
 ixgbe_jcl_reinit(struct adapter *adapter, bus_dma_tag_t dmat,
     struct rx_ring *rxr, int nbuf, size_t size)
@@ -187,13 +203,7 @@ ixgbe_jcl_reinit(struct adapter *adapter
 		return;
 
 	/* Free all dmamem */
-	while ((em = ixgbe_getext(eh, 0)) != NULL) {
-		KASSERT(em->em_vaddr != NULL);
-		bus_dmamem_unmap(dmat, em->em_vaddr, em->em_size);
-		bus_dmamem_free(dmat, &em->em_seg, 1);
-		memset(em, 0, sizeof(*em));
-		kmem_free(em, sizeof(*em));
-	}
+	ixgbe_jcl_freeall(adapter, rxr);
 
 	for (i = 0; i < nbuf; i++) {
 		if ((em = ixgbe_newext(eh, dmat, size)) == NULL) {
@@ -210,6 +220,21 @@ ixgbe_jcl_reinit(struct adapter *adapter
 	rxr->last_num_rx_desc = adapter->num_rx_desc;
 }
 
+void
+ixgbe_jcl_destroy(struct adapter *adapter, struct rx_ring *rxr)
+{
+	ixgbe_extmem_head_t *eh = &rxr->jcl_head;
+
+	/* Free all dmamem */
+	ixgbe_jcl_freeall(adapter, rxr);
+
+	if (eh->eh_initialized) {
+		mutex_destroy(&eh->eh_mtx);
+		eh->eh_initialized = false;
+	}
+}
+
+
 static void
 ixgbe_jcl_free(struct mbuf *m, void *buf, size_t size, void *arg)
 {

Reply via email to