svn commit: r287272 - stable/10/sys/dev/usb

2015-08-29 Thread Hans Petter Selasky
Author: hselasky
Date: Sat Aug 29 06:11:50 2015
New Revision: 287272
URL: https://svnweb.freebsd.org/changeset/base/287272

Log:
  MFC r286799:
  Fix race in USB PF which can happen if we stop tracing exactly when
  the kernel is tapping an USB transfer. This leads to a NULL pointer
  access. The solution is to only trace while the USB bus lock is
  locked.

Modified:
  stable/10/sys/dev/usb/usb_pf.c
  stable/10/sys/dev/usb/usb_transfer.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/dev/usb/usb_pf.c
==
--- stable/10/sys/dev/usb/usb_pf.c  Sat Aug 29 06:07:55 2015
(r287271)
+++ stable/10/sys/dev/usb/usb_pf.c  Sat Aug 29 06:11:50 2015
(r287272)
@@ -220,7 +220,13 @@ usbpf_clone_destroy(struct if_clone *ifc
ubus = ifp-if_softc;
unit = ifp-if_dunit;
 
+   /*
+* Lock USB before clearing the ifp pointer, to avoid
+* clearing the pointer in the middle of a TAP operation:
+*/
+   USB_BUS_LOCK(ubus);
ubus-ifp = NULL;
+   USB_BUS_UNLOCK(ubus);
bpfdetach(ifp);
if_detach(ifp);
if_free(ifp);

Modified: stable/10/sys/dev/usb/usb_transfer.c
==
--- stable/10/sys/dev/usb/usb_transfer.cSat Aug 29 06:07:55 2015
(r287271)
+++ stable/10/sys/dev/usb/usb_transfer.cSat Aug 29 06:11:50 2015
(r287272)
@@ -2381,8 +2381,11 @@ usbd_callback_wrapper(struct usb_xfer_qu
}
 
 #if USB_HAVE_PF
-   if (xfer-usb_state != USB_ST_SETUP)
+   if (xfer-usb_state != USB_ST_SETUP) {
+   USB_BUS_LOCK(info-bus);
usbpf_xfertap(xfer, USBPF_XFERTAP_DONE);
+   USB_BUS_UNLOCK(info-bus);
+   }
 #endif
/* call processing routine */
(xfer-callback) (xfer, xfer-error);
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to svn-src-stable-10-unsubscr...@freebsd.org


svn commit: r287274 - in stable/10/sys: boot/usb dev/usb dev/usb/controller

2015-08-29 Thread Hans Petter Selasky
Author: hselasky
Date: Sat Aug 29 06:23:40 2015
New Revision: 287274
URL: https://svnweb.freebsd.org/changeset/base/287274

Log:
  MFC r286773:
  Improve the realtime properties of USB transfers for embedded systems
  like RPI-B and RPI-2.

Modified:
  stable/10/sys/boot/usb/bsd_kernel.h
  stable/10/sys/dev/usb/controller/usb_controller.c
  stable/10/sys/dev/usb/usb_bus.h
  stable/10/sys/dev/usb/usb_device.c
  stable/10/sys/dev/usb/usb_hub.c
  stable/10/sys/dev/usb/usb_process.h
  stable/10/sys/dev/usb/usb_transfer.c
  stable/10/sys/dev/usb/usbdi.h
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/boot/usb/bsd_kernel.h
==
--- stable/10/sys/boot/usb/bsd_kernel.h Sat Aug 29 06:17:39 2015
(r287273)
+++ stable/10/sys/boot/usb/bsd_kernel.h Sat Aug 29 06:23:40 2015
(r287274)
@@ -42,7 +42,8 @@
 #defineM_USBDEV 0
 #defineUSB_PROC_MAX 3
 #defineUSB_BUS_GIANT_PROC(bus) (usb_process + 2)
-#defineUSB_BUS_NON_GIANT_PROC(bus) (usb_process + 2)
+#defineUSB_BUS_NON_GIANT_BULK_PROC(bus) (usb_process + 2)
+#defineUSB_BUS_NON_GIANT_ISOC_PROC(bus) (usb_process + 2)
 #defineUSB_BUS_EXPLORE_PROC(bus) (usb_process + 0)
 #defineUSB_BUS_CONTROL_XFER_PROC(bus) (usb_process + 1)
 #defineSYSCTL_DECL(...)

Modified: stable/10/sys/dev/usb/controller/usb_controller.c
==
--- stable/10/sys/dev/usb/controller/usb_controller.c   Sat Aug 29 06:17:39 
2015(r287273)
+++ stable/10/sys/dev/usb/controller/usb_controller.c   Sat Aug 29 06:23:40 
2015(r287274)
@@ -233,7 +233,8 @@ usb_detach(device_t dev)
/* Get rid of USB callback processes */
 
usb_proc_free(USB_BUS_GIANT_PROC(bus));
-   usb_proc_free(USB_BUS_NON_GIANT_PROC(bus));
+   usb_proc_free(USB_BUS_NON_GIANT_ISOC_PROC(bus));
+   usb_proc_free(USB_BUS_NON_GIANT_BULK_PROC(bus));
 
/* Get rid of USB explore process */
 
@@ -397,7 +398,8 @@ usb_bus_explore(struct usb_proc_msg *pm)
 */
usb_proc_rewakeup(USB_BUS_CONTROL_XFER_PROC(bus));
usb_proc_rewakeup(USB_BUS_GIANT_PROC(bus));
-   usb_proc_rewakeup(USB_BUS_NON_GIANT_PROC(bus));
+   usb_proc_rewakeup(USB_BUS_NON_GIANT_ISOC_PROC(bus));
+   usb_proc_rewakeup(USB_BUS_NON_GIANT_BULK_PROC(bus));
 #endif
 
USB_BUS_UNLOCK(bus);
@@ -862,9 +864,13 @@ usb_attach_sub(device_t dev, struct usb_
bus-bus_mtx, device_get_nameunit(dev), USB_PRI_MED)) {
device_printf(dev, WARNING: Creation of USB Giant 
callback process failed.\n);
-   } else if (usb_proc_create(USB_BUS_NON_GIANT_PROC(bus),
+   } else if (usb_proc_create(USB_BUS_NON_GIANT_ISOC_PROC(bus),
+   bus-bus_mtx, device_get_nameunit(dev), USB_PRI_HIGHEST)) {
+   device_printf(dev, WARNING: Creation of USB non-Giant ISOC 
+   callback process failed.\n);
+   } else if (usb_proc_create(USB_BUS_NON_GIANT_BULK_PROC(bus),
bus-bus_mtx, device_get_nameunit(dev), USB_PRI_HIGH)) {
-   device_printf(dev, WARNING: Creation of USB non-Giant 
+   device_printf(dev, WARNING: Creation of USB non-Giant BULK 
callback process failed.\n);
} else if (usb_proc_create(USB_BUS_EXPLORE_PROC(bus),
bus-bus_mtx, device_get_nameunit(dev), USB_PRI_MED)) {

Modified: stable/10/sys/dev/usb/usb_bus.h
==
--- stable/10/sys/dev/usb/usb_bus.h Sat Aug 29 06:17:39 2015
(r287273)
+++ stable/10/sys/dev/usb/usb_bus.h Sat Aug 29 06:23:40 2015
(r287274)
@@ -57,19 +57,26 @@ struct usb_bus {
struct root_hold_token *bus_roothold;
 #endif
 
+/* convenience macros */
+#defineUSB_BUS_TT_PROC(bus) USB_BUS_NON_GIANT_ISOC_PROC(bus)
+#defineUSB_BUS_CS_PROC(bus) USB_BUS_NON_GIANT_ISOC_PROC(bus)
+  
 #if USB_HAVE_PER_BUS_PROCESS
 #defineUSB_BUS_GIANT_PROC(bus) ((bus)-giant_callback_proc)
-#defineUSB_BUS_NON_GIANT_PROC(bus) ((bus)-non_giant_callback_proc)
+#defineUSB_BUS_NON_GIANT_ISOC_PROC(bus) 
((bus)-non_giant_isoc_callback_proc)
+#defineUSB_BUS_NON_GIANT_BULK_PROC(bus) 
((bus)-non_giant_bulk_callback_proc)
 #defineUSB_BUS_EXPLORE_PROC(bus) ((bus)-explore_proc)
 #defineUSB_BUS_CONTROL_XFER_PROC(bus) ((bus)-control_xfer_proc)
-
/*
-* There are two callback processes. One for Giant locked
-* callbacks. One for non-Giant locked callbacks. This should
-* avoid congestion and reduce response time in most cases.
+* There are three callback processes. One for Giant locked
+* callbacks. One for non-Giant locked non-periodic callbacks
+* and one for 

svn commit: r287271 - stable/10/sys/dev/usb/controller

2015-08-29 Thread Hans Petter Selasky
Author: hselasky
Date: Sat Aug 29 06:07:55 2015
New Revision: 287271
URL: https://svnweb.freebsd.org/changeset/base/287271

Log:
  MFC r283067, r286118, r285638, r285935, r286778, r286780 and r286802:
  - Make the FIFO configuration a bit more flexible for the DWC OTG in
  device side mode.
  - Limit the number of times we loop inside the DWC OTG poll handler to
  avoid starving other fast interrupts. Fix a comment while at it.
  - Optimise the DWC OTG host mode driver's transmit path
  - Optimise the DWC OTG host mode driver's receive path
  - Minor code refactor to avoid duplicating code.
  - Handle NYET high speed tokens and predict NAK'ing is up next.
  - Fixes for HIGH speed ISOCHRONOUS traffic.

Modified:
  stable/10/sys/dev/usb/controller/dwc_otg.c
  stable/10/sys/dev/usb/controller/dwc_otg.h
  stable/10/sys/dev/usb/controller/dwc_otgreg.h
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/dev/usb/controller/dwc_otg.c
==
--- stable/10/sys/dev/usb/controller/dwc_otg.c  Sat Aug 29 04:33:31 2015
(r287270)
+++ stable/10/sys/dev/usb/controller/dwc_otg.c  Sat Aug 29 06:07:55 2015
(r287271)
@@ -1,6 +1,7 @@
 /* $FreeBSD$ */
 /*-
- * Copyright (c) 2012 Hans Petter Selasky. All rights reserved.
+ * Copyright (c) 2015 Daisuke Aoyama. All rights reserved.
+ * Copyright (c) 2012-2015 Hans Petter Selasky. All rights reserved.
  * Copyright (c) 2010-2011 Aleksandr Rybalko. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -152,7 +153,6 @@ static void dwc_otg_do_poll(struct usb_b
 static void dwc_otg_standard_done(struct usb_xfer *);
 static void dwc_otg_root_intr(struct dwc_otg_softc *);
 static void dwc_otg_interrupt_poll_locked(struct dwc_otg_softc *);
-static void dwc_otg_host_channel_disable(struct dwc_otg_softc *, uint8_t);
 
 /*
  * Here is a configuration that the chip supports.
@@ -225,7 +225,7 @@ dwc_otg_init_fifo(struct dwc_otg_softc *
/* split equally for IN and OUT */
fifo_size /= 2;
 
-   /* align to 4 bytes boundary */
+   /* Align to 4 bytes boundary (refer to PGM) */
fifo_size = ~3;
 
/* set global receive FIFO size */
@@ -238,13 +238,6 @@ dwc_otg_init_fifo(struct dwc_otg_softc *
return (EINVAL);
}
 
-   /* disable any leftover host channels */
-   for (x = 0; x != sc-sc_host_ch_max; x++) {
-   if (sc-sc_chan_state[x].wait_sof == 0)
-   continue;
-   dwc_otg_host_channel_disable(sc, x);
-   }
-
if (mode == DWC_MODE_HOST) {
 
/* reset active endpoints */
@@ -253,6 +246,8 @@ dwc_otg_init_fifo(struct dwc_otg_softc *
/* split equally for periodic and non-periodic */
fifo_size /= 2;
 
+   DPRINTF(PTX/NPTX FIFO=%u\n, fifo_size);
+
/* align to 4 bytes boundary */
fifo_size = ~3;
 
@@ -263,7 +258,7 @@ dwc_otg_init_fifo(struct dwc_otg_softc *
tx_start += fifo_size;
 
for (x = 0; x != sc-sc_host_ch_max; x++) {
-   /* disable all host interrupts */
+   /* enable all host interrupts */
DWC_OTG_WRITE_4(sc, DOTG_HCINTMSK(x),
HCINT_DEFAULT_MASK);
}
@@ -275,13 +270,6 @@ dwc_otg_init_fifo(struct dwc_otg_softc *
/* reset host channel state */
memset(sc-sc_chan_state, 0, sizeof(sc-sc_chan_state));
 
-   /* reset FIFO TX levels */
-   sc-sc_tx_cur_p_level = 0;
-   sc-sc_tx_cur_np_level = 0;
-
-   /* store maximum periodic and non-periodic FIFO TX size */
-   sc-sc_tx_max_size = fifo_size;
-
/* enable all host channel interrupts */
DWC_OTG_WRITE_4(sc, DOTG_HAINTMSK,
(1U  sc-sc_host_ch_max) - 1U);
@@ -314,32 +302,29 @@ dwc_otg_init_fifo(struct dwc_otg_softc *
if (x  sc-sc_dev_in_ep_max) {
uint32_t limit;
 
-   limit = (x == 1) ? DWC_OTG_MAX_TXN :
-   (DWC_OTG_MAX_TXN / 2);
+   limit = (x == 1) ? MIN(DWC_OTG_TX_MAX_FIFO_SIZE,
+   DWC_OTG_MAX_TXN) : MIN(DWC_OTG_MAX_TXN / 2,
+   DWC_OTG_TX_MAX_FIFO_SIZE);
 
-   if (fifo_size = limit) {
-   DWC_OTG_WRITE_4(sc, DOTG_DIEPTXF(x),
-   ((limit / 4)  16) |
-   (tx_start / 4));
-   tx_start += limit;
-   fifo_size -= limit;
-   pf-usb.max_in_frame_size = 0x200;
-   pf-usb.support_in = 1;
+   /* see if there is enough FIFO space */
+ 

svn commit: r287287 - stable/10/sys/gnu/fs/reiserfs

2015-08-29 Thread Tai-hwa Liang
Author: avatar
Date: Sat Aug 29 11:15:54 2015
New Revision: 287287
URL: https://svnweb.freebsd.org/changeset/base/287287

Log:
  MFC r286888: Using consistent coding style to deal with error inside the loop.

Modified:
  stable/10/sys/gnu/fs/reiserfs/reiserfs_vfsops.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/gnu/fs/reiserfs/reiserfs_vfsops.c
==
--- stable/10/sys/gnu/fs/reiserfs/reiserfs_vfsops.c Sat Aug 29 10:53:53 
2015(r287286)
+++ stable/10/sys/gnu/fs/reiserfs/reiserfs_vfsops.c Sat Aug 29 11:15:54 
2015(r287287)
@@ -960,8 +960,8 @@ uint32_t find_hash_out(struct reiserfs_m
key.on_disk_key.k_objectid, key.on_disk_key.k_dir_id);
retval = search_by_entry_key(sbi, key, path, de);
if (retval == IO_ERROR) {
-   pathrelse(path);
-   return (UNSET_HASH);
+   hash = UNSET_HASH;
+   break;
}
if (retval == NAME_NOT_FOUND)
de.de_entry_num--;
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to svn-src-stable-10-unsubscr...@freebsd.org


svn commit: r287286 - stable/10/sys/cam/ata

2015-08-29 Thread Alexander Motin
Author: mav
Date: Sat Aug 29 10:53:53 2015
New Revision: 287286
URL: https://svnweb.freebsd.org/changeset/base/287286

Log:
  MFC r287025: Remove some code duplication by using biofinish().

Modified:
  stable/10/sys/cam/ata/ata_da.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/cam/ata/ata_da.c
==
--- stable/10/sys/cam/ata/ata_da.c  Sat Aug 29 10:52:16 2015
(r287285)
+++ stable/10/sys/cam/ata/ata_da.c  Sat Aug 29 10:53:53 2015
(r287286)
@@ -1535,9 +1535,7 @@ adastart(struct cam_periph *periph, unio
} else {
/* This can happen if DMA was disabled. */
bioq_remove(softc-trim_queue, bp);
-   bp-bio_error = EOPNOTSUPP;
-   bp-bio_flags |= BIO_ERROR;
-   biodone(bp);
+   biofinish(bp, NULL, EOPNOTSUPP);
xpt_release_ccb(start_ccb);
adaschedule(periph);
return;
@@ -1602,9 +1600,7 @@ adastart(struct cam_periph *periph, unio
}
}
if (fail) {
-   bp-bio_error = EIO;
-   bp-bio_flags |= BIO_ERROR;
-   biodone(bp);
+   biofinish(bp, NULL, EIO);
xpt_release_ccb(start_ccb);
adaschedule(periph);
return;
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to svn-src-stable-10-unsubscr...@freebsd.org


svn commit: r287298 - stable/10/lib/libc/gen

2015-08-29 Thread Jilles Tjoelker
Author: jilles
Date: Sat Aug 29 20:41:09 2015
New Revision: 287298
URL: https://svnweb.freebsd.org/changeset/base/287298

Log:
  MFC r279084,280713: setmode(): Use sysctl kern.proc.umask instead of umask()
  if possible.
  
  The kern.proc.umask.pid sysctl allows querying the umask without
  temporarily modifying it.
  
  r280713 is the actual change, while r279084 is a whitespace change.

Modified:
  stable/10/lib/libc/gen/setmode.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/lib/libc/gen/setmode.c
==
--- stable/10/lib/libc/gen/setmode.cSat Aug 29 19:47:20 2015
(r287297)
+++ stable/10/lib/libc/gen/setmode.cSat Aug 29 20:41:09 2015
(r287298)
@@ -39,6 +39,7 @@ __FBSDID($FreeBSD$);
 #include namespace.h
 #include sys/types.h
 #include sys/stat.h
+#include sys/sysctl.h
 
 #include ctype.h
 #include errno.h
@@ -68,6 +69,7 @@ typedef struct bitcmd {
 #defineCMD2_OBITS  0x08
 #defineCMD2_UBITS  0x10
 
+static mode_t   getumask(void);
 static BITCMD  *addcmd(BITCMD *, mode_t, mode_t, mode_t, mode_t);
 static void compress_mode(BITCMD *);
 #ifdef SETMODE_DEBUG
@@ -169,7 +171,6 @@ setmode(const char *p)
int serrno;
char op, *ep;
BITCMD *set, *saveset, *endset;
-   sigset_t sigset, sigoset;
mode_t mask, perm, permXbits, who;
long perml;
int equalopdone;
@@ -182,15 +183,9 @@ setmode(const char *p)
 
/*
 * Get a copy of the mask for the permissions that are mask relative.
-* Flip the bits, we want what's not set.  Since it's possible that
-* the caller is opening files inside a signal handler, protect them
-* as best we can.
+* Flip the bits, we want what's not set.
 */
-   sigfillset(sigset);
-(void)_sigprocmask(SIG_BLOCK, sigset, sigoset);
-   (void)umask(mask = umask(0));
-   mask = ~mask;
-(void)_sigprocmask(SIG_SETMASK, sigoset, NULL);
+   mask = ~getumask();
 
setlen = SET_LEN + 2;
 
@@ -346,6 +341,35 @@ out:
return NULL;
 }
 
+static mode_t
+getumask(void)
+{
+   sigset_t sigset, sigoset;
+   size_t len;
+   mode_t mask;
+   u_short smask;
+
+   /*
+* First try requesting the umask without temporarily modifying it.
+* Note that this does not work if the sysctl
+* security.bsd.unprivileged_proc_debug is set to 0.
+*/
+   len = sizeof(smask);
+   if (sysctl((int[4]){ CTL_KERN, KERN_PROC, KERN_PROC_UMASK, getpid() },
+   4, smask, len, NULL, 0) == 0)
+   return (smask);
+
+   /*
+* Since it's possible that the caller is opening files inside a signal
+* handler, protect them as best we can.
+*/
+   sigfillset(sigset);
+   (void)_sigprocmask(SIG_BLOCK, sigset, sigoset);
+   (void)umask(mask = umask(0));
+   (void)_sigprocmask(SIG_SETMASK, sigoset, NULL);
+   return (mask);
+}
+
 static BITCMD *
 addcmd(BITCMD *set, mode_t op, mode_t who, mode_t oparg, mode_t mask)
 {
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to svn-src-stable-10-unsubscr...@freebsd.org