svn commit: r367583 - in head/sys: kern sys

2020-11-11 Thread Mateusz Guzik
Author: mjg
Date: Wed Nov 11 08:48:43 2020
New Revision: 367583
URL: https://svnweb.freebsd.org/changeset/base/367583

Log:
  thread: fix thread0 tid allocation
  
  Startup code hardcodes the value instead of allocating it.
  The first spawned thread would then be a duplicate.
  
  Pointy hat:   mjg

Modified:
  head/sys/kern/init_main.c
  head/sys/kern/kern_thread.c
  head/sys/sys/proc.h

Modified: head/sys/kern/init_main.c
==
--- head/sys/kern/init_main.c   Wed Nov 11 00:43:13 2020(r367582)
+++ head/sys/kern/init_main.c   Wed Nov 11 08:48:43 2020(r367583)
@@ -496,8 +496,7 @@ proc0_init(void *dummy __unused)
p->p_klist = knlist_alloc(&p->p_mtx);
STAILQ_INIT(&p->p_ktr);
p->p_nice = NZERO;
-   /* pid_max cannot be greater than PID_MAX */
-   td->td_tid = PID_MAX + 1;
+   td->td_tid = THREAD0_TID;
LIST_INSERT_HEAD(TIDHASH(td->td_tid), td, td_hash);
td->td_state = TDS_RUNNING;
td->td_pri_class = PRI_TIMESHARE;

Modified: head/sys/kern/kern_thread.c
==
--- head/sys/kern/kern_thread.c Wed Nov 11 00:43:13 2020(r367582)
+++ head/sys/kern/kern_thread.c Wed Nov 11 08:48:43 2020(r367583)
@@ -354,6 +354,7 @@ extern int max_threads_per_proc;
 void
 threadinit(void)
 {
+   lwpid_t tid0;
uint32_t flags;
 
/*
@@ -374,6 +375,9 @@ threadinit(void)
 
mtx_init(&tid_lock, "TID lock", NULL, MTX_DEF);
tid_bitmap = bit_alloc(maxthread, M_TIDHASH, M_WAITOK);
+   tid0 = tid_alloc();
+   if (tid0 != THREAD0_TID)
+   panic("tid0 %d != %d\n", tid0, THREAD0_TID);
 
flags = UMA_ZONE_NOFREE;
 #ifdef __aarch64__

Modified: head/sys/sys/proc.h
==
--- head/sys/sys/proc.h Wed Nov 11 00:43:13 2020(r367582)
+++ head/sys/sys/proc.h Wed Nov 11 08:48:43 2020(r367583)
@@ -855,6 +855,7 @@ MALLOC_DECLARE(M_SUBPROC);
  */
 #definePID_MAX 9
 #defineNO_PID  10
+#defineTHREAD0_TID NO_PID
 extern pid_t pid_max;
 
 #defineSESS_LEADER(p)  ((p)->p_session->s_leader == (p))
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r367584 - in head/sys: kern sys

2020-11-11 Thread Mateusz Guzik
Author: mjg
Date: Wed Nov 11 08:50:04 2020
New Revision: 367584
URL: https://svnweb.freebsd.org/changeset/base/367584

Log:
  thread: rework tidhash vs proc lock interaction
  
  Apart from minor clean up this gets rid of proc unlock/lock cycle on thread
  exit to work around LOR against tidhash lock.

Modified:
  head/sys/kern/init_main.c
  head/sys/kern/kern_kthread.c
  head/sys/kern/kern_thr.c
  head/sys/kern/kern_thread.c
  head/sys/sys/proc.h

Modified: head/sys/kern/init_main.c
==
--- head/sys/kern/init_main.c   Wed Nov 11 08:48:43 2020(r367583)
+++ head/sys/kern/init_main.c   Wed Nov 11 08:50:04 2020(r367584)
@@ -497,7 +497,7 @@ proc0_init(void *dummy __unused)
STAILQ_INIT(&p->p_ktr);
p->p_nice = NZERO;
td->td_tid = THREAD0_TID;
-   LIST_INSERT_HEAD(TIDHASH(td->td_tid), td, td_hash);
+   tidhash_add(td);
td->td_state = TDS_RUNNING;
td->td_pri_class = PRI_TIMESHARE;
td->td_user_pri = PUSER;

Modified: head/sys/kern/kern_kthread.c
==
--- head/sys/kern/kern_kthread.cWed Nov 11 08:48:43 2020
(r367583)
+++ head/sys/kern/kern_kthread.cWed Nov 11 08:50:04 2020
(r367584)
@@ -350,15 +350,12 @@ kthread_exit(void)
 * The last exiting thread in a kernel process must tear down
 * the whole process.
 */
-   rw_wlock(&tidhash_lock);
PROC_LOCK(p);
if (p->p_numthreads == 1) {
PROC_UNLOCK(p);
-   rw_wunlock(&tidhash_lock);
kproc_exit(0);
}
-   LIST_REMOVE(td, td_hash);
-   rw_wunlock(&tidhash_lock);
+   tidhash_remove(td);
umtx_thread_exit(td);
tdsigcleanup(td);
PROC_SLOCK(p);

Modified: head/sys/kern/kern_thr.c
==
--- head/sys/kern/kern_thr.cWed Nov 11 08:48:43 2020(r367583)
+++ head/sys/kern/kern_thr.cWed Nov 11 08:50:04 2020(r367584)
@@ -353,14 +353,13 @@ kern_thr_exit(struct thread *td)
return (0);
}
 
-   p->p_pendingexits++;
td->td_dbgflags |= TDB_EXIT;
-   if (p->p_ptevents & PTRACE_LWP)
+   if (p->p_ptevents & PTRACE_LWP) {
+   p->p_pendingexits++;
ptracestop(td, SIGTRAP, NULL);
-   PROC_UNLOCK(p);
+   p->p_pendingexits--;
+   }
tidhash_remove(td);
-   PROC_LOCK(p);
-   p->p_pendingexits--;
 
/*
 * The check above should prevent all other threads from this

Modified: head/sys/kern/kern_thread.c
==
--- head/sys/kern/kern_thread.c Wed Nov 11 08:48:43 2020(r367583)
+++ head/sys/kern/kern_thread.c Wed Nov 11 08:50:04 2020(r367584)
@@ -147,9 +147,10 @@ SYSCTL_INT(_kern, OID_AUTO, maxthread, CTLFLAG_RDTUN,
 
 static int nthreads;
 
-struct tidhashhead *tidhashtbl;
-u_long tidhash;
-struct rwlock tidhash_lock;
+static LIST_HEAD(tidhashhead, thread) *tidhashtbl;
+static u_long  tidhash;
+static struct  rwlock tidhash_lock;
+#defineTIDHASH(tid)(&tidhashtbl[(tid) & tidhash])
 
 EVENTHANDLER_LIST_DEFINE(thread_ctor);
 EVENTHANDLER_LIST_DEFINE(thread_dtor);
@@ -1329,13 +1330,65 @@ thread_single_end(struct proc *p, int mode)
kick_proc0();
 }
 
-/* Locate a thread by number; return with proc lock held. */
+/*
+ * Locate a thread by number and return with proc lock held.
+ *
+ * thread exit establishes proc -> tidhash lock ordering, but lookup
+ * takes tidhash first and needs to return locked proc.
+ *
+ * The problem is worked around by relying on type-safety of both
+ * structures and doing the work in 2 steps:
+ * - tidhash-locked lookup which saves both thread and proc pointers
+ * - proc-locked verification that the found thread still matches
+ */
+static bool
+tdfind_hash(lwpid_t tid, pid_t pid, struct proc **pp, struct thread **tdp)
+{
+#define RUN_THRESH 16
+   struct proc *p;
+   struct thread *td;
+   int run;
+   bool locked;
+
+   run = 0;
+   rw_rlock(&tidhash_lock);
+   locked = true;
+   LIST_FOREACH(td, TIDHASH(tid), td_hash) {
+   if (td->td_tid != tid) {
+   run++;
+   continue;
+   }
+   p = td->td_proc;
+   if (pid != -1 && p->p_pid != pid) {
+   td = NULL;
+   break;
+   }
+   if (run > RUN_THRESH) {
+   if (rw_try_upgrade(&tidhash_lock)) {
+   LIST_REMOVE(td, td_hash);
+   LIST_INSERT_HEAD(TIDHASH(td->td_tid),
+   td, td_hash);
+   rw_wunlock(&tidhash_lock);
+  

svn commit: r367585 - head/sys/kern

2020-11-11 Thread Mateusz Guzik
Author: mjg
Date: Wed Nov 11 08:51:04 2020
New Revision: 367585
URL: https://svnweb.freebsd.org/changeset/base/367585

Log:
  thread: add more fine-grained tidhash locking
  
  Note this still does not scale but is enough to move it out of the way
  for the foreseable future.
  
  In particular a trivial benchmark spawning/killing threads stops contesting
  on tidhash.

Modified:
  head/sys/kern/kern_thread.c

Modified: head/sys/kern/kern_thread.c
==
--- head/sys/kern/kern_thread.c Wed Nov 11 08:50:04 2020(r367584)
+++ head/sys/kern/kern_thread.c Wed Nov 11 08:51:04 2020(r367585)
@@ -149,8 +149,10 @@ static int nthreads;
 
 static LIST_HEAD(tidhashhead, thread) *tidhashtbl;
 static u_long  tidhash;
-static struct  rwlock tidhash_lock;
-#defineTIDHASH(tid)(&tidhashtbl[(tid) & tidhash])
+static u_long  tidhashlock;
+static struct  rwlock *tidhashtbl_lock;
+#defineTIDHASH(tid)(&tidhashtbl[(tid) & tidhash])
+#defineTIDHASHLOCK(tid)(&tidhashtbl_lock[(tid) & tidhashlock])
 
 EVENTHANDLER_LIST_DEFINE(thread_ctor);
 EVENTHANDLER_LIST_DEFINE(thread_dtor);
@@ -355,6 +357,7 @@ extern int max_threads_per_proc;
 void
 threadinit(void)
 {
+   u_long i;
lwpid_t tid0;
uint32_t flags;
 
@@ -395,7 +398,13 @@ threadinit(void)
thread_ctor, thread_dtor, thread_init, thread_fini,
32 - 1, flags);
tidhashtbl = hashinit(maxproc / 2, M_TIDHASH, &tidhash);
-   rw_init(&tidhash_lock, "tidhash");
+   tidhashlock = (tidhash + 1) / 64;
+   if (tidhashlock > 0)
+   tidhashlock--;
+   tidhashtbl_lock = malloc(sizeof(*tidhashtbl_lock) * (tidhashlock + 1),
+   M_TIDHASH, M_WAITOK | M_ZERO);
+   for (i = 0; i < tidhashlock + 1; i++)
+   rw_init(&tidhashtbl_lock[i], "tidhash");
 }
 
 /*
@@ -1351,7 +1360,7 @@ tdfind_hash(lwpid_t tid, pid_t pid, struct proc **pp, 
bool locked;
 
run = 0;
-   rw_rlock(&tidhash_lock);
+   rw_rlock(TIDHASHLOCK(tid));
locked = true;
LIST_FOREACH(td, TIDHASH(tid), td_hash) {
if (td->td_tid != tid) {
@@ -1364,11 +1373,11 @@ tdfind_hash(lwpid_t tid, pid_t pid, struct proc **pp, 
break;
}
if (run > RUN_THRESH) {
-   if (rw_try_upgrade(&tidhash_lock)) {
+   if (rw_try_upgrade(TIDHASHLOCK(tid))) {
LIST_REMOVE(td, td_hash);
LIST_INSERT_HEAD(TIDHASH(td->td_tid),
td, td_hash);
-   rw_wunlock(&tidhash_lock);
+   rw_wunlock(TIDHASHLOCK(tid));
locked = false;
break;
}
@@ -1376,7 +1385,7 @@ tdfind_hash(lwpid_t tid, pid_t pid, struct proc **pp, 
break;
}
if (locked)
-   rw_runlock(&tidhash_lock);
+   rw_runlock(TIDHASHLOCK(tid));
if (td == NULL)
return (false);
*pp = p;
@@ -1421,15 +1430,16 @@ tdfind(lwpid_t tid, pid_t pid)
 void
 tidhash_add(struct thread *td)
 {
-   rw_wlock(&tidhash_lock);
+   rw_wlock(TIDHASHLOCK(td->td_tid));
LIST_INSERT_HEAD(TIDHASH(td->td_tid), td, td_hash);
-   rw_wunlock(&tidhash_lock);
+   rw_wunlock(TIDHASHLOCK(td->td_tid));
 }
 
 void
 tidhash_remove(struct thread *td)
 {
-   rw_wlock(&tidhash_lock);
+
+   rw_wlock(TIDHASHLOCK(td->td_tid));
LIST_REMOVE(td, td_hash);
-   rw_wunlock(&tidhash_lock);
+   rw_wunlock(TIDHASHLOCK(td->td_tid));
 }
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r367586 - stable/12/usr.bin/usbhidaction

2020-11-11 Thread Mateusz Piotrowski
Author: 0mp (doc,ports committer)
Date: Wed Nov 11 11:25:14 2020
New Revision: 367586
URL: https://svnweb.freebsd.org/changeset/base/367586

Log:
  MFC r367097:
  
  Correct USB HID item in examples
  
  It turns out that examples were incorrectly referring to Volume_Up
  and Volume_Down, which are not defined at all.
  
  PR:   250683

Modified:
  stable/12/usr.bin/usbhidaction/usbhidaction.1
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/usr.bin/usbhidaction/usbhidaction.1
==
--- stable/12/usr.bin/usbhidaction/usbhidaction.1   Wed Nov 11 08:51:04 
2020(r367585)
+++ stable/12/usr.bin/usbhidaction/usbhidaction.1   Wed Nov 11 11:25:14 
2020(r367586)
@@ -28,7 +28,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd April 9, 2003
+.Dd October 28, 2020
 .Dt USBHIDACTION 1
 .Os
 .Sh NAME
@@ -139,8 +139,8 @@ The following configuration file can be used to contro
 of Philips USB speakers with the HID controls on the speakers.
 .Bd -literal -offset indent
 # Configuration for various Philips USB speakers
-Consumer:Volume_Up  1 0 mixer -f $1 vol +1
-Consumer:Volume_Down1 0 mixer -f $1 vol -1
+Consumer:Volume_Increment   1 0 mixer -f $1 vol +1
+Consumer:Volume_Decrement   1 0 mixer -f $1 vol -1
 # mute not supported
 #Consumer:Mute  1 0 mixer -f $1 mute
 Consumer:Channel_Top.Microsoft:Base_Up  1 0 mixer -f $1 bass +1
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r367587 - stable/11/usr.bin/usbhidaction

2020-11-11 Thread Mateusz Piotrowski
Author: 0mp (doc,ports committer)
Date: Wed Nov 11 11:26:36 2020
New Revision: 367587
URL: https://svnweb.freebsd.org/changeset/base/367587

Log:
  MFC r367097:
  
  Correct USB HID item in examples
  
  It turns out that examples were incorrectly referring to Volume_Up
  and Volume_Down, which are not defined at all.
  
  PR:   250683

Modified:
  stable/11/usr.bin/usbhidaction/usbhidaction.1
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/usr.bin/usbhidaction/usbhidaction.1
==
--- stable/11/usr.bin/usbhidaction/usbhidaction.1   Wed Nov 11 11:25:14 
2020(r367586)
+++ stable/11/usr.bin/usbhidaction/usbhidaction.1   Wed Nov 11 11:26:36 
2020(r367587)
@@ -28,7 +28,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd April 9, 2003
+.Dd October 28, 2020
 .Dt USBHIDACTION 1
 .Os
 .Sh NAME
@@ -139,8 +139,8 @@ The following configuration file can be used to contro
 of Philips USB speakers with the HID controls on the speakers.
 .Bd -literal -offset indent
 # Configuration for various Philips USB speakers
-Consumer:Volume_Up  1 0 mixer -f $1 vol +1
-Consumer:Volume_Down1 0 mixer -f $1 vol -1
+Consumer:Volume_Increment   1 0 mixer -f $1 vol +1
+Consumer:Volume_Decrement   1 0 mixer -f $1 vol -1
 # mute not supported
 #Consumer:Mute  1 0 mixer -f $1 mute
 Consumer:Channel_Top.Microsoft:Base_Up  1 0 mixer -f $1 bass +1
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r367588 - in head/sys: kern sys

2020-11-11 Thread Mark Johnston
Author: markj
Date: Wed Nov 11 13:44:27 2020
New Revision: 367588
URL: https://svnweb.freebsd.org/changeset/base/367588

Log:
  Fix a pair of races in SIGIO registration
  
  First, funsetownlst() list looks at the first element of the list to see
  whether it's processing a process or a process group list.  Then it
  acquires the global sigio lock and processes the list.  However, nothing
  prevents the first sigio tracker from being freed by a concurrent
  funsetown() before the sigio lock is acquired.
  
  Fix this by acquiring the global sigio lock immediately after checking
  whether the list is empty.  Callers of funsetownlst() ensure that new
  sigio trackers cannot be added concurrently.
  
  Second, fsetown() uses funsetown() to remove an existing sigio structure
  from a file object.  However, funsetown() uses a racy check to avoid the
  sigio lock, so two threads may call fsetown() on the same file object,
  both observe that no sigio tracker is present, and enqueue two sigio
  trackers for the same file object.  However, if the file object is
  destroyed, funsetown() will only remove one sigio tracker, and
  funsetownlst() may later trigger a use-after-free when it clears the
  file object reference for each entry in the list.
  
  Fix this by introducing funsetown_locked(), which avoids the racy check.
  
  Reviewed by:  kib
  Reported by:  pho
  Tested by:pho
  MFC after:1 week
  Sponsored by: The FreeBSD Foundation
  Differential Revision:https://reviews.freebsd.org/D27157

Modified:
  head/sys/kern/kern_descrip.c
  head/sys/kern/kern_exit.c
  head/sys/kern/kern_proc.c
  head/sys/sys/signalvar.h

Modified: head/sys/kern/kern_descrip.c
==
--- head/sys/kern/kern_descrip.cWed Nov 11 11:26:36 2020
(r367587)
+++ head/sys/kern/kern_descrip.cWed Nov 11 13:44:27 2020
(r367588)
@@ -1001,6 +1001,40 @@ unlock:
return (error);
 }
 
+static void
+sigiofree(struct sigio *sigio)
+{
+   crfree(sigio->sio_ucred);
+   free(sigio, M_SIGIO);
+}
+
+static struct sigio *
+funsetown_locked(struct sigio *sigio)
+{
+   struct proc *p;
+   struct pgrp *pg;
+
+   SIGIO_ASSERT_LOCKED();
+
+   if (sigio == NULL)
+   return (NULL);
+   *(sigio->sio_myref) = NULL;
+   if (sigio->sio_pgid < 0) {
+   pg = sigio->sio_pgrp;
+   PGRP_LOCK(pg);
+   SLIST_REMOVE(&sigio->sio_pgrp->pg_sigiolst, sigio,
+   sigio, sio_pgsigio);
+   PGRP_UNLOCK(pg);
+   } else {
+   p = sigio->sio_proc;
+   PROC_LOCK(p);
+   SLIST_REMOVE(&sigio->sio_proc->p_sigiolst, sigio,
+   sigio, sio_pgsigio);
+   PROC_UNLOCK(p);
+   }
+   return (sigio);
+}
+
 /*
  * If sigio is on the list associated with a process or process group,
  * disable signalling from the device, remove sigio from the list and
@@ -1011,92 +1045,82 @@ funsetown(struct sigio **sigiop)
 {
struct sigio *sigio;
 
+   /* Racy check, consumers must provide synchronization. */
if (*sigiop == NULL)
return;
+
SIGIO_LOCK();
-   sigio = *sigiop;
-   if (sigio == NULL) {
-   SIGIO_UNLOCK();
-   return;
-   }
-   *(sigio->sio_myref) = NULL;
-   if ((sigio)->sio_pgid < 0) {
-   struct pgrp *pg = (sigio)->sio_pgrp;
-   PGRP_LOCK(pg);
-   SLIST_REMOVE(&sigio->sio_pgrp->pg_sigiolst, sigio,
-   sigio, sio_pgsigio);
-   PGRP_UNLOCK(pg);
-   } else {
-   struct proc *p = (sigio)->sio_proc;
-   PROC_LOCK(p);
-   SLIST_REMOVE(&sigio->sio_proc->p_sigiolst, sigio,
-   sigio, sio_pgsigio);
-   PROC_UNLOCK(p);
-   }
+   sigio = funsetown_locked(*sigiop);
SIGIO_UNLOCK();
-   crfree(sigio->sio_ucred);
-   free(sigio, M_SIGIO);
+   if (sigio != NULL)
+   sigiofree(sigio);
 }
 
 /*
- * Free a list of sigio structures.
- * We only need to lock the SIGIO_LOCK because we have made ourselves
- * inaccessible to callers of fsetown and therefore do not need to lock
- * the proc or pgrp struct for the list manipulation.
+ * Free a list of sigio structures.  The caller must ensure that new sigio
+ * structures cannot be added after this point.  For process groups this is
+ * guaranteed using the proctree lock; for processes, the P_WEXIT flag serves
+ * as an interlock.
  */
 void
 funsetownlst(struct sigiolst *sigiolst)
 {
struct proc *p;
struct pgrp *pg;
-   struct sigio *sigio;
+   struct sigio *sigio, *tmp;
 
+   /* Racy check. */
sigio = SLIST_FIRST(sigiolst);
if (sigio == NULL)
return;
+
p = NULL;
pg = NULL;
 
+   SIGIO_LOCK();
+   sigio = SLIST_FIRST(sig

svn commit: r367589 - in head/sys: geom ufs/ffs

2020-11-11 Thread Mark Johnston
Author: markj
Date: Wed Nov 11 13:48:07 2020
New Revision: 367589
URL: https://svnweb.freebsd.org/changeset/base/367589

Log:
  ffs: Clamp BIO_SPEEDUP length
  
  On 32-bit platforms, the computed size of the BIO_SPEEDUP requested by
  softdep_request_cleanup() may be negative when assigned to bp->b_bcount,
  which has type "long".
  
  Clamp the size to LONG_MAX.  Also convert the unused g_io_speedup() to
  use an off_t for the magnitude of the shortage for consistency with
  softdep_send_speedup().
  
  Reviewed by:  chs, kib
  Reported by:  pho
  Tested by:pho
  Sponsored by: The FreeBSD Foundation
  Differential Revision:https://reviews.freebsd.org/D27081

Modified:
  head/sys/geom/geom.h
  head/sys/geom/geom_io.c
  head/sys/ufs/ffs/ffs_softdep.c

Modified: head/sys/geom/geom.h
==
--- head/sys/geom/geom.hWed Nov 11 13:44:27 2020(r367588)
+++ head/sys/geom/geom.hWed Nov 11 13:48:07 2020(r367589)
@@ -334,7 +334,8 @@ void g_io_deliver(struct bio *bp, int error);
 int g_io_getattr(const char *attr, struct g_consumer *cp, int *len, void *ptr);
 int g_io_zonecmd(struct disk_zone_args *zone_args, struct g_consumer *cp);
 int g_io_flush(struct g_consumer *cp);
-int g_io_speedup(size_t shortage, u_int flags, size_t *resid, struct 
g_consumer *cp);
+int g_io_speedup(off_t shortage, u_int flags, size_t *resid,
+struct g_consumer *cp);
 void g_io_request(struct bio *bp, struct g_consumer *cp);
 struct bio *g_new_bio(void);
 struct bio *g_alloc_bio(void);

Modified: head/sys/geom/geom_io.c
==
--- head/sys/geom/geom_io.c Wed Nov 11 13:44:27 2020(r367588)
+++ head/sys/geom/geom_io.c Wed Nov 11 13:48:07 2020(r367589)
@@ -341,15 +341,15 @@ g_io_zonecmd(struct disk_zone_args *zone_args, struct 
  * operation should be done.
  */
 int
-g_io_speedup(size_t shortage, u_int flags, size_t *resid, struct g_consumer 
*cp)
+g_io_speedup(off_t shortage, u_int flags, size_t *resid, struct g_consumer *cp)
 {
struct bio *bp;
int error;
 
KASSERT((flags & (BIO_SPEEDUP_TRIM | BIO_SPEEDUP_WRITE)) != 0,
("Invalid flags passed to g_io_speedup: %#x", flags));
-   g_trace(G_T_BIO, "bio_speedup(%s, %zu, %#x)", cp->provider->name,
-   shortage, flags);
+   g_trace(G_T_BIO, "bio_speedup(%s, %jd, %#x)", cp->provider->name,
+   (intmax_t)shortage, flags);
bp = g_new_bio();
if (bp == NULL)
return (ENOMEM);

Modified: head/sys/ufs/ffs/ffs_softdep.c
==
--- head/sys/ufs/ffs/ffs_softdep.c  Wed Nov 11 13:44:27 2020
(r367588)
+++ head/sys/ufs/ffs/ffs_softdep.c  Wed Nov 11 13:48:07 2020
(r367589)
@@ -1464,7 +1464,7 @@ worklist_speedup(mp)
 }
 
 static void
-softdep_send_speedup(struct ufsmount *ump, size_t shortage, u_int flags)
+softdep_send_speedup(struct ufsmount *ump, off_t shortage, u_int flags)
 {
struct buf *bp;
 
@@ -1474,7 +1474,7 @@ softdep_send_speedup(struct ufsmount *ump, size_t shor
bp = malloc(sizeof(*bp), M_TRIM, M_WAITOK | M_ZERO);
bp->b_iocmd = BIO_SPEEDUP;
bp->b_ioflags = flags;
-   bp->b_bcount = shortage;
+   bp->b_bcount = omin(shortage, LONG_MAX);
g_vfs_strategy(ump->um_bo, bp);
bufwait(bp);
free(bp, M_TRIM);
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


Re: svn commit: r367588 - in head/sys: kern sys

2020-11-11 Thread Hans Petter Selasky

On 11/11/20 2:44 PM, Mark Johnston wrote:

+#defineSIGIO_ASSERT_LOCKED(type) mtx_assert(&sigio_lock, MA_OWNED)
  


Minor nit: "type" argument can be removed from macro.

--HPS
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r367590 - head/sys/sys

2020-11-11 Thread Mark Johnston
Author: markj
Date: Wed Nov 11 14:03:49 2020
New Revision: 367590
URL: https://svnweb.freebsd.org/changeset/base/367590

Log:
  Remove an extraneous parameter from SIGIO_ASSERT_LOCKED()
  
  Reported by:  hselasky
  MFC with: r367588

Modified:
  head/sys/sys/signalvar.h

Modified: head/sys/sys/signalvar.h
==
--- head/sys/sys/signalvar.hWed Nov 11 13:48:07 2020(r367589)
+++ head/sys/sys/signalvar.hWed Nov 11 14:03:49 2020(r367590)
@@ -337,7 +337,7 @@ struct thread;
 #defineSIGIO_TRYLOCK() mtx_trylock(&sigio_lock)
 #defineSIGIO_UNLOCK()  mtx_unlock(&sigio_lock)
 #defineSIGIO_LOCKED()  mtx_owned(&sigio_lock)
-#defineSIGIO_ASSERT_LOCKED(type) mtx_assert(&sigio_lock, MA_OWNED)
+#defineSIGIO_ASSERT_LOCKED() mtx_assert(&sigio_lock, MA_OWNED)
 
 extern struct mtx  sigio_lock;
 
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


Re: svn commit: r367588 - in head/sys: kern sys

2020-11-11 Thread Mark Johnston
On Wed, Nov 11, 2020 at 02:58:32PM +0100, Hans Petter Selasky wrote:
> On 11/11/20 2:44 PM, Mark Johnston wrote:
> > +#defineSIGIO_ASSERT_LOCKED(type) mtx_assert(&sigio_lock, MA_OWNED)
> >   
> 
> Minor nit: "type" argument can be removed from macro.

Fixed, thanks.
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r367591 - in stable/12/sys/amd64: amd64 include

2020-11-11 Thread Mark Johnston
Author: markj
Date: Wed Nov 11 14:06:45 2020
New Revision: 367591
URL: https://svnweb.freebsd.org/changeset/base/367591

Log:
  MFC r367335:
  amd64: Make it easier to configure exception stack sizes

Modified:
  stable/12/sys/amd64/amd64/machdep.c
  stable/12/sys/amd64/amd64/mp_machdep.c
  stable/12/sys/amd64/amd64/pmap.c
  stable/12/sys/amd64/include/intr_machdep.h
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/amd64/amd64/machdep.c
==
--- stable/12/sys/amd64/amd64/machdep.c Wed Nov 11 14:03:49 2020
(r367590)
+++ stable/12/sys/amd64/amd64/machdep.c Wed Nov 11 14:06:45 2020
(r367591)
@@ -679,10 +679,10 @@ struct user_segment_descriptor gdt[NGDT * MAXCPU];/* g
 static struct gate_descriptor idt0[NIDT];
 struct gate_descriptor *idt = &idt0[0];/* interrupt descriptor table */
 
-static char dblfault_stack[PAGE_SIZE] __aligned(16);
-static char mce0_stack[PAGE_SIZE] __aligned(16);
-static char nmi0_stack[PAGE_SIZE] __aligned(16);
-static char dbg0_stack[PAGE_SIZE] __aligned(16);
+static char dblfault_stack[DBLFAULT_STACK_SIZE] __aligned(16);
+static char mce0_stack[MCE_STACK_SIZE] __aligned(16);
+static char nmi0_stack[NMI_STACK_SIZE] __aligned(16);
+static char dbg0_stack[DBG_STACK_SIZE] __aligned(16);
 CTASSERT(sizeof(struct nmi_pcpu) == 16);
 
 struct amd64tss common_tss[MAXCPU];

Modified: stable/12/sys/amd64/amd64/mp_machdep.c
==
--- stable/12/sys/amd64/amd64/mp_machdep.c  Wed Nov 11 14:03:49 2020
(r367590)
+++ stable/12/sys/amd64/amd64/mp_machdep.c  Wed Nov 11 14:06:45 2020
(r367591)
@@ -300,18 +300,19 @@ init_secondary(void)
common_tss[cpu] = common_tss[0];
common_tss[cpu].tss_iobase = sizeof(struct amd64tss) +
IOPERM_BITMAP_SIZE;
-   common_tss[cpu].tss_ist1 = (long)&doublefault_stack[PAGE_SIZE];
+   common_tss[cpu].tss_ist1 =
+   (long)&doublefault_stack[DBLFAULT_STACK_SIZE];
 
/* The NMI stack runs on IST2. */
-   np = ((struct nmi_pcpu *) &nmi_stack[PAGE_SIZE]) - 1;
+   np = ((struct nmi_pcpu *)&nmi_stack[NMI_STACK_SIZE]) - 1;
common_tss[cpu].tss_ist2 = (long) np;
 
/* The MC# stack runs on IST3. */
-   np = ((struct nmi_pcpu *) &mce_stack[PAGE_SIZE]) - 1;
+   np = ((struct nmi_pcpu *)&mce_stack[MCE_STACK_SIZE]) - 1;
common_tss[cpu].tss_ist3 = (long) np;
 
/* The DB# stack runs on IST4. */
-   np = ((struct nmi_pcpu *) &dbg_stack[PAGE_SIZE]) - 1;
+   np = ((struct nmi_pcpu *)&dbg_stack[DBG_STACK_SIZE]) - 1;
common_tss[cpu].tss_ist4 = (long) np;
 
/* Prepare private GDT */
@@ -353,15 +354,15 @@ init_secondary(void)
common_tss[cpu].tss_rsp0 = 0;
 
/* Save the per-cpu pointer for use by the NMI handler. */
-   np = ((struct nmi_pcpu *) &nmi_stack[PAGE_SIZE]) - 1;
+   np = ((struct nmi_pcpu *)&nmi_stack[NMI_STACK_SIZE]) - 1;
np->np_pcpu = (register_t) pc;
 
/* Save the per-cpu pointer for use by the MC# handler. */
-   np = ((struct nmi_pcpu *) &mce_stack[PAGE_SIZE]) - 1;
+   np = ((struct nmi_pcpu *)&mce_stack[MCE_STACK_SIZE]) - 1;
np->np_pcpu = (register_t) pc;
 
/* Save the per-cpu pointer for use by the DB# handler. */
-   np = ((struct nmi_pcpu *) &dbg_stack[PAGE_SIZE]) - 1;
+   np = ((struct nmi_pcpu *)&dbg_stack[DBG_STACK_SIZE]) - 1;
np->np_pcpu = (register_t) pc;
 
wrmsr(MSR_FSBASE, 0);   /* User value */
@@ -488,13 +489,14 @@ native_start_all_aps(void)
/* allocate and set up an idle stack data page */
bootstacks[cpu] = (void *)kmem_malloc(kstack_pages * PAGE_SIZE,
M_WAITOK | M_ZERO);
-   doublefault_stack = (char *)kmem_malloc(PAGE_SIZE, M_WAITOK |
-   M_ZERO);
-   mce_stack = (char *)kmem_malloc(PAGE_SIZE, M_WAITOK | M_ZERO);
+   doublefault_stack = (char *)kmem_malloc(DBLFAULT_STACK_SIZE,
+   M_WAITOK | M_ZERO);
+   mce_stack = (char *)kmem_malloc(MCE_STACK_SIZE,
+   M_WAITOK | M_ZERO);
nmi_stack = (char *)kmem_malloc_domainset(
-   DOMAINSET_PREF(domain), PAGE_SIZE, M_WAITOK | M_ZERO);
+   DOMAINSET_PREF(domain), NMI_STACK_SIZE, M_WAITOK | M_ZERO);
dbg_stack = (char *)kmem_malloc_domainset(
-   DOMAINSET_PREF(domain), PAGE_SIZE, M_WAITOK | M_ZERO);
+   DOMAINSET_PREF(domain), DBG_STACK_SIZE, M_WAITOK | M_ZERO);
dpcpu = (void *)kmem_malloc_domainset(DOMAINSET_PREF(domain),
DPCPU_SIZE, M_WAITOK | M_ZERO);
 

Modified: stable/12/sys/amd64/amd64/pmap.c
==
--- stable/12/sys/amd64/amd64/pmap.cWed Nov 

svn commit: r367592 - head/usr.bin/env

2020-11-11 Thread Mateusz Piotrowski
Author: 0mp (doc,ports committer)
Date: Wed Nov 11 14:53:03 2020
New Revision: 367592
URL: https://svnweb.freebsd.org/changeset/base/367592

Log:
  Document in the synopsis that -0 cannot be used with the utility argument

Modified:
  head/usr.bin/env/env.1

Modified: head/usr.bin/env/env.1
==
--- head/usr.bin/env/env.1  Wed Nov 11 14:06:45 2020(r367591)
+++ head/usr.bin/env/env.1  Wed Nov 11 14:53:03 2020(r367592)
@@ -31,7 +31,7 @@
 .\" From FreeBSD: src/usr.bin/printenv/printenv.1,v 1.17 2002/11/26 17:33:35 
ru Exp
 .\" $FreeBSD$
 .\"
-.Dd April 24, 2020
+.Dd November 11, 2020
 .Dt ENV 1
 .Os
 .Sh NAME
@@ -41,11 +41,16 @@
 .Nm
 .Op Fl 0iv
 .Op Fl L Ns | Ns Fl U Ar user Ns Op / Ns Ar class
+.Op Fl u Ar name
+.Op Ar name Ns = Ns Ar value ...
+.Nm
+.Op Fl iv
+.Op Fl L Ns | Ns Fl U Ar user Ns Op / Ns Ar class
 .Op Fl P Ar altpath
 .Op Fl S Ar string
 .Op Fl u Ar name
 .Op Ar name Ns = Ns Ar value ...
-.Op Ar utility Op Ar argument ...
+.Ar utility Op Ar argument ...
 .Sh DESCRIPTION
 The
 .Nm
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r367593 - in head/sys/amd64: amd64 include vmm/amd vmm/intel

2020-11-11 Thread Mark Johnston
Author: markj
Date: Wed Nov 11 15:01:17 2020
New Revision: 367593
URL: https://svnweb.freebsd.org/changeset/base/367593

Log:
  vmm: Make pmap_invalidate_ept() wait synchronously for guest exits
  
  Currently EPT TLB invalidation is done by incrementing a generation
  counter and issuing an IPI to all CPUs currently running vCPU threads.
  The VMM inner loop caches the most recently observed generation on each
  host CPU and invalidates TLB entries before executing the VM if the
  cached generation number is not the most recent value.
  pmap_invalidate_ept() issues IPIs to force each vCPU to stop executing
  guest instructions and reload the generation number.  However, it does
  not actually wait for vCPUs to exit, potentially creating a window where
  guests may continue to reference stale TLB entries.
  
  Fix the problem by bracketing guest execution with an SMR read section
  which is entered before loading the invalidation generation.  Then,
  pmap_invalidate_ept() increments the current write sequence before
  loading pm_active and sending IPIs, and polls readers to ensure that all
  vCPUs potentially operating with stale TLB entries have exited before
  pmap_invalidate_ept() returns.
  
  Also ensure that unsynchronized loads of the generation counter are
  wrapped with atomic(9), and stop (inconsistently) updating the
  invalidation counter and pm_active bitmask with acquire semantics.
  
  Reviewed by:  grehan, kib
  Sponsored by: The FreeBSD Foundation
  Differential Revision:https://reviews.freebsd.org/D26910

Modified:
  head/sys/amd64/amd64/pmap.c
  head/sys/amd64/include/pmap.h
  head/sys/amd64/vmm/amd/svm.c
  head/sys/amd64/vmm/intel/vmx.c

Modified: head/sys/amd64/amd64/pmap.c
==
--- head/sys/amd64/amd64/pmap.c Wed Nov 11 14:53:03 2020(r367592)
+++ head/sys/amd64/amd64/pmap.c Wed Nov 11 15:01:17 2020(r367593)
@@ -125,6 +125,7 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -2647,7 +2648,7 @@ pmap_update_pde_store(pmap_t pmap, pd_entry_t *pde, pd
 * "all" host cpus and force any vcpu context to exit as a
 * side-effect.
 */
-   atomic_add_acq_long(&pmap->pm_eptgen, 1);
+   atomic_add_long(&pmap->pm_eptgen, 1);
break;
default:
panic("pmap_update_pde_store: bad pm_type %d", pmap->pm_type);
@@ -2722,6 +2723,7 @@ pmap_update_pde_invalidate(pmap_t pmap, vm_offset_t va
 static __inline void
 pmap_invalidate_ept(pmap_t pmap)
 {
+   smr_seq_t goal;
int ipinum;
 
sched_pin();
@@ -2742,15 +2744,30 @@ pmap_invalidate_ept(pmap_t pmap)
 * Each vcpu keeps a cache of this counter and compares it
 * just before a vmresume. If the counter is out-of-date an
 * invept will be done to flush stale mappings from the TLB.
+*
+* To ensure that all vCPU threads have observed the new counter
+* value before returning, we use SMR.  Ordering is important here:
+* the VMM enters an SMR read section before loading the counter
+* and after updating the pm_active bit set.  Thus, pm_active is
+* a superset of active readers, and any reader that has observed
+* the goal has observed the new counter value.
 */
-   atomic_add_acq_long(&pmap->pm_eptgen, 1);
+   atomic_add_long(&pmap->pm_eptgen, 1);
 
+   goal = smr_advance(pmap->pm_eptsmr);
+
/*
 * Force the vcpu to exit and trap back into the hypervisor.
 */
ipinum = pmap->pm_flags & PMAP_NESTED_IPIMASK;
ipi_selected(pmap->pm_active, ipinum);
sched_unpin();
+
+   /*
+* Ensure that all active vCPUs will observe the new generation counter
+* value before executing any more guest instructions.
+*/
+   smr_wait(pmap->pm_eptsmr, goal);
 }
 
 static cpuset_t
@@ -4086,7 +4103,8 @@ pmap_pinit_type(pmap_t pmap, enum pmap_type pm_type, i
 * address space.
 * Install minimal kernel mappings in PTI case.
 */
-   if (pm_type == PT_X86) {
+   switch (pm_type) {
+   case PT_X86:
pmap->pm_cr3 = pmltop_phys;
if (pmap_is_la57(pmap))
pmap_pinit_pml5(pmltop_pg);
@@ -4107,6 +4125,11 @@ pmap_pinit_type(pmap_t pmap, enum pmap_type pm_type, i
rangeset_init(&pmap->pm_pkru, pkru_dup_range,
pkru_free_range, pmap, M_NOWAIT);
}
+   break;
+   case PT_EPT:
+   case PT_RVI:
+   pmap->pm_eptsmr = smr_create("pmap", 0, 0);
+   break;
}
 
pmap->pm_root.rt_root = 0;

Modified: head/sys/amd64/include/pmap.h
==
--- head/sys/amd64/include/pmap.h   Wed Nov 1

svn commit: r367594 - head/sys/net

2020-11-11 Thread Andrey V. Elsukov
Author: ae
Date: Wed Nov 11 15:53:36 2020
New Revision: 367594
URL: https://svnweb.freebsd.org/changeset/base/367594

Log:
  Fix possible NULL pointer dereference.
  
  lagg(4) replaces if_output method of its child interfaces and expects
  that this method can be called only by child interfaces. But it is
  possible that lagg_port_output() could be called by children of child
  interfaces. In this case ifnet's if_lagg field is NULL. Add check that
  lp is not NULL.
  
  Obtained from:Yandex LLC
  MFC after:1 week
  Sponsored by: Yandex LLC

Modified:
  head/sys/net/if_lagg.c

Modified: head/sys/net/if_lagg.c
==
--- head/sys/net/if_lagg.c  Wed Nov 11 15:01:17 2020(r367593)
+++ head/sys/net/if_lagg.c  Wed Nov 11 15:53:36 2020(r367594)
@@ -1145,7 +1145,8 @@ lagg_port_output(struct ifnet *ifp, struct mbuf *m,
switch (dst->sa_family) {
case pseudo_AF_HDRCMPLT:
case AF_UNSPEC:
-   return ((*lp->lp_output)(ifp, m, dst, ro));
+   if (lp != NULL)
+   return ((*lp->lp_output)(ifp, m, dst, ro));
}
 
/* drop any other frames */
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r367595 - head/sys/vm

2020-11-11 Thread Mark Johnston
Author: markj
Date: Wed Nov 11 17:16:39 2020
New Revision: 367595
URL: https://svnweb.freebsd.org/changeset/base/367595

Log:
  vm_map: Handle kernel map entry allocator recursion
  
  On platforms without a direct map[*], vm_map_insert() may in rare
  situations need to allocate a kernel map entry in order to allocate
  kernel map entries.  This poses a problem similar to the one solved for
  vmem boundary tags by vmem_bt_alloc().  In fact the kernel map case is a
  bit more complicated since we must allocate entries with the kernel map
  locked, whereas vmem can recurse into itself because boundary tags are
  allocated up-front.
  
  The solution is to add a custom slab allocator for kmapentzone which
  allocates KVA directly from kernel_map, bypassing the kmem_* layer.
  This avoids mutual recursion with the vmem btag allocator.  Then, when
  vm_map_insert() allocates a new kernel map entry, it avoids triggering
  allocation of a new slab with M_NOVM until after the insertion is
  complete.  Instead, vm_map_insert() allocates from the reserve and sets
  a flag in kernel_map to trigger re-population of the reserve just before
  the map is unlocked.  This places an implicit upper bound on the number
  of kernel map entries that may be allocated before the kernel map lock
  is released, but in general a bound of 1 suffices.
  
  [*] This also comes up on amd64 with UMA_MD_SMALL_ALLOC undefined, a
  configuration required by some kernel sanitizers.
  
  Discussed with:   kib, rlibby
  Reported by:  andrew
  Tested by:pho (i386 and amd64 with !UMA_MD_SMALL_ALLOC)
  Sponsored by: The FreeBSD Foundation
  Differential Revision:https://reviews.freebsd.org/D26851

Modified:
  head/sys/vm/vm_map.c
  head/sys/vm/vm_map.h

Modified: head/sys/vm/vm_map.c
==
--- head/sys/vm/vm_map.cWed Nov 11 15:53:36 2020(r367594)
+++ head/sys/vm/vm_map.cWed Nov 11 17:16:39 2020(r367595)
@@ -175,29 +175,106 @@ static void vm_map_wire_entry_failure(vm_map_t map, vm
start = end;\
}
 
+#ifndef UMA_MD_SMALL_ALLOC
+
 /*
+ * Allocate a new slab for kernel map entries.  The kernel map may be locked or
+ * unlocked, depending on whether the request is coming from the kernel map or 
a
+ * submap.  This function allocates a virtual address range directly from the
+ * kernel map instead of the kmem_* layer to avoid recursion on the kernel map
+ * lock and also to avoid triggering allocator recursion in the vmem boundary
+ * tag allocator.
+ */
+static void *
+kmapent_alloc(uma_zone_t zone, vm_size_t bytes, int domain, uint8_t *pflag,
+int wait)
+{
+   vm_offset_t addr;
+   int error, locked;
+
+   *pflag = UMA_SLAB_PRIV;
+
+   if (!(locked = vm_map_locked(kernel_map)))
+   vm_map_lock(kernel_map);
+   addr = vm_map_findspace(kernel_map, vm_map_min(kernel_map), bytes);
+   if (addr + bytes < addr || addr + bytes > vm_map_max(kernel_map))
+   panic("%s: kernel map is exhausted", __func__);
+   error = vm_map_insert(kernel_map, NULL, 0, addr, addr + bytes,
+   VM_PROT_RW, VM_PROT_RW, MAP_NOFAULT);
+   if (error != KERN_SUCCESS)
+   panic("%s: vm_map_insert() failed: %d", __func__, error);
+   if (!locked)
+   vm_map_unlock(kernel_map);
+   error = kmem_back_domain(domain, kernel_object, addr, bytes, M_NOWAIT |
+   M_USE_RESERVE | (wait & M_ZERO));
+   if (error == KERN_SUCCESS) {
+   return ((void *)addr);
+   } else {
+   if (!locked)
+   vm_map_lock(kernel_map);
+   vm_map_delete(kernel_map, addr, bytes);
+   if (!locked)
+   vm_map_unlock(kernel_map);
+   return (NULL);
+   }
+}
+
+static void
+kmapent_free(void *item, vm_size_t size, uint8_t pflag)
+{
+   vm_offset_t addr;
+   int error;
+
+   if ((pflag & UMA_SLAB_PRIV) == 0)
+   /* XXX leaked */
+   return;
+
+   addr = (vm_offset_t)item;
+   kmem_unback(kernel_object, addr, size);
+   error = vm_map_remove(kernel_map, addr, addr + size);
+   KASSERT(error == KERN_SUCCESS,
+   ("%s: vm_map_remove failed: %d", __func__, error));
+}
+
+/*
+ * The worst-case upper bound on the number of kernel map entries that may be
+ * created before the zone must be replenished in _vm_map_unlock().
+ */
+#defineKMAPENT_RESERVE 1
+
+#endif /* !UMD_MD_SMALL_ALLOC */
+
+/*
  * vm_map_startup:
  *
- * Initialize the vm_map module.  Must be called before
- * any other vm_map routines.
+ * Initialize the vm_map module.  Must be called before any other vm_map
+ * routines.
  *
- * Map and entry structures are allocated from the general
- * purpose memory pool with some exceptions:
- *
- * - The kernel map and km

svn commit: r367596 - head/sys/net

2020-11-11 Thread Mark Johnston
Author: markj
Date: Wed Nov 11 18:00:06 2020
New Revision: 367596
URL: https://svnweb.freebsd.org/changeset/base/367596

Log:
  iflib: Free full mbuf chains when draining transmit queues
  
  Submitted by: Sai Rajesh Tallamraju 
  Reviewed by:  gallatin, hselasky
  MFC after:1 week
  Sponsored by: NetApp, Inc.
  Differential Revision:https://reviews.freebsd.org/D27179

Modified:
  head/sys/net/iflib.c

Modified: head/sys/net/iflib.c
==
--- head/sys/net/iflib.cWed Nov 11 17:16:39 2020(r367595)
+++ head/sys/net/iflib.cWed Nov 11 18:00:06 2020(r367596)
@@ -1781,7 +1781,7 @@ iflib_txsd_free(if_ctx_t ctx, iflib_txq_t txq, int i)
bus_dmamap_unload(txq->ift_tso_buf_tag,
txq->ift_sds.ifsd_tso_map[i]);
}
-   m_free(*mp);
+   m_freem(*mp);
DBG_COUNTER_INC(tx_frees);
*mp = NULL;
 }
@@ -3660,7 +3660,7 @@ iflib_txq_drain(struct ifmp_ring *r, uint32_t cidx, ui
DBG_COUNTER_INC(txq_drain_flushing);
for (i = 0; i < avail; i++) {
if (__predict_true(r->items[(cidx + i) & (r->size-1)] 
!= (void *)txq))
-   m_free(r->items[(cidx + i) & (r->size-1)]);
+   m_freem(r->items[(cidx + i) & (r->size-1)]);
r->items[(cidx + i) & (r->size-1)] = NULL;
}
return (avail);
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r367597 - in head/sys: kern sys

2020-11-11 Thread Mateusz Guzik
Author: mjg
Date: Wed Nov 11 18:43:51 2020
New Revision: 367597
URL: https://svnweb.freebsd.org/changeset/base/367597

Log:
  thread: lockless zombie list manipulation
  
  This gets rid of the most contended spinlock seen when creating/destroying
  threads in a loop. (modulo kstack)
  
  Tested by:alfredo (ppc64), bdragon (ppc64)

Modified:
  head/sys/kern/kern_thread.c
  head/sys/sys/proc.h

Modified: head/sys/kern/kern_thread.c
==
--- head/sys/kern/kern_thread.c Wed Nov 11 18:00:06 2020(r367596)
+++ head/sys/kern/kern_thread.c Wed Nov 11 18:43:51 2020(r367597)
@@ -128,9 +128,7 @@ SDT_PROBE_DEFINE(proc, , , lwp__exit);
  */
 static uma_zone_t thread_zone;
 
-TAILQ_HEAD(, thread) zombie_threads = TAILQ_HEAD_INITIALIZER(zombie_threads);
-static struct mtx zombie_lock;
-MTX_SYSINIT(zombie_lock, &zombie_lock, "zombie lock", MTX_SPIN);
+static __exclusive_cache_line struct thread *thread_zombies;
 
 static void thread_zombie(struct thread *);
 static int thread_unsuspend_one(struct thread *td, struct proc *p,
@@ -409,14 +407,20 @@ threadinit(void)
 
 /*
  * Place an unused thread on the zombie list.
- * Use the slpq as that must be unused by now.
  */
 void
 thread_zombie(struct thread *td)
 {
-   mtx_lock_spin(&zombie_lock);
-   TAILQ_INSERT_HEAD(&zombie_threads, td, td_slpq);
-   mtx_unlock_spin(&zombie_lock);
+   struct thread *ztd;
+
+   ztd = atomic_load_ptr(&thread_zombies);
+   for (;;) {
+   td->td_zombie = ztd;
+   if (atomic_fcmpset_rel_ptr((uintptr_t *)&thread_zombies,
+   (uintptr_t *)&ztd, (uintptr_t)td))
+   break;
+   continue;
+   }
 }
 
 /*
@@ -430,29 +434,27 @@ thread_stash(struct thread *td)
 }
 
 /*
- * Reap zombie resources.
+ * Reap zombie threads.
  */
 void
 thread_reap(void)
 {
-   struct thread *td_first, *td_next;
+   struct thread *itd, *ntd;
 
/*
-* Don't even bother to lock if none at this instant,
-* we really don't care about the next instant.
+* Reading upfront is pessimal if followed by concurrent atomic_swap,
+* but most of the time the list is empty.
 */
-   if (!TAILQ_EMPTY(&zombie_threads)) {
-   mtx_lock_spin(&zombie_lock);
-   td_first = TAILQ_FIRST(&zombie_threads);
-   if (td_first)
-   TAILQ_INIT(&zombie_threads);
-   mtx_unlock_spin(&zombie_lock);
-   while (td_first) {
-   td_next = TAILQ_NEXT(td_first, td_slpq);
-   thread_cow_free(td_first);
-   thread_free(td_first);
-   td_first = td_next;
-   }
+   if (thread_zombies == NULL)
+   return;
+
+   itd = (struct thread *)atomic_swap_ptr((uintptr_t *)&thread_zombies,
+   (uintptr_t)NULL);
+   while (itd != NULL) {
+   ntd = itd->td_zombie;
+   thread_cow_free(itd);
+   thread_free(itd);
+   itd = ntd;
}
 }
 

Modified: head/sys/sys/proc.h
==
--- head/sys/sys/proc.h Wed Nov 11 18:00:06 2020(r367596)
+++ head/sys/sys/proc.h Wed Nov 11 18:43:51 2020(r367597)
@@ -229,7 +229,10 @@ struct thread {
struct proc *td_proc;   /* (*) Associated process. */
TAILQ_ENTRY(thread) td_plist;   /* (*) All threads in this proc. */
TAILQ_ENTRY(thread) td_runq;/* (t) Run queue. */
-   TAILQ_ENTRY(thread) td_slpq;/* (t) Sleep queue. */
+   union   {
+   TAILQ_ENTRY(thread) td_slpq;/* (t) Sleep queue. */
+   struct thread *td_zombie; /* Zombie list linkage */
+   };
TAILQ_ENTRY(thread) td_lockq;   /* (t) Lock queue. */
LIST_ENTRY(thread) td_hash; /* (d) Hash chain. */
struct cpuset   *td_cpuset; /* (t) CPU affinity mask. */
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r367598 - head/sys/kern

2020-11-11 Thread Mateusz Guzik
Author: mjg
Date: Wed Nov 11 18:45:06 2020
New Revision: 367598
URL: https://svnweb.freebsd.org/changeset/base/367598

Log:
  thread: batch tid_free calls in thread_reap
  
  This eliminates the highly pessimal pattern of relocking from multiple
  CPUs in quick succession. Note this is still globally serialized.

Modified:
  head/sys/kern/kern_thread.c

Modified: head/sys/kern/kern_thread.c
==
--- head/sys/kern/kern_thread.c Wed Nov 11 18:43:51 2020(r367597)
+++ head/sys/kern/kern_thread.c Wed Nov 11 18:45:06 2020(r367598)
@@ -133,6 +133,7 @@ static __exclusive_cache_line struct thread *thread_zo
 static void thread_zombie(struct thread *);
 static int thread_unsuspend_one(struct thread *td, struct proc *p,
 bool boundary);
+static void thread_free_batched(struct thread *td);
 
 static struct mtx tid_lock;
 static bitstr_t *tid_bitmap;
@@ -200,21 +201,41 @@ tid_alloc(void)
 }
 
 static void
-tid_free(lwpid_t rtid)
+tid_free_locked(lwpid_t rtid)
 {
lwpid_t tid;
 
+   mtx_assert(&tid_lock, MA_OWNED);
KASSERT(rtid >= NO_PID,
("%s: invalid tid %d\n", __func__, rtid));
tid = rtid - NO_PID;
-   mtx_lock(&tid_lock);
KASSERT(bit_test(tid_bitmap, tid) != 0,
("thread ID %d not allocated\n", rtid));
bit_clear(tid_bitmap, tid);
nthreads--;
+}
+
+static void
+tid_free(lwpid_t rtid)
+{
+
+   mtx_lock(&tid_lock);
+   tid_free_locked(rtid);
mtx_unlock(&tid_lock);
 }
 
+static void
+tid_free_batch(lwpid_t *batch, int n)
+{
+   int i;
+
+   mtx_lock(&tid_lock);
+   for (i = 0; i < n; i++) {
+   tid_free_locked(batch[i]);
+   }
+   mtx_unlock(&tid_lock);
+}
+
 /*
  * Prepare a thread for use.
  */
@@ -440,6 +461,8 @@ void
 thread_reap(void)
 {
struct thread *itd, *ntd;
+   lwpid_t tidbatch[16];
+   int tidbatchn;
 
/*
 * Reading upfront is pessimal if followed by concurrent atomic_swap,
@@ -450,12 +473,23 @@ thread_reap(void)
 
itd = (struct thread *)atomic_swap_ptr((uintptr_t *)&thread_zombies,
(uintptr_t)NULL);
+   tidbatchn = 0;
while (itd != NULL) {
ntd = itd->td_zombie;
+   tidbatch[tidbatchn] = itd->td_tid;
+   tidbatchn++;
thread_cow_free(itd);
-   thread_free(itd);
+   thread_free_batched(itd);
+   if (tidbatchn == nitems(tidbatch)) {
+   tid_free_batch(tidbatch, tidbatchn);
+   tidbatchn = 0;
+   }
itd = ntd;
}
+
+   if (tidbatchn != 0) {
+   tid_free_batch(tidbatch, tidbatchn);
+   }
 }
 
 /*
@@ -502,8 +536,8 @@ thread_alloc_stack(struct thread *td, int pages)
 /*
  * Deallocate a thread.
  */
-void
-thread_free(struct thread *td)
+static void
+thread_free_batched(struct thread *td)
 {
 
EVENTHANDLER_DIRECT_INVOKE(thread_dtor, td);
@@ -515,9 +549,21 @@ thread_free(struct thread *td)
if (td->td_kstack != 0)
vm_thread_dispose(td);
callout_drain(&td->td_slpcallout);
-   tid_free(td->td_tid);
+   /*
+* Freeing handled by the caller.
+*/
td->td_tid = -1;
uma_zfree(thread_zone, td);
+}
+
+void
+thread_free(struct thread *td)
+{
+   lwpid_t tid;
+
+   tid = td->td_tid;
+   thread_free_batched(td);
+   tid_free(tid);
 }
 
 void
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r367599 - stable/12/sys/net

2020-11-11 Thread Vincenzo Maffione
Author: vmaffione
Date: Wed Nov 11 21:27:16 2020
New Revision: 367599
URL: https://svnweb.freebsd.org/changeset/base/367599

Log:
  MFC r367093, r367117
  
  iflib: add per-tx-queue netmap timer
  
  The way netmap TX is handled in iflib when TX interrupts are not
  used (IFC_NETMAP_TX_IRQ not set) has some issues:
- The netmap_tx_irq() function gets called by iflib_timer(), which
  gets scheduled with tick granularity (hz). This is not frequent
  enough for 10Gbps NICs and beyond (e.g., ixgbe or ixl). The end
  result is that the transmitting netmap application is not woken
  up fast enough to saturate the link with small packets.
- The iflib_timer() functions also calls isc_txd_credits_update()
  to ask for more TX completion updates. However, this violates
  the netmap requirement that only txsync can access the TX queue
  for datapath operations. Only netmap_tx_irq() may be called out
  of the txsync context.
  
  This change introduces per-tx-queue netmap timers, using microsecond
  granularity to ensure that netmap_tx_irq() can be called often enough
  to allow for maximum packet rate. The timer routine simply calls
  netmap_tx_irq() to wake up the netmap application. The latter will
  wake up and call txsync to collect TX completion updates.
  
  This change brings back line rate speed with small packets for ixgbe.
  For the time being, timer expiration is hardcoded to 90 microseconds,
  in order to avoid introducing a new sysctl.
  We may eventually implement an adaptive expiration period or use another
  deferred work mechanism in place of timers.
  
  Also, fix the timers usage to make sure that each queue is serviced
  by a different CPU.
  
  PR: 248652
  Reported by:s...@efficientip.com

Modified:
  stable/12/sys/net/iflib.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/net/iflib.c
==
--- stable/12/sys/net/iflib.c   Wed Nov 11 18:45:06 2020(r367598)
+++ stable/12/sys/net/iflib.c   Wed Nov 11 21:27:16 2020(r367599)
@@ -348,6 +348,9 @@ struct iflib_txq {
qidx_t  ift_size;
uint16_tift_id;
struct callout  ift_timer;
+#ifdef DEV_NETMAP
+   struct callout  ift_netmap_timer;
+#endif /* DEV_NETMAP */
 
if_txsd_vec_t   ift_sds;
uint8_t ift_qstatus;
@@ -763,6 +766,7 @@ iflib_num_tx_descs(if_ctx_t ctx)
 MODULE_DEPEND(iflib, netmap, 1, 1, 1);
 
 static int netmap_fl_refill(iflib_rxq_t rxq, struct netmap_kring *kring, bool 
init);
+static void iflib_netmap_timer(void *arg);
 
 /*
  * device-specific sysctl variables:
@@ -928,6 +932,8 @@ netmap_fl_refill(iflib_rxq_t rxq, struct netmap_kring 
return (0);
 }
 
+#define NETMAP_TX_TIMER_US 90
+
 /*
  * Reconcile kernel and user view of the transmit ring.
  *
@@ -1057,9 +1063,8 @@ iflib_netmap_txsync(struct netmap_kring *kring, int fl
 * Second part: reclaim buffers for completed transmissions.
 *
 * If there are unclaimed buffers, attempt to reclaim them.
-* If none are reclaimed, and TX IRQs are not in use, do an initial
-* minimal delay, then trigger the tx handler which will spin in the
-* group task queue.
+* If we don't manage to reclaim them all, and TX IRQs are not in use,
+* trigger a per-tx-queue timer to try again later.
 */
if (kring->nr_hwtail != nm_prev(kring->nr_hwcur, lim)) {
if (iflib_tx_credits_update(ctx, txq)) {
@@ -1068,11 +1073,14 @@ iflib_netmap_txsync(struct netmap_kring *kring, int fl
kring->nr_hwtail = nm_prev(netmap_idx_n2k(kring, 
nic_i), lim);
}
}
+
if (!(ctx->ifc_flags & IFC_NETMAP_TX_IRQ))
if (kring->nr_hwtail != nm_prev(kring->nr_hwcur, lim)) {
-   callout_reset_on(&txq->ift_timer, hz < 2000 ? 1 : hz / 
1000,
-   iflib_timer, txq, txq->ift_timer.c_cpu);
-   }
+   callout_reset_sbt_on(&txq->ift_netmap_timer,
+   NETMAP_TX_TIMER_US * SBT_1US, SBT_1US,
+   iflib_netmap_timer, txq,
+   txq->ift_netmap_timer.c_cpu, 0);
+   }
return (0);
 }
 
@@ -1275,28 +1283,16 @@ iflib_netmap_rxq_init(if_ctx_t ctx, iflib_rxq_t rxq)
 }
 
 static void
-iflib_netmap_timer_adjust(if_ctx_t ctx, iflib_txq_t txq, uint32_t *reset_on)
+iflib_netmap_timer(void *arg)
 {
-   struct netmap_kring *kring;
-   uint16_t txqid;
+   iflib_txq_t txq = arg;
+   if_ctx_t ctx = txq->ift_ctx;
 
-   txqid = txq->ift_id;
-   kring = netmap_kring_on(NA(ctx->ifc_ifp), txqid, NR_TX);
-   if (kring == NULL)
-   return;
-
-   if (kring->nr_hwcur != nm_next(kring->nr_hwtail, kring->nkr_num_slots - 
1)) {
-   bus_dmamap_sync(txq->ift_ifdi->idi_tag, txq->ift_i

svn commit: r367600 - head/sys/cam/ctl

2020-11-11 Thread Alexander Motin
Author: mav
Date: Wed Nov 11 21:59:39 2020
New Revision: 367600
URL: https://svnweb.freebsd.org/changeset/base/367600

Log:
  Make CTL nicer to increased MAXPHYS.
  
  Before this CTL always allocated MAXPHYS-sized buffers, even for 4KB I/O,
  that is even more overkill for MAXPHYS of 1MB.  This change limits maximum
  allocation to 512KB if MAXPHYS is bigger, plus if one is above 128KB, adds
  new 128KB UMA zone for smaller I/Os.  The patch factors out alloc/free,
  so later we could make it use more zones or malloc() if we'd like.
  
  MFC after:1 week
  Sponsored by: iXsystems, Inc.

Modified:
  head/sys/cam/ctl/ctl_backend_block.c

Modified: head/sys/cam/ctl/ctl_backend_block.c
==
--- head/sys/cam/ctl/ctl_backend_block.cWed Nov 11 21:27:16 2020
(r367599)
+++ head/sys/cam/ctl/ctl_backend_block.cWed Nov 11 21:59:39 2020
(r367600)
@@ -102,7 +102,7 @@ __FBSDID("$FreeBSD$");
  */
 #defineCTLBLK_HALF_IO_SIZE (512 * 1024)
 #defineCTLBLK_MAX_IO_SIZE  (CTLBLK_HALF_IO_SIZE * 2)
-#defineCTLBLK_MAX_SEG  MAXPHYS
+#defineCTLBLK_MAX_SEG  MIN(CTLBLK_HALF_IO_SIZE, MAXPHYS)
 #defineCTLBLK_HALF_SEGSMAX(CTLBLK_HALF_IO_SIZE / 
CTLBLK_MAX_SEG, 1)
 #defineCTLBLK_MAX_SEGS (CTLBLK_HALF_SEGS * 2)
 
@@ -190,6 +190,9 @@ struct ctl_be_block_softc {
SLIST_HEAD(, ctl_be_block_lun)   lun_list;
uma_zone_t   beio_zone;
uma_zone_t   buf_zone;
+#if (CTLBLK_MAX_SEG > 131072)
+   uma_zone_t   buf128_zone;
+#endif
 };
 
 static struct ctl_be_block_softc backend_block_softc;
@@ -299,6 +302,32 @@ static struct ctl_backend_driver ctl_be_block_driver =
 MALLOC_DEFINE(M_CTLBLK, "ctlblock", "Memory used for CTL block backend");
 CTL_BACKEND_DECLARE(cbb, ctl_be_block_driver);
 
+static void
+ctl_alloc_seg(struct ctl_be_block_softc *softc, struct ctl_sg_entry *sg,
+size_t len)
+{
+
+#if (CTLBLK_MAX_SEG > 131072)
+   if (len <= 131072)
+   sg->addr = uma_zalloc(softc->buf128_zone, M_WAITOK);
+   else
+#endif
+   sg->addr = uma_zalloc(softc->buf_zone, M_WAITOK);
+   sg->len = len;
+}
+
+static void
+ctl_free_seg(struct ctl_be_block_softc *softc, struct ctl_sg_entry *sg)
+{
+
+#if (CTLBLK_MAX_SEG > 131072)
+   if (sg->len <= 131072)
+   uma_zfree(softc->buf128_zone, sg->addr);
+   else
+#endif
+   uma_zfree(softc->buf_zone, sg->addr);
+}
+
 static struct ctl_be_block_io *
 ctl_alloc_beio(struct ctl_be_block_softc *softc)
 {
@@ -317,12 +346,12 @@ ctl_real_free_beio(struct ctl_be_block_io *beio)
int i;
 
for (i = 0; i < beio->num_segs; i++) {
-   uma_zfree(softc->buf_zone, beio->sg_segs[i].addr);
+   ctl_free_seg(softc, &beio->sg_segs[i]);
 
/* For compare we had two equal S/G lists. */
if (beio->two_sglists) {
-   uma_zfree(softc->buf_zone,
-   beio->sg_segs[i + CTLBLK_HALF_SEGS].addr);
+   ctl_free_seg(softc,
+   &beio->sg_segs[i + CTLBLK_HALF_SEGS]);
}
}
 
@@ -1140,8 +1169,7 @@ ctl_be_block_dispatch_dev(struct ctl_be_block_lun *be_
 
/*
 * We have to limit our I/O size to the maximum supported by the
-* backend device.  Hopefully it is MAXPHYS.  If the driver doesn't
-* set it properly, use DFLTPHYS.
+* backend device.
 */
if (csw) {
max_iosize = dev->si_iosize_max;
@@ -1330,8 +1358,7 @@ ctl_be_block_cw_dispatch_ws(struct ctl_be_block_lun *b
seglen -= seglen % cbe_lun->blocksize;
} else
seglen -= seglen % cbe_lun->blocksize;
-   beio->sg_segs[i].len = seglen;
-   beio->sg_segs[i].addr = uma_zalloc(softc->buf_zone, M_WAITOK);
+   ctl_alloc_seg(softc, &beio->sg_segs[i], seglen);
 
DPRINTF("segment %d addr %p len %zd\n", i,
beio->sg_segs[i].addr, beio->sg_segs[i].len);
@@ -1603,18 +1630,17 @@ ctl_be_block_dispatch(struct ctl_be_block_lun *be_lun,
/*
 * Setup the S/G entry for this chunk.
 */
-   beio->sg_segs[i].len = min(CTLBLK_MAX_SEG, len_left);
-   beio->sg_segs[i].addr = uma_zalloc(softc->buf_zone, M_WAITOK);
+   ctl_alloc_seg(softc, &beio->sg_segs[i],
+   min(CTLBLK_MAX_SEG, len_left));
 
DPRINTF("segment %d addr %p len %zd\n", i,
beio->sg_segs[i].addr, beio->sg_segs[i].len);
 
/* Set up second segment for compare operation. */
if (beio->two_sglists) {
-   beio->sg_segs[i + CTLBLK_HALF_SEGS].len =
-   

svn commit: r367601 - stable/11/sys/kern

2020-11-11 Thread Brooks Davis
Author: brooks
Date: Wed Nov 11 22:00:30 2020
New Revision: 367601
URL: https://svnweb.freebsd.org/changeset/base/367601

Log:
  MFC r367302:
  
  sysvshm: pass relevant uap members as arguments
  
  Alter shmget_allocate_segment and shmget_existing to take the values
  they want from struct shmget_args rather than passing the struct
  around.  In general, uap structures should only be the interface to
  sys_ functions.
  
  This makes one small functional change and records the allocated space
  rather than the requested space.  If this turns out to be a problem (e.g.
  if software tries to find undersized segments by exact size rather than
  using keys), we can correct that easily.
  
  Reviewed by:  kib
  Obtained from:CheriBSD
  Sponsored by: DARPA
  Differential Revision:https://reviews.freebsd.org/D27077

Modified:
  stable/11/sys/kern/sysv_shm.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/kern/sysv_shm.c
==
--- stable/11/sys/kern/sysv_shm.c   Wed Nov 11 21:59:39 2020
(r367600)
+++ stable/11/sys/kern/sysv_shm.c   Wed Nov 11 22:00:30 2020
(r367601)
@@ -102,11 +102,6 @@ FEATURE(sysv_shm, "System V shared memory segments sup
 
 static MALLOC_DEFINE(M_SHM, "shm", "SVID compatible shared memory segments");
 
-static int shmget_allocate_segment(struct thread *td,
-struct shmget_args *uap, int mode);
-static int shmget_existing(struct thread *td, struct shmget_args *uap,
-int mode, int segnum);
-
 #defineSHMSEG_FREE 0x0200
 #defineSHMSEG_REMOVED  0x0400
 #defineSHMSEG_ALLOCATED0x0800
@@ -125,6 +120,10 @@ static void shm_deallocate_segment(struct shmid_kernel
 static int shm_find_segment_by_key(struct prison *, key_t);
 static struct shmid_kernel *shm_find_segment(struct prison *, int, bool);
 static int shm_delete_mapping(struct vmspace *vm, struct shmmap_state *);
+static int shmget_allocate_segment(struct thread *td, key_t key, size_t size,
+int mode);
+static int shmget_existing(struct thread *td, size_t size, int shmflg,
+int mode, int segnum);
 static void shmrealloc(void);
 static int shminit(void);
 static int sysvshm_modload(struct module *, int, void *);
@@ -643,7 +642,7 @@ done:
 
 
 static int
-shmget_existing(struct thread *td, struct shmget_args *uap, int mode,
+shmget_existing(struct thread *td, size_t size, int shmflg, int mode,
 int segnum)
 {
struct shmid_kernel *shmseg;
@@ -655,35 +654,34 @@ shmget_existing(struct thread *td, struct shmget_args 
KASSERT(segnum >= 0 && segnum < shmalloced,
("segnum %d shmalloced %d", segnum, shmalloced));
shmseg = &shmsegs[segnum];
-   if ((uap->shmflg & (IPC_CREAT | IPC_EXCL)) == (IPC_CREAT | IPC_EXCL))
+   if ((shmflg & (IPC_CREAT | IPC_EXCL)) == (IPC_CREAT | IPC_EXCL))
return (EEXIST);
 #ifdef MAC
-   error = mac_sysvshm_check_shmget(td->td_ucred, shmseg, uap->shmflg);
+   error = mac_sysvshm_check_shmget(td->td_ucred, shmseg, shmflg);
if (error != 0)
return (error);
 #endif
-   if (uap->size != 0 && uap->size > shmseg->u.shm_segsz)
+   if (size != 0 && size > shmseg->u.shm_segsz)
return (EINVAL);
td->td_retval[0] = IXSEQ_TO_IPCID(segnum, shmseg->u.shm_perm);
return (0);
 }
 
 static int
-shmget_allocate_segment(struct thread *td, struct shmget_args *uap, int mode)
+shmget_allocate_segment(struct thread *td, key_t key, size_t size, int mode)
 {
struct ucred *cred = td->td_ucred;
struct shmid_kernel *shmseg;
vm_object_t shm_object;
int i, segnum;
-   size_t size;
 
SYSVSHM_ASSERT_LOCKED();
 
-   if (uap->size < shminfo.shmmin || uap->size > shminfo.shmmax)
+   if (size < shminfo.shmmin || size > shminfo.shmmax)
return (EINVAL);
if (shm_nused >= shminfo.shmmni) /* Any shmids left? */
return (ENOSPC);
-   size = round_page(uap->size);
+   size = round_page(size);
if (shm_committed + btoc(size) > shminfo.shmall)
return (ENOMEM);
if (shm_last_free < 0) {
@@ -744,10 +742,10 @@ shmget_allocate_segment(struct thread *td, struct shmg
shmseg->u.shm_perm.cuid = shmseg->u.shm_perm.uid = cred->cr_uid;
shmseg->u.shm_perm.cgid = shmseg->u.shm_perm.gid = cred->cr_gid;
shmseg->u.shm_perm.mode = (mode & ACCESSPERMS) | SHMSEG_ALLOCATED;
-   shmseg->u.shm_perm.key = uap->key;
+   shmseg->u.shm_perm.key = key;
shmseg->u.shm_perm.seq = (shmseg->u.shm_perm.seq + 1) & 0x7fff;
shmseg->cred = crhold(cred);
-   shmseg->u.shm_segsz = uap->size;
+   shmseg->u.shm_segsz = size;
shmseg->u.shm_cpid = td->td_proc->p_pid;
shmseg->u.shm_lpid = shmseg->u.shm_nattch = 0;
shmseg->u.shm_atime = shmseg->u.shm_dtime = 0;
@@ -780,16 +778,18

svn commit: r367602 - in stable: 11/contrib/llvm-project/clang/lib/Sema 12/contrib/llvm-project/clang/lib/Sema

2020-11-11 Thread Dimitry Andric
Author: dim
Date: Wed Nov 11 22:15:25 2020
New Revision: 367602
URL: https://svnweb.freebsd.org/changeset/base/367602

Log:
  MFC r366683:
  
  Merge commit 35ecc7fe4 from llvm git (by Hubert Tong):
  
[clang][Sema] Fix PR47676: Handle dependent AltiVec C-style cast
  
Fix premature decision in the presence of type-dependent expression
operands on whether AltiVec vector initializations from single
expressions are "splat" operations.
  
Verify that the instantiation is able to determine the correct cast
semantics for both the scalar type and the vector type case.
  
Note that, because the change only affects the single-expression case
(and the target type is an AltiVec-style vector type), the
replacement of a parenthesized list with a parenthesized expression
does not change the semantics of the program in a program-observable
manner.
  
Reviewed By: aaron.ballman
  
Differential Revision: https://reviews.llvm.org/D88526
  
  This should fix 'Assertion failed: (isScalarType()), function
  getScalarTypeKind, file /usr/src/contrib/llvm-project/clang/lib/AST
  /Type.cpp, line 2146', when building the graphics/opencv-core port for
  powerpc64le.
  
  Requested by: pkubaj

Modified:
  stable/12/contrib/llvm-project/clang/lib/Sema/SemaExpr.cpp
Directory Properties:
  stable/12/   (props changed)

Changes in other areas also in this revision:
Modified:
  stable/11/contrib/llvm-project/clang/lib/Sema/SemaExpr.cpp
Directory Properties:
  stable/11/   (props changed)

Modified: stable/12/contrib/llvm-project/clang/lib/Sema/SemaExpr.cpp
==
--- stable/12/contrib/llvm-project/clang/lib/Sema/SemaExpr.cpp  Wed Nov 11 
22:00:30 2020(r367601)
+++ stable/12/contrib/llvm-project/clang/lib/Sema/SemaExpr.cpp  Wed Nov 11 
22:15:25 2020(r367602)
@@ -6809,7 +6809,7 @@ Sema::ActOnCastExpr(Scope *S, SourceLocation LParenLoc
 }
 if (PE || PLE->getNumExprs() == 1) {
   Expr *E = (PE ? PE->getSubExpr() : PLE->getExpr(0));
-  if (!E->getType()->isVectorType())
+  if (!E->isTypeDependent() && !E->getType()->isVectorType())
 isVectorLiteral = true;
 }
 else
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r367602 - in stable: 11/contrib/llvm-project/clang/lib/Sema 12/contrib/llvm-project/clang/lib/Sema

2020-11-11 Thread Dimitry Andric
Author: dim
Date: Wed Nov 11 22:15:25 2020
New Revision: 367602
URL: https://svnweb.freebsd.org/changeset/base/367602

Log:
  MFC r366683:
  
  Merge commit 35ecc7fe4 from llvm git (by Hubert Tong):
  
[clang][Sema] Fix PR47676: Handle dependent AltiVec C-style cast
  
Fix premature decision in the presence of type-dependent expression
operands on whether AltiVec vector initializations from single
expressions are "splat" operations.
  
Verify that the instantiation is able to determine the correct cast
semantics for both the scalar type and the vector type case.
  
Note that, because the change only affects the single-expression case
(and the target type is an AltiVec-style vector type), the
replacement of a parenthesized list with a parenthesized expression
does not change the semantics of the program in a program-observable
manner.
  
Reviewed By: aaron.ballman
  
Differential Revision: https://reviews.llvm.org/D88526
  
  This should fix 'Assertion failed: (isScalarType()), function
  getScalarTypeKind, file /usr/src/contrib/llvm-project/clang/lib/AST
  /Type.cpp, line 2146', when building the graphics/opencv-core port for
  powerpc64le.
  
  Requested by: pkubaj

Modified:
  stable/11/contrib/llvm-project/clang/lib/Sema/SemaExpr.cpp
Directory Properties:
  stable/11/   (props changed)

Changes in other areas also in this revision:
Modified:
  stable/12/contrib/llvm-project/clang/lib/Sema/SemaExpr.cpp
Directory Properties:
  stable/12/   (props changed)

Modified: stable/11/contrib/llvm-project/clang/lib/Sema/SemaExpr.cpp
==
--- stable/11/contrib/llvm-project/clang/lib/Sema/SemaExpr.cpp  Wed Nov 11 
22:00:30 2020(r367601)
+++ stable/11/contrib/llvm-project/clang/lib/Sema/SemaExpr.cpp  Wed Nov 11 
22:15:25 2020(r367602)
@@ -6809,7 +6809,7 @@ Sema::ActOnCastExpr(Scope *S, SourceLocation LParenLoc
 }
 if (PE || PLE->getNumExprs() == 1) {
   Expr *E = (PE ? PE->getSubExpr() : PLE->getExpr(0));
-  if (!E->getType()->isVectorType())
+  if (!E->isTypeDependent() && !E->getType()->isVectorType())
 isVectorLiteral = true;
 }
 else
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r367603 - in stable: 11/contrib/llvm-project/llvm/lib/Target/PowerPC 12/contrib/llvm-project/llvm/lib/Target/PowerPC

2020-11-11 Thread Dimitry Andric
Author: dim
Date: Wed Nov 11 22:18:24 2020
New Revision: 367603
URL: https://svnweb.freebsd.org/changeset/base/367603

Log:
  MFC r367485:
  
  Merge commit 354d3106c from llvm git (by Kai Luo):
  
[PowerPC] Skip combining (uint_to_fp x) if x is not simple type
  
Current powerpc64le backend hits
```
Combining: t7: f64 = uint_to_fp t6
llc: llvm-project/llvm/include/llvm/CodeGen/ValueTypes.h:291:
llvm::MVT llvm::EVT::getSimpleVT() const: Assertion `isSimple() &&
"Expected a SimpleValueType!"' failed.
```
This patch fixes it by skipping combination if `t6` is not simple
type.
Fixed https://bugs.llvm.org/show_bug.cgi?id=47660.
  
Reviewed By: #powerpc, steven.zhang
  
Differential Revision: https://reviews.llvm.org/D88388
  
  This should fix the llvm assertion mentioned above when building the
  following ports for powerpc64le:
  
  * audio/traverso
  * databases/percona57-pam-for-mysql
  * databases/percona57-server
  * emulators/citra
  * emulators/citra-qt5
  * games/7kaa
  * graphics/dia
  * graphics/mandelbulber
  * graphics/pcl-pointclouds
  * net-p2p/libtorrent-rasterbar
  * textproc/htmldoc
  
  Requested by: pkubaj

Modified:
  stable/12/contrib/llvm-project/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
Directory Properties:
  stable/12/   (props changed)

Changes in other areas also in this revision:
Modified:
  stable/11/contrib/llvm-project/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
Directory Properties:
  stable/11/   (props changed)

Modified: 
stable/12/contrib/llvm-project/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
==
--- stable/12/contrib/llvm-project/llvm/lib/Target/PowerPC/PPCISelLowering.cpp  
Wed Nov 11 22:15:25 2020(r367602)
+++ stable/12/contrib/llvm-project/llvm/lib/Target/PowerPC/PPCISelLowering.cpp  
Wed Nov 11 22:18:24 2020(r367603)
@@ -13371,6 +13371,8 @@ SDValue PPCTargetLowering::combineFPToIntToFP(SDNode *
   // from the hardware.
   if (Op.getValueType() != MVT::f32 && Op.getValueType() != MVT::f64)
 return SDValue();
+  if (!Op.getOperand(0).getValueType().isSimple())
+return SDValue();
   if (Op.getOperand(0).getValueType().getSimpleVT() <= MVT(MVT::i1) ||
   Op.getOperand(0).getValueType().getSimpleVT() > MVT(MVT::i64))
 return SDValue();
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r367603 - in stable: 11/contrib/llvm-project/llvm/lib/Target/PowerPC 12/contrib/llvm-project/llvm/lib/Target/PowerPC

2020-11-11 Thread Dimitry Andric
Author: dim
Date: Wed Nov 11 22:18:24 2020
New Revision: 367603
URL: https://svnweb.freebsd.org/changeset/base/367603

Log:
  MFC r367485:
  
  Merge commit 354d3106c from llvm git (by Kai Luo):
  
[PowerPC] Skip combining (uint_to_fp x) if x is not simple type
  
Current powerpc64le backend hits
```
Combining: t7: f64 = uint_to_fp t6
llc: llvm-project/llvm/include/llvm/CodeGen/ValueTypes.h:291:
llvm::MVT llvm::EVT::getSimpleVT() const: Assertion `isSimple() &&
"Expected a SimpleValueType!"' failed.
```
This patch fixes it by skipping combination if `t6` is not simple
type.
Fixed https://bugs.llvm.org/show_bug.cgi?id=47660.
  
Reviewed By: #powerpc, steven.zhang
  
Differential Revision: https://reviews.llvm.org/D88388
  
  This should fix the llvm assertion mentioned above when building the
  following ports for powerpc64le:
  
  * audio/traverso
  * databases/percona57-pam-for-mysql
  * databases/percona57-server
  * emulators/citra
  * emulators/citra-qt5
  * games/7kaa
  * graphics/dia
  * graphics/mandelbulber
  * graphics/pcl-pointclouds
  * net-p2p/libtorrent-rasterbar
  * textproc/htmldoc
  
  Requested by: pkubaj

Modified:
  stable/11/contrib/llvm-project/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
Directory Properties:
  stable/11/   (props changed)

Changes in other areas also in this revision:
Modified:
  stable/12/contrib/llvm-project/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
Directory Properties:
  stable/12/   (props changed)

Modified: 
stable/11/contrib/llvm-project/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
==
--- stable/11/contrib/llvm-project/llvm/lib/Target/PowerPC/PPCISelLowering.cpp  
Wed Nov 11 22:15:25 2020(r367602)
+++ stable/11/contrib/llvm-project/llvm/lib/Target/PowerPC/PPCISelLowering.cpp  
Wed Nov 11 22:18:24 2020(r367603)
@@ -13371,6 +13371,8 @@ SDValue PPCTargetLowering::combineFPToIntToFP(SDNode *
   // from the hardware.
   if (Op.getValueType() != MVT::f32 && Op.getValueType() != MVT::f64)
 return SDValue();
+  if (!Op.getOperand(0).getValueType().isSimple())
+return SDValue();
   if (Op.getOperand(0).getValueType().getSimpleVT() <= MVT(MVT::i1) ||
   Op.getOperand(0).getValueType().getSimpleVT() > MVT(MVT::i64))
 return SDValue();
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r367604 - head/sys/kern

2020-11-11 Thread Kyle Evans
Author: kevans
Date: Wed Nov 11 22:35:23 2020
New Revision: 367604
URL: https://svnweb.freebsd.org/changeset/base/367604

Log:
  umtx: drop incorrect timespec32 definition
  
  This works for amd64, but none others -- drop it, because we already have a
  proper definition in sys/compat/freebsd32/freebsd32.h that correctly uses
  time32_t.
  
  MFC after:1 week

Modified:
  head/sys/kern/kern_umtx.c

Modified: head/sys/kern/kern_umtx.c
==
--- head/sys/kern/kern_umtx.c   Wed Nov 11 22:18:24 2020(r367603)
+++ head/sys/kern/kern_umtx.c   Wed Nov 11 22:35:23 2020(r367604)
@@ -76,6 +76,7 @@ __FBSDID("$FreeBSD$");
 #include 
 
 #ifdef COMPAT_FREEBSD32
+#include 
 #include 
 #endif
 
@@ -4127,11 +4128,6 @@ sys__umtx_op(struct thread *td, struct _umtx_op_args *
 }
 
 #ifdef COMPAT_FREEBSD32
-
-struct timespec32 {
-   int32_t tv_sec;
-   int32_t tv_nsec;
-};
 
 struct umtx_time32 {
struct  timespec32  timeout;
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r367605 - head/sys/kern

2020-11-11 Thread Mateusz Guzik
Author: mjg
Date: Thu Nov 12 00:29:23 2020
New Revision: 367605
URL: https://svnweb.freebsd.org/changeset/base/367605

Log:
  thread: move nthread management out of tid_alloc
  
  While this adds more work single-threaded, it also enables SMP-related
  speed ups.

Modified:
  head/sys/kern/kern_thread.c

Modified: head/sys/kern/kern_thread.c
==
--- head/sys/kern/kern_thread.c Wed Nov 11 22:35:23 2020(r367604)
+++ head/sys/kern/kern_thread.c Thu Nov 12 00:29:23 2020(r367605)
@@ -144,7 +144,7 @@ static int maxthread;
 SYSCTL_INT(_kern, OID_AUTO, maxthread, CTLFLAG_RDTUN,
 &maxthread, 0, "Maximum number of threads");
 
-static int nthreads;
+static __exclusive_cache_line int nthreads;
 
 static LIST_HEAD(tidhashhead, thread) *tidhashtbl;
 static u_long  tidhash;
@@ -158,29 +158,52 @@ EVENTHANDLER_LIST_DEFINE(thread_dtor);
 EVENTHANDLER_LIST_DEFINE(thread_init);
 EVENTHANDLER_LIST_DEFINE(thread_fini);
 
-static lwpid_t
-tid_alloc(void)
+static bool
+thread_count_inc(void)
 {
static struct timeval lastfail;
static int curfail;
-   static lwpid_t trytid;
-   lwpid_t tid;
+   int nthreads_new;
 
-   mtx_lock(&tid_lock);
-   if (nthreads + 1 >= maxthread - 100) {
+   thread_reap();
+
+   nthreads_new = atomic_fetchadd_int(&nthreads, 1) + 1;
+   if (nthreads_new >= maxthread - 100) {
if (priv_check_cred(curthread->td_ucred, PRIV_MAXPROC) != 0 ||
-   nthreads + 1 >= maxthread) {
-   mtx_unlock(&tid_lock);
+   nthreads_new >= maxthread) {
+   atomic_subtract_int(&nthreads, 1);
if (ppsratecheck(&lastfail, &curfail, 1)) {
printf("maxthread limit exceeded by uid %u "
"(pid %d); consider increasing 
kern.maxthread\n",
curthread->td_ucred->cr_ruid, curproc->p_pid);
}
-   return (-1);
+   return (false);
}
}
+   return (true);
+}
 
-   nthreads++;
+static void
+thread_count_sub(int n)
+{
+
+   atomic_subtract_int(&nthreads, n);
+}
+
+static void
+thread_count_dec(void)
+{
+
+   thread_count_sub(1);
+}
+
+static lwpid_t
+tid_alloc(void)
+{
+   static lwpid_t trytid;
+   lwpid_t tid;
+
+   mtx_lock(&tid_lock);
/*
 * It is an invariant that the bitmap is big enough to hold maxthread
 * IDs. If we got to this point there has to be at least one free.
@@ -212,7 +235,6 @@ tid_free_locked(lwpid_t rtid)
KASSERT(bit_test(tid_bitmap, tid) != 0,
("thread ID %d not allocated\n", rtid));
bit_clear(tid_bitmap, tid);
-   nthreads--;
 }
 
 static void
@@ -398,6 +420,10 @@ threadinit(void)
 
mtx_init(&tid_lock, "TID lock", NULL, MTX_DEF);
tid_bitmap = bit_alloc(maxthread, M_TIDHASH, M_WAITOK);
+   /*
+* Handle thread0.
+*/
+   thread_count_inc();
tid0 = tid_alloc();
if (tid0 != THREAD0_TID)
panic("tid0 %d != %d\n", tid0, THREAD0_TID);
@@ -482,6 +508,7 @@ thread_reap(void)
thread_free_batched(itd);
if (tidbatchn == nitems(tidbatch)) {
tid_free_batch(tidbatch, tidbatchn);
+   thread_count_sub(tidbatchn);
tidbatchn = 0;
}
itd = ntd;
@@ -489,6 +516,7 @@ thread_reap(void)
 
if (tidbatchn != 0) {
tid_free_batch(tidbatch, tidbatchn);
+   thread_count_sub(tidbatchn);
}
 }
 
@@ -501,18 +529,17 @@ thread_alloc(int pages)
struct thread *td;
lwpid_t tid;
 
-   thread_reap(); /* check if any zombies to get */
-
-   tid = tid_alloc();
-   if (tid == -1) {
+   if (!thread_count_inc()) {
return (NULL);
}
 
+   tid = tid_alloc();
td = uma_zalloc(thread_zone, M_WAITOK);
KASSERT(td->td_kstack == 0, ("thread_alloc got thread with kstack"));
if (!vm_thread_new(td, pages)) {
uma_zfree(thread_zone, td);
tid_free(tid);
+   thread_count_dec();
return (NULL);
}
td->td_tid = tid;
@@ -564,6 +591,7 @@ thread_free(struct thread *td)
tid = td->td_tid;
thread_free_batched(td);
tid_free(tid);
+   thread_count_dec();
 }
 
 void
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r367606 - head/usr.sbin/bhyve

2020-11-11 Thread Konstantin Belousov
Author: kib
Date: Thu Nov 12 00:46:53 2020
New Revision: 367606
URL: https://svnweb.freebsd.org/changeset/base/367606

Log:
  bhyve: avoid allocating BARs above the end of supported physical addresses.
  
  Read CPUID leaf 0x808 to determine max supported phys address and
  create BAR region right below it, reserving 1/4 of the supported guest
  physical address space to the 64bit BARs mappings.
  
  PR:250802 (although the issue from PR is not fixed by the change)
  Noted and reviewed by:grehan
  Sponsored by: The FreeBSD Foundation
  MFC after:2 weeks
  Differential revision:https://reviews.freebsd.org/D27095

Modified:
  head/usr.sbin/bhyve/pci_emul.c

Modified: head/usr.sbin/bhyve/pci_emul.c
==
--- head/usr.sbin/bhyve/pci_emul.c  Thu Nov 12 00:29:23 2020
(r367605)
+++ head/usr.sbin/bhyve/pci_emul.c  Thu Nov 12 00:46:53 2020
(r367606)
@@ -33,6 +33,9 @@ __FBSDID("$FreeBSD$");
 
 #include 
 #include 
+#include 
+#include 
+#include 
 
 #include 
 #include 
@@ -46,6 +49,8 @@ __FBSDID("$FreeBSD$");
 
 #include 
 #include 
+#include 
+#include 
 #include 
 
 #include "acpi.h"
@@ -98,6 +103,7 @@ SET_DECLARE(pci_devemu_set, struct pci_devemu);
 static uint64_t pci_emul_iobase;
 static uint64_t pci_emul_membase32;
 static uint64_t pci_emul_membase64;
+static uint64_t pci_emul_memlim64;
 
 #definePCI_EMUL_IOBASE 0x2000
 #definePCI_EMUL_IOLIMIT0x1
@@ -108,9 +114,6 @@ SYSRES_MEM(PCI_EMUL_ECFG_BASE, PCI_EMUL_ECFG_SIZE);
 
 #definePCI_EMUL_MEMLIMIT32 PCI_EMUL_ECFG_BASE
 
-#definePCI_EMUL_MEMBASE64  0xD0UL
-#definePCI_EMUL_MEMLIMIT64 0xFDUL
-
 static struct pci_devemu *pci_emul_finddev(char *name);
 static void pci_lintr_route(struct pci_devinst *pi);
 static void pci_lintr_update(struct pci_devinst *pi);
@@ -632,7 +635,7 @@ pci_emul_alloc_pbar(struct pci_devinst *pdi, int idx, 
baseptr = &hostbase;
else
baseptr = &pci_emul_membase64;
-   limit = PCI_EMUL_MEMLIMIT64;
+   limit = pci_emul_memlim64;
mask = PCIM_BAR_MEM_BASE;
lobits = PCIM_BAR_MEM_SPACE | PCIM_BAR_MEM_64 |
 PCIM_BAR_MEM_PREFETCH;
@@ -1101,12 +1104,25 @@ init_pci(struct vmctx *ctx)
struct slotinfo *si;
struct funcinfo *fi;
size_t lowmem;
-   int bus, slot, func;
-   int error;
+   uint64_t cpu_maxphysaddr, pci_emul_memresv64;
+   u_int regs[4];
+   int bus, slot, func, error;
 
pci_emul_iobase = PCI_EMUL_IOBASE;
pci_emul_membase32 = vm_get_lowmem_limit(ctx);
-   pci_emul_membase64 = PCI_EMUL_MEMBASE64;
+
+   do_cpuid(0x8008, regs);
+   cpu_maxphysaddr = 1ULL << (regs[0] & 0xff);
+   if (cpu_maxphysaddr > VM_MAXUSER_ADDRESS_LA48)
+   cpu_maxphysaddr = VM_MAXUSER_ADDRESS_LA48;
+   pci_emul_memresv64 = cpu_maxphysaddr / 4;
+   /*
+* Max power of 2 that is less then
+* cpu_maxphysaddr - pci_emul_memresv64.
+*/
+   pci_emul_membase64 = 1ULL << (flsl(cpu_maxphysaddr -
+   pci_emul_memresv64) - 1);
+   pci_emul_memlim64 = cpu_maxphysaddr;
 
for (bus = 0; bus < MAXBUSES; bus++) {
if ((bi = pci_businfo[bus]) == NULL)
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r367607 - head/usr.sbin/bhyve

2020-11-11 Thread Konstantin Belousov
Author: kib
Date: Thu Nov 12 00:51:53 2020
New Revision: 367607
URL: https://svnweb.freebsd.org/changeset/base/367607

Log:
  bhyve: increase allowed size for 64bit BAR allocation below 4G from 32 to 128 
MB.
  
  Reviewed by:  grehan
  Sponsored by: The FreeBSD Foundation
  MFC after:2 weeks
  Differential revision:https://reviews.freebsd.org/D27095

Modified:
  head/usr.sbin/bhyve/pci_emul.c

Modified: head/usr.sbin/bhyve/pci_emul.c
==
--- head/usr.sbin/bhyve/pci_emul.c  Thu Nov 12 00:46:53 2020
(r367606)
+++ head/usr.sbin/bhyve/pci_emul.c  Thu Nov 12 00:51:53 2020
(r367607)
@@ -625,9 +625,9 @@ pci_emul_alloc_pbar(struct pci_devinst *pdi, int idx, 
 * Some drivers do not work well if the 64-bit BAR is allocated
 * above 4GB. Allow for this by allocating small requests under
 * 4GB unless then allocation size is larger than some arbitrary
-* number (32MB currently).
+* number (128MB currently).
 */
-   if (size > 32 * 1024 * 1024) {
+   if (size > 128 * 1024 * 1024) {
/*
 * XXX special case for device requiring peer-peer DMA
 */
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r367608 - head/sys/dev/cxgbe

2020-11-11 Thread Navdeep Parhar
Author: np
Date: Thu Nov 12 01:18:05 2020
New Revision: 367608
URL: https://svnweb.freebsd.org/changeset/base/367608

Log:
  cxgbev(4): Make sure that the iq/eq map sizes are correct for VFs.
  
  This should have been part of r366929.
  
  MFC after:3 days
  Sponsored by: Chelsio Communications

Modified:
  head/sys/dev/cxgbe/t4_main.c
  head/sys/dev/cxgbe/t4_vf.c

Modified: head/sys/dev/cxgbe/t4_main.c
==
--- head/sys/dev/cxgbe/t4_main.cThu Nov 12 00:51:53 2020
(r367607)
+++ head/sys/dev/cxgbe/t4_main.cThu Nov 12 01:18:05 2020
(r367608)
@@ -4467,9 +4467,9 @@ get_params__post_init(struct adapter *sc)
"failed to query parameters (post_init2): %d.\n", rc);
return (rc);
}
-   MPASS(val[0] >= sc->sge.iq_start);
+   MPASS((int)val[0] >= sc->sge.iq_start);
sc->sge.iqmap_sz = val[0] - sc->sge.iq_start + 1;
-   MPASS(val[1] >= sc->sge.eq_start);
+   MPASS((int)val[1] >= sc->sge.eq_start);
sc->sge.eqmap_sz = val[1] - sc->sge.eq_start + 1;
 
if (chip_id(sc) >= CHELSIO_T6) {

Modified: head/sys/dev/cxgbe/t4_vf.c
==
--- head/sys/dev/cxgbe/t4_vf.c  Thu Nov 12 00:51:53 2020(r367607)
+++ head/sys/dev/cxgbe/t4_vf.c  Thu Nov 12 01:18:05 2020(r367608)
@@ -695,13 +695,16 @@ t4vf_attach(device_t dev)
s->neq += sc->params.nports;/* ctrl queues: 1 per port */
s->niq = s->nrxq + 1;   /* 1 extra for firmware event queue */
 
+   s->iqmap_sz = s->niq;
+   s->eqmap_sz = s->neq;
+
s->rxq = malloc(s->nrxq * sizeof(struct sge_rxq), M_CXGBE,
M_ZERO | M_WAITOK);
s->txq = malloc(s->ntxq * sizeof(struct sge_txq), M_CXGBE,
M_ZERO | M_WAITOK);
-   s->iqmap = malloc(s->niq * sizeof(struct sge_iq *), M_CXGBE,
+   s->iqmap = malloc(s->iqmap_sz * sizeof(struct sge_iq *), M_CXGBE,
M_ZERO | M_WAITOK);
-   s->eqmap = malloc(s->neq * sizeof(struct sge_eq *), M_CXGBE,
+   s->eqmap = malloc(s->eqmap_sz * sizeof(struct sge_eq *), M_CXGBE,
M_ZERO | M_WAITOK);
 
sc->irq = malloc(sc->intr_count * sizeof(struct irq), M_CXGBE,
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r367609 - head/sys/dev/mlx5/mlx5_en

2020-11-11 Thread Konstantin Belousov
Author: kib
Date: Thu Nov 12 02:21:14 2020
New Revision: 367609
URL: https://svnweb.freebsd.org/changeset/base/367609

Log:
  mlx5en: Refactor repeated code to register media type to mlx5e_ifm_add().
  
  Sponsored by: Mellanox Technologies/NVidia Networking
  MFC after:1 week

Modified:
  head/sys/dev/mlx5/mlx5_en/mlx5_en_main.c

Modified: head/sys/dev/mlx5/mlx5_en/mlx5_en_main.c
==
--- head/sys/dev/mlx5/mlx5_en/mlx5_en_main.cThu Nov 12 01:18:05 2020
(r367608)
+++ head/sys/dev/mlx5/mlx5_en/mlx5_en_main.cThu Nov 12 02:21:14 2020
(r367609)
@@ -4260,6 +4260,14 @@ mlx5e_snd_tag_free(struct m_snd_tag *pmt)
}
 }
 
+static void
+mlx5e_ifm_add(struct mlx5e_priv *priv, int type)
+{
+   ifmedia_add(&priv->media, type | IFM_ETHER, 0, NULL);
+   ifmedia_add(&priv->media, type | IFM_ETHER | IFM_FDX |
+   IFM_ETH_RXPAUSE | IFM_ETH_TXPAUSE, 0, NULL);
+}
+
 static void *
 mlx5e_create_ifp(struct mlx5_core_dev *mdev)
 {
@@ -4463,21 +4471,12 @@ mlx5e_create_ifp(struct mlx5_core_dev *mdev)
mlx5e_mode_table[i][j];
if (media_entry.baudrate == 0)
continue;
-   if (MLX5E_PROT_MASK(i) & eth_proto_cap) {
-   ifmedia_add(&priv->media,
-   media_entry.subtype |
-   IFM_ETHER, 0, NULL);
-   ifmedia_add(&priv->media,
-   media_entry.subtype |
-   IFM_ETHER | IFM_FDX |
-   IFM_ETH_RXPAUSE | IFM_ETH_TXPAUSE, 0, NULL);
-   }
+   if (MLX5E_PROT_MASK(i) & eth_proto_cap)
+   mlx5e_ifm_add(priv, media_entry.subtype);
}
}
 
-   ifmedia_add(&priv->media, IFM_ETHER | IFM_AUTO, 0, NULL);
-   ifmedia_add(&priv->media, IFM_ETHER | IFM_AUTO | IFM_FDX |
-   IFM_ETH_RXPAUSE | IFM_ETH_TXPAUSE, 0, NULL);
+   mlx5e_ifm_add(priv, IFM_AUTO);
 
/* Set autoselect by default */
ifmedia_set(&priv->media, IFM_ETHER | IFM_AUTO | IFM_FDX |
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r367610 - head/sys/dev/mlx5/mlx5_en

2020-11-11 Thread Konstantin Belousov
Author: kib
Date: Thu Nov 12 02:22:16 2020
New Revision: 367610
URL: https://svnweb.freebsd.org/changeset/base/367610

Log:
  mlx5en: Register all combinations of FDX/RXPAUSE/TXPAUSE as valid media types.
  
  Sponsored by: Mellanox Technologies/NVidia Networking
  MFC after:1 week

Modified:
  head/sys/dev/mlx5/mlx5_en/mlx5_en_main.c

Modified: head/sys/dev/mlx5/mlx5_en/mlx5_en_main.c
==
--- head/sys/dev/mlx5/mlx5_en/mlx5_en_main.cThu Nov 12 02:21:14 2020
(r367609)
+++ head/sys/dev/mlx5/mlx5_en/mlx5_en_main.cThu Nov 12 02:22:16 2020
(r367610)
@@ -4264,6 +4264,15 @@ static void
 mlx5e_ifm_add(struct mlx5e_priv *priv, int type)
 {
ifmedia_add(&priv->media, type | IFM_ETHER, 0, NULL);
+   ifmedia_add(&priv->media, type | IFM_ETHER |
+   IFM_ETH_RXPAUSE | IFM_ETH_TXPAUSE, 0, NULL);
+   ifmedia_add(&priv->media, type | IFM_ETHER | IFM_ETH_RXPAUSE, 0, NULL);
+   ifmedia_add(&priv->media, type | IFM_ETHER | IFM_ETH_TXPAUSE, 0, NULL);
+   ifmedia_add(&priv->media, type | IFM_ETHER | IFM_FDX, 0, NULL);
+   ifmedia_add(&priv->media, type | IFM_ETHER | IFM_FDX |
+   IFM_ETH_RXPAUSE, 0, NULL);
+   ifmedia_add(&priv->media, type | IFM_ETHER | IFM_FDX |
+   IFM_ETH_TXPAUSE, 0, NULL);
ifmedia_add(&priv->media, type | IFM_ETHER | IFM_FDX |
IFM_ETH_RXPAUSE | IFM_ETH_TXPAUSE, 0, NULL);
 }
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r367611 - head/sys/dev/mlx5/mlx5_en

2020-11-11 Thread Konstantin Belousov
Author: kib
Date: Thu Nov 12 02:23:27 2020
New Revision: 367611
URL: https://svnweb.freebsd.org/changeset/base/367611

Log:
  mlx5en: stop ignoring pauses and flow in the media reqs.
  
  Sponsored by: Mellanox Technologies/NVidia Networking
  MFC after:1 week

Modified:
  head/sys/dev/mlx5/mlx5_en/mlx5_en_main.c

Modified: head/sys/dev/mlx5/mlx5_en/mlx5_en_main.c
==
--- head/sys/dev/mlx5/mlx5_en/mlx5_en_main.cThu Nov 12 02:22:16 2020
(r367610)
+++ head/sys/dev/mlx5/mlx5_en/mlx5_en_main.cThu Nov 12 02:23:27 2020
(r367611)
@@ -4449,8 +4449,7 @@ mlx5e_create_ifp(struct mlx5_core_dev *mdev)
 
/* Set default media status */
priv->media_status_last = IFM_AVALID;
-   priv->media_active_last = IFM_ETHER | IFM_AUTO |
-   IFM_ETH_RXPAUSE | IFM_FDX;
+   priv->media_active_last = IFM_ETHER | IFM_AUTO | IFM_FDX;
 
/* setup default pauseframes configuration */
mlx5e_setup_pauseframes(priv);
@@ -4470,7 +4469,7 @@ mlx5e_create_ifp(struct mlx5_core_dev *mdev)
mlx5_en_err(ifp, "Query port media capability failed, %d\n", 
err);
}
 
-   ifmedia_init(&priv->media, IFM_IMASK | IFM_ETH_FMASK,
+   ifmedia_init(&priv->media, IFM_IMASK,
mlx5e_media_change, mlx5e_media_status);
 
speeds_num = ext ? MLX5E_EXT_LINK_SPEEDS_NUMBER : 
MLX5E_LINK_SPEEDS_NUMBER;
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r367612 - head/sys/dev/mlx5/mlx5_en

2020-11-11 Thread Konstantin Belousov
Author: kib
Date: Thu Nov 12 02:25:10 2020
New Revision: 367612
URL: https://svnweb.freebsd.org/changeset/base/367612

Log:
  mlx5en: Set ifmr_current same as ifmr_active.
  
  This both:
  - makes ifconfig media line similar to that of other drivers.
  - fixes ENXIO in case when paradoxical current media word is not registered.
  
  Now e.g.
ifconfig mce0 -mediaopt txpause,rxpause
  works by disabling pauses if enabled.
  
  Sponsored by: Mellanox Technologies/NVidia Networking
  MFC after:1 week

Modified:
  head/sys/dev/mlx5/mlx5_en/mlx5_en_main.c

Modified: head/sys/dev/mlx5/mlx5_en/mlx5_en_main.c
==
--- head/sys/dev/mlx5/mlx5_en/mlx5_en_main.cThu Nov 12 02:23:27 2020
(r367611)
+++ head/sys/dev/mlx5/mlx5_en/mlx5_en_main.cThu Nov 12 02:25:10 2020
(r367612)
@@ -499,7 +499,7 @@ mlx5e_media_status(struct ifnet *dev, struct ifmediare
struct mlx5e_priv *priv = dev->if_softc;
 
ifmr->ifm_status = priv->media_status_last;
-   ifmr->ifm_active = priv->media_active_last |
+   ifmr->ifm_current = ifmr->ifm_active = priv->media_active_last |
(priv->params.rx_pauseframe_control ? IFM_ETH_RXPAUSE : 0) |
(priv->params.tx_pauseframe_control ? IFM_ETH_TXPAUSE : 0);
 
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r367613 - head/usr.sbin/bhyve

2020-11-11 Thread Konstantin Belousov
Author: kib
Date: Thu Nov 12 02:52:01 2020
New Revision: 367613
URL: https://svnweb.freebsd.org/changeset/base/367613

Log:
  bhyve: remove a hack to map all 8G BARs 1:1
  
  Suggested and reviewed by:grehan
  Sponsored by: The FreeBSD Foundation
  MFC after:2 weeks
  Differential revision:https://reviews.freebsd.org/D27186

Modified:
  head/usr.sbin/bhyve/pci_emul.c
  head/usr.sbin/bhyve/pci_emul.h
  head/usr.sbin/bhyve/pci_passthru.c

Modified: head/usr.sbin/bhyve/pci_emul.c
==
--- head/usr.sbin/bhyve/pci_emul.c  Thu Nov 12 02:25:10 2020
(r367612)
+++ head/usr.sbin/bhyve/pci_emul.c  Thu Nov 12 02:52:01 2020
(r367613)
@@ -454,14 +454,6 @@ pci_emul_alloc_resource(uint64_t *baseptr, uint64_t li
return (-1);
 }
 
-int
-pci_emul_alloc_bar(struct pci_devinst *pdi, int idx, enum pcibar_type type,
-  uint64_t size)
-{
-
-   return (pci_emul_alloc_pbar(pdi, idx, 0, type, size));
-}
-
 /*
  * Register (or unregister) the MMIO or I/O region associated with the BAR
  * register 'idx' of an emulated pci device.
@@ -586,8 +578,8 @@ update_bar_address(struct pci_devinst *pi, uint64_t ad
 }
 
 int
-pci_emul_alloc_pbar(struct pci_devinst *pdi, int idx, uint64_t hostbase,
-   enum pcibar_type type, uint64_t size)
+pci_emul_alloc_bar(struct pci_devinst *pdi, int idx, enum pcibar_type type,
+uint64_t size)
 {
int error;
uint64_t *baseptr, limit, addr, mask, lobits, bar;
@@ -628,13 +620,7 @@ pci_emul_alloc_pbar(struct pci_devinst *pdi, int idx, 
 * number (128MB currently).
 */
if (size > 128 * 1024 * 1024) {
-   /*
-* XXX special case for device requiring peer-peer DMA
-*/
-   if (size == 0x1UL)
-   baseptr = &hostbase;
-   else
-   baseptr = &pci_emul_membase64;
+   baseptr = &pci_emul_membase64;
limit = pci_emul_memlim64;
mask = PCIM_BAR_MEM_BASE;
lobits = PCIM_BAR_MEM_SPACE | PCIM_BAR_MEM_64 |

Modified: head/usr.sbin/bhyve/pci_emul.h
==
--- head/usr.sbin/bhyve/pci_emul.h  Thu Nov 12 02:25:10 2020
(r367612)
+++ head/usr.sbin/bhyve/pci_emul.h  Thu Nov 12 02:52:01 2020
(r367613)
@@ -221,8 +221,6 @@ int init_pci(struct vmctx *ctx);
 void   pci_callback(void);
 intpci_emul_alloc_bar(struct pci_devinst *pdi, int idx,
enum pcibar_type type, uint64_t size);
-intpci_emul_alloc_pbar(struct pci_devinst *pdi, int idx,
-   uint64_t hostbase, enum pcibar_type type, uint64_t size);
 intpci_emul_add_msicap(struct pci_devinst *pi, int msgnum);
 intpci_emul_add_pciecap(struct pci_devinst *pi, int pcie_device_type);
 void   pci_emul_capwrite(struct pci_devinst *pi, int offset, int bytes,

Modified: head/usr.sbin/bhyve/pci_passthru.c
==
--- head/usr.sbin/bhyve/pci_passthru.c  Thu Nov 12 02:25:10 2020
(r367612)
+++ head/usr.sbin/bhyve/pci_passthru.c  Thu Nov 12 02:52:01 2020
(r367613)
@@ -583,7 +583,7 @@ cfginitbar(struct vmctx *ctx, struct passthru_softc *s
sc->psc_bar[i].addr = base;
 
/* Allocate the BAR in the guest I/O or MMIO space */
-   error = pci_emul_alloc_pbar(pi, i, base, bartype, size);
+   error = pci_emul_alloc_bar(pi, i, bartype, size);
if (error)
return (-1);
 
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"