svn commit: r367945 - head

2020-11-22 Thread Eitan Adler
Author: eadler
Date: Mon Nov 23 04:39:29 2020
New Revision: 367945
URL: https://svnweb.freebsd.org/changeset/base/367945

Log:
  arcconfig: add callsign again
  
  Problem
  
  When using git-svn or other non-pure-svn tooling the original subversion
  URL is not present. This causes arcanist/phabricator to be unable to
  determine which repository is being modified.
  
  Solution
  
  Restore callsign to .arcconfig to enable exact repository matching even
  with git-svn.
  
  Reported By:  jhb

Modified:
  head/.arcconfig

Modified: head/.arcconfig
==
--- head/.arcconfig Mon Nov 23 02:49:53 2020(r367944)
+++ head/.arcconfig Mon Nov 23 04:39:29 2020(r367945)
@@ -1,4 +1,5 @@
 {
+   "repository.callsign" : "S",
"phabricator.uri" : "https://reviews.freebsd.org/";,
"history.immutable" : true
 }
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r367944 - head/sys/kern

2020-11-22 Thread Kyle Evans
Author: kevans
Date: Mon Nov 23 02:49:53 2020
New Revision: 367944
URL: https://svnweb.freebsd.org/changeset/base/367944

Log:
  cpuset_setproc: use the appropriate parent for new anonymous sets
  
  As far as I can tell, this has been the case since initially committed in
  2008.  cpuset_setproc is the executor of cpuset reassignment; note this
  excerpt from the description:
  
  * 1) Set is non-null.  This reparents all anonymous sets to the provided
  *set and replaces all non-anonymous td_cpusets with the provided set.
  
  However, reviewing cpuset_setproc_setthread() for some jail related work
  unearthed the error: if tdset was not anonymous, we were replacing it with
  `set`. If it was anonymous, then we'd rebase it onto `set` (i.e. copy the
  thread's mask over and AND it with `set`) but give the new anonymous set
  the original tdset as the parent (i.e. the base of the set we're supposed to
  be leaving behind).
  
  The primary visible consequences were that:
  
  1.) cpuset_getid() following such assignment returns the wrong result, the
  setid that we left behind rather than the one we joined.
  2.) When a process attached to the jail, the base set of any anonymous
  threads was a set outside of the jail.
  
  This was initially bundled in D27298, but it's a minor fix that's fairly
  easy to verify the correctness of.
  
  A test is included in D27307 ("badparent"), which demonstrates the issue
  with, effectively:
  
  osetid = cpuset_getid()
  newsetid = cpuset()
  cpuset_setaffinity(thread)
  cpuset_setid(osetid)
  cpuset_getid(thread) -> observe that it matches newsetid instead of osetid.
  
  MFC after:1 week

Modified:
  head/sys/kern/kern_cpuset.c

Modified: head/sys/kern/kern_cpuset.c
==
--- head/sys/kern/kern_cpuset.c Mon Nov 23 00:58:14 2020(r367943)
+++ head/sys/kern/kern_cpuset.c Mon Nov 23 02:49:53 2020(r367944)
@@ -1090,7 +1090,7 @@ cpuset_setproc_setthread(struct cpuset *tdset, struct 
if (error)
return (error);
 
-   return cpuset_shadow(tdset, nsetp, &mask, &domain, freelist,
+   return cpuset_shadow(set, nsetp, &mask, &domain, freelist,
domainlist);
 }
 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r367943 - in head/sys: compat/freebsd32 kern

2020-11-22 Thread Kyle Evans
Author: kevans
Date: Mon Nov 23 00:58:14 2020
New Revision: 367943
URL: https://svnweb.freebsd.org/changeset/base/367943

Log:
  freebsd32: take the _umtx_op struct definitions back
  
  Providing these in freebsd32.h facilitates local testing/measuring of the
  structs rather than forcing one to locally recreate them. Sanity checking
  offsets/sizes remains in kern_umtx.c where these are typically used.

Modified:
  head/sys/compat/freebsd32/freebsd32.h
  head/sys/kern/kern_umtx.c

Modified: head/sys/compat/freebsd32/freebsd32.h
==
--- head/sys/compat/freebsd32/freebsd32.h   Mon Nov 23 00:33:06 2020
(r367942)
+++ head/sys/compat/freebsd32/freebsd32.h   Mon Nov 23 00:58:14 2020
(r367943)
@@ -94,6 +94,27 @@ struct itimerval32 {
struct timeval32 it_value;
 };
 
+struct umtx_time32 {
+   struct  timespec32  _timeout;
+   uint32_t_flags;
+   uint32_t_clockid;
+};
+
+struct umtx_robust_lists_params_compat32 {
+   uint32_trobust_list_offset;
+   uint32_trobust_priv_list_offset;
+   uint32_trobust_inact_offset;
+};
+
+struct umutex32 {
+   volatile __lwpid_t  m_owner;/* Owner of the mutex */
+   __uint32_t  m_flags;/* Flags of the mutex */
+   __uint32_t  m_ceilings[2];  /* Priority protect ceiling */
+   __uint32_t  m_rb_lnk;   /* Robust linkage */
+   __uint32_t  m_pad;
+   __uint32_t  m_spare[2];
+};
+
 #define FREEBSD4_MFSNAMELEN16
 #define FREEBSD4_MNAMELEN  (88 - 2 * sizeof(int32_t))
 

Modified: head/sys/kern/kern_umtx.c
==
--- head/sys/kern/kern_umtx.c   Mon Nov 23 00:33:06 2020(r367942)
+++ head/sys/kern/kern_umtx.c   Mon Nov 23 00:58:14 2020(r367943)
@@ -232,27 +232,6 @@ struct umtx_copyops {
const bool  compat32;
 };
 
-struct umtx_time32 {
-   struct  timespec32  _timeout;
-   uint32_t_flags;
-   uint32_t_clockid;
-};
-
-struct umtx_robust_lists_params_compat32 {
-   uint32_trobust_list_offset;
-   uint32_trobust_priv_list_offset;
-   uint32_trobust_inact_offset;
-};
-
-struct umutex32 {
-   volatile __lwpid_t  m_owner;/* Owner of the mutex */
-   __uint32_t  m_flags;/* Flags of the mutex */
-   __uint32_t  m_ceilings[2];  /* Priority protect ceiling */
-   __uint32_t  m_rb_lnk;   /* Robust linkage */
-   __uint32_t  m_pad;
-   __uint32_t  m_spare[2];
-};
-
 _Static_assert(sizeof(struct umutex) == sizeof(struct umutex32), "umutex32");
 _Static_assert(__offsetof(struct umutex, m_spare[0]) ==
 __offsetof(struct umutex32, m_spare[0]), "m_spare32");
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r367942 - head/sys/kern

2020-11-22 Thread Kyle Evans
Author: kevans
Date: Mon Nov 23 00:33:06 2020
New Revision: 367942
URL: https://svnweb.freebsd.org/changeset/base/367942

Log:
  kern: dup: do not assume oldfde is valid
  
  oldfde may be invalidated if the table has grown due to the operation that
  we're performing, either via fdalloc() or a direct fdgrowtable_exp().
  
  This was technically OK before rS367927 because the old table remained valid
  until the filedesc became unused, but now it may be freed immediately if
  it's an unshared table in a single-threaded process, so it is no longer a
  good assumption to make.
  
  This fixes dup/dup2 invocations that grow the file table; in the initial
  report, it manifested as a kernel panic in devel/gmake's configure script.
  
  Reported by:  Guy Yur 
  Reviewed by:  rew
  Differential Revision:https://reviews.freebsd.org/D27319

Modified:
  head/sys/kern/kern_descrip.c

Modified: head/sys/kern/kern_descrip.c
==
--- head/sys/kern/kern_descrip.cSun Nov 22 20:21:10 2020
(r367941)
+++ head/sys/kern/kern_descrip.cMon Nov 23 00:33:06 2020
(r367942)
@@ -870,7 +870,7 @@ kern_dup(struct thread *td, u_int mode, int flags, int
struct filedesc *fdp;
struct filedescent *oldfde, *newfde;
struct proc *p;
-   struct file *delfp;
+   struct file *delfp, *oldfp;
u_long *oioctls, *nioctls;
int error, maxfd;
 
@@ -910,7 +910,8 @@ kern_dup(struct thread *td, u_int mode, int flags, int
}
 
oldfde = &fdp->fd_ofiles[old];
-   if (!fhold(oldfde->fde_file))
+   oldfp = oldfde->fde_file;
+   if (!fhold(oldfp))
goto unlock;
 
/*
@@ -922,14 +923,14 @@ kern_dup(struct thread *td, u_int mode, int flags, int
case FDDUP_NORMAL:
case FDDUP_FCNTL:
if ((error = fdalloc(td, new, &new)) != 0) {
-   fdrop(oldfde->fde_file, td);
+   fdrop(oldfp, td);
goto unlock;
}
break;
case FDDUP_MUSTREPLACE:
/* Target file descriptor must exist. */
if (fget_locked(fdp, new) == NULL) {
-   fdrop(oldfde->fde_file, td);
+   fdrop(oldfp, td);
goto unlock;
}
break;
@@ -948,7 +949,7 @@ kern_dup(struct thread *td, u_int mode, int flags, int
error = racct_set_unlocked(p, RACCT_NOFILE, new 
+ 1);
if (error != 0) {
error = EMFILE;
-   fdrop(oldfde->fde_file, td);
+   fdrop(oldfp, td);
goto unlock;
}
}
@@ -963,6 +964,12 @@ kern_dup(struct thread *td, u_int mode, int flags, int
}
 
KASSERT(old != new, ("new fd is same as old"));
+
+   /* Refetch oldfde because the table may have grown and old one freed. */
+   oldfde = &fdp->fd_ofiles[old];
+   KASSERT(oldfp == oldfde->fde_file,
+   ("fdt_ofiles shift from growth observed at fd %d",
+   old));
 
newfde = &fdp->fd_ofiles[new];
delfp = newfde->fde_file;
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r367928 - in head/sys: compat/freebsd32 kern sys

2020-11-22 Thread Kyle Evans
On Sun, Nov 22, 2020 at 1:55 AM Konstantin Belousov  wrote:
>
> On Sun, Nov 22, 2020 at 05:34:51AM +, Kyle Evans wrote:
> > Author: kevans
> > Date: Sun Nov 22 05:34:51 2020
> > New Revision: 367928
> > URL: https://svnweb.freebsd.org/changeset/base/367928
> >
> > Log:
> >   _umtx_op: move compat32 definitions back in
> >
> >   These are reasonably compact, and a future commit will blur the compat32
> >   lines by supporting 32-bit operations with the native _umtx_op.
>
> I do not mind much about placement of the compat32 syscall stubs, but I
> did suggested and liked move of the compat32 structures definitions into
> freebsd32.h.
>
> They are actually useful that way, at least allowing me to write some 
> (private)
> tests in the past.

Ah, sure, sorry- this doesn't force us to re-add implementation
details to other headers, so I don't see any problem. I will move just
the struct definitions back shortly.
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r367941 - in head/sys: net net/route netinet netinet6

2020-11-22 Thread Alexander V. Chernikov
Author: melifaro
Date: Sun Nov 22 20:21:10 2020
New Revision: 367941
URL: https://svnweb.freebsd.org/changeset/base/367941

Log:
  Refactor rib iterator functions.
  
  * Make rib_walk() order of arguments consistent with the rest of RIB api
  * Add rib_walk_ext() allowing to exec callback before/after iteration.
  * Rename rt_foreach_fib_walk_del -> rib_foreach_table_walk_del
  * Rename rt_forach_fib_walk -> rib_foreach_table_walk
  * Move rib_foreach_table_walk{_del} to route/route_helpers.c
  * Slightly refactor rib_foreach_table_walk{_del} to make the implementation
   consistent and prepare for upcoming iterator optimizations.
  
  Differential Revision:https://reviews.freebsd.org/D27219

Modified:
  head/sys/net/route.c
  head/sys/net/route.h
  head/sys/net/route/route_ctl.c
  head/sys/net/route/route_ctl.h
  head/sys/net/route/route_helpers.c
  head/sys/netinet/in_rmx.c
  head/sys/netinet6/nd6_rtr.c

Modified: head/sys/net/route.c
==
--- head/sys/net/route.cSun Nov 22 20:16:46 2020(r367940)
+++ head/sys/net/route.cSun Nov 22 20:21:10 2020(r367941)
@@ -458,81 +458,6 @@ rib_free_info(struct rt_addrinfo *info)
 }
 
 /*
- * Iterates over all existing fibs in system calling
- *  @setwa_f function prior to traversing each fib.
- *  Calls @wa_f function for each element in current fib.
- * If af is not AF_UNSPEC, iterates over fibs in particular
- * address family.
- */
-void
-rt_foreach_fib_walk(int af, rt_setwarg_t *setwa_f, rt_walktree_f_t *wa_f,
-void *arg)
-{
-   struct rib_head *rnh;
-   uint32_t fibnum;
-   int i;
-
-   for (fibnum = 0; fibnum < rt_numfibs; fibnum++) {
-   /* Do we want some specific family? */
-   if (af != AF_UNSPEC) {
-   rnh = rt_tables_get_rnh(fibnum, af);
-   if (rnh == NULL)
-   continue;
-   if (setwa_f != NULL)
-   setwa_f(rnh, fibnum, af, arg);
-
-   RIB_WLOCK(rnh);
-   rnh->rnh_walktree(&rnh->head, (walktree_f_t *)wa_f,arg);
-   RIB_WUNLOCK(rnh);
-   continue;
-   }
-
-   for (i = 1; i <= AF_MAX; i++) {
-   rnh = rt_tables_get_rnh(fibnum, i);
-   if (rnh == NULL)
-   continue;
-   if (setwa_f != NULL)
-   setwa_f(rnh, fibnum, i, arg);
-
-   RIB_WLOCK(rnh);
-   rnh->rnh_walktree(&rnh->head, (walktree_f_t *)wa_f,arg);
-   RIB_WUNLOCK(rnh);
-   }
-   }
-}
-
-/*
- * Iterates over all existing fibs in system and deletes each element
- *  for which @filter_f function returns non-zero value.
- * If @family is not AF_UNSPEC, iterates over fibs in particular
- * address family.
- */
-void
-rt_foreach_fib_walk_del(int family, rt_filter_f_t *filter_f, void *arg)
-{
-   u_int fibnum;
-   int i, start, end;
-
-   for (fibnum = 0; fibnum < rt_numfibs; fibnum++) {
-   /* Do we want some specific family? */
-   if (family != AF_UNSPEC) {
-   start = family;
-   end = family;
-   } else {
-   start = 1;
-   end = AF_MAX;
-   }
-
-   for (i = start; i <= end; i++) {
-   if (rt_tables_get_rnh(fibnum, i) == NULL)
-   continue;
-
-   rib_walk_del(fibnum, i, filter_f, arg, 0);
-   }
-   }
-}
-
-/*
  * Delete Routes for a Network Interface
  *
  * Called for each routing entry via the rnh->rnh_walktree() call above
@@ -577,14 +502,14 @@ rt_flushifroutes_af(struct ifnet *ifp, int af)
KASSERT((af >= 1 && af <= AF_MAX), ("%s: af %d not >= 1 and <= %d",
__func__, af, AF_MAX));
 
-   rt_foreach_fib_walk_del(af, rt_ifdelroute, ifp);
+   rib_foreach_table_walk_del(af, rt_ifdelroute, ifp);
 }
 
 void
 rt_flushifroutes(struct ifnet *ifp)
 {
 
-   rt_foreach_fib_walk_del(AF_UNSPEC, rt_ifdelroute, ifp);
+   rib_foreach_table_walk_del(AF_UNSPEC, rt_ifdelroute, ifp);
 }
 
 /*

Modified: head/sys/net/route.h
==
--- head/sys/net/route.hSun Nov 22 20:16:46 2020(r367940)
+++ head/sys/net/route.hSun Nov 22 20:21:10 2020(r367941)
@@ -342,7 +342,7 @@ struct rt_msghdr {
 
 struct rtentry;
 struct nhop_object;
-typedef int rt_filter_f_t(const struct rtentry *, const struct nhop_object *,
+typedef int rib_filter_f_t(const struct rtentry *, const struct nhop_object *,
 void *);
 
 struct rt_addrinfo {
@@ -351,7 +351,7 @@ struct rt_addrinfo {
struct  sockaddr *rti_info[RTAX

svn commit: r367940 - head/sys/dev/dwc

2020-11-22 Thread Emmanuel Vadot
Author: manu
Date: Sun Nov 22 20:16:46 2020
New Revision: 367940
URL: https://svnweb.freebsd.org/changeset/base/367940

Log:
  if_dwc: Correctly configure the DMA engine based on the fdt properties
  
  Do not hardcode what we setup for the DMA engine configuration but
  lookup the fdt properties and configuring accordingly.
  Use a default value of 8 for the burst dma length for both TX and
  RX, this is what we used for TX before.

Modified:
  head/sys/dev/dwc/if_dwc.c
  head/sys/dev/dwc/if_dwc.h

Modified: head/sys/dev/dwc/if_dwc.c
==
--- head/sys/dev/dwc/if_dwc.c   Sun Nov 22 18:54:14 2020(r367939)
+++ head/sys/dev/dwc/if_dwc.c   Sun Nov 22 20:16:46 2020(r367940)
@@ -1496,6 +1496,9 @@ dwc_attach(device_t dev)
uint32_t reg;
char *phy_mode;
phandle_t node;
+   uint32_t txpbl, rxpbl;
+   bool nopblx8 = false;
+   bool fixed_burst = false;
 
sc = device_get_softc(dev);
sc->dev = dev;
@@ -1513,6 +1516,15 @@ dwc_attach(device_t dev)
OF_prop_free(phy_mode);
}
 
+   if (OF_getencprop(node, "snps,txpbl", &txpbl, sizeof(uint32_t)) <= 0)
+   txpbl = 8;
+   if (OF_getencprop(node, "snps,rxpbl", &rxpbl, sizeof(uint32_t)) <= 0)
+   rxpbl = 8;
+   if (OF_hasprop(node, "snps,no-pbl-x8") == 1)
+   nopblx8 = true;
+   if (OF_hasprop(node, "snps,fixed-burst") == 1)
+   fixed_burst = true;
+
if (IF_DWC_INIT(dev) != 0)
return (ENXIO);
 
@@ -1550,12 +1562,13 @@ dwc_attach(device_t dev)
return (ENXIO);
}
 
-   if (sc->mactype != DWC_GMAC_EXT_DESC) {
-   reg = BUS_MODE_FIXEDBURST;
-   reg |= (BUS_MODE_PRIORXTX_41 << BUS_MODE_PRIORXTX_SHIFT);
-   } else
-   reg = (BUS_MODE_EIGHTXPBL);
-   reg |= (BUS_MODE_PBL_BEATS_8 << BUS_MODE_PBL_SHIFT);
+   reg = BUS_MODE_USP;
+   if (!nopblx8)
+   reg |= BUS_MODE_EIGHTXPBL;
+   reg |= (txpbl << BUS_MODE_PBL_SHIFT);
+   reg |= (rxpbl << BUS_MODE_RPBL_SHIFT);
+   if (fixed_burst)
+   reg |= BUS_MODE_FIXEDBURST;
WRITE4(sc, BUS_MODE, reg);
 
/*

Modified: head/sys/dev/dwc/if_dwc.h
==
--- head/sys/dev/dwc/if_dwc.h   Sun Nov 22 18:54:14 2020(r367939)
+++ head/sys/dev/dwc/if_dwc.h   Sun Nov 22 20:16:46 2020(r367940)
@@ -220,6 +220,8 @@
 /* DMA */
 #defineBUS_MODE0x1000
 #define BUS_MODE_EIGHTXPBL (1 << 24) /* Multiplies PBL by 8 */
+#define BUS_MODE_USP   (1 << 23)
+#define BUS_MODE_RPBL_SHIFT17 /* Single block transfer size */
 #define BUS_MODE_FIXEDBURST(1 << 16)
 #define BUS_MODE_PRIORXTX_SHIFT14
 #define BUS_MODE_PRIORXTX_41   3
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r367938 - head/release/arm64

2020-11-22 Thread Emmanuel Vadot
Author: manu
Date: Sun Nov 22 18:42:08 2020
New Revision: 367938
URL: https://svnweb.freebsd.org/changeset/base/367938

Log:
  release: rpi3: Copy the bcm2710 variant of the rpi2
  
  This is the dtb intented to be used for booting RPI2 v1.2 in aarch64.

Modified:
  head/release/arm64/RPI3.conf

Modified: head/release/arm64/RPI3.conf
==
--- head/release/arm64/RPI3.confSun Nov 22 16:13:09 2020
(r367937)
+++ head/release/arm64/RPI3.confSun Nov 22 18:42:08 2020
(r367938)
@@ -4,7 +4,7 @@
 #
 
 DTB_DIR="/usr/local/share/rpi-firmware"
-DTB="bcm2709-rpi-2-b.dtb bcm2710-rpi-3-b.dtb bcm2710-rpi-3-b-plus.dtb 
bcm2711-rpi-4-b.dtb"
+DTB="bcm2710-rpi-2-b.dtb bcm2710-rpi-3-b.dtb bcm2710-rpi-3-b-plus.dtb 
bcm2711-rpi-4-b.dtb"
 EMBEDDED_TARGET_ARCH="aarch64"
 EMBEDDED_TARGET="arm64"
 EMBEDDEDBUILD=1
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r367927 - in head: sys/kern tests/sys/kern

2020-11-22 Thread Kyle Evans
On Sun, Nov 22, 2020 at 11:25 AM Kyle Evans  wrote:
>
> On Sun, Nov 22, 2020 at 10:36 AM Kyle Evans  wrote:
> >
> > On Sun, Nov 22, 2020 at 9:54 AM Guy Yur  wrote:
> > >
> > > On 22/11/20 7:00 am, Robert Wing wrote:
> > > > Author: rew
> > > > Date: Sun Nov 22 05:00:28 2020
> > > > New Revision: 367927
> > > > URL: https://svnweb.freebsd.org/changeset/base/367927
> > > >
> > > > Log:
> > > >fd: free old file descriptor tables when not shared
> > > >
> > > >During the life of a process, new file descriptor tables may be 
> > > > allocated. When
> > > >a new table is allocated, the old table is placed in a free list and 
> > > > held onto
> > > >until all processes referencing them exit.
> > > >
> > > >When a new file descriptor table is allocated, the old file 
> > > > descriptor table
> > > >can be freed when the current process has a single-thread and the 
> > > > file
> > > >descriptor table is not being shared with any other processes.
> > > >
> > > >Reviewed by:kevans
> > > >Approved by:kevans (mentor)
> > > >Differential Revision:  https://reviews.freebsd.org/D18617
> > > >
> > > > Added:
> > > >head/tests/sys/kern/fdgrowtable_test.c   (contents, props changed)
> > > > Modified:
> > > >head/sys/kern/kern_descrip.c
> > > >head/tests/sys/kern/Makefile
> > >
> > > Hi,
> > >
> > > I am getting a kernel panic with this commit when building
> > > devel/gmake port and it runs dup2 test in configure script.
> > >
> > > panic: fc_ioctls != NULL, but fc_nioctls=-16162
> > > ...
> > > #10 0x80655c72 in vpanic (fmt=, ap=)
> > >  at /usr/src/sys/kern/kern_shutdown.c:907
> > > #11 0x80655a03 in panic (
> > >  fmt=0x80eb2b78  "헝\200\377\377\377\377")
> > >  at /usr/src/sys/kern/kern_shutdown.c:843
> > > #12 0x805fff9a in filecaps_copy_prep (src=)
> > >  at /usr/src/sys/kern/kern_descrip.c:1629
> > > #13 kern_dup (td=, mode=, flags=0,
> > >  old=, new=256) at /usr/src/sys/kern/kern_descrip.c:970
> > > #14 0x8094a5de in syscallenter (td=)
> > >  at /usr/src/sys/amd64/amd64/../../kern/subr_syscall.c:189
> > > #15 amd64_syscall (td=0xfe00513f8500, traced=0)
> > >  at /usr/src/sys/amd64/amd64/trap.c:1156
> > >
> > >
> > > Simplified test program that causes panic:
> > > #include 
> > > #include 
> > >
> > > int main ()
> > > {
> > >int bad_fd = INT_MAX;
> > >dup2 (1, 1);
> > >close (0);
> > >dup2 (0, 0);
> > >dup2 (2, bad_fd);
> > >dup2 (2, -1);
> > >dup2 (2, 255);
> > >dup2 (2, 256);
> > >return 0;
> > > }
> > >
> >
> > Whoops. =\
> >
> > It looks like kern_dup grows the file table but assumes that it can
> > continue using oldfe that it fetched from the now-freed table. I
> > suspect we just need to refetch oldfde after the grow operation, and
> > it might be a good idea (under INVARIANTS) to grab the fp from oldfde
> > before we grow the table and assert that the new entry we fetch is the
> > same underlying file.
> >
>
> I can confirm that the below fixes it and no other growth spots keep
> pointers into the old table around, I'll give it a little bit for any
> objections to be raised then commit.
>

Bah, sorry, this still isn't right. The other paths may grow the table
via fdalloc(). I'll throw up a review for this shortly.
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r367927 - in head: sys/kern tests/sys/kern

2020-11-22 Thread Kyle Evans
On Sun, Nov 22, 2020 at 10:36 AM Kyle Evans  wrote:
>
> On Sun, Nov 22, 2020 at 9:54 AM Guy Yur  wrote:
> >
> > On 22/11/20 7:00 am, Robert Wing wrote:
> > > Author: rew
> > > Date: Sun Nov 22 05:00:28 2020
> > > New Revision: 367927
> > > URL: https://svnweb.freebsd.org/changeset/base/367927
> > >
> > > Log:
> > >fd: free old file descriptor tables when not shared
> > >
> > >During the life of a process, new file descriptor tables may be 
> > > allocated. When
> > >a new table is allocated, the old table is placed in a free list and 
> > > held onto
> > >until all processes referencing them exit.
> > >
> > >When a new file descriptor table is allocated, the old file descriptor 
> > > table
> > >can be freed when the current process has a single-thread and the file
> > >descriptor table is not being shared with any other processes.
> > >
> > >Reviewed by:kevans
> > >Approved by:kevans (mentor)
> > >Differential Revision:  https://reviews.freebsd.org/D18617
> > >
> > > Added:
> > >head/tests/sys/kern/fdgrowtable_test.c   (contents, props changed)
> > > Modified:
> > >head/sys/kern/kern_descrip.c
> > >head/tests/sys/kern/Makefile
> >
> > Hi,
> >
> > I am getting a kernel panic with this commit when building
> > devel/gmake port and it runs dup2 test in configure script.
> >
> > panic: fc_ioctls != NULL, but fc_nioctls=-16162
> > ...
> > #10 0x80655c72 in vpanic (fmt=, ap=)
> >  at /usr/src/sys/kern/kern_shutdown.c:907
> > #11 0x80655a03 in panic (
> >  fmt=0x80eb2b78  "헝\200\377\377\377\377")
> >  at /usr/src/sys/kern/kern_shutdown.c:843
> > #12 0x805fff9a in filecaps_copy_prep (src=)
> >  at /usr/src/sys/kern/kern_descrip.c:1629
> > #13 kern_dup (td=, mode=, flags=0,
> >  old=, new=256) at /usr/src/sys/kern/kern_descrip.c:970
> > #14 0x8094a5de in syscallenter (td=)
> >  at /usr/src/sys/amd64/amd64/../../kern/subr_syscall.c:189
> > #15 amd64_syscall (td=0xfe00513f8500, traced=0)
> >  at /usr/src/sys/amd64/amd64/trap.c:1156
> >
> >
> > Simplified test program that causes panic:
> > #include 
> > #include 
> >
> > int main ()
> > {
> >int bad_fd = INT_MAX;
> >dup2 (1, 1);
> >close (0);
> >dup2 (0, 0);
> >dup2 (2, bad_fd);
> >dup2 (2, -1);
> >dup2 (2, 255);
> >dup2 (2, 256);
> >return 0;
> > }
> >
>
> Whoops. =\
>
> It looks like kern_dup grows the file table but assumes that it can
> continue using oldfe that it fetched from the now-freed table. I
> suspect we just need to refetch oldfde after the grow operation, and
> it might be a good idea (under INVARIANTS) to grab the fp from oldfde
> before we grow the table and assert that the new entry we fetch is the
> same underlying file.
>

I can confirm that the below fixes it and no other growth spots keep
pointers into the old table around, I'll give it a little bit for any
objections to be raised then commit.

diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c
index b5680bd79e1..1a3a5cafbea 100644
--- a/sys/kern/kern_descrip.c
+++ b/sys/kern/kern_descrip.c
@@ -936,6 +936,12 @@ kern_dup(struct thread *td, u_int mode, int
flags, int old, int new)
break;
case FDDUP_FIXED:
if (new >= fdp->fd_nfiles) {
+#ifdef INVARIANTS
+   struct file *ofp;
+
+   ofp = oldfde->fde_file;
+#endif
+
/*
 * The resource limits are here instead of e.g.
 * fdalloc(), because the file descriptor table may be
@@ -955,6 +961,11 @@ kern_dup(struct thread *td, u_int mode, int
flags, int old, int new)
}
 #endif
fdgrowtable_exp(fdp, new + 1);
+   /* Refetch; old entry may be invalid. */
+   oldfde = &fdp->fd_ofiles[old];
+   KASSERT(ofp == oldfde->fde_file,
+   ("fdt_ofiles shift from growth observed at fd %d",
+   old));
}
if (!fdisused(fdp, new))
fdused(fdp, new);
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r367927 - in head: sys/kern tests/sys/kern

2020-11-22 Thread Kyle Evans
On Sun, Nov 22, 2020 at 9:54 AM Guy Yur  wrote:
>
> On 22/11/20 7:00 am, Robert Wing wrote:
> > Author: rew
> > Date: Sun Nov 22 05:00:28 2020
> > New Revision: 367927
> > URL: https://svnweb.freebsd.org/changeset/base/367927
> >
> > Log:
> >fd: free old file descriptor tables when not shared
> >
> >During the life of a process, new file descriptor tables may be 
> > allocated. When
> >a new table is allocated, the old table is placed in a free list and 
> > held onto
> >until all processes referencing them exit.
> >
> >When a new file descriptor table is allocated, the old file descriptor 
> > table
> >can be freed when the current process has a single-thread and the file
> >descriptor table is not being shared with any other processes.
> >
> >Reviewed by:kevans
> >Approved by:kevans (mentor)
> >Differential Revision:  https://reviews.freebsd.org/D18617
> >
> > Added:
> >head/tests/sys/kern/fdgrowtable_test.c   (contents, props changed)
> > Modified:
> >head/sys/kern/kern_descrip.c
> >head/tests/sys/kern/Makefile
>
> Hi,
>
> I am getting a kernel panic with this commit when building
> devel/gmake port and it runs dup2 test in configure script.
>
> panic: fc_ioctls != NULL, but fc_nioctls=-16162
> ...
> #10 0x80655c72 in vpanic (fmt=, ap=)
>  at /usr/src/sys/kern/kern_shutdown.c:907
> #11 0x80655a03 in panic (
>  fmt=0x80eb2b78  "헝\200\377\377\377\377")
>  at /usr/src/sys/kern/kern_shutdown.c:843
> #12 0x805fff9a in filecaps_copy_prep (src=)
>  at /usr/src/sys/kern/kern_descrip.c:1629
> #13 kern_dup (td=, mode=, flags=0,
>  old=, new=256) at /usr/src/sys/kern/kern_descrip.c:970
> #14 0x8094a5de in syscallenter (td=)
>  at /usr/src/sys/amd64/amd64/../../kern/subr_syscall.c:189
> #15 amd64_syscall (td=0xfe00513f8500, traced=0)
>  at /usr/src/sys/amd64/amd64/trap.c:1156
>
>
> Simplified test program that causes panic:
> #include 
> #include 
>
> int main ()
> {
>int bad_fd = INT_MAX;
>dup2 (1, 1);
>close (0);
>dup2 (0, 0);
>dup2 (2, bad_fd);
>dup2 (2, -1);
>dup2 (2, 255);
>dup2 (2, 256);
>return 0;
> }
>

Whoops. =\

It looks like kern_dup grows the file table but assumes that it can
continue using oldfe that it fetched from the now-freed table. I
suspect we just need to refetch oldfde after the grow operation, and
it might be a good idea (under INVARIANTS) to grab the fp from oldfde
before we grow the table and assert that the new entry we fetch is the
same underlying file.

Thanks,

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


Re: svn commit: r367929 - head/sys/dev/isp

2020-11-22 Thread Alexander Motin
On 22.11.2020 10:23, Kyle Evans wrote:
> On Sat, Nov 21, 2020 at 11:43 PM Alexander Motin  wrote:
>> Author: mav
>> Date: Sun Nov 22 05:42:52 2020
>> New Revision: 367929
>> URL: https://svnweb.freebsd.org/changeset/base/367929
>>
>> Log:
>>   Fix build after 367926.
>>
>>   Option ISP_TARGET_MODE is evil.
>>
> 
> The LINT build appears to be broken following these, see:
> https://ci.freebsd.org/job/FreeBSD-head-amd64-LINT/18514/console
> 
> 09:02:49 --- isp_freebsd.o ---
> 09:02:49 /workspace/src/sys/dev/isp/isp_freebsd.c:1483:26: error: more
> '%' conversions than data arguments [-Werror,-Wformat]
> 09:02:49 KASSERT(atp == NULL, ("%s: atp is not NULL on noresrc!\n"));
> 09:02:49~^

Fixed in r367937.  Thanks.

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


svn commit: r367937 - head/sys/dev/isp

2020-11-22 Thread Alexander Motin
Author: mav
Date: Sun Nov 22 16:13:09 2020
New Revision: 367937
URL: https://svnweb.freebsd.org/changeset/base/367937

Log:
  Fix debug build after 367926.

Modified:
  head/sys/dev/isp/isp_freebsd.c

Modified: head/sys/dev/isp/isp_freebsd.c
==
--- head/sys/dev/isp/isp_freebsd.c  Sun Nov 22 13:39:21 2020
(r367936)
+++ head/sys/dev/isp/isp_freebsd.c  Sun Nov 22 16:13:09 2020
(r367937)
@@ -1480,7 +1480,7 @@ isp_handle_platform_atio7(ispsoftc_t *isp, at7_entry_t
xpt_done((union ccb *)atiop);
return;
 noresrc:
-   KASSERT(atp == NULL, ("%s: atp is not NULL on noresrc!\n"));
+   KASSERT(atp == NULL, ("%s: atp is not NULL on noresrc!\n", __func__));
ntp = isp_get_ntpd(isp, chan);
if (ntp == NULL) {
isp_endcmd(isp, aep, nphdl, chan, SCSI_STATUS_BUSY, 0);
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r367927 - in head: sys/kern tests/sys/kern

2020-11-22 Thread Guy Yur

On 22/11/20 7:00 am, Robert Wing wrote:

Author: rew
Date: Sun Nov 22 05:00:28 2020
New Revision: 367927
URL: https://svnweb.freebsd.org/changeset/base/367927

Log:
   fd: free old file descriptor tables when not shared
   
   During the life of a process, new file descriptor tables may be allocated. When

   a new table is allocated, the old table is placed in a free list and held 
onto
   until all processes referencing them exit.
   
   When a new file descriptor table is allocated, the old file descriptor table

   can be freed when the current process has a single-thread and the file
   descriptor table is not being shared with any other processes.
   
   Reviewed by:kevans

   Approved by:kevans (mentor)
   Differential Revision:  https://reviews.freebsd.org/D18617

Added:
   head/tests/sys/kern/fdgrowtable_test.c   (contents, props changed)
Modified:
   head/sys/kern/kern_descrip.c
   head/tests/sys/kern/Makefile


Hi,

I am getting a kernel panic with this commit when building
devel/gmake port and it runs dup2 test in configure script.

panic: fc_ioctls != NULL, but fc_nioctls=-16162
...
#10 0x80655c72 in vpanic (fmt=, ap=)
    at /usr/src/sys/kern/kern_shutdown.c:907
#11 0x80655a03 in panic (
    fmt=0x80eb2b78  "헝\200\377\377\377\377")
    at /usr/src/sys/kern/kern_shutdown.c:843
#12 0x805fff9a in filecaps_copy_prep (src=)
    at /usr/src/sys/kern/kern_descrip.c:1629
#13 kern_dup (td=, mode=, flags=0,
    old=, new=256) at /usr/src/sys/kern/kern_descrip.c:970
#14 0x8094a5de in syscallenter (td=)
    at /usr/src/sys/amd64/amd64/../../kern/subr_syscall.c:189
#15 amd64_syscall (td=0xfe00513f8500, traced=0)
    at /usr/src/sys/amd64/amd64/trap.c:1156


Simplified test program that causes panic:
#include 
#include 

int main ()
{
  int bad_fd = INT_MAX;
  dup2 (1, 1);
  close (0);
  dup2 (0, 0);
  dup2 (2, bad_fd);
  dup2 (2, -1);
  dup2 (2, 255);
  dup2 (2, 256);
  return 0;
}


Thanks,
Guy Yur

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


Re: svn commit: r367929 - head/sys/dev/isp

2020-11-22 Thread Kyle Evans
On Sat, Nov 21, 2020 at 11:43 PM Alexander Motin  wrote:
>
> Author: mav
> Date: Sun Nov 22 05:42:52 2020
> New Revision: 367929
> URL: https://svnweb.freebsd.org/changeset/base/367929
>
> Log:
>   Fix build after 367926.
>
>   Option ISP_TARGET_MODE is evil.
>

The LINT build appears to be broken following these, see:
https://ci.freebsd.org/job/FreeBSD-head-amd64-LINT/18514/console

09:02:49 --- isp_freebsd.o ---
09:02:49 /workspace/src/sys/dev/isp/isp_freebsd.c:1483:26: error: more
'%' conversions than data arguments [-Werror,-Wformat]
09:02:49 KASSERT(atp == NULL, ("%s: atp is not NULL on noresrc!\n"));
09:02:49~^
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r367936 - head/tools/tools/netmap

2020-11-22 Thread Vincenzo Maffione
Author: vmaffione
Date: Sun Nov 22 13:39:21 2020
New Revision: 367936
URL: https://svnweb.freebsd.org/changeset/base/367936

Log:
  netmap: bridge: improve readability
  
  Multiple cosmetic changes, plus a fix to a verbose print
  (indicating wrong net->host/host->net direction).
  
  MFC after:3 days

Modified:
  head/tools/tools/netmap/bridge.c

Modified: head/tools/tools/netmap/bridge.c
==
--- head/tools/tools/netmap/bridge.cSun Nov 22 10:02:56 2020
(r367935)
+++ head/tools/tools/netmap/bridge.cSun Nov 22 13:39:21 2020
(r367936)
@@ -3,19 +3,19 @@
  *
  * BSD license
  *
- * A netmap client to bridge two network interfaces
- * (or one interface and the host stack).
+ * A netmap application to bridge two network interfaces,
+ * or one interface and the host stack.
  *
  * $FreeBSD$
  */
 
+#include 
+#include 
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
-#include 
 
 static int verbose = 0;
 
@@ -32,30 +32,39 @@ sigint_h(int sig)
 
 
 /*
- * how many packets on this set of queues ?
+ * How many slots do we (user application) have on this
+ * set of queues ?
  */
 static int
-pkt_queued(struct nmport_d *d, int tx)
+rx_slots_avail(struct nmport_d *d)
 {
u_int i, tot = 0;
 
-   if (tx) {
-   for (i = d->first_tx_ring; i <= d->last_tx_ring; i++) {
-   tot += nm_ring_space(NETMAP_TXRING(d->nifp, i));
-   }
-   } else {
-   for (i = d->first_rx_ring; i <= d->last_rx_ring; i++) {
-   tot += nm_ring_space(NETMAP_RXRING(d->nifp, i));
-   }
+   for (i = d->first_rx_ring; i <= d->last_rx_ring; i++) {
+   tot += nm_ring_space(NETMAP_RXRING(d->nifp, i));
}
+
return tot;
 }
 
+static int
+tx_slots_avail(struct nmport_d *d)
+{
+   u_int i, tot = 0;
+
+   for (i = d->first_tx_ring; i <= d->last_tx_ring; i++) {
+   tot += nm_ring_space(NETMAP_TXRING(d->nifp, i));
+   }
+
+   return tot;
+}
+
 /*
- * move up to 'limit' pkts from rxring to txring swapping buffers.
+ * Move up to 'limit' pkts from rxring to txring, swapping buffers
+ * if zerocopy is possible. Otherwise fall back on packet copying.
  */
 static int
-process_rings(struct netmap_ring *rxring, struct netmap_ring *txring,
+rings_move(struct netmap_ring *rxring, struct netmap_ring *txring,
  u_int limit, const char *msg)
 {
u_int j, k, m = 0;
@@ -63,7 +72,7 @@ process_rings(struct netmap_ring *rxring, struct netma
/* print a warning if any of the ring flags is set (e.g. NM_REINIT) */
if (rxring->flags || txring->flags)
D("%s rxflags %x txflags %x",
-   msg, rxring->flags, txring->flags);
+   msg, rxring->flags, txring->flags);
j = rxring->head; /* RX */
k = txring->head; /* TX */
m = nm_ring_space(rxring);
@@ -79,16 +88,18 @@ process_rings(struct netmap_ring *rxring, struct netma
 
/* swap packets */
if (ts->buf_idx < 2 || rs->buf_idx < 2) {
-   RD(5, "wrong index rx[%d] = %d  -> tx[%d] = %d",
-   j, rs->buf_idx, k, ts->buf_idx);
+   RD(2, "wrong index rxr[%d] = %d  -> txr[%d] = %d",
+   j, rs->buf_idx, k, ts->buf_idx);
sleep(2);
}
/* copy the packet length. */
if (rs->len > rxring->nr_buf_size) {
-   RD(5, "wrong len %d rx[%d] -> tx[%d]", rs->len, j, k);
+   RD(2,  "%s: invalid len %u, rxr[%d] -> txr[%d]",
+   msg, rs->len, j, k);
rs->len = 0;
} else if (verbose > 1) {
-   D("%s send len %d rx[%d] -> tx[%d]", msg, rs->len, j, 
k);
+   D("%s: fwd len %u, rx[%d] -> tx[%d]",
+   msg, rs->len, j, k);
}
ts->len = rs->len;
if (zerocopy) {
@@ -111,24 +122,23 @@ process_rings(struct netmap_ring *rxring, struct netma
rxring->head = rxring->cur = j;
txring->head = txring->cur = k;
if (verbose && m > 0)
-   D("%s sent %d packets to %p", msg, m, txring);
+   D("%s fwd %d packets: rxring %u --> txring %u",
+   msg, m, rxring->ringid, txring->ringid);
 
return (m);
 }
 
-/* move packts from src to destination */
+/* Move packets from source port to destination port. */
 static int
-move(struct nmport_d *src, struct nmport_d *dst, u_int limit)
+ports_move(struct nmport_d *src, struct nmport_d *dst, u_int limit,
+   const char *msg)
 {
struct netmap_ring *txring, *rxring;
u_int m = 0, si = src->first_rx_ring, di = dst->first_tx_ring;
-   const char *msg = (src->reg.nr_flags == NR_REG_

svn commit: r367935 - head/usr.sbin/valectl

2020-11-22 Thread Vincenzo Maffione
Author: vmaffione
Date: Sun Nov 22 10:02:56 2020
New Revision: 367935
URL: https://svnweb.freebsd.org/changeset/base/367935

Log:
  netmap: valectl: switch to libnetmap
  
  Use the newer libnetmap (included in base) rather than the older
  nm_open()/nm_close() defined in netmap_user.h
  
  MFC after:  3 days

Modified:
  head/usr.sbin/valectl/Makefile
  head/usr.sbin/valectl/valectl.c

Modified: head/usr.sbin/valectl/Makefile
==
--- head/usr.sbin/valectl/Makefile  Sun Nov 22 09:38:01 2020
(r367934)
+++ head/usr.sbin/valectl/Makefile  Sun Nov 22 10:02:56 2020
(r367935)
@@ -5,4 +5,6 @@ MAN=valectl.8
 
 WARNS?=3
 
+LIBADD=netmap
+
 .include 

Modified: head/usr.sbin/valectl/valectl.c
==
--- head/usr.sbin/valectl/valectl.c Sun Nov 22 09:38:01 2020
(r367934)
+++ head/usr.sbin/valectl/valectl.c Sun Nov 22 10:02:56 2020
(r367935)
@@ -25,9 +25,8 @@
 
 /* $FreeBSD$ */
 
-#define NETMAP_WITH_LIBS
-#include 
-#include 
+#define LIBNETMAP_NOTHREADSAFE
+#include 
 
 #include 
 #include 
@@ -42,14 +41,58 @@
 #include /* basename */
 #include /* atoi, free */
 
+int verbose;
+
+struct args {
+   const char *name;
+   const char *config;
+   const char *mem_id;
+
+   uint16_t nr_reqtype;
+   uint32_t nr_mode;
+};
+
 static void
-parse_nmr_config(const char* conf, struct nmreq *nmr)
+dump_port_info(struct nmreq_port_info_get *v)
 {
+   printf("memsize:%"PRIu64"\n", v->nr_memsize);
+   printf("tx_slots:   %"PRIu32"\n", v->nr_tx_slots);
+   printf("rx_slots:   %"PRIu32"\n", v->nr_rx_slots);
+   printf("tx_rings:   %"PRIu16"\n", v->nr_tx_rings);
+   printf("rx_rings%"PRIu16"\n", v->nr_rx_rings);
+   printf("mem_id: %"PRIu16"\n", v->nr_mem_id);
+}
+
+static void
+dump_newif(struct nmreq_vale_newif *v)
+{
+   printf("tx_slots:   %"PRIu32"\n", v->nr_tx_slots);
+   printf("rx_slots:   %"PRIu32"\n", v->nr_rx_slots);
+   printf("tx_rings:   %"PRIu16"\n", v->nr_tx_rings);
+   printf("rx_ring:%"PRIu16"\n", v->nr_rx_rings);
+   printf("mem_id: %"PRIu16"\n", v->nr_mem_id);
+}
+
+static void
+dump_vale_list(struct nmreq_vale_list *v)
+{
+   printf("bridge_idx: %"PRIu16"\n", v->nr_bridge_idx);
+   printf("port_idx:   %"PRIu16"\n", v->nr_port_idx);
+}
+
+
+static void
+parse_ring_config(const char* conf,
+   uint32_t *nr_tx_slots,
+   uint32_t *nr_rx_slots,
+   uint16_t *nr_tx_rings,
+   uint16_t *nr_rx_rings)
+{
char *w, *tok;
int i, v;
 
-   nmr->nr_tx_rings = nmr->nr_rx_rings = 0;
-   nmr->nr_tx_slots = nmr->nr_rx_slots = 0;
+   *nr_tx_rings = *nr_rx_rings = 0;
+   *nr_tx_slots = *nr_rx_slots = 0;
if (conf == NULL || ! *conf)
return;
w = strdup(conf);
@@ -57,137 +100,235 @@ parse_nmr_config(const char* conf, struct nmreq *nmr)
v = atoi(tok);
switch (i) {
case 0:
-   nmr->nr_tx_slots = nmr->nr_rx_slots = v;
+   *nr_tx_slots = *nr_rx_slots = v;
break;
case 1:
-   nmr->nr_rx_slots = v;
+   *nr_rx_slots = v;
break;
case 2:
-   nmr->nr_tx_rings = nmr->nr_rx_rings = v;
+   *nr_tx_rings = *nr_rx_rings = v;
break;
case 3:
-   nmr->nr_rx_rings = v;
+   *nr_rx_rings = v;
break;
default:
-   D("ignored config: %s", tok);
+   fprintf(stderr, "ignored config: %s", tok);
break;
}
}
-   D("txr %d txd %d rxr %d rxd %d",
-   nmr->nr_tx_rings, nmr->nr_tx_slots,
-   nmr->nr_rx_rings, nmr->nr_rx_slots);
+   ND("txr %d txd %d rxr %d rxd %d",
+   *nr_tx_rings, *nr_tx_slots,
+   *nr_rx_rings, *nr_rx_slots);
free(w);
 }
 
 static int
-bdg_ctl(const char *name, int nr_cmd, int nr_arg, char *nmr_config, int 
nr_arg2)
+parse_poll_config(const char *conf, struct nmreq_vale_polling *v)
 {
-   struct nmreq nmr;
-   int error = 0;
-   int fd = open("/dev/netmap", O_RDWR);
+   char *w, *tok;
+   int i, p;
 
-   if (fd == -1) {
-   D("Unable to open /dev/netmap");
+   if (conf == NULL || ! *conf) {
+   fprintf(stderr, "invalid null/empty config\n");
return -1;
}
+   w = strdup(conf);
+   for (i = 0, tok = strtok(w, ","); tok; i++, tok = strtok(NULL, ",")) {
+   p = atoi(tok);
+   switch (i) {

svn commit: r367934 - head/tools/tools/netmap

2020-11-22 Thread Vincenzo Maffione
Author: vmaffione
Date: Sun Nov 22 09:38:01 2020
New Revision: 367934
URL: https://svnweb.freebsd.org/changeset/base/367934

Log:
  netmap: nmreplay: switch to libnetmap
  
  Use the newer libnetmap (included in base) rather than the older
  nm_open()/nm_close() defined in netmap_user.h
  
  MFC after:  3 days

Modified:
  head/tools/tools/netmap/nmreplay.c

Modified: head/tools/tools/netmap/nmreplay.c
==
--- head/tools/tools/netmap/nmreplay.c  Sun Nov 22 09:28:50 2020
(r367933)
+++ head/tools/tools/netmap/nmreplay.c  Sun Nov 22 09:38:01 2020
(r367934)
@@ -106,12 +106,27 @@
 #define DDD(_fmt, ...) ED("--DDD-- " _fmt, ##__VA_ARGS__)
 
 #define _GNU_SOURCE// for CPU_SET() etc
+#include 
+#include 
+#include 
+#include  /* log, exp etc. */
+#include 
+#ifdef __FreeBSD__
+#include  /* pthread w/ affinity */
+#include  /* cpu_set */
+#endif /* __FreeBSD__ */
+#include 
 #include 
-#define NETMAP_WITH_LIBS
-#include 
+#include 
+#include  /* memcpy */
+#include 
+#include 
+#include 
 #include 
+#include  // setpriority
+#include 
+#include 
 
-
 /*
  *
  * A packet in the queue is q_pkt plus the payload.
@@ -242,15 +257,6 @@ static struct nm_pcap_file *readpcap(const char *fn);
 static void destroy_pcap(struct nm_pcap_file *file);
 
 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include  /* memcpy */
-
-#include 
-
 #define NS_SCALE 10UL  /* nanoseconds in 1s */
 
 static void destroy_pcap(struct nm_pcap_file *pf)
@@ -435,18 +441,6 @@ static int verbose = 0;
 
 static int do_abort = 0;
 
-#include 
-#include 
-#include 
-#include 
-
-#include  // setpriority
-
-#ifdef __FreeBSD__
-#include  /* pthread w/ affinity */
-#include  /* cpu_set */
-#endif /* __FreeBSD__ */
-
 #ifdef linux
 #define cpuset_tcpu_set_t
 #endif
@@ -566,7 +560,7 @@ struct _qs { /* shared queue */
struct nm_pcap_file *pcap;  /* the pcap struct */
 
/* parameters for reading from the netmap port */
-   struct nm_desc *src_port;   /* netmap descriptor */
+   struct nmport_d *src_port;  /* netmap descriptor */
const char *prod_ifname;/* interface name or pcap file */
struct netmap_ring *rxring; /* current ring being handled */
uint32_tsi; /* ring index */
@@ -640,8 +634,8 @@ struct pipe_args {
int cons_core;  /* core for cons() */
int prod_core;  /* core for prod() */
 
-   struct nm_desc *pa; /* netmap descriptor */
-   struct nm_desc *pb;
+   struct nmport_d *pa;/* netmap descriptor */
+   struct nmport_d *pb;
 
struct _qs  q;
 };
@@ -843,7 +837,7 @@ fail:
 if (q->buf != NULL) {
free(q->buf);
 }
-nm_close(pa->pb);
+nmport_close(pa->pb);
 return (NULL);
 }
 
@@ -893,7 +887,7 @@ cons(void *_pa)
continue;
}
/* XXX copy is inefficient but simple */
-   if (nm_inject(pa->pb, (char *)(p + 1), p->pktlen) == 0) {
+   if (nmport_inject(pa->pb, (char *)(p + 1), p->pktlen) == 0) {
RD(1, "inject failed len %d now %ld tx %ld h %ld t %ld next %ld",
(int)p->pktlen, (u_long)q->cons_now, (u_long)p->pt_tx,
(u_long)q->_head, (u_long)q->_tail, (u_long)p->next);
@@ -939,7 +933,7 @@ nmreplay_main(void *_a)
 pcap_prod((void*)a);
 destroy_pcap(q->pcap);
 q->pcap = NULL;
-a->pb = nm_open(q->cons_ifname, NULL, 0, NULL);
+a->pb = nmport_open(q->cons_ifname);
 if (a->pb == NULL) {
EEE("cannot open netmap on %s", q->cons_ifname);
do_abort = 1; // XXX any better way ?
@@ -1372,7 +1366,6 @@ parse_bw(const char *arg)
  * 24 useful random bits.
  */
 
-#include  /* log, exp etc. */
 static inline uint64_t
 my_random24(void)  /* 24 useful bits */
 {
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r367933 - head/tools/tools/netmap

2020-11-22 Thread Vincenzo Maffione
Author: vmaffione
Date: Sun Nov 22 09:28:50 2020
New Revision: 367933
URL: https://svnweb.freebsd.org/changeset/base/367933

Log:
  netmap: lb: switch to libnetmap
  
  Use the newer libnetmap (included in base) rather than the older
  nm_open()/nm_close() defined in netmap_user.h
  
  MFC after:3 days

Modified:
  head/tools/tools/netmap/lb.c
  head/tools/tools/netmap/pkt_hash.c

Modified: head/tools/tools/netmap/lb.c
==
--- head/tools/tools/netmap/lb.cSun Nov 22 09:20:08 2020
(r367932)
+++ head/tools/tools/netmap/lb.cSun Nov 22 09:28:50 2020
(r367933)
@@ -23,21 +23,22 @@
  * SUCH DAMAGE.
  */
 /* $FreeBSD$ */
-#include 
-#include 
 #include 
-#include 
+#include 
 #include 
+#include 
+#include /* htonl */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
 #include 
-
-#define NETMAP_WITH_LIBS
-#include 
+#include 
 #include 
+#include 
 
-#include /* htonl */
-
-#include 
-
 #include "pkt_hash.h"
 #include "ctrs.h"
 
@@ -86,12 +87,12 @@ struct compact_ipv6_hdr {
 #define DEF_BATCH  2048
 #define DEF_WAIT_LINK  2
 #define DEF_STATS_INT  600
-#define BUF_REVOKE 100
+#define BUF_REVOKE 150
 #define STAT_MSG_MAXSIZE 1024
 
 static struct {
-   char ifname[MAX_IFNAMELEN];
-   char base_name[MAX_IFNAMELEN];
+   char ifname[MAX_IFNAMELEN + 1];
+   char base_name[MAX_IFNAMELEN + 1];
int netmap_fd;
uint16_t output_rings;
uint16_t num_groups;
@@ -173,7 +174,7 @@ struct port_des {
unsigned int last_sync;
uint32_t last_tail;
struct overflow_queue *oq;
-   struct nm_desc *nmd;
+   struct nmport_d *nmd;
struct netmap_ring *ring;
struct group_des *group;
 };
@@ -375,7 +376,7 @@ free_buffers(void)
D("added %d buffers to netmap free list", tot);
 
for (i = 0; i < glob_arg.output_rings + 1; ++i) {
-   nm_close(ports[i].nmd);
+   nmport_close(ports[i].nmd);
}
 }
 
@@ -480,6 +481,28 @@ init_groups(void)
g->last = 1;
 }
 
+
+/* To support packets that span multiple slots (NS_MOREFRAG) we
+ * need to make sure of the following:
+ *
+ * - all fragments of the same packet must go to the same output pipe
+ * - when dropping, all fragments of the same packet must be dropped
+ *
+ * For the former point we remember and reuse the last hash computed
+ * in each input ring, and only update it when NS_MOREFRAG was not
+ * set in the last received slot (this marks the start of a new packet).
+ *
+ * For the latter point, we only update the output ring head pointer
+ * when an entire packet has been forwarded. We keep a shadow_head
+ * pointer to know where to put the next partial fragment and,
+ * when the need to drop arises, we roll it back to head.
+ */
+struct morefrag {
+   uint16_t last_flag; /* for intput rings */
+   uint32_t last_hash; /* for input rings */
+   uint32_t shadow_head;   /* for output rings */
+};
+
 /* push the packet described by slot rs to the group g.
  * This may cause other buffers to be pushed down the
  * chain headed by g.
@@ -493,21 +516,28 @@ forward_packet(struct group_des *g, struct netmap_slot
struct port_des *port = &g->ports[output_port];
struct netmap_ring *ring = port->ring;
struct overflow_queue *q = port->oq;
+   struct morefrag *mf = (struct morefrag *)ring->sem;
+   uint16_t curmf = rs->flags & NS_MOREFRAG;
 
/* Move the packet to the output pipe, unless there is
 * either no space left on the ring, or there is some
 * packet still in the overflow queue (since those must
 * take precedence over the new one)
*/
-   if (ring->head != ring->tail && (q == NULL || oq_empty(q))) {
-   struct netmap_slot *ts = &ring->slot[ring->head];
+   if (mf->shadow_head != ring->tail && (q == NULL || oq_empty(q))) {
+   struct netmap_slot *ts = &ring->slot[mf->shadow_head];
struct netmap_slot old_slot = *ts;
 
ts->buf_idx = rs->buf_idx;
ts->len = rs->len;
-   ts->flags |= NS_BUF_CHANGED;
+   ts->flags = rs->flags | NS_BUF_CHANGED;
ts->ptr = rs->ptr;
-   ring->head = nm_ring_next(ring, ring->head);
+   mf->shadow_head = nm_ring_next(ring, mf->shadow_head);
+   if (!curmf) {
+   ring->head = mf->shadow_head;
+   }
+   ND("curmf %2x ts->flags %2x shadow_head %3u head %3u tail %3u",
+   curmf, ts->flags, mf->shadow_head, ring->head, 
ring->tail);
port->ctr.bytes += rs->len;
port->ctr.pkts++;
forwarded++;
@@ -516,9 +546,20 @@ forward_packet(struct group_des *g, struct netmap_slot
 
/* use the overflow queue, if available */
if 

svn commit: r367932 - head/tools/tools/netmap

2020-11-22 Thread Vincenzo Maffione
Author: vmaffione
Date: Sun Nov 22 09:20:08 2020
New Revision: 367932
URL: https://svnweb.freebsd.org/changeset/base/367932

Log:
  netmap: pkt-gen: switch to libnetmap
  
  Use the newer libnetmap (included in base) rather than the older
  nm_open()/nm_close() defined in netmap_user.h

Modified:
  head/tools/tools/netmap/pkt-gen.c

Modified: head/tools/tools/netmap/pkt-gen.c
==
--- head/tools/tools/netmap/pkt-gen.c   Sun Nov 22 09:10:12 2020
(r367931)
+++ head/tools/tools/netmap/pkt-gen.c   Sun Nov 22 09:20:08 2020
(r367932)
@@ -38,36 +38,40 @@
  */
 
 #define _GNU_SOURCE/* for CPU_SET() */
-#include 
-#define NETMAP_WITH_LIBS
-#include 
-
-#include  // isprint()
-#include // sysconf()
-#include 
 #include  /* ntohs */
-#ifndef _WIN32
-#include /* sysctl */
-#endif
+#include 
+#include  // isprint()
+#include 
+#include 
 #include/* getifaddrs */
+#include 
+#include 
 #include 
 #include 
 #include 
-#include 
 #include 
+#include 
+#ifndef NO_PCAP
+#include 
+#endif
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#if !defined(_WIN32) && !defined(linux)
+#include /* sysctl */
+#endif
+#include 
+#include // sysconf()
 #ifdef linux
 #define IPV6_VERSION   0x60
 #define IPV6_DEFHLIM   64
 #endif
-#include 
-#include 
 
-#include 
-
-#ifndef NO_PCAP
-#include 
-#endif
-
 #include "ctrs.h"
 
 static void usage(int);
@@ -236,7 +240,8 @@ struct mac_range {
 };
 
 /* ifname can be netmap:foo- */
-#define MAX_IFNAMELEN  64  /* our buffer for ifname */
+#define MAX_IFNAMELEN  512 /* our buffer for ifname */
+//#define MAX_PKTSIZE  1536
 #define MAX_PKTSIZEMAX_BODYSIZE/* XXX: + IP_HDR + ETH_HDR */
 
 /* compact timestamp to fit into 60 byte packet. (enough to obtain RTT) */
@@ -288,7 +293,8 @@ struct glob_arg {
 
int affinity;
int main_fd;
-   struct nm_desc *nmd;
+   struct nmport_d *nmd;
+   uint32_t orig_mode;
int report_interval;/* milliseconds between prints */
void *(*td_body)(void *);
int td_type;
@@ -322,7 +328,7 @@ struct targ {
int completed;
int cancel;
int fd;
-   struct nm_desc *nmd;
+   struct nmport_d *nmd;
/* these ought to be volatile, but they are
 * only sampled and errors should not accumulate
 */
@@ -515,17 +521,21 @@ extract_mac_range(struct mac_range *r)
 static int
 get_if_mtu(const struct glob_arg *g)
 {
-   char ifname[IFNAMSIZ];
struct ifreq ifreq;
int s, ret;
+   const char *ifname = g->nmd->hdr.nr_name;
+   size_t len;
 
-   if (!strncmp(g->ifname, "netmap:", 7) && !strchr(g->ifname, '{')
-   && !strchr(g->ifname, '}')) {
-   /* Parse the interface name and ask the kernel for the
-* MTU value. */
-   strncpy(ifname, g->ifname+7, IFNAMSIZ-1);
-   ifname[strcspn(ifname, "-*^{}/@")] = '\0';
+   if (!strncmp(g->ifname, "netmap:", 7) && !strchr(ifname, '{')
+   && !strchr(ifname, '}')) {
 
+   len = strlen(ifname);
+
+   if (len > IFNAMSIZ) {
+   D("'%s' too long, cannot ask for MTU", ifname);
+   return -1;
+   }
+
s = socket(AF_INET, SOCK_DGRAM, 0);
if (s < 0) {
D("socket() failed: %s", strerror(errno));
@@ -533,13 +543,15 @@ get_if_mtu(const struct glob_arg *g)
}
 
memset(&ifreq, 0, sizeof(ifreq));
-   strncpy(ifreq.ifr_name, ifname, IFNAMSIZ);
+   memcpy(ifreq.ifr_name, ifname, len);
 
ret = ioctl(s, SIOCGIFMTU, &ifreq);
if (ret) {
D("ioctl(SIOCGIFMTU) failed: %s", strerror(errno));
}
 
+   close(s);
+
return ifreq.ifr_mtu;
}
 
@@ -620,7 +632,7 @@ system_ncpus(void)
  * and #rx-rings.
  */
 static int
-parse_nmr_config(const char* conf, struct nmreq *nmr)
+parse_nmr_config(const char* conf, struct nmreq_register *nmr)
 {
char *w, *tok;
int i, v;
@@ -654,9 +666,7 @@ parse_nmr_config(const char* conf, struct nmreq *nmr)
nmr->nr_tx_rings, nmr->nr_tx_slots,
nmr->nr_rx_rings, nmr->nr_rx_slots);
free(w);
-   return (nmr->nr_tx_rings || nmr->nr_tx_slots ||
-   nmr->nr_rx_rings || nmr->nr_rx_slots) ?
-   NM_OPEN_RING_CFG : 0;
+   return 0;
 }
 
 
@@ -1108,20 +1118,22 @@ initialize_packet(struct targ *targ)
 static void
 get_vnet_hdr_len(struct glob_arg *g)
 {
-   struct nmreq req;
+   struct nmreq_header hdr;
+   struct nmreq_port_hdr ph;
int err;
 
-   memset(&req, 0, sizeof(req));
-   bcopy(g->nmd->req.nr_name, req.nr_name, sizeof(req.nr_na

svn commit: r367931 - head/tools/tools/netmap

2020-11-22 Thread Vincenzo Maffione
Author: vmaffione
Date: Sun Nov 22 09:10:12 2020
New Revision: 367931
URL: https://svnweb.freebsd.org/changeset/base/367931

Log:
  netmap: bridge: switch to libnetmap
  
  Use the newer libnetmap (included in base) rather than the older
  nm_open()/nm_close() defined in netmap_user.h

Modified:
  head/tools/tools/netmap/Makefile
  head/tools/tools/netmap/bridge.c

Modified: head/tools/tools/netmap/Makefile
==
--- head/tools/tools/netmap/MakefileSun Nov 22 05:47:45 2020
(r367930)
+++ head/tools/tools/netmap/MakefileSun Nov 22 09:10:12 2020
(r367931)
@@ -11,7 +11,7 @@ MAN=
 .include 
 .include 
 
-LDFLAGS += -lpthread
+LDFLAGS += -lpthread -lnetmap
 .ifdef WITHOUT_PCAP
 CFLAGS += -DNO_PCAP
 .else
@@ -27,7 +27,7 @@ pkt-gen: pkt-gen.o
$(CC) $(CFLAGS) -o pkt-gen pkt-gen.o $(LDFLAGS)
 
 bridge: bridge.o
-   $(CC) $(CFLAGS) -o bridge bridge.o
+   $(CC) $(CFLAGS) -o bridge bridge.o $(LDFLAGS)
 
 nmreplay: nmreplay.o
$(CC) $(CFLAGS) -o nmreplay nmreplay.o $(LDFLAGS)

Modified: head/tools/tools/netmap/bridge.c
==
--- head/tools/tools/netmap/bridge.cSun Nov 22 05:47:45 2020
(r367930)
+++ head/tools/tools/netmap/bridge.cSun Nov 22 09:10:12 2020
(r367931)
@@ -10,9 +10,12 @@
  */
 
 #include 
-#define NETMAP_WITH_LIBS
-#include 
 #include 
+#include 
+#include 
+#include 
+#include 
+#include 
 
 static int verbose = 0;
 
@@ -32,7 +35,7 @@ sigint_h(int sig)
  * how many packets on this set of queues ?
  */
 static int
-pkt_queued(struct nm_desc *d, int tx)
+pkt_queued(struct nmport_d *d, int tx)
 {
u_int i, tot = 0;
 
@@ -61,8 +64,8 @@ process_rings(struct netmap_ring *rxring, struct netma
if (rxring->flags || txring->flags)
D("%s rxflags %x txflags %x",
msg, rxring->flags, txring->flags);
-   j = rxring->cur; /* RX */
-   k = txring->cur; /* TX */
+   j = rxring->head; /* RX */
+   k = txring->head; /* TX */
m = nm_ring_space(rxring);
if (m < limit)
limit = m;
@@ -115,11 +118,11 @@ process_rings(struct netmap_ring *rxring, struct netma
 
 /* move packts from src to destination */
 static int
-move(struct nm_desc *src, struct nm_desc *dst, u_int limit)
+move(struct nmport_d *src, struct nmport_d *dst, u_int limit)
 {
struct netmap_ring *txring, *rxring;
u_int m = 0, si = src->first_rx_ring, di = dst->first_tx_ring;
-   const char *msg = (src->req.nr_flags == NR_REG_SW) ?
+   const char *msg = (src->reg.nr_flags == NR_REG_SW) ?
"host->net" : "net->host";
 
while (si <= src->last_rx_ring && di <= dst->last_tx_ring) {
@@ -175,7 +178,7 @@ main(int argc, char **argv)
struct pollfd pollfd[2];
int ch;
u_int burst = 1024, wait_link = 4;
-   struct nm_desc *pa = NULL, *pb = NULL;
+   struct nmport_d *pa = NULL, *pb = NULL;
char *ifa = NULL, *ifb = NULL;
char ifabuf[64] = { 0 };
int loopback = 0;
@@ -252,16 +255,16 @@ main(int argc, char **argv)
} else {
/* two different interfaces. Take all rings on if1 */
}
-   pa = nm_open(ifa, NULL, 0, NULL);
+   pa = nmport_open(ifa);
if (pa == NULL) {
D("cannot open %s", ifa);
return (1);
}
/* try to reuse the mmap() of the first interface, if possible */
-   pb = nm_open(ifb, NULL, NM_OPEN_NO_MMAP, pa);
+   pb = nmport_open(ifb);
if (pb == NULL) {
D("cannot open %s", ifb);
-   nm_close(pa);
+   nmport_close(pa);
return (1);
}
zerocopy = zerocopy && (pa->mem == pb->mem);
@@ -275,8 +278,8 @@ main(int argc, char **argv)
D("Wait %d secs for link to come up...", wait_link);
sleep(wait_link);
D("Ready to go, %s 0x%x/%d <-> %s 0x%x/%d.",
-   pa->req.nr_name, pa->first_rx_ring, pa->req.nr_rx_rings,
-   pb->req.nr_name, pb->first_rx_ring, pb->req.nr_rx_rings);
+   pa->hdr.nr_name, pa->first_rx_ring, pa->reg.nr_rx_rings,
+   pb->hdr.nr_name, pb->first_rx_ring, pb->reg.nr_rx_rings);
 
/* main loop */
signal(SIGINT, sigint_h);
@@ -320,12 +323,12 @@ main(int argc, char **argv)
pollfd[0].events,
pollfd[0].revents,
pkt_queued(pa, 0),
-   NETMAP_RXRING(pa->nifp, pa->cur_rx_ring)->cur,
+   NETMAP_RXRING(pa->nifp, pa->cur_rx_ring)->head,
pkt_queued(pa, 1),
pollfd[1].events,
pollfd[1].revents,
pkt_queued(pb, 0),
-