svn commit: r324050 - head/sys/netinet

2017-09-26 Thread Sepherosa Ziehau
Author: sephe
Date: Wed Sep 27 05:52:37 2017
New Revision: 324050
URL: https://svnweb.freebsd.org/changeset/base/324050

Log:
  tcp: Don't "negotiate" MSS.
  
  _NO_ OSes actually "negotiate" MSS.
  
  RFC 879:
  "... This Maximum Segment Size (MSS) announcement (often mistakenly
  called a negotiation) ..."
  
  This negotiation behaviour was introduced 11 years ago by r159955
  without any explaination about why FreeBSD had to "negotiate" MSS:
  
  In syncache_respond() do not reply with a MSS that is larger than what
  the peer announced to us but make it at least tcp_minmss in size.
  
  Sponsored by:   TCP/IP Optimization Fundraise 2005
  
  The tcp_minmss behaviour is still kept.
  
  Syncookie fix was prodded by tuexen, who also helped to test this
  patch w/ packetdrill.
  
  Reviewed by:  tuexen, karels, bz (previous version)
  MFC after:2 week
  Sponsored by: Microsoft
  Differential Revision:https://reviews.freebsd.org/D12430

Modified:
  head/sys/netinet/tcp_syncache.c

Modified: head/sys/netinet/tcp_syncache.c
==
--- head/sys/netinet/tcp_syncache.c Wed Sep 27 05:44:50 2017
(r324049)
+++ head/sys/netinet/tcp_syncache.c Wed Sep 27 05:52:37 2017
(r324050)
@@ -1634,9 +1634,7 @@ syncache_respond(struct syncache *sc, struct syncache_
tlen = hlen + sizeof(struct tcphdr);
 
/* Determine MSS we advertize to other end of connection. */
-   mssopt = tcp_mssopt(>sc_inc);
-   if (sc->sc_peer_mss)
-   mssopt = max( min(sc->sc_peer_mss, mssopt), V_tcp_minmss);
+   mssopt = max(tcp_mssopt(>sc_inc), V_tcp_minmss);
 
/* XXX: Assume that the entire packet will fit in a header mbuf. */
KASSERT(max_linkhdr + tlen + TCP_MAXOLEN <= MHLEN,
@@ -1985,7 +1983,7 @@ syncookie_mac(struct in_conninfo *inc, tcp_seq irs, ui
 static tcp_seq
 syncookie_generate(struct syncache_head *sch, struct syncache *sc)
 {
-   u_int i, mss, secbit, wscale;
+   u_int i, secbit, wscale;
uint32_t iss, hash;
uint8_t *secbits;
union syncookie cookie;
@@ -1995,8 +1993,8 @@ syncookie_generate(struct syncache_head *sch, struct s
cookie.cookie = 0;
 
/* Map our computed MSS into the 3-bit index. */
-   mss = min(tcp_mssopt(>sc_inc), max(sc->sc_peer_mss, V_tcp_minmss));
-   for (i = nitems(tcp_sc_msstab) - 1; tcp_sc_msstab[i] > mss && i > 0;
+   for (i = nitems(tcp_sc_msstab) - 1;
+tcp_sc_msstab[i] > sc->sc_peer_mss && i > 0;
 i--)
;
cookie.flags.mss_idx = i;
___
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: r324049 - head/sys/dev/hyperv/netvsc

2017-09-26 Thread Sepherosa Ziehau
Author: sephe
Date: Wed Sep 27 05:44:50 2017
New Revision: 324049
URL: https://svnweb.freebsd.org/changeset/base/324049

Log:
  hyperv/hn: Fix UDP checksum offload issue in Azure.
  
  UDP checksum offload does not work in Azure if following conditions are
  met:
  - sizeof(IP hdr + UDP hdr + payload) > 1420.
  - IP_DF is not set in IP hdr
  
  Use software checksum for UDP datagrams falling into this category.
  
  Add two tunables to disable UDP/IPv4 and UDP/IPv6 checksum offload, in
  case something unexpected happened.
  
  MFC after:1 week
  Sponsored by: Microsoft
  Differential Revision:https://reviews.freebsd.org/D12429

Modified:
  head/sys/dev/hyperv/netvsc/if_hn.c

Modified: head/sys/dev/hyperv/netvsc/if_hn.c
==
--- head/sys/dev/hyperv/netvsc/if_hn.c  Wed Sep 27 04:42:40 2017
(r324048)
+++ head/sys/dev/hyperv/netvsc/if_hn.c  Wed Sep 27 05:44:50 2017
(r324049)
@@ -62,6 +62,7 @@ __FBSDID("$FreeBSD$");
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -460,6 +461,35 @@ SYSCTL_INT(_hw_hn, OID_AUTO, trust_hostip, CTLFLAG_RDT
 "Trust ip packet verification on host side, "
 "when csum info is missing (global setting)");
 
+/*
+ * Offload UDP/IPv4 checksum.
+ */
+static int hn_enable_udp4cs = 1;
+SYSCTL_INT(_hw_hn, OID_AUTO, enable_udp4cs, CTLFLAG_RDTUN,
+_enable_udp4cs, 0, "Offload UDP/IPv4 checksum");
+
+/*
+ * Offload UDP/IPv6 checksum.
+ */
+static int hn_enable_udp6cs = 1;
+SYSCTL_INT(_hw_hn, OID_AUTO, enable_udp6cs, CTLFLAG_RDTUN,
+_enable_udp6cs, 0, "Offload UDP/IPv6 checksum");
+
+/* Stats. */
+static counter_u64_t   hn_udpcs_fixup;
+SYSCTL_COUNTER_U64(_hw_hn, OID_AUTO, udpcs_fixup, CTLFLAG_RW,
+_udpcs_fixup, "# of UDP checksum fixup");
+
+/*
+ * See hn_set_hlen().
+ *
+ * This value is for Azure.  For Hyper-V, set this above
+ * 65536 to disable UDP datagram checksum fixup.
+ */
+static int hn_udpcs_fixup_mtu = 1420;
+SYSCTL_INT(_hw_hn, OID_AUTO, udpcs_fixup_mtu, CTLFLAG_RWTUN,
+_udpcs_fixup_mtu, 0, "UDP checksum fixup MTU threshold");
+
 /* Limit TSO burst size */
 static int hn_tso_maxlen = IP_MAXPACKET;
 SYSCTL_INT(_hw_hn, OID_AUTO, tso_maxlen, CTLFLAG_RDTUN,
@@ -799,6 +829,27 @@ hn_set_hlen(struct mbuf *m_head)
ip = mtodo(m_head, ehlen);
iphlen = ip->ip_hl << 2;
m_head->m_pkthdr.l3hlen = iphlen;
+
+   /*
+* UDP checksum offload does not work in Azure, if the
+* following conditions meet:
+* - sizeof(IP hdr + UDP hdr + payload) > 1420.
+* - IP_DF is not set in the IP hdr.
+*
+* Fallback to software checksum for these UDP datagrams.
+*/
+   if ((m_head->m_pkthdr.csum_flags & CSUM_IP_UDP) &&
+   m_head->m_pkthdr.len > hn_udpcs_fixup_mtu + ehlen &&
+   (ntohs(ip->ip_off) & IP_DF) == 0) {
+   uint16_t off = ehlen + iphlen;
+
+   counter_u64_add(hn_udpcs_fixup, 1);
+   PULLUP_HDR(m_head, off + sizeof(struct udphdr));
+   *(uint16_t *)(m_head->m_data + off +
+m_head->m_pkthdr.csum_data) = in_cksum_skip(
+   m_head, m_head->m_pkthdr.len, off);
+   m_head->m_pkthdr.csum_flags &= ~CSUM_IP_UDP;
+   }
}
 #endif
 #if defined(INET6) && defined(INET)
@@ -5479,11 +5530,11 @@ hn_fixup_tx_data(struct hn_softc *sc)
csum_assist |= CSUM_IP;
if (sc->hn_caps & HN_CAP_TCP4CS)
csum_assist |= CSUM_IP_TCP;
-   if (sc->hn_caps & HN_CAP_UDP4CS)
+   if ((sc->hn_caps & HN_CAP_UDP4CS) && hn_enable_udp4cs)
csum_assist |= CSUM_IP_UDP;
if (sc->hn_caps & HN_CAP_TCP6CS)
csum_assist |= CSUM_IP6_TCP;
-   if (sc->hn_caps & HN_CAP_UDP6CS)
+   if ((sc->hn_caps & HN_CAP_UDP6CS) && hn_enable_udp6cs)
csum_assist |= CSUM_IP6_UDP;
for (i = 0; i < sc->hn_tx_ring_cnt; ++i)
sc->hn_tx_ring[i].hn_csum_assist = csum_assist;
@@ -7336,6 +7387,8 @@ hn_sysinit(void *arg __unused)
 {
int i;
 
+   hn_udpcs_fixup = counter_u64_alloc(M_WAITOK);
+
 #ifdef HN_IFSTART_SUPPORT
/*
 * Don't use ifnet.if_start if transparent VF mode is requested;
@@ -7415,5 +7468,7 @@ hn_sysuninit(void *arg __unused)
if (hn_vfmap != NULL)
free(hn_vfmap, M_DEVBUF);
rm_destroy(_vfmap_lock);
+
+   counter_u64_free(hn_udpcs_fixup);
 }
 SYSUNINIT(hn_sysuninit, SI_SUB_DRIVERS, SI_ORDER_SECOND, hn_sysuninit, NULL);
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, 

svn commit: r324048 - head/sys/dev/hyperv/netvsc

2017-09-26 Thread Sepherosa Ziehau
Author: sephe
Date: Wed Sep 27 04:42:40 2017
New Revision: 324048
URL: https://svnweb.freebsd.org/changeset/base/324048

Log:
  hyperv/hn: Set tcp header offset for CSUM/LSO offloading.
  
  No observable effect; better safe than sorry.
  
  MFC after:1 week
  Sponsored by: Microsoft
  Differential Revision:https://reviews.freebsd.org/D12417

Modified:
  head/sys/dev/hyperv/netvsc/if_hn.c
  head/sys/dev/hyperv/netvsc/ndis.h

Modified: head/sys/dev/hyperv/netvsc/if_hn.c
==
--- head/sys/dev/hyperv/netvsc/if_hn.c  Wed Sep 27 01:47:54 2017
(r324047)
+++ head/sys/dev/hyperv/netvsc/if_hn.c  Wed Sep 27 04:42:40 2017
(r324048)
@@ -727,6 +727,7 @@ hn_tso_fixup(struct mbuf *m_head)
ehlen = ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN;
else
ehlen = ETHER_HDR_LEN;
+   m_head->m_pkthdr.l2hlen = ehlen;
 
 #ifdef INET
if (m_head->m_pkthdr.csum_flags & CSUM_IP_TSO) {
@@ -736,6 +737,7 @@ hn_tso_fixup(struct mbuf *m_head)
PULLUP_HDR(m_head, ehlen + sizeof(*ip));
ip = mtodo(m_head, ehlen);
iphlen = ip->ip_hl << 2;
+   m_head->m_pkthdr.l3hlen = iphlen;
 
PULLUP_HDR(m_head, ehlen + iphlen + sizeof(*th));
th = mtodo(m_head, ehlen + iphlen);
@@ -759,6 +761,7 @@ hn_tso_fixup(struct mbuf *m_head)
m_freem(m_head);
return (NULL);
}
+   m_head->m_pkthdr.l3hlen = sizeof(*ip6);
 
PULLUP_HDR(m_head, ehlen + sizeof(*ip6) + sizeof(*th));
th = mtodo(m_head, ehlen + sizeof(*ip6));
@@ -768,41 +771,34 @@ hn_tso_fixup(struct mbuf *m_head)
}
 #endif
return (m_head);
-
 }
 
 /*
  * NOTE: If this function failed, the m_head would be freed.
  */
 static __inline struct mbuf *
-hn_check_tcpsyn(struct mbuf *m_head, int *tcpsyn)
+hn_set_hlen(struct mbuf *m_head)
 {
const struct ether_vlan_header *evl;
-   const struct tcphdr *th;
int ehlen;
 
-   *tcpsyn = 0;
-
PULLUP_HDR(m_head, sizeof(*evl));
evl = mtod(m_head, const struct ether_vlan_header *);
if (evl->evl_encap_proto == ntohs(ETHERTYPE_VLAN))
ehlen = ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN;
else
ehlen = ETHER_HDR_LEN;
+   m_head->m_pkthdr.l2hlen = ehlen;
 
 #ifdef INET
-   if (m_head->m_pkthdr.csum_flags & CSUM_IP_TCP) {
+   if (m_head->m_pkthdr.csum_flags & (CSUM_IP_TCP | CSUM_IP_UDP)) {
const struct ip *ip;
int iphlen;
 
PULLUP_HDR(m_head, ehlen + sizeof(*ip));
ip = mtodo(m_head, ehlen);
iphlen = ip->ip_hl << 2;
-
-   PULLUP_HDR(m_head, ehlen + iphlen + sizeof(*th));
-   th = mtodo(m_head, ehlen + iphlen);
-   if (th->th_flags & TH_SYN)
-   *tcpsyn = 1;
+   m_head->m_pkthdr.l3hlen = iphlen;
}
 #endif
 #if defined(INET6) && defined(INET)
@@ -814,18 +810,36 @@ hn_check_tcpsyn(struct mbuf *m_head, int *tcpsyn)
 
PULLUP_HDR(m_head, ehlen + sizeof(*ip6));
ip6 = mtodo(m_head, ehlen);
-   if (ip6->ip6_nxt != IPPROTO_TCP)
-   return (m_head);
-
-   PULLUP_HDR(m_head, ehlen + sizeof(*ip6) + sizeof(*th));
-   th = mtodo(m_head, ehlen + sizeof(*ip6));
-   if (th->th_flags & TH_SYN)
-   *tcpsyn = 1;
+   if (ip6->ip6_nxt != IPPROTO_TCP) {
+   m_freem(m_head);
+   return (NULL);
+   }
+   m_head->m_pkthdr.l3hlen = sizeof(*ip6);
}
 #endif
return (m_head);
 }
 
+/*
+ * NOTE: If this function failed, the m_head would be freed.
+ */
+static __inline struct mbuf *
+hn_check_tcpsyn(struct mbuf *m_head, int *tcpsyn)
+{
+   const struct tcphdr *th;
+   int ehlen, iphlen;
+
+   *tcpsyn = 0;
+   ehlen = m_head->m_pkthdr.l2hlen;
+   iphlen = m_head->m_pkthdr.l3hlen;
+
+   PULLUP_HDR(m_head, ehlen + iphlen + sizeof(*th));
+   th = mtodo(m_head, ehlen + iphlen);
+   if (th->th_flags & TH_SYN)
+   *tcpsyn = 1;
+   return (m_head);
+}
+
 #undef PULLUP_HDR
 
 #endif /* INET6 || INET */
@@ -3010,7 +3024,8 @@ hn_encap(struct ifnet *ifp, struct hn_tx_ring *txr, st
NDIS_LSO2_INFO_SIZE, NDIS_PKTINFO_TYPE_LSO);
 #ifdef INET
if (m_head->m_pkthdr.csum_flags & CSUM_IP_TSO) {
-   *pi_data = NDIS_LSO2_INFO_MAKEIPV4(0,
+   *pi_data = NDIS_LSO2_INFO_MAKEIPV4(
+   m_head->m_pkthdr.l2hlen + m_head->m_pkthdr.l3hlen,
m_head->m_pkthdr.tso_segsz);
}
 #endif
@@ -3019,7 +3034,8 @@ hn_encap(struct ifnet *ifp, struct hn_tx_ring *txr, st
 

svn commit: r324045 - head/sys/kern

2017-09-26 Thread Mateusz Guzik
Author: mjg
Date: Wed Sep 27 01:31:52 2017
New Revision: 324045
URL: https://svnweb.freebsd.org/changeset/base/324045

Log:
  sysctl: remove target buffer read/write checks prior to calling the handler
  
  Said checks were inherently racy anyway as jokers could unmap target areas
  before the handler got around to accessing them.
  
  This saves time by avoiding locking the address space.
  
  MFC after:1 week

Modified:
  head/sys/kern/kern_sysctl.c

Modified: head/sys/kern/kern_sysctl.c
==
--- head/sys/kern/kern_sysctl.c Wed Sep 27 01:27:43 2017(r324044)
+++ head/sys/kern/kern_sysctl.c Wed Sep 27 01:31:52 2017(r324045)
@@ -2061,16 +2061,9 @@ userland_sysctl(struct thread *td, int *name, u_int na
}
}
req.validlen = req.oldlen;
+   req.oldptr = old;
 
-   if (old) {
-   if (!useracc(old, req.oldlen, VM_PROT_WRITE))
-   return (EFAULT);
-   req.oldptr= old;
-   }
-
if (new != NULL) {
-   if (!useracc(new, newlen, VM_PROT_READ))
-   return (EFAULT);
req.newlen = newlen;
req.newptr = 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"


svn commit: r324044 - head/sys/kern

2017-09-26 Thread Mateusz Guzik
Author: mjg
Date: Wed Sep 27 01:27:43 2017
New Revision: 324044
URL: https://svnweb.freebsd.org/changeset/base/324044

Log:
  Annotate sysctlmemlock with __exclusive_cache_line.
  
  MFC after:1 week

Modified:
  head/sys/kern/kern_sysctl.c

Modified: head/sys/kern/kern_sysctl.c
==
--- head/sys/kern/kern_sysctl.c Wed Sep 27 01:12:47 2017(r324043)
+++ head/sys/kern/kern_sysctl.c Wed Sep 27 01:27:43 2017(r324044)
@@ -88,7 +88,7 @@ static MALLOC_DEFINE(M_SYSCTLTMP, "sysctltmp", "sysctl
  * sysctl requests larger than a single page via an exclusive lock.
  */
 static struct rmlock sysctllock;
-static struct sx sysctlmemlock;
+static struct sx __exclusive_cache_line sysctlmemlock;
 
 #defineSYSCTL_WLOCK()  rm_wlock()
 #defineSYSCTL_WUNLOCK()rm_wunlock()
___
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: r324043 - in head: . share/man/man9

2017-09-26 Thread Mateusz Guzik
Author: mjg
Date: Wed Sep 27 01:12:47 2017
New Revision: 324043
URL: https://svnweb.freebsd.org/changeset/base/324043

Log:
  Remove manpage entries about crshared(9)
  
  The function itself was removed years ago in r272546
  
  Submitted by: Paulm 
  MFC after:2 weeks

Modified:
  head/ObsoleteFiles.inc
  head/share/man/man9/Makefile
  head/share/man/man9/ucred.9

Modified: head/ObsoleteFiles.inc
==
--- head/ObsoleteFiles.inc  Wed Sep 27 01:03:00 2017(r324042)
+++ head/ObsoleteFiles.inc  Wed Sep 27 01:12:47 2017(r324043)
@@ -38,6 +38,8 @@
 #   xargs -n1 | sort | uniq -d;
 # done
 
+# 20170927: crshared
+OLD_FILES+=usr/share/man/man9/crshared.9.gz
 # 20170927: procctl
 OLD_FILES+=usr/share/man/man8/procctl.8.gz
 OLD_FILES+=usr/sbin/procctl

Modified: head/share/man/man9/Makefile
==
--- head/share/man/man9/MakefileWed Sep 27 01:03:00 2017
(r324042)
+++ head/share/man/man9/MakefileWed Sep 27 01:12:47 2017
(r324043)
@@ -1929,7 +1929,6 @@ MLINKS+=ucred.9 cred_update_thread.9 \
ucred.9 crget.9 \
ucred.9 crhold.9 \
ucred.9 crsetgroups.9 \
-   ucred.9 crshared.9 \
ucred.9 cru2x.9
 MLINKS+=uidinfo.9 uifind.9 \
uidinfo.9 uifree.9 \

Modified: head/share/man/man9/ucred.9
==
--- head/share/man/man9/ucred.9 Wed Sep 27 01:03:00 2017(r324042)
+++ head/share/man/man9/ucred.9 Wed Sep 27 01:12:47 2017(r324043)
@@ -26,7 +26,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd June 19, 2009
+.Dd September 27, 2017
 .Dt UCRED 9
 .Os
 .Sh NAME
@@ -34,7 +34,6 @@
 .Nm crget ,
 .Nm crhold ,
 .Nm crfree ,
-.Nm crshared ,
 .Nm crcopy ,
 .Nm crdup ,
 .Nm cru2x ,
@@ -49,8 +48,6 @@
 .Fn crhold "struct ucred *cr"
 .Ft void
 .Fn crfree "struct ucred *cr"
-.Ft int
-.Fn crshared "struct ucred *cr"
 .Ft void
 .Fn crcopy "struct ucred *dest" "struct ucred *src"
 .Ft "struct ucred *"
@@ -86,12 +83,6 @@ function decreases the reference count on the credenti
 If the count drops to 0, the storage for the structure is freed.
 .Pp
 The
-.Fn crshared
-function returns true if the credential is shared.
-A credential is considered to be shared if its reference
-count is greater than one.
-.Pp
-The
 .Fn crcopy
 function copies the contents of the source (template)
 credential into the destination template.
@@ -170,10 +161,6 @@ and
 all return a pointer to a
 .Vt ucred
 structure.
-.Pp
-.Fn crshared
-returns 0 if the credential has a reference count greater than 1;
-otherwise, 1 is returned.
 .Sh USAGE NOTES
 As of
 .Fx 5.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"


svn commit: r324042 - in head: . share/man/man5 targets/pseudo/userland usr.sbin usr.sbin/procctl

2017-09-26 Thread Mateusz Guzik
Author: mjg
Date: Wed Sep 27 01:03:00 2017
New Revision: 324042
URL: https://svnweb.freebsd.org/changeset/base/324042

Log:
  Whack procctl(8)
  
  It was supposed to provide a recovery mechanism against bugs in procfs's
  long deprecated tracing capabilities.
  
  Remove the tool as a prerequisite to axing the kernel side.
  
  The tracing facility to use is ptrace(2).
  
  MFC after:2 weeks

Deleted:
  head/usr.sbin/procctl/
Modified:
  head/ObsoleteFiles.inc
  head/share/man/man5/procfs.5
  head/targets/pseudo/userland/Makefile.depend
  head/usr.sbin/Makefile

Modified: head/ObsoleteFiles.inc
==
--- head/ObsoleteFiles.inc  Wed Sep 27 00:57:05 2017(r324041)
+++ head/ObsoleteFiles.inc  Wed Sep 27 01:03:00 2017(r324042)
@@ -38,6 +38,9 @@
 #   xargs -n1 | sort | uniq -d;
 # done
 
+# 20170927: procctl
+OLD_FILES+=usr/share/man/man8/procctl.8.gz
+OLD_FILES+=usr/sbin/procctl
 # 20170926: remove unneeded man aliases and locales directory
 OLD_FILES+=usr/share/man/en.ISO8859-1/man1
 OLD_FILES+=usr/share/man/en.ISO8859-1/man2

Modified: head/share/man/man5/procfs.5
==
--- head/share/man/man5/procfs.5Wed Sep 27 00:57:05 2017
(r324041)
+++ head/share/man/man5/procfs.5Wed Sep 27 01:03:00 2017
(r324042)
@@ -196,7 +196,6 @@ file system on
 .Xr mount 2 ,
 .Xr sigaction 2 ,
 .Xr unmount 2 ,
-.Xr procctl 8 ,
 .Xr pseudofs 9
 .Sh AUTHORS
 .An -nosplit

Modified: head/targets/pseudo/userland/Makefile.depend
==
--- head/targets/pseudo/userland/Makefile.dependWed Sep 27 00:57:05 
2017(r324041)
+++ head/targets/pseudo/userland/Makefile.dependWed Sep 27 01:03:00 
2017(r324042)
@@ -708,7 +708,6 @@ DIRDEPS+= \
usr.sbin/pppctl \
usr.sbin/praliases \
usr.sbin/praudit \
-   usr.sbin/procctl \
usr.sbin/prometheus_sysctl_exporter \
usr.sbin/pstat \
usr.sbin/pw \

Modified: head/usr.sbin/Makefile
==
--- head/usr.sbin/Makefile  Wed Sep 27 00:57:05 2017(r324041)
+++ head/usr.sbin/Makefile  Wed Sep 27 01:03:00 2017(r324042)
@@ -61,7 +61,6 @@ SUBDIR=   adduser \
pciconf \
periodic \
powerd \
-   procctl \
prometheus_sysctl_exporter \
pstat \
pw \
___
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: r324041 - in head/sys: kern sys

2017-09-26 Thread Mateusz Guzik
Author: mjg
Date: Wed Sep 27 00:57:05 2017
New Revision: 324041
URL: https://svnweb.freebsd.org/changeset/base/324041

Log:
  mtx: drop the tid argument from _mtx_lock_sleep
  
  tid must be equal to curthread and the target routine was already reading
  it anyway, which is not a problem. Not passing it as a parameter allows for
  a little bit shorter code in callers.
  
  MFC after:1 week

Modified:
  head/sys/kern/kern_mutex.c
  head/sys/sys/mutex.h

Modified: head/sys/kern/kern_mutex.c
==
--- head/sys/kern/kern_mutex.c  Tue Sep 26 23:42:44 2017(r324040)
+++ head/sys/kern/kern_mutex.c  Wed Sep 27 00:57:05 2017(r324041)
@@ -248,7 +248,7 @@ __mtx_lock_flags(volatile uintptr_t *c, int opts, cons
tid = (uintptr_t)curthread;
v = MTX_UNOWNED;
if (!_mtx_obtain_lock_fetch(m, , tid))
-   _mtx_lock_sleep(m, v, tid, opts, file, line);
+   _mtx_lock_sleep(m, v, opts, file, line);
else
LOCKSTAT_PROFILE_OBTAIN_LOCK_SUCCESS(adaptive__acquire,
m, 0, 0, file, line);
@@ -443,15 +443,17 @@ _mtx_trylock_flags_(volatile uintptr_t *c, int opts, c
  */
 #if LOCK_DEBUG > 0
 void
-__mtx_lock_sleep(volatile uintptr_t *c, uintptr_t v, uintptr_t tid, int opts,
-const char *file, int line)
+__mtx_lock_sleep(volatile uintptr_t *c, uintptr_t v, int opts, const char 
*file,
+int line)
 #else
 void
-__mtx_lock_sleep(volatile uintptr_t *c, uintptr_t v, uintptr_t tid)
+__mtx_lock_sleep(volatile uintptr_t *c, uintptr_t v)
 #endif
 {
+   struct thread *td;
struct mtx *m;
struct turnstile *ts;
+   uintptr_t tid;
 #ifdef ADAPTIVE_MUTEXES
volatile struct thread *owner;
 #endif
@@ -473,8 +475,9 @@ __mtx_lock_sleep(volatile uintptr_t *c, uintptr_t v, u
 #if defined(KDTRACE_HOOKS) || defined(LOCK_PROFILING)
int doing_lockprof;
 #endif
-
-   if (SCHEDULER_STOPPED())
+   td = curthread;
+   tid = (uintptr_t)td;
+   if (SCHEDULER_STOPPED_TD(td))
return;
 
 #if defined(ADAPTIVE_MUTEXES)
@@ -486,7 +489,7 @@ __mtx_lock_sleep(volatile uintptr_t *c, uintptr_t v, u
if (__predict_false(v == MTX_UNOWNED))
v = MTX_READ_VALUE(m);
 
-   if (__predict_false(lv_mtx_owner(v) == (struct thread *)tid)) {
+   if (__predict_false(lv_mtx_owner(v) == td)) {
KASSERT((m->lock_object.lo_flags & LO_RECURSABLE) != 0 ||
(opts & MTX_RECURSE) != 0,
("_mtx_lock_sleep: recursed on non-recursive mutex %s @ %s:%d\n",

Modified: head/sys/sys/mutex.h
==
--- head/sys/sys/mutex.hTue Sep 26 23:42:44 2017(r324040)
+++ head/sys/sys/mutex.hWed Sep 27 00:57:05 2017(r324041)
@@ -99,12 +99,12 @@ int _mtx_trylock_flags_(volatile uintptr_t *c, int opt
int line);
 void   mutex_init(void);
 #if LOCK_DEBUG > 0
-void   __mtx_lock_sleep(volatile uintptr_t *c, uintptr_t v, uintptr_t tid,
-   int opts, const char *file, int line);
+void   __mtx_lock_sleep(volatile uintptr_t *c, uintptr_t v, int opts,
+   const char *file, int line);
 void   __mtx_unlock_sleep(volatile uintptr_t *c, int opts, const char *file,
int line);
 #else
-void   __mtx_lock_sleep(volatile uintptr_t *c, uintptr_t v, uintptr_t tid);
+void   __mtx_lock_sleep(volatile uintptr_t *c, uintptr_t v);
 void   __mtx_unlock_sleep(volatile uintptr_t *c);
 #endif
 
@@ -147,13 +147,13 @@ void  thread_lock_flags_(struct thread *, int, const 
ch
 #definemtx_trylock_flags_(m, o, f, l)  
\
_mtx_trylock_flags_(&(m)->mtx_lock, o, f, l)
 #if LOCK_DEBUG > 0
-#define_mtx_lock_sleep(m, v, t, o, f, l)   
\
-   __mtx_lock_sleep(&(m)->mtx_lock, v, t, o, f, l)
+#define_mtx_lock_sleep(m, v, o, f, l)  
\
+   __mtx_lock_sleep(&(m)->mtx_lock, v, o, f, l)
 #define_mtx_unlock_sleep(m, o, f, l)   
\
__mtx_unlock_sleep(&(m)->mtx_lock, o, f, l)
 #else
-#define_mtx_lock_sleep(m, v, t, o, f, l)   
\
-   __mtx_lock_sleep(&(m)->mtx_lock, v, t)
+#define_mtx_lock_sleep(m, v, o, f, l)  
\
+   __mtx_lock_sleep(&(m)->mtx_lock, v)
 #define_mtx_unlock_sleep(m, o, f, l)   
\
__mtx_unlock_sleep(&(m)->mtx_lock)
 #endif
@@ -208,7 +208,7 @@ voidthread_lock_flags_(struct thread *, int, const 
ch
\
if (__predict_false(LOCKSTAT_PROFILE_ENABLED(adaptive__acquire) ||\
!_mtx_obtain_lock_fetch((mp), &_v, _tid)))  \
-   _mtx_lock_sleep((mp), _v, _tid, (opts), (file), 

svn commit: r324040 - in head/sys/fs: nfs nfsclient

2017-09-26 Thread Rick Macklem
Author: rmacklem
Date: Tue Sep 26 23:42:44 2017
New Revision: 324040
URL: https://svnweb.freebsd.org/changeset/base/324040

Log:
  Add major and minor version arguments to nfscl_reqstart().
  
  This patch adds "vers" and "minorvers" arguments to nfscl_reqstart().
  The patch always passes them in as "0" and that implies no change
  in semantics. These arguments will be used by a future commit that
  adds support for the Flexible File Layout.

Modified:
  head/sys/fs/nfs/nfs_var.h
  head/sys/fs/nfs/nfscl.h
  head/sys/fs/nfsclient/nfs_clcomsubs.c
  head/sys/fs/nfsclient/nfs_clrpcops.c

Modified: head/sys/fs/nfs/nfs_var.h
==
--- head/sys/fs/nfs/nfs_var.h   Tue Sep 26 23:24:15 2017(r324039)
+++ head/sys/fs/nfs/nfs_var.h   Tue Sep 26 23:42:44 2017(r324040)
@@ -303,7 +303,7 @@ struct ucred *nfsrv_getgrpscred(struct ucred *);
 void nfsm_uiombuf(struct nfsrv_descript *, struct uio *, int);
 struct mbuf *nfsm_uiombuflist(struct uio *, int, struct mbuf **, char **);
 void nfscl_reqstart(struct nfsrv_descript *, int, struct nfsmount *,
-u_int8_t *, int, u_int32_t **, struct nfsclsession *);
+u_int8_t *, int, u_int32_t **, struct nfsclsession *, int, int);
 nfsuint64 *nfscl_getcookie(struct nfsnode *, off_t off, int);
 void nfscl_fillsattr(struct nfsrv_descript *, struct vattr *,
   vnode_t, int, u_int32_t);

Modified: head/sys/fs/nfs/nfscl.h
==
--- head/sys/fs/nfs/nfscl.h Tue Sep 26 23:24:15 2017(r324039)
+++ head/sys/fs/nfs/nfscl.h Tue Sep 26 23:42:44 2017(r324040)
@@ -49,7 +49,8 @@ struct nfsv4node {
  */
 #defineNFSCL_REQSTART(n, p, v) 
\
nfscl_reqstart((n), (p), VFSTONFS((v)->v_mount),\
-   VTONFS(v)->n_fhp->nfh_fh, VTONFS(v)->n_fhp->nfh_len, NULL, NULL)
+   VTONFS(v)->n_fhp->nfh_fh, VTONFS(v)->n_fhp->nfh_len, NULL,  \
+   NULL, 0, 0)
 
 /*
  * These two macros convert between a lease duration and renew interval.

Modified: head/sys/fs/nfsclient/nfs_clcomsubs.c
==
--- head/sys/fs/nfsclient/nfs_clcomsubs.c   Tue Sep 26 23:24:15 2017
(r324039)
+++ head/sys/fs/nfsclient/nfs_clcomsubs.c   Tue Sep 26 23:42:44 2017
(r324040)
@@ -131,7 +131,8 @@ static int nfs_bigrequest[NFSV41_NPROCS] = {
  */
 APPLESTATIC void
 nfscl_reqstart(struct nfsrv_descript *nd, int procnum, struct nfsmount *nmp,
-u_int8_t *nfhp, int fhlen, u_int32_t **opcntpp, struct nfsclsession *sep)
+u_int8_t *nfhp, int fhlen, u_int32_t **opcntpp, struct nfsclsession *sep,
+int vers, int minorvers)
 {
struct mbuf *mb;
u_int32_t *tl;
@@ -142,14 +143,22 @@ nfscl_reqstart(struct nfsrv_descript *nd, int procnum,
 * First, fill in some of the fields of nd.
 */
nd->nd_slotseq = NULL;
-   if (NFSHASNFSV4(nmp)) {
+   if (vers == NFS_VER4) {
nd->nd_flag = ND_NFSV4 | ND_NFSCL;
-   if (NFSHASNFSV4N(nmp))
+   if (minorvers == NFSV41_MINORVERSION)
nd->nd_flag |= ND_NFSV41;
-   } else if (NFSHASNFSV3(nmp))
+   } else if (vers == NFS_VER3)
nd->nd_flag = ND_NFSV3 | ND_NFSCL;
-   else
-   nd->nd_flag = ND_NFSV2 | ND_NFSCL;
+   else {
+   if (NFSHASNFSV4(nmp)) {
+   nd->nd_flag = ND_NFSV4 | ND_NFSCL;
+   if (NFSHASNFSV4N(nmp))
+   nd->nd_flag |= ND_NFSV41;
+   } else if (NFSHASNFSV3(nmp))
+   nd->nd_flag = ND_NFSV3 | ND_NFSCL;
+   else
+   nd->nd_flag = ND_NFSV2 | ND_NFSCL;
+   }
nd->nd_procnum = procnum;
nd->nd_repstat = 0;
 

Modified: head/sys/fs/nfsclient/nfs_clrpcops.c
==
--- head/sys/fs/nfsclient/nfs_clrpcops.cTue Sep 26 23:24:15 2017
(r324039)
+++ head/sys/fs/nfsclient/nfs_clrpcops.cTue Sep 26 23:42:44 2017
(r324040)
@@ -429,7 +429,7 @@ nfsrpc_openrpc(struct nfsmount *nmp, vnode_t vp, u_int
 
dp = *dpp;
*dpp = NULL;
-   nfscl_reqstart(nd, NFSPROC_OPEN, nmp, nfhp, fhlen, NULL, NULL);
+   nfscl_reqstart(nd, NFSPROC_OPEN, nmp, nfhp, fhlen, NULL, NULL, 0, 0);
NFSM_BUILD(tl, u_int32_t *, 5 * NFSX_UNSIGNED);
*tl++ = txdr_unsigned(op->nfso_own->nfsow_seqid);
*tl++ = txdr_unsigned(mode & NFSV4OPEN_ACCESSBOTH);
@@ -785,7 +785,7 @@ nfsrpc_closerpc(struct nfsrv_descript *nd, struct nfsm
int error;
 
nfscl_reqstart(nd, NFSPROC_CLOSE, nmp, op->nfso_fh,
-   op->nfso_fhlen, NULL, NULL);
+   op->nfso_fhlen, NULL, NULL, 0, 0);
NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED + 

svn commit: r324039 - head/sys/ufs/ffs

2017-09-26 Thread John Baldwin
Author: jhb
Date: Tue Sep 26 23:24:15 2017
New Revision: 324039
URL: https://svnweb.freebsd.org/changeset/base/324039

Log:
  Don't defer wakeup()s for completed journal workitems.
  
  Normally wakeups() are performed for completed softupdates work items
  in workitem_free() before the underlying memory is free()'d.
  complete_jseg() was clearing the "wakeup needed" flag in work items to
  defer the wakeup until the end of each loop iteration.  However, this
  resulted in the item being free'd before it's address was used with
  wakeup().  As a result, another part of the kernel could allocate this
  memory from malloc() and use it as a wait channel for a different
  "event" with a different lock.  This triggered an assertion failure
  when the lock passed to sleepq_add() did not match the existing lock
  associated with the sleep queue.  Fix this by removing the code to
  defer the wakeup in complete_jseg() allowing the wakeup to occur
  slightly earlier in workitem_free() before free() is called.
  
  The main reason I can think of for deferring a wakeup() would be to
  avoid waking up a waiter while holding a lock that the waiter would
  need.  However, no locks are dropped in between the wakeup() in
  workitem_free() and the end of the loop in complete_jseg() as far as I
  can tell.
  
  In general I think it is not safe to do a wakeup() after free() as one
  cannot control how other parts of the kernel that might reuse the
  address for a different wait channel will handle spurious wakeups.
  
  Reported by:  pho
  Reviewed by:  kib
  MFC after:2 weeks
  Differential Revision:https://reviews.freebsd.org/D12494

Modified:
  head/sys/ufs/ffs/ffs_softdep.c

Modified: head/sys/ufs/ffs/ffs_softdep.c
==
--- head/sys/ufs/ffs/ffs_softdep.c  Tue Sep 26 23:23:58 2017
(r324038)
+++ head/sys/ufs/ffs/ffs_softdep.c  Tue Sep 26 23:24:15 2017
(r324039)
@@ -3596,15 +3596,13 @@ complete_jseg(jseg)
 {
struct worklist *wk;
struct jmvref *jmvref;
-   int waiting;
 #ifdef INVARIANTS
int i = 0;
 #endif
 
while ((wk = LIST_FIRST(>js_entries)) != NULL) {
WORKLIST_REMOVE(wk);
-   waiting = wk->wk_state & IOWAITING;
-   wk->wk_state &= ~(INPROGRESS | IOWAITING);
+   wk->wk_state &= ~INPROGRESS;
wk->wk_state |= COMPLETE;
KASSERT(i++ < jseg->js_cnt,
("handle_written_jseg: overflow %d >= %d",
@@ -3645,8 +3643,6 @@ complete_jseg(jseg)
TYPENAME(wk->wk_type));
/* NOTREACHED */
}
-   if (waiting)
-   wakeup(wk);
}
/* Release the self reference so the structure may be freed. */
rele_jseg(jseg);
___
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: r324038 - in head/sys: dev/bnxt dev/drm dev/drm2/i915 dev/drm2/radeon dev/e1000 net

2017-09-26 Thread Conrad Meyer
Author: cem
Date: Tue Sep 26 23:23:58 2017
New Revision: 324038
URL: https://svnweb.freebsd.org/changeset/base/324038

Log:
  Add PNP metadata to more drivers
  
  GPUs: radeonkms, i915kms
  NICs: if_em, if_igb, if_bnxt
  
  This metadata isn't used yet, but it will be handy to have later to
  implement automatic module loading.
  
  Reviewed by:  imp, mmacy
  Sponsored by: Dell EMC Isilon
  Differential Revision:https://reviews.freebsd.org/D12488

Modified:
  head/sys/dev/bnxt/if_bnxt.c
  head/sys/dev/drm/drmP.h
  head/sys/dev/drm2/i915/i915_drv.c
  head/sys/dev/drm2/radeon/radeon_drv.c
  head/sys/dev/e1000/if_em.c
  head/sys/net/iflib.h

Modified: head/sys/dev/bnxt/if_bnxt.c
==
--- head/sys/dev/bnxt/if_bnxt.c Tue Sep 26 23:12:32 2017(r324037)
+++ head/sys/dev/bnxt/if_bnxt.c Tue Sep 26 23:23:58 2017(r324038)
@@ -243,6 +243,8 @@ MODULE_DEPEND(bnxt, pci, 1, 1, 1);
 MODULE_DEPEND(bnxt, ether, 1, 1, 1);
 MODULE_DEPEND(bnxt, iflib, 1, 1, 1);
 
+IFLIB_PNP_INFO(pci, bnxt, bnxt_vendor_info_array);
+
 static device_method_t bnxt_iflib_methods[] = {
DEVMETHOD(ifdi_tx_queues_alloc, bnxt_tx_queues_alloc),
DEVMETHOD(ifdi_rx_queues_alloc, bnxt_rx_queues_alloc),

Modified: head/sys/dev/drm/drmP.h
==
--- head/sys/dev/drm/drmP.h Tue Sep 26 23:12:32 2017(r324037)
+++ head/sys/dev/drm/drmP.h Tue Sep 26 23:23:58 2017(r324038)
@@ -321,7 +321,7 @@ typedef struct drm_pci_id_list
 {
int vendor;
int device;
-   long driver_private;
+   intptr_t driver_private;
char *name;
 } drm_pci_id_list_t;
 

Modified: head/sys/dev/drm2/i915/i915_drv.c
==
--- head/sys/dev/drm2/i915/i915_drv.c   Tue Sep 26 23:12:32 2017
(r324037)
+++ head/sys/dev/drm2/i915/i915_drv.c   Tue Sep 26 23:23:58 2017
(r324038)
@@ -1236,6 +1236,8 @@ MODULE_DEPEND(i915kms, agp, 1, 1, 1);
 MODULE_DEPEND(i915kms, iicbus, 1, 1, 1);
 MODULE_DEPEND(i915kms, iic, 1, 1, 1);
 MODULE_DEPEND(i915kms, iicbb, 1, 1, 1);
+MODULE_PNP_INFO("U32:vendor;U32:device;P;D:human", vgapci, i915, pciidlist,
+sizeof(pciidlist[0]), nitems(pciidlist));
 
 /* We give fast paths for the really cool registers */
 #define NEEDS_FORCE_WAKE(dev_priv, reg) \

Modified: head/sys/dev/drm2/radeon/radeon_drv.c
==
--- head/sys/dev/drm2/radeon/radeon_drv.c   Tue Sep 26 23:12:32 2017
(r324037)
+++ head/sys/dev/drm2/radeon/radeon_drv.c   Tue Sep 26 23:23:58 2017
(r324038)
@@ -401,3 +401,5 @@ MODULE_DEPEND(radeonkms, iicbus, 1, 1, 1);
 MODULE_DEPEND(radeonkms, iic, 1, 1, 1);
 MODULE_DEPEND(radeonkms, iicbb, 1, 1, 1);
 MODULE_DEPEND(radeonkms, firmware, 1, 1, 1);
+MODULE_PNP_INFO("U32:vendor;U32:device;P;D:human", vgapci, radeonkms,
+pciidlist, sizeof(pciidlist[0]), nitems(pciidlist));

Modified: head/sys/dev/e1000/if_em.c
==
--- head/sys/dev/e1000/if_em.c  Tue Sep 26 23:12:32 2017(r324037)
+++ head/sys/dev/e1000/if_em.c  Tue Sep 26 23:23:58 2017(r324038)
@@ -339,6 +339,8 @@ MODULE_DEPEND(em, pci, 1, 1, 1);
 MODULE_DEPEND(em, ether, 1, 1, 1);
 MODULE_DEPEND(em, iflib, 1, 1, 1);
 
+IFLIB_PNP_INFO(pci, em, em_vendor_info_array);
+
 static driver_t igb_driver = {
"igb", igb_methods, sizeof(struct adapter),
 };
@@ -350,6 +352,7 @@ MODULE_DEPEND(igb, pci, 1, 1, 1);
 MODULE_DEPEND(igb, ether, 1, 1, 1);
 MODULE_DEPEND(igb, iflib, 1, 1, 1);
 
+IFLIB_PNP_INFO(pci, igb, igb_vendor_info_array);
 
 static device_method_t em_if_methods[] = {
DEVMETHOD(ifdi_attach_pre, em_if_attach_pre),

Modified: head/sys/net/iflib.h
==
--- head/sys/net/iflib.hTue Sep 26 23:12:32 2017(r324037)
+++ head/sys/net/iflib.hTue Sep 26 23:23:58 2017(r324038)
@@ -173,6 +173,11 @@ typedef struct pci_vendor_info {
 #define PVID_OEM(vendor, devid, svid, sdevid, revid, name) {vendor, devid, 
svid, sdevid, revid, 0, name}
 #define PVID_END {0, 0, 0, 0, 0, 0, NULL}
 
+#define IFLIB_PNP_DESCR "U32:vendor;U32:device;U32:subvendor;U32:subdevice;" \
+"U32:revision;U32:class;D:human"
+#define IFLIB_PNP_INFO(b, u, t) \
+MODULE_PNP_INFO(IFLIB_PNP_DESCR, b, u, t, sizeof(t[0]), nitems(t))
+
 typedef struct if_txrx {
int (*ift_txd_encap) (void *, if_pkt_info_t);
void (*ift_txd_flush) (void *, uint16_t, qidx_t pidx);
___
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: r324037 - in head: share/man/man4 sys/conf sys/crypto/aesni sys/modules/aesni tests/sys/opencrypto

2017-09-26 Thread Conrad Meyer
Author: cem
Date: Tue Sep 26 23:12:32 2017
New Revision: 324037
URL: https://svnweb.freebsd.org/changeset/base/324037

Log:
  aesni(4): Add support for x86 SHA intrinsics
  
  Some x86 class CPUs have accelerated intrinsics for SHA1 and SHA256.
  Provide this functionality on CPUs that support it.
  
  This implements CRYPTO_SHA1, CRYPTO_SHA1_HMAC, and CRYPTO_SHA2_256_HMAC.
  
  Correctness: The cryptotest.py suite in tests/sys/opencrypto has been
  enhanced to verify SHA1 and SHA256 HMAC using standard NIST test vectors.
  The test passes on this driver.  Additionally, jhb's cryptocheck tool has
  been used to compare various random inputs against OpenSSL.  This test also
  passes.
  
  Rough performance averages on AMD Ryzen 1950X (4kB buffer):
  aesni:  SHA1: ~8300 Mb/sSHA256: ~8000 Mb/s
  cryptosoft:   ~1800 Mb/sSHA256: ~1800 Mb/s
  
  So ~4.4-4.6x speedup depending on algorithm choice.  This is consistent with
  the results the Linux folks saw for 4kB buffers.
  
  The driver borrows SHA update code from sys/crypto sha1 and sha256.  The
  intrinsic step function comes from Intel under a 3-clause BSDL.[0]  The
  intel_sha_extensions_sha_intrinsic.c files were renamed and lightly
  modified (added const, resolved a warning or two; included the sha_sse
  header to declare the functions).
  
  [0]: 
https://software.intel.com/en-us/articles/intel-sha-extensions-implementations
  
  Reviewed by:  jhb
  Sponsored by: Dell EMC Isilon
  Differential Revision:https://reviews.freebsd.org/D12452

Added:
  head/sys/crypto/aesni/intel_sha1.c   (contents, props changed)
  head/sys/crypto/aesni/intel_sha256.c   (contents, props changed)
  head/sys/crypto/aesni/sha_sse.h   (contents, props changed)
Modified:
  head/share/man/man4/aesni.4
  head/sys/conf/files.amd64
  head/sys/conf/files.i386
  head/sys/crypto/aesni/aesni.c
  head/sys/crypto/aesni/aesni.h
  head/sys/modules/aesni/Makefile
  head/tests/sys/opencrypto/cryptotest.py

Modified: head/share/man/man4/aesni.4
==
--- head/share/man/man4/aesni.4 Tue Sep 26 22:32:08 2017(r324036)
+++ head/share/man/man4/aesni.4 Tue Sep 26 23:12:32 2017(r324037)
@@ -24,12 +24,12 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd December 14, 2015
+.Dd September 26, 2017
 .Dt AESNI 4
 .Os
 .Sh NAME
 .Nm aesni
-.Nd "driver for the AES accelerator on Intel CPUs"
+.Nd "driver for the AES and SHA accelerator on x86 CPUs"
 .Sh SYNOPSIS
 To compile this driver into the kernel,
 place the following lines in your
@@ -47,8 +47,8 @@ module at boot time, place the following line in
 aesni_load="YES"
 .Ed
 .Sh DESCRIPTION
-Starting with some models of Core i5/i7, Intel processors implement
-a new set of instructions called AESNI.
+Starting with Intel Westmere and AMD Bulldozer, some x86 processors implement a
+new set of instructions called AESNI.
 The set of six instructions accelerates the calculation of the key
 schedule for key lengths of 128, 192, and 256 of the Advanced
 Encryption Standard (AES) symmetric cipher, and provides a hardware
@@ -56,13 +56,24 @@ implementation of the regular and the last encryption 
 rounds.
 .Pp
 The processor capability is reported as AESNI in the Features2 line at boot.
+.Pp
+Starting with the Intel Goldmont and AMD Ryzen microarchitectures, some x86
+processors implement a new set of SHA instructions.
+The set of seven instructions accelerates the calculation of SHA1 and SHA256
+hashes.
+.Pp
+The processor capability is reported as SHA in the Structured Extended Features
+line at boot.
+.Pp
 The
 .Nm
-driver does not attach on systems that lack the required CPU capability.
+driver does not attach on systems that lack both CPU capabilities.
+On systems that support only one of AESNI or SHA extensions, the driver will
+attach and support that one function.
 .Pp
 The
 .Nm
-driver registers itself to accelerate AES operations for
+driver registers itself to accelerate AES and SHA operations for
 .Xr crypto 4 .
 Besides speed, the advantage of using the
 .Nm
@@ -83,13 +94,18 @@ The
 .Nm
 driver first appeared in
 .Fx 9.0 .
+SHA support was added in
+.Fx 12.0 .
 .Sh AUTHORS
 .An -nosplit
 The
 .Nm
 driver was written by
-.An Konstantin Belousov Aq Mt k...@freebsd.org .
+.An Konstantin Belousov Aq Mt k...@freebsd.org
+and
+.An Conrad Meyer Aq Mt c...@freebsd.org .
 The key schedule calculation code was adopted from the sample provided
 by Intel and used in the analogous
 .Ox
 driver.
+The hash step intrinsics implementations were supplied by Intel.

Modified: head/sys/conf/files.amd64
==
--- head/sys/conf/files.amd64   Tue Sep 26 22:32:08 2017(r324036)
+++ head/sys/conf/files.amd64   Tue Sep 26 23:12:32 2017(r324037)
@@ -182,6 +182,16 @@ aesni_wrap.o   optional aesni  
\
 crypto/blowfish/bf_enc.c   optionalcrypto | 

svn commit: r324033 - head/tools/tools/nanobsd

2017-09-26 Thread Gleb Smirnoff
Author: glebius
Date: Tue Sep 26 21:54:19 2017
New Revision: 324033
URL: https://svnweb.freebsd.org/changeset/base/324033

Log:
  Fix regression from r323855.  The EXIT trap now isn't cleared, so upon
  exit it tried to unmount already unmounted partition, resulting in failure.

Modified:
  head/tools/tools/nanobsd/legacy.sh

Modified: head/tools/tools/nanobsd/legacy.sh
==
--- head/tools/tools/nanobsd/legacy.sh  Tue Sep 26 21:18:43 2017
(r324032)
+++ head/tools/tools/nanobsd/legacy.sh  Tue Sep 26 21:54:19 2017
(r324033)
@@ -197,7 +197,7 @@ create_diskimage ( ) (
fi
mdconfig -d -u $MD
 
-   trap - 1 2 15
+   trap - 1 2 15 EXIT
 
) > ${NANO_LOG}/_.di 2>&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"


svn commit: r324026 - head/sys/dev/qlxgbe

2017-09-26 Thread David C Somayajulu
Author: davidcs
Date: Tue Sep 26 20:53:25 2017
New Revision: 324026
URL: https://svnweb.freebsd.org/changeset/base/324026

Log:
  Fix delete all multicast addresses
  
  Submitted by:anand.kh...@cavium.com
  MFC after:5 days

Modified:
  head/sys/dev/qlxgbe/ql_glbl.h
  head/sys/dev/qlxgbe/ql_hw.c
  head/sys/dev/qlxgbe/ql_os.c

Modified: head/sys/dev/qlxgbe/ql_glbl.h
==
--- head/sys/dev/qlxgbe/ql_glbl.h   Tue Sep 26 20:26:48 2017
(r324025)
+++ head/sys/dev/qlxgbe/ql_glbl.h   Tue Sep 26 20:53:25 2017
(r324026)
@@ -75,6 +75,7 @@ extern int ql_hw_check_health(qla_host_t *ha);
 extern void qla_hw_async_event(qla_host_t *ha);
 extern int qla_get_nic_partition(qla_host_t *ha, uint32_t *supports_9kb,
uint32_t *num_rcvq);
+extern int qla_hw_del_all_mcast(qla_host_t *ha);
 
 extern int ql_iscsi_pdu(qla_host_t *ha, struct mbuf *mp);
 extern void ql_minidump(qla_host_t *ha);

Modified: head/sys/dev/qlxgbe/ql_hw.c
==
--- head/sys/dev/qlxgbe/ql_hw.c Tue Sep 26 20:26:48 2017(r324025)
+++ head/sys/dev/qlxgbe/ql_hw.c Tue Sep 26 20:53:25 2017(r324026)
@@ -64,7 +64,6 @@ static int qla_link_event_req(qla_host_t *ha, uint16_t
 static int qla_tx_tso(qla_host_t *ha, struct mbuf *mp, q80_tx_cmd_t *tx_cmd,
uint8_t *hdr);
 static int qla_hw_add_all_mcast(qla_host_t *ha);
-static int qla_hw_del_all_mcast(qla_host_t *ha);
 static int qla_add_rcv_rings(qla_host_t *ha, uint32_t sds_idx, uint32_t nsds);
 
 static int qla_init_nic_func(qla_host_t *ha);
@@ -3413,7 +3412,7 @@ qla_hw_add_all_mcast(qla_host_t *ha)
return (ret);
 }
 
-static int
+int
 qla_hw_del_all_mcast(qla_host_t *ha)
 {
int ret;

Modified: head/sys/dev/qlxgbe/ql_os.c
==
--- head/sys/dev/qlxgbe/ql_os.c Tue Sep 26 20:26:48 2017(r324025)
+++ head/sys/dev/qlxgbe/ql_os.c Tue Sep 26 20:53:25 2017(r324026)
@@ -975,7 +975,19 @@ qla_set_multi(qla_host_t *ha, uint32_t add_multi)
return (-1);
 
if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
-   ret = ql_hw_set_multi(ha, mta, mcnt, add_multi);
+
+   if (!add_multi) {
+   ret = qla_hw_del_all_mcast(ha);
+
+   if (ret)
+   device_printf(ha->pci_dev,
+   "%s: qla_hw_del_all_mcast() failed\n",
+   __func__);
+   }
+
+   if (!ret)
+   ret = ql_hw_set_multi(ha, mta, mcnt, 1);
+
}
 
QLA_UNLOCK(ha, __func__);
___
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: r324024 - head/sys/arm/allwinner

2017-09-26 Thread Emmanuel Vadot
Author: manu
Date: Tue Sep 26 20:23:09 2017
New Revision: 324024
URL: https://svnweb.freebsd.org/changeset/base/324024

Log:
  a10_gpio: Enable all needed clocks
  
  Do not enable only the first clock, enable them all.

Modified:
  head/sys/arm/allwinner/a10_gpio.c

Modified: head/sys/arm/allwinner/a10_gpio.c
==
--- head/sys/arm/allwinner/a10_gpio.c   Tue Sep 26 19:56:36 2017
(r324023)
+++ head/sys/arm/allwinner/a10_gpio.c   Tue Sep 26 20:23:09 2017
(r324024)
@@ -165,6 +165,11 @@ static struct ofw_compat_data compat_data[] = {
{NULL,  0}
 };
 
+struct clk_list {
+   TAILQ_ENTRY(clk_list)   next;
+   clk_t   clk;
+};
+
 struct a10_gpio_softc {
device_tsc_dev;
device_tsc_busdev;
@@ -175,6 +180,7 @@ struct a10_gpio_softc {
bus_space_handle_t  sc_bsh;
void *  sc_intrhand;
const struct allwinner_padconf *padconf;
+   TAILQ_HEAD(, clk_list)  clk_list;
 };
 
 #defineA10_GPIO_LOCK(_sc)  mtx_lock_spin(&(_sc)->sc_mtx)
@@ -766,8 +772,10 @@ a10_gpio_attach(device_t dev)
int rid, error;
phandle_t gpio;
struct a10_gpio_softc *sc;
+   struct clk_list *clkp, *clkp_tmp;
clk_t clk;
-   hwreset_t rst;
+   hwreset_t rst = NULL;
+   int off, err;
 
sc = device_get_softc(dev);
sc->sc_dev = dev;
@@ -811,12 +819,17 @@ a10_gpio_attach(device_t dev)
}
}
 
-   if (clk_get_by_ofw_index(dev, 0, 0, ) == 0) {
-   error = clk_enable(clk);
-   if (error != 0) {
-   device_printf(dev, "could not enable clock\n");
-   return (error);
+   TAILQ_INIT(>clk_list);
+   for (off = 0; clk_get_by_ofw_index(dev, 0, off, ) == 0; off++) {
+   err = clk_enable(clk);
+   if (err != 0) {
+   device_printf(dev, "Could not enable clock %s\n",
+   clk_get_name(clk));
+   goto fail;
}
+   clkp = malloc(sizeof(*clkp), M_DEVBUF, M_WAITOK | M_ZERO);
+   clkp->clk = clk;
+   TAILQ_INSERT_TAIL(>clk_list, clkp, next);
}
 
sc->sc_busdev = gpiobus_attach_bus(dev);
@@ -839,6 +852,26 @@ fail:
if (sc->sc_mem_res)
bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->sc_mem_res);
mtx_destroy(>sc_mtx);
+
+   /* Disable clock */
+   TAILQ_FOREACH_SAFE(clkp, >clk_list, next, clkp_tmp) {
+   err = clk_disable(clkp->clk);
+   if (err != 0)
+   device_printf(dev, "Could not disable clock %s\n",
+   clk_get_name(clkp->clk));
+   err = clk_release(clkp->clk);
+   if (err != 0)
+   device_printf(dev, "Could not release clock %s\n",
+   clk_get_name(clkp->clk));
+   TAILQ_REMOVE(>clk_list, clkp, next);
+   free(clkp, M_DEVBUF);
+   }
+
+   /* Assert resets */
+   if (rst) {
+   hwreset_assert(rst);
+   hwreset_release(rst);
+   }
 
return (ENXIO);
 }
___
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: r324022 - head/sys/arm/allwinner

2017-09-26 Thread Emmanuel Vadot
Author: manu
Date: Tue Sep 26 19:21:43 2017
New Revision: 324022
URL: https://svnweb.freebsd.org/changeset/base/324022

Log:
  a10_ehci: Enable all clocks and reset
  
  a10_ehci can have multiple clocks and reset, enable them all instead of
  only the first one.

Modified:
  head/sys/arm/allwinner/a10_ehci.c

Modified: head/sys/arm/allwinner/a10_ehci.c
==
--- head/sys/arm/allwinner/a10_ehci.c   Tue Sep 26 19:20:50 2017
(r324021)
+++ head/sys/arm/allwinner/a10_ehci.c   Tue Sep 26 19:21:43 2017
(r324022)
@@ -88,11 +88,21 @@ __FBSDID("$FreeBSD$");
 static device_attach_t a10_ehci_attach;
 static device_detach_t a10_ehci_detach;
 
+struct clk_list {
+   TAILQ_ENTRY(clk_list)   next;
+   clk_t   clk;
+};
+
+struct hwrst_list {
+   TAILQ_ENTRY(hwrst_list) next;
+   hwreset_t   rst;
+};
+
 struct aw_ehci_softc {
ehci_softc_tsc;
-   clk_t   clk;
-   hwreset_t   rst;
-   phy_t   phy;
+   TAILQ_HEAD(, clk_list)  clk_list;
+   TAILQ_HEAD(, hwrst_list)rst_list;
+   phy_t   phy;
 };
 
 struct aw_ehci_conf {
@@ -114,6 +124,7 @@ static struct ofw_compat_data compat_data[] = {
{ "allwinner,sun7i-a20-ehci",   (uintptr_t)_ehci_conf },
{ "allwinner,sun8i-a83t-ehci",  (uintptr_t)_ehci_conf },
{ "allwinner,sun8i-h3-ehci",(uintptr_t)_ehci_conf },
+   /* { "allwinner,sun50i-a64-ehci",   (uintptr_t)_ehci_conf }, */
{ NULL, (uintptr_t)NULL }
 };
 
@@ -139,8 +150,11 @@ a10_ehci_attach(device_t self)
ehci_softc_t *sc = _sc->sc;
const struct aw_ehci_conf *conf;
bus_space_handle_t bsh;
-   int err;
-   int rid;
+   int err, rid, off;
+   struct clk_list *clkp;
+   clk_t clk;
+   struct hwrst_list *rstp;
+   hwreset_t rst;
uint32_t reg_value = 0;
 
conf = USB_CONF(self);
@@ -204,27 +218,33 @@ a10_ehci_attach(device_t self)
 
sc->sc_flags |= EHCI_SCFLG_DONTRESET;
 
+   /* Enable clock for USB */
+   TAILQ_INIT(_sc->clk_list);
+   for (off = 0; clk_get_by_ofw_index(self, 0, off, ) == 0; off++) {
+   err = clk_enable(clk);
+   if (err != 0) {
+   device_printf(self, "Could not enable clock %s\n",
+   clk_get_name(clk));
+   goto error;
+   }
+   clkp = malloc(sizeof(*clkp), M_DEVBUF, M_WAITOK | M_ZERO);
+   clkp->clk = clk;
+   TAILQ_INSERT_TAIL(_sc->clk_list, clkp, next);
+   }
+
/* De-assert reset */
-   if (hwreset_get_by_ofw_idx(self, 0, 0, _sc->rst) == 0) {
-   err = hwreset_deassert(aw_sc->rst);
+   TAILQ_INIT(_sc->rst_list);
+   for (off = 0; hwreset_get_by_ofw_idx(self, 0, off, ) == 0; off++) {
+   err = hwreset_deassert(rst);
if (err != 0) {
device_printf(self, "Could not de-assert reset\n");
goto error;
}
+   rstp = malloc(sizeof(*rstp), M_DEVBUF, M_WAITOK | M_ZERO);
+   rstp->rst = rst;
+   TAILQ_INSERT_TAIL(_sc->rst_list, rstp, next);
}
 
-   /* Enable clock for USB */
-   err = clk_get_by_ofw_index(self, 0, 0, _sc->clk);
-   if (err != 0) {
-   device_printf(self, "Could not get clock\n");
-   goto error;
-   }
-   err = clk_enable(aw_sc->clk);
-   if (err != 0) {
-   device_printf(self, "Could not enable clock\n");
-   goto error;
-   }
-
/* Enable USB PHY */
if (phy_get_by_ofw_name(self, 0, "usb", _sc->phy) == 0) {
err = phy_enable(self, aw_sc->phy);
@@ -272,6 +292,8 @@ a10_ehci_detach(device_t self)
const struct aw_ehci_conf *conf;
int err;
uint32_t reg_value = 0;
+   struct clk_list *clk, *clk_tmp;
+   struct hwrst_list *rst, *rst_tmp;
 
conf = USB_CONF(self);
 
@@ -319,16 +341,26 @@ a10_ehci_detach(device_t self)
reg_value &= ~SW_ULPI_BYPASS; /* ULPI bypass disable */
A10_WRITE_4(sc, SW_USB_PMU_IRQ_ENABLE, reg_value);
 
-   /* Disable clock for USB */
-   if (aw_sc->clk != NULL) {
-   clk_disable(aw_sc->clk);
-   clk_release(aw_sc->clk);
+   /* Disable clock */
+   TAILQ_FOREACH_SAFE(clk, _sc->clk_list, next, clk_tmp) {
+   err = clk_disable(clk->clk);
+   if (err != 0)
+   device_printf(self, "Could not disable clock %s\n",
+   clk_get_name(clk->clk));
+   err = clk_release(clk->clk);
+   if (err != 0)
+   device_printf(self, "Could not release clock %s\n",
+   clk_get_name(clk->clk));
+   

svn commit: r324021 - head/sys/arm/allwinner

2017-09-26 Thread Emmanuel Vadot
Author: manu
Date: Tue Sep 26 19:20:50 2017
New Revision: 324021
URL: https://svnweb.freebsd.org/changeset/base/324021

Log:
  aw_usbphy: Only reroute OTG for phy0
  
  We only need to route OTG port to host mode on phy0 and if no VBUS
  is present on the port, otherwise leave the port in periperal mode.

Modified:
  head/sys/arm/allwinner/aw_usbphy.c

Modified: head/sys/arm/allwinner/aw_usbphy.c
==
--- head/sys/arm/allwinner/aw_usbphy.c  Tue Sep 26 19:19:44 2017
(r324020)
+++ head/sys/arm/allwinner/aw_usbphy.c  Tue Sep 26 19:20:50 2017
(r324021)
@@ -160,13 +160,6 @@ awusbphy_configure(device_t dev, int phyno)
if (sc->phy_conf->pmu_unk1 == true)
CLR4(sc->pmu[phyno], PMU_UNK_H3, PMU_UNK_H3_CLR);
 
-   if (sc->phy_conf->phy0_route == true) {
-   if (phyno == 0)
-   SET4(sc->phy_ctrl, OTG_PHY_CFG, OTG_PHY_ROUTE_OTG);
-   else
-   CLR4(sc->phy_ctrl, OTG_PHY_CFG, OTG_PHY_ROUTE_OTG);
-   }
-
SET4(sc->pmu[phyno], PMU_IRQ_ENABLE, PMU_ULPI_BYPASS |
PMU_AHB_INCR8 | PMU_AHB_INCR4 | PMU_AHB_INCRX_ALIGN);
 }
@@ -266,8 +259,11 @@ awusbphy_vbus_detect(device_t dev, int *val)
 
if (sc->vbus_det_valid) {
error = gpio_pin_is_active(sc->vbus_det_pin, );
-   if (error != 0)
+   if (error != 0) {
+   device_printf(dev, "Cannot get status of id pin %d\n",
+   error);
return (error);
+   }
*val = active;
return (0);
}
@@ -300,7 +296,21 @@ awusbphy_phy_enable(device_t dev, intptr_t phy, bool e
/* If an external vbus is detected, do not enable phy 0 */
if (phy == 0) {
error = awusbphy_vbus_detect(dev, _det);
-   if (error == 0 && vbus_det == 1)
+   if (error)
+   goto out;
+
+   /* Depending on the PHY we need to route OTG to 
OHCI/EHCI */
+   if (sc->phy_conf->phy0_route == true) {
+   if (vbus_det == 0)
+   /* Host mode */
+   CLR4(sc->phy_ctrl, OTG_PHY_CFG,
+OTG_PHY_ROUTE_OTG);
+   else
+   /* Peripheral mode */
+   SET4(sc->phy_ctrl, OTG_PHY_CFG,
+OTG_PHY_ROUTE_OTG);
+   }
+   if (vbus_det == 1)
return (0);
} else
error = 0;
@@ -308,6 +318,8 @@ awusbphy_phy_enable(device_t dev, intptr_t phy, bool e
error = regulator_enable(reg);
} else
error = regulator_disable(reg);
+
+out:
if (error != 0) {
device_printf(dev,
"couldn't %s regulator for phy %jd\n",
___
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: r324020 - head/sys/arm/allwinner

2017-09-26 Thread Emmanuel Vadot
Author: manu
Date: Tue Sep 26 19:19:44 2017
New Revision: 324020
URL: https://svnweb.freebsd.org/changeset/base/324020

Log:
  aw_usbphy: Fix write of unknown register
  
  Some SoC require a write to a unknown register to work corectly.
  This write should be in the pmu region not in the phy ctrl one.
  
  Reported by:  Mark Millard (mar...@dsl-only.net)

Modified:
  head/sys/arm/allwinner/aw_usbphy.c

Modified: head/sys/arm/allwinner/aw_usbphy.c
==
--- head/sys/arm/allwinner/aw_usbphy.c  Tue Sep 26 17:52:52 2017
(r324019)
+++ head/sys/arm/allwinner/aw_usbphy.c  Tue Sep 26 19:19:44 2017
(r324020)
@@ -158,7 +158,7 @@ awusbphy_configure(device_t dev, int phyno)
return;
 
if (sc->phy_conf->pmu_unk1 == true)
-   CLR4(sc->phy_ctrl, PMU_UNK_H3, PMU_UNK_H3_CLR);
+   CLR4(sc->pmu[phyno], PMU_UNK_H3, PMU_UNK_H3_CLR);
 
if (sc->phy_conf->phy0_route == true) {
if (phyno == 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"


svn commit: r324019 - in head/sys: crypto/via opencrypto

2017-09-26 Thread Conrad Meyer
Author: cem
Date: Tue Sep 26 17:52:52 2017
New Revision: 324019
URL: https://svnweb.freebsd.org/changeset/base/324019

Log:
  opencrypto: Use C99 initializers for auth_hash instances
  
  A misordering in the Via padlock driver really strongly suggested that these
  should use C99 named initializers.
  
  No functional change.
  
  Sponsored by: Dell EMC Isilon

Modified:
  head/sys/crypto/via/padlock_hash.c
  head/sys/opencrypto/xform_md5.c
  head/sys/opencrypto/xform_null.c
  head/sys/opencrypto/xform_rmd160.c
  head/sys/opencrypto/xform_sha1.c
  head/sys/opencrypto/xform_sha2.c

Modified: head/sys/crypto/via/padlock_hash.c
==
--- head/sys/crypto/via/padlock_hash.c  Tue Sep 26 17:35:53 2017
(r324018)
+++ head/sys/crypto/via/padlock_hash.c  Tue Sep 26 17:52:52 2017
(r324019)
@@ -81,21 +81,27 @@ static void padlock_sha1_final(uint8_t *hash, struct p
 static void padlock_sha256_final(uint8_t *hash, struct padlock_sha_ctx *ctx);
 
 static struct auth_hash padlock_hmac_sha1 = {
-   CRYPTO_SHA1_HMAC, "HMAC-SHA1",
-   SHA1_HMAC_BLOCK_LEN, SHA1_HASH_LEN, sizeof(struct padlock_sha_ctx),
-   SHA1_HMAC_BLOCK_LEN,
-(void (*)(void *))padlock_sha_init, NULL, NULL,
-   (int (*)(void *, const uint8_t *, uint16_t))padlock_sha_update,
-   (void (*)(uint8_t *, void *))padlock_sha1_final
+   .type = CRYPTO_SHA1_HMAC,
+   .name = "HMAC-SHA1",
+   .keysize = SHA1_HMAC_BLOCK_LEN,
+   .hashsize = SHA1_HASH_LEN,
+   .ctxsize = sizeof(struct padlock_sha_ctx),
+   .blocksize = SHA1_HMAC_BLOCK_LEN,
+.Init = (void (*)(void *))padlock_sha_init,
+   .Update = (int (*)(void *, const uint8_t *, 
uint16_t))padlock_sha_update,
+   .Final = (void (*)(uint8_t *, void *))padlock_sha1_final,
 };
 
 static struct auth_hash padlock_hmac_sha256 = {
-   CRYPTO_SHA2_256_HMAC, "HMAC-SHA2-256",
-   SHA2_256_HMAC_BLOCK_LEN, SHA2_256_HASH_LEN,
-   sizeof(struct padlock_sha_ctx), SHA2_256_HMAC_BLOCK_LEN,
-(void (*)(void *))padlock_sha_init, NULL, NULL,
-   (int (*)(void *, const uint8_t *, uint16_t))padlock_sha_update,
-   (void (*)(uint8_t *, void *))padlock_sha256_final
+   .type = CRYPTO_SHA2_256_HMAC,
+   .name = "HMAC-SHA2-256",
+   .keysize = SHA2_256_HMAC_BLOCK_LEN,
+   .hashsize = SHA2_256_HASH_LEN,
+   .ctxsize = sizeof(struct padlock_sha_ctx),
+   .blocksize = SHA2_256_HMAC_BLOCK_LEN,
+.Init = (void (*)(void *))padlock_sha_init,
+   .Update = (int (*)(void *, const uint8_t *, 
uint16_t))padlock_sha_update,
+   .Final = (void (*)(uint8_t *, void *))padlock_sha256_final,
 };
 
 MALLOC_DECLARE(M_PADLOCK);

Modified: head/sys/opencrypto/xform_md5.c
==
--- head/sys/opencrypto/xform_md5.c Tue Sep 26 17:35:53 2017
(r324018)
+++ head/sys/opencrypto/xform_md5.c Tue Sep 26 17:52:52 2017
(r324019)
@@ -57,17 +57,27 @@ static  int MD5Update_int(void *, const u_int8_t *, u_i
 
 /* Authentication instances */
 struct auth_hash auth_hash_hmac_md5 = {
-   CRYPTO_MD5_HMAC, "HMAC-MD5",
-   MD5_HMAC_BLOCK_LEN, MD5_HASH_LEN, sizeof(MD5_CTX), MD5_HMAC_BLOCK_LEN,
-   (void (*) (void *)) MD5Init, NULL, NULL, MD5Update_int,
-   (void (*) (u_int8_t *, void *)) MD5Final
+   .type = CRYPTO_MD5_HMAC,
+   .name = "HMAC-MD5",
+   .keysize = MD5_HMAC_BLOCK_LEN,
+   .hashsize = MD5_HASH_LEN,
+   .ctxsize = sizeof(MD5_CTX),
+   .blocksize = MD5_HMAC_BLOCK_LEN,
+   .Init = (void (*) (void *)) MD5Init,
+   .Update = MD5Update_int,
+   .Final = (void (*) (u_int8_t *, void *)) MD5Final,
 };
 
 struct auth_hash auth_hash_key_md5 = {
-   CRYPTO_MD5_KPDK, "Keyed MD5",
-   0, MD5_KPDK_HASH_LEN, sizeof(MD5_CTX), 0,
-   (void (*)(void *)) MD5Init, NULL, NULL, MD5Update_int,
-   (void (*)(u_int8_t *, void *)) MD5Final
+   .type = CRYPTO_MD5_KPDK,
+   .name = "Keyed MD5",
+   .keysize = 0,
+   .hashsize = MD5_KPDK_HASH_LEN,
+   .ctxsize = sizeof(MD5_CTX),
+   .blocksize = 0,
+   .Init = (void (*)(void *)) MD5Init,
+   .Update = MD5Update_int,
+   .Final = (void (*)(u_int8_t *, void *)) MD5Final,
 };
 
 /*

Modified: head/sys/opencrypto/xform_null.c
==
--- head/sys/opencrypto/xform_null.cTue Sep 26 17:35:53 2017
(r324018)
+++ head/sys/opencrypto/xform_null.cTue Sep 26 17:52:52 2017
(r324019)
@@ -76,10 +76,18 @@ struct enc_xform enc_xform_null = {
 };
 
 /* Authentication instances */
-struct auth_hash auth_hash_null = {/* NB: context isn't used */
-   CRYPTO_NULL_HMAC, "NULL-HMAC",
-   0, NULL_HASH_LEN, sizeof(int), NULL_HMAC_BLOCK_LEN,
-   null_init, null_reinit, null_reinit, null_update, null_final
+struct auth_hash auth_hash_null = {
+   

svn commit: r324017 - in head/sys: crypto/via netipsec opencrypto

2017-09-26 Thread Conrad Meyer
Author: cem
Date: Tue Sep 26 16:18:10 2017
New Revision: 324017
URL: https://svnweb.freebsd.org/changeset/base/324017

Log:
  opencrypto: Loosen restriction on HMAC key sizes
  
  Theoretically, HMACs do not actually have any limit on key sizes.
  Transforms should compact input keys larger than the HMAC block size by
  using the transform (hash) on the input key.
  
  (Short input keys are padded out with zeros to the HMAC block size.)
  
  Still, not all FreeBSD crypto drivers that provide HMAC functionality
  handle longer-than-blocksize keys appropriately, so enforce a "maximum" key
  length in the crypto API for auth_hashes that previously expressed a
  requirement.  (The "maximum" is the size of a single HMAC block for the
  given transform.)  Unconstrained auth_hashes are left as-is.
  
  I believe the previous hardcoded sizes were committed in the original
  import of opencrypto from OpenBSD and are due to specific protocol
  details of IPSec.  Note that none of the previous sizes actually matched
  the appropriate HMAC block size.
  
  The previous hardcoded sizes made the SHA tests in cryptotest.py
  useless for testing FreeBSD crypto drivers; none of the NIST-KAT example
  inputs had keys sized to the previous expectations.
  
  The following drivers were audited to check that they handled keys up to
  the block size of the HMAC safely:
  
Software HMAC:
  * padlock(4)
  * cesa
  * glxsb
  * safe(4)
  * ubsec(4)
  
Hardware accelerated HMAC:
  * ccr(4)
  * hifn(4)
  * sec(4) (Only supports up to 64 byte keys despite claiming to
support SHA2 HMACs, but validates input key sizes)
  * cryptocteon (MIPS)
  * nlmsec (MIPS)
  * rmisec (MIPS) (Amusingly, does not appear to use key material at
all -- presumed broken)
  
  Reviewed by:  jhb (previous version), rlibby (previous version)
  Sponsored by: Dell EMC Isilon
  Differential Revision:https://reviews.freebsd.org/D12437

Modified:
  head/sys/crypto/via/padlock_hash.c
  head/sys/netipsec/xform_ah.c
  head/sys/opencrypto/cryptodev.c
  head/sys/opencrypto/cryptodev.h
  head/sys/opencrypto/xform_md5.c
  head/sys/opencrypto/xform_null.c
  head/sys/opencrypto/xform_rmd160.c
  head/sys/opencrypto/xform_sha1.c
  head/sys/opencrypto/xform_sha2.c

Modified: head/sys/crypto/via/padlock_hash.c
==
--- head/sys/crypto/via/padlock_hash.c  Tue Sep 26 15:38:16 2017
(r324016)
+++ head/sys/crypto/via/padlock_hash.c  Tue Sep 26 16:18:10 2017
(r324017)
@@ -82,7 +82,8 @@ static void padlock_sha256_final(uint8_t *hash, struct
 
 static struct auth_hash padlock_hmac_sha1 = {
CRYPTO_SHA1_HMAC, "HMAC-SHA1",
-   20, SHA1_HASH_LEN, SHA1_HMAC_BLOCK_LEN, sizeof(struct padlock_sha_ctx),
+   SHA1_HMAC_BLOCK_LEN, SHA1_HASH_LEN, sizeof(struct padlock_sha_ctx),
+   SHA1_HMAC_BLOCK_LEN,
 (void (*)(void *))padlock_sha_init, NULL, NULL,
(int (*)(void *, const uint8_t *, uint16_t))padlock_sha_update,
(void (*)(uint8_t *, void *))padlock_sha1_final
@@ -90,7 +91,8 @@ static struct auth_hash padlock_hmac_sha1 = {
 
 static struct auth_hash padlock_hmac_sha256 = {
CRYPTO_SHA2_256_HMAC, "HMAC-SHA2-256",
-   32, SHA2_256_HASH_LEN, SHA2_256_HMAC_BLOCK_LEN, sizeof(struct 
padlock_sha_ctx),
+   SHA2_256_HMAC_BLOCK_LEN, SHA2_256_HASH_LEN,
+   sizeof(struct padlock_sha_ctx), SHA2_256_HMAC_BLOCK_LEN,
 (void (*)(void *))padlock_sha_init, NULL, NULL,
(int (*)(void *, const uint8_t *, uint16_t))padlock_sha_update,
(void (*)(uint8_t *, void *))padlock_sha256_final

Modified: head/sys/netipsec/xform_ah.c
==
--- head/sys/netipsec/xform_ah.cTue Sep 26 15:38:16 2017
(r324016)
+++ head/sys/netipsec/xform_ah.cTue Sep 26 16:18:10 2017
(r324017)
@@ -193,9 +193,9 @@ ah_init0(struct secasvar *sav, struct xformsw *xsp, st
return EINVAL;
}
keylen = _KEYLEN(sav->key_auth);
-   if (keylen != thash->keysize && thash->keysize != 0) {
+   if (keylen > thash->keysize && thash->keysize != 0) {
DPRINTF(("%s: invalid keylength %d, algorithm %s requires "
-   "keysize %d\n", __func__,
+   "keysize less than %d\n", __func__,
 keylen, thash->name, thash->keysize));
return EINVAL;
}

Modified: head/sys/opencrypto/cryptodev.c
==
--- head/sys/opencrypto/cryptodev.c Tue Sep 26 15:38:16 2017
(r324016)
+++ head/sys/opencrypto/cryptodev.c Tue Sep 26 16:18:10 2017
(r324017)
@@ -520,7 +520,8 @@ cryptof_ioctl(
if (thash) {
cria.cri_alg = thash->type;
cria.cri_klen = 

svn commit: r324016 - in head/sys/cddl: compat/opensolaris/sys contrib/opensolaris/uts/common/fs/zfs

2017-09-26 Thread Andriy Gapon
Author: avg
Date: Tue Sep 26 15:38:16 2017
New Revision: 324016
URL: https://svnweb.freebsd.org/changeset/base/324016

Log:
  fix r324011, MFV of r323535, 8585 improve batching done in zil_commit()
  
  I managed to commit an older version of the change.
  Plus, even the latest version was not ready for userland compilation.
  
  Reported by:  "O. Hartmann" ,
cy
  MFC after:1 week
  X-MFC with:   r324011

Modified:
  head/sys/cddl/compat/opensolaris/sys/time.h
  head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zil.c

Modified: head/sys/cddl/compat/opensolaris/sys/time.h
==
--- head/sys/cddl/compat/opensolaris/sys/time.h Tue Sep 26 12:46:17 2017
(r324015)
+++ head/sys/cddl/compat/opensolaris/sys/time.h Tue Sep 26 15:38:16 2017
(r324016)
@@ -40,6 +40,9 @@
 #defineMSEC2NSEC(m)((hrtime_t)(m) * (NANOSEC / MILLISEC))
 #defineNSEC2MSEC(n)((n) / (NANOSEC / MILLISEC))
 
+#defineUSEC2NSEC(m)((hrtime_t)(m) * (NANOSEC / MICROSEC))
+#defineNSEC2USEC(n)((n) / (NANOSEC / MICROSEC))
+
 #defineNSEC2SEC(n) ((n) / (NANOSEC / SEC))
 #defineSEC2NSEC(m) ((hrtime_t)(m) * (NANOSEC / SEC))
 

Modified: head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zil.c
==
--- head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zil.c   Tue Sep 26 
12:46:17 2017(r324015)
+++ head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zil.c   Tue Sep 26 
15:38:16 2017(r324016)
@@ -2283,8 +2283,13 @@ zil_commit_waiter(zilog_t *zilog, zil_commit_waiter_t 
 * zil_process_commit_list() function.
 */
int pct = MAX(zfs_commit_timeout_pct, 1);
+#if defined(illumos) || !defined(_KERNEL)
hrtime_t sleep = (zilog->zl_last_lwb_latency * pct) / 100;
hrtime_t wakeup = gethrtime() + sleep;
+#else
+   sbintime_t sleep = nstosbt((zilog->zl_last_lwb_latency * pct) / 100);
+   sbintime_t wakeup = getsbinuptime() + sleep;
+#endif
boolean_t timedout = B_FALSE;
 
while (!zcw->zcw_done) {
@@ -2322,7 +2327,7 @@ zil_commit_waiter(zilog_t *zilog, zil_commit_waiter_t 
 * timeout is reached; responsibility (2) from
 * the comment above this function.
 */
-#ifdef illumos
+#if defined(illumos) || !defined(_KERNEL)
clock_t timeleft = cv_timedwait_hires(>zcw_cv,
>zcw_lock, wakeup, USEC2NSEC(1),
CALLOUT_FLAG_ABSOLUTE);
@@ -2331,8 +2336,7 @@ zil_commit_waiter(zilog_t *zilog, zil_commit_waiter_t 
continue;
 #else
int wait_err = cv_timedwait_sbt(>zcw_cv,
-   >zcw_lock, wakeup * SBT_1NS, SBT_1NS,
-   C_ABSOLUTE);
+   >zcw_lock, wakeup, SBT_1NS, C_ABSOLUTE);
if (wait_err != EWOULDBLOCK || zcw->zcw_done)
continue;
 #endif
___
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: r324011 - in head: cddl/contrib/opensolaris/cmd/ztest sys/cddl/contrib/opensolaris/uts/common/fs/zfs sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys sys/cddl/contrib/opensolaris/uts

2017-09-26 Thread Andriy Gapon
On 26/09/2017 16:48, O. Hartmann wrote:
> Build world/kernel on r324015 fails due to:
> 
> [...]
> ===> lib/libpam/modules/pam_login_access (obj)
> --- cddl/lib__L ---
> --- zil.o ---
> /usr/src/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zil.c:2333:19: 
> warning:
> implicit declaration of function 'cv_timedwait_sbt' is invalid in C99
> [-Wimplicit-function-declaration] int wait_err = 
> cv_timedwait_sbt(>zcw_cv,
> ^ /usr/src/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zil.c:2335:8: error:
> use of undeclared identifier 'C_ABSOLUTE' C_ABSOLUTE);
> ^
> --- lib__L ---
> --- obj_subdir_lib/libpam/modules/pam_nologin ---
> ===> lib/libpam/modules/pam_nologin (obj)
> --- cddl/lib__L ---
> 1 warning and 1 error generated.

Seems like messed up the commit.
Not only I managed to somehow commit an older version of what I had in the
review request, but I also forget that zil.c is compiled in userland mode as 
well.

A fix is coming shortly.
Apologies for the breakage.

-- 
Andriy Gapon
___
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: r324011 - in head: cddl/contrib/opensolaris/cmd/ztest sys/cddl/contrib/opensolaris/uts/common/fs/zfs sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys sys/cddl/contrib/opensolaris/uts

2017-09-26 Thread O. Hartmann
On Tue, 26 Sep 2017 11:04:08 + (UTC)
Andriy Gapon  wrote:

> Author: avg
> Date: Tue Sep 26 11:04:08 2017
> New Revision: 324011
> URL: https://svnweb.freebsd.org/changeset/base/324011
> 
> Log:
>   MFV r323535: 8585 improve batching done in zil_commit()
>   
>   FreeBSD notes:
>   - this MFV reverts FreeBSD commit r314549 to make the merge easier
>   - at present our emulation of cv_timedwait_hires is rather poor,
> so I elected to use cv_timedwait_sbt directly
>   Please see the differential revision for details.
>   Unfortunately, I did not get any positive reviews, so there could be
>   bugs in the FreeBSD-specific piece of the merge.
>   Hence, the long MFC timeout.
>   
>   illumos/illumos-gate@1271e4b10dfaaed576c08a812f466f6e81370e5e
>   
> https://github.com/illumos/illumos-gate/commit/1271e4b10dfaaed576c08a812f466f6e81370e5e
>   
>   https://www.illumos.org/issues/8585
> The current implementation of zil_commit() can introduce significant
> latency, beyond what is inherent due to the latency of the underlying
> storage. The additional latency comes from two main problems:
> 1. When there's outstanding ZIL blocks being written (i.e. there's
> already a "writer thread" in progress), then any new calls to
> zil_commit() will block waiting for the currently oustanding ZIL
> blocks to complete. The blocks written for each "writer thread" is
> coined a "batch", and there can only ever be a single "batch" being
> written at a time. When a batch is being written, any new ZIL
> transactions will have to wait for the next batch to be written,
> which won't occur until the current batch finishes.
> As a result, the underlying storage may not be used as efficiently
> as possible. While "new" threads enter zil_commit() and are blocked
> waiting for the next batch, it's possible that the underlying
> storage isn't fully utilized by the current batch of ZIL blocks. In
> that case, it'd be better to allow these new threads to generate
> (and issue) a new ZIL block, such that it could be serviced by the
> underlying storage concurrently with the other ZIL blocks that are
> being serviced.
> 2. Any call to zil_commit() must wait for all ZIL blocks in its "batch"
> to complete, prior to zil_commit() returning. The size of any given
> batch is proportional to the number of ZIL transaction in the queue
> at the time that the batch starts processing the queue; which
> doesn't occur until the previous batch completes. Thus, if there's a
> lot of transactions in the queue, the batch could be composed of
> many ZIL blocks, and each call to zil_commit() will have to wait for
> all of these writes to complete (even if the thread calling
> zil_commit() only cared about one of the transactions in the batch).
>   
>   Reviewed by: Brad Lewis 
>   Reviewed by: Matt Ahrens 
>   Reviewed by: George Wilson 
>   Approved by: Dan McDonald 
>   Author: Prakash Surya 
>   
>   MFC after:  1 month
>   Differential Revision:  https://reviews.freebsd.org/D12355
> 
> Modified:
>   head/cddl/contrib/opensolaris/cmd/ztest/ztest.c
>   head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dmu.c
>   head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/dmu.h
>   head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zil.h
>   head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zil_impl.h
>   head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zio.h
>   head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/txg.c
>   head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c
>   head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zil.c
>   head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zio.c
>   head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zvol.c
>   head/sys/cddl/contrib/opensolaris/uts/common/sys/debug.h
> Directory Properties:
>   head/cddl/contrib/opensolaris/   (props changed)
>   head/sys/cddl/contrib/opensolaris/   (props changed)
> 
> Modified: head/cddl/contrib/opensolaris/cmd/ztest/ztest.c
> ==
> --- head/cddl/contrib/opensolaris/cmd/ztest/ztest.c   Tue Sep 26
> 09:34:18 2017 (r324010) +++
> head/cddl/contrib/opensolaris/cmd/ztest/ztest.c   Tue Sep 26 11:04:08
> 2017  (r324011) @@ -1825,13 +1825,14 @@ ztest_get_done(zgd_t *zgd, int
> error) ztest_object_unlock(zd, object); 
>   if (error == 0 && zgd->zgd_bp)
> - zil_add_block(zgd->zgd_zilog, zgd->zgd_bp);
> + zil_lwb_add_block(zgd->zgd_lwb, zgd->zgd_bp);
>  
>   umem_free(zgd, sizeof (*zgd));
>  }
>  
>  static int
> -ztest_get_data(void *arg, lr_write_t *lr, char *buf, zio_t *zio)
> +ztest_get_data(void *arg, 

Re: svn commit: r324007 - head/usr.sbin/mountd

2017-09-26 Thread Emmanuel Vadot
On Tue, 26 Sep 2017 22:09:53 +1000 (EST)
Bruce Evans  wrote:

> On Tue, 26 Sep 2017, Emmanuel Vadot wrote:
> 
> > On Tue, 26 Sep 2017 13:24:57 +0300
> > Konstantin Belousov  wrote:
> >
> >> On Tue, Sep 26, 2017 at 09:18:18AM +, Emmanuel Vadot wrote:
> >>> @@ -1940,14 +1936,16 @@ add_expdir(struct dirlist **dpp, char *cp, int 
> >>> len)
> >>>  {
> >>>   struct dirlist *dp;
> >>>
> >>> - dp = (struct dirlist *)malloc(sizeof (struct dirlist) + len);
> >>> + dp = (struct dirlist *)malloc(sizeof (struct dirlist));
> >> You might remove the unneeded cast as well.
> >
> > Right, done in 324012.

 Hi Bruce,

> Er, mountd has many similar casts, not just the one fixed, and worse ones
> like casting dp to caddr_t before passing it to free() (caddr_t is bogus,
> and free() doesn't actually take it -- its prototype converts caddr_t to
> void *, just like it would convert dp's type to void *)).  Some of these
> casts were needed in 1987 for unprototyped pre-StandardC code.  caddr_t
> was more needed in 1977 before void * existed (free() takes a char * arg
> in K).

 I've fixed this one in 324014 and will probably apply style(9) to the
whole file at some point.

> But the main hug near here is leaking memory for strdup()).  The above
> malloc() allocates 2 storage areas together (1 for the string at the
> end), and seems to have a corresponding free().  Now there is an extra
> separate storage error for the string and no separate free() for it.

 Yes, sorry for that, this is fixed in 324014 too.

> This is not much more than a style bug too.  mountd is a long-lived
> daemon, so it should avoid leaking memory, but it would probably work
> OK for a few thousand mounts with no free()s at all or a few million
> with no frees of strings.  But it tries to free() most things, so it
> is a style bug to not try for some.
> 
> Bruce

 Thanks,

-- 
Emmanuel Vadot  
___
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: r324014 - head/usr.sbin/mountd

2017-09-26 Thread Emmanuel Vadot
Author: manu
Date: Tue Sep 26 12:15:13 2017
New Revision: 324014
URL: https://svnweb.freebsd.org/changeset/base/324014

Log:
  mountd: Avoid memory leak by freeing dp_dirp
  
  Introduced in r324007, the data alloced by strdup was never free'ed.
  While here, remove cast to caddr_t when freeing dp.
  
  Reported by:  bde
  MFC after:1 week
  X MFC With:   r324007

Modified:
  head/usr.sbin/mountd/mountd.c

Modified: head/usr.sbin/mountd/mountd.c
==
--- head/usr.sbin/mountd/mountd.c   Tue Sep 26 11:16:33 2017
(r324013)
+++ head/usr.sbin/mountd/mountd.c   Tue Sep 26 12:15:13 2017
(r324014)
@@ -2159,7 +2159,8 @@ free_dir(struct dirlist *dp)
free_dir(dp->dp_left);
free_dir(dp->dp_right);
free_host(dp->dp_hosts);
-   free((caddr_t)dp);
+   free(dp->dp_dirp);
+   free(dp);
}
 }
 
___
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: r324007 - head/usr.sbin/mountd

2017-09-26 Thread Bruce Evans

On Tue, 26 Sep 2017, Emmanuel Vadot wrote:


On Tue, 26 Sep 2017 13:24:57 +0300
Konstantin Belousov  wrote:


On Tue, Sep 26, 2017 at 09:18:18AM +, Emmanuel Vadot wrote:

@@ -1940,14 +1936,16 @@ add_expdir(struct dirlist **dpp, char *cp, int len)
 {
struct dirlist *dp;

-   dp = (struct dirlist *)malloc(sizeof (struct dirlist) + len);
+   dp = (struct dirlist *)malloc(sizeof (struct dirlist));

You might remove the unneeded cast as well.


Right, done in 324012.


Er, mountd has many similar casts, not just the one fixed, and worse ones
like casting dp to caddr_t before passing it to free() (caddr_t is bogus,
and free() doesn't actually take it -- its prototype converts caddr_t to
void *, just like it would convert dp's type to void *)).  Some of these
casts were needed in 1987 for unprototyped pre-StandardC code.  caddr_t
was more needed in 1977 before void * existed (free() takes a char * arg
in K).

But the main hug near here is leaking memory for strdup()).  The above
malloc() allocates 2 storage areas together (1 for the string at the
end), and seems to have a corresponding free().  Now there is an extra
separate storage error for the string and no separate free() for it.

This is not much more than a style bug too.  mountd is a long-lived
daemon, so it should avoid leaking memory, but it would probably work
OK for a few thousand mounts with no free()s at all or a few million
with no frees of strings.  But it tries to free() most things, so it
is a style bug to not try for some.

Bruce
___
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: r324013 - head/usr.bin/calendar

2017-09-26 Thread Baptiste Daroussin
Author: bapt
Date: Tue Sep 26 11:16:33 2017
New Revision: 324013
URL: https://svnweb.freebsd.org/changeset/base/324013

Log:
  calendar: replace strcpy/strcat with asprintf

Modified:
  head/usr.bin/calendar/events.c

Modified: head/usr.bin/calendar/events.c
==
--- head/usr.bin/calendar/events.c  Tue Sep 26 11:11:17 2017
(r324012)
+++ head/usr.bin/calendar/events.c  Tue Sep 26 11:16:33 2017
(r324013)
@@ -86,12 +86,9 @@ event_continue(struct event *e, char *txt)
errx(1, "event_continue: cannot allocate memory");
 
free(e->text);
-   e->text = (char *)malloc(strlen(text) + strlen(txt) + 3);
+   asprintf(>text, "%s\n%s", text, txt);
if (e->text == NULL)
errx(1, "event_continue: cannot allocate memory");
-   strcpy(e->text, text);
-   strcat(e->text, "\n");
-   strcat(e->text, txt);
free(text);
 
return;
___
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: r324007 - head/usr.sbin/mountd

2017-09-26 Thread Emmanuel Vadot
On Tue, 26 Sep 2017 13:24:57 +0300
Konstantin Belousov  wrote:

> On Tue, Sep 26, 2017 at 09:18:18AM +, Emmanuel Vadot wrote:
> > @@ -1940,14 +1936,16 @@ add_expdir(struct dirlist **dpp, char *cp, int len)
> >  {
> > struct dirlist *dp;
> >  
> > -   dp = (struct dirlist *)malloc(sizeof (struct dirlist) + len);
> > +   dp = (struct dirlist *)malloc(sizeof (struct dirlist));
> You might remove the unneeded cast as well.

 Right, done in 324012.

 Thanks,

-- 
Emmanuel Vadot  
___
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: r324012 - head/usr.sbin/mountd

2017-09-26 Thread Emmanuel Vadot
Author: manu
Date: Tue Sep 26 11:11:17 2017
New Revision: 324012
URL: https://svnweb.freebsd.org/changeset/base/324012

Log:
  mountd: Remove unneeded cast
  
  Reported by:  kib
  MFC after:1 week
  X MFC With:   r324007

Modified:
  head/usr.sbin/mountd/mountd.c

Modified: head/usr.sbin/mountd/mountd.c
==
--- head/usr.sbin/mountd/mountd.c   Tue Sep 26 11:04:08 2017
(r324011)
+++ head/usr.sbin/mountd/mountd.c   Tue Sep 26 11:11:17 2017
(r324012)
@@ -1936,7 +1936,7 @@ add_expdir(struct dirlist **dpp, char *cp, int len)
 {
struct dirlist *dp;
 
-   dp = (struct dirlist *)malloc(sizeof (struct dirlist));
+   dp = malloc(sizeof (struct dirlist));
if (dp == (struct dirlist *)NULL)
out_of_mem();
dp->dp_left = *dpp;
___
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: r324011 - in head: cddl/contrib/opensolaris/cmd/ztest sys/cddl/contrib/opensolaris/uts/common/fs/zfs sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys sys/cddl/contrib/opensolaris/uts/...

2017-09-26 Thread Andriy Gapon
Author: avg
Date: Tue Sep 26 11:04:08 2017
New Revision: 324011
URL: https://svnweb.freebsd.org/changeset/base/324011

Log:
  MFV r323535: 8585 improve batching done in zil_commit()
  
  FreeBSD notes:
  - this MFV reverts FreeBSD commit r314549 to make the merge easier
  - at present our emulation of cv_timedwait_hires is rather poor,
so I elected to use cv_timedwait_sbt directly
  Please see the differential revision for details.
  Unfortunately, I did not get any positive reviews, so there could be
  bugs in the FreeBSD-specific piece of the merge.
  Hence, the long MFC timeout.
  
  illumos/illumos-gate@1271e4b10dfaaed576c08a812f466f6e81370e5e
  
https://github.com/illumos/illumos-gate/commit/1271e4b10dfaaed576c08a812f466f6e81370e5e
  
  https://www.illumos.org/issues/8585
The current implementation of zil_commit() can introduce significant
latency, beyond what is inherent due to the latency of the underlying
storage. The additional latency comes from two main problems:
1. When there's outstanding ZIL blocks being written (i.e. there's
already a "writer thread" in progress), then any new calls to
zil_commit() will block waiting for the currently oustanding ZIL
blocks to complete. The blocks written for each "writer thread" is
coined a "batch", and there can only ever be a single "batch" being
written at a time. When a batch is being written, any new ZIL
transactions will have to wait for the next batch to be written,
which won't occur until the current batch finishes.
As a result, the underlying storage may not be used as efficiently
as possible. While "new" threads enter zil_commit() and are blocked
waiting for the next batch, it's possible that the underlying
storage isn't fully utilized by the current batch of ZIL blocks. In
that case, it'd be better to allow these new threads to generate
(and issue) a new ZIL block, such that it could be serviced by the
underlying storage concurrently with the other ZIL blocks that are
being serviced.
2. Any call to zil_commit() must wait for all ZIL blocks in its "batch"
to complete, prior to zil_commit() returning. The size of any given
batch is proportional to the number of ZIL transaction in the queue
at the time that the batch starts processing the queue; which
doesn't occur until the previous batch completes. Thus, if there's a
lot of transactions in the queue, the batch could be composed of
many ZIL blocks, and each call to zil_commit() will have to wait for
all of these writes to complete (even if the thread calling
zil_commit() only cared about one of the transactions in the batch).
  
  Reviewed by: Brad Lewis 
  Reviewed by: Matt Ahrens 
  Reviewed by: George Wilson 
  Approved by: Dan McDonald 
  Author: Prakash Surya 
  
  MFC after:1 month
  Differential Revision:https://reviews.freebsd.org/D12355

Modified:
  head/cddl/contrib/opensolaris/cmd/ztest/ztest.c
  head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dmu.c
  head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/dmu.h
  head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zil.h
  head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zil_impl.h
  head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zio.h
  head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/txg.c
  head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c
  head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zil.c
  head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zio.c
  head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zvol.c
  head/sys/cddl/contrib/opensolaris/uts/common/sys/debug.h
Directory Properties:
  head/cddl/contrib/opensolaris/   (props changed)
  head/sys/cddl/contrib/opensolaris/   (props changed)

Modified: head/cddl/contrib/opensolaris/cmd/ztest/ztest.c
==
--- head/cddl/contrib/opensolaris/cmd/ztest/ztest.c Tue Sep 26 09:34:18 
2017(r324010)
+++ head/cddl/contrib/opensolaris/cmd/ztest/ztest.c Tue Sep 26 11:04:08 
2017(r324011)
@@ -1825,13 +1825,14 @@ ztest_get_done(zgd_t *zgd, int error)
ztest_object_unlock(zd, object);
 
if (error == 0 && zgd->zgd_bp)
-   zil_add_block(zgd->zgd_zilog, zgd->zgd_bp);
+   zil_lwb_add_block(zgd->zgd_lwb, zgd->zgd_bp);
 
umem_free(zgd, sizeof (*zgd));
 }
 
 static int
-ztest_get_data(void *arg, lr_write_t *lr, char *buf, zio_t *zio)
+ztest_get_data(void *arg, lr_write_t *lr, char *buf, struct lwb *lwb,
+zio_t *zio)
 {
ztest_ds_t *zd = arg;
objset_t *os = zd->zd_os;
@@ -1845,6 +1846,10 @@ ztest_get_data(void *arg, lr_write_t *lr, char *buf, z
zgd_t *zgd;
   

Re: svn commit: r324007 - head/usr.sbin/mountd

2017-09-26 Thread Konstantin Belousov
On Tue, Sep 26, 2017 at 09:18:18AM +, Emmanuel Vadot wrote:
> @@ -1940,14 +1936,16 @@ add_expdir(struct dirlist **dpp, char *cp, int len)
>  {
>   struct dirlist *dp;
>  
> - dp = (struct dirlist *)malloc(sizeof (struct dirlist) + len);
> + dp = (struct dirlist *)malloc(sizeof (struct dirlist));
You might remove the unneeded cast as well.
___
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: r323873 - head/sys/netgraph

2017-09-26 Thread Eugene Grosbein
On 26.09.2017 03:59, Gleb Smirnoff wrote:
> On Thu, Sep 21, 2017 at 08:16:11PM +, Eugene Grosbein wrote:
> E> Author: eugen (ports committer)
> E> Date: Thu Sep 21 20:16:10 2017
> E> New Revision: 323873
> E> URL: https://svnweb.freebsd.org/changeset/base/323873
> E> 
> E> Log:
> E>   Unprotected modification of ng_iface(4) private data leads to kernel 
> panic.
> E>   Fix a race with per-node read-mostly lock and refcounting for a hook.
> 
> The patch is far from ideal. Netgraph already has internal locking,
> which guarantess write semantics for "disconnect" and "newhook"
> scenarios. As well as read semantics for "rcvdata".
> 
> Since ng_iface is a gate node, that gates data between netgraph and the
> big network stack, it of course needs extra locking in the interface
> output method. But better piggyback on the netgraph locking, rather than
> add your own, IMHO.

I'm afraid you have not read the change well enough.
It does utilizes generic netgraph locking like NG_HOOK_REF(hook)
for entities visible to base netgraph code.

And it uses own locking only to protect private ng_iface structures
from parallel modifications with another kernel thread runnning same
ng_iface code. It uses lightweight rmlock there as that is network hot path
and anyway, other netgraph code has nothing to do with node's private data.

___
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: r324007 - head/usr.sbin/mountd

2017-09-26 Thread Emmanuel Vadot
Author: manu
Date: Tue Sep 26 09:18:18 2017
New Revision: 324007
URL: https://svnweb.freebsd.org/changeset/base/324007

Log:
  mountd: Replace malloc+strcpy to strdup
  
  Reviewed by:  bapt
  MFC after:1 week
  Sponsored by: Gandi.net
  Differential Revision:https://reviews.freebsd.org/D12503

Modified:
  head/usr.sbin/mountd/mountd.c

Modified: head/usr.sbin/mountd/mountd.c
==
--- head/usr.sbin/mountd/mountd.c   Tue Sep 26 09:01:56 2017
(r324006)
+++ head/usr.sbin/mountd/mountd.c   Tue Sep 26 09:18:18 2017
(r324007)
@@ -101,7 +101,7 @@ struct dirlist {
struct dirlist  *dp_right;
int dp_flag;
struct hostlist *dp_hosts;  /* List of hosts this dir exported to */
-   chardp_dirp[1]; /* Actually malloc'd to size of dir */
+   char*dp_dirp;
 };
 /* dp_flag bits */
 #defineDP_DEFSET   0x1
@@ -1525,12 +1525,8 @@ get_exportlist_one(void)
if (ep == (struct exportlist *)NULL) {
ep = get_exp();
ep->ex_fs = fsb.f_fsid;
-   ep->ex_fsdir = (char *)malloc
-   (strlen(fsb.f_mntonname) + 1);
-   if (ep->ex_fsdir)
-   strcpy(ep->ex_fsdir,
-   fsb.f_mntonname);
-   else
+   ep->ex_fsdir = 
strdup(fsb.f_mntonname);
+   if (ep->ex_fsdir == NULL)
out_of_mem();
if (debug)
warnx(
@@ -1940,14 +1936,16 @@ add_expdir(struct dirlist **dpp, char *cp, int len)
 {
struct dirlist *dp;
 
-   dp = (struct dirlist *)malloc(sizeof (struct dirlist) + len);
+   dp = (struct dirlist *)malloc(sizeof (struct dirlist));
if (dp == (struct dirlist *)NULL)
out_of_mem();
dp->dp_left = *dpp;
dp->dp_right = (struct dirlist *)NULL;
dp->dp_flag = 0;
dp->dp_hosts = (struct hostlist *)NULL;
-   strcpy(dp->dp_dirp, cp);
+   dp->dp_dirp = strndup(cp, len);
+   if (dp->dp_dirp == NULL)
+   out_of_mem();
*dpp = dp;
return (dp->dp_dirp);
 }
___
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"