Re: panic during boot of 5.7 in de(4) running in Hyper-V

2015-06-25 Thread Reyk Floeter
On Tue, Jun 23, 2015 at 09:08:25PM -0600, Theo de Raadt wrote:
  I looked into this last year but lost interest. It seems like the DMA buffer
  is being placed past the UVM constraint for DMA ( eg  4GB).
 
 A configuration buffer is in the softc.  It should be allocated to be
 dma-reachable.
 
 This driver is quite ugly.  Maybe the following diff works?
 

It fixes the issue for me, with two changes below, otherwise OK.

But I still don't get any traffic with de(4) on Hyper-V here ...  or
just once in a while with dhclient  but this seems to be a
different issue.

Reyk

 Index: if_de.c
 ===
 RCS file: /cvs/src/sys/dev/pci/if_de.c,v
 retrieving revision 1.120
 diff -u -p -u -r1.120 if_de.c
 --- if_de.c   15 May 2015 11:36:30 -  1.120
 +++ if_de.c   24 Jun 2015 00:05:05 -
 @@ -49,6 +49,7 @@
  #include sys/kernel.h
  #include sys/device.h
  #include sys/timeout.h
 +#include sys/pool.h
  
  #include net/if.h
  #include net/if_media.h
 @@ -2907,7 +2908,7 @@ tulip_addr_filter(tulip_softc_t * const 
* go into hash perfect mode (512 bit multicast
* hash and one perfect hardware).
*/
 - bzero(sc-tulip_setupdata, sizeof(sc-tulip_setupdata));
 + bzero(sc-tulip_setupdata, TULIP_SETUP);
   if (ac-ac_multirangecnt  0) {
   sc-tulip_flags |= TULIP_ALLMULTI;
   sc-tulip_flags = ~(TULIP_WANTHASHONLY|TULIP_WANTHASHPERFECT);
 @@ -4085,8 +4086,7 @@ tulip_txput_setup(tulip_softc_t * const 
   sc-tulip_if.if_start = tulip_ifstart;
   return;
  }
 -bcopy(sc-tulip_setupdata, sc-tulip_setupbuf,
 -   sizeof(sc-tulip_setupbuf));
 +bcopy(sc-tulip_setupdata, sc-tulip_setupbuf, TULIP_SETUP);
  /*
   * Clear WANTSETUP and set DOINGSETUP.  Set know that WANTSETUP is
   * set and DOINGSETUP is clear doing an XOR of the two will DTRT.
 @@ -4357,16 +4357,17 @@ tulip_busdma_init(tulip_softc_t * const 
  {
  int error = 0;
  
 +sc-tulip_setupbuf = dma_alloc(TULIP_SETUP, PR_WAITOK);
 +sc-tulip_setupdata = malloc(TULIP_SETUP, M_DEVBUF, M_WAITOK);
 +
  /*
   * Allocate dmamap for setup descriptor
   */
  error = bus_dmamap_create(sc-tulip_dmatag, sizeof(sc-tulip_setupbuf), 
 2,

Here is a missing TULIP_SETUP, it should be:

  error = bus_dmamap_create(sc-tulip_dmatag, TULIP_SETUP, 2,
TULIP_SETUP, 0, BUS_DMA_NOWAIT, sc-tulip_setupmap);

 -   sizeof(sc-tulip_setupbuf), 0, BUS_DMA_NOWAIT,
 -   sc-tulip_setupmap);
 + TULIP_SETUP, 0, BUS_DMA_NOWAIT, sc-tulip_setupmap);
  if (error == 0) {
   error = bus_dmamap_load(sc-tulip_dmatag, sc-tulip_setupmap,
 - sc-tulip_setupbuf, sizeof(sc-tulip_setupbuf),
 - NULL, BUS_DMA_NOWAIT);
 + sc-tulip_setupbuf, TULIP_SETUP, NULL, BUS_DMA_NOWAIT);
   if (error)
   bus_dmamap_destroy(sc-tulip_dmatag, sc-tulip_setupmap);
  }
 Index: if_devar.h
 ===
 RCS file: /cvs/src/sys/dev/pci/if_devar.h,v
 retrieving revision 1.33
 diff -u -p -u -r1.33 if_devar.h
 --- if_devar.h10 Feb 2015 03:51:58 -  1.33
 +++ if_devar.h24 Jun 2015 00:04:36 -
 @@ -600,8 +600,10 @@ struct _tulip_softc_t {
   * one is the one being sent while the other is the one being
   * filled.
   */
 -u_int32_t tulip_setupbuf[192/sizeof(u_int32_t)];
 -u_int32_t tulip_setupdata[192/sizeof(u_int32_t)];
 +#define TULIP_SETUP  (192 / sizeof(u_int32_t))

As mentioned in another mail, this should be changed to

#define TULIP_SETUP 192

 +u_int32_t *tulip_setupbuf;
 +u_int32_t *tulip_setupdata;
 +
  char tulip_boardid[16];  /* buffer for board ID */
  u_int8_t tulip_rombuf[128];
  struct device *tulip_pci_busno;  /* needed for multiport boards */



Re: panic during boot of 5.7 in de(4) running in Hyper-V

2015-06-24 Thread pizdelect
On Tue, Jun 23, 2015 at 09:08:25PM -0600, Theo de Raadt wrote:
 -bcopy(sc-tulip_setupdata, sc-tulip_setupbuf,
 -   sizeof(sc-tulip_setupbuf));
 +bcopy(sc-tulip_setupdata, sc-tulip_setupbuf, TULIP_SETUP);

 +sc-tulip_setupbuf = dma_alloc(TULIP_SETUP, PR_WAITOK);
 +sc-tulip_setupdata = malloc(TULIP_SETUP, M_DEVBUF, M_WAITOK);

 -u_int32_t tulip_setupbuf[192/sizeof(u_int32_t)];
 -u_int32_t tulip_setupdata[192/sizeof(u_int32_t)];
 +#define TULIP_SETUP  (192 / sizeof(u_int32_t))

FWIW, change that to:

+#define TULIP_SETUP192

 +u_int32_t *tulip_setupbuf;
 +u_int32_t *tulip_setupdata;



panic during boot of 5.7 in de(4) running in Hyper-V

2015-06-23 Thread Tom Schutter
I installed 5.7 from 
http://ftp3.usa.openbsd.org/pub/OpenBSD/5.7/amd64/install57.iso
in a Windows Server 2012 R2 Hyper-V VM using the Legacy Network
Adapter.  I always get a kernel panic in the de(4) driver during boot.
If I remove the legacy NIC from the VM config, then I successfully
boot, but obviously with no network access.

What additional information can I provide to help with diagnosis and
create a proper bug report?

 OpenBSD/amd64 BOOT 3.28
...
wsdisplay0 at vga1 mux 1: console (80x25, vt100 emulation)
wsdisplay0: screen 1-5 added (80x25, vt100 emulation)
de0 at pci0 dev 10 function 0 DEC 21140 rev 0x20panic: Non dma-reachable 
buffer at curaddr 0x107762b70(raw)
Stopped at  Debugger+0x9:   leave
Debugger() at Debugger+0x9
panic() at panic+0xfe
_bus_dmamap_load_buffer() at _bus_dmamap_load_buffer+0x1b6
_bus_dmamap_load() at _bus_dmamap_load+0x7f
tulip_busdma_init() at tulip_busdma_init+0xa0
tulip_attach() at tulip_attach+0x2a4
config_attach() at config_attach+0x1bc
pci_probe_device() at pci_probe_device+0x467
pci_enumerate_bus() at pci_enumerate_bus+0xe9
config_attach() at config_attach+0x1bc
end trace frame: 0x81a28e60, count: 0
RUN AT LEAST 'trace' AND 'ps' AND INCLUDE OUTPUT WHEN REPORTING THIS PANIC!
DO NOT EVEN BOTHER REPORTING THIS WITHOUT INCLUDING THAT INFORMATION!
ddb trace
Debugger() at Debugger+0x9
panic() at panic+0xfe
_bus_dmamap_load_buffer() at _bus_dmamap_load_buffer+0x1b6
_bus_dmamap_load() at _bus_dmamap_load+0x7f
tulip_busdma_init() at tulip_busdma_init+0xa0
tulip_attach() at tulip_attach+0x2a4
config_attach() at config_attach+0x1bc
pci_probe_device() at pci_probe_device+0x467
pci_enumerate_bus() at pci_enumerate_bus+0xe9
config_attach() at config_attach+0x1bc
cpu_configure() at cpu_configure+0x1b
main() at main+0x3df
end trace frame: 0x0, count: -14
ddb ps
   PID   PPID   PGRPUID  S FLAGS  WAIT COMMAND
*0 -1  0  0  7   0x10200   swapper

-- 
Tom Schutter



Re: panic during boot of 5.7 in de(4) running in Hyper-V

2015-06-23 Thread Theo de Raadt
 I looked into this last year but lost interest. It seems like the DMA buffer
 is being placed past the UVM constraint for DMA ( eg  4GB).

A configuration buffer is in the softc.  It should be allocated to be
dma-reachable.

This driver is quite ugly.  Maybe the following diff works?

Index: if_de.c
===
RCS file: /cvs/src/sys/dev/pci/if_de.c,v
retrieving revision 1.120
diff -u -p -u -r1.120 if_de.c
--- if_de.c 15 May 2015 11:36:30 -  1.120
+++ if_de.c 24 Jun 2015 00:05:05 -
@@ -49,6 +49,7 @@
 #include sys/kernel.h
 #include sys/device.h
 #include sys/timeout.h
+#include sys/pool.h
 
 #include net/if.h
 #include net/if_media.h
@@ -2907,7 +2908,7 @@ tulip_addr_filter(tulip_softc_t * const 
 * go into hash perfect mode (512 bit multicast
 * hash and one perfect hardware).
 */
-   bzero(sc-tulip_setupdata, sizeof(sc-tulip_setupdata));
+   bzero(sc-tulip_setupdata, TULIP_SETUP);
if (ac-ac_multirangecnt  0) {
sc-tulip_flags |= TULIP_ALLMULTI;
sc-tulip_flags = ~(TULIP_WANTHASHONLY|TULIP_WANTHASHPERFECT);
@@ -4085,8 +4086,7 @@ tulip_txput_setup(tulip_softc_t * const 
sc-tulip_if.if_start = tulip_ifstart;
return;
 }
-bcopy(sc-tulip_setupdata, sc-tulip_setupbuf,
- sizeof(sc-tulip_setupbuf));
+bcopy(sc-tulip_setupdata, sc-tulip_setupbuf, TULIP_SETUP);
 /*
  * Clear WANTSETUP and set DOINGSETUP.  Set know that WANTSETUP is
  * set and DOINGSETUP is clear doing an XOR of the two will DTRT.
@@ -4357,16 +4357,17 @@ tulip_busdma_init(tulip_softc_t * const 
 {
 int error = 0;
 
+sc-tulip_setupbuf = dma_alloc(TULIP_SETUP, PR_WAITOK);
+sc-tulip_setupdata = malloc(TULIP_SETUP, M_DEVBUF, M_WAITOK);
+
 /*
  * Allocate dmamap for setup descriptor
  */
 error = bus_dmamap_create(sc-tulip_dmatag, sizeof(sc-tulip_setupbuf), 2,
- sizeof(sc-tulip_setupbuf), 0, BUS_DMA_NOWAIT,
- sc-tulip_setupmap);
+   TULIP_SETUP, 0, BUS_DMA_NOWAIT, sc-tulip_setupmap);
 if (error == 0) {
error = bus_dmamap_load(sc-tulip_dmatag, sc-tulip_setupmap,
-   sc-tulip_setupbuf, sizeof(sc-tulip_setupbuf),
-   NULL, BUS_DMA_NOWAIT);
+   sc-tulip_setupbuf, TULIP_SETUP, NULL, BUS_DMA_NOWAIT);
if (error)
bus_dmamap_destroy(sc-tulip_dmatag, sc-tulip_setupmap);
 }
Index: if_devar.h
===
RCS file: /cvs/src/sys/dev/pci/if_devar.h,v
retrieving revision 1.33
diff -u -p -u -r1.33 if_devar.h
--- if_devar.h  10 Feb 2015 03:51:58 -  1.33
+++ if_devar.h  24 Jun 2015 00:04:36 -
@@ -600,8 +600,10 @@ struct _tulip_softc_t {
  * one is the one being sent while the other is the one being
  * filled.
  */
-u_int32_t tulip_setupbuf[192/sizeof(u_int32_t)];
-u_int32_t tulip_setupdata[192/sizeof(u_int32_t)];
+#define TULIP_SETUP(192 / sizeof(u_int32_t))
+u_int32_t *tulip_setupbuf;
+u_int32_t *tulip_setupdata;
+
 char tulip_boardid[16];/* buffer for board ID */
 u_int8_t tulip_rombuf[128];
 struct device *tulip_pci_busno;/* needed for multiport boards */



Re: panic during boot of 5.7 in de(4) running in Hyper-V

2015-06-23 Thread Mike Larkin
On Tue, Jun 23, 2015 at 02:57:51PM -0600, Tom Schutter wrote:
 I installed 5.7 from 
 http://ftp3.usa.openbsd.org/pub/OpenBSD/5.7/amd64/install57.iso
 in a Windows Server 2012 R2 Hyper-V VM using the Legacy Network
 Adapter.  I always get a kernel panic in the de(4) driver during boot.
 If I remove the legacy NIC from the VM config, then I successfully
 boot, but obviously with no network access.

I looked into this last year but lost interest. It seems like the DMA buffer
is being placed past the UVM constraint for DMA ( eg  4GB). I'm not sure
why that's happening, I only spent a day or so looking at it before I got
bored and moved on to something else.

A side note - the same config on hyperV seems to work on i386, but I noticed
some strange clock skewing using that config so I gave up on that also.

Another side note - disabling de(4) in config and letting the kernel fall back
to dc(4) gets past this particular panic but doesn't allow any traffic
to pass.

-ml

 
 What additional information can I provide to help with diagnosis and
 create a proper bug report?
 
  OpenBSD/amd64 BOOT 3.28
 ...
 wsdisplay0 at vga1 mux 1: console (80x25, vt100 emulation)
 wsdisplay0: screen 1-5 added (80x25, vt100 emulation)
 de0 at pci0 dev 10 function 0 DEC 21140 rev 0x20panic: Non dma-reachable 
 buffer at curaddr 0x107762b70(raw)
 Stopped at  Debugger+0x9:   leave
 Debugger() at Debugger+0x9
 panic() at panic+0xfe
 _bus_dmamap_load_buffer() at _bus_dmamap_load_buffer+0x1b6
 _bus_dmamap_load() at _bus_dmamap_load+0x7f
 tulip_busdma_init() at tulip_busdma_init+0xa0
 tulip_attach() at tulip_attach+0x2a4
 config_attach() at config_attach+0x1bc
 pci_probe_device() at pci_probe_device+0x467
 pci_enumerate_bus() at pci_enumerate_bus+0xe9
 config_attach() at config_attach+0x1bc
 end trace frame: 0x81a28e60, count: 0
 RUN AT LEAST 'trace' AND 'ps' AND INCLUDE OUTPUT WHEN REPORTING THIS PANIC!
 DO NOT EVEN BOTHER REPORTING THIS WITHOUT INCLUDING THAT INFORMATION!
 ddb trace
 Debugger() at Debugger+0x9
 panic() at panic+0xfe
 _bus_dmamap_load_buffer() at _bus_dmamap_load_buffer+0x1b6
 _bus_dmamap_load() at _bus_dmamap_load+0x7f
 tulip_busdma_init() at tulip_busdma_init+0xa0
 tulip_attach() at tulip_attach+0x2a4
 config_attach() at config_attach+0x1bc
 pci_probe_device() at pci_probe_device+0x467
 pci_enumerate_bus() at pci_enumerate_bus+0xe9
 config_attach() at config_attach+0x1bc
 cpu_configure() at cpu_configure+0x1b
 main() at main+0x3df
 end trace frame: 0x0, count: -14
 ddb ps
PID   PPID   PGRPUID  S FLAGS  WAIT COMMAND
 *0 -1  0  0  7   0x10200   swapper
 
 -- 
 Tom Schutter