From owner-svn-src-stable-12@freebsd.org Sun Apr 21 00:05:13 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id B411A1579F38; Sun, 21 Apr 2019 00:05:13 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 2431780252; Sun, 21 Apr 2019 00:05:13 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id EE9B01D754; Sun, 21 Apr 2019 00:05:12 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3L05CS1004362; Sun, 21 Apr 2019 00:05:12 GMT (envelope-from rmacklem@FreeBSD.org) Received: (from rmacklem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3L05CY6004361; Sun, 21 Apr 2019 00:05:12 GMT (envelope-from rmacklem@FreeBSD.org) Message-Id: <201904210005.x3L05CY6004361@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: rmacklem set sender to rmacklem@FreeBSD.org using -f From: Rick Macklem Date: Sun, 21 Apr 2019 00:05:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346461 - stable/12/usr.sbin/nfsuserd X-SVN-Group: stable-12 X-SVN-Commit-Author: rmacklem X-SVN-Commit-Paths: stable/12/usr.sbin/nfsuserd X-SVN-Commit-Revision: 346461 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 2431780252 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.96 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.96)[-0.965,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 21 Apr 2019 00:05:14 -0000 Author: rmacklem Date: Sun Apr 21 00:05:12 2019 New Revision: 346461 URL: https://svnweb.freebsd.org/changeset/base/346461 Log: MFC: r345994 Fix nfsuserd so that it handles the mapped localhost address when jails are enabled. The nfsuserd(8) daemon does not function correctly when jails are enabled, since localhost gets mapped to another IP address and, as such, the upcall RPC fails. This patch fixes the problem by doing a getsockname(2) of a socket mapped to localhost to find out what the correct address is for the comparison test with the upcall's from IP address. This patch also adds INET6 support and the required #ifdef's for INET and INET6. It now uses INET6 by default for the upcalls, if the kernel has INET6 support and the daemon is also built with INET6 support. Modified: stable/12/usr.sbin/nfsuserd/Makefile stable/12/usr.sbin/nfsuserd/nfsuserd.c Directory Properties: stable/12/ (props changed) Modified: stable/12/usr.sbin/nfsuserd/Makefile ============================================================================== --- stable/12/usr.sbin/nfsuserd/Makefile Sat Apr 20 23:46:06 2019 (r346460) +++ stable/12/usr.sbin/nfsuserd/Makefile Sun Apr 21 00:05:12 2019 (r346461) @@ -1,7 +1,16 @@ # $FreeBSD$ +.include + PROG= nfsuserd MAN= nfsuserd.8 WARNS?= 3 + +.if ${MK_INET_SUPPORT} != "no" +CFLAGS+= -DINET +.endif +.if ${MK_INET6_SUPPORT} != "no" +CFLAGS+= -DINET6 +.endif .include Modified: stable/12/usr.sbin/nfsuserd/nfsuserd.c ============================================================================== --- stable/12/usr.sbin/nfsuserd/nfsuserd.c Sat Apr 20 23:46:06 2019 (r346460) +++ stable/12/usr.sbin/nfsuserd/nfsuserd.c Sun Apr 21 00:05:12 2019 (r346461) @@ -40,6 +40,10 @@ __FBSDID("$FreeBSD$"); #include #include +#include + +#include + #include #include @@ -72,6 +76,7 @@ static void nfsuserdsrv(struct svc_req *, SVCXPRT *); static bool_t xdr_getid(XDR *, caddr_t); static bool_t xdr_getname(XDR *, caddr_t); static bool_t xdr_retval(XDR *, caddr_t); +static int nfsbind_localhost(void); #define MAXNAME 1024 #define MAXNFSUSERD 20 @@ -94,6 +99,10 @@ gid_t defaultgid = 65533; int verbose = 0, im_a_slave = 0, nfsuserdcnt = -1, forcestart = 0; int defusertimeout = DEFUSERTIMEOUT, manage_gids = 0; pid_t slaves[MAXNFSUSERD]; +static struct sockaddr_storage fromip; +#ifdef INET6 +static struct in6_addr in6loopback = IN6ADDR_LOOPBACK_INIT; +#endif int main(int argc, char *argv[]) @@ -105,13 +114,20 @@ main(int argc, char *argv[]) struct group *grp; int sock, one = 1; SVCXPRT *udptransp; - u_short portnum; + struct nfsuserd_args nargs; sigset_t signew; char hostname[MAXHOSTNAMELEN + 1], *cp; struct addrinfo *aip, hints; static uid_t check_dups[MAXUSERMAX]; gid_t grps[NGROUPS]; int ngroup; +#ifdef INET + struct sockaddr_in *sin; +#endif +#ifdef INET6 + struct sockaddr_in6 *sin6; +#endif + int s; if (modfind("nfscommon") < 0) { /* Not present in kernel, try loading it */ @@ -144,6 +160,37 @@ main(int argc, char *argv[]) } } } + + /* + * See if this server handles IPv4 or IPv6 and set up the default + * localhost address. + */ + s = -1; +#ifdef INET6 + s = socket(PF_INET6, SOCK_DGRAM, 0); + if (s >= 0) { + fromip.ss_family = AF_INET6; + fromip.ss_len = sizeof(struct sockaddr_in6); + sin6 = (struct sockaddr_in6 *)&fromip; + sin6->sin6_addr = in6loopback; + close(s); + } +#endif /* INET6 */ +#ifdef INET + if (s < 0) { + s = socket(PF_INET, SOCK_DGRAM, 0); + if (s >= 0) { + fromip.ss_family = AF_INET; + fromip.ss_len = sizeof(struct sockaddr_in); + sin = (struct sockaddr_in *)&fromip; + sin->sin_addr.s_addr = htonl(INADDR_LOOPBACK); + close(s); + } + } +#endif /* INET */ + if (s < 0) + err(1, "Can't create a inet/inet6 socket"); + nid.nid_usermax = DEFUSERMAX; nid.nid_usertimeout = defusertimeout; @@ -245,11 +292,12 @@ main(int argc, char *argv[]) for (i = 0; i < nfsuserdcnt; i++) slaves[i] = (pid_t)-1; + nargs.nuserd_family = fromip.ss_family; /* * Set up the service port to accept requests via UDP from - * localhost (127.0.0.1). + * localhost (INADDR_LOOPBACK or IN6ADDR_LOOPBACK_INIT). */ - if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) + if ((sock = socket(nargs.nuserd_family, SOCK_DGRAM, IPPROTO_UDP)) < 0) err(1, "cannot create udp socket"); /* @@ -272,11 +320,11 @@ main(int argc, char *argv[]) /* * Tell the kernel what my port# is. */ - portnum = htons(udptransp->xp_port); + nargs.nuserd_port = htons(udptransp->xp_port); #ifdef DEBUG - printf("portnum=0x%x\n", portnum); + printf("portnum=0x%x\n", nargs.nuserd_port); #else - if (nfssvc(NFSSVC_NFSUSERDPORT, (caddr_t)&portnum) < 0) { + if (nfssvc(NFSSVC_NFSUSERDPORT | NFSSVC_NEWSTRUCT, &nargs) < 0) { if (errno == EPERM) { fprintf(stderr, "Can't start nfsuserd when already running"); @@ -457,27 +505,92 @@ nfsuserdsrv(struct svc_req *rqstp, SVCXPRT *transp) struct passwd *pwd; struct group *grp; int error; +#if defined(INET) || defined(INET6) u_short sport; + int ret; +#endif struct info info; struct nfsd_idargs nid; - u_int32_t saddr; gid_t grps[NGROUPS]; int ngroup; +#ifdef INET + struct sockaddr_in *fromsin, *sin; +#endif +#ifdef INET6 + struct sockaddr_in6 *fromsin6, *sin6; + char buf[INET6_ADDRSTRLEN]; +#endif /* - * Only handle requests from 127.0.0.1 on a reserved port number. + * Only handle requests from localhost on a reserved port number. + * If the upcall is from a different address, call nfsbind_localhost() + * to check for a remapping of localhost, due to jails. * (Since a reserved port # at localhost implies a client with * local root, there won't be a security breach. This is about * the only case I can think of where a reserved port # means * something.) */ - sport = ntohs(transp->xp_raddr.sin_port); - saddr = ntohl(transp->xp_raddr.sin_addr.s_addr); - if ((rqstp->rq_proc != NULLPROC && sport >= IPPORT_RESERVED) || - saddr != 0x7f000001) { - syslog(LOG_ERR, "req from ip=0x%x port=%d\n", saddr, sport); - svcerr_weakauth(transp); - return; + if (rqstp->rq_proc != NULLPROC) { + switch (fromip.ss_family) { +#ifdef INET + case AF_INET: + if (transp->xp_rtaddr.len < sizeof(*sin)) { + syslog(LOG_ERR, "xp_rtaddr too small"); + svcerr_weakauth(transp); + return; + } + sin = (struct sockaddr_in *)transp->xp_rtaddr.buf; + fromsin = (struct sockaddr_in *)&fromip; + sport = ntohs(sin->sin_port); + if (sport >= IPPORT_RESERVED) { + syslog(LOG_ERR, "not a reserved port#"); + svcerr_weakauth(transp); + return; + } + ret = 1; + if (sin->sin_addr.s_addr != fromsin->sin_addr.s_addr) + ret = nfsbind_localhost(); + if (ret == 0 || sin->sin_addr.s_addr != + fromsin->sin_addr.s_addr) { + syslog(LOG_ERR, "bad from ip %s", + inet_ntoa(sin->sin_addr)); + svcerr_weakauth(transp); + return; + } + break; +#endif /* INET */ +#ifdef INET6 + case AF_INET6: + if (transp->xp_rtaddr.len < sizeof(*sin6)) { + syslog(LOG_ERR, "xp_rtaddr too small"); + svcerr_weakauth(transp); + return; + } + sin6 = (struct sockaddr_in6 *)transp->xp_rtaddr.buf; + fromsin6 = (struct sockaddr_in6 *)&fromip; + sport = ntohs(sin6->sin6_port); + if (sport >= IPV6PORT_RESERVED) { + syslog(LOG_ERR, "not a reserved port#"); + svcerr_weakauth(transp); + return; + } + ret = 1; + if (!IN6_ARE_ADDR_EQUAL(&sin6->sin6_addr, + &fromsin6->sin6_addr)) + ret = nfsbind_localhost(); + if (ret == 0 || !IN6_ARE_ADDR_EQUAL(&sin6->sin6_addr, + &fromsin6->sin6_addr)) { + if (inet_ntop(AF_INET6, &sin6->sin6_addr, buf, + INET6_ADDRSTRLEN) != NULL) + syslog(LOG_ERR, "bad from ip %s", buf); + else + syslog(LOG_ERR, "bad from ip6 addr"); + svcerr_weakauth(transp); + return; + } + break; +#endif /* INET6 */ + } } switch (rqstp->rq_proc) { case NULLPROC: @@ -716,6 +829,67 @@ cleanup_term(int signo __unused) exit(1); } exit(0); +} + +/* + * Get the IP address that the localhost address maps to. + * This is needed when jails map localhost to another IP address. + */ +static int +nfsbind_localhost(void) +{ +#ifdef INET + struct sockaddr_in sin; +#endif +#ifdef INET6 + struct sockaddr_in6 sin6; +#endif + socklen_t slen; + int ret, s; + + switch (fromip.ss_family) { +#ifdef INET6 + case AF_INET6: + s = socket(PF_INET6, SOCK_DGRAM, 0); + if (s < 0) + return (0); + memset(&sin6, 0, sizeof(sin6)); + sin6.sin6_len = sizeof(sin6); + sin6.sin6_family = AF_INET6; + sin6.sin6_addr = in6loopback; + sin6.sin6_port = 0; + ret = bind(s, (struct sockaddr *)&sin6, sizeof(sin6)); + if (ret < 0) { + close(s); + return (0); + } + break; +#endif /* INET6 */ +#ifdef INET + case AF_INET: + s = socket(PF_INET, SOCK_DGRAM, 0); + if (s < 0) + return (0); + memset(&sin, 0, sizeof(sin)); + sin.sin_len = sizeof(sin); + sin.sin_family = AF_INET; + sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + sin.sin_port = 0; + ret = bind(s, (struct sockaddr *)&sin, sizeof(sin)); + if (ret < 0) { + close(s); + return (0); + } + break; +#endif /* INET */ + } + memset(&fromip, 0, sizeof(fromip)); + slen = sizeof(fromip); + ret = getsockname(s, (struct sockaddr *)&fromip, &slen); + close(s); + if (ret < 0) + return (0); + return (1); } static void From owner-svn-src-stable-12@freebsd.org Sun Apr 21 00:11:59 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id D98EF157A1D7; Sun, 21 Apr 2019 00:11:59 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 7E22080753; Sun, 21 Apr 2019 00:11:59 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 5837F1D8D5; Sun, 21 Apr 2019 00:11:59 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3L0Bxfw009080; Sun, 21 Apr 2019 00:11:59 GMT (envelope-from rmacklem@FreeBSD.org) Received: (from rmacklem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3L0BxWF009079; Sun, 21 Apr 2019 00:11:59 GMT (envelope-from rmacklem@FreeBSD.org) Message-Id: <201904210011.x3L0BxWF009079@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: rmacklem set sender to rmacklem@FreeBSD.org using -f From: Rick Macklem Date: Sun, 21 Apr 2019 00:11:59 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346462 - stable/12/usr.sbin/nfsuserd X-SVN-Group: stable-12 X-SVN-Commit-Author: rmacklem X-SVN-Commit-Paths: stable/12/usr.sbin/nfsuserd X-SVN-Commit-Revision: 346462 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 7E22080753 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.96 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.96)[-0.961,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 21 Apr 2019 00:12:00 -0000 Author: rmacklem Date: Sun Apr 21 00:11:58 2019 New Revision: 346462 URL: https://svnweb.freebsd.org/changeset/base/346462 Log: MFC: r345995 Delete the BUGS entry related to failing when jails are enabled. r345994 has finally fixed the bug that caused the nfsuserd(8) daemon to fail when jails were enabled, so delete the BUGS entry from the man page. This is a content change. Modified: stable/12/usr.sbin/nfsuserd/nfsuserd.8 Directory Properties: stable/12/ (props changed) Modified: stable/12/usr.sbin/nfsuserd/nfsuserd.8 ============================================================================== --- stable/12/usr.sbin/nfsuserd/nfsuserd.8 Sun Apr 21 00:05:12 2019 (r346461) +++ stable/12/usr.sbin/nfsuserd/nfsuserd.8 Sun Apr 21 00:11:58 2019 (r346462) @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd August 22, 2018 +.Dd April 6, 2019 .Dt NFSUSERD 8 .Os .Sh NAME @@ -131,9 +131,3 @@ those requests fail and the library functions don't re and .Xr passwd 5 for more information on how the databases are accessed. -.Pp -Since the kernel communicates with the -.Nm -daemon via an upcall that uses the IP address 127.0.0.1, it does not work correctly when -.Xr jail 8 -are used and can crash the system. From owner-svn-src-stable-12@freebsd.org Sun Apr 21 09:11:24 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 16D7315872F7; Sun, 21 Apr 2019 09:11:24 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id AA9C46ADAB; Sun, 21 Apr 2019 09:11:23 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 8591723347; Sun, 21 Apr 2019 09:11:23 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3L9BNF8094076; Sun, 21 Apr 2019 09:11:23 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3L9BNQr094075; Sun, 21 Apr 2019 09:11:23 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201904210911.x3L9BNQr094075@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Sun, 21 Apr 2019 09:11:23 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346484 - stable/12/libexec/rtld-elf X-SVN-Group: stable-12 X-SVN-Commit-Author: kib X-SVN-Commit-Paths: stable/12/libexec/rtld-elf X-SVN-Commit-Revision: 346484 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: AA9C46ADAB X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.96 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.96)[-0.958,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 21 Apr 2019 09:11:24 -0000 Author: kib Date: Sun Apr 21 09:11:22 2019 New Revision: 346484 URL: https://svnweb.freebsd.org/changeset/base/346484 Log: MFC r346216: ld-elf.so: make LD_DEBUG always functional. Modified: stable/12/libexec/rtld-elf/Makefile stable/12/libexec/rtld-elf/debug.h Directory Properties: stable/12/ (props changed) Modified: stable/12/libexec/rtld-elf/Makefile ============================================================================== --- stable/12/libexec/rtld-elf/Makefile Sun Apr 21 04:35:49 2019 (r346483) +++ stable/12/libexec/rtld-elf/Makefile Sun Apr 21 09:11:22 2019 (r346484) @@ -2,7 +2,7 @@ # Use the following command to build local debug version of dynamic # linker: -# make DEBUG_FLAGS=-g DEBUG=-DDEBUG WITHOUT_TESTS=yes all +# make DEBUG_FLAGS=-g WITHOUT_TESTS=yes all .include PACKAGE= clibs Modified: stable/12/libexec/rtld-elf/debug.h ============================================================================== --- stable/12/libexec/rtld-elf/debug.h Sun Apr 21 04:35:49 2019 (r346483) +++ stable/12/libexec/rtld-elf/debug.h Sun Apr 21 09:11:22 2019 (r346484) @@ -39,10 +39,10 @@ #include #include -extern void debug_printf(const char *, ...) __printflike(1, 2); +void debug_printf(const char *, ...) __printflike(1, 2); extern int debug; -#ifdef DEBUG +#ifndef NO_LD_DEBUG #define dbg(...) debug_printf(__VA_ARGS__) #else #define dbg(...) ((void) 0) From owner-svn-src-stable-12@freebsd.org Sun Apr 21 19:49:16 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 398B81582F7C; Sun, 21 Apr 2019 19:49:16 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id CF2368773B; Sun, 21 Apr 2019 19:49:15 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id AFBD12033; Sun, 21 Apr 2019 19:49:15 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3LJnFEP037531; Sun, 21 Apr 2019 19:49:15 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3LJnFoj037530; Sun, 21 Apr 2019 19:49:15 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201904211949.x3LJnFoj037530@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Sun, 21 Apr 2019 19:49:15 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346494 - stable/12/sys/arm/ti X-SVN-Group: stable-12 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: stable/12/sys/arm/ti X-SVN-Commit-Revision: 346494 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: CF2368773B X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.97 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.97)[-0.968,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 21 Apr 2019 19:49:16 -0000 Author: ian Date: Sun Apr 21 19:49:15 2019 New Revision: 346494 URL: https://svnweb.freebsd.org/changeset/base/346494 Log: MFC r342652: Support the SPI mode and bus clock frequency parameters set by the devices requesting SPI transfers. Modified: stable/12/sys/arm/ti/ti_spi.c Modified: stable/12/sys/arm/ti/ti_spi.c ============================================================================== --- stable/12/sys/arm/ti/ti_spi.c Sun Apr 21 19:30:37 2019 (r346493) +++ stable/12/sys/arm/ti/ti_spi.c Sun Apr 21 19:49:15 2019 (r346494) @@ -446,7 +446,7 @@ ti_spi_transfer(device_t dev, device_t child, struct s { int err; struct ti_spi_softc *sc; - uint32_t reg, cs; + uint32_t clockhz, cs, mode, reg; sc = device_get_softc(dev); @@ -457,6 +457,8 @@ ti_spi_transfer(device_t dev, device_t child, struct s /* Get the proper chip select for this child. */ spibus_get_cs(child, &cs); + spibus_get_clock(child, &clockhz); + spibus_get_mode(child, &mode); cs &= ~SPIBUS_CS_HIGH; @@ -466,6 +468,13 @@ ti_spi_transfer(device_t dev, device_t child, struct s return (EINVAL); } + if (mode > 3) + { + device_printf(dev, "Invalid mode %d requested by %s\n", mode, + device_get_nameunit(child)); + return (EINVAL); + } + TI_SPI_LOCK(sc); /* If the controller is in use wait until it is available. */ @@ -487,8 +496,8 @@ ti_spi_transfer(device_t dev, device_t child, struct s /* Disable FIFO for now. */ sc->sc_fifolvl = 1; - /* Use a safe clock - 500kHz. */ - ti_spi_set_clock(sc, sc->sc_cs, 500000); + /* Set the bus frequency. */ + ti_spi_set_clock(sc, sc->sc_cs, clockhz); /* Disable the FIFO. */ TI_SPI_WRITE(sc, MCSPI_XFERLEVEL, 0); @@ -500,6 +509,7 @@ ti_spi_transfer(device_t dev, device_t child, struct s MCSPI_CONF_DPE1 | MCSPI_CONF_DPE0 | MCSPI_CONF_DMAR | MCSPI_CONF_DMAW | MCSPI_CONF_EPOL); reg |= MCSPI_CONF_DPE0 | MCSPI_CONF_EPOL | MCSPI_CONF_WL8BITS; + reg |= mode; /* POL and PHA are the low bits, we can just OR-in mode */ TI_SPI_WRITE(sc, MCSPI_CONF_CH(sc->sc_cs), reg); #if 0 From owner-svn-src-stable-12@freebsd.org Sun Apr 21 19:50:31 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 97DDC1583033; Sun, 21 Apr 2019 19:50:31 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 3AA2D8789D; Sun, 21 Apr 2019 19:50:31 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 0EE612037; Sun, 21 Apr 2019 19:50:31 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3LJoUsB037754; Sun, 21 Apr 2019 19:50:30 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3LJoURo037753; Sun, 21 Apr 2019 19:50:30 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201904211950.x3LJoURo037753@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Sun, 21 Apr 2019 19:50:30 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346495 - stable/12/sys/arm/arm X-SVN-Group: stable-12 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: stable/12/sys/arm/arm X-SVN-Commit-Revision: 346495 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 3AA2D8789D X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.97 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.97)[-0.968,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 21 Apr 2019 19:50:31 -0000 Author: ian Date: Sun Apr 21 19:50:30 2019 New Revision: 346495 URL: https://svnweb.freebsd.org/changeset/base/346495 Log: MFC r342850: Add a missing \n to a bootverbose printf. Modified: stable/12/sys/arm/arm/mpcore_timer.c Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/arm/arm/mpcore_timer.c ============================================================================== --- stable/12/sys/arm/arm/mpcore_timer.c Sun Apr 21 19:49:15 2019 (r346494) +++ stable/12/sys/arm/arm/mpcore_timer.c Sun Apr 21 19:50:30 2019 (r346495) @@ -420,7 +420,7 @@ arm_tmr_attach(device_t dev) tc_err = attach_tc(sc); else if (bootverbose) device_printf(sc->dev, - "not using variable-frequency device as timecounter"); + "not using variable-frequency device as timecounter\n"); sc->memrid++; sc->irqrid++; } From owner-svn-src-stable-12@freebsd.org Sun Apr 21 20:40:51 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 57AAB1583E0F; Sun, 21 Apr 2019 20:40:51 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id C203288E6F; Sun, 21 Apr 2019 20:40:50 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 9FD982904; Sun, 21 Apr 2019 20:40:50 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3LKeorw069755; Sun, 21 Apr 2019 20:40:50 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3LKeoRX069754; Sun, 21 Apr 2019 20:40:50 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201904212040.x3LKeoRX069754@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Sun, 21 Apr 2019 20:40:50 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346496 - in stable/12/stand/uboot: common lib X-SVN-Group: stable-12 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: in stable/12/stand/uboot: common lib X-SVN-Commit-Revision: 346496 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: C203288E6F X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.96 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.96)[-0.962,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 21 Apr 2019 20:40:51 -0000 Author: ian Date: Sun Apr 21 20:40:49 2019 New Revision: 346496 URL: https://svnweb.freebsd.org/changeset/base/346496 Log: MFC r344247: Make uboot_devdesc properly alias disk_devdesc, so that parsing the u-boot loaderdev variable works correctly. The uboot_devdesc struct is variously cast back and forth between uboot_devdesc and disk_devdesc as pointers are handed off through various opaque interfaces. uboot_devdesc attempted to mimic the layout of disk_devdesc by having a devdesc struct, followed by a union of some device-specific stuff that included a struct that contains the same fields as a disk_devdesc. However, one of those fields inside the struct is 64-bit which causes the entire union to be 64-bit aligned -- 32 bits of padding is added between the struct devdesc and the union, so the whole mess ends up NOT properly mimicking a disk_devdesc after all. (In disk_devdesc there is also 32 bits of padding, but it shows up immediately before the d_offset field, rather than before the whole collection of d_* fields.) This fixes the problem by using an anonymous union to overlay the devdesc field uboot network devices need with the disk_devdesc that uboot storage devices need. This is a different solution than the one contributed with the PR (so if anything goes wrong, the blame goes to me), but 95% of the credit for this fix goes to Pawel Worach and Manuel Stuhn who analyzed the problem and proposed a fix. PR: 233097 Modified: stable/12/stand/uboot/common/main.c stable/12/stand/uboot/lib/libuboot.h Directory Properties: stable/12/ (props changed) Modified: stable/12/stand/uboot/common/main.c ============================================================================== --- stable/12/stand/uboot/common/main.c Sun Apr 21 19:50:30 2019 (r346495) +++ stable/12/stand/uboot/common/main.c Sun Apr 21 20:40:49 2019 (r346496) @@ -310,13 +310,13 @@ print_disk_probe_info() char slice[32]; char partition[32]; - if (currdev.d_disk.slice > 0) - sprintf(slice, "%d", currdev.d_disk.slice); + if (currdev.d_disk.d_slice > 0) + sprintf(slice, "%d", currdev.d_disk.d_slice); else strcpy(slice, ""); - if (currdev.d_disk.partition >= 0) - sprintf(partition, "%d", currdev.d_disk.partition); + if (currdev.d_disk.d_partition >= 0) + sprintf(partition, "%d", currdev.d_disk.d_partition); else strcpy(partition, ""); @@ -332,8 +332,8 @@ probe_disks(int devidx, int load_type, int load_unit, int open_result, unit; struct open_file f; - currdev.d_disk.slice = load_slice; - currdev.d_disk.partition = load_partition; + currdev.d_disk.d_slice = load_slice; + currdev.d_disk.d_partition = load_partition; f.f_devdata = &currdev; open_result = -1; Modified: stable/12/stand/uboot/lib/libuboot.h ============================================================================== --- stable/12/stand/uboot/lib/libuboot.h Sun Apr 21 19:50:30 2019 (r346495) +++ stable/12/stand/uboot/lib/libuboot.h Sun Apr 21 20:40:49 2019 (r346496) @@ -27,18 +27,14 @@ * $FreeBSD$ */ +#include + struct uboot_devdesc { - struct devdesc dd; /* Must be first. */ union { - struct { - int slice; - int partition; - off_t offset; - } disk; - } d_kind; + struct devdesc dd; + struct disk_devdesc d_disk; + }; }; - -#define d_disk d_kind.disk /* * Default network packet alignment in memory. On arm arches packets must be From owner-svn-src-stable-12@freebsd.org Sun Apr 21 20:46:50 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id C15BA1584042; Sun, 21 Apr 2019 20:46:50 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 5E6F68924F; Sun, 21 Apr 2019 20:46:50 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4E0332A8E; Sun, 21 Apr 2019 20:46:50 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3LKkohg072637; Sun, 21 Apr 2019 20:46:50 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3LKko65072636; Sun, 21 Apr 2019 20:46:50 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201904212046.x3LKko65072636@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Sun, 21 Apr 2019 20:46:50 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346497 - stable/12/stand/uboot/common X-SVN-Group: stable-12 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: stable/12/stand/uboot/common X-SVN-Commit-Revision: 346497 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 5E6F68924F X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.96 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.96)[-0.962,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 21 Apr 2019 20:46:51 -0000 Author: ian Date: Sun Apr 21 20:46:49 2019 New Revision: 346497 URL: https://svnweb.freebsd.org/changeset/base/346497 Log: MFC r344260, r344335 r344260: Allow the u-boot loaderdev env var to be formatted in the "usual" loader(8) way: device[s|p]. E.g., disk0s2a or disk3p12. The code first tries to parse the variable in this format using the standard disk_parsedev(). If that fails, it falls back to parsing the legacy format that has been supported by ubldr for years. In addition to 'disk', all the valid uboot device names can also be used: mmc, sata, usb, ide, scsi. The 'disk' device serves as an alias for all those types and will match the Nth storage-type device found (where N is the unit number). r344335: Fix the handling of legacy-format devices in the u-boot loaderdev variable. When I added support for the standard loader(8) disk0s2a: type formats, the parsing of legacy format was broken because it also contains a colon, but it comes before the slice and partition. That would cause disk_parsedev() to return success with the slice and partition set to wildcard values. This change examines the string first, and if it contains spaces, dots, or a colon at any position other than the end, it must be a legacy-format string and we don't even try to use disk_parsedev() on it. Modified: stable/12/stand/uboot/common/main.c Directory Properties: stable/12/ (props changed) Modified: stable/12/stand/uboot/common/main.c ============================================================================== --- stable/12/stand/uboot/common/main.c Sun Apr 21 20:40:49 2019 (r346496) +++ stable/12/stand/uboot/common/main.c Sun Apr 21 20:46:49 2019 (r346497) @@ -182,6 +182,14 @@ device_typename(int type) * The returned values for slice and partition are interpreted by * disk_open(). * + * The device string can be a standard loader(8) disk specifier: + * + * disks disk0s1 + * disks disk1s2a + * diskp disk0p4 + * + * or one of the following formats: + * * Valid device strings: For device types: * * DEV_TYP_STOR, DEV_TYP_NET @@ -198,6 +206,7 @@ device_typename(int type) static void get_load_device(int *type, int *unit, int *slice, int *partition) { + struct disk_devdesc dev; char *devstr; const char *p; char *endp; @@ -215,6 +224,26 @@ get_load_device(int *type, int *unit, int *slice, int printf("U-Boot env: loaderdev='%s'\n", devstr); p = get_device_type(devstr, type); + + /* + * If type is DEV_TYP_STOR we have a disk-like device. If the remainder + * of the string contains spaces, dots, or a colon in any location other + * than the last char, it's legacy format. Otherwise it might be + * standard loader(8) format (e.g., disk0s2a or mmc1p12), so try to + * parse the remainder of the string as such, and if it works, return + * those results. Otherwise we'll fall through to the code that parses + * the legacy format. + */ + if (*type & DEV_TYP_STOR) { + size_t len = strlen(p); + if (strcspn(p, " .") == len && strcspn(p, ":") >= len - 1 && + disk_parsedev(&dev, p, NULL) == 0) { + *unit = dev.dd.d_unit; + *slice = dev.d_slice; + *partition = dev.d_partition; + return; + } + } /* Ignore optional spaces after the device name. */ while (*p == ' ') From owner-svn-src-stable-12@freebsd.org Sun Apr 21 20:50:56 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 69DEF15840F1; Sun, 21 Apr 2019 20:50:56 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 0CB7C893C7; Sun, 21 Apr 2019 20:50:56 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id D65D02AB1; Sun, 21 Apr 2019 20:50:55 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3LKotY0074371; Sun, 21 Apr 2019 20:50:55 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3LKotwf074370; Sun, 21 Apr 2019 20:50:55 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201904212050.x3LKotwf074370@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Sun, 21 Apr 2019 20:50:55 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346498 - stable/12/sys/arm/freescale/imx X-SVN-Group: stable-12 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: stable/12/sys/arm/freescale/imx X-SVN-Commit-Revision: 346498 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 0CB7C893C7 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.96 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.96)[-0.959,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 21 Apr 2019 20:50:56 -0000 Author: ian Date: Sun Apr 21 20:50:55 2019 New Revision: 346498 URL: https://svnweb.freebsd.org/changeset/base/346498 Log: MFC r345000: Mark the imx_spi device busy while transfers are in progress, so that the module can't be unloaded while interrupts are pending. Modified: stable/12/sys/arm/freescale/imx/imx_spi.c Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/arm/freescale/imx/imx_spi.c ============================================================================== --- stable/12/sys/arm/freescale/imx/imx_spi.c Sun Apr 21 20:46:49 2019 (r346497) +++ stable/12/sys/arm/freescale/imx/imx_spi.c Sun Apr 21 20:50:55 2019 (r346498) @@ -424,6 +424,7 @@ spi_transfer(device_t dev, device_t child, struct spi_ } mtx_lock(&sc->mtx); + device_busy(sc->dev); if (sc->debug >= 1) { device_printf(sc->dev, @@ -448,6 +449,7 @@ spi_transfer(device_t dev, device_t child, struct spi_ spi_set_chipsel(sc, cs, false); WR4(sc, ECSPI_CTLREG, 0); + device_unbusy(sc->dev); mtx_unlock(&sc->mtx); return (err); @@ -468,11 +470,11 @@ static int spi_detach(device_t dev) { struct spi_softc *sc = device_get_softc(dev); - int idx; + int error, idx; - mtx_lock(&sc->mtx); + if ((error = bus_generic_detach(sc->dev)) != 0) + return (error); - bus_generic_detach(sc->dev); if (sc->spibus != NULL) device_delete_child(dev, sc->spibus); @@ -488,7 +490,6 @@ spi_detach(device_t dev) if (sc->memres != NULL) bus_release_resource(sc->dev, SYS_RES_MEMORY, 0, sc->memres); - mtx_unlock(&sc->mtx); mtx_destroy(&sc->mtx); return (0); From owner-svn-src-stable-12@freebsd.org Sun Apr 21 20:53:16 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id B1A0115842B7; Sun, 21 Apr 2019 20:53:16 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 529C88972E; Sun, 21 Apr 2019 20:53:16 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 0E1312C30; Sun, 21 Apr 2019 20:53:16 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3LKrFXp077689; Sun, 21 Apr 2019 20:53:15 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3LKrFXG077688; Sun, 21 Apr 2019 20:53:15 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201904212053.x3LKrFXG077688@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Sun, 21 Apr 2019 20:53:15 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346499 - stable/12/sys/kern X-SVN-Group: stable-12 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: stable/12/sys/kern X-SVN-Commit-Revision: 346499 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 529C88972E X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.96 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.96)[-0.962,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 21 Apr 2019 20:53:16 -0000 Author: ian Date: Sun Apr 21 20:53:15 2019 New Revision: 346499 URL: https://svnweb.freebsd.org/changeset/base/346499 Log: MFC r345475-r345476 r345475: Truncate a too-long interrupt handler name when there is only one handler. There are only 19 bytes available for the name of an interrupt plus the name(s) of handlers/drivers using it. There is a mechanism from the days of shared interrupts that replaces some of the handler names with '+' when they don't all fit into 19 bytes. In modern times there is typically only one device on an interrupt, but long device names are the norm, especially with embedded systems. Also, in systems with multiple interrupt controllers, the names of the interrupts themselves can be long. For example, 'gic0,s54: imx6_anatop0' doesn't fit, and replacing the device driver name with a '+' provides no useful info at all. When there is only one handler but its name was too long to fit, this change truncates enough leading chars of the handler name (replacing them with a '-' char to indicate that some chars are missing) to use all 19 bytes, preserving the unit number typically on the end of the name. Using the prior example, this results in: 'gic0,s54:-6_anatop0' which provides plenty of info to figure out which device is involved. PR: 211946 Reviewed by: gonzo@ (prior version without the '-' char) Differential Revision: https://reviews.freebsd.org/D19675 r345476: Revert accidental change that should not have been included in r345475. I had changed this value as part of a local experiment, and neglected to change it back before committing the other changes. Modified: stable/12/sys/kern/kern_intr.c Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/kern/kern_intr.c ============================================================================== --- stable/12/sys/kern/kern_intr.c Sun Apr 21 20:50:55 2019 (r346498) +++ stable/12/sys/kern/kern_intr.c Sun Apr 21 20:53:15 2019 (r346499) @@ -209,10 +209,20 @@ intr_event_update(struct intr_event *ie) } /* - * If the handler names were too long, add +'s to indicate missing - * names. If we run out of room and still have +'s to add, change - * the last character from a + to a *. + * If there is only one handler and its name is too long, just copy in + * as much of the end of the name (includes the unit number) as will + * fit. Otherwise, we have multiple handlers and not all of the names + * will fit. Add +'s to indicate missing names. If we run out of room + * and still have +'s to add, change the last character from a + to a *. */ + if (missed == 1 && space == 1) { + ih = CK_SLIST_FIRST(&ie->ie_handlers); + missed = strlen(ie->ie_fullname) + strlen(ih->ih_name) + 2 - + sizeof(ie->ie_fullname); + strcat(ie->ie_fullname, (missed == 0) ? " " : "-"); + strcat(ie->ie_fullname, &ih->ih_name[missed]); + missed = 0; + } last = &ie->ie_fullname[sizeof(ie->ie_fullname) - 2]; while (missed-- > 0) { if (strlen(ie->ie_fullname) + 1 == sizeof(ie->ie_fullname)) { From owner-svn-src-stable-12@freebsd.org Sun Apr 21 20:55:34 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 4A39815843CB; Sun, 21 Apr 2019 20:55:34 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id E3B1689A36; Sun, 21 Apr 2019 20:55:33 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id B38562C39; Sun, 21 Apr 2019 20:55:33 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3LKtXi7078132; Sun, 21 Apr 2019 20:55:33 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3LKtX9T078131; Sun, 21 Apr 2019 20:55:33 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201904212055.x3LKtX9T078131@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Sun, 21 Apr 2019 20:55:33 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346500 - stable/12/sys/arm/arm X-SVN-Group: stable-12 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: stable/12/sys/arm/arm X-SVN-Commit-Revision: 346500 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: E3B1689A36 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.96 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.96)[-0.959,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 21 Apr 2019 20:55:34 -0000 Author: ian Date: Sun Apr 21 20:55:33 2019 New Revision: 346500 URL: https://svnweb.freebsd.org/changeset/base/346500 Log: MFC r346312: Only set up the interrupts that will actually be used in arm generic_timer. The code previously set up interrupt handlers for all the interrupt resources available, including for timers that are not in use. That could lead to interrupt storms. For example, if boot firmware enabled the virtual timer but the kernel is using the physical timer, it could get flooded with interrupts on the virtual timer which it cannot shut off. By only setting up an interrupt handler for the hardware that will actually be used, any interrupts from other timer units will remain masked in the interrupt controller. Differential Revision: https://reviews.freebsd.org/D19871 Modified: stable/12/sys/arm/arm/generic_timer.c Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/arm/arm/generic_timer.c ============================================================================== --- stable/12/sys/arm/arm/generic_timer.c Sun Apr 21 20:53:15 2019 (r346499) +++ stable/12/sys/arm/arm/generic_timer.c Sun Apr 21 20:55:33 2019 (r346500) @@ -396,7 +396,7 @@ arm_tmr_attach(device_t dev) pcell_t clock; #endif int error; - int i; + int i, first_timer, last_timer; sc = device_get_softc(dev); if (arm_tmr_sc) @@ -436,17 +436,25 @@ arm_tmr_attach(device_t dev) return (ENXIO); } -#ifdef __arm__ - sc->physical = true; -#else /* __aarch64__ */ - /* If we do not have a virtual timer use the physical. */ - sc->physical = (sc->res[2] == NULL) ? true : false; +#ifdef __aarch64__ + /* Use the virtual timer if we have one. */ + if (sc->res[2] != NULL) { + sc->physical = false; + first_timer = 2; + last_timer = 2; + } else #endif + /* Otherwise set up the secure and non-secure physical timers. */ + { + sc->physical = true; + first_timer = 0; + last_timer = 1; + } arm_tmr_sc = sc; /* Setup secure, non-secure and virtual IRQs handler */ - for (i = 0; i < 3; i++) { + for (i = first_timer; i <= last_timer; i++) { /* If we do not have the interrupt, skip it. */ if (sc->res[i] == NULL) continue; From owner-svn-src-stable-12@freebsd.org Sun Apr 21 22:13:09 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 7C3AD158702E; Sun, 21 Apr 2019 22:13:09 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4299A8CA4B; Sun, 21 Apr 2019 22:13:09 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id F2D233C6D; Sun, 21 Apr 2019 22:13:08 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3LMD8QJ020226; Sun, 21 Apr 2019 22:13:08 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3LMD7wZ020221; Sun, 21 Apr 2019 22:13:07 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201904212213.x3LMD7wZ020221@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Sun, 21 Apr 2019 22:13:07 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346501 - in stable/12/stand: i386/common i386/gptboot i386/loader i386/zfsboot libsa/zfs X-SVN-Group: stable-12 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: in stable/12/stand: i386/common i386/gptboot i386/loader i386/zfsboot libsa/zfs X-SVN-Commit-Revision: 346501 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 4299A8CA4B X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.95 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.95)[-0.950,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 21 Apr 2019 22:13:10 -0000 Author: ian Date: Sun Apr 21 22:13:07 2019 New Revision: 346501 URL: https://svnweb.freebsd.org/changeset/base/346501 Log: MFC r341420, r341473, r341651 r341420: Eliminate duplicated code and struct member definitions in the handoff of args data between gptboot/zfsboot and loader(8). Despite what seems like a lot of changes here, there are no actual changes in behavior, or in the data layout in the structures involved. This is just eliminating identical code pasted into multiple locations. In detail, the changes are... - Move struct zfs_boot_args definition from libsa/zfs/libzfs.h to i386/common/bootargs.h because it is specific to x86 booting and the handoff between zfsboot and loader, and has no relation to the zfs library code in general. - The geli_boot_args and zfs_boot_args structs both contain an identical set of member variables containing geli information. Extract this out to a new geli_boot_data struct, and embed it in the arg-passing structs. - Provide new routines geli_import_boot_data() and geli_export_boot_data() that can be shared between gptboot, zfsboot, and loader instead of pasting identical code into several different .c files. - Remove some checks for a NULL pointer that can never be true because the pointer being tested was set using pointer math (kargs + 1) and that can never result in NULL in this code. r341473: Fix args cross-threading between gptboot(8) and loader(8) with zfs support. When loader(8) is built with zfs support enabled, it assumes that any extarg data present is a zfs_boot_args struct, but if the first-stage loader was gptboot(8) the extarg data is actually a geli_boot_args struct. Luckily, zfsboot(8) and gptzfsboot(8) have always passed KARGS_FLAGS_ZFS along with KARGS_FLAGS_EXTARG, so we can use KARGS_FLAGS_ZFS to decide whether the extarg data is a zfs_boot_args struct. To avoid similar problems in the future, gptboot(8) now passes a new KARGS_FLAGS_GELI to indicate that extarg data is geli_boot_args. In loader(8), if the neither KARGS_FLAGS_ZFS nor KARGS_FLAGS_GELI is set but extarg data is present (which will be the case for gptboot compiled before this change), we now check for the known size of the geli_boot_args struct passed by the older versions of gptboot as a way of confirming what type of extarg data is present. In a semi-related tidying up, since loader's main() has already decided what type of extarg data is present and set the global 'zargs' var accordingly, don't repeat the check in extract_currdev, just check whether zargs is NULL or not. r341651: Don't reference zfs-specific variables if LOADER_ZFS_SUPPORT is undefined because the variables will be undefined too. Modified: stable/12/stand/i386/common/bootargs.h stable/12/stand/i386/gptboot/gptboot.c stable/12/stand/i386/loader/main.c stable/12/stand/i386/zfsboot/zfsboot.c stable/12/stand/libsa/zfs/libzfs.h Directory Properties: stable/12/ (props changed) Modified: stable/12/stand/i386/common/bootargs.h ============================================================================== --- stable/12/stand/i386/common/bootargs.h Sun Apr 21 20:55:33 2019 (r346500) +++ stable/12/stand/i386/common/bootargs.h Sun Apr 21 22:13:07 2019 (r346501) @@ -18,10 +18,11 @@ #ifndef _BOOT_I386_ARGS_H_ #define _BOOT_I386_ARGS_H_ -#define KARGS_FLAGS_CD 0x1 -#define KARGS_FLAGS_PXE 0x2 -#define KARGS_FLAGS_ZFS 0x4 -#define KARGS_FLAGS_EXTARG 0x8 /* variably sized extended argument */ +#define KARGS_FLAGS_CD 0x0001 /* .bootdev is a bios CD dev */ +#define KARGS_FLAGS_PXE 0x0002 /* .pxeinfo is valid */ +#define KARGS_FLAGS_ZFS 0x0004 /* .zfspool is valid, EXTARG is zfs_boot_args */ +#define KARGS_FLAGS_EXTARG 0x0008 /* variably sized extended argument */ +#define KARGS_FLAGS_GELI 0x0010 /* EXTARG is geli_boot_args */ #define BOOTARGS_SIZE 24 /* sizeof(struct bootargs) */ #define BA_BOOTFLAGS 8 /* offsetof(struct bootargs, bootflags) */ @@ -84,11 +85,15 @@ struct bootargs #ifdef LOADER_GELI_SUPPORT #include +#include "geliboot.h" #endif -struct geli_boot_args +/* + * geli_boot_data is embedded in geli_boot_args (passed from gptboot to loader) + * and in zfs_boot_args (passed from zfsboot and gptzfsboot to loader). + */ +struct geli_boot_data { - uint32_t size; union { char gelipw[256]; struct { @@ -104,6 +109,49 @@ struct geli_boot_args #endif }; }; +}; + +#ifdef LOADER_GELI_SUPPORT + +static inline void +export_geli_boot_data(struct geli_boot_data *gbdata) +{ + + gbdata->notapw = '\0'; + gbdata->keybuf_sentinel = KEYBUF_SENTINEL; + gbdata->keybuf = malloc(sizeof(struct keybuf) + + (GELI_MAX_KEYS * sizeof(struct keybuf_ent))); + geli_export_key_buffer(gbdata->keybuf); +} + +static inline void +import_geli_boot_data(struct geli_boot_data *gbdata) +{ + + if (gbdata->gelipw[0] != '\0') { + setenv("kern.geom.eli.passphrase", gbdata->gelipw, 1); + explicit_bzero(gbdata->gelipw, sizeof(gbdata->gelipw)); + } else if (gbdata->keybuf_sentinel == KEYBUF_SENTINEL) { + geli_import_key_buffer(gbdata->keybuf); + } +} +#endif /* LOADER_GELI_SUPPORT */ + +struct geli_boot_args +{ + uint32_t size; + struct geli_boot_data gelidata; +}; + +struct zfs_boot_args +{ + uint32_t size; + uint32_t reserved; + uint64_t pool; + uint64_t root; + uint64_t primary_pool; + uint64_t primary_vdev; + struct geli_boot_data gelidata; }; #endif /*__ASSEMBLER__*/ Modified: stable/12/stand/i386/gptboot/gptboot.c ============================================================================== --- stable/12/stand/i386/gptboot/gptboot.c Sun Apr 21 20:55:33 2019 (r346500) +++ stable/12/stand/i386/gptboot/gptboot.c Sun Apr 21 22:13:07 2019 (r346501) @@ -114,7 +114,6 @@ static int vdev_read(void *vdev __unused, void *priv, #ifdef LOADER_GELI_SUPPORT #include "geliboot.h" static char gelipw[GELI_PW_MAXLEN]; -static struct keybuf *gelibuf; #endif struct gptdsk { @@ -480,12 +479,7 @@ load(void) #ifdef LOADER_GELI_SUPPORT geliargs.size = sizeof(geliargs); explicit_bzero(gelipw, sizeof(gelipw)); - gelibuf = malloc(sizeof(struct keybuf) + - (GELI_MAX_KEYS * sizeof(struct keybuf_ent))); - geli_export_key_buffer(gelibuf); - geliargs.notapw = '\0'; - geliargs.keybuf_sentinel = KEYBUF_SENTINEL; - geliargs.keybuf = gelibuf; + export_geli_boot_data(&geliargs.gelidata); #endif /* * Note that the geliargs struct is passed by value, not by pointer. @@ -496,7 +490,7 @@ load(void) __exec((caddr_t)addr, RB_BOOTINFO | (opts & RBX_MASK), MAKEBOOTDEV(dev_maj[gdsk.dsk.type], gdsk.dsk.part + 1, gdsk.dsk.unit, 0xff), #ifdef LOADER_GELI_SUPPORT - KARGS_FLAGS_EXTARG, 0, 0, VTOP(&bootinfo), geliargs + KARGS_FLAGS_GELI | KARGS_FLAGS_EXTARG, 0, 0, VTOP(&bootinfo), geliargs #else 0, 0, 0, VTOP(&bootinfo) #endif Modified: stable/12/stand/i386/loader/main.c ============================================================================== --- stable/12/stand/i386/loader/main.c Sun Apr 21 20:55:33 2019 (r346500) +++ stable/12/stand/i386/loader/main.c Sun Apr 21 22:13:07 2019 (r346501) @@ -73,6 +73,7 @@ void exit(int code); #ifdef LOADER_GELI_SUPPORT #include "geliboot.h" struct geli_boot_args *gargs; +struct geli_boot_data *gbdata; #endif #ifdef LOADER_ZFS_SUPPORT struct zfs_boot_args *zargs; @@ -169,37 +170,49 @@ main(void) #ifdef LOADER_ZFS_SUPPORT archsw.arch_zfs_probe = i386_zfs_probe; -#ifdef LOADER_GELI_SUPPORT - if ((kargs->bootflags & KARGS_FLAGS_EXTARG) != 0) { + /* + * zfsboot and gptzfsboot have always passed KARGS_FLAGS_ZFS, so if that is + * set along with KARGS_FLAGS_EXTARG we know we can interpret the extarg + * data as a struct zfs_boot_args. + */ +#define KARGS_EXTARGS_ZFS (KARGS_FLAGS_EXTARG | KARGS_FLAGS_ZFS) + + if ((kargs->bootflags & KARGS_EXTARGS_ZFS) == KARGS_EXTARGS_ZFS) { zargs = (struct zfs_boot_args *)(kargs + 1); - if (zargs != NULL && zargs->size >= offsetof(struct zfs_boot_args, gelipw)) { - if (zargs->size >= offsetof(struct zfs_boot_args, keybuf_sentinel) && - zargs->keybuf_sentinel == KEYBUF_SENTINEL) { - geli_import_key_buffer(zargs->keybuf); - } - if (zargs->gelipw[0] != '\0') { - setenv("kern.geom.eli.passphrase", zargs->gelipw, 1); - explicit_bzero(zargs->gelipw, sizeof(zargs->gelipw)); - } - } } -#endif /* LOADER_GELI_SUPPORT */ -#else /* !LOADER_ZFS_SUPPORT */ +#endif /* LOADER_ZFS_SUPPORT */ + #ifdef LOADER_GELI_SUPPORT - if ((kargs->bootflags & KARGS_FLAGS_EXTARG) != 0) { + /* + * If we decided earlier that we have zfs_boot_args extarg data, and it is + * big enough to contain the embedded geli data (the early zfs_boot_args + * structs weren't), then init the gbdata pointer accordingly. If there is + * extarg data which isn't zfs_boot_args data, determine whether it is + * geli_boot_args data. Recent versions of gptboot set KARGS_FLAGS_GELI to + * indicate that. Earlier versions didn't, but we presume that's what we + * have if the extarg size exactly matches the size of the geli_boot_args + * struct during that pre-flag era. + */ +#define LEGACY_GELI_ARGS_SIZE 260 /* This can never change */ + +#ifdef LOADER_ZFS_SUPPORT + if (zargs != NULL) { + if (zargs->size > offsetof(struct zfs_boot_args, gelidata)) { + gbdata = &zargs->gelidata; + } + } else +#endif /* LOADER_ZFS_SUPPORT */ + if ((kargs->bootflags & KARGS_FLAGS_EXTARG) != 0) { gargs = (struct geli_boot_args *)(kargs + 1); - if (gargs != NULL && gargs->size >= offsetof(struct geli_boot_args, gelipw)) { - if (gargs->keybuf_sentinel == KEYBUF_SENTINEL) { - geli_import_key_buffer(gargs->keybuf); - } - if (gargs->gelipw[0] != '\0') { - setenv("kern.geom.eli.passphrase", gargs->gelipw, 1); - explicit_bzero(gargs->gelipw, sizeof(gargs->gelipw)); - } + if ((kargs->bootflags & KARGS_FLAGS_GELI) || + gargs->size == LEGACY_GELI_ARGS_SIZE) { + gbdata = &gargs->gelidata; } } + + if (gbdata != NULL) + import_geli_boot_data(gbdata); #endif /* LOADER_GELI_SUPPORT */ -#endif /* LOADER_ZFS_SUPPORT */ /* * March through the device switch probing for things. @@ -271,11 +284,7 @@ extract_currdev(void) } #ifdef LOADER_ZFS_SUPPORT } else if ((kargs->bootflags & KARGS_FLAGS_ZFS) != 0) { - zargs = NULL; - /* check for new style extended argument */ - if ((kargs->bootflags & KARGS_FLAGS_EXTARG) != 0) - zargs = (struct zfs_boot_args *)(kargs + 1); - + /* zargs was set in main() if we have new style extended argument */ if (zargs != NULL && zargs->size >= offsetof(struct zfs_boot_args, primary_pool)) { /* sufficient data is provided */ Modified: stable/12/stand/i386/zfsboot/zfsboot.c ============================================================================== --- stable/12/stand/i386/zfsboot/zfsboot.c Sun Apr 21 20:55:33 2019 (r346500) +++ stable/12/stand/i386/zfsboot/zfsboot.c Sun Apr 21 22:13:07 2019 (r346501) @@ -129,7 +129,6 @@ int main(void); #ifdef LOADER_GELI_SUPPORT #include "geliboot.h" static char gelipw[GELI_PW_MAXLEN]; -static struct keybuf *gelibuf; #endif struct zfsdsk { @@ -993,13 +992,7 @@ load(void) zfsargs.primary_pool = primary_spa->spa_guid; #ifdef LOADER_GELI_SUPPORT explicit_bzero(gelipw, sizeof(gelipw)); - gelibuf = malloc(sizeof(struct keybuf) + (GELI_MAX_KEYS * sizeof(struct keybuf_ent))); - geli_export_key_buffer(gelibuf); - zfsargs.notapw = '\0'; - zfsargs.keybuf_sentinel = KEYBUF_SENTINEL; - zfsargs.keybuf = gelibuf; -#else - zfsargs.gelipw[0] = '\0'; + export_geli_boot_data(&zfsargs.gelidata); #endif if (primary_vdev != NULL) zfsargs.primary_vdev = primary_vdev->v_guid; Modified: stable/12/stand/libsa/zfs/libzfs.h ============================================================================== --- stable/12/stand/libsa/zfs/libzfs.h Sun Apr 21 20:55:33 2019 (r346500) +++ stable/12/stand/libsa/zfs/libzfs.h Sun Apr 21 22:13:07 2019 (r346501) @@ -44,31 +44,6 @@ struct zfs_devdesc { #include #endif -struct zfs_boot_args -{ - uint32_t size; - uint32_t reserved; - uint64_t pool; - uint64_t root; - uint64_t primary_pool; - uint64_t primary_vdev; - union { - char gelipw[256]; - struct { - char notapw; /* - * single null byte to stop keybuf - * being interpreted as a password - */ - uint32_t keybuf_sentinel; -#ifdef LOADER_GELI_SUPPORT - struct keybuf *keybuf; -#else - void *keybuf; -#endif - }; - }; -}; - int zfs_parsedev(struct zfs_devdesc *dev, const char *devspec, const char **path); char *zfs_fmtdev(void *vdev); From owner-svn-src-stable-12@freebsd.org Sun Apr 21 22:21:37 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 2649515876D1; Sun, 21 Apr 2019 22:21:37 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id C1CA18CEAE; Sun, 21 Apr 2019 22:21:36 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 9AFD43CC7; Sun, 21 Apr 2019 22:21:36 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3LMLaV4021469; Sun, 21 Apr 2019 22:21:36 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3LMLawp021468; Sun, 21 Apr 2019 22:21:36 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201904212221.x3LMLawp021468@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Sun, 21 Apr 2019 22:21:36 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346502 - stable/12/sys/dev/vt X-SVN-Group: stable-12 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: stable/12/sys/dev/vt X-SVN-Commit-Revision: 346502 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: C1CA18CEAE X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.95 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.95)[-0.948,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 21 Apr 2019 22:21:37 -0000 Author: ian Date: Sun Apr 21 22:21:36 2019 New Revision: 346502 URL: https://svnweb.freebsd.org/changeset/base/346502 Log: MFC r342639: When allocating a new keyboard at vt_upgrade() time, unwind any cngrabs done on the old keyboard and then do the corresponding number of grabs on the new keyboard. This fixes a race that can leave the system with a non-functioning keyboard. It goes like this... - The bios claims there is an AT keyboard, atkbd attaches. - SI_SUB_INT_CONFIG_HOOKS runs. - USB probes devices. Devices begin attaching, including disks. - GELI prompts for a password for a just-attached disk, which results in a cngrab() while atkbd is the keyboard. - A USB keyboard attaches. - vt_upgrade() runs and switches the keyboard to the new USB keyboard, but because cngrab was never called for it, it's not activated and keystrokes are ignored. - Now there is no functional keyboard and no way to get one; even plugging in a different USB keyboard doesn't help, because the console is still grabbed, still waiting for a GELI pw. Modified: stable/12/sys/dev/vt/vt_core.c Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/dev/vt/vt_core.c ============================================================================== --- stable/12/sys/dev/vt/vt_core.c Sun Apr 21 22:13:07 2019 (r346501) +++ stable/12/sys/dev/vt/vt_core.c Sun Apr 21 22:21:36 2019 (r346502) @@ -977,10 +977,22 @@ vt_kbdevent(keyboard_t *kbd, int event, void *arg) static int vt_allocate_keyboard(struct vt_device *vd) { - int idx0, idx; + int grabbed, i, idx0, idx; keyboard_t *k0, *k; keyboard_info_t ki; + /* + * If vt_upgrade() happens while the console is grabbed, we are + * potentially going to switch keyboard devices while the keyboard is in + * use. Unwind the grabbing of the current keyboard first, then we will + * re-grab the new keyboard below, before we return. + */ + if (vd->vd_curwindow == &vt_conswindow) { + grabbed = vd->vd_curwindow->vw_grabbed; + for (i = 0; i < grabbed; ++i) + vtterm_cnungrab(vd->vd_curwindow->vw_terminal); + } + idx0 = kbd_allocate("kbdmux", -1, vd, vt_kbdevent, vd); if (idx0 >= 0) { DPRINTF(20, "%s: kbdmux allocated, idx = %d\n", __func__, idx0); @@ -1011,6 +1023,11 @@ vt_allocate_keyboard(struct vt_device *vd) } vd->vd_keyboard = idx0; DPRINTF(20, "%s: vd_keyboard = %d\n", __func__, vd->vd_keyboard); + + if (vd->vd_curwindow == &vt_conswindow) { + for (i = 0; i < grabbed; ++i) + vtterm_cngrab(vd->vd_curwindow->vw_terminal); + } return (idx0); } From owner-svn-src-stable-12@freebsd.org Sun Apr 21 22:26:29 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E25DA15877A2; Sun, 21 Apr 2019 22:26:28 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 507708D1EE; Sun, 21 Apr 2019 22:26:28 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 28F2D3E1A; Sun, 21 Apr 2019 22:26:28 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3LMQSmA025875; Sun, 21 Apr 2019 22:26:28 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3LMQR1C025874; Sun, 21 Apr 2019 22:26:28 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201904212226.x3LMQR1C025874@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Sun, 21 Apr 2019 22:26:27 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346503 - stable/12/stand/common X-SVN-Group: stable-12 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: stable/12/stand/common X-SVN-Commit-Revision: 346503 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 507708D1EE X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.95 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.95)[-0.948,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 21 Apr 2019 22:26:29 -0000 Author: ian Date: Sun Apr 21 22:26:27 2019 New Revision: 346503 URL: https://svnweb.freebsd.org/changeset/base/346503 Log: MFC r344238-r344241 r344238: Restore loader(8)'s ability for lsdev to show partitions within a bsd slice. I'm pretty sure this used to work at one time, perhaps long ago. It has been failing recently because if you call disk_open() with dev->d_partition set to -1 when d_slice refers to a bsd slice, it assumes you want it to open the first partition within that slice. When you then pass that open dev instance to ptable_open(), it tries to read the start of the 'a' partition and decides there is no recognizable partition type there. This restores the old functionality by resetting d_offset to the start of the raw slice after disk_open() returns. For good measure, d_partition is also set back to -1, although that doesn't currently affect anything. I would have preferred to make disk_open() avoid such rude assumptions and if you ask for partition -1 you get the raw slice. But the commit history shows that someone already did that once (r239058), and had to revert it (r239232), so I didn't even try to go down that road. r344239: Use a couple local variables to avoid repetitive long expressions that cause line-wrapping. r344240: Make lsdev -v output line up in neat columns by using a fixed width for the size field and a tab between the partition type and the size. Changes this disk devices: disk0 (MMC) disk0s1: DOS/Windows 49MB disk0s2: FreeBSD 14GB disk0s2a: FreeBSD UFS 14GB disk0s2b: Unknown 2048KB disk0s2d: FreeBSD UFS 2040KB to this disk devices: disk0 (MMC) disk0s1: DOS/Windows 49MB disk0s2: FreeBSD 14GB disk0s2a: FreeBSD UFS 14GB disk0s2b: Unknown 2048KB disk0s2d: FreeBSD UFS 2040KB r344241: Garbage collect no-longer-used constant. Modified: stable/12/stand/common/disk.c Directory Properties: stable/12/ (props changed) Modified: stable/12/stand/common/disk.c ============================================================================== --- stable/12/stand/common/disk.c Sun Apr 21 22:21:36 2019 (r346502) +++ stable/12/stand/common/disk.c Sun Apr 21 22:26:27 2019 (r346503) @@ -75,7 +75,7 @@ display_size(uint64_t size, u_int sectorsize) size /= 1024; unit = 'M'; } - sprintf(buf, "%ld%cB", (long)size, unit); + sprintf(buf, "%4ld%cB", (long)size, unit); return (buf); } @@ -102,7 +102,6 @@ ptblread(void *d, void *buf, size_t blocks, uint64_t o blocks * od->sectorsize, (char *)buf, NULL)); } -#define PWIDTH 35 static int ptable_print(void *arg, const char *pname, const struct ptable_entry *part) { @@ -112,16 +111,16 @@ ptable_print(void *arg, const char *pname, const struc struct ptable *table; char line[80]; int res; + u_int sectsize; + uint64_t partsize; pa = (struct print_args *)arg; od = (struct open_disk *)pa->dev->dd.d_opendata; - sprintf(line, " %s%s: %s", pa->prefix, pname, - parttype2str(part->type)); - if (pa->verbose) - sprintf(line, "%-*s%s", PWIDTH, line, - display_size(part->end - part->start + 1, - od->sectorsize)); - strcat(line, "\n"); + sectsize = od->sectorsize; + partsize = part->end - part->start + 1; + sprintf(line, " %s%s: %s\t%s\n", pa->prefix, pname, + parttype2str(part->type), + pa->verbose ? display_size(partsize, sectsize) : ""); if (pager_output(line)) return 1; res = 0; @@ -131,10 +130,15 @@ ptable_print(void *arg, const char *pname, const struc dev.dd.d_unit = pa->dev->dd.d_unit; dev.d_slice = part->index; dev.d_partition = -1; - if (disk_open(&dev, part->end - part->start + 1, - od->sectorsize) == 0) { - table = ptable_open(&dev, part->end - part->start + 1, - od->sectorsize, ptblread); + if (disk_open(&dev, partsize, sectsize) == 0) { + /* + * disk_open() for partition -1 on a bsd slice assumes + * you want the first bsd partition. Reset things so + * that we're looking at the start of the raw slice. + */ + dev.d_partition = -1; + dev.d_offset = part->start; + table = ptable_open(&dev, partsize, sectsize, ptblread); if (table != NULL) { sprintf(line, " %s%s", pa->prefix, pname); bsd.dev = pa->dev; @@ -149,7 +153,6 @@ ptable_print(void *arg, const char *pname, const struc return (res); } -#undef PWIDTH int disk_print(struct disk_devdesc *dev, char *prefix, int verbose) From owner-svn-src-stable-12@freebsd.org Sun Apr 21 22:28:51 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 2B13115878A1; Sun, 21 Apr 2019 22:28:51 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id BFEA38D36F; Sun, 21 Apr 2019 22:28:50 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 8254C3E1D; Sun, 21 Apr 2019 22:28:50 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3LMSoVA026016; Sun, 21 Apr 2019 22:28:50 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3LMSoI0026015; Sun, 21 Apr 2019 22:28:50 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201904212228.x3LMSoI0026015@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Sun, 21 Apr 2019 22:28:50 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346504 - stable/12/stand/uboot/common X-SVN-Group: stable-12 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: stable/12/stand/uboot/common X-SVN-Commit-Revision: 346504 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: BFEA38D36F X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.95 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.95)[-0.948,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 21 Apr 2019 22:28:51 -0000 Author: ian Date: Sun Apr 21 22:28:50 2019 New Revision: 346504 URL: https://svnweb.freebsd.org/changeset/base/346504 Log: MFC r344254-r344255 r344254: Use DEV_TYP_NONE instead of -1 to indicate no device was specified. DEV_TYP_NONE has a value of zero, which makes more sense since the device type is a bunch of bits describing the device, crammed into an int. r344255: Fix more places to use DEV_TYP_NONE instead of -1 to indicate 'no device'. Modified: stable/12/stand/uboot/common/main.c Directory Properties: stable/12/ (props changed) Modified: stable/12/stand/uboot/common/main.c ============================================================================== --- stable/12/stand/uboot/common/main.c Sun Apr 21 22:26:27 2019 (r346503) +++ stable/12/stand/uboot/common/main.c Sun Apr 21 22:28:50 2019 (r346504) @@ -156,7 +156,7 @@ get_device_type(const char *devstr, int *devtype) printf("Unknown device type '%s'\n", devstr); } - *devtype = -1; + *devtype = DEV_TYP_NONE; return (NULL); } @@ -211,7 +211,7 @@ get_load_device(int *type, int *unit, int *slice, int const char *p; char *endp; - *type = -1; + *type = DEV_TYP_NONE; *unit = -1; *slice = 0; *partition = -1; @@ -250,13 +250,13 @@ get_load_device(int *type, int *unit, int *slice, int p++; /* Unknown device name, or a known name without unit number. */ - if ((*type == -1) || (*p == '\0')) { + if ((*type == DEV_TYP_NONE) || (*p == '\0')) { return; } /* Malformed unit number. */ if (!isdigit(*p)) { - *type = -1; + *type = DEV_TYP_NONE; return; } @@ -271,7 +271,7 @@ get_load_device(int *type, int *unit, int *slice, int /* Device string is malformed beyond unit number. */ if (*p != ':') { - *type = -1; + *type = DEV_TYP_NONE; *unit = -1; return; } @@ -284,7 +284,7 @@ get_load_device(int *type, int *unit, int *slice, int /* Only DEV_TYP_STOR devices can have a slice specification. */ if (!(*type & DEV_TYP_STOR)) { - *type = -1; + *type = DEV_TYP_NONE; *unit = -1; return; } @@ -293,7 +293,7 @@ get_load_device(int *type, int *unit, int *slice, int /* Malformed slice number. */ if (p == endp) { - *type = -1; + *type = DEV_TYP_NONE; *unit = -1; *slice = 0; return; @@ -307,7 +307,7 @@ get_load_device(int *type, int *unit, int *slice, int /* Device string is malformed beyond slice number. */ if (*p != '.') { - *type = -1; + *type = DEV_TYP_NONE; *unit = -1; *slice = 0; return; @@ -327,7 +327,7 @@ get_load_device(int *type, int *unit, int *slice, int return; /* Junk beyond partition number. */ - *type = -1; + *type = DEV_TYP_NONE; *unit = -1; *slice = 0; *partition = -1; @@ -496,14 +496,14 @@ main(int argc, char **argv) currdev.dd.d_dev = devsw[i]; currdev.dd.d_unit = 0; - if ((load_type == -1 || (load_type & DEV_TYP_STOR)) && + if ((load_type == DEV_TYP_NONE || (load_type & DEV_TYP_STOR)) && strcmp(devsw[i]->dv_name, "disk") == 0) { if (probe_disks(i, load_type, load_unit, load_slice, load_partition) == 0) break; } - if ((load_type == -1 || (load_type & DEV_TYP_NET)) && + if ((load_type == DEV_TYP_NONE || (load_type & DEV_TYP_NET)) && strcmp(devsw[i]->dv_name, "net") == 0) break; } From owner-svn-src-stable-12@freebsd.org Sun Apr 21 22:31:53 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id DC98F1587956; Sun, 21 Apr 2019 22:31:53 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 850B18D6CC; Sun, 21 Apr 2019 22:31:53 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 331D63F9A; Sun, 21 Apr 2019 22:31:53 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3LMVriH027662; Sun, 21 Apr 2019 22:31:53 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3LMVrpf027661; Sun, 21 Apr 2019 22:31:53 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201904212231.x3LMVrpf027661@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Sun, 21 Apr 2019 22:31:53 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346505 - stable/12/sys/arm/freescale/imx X-SVN-Group: stable-12 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: stable/12/sys/arm/freescale/imx X-SVN-Commit-Revision: 346505 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 850B18D6CC X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.96 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.96)[-0.965,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 21 Apr 2019 22:31:54 -0000 Author: ian Date: Sun Apr 21 22:31:52 2019 New Revision: 346505 URL: https://svnweb.freebsd.org/changeset/base/346505 Log: MFC r344267: Add a compatible string to match recent changes in the upstream dts. Modified: stable/12/sys/arm/freescale/imx/imx6_snvs.c Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/arm/freescale/imx/imx6_snvs.c ============================================================================== --- stable/12/sys/arm/freescale/imx/imx6_snvs.c Sun Apr 21 22:28:50 2019 (r346504) +++ stable/12/sys/arm/freescale/imx/imx6_snvs.c Sun Apr 21 22:31:52 2019 (r346505) @@ -73,6 +73,7 @@ struct snvs_softc { }; static struct ofw_compat_data compat_data[] = { + {"fsl,sec-v4.0-mon-rtc-lp", true}, {"fsl,sec-v4.0-mon", true}, {NULL, false} }; From owner-svn-src-stable-12@freebsd.org Mon Apr 22 00:38:28 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 6A1C31589E71; Mon, 22 Apr 2019 00:38:28 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 1AE4668404; Mon, 22 Apr 2019 00:38:28 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id E540D5414; Mon, 22 Apr 2019 00:38:27 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3M0cR9q093934; Mon, 22 Apr 2019 00:38:27 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3M0cQ6S093924; Mon, 22 Apr 2019 00:38:26 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201904220038.x3M0cQ6S093924@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Mon, 22 Apr 2019 00:38:26 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346508 - in stable/12: share/man/man4 sys/conf sys/dev/fdt sys/dev/flash sys/modules sys/modules/fdt sys/modules/fdt/fdt_slicer sys/sys X-SVN-Group: stable-12 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: in stable/12: share/man/man4 sys/conf sys/dev/fdt sys/dev/flash sys/modules sys/modules/fdt sys/modules/fdt/fdt_slicer sys/sys X-SVN-Commit-Revision: 346508 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 1AE4668404 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.97 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.97)[-0.967,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Apr 2019 00:38:28 -0000 Author: ian Date: Mon Apr 22 00:38:25 2019 New Revision: 346508 URL: https://svnweb.freebsd.org/changeset/base/346508 Log: MFC r344505-r344507, r344523, r344525-r344526, r344529, r344606-r344612, r344614-r344616, r344681, r344684-r344686, r344728, r344733-r344734, r344981 A large set of changes that collectively modernize the at45d and mx25l (DataFlash and SpiFlash) drivers, add FDT support, and add geom_flashmap and geom_label support to them. r344505: Add a functional detach() implementation to make module unloading possible. r344506: Add support for probing/attaching on FDT-based systems. r344507: Switch to using config_intrhook_oneshot(). That allows the error handling in the delayed attach to use early returns, which allows reducing the level of indentation. So all in all, what looks like a lot of changes is really no change in behavior, mostly just moving whitespace around. r344523: Include the jedec "extended device information string" in the criteria used to match a chip to our table of metadata describing the chips. At least one new DataFlash chip has a 3-byte jedec ID identical to its predecessors and differs only in the extended info, and it has different metadata requiring a unique entry in the table. This paves the way for supporting such chips. The metadata table now includes two new fields, extmask and extid. The two bytes of extended info obtained from the chip are ANDed with extmask then compared to extid, so it's possible to use only a subset of the extended info in the matching. We now always read 6 bytes of jedec ID info. Most chips don't return any extended info, and the values read back for those two bytes may be indeterminate, but such chips have extmask and extid values of 0x0000 in the table, so the extid effectively doesn't participate in the matching on those chips and it doesn't matter what they return in the extended info bytes. r344525: Add a metadata entry for the AT45DB641E chip. This chip has the same 3-byte jedec ID as its older cousin the AT45DB642D, but uses a different page size. The only way to distinguish between the two chips is that the 2D chip has 0 bytes of extended ID info and the new 1E has 1 byte of extended ID. The actual value of the extended ID byte is all zeroes. In other words, it's the presence of the extended info that identifies this chip. (Presumably a future upgrade might define non-zero values for the extended ID byte.) r344526: Resolve a name conflict when both SpiFlash and DataFlash devices are present. Both SpiFlash (mx25l) and DataFlash (at45d) drivers create a disk device with a name of /dev/flash/spiN where N is the driver's unit number. If both types of devices are present in the same system, this creates a fatal conflict that prevents attachment of whichever device attaches second (because mx25l0 and at45d0 both try to create a spi0). This gives each type of device a unique name (mx25lN or at45dN respectively) and also adds an alias of spiN for compatibility. When both device types appear in the same system, only the first to attach gets the spiN alias. When the second device attaches there is a non-fatal warning that the alias can't be created, but both devices are still accessible via their primary names (and there is no need for the spiN name to work for backwards compatibility on such a system, because it has never been possible to use the spiN names when both devices exist). r344529: Fix a paste-o that broke the build on all arches. r344606: Add support for geom_flashmap by providing a getattr() for "SPI:device". r344607: Compile fdt_slicer and geom_flashmap when the at45d device is included. r344608: Update a comment to reflect reality; no functional changes. r344609: Make it possible to load fdt_slicer as a module (unloading works too fwiw). r344610: Add manpages for at45d(4) and mx25l(4). r344611: Add a module dependency on fdt_slicer. r344612: Add a module dependency on fdt_slicer. Also, move the PNP_INFO to its more usual location, down near the DRIVER_MODULE() stuff. r344614: Rename some functions and variables to have shorter names, which allows unwrapping multiple lines of code. Also, convert some short multiline comments into single-line comments. Change old-school FALSE to false. All in all, no functional changes, it's just more compact and readable. r344615: Child nodes with a compatible property are not slices, according to the devicetree/bindings/mtd/partitions.txt document, so just ignore them. r344616: Add support to fdt_slicer for the new style partition data documented in devicetree/bindings/mtd/partition.txt. In the old style, all the children of the device node which did not have a compatible property were the partitions. In the new style, there is a child node of the device which has a compatible string of "fixed-partitions", and its children are the individual partitions. Also, support the read-only property by setting the corresponding slice flag. r344681: Build fdt support modules on systems that use fdt data. kern.opts.mk sets make var OPT_FDT to a non-empty value if platform.h contains OPT_FDT. r344684: Undo accidental part of r344681. I think I must have accidentally mouse-click pasted while scrolling and didn't notice it. Reported by: jhibbits@ r344685: Add required header file to SRCS. r344686: Add another required header file. For some reason this seems to be required on aarch64, but I can build armv7 from clean without needing this in the list. (The file does get included, so the mystery is why armv7 works.) r344728: Bugfix: use a dummy buffer for the inactive side of a transfer. This is especially important for writes. SPI is inherently a bidirectional bus; you receive data (even if it's garbage) while writing. We should not receive that data into the same buffer we're writing to the device. When reading it doesn't matter what we send to the device, but using the dummy buffer for that as well is pleasingly symmetrical. r344733: Add some comments. Give #define'd names to some scattered numbers. Change some #define'd names to be more descriptive. When reporting a post-write compare failure, report the page number, not the byte address of the page. The latter is the only functional change, it makes the number match the words of the error message. r344734: Allow the sector size of the disk device to be configured using hints or FDT data. The sector size must be a multiple of the device's page size. If not configured, use the historical default of the device page size. Setting the disk sector size to 512 or 4096 allows a variety of standard filesystems to be used on the device. Of course you wouldn't want to be writing frequently to a SPI flash chip like it was a disk drive, but for data that gets written once (or rarely) and read often, using a standard filesystem is a nice convenient thing. r344981: Give the mx25l device sole ownership of the name /dev/flash/spi* instead of trying to use disk_add_alias() to make spi* an alias for mx25l*. It turns out disk_add_alias() works for partitions, but not slices, and that's hard to fix. This change is, in effect, a partial revert of r344526. The mips world relies on the existence of flashmap names formatted as /dev/flash/spi0s.name, whereas pretty much nothing relies on at45d devices using the /dev/spi* names (because until recently the at45d driver didn't even work reliably). So this change makes mx25l devices the sole owner of the /dev/flash/spi* namespace, which actually makes some sense because it is a SpiFlash(tm) device, so flash/spi isn't a horrible name. Added: stable/12/share/man/man4/at45d.4 - copied, changed from r344612, head/share/man/man4/at45d.4 stable/12/share/man/man4/mx25l.4 - copied unchanged from r344612, head/share/man/man4/mx25l.4 stable/12/sys/modules/fdt/ - copied from r344612, head/sys/modules/fdt/ Modified: stable/12/share/man/man4/Makefile stable/12/sys/conf/files stable/12/sys/dev/fdt/fdt_slicer.c stable/12/sys/dev/flash/at45d.c stable/12/sys/dev/flash/mx25l.c stable/12/sys/modules/Makefile stable/12/sys/modules/fdt/fdt_slicer/Makefile stable/12/sys/sys/slicer.h Directory Properties: stable/12/ (props changed) Modified: stable/12/share/man/man4/Makefile ============================================================================== --- stable/12/share/man/man4/Makefile Sun Apr 21 23:04:06 2019 (r346507) +++ stable/12/share/man/man4/Makefile Mon Apr 22 00:38:25 2019 (r346508) @@ -55,6 +55,7 @@ MAN= aac.4 \ ${_apic.4} \ arcmsr.4 \ ${_asmc.4} \ + at45d.4 \ ata.4 \ ath.4 \ ath_ahb.4 \ @@ -306,6 +307,7 @@ MAN= aac.4 \ mvs.4 \ mwl.4 \ mwlfw.4 \ + mx25l.4 \ mxge.4 \ my.4 \ nand.4 \ Copied and modified: stable/12/share/man/man4/at45d.4 (from r344612, head/share/man/man4/at45d.4) ============================================================================== --- head/share/man/man4/at45d.4 Tue Feb 26 22:52:41 2019 (r344612, copy source) +++ stable/12/share/man/man4/at45d.4 Mon Apr 22 00:38:25 2019 (r346508) @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd February 26, 2019 +.Dd March 2, 2019 .Dt AT45D 4 .Os .Sh NAME @@ -126,6 +126,10 @@ The following properties are optional for the .Nm device subnode: .Bl -tag -width indent +.It Va freebsd,sectorsize +The sector size of the disk created for this storage device. +It must be a multiple of the device's page size. +The default is the device page size. .It Va spi-cpha Empty property indicating the slave device requires shifted clock phase (CPHA) mode. @@ -156,6 +160,10 @@ The chip-select number to assert when performing I/O f Set the high bit (1 << 31) to invert the logic level of the chip select line. .It Va hint.at45d.%d.mode The SPI mode (0-3) to use when communicating with this device. +.It Va hint.at45d.%d.sectorsize +The sector size of the disk created for this storage device. +It must be a multiple of the device's page size. +The default is the device page size. .El .Sh FILES .Bl -tag -width /dev/flash/at45d? Copied: stable/12/share/man/man4/mx25l.4 (from r344612, head/share/man/man4/mx25l.4) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/12/share/man/man4/mx25l.4 Mon Apr 22 00:38:25 2019 (r346508, copy of r344612, head/share/man/man4/mx25l.4) @@ -0,0 +1,209 @@ +.\" +.\" Copyright (c) 2019 Ian Lepore +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd February 26, 2019 +.Dt MX25L 4 +.Os +.Sh NAME +.Nm mx25l +.Nd driver for SpiFlash(tm) compatible non-volatile storage devices +.Sh SYNOPSIS +To compile this driver into the kernel, +place the following line in your +kernel configuration file: +.Bd -ragged -offset indent +.Cd "device mx25l" +.Ed +.Pp +Alternatively, to load the driver as a +module at boot time, place the following line in +.Xr loader.conf 5 : +.Bd -literal -offset indent +mx25l_load="YES" +.Ed +.Sh DESCRIPTION +The +.Nm +driver provides support for the family of non-volatile storage +devices known collectively as SpiFlash(tm). +SpiFlash chips typically have part numbers beginning with EN25, +IS25, MX25, S25, SST25, or W25. +.Pp +The +.Nm +driver uses opcode 0x9f to read the manufacturer and device ID +data to determine whether the device is supported. +The device ID is looked up using a table of data within the driver +which describes the attributes of each supported device, +such as block size, sector size, and device capacity. +When a supported device is found, the +.Nm +driver creates a disk device and makes it accessible at +.Pa /dev/flash/mx25l? . +The new disk device is then tasted by the available +.Xr geom 4 +modules as with any disk device. +.Sh HARDWARE +The +.Nm +driver provides support for the following devices: +.Pp +.Bl -bullet -compact +.It +AT25DF641 +.It +EN25F32 +.It +EN25P32 +.It +EN25P64 +.It +EN25Q32 +.It +EN25Q64 +.It +GD25Q64 +.It +M25P32 +.It +M25P64 +.It +MX25L1606E +.It +MX25LL128 +.It +MX25LL256 +.It +MX25LL32 +.It +MX25LL64 +.It +S25FL032 +.It +S25FL064 +.It +S25FL128 +.It +S25FL256S +.It +SST25VF010A +.It +SST25VF032B +.It +W25Q128 +.It +W25Q256 +.It +W25Q32 +.It +W25Q64 +.It +W25Q64BV +.It +W25X32 +.It +W25X64 +.El +.Sh FDT CONFIGURATION +On an +.Xr fdt 4 +based system, the +.Nm +device is defined as a slave device subnode +of the SPI bus controller node. +All properties documented in the +.Va spibus.txt +bindings document can be used with the +.Nm +device. +The most commonly-used ones are documented below. +.Pp +The following properties are required in the +.Nm +device subnode: +.Bl -tag -width indent +.It Va compatible +Must be the string "jedec,spi-nor". +.It Va reg +Chip select address of device. +.It Va spi-max-frequency +The maximum bus frequency to use when communicating with this slave device. +Actual bus speed may be lower, depending on the capabilities of the SPI +bus controller hardware. +.El +.Pp +The following properties are optional for the +.Nm +device subnode: +.Bl -tag -width indent +.It Va spi-cpha +Empty property indicating the slave device requires shifted clock +phase (CPHA) mode. +.It Va spi-cpol +Empty property indicating the slave device requires inverse clock +polarity (CPOL) mode. +.It Va spi-cs-high +Empty property indicating the slave device requires chip select active high. +.El +.Sh HINTS CONFIGURATION +On a +.Xr device.hints 5 +based system, such as +.Li MIPS , +these values are configurable for +.Nm : +.Bl -tag -width indent +.It Va hint.mx25l.%d.at +The spibus the +.Nm +instance is attached to. +.It Va hint.mx25l.%d.clock +The maximum bus frequency to use when communicating with this device. +Actual bus speed may be lower, depending on the capabilities of the SPI +bus controller hardware. +.It Va hint.mx25l.%d.cs +The chip-select number to assert when performing I/O for this device. +Set the high bit (1 << 31) to invert the logic level of the chip select line. +.It Va hint.mx25l.%d.mode +The SPI mode (0-3) to use when communicating with this device. +.El +.Sh FILES +.Bl -tag -width /dev/flash/mx25l? +.It Pa /dev/flash/mx25l? +Provides read/write access to the storage device. +.It Pa /dev/flash/spi? +An alias for the +.Pa /dev/mx25l? +device, for backwards compatibility with older versions of the driver. +.El +.Sh SEE ALSO +.Xr fdt 4 , +.Xr geom 4 +.Sh HISTORY +The +.Nm +driver first appeared in +.Fx 8.0 . Modified: stable/12/sys/conf/files ============================================================================== --- stable/12/sys/conf/files Sun Apr 21 23:04:06 2019 (r346507) +++ stable/12/sys/conf/files Mon Apr 22 00:38:25 2019 (r346508) @@ -1784,7 +1784,7 @@ dev/fdt/fdt_clock_if.m optional fdt fdt_clock dev/fdt/fdt_common.c optional fdt dev/fdt/fdt_pinctrl.c optional fdt fdt_pinctrl dev/fdt/fdt_pinctrl_if.m optional fdt fdt_pinctrl -dev/fdt/fdt_slicer.c optional fdt cfi | fdt nand | fdt mx25l | fdt n25q +dev/fdt/fdt_slicer.c optional fdt cfi | fdt nand | fdt mx25l | fdt n25q | fdt at45d dev/fdt/fdt_static_dtb.S optional fdt fdt_dtb_static \ dependency "fdt_dtb_file" dev/fdt/simplebus.c optional fdt @@ -3672,7 +3672,7 @@ geom/geom_disk.c standard geom/geom_dump.c standard geom/geom_event.c standard geom/geom_fox.c optional geom_fox -geom/geom_flashmap.c optional fdt cfi | fdt nand | fdt mx25l | mmcsd | fdt n25q +geom/geom_flashmap.c optional fdt cfi | fdt nand | fdt mx25l | mmcsd | fdt n25q | fdt at45d geom/geom_io.c standard geom/geom_kern.c standard geom/geom_map.c optional geom_map Modified: stable/12/sys/dev/fdt/fdt_slicer.c ============================================================================== --- stable/12/sys/dev/fdt/fdt_slicer.c Sun Apr 21 23:04:06 2019 (r346507) +++ stable/12/sys/dev/fdt/fdt_slicer.c Mon Apr 22 00:38:25 2019 (r346508) @@ -32,6 +32,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -45,42 +46,34 @@ __FBSDID("$FreeBSD$"); #define debugf(fmt, args...) #endif -static int fdt_flash_fill_slices(device_t dev, const char *provider, +static int fill_slices(device_t dev, const char *provider, struct flash_slice *slices, int *slices_num); static void fdt_slicer_init(void); static int -fdt_flash_fill_slices(device_t dev, const char *provider __unused, - struct flash_slice *slices, int *slices_num) +fill_slices_from_node(phandle_t node, struct flash_slice *slices, int *count) { - char *slice_name; - phandle_t dt_node, dt_child; + char *label; + phandle_t child; u_long base, size; - int i; - ssize_t name_len; + int flags, i; + ssize_t nmlen; - /* - * We assume the caller provides buffer for FLASH_SLICES_MAX_NUM - * flash_slice structures. - */ - if (slices == NULL) { - *slices_num = 0; - return (ENOMEM); - } + i = 0; + for (child = OF_child(node); child != 0; child = OF_peer(child)) { + flags = FLASH_SLICES_FLAG_NONE; - dt_node = ofw_bus_get_node(dev); - for (dt_child = OF_child(dt_node), i = 0; dt_child != 0; - dt_child = OF_peer(dt_child)) { + /* Nodes with a compatible property are not slices. */ + if (OF_hasprop(child, "compatible")) + continue; if (i == FLASH_SLICES_MAX_NUM) { debugf("not enough buffer for slice i=%d\n", i); break; } - /* - * Retrieve start and size of the slice. - */ - if (fdt_regsize(dt_child, &base, &size) != 0) { + /* Retrieve start and size of the slice. */ + if (fdt_regsize(child, &base, &size) != 0) { debugf("error during processing reg property, i=%d\n", i); continue; @@ -91,50 +84,102 @@ fdt_flash_fill_slices(device_t dev, const char *provid continue; } - /* - * Retrieve label. - */ - name_len = OF_getprop_alloc(dt_child, "label", - (void **)&slice_name); - if (name_len <= 0) { + /* Retrieve label. */ + nmlen = OF_getprop_alloc(child, "label", (void **)&label); + if (nmlen <= 0) { /* Use node name if no label defined */ - name_len = OF_getprop_alloc(dt_child, "name", - (void **)&slice_name); - if (name_len <= 0) { + nmlen = OF_getprop_alloc(child, "name", (void **)&label); + if (nmlen <= 0) { debugf("slice i=%d with no name\n", i); - slice_name = NULL; + label = NULL; } } - /* - * Fill slice entry data. - */ + if (OF_hasprop(child, "read-only")) + flags |= FLASH_SLICES_FLAG_RO; + + /* Fill slice entry data. */ slices[i].base = base; slices[i].size = size; - slices[i].label = slice_name; + slices[i].label = label; + slices[i].flags = flags; i++; } - *slices_num = i; + *count = i; return (0); } +static int +fill_slices(device_t dev, const char *provider __unused, + struct flash_slice *slices, int *slices_num) +{ + phandle_t child, node; + + /* + * We assume the caller provides buffer for FLASH_SLICES_MAX_NUM + * flash_slice structures. + */ + if (slices == NULL) { + *slices_num = 0; + return (ENOMEM); + } + + node = ofw_bus_get_node(dev); + + /* + * If there is a child node whose compatible is "fixed-partitions" then + * we have new-style data where all partitions are the children of that + * node. Otherwise we have old-style data where all the children of the + * device node are the partitions. + */ + child = fdt_find_compatible(node, "fixed-partitions", false); + if (child == 0) + return fill_slices_from_node(node, slices, slices_num); + else + return fill_slices_from_node(child, slices, slices_num); +} + static void fdt_slicer_init(void) { - flash_register_slicer(fdt_flash_fill_slices, FLASH_SLICES_TYPE_NAND, - FALSE); - flash_register_slicer(fdt_flash_fill_slices, FLASH_SLICES_TYPE_CFI, - FALSE); - flash_register_slicer(fdt_flash_fill_slices, FLASH_SLICES_TYPE_SPI, - FALSE); + flash_register_slicer(fill_slices, FLASH_SLICES_TYPE_NAND, false); + flash_register_slicer(fill_slices, FLASH_SLICES_TYPE_CFI, false); + flash_register_slicer(fill_slices, FLASH_SLICES_TYPE_SPI, false); } +static void +fdt_slicer_cleanup(void) +{ + + flash_register_slicer(NULL, FLASH_SLICES_TYPE_NAND, true); + flash_register_slicer(NULL, FLASH_SLICES_TYPE_CFI, true); + flash_register_slicer(NULL, FLASH_SLICES_TYPE_SPI, true); +} + /* * Must be initialized after GEOM classes (SI_SUB_DRIVERS/SI_ORDER_FIRST), * i. e. after g_init() is called, due to the use of the GEOM topology_lock * in flash_register_slicer(). However, must be before SI_SUB_CONFIGURE. */ -SYSINIT(fdt_slicer_rootconf, SI_SUB_DRIVERS, SI_ORDER_SECOND, fdt_slicer_init, - NULL); +SYSINIT(fdt_slicer, SI_SUB_DRIVERS, SI_ORDER_SECOND, fdt_slicer_init, NULL); +SYSUNINIT(fdt_slicer, SI_SUB_DRIVERS, SI_ORDER_SECOND, fdt_slicer_cleanup, NULL); + +static int +mod_handler(module_t mod, int type, void *data) +{ + + /* + * Nothing to do here: the SYSINIT/SYSUNINIT defined above run + * automatically at module load/unload time. + */ + return (0); +} + +static moduledata_t fdt_slicer_mod = { + "fdt_slicer", mod_handler, NULL +}; + +DECLARE_MODULE(fdt_slicer, fdt_slicer_mod, SI_SUB_DRIVERS, SI_ORDER_SECOND); +MODULE_VERSION(fdt_slicer, 1); Modified: stable/12/sys/dev/flash/at45d.c ============================================================================== --- stable/12/sys/dev/flash/at45d.c Sun Apr 21 23:04:06 2019 (r346507) +++ stable/12/sys/dev/flash/at45d.c Mon Apr 22 00:38:25 2019 (r346508) @@ -35,6 +35,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -47,10 +48,36 @@ __FBSDID("$FreeBSD$"); #include #include "spibus_if.h" +#include "opt_platform.h" + +#ifdef FDT +#include +#include +#include + +static struct ofw_compat_data compat_data[] = { + { "atmel,at45", 1 }, + { "atmel,dataflash", 1 }, + { NULL, 0 }, +}; +#endif + +/* This is the information returned by the MANUFACTURER_ID command. */ +struct at45d_mfg_info { + uint32_t jedec_id; /* Mfg ID, DevId1, DevId2, ExtLen */ + uint16_t ext_id; /* ExtId1, ExtId2 */ +}; + +/* + * This is an entry in our table of metadata describing the chips. We match on + * both jedec id and extended id info returned by the MANUFACTURER_ID command. + */ struct at45d_flash_ident { const char *name; uint32_t jedec; + uint16_t extid; + uint16_t extmask; uint16_t pagecount; uint16_t pageoffset; uint16_t pagesize; @@ -63,13 +90,18 @@ struct at45d_softc struct mtx sc_mtx; struct disk *disk; struct proc *p; - struct intr_config_hook config_intrhook; device_t dev; + u_int taskstate; uint16_t pagecount; uint16_t pageoffset; uint16_t pagesize; + void *dummybuf; }; +#define TSTATE_STOPPED 0 +#define TSTATE_STOPPING 1 +#define TSTATE_RUNNING 2 + #define AT45D_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx) #define AT45D_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx) #define AT45D_LOCK_INIT(_sc) \ @@ -87,36 +119,51 @@ static device_probe_t at45d_probe; /* disk routines */ static int at45d_close(struct disk *dp); static int at45d_open(struct disk *dp); +static int at45d_getattr(struct bio *bp); static void at45d_strategy(struct bio *bp); static void at45d_task(void *arg); /* helper routines */ static void at45d_delayed_attach(void *xsc); -static int at45d_get_mfg_info(device_t dev, uint8_t *resp); +static int at45d_get_mfg_info(device_t dev, struct at45d_mfg_info *resp); static int at45d_get_status(device_t dev, uint8_t *status); static int at45d_wait_ready(device_t dev, uint8_t *status); -#define BUFFER_TRANSFER 0x53 -#define BUFFER_COMPARE 0x60 +#define PAGE_TO_BUFFER_TRANSFER 0x53 +#define PAGE_TO_BUFFER_COMPARE 0x60 #define PROGRAM_THROUGH_BUFFER 0x82 #define MANUFACTURER_ID 0x9f #define STATUS_REGISTER_READ 0xd7 #define CONTINUOUS_ARRAY_READ 0xe8 +#define STATUS_READY (1u << 7) +#define STATUS_CMPFAIL (1u << 6) +#define STATUS_PAGE2N (1u << 0) + /* + * Metadata for supported chips. + * + * The jedec id in this table includes the extended id length byte. A match is + * based on both jedec id and extended id matching. The chip's extended id (not + * present in most chips) is ANDed with ExtMask and the result is compared to + * ExtId. If a chip only returns 1 ext id byte it will be in the upper 8 bits + * of ExtId in this table. + * * A sectorsize2n != 0 is used to indicate that a device optionally supports * 2^N byte pages. If support for the latter is enabled, the sector offset * has to be reduced by one. */ static const struct at45d_flash_ident at45d_flash_devices[] = { - { "AT45DB011B", 0x1f2200, 512, 9, 264, 256 }, - { "AT45DB021B", 0x1f2300, 1024, 9, 264, 256 }, - { "AT45DB041x", 0x1f2400, 2028, 9, 264, 256 }, - { "AT45DB081B", 0x1f2500, 4096, 9, 264, 256 }, - { "AT45DB161x", 0x1f2600, 4096, 10, 528, 512 }, - { "AT45DB321x", 0x1f2700, 8192, 10, 528, 0 }, - { "AT45DB321x", 0x1f2701, 8192, 10, 528, 512 }, - { "AT45DB642x", 0x1f2800, 8192, 11, 1056, 1024 } + /* Part Name Jedec ID ExtId ExtMask PgCnt Offs PgSz PgSz2n */ + { "AT45DB011B", 0x1f220000, 0x0000, 0x0000, 512, 9, 264, 256 }, + { "AT45DB021B", 0x1f230000, 0x0000, 0x0000, 1024, 9, 264, 256 }, + { "AT45DB041x", 0x1f240000, 0x0000, 0x0000, 2028, 9, 264, 256 }, + { "AT45DB081B", 0x1f250000, 0x0000, 0x0000, 4096, 9, 264, 256 }, + { "AT45DB161x", 0x1f260000, 0x0000, 0x0000, 4096, 10, 528, 512 }, + { "AT45DB321x", 0x1f270000, 0x0000, 0x0000, 8192, 10, 528, 0 }, + { "AT45DB321x", 0x1f270100, 0x0000, 0x0000, 8192, 10, 528, 512 }, + { "AT45DB641E", 0x1f280001, 0x0000, 0xff00, 32768, 9, 264, 256 }, + { "AT45DB642x", 0x1f280000, 0x0000, 0x0000, 8192, 11, 1056, 1024 }, }; static int @@ -140,7 +187,7 @@ at45d_get_status(device_t dev, uint8_t *status) } static int -at45d_get_mfg_info(device_t dev, uint8_t *resp) +at45d_get_mfg_info(device_t dev, struct at45d_mfg_info *resp) { uint8_t rxBuf[8], txBuf[8]; struct spi_command cmd; @@ -153,11 +200,14 @@ at45d_get_mfg_info(device_t dev, uint8_t *resp) txBuf[0] = MANUFACTURER_ID; cmd.tx_cmd = &txBuf; cmd.rx_cmd = &rxBuf; - cmd.tx_cmd_sz = cmd.rx_cmd_sz = 5; + cmd.tx_cmd_sz = cmd.rx_cmd_sz = 7; err = SPIBUS_TRANSFER(device_get_parent(dev), dev, &cmd); if (err) return (err); - memcpy(resp, rxBuf + 1, 4); + + resp->jedec_id = be32dec(rxBuf + 1); + resp->ext_id = be16dec(rxBuf + 5); + return (0); } @@ -175,16 +225,29 @@ at45d_wait_ready(device_t dev, uint8_t *status) err = ETIMEDOUT; else err = at45d_get_status(dev, status); - } while (err == 0 && (*status & 0x80) == 0); + } while (err == 0 && !(*status & STATUS_READY)); return (err); } static int at45d_probe(device_t dev) { + int rv; +#ifdef FDT + if (!ofw_bus_status_okay(dev)) + return (ENXIO); + + if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0) + return (ENXIO); + + rv = BUS_PROBE_DEFAULT; +#else + rv = BUS_PROBE_NOWILDCARD; +#endif + device_set_desc(dev, "AT45D Flash Family"); - return (0); + return (rv); } static int @@ -196,81 +259,135 @@ at45d_attach(device_t dev) sc->dev = dev; AT45D_LOCK_INIT(sc); - /* We'll see what kind of flash we have later... */ - sc->config_intrhook.ich_func = at45d_delayed_attach; - sc->config_intrhook.ich_arg = sc; - if (config_intrhook_establish(&sc->config_intrhook) != 0) { - device_printf(dev, "config_intrhook_establish failed\n"); - return (ENOMEM); - } + config_intrhook_oneshot(at45d_delayed_attach, sc); return (0); } static int at45d_detach(device_t dev) { + struct at45d_softc *sc; + int err; - return (EBUSY) /* XXX */; + sc = device_get_softc(dev); + err = 0; + + AT45D_LOCK(sc); + if (sc->taskstate == TSTATE_RUNNING) { + sc->taskstate = TSTATE_STOPPING; + wakeup(sc); + while (err == 0 && sc->taskstate != TSTATE_STOPPED) { + err = msleep(sc, &sc->sc_mtx, 0, "at45dt", hz * 3); + if (err != 0) { + sc->taskstate = TSTATE_RUNNING; + device_printf(sc->dev, + "Failed to stop queue task\n"); + } + } + } + AT45D_UNLOCK(sc); + + if (err == 0 && sc->taskstate == TSTATE_STOPPED) { + if (sc->disk) { + disk_destroy(sc->disk); + bioq_flush(&sc->bio_queue, NULL, ENXIO); + free(sc->dummybuf, M_DEVBUF); + } + AT45D_LOCK_DESTROY(sc); + } + return (err); } static void at45d_delayed_attach(void *xsc) { struct at45d_softc *sc; + struct at45d_mfg_info mfginfo; const struct at45d_flash_ident *ident; u_int i; + int sectorsize; uint32_t jedec; uint16_t pagesize; - uint8_t buf[4], status; + uint8_t status; sc = xsc; ident = NULL; jedec = 0; - if (at45d_wait_ready(sc->dev, &status) != 0) + if (at45d_wait_ready(sc->dev, &status) != 0) { device_printf(sc->dev, "Error waiting for device-ready.\n"); - else if (at45d_get_mfg_info(sc->dev, buf) != 0) + return; + } + if (at45d_get_mfg_info(sc->dev, &mfginfo) != 0) { device_printf(sc->dev, "Failed to get ID.\n"); - else { - jedec = buf[0] << 16 | buf[1] << 8 | buf[2]; - for (i = 0; i < nitems(at45d_flash_devices); i++) { - if (at45d_flash_devices[i].jedec == jedec) { - ident = &at45d_flash_devices[i]; - break; - } + return; + } + for (i = 0; i < nitems(at45d_flash_devices); i++) { + ident = &at45d_flash_devices[i]; + if (mfginfo.jedec_id == ident->jedec && + (mfginfo.ext_id & ident->extmask) == ident->extid) { + break; } } - if (ident == NULL) + if (i == nitems(at45d_flash_devices)) { device_printf(sc->dev, "JEDEC 0x%x not in list.\n", jedec); - else { - sc->pagecount = ident->pagecount; - sc->pageoffset = ident->pageoffset; - if (ident->pagesize2n != 0 && (status & 0x01) != 0) { - sc->pageoffset -= 1; - pagesize = ident->pagesize2n; - } else - pagesize = ident->pagesize; - sc->pagesize = pagesize; + return; + } - sc->disk = disk_alloc(); - sc->disk->d_open = at45d_open; - sc->disk->d_close = at45d_close; - sc->disk->d_strategy = at45d_strategy; - sc->disk->d_name = "flash/spi"; - sc->disk->d_drv1 = sc; - sc->disk->d_maxsize = DFLTPHYS; - sc->disk->d_sectorsize = pagesize; - sc->disk->d_mediasize = pagesize * ident->pagecount; - sc->disk->d_unit = device_get_unit(sc->dev); - disk_create(sc->disk, DISK_VERSION); - bioq_init(&sc->bio_queue); - kproc_create(&at45d_task, sc, &sc->p, 0, 0, - "task: at45d flash"); - device_printf(sc->dev, "%s, %d bytes per page, %d pages\n", - ident->name, pagesize, ident->pagecount); + sc->pagecount = ident->pagecount; + sc->pageoffset = ident->pageoffset; + if (ident->pagesize2n != 0 && (status & STATUS_PAGE2N)) { + sc->pageoffset -= 1; + pagesize = ident->pagesize2n; + } else + pagesize = ident->pagesize; + sc->pagesize = pagesize; + + /* + * By default we set up a disk with a sector size that matches the + * device page size. If there is a device hint or fdt property + * requesting a different size, use that, as long as it is a multiple of + * the device page size). + */ + sectorsize = pagesize; +#ifdef FDT + { + pcell_t size; + if (OF_getencprop(ofw_bus_get_node(sc->dev), + "freebsd,sectorsize", &size, sizeof(size)) > 0) + sectorsize = size; } +#endif + resource_int_value(device_get_name(sc->dev), device_get_unit(sc->dev), + "sectorsize", §orsize); - config_intrhook_disestablish(&sc->config_intrhook); + if ((sectorsize % pagesize) != 0) { + device_printf(sc->dev, "Invalid sectorsize %d, " + "must be a multiple of %d\n", sectorsize, pagesize); + return; + } + + sc->dummybuf = malloc(pagesize, M_DEVBUF, M_WAITOK | M_ZERO); + + sc->disk = disk_alloc(); + sc->disk->d_open = at45d_open; + sc->disk->d_close = at45d_close; + sc->disk->d_strategy = at45d_strategy; + sc->disk->d_getattr = at45d_getattr; + sc->disk->d_name = "flash/at45d"; + sc->disk->d_drv1 = sc; + sc->disk->d_maxsize = DFLTPHYS; + sc->disk->d_sectorsize = sectorsize; + sc->disk->d_mediasize = pagesize * ident->pagecount; + sc->disk->d_unit = device_get_unit(sc->dev); + disk_create(sc->disk, DISK_VERSION); + bioq_init(&sc->bio_queue); + kproc_create(&at45d_task, sc, &sc->p, 0, 0, "task: at45d flash"); + sc->taskstate = TSTATE_RUNNING; + device_printf(sc->dev, + "%s, %d bytes per page, %d pages; %d KBytes; disk sector size %d\n", + ident->name, pagesize, ident->pagecount, + (pagesize * ident->pagecount) / 1024, sectorsize); } static int @@ -287,6 +404,26 @@ at45d_close(struct disk *dp) return (0); } +static int +at45d_getattr(struct bio *bp) +{ + struct at45d_softc *sc; + + /* + * This function exists to support geom_flashmap and fdt_slicer. + */ + + if (bp->bio_disk == NULL || bp->bio_disk->d_drv1 == NULL) + return (ENXIO); + if (strcmp(bp->bio_attribute, "SPI::device") != 0) + return (-1); + sc = bp->bio_disk->d_drv1; + if (bp->bio_length != sizeof(sc->dev)) + return (EFAULT); + bcopy(&sc->dev, bp->bio_data, sizeof(sc->dev)); + return (0); +} + static void at45d_strategy(struct bio *bp) { @@ -324,9 +461,15 @@ at45d_task(void *arg) for (;;) { AT45D_LOCK(sc); do { + if (sc->taskstate == TSTATE_STOPPING) { + sc->taskstate = TSTATE_STOPPED; + AT45D_UNLOCK(sc); + wakeup(sc); + kproc_exit(0); + } bp = bioq_takefirst(&sc->bio_queue); if (bp == NULL) - msleep(sc, &sc->sc_mtx, PRIBIO, "jobqueue", 0); + msleep(sc, &sc->sc_mtx, PRIBIO, "at45dq", 0); } while (bp == NULL); AT45D_UNLOCK(sc); @@ -340,11 +483,13 @@ at45d_task(void *arg) case BIO_READ: txBuf[0] = CONTINUOUS_ARRAY_READ; cmd.tx_cmd_sz = cmd.rx_cmd_sz = 8; - cmd.tx_data = cmd.rx_data = buf; + cmd.tx_data = sc->dummybuf; + cmd.rx_data = buf; break; case BIO_WRITE: cmd.tx_cmd_sz = cmd.rx_cmd_sz = 4; - cmd.tx_data = cmd.rx_data = buf; + cmd.tx_data = buf; + cmd.rx_data = sc->dummybuf; if (resid + offset > sc->pagesize) len = sc->pagesize - offset; break; @@ -363,14 +508,19 @@ at45d_task(void *arg) } addr = page << sc->pageoffset; if (bp->bio_cmd == BIO_WRITE) { + /* + * If writing less than a full page, transfer + * the existing page to the buffer, so that our + * PROGRAM_THROUGH_BUFFER below will preserve + * the parts of the page we're not writing. + */ if (len != sc->pagesize) { - txBuf[0] = BUFFER_TRANSFER; + txBuf[0] = PAGE_TO_BUFFER_TRANSFER; txBuf[1] = ((addr >> 16) & 0xff); txBuf[2] = ((addr >> 8) & 0xff); txBuf[3] = 0; cmd.tx_data_sz = cmd.rx_data_sz = 0; - err = SPIBUS_TRANSFER(pdev, dev, - &cmd); + err = SPIBUS_TRANSFER(pdev, dev, &cmd); if (err == 0) err = at45d_wait_ready(dev, &status); @@ -396,7 +546,7 @@ at45d_task(void *arg) } if (bp->bio_cmd == BIO_WRITE) { addr = page << sc->pageoffset; - txBuf[0] = BUFFER_COMPARE; + txBuf[0] = PAGE_TO_BUFFER_COMPARE; txBuf[1] = ((addr >> 16) & 0xff); txBuf[2] = ((addr >> 8) & 0xff); txBuf[3] = 0; @@ -404,9 +554,9 @@ at45d_task(void *arg) err = SPIBUS_TRANSFER(pdev, dev, &cmd); if (err == 0) err = at45d_wait_ready(dev, &status); - if (err != 0 || (status & 0x40) != 0) { + if (err != 0 || (status & STATUS_CMPFAIL)) { device_printf(dev, "comparing page " - "%d failed (status=0x%x)\n", addr, + "%d failed (status=0x%x)\n", page, status); berr = EIO; goto out; @@ -420,7 +570,10 @@ at45d_task(void *arg) len = sc->pagesize; else len = resid; - cmd.tx_data = cmd.rx_data = buf; + if (bp->bio_cmd == BIO_READ) + cmd.rx_data = buf; + else + cmd.tx_data = buf; } out: if (berr != 0) { @@ -451,3 +604,8 @@ static driver_t at45d_driver = { DRIVER_MODULE(at45d, spibus, at45d_driver, at45d_devclass, NULL, NULL); MODULE_DEPEND(at45d, spibus, 1, 1, 1); +#ifdef FDT +MODULE_DEPEND(at45d, fdt_slicer, 1, 1, 1); +SPIBUS_PNP_INFO(compat_data); +#endif + Modified: stable/12/sys/dev/flash/mx25l.c ============================================================================== --- stable/12/sys/dev/flash/mx25l.c Sun Apr 21 23:04:06 2019 (r346507) +++ stable/12/sys/dev/flash/mx25l.c Mon Apr 22 00:38:25 2019 (r346508) @@ -685,5 +685,6 @@ static driver_t mx25l_driver = { DRIVER_MODULE(mx25l, spibus, mx25l_driver, mx25l_devclass, 0, 0); MODULE_DEPEND(mx25l, spibus, 1, 1, 1); #ifdef FDT +MODULE_DEPEND(mx25l, fdt_slicer, 1, 1, 1); SPIBUS_PNP_INFO(compat_data); #endif Modified: stable/12/sys/modules/Makefile ============================================================================== --- stable/12/sys/modules/Makefile Sun Apr 21 23:04:06 2019 (r346507) +++ stable/12/sys/modules/Makefile Mon Apr 22 00:38:25 2019 (r346508) @@ -488,6 +488,10 @@ SUBDIR+= iscsi SUBDIR+= iscsi_initiator .endif +.if !empty(OPT_FDT) +SUBDIR+= fdt +.endif + .if ${MACHINE_CPUARCH} == "aarch64" || ${MACHINE_CPUARCH} == "amd64" || \ ${MACHINE_CPUARCH} == "i386" SUBDIR+= linprocfs Modified: stable/12/sys/modules/fdt/fdt_slicer/Makefile ============================================================================== --- head/sys/modules/fdt/fdt_slicer/Makefile Tue Feb 26 22:52:41 2019 (r344612) +++ stable/12/sys/modules/fdt/fdt_slicer/Makefile Mon Apr 22 00:38:25 2019 (r346508) @@ -7,6 +7,8 @@ SRCS= fdt_slicer.c # Generated files... SRCS+= \ + bus_if.h \ + device_if.h \ *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From owner-svn-src-stable-12@freebsd.org Mon Apr 22 00:45:11 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 7E046158A18F; Mon, 22 Apr 2019 00:45:11 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 246BF69CDB; Mon, 22 Apr 2019 00:45:11 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id EE25D55D1; Mon, 22 Apr 2019 00:45:10 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3M0jAfJ099235; Mon, 22 Apr 2019 00:45:10 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3M0j9JH099227; Mon, 22 Apr 2019 00:45:09 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201904220045.x3M0j9JH099227@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Mon, 22 Apr 2019 00:45:09 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346509 - in stable/12/sys: conf geom geom/label modules/geom/geom_label X-SVN-Group: stable-12 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: in stable/12/sys: conf geom geom/label modules/geom/geom_label X-SVN-Commit-Revision: 346509 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 246BF69CDB X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.96 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.96)[-0.962,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Apr 2019 00:45:11 -0000 Author: ian Date: Mon Apr 22 00:45:09 2019 New Revision: 346509 URL: https://svnweb.freebsd.org/changeset/base/346509 Log: MFC r345480, r346013 r345480: Support device-independent labels for geom_flashmap slices. While geom_flashmap has always supported label names for its slices, it does so by appending "s.labelname" to the provider device name, meaning you still have to know the name and unit of the hardware device to use the labels. These changes add support for device-independent geom_flashmap labels, using the standard geom_label infrastructure. geom_flashmap now creates a softc struct attached to its geom, and as it creates slices it stores the label into an array in the softc. The new geom_label_flashmap uses those labels when tasting a geom_flashmap provider. Differential Revision: https://reviews.freebsd.org/D19535 r346013: Add g_label_flashmap.c to the module, should have been part of r345480. Added: stable/12/sys/geom/geom_flashmap.h - copied unchanged from r345480, head/sys/geom/geom_flashmap.h stable/12/sys/geom/label/g_label_flashmap.c - copied unchanged from r345480, head/sys/geom/label/g_label_flashmap.c Modified: stable/12/sys/conf/files stable/12/sys/geom/geom_flashmap.c stable/12/sys/geom/label/g_label.c stable/12/sys/geom/label/g_label.h stable/12/sys/modules/geom/geom_label/Makefile Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/conf/files ============================================================================== --- stable/12/sys/conf/files Mon Apr 22 00:38:25 2019 (r346508) +++ stable/12/sys/conf/files Mon Apr 22 00:45:09 2019 (r346509) @@ -3689,6 +3689,7 @@ geom/journal/g_journal.c optional geom_journal geom/journal/g_journal_ufs.c optional geom_journal geom/label/g_label.c optional geom_label | geom_label_gpt geom/label/g_label_ext2fs.c optional geom_label +geom/label/g_label_flashmap.c optional geom_label geom/label/g_label_iso9660.c optional geom_label geom/label/g_label_msdosfs.c optional geom_label geom/label/g_label_ntfs.c optional geom_label Modified: stable/12/sys/geom/geom_flashmap.c ============================================================================== --- stable/12/sys/geom/geom_flashmap.c Mon Apr 22 00:38:25 2019 (r346508) +++ stable/12/sys/geom/geom_flashmap.c Mon Apr 22 00:45:09 2019 (r346509) @@ -39,13 +39,12 @@ __FBSDID("$FreeBSD$"); #include #include -#include #include +#include +#include #include -#define FLASHMAP_CLASS_NAME "Flashmap" - struct g_flashmap_slice { off_t sl_start; off_t sl_end; @@ -71,8 +70,8 @@ static g_taste_t g_flashmap_taste; static int g_flashmap_load(device_t dev, struct g_provider *pp, flash_slicer_t slicer, struct g_flashmap_head *head); -static int g_flashmap_modify(struct g_geom *gp, const char *devname, - int secsize, struct g_flashmap_head *slices); +static int g_flashmap_modify(struct g_flashmap *gfp, struct g_geom *gp, + const char *devname, int secsize, struct g_flashmap_head *slices); static void g_flashmap_print(struct g_flashmap_slice *slice); MALLOC_DECLARE(M_FLASHMAP); @@ -88,8 +87,8 @@ g_flashmap_print(struct g_flashmap_slice *slice) } static int -g_flashmap_modify(struct g_geom *gp, const char *devname, int secsize, - struct g_flashmap_head *slices) +g_flashmap_modify(struct g_flashmap *gfp, struct g_geom *gp, + const char *devname, int secsize, struct g_flashmap_head *slices) { struct g_flashmap_slice *slice; int i, error; @@ -114,6 +113,8 @@ g_flashmap_modify(struct g_geom *gp, const char *devna i = 0; STAILQ_FOREACH(slice, slices, sl_link) { + free(__DECONST(void *, gfp->labels[i]), M_FLASHMAP); + gfp->labels[i] = strdup(slice->sl_name, M_FLASHMAP); error = g_slice_config(gp, i++, G_SLICE_CONFIG_SET, slice->sl_start, slice->sl_end - slice->sl_start + 1, @@ -153,6 +154,7 @@ g_flashmap_taste(struct g_class *mp, struct g_provider struct g_consumer *cp; struct g_flashmap_head head; struct g_flashmap_slice *slice, *slice_temp; + struct g_flashmap *gfp; flash_slicer_t slicer; device_t dev; int i, size; @@ -164,7 +166,8 @@ g_flashmap_taste(struct g_class *mp, struct g_provider strcmp(pp->geom->class->name, G_DISK_CLASS_NAME) != 0) return (NULL); - gp = g_slice_new(mp, FLASH_SLICES_MAX_NUM, pp, &cp, NULL, 0, NULL); + gp = g_slice_new(mp, FLASH_SLICES_MAX_NUM, pp, &cp, (void**)&gfp, + sizeof(struct g_flashmap), NULL); if (gp == NULL) return (NULL); @@ -186,7 +189,7 @@ g_flashmap_taste(struct g_class *mp, struct g_provider if (g_flashmap_load(dev, pp, slicer, &head) == 0) break; - g_flashmap_modify(gp, cp->provider->name, + g_flashmap_modify(gfp, gp, cp->provider->name, cp->provider->sectorsize, &head); } while (0); Copied: stable/12/sys/geom/geom_flashmap.h (from r345480, head/sys/geom/geom_flashmap.h) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/12/sys/geom/geom_flashmap.h Mon Apr 22 00:45:09 2019 (r346509, copy of r345480, head/sys/geom/geom_flashmap.h) @@ -0,0 +1,39 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2019 Ian Lepore + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _GEOM_GEOM_FLASHMAP_H_ + +#define FLASHMAP_CLASS_NAME "Flashmap" + +struct g_flashmap { + const char *labels[FLASH_SLICES_MAX_NUM]; +}; + +#endif + Modified: stable/12/sys/geom/label/g_label.c ============================================================================== --- stable/12/sys/geom/label/g_label.c Mon Apr 22 00:38:25 2019 (r346508) +++ stable/12/sys/geom/label/g_label.c Mon Apr 22 00:45:09 2019 (r346509) @@ -95,6 +95,7 @@ const struct g_label_desc *g_labels[] = { &g_label_reiserfs, &g_label_ntfs, &g_label_disk_ident, + &g_label_flashmap, #endif NULL }; Modified: stable/12/sys/geom/label/g_label.h ============================================================================== --- stable/12/sys/geom/label/g_label.h Mon Apr 22 00:38:25 2019 (r346508) +++ stable/12/sys/geom/label/g_label.h Mon Apr 22 00:45:09 2019 (r346509) @@ -88,6 +88,7 @@ extern struct g_label_desc g_label_ntfs; extern struct g_label_desc g_label_gpt; extern struct g_label_desc g_label_gpt_uuid; extern struct g_label_desc g_label_disk_ident; +extern struct g_label_desc g_label_flashmap; extern void g_label_rtrim(char *label, size_t size); #endif /* _KERNEL */ Copied: stable/12/sys/geom/label/g_label_flashmap.c (from r345480, head/sys/geom/label/g_label_flashmap.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/12/sys/geom/label/g_label_flashmap.c Mon Apr 22 00:45:09 2019 (r346509, copy of r345480, head/sys/geom/label/g_label_flashmap.c) @@ -0,0 +1,77 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2019 Ian Lepore + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#define G_LABEL_FLASHMAP_SLICE_DIR "flash" + +static void +g_label_flashmap_taste(struct g_consumer *cp, char *label, size_t size) +{ + struct g_flashmap *gfp; + struct g_slicer *gsp; + struct g_provider *pp; + + g_topology_assert_not(); + + pp = cp->provider; + label[0] = '\0'; + + /* We taste only partitions handled by flashmap */ + if (strncmp(pp->geom->class->name, FLASHMAP_CLASS_NAME, + sizeof(FLASHMAP_CLASS_NAME)) != 0) + return; + + gsp = (struct g_slicer *)pp->geom->softc; + gfp = (struct g_flashmap *)gsp->softc; + + /* If it's handled by flashmap it should have a label, but be safe. */ + if (gfp->labels[pp->index] == NULL) + return; + + strlcpy(label, gfp->labels[pp->index], size); +} + +struct g_label_desc g_label_flashmap = { + .ld_taste = g_label_flashmap_taste, + .ld_dir = G_LABEL_FLASHMAP_SLICE_DIR, + .ld_enabled = 1 +}; + +G_LABEL_INIT(flashmap, g_label_flashmap, "Create device nodes for Flashmap labels"); Modified: stable/12/sys/modules/geom/geom_label/Makefile ============================================================================== --- stable/12/sys/modules/geom/geom_label/Makefile Mon Apr 22 00:38:25 2019 (r346508) +++ stable/12/sys/modules/geom/geom_label/Makefile Mon Apr 22 00:45:09 2019 (r346509) @@ -6,6 +6,7 @@ KMOD= geom_label SRCS= g_label.c SRCS+= g_label_disk_ident.c SRCS+= g_label_ext2fs.c +SRCS+= g_label_flashmap.c SRCS+= g_label_gpt.c SRCS+= g_label_iso9660.c SRCS+= g_label_msdosfs.c From owner-svn-src-stable-12@freebsd.org Mon Apr 22 00:49:15 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 06322158A2D2; Mon, 22 Apr 2019 00:49:15 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id A094969F6E; Mon, 22 Apr 2019 00:49:14 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 7EC6F55D5; Mon, 22 Apr 2019 00:49:14 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3M0nE35099621; Mon, 22 Apr 2019 00:49:14 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3M0nEa0099620; Mon, 22 Apr 2019 00:49:14 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201904220049.x3M0nEa0099620@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Mon, 22 Apr 2019 00:49:14 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346510 - stable/12/sys/dev/spibus X-SVN-Group: stable-12 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: stable/12/sys/dev/spibus X-SVN-Commit-Revision: 346510 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: A094969F6E X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.96 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.96)[-0.957,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Apr 2019 00:49:15 -0000 Author: ian Date: Mon Apr 22 00:49:13 2019 New Revision: 346510 URL: https://svnweb.freebsd.org/changeset/base/346510 Log: MFC r344556: Set maximum bus clock speed from hints when attaching hinted spibus(4) children. Some devices (such as spigen(4)) document that this works, but it appears that the code to implement it never got added. Modified: stable/12/sys/dev/spibus/spibus.c Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/dev/spibus/spibus.c ============================================================================== --- stable/12/sys/dev/spibus/spibus.c Mon Apr 22 00:45:09 2019 (r346509) +++ stable/12/sys/dev/spibus/spibus.c Mon Apr 22 00:49:13 2019 (r346510) @@ -216,6 +216,7 @@ spibus_hinted_child(device_t bus, const char *dname, i child = BUS_ADD_CHILD(bus, 0, dname, dunit); devi = SPIBUS_IVAR(child); devi->mode = SPIBUS_MODE_NONE; + resource_int_value(dname, dunit, "clock", &devi->clock); resource_int_value(dname, dunit, "cs", &devi->cs); resource_int_value(dname, dunit, "mode", &devi->mode); } From owner-svn-src-stable-12@freebsd.org Mon Apr 22 03:06:15 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id EC82A158CD5F; Mon, 22 Apr 2019 03:06:14 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 941BE6DFA5; Mon, 22 Apr 2019 03:06:14 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 5F8DF6DB7; Mon, 22 Apr 2019 03:06:14 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3M36EDI073211; Mon, 22 Apr 2019 03:06:14 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3M36Do1073208; Mon, 22 Apr 2019 03:06:13 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201904220306.x3M36Do1073208@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Mon, 22 Apr 2019 03:06:13 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346514 - in stable: 11/usr.sbin/cron/cron 11/usr.sbin/cron/crontab 12/usr.sbin/cron/cron 12/usr.sbin/cron/crontab X-SVN-Group: stable-12 X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: in stable: 11/usr.sbin/cron/cron 11/usr.sbin/cron/crontab 12/usr.sbin/cron/cron 12/usr.sbin/cron/crontab X-SVN-Commit-Revision: 346514 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 941BE6DFA5 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.98 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.98)[-0.976,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Apr 2019 03:06:15 -0000 Author: kevans Date: Mon Apr 22 03:06:12 2019 New Revision: 346514 URL: https://svnweb.freebsd.org/changeset/base/346514 Log: MFC r346252: cron(8): Add MAILFROM ability for crontabs This changes the sender mail address in a similar fashion to how MAILTO may change the recipient. The default from address remains unchanged. PR: 140304 Modified: stable/12/usr.sbin/cron/cron/cron.8 stable/12/usr.sbin/cron/cron/do_command.c stable/12/usr.sbin/cron/crontab/crontab.5 Directory Properties: stable/12/ (props changed) Changes in other areas also in this revision: Modified: stable/11/usr.sbin/cron/cron/cron.8 stable/11/usr.sbin/cron/cron/do_command.c stable/11/usr.sbin/cron/crontab/crontab.5 Directory Properties: stable/11/ (props changed) Modified: stable/12/usr.sbin/cron/cron/cron.8 ============================================================================== --- stable/12/usr.sbin/cron/cron/cron.8 Mon Apr 22 03:04:39 2019 (r346513) +++ stable/12/usr.sbin/cron/cron/cron.8 Mon Apr 22 03:06:12 2019 (r346514) @@ -17,7 +17,7 @@ .\" .\" $FreeBSD$ .\" -.Dd July 19, 2017 +.Dd April 15, 2019 .Dt CRON 8 .Os .Sh NAME @@ -79,6 +79,9 @@ commands, any output is mailed to the owner of the cro named in the .Ev MAILTO environment variable in the crontab, if such exists). +The from address of this mail may be set with the +.Ev MAILFROM +environment variable. .Pp Additionally, .Nm Modified: stable/12/usr.sbin/cron/cron/do_command.c ============================================================================== --- stable/12/usr.sbin/cron/cron/do_command.c Mon Apr 22 03:04:39 2019 (r346513) +++ stable/12/usr.sbin/cron/cron/do_command.c Mon Apr 22 03:06:12 2019 (r346514) @@ -93,7 +93,7 @@ child_process(e, u) { int stdin_pipe[2], stdout_pipe[2]; register char *input_data; - char *usernm, *mailto; + char *usernm, *mailto, *mailfrom; int children = 0; # if defined(LOGIN_CAP) struct passwd *pwd; @@ -111,6 +111,7 @@ child_process(e, u) */ usernm = env_get("LOGNAME", e->envp); mailto = env_get("MAILTO", e->envp); + mailfrom = env_get("MAILFROM", e->envp); #ifdef PAM /* use PAM to see if the user's account is available, @@ -503,8 +504,12 @@ child_process(e, u) warn("%s", MAILCMD); (void) _exit(ERROR_EXIT); } - fprintf(mail, "From: Cron Daemon <%s@%s>\n", - usernm, hostname); + if (mailfrom == NULL || *mailfrom == '\0') + fprintf(mail, "From: Cron Daemon <%s@%s>\n", + usernm, hostname); + else + fprintf(mail, "From: Cron Daemon <%s>\n", + mailfrom); fprintf(mail, "To: %s\n", mailto); fprintf(mail, "Subject: Cron <%s@%s> %s\n", usernm, first_word(hostname, "."), Modified: stable/12/usr.sbin/cron/crontab/crontab.5 ============================================================================== --- stable/12/usr.sbin/cron/crontab/crontab.5 Mon Apr 22 03:04:39 2019 (r346513) +++ stable/12/usr.sbin/cron/crontab/crontab.5 Mon Apr 22 03:06:12 2019 (r346514) @@ -17,7 +17,7 @@ .\" .\" $FreeBSD$ .\" -.Dd June 6, 2018 +.Dd April 15, 2019 .Dt CRONTAB 5 .Os .Sh NAME @@ -116,6 +116,9 @@ If .Ev MAILTO is defined (and non-empty), mail is sent to the user so named. +If +.Ev MAILFROM +is defined (and non-empty), its value will be used as the from address. .Ev MAILTO may also be used to direct mail to multiple recipients by separating recipient users with a comma. From owner-svn-src-stable-12@freebsd.org Mon Apr 22 08:58:39 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 6000F1593AF4; Mon, 22 Apr 2019 08:58:39 +0000 (UTC) (envelope-from ngie@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 092CE8110C; Mon, 22 Apr 2019 08:58:39 +0000 (UTC) (envelope-from ngie@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id D1AF5A8C3; Mon, 22 Apr 2019 08:58:38 +0000 (UTC) (envelope-from ngie@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3M8wcBC058506; Mon, 22 Apr 2019 08:58:38 GMT (envelope-from ngie@FreeBSD.org) Received: (from ngie@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3M8wXYZ058480; Mon, 22 Apr 2019 08:58:33 GMT (envelope-from ngie@FreeBSD.org) Message-Id: <201904220858.x3M8wXYZ058480@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ngie set sender to ngie@FreeBSD.org using -f From: Enji Cooper Date: Mon, 22 Apr 2019 08:58:33 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346536 - in stable/12: contrib/elftoolchain contrib/elftoolchain/addr2line contrib/elftoolchain/ar contrib/elftoolchain/common contrib/elftoolchain/cxxfilt contrib/elftoolchain/elfcopy... X-SVN-Group: stable-12 X-SVN-Commit-Author: ngie X-SVN-Commit-Paths: in stable/12: contrib/elftoolchain contrib/elftoolchain/addr2line contrib/elftoolchain/ar contrib/elftoolchain/common contrib/elftoolchain/cxxfilt contrib/elftoolchain/elfcopy contrib/elftoolchain/lib... X-SVN-Commit-Revision: 346536 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 092CE8110C X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.98 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.98)[-0.979,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Apr 2019 08:58:39 -0000 Author: ngie Date: Mon Apr 22 08:58:33 2019 New Revision: 346536 URL: https://svnweb.freebsd.org/changeset/base/346536 Log: MFC r339473,r340075,r342918,r343592,r343593,r343614,r343665,r343669: MFC a number of changes to elftoolchain/readelf(1). This brings the copy of elftoolchain more in line with the version in ^/head and partially fixes the issue with `sys.kern.coredump_phnum_test.coredump_phnum` on ^/stable/12. Tested with: make tinderbox r339473 (by emaste): libelf: also test for 64-bit ELF in _libelf_is_mips64el Although _libelf_is_mips64el is only called in contexts where we've already checked that e_class is ELFCLASS64 but this may change in the future. Add a safety belt so that we don't access an invalid e_ehdr64 union member if it does. r340075 (by emaste): readelf: decode R_MIPS_HIGHER and R_MIPS_HIGHEST relocation types r342918 (by emaste): Update to ELF Tool Chain r3668 Highlights: - Make sure that only TLS sections are sorted into TLS segment. - Fixed multiple errors in "Section to Segment mapping". - Man page updates - ar improvements - elfcopy: avoid filter_reloc uninitialized variable for rela - elfcopy: avoid stripping relocations from static binaries - readelf: avoid printing directory in front of absolute path - readelf: add NT_FREEBSD_FEATURE_CTL FreeBSD note type - test improvements NOTES: Some of these changes originated in FreeBSD and simply reduce diffs between contrib and vendor. ELF Tool Chain ar is not (currently) used in FreeBSD, and there are improvements in both FreeBSD and ELF Tool Chain ar that are not in the other. r343592 (by emaste): readelf: decode flag bits in DT_FLAGS/DT_FLAGS_1 Decode d_val when the tag is DT_FLAGS or DT_FLAGS_1 based on the information at: https://docs.oracle.com/cd/E23824_01/html/819-0690/chapter6-42444.html PR: 232983 r343593 (by emaste): readelf: fix i386 build Use %jx and (uintmax_t) cast. PR: 232983 MFC with: r343592 r343614 (by emaste): readelf: dump elf note data Output format is compatible with GNU readelf's handling of unknown note types (modulo a GNU char signedness bug); future changes will add type- specific decoding. Relnotes: Yes r343665 (by emaste): readelf: use table-based DT_FLAGS and DT_FLAGS_1 decoding Fewer lines of code and more maintainable. r343669 (by emaste): readelf: decode FreeBSD note types Decode NT_FREEBSD_ABI_TAG, NT_FREEBSD_ARCH_TAG, and NT_FREEBSD_FEATURE_CTL. Relnotes: Yes Added: stable/12/contrib/elftoolchain/README.rst - copied unchanged from r342918, head/contrib/elftoolchain/README.rst stable/12/contrib/elftoolchain/libelf/libelf_elfmachine.c - copied unchanged from r342918, head/contrib/elftoolchain/libelf/libelf_elfmachine.c Modified: stable/12/contrib/elftoolchain/addr2line/addr2line.1 stable/12/contrib/elftoolchain/addr2line/addr2line.c stable/12/contrib/elftoolchain/ar/ar.1 stable/12/contrib/elftoolchain/ar/ar.5 stable/12/contrib/elftoolchain/ar/ar.c stable/12/contrib/elftoolchain/ar/ar.h stable/12/contrib/elftoolchain/ar/ranlib.1 stable/12/contrib/elftoolchain/ar/read.c stable/12/contrib/elftoolchain/ar/write.c stable/12/contrib/elftoolchain/common/native-elf-format stable/12/contrib/elftoolchain/cxxfilt/c++filt.1 stable/12/contrib/elftoolchain/elfcopy/elfcopy.1 stable/12/contrib/elftoolchain/elfcopy/elfcopy.h stable/12/contrib/elftoolchain/elfcopy/mcs.1 stable/12/contrib/elftoolchain/elfcopy/sections.c stable/12/contrib/elftoolchain/elfcopy/segments.c stable/12/contrib/elftoolchain/elfcopy/strip.1 stable/12/contrib/elftoolchain/libdwarf/dwarf.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_add_AT_comp_dir.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_add_AT_const_value_string.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_add_AT_dataref.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_add_AT_flag.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_add_AT_location_expr.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_add_AT_name.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_add_AT_producer.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_add_AT_ref_address.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_add_AT_reference.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_add_AT_signed_const.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_add_AT_string.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_add_AT_targ_address.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_add_arange.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_add_die_to_debug.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_add_directory_decl.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_add_expr_addr.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_add_expr_gen.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_add_fde_inst.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_add_file_decl.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_add_frame_cie.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_add_frame_fde.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_add_funcname.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_add_line_entry.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_add_pubname.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_add_typename.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_add_varname.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_add_weakname.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_attr.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_attrlist.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_attroffset.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_attrval_signed.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_child.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_dealloc.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_def_macro.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_die_abbrev_code.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_die_link.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_diename.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_dieoffset.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_end_macro_file.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_errmsg.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_errno.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_expand_frame_instructions.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_expr_current_offset.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_expr_into_block.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_fde_cfa_offset.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_find_macro_value_start.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_finish.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_formaddr.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_formblock.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_formexprloc.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_formflag.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_formref.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_formsig8.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_formstring.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_formudata.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_get_AT_name.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_get_abbrev.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_get_abbrev_children_flag.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_get_abbrev_code.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_get_abbrev_entry.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_get_abbrev_tag.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_get_address_size.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_get_arange.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_get_arange_info.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_get_aranges.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_get_cie_index.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_get_cie_info.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_get_cie_of_fde.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_get_cu_die_offset.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_get_die_infotypes_flag.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_get_elf.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_get_fde_at_pc.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_get_fde_info_for_all_regs.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_get_fde_info_for_all_regs3.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_get_fde_info_for_cfa_reg3.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_get_fde_info_for_reg.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_get_fde_info_for_reg3.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_get_fde_instr_bytes.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_get_fde_list.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_get_fde_n.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_get_fde_range.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_get_form_class.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_get_funcs.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_get_globals.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_get_loclist_entry.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_get_macro_details.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_get_pubtypes.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_get_ranges.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_get_relocation_info.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_get_relocation_info_count.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_get_section_bytes.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_get_section_max_offsets.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_get_str.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_get_types.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_get_vars.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_get_weaks.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_hasattr.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_hasform.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_highpc.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_init.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_lineno.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_lne_end_sequence.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_lne_set_address.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_loclist.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_loclist_from_expr.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_new_die.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_new_expr.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_new_fde.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_next_cu_header.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_next_types_section.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_object_init.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_producer_init.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_producer_set_isa.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_reset_section_bytes.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_set_frame_cfa_value.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_set_reloc_application.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_seterrarg.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_srcfiles.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_srclines.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_start_macro_file.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_tag.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_transform_to_disk_form.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_undef_macro.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_vendor_ext.3 stable/12/contrib/elftoolchain/libdwarf/dwarf_whatattr.3 stable/12/contrib/elftoolchain/libelf/Makefile stable/12/contrib/elftoolchain/libelf/_libelf.h stable/12/contrib/elftoolchain/libelf/elf.3 stable/12/contrib/elftoolchain/libelf/elf_begin.3 stable/12/contrib/elftoolchain/libelf/elf_cntl.3 stable/12/contrib/elftoolchain/libelf/elf_data.c stable/12/contrib/elftoolchain/libelf/elf_end.3 stable/12/contrib/elftoolchain/libelf/elf_errmsg.3 stable/12/contrib/elftoolchain/libelf/elf_fill.3 stable/12/contrib/elftoolchain/libelf/elf_flagdata.3 stable/12/contrib/elftoolchain/libelf/elf_getarhdr.3 stable/12/contrib/elftoolchain/libelf/elf_getarsym.3 stable/12/contrib/elftoolchain/libelf/elf_getbase.3 stable/12/contrib/elftoolchain/libelf/elf_getdata.3 stable/12/contrib/elftoolchain/libelf/elf_getident.3 stable/12/contrib/elftoolchain/libelf/elf_getphdrnum.3 stable/12/contrib/elftoolchain/libelf/elf_getphnum.3 stable/12/contrib/elftoolchain/libelf/elf_getscn.3 stable/12/contrib/elftoolchain/libelf/elf_getshdrnum.3 stable/12/contrib/elftoolchain/libelf/elf_getshdrstrndx.3 stable/12/contrib/elftoolchain/libelf/elf_getshnum.3 stable/12/contrib/elftoolchain/libelf/elf_getshstrndx.3 stable/12/contrib/elftoolchain/libelf/elf_hash.3 stable/12/contrib/elftoolchain/libelf/elf_kind.3 stable/12/contrib/elftoolchain/libelf/elf_memory.3 stable/12/contrib/elftoolchain/libelf/elf_next.3 stable/12/contrib/elftoolchain/libelf/elf_open.3 stable/12/contrib/elftoolchain/libelf/elf_rand.3 stable/12/contrib/elftoolchain/libelf/elf_rawfile.3 stable/12/contrib/elftoolchain/libelf/elf_scn.c stable/12/contrib/elftoolchain/libelf/elf_strptr.3 stable/12/contrib/elftoolchain/libelf/elf_update.3 stable/12/contrib/elftoolchain/libelf/elf_update.c stable/12/contrib/elftoolchain/libelf/elf_version.3 stable/12/contrib/elftoolchain/libelf/gelf.3 stable/12/contrib/elftoolchain/libelf/gelf_checksum.3 stable/12/contrib/elftoolchain/libelf/gelf_fsize.3 stable/12/contrib/elftoolchain/libelf/gelf_getcap.3 stable/12/contrib/elftoolchain/libelf/gelf_getclass.3 stable/12/contrib/elftoolchain/libelf/gelf_getdyn.3 stable/12/contrib/elftoolchain/libelf/gelf_getehdr.3 stable/12/contrib/elftoolchain/libelf/gelf_getmove.3 stable/12/contrib/elftoolchain/libelf/gelf_getphdr.3 stable/12/contrib/elftoolchain/libelf/gelf_getrel.3 stable/12/contrib/elftoolchain/libelf/gelf_getrela.3 stable/12/contrib/elftoolchain/libelf/gelf_getshdr.3 stable/12/contrib/elftoolchain/libelf/gelf_getsym.3 stable/12/contrib/elftoolchain/libelf/gelf_getsyminfo.3 stable/12/contrib/elftoolchain/libelf/gelf_getsymshndx.3 stable/12/contrib/elftoolchain/libelf/gelf_mips64el.c stable/12/contrib/elftoolchain/libelf/gelf_newehdr.3 stable/12/contrib/elftoolchain/libelf/gelf_newphdr.3 stable/12/contrib/elftoolchain/libelf/gelf_update_ehdr.3 stable/12/contrib/elftoolchain/libelf/gelf_xlate.c stable/12/contrib/elftoolchain/libelf/gelf_xlatetof.3 stable/12/contrib/elftoolchain/libelf/libelf_convert.m4 stable/12/contrib/elftoolchain/libelf/libelf_ehdr.c stable/12/contrib/elftoolchain/libelf/libelf_phdr.c stable/12/contrib/elftoolchain/libelf/libelf_xlate.c stable/12/contrib/elftoolchain/libelftc/elftc.3 stable/12/contrib/elftoolchain/libelftc/elftc_bfd_find_target.3 stable/12/contrib/elftoolchain/libelftc/elftc_copyfile.3 stable/12/contrib/elftoolchain/libelftc/elftc_demangle.3 stable/12/contrib/elftoolchain/libelftc/elftc_reloc_type_str.3 stable/12/contrib/elftoolchain/libelftc/elftc_reloc_type_str.c stable/12/contrib/elftoolchain/libelftc/elftc_set_timestamps.3 stable/12/contrib/elftoolchain/libelftc/elftc_string_table_create.3 stable/12/contrib/elftoolchain/libelftc/elftc_timestamp.3 stable/12/contrib/elftoolchain/libelftc/elftc_version.3 stable/12/contrib/elftoolchain/nm/nm.1 stable/12/contrib/elftoolchain/readelf/readelf.1 stable/12/contrib/elftoolchain/readelf/readelf.c stable/12/contrib/elftoolchain/strings/strings.c stable/12/lib/libelf/Makefile stable/12/lib/libelftc/elftc_version.c Directory Properties: stable/12/ (props changed) Copied: stable/12/contrib/elftoolchain/README.rst (from r342918, head/contrib/elftoolchain/README.rst) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/12/contrib/elftoolchain/README.rst Mon Apr 22 08:58:33 2019 (r346536, copy of r342918, head/contrib/elftoolchain/README.rst) @@ -0,0 +1,126 @@ +The Elftoolchain Project +======================== + +.. contents:: Table of Contents + +Description +----------- + +This software implements essential compilation tools and libraries for: + +- managing program objects conforming to the ELF_ object format, and +- for managing DWARF_ debugging information in ELF objects. + +The project currently implements the following utilities and +libraries: + +=========== ============================================ +Name Description +=========== ============================================ +ar Archive manager. +addr2line Debug tool. +brandelf Manage the ELF brand on executables. +c++filt Translate encoded symbols. +elfcopy Copy and translate between object formats. +elfdump Diagnostic tool. +findtextrel Find undesired text relocations. +libdwarf DWARF access library. +libelf ELF access library. +mcs Manage comment sections. +nm List symbols in an ELF object. +ranlib Add archive symbol tables to an archive. +readelf Display ELF information. +size List object sizes. +strings Extract printable strings. +strip Discard information from ELF objects. +=========== ============================================ + +.. _ELF: http://en.wikipedia.org/wiki/Executable_and_Linkable_Format +.. _DWARF: http://www.dwarfstd.org/ + + +Project Documentation +--------------------- + +- Release notes for released versions of this software are present in + the file ``RELEASE-NOTES`` in the current directory. +- The file ``INSTALL`` in the current directory contains instructions + on building and installing this software. +- Reference documentation in the form of manual pages is provided for + the utilities and libraries developed by the project. +- Additional tutorial documentation is present in the + ``documentation`` directory. + + +Tracking Ongoing Development +---------------------------- + +The project uses subversion_ for its version control system. + +.. _subversion: https://subversion.apache.org/ + +The subversion branch for the current set of sources may be accessed +at the following URL:: + + https://elftoolchain.svn.sourceforge.net/svnroot/elftoolchain/trunk + +The project's source tree may be checked out from its repository by +using the ``svn checkout`` command:: + + % svn checkout https://elftoolchain.svn.sourceforge.net/svnroot/elftoolchain/trunk + +Checked-out sources may be kept upto-date by running ``svn update`` +inside the source directory:: + + % svn update + + +Instructions on building and installing the software are given in the +file ``INSTALL`` in the current directory. + +Downloading Released Software +----------------------------- + +Released versions of the project's software may also be downloaded +from SourceForge's `file release system`_. + +.. _file release system: http://sourceforge.net/projects/elftoolchain/files/ + +Copyright and License +--------------------- + +This code is copyright its authors, and is distributed under the `BSD +License`_. + +.. _BSD License: http://www.opensource.org/licenses/bsd-license.php + + +Developer Community +------------------- + +The project's developers may be contacted using the mailing list: +````. + + +Reporting Bugs +-------------- + +Please use our `Trac instance`_ for viewing existing bug reports and +for submitting new bug reports. + +.. _`Trac instance`: http://sourceforge.net/apps/trac/elftoolchain/report + + +Additional Information +---------------------- + +Additional information about the project may be found on the `project +website`_. + +.. _project website: http://elftoolchain.sourceforge.net/ + +.. $Id: README.rst 3656 2018-12-26 09:46:24Z jkoshy $ + +.. Local Variables: +.. mode: rst +.. End: Modified: stable/12/contrib/elftoolchain/addr2line/addr2line.1 ============================================================================== --- stable/12/contrib/elftoolchain/addr2line/addr2line.1 Mon Apr 22 08:32:00 2019 (r346535) +++ stable/12/contrib/elftoolchain/addr2line/addr2line.1 Mon Apr 22 08:58:33 2019 (r346536) @@ -22,11 +22,11 @@ .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.\" $Id: addr2line.1 3263 2015-11-30 04:25:54Z kaiwang27 $ +.\" $Id: addr2line.1 3642 2018-10-14 14:24:28Z jkoshy $ .\" .Dd November 30, 2015 -.Os .Dt ADDR2LINE 1 +.Os .Sh NAME .Nm addr2line .Nd translate program addresses to source file names and line numbers Modified: stable/12/contrib/elftoolchain/addr2line/addr2line.c ============================================================================== --- stable/12/contrib/elftoolchain/addr2line/addr2line.c Mon Apr 22 08:32:00 2019 (r346535) +++ stable/12/contrib/elftoolchain/addr2line/addr2line.c Mon Apr 22 08:58:33 2019 (r346536) @@ -40,7 +40,7 @@ #include "uthash.h" #include "_elftc.h" -ELFTC_VCSID("$Id: addr2line.c 3499 2016-11-25 16:06:29Z emaste $"); +ELFTC_VCSID("$Id: addr2line.c 3544 2017-06-05 14:51:44Z emaste $"); struct Func { char *name; Modified: stable/12/contrib/elftoolchain/ar/ar.1 ============================================================================== --- stable/12/contrib/elftoolchain/ar/ar.1 Mon Apr 22 08:32:00 2019 (r346535) +++ stable/12/contrib/elftoolchain/ar/ar.1 Mon Apr 22 08:58:33 2019 (r346536) @@ -21,51 +21,52 @@ .\" out of the use of this software, even if advised of the possibility of .\" such damage. .\" -.\" $Id: ar.1 3230 2015-07-27 17:11:38Z emaste $ +.\" $Id: ar.1 3642 2018-10-14 14:24:28Z jkoshy $ .\" -.Dd July 27, 2015 -.Os +.Dd September 30, 2018 .Dt AR 1 +.Os .Sh NAME .Nm ar .Nd manage archives .Sh SYNOPSIS .Nm .Fl d -.Op Fl T .Op Fl f .Op Fl j +.Op Fl T .Op Fl v .Op Fl z .Ar archive .Ar .Nm .Fl m -.Op Fl T .Op Fl a Ar position-after .Op Fl b Ar position-before .Op Fl f .Op Fl i Ar position-before .Op Fl j .Op Fl s | Fl S +.Op Fl T .Op Fl z .Ar archive .Ar .Nm .Fl p -.Op Fl T .Op Fl f +.Op Fl s +.Op Fl T .Op Fl v .Ar archive .Op Ar .Nm .Fl q -.Op Fl T .Op Fl c .Op Fl D .Op Fl f .Op Fl F Ar flavor | Fl -flavor Ar flavor .Op Fl s | Fl S +.Op Fl T .Op Fl U .Op Fl v .Op Fl z @@ -73,7 +74,6 @@ .Ar .Nm .Fl r -.Op Fl T .Op Fl a Ar position-after .Op Fl b Ar position-before .Op Fl c @@ -83,6 +83,7 @@ .Op Fl i Ar position-before .Op Fl j .Op Fl s | Fl S +.Op Fl T .Op Fl u .Op Fl U .Op Fl v @@ -99,6 +100,7 @@ .Nm .Fl t .Op Fl f +.Op Fl s .Op Fl T .Op Fl v .Ar archive @@ -106,9 +108,10 @@ .Nm .Fl x .Op Fl C -.Op Fl T .Op Fl f .Op Fl o +.Op Fl s +.Op Fl T .Op Fl u .Op Fl v .Ar archive Modified: stable/12/contrib/elftoolchain/ar/ar.5 ============================================================================== --- stable/12/contrib/elftoolchain/ar/ar.5 Mon Apr 22 08:32:00 2019 (r346535) +++ stable/12/contrib/elftoolchain/ar/ar.5 Mon Apr 22 08:58:33 2019 (r346536) @@ -21,11 +21,11 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $Id: ar.5 3182 2015-04-10 16:08:10Z emaste $ +.\" $Id: ar.5 3642 2018-10-14 14:24:28Z jkoshy $ .\" -.Dd November 28, 2010 -.Os +.Dd September 30, 2018 .Dt AR 5 +.Os .Sh NAME .Nm ar .Nd archive file format for @@ -84,6 +84,8 @@ An archive header comprises the following fixed sized .Bl -tag -width "Li ar_name" .It Ar ar_name (16 bytes) The file name of the archive member. +This field names a leaf file; absolute paths and relative paths containing +directory names are not supported. The format of this field varies between the BSD and SVR4/GNU formats and is described in more detail in the section .Sx "Representing File Names" Modified: stable/12/contrib/elftoolchain/ar/ar.c ============================================================================== --- stable/12/contrib/elftoolchain/ar/ar.c Mon Apr 22 08:32:00 2019 (r346535) +++ stable/12/contrib/elftoolchain/ar/ar.c Mon Apr 22 08:58:33 2019 (r346536) @@ -72,7 +72,7 @@ #include "ar.h" -ELFTC_VCSID("$Id: ar.c 3319 2016-01-13 21:37:53Z jkoshy $"); +ELFTC_VCSID("$Id: ar.c 3629 2018-09-30 19:26:28Z jkoshy $"); enum options { @@ -100,11 +100,12 @@ main(int argc, char **argv) struct bsdar *bsdar, bsdar_storage; char *arcmd, *argv1_saved; size_t len; - int i, opt; + int exitcode, i, opt; bsdar = &bsdar_storage; memset(bsdar, 0, sizeof(*bsdar)); + exitcode = EXIT_SUCCESS; arcmd = argv1_saved = NULL; bsdar->output = stdout; @@ -152,9 +153,9 @@ main(int argc, char **argv) bsdar->options |= AR_S; while ((bsdar->filename = *argv++) != NULL) - ar_write_archive(bsdar, 's'); + exitcode |= ar_write_archive(bsdar, 's'); - exit(EXIT_SUCCESS); + exit(exitcode); } else { if (argc < 2) bsdar_usage(); @@ -331,30 +332,33 @@ main(int argc, char **argv) if ((!bsdar->mode || strchr("ptx", bsdar->mode)) && bsdar->options & AR_S) { - ar_write_archive(bsdar, 's'); + exitcode = ar_write_archive(bsdar, 's'); if (!bsdar->mode) - exit(EXIT_SUCCESS); + exit(exitcode); } switch(bsdar->mode) { case 'd': case 'm': case 'q': case 'r': - ar_write_archive(bsdar, bsdar->mode); + exitcode = ar_write_archive(bsdar, bsdar->mode); break; case 'p': case 't': case 'x': - ar_read_archive(bsdar, bsdar->mode); + exitcode = ar_read_archive(bsdar, bsdar->mode); break; default: bsdar_usage(); /* NOTREACHED */ } - for (i = 0; i < bsdar->argc; i++) - if (bsdar->argv[i] != NULL) + for (i = 0; i < bsdar->argc; i++) { + if (bsdar->argv[i] != NULL) { bsdar_warnc(bsdar, 0, "%s: not found in archive", bsdar->argv[i]); + exitcode = EXIT_FAILURE; + } + } - exit(EXIT_SUCCESS); + exit(exitcode); } static void Modified: stable/12/contrib/elftoolchain/ar/ar.h ============================================================================== --- stable/12/contrib/elftoolchain/ar/ar.h Mon Apr 22 08:32:00 2019 (r346535) +++ stable/12/contrib/elftoolchain/ar/ar.h Mon Apr 22 08:58:33 2019 (r346536) @@ -23,7 +23,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: ar.h 2496 2012-04-24 02:33:40Z jkoshy $ + * $Id: ar.h 3629 2018-09-30 19:26:28Z jkoshy $ */ #include @@ -135,8 +135,8 @@ struct bsdar { }; void ar_mode_script(struct bsdar *ar); -void ar_read_archive(struct bsdar *_ar, int _mode); -void ar_write_archive(struct bsdar *_ar, int _mode); +int ar_read_archive(struct bsdar *_ar, int _mode); +int ar_write_archive(struct bsdar *_ar, int _mode); void bsdar_errc(struct bsdar *, int _code, const char *fmt, ...); int bsdar_is_pseudomember(struct bsdar *_ar, const char *_name); const char *bsdar_strmode(mode_t m); Modified: stable/12/contrib/elftoolchain/ar/ranlib.1 ============================================================================== --- stable/12/contrib/elftoolchain/ar/ranlib.1 Mon Apr 22 08:32:00 2019 (r346535) +++ stable/12/contrib/elftoolchain/ar/ranlib.1 Mon Apr 22 08:58:33 2019 (r346536) @@ -21,11 +21,11 @@ .\" out of the use of this software, even if advised of the possibility of .\" such damage. .\" -.\" $Id: ranlib.1 3195 2015-05-12 17:22:19Z emaste $ +.\" $Id: ranlib.1 3642 2018-10-14 14:24:28Z jkoshy $ .\" .Dd December 9, 2012 -.Os .Dt RANLIB 1 +.Os .Sh NAME .Nm ranlib .Nd update archive symbol tables Modified: stable/12/contrib/elftoolchain/ar/read.c ============================================================================== --- stable/12/contrib/elftoolchain/ar/read.c Mon Apr 22 08:32:00 2019 (r346535) +++ stable/12/contrib/elftoolchain/ar/read.c Mon Apr 22 08:58:33 2019 (r346536) @@ -34,16 +34,20 @@ #include #include #include +#include #include #include "ar.h" -ELFTC_VCSID("$Id: read.c 3180 2015-04-09 15:13:57Z emaste $"); +ELFTC_VCSID("$Id: read.c 3629 2018-09-30 19:26:28Z jkoshy $"); /* * Handle read modes: 'x', 't' and 'p'. + * + * Returns EXIT_SUCCESS if all operations completed successfully or returns + * EXIT_FAILURE otherwise. */ -void +int ar_read_archive(struct bsdar *bsdar, int mode) { FILE *out; @@ -60,8 +64,8 @@ ar_read_archive(struct bsdar *bsdar, int mode) gid_t gid; char **av; char buf[25]; - char find; - int i, flags, r; + int found; + int exitcode, i, flags, r; assert(mode == 'p' || mode == 't' || mode == 'x'); @@ -70,6 +74,7 @@ ar_read_archive(struct bsdar *bsdar, int mode) archive_read_support_format_ar(a); AC(archive_read_open_filename(a, bsdar->filename, DEF_BLKSZ)); + exitcode = EXIT_SUCCESS; out = bsdar->output; for (;;) { @@ -96,12 +101,27 @@ ar_read_archive(struct bsdar *bsdar, int mode) if (bsdar_is_pseudomember(bsdar, name)) continue; + /* The ar(5) format only supports 'leaf' file names. */ + if (strchr(name, '/')) { + bsdar_warnc(bsdar, 0, "ignoring entry: %s", + name); + continue; + } + + /* + * If we had been given a list of file names to process, check + * that the current entry is present in this list. + */ if (bsdar->argc > 0) { - find = 0; + found = 0; for(i = 0; i < bsdar->argc; i++) { av = &bsdar->argv[i]; if (*av == NULL) continue; + /* + * Per POSIX, only the basename of a file + * argument should be compared. + */ if ((bname = basename(*av)) == NULL) bsdar_errc(bsdar, errno, "basename failed"); @@ -109,10 +129,10 @@ ar_read_archive(struct bsdar *bsdar, int mode) continue; *av = NULL; - find = 1; + found = 1; break; } - if (!find) + if (!found) continue; } @@ -157,7 +177,7 @@ ar_read_archive(struct bsdar *bsdar, int mode) /* mode == 'x' */ if (stat(name, &sb) != 0) { if (errno != ENOENT) { - bsdar_warnc(bsdar, 0, + bsdar_warnc(bsdar, errno, "stat %s failed", bsdar->filename); continue; @@ -174,12 +194,6 @@ ar_read_archive(struct bsdar *bsdar, int mode) if (bsdar->options & AR_V) (void)fprintf(out, "x - %s\n", name); - /* Disallow absolute paths. */ - if (name[0] == '/') { - bsdar_warnc(bsdar, 0, - "Absolute path '%s'", name); - continue; - } /* Basic path security flags. */ flags = ARCHIVE_EXTRACT_SECURE_SYMLINKS | ARCHIVE_EXTRACT_SECURE_NODOTDOT; @@ -189,11 +203,19 @@ ar_read_archive(struct bsdar *bsdar, int mode) r = archive_read_extract(a, entry, flags); } - if (r) + if (r) { bsdar_warnc(bsdar, 0, "%s", archive_error_string(a)); + exitcode = EXIT_FAILURE; + } } } + + if (r == ARCHIVE_FATAL) + exitcode = EXIT_FAILURE; + AC(archive_read_close(a)); ACV(archive_read_free(a)); + + return (exitcode); } Modified: stable/12/contrib/elftoolchain/ar/write.c ============================================================================== --- stable/12/contrib/elftoolchain/ar/write.c Mon Apr 22 08:32:00 2019 (r346535) +++ stable/12/contrib/elftoolchain/ar/write.c Mon Apr 22 08:58:33 2019 (r346536) @@ -40,7 +40,7 @@ #include "ar.h" -ELFTC_VCSID("$Id: write.c 3183 2015-04-10 16:18:42Z emaste $"); +ELFTC_VCSID("$Id: write.c 3629 2018-09-30 19:26:28Z jkoshy $"); #define _ARMAG_LEN 8 /* length of the magic string */ #define _ARHDR_LEN 60 /* length of the archive header */ @@ -352,17 +352,20 @@ read_objs(struct bsdar *bsdar, const char *archive, in /* * Write an archive. + * + * Returns EXIT_SUCCESS if the write succeeded or EXIT_FAILURE otherwise. */ -void +int ar_write_archive(struct bsdar *bsdar, int mode) { struct ar_obj *nobj, *obj, *obj_temp, *pos; struct stat sb; const char *bname; char **av; - int i; + int exitcode, i; TAILQ_INIT(&bsdar->v_obj); + exitcode = EXIT_SUCCESS; nobj = NULL; pos = NULL; memset(&sb, 0, sizeof(sb)); @@ -376,16 +379,16 @@ ar_write_archive(struct bsdar *bsdar, int mode) */ if (stat(bsdar->filename, &sb) != 0) { if (errno != ENOENT) { - bsdar_warnc(bsdar, 0, "stat %s failed", + bsdar_warnc(bsdar, errno, "stat %s failed", bsdar->filename); - return; + return (EXIT_FAILURE); } /* We do not create archive in mode 'd', 'm' and 's'. */ if (mode != 'r' && mode != 'q') { bsdar_warnc(bsdar, 0, "%s: no such file", bsdar->filename); - return; + return (EXIT_FAILURE); } /* Issue a message if the '-c' option was not specified. */ @@ -474,8 +477,10 @@ ar_write_archive(struct bsdar *bsdar, int mode) */ nobj = create_obj_from_file(bsdar, *av, obj->mtime); - if (nobj == NULL) + if (nobj == NULL) { + exitcode = EXIT_FAILURE; goto skip_obj; + } } if (bsdar->options & AR_V) @@ -510,9 +515,13 @@ new_archive: av = &bsdar->argv[i]; if (*av != NULL && (mode == 'r' || mode == 'q')) { nobj = create_obj_from_file(bsdar, *av, 0); - if (nobj != NULL) - insert_obj(bsdar, nobj, pos); - if (bsdar->options & AR_V && nobj != NULL) + if (nobj == NULL) { + exitcode = EXIT_FAILURE; + *av = NULL; + continue; + } + insert_obj(bsdar, nobj, pos); + if (bsdar->options & AR_V) (void)fprintf(bsdar->output, "a - %s\n", *av); *av = NULL; } @@ -521,6 +530,8 @@ new_archive: write_objs: write_objs(bsdar); write_cleanup(bsdar); + + return (exitcode); } /* Modified: stable/12/contrib/elftoolchain/common/native-elf-format ============================================================================== --- stable/12/contrib/elftoolchain/common/native-elf-format Mon Apr 22 08:32:00 2019 (r346535) +++ stable/12/contrib/elftoolchain/common/native-elf-format Mon Apr 22 08:58:33 2019 (r346536) @@ -1,6 +1,6 @@ #!/bin/sh # -# $Id: native-elf-format 3293 2016-01-07 19:26:27Z emaste $ +# $Id: native-elf-format 3650 2018-11-25 12:06:28Z jkoshy $ # # Find the native ELF format for a host platform by compiling a # test object and examining the resulting object. @@ -35,7 +35,7 @@ $1 ~ "Machine:" { elfarch = "EM_386"; } else if (match($0, "MIPS")) { elfarch = "EM_MIPS"; - } else if (match($0, ".*[xX]86-64")) { + } else if (match($0, ".*[xX]86[-_]64")) { elfarch = "EM_X86_64"; } else { elfarch = "unknown"; Modified: stable/12/contrib/elftoolchain/cxxfilt/c++filt.1 ============================================================================== --- stable/12/contrib/elftoolchain/cxxfilt/c++filt.1 Mon Apr 22 08:32:00 2019 (r346535) +++ stable/12/contrib/elftoolchain/cxxfilt/c++filt.1 Mon Apr 22 08:58:33 2019 (r346536) @@ -22,11 +22,11 @@ .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.\" $Id: c++filt.1 3195 2015-05-12 17:22:19Z emaste $ +.\" $Id: c++filt.1 3642 2018-10-14 14:24:28Z jkoshy $ .\" .Dd August 24, 2011 -.Os .Dt C++FILT 1 +.Os .Sh NAME .Nm c++filt .Nd decode C++ symbols Modified: stable/12/contrib/elftoolchain/elfcopy/elfcopy.1 ============================================================================== --- stable/12/contrib/elftoolchain/elfcopy/elfcopy.1 Mon Apr 22 08:32:00 2019 (r346535) +++ stable/12/contrib/elftoolchain/elfcopy/elfcopy.1 Mon Apr 22 08:58:33 2019 (r346536) @@ -21,11 +21,11 @@ .\" out of the use of this software, even if advised of the possibility of .\" such damage. .\" -.\" $Id: elfcopy.1 3565 2017-08-31 02:24:19Z emaste $ +.\" $Id: elfcopy.1 3642 2018-10-14 14:24:28Z jkoshy $ .\" .Dd August 30, 2017 -.Os .Dt ELFCOPY 1 +.Os .Sh NAME .Nm elfcopy , .Nm objcopy Modified: stable/12/contrib/elftoolchain/elfcopy/elfcopy.h ============================================================================== --- stable/12/contrib/elftoolchain/elfcopy/elfcopy.h Mon Apr 22 08:32:00 2019 (r346535) +++ stable/12/contrib/elftoolchain/elfcopy/elfcopy.h Mon Apr 22 08:58:33 2019 (r346536) @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: elfcopy.h 3446 2016-05-03 01:31:17Z emaste $ + * $Id: elfcopy.h 3615 2018-05-17 04:12:24Z kaiwang27 $ */ #include Modified: stable/12/contrib/elftoolchain/elfcopy/mcs.1 ============================================================================== --- stable/12/contrib/elftoolchain/elfcopy/mcs.1 Mon Apr 22 08:32:00 2019 (r346535) +++ stable/12/contrib/elftoolchain/elfcopy/mcs.1 Mon Apr 22 08:58:33 2019 (r346536) @@ -21,11 +21,11 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $Id: mcs.1 2247 2011-11-29 08:41:34Z jkoshy $ +.\" $Id: mcs.1 3642 2018-10-14 14:24:28Z jkoshy $ .\" .Dd November 29, 2011 -.Os .Dt MCS 1 +.Os .Sh NAME .Nm mcs .Nd manipulate the comment section of an ELF object Modified: stable/12/contrib/elftoolchain/elfcopy/sections.c ============================================================================== --- stable/12/contrib/elftoolchain/elfcopy/sections.c Mon Apr 22 08:32:00 2019 (r346535) +++ stable/12/contrib/elftoolchain/elfcopy/sections.c Mon Apr 22 08:58:33 2019 (r346536) @@ -34,7 +34,7 @@ #include "elfcopy.h" -ELFTC_VCSID("$Id: sections.c 3443 2016-04-15 18:57:54Z kaiwang27 $"); +ELFTC_VCSID("$Id: sections.c 3646 2018-10-27 02:25:39Z emaste $"); static void add_gnu_debuglink(struct elfcopy *ecp); static uint32_t calc_crc32(const char *p, size_t len, uint32_t crc); Modified: stable/12/contrib/elftoolchain/elfcopy/segments.c ============================================================================== --- stable/12/contrib/elftoolchain/elfcopy/segments.c Mon Apr 22 08:32:00 2019 (r346535) +++ stable/12/contrib/elftoolchain/elfcopy/segments.c Mon Apr 22 08:58:33 2019 (r346536) @@ -34,7 +34,7 @@ #include "elfcopy.h" -ELFTC_VCSID("$Id: segments.c 3449 2016-05-03 13:59:29Z emaste $"); +ELFTC_VCSID("$Id: segments.c 3615 2018-05-17 04:12:24Z kaiwang27 $"); static void insert_to_inseg_list(struct segment *seg, struct section *sec); Modified: stable/12/contrib/elftoolchain/elfcopy/strip.1 ============================================================================== --- stable/12/contrib/elftoolchain/elfcopy/strip.1 Mon Apr 22 08:32:00 2019 (r346535) +++ stable/12/contrib/elftoolchain/elfcopy/strip.1 Mon Apr 22 08:58:33 2019 (r346536) @@ -21,11 +21,11 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $Id: strip.1 2069 2011-10-26 15:53:48Z jkoshy $ +.\" $Id: strip.1 3642 2018-10-14 14:24:28Z jkoshy $ .\" .Dd September 17, 2011 -.Os .Dt STRIP 1 +.Os .Sh NAME .Nm strip .Nd discard information from ELF objects Modified: stable/12/contrib/elftoolchain/libdwarf/dwarf.3 ============================================================================== --- stable/12/contrib/elftoolchain/libdwarf/dwarf.3 Mon Apr 22 08:32:00 2019 (r346535) +++ stable/12/contrib/elftoolchain/libdwarf/dwarf.3 Mon Apr 22 08:58:33 2019 (r346536) @@ -21,11 +21,11 @@ .\" out of the use of this software, even if advised of the possibility of .\" such damage. .\" -.\" $Id: dwarf.3 3295 2016-01-08 22:08:10Z jkoshy $ +.\" $Id: dwarf.3 3644 2018-10-15 19:55:01Z jkoshy $ .\" .Dd December 21, 2014 -.Os .Dt DWARF 3 +.Os .Sh NAME .Nm dwarf .Nd access debugging information in object files @@ -34,7 +34,6 @@ .Sh SYNOPSIS .In libdwarf.h .Sh DESCRIPTION -.Pp The .Lb libdwarf provides functions that allow an application to read and write debugging @@ -129,7 +128,6 @@ A descriptor representing a static variable. A descriptor representing a weak name. .El .Ss Error Handling -.Pp Library functions that encounter an error will return with a value other than .Dv DW_DLV_OK . @@ -173,7 +171,7 @@ below. .Pp .Bl -tag -compact -width "CCCC" .It Abbreviations -.Bl -tag -compact +.Bl -tag -compact -width indent .It Fn dwarf_get_abbrev Retrieve abbreviation information at a given offset. .It Fn dwarf_get_abbrev_children_flag @@ -187,7 +185,7 @@ descriptor. Retrieve the tag for an abbreviation entry. .El .It Addresses -.Bl -tag -compact +.Bl -tag -compact -width indent .It Fn dwarf_get_address_size Return the number of bytes needed to represent an address. .It Fn dwarf_get_arange @@ -206,7 +204,7 @@ Retrieve information about non-contiguous address rang a debugging information entry. .El .It Attributes -.Bl -tag -compact +.Bl -tag -compact -width indent .It Fn dwarf_arrayorder Retrieve the value of a .Dv DW_AT_ordering @@ -279,7 +277,7 @@ Retrieve the attribute code for an attribute. Retrieve the form of an attribute. .El .It Call Information Entries and Frame Descriptor Entries -.Bl -tag -compact +.Bl -tag -compact -width indent .It Fn dwarf_get_cie_index Retrieve the index for a CIE descriptor. .It Fn dwarf_get_cie_info @@ -308,7 +306,7 @@ Retrieve an FDE descriptor. Retrieve range information from an FDE descriptor. .El .It Compilation Units -.Bl -tag -compact +.Bl -tag -compact -width indent .It Xo .Fn dwarf_get_cu_die_offset_given_cu_header_offset , .Fn dwarf_get_cu_die_offset_given_cu_header_offset_b @@ -323,7 +321,7 @@ compilation or type unit. Step through compilation units in a debug context. .El .It Debugging Information Entries -.Bl -tag -compact +.Bl -tag -compact -width indent .It Fn dwarf_child Returns the child of a debugging information entry. .It Fn dwarf_die_abbrev_code @@ -353,7 +351,7 @@ entry. Retrieve the tag for a debugging information entry. .El .It Functions -.Bl -tag -compact +.Bl -tag -compact -width indent .It Fn dwarf_func_cu_offset Retrieves the offset for the compilation unit for a function. .It Fn dwarf_func_die_offset @@ -367,7 +365,7 @@ Retrieve both the name and offsets for a function. Retrieve information about static functions. .El .It Globals -.Bl -tag -compact +.Bl -tag -compact -width indent .It Fn dwarf_get_globals Retrieve a list of globals. .It Fn dwarf_global_cu_offset @@ -396,7 +394,7 @@ and allow an application to specify alternate low-level file access routines. .It Line Numbers -.Bl -tag -compact +.Bl -tag -compact -width indent .It Fn dwarf_lineaddr Retrieve the program address for a source line. .It Fn dwarf_linebeginstatement @@ -420,7 +418,7 @@ Retrieve source files for a compilation unit. Return line number information for a compilation unit. .El .It Location Lists -.Bl -tag -compact +.Bl -tag -compact -width indent .It Fn dwarf_get_loclist_entry Retrieve a location list entry. .It Fn dwarf_loclist , Fn dwarf_loclist_n @@ -433,7 +431,7 @@ Retrieve location expressions. Translate a location expression into a location descriptor. .El .It Error Handling -.Bl -tag -compact +.Bl -tag -compact -width indent .It Fn dwarf_errmsg Retrieve a human-readable error message. .It Fn dwarf_errno @@ -444,7 +442,7 @@ Set the argument passed to a callback error handler. Set the callback handler to be called in case of an error. .El .It Frame Handling -.Bl -tag -compact +.Bl -tag -compact -width indent .It Fn dwarf_expand_frame_instructions Translate frame instruction bytes. .It Fn dwarf_set_frame_cfa_value @@ -464,7 +462,7 @@ Set the register number representing the rule. .El .It Macros -.Bl -tag -compact +.Bl -tag -compact -width indent .It Fn dwarf_find_macro_value_start Return the macro value part of a macro string. .It Fn dwarf_get_macro_details @@ -523,7 +521,7 @@ for DWARF constants: and .Fn dwarf_get_VIS_name . .It Types -.Bl -tag -compact +.Bl -tag -compact -width indent .It Fn dwarf_get_pubtypes , Fn dwarf_get_types Retrieve descriptors for user-defined types. .It Fn dwarf_next_types_section @@ -540,7 +538,7 @@ Retrieve the name of a type. Retrieve the name and offsets for a type. .El .It Variables -.Bl -tag -compact +.Bl -tag -compact -width indent .It Fn dwarf_get_vars Retrieve descriptors for static variables. .It Fn dwarf_var_cu_offset @@ -553,7 +551,7 @@ Retrieve the name of a variable. Retrieve the name and offsets for a variable. .El .It Weak Symbols -.Bl -tag -compact +.Bl -tag -compact -width indent .It Fn dwarf_get_weaks Retrieve information about weak symbols. .It Fn dwarf_weak_cu_offset @@ -566,7 +564,7 @@ Retrieve the name of a weak symbol. Retrieve the name and offsets for a weak symbol. .El .It Miscellaneous -.Bl -tag -compact +.Bl -tag -compact -width indent .It Fn dwarf_get_elf Retrieve the ELF descriptor for a debug context, see .Xr elf 3 . @@ -605,7 +603,7 @@ information entry: and .Fn dwarf_add_AT_unsigned_const . .It Debugging Information Entry Management -.Bl -tag -compact +.Bl -tag -compact -width indent .It Fn dwarf_add_die_to_debug Set the root debugging information entry for a DWARF producer instance. .It Fn dwarf_die_link @@ -623,7 +621,7 @@ are used to initialize a producer instance. When done, applications release resources using the function .Fn dwarf_producer_finish . .It Relocations and Sections -.Bl -tag -compact +.Bl -tag -compact -width indent .It Fn dwarf_get_relocation_info Retrieve a relocation array from a producer instance. .It Fn dwarf_get_relocation_info_count @@ -636,7 +634,7 @@ Reset internal state for a producer instance. Prepare byte streams for writing out. .El .It Macros -.Bl -tag -compact +.Bl -tag -compact -width indent .It Fn dwarf_def_macro Add a macro definition. .It Fn dwarf_end_macro_file , Fn dwarf_start_macro_file @@ -647,7 +645,7 @@ Note the removal of a macro definition. Enables storing macro information as specified in the DWARF standard. .El .It Symbols, Expressions, Addresses and Offsets -.Bl -tag -compact +.Bl -tag -compact -width indent .It Fn dwarf_add_arange , Fn dwarf_add_arange_b Add address range information. .It Fn dwarf_add_directory_decl @@ -741,7 +739,9 @@ The DWARF(3) API originated at Silicon Graphics Inc. .Pp A BSD-licensed implementation of a subset of the API was written by .An John Birrell Aq Mt jb@FreeBSD.org -for the FreeBSD project. +for the +.Fx +project. The implementation was subsequently revised and completed by .An Kai Wang Aq Mt kaiwang27@users.sourceforge.net . .Pp Modified: stable/12/contrib/elftoolchain/libdwarf/dwarf_add_AT_comp_dir.3 ============================================================================== --- stable/12/contrib/elftoolchain/libdwarf/dwarf_add_AT_comp_dir.3 Mon Apr 22 08:32:00 2019 (r346535) +++ stable/12/contrib/elftoolchain/libdwarf/dwarf_add_AT_comp_dir.3 Mon Apr 22 08:58:33 2019 (r346536) @@ -22,11 +22,11 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $Id: dwarf_add_AT_comp_dir.3 2072 2011-10-27 03:26:49Z jkoshy $ +.\" $Id: dwarf_add_AT_comp_dir.3 3640 2018-10-14 14:09:13Z jkoshy $ .\" .Dd September 4, 2011 -.Os .Dt DWARF_ADD_AT_COMP_DIR 3 +.Os .Sh NAME .Nm dwarf_add_AT_comp_dir .Nd create and attach a DW_AT_comp_dir attribute Modified: stable/12/contrib/elftoolchain/libdwarf/dwarf_add_AT_const_value_string.3 ============================================================================== --- stable/12/contrib/elftoolchain/libdwarf/dwarf_add_AT_const_value_string.3 Mon Apr 22 08:32:00 2019 (r346535) +++ stable/12/contrib/elftoolchain/libdwarf/dwarf_add_AT_const_value_string.3 Mon Apr 22 08:58:33 2019 (r346536) @@ -22,11 +22,11 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $Id: dwarf_add_AT_const_value_string.3 2072 2011-10-27 03:26:49Z jkoshy $ +.\" $Id: dwarf_add_AT_const_value_string.3 3640 2018-10-14 14:09:13Z jkoshy $ .\" .Dd September 4, 2011 -.Os .Dt DWARF_ADD_AT_CONST_VALUE_STRING 3 +.Os .Sh NAME .Nm dwarf_add_AT_const_value_signedint , .Nm dwarf_add_AT_const_value_string , Modified: stable/12/contrib/elftoolchain/libdwarf/dwarf_add_AT_dataref.3 ============================================================================== --- stable/12/contrib/elftoolchain/libdwarf/dwarf_add_AT_dataref.3 Mon Apr 22 08:32:00 2019 (r346535) +++ stable/12/contrib/elftoolchain/libdwarf/dwarf_add_AT_dataref.3 Mon Apr 22 08:58:33 2019 (r346536) @@ -22,11 +22,11 @@ *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From owner-svn-src-stable-12@freebsd.org Mon Apr 22 10:01:22 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E518B1595252; Mon, 22 Apr 2019 10:01:21 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 8A63B834EF; Mon, 22 Apr 2019 10:01:21 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 65B50B42F; Mon, 22 Apr 2019 10:01:21 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3MA1LCv092162; Mon, 22 Apr 2019 10:01:21 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3MA1K4d092158; Mon, 22 Apr 2019 10:01:20 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201904221001.x3MA1K4d092158@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Mon, 22 Apr 2019 10:01:20 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346537 - in stable/12: lib/libc/stdlib libexec/rtld-elf X-SVN-Group: stable-12 X-SVN-Commit-Author: kib X-SVN-Commit-Paths: in stable/12: lib/libc/stdlib libexec/rtld-elf X-SVN-Commit-Revision: 346537 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 8A63B834EF X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.97 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.97)[-0.968,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Apr 2019 10:01:22 -0000 Author: kib Date: Mon Apr 22 10:01:20 2019 New Revision: 346537 URL: https://svnweb.freebsd.org/changeset/base/346537 Log: MFC r346225: Fix order of destructors between main binary and libraries. Modified: stable/12/lib/libc/stdlib/Symbol.map stable/12/lib/libc/stdlib/atexit.c stable/12/libexec/rtld-elf/rtld.c Directory Properties: stable/12/ (props changed) Modified: stable/12/lib/libc/stdlib/Symbol.map ============================================================================== --- stable/12/lib/libc/stdlib/Symbol.map Mon Apr 22 08:58:33 2019 (r346536) +++ stable/12/lib/libc/stdlib/Symbol.map Mon Apr 22 10:01:20 2019 (r346537) @@ -129,4 +129,5 @@ FBSDprivate_1.0 { _system; __libc_system; __cxa_thread_call_dtors; + __libc_atexit; }; Modified: stable/12/lib/libc/stdlib/atexit.c ============================================================================== --- stable/12/lib/libc/stdlib/atexit.c Mon Apr 22 08:58:33 2019 (r346536) +++ stable/12/lib/libc/stdlib/atexit.c Mon Apr 22 10:01:20 2019 (r346537) @@ -142,6 +142,7 @@ atexit(void (*func)(void)) error = atexit_register(&fn); return (error); } +__weak_reference(atexit, __libc_atexit); /** * Register a block to be performed at exit. Modified: stable/12/libexec/rtld-elf/rtld.c ============================================================================== --- stable/12/libexec/rtld-elf/rtld.c Mon Apr 22 08:58:33 2019 (r346536) +++ stable/12/libexec/rtld-elf/rtld.c Mon Apr 22 10:01:20 2019 (r346537) @@ -151,6 +151,7 @@ static int rtld_dirname(const char *, char *); static int rtld_dirname_abs(const char *, char *); static void *rtld_dlopen(const char *name, int fd, int mode); static void rtld_exit(void); +static void rtld_nop_exit(void); static char *search_library_path(const char *, const char *, const char *, int *); static char *search_library_pathfds(const char *, const char *, int *); @@ -295,6 +296,8 @@ const char *ld_path_rtld = _PATH_RTLD; const char *ld_standard_library_path = STANDARD_LIBRARY_PATH; const char *ld_env_prefix = LD_; +static void (*rtld_exit_ptr)(void); + /* * Fill in a DoneList with an allocation large enough to hold all of * the currently-loaded objects. Keep this as a macro since it calls @@ -756,6 +759,7 @@ _rtld(Elf_Addr *sp, func_ptr_type *exit_proc, Obj_Entr *ld_bind_now != '\0', SYMLOOK_EARLY, &lockstate) == -1) rtld_die(); + rtld_exit_ptr = rtld_exit; if (obj_main->crt_no_init) preinit_main(); objlist_call_init(&initlist, &lockstate); @@ -778,7 +782,7 @@ _rtld(Elf_Addr *sp, func_ptr_type *exit_proc, Obj_Entr dbg("transferring control to program entry point = %p", obj_main->entry); /* Return the exit procedure and the program entry point. */ - *exit_proc = rtld_exit; + *exit_proc = rtld_exit_ptr; *objp = obj_main; return (func_ptr_type) obj_main->entry; } @@ -2657,6 +2661,7 @@ objlist_call_init(Objlist *list, RtldLockState *lockst Obj_Entry *obj; char *saved_msg; Elf_Addr *init_addr; + void (*reg)(void (*)(void)); int index; /* @@ -2685,7 +2690,16 @@ objlist_call_init(Objlist *list, RtldLockState *lockst */ elm->obj->init_done = true; hold_object(elm->obj); + reg = NULL; + if (elm->obj == obj_main && obj_main->crt_no_init) { + reg = (void (*)(void (*)(void)))get_program_var_addr( + "__libc_atexit", lockstate); + } lock_release(rtld_bind_lock, lockstate); + if (reg != NULL) { + reg(rtld_exit); + rtld_exit_ptr = rtld_nop_exit; + } /* * It is legal to have both DT_INIT and DT_INIT_ARRAY defined. @@ -2997,6 +3011,11 @@ rtld_exit(void) if (!libmap_disable) lm_fini(); lock_release(rtld_bind_lock, &lockstate); +} + +static void +rtld_nop_exit(void) +{ } /* From owner-svn-src-stable-12@freebsd.org Mon Apr 22 11:13:55 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 258951596D61; Mon, 22 Apr 2019 11:13:55 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id B8A5C85C54; Mon, 22 Apr 2019 11:13:54 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 915D5C216; Mon, 22 Apr 2019 11:13:54 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3MBDscG033259; Mon, 22 Apr 2019 11:13:54 GMT (envelope-from markj@FreeBSD.org) Received: (from markj@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3MBDseR033257; Mon, 22 Apr 2019 11:13:54 GMT (envelope-from markj@FreeBSD.org) Message-Id: <201904221113.x3MBDseR033257@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: markj set sender to markj@FreeBSD.org using -f From: Mark Johnston Date: Mon, 22 Apr 2019 11:13:54 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346540 - in stable/12: sys/kern tests/sys/kern X-SVN-Group: stable-12 X-SVN-Commit-Author: markj X-SVN-Commit-Paths: in stable/12: sys/kern tests/sys/kern X-SVN-Commit-Revision: 346540 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: B8A5C85C54 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.98 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.98)[-0.977,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Apr 2019 11:13:55 -0000 Author: markj Date: Mon Apr 22 11:13:53 2019 New Revision: 346540 URL: https://svnweb.freebsd.org/changeset/base/346540 Log: MFC r346009: Set the p_oppid field of orphans when exiting. Modified: stable/12/sys/kern/kern_exit.c stable/12/tests/sys/kern/ptrace_test.c Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/kern/kern_exit.c ============================================================================== --- stable/12/sys/kern/kern_exit.c Mon Apr 22 11:09:24 2019 (r346539) +++ stable/12/sys/kern/kern_exit.c Mon Apr 22 11:13:53 2019 (r346540) @@ -521,6 +521,11 @@ exit1(struct thread *td, int rval, int signo) */ while ((q = LIST_FIRST(&p->p_orphans)) != NULL) { PROC_LOCK(q); + KASSERT(q->p_oppid == p->p_pid, + ("orphan %p of %p has unexpected oppid %d", q, p, + q->p_oppid)); + q->p_oppid = q->p_reaper->p_pid; + /* * If we are the real parent of this process * but it has been reparented to a debugger, then Modified: stable/12/tests/sys/kern/ptrace_test.c ============================================================================== --- stable/12/tests/sys/kern/ptrace_test.c Mon Apr 22 11:09:24 2019 (r346539) +++ stable/12/tests/sys/kern/ptrace_test.c Mon Apr 22 11:13:53 2019 (r346540) @@ -453,6 +453,67 @@ ATF_TC_BODY(ptrace__parent_sees_exit_after_unrelated_d } /* + * Make sure that we can collect the exit status of an orphaned process. + */ +ATF_TC_WITHOUT_HEAD(ptrace__parent_exits_before_child); +ATF_TC_BODY(ptrace__parent_exits_before_child, tc) +{ + ssize_t n; + int cpipe1[2], cpipe2[2], gcpipe[2], status; + pid_t child, gchild; + + ATF_REQUIRE(pipe(cpipe1) == 0); + ATF_REQUIRE(pipe(cpipe2) == 0); + ATF_REQUIRE(pipe(gcpipe) == 0); + + ATF_REQUIRE(procctl(P_PID, getpid(), PROC_REAP_ACQUIRE, NULL) == 0); + + ATF_REQUIRE((child = fork()) != -1); + if (child == 0) { + CHILD_REQUIRE((gchild = fork()) != -1); + if (gchild == 0) { + status = 1; + do { + n = read(gcpipe[0], &status, sizeof(status)); + } while (n == -1 && errno == EINTR); + _exit(status); + } + + CHILD_REQUIRE(write(cpipe1[1], &gchild, sizeof(gchild)) == + sizeof(gchild)); + CHILD_REQUIRE(read(cpipe2[0], &status, sizeof(status)) == + sizeof(status)); + _exit(status); + } + + ATF_REQUIRE(read(cpipe1[0], &gchild, sizeof(gchild)) == sizeof(gchild)); + + ATF_REQUIRE(ptrace(PT_ATTACH, gchild, NULL, 0) == 0); + + status = 0; + ATF_REQUIRE(write(cpipe2[1], &status, sizeof(status)) == + sizeof(status)); + ATF_REQUIRE(waitpid(child, &status, 0) == child); + ATF_REQUIRE(WIFEXITED(status) && WEXITSTATUS(status) == 0); + + status = 0; + ATF_REQUIRE(write(gcpipe[1], &status, sizeof(status)) == + sizeof(status)); + ATF_REQUIRE(waitpid(gchild, &status, 0) == gchild); + ATF_REQUIRE(WIFSTOPPED(status)); + ATF_REQUIRE(ptrace(PT_DETACH, gchild, (caddr_t)1, 0) == 0); + ATF_REQUIRE(waitpid(gchild, &status, 0) == gchild); + ATF_REQUIRE(WIFEXITED(status) && WEXITSTATUS(status) == 0); + + ATF_REQUIRE(close(cpipe1[0]) == 0); + ATF_REQUIRE(close(cpipe1[1]) == 0); + ATF_REQUIRE(close(cpipe2[0]) == 0); + ATF_REQUIRE(close(cpipe2[1]) == 0); + ATF_REQUIRE(close(gcpipe[0]) == 0); + ATF_REQUIRE(close(gcpipe[1]) == 0); +} + +/* * The parent process should always act the same regardless of how the * debugger is attached to it. */ @@ -3851,6 +3912,7 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, ptrace__parent_wait_after_attach); ATF_TP_ADD_TC(tp, ptrace__parent_sees_exit_after_child_debugger); ATF_TP_ADD_TC(tp, ptrace__parent_sees_exit_after_unrelated_debugger); + ATF_TP_ADD_TC(tp, ptrace__parent_exits_before_child); ATF_TP_ADD_TC(tp, ptrace__follow_fork_both_attached); ATF_TP_ADD_TC(tp, ptrace__follow_fork_child_detached); ATF_TP_ADD_TC(tp, ptrace__follow_fork_parent_detached); From owner-svn-src-stable-12@freebsd.org Mon Apr 22 14:56:30 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id D299F159C2C1; Mon, 22 Apr 2019 14:56:29 +0000 (UTC) (envelope-from gjb@freebsd.org) Received: from freefall.freebsd.org (freefall.freebsd.org [96.47.72.132]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "freefall.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 777098EA05; Mon, 22 Apr 2019 14:56:29 +0000 (UTC) (envelope-from gjb@freebsd.org) Received: from FreeBSD.org (freefall.freebsd.org [IPv6:2610:1c1:1:6074::16:84]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by freefall.freebsd.org (Postfix) with ESMTPS id CE520101AE; Mon, 22 Apr 2019 14:56:28 +0000 (UTC) (envelope-from gjb@freebsd.org) Date: Mon, 22 Apr 2019 14:56:25 +0000 From: Glen Barber To: Colin Percival Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org, portmgr@freebsd.org Subject: Re: svn commit: r340905 - in stable/12: release/pkg_repos usr.sbin/pkg Message-ID: <20190422145625.GA2572@FreeBSD.org> References: <201811241747.wAOHlr6W029937@repo.freebsd.org> <0100016a32795508-fd8bbc41-2b38-40ae-903a-e3ef3739dfd8-000000@email.amazonses.com> <20190419130522.GI39941@FreeBSD.org> <0100016a3bf3402e-9d865a0a-5c6e-43fc-b590-f6b7171b9d35-000000@email.amazonses.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="PNTmBPCT7hxwcZjr" Content-Disposition: inline In-Reply-To: <0100016a3bf3402e-9d865a0a-5c6e-43fc-b590-f6b7171b9d35-000000@email.amazonses.com> User-Agent: Mutt/1.11.2 (2019-01-07) X-Rspamd-Queue-Id: 777098EA05 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.99 / 15.00]; local_wl_from(0.00)[freebsd.org]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.99)[-0.986,0]; ASN(0.00)[asn:11403, ipnet:96.47.64.0/20, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Apr 2019 14:56:30 -0000 --PNTmBPCT7hxwcZjr Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Apr 20, 2019 at 06:12:38PM +0000, Colin Percival wrote: > On 4/19/19 6:05 AM, Glen Barber wrote: > > On Thu, Apr 18, 2019 at 10:02:53PM +0000, Colin Percival wrote: > >> On 11/24/18 9:47 AM, Glen Barber wrote: > >>> Log: > >>> Revert r340161 in stable/12, setting the default pkg(8) repository = back > >>> to 'latest' from 'quarterly' prior to branching releng/12.0. > >> It looks like this is incorrect for non-x86 architectures. Portmgr may > >> correct me here, but it looks like "latest" builds are only done on no= n-x86 > >> architectures on HEAD. (The same problem also applies on stable/11.) > >> > >> I'm guessing that the answer here is to have different package configu= rations > >> installed depending on the architecture; I knew how to do this with th= e old > >> style of src/etc but I'm not sure how to do it now that pkgbase has sp= read > >> configuration files all over the tree. > >=20 > > For 13.0-CURRENT, both latest and quarterly are updated. For non-x86 on > > 12.0-STABLE and 11.2-STABLE, quarterly is updated (not latest), so from > > a general sense of this particular commit, it is correct. > >=20 > > But you are also correct in your assertion that the current default > > (latest) for non-x86 does appear to be incorrect. > I think this patch does what we need in stable/12 -- installing a differe= nt > FreeBSD.conf file depending on whether TARGET_ARCH is amd64/i386. I'm not > sure if we should have anything similar in HEAD since we want to use "lat= est" > packages on all architectures there; we might want to have both configura= tion > files in HEAD but always install the same one there. >=20 > Let me know what you'd like done; this is the last issue (aside from MFCs) > blocking ARM64 AMIs from working on stable/12. >=20 > --=20 > Colin Percival > Security Officer Emeritus, FreeBSD | The power to serve > Founder, Tarsnap | www.tarsnap.com | Online backups for the truly paranoid > Index: usr.sbin/pkg/FreeBSD.conf > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- usr.sbin/pkg/FreeBSD.conf (revision 346346) > +++ usr.sbin/pkg/FreeBSD.conf (nonexistent) > @@ -1,16 +0,0 @@ > -# $FreeBSD$ > -# > -# To disable this repository, instead of modifying or removing this file, > -# create a /usr/local/etc/pkg/repos/FreeBSD.conf file: > -# > -# mkdir -p /usr/local/etc/pkg/repos > -# echo "FreeBSD: { enabled: no }" > /usr/local/etc/pkg/repos/FreeBSD.c= onf > -# > - > -FreeBSD: { > - url: "pkg+http://pkg.FreeBSD.org/${ABI}/latest", > - mirror_type: "srv", > - signature_type: "fingerprints", > - fingerprints: "/usr/share/keys/pkg", > - enabled: yes > -} >=20 > Property changes on: usr.sbin/pkg/FreeBSD.conf > ___________________________________________________________________ > Deleted: svn:keywords > ## -1 +0,0 ## > -FreeBSD=3D%H > \ No newline at end of property > Index: usr.sbin/pkg/FreeBSD.conf.latest > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- usr.sbin/pkg/FreeBSD.conf.latest (nonexistent) > +++ usr.sbin/pkg/FreeBSD.conf.latest (working copy) > @@ -0,0 +1,16 @@ > +# $FreeBSD: stable/12/usr.sbin/pkg/FreeBSD.conf 340905 2018-11-24 17:47:= 53Z gjb $ > +# > +# To disable this repository, instead of modifying or removing this file, > +# create a /usr/local/etc/pkg/repos/FreeBSD.conf file: > +# > +# mkdir -p /usr/local/etc/pkg/repos > +# echo "FreeBSD: { enabled: no }" > /usr/local/etc/pkg/repos/FreeBSD.c= onf > +# > + > +FreeBSD: { > + url: "pkg+http://pkg.FreeBSD.org/${ABI}/latest", > + mirror_type: "srv", > + signature_type: "fingerprints", > + fingerprints: "/usr/share/keys/pkg", > + enabled: yes > +} > Index: usr.sbin/pkg/FreeBSD.conf.quarterly > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- usr.sbin/pkg/FreeBSD.conf.quarterly (nonexistent) > +++ usr.sbin/pkg/FreeBSD.conf.quarterly (working copy) > @@ -0,0 +1,16 @@ > +# $FreeBSD: stable/12/usr.sbin/pkg/FreeBSD.conf 340905 2018-11-24 17:47:= 53Z gjb $ > +# > +# To disable this repository, instead of modifying or removing this file, > +# create a /usr/local/etc/pkg/repos/FreeBSD.conf file: > +# > +# mkdir -p /usr/local/etc/pkg/repos > +# echo "FreeBSD: { enabled: no }" > /usr/local/etc/pkg/repos/FreeBSD.c= onf > +# > + > +FreeBSD: { > + url: "pkg+http://pkg.FreeBSD.org/${ABI}/quarterly", > + mirror_type: "srv", > + signature_type: "fingerprints", > + fingerprints: "/usr/share/keys/pkg", > + enabled: yes > +} > Index: usr.sbin/pkg/Makefile > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- usr.sbin/pkg/Makefile (revision 346346) > +++ usr.sbin/pkg/Makefile (working copy) > @@ -1,6 +1,12 @@ > # $FreeBSD$ > =20 > -CONFS=3D FreeBSD.conf > +.if ${TARGET_ARCH} !=3D "amd64" && ${TARGET_ARCH} !=3D "i386" > +CONFS=3D FreeBSD.conf.quarterly > +.else > +CONFS=3D FreeBSD.conf.latest > +.endif > +CONFSNAME=3D FreeBSD.conf > + > CONFSDIR=3D /etc/pkg > CONFSMODE=3D 644 > PROG=3D pkg This looks somewhat similar to what I was thinking, but I'd like to think about this a bit more. What I was thinking was installing FreeBSD.conf for amd64 and i386 (which get switched to 'quarterly' during a release cycle), and creating creating an arch-specific FreeBSD.conf-${TARGET_ARCH} that defaults to 'quarterly' for the other architectures. Your way lessens the number of configuration files in-tree, while what I was thinking would lessen the number of files to touch when switching the default during the cycle, so I'm conflicted at the moment on which method I (personally) prefer. Glen --PNTmBPCT7hxwcZjr Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEjRJAPC5sqwhs9k2jAxRYpUeP4pMFAly91hkACgkQAxRYpUeP 4pMxAw//Sa9TpYGYoGkru7p95GuTiRXfoNRiGoDHzygUsVFsWYIgfC9q9tKBcm7V rwNdwCg4GVeD6sjqBR0QxdZK63pTjXjBp632NS5U1rfz7JHE5Ts7Tkx/WdVhEDuu wyuztWj1qc7yZTYbUxXjeZ2mc2D5Gk4y71cJzd0ZYVnLe19NHIm1HtHgvtyILnEe vKgvhxBUW1Ssvz5JGrLh5mFnMOaCQfPYrZaNbkB+yaBfMJyx0AG18m5j4Br86sbd aP4Fah36M5e4oY9lcLBqy6fcPDMFFpTqe38ZPM2EBIc+Een7f8RWf6J0S4Aa/N8f 3sMN1YVIairYdY05mlU2lCi3H9a+oHC7wWqSdOTWxJ3w/OUDAYQKVVe/iB4PHxoY WUN4iTxX4ap6QsT4kjsCSs6lQgwAsy5f25YqPgHTk6L/MiM3gCQqed2T6gEVTcf8 5/GPcSEGtVzxTZtrd4zcyq33Wni2ROSvJDcAGfKR4YrVWiyOLlXAtsa/F6Chrold HeaN0SBf8j3bzz1U8jwJuBEOAhe26VW12PeY4KUBVIYE0YZIEut4lk/ZJwr8qC8y l2BApjKsMKHTE/439AJLt3nMfgDVwFN0KJTcAYWFUfU0tdk4MmDl7CP73+JiCS3C Sn4gh4RUzg05spn7Ab7nxTJLVVe0sBujWncE0uXuvcaYWeA7fCI= =O3cI -----END PGP SIGNATURE----- --PNTmBPCT7hxwcZjr-- From owner-svn-src-stable-12@freebsd.org Tue Apr 23 02:29:09 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id B3FA6158A6C2; Tue, 23 Apr 2019 02:29:09 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 5657A8993A; Tue, 23 Apr 2019 02:29:09 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 3132B1DF84; Tue, 23 Apr 2019 02:29:09 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3N2T95D025992; Tue, 23 Apr 2019 02:29:09 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3N2T8bg025990; Tue, 23 Apr 2019 02:29:08 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201904230229.x3N2T8bg025990@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Tue, 23 Apr 2019 02:29:08 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346586 - in stable: 11/usr.sbin/cron/cron 11/usr.sbin/cron/crontab 12/usr.sbin/cron/cron 12/usr.sbin/cron/crontab X-SVN-Group: stable-12 X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: in stable: 11/usr.sbin/cron/cron 11/usr.sbin/cron/crontab 12/usr.sbin/cron/cron 12/usr.sbin/cron/crontab X-SVN-Commit-Revision: 346586 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 5657A8993A X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.96 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.96)[-0.964,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 Apr 2019 02:29:10 -0000 Author: kevans Date: Tue Apr 23 02:29:08 2019 New Revision: 346586 URL: https://svnweb.freebsd.org/changeset/base/346586 Log: MFC r346427: cron(8): schedule interval jobs that loaded during execution Jobs using the @ syntax currently only get executed if they exist when cron is started. The simplest reproducer of this is: echo '@20 root echo "Hello!"' >> /etc/cron.d/myjob myjob will get loaded at the next second==0, but this echo job will not run until cron restarts. These jobs are normally handled in run_reboot_jobs(), which sets e->lastexit of INTERVAL jobs to the startup time so they run 'n' seconds later. Fix this by special-casing TargetTime > 0 in the database load. Preexisting jobs will be handled at startup during run_reboot_jobs as normal, but if we've reloaded a database during runtime we'll hit this case and set e->lastexit to the current time when we process it. They will then run every 'n' seconds from that point, and a full restart of cron is no longer required to make these jobs work. Modified: stable/12/usr.sbin/cron/cron/database.c stable/12/usr.sbin/cron/crontab/crontab.5 Directory Properties: stable/12/ (props changed) Changes in other areas also in this revision: Modified: stable/11/usr.sbin/cron/cron/database.c stable/11/usr.sbin/cron/crontab/crontab.5 Directory Properties: stable/11/ (props changed) Modified: stable/12/usr.sbin/cron/cron/database.c ============================================================================== --- stable/12/usr.sbin/cron/cron/database.c Mon Apr 22 21:28:43 2019 (r346585) +++ stable/12/usr.sbin/cron/cron/database.c Tue Apr 23 02:29:08 2019 (r346586) @@ -259,6 +259,8 @@ process_crontab(uname, fname, tabname, statbuf, new_db struct passwd *pw = NULL; int crontab_fd = OK - 1; user *u; + entry *e; + time_t now; if (strcmp(fname, SYS_NAME) && !(pw = getpwnam(uname))) { /* file doesn't have a user in passwd file. @@ -307,6 +309,21 @@ process_crontab(uname, fname, tabname, statbuf, new_db u = load_user(crontab_fd, pw, fname); if (u != NULL) { u->mtime = statbuf->st_mtime; + /* + * TargetTime == 0 when we're initially populating the database, + * and TargetTime > 0 any time after that (i.e. we're reloading + * cron.d/ files because they've been created/modified). In the + * latter case, we should check for any interval jobs and run + * them 'n' seconds from the time the job was loaded/reloaded. + * Otherwise, they will not be run until cron is restarted. + */ + if (TargetTime != 0) { + now = time(NULL); + for (e = u->crontab; e != NULL; e = e->next) { + if ((e->flags & INTERVAL) != 0) + e->lastexit = now; + } + } link_user(new_db, u); } Modified: stable/12/usr.sbin/cron/crontab/crontab.5 ============================================================================== --- stable/12/usr.sbin/cron/crontab/crontab.5 Mon Apr 22 21:28:43 2019 (r346585) +++ stable/12/usr.sbin/cron/crontab/crontab.5 Tue Apr 23 02:29:08 2019 (r346586) @@ -17,7 +17,7 @@ .\" .\" $FreeBSD$ .\" -.Dd April 15, 2019 +.Dd April 19, 2019 .Dt CRONTAB 5 .Os .Sh NAME @@ -245,12 +245,14 @@ string meaning The .Sq @ symbol followed by a numeric value has a special notion of running -a job that much seconds after completion of previous invocation of +a job that many seconds after completion of the previous invocation of the job. Unlike regular syntax, it guarantees not to overlap two or more -invocations of the same job. -The first run is scheduled specified amount of seconds after cron -has started. +invocations of the same job during normal cron execution. +Note, however, that overlap may occur if the job is running when the file +containing the job is modified and subsequently reloaded. +The first run is scheduled for the specified number of seconds after cron +is started or the crontab entry is reloaded. .Sh EXAMPLE CRON FILE .Bd -literal From owner-svn-src-stable-12@freebsd.org Tue Apr 23 02:37:13 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 51B1E158A9C7; Tue, 23 Apr 2019 02:37:13 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id E80AA89E85; Tue, 23 Apr 2019 02:37:12 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id BA6431E13E; Tue, 23 Apr 2019 02:37:12 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3N2bCOb031135; Tue, 23 Apr 2019 02:37:12 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3N2bCHd031134; Tue, 23 Apr 2019 02:37:12 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201904230237.x3N2bCHd031134@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Tue, 23 Apr 2019 02:37:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346587 - in stable: 11/usr.sbin/config 12/usr.sbin/config X-SVN-Group: stable-12 X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: in stable: 11/usr.sbin/config 12/usr.sbin/config X-SVN-Commit-Revision: 346587 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: E80AA89E85 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.96 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.96)[-0.962,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 Apr 2019 02:37:13 -0000 Author: kevans Date: Tue Apr 23 02:37:12 2019 New Revision: 346587 URL: https://svnweb.freebsd.org/changeset/base/346587 Log: MFC r346254: config(8): replace opteq with a call to strcasecmp This obscures the comparison slightly less; when option name appear in files, they are case-insensitive. Modified: stable/12/usr.sbin/config/mkmakefile.c Directory Properties: stable/12/ (props changed) Changes in other areas also in this revision: Modified: stable/11/usr.sbin/config/mkmakefile.c Directory Properties: stable/11/ (props changed) Modified: stable/12/usr.sbin/config/mkmakefile.c ============================================================================== --- stable/12/usr.sbin/config/mkmakefile.c Tue Apr 23 02:29:08 2019 (r346586) +++ stable/12/usr.sbin/config/mkmakefile.c Tue Apr 23 02:37:12 2019 (r346587) @@ -62,7 +62,6 @@ static void do_rules(FILE *); static void do_xxfiles(char *, FILE *); static void do_objs(FILE *); static void do_before_depend(FILE *); -static int opteq(const char *, const char *); static void read_files(void); static void sanitize_envline(char *result, const char *src); static bool preprocess(char *line, char *result); @@ -565,7 +564,8 @@ next: goto nextparam; } SLIST_FOREACH(op, &opt, op_next) - if (op->op_value == 0 && opteq(op->op_name, wd)) { + if (op->op_value == 0 && + strcasecmp(op->op_name, wd) == 0) { if (not) match = 0; goto nextparam; @@ -625,23 +625,6 @@ read_files(void) tnl = STAILQ_NEXT(nl, f_next); free(nl->f_name); free(nl); - } -} - -static int -opteq(const char *cp, const char *dp) -{ - char c, d; - - for (; ; cp++, dp++) { - if (*cp != *dp) { - c = isupper(*cp) ? tolower(*cp) : *cp; - d = isupper(*dp) ? tolower(*dp) : *dp; - if (c != d) - return (0); - } - if (*cp == 0) - return (1); } } From owner-svn-src-stable-12@freebsd.org Tue Apr 23 12:29:21 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id DAF10159947C; Tue, 23 Apr 2019 12:29:20 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 72BEE6FD76; Tue, 23 Apr 2019 12:29:20 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 467D52474A; Tue, 23 Apr 2019 12:29:20 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3NCTK3w045353; Tue, 23 Apr 2019 12:29:20 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3NCTJ31045352; Tue, 23 Apr 2019 12:29:19 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201904231229.x3NCTJ31045352@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Tue, 23 Apr 2019 12:29:19 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346597 - in stable/12/sys: amd64/amd64 i386/i386 X-SVN-Group: stable-12 X-SVN-Commit-Author: kib X-SVN-Commit-Paths: in stable/12/sys: amd64/amd64 i386/i386 X-SVN-Commit-Revision: 346597 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 72BEE6FD76 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.97 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.97)[-0.972,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 Apr 2019 12:29:21 -0000 Author: kib Date: Tue Apr 23 12:29:19 2019 New Revision: 346597 URL: https://svnweb.freebsd.org/changeset/base/346597 Log: MFC r345562 (by cem), r346294: x86: Use XSAVEOPT for fpusave(), when available. Modified: stable/12/sys/amd64/amd64/fpu.c stable/12/sys/i386/i386/npx.c Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/amd64/amd64/fpu.c ============================================================================== --- stable/12/sys/amd64/amd64/fpu.c Tue Apr 23 12:23:44 2019 (r346596) +++ stable/12/sys/amd64/amd64/fpu.c Tue Apr 23 12:29:19 2019 (r346597) @@ -100,6 +100,17 @@ xsave(char *addr, uint64_t mask) "memory"); } +static __inline void +xsaveopt(char *addr, uint64_t mask) +{ + uint32_t low, hi; + + low = mask; + hi = mask >> 32; + __asm __volatile("xsaveopt %0" : "=m" (*addr) : "a" (low), "d" (hi) : + "memory"); +} + #else /* !(__GNUCLIKE_ASM && !lint) */ void fldcw(u_short cw); @@ -113,6 +124,7 @@ void ldmxcsr(u_int csr); void stmxcsr(u_int *csr); void xrstor(char *addr, uint64_t mask); void xsave(char *addr, uint64_t mask); +void xsaveopt(char *addr, uint64_t mask); #endif /* __GNUCLIKE_ASM && !lint */ @@ -158,6 +170,13 @@ struct xsave_area_elm_descr { } *xsave_area_desc; static void +fpusave_xsaveopt(void *addr) +{ + + xsaveopt((char *)addr, xsave_mask); +} + +static void fpusave_xsave(void *addr) { @@ -201,7 +220,10 @@ DEFINE_IFUNC(, void, fpusave, (void *), static) { init_xsave(); - return (use_xsave ? fpusave_xsave : fpusave_fxsave); + if (use_xsave) + return ((cpu_stdext_feature & CPUID_EXTSTATE_XSAVEOPT) != 0 ? + fpusave_xsaveopt : fpusave_xsave); + return (fpusave_fxsave); } DEFINE_IFUNC(, void, fpurestore, (void *), static) @@ -348,6 +370,7 @@ fpuinit(void) static void fpuinitstate(void *arg __unused) { + uint64_t *xstate_bv; register_t saveintr; int cp[4], i, max_ext_n; @@ -356,7 +379,7 @@ fpuinitstate(void *arg __unused) saveintr = intr_disable(); stop_emulating(); - fpusave(fpu_initialstate); + fpusave_fxsave(fpu_initialstate); if (fpu_initialstate->sv_env.en_mxcsr_mask) cpu_mxcsr_mask = fpu_initialstate->sv_env.en_mxcsr_mask; else @@ -378,6 +401,10 @@ fpuinitstate(void *arg __unused) * Save Area. */ if (use_xsave) { + xstate_bv = (uint64_t *)((char *)(fpu_initialstate + 1) + + offsetof(struct xstate_hdr, xstate_bv)); + *xstate_bv = XFEATURE_ENABLED_X87 | XFEATURE_ENABLED_SSE; + max_ext_n = flsl(xsave_mask); xsave_area_desc = malloc(max_ext_n * sizeof(struct xsave_area_elm_descr), M_DEVBUF, M_WAITOK | M_ZERO); Modified: stable/12/sys/i386/i386/npx.c ============================================================================== --- stable/12/sys/i386/i386/npx.c Tue Apr 23 12:23:44 2019 (r346596) +++ stable/12/sys/i386/i386/npx.c Tue Apr 23 12:29:19 2019 (r346597) @@ -313,7 +313,7 @@ cleanup: } static void -npxsave_xsaveopt(union savefpu *addr) +fpusave_xsaveopt(union savefpu *addr) { xsaveopt((char *)addr, xsave_mask); @@ -352,29 +352,18 @@ init_xsave(void) TUNABLE_INT_FETCH("hw.use_xsave", &use_xsave); } -DEFINE_IFUNC(, void, npxsave_core, (union savefpu *), static) +DEFINE_IFUNC(, void, fpusave, (union savefpu *), static) { init_xsave(); if (use_xsave) return ((cpu_stdext_feature & CPUID_EXTSTATE_XSAVEOPT) != 0 ? - npxsave_xsaveopt : fpusave_xsave); + fpusave_xsaveopt : fpusave_xsave); if (cpu_fxsr) return (fpusave_fxsave); return (fpusave_fnsave); } -DEFINE_IFUNC(, void, fpusave, (union savefpu *), static) -{ - - init_xsave(); - if (use_xsave) - return (fpusave_xsave); - if (cpu_fxsr) - return (fpusave_fxsave); - return (fpusave_fnsave); -} - /* * Enable XSAVE if supported and allowed by user. * Calculate the xsave_mask. @@ -483,6 +472,7 @@ npxinit(bool bsp) static void npxinitstate(void *arg __unused) { + uint64_t *xstate_bv; register_t saveintr; int cp[4], i, max_ext_n; @@ -494,7 +484,10 @@ npxinitstate(void *arg __unused) saveintr = intr_disable(); stop_emulating(); - fpusave(npx_initialstate); + if (cpu_fxsr) + fpusave_fxsave(npx_initialstate); + else + fpusave_fnsave(npx_initialstate); if (cpu_fxsr) { if (npx_initialstate->sv_xmm.sv_env.en_mxcsr_mask) cpu_mxcsr_mask = @@ -515,6 +508,7 @@ npxinitstate(void *arg __unused) sizeof(npx_initialstate->sv_xmm.sv_fp)); bzero(npx_initialstate->sv_xmm.sv_xmm, sizeof(npx_initialstate->sv_xmm.sv_xmm)); + } else bzero(npx_initialstate->sv_87.sv_ac, sizeof(npx_initialstate->sv_87.sv_ac)); @@ -524,6 +518,10 @@ npxinitstate(void *arg __unused) * Save Area. */ if (use_xsave) { + xstate_bv = (uint64_t *)((char *)(npx_initialstate + 1) + + offsetof(struct xstate_hdr, xstate_bv)); + *xstate_bv = XFEATURE_ENABLED_X87 | XFEATURE_ENABLED_SSE; + if (xsave_mask >> 32 != 0) max_ext_n = fls(xsave_mask >> 32) + 32; else @@ -922,7 +920,7 @@ npxsave(union savefpu *addr) { stop_emulating(); - npxsave_core(addr); + fpusave(addr); } void npxswitch(struct thread *td, struct pcb *pcb); From owner-svn-src-stable-12@freebsd.org Wed Apr 24 06:41:53 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 8C41F158E7D9; Wed, 24 Apr 2019 06:41:53 +0000 (UTC) (envelope-from bcr@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 05737766B5; Wed, 24 Apr 2019 06:41:53 +0000 (UTC) (envelope-from bcr@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id D43E486ED; Wed, 24 Apr 2019 06:41:52 +0000 (UTC) (envelope-from bcr@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3O6fqWF026773; Wed, 24 Apr 2019 06:41:52 GMT (envelope-from bcr@FreeBSD.org) Received: (from bcr@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3O6fqVp026772; Wed, 24 Apr 2019 06:41:52 GMT (envelope-from bcr@FreeBSD.org) Message-Id: <201904240641.x3O6fqVp026772@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: bcr set sender to bcr@FreeBSD.org using -f From: Benedict Reuschling Date: Wed, 24 Apr 2019 06:41:52 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346629 - stable/12/sbin/ipfw X-SVN-Group: stable-12 X-SVN-Commit-Author: bcr X-SVN-Commit-Paths: stable/12/sbin/ipfw X-SVN-Commit-Revision: 346629 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 05737766B5 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.97 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.97)[-0.970,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Apr 2019 06:41:53 -0000 Author: bcr (doc committer) Date: Wed Apr 24 06:41:52 2019 New Revision: 346629 URL: https://svnweb.freebsd.org/changeset/base/346629 Log: MFC r346490: Typo fix in ipfw.8: amd -> and There is an (obvious) typo in the following sentence: "Please note, that keep-state amd limit imply implicit check-state for ..." Replace the "amd" with "and", bump .Dd. PR: 237438 Submitted by: michael@galassi.us Modified: stable/12/sbin/ipfw/ipfw.8 Directory Properties: stable/12/ (props changed) Modified: stable/12/sbin/ipfw/ipfw.8 ============================================================================== --- stable/12/sbin/ipfw/ipfw.8 Wed Apr 24 06:25:21 2019 (r346628) +++ stable/12/sbin/ipfw/ipfw.8 Wed Apr 24 06:41:52 2019 (r346629) @@ -1,7 +1,7 @@ .\" .\" $FreeBSD$ .\" -.Dd March 19, 2019 +.Dd April 21, 2019 .Dt IPFW 8 .Os .Sh NAME @@ -250,7 +250,7 @@ rule, and are typically used to open the firewall on-d legitimate traffic only. Please note, that .Cm keep-state -amd +and .Cm limit imply implicit .Cm check-state From owner-svn-src-stable-12@freebsd.org Wed Apr 24 14:08:15 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 601191599EA4; Wed, 24 Apr 2019 14:08:15 +0000 (UTC) (envelope-from kp@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 02B588E1FF; Wed, 24 Apr 2019 14:08:15 +0000 (UTC) (envelope-from kp@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id D0862D3ED; Wed, 24 Apr 2019 14:08:14 +0000 (UTC) (envelope-from kp@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3OE8EJp063973; Wed, 24 Apr 2019 14:08:14 GMT (envelope-from kp@FreeBSD.org) Received: (from kp@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3OE8ETW063972; Wed, 24 Apr 2019 14:08:14 GMT (envelope-from kp@FreeBSD.org) Message-Id: <201904241408.x3OE8ETW063972@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kp set sender to kp@FreeBSD.org using -f From: Kristof Provost Date: Wed, 24 Apr 2019 14:08:14 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346635 - stable/12/sys/netpfil/pf X-SVN-Group: stable-12 X-SVN-Commit-Author: kp X-SVN-Commit-Paths: stable/12/sys/netpfil/pf X-SVN-Commit-Revision: 346635 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 02B588E1FF X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.96 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_SHORT(-0.96)[-0.959,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Apr 2019 14:08:15 -0000 Author: kp Date: Wed Apr 24 14:08:14 2019 New Revision: 346635 URL: https://svnweb.freebsd.org/changeset/base/346635 Log: MFC r346319: pf: Fix panic on invalid DIOCRSETTFLAGS If during DIOCRSETTFLAGS pfrio_buffer is NULL copyin() will fault, which we're not allowed to do with a lock held. We must count the number of entries in the table and release the lock during copyin(). Only then can we re-acquire the lock. Note that this is safe, because pfr_set_tflags() will check if the table and entries exist. This was discovered by a local syzcaller instance. Modified: stable/12/sys/netpfil/pf/pf_ioctl.c Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/netpfil/pf/pf_ioctl.c ============================================================================== --- stable/12/sys/netpfil/pf/pf_ioctl.c Wed Apr 24 13:44:30 2019 (r346634) +++ stable/12/sys/netpfil/pf/pf_ioctl.c Wed Apr 24 14:08:14 2019 (r346635) @@ -3103,24 +3103,24 @@ DIOCCHANGEADDR_error: break; } - PF_RULES_WLOCK(); + PF_RULES_RLOCK(); n = pfr_table_count(&io->pfrio_table, io->pfrio_flags); io->pfrio_size = min(io->pfrio_size, n); + PF_RULES_RUNLOCK(); totlen = io->pfrio_size * sizeof(struct pfr_table); pfrts = mallocarray(io->pfrio_size, sizeof(struct pfr_table), M_TEMP, M_NOWAIT); if (pfrts == NULL) { error = ENOMEM; - PF_RULES_WUNLOCK(); break; } error = copyin(io->pfrio_buffer, pfrts, totlen); if (error) { free(pfrts, M_TEMP); - PF_RULES_WUNLOCK(); break; } + PF_RULES_WLOCK(); error = pfr_set_tflags(pfrts, io->pfrio_size, io->pfrio_setflag, io->pfrio_clrflag, &io->pfrio_nchange, &io->pfrio_ndel, io->pfrio_flags | PFR_FLAG_USERIOCTL); From owner-svn-src-stable-12@freebsd.org Wed Apr 24 15:03:01 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 02BD2159B208; Wed, 24 Apr 2019 15:03:01 +0000 (UTC) (envelope-from kp@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 9BD3369E1A; Wed, 24 Apr 2019 15:03:00 +0000 (UTC) (envelope-from kp@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 67965DE29; Wed, 24 Apr 2019 15:03:00 +0000 (UTC) (envelope-from kp@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3OF3034096940; Wed, 24 Apr 2019 15:03:00 GMT (envelope-from kp@FreeBSD.org) Received: (from kp@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3OF30MB096939; Wed, 24 Apr 2019 15:03:00 GMT (envelope-from kp@FreeBSD.org) Message-Id: <201904241503.x3OF30MB096939@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kp set sender to kp@FreeBSD.org using -f From: Kristof Provost Date: Wed, 24 Apr 2019 15:03:00 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346638 - stable/12/tests/sys/netpfil/pf/ioctl X-SVN-Group: stable-12 X-SVN-Commit-Author: kp X-SVN-Commit-Paths: stable/12/tests/sys/netpfil/pf/ioctl X-SVN-Commit-Revision: 346638 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 9BD3369E1A X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.97 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.97)[-0.971,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Apr 2019 15:03:01 -0000 Author: kp Date: Wed Apr 24 15:02:59 2019 New Revision: 346638 URL: https://svnweb.freebsd.org/changeset/base/346638 Log: MFC r346320: pf tests: Try to provoke the panic with invalid DIOCRSETTFLAGS There was an issue with copyin() on DIOCRSETTFLAGS, which would panic if pfrio_buffer was NULL. Test for the issue fixed in r346319. Modified: stable/12/tests/sys/netpfil/pf/ioctl/validation.c Directory Properties: stable/12/ (props changed) Modified: stable/12/tests/sys/netpfil/pf/ioctl/validation.c ============================================================================== --- stable/12/tests/sys/netpfil/pf/ioctl/validation.c Wed Apr 24 14:25:35 2019 (r346637) +++ stable/12/tests/sys/netpfil/pf/ioctl/validation.c Wed Apr 24 15:02:59 2019 (r346638) @@ -305,6 +305,11 @@ ATF_TC_BODY(settflags, tc) io.pfrio_size = 1 << 28; if (ioctl(dev, DIOCRSETTFLAGS, &io) != 0) atf_tc_fail("Request with size 1 << 24 failed"); + + /* NULL buffer */ + io.pfrio_buffer = NULL; + if (ioctl(dev, DIOCRSETTFLAGS, &io) != -1) + atf_tc_fail("Request with NULL buffer succeeded"); } ATF_TC_CLEANUP(settflags, tc) From owner-svn-src-stable-12@freebsd.org Thu Apr 25 03:46:55 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id BCD0C158AC73; Thu, 25 Apr 2019 03:46:55 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 6171D8E115; Thu, 25 Apr 2019 03:46:55 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 3B5221E13A; Thu, 25 Apr 2019 03:46:55 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3P3kt4I006552; Thu, 25 Apr 2019 03:46:55 GMT (envelope-from markj@FreeBSD.org) Received: (from markj@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3P3kswk006550; Thu, 25 Apr 2019 03:46:54 GMT (envelope-from markj@FreeBSD.org) Message-Id: <201904250346.x3P3kswk006550@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: markj set sender to markj@FreeBSD.org using -f From: Mark Johnston Date: Thu, 25 Apr 2019 03:46:54 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346658 - in stable/12/sys: netinet netinet6 X-SVN-Group: stable-12 X-SVN-Commit-Author: markj X-SVN-Commit-Paths: in stable/12/sys: netinet netinet6 X-SVN-Commit-Revision: 346658 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 6171D8E115 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.90 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.90)[-0.902,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Apr 2019 03:46:56 -0000 Author: markj Date: Thu Apr 25 03:46:54 2019 New Revision: 346658 URL: https://svnweb.freebsd.org/changeset/base/346658 Log: MFC r346118: Reinitialize multicast source filter structures after invalidation. Modified: stable/12/sys/netinet/in_mcast.c stable/12/sys/netinet6/in6_mcast.c Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/netinet/in_mcast.c ============================================================================== --- stable/12/sys/netinet/in_mcast.c Thu Apr 25 02:16:48 2019 (r346657) +++ stable/12/sys/netinet/in_mcast.c Thu Apr 25 03:46:54 2019 (r346658) @@ -2544,10 +2544,14 @@ out_in_multi_locked: if (is_final) { /* Remove the gap in the membership and filter array. */ + KASSERT(RB_EMPTY(&imf->imf_sources), + ("%s: imf_sources not empty", __func__)); for (++idx; idx < imo->imo_num_memberships; ++idx) { - imo->imo_membership[idx-1] = imo->imo_membership[idx]; - imo->imo_mfilters[idx-1] = imo->imo_mfilters[idx]; + imo->imo_membership[idx - 1] = imo->imo_membership[idx]; + imo->imo_mfilters[idx - 1] = imo->imo_mfilters[idx]; } + imf_init(&imo->imo_mfilters[idx - 1], MCAST_UNDEFINED, + MCAST_EXCLUDE); imo->imo_num_memberships--; } Modified: stable/12/sys/netinet6/in6_mcast.c ============================================================================== --- stable/12/sys/netinet6/in6_mcast.c Thu Apr 25 02:16:48 2019 (r346657) +++ stable/12/sys/netinet6/in6_mcast.c Thu Apr 25 03:46:54 2019 (r346658) @@ -2470,10 +2470,14 @@ in6p_leave_group(struct inpcb *inp, struct sockopt *so if (is_final) { /* Remove the gap in the membership array. */ + KASSERT(RB_EMPTY(&imf->im6f_sources), + ("%s: im6f_sources not empty", __func__)); for (++idx; idx < imo->im6o_num_memberships; ++idx) { - imo->im6o_membership[idx-1] = imo->im6o_membership[idx]; - imo->im6o_mfilters[idx-1] = imo->im6o_mfilters[idx]; + imo->im6o_membership[idx - 1] = imo->im6o_membership[idx]; + imo->im6o_mfilters[idx - 1] = imo->im6o_mfilters[idx]; } + im6f_init(&imo->im6o_mfilters[idx - 1], MCAST_UNDEFINED, + MCAST_EXCLUDE); imo->im6o_num_memberships--; } From owner-svn-src-stable-12@freebsd.org Thu Apr 25 03:48:38 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 6A3D3158ADFB; Thu, 25 Apr 2019 03:48:38 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 124228E512; Thu, 25 Apr 2019 03:48:38 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id A68991E13E; Thu, 25 Apr 2019 03:48:37 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3P3mbuK006713; Thu, 25 Apr 2019 03:48:37 GMT (envelope-from markj@FreeBSD.org) Received: (from markj@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3P3mbOe006712; Thu, 25 Apr 2019 03:48:37 GMT (envelope-from markj@FreeBSD.org) Message-Id: <201904250348.x3P3mbOe006712@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: markj set sender to markj@FreeBSD.org using -f From: Mark Johnston Date: Thu, 25 Apr 2019 03:48:37 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346660 - stable/12/sys/vm X-SVN-Group: stable-12 X-SVN-Commit-Author: markj X-SVN-Commit-Paths: stable/12/sys/vm X-SVN-Commit-Revision: 346660 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 124228E512 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.90 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.90)[-0.902,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Apr 2019 03:48:38 -0000 Author: markj Date: Thu Apr 25 03:48:37 2019 New Revision: 346660 URL: https://svnweb.freebsd.org/changeset/base/346660 Log: MFC r346543: Disable vm map consistency checking by default on INVARIANTS kernels. Modified: stable/12/sys/vm/vm_map.c Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/vm/vm_map.c ============================================================================== --- stable/12/sys/vm/vm_map.c Thu Apr 25 03:47:32 2019 (r346659) +++ stable/12/sys/vm/vm_map.c Thu Apr 25 03:48:37 2019 (r346660) @@ -670,6 +670,14 @@ _vm_map_assert_locked(vm_map_t map, const char *file, #define VM_MAP_ASSERT_LOCKED(map) \ _vm_map_assert_locked(map, LOCK_FILE, LOCK_LINE) +#ifdef DIAGNOSTIC +static int enable_vmmap_check = 1; +#else +static int enable_vmmap_check = 0; +#endif +SYSCTL_INT(_debug, OID_AUTO, vmmap_check, CTLFLAG_RWTUN, + &enable_vmmap_check, 0, "Enable vm map consistency checking"); + static void _vm_map_assert_consistent(vm_map_t map) { @@ -677,6 +685,9 @@ _vm_map_assert_consistent(vm_map_t map) vm_map_entry_t child; vm_size_t max_left, max_right; + if (!enable_vmmap_check) + return; + for (entry = map->header.next; entry != &map->header; entry = entry->next) { KASSERT(entry->prev->end <= entry->start, @@ -714,7 +725,7 @@ _vm_map_assert_consistent(vm_map_t map) #else #define VM_MAP_ASSERT_LOCKED(map) #define VM_MAP_ASSERT_CONSISTENT(map) -#endif +#endif /* INVARIANTS */ /* * _vm_map_unlock_and_wait: From owner-svn-src-stable-12@freebsd.org Thu Apr 25 08:25:49 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 752AF15901C5; Thu, 25 Apr 2019 08:25:49 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 1C7E270006; Thu, 25 Apr 2019 08:25:49 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id E5B07210F1; Thu, 25 Apr 2019 08:25:48 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3P8Pmsi056044; Thu, 25 Apr 2019 08:25:48 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3P8Pm5e056043; Thu, 25 Apr 2019 08:25:48 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201904250825.x3P8Pm5e056043@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Thu, 25 Apr 2019 08:25:48 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346661 - stable/12/sys/x86/iommu X-SVN-Group: stable-12 X-SVN-Commit-Author: kib X-SVN-Commit-Paths: stable/12/sys/x86/iommu X-SVN-Commit-Revision: 346661 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 1C7E270006 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.97 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.97)[-0.975,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Apr 2019 08:25:49 -0000 Author: kib Date: Thu Apr 25 08:25:48 2019 New Revision: 346661 URL: https://svnweb.freebsd.org/changeset/base/346661 Log: MFC r346350: Reduce verbosity, do not announce details of irte programming by default. Modified: stable/12/sys/x86/iommu/intel_intrmap.c Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/x86/iommu/intel_intrmap.c ============================================================================== --- stable/12/sys/x86/iommu/intel_intrmap.c Thu Apr 25 03:48:37 2019 (r346660) +++ stable/12/sys/x86/iommu/intel_intrmap.c Thu Apr 25 08:25:48 2019 (r346661) @@ -270,9 +270,11 @@ dmar_ir_program_irte(struct dmar_unit *unit, u_int idx irte = &(unit->irt[idx]); high = DMAR_IRTE2_SVT_RID | DMAR_IRTE2_SQ_RID | DMAR_IRTE2_SID_RID(rid); - device_printf(unit->dev, - "programming irte[%d] rid %#x high %#jx low %#jx\n", - idx, rid, (uintmax_t)high, (uintmax_t)low); + if (bootverbose) { + device_printf(unit->dev, + "programming irte[%d] rid %#x high %#jx low %#jx\n", + idx, rid, (uintmax_t)high, (uintmax_t)low); + } DMAR_LOCK(unit); if ((irte->irte1 & DMAR_IRTE1_P) != 0) { /* From owner-svn-src-stable-12@freebsd.org Thu Apr 25 08:27:02 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 01BFC159023D; Thu, 25 Apr 2019 08:27:02 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 986A67013D; Thu, 25 Apr 2019 08:27:01 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 93498210F2; Thu, 25 Apr 2019 08:27:00 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3P8R0V6056157; Thu, 25 Apr 2019 08:27:00 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3P8R0oT056156; Thu, 25 Apr 2019 08:27:00 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201904250827.x3P8R0oT056156@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Thu, 25 Apr 2019 08:27:00 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346662 - stable/12/sys/x86/iommu X-SVN-Group: stable-12 X-SVN-Commit-Author: kib X-SVN-Commit-Paths: stable/12/sys/x86/iommu X-SVN-Commit-Revision: 346662 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 986A67013D X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.97 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.97)[-0.975,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Apr 2019 08:27:02 -0000 Author: kib Date: Thu Apr 25 08:27:00 2019 New Revision: 346662 URL: https://svnweb.freebsd.org/changeset/base/346662 Log: MFC r346351: Remove witness warning. dmar_bus_dmamap_create() does not sleep. Modified: stable/12/sys/x86/iommu/busdma_dmar.c Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/x86/iommu/busdma_dmar.c ============================================================================== --- stable/12/sys/x86/iommu/busdma_dmar.c Thu Apr 25 08:25:48 2019 (r346661) +++ stable/12/sys/x86/iommu/busdma_dmar.c Thu Apr 25 08:27:00 2019 (r346662) @@ -371,8 +371,6 @@ dmar_bus_dmamap_create(bus_dma_tag_t dmat, int flags, struct bus_dma_tag_dmar *tag; struct bus_dmamap_dmar *map; - WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL, "%s", __func__); - tag = (struct bus_dma_tag_dmar *)dmat; map = malloc_domainset(sizeof(*map), M_DMAR_DMAMAP, DOMAINSET_PREF(tag->common.domain), M_NOWAIT | M_ZERO); From owner-svn-src-stable-12@freebsd.org Thu Apr 25 08:28:56 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 11923159033B; Thu, 25 Apr 2019 08:28:56 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id AB172702DA; Thu, 25 Apr 2019 08:28:55 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 7F0C7210F5; Thu, 25 Apr 2019 08:28:55 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3P8StrP056303; Thu, 25 Apr 2019 08:28:55 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3P8SsJQ056297; Thu, 25 Apr 2019 08:28:54 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201904250828.x3P8SsJQ056297@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Thu, 25 Apr 2019 08:28:54 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346663 - stable/12/sys/x86/iommu X-SVN-Group: stable-12 X-SVN-Commit-Author: kib X-SVN-Commit-Paths: stable/12/sys/x86/iommu X-SVN-Commit-Revision: 346663 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: AB172702DA X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.97 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.98)[-0.976,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Apr 2019 08:28:56 -0000 Author: kib Date: Thu Apr 25 08:28:54 2019 New Revision: 346663 URL: https://svnweb.freebsd.org/changeset/base/346663 Log: MFC r346352, r346355: Correct handling of RMRR during early enumeration stages. Modified: stable/12/sys/x86/iommu/busdma_dmar.c stable/12/sys/x86/iommu/intel_ctx.c stable/12/sys/x86/iommu/intel_dmar.h stable/12/sys/x86/iommu/intel_drv.c stable/12/sys/x86/iommu/intel_intrmap.c stable/12/sys/x86/iommu/intel_utils.c Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/x86/iommu/busdma_dmar.c ============================================================================== --- stable/12/sys/x86/iommu/busdma_dmar.c Thu Apr 25 08:27:00 2019 (r346662) +++ stable/12/sys/x86/iommu/busdma_dmar.c Thu Apr 25 08:28:54 2019 (r346663) @@ -275,7 +275,7 @@ dmar_get_dma_tag(device_t dev, device_t child) struct dmar_ctx *ctx; bus_dma_tag_t res; - dmar = dmar_find(child); + dmar = dmar_find(child, bootverbose); /* Not in scope of any DMAR ? */ if (dmar == NULL) return (NULL); Modified: stable/12/sys/x86/iommu/intel_ctx.c ============================================================================== --- stable/12/sys/x86/iommu/intel_ctx.c Thu Apr 25 08:27:00 2019 (r346662) +++ stable/12/sys/x86/iommu/intel_ctx.c Thu Apr 25 08:28:54 2019 (r346663) @@ -62,6 +62,8 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include +#include #include #include #include @@ -203,7 +205,9 @@ dmar_flush_for_ctx_entry(struct dmar_unit *dmar, bool } static int -domain_init_rmrr(struct dmar_domain *domain, device_t dev) +domain_init_rmrr(struct dmar_domain *domain, device_t dev, int bus, + int slot, int func, int dev_domain, int dev_busno, + const void *dev_path, int dev_path_len) { struct dmar_map_entries_tailq rmrr_entries; struct dmar_map_entry *entry, *entry1; @@ -214,7 +218,8 @@ domain_init_rmrr(struct dmar_domain *domain, device_t error = 0; TAILQ_INIT(&rmrr_entries); - dmar_dev_parse_rmrr(domain, dev, &rmrr_entries); + dmar_dev_parse_rmrr(domain, dev_domain, dev_busno, dev_path, + dev_path_len, &rmrr_entries); TAILQ_FOREACH_SAFE(entry, &rmrr_entries, unroll_link, entry1) { /* * VT-d specification requires that the start of an @@ -227,12 +232,19 @@ domain_init_rmrr(struct dmar_domain *domain, device_t */ start = entry->start; end = entry->end; + if (bootverbose) + printf("dmar%d ctx pci%d:%d:%d RMRR [%#jx, %#jx]\n", + domain->dmar->unit, bus, slot, func, + (uintmax_t)start, (uintmax_t)end); entry->start = trunc_page(start); entry->end = round_page(end); if (entry->start == entry->end) { /* Workaround for some AMI (?) BIOSes */ if (bootverbose) { - device_printf(dev, "BIOS bug: dmar%d RMRR " + if (dev != NULL) + device_printf(dev, ""); + printf("pci%d:%d:%d ", bus, slot, func); + printf("BIOS bug: dmar%d RMRR " "region (%jx, %jx) corrected\n", domain->dmar->unit, start, end); } @@ -260,9 +272,13 @@ domain_init_rmrr(struct dmar_domain *domain, device_t DMAR_UNLOCK(domain->dmar); } else { if (error1 != 0) { - device_printf(dev, + if (dev != NULL) + device_printf(dev, ""); + printf("pci%d:%d:%d ", bus, slot, func); + printf( "dmar%d failed to map RMRR region (%jx, %jx) %d\n", - domain->dmar->unit, start, end, error1); + domain->dmar->unit, start, end, + error1); error = error1; } TAILQ_REMOVE(&rmrr_entries, entry, unroll_link); @@ -404,8 +420,9 @@ dmar_domain_destroy(struct dmar_domain *domain) free(domain, M_DMAR_DOMAIN); } -struct dmar_ctx * -dmar_get_ctx_for_dev(struct dmar_unit *dmar, device_t dev, uint16_t rid, +static struct dmar_ctx * +dmar_get_ctx_for_dev1(struct dmar_unit *dmar, device_t dev, uint16_t rid, + int dev_domain, int dev_busno, const void *dev_path, int dev_path_len, bool id_mapped, bool rmrr_init) { struct dmar_domain *domain, *domain1; @@ -415,9 +432,15 @@ dmar_get_ctx_for_dev(struct dmar_unit *dmar, device_t int bus, slot, func, error; bool enable; - bus = pci_get_bus(dev); - slot = pci_get_slot(dev); - func = pci_get_function(dev); + if (dev != NULL) { + bus = pci_get_bus(dev); + slot = pci_get_slot(dev); + func = pci_get_function(dev); + } else { + bus = PCI_RID2BUS(rid); + slot = PCI_RID2SLOT(rid); + func = PCI_RID2FUNC(rid); + } enable = false; TD_PREP_PINNED_ASSERT; DMAR_LOCK(dmar); @@ -436,7 +459,9 @@ dmar_get_ctx_for_dev(struct dmar_unit *dmar, device_t return (NULL); } if (!id_mapped) { - error = domain_init_rmrr(domain1, dev); + error = domain_init_rmrr(domain1, dev, bus, + slot, func, dev_domain, dev_busno, dev_path, + dev_path_len); if (error != 0) { dmar_domain_destroy(domain1); TD_PINNED_ASSERT; @@ -468,12 +493,14 @@ dmar_get_ctx_for_dev(struct dmar_unit *dmar, device_t enable = true; LIST_INSERT_HEAD(&dmar->domains, domain, link); ctx_id_entry_init(ctx, ctxp, false); - device_printf(dev, + if (dev != NULL) { + device_printf(dev, "dmar%d pci%d:%d:%d:%d rid %x domain %d mgaw %d " - "agaw %d %s-mapped\n", - dmar->unit, dmar->segment, bus, slot, - func, rid, domain->domain, domain->mgaw, - domain->agaw, id_mapped ? "id" : "re"); + "agaw %d %s-mapped\n", + dmar->unit, dmar->segment, bus, slot, + func, rid, domain->domain, domain->mgaw, + domain->agaw, id_mapped ? "id" : "re"); + } dmar_unmap_pgtbl(sf); } else { dmar_unmap_pgtbl(sf); @@ -485,6 +512,8 @@ dmar_get_ctx_for_dev(struct dmar_unit *dmar, device_t } } else { domain = ctx->domain; + if (ctx->ctx_tag.owner == NULL) + ctx->ctx_tag.owner = dev; ctx->refs++; /* tag referenced us */ } @@ -502,7 +531,14 @@ dmar_get_ctx_for_dev(struct dmar_unit *dmar, device_t */ if (enable && !rmrr_init && (dmar->hw_gcmd & DMAR_GCMD_TE) == 0) { error = dmar_enable_translation(dmar); - if (error != 0) { + if (error == 0) { + if (bootverbose) { + printf("dmar%d: enabled translation\n", + dmar->unit); + } + } else { + printf("dmar%d: enabling translation failed, " + "error %d\n", dmar->unit, error); dmar_free_ctx_locked(dmar, ctx); TD_PINNED_ASSERT; return (NULL); @@ -511,6 +547,31 @@ dmar_get_ctx_for_dev(struct dmar_unit *dmar, device_t DMAR_UNLOCK(dmar); TD_PINNED_ASSERT; return (ctx); +} + +struct dmar_ctx * +dmar_get_ctx_for_dev(struct dmar_unit *dmar, device_t dev, uint16_t rid, + bool id_mapped, bool rmrr_init) +{ + int dev_domain, dev_path_len, dev_busno; + + dev_domain = pci_get_domain(dev); + dev_path_len = dmar_dev_depth(dev); + ACPI_DMAR_PCI_PATH dev_path[dev_path_len]; + dmar_dev_path(dev, &dev_busno, dev_path, dev_path_len); + return (dmar_get_ctx_for_dev1(dmar, dev, rid, dev_domain, dev_busno, + dev_path, dev_path_len, id_mapped, rmrr_init)); +} + +struct dmar_ctx * +dmar_get_ctx_for_devpath(struct dmar_unit *dmar, uint16_t rid, + int dev_domain, int dev_busno, + const void *dev_path, int dev_path_len, + bool id_mapped, bool rmrr_init) +{ + + return (dmar_get_ctx_for_dev1(dmar, NULL, rid, dev_domain, dev_busno, + dev_path, dev_path_len, id_mapped, rmrr_init)); } int Modified: stable/12/sys/x86/iommu/intel_dmar.h ============================================================================== --- stable/12/sys/x86/iommu/intel_dmar.h Thu Apr 25 08:27:00 2019 (r346662) +++ stable/12/sys/x86/iommu/intel_dmar.h Thu Apr 25 08:28:54 2019 (r346663) @@ -258,7 +258,7 @@ struct dmar_unit { #define DMAR_BARRIER_RMRR 0 #define DMAR_BARRIER_USEQ 1 -struct dmar_unit *dmar_find(device_t dev); +struct dmar_unit *dmar_find(device_t dev, bool verbose); struct dmar_unit *dmar_find_hpet(device_t dev, uint16_t *rid); struct dmar_unit *dmar_find_ioapic(u_int apic_id, uint16_t *rid); @@ -325,10 +325,16 @@ void domain_flush_iotlb_sync(struct dmar_domain *domai int domain_alloc_pgtbl(struct dmar_domain *domain); void domain_free_pgtbl(struct dmar_domain *domain); +int dmar_dev_depth(device_t child); +void dmar_dev_path(device_t child, int *busno, void *path1, int depth); + struct dmar_ctx *dmar_instantiate_ctx(struct dmar_unit *dmar, device_t dev, bool rmrr); struct dmar_ctx *dmar_get_ctx_for_dev(struct dmar_unit *dmar, device_t dev, uint16_t rid, bool id_mapped, bool rmrr_init); +struct dmar_ctx *dmar_get_ctx_for_devpath(struct dmar_unit *dmar, uint16_t rid, + int dev_domain, int dev_busno, const void *dev_path, int dev_path_len, + bool id_mapped, bool rmrr_init); int dmar_move_ctx_to_domain(struct dmar_domain *domain, struct dmar_ctx *ctx); void dmar_free_ctx_locked(struct dmar_unit *dmar, struct dmar_ctx *ctx); void dmar_free_ctx(struct dmar_ctx *ctx); @@ -360,7 +366,8 @@ int dmar_gas_map_region(struct dmar_domain *domain, int dmar_gas_reserve_region(struct dmar_domain *domain, dmar_gaddr_t start, dmar_gaddr_t end); -void dmar_dev_parse_rmrr(struct dmar_domain *domain, device_t dev, +void dmar_dev_parse_rmrr(struct dmar_domain *domain, int dev_domain, + int dev_busno, const void *dev_path, int dev_path_len, struct dmar_map_entries_tailq *rmrr_entries); int dmar_instantiate_rmrr_ctxs(struct dmar_unit *dmar); @@ -382,7 +389,6 @@ void dmar_fini_irt(struct dmar_unit *unit); extern dmar_haddr_t dmar_high; extern int haw; extern int dmar_tbl_pagecnt; -extern int dmar_match_verbose; extern int dmar_batch_coalesce; extern int dmar_check_free; Modified: stable/12/sys/x86/iommu/intel_drv.c ============================================================================== --- stable/12/sys/x86/iommu/intel_drv.c Thu Apr 25 08:27:00 2019 (r346662) +++ stable/12/sys/x86/iommu/intel_drv.c Thu Apr 25 08:28:54 2019 (r346663) @@ -54,6 +54,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -176,7 +177,6 @@ dmar_identify(driver_t *driver, device_t parent) #ifdef INVARIANTS TUNABLE_INT_FETCH("hw.dmar.check_free", &dmar_check_free); #endif - TUNABLE_INT_FETCH("hw.dmar.match_verbose", &dmar_match_verbose); status = AcpiGetTable(ACPI_SIG_DMAR, 1, (ACPI_TABLE_HEADER **)&dmartbl); if (ACPI_FAILURE(status)) return; @@ -595,21 +595,20 @@ DRIVER_MODULE(dmar, acpi, dmar_driver, dmar_devclass, MODULE_DEPEND(dmar, acpi, 1, 1, 1); static void -dmar_print_path(device_t dev, const char *banner, int busno, int depth, - const ACPI_DMAR_PCI_PATH *path) +dmar_print_path(int busno, int depth, const ACPI_DMAR_PCI_PATH *path) { int i; - device_printf(dev, "%s [%d, ", banner, busno); + printf("[%d, ", busno); for (i = 0; i < depth; i++) { if (i != 0) printf(", "); printf("(%d, %d)", path[i].Device, path[i].Function); } - printf("]\n"); + printf("]"); } -static int +int dmar_dev_depth(device_t child) { devclass_t pci_class; @@ -627,13 +626,15 @@ dmar_dev_depth(device_t child) } } -static void -dmar_dev_path(device_t child, int *busno, ACPI_DMAR_PCI_PATH *path, int depth) +void +dmar_dev_path(device_t child, int *busno, void *path1, int depth) { devclass_t pci_class; device_t bus, pcib; + ACPI_DMAR_PCI_PATH *path; pci_class = devclass_find("pci"); + path = path1; for (depth--; depth != -1; depth--) { path[depth].Device = pci_get_slot(child); path[depth].Function = pci_get_function(child); @@ -673,14 +674,14 @@ dmar_match_pathes(int busno1, const ACPI_DMAR_PCI_PATH } static int -dmar_match_devscope(ACPI_DMAR_DEVICE_SCOPE *devscope, device_t dev, - int dev_busno, const ACPI_DMAR_PCI_PATH *dev_path, int dev_path_len) +dmar_match_devscope(ACPI_DMAR_DEVICE_SCOPE *devscope, int dev_busno, + const ACPI_DMAR_PCI_PATH *dev_path, int dev_path_len) { ACPI_DMAR_PCI_PATH *path; int path_len; if (devscope->Length < sizeof(*devscope)) { - printf("dmar_find: corrupted DMAR table, dl %d\n", + printf("dmar_match_devscope: corrupted DMAR table, dl %d\n", devscope->Length); return (-1); } @@ -689,99 +690,112 @@ dmar_match_devscope(ACPI_DMAR_DEVICE_SCOPE *devscope, return (0); path_len = devscope->Length - sizeof(*devscope); if (path_len % 2 != 0) { - printf("dmar_find_bsf: corrupted DMAR table, dl %d\n", + printf("dmar_match_devscope: corrupted DMAR table, dl %d\n", devscope->Length); return (-1); } path_len /= 2; path = (ACPI_DMAR_PCI_PATH *)(devscope + 1); if (path_len == 0) { - printf("dmar_find: corrupted DMAR table, dl %d\n", + printf("dmar_match_devscope: corrupted DMAR table, dl %d\n", devscope->Length); return (-1); } - if (dmar_match_verbose) - dmar_print_path(dev, "DMAR", devscope->Bus, path_len, path); return (dmar_match_pathes(devscope->Bus, path, path_len, dev_busno, dev_path, dev_path_len, devscope->EntryType)); } -struct dmar_unit * -dmar_find(device_t dev) +static bool +dmar_match_by_path(struct dmar_unit *unit, int dev_domain, int dev_busno, + const ACPI_DMAR_PCI_PATH *dev_path, int dev_path_len, const char **banner) { - device_t dmar_dev; ACPI_DMAR_HARDWARE_UNIT *dmarh; ACPI_DMAR_DEVICE_SCOPE *devscope; char *ptr, *ptrend; - int i, match, dev_domain, dev_busno, dev_path_len; + int match; + dmarh = dmar_find_by_index(unit->unit); + if (dmarh == NULL) + return (false); + if (dmarh->Segment != dev_domain) + return (false); + if ((dmarh->Flags & ACPI_DMAR_INCLUDE_ALL) != 0) { + if (banner != NULL) + *banner = "INCLUDE_ALL"; + return (true); + } + ptr = (char *)dmarh + sizeof(*dmarh); + ptrend = (char *)dmarh + dmarh->Header.Length; + while (ptr < ptrend) { + devscope = (ACPI_DMAR_DEVICE_SCOPE *)ptr; + ptr += devscope->Length; + match = dmar_match_devscope(devscope, dev_busno, dev_path, + dev_path_len); + if (match == -1) + return (false); + if (match == 1) { + if (banner != NULL) + *banner = "specific match"; + return (true); + } + } + return (false); +} + +static struct dmar_unit * +dmar_find_by_scope(int dev_domain, int dev_busno, + const ACPI_DMAR_PCI_PATH *dev_path, int dev_path_len) +{ + struct dmar_unit *unit; + int i; + + for (i = 0; i < dmar_devcnt; i++) { + if (dmar_devs[i] == NULL) + continue; + unit = device_get_softc(dmar_devs[i]); + if (dmar_match_by_path(unit, dev_domain, dev_busno, dev_path, + dev_path_len, NULL)) + return (unit); + } + return (NULL); +} + +struct dmar_unit * +dmar_find(device_t dev, bool verbose) +{ + device_t dmar_dev; + struct dmar_unit *unit; + const char *banner; + int i, dev_domain, dev_busno, dev_path_len; + dmar_dev = NULL; dev_domain = pci_get_domain(dev); dev_path_len = dmar_dev_depth(dev); ACPI_DMAR_PCI_PATH dev_path[dev_path_len]; dmar_dev_path(dev, &dev_busno, dev_path, dev_path_len); - if (dmar_match_verbose) - dmar_print_path(dev, "PCI", dev_busno, dev_path_len, dev_path); + banner = ""; for (i = 0; i < dmar_devcnt; i++) { if (dmar_devs[i] == NULL) continue; - dmarh = dmar_find_by_index(i); - if (dmarh == NULL) - continue; - if (dmarh->Segment != dev_domain) - continue; - if ((dmarh->Flags & ACPI_DMAR_INCLUDE_ALL) != 0) { - dmar_dev = dmar_devs[i]; - if (dmar_match_verbose) { - device_printf(dev, - "pci%d:%d:%d:%d matched dmar%d INCLUDE_ALL\n", - dev_domain, pci_get_bus(dev), - pci_get_slot(dev), - pci_get_function(dev), - ((struct dmar_unit *)device_get_softc( - dmar_dev))->unit); - } - goto found; - } - ptr = (char *)dmarh + sizeof(*dmarh); - ptrend = (char *)dmarh + dmarh->Header.Length; - for (;;) { - if (ptr >= ptrend) - break; - devscope = (ACPI_DMAR_DEVICE_SCOPE *)ptr; - ptr += devscope->Length; - if (dmar_match_verbose) { - device_printf(dev, - "pci%d:%d:%d:%d matching dmar%d\n", - dev_domain, pci_get_bus(dev), - pci_get_slot(dev), - pci_get_function(dev), - ((struct dmar_unit *)device_get_softc( - dmar_devs[i]))->unit); - } - match = dmar_match_devscope(devscope, dev, dev_busno, - dev_path, dev_path_len); - if (dmar_match_verbose) { - if (match == -1) - printf("table error\n"); - else if (match == 0) - printf("not matched\n"); - else - printf("matched\n"); - } - if (match == -1) - return (NULL); - else if (match == 1) { - dmar_dev = dmar_devs[i]; - goto found; - } - } + unit = device_get_softc(dmar_devs[i]); + if (dmar_match_by_path(unit, dev_domain, dev_busno, + dev_path, dev_path_len, &banner)) + break; } - return (NULL); -found: - return (device_get_softc(dmar_dev)); + if (i == dmar_devcnt) + return (NULL); + + if (verbose) { + device_printf(dev, "pci%d:%d:%d:%d matched dmar%d by %s", + dev_domain, pci_get_bus(dev), pci_get_slot(dev), + pci_get_function(dev), unit->unit, banner); + printf(" scope path "); + dmar_print_path(dev_busno, dev_path_len, dev_path); + printf("\n"); + } + return (unit); } static struct dmar_unit * @@ -865,10 +879,9 @@ dmar_find_ioapic(u_int apic_id, uint16_t *rid) struct rmrr_iter_args { struct dmar_domain *domain; - device_t dev; int dev_domain; int dev_busno; - ACPI_DMAR_PCI_PATH *dev_path; + const ACPI_DMAR_PCI_PATH *dev_path; int dev_path_len; struct dmar_map_entries_tailq *rmrr_entries; }; @@ -888,12 +901,6 @@ dmar_rmrr_iter(ACPI_DMAR_HEADER *dmarh, void *arg) ria = arg; resmem = (ACPI_DMAR_RESERVED_MEMORY *)dmarh; - if (dmar_match_verbose) { - printf("RMRR [%jx,%jx] segment %d\n", - (uintmax_t)resmem->BaseAddress, - (uintmax_t)resmem->EndAddress, - resmem->Segment); - } if (resmem->Segment != ria->dev_domain) return (1); @@ -904,11 +911,9 @@ dmar_rmrr_iter(ACPI_DMAR_HEADER *dmarh, void *arg) break; devscope = (ACPI_DMAR_DEVICE_SCOPE *)ptr; ptr += devscope->Length; - match = dmar_match_devscope(devscope, ria->dev, ria->dev_busno, + match = dmar_match_devscope(devscope, ria->dev_busno, ria->dev_path, ria->dev_path_len); if (match == 1) { - if (dmar_match_verbose) - printf("matched\n"); entry = dmar_gas_alloc_entry(ria->domain, DMAR_PGF_WAITOK); entry->start = resmem->BaseAddress; @@ -916,8 +921,6 @@ dmar_rmrr_iter(ACPI_DMAR_HEADER *dmarh, void *arg) entry->end = resmem->EndAddress; TAILQ_INSERT_TAIL(ria->rmrr_entries, entry, unroll_link); - } else if (dmar_match_verbose) { - printf("not matched, err %d\n", match); } } @@ -925,25 +928,17 @@ dmar_rmrr_iter(ACPI_DMAR_HEADER *dmarh, void *arg) } void -dmar_dev_parse_rmrr(struct dmar_domain *domain, device_t dev, +dmar_dev_parse_rmrr(struct dmar_domain *domain, int dev_domain, int dev_busno, + const void *dev_path, int dev_path_len, struct dmar_map_entries_tailq *rmrr_entries) { struct rmrr_iter_args ria; - ria.dev_domain = pci_get_domain(dev); - ria.dev_path_len = dmar_dev_depth(dev); - ACPI_DMAR_PCI_PATH dev_path[ria.dev_path_len]; - dmar_dev_path(dev, &ria.dev_busno, dev_path, ria.dev_path_len); - - if (dmar_match_verbose) { - device_printf(dev, "parsing RMRR entries for "); - dmar_print_path(dev, "PCI", ria.dev_busno, ria.dev_path_len, - dev_path); - } - ria.domain = domain; - ria.dev = dev; - ria.dev_path = dev_path; + ria.dev_domain = dev_domain; + ria.dev_busno = dev_busno; + ria.dev_path = (const ACPI_DMAR_PCI_PATH *)dev_path; + ria.dev_path_len = dev_path_len; ria.rmrr_entries = rmrr_entries; dmar_iterate_tbl(dmar_rmrr_iter, &ria); } @@ -954,28 +949,22 @@ struct inst_rmrr_iter_args { static device_t dmar_path_dev(int segment, int path_len, int busno, - const ACPI_DMAR_PCI_PATH *path) + const ACPI_DMAR_PCI_PATH *path, uint16_t *rid) { - devclass_t pci_class; - device_t bus, pcib, dev; + device_t dev; int i; - pci_class = devclass_find("pci"); dev = NULL; - for (i = 0; i < path_len; i++, path++) { + for (i = 0; i < path_len; i++) { dev = pci_find_dbsf(segment, busno, path->Device, path->Function); - if (dev == NULL) - break; if (i != path_len - 1) { - bus = device_get_parent(dev); - pcib = device_get_parent(bus); - if (device_get_devclass(device_get_parent(pcib)) != - pci_class) - return (NULL); + busno = pci_cfgregread(busno, path->Device, + path->Function, PCIR_SECBUS_1, 1); + path++; } - busno = pcib_get_bus(dev); } + *rid = PCI_RID(busno, path->Device, path->Function); return (dev); } @@ -986,21 +975,19 @@ dmar_inst_rmrr_iter(ACPI_DMAR_HEADER *dmarh, void *arg const ACPI_DMAR_DEVICE_SCOPE *devscope; struct inst_rmrr_iter_args *iria; const char *ptr, *ptrend; - struct dmar_unit *dev_dmar; device_t dev; + struct dmar_unit *unit; + int dev_path_len; + uint16_t rid; + iria = arg; + if (dmarh->Type != ACPI_DMAR_TYPE_RESERVED_MEMORY) return (1); - iria = arg; resmem = (ACPI_DMAR_RESERVED_MEMORY *)dmarh; if (resmem->Segment != iria->dmar->segment) return (1); - if (dmar_match_verbose) { - printf("dmar%d: RMRR [%jx,%jx]\n", iria->dmar->unit, - (uintmax_t)resmem->BaseAddress, - (uintmax_t)resmem->EndAddress); - } ptr = (const char *)resmem + sizeof(*resmem); ptrend = (const char *)resmem + resmem->Header.Length; @@ -1012,31 +999,40 @@ dmar_inst_rmrr_iter(ACPI_DMAR_HEADER *dmarh, void *arg /* XXXKIB bridge */ if (devscope->EntryType != ACPI_DMAR_SCOPE_TYPE_ENDPOINT) continue; - if (dmar_match_verbose) { - dmar_print_path(iria->dmar->dev, "RMRR scope", - devscope->Bus, (devscope->Length - - sizeof(ACPI_DMAR_DEVICE_SCOPE)) / 2, - (const ACPI_DMAR_PCI_PATH *)(devscope + 1)); - } - dev = dmar_path_dev(resmem->Segment, (devscope->Length - - sizeof(ACPI_DMAR_DEVICE_SCOPE)) / 2, devscope->Bus, - (const ACPI_DMAR_PCI_PATH *)(devscope + 1)); + rid = 0; + dev_path_len = (devscope->Length - + sizeof(ACPI_DMAR_DEVICE_SCOPE)) / 2; + dev = dmar_path_dev(resmem->Segment, dev_path_len, + devscope->Bus, + (const ACPI_DMAR_PCI_PATH *)(devscope + 1), &rid); if (dev == NULL) { - if (dmar_match_verbose) - printf("null dev\n"); - continue; - } - dev_dmar = dmar_find(dev); - if (dev_dmar != iria->dmar) { - if (dmar_match_verbose) { - printf("dmar%d matched, skipping\n", - dev_dmar->unit); + if (bootverbose) { + printf("dmar%d no dev found for RMRR " + "[%#jx, %#jx] rid %#x scope path ", + iria->dmar->unit, + (uintmax_t)resmem->BaseAddress, + (uintmax_t)resmem->EndAddress, + rid); + dmar_print_path(devscope->Bus, dev_path_len, + (const ACPI_DMAR_PCI_PATH *)(devscope + 1)); + printf("\n"); } - continue; + unit = dmar_find_by_scope(resmem->Segment, + devscope->Bus, + (const ACPI_DMAR_PCI_PATH *)(devscope + 1), + dev_path_len); + if (iria->dmar != unit) + continue; + dmar_get_ctx_for_devpath(iria->dmar, rid, + resmem->Segment, devscope->Bus, + (const ACPI_DMAR_PCI_PATH *)(devscope + 1), + dev_path_len, false, true); + } else { + unit = dmar_find(dev, false); + if (iria->dmar != unit) + continue; + dmar_instantiate_ctx(iria->dmar, dev, true); } - if (dmar_match_verbose) - printf("matched, instantiating RMRR context\n"); - dmar_instantiate_ctx(iria->dmar, dev, true); } return (1); @@ -1057,8 +1053,6 @@ dmar_instantiate_rmrr_ctxs(struct dmar_unit *dmar) error = 0; iria.dmar = dmar; - if (dmar_match_verbose) - printf("dmar%d: instantiating RMRR contexts\n", dmar->unit); dmar_iterate_tbl(dmar_inst_rmrr_iter, &iria); DMAR_LOCK(dmar); if (!LIST_EMPTY(&dmar->domains)) { @@ -1066,6 +1060,15 @@ dmar_instantiate_rmrr_ctxs(struct dmar_unit *dmar) ("dmar%d: RMRR not handled but translation is already enabled", dmar->unit)); error = dmar_enable_translation(dmar); + if (bootverbose) { + if (error == 0) { + printf("dmar%d: enabled translation\n", + dmar->unit); + } else { + printf("dmar%d: enabling translation failed, " + "error %d\n", dmar->unit, error); + } + } } dmar_barrier_exit(dmar, DMAR_BARRIER_RMRR); return (error); Modified: stable/12/sys/x86/iommu/intel_intrmap.c ============================================================================== --- stable/12/sys/x86/iommu/intel_intrmap.c Thu Apr 25 08:27:00 2019 (r346662) +++ stable/12/sys/x86/iommu/intel_intrmap.c Thu Apr 25 08:28:54 2019 (r346663) @@ -251,7 +251,7 @@ dmar_ir_find(device_t src, uint16_t *rid, int *is_dmar } else if (src_class == devclass_find("hpet")) { unit = dmar_find_hpet(src, rid); } else { - unit = dmar_find(src); + unit = dmar_find(src, bootverbose); if (unit != NULL && rid != NULL) dmar_get_requester(src, rid); } Modified: stable/12/sys/x86/iommu/intel_utils.c ============================================================================== --- stable/12/sys/x86/iommu/intel_utils.c Thu Apr 25 08:27:00 2019 (r346662) +++ stable/12/sys/x86/iommu/intel_utils.c Thu Apr 25 08:28:54 2019 (r346663) @@ -614,7 +614,6 @@ dmar_barrier_exit(struct dmar_unit *dmar, u_int barrie DMAR_UNLOCK(dmar); } -int dmar_match_verbose; int dmar_batch_coalesce = 100; struct timespec dmar_hw_timeout = { .tv_sec = 0, @@ -658,9 +657,6 @@ static SYSCTL_NODE(_hw, OID_AUTO, dmar, CTLFLAG_RD, NU SYSCTL_INT(_hw_dmar, OID_AUTO, tbl_pagecnt, CTLFLAG_RD, &dmar_tbl_pagecnt, 0, "Count of pages used for DMAR pagetables"); -SYSCTL_INT(_hw_dmar, OID_AUTO, match_verbose, CTLFLAG_RWTUN, - &dmar_match_verbose, 0, - "Verbose matching of the PCI devices to DMAR paths"); SYSCTL_INT(_hw_dmar, OID_AUTO, batch_coalesce, CTLFLAG_RWTUN, &dmar_batch_coalesce, 0, "Number of qi batches between interrupt"); From owner-svn-src-stable-12@freebsd.org Thu Apr 25 11:56:09 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 55A5115944C5; Thu, 25 Apr 2019 11:56:09 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id F0AB680A76; Thu, 25 Apr 2019 11:56:08 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id CBFBA2358F; Thu, 25 Apr 2019 11:56:08 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3PBu8eY069516; Thu, 25 Apr 2019 11:56:08 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3PBu8dD069489; Thu, 25 Apr 2019 11:56:08 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201904251156.x3PBu8dD069489@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Thu, 25 Apr 2019 11:56:08 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346665 - in stable/12: lib/libcuse sys/fs/cuse X-SVN-Group: stable-12 X-SVN-Commit-Author: hselasky X-SVN-Commit-Paths: in stable/12: lib/libcuse sys/fs/cuse X-SVN-Commit-Revision: 346665 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: F0AB680A76 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.96 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.96)[-0.958,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Apr 2019 11:56:09 -0000 Author: hselasky Date: Thu Apr 25 11:56:07 2019 New Revision: 346665 URL: https://svnweb.freebsd.org/changeset/base/346665 Log: MFC r346356: Implement flag for telling cuse(3) clients if the peer is running in 32-bit compat mode or not. This is useful when implementing compatibility ioctl(2) handlers in userspace. Sponsored by: Mellanox Technologies Modified: stable/12/lib/libcuse/cuse.3 stable/12/sys/fs/cuse/cuse.c stable/12/sys/fs/cuse/cuse_defs.h Directory Properties: stable/12/ (props changed) Modified: stable/12/lib/libcuse/cuse.3 ============================================================================== --- stable/12/lib/libcuse/cuse.3 Thu Apr 25 09:13:15 2019 (r346664) +++ stable/12/lib/libcuse/cuse.3 Thu Apr 25 11:56:07 2019 (r346665) @@ -25,7 +25,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd October 5, 2017 +.Dd April 17, 2019 .Dt CUSE 3 .Os .Sh NAME @@ -303,6 +303,7 @@ enum { CUSE_FFLAG_READ CUSE_FFLAG_WRITE CUSE_FFLAG_NONBLOCK + CUSE_FFLAG_COMPAT32 CUSE_CMD_NONE CUSE_CMD_OPEN Modified: stable/12/sys/fs/cuse/cuse.c ============================================================================== --- stable/12/sys/fs/cuse/cuse.c Thu Apr 25 09:13:15 2019 (r346664) +++ stable/12/sys/fs/cuse/cuse.c Thu Apr 25 11:56:07 2019 (r346665) @@ -51,6 +51,7 @@ #include #include #include +#include #include @@ -536,7 +537,10 @@ cuse_client_send_command_locked(struct cuse_client_com if (ioflag & IO_NDELAY) cuse_fflags |= CUSE_FFLAG_NONBLOCK; - +#if defined(__LP64__) + if (SV_CURPROC_FLAG(SV_ILP32)) + cuse_fflags |= CUSE_FFLAG_COMPAT32; +#endif pccmd->sub.fflags = cuse_fflags; pccmd->sub.data_pointer = data_ptr; pccmd->sub.argument = arg; Modified: stable/12/sys/fs/cuse/cuse_defs.h ============================================================================== --- stable/12/sys/fs/cuse/cuse_defs.h Thu Apr 25 09:13:15 2019 (r346664) +++ stable/12/sys/fs/cuse/cuse_defs.h Thu Apr 25 11:56:07 2019 (r346665) @@ -27,7 +27,7 @@ #ifndef _CUSE_DEFS_H_ #define _CUSE_DEFS_H_ -#define CUSE_VERSION 0x000123 +#define CUSE_VERSION 0x000124 #define CUSE_ERR_NONE 0 #define CUSE_ERR_BUSY -1 @@ -49,6 +49,7 @@ #define CUSE_FFLAG_READ 1 #define CUSE_FFLAG_WRITE 2 #define CUSE_FFLAG_NONBLOCK 4 +#define CUSE_FFLAG_COMPAT32 8 /* peer is running in 32-bit compat mode */ #define CUSE_DBG_NONE 0 #define CUSE_DBG_FULL 1 From owner-svn-src-stable-12@freebsd.org Thu Apr 25 12:00:07 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 810C21594A77; Thu, 25 Apr 2019 12:00:07 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 27C1180FAC; Thu, 25 Apr 2019 12:00:07 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id F422D235B1; Thu, 25 Apr 2019 12:00:06 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3PC06ZW070018; Thu, 25 Apr 2019 12:00:06 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3PC06ax070017; Thu, 25 Apr 2019 12:00:06 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201904251200.x3PC06ax070017@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Thu, 25 Apr 2019 12:00:06 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346667 - stable/12/sys/dev/usb/controller X-SVN-Group: stable-12 X-SVN-Commit-Author: hselasky X-SVN-Commit-Paths: stable/12/sys/dev/usb/controller X-SVN-Commit-Revision: 346667 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 27C1180FAC X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.98 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.98)[-0.976,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Apr 2019 12:00:07 -0000 Author: hselasky Date: Thu Apr 25 12:00:06 2019 New Revision: 346667 URL: https://svnweb.freebsd.org/changeset/base/346667 Log: MFC r346229 and r346248: Fix spelling and remove superfluous USB keyword. Submitted by: Dmitry Luhtionov Sponsored by: Mellanox Technologies Modified: stable/12/sys/dev/usb/controller/ehci_pci.c Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/dev/usb/controller/ehci_pci.c ============================================================================== --- stable/12/sys/dev/usb/controller/ehci_pci.c Thu Apr 25 11:57:34 2019 (r346666) +++ stable/12/sys/dev/usb/controller/ehci_pci.c Thu Apr 25 12:00:06 2019 (r346667) @@ -181,7 +181,7 @@ ehci_pci_match(device_t self) case 0x8d2d8086: return ("Intel Wellsburg USB 2.0 controller"); case 0x9c268086: - return ("Intel Lynx Point LP USB 2.0 controller USB"); + return ("Intel Lynx Point-LP USB 2.0 controller"); case 0x00e01033: return ("NEC uPD 72010x USB 2.0 controller"); From owner-svn-src-stable-12@freebsd.org Thu Apr 25 14:33:39 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 68F761598CEA; Thu, 25 Apr 2019 14:33:39 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id E1D20875BB; Thu, 25 Apr 2019 14:33:38 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id B939125100; Thu, 25 Apr 2019 14:33:38 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3PEXcnA055251; Thu, 25 Apr 2019 14:33:38 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3PEXcHH055250; Thu, 25 Apr 2019 14:33:38 GMT (envelope-from mav@FreeBSD.org) Message-Id: <201904251433.x3PEXcHH055250@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Thu, 25 Apr 2019 14:33:38 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346672 - stable/12/sys/cddl/contrib/opensolaris/uts/common/fs/zfs X-SVN-Group: stable-12 X-SVN-Commit-Author: mav X-SVN-Commit-Paths: stable/12/sys/cddl/contrib/opensolaris/uts/common/fs/zfs X-SVN-Commit-Revision: 346672 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: E1D20875BB X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.94 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.94)[-0.940,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Apr 2019 14:33:39 -0000 Author: mav Date: Thu Apr 25 14:33:38 2019 New Revision: 346672 URL: https://svnweb.freebsd.org/changeset/base/346672 Log: MFC r340311: Do not ignore arc_adjust() return value. This covers scenario when ARC may not shrink as fast as it could: 1. arc_size < arc_c and arc_adjust() does not evict anything, returning zero to arc_reclaim_thread(); 2. arc_available_memory() reports memory pressure, which can not be satisfied by arc_kmem_reap_now(); 3. arc_shrink() reduces arc_c and calls arc_adjust(), return of which is ignored; 4. even if the last arc_adjust() could not satisfy arc_size < arc_c, arc_reclaim_thread() will still go to sleep, since the first one returned zero. Modified: stable/12/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/arc.c Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/arc.c ============================================================================== --- stable/12/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/arc.c Thu Apr 25 13:46:12 2019 (r346671) +++ stable/12/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/arc.c Thu Apr 25 14:33:38 2019 (r346672) @@ -4565,7 +4565,7 @@ arc_flush(spa_t *spa, boolean_t retry) (void) arc_flush_state(arc_mfu_ghost, guid, ARC_BUFC_METADATA, retry); } -void +uint64_t arc_shrink(int64_t to_free) { uint64_t asize = aggsum_value(&arc_size); @@ -4593,8 +4593,9 @@ arc_shrink(int64_t to_free) if (asize > arc_c) { DTRACE_PROBE2(arc__shrink_adjust, uint64_t, asize, uint64_t, arc_c); - (void) arc_adjust(); + return (arc_adjust()); } + return (0); } typedef enum free_memory_reason_t { @@ -4917,7 +4918,7 @@ arc_reclaim_thread(void *unused __unused) to_free = MAX(to_free, ptob(needfree)); #endif #endif - arc_shrink(to_free); + evicted += arc_shrink(to_free); } } else if (free_memory < arc_c >> arc_no_grow_shift) { arc_no_grow = B_TRUE; From owner-svn-src-stable-12@freebsd.org Thu Apr 25 14:39:54 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 630771598D9F; Thu, 25 Apr 2019 14:39:54 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id F16BD87812; Thu, 25 Apr 2019 14:39:53 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id B186125120; Thu, 25 Apr 2019 14:39:53 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3PEdrq6055627; Thu, 25 Apr 2019 14:39:53 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3PEdqUR055623; Thu, 25 Apr 2019 14:39:52 GMT (envelope-from mav@FreeBSD.org) Message-Id: <201904251439.x3PEdqUR055623@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Thu, 25 Apr 2019 14:39:52 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346673 - in stable/12/cddl/contrib/opensolaris: cmd/zfs lib/libzfs/common X-SVN-Group: stable-12 X-SVN-Commit-Author: mav X-SVN-Commit-Paths: in stable/12/cddl/contrib/opensolaris: cmd/zfs lib/libzfs/common X-SVN-Commit-Revision: 346673 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: F16BD87812 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.97 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_SHORT(-0.97)[-0.969,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Apr 2019 14:39:54 -0000 Author: mav Date: Thu Apr 25 14:39:52 2019 New Revision: 346673 URL: https://svnweb.freebsd.org/changeset/base/346673 Log: MFC r344601 (by sef): Set process title during zfs send. This adds a '-V' option to 'zfs send', which sets the process title once a second to the progress information. This code has been in FreeNAS for a long time now; this is just upstreaming it here. It was originially written by delphij. Modified: stable/12/cddl/contrib/opensolaris/cmd/zfs/zfs.8 stable/12/cddl/contrib/opensolaris/cmd/zfs/zfs_main.c stable/12/cddl/contrib/opensolaris/lib/libzfs/common/libzfs.h stable/12/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_sendrecv.c Directory Properties: stable/12/ (props changed) Modified: stable/12/cddl/contrib/opensolaris/cmd/zfs/zfs.8 ============================================================================== --- stable/12/cddl/contrib/opensolaris/cmd/zfs/zfs.8 Thu Apr 25 14:33:38 2019 (r346672) +++ stable/12/cddl/contrib/opensolaris/cmd/zfs/zfs.8 Thu Apr 25 14:39:52 2019 (r346673) @@ -32,7 +32,7 @@ .\" .\" $FreeBSD$ .\" -.Dd August 11, 2018 +.Dd February 15, 2018 .Dt ZFS 8 .Os .Sh NAME @@ -184,7 +184,7 @@ .Ar bookmark .Nm .Cm send -.Op Fl DLPRcenpv +.Op Fl DLPRVcenpv .Op Fl i Ar snapshot | Fl I Ar snapshot .Ar snapshot .Nm @@ -194,7 +194,7 @@ .Ar filesystem Ns | Ns Ar volume Ns | Ns Ar snapshot .Nm .Cm send -.Op Fl Penv +.Op Fl PVenv .Fl t Ar receive_resume_token .Nm .Cm receive Ns | Ns Cm recv @@ -2607,7 +2607,7 @@ feature. .It Xo .Nm .Cm send -.Op Fl DLPRcenpv +.Op Fl DLPRVcenpv .Op Fl i Ar snapshot | Fl I Ar snapshot .Ar snapshot .Xc @@ -2753,6 +2753,8 @@ Print machine-parsable verbose information about the s .It Fl v, -verbose Print verbose information about the stream package generated. This information includes a per-second report of how much data has been sent. +.It Fl V +Set the process title to a per-second report of how much data has been sent. .El .Pp The format of the stream is committed. You will be able to receive your streams Modified: stable/12/cddl/contrib/opensolaris/cmd/zfs/zfs_main.c ============================================================================== --- stable/12/cddl/contrib/opensolaris/cmd/zfs/zfs_main.c Thu Apr 25 14:33:38 2019 (r346672) +++ stable/12/cddl/contrib/opensolaris/cmd/zfs/zfs_main.c Thu Apr 25 14:39:52 2019 (r346673) @@ -3813,7 +3813,7 @@ zfs_do_send(int argc, char **argv) }; /* check options */ - while ((c = getopt_long(argc, argv, ":i:I:RbDpvnPLet:c", long_options, + while ((c = getopt_long(argc, argv, ":i:I:RbDpVvnPLet:c", long_options, NULL)) != -1) { switch (c) { case 'i': @@ -3836,6 +3836,10 @@ zfs_do_send(int argc, char **argv) case 'P': flags.parsable = B_TRUE; flags.verbose = B_TRUE; + break; + case 'V': + flags.progress = B_TRUE; + flags.progressastitle = B_TRUE; break; case 'v': if (flags.verbose) Modified: stable/12/cddl/contrib/opensolaris/lib/libzfs/common/libzfs.h ============================================================================== --- stable/12/cddl/contrib/opensolaris/lib/libzfs/common/libzfs.h Thu Apr 25 14:33:38 2019 (r346672) +++ stable/12/cddl/contrib/opensolaris/lib/libzfs/common/libzfs.h Thu Apr 25 14:39:52 2019 (r346673) @@ -651,6 +651,9 @@ typedef struct sendflags { /* compressed WRITE records are permitted */ boolean_t compress; + + /* show progress as process title(ie. -V) */ + boolean_t progressastitle; } sendflags_t; typedef boolean_t (snapfilter_cb_t)(zfs_handle_t *, void *); Modified: stable/12/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_sendrecv.c ============================================================================== --- stable/12/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_sendrecv.c Thu Apr 25 14:33:38 2019 (r346672) +++ stable/12/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_sendrecv.c Thu Apr 25 14:39:52 2019 (r346673) @@ -85,6 +85,8 @@ typedef struct progress_arg { zfs_handle_t *pa_zhp; int pa_fd; boolean_t pa_parsable; + boolean_t pa_astitle; + uint64_t pa_size; } progress_arg_t; typedef struct dataref { @@ -930,6 +932,7 @@ typedef struct send_dump_data { uint64_t prevsnap_obj; boolean_t seenfrom, seento, replicate, doall, fromorigin; boolean_t verbose, dryrun, parsable, progress, embed_data, std_out; + boolean_t progressastitle; boolean_t large_block, compress; int outfd; boolean_t err; @@ -1110,14 +1113,14 @@ send_progress_thread(void *arg) zfs_cmd_t zc = { 0 }; zfs_handle_t *zhp = pa->pa_zhp; libzfs_handle_t *hdl = zhp->zfs_hdl; - unsigned long long bytes; + unsigned long long bytes, total; char buf[16]; time_t t; struct tm *tm; (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name)); - if (!pa->pa_parsable) + if (!pa->pa_parsable && !pa->pa_astitle) (void) fprintf(stderr, "TIME SENT SNAPSHOT\n"); /* @@ -1134,7 +1137,16 @@ send_progress_thread(void *arg) tm = localtime(&t); bytes = zc.zc_cookie; - if (pa->pa_parsable) { + if (pa->pa_astitle) { + int pct; + if (pa->pa_size > bytes) + pct = 100 * bytes / pa->pa_size; + else + pct = 100; + + setproctitle("sending %s (%d%%: %llu/%llu)", + zhp->zfs_name, pct, bytes, pa->pa_size); + } else if (pa->pa_parsable) { (void) fprintf(stderr, "%02d:%02d:%02d\t%llu\t%s\n", tm->tm_hour, tm->tm_min, tm->tm_sec, bytes, zhp->zfs_name); @@ -1204,6 +1216,7 @@ dump_snapshot(zfs_handle_t *zhp, void *arg) boolean_t isfromsnap, istosnap, fromorigin; boolean_t exclude = B_FALSE; FILE *fout = sdd->std_out ? stdout : stderr; + uint64_t size = 0; err = 0; thissnap = strchr(zhp->zfs_name, '@') + 1; @@ -1278,15 +1291,16 @@ dump_snapshot(zfs_handle_t *zhp, void *arg) fromorigin = sdd->prevsnap[0] == '\0' && (sdd->fromorigin || sdd->replicate); - if (sdd->verbose) { - uint64_t size = 0; + if (sdd->progress && sdd->dryrun) { (void) estimate_ioctl(zhp, sdd->prevsnap_obj, fromorigin, flags, &size); + sdd->size += size; + } + if (sdd->verbose) { send_print_verbose(fout, zhp->zfs_name, sdd->prevsnap[0] ? sdd->prevsnap : NULL, size, sdd->parsable); - sdd->size += size; } if (!sdd->dryrun) { @@ -1298,6 +1312,8 @@ dump_snapshot(zfs_handle_t *zhp, void *arg) pa.pa_zhp = zhp; pa.pa_fd = sdd->outfd; pa.pa_parsable = sdd->parsable; + pa.pa_size = sdd->size; + pa.pa_astitle = sdd->progressastitle; if ((err = pthread_create(&tid, NULL, send_progress_thread, &pa)) != 0) { @@ -1580,6 +1596,7 @@ zfs_send_resume(libzfs_handle_t *hdl, sendflags_t *fla int error = 0; char name[ZFS_MAX_DATASET_NAME_LEN]; enum lzc_send_flags lzc_flags = 0; + uint64_t size = 0; FILE *fout = (flags->verbose && flags->dryrun) ? stdout : stderr; (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, @@ -1648,12 +1665,13 @@ zfs_send_resume(libzfs_handle_t *hdl, sendflags_t *fla fromname = name; } - if (flags->verbose) { - uint64_t size = 0; + if (flags->progress) { error = lzc_send_space(zhp->zfs_name, fromname, lzc_flags, &size); if (error == 0) size = MAX(0, (int64_t)(size - bytes)); + } + if (flags->verbose) { send_print_verbose(fout, zhp->zfs_name, fromname, size, flags->parsable); } @@ -1669,6 +1687,8 @@ zfs_send_resume(libzfs_handle_t *hdl, sendflags_t *fla pa.pa_zhp = zhp; pa.pa_fd = outfd; pa.pa_parsable = flags->parsable; + pa.pa_size = size; + pa.pa_astitle = flags->progressastitle; error = pthread_create(&tid, NULL, send_progress_thread, &pa); @@ -1878,6 +1898,7 @@ zfs_send(zfs_handle_t *zhp, const char *fromsnap, cons sdd.verbose = flags->verbose; sdd.parsable = flags->parsable; sdd.progress = flags->progress; + sdd.progressastitle = flags->progressastitle; sdd.dryrun = flags->dryrun; sdd.large_block = flags->largeblock; sdd.embed_data = flags->embed_data; @@ -1914,7 +1935,7 @@ zfs_send(zfs_handle_t *zhp, const char *fromsnap, cons sdd.cleanup_fd = -1; sdd.snapholds = NULL; } - if (flags->verbose || sdd.snapholds != NULL) { + if (flags->progress || sdd.snapholds != NULL) { /* * Do a verbose no-op dry run to get all the verbose output * or to gather snapshot hold's before generating any data, From owner-svn-src-stable-12@freebsd.org Thu Apr 25 14:41:31 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id B5A641598E80; Thu, 25 Apr 2019 14:41:30 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 6955B87D55; Thu, 25 Apr 2019 14:41:30 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 2A26D25274; Thu, 25 Apr 2019 14:41:30 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3PEfUGI056713; Thu, 25 Apr 2019 14:41:30 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3PEfTiP056709; Thu, 25 Apr 2019 14:41:29 GMT (envelope-from mav@FreeBSD.org) Message-Id: <201904251441.x3PEfTiP056709@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Thu, 25 Apr 2019 14:41:29 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346674 - in stable/12/sys/cddl/contrib/opensolaris/uts/common/fs/zfs: . sys X-SVN-Group: stable-12 X-SVN-Commit-Author: mav X-SVN-Commit-Paths: in stable/12/sys/cddl/contrib/opensolaris/uts/common/fs/zfs: . sys X-SVN-Commit-Revision: 346674 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 6955B87D55 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.97 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.97)[-0.970,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Apr 2019 14:41:31 -0000 Author: mav Date: Thu Apr 25 14:41:29 2019 New Revision: 346674 URL: https://svnweb.freebsd.org/changeset/base/346674 Log: MFC r345200: MFV r336930: 9284 arc_reclaim_thread has 2 jobs `arc_reclaim_thread()` calls `arc_adjust()` after calling `arc_kmem_reap_now()`; `arc_adjust()` signals `arc_get_data_buf()` to indicate that we may no longer be `arc_is_overflowing()`. The problem is, `arc_kmem_reap_now()` can take several seconds to complete, has no impact on `arc_is_overflowing()`, but due to how the code is structured, can impact how long the ARC will remain in the `arc_is_overflowing()` state. The fix is to use seperate threads to: 1. keep `arc_size` under `arc_c`, by calling `arc_adjust()`, which improves `arc_is_overflowing()` 2. keep enough free memory in the system, by calling `arc_kmem_reap_now()` plus `arc_shrink()`, which improves `arc_available_memory()`. illumos/illumos-gate@de753e34f9c399037936e8bc547d823bba9d4b0d Reviewed by: Matt Ahrens Reviewed by: Serapheim Dimitropoulos Reviewed by: Pavel Zakharov Reviewed by: Dan Kimmel Reviewed by: Paul Dagnelie Reviewed by: Dan McDonald Reviewed by: Tim Kordas Approved by: Garrett D'Amore Modified: stable/12/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/arc.c stable/12/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zthr.h stable/12/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zthr.c Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/arc.c ============================================================================== --- stable/12/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/arc.c Thu Apr 25 14:39:52 2019 (r346673) +++ stable/12/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/arc.c Thu Apr 25 14:41:29 2019 (r346674) @@ -281,6 +281,7 @@ #include #include #include +#include #include #include #include @@ -296,11 +297,23 @@ int arc_procfd; #endif #endif /* illumos */ -static kmutex_t arc_reclaim_lock; -static kcondvar_t arc_reclaim_thread_cv; -static boolean_t arc_reclaim_thread_exit; -static kcondvar_t arc_reclaim_waiters_cv; +/* + * This thread's job is to keep enough free memory in the system, by + * calling arc_kmem_reap_now() plus arc_shrink(), which improves + * arc_available_memory(). + */ +static zthr_t *arc_reap_zthr; +/* + * This thread's job is to keep arc_size under arc_c, by calling + * arc_adjust(), which improves arc_is_overflowing(). + */ +static zthr_t *arc_adjust_zthr; + +static kmutex_t arc_adjust_lock; +static kcondvar_t arc_adjust_waiters_cv; +static boolean_t arc_adjust_needed = B_FALSE; + static kmutex_t arc_dnlc_evicts_lock; static kcondvar_t arc_dnlc_evicts_cv; static boolean_t arc_dnlc_evicts_thread_exit; @@ -317,19 +330,23 @@ uint_t arc_reduce_dnlc_percent = 3; int zfs_arc_evict_batch_limit = 10; /* number of seconds before growing cache again */ -static int arc_grow_retry = 60; +int arc_grow_retry = 60; -/* number of milliseconds before attempting a kmem-cache-reap */ -static int arc_kmem_cache_reap_retry_ms = 0; +/* + * Minimum time between calls to arc_kmem_reap_soon(). Note that this will + * be converted to ticks, so with the default hz=100, a setting of 15 ms + * will actually wait 2 ticks, or 20ms. + */ +int arc_kmem_cache_reap_retry_ms = 1000; /* shift of arc_c for calculating overflow limit in arc_get_data_impl */ -int zfs_arc_overflow_shift = 8; +int zfs_arc_overflow_shift = 8; /* shift of arc_c for calculating both min and max arc_p */ -static int arc_p_min_shift = 4; +int arc_p_min_shift = 4; /* log2(fraction of arc to reclaim) */ -static int arc_shrink_shift = 7; +int arc_shrink_shift = 7; /* * log2(fraction of ARC which must be free to allow growing). @@ -355,7 +372,7 @@ static int zfs_arc_min_prescient_prefetch_ms = 6; */ int arc_lotsfree_percent = 10; -static int arc_dead; +static boolean_t arc_initialized; extern boolean_t zfs_prefetch_disable; /* @@ -1052,6 +1069,7 @@ static kmutex_t arc_prune_mtx; static taskq_t *arc_prune_taskq; static int arc_no_grow; /* Don't try to grow cache size */ +static hrtime_t arc_growtime; static uint64_t arc_tempreserve; static uint64_t arc_loaned_bytes; @@ -1819,8 +1837,8 @@ hdr_recl(void *unused) * umem calls the reclaim func when we destroy the buf cache, * which is after we do arc_fini(). */ - if (!arc_dead) - cv_signal(&arc_reclaim_thread_cv); + if (arc_initialized) + zthr_wakeup(arc_reap_zthr); } static void @@ -3905,13 +3923,14 @@ arc_evict_state_impl(multilist_t *ml, int idx, arc_buf * function should proceed in this case). * * If threads are left sleeping, due to not - * using cv_broadcast, they will be woken up - * just before arc_reclaim_thread() sleeps. + * using cv_broadcast here, they will be woken + * up via cv_broadcast in arc_adjust_cb() just + * before arc_adjust_zthr sleeps. */ - mutex_enter(&arc_reclaim_lock); + mutex_enter(&arc_adjust_lock); if (!arc_is_overflowing()) - cv_signal(&arc_reclaim_waiters_cv); - mutex_exit(&arc_reclaim_lock); + cv_signal(&arc_adjust_waiters_cv); + mutex_exit(&arc_adjust_lock); } else { ARCSTAT_BUMP(arcstat_mutex_miss); } @@ -4565,8 +4584,8 @@ arc_flush(spa_t *spa, boolean_t retry) (void) arc_flush_state(arc_mfu_ghost, guid, ARC_BUFC_METADATA, retry); } -uint64_t -arc_shrink(int64_t to_free) +static void +arc_reduce_target_size(int64_t to_free) { uint64_t asize = aggsum_value(&arc_size); if (arc_c > arc_c_min) { @@ -4593,9 +4612,12 @@ arc_shrink(int64_t to_free) if (asize > arc_c) { DTRACE_PROBE2(arc__shrink_adjust, uint64_t, asize, uint64_t, arc_c); - return (arc_adjust()); + /* See comment in arc_adjust_cb_check() on why lock+flag */ + mutex_enter(&arc_adjust_lock); + arc_adjust_needed = B_TRUE; + mutex_exit(&arc_adjust_lock); + zthr_wakeup(arc_adjust_zthr); } - return (0); } typedef enum free_memory_reason_t { @@ -4765,7 +4787,7 @@ extern kmem_cache_t *range_seg_cache; extern kmem_cache_t *abd_chunk_cache; static __noinline void -arc_kmem_reap_now(void) +arc_kmem_reap_soon(void) { size_t i; kmem_cache_t *prev_cache = NULL; @@ -4788,16 +4810,6 @@ arc_kmem_reap_now(void) #endif #endif - /* - * If a kmem reap is already active, don't schedule more. We must - * check for this because kmem_cache_reap_soon() won't actually - * block on the cache being reaped (this is to prevent callers from - * becoming implicitly blocked by a system-wide kmem reap -- which, - * on a system with many, many full magazines, can take minutes). - */ - if (kmem_cache_reap_active()) - return; - for (i = 0; i < SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT; i++) { if (zio_buf_cache[i] != prev_cache) { prev_cache = zio_buf_cache[i]; @@ -4826,141 +4838,163 @@ arc_kmem_reap_now(void) DTRACE_PROBE(arc__kmem_reap_end); } -/* - * Threads can block in arc_get_data_impl() waiting for this thread to evict - * enough data and signal them to proceed. When this happens, the threads in - * arc_get_data_impl() are sleeping while holding the hash lock for their - * particular arc header. Thus, we must be careful to never sleep on a - * hash lock in this thread. This is to prevent the following deadlock: - * - * - Thread A sleeps on CV in arc_get_data_impl() holding hash lock "L", - * waiting for the reclaim thread to signal it. - * - * - arc_reclaim_thread() tries to acquire hash lock "L" using mutex_enter, - * fails, and goes to sleep forever. - * - * This possible deadlock is avoided by always acquiring a hash lock - * using mutex_tryenter() from arc_reclaim_thread(). - */ /* ARGSUSED */ -static void -arc_reclaim_thread(void *unused __unused) +static boolean_t +arc_adjust_cb_check(void *arg, zthr_t *zthr) { - hrtime_t growtime = 0; - hrtime_t kmem_reap_time = 0; - callb_cpr_t cpr; + /* + * This is necessary in order for the mdb ::arc dcmd to + * show up to date information. Since the ::arc command + * does not call the kstat's update function, without + * this call, the command may show stale stats for the + * anon, mru, mru_ghost, mfu, and mfu_ghost lists. Even + * with this change, the data might be up to 1 second + * out of date(the arc_adjust_zthr has a maximum sleep + * time of 1 second); but that should suffice. The + * arc_state_t structures can be queried directly if more + * accurate information is needed. + */ + if (arc_ksp != NULL) + arc_ksp->ks_update(arc_ksp, KSTAT_READ); - CALLB_CPR_INIT(&cpr, &arc_reclaim_lock, callb_generic_cpr, FTAG); + /* + * We have to rely on arc_get_data_impl() to tell us when to adjust, + * rather than checking if we are overflowing here, so that we are + * sure to not leave arc_get_data_impl() waiting on + * arc_adjust_waiters_cv. If we have become "not overflowing" since + * arc_get_data_impl() checked, we need to wake it up. We could + * broadcast the CV here, but arc_get_data_impl() may have not yet + * gone to sleep. We would need to use a mutex to ensure that this + * function doesn't broadcast until arc_get_data_impl() has gone to + * sleep (e.g. the arc_adjust_lock). However, the lock ordering of + * such a lock would necessarily be incorrect with respect to the + * zthr_lock, which is held before this function is called, and is + * held by arc_get_data_impl() when it calls zthr_wakeup(). + */ + return (arc_adjust_needed); +} - mutex_enter(&arc_reclaim_lock); - while (!arc_reclaim_thread_exit) { - uint64_t evicted = 0; +/* + * Keep arc_size under arc_c by running arc_adjust which evicts data + * from the ARC. */ +/* ARGSUSED */ +static int +arc_adjust_cb(void *arg, zthr_t *zthr) +{ + uint64_t evicted = 0; + /* Evict from cache */ + evicted = arc_adjust(); + + /* + * If evicted is zero, we couldn't evict anything + * via arc_adjust(). This could be due to hash lock + * collisions, but more likely due to the majority of + * arc buffers being unevictable. Therefore, even if + * arc_size is above arc_c, another pass is unlikely to + * be helpful and could potentially cause us to enter an + * infinite loop. Additionally, zthr_iscancelled() is + * checked here so that if the arc is shutting down, the + * broadcast will wake any remaining arc adjust waiters. + */ + mutex_enter(&arc_adjust_lock); + arc_adjust_needed = !zthr_iscancelled(arc_adjust_zthr) && + evicted > 0 && aggsum_compare(&arc_size, arc_c) > 0; + if (!arc_adjust_needed) { /* - * This is necessary in order for the mdb ::arc dcmd to - * show up to date information. Since the ::arc command - * does not call the kstat's update function, without - * this call, the command may show stale stats for the - * anon, mru, mru_ghost, mfu, and mfu_ghost lists. Even - * with this change, the data might be up to 1 second - * out of date; but that should suffice. The arc_state_t - * structures can be queried directly if more accurate - * information is needed. + * We're either no longer overflowing, or we + * can't evict anything more, so we should wake + * up any waiters. */ - if (arc_ksp != NULL) - arc_ksp->ks_update(arc_ksp, KSTAT_READ); + cv_broadcast(&arc_adjust_waiters_cv); + } + mutex_exit(&arc_adjust_lock); - mutex_exit(&arc_reclaim_lock); + return (0); +} +/* ARGSUSED */ +static boolean_t +arc_reap_cb_check(void *arg, zthr_t *zthr) +{ + int64_t free_memory = arc_available_memory(); + + /* + * If a kmem reap is already active, don't schedule more. We must + * check for this because kmem_cache_reap_soon() won't actually + * block on the cache being reaped (this is to prevent callers from + * becoming implicitly blocked by a system-wide kmem reap -- which, + * on a system with many, many full magazines, can take minutes). + */ + if (!kmem_cache_reap_active() && + free_memory < 0) { + arc_no_grow = B_TRUE; + arc_warm = B_TRUE; /* - * We call arc_adjust() before (possibly) calling - * arc_kmem_reap_now(), so that we can wake up - * arc_get_data_impl() sooner. + * Wait at least zfs_grow_retry (default 60) seconds + * before considering growing. */ - evicted = arc_adjust(); + arc_growtime = gethrtime() + SEC2NSEC(arc_grow_retry); + return (B_TRUE); + } else if (free_memory < arc_c >> arc_no_grow_shift) { + arc_no_grow = B_TRUE; + } else if (gethrtime() >= arc_growtime) { + arc_no_grow = B_FALSE; + } - int64_t free_memory = arc_available_memory(); - if (free_memory < 0) { - hrtime_t curtime = gethrtime(); - arc_no_grow = B_TRUE; - arc_warm = B_TRUE; + return (B_FALSE); +} - /* - * Wait at least zfs_grow_retry (default 60) seconds - * before considering growing. - */ - growtime = curtime + SEC2NSEC(arc_grow_retry); +/* + * Keep enough free memory in the system by reaping the ARC's kmem + * caches. To cause more slabs to be reapable, we may reduce the + * target size of the cache (arc_c), causing the arc_adjust_cb() + * to free more buffers. + */ +/* ARGSUSED */ +static int +arc_reap_cb(void *arg, zthr_t *zthr) +{ + int64_t free_memory; - /* - * Wait at least arc_kmem_cache_reap_retry_ms - * between arc_kmem_reap_now() calls. Without - * this check it is possible to end up in a - * situation where we spend lots of time - * reaping caches, while we're near arc_c_min. - */ - if (curtime >= kmem_reap_time) { - arc_kmem_reap_now(); - kmem_reap_time = gethrtime() + - MSEC2NSEC(arc_kmem_cache_reap_retry_ms); - } + /* + * Kick off asynchronous kmem_reap()'s of all our caches. + */ + arc_kmem_reap_soon(); - /* - * If we are still low on memory, shrink the ARC - * so that we have arc_shrink_min free space. - */ - free_memory = arc_available_memory(); + /* + * Wait at least arc_kmem_cache_reap_retry_ms between + * arc_kmem_reap_soon() calls. Without this check it is possible to + * end up in a situation where we spend lots of time reaping + * caches, while we're near arc_c_min. Waiting here also gives the + * subsequent free memory check a chance of finding that the + * asynchronous reap has already freed enough memory, and we don't + * need to call arc_reduce_target_size(). + */ + delay((hz * arc_kmem_cache_reap_retry_ms + 999) / 1000); - int64_t to_free = - (arc_c >> arc_shrink_shift) - free_memory; - if (to_free > 0) { + /* + * Reduce the target size as needed to maintain the amount of free + * memory in the system at a fraction of the arc_size (1/128th by + * default). If oversubscribed (free_memory < 0) then reduce the + * target arc_size by the deficit amount plus the fractional + * amount. If free memory is positive but less then the fractional + * amount, reduce by what is needed to hit the fractional amount. + */ + free_memory = arc_available_memory(); + + int64_t to_free = + (arc_c >> arc_shrink_shift) - free_memory; + if (to_free > 0) { #ifdef _KERNEL #ifdef illumos - to_free = MAX(to_free, ptob(needfree)); + to_free = MAX(to_free, ptob(needfree)); #endif #endif - evicted += arc_shrink(to_free); - } - } else if (free_memory < arc_c >> arc_no_grow_shift) { - arc_no_grow = B_TRUE; - } else if (gethrtime() >= growtime) { - arc_no_grow = B_FALSE; - } - - mutex_enter(&arc_reclaim_lock); - - /* - * If evicted is zero, we couldn't evict anything via - * arc_adjust(). This could be due to hash lock - * collisions, but more likely due to the majority of - * arc buffers being unevictable. Therefore, even if - * arc_size is above arc_c, another pass is unlikely to - * be helpful and could potentially cause us to enter an - * infinite loop. - */ - if (aggsum_compare(&arc_size, arc_c) <= 0|| evicted == 0) { - /* - * We're either no longer overflowing, or we - * can't evict anything more, so we should wake - * up any threads before we go to sleep. - */ - cv_broadcast(&arc_reclaim_waiters_cv); - - /* - * Block until signaled, or after one second (we - * might need to perform arc_kmem_reap_now() - * even if we aren't being signalled) - */ - CALLB_CPR_SAFE_BEGIN(&cpr); - (void) cv_timedwait_hires(&arc_reclaim_thread_cv, - &arc_reclaim_lock, SEC2NSEC(1), MSEC2NSEC(1), 0); - CALLB_CPR_SAFE_END(&cpr, &arc_reclaim_lock); - } + arc_reduce_target_size(to_free); } - arc_reclaim_thread_exit = B_FALSE; - cv_broadcast(&arc_reclaim_thread_cv); - CALLB_CPR_EXIT(&cpr); /* drops arc_reclaim_lock */ - thread_exit(); + return (0); } static u_int arc_dnlc_evicts_arg; @@ -5055,8 +5089,11 @@ arc_adapt(int bytes, arc_state_t *state) } ASSERT((int64_t)arc_p >= 0); + /* + * Wake reap thread if we do not have any available memory + */ if (arc_reclaim_needed()) { - cv_signal(&arc_reclaim_thread_cv); + zthr_wakeup(arc_reap_zthr); return; } @@ -5164,7 +5201,7 @@ arc_get_data_impl(arc_buf_hdr_t *hdr, uint64_t size, v * overflowing; thus we don't use a while loop here. */ if (arc_is_overflowing()) { - mutex_enter(&arc_reclaim_lock); + mutex_enter(&arc_adjust_lock); /* * Now that we've acquired the lock, we may no longer be @@ -5178,11 +5215,12 @@ arc_get_data_impl(arc_buf_hdr_t *hdr, uint64_t size, v * shouldn't cause any harm. */ if (arc_is_overflowing()) { - cv_signal(&arc_reclaim_thread_cv); - cv_wait(&arc_reclaim_waiters_cv, &arc_reclaim_lock); + arc_adjust_needed = B_TRUE; + zthr_wakeup(arc_adjust_zthr); + (void) cv_wait(&arc_adjust_waiters_cv, + &arc_adjust_lock); } - - mutex_exit(&arc_reclaim_lock); + mutex_exit(&arc_adjust_lock); } VERIFY3U(hdr->b_type, ==, type); @@ -6898,19 +6936,28 @@ static eventhandler_tag arc_event_lowmem = NULL; static void arc_lowmem(void *arg __unused, int howto __unused) { + int64_t free_memory, to_free; - mutex_enter(&arc_reclaim_lock); - DTRACE_PROBE1(arc__needfree, int64_t, ((int64_t)freemem - zfs_arc_free_target) * PAGESIZE); - cv_signal(&arc_reclaim_thread_cv); + arc_no_grow = B_TRUE; + arc_warm = B_TRUE; + arc_growtime = gethrtime() + SEC2NSEC(arc_grow_retry); + free_memory = arc_available_memory(); + to_free = (arc_c >> arc_shrink_shift) - MIN(free_memory, 0); + DTRACE_PROBE2(arc__needfree, int64_t, free_memory, int64_t, to_free); + arc_reduce_target_size(to_free); + mutex_enter(&arc_adjust_lock); + arc_adjust_needed = B_TRUE; + zthr_wakeup(arc_adjust_zthr); + /* * It is unsafe to block here in arbitrary threads, because we can come * here from ARC itself and may hold ARC locks and thus risk a deadlock * with ARC reclaim thread. */ if (curproc == pageproc) - (void) cv_wait(&arc_reclaim_waiters_cv, &arc_reclaim_lock); - mutex_exit(&arc_reclaim_lock); + (void) cv_wait(&arc_adjust_waiters_cv, &arc_adjust_lock); + mutex_exit(&arc_adjust_lock); } #endif @@ -7052,12 +7099,9 @@ arc_init(void) #else uint64_t allmem = kmem_size(); #endif + mutex_init(&arc_adjust_lock, NULL, MUTEX_DEFAULT, NULL); + cv_init(&arc_adjust_waiters_cv, NULL, CV_DEFAULT, NULL); - - mutex_init(&arc_reclaim_lock, NULL, MUTEX_DEFAULT, NULL); - cv_init(&arc_reclaim_thread_cv, NULL, CV_DEFAULT, NULL); - cv_init(&arc_reclaim_waiters_cv, NULL, CV_DEFAULT, NULL); - mutex_init(&arc_dnlc_evicts_lock, NULL, MUTEX_DEFAULT, NULL); cv_init(&arc_dnlc_evicts_cv, NULL, CV_DEFAULT, NULL); @@ -7159,6 +7203,13 @@ arc_init(void) zfs_arc_max = arc_c_max; arc_state_init(); + + /* + * The arc must be "uninitialized", so that hdr_recl() (which is + * registered by buf_init()) will not access arc_reap_zthr before + * it is created. + */ + ASSERT(!arc_initialized); buf_init(); list_create(&arc_prune_list, sizeof (arc_prune_t), @@ -7168,7 +7219,6 @@ arc_init(void) arc_prune_taskq = taskq_create("arc_prune", max_ncpus, minclsyspri, max_ncpus, INT_MAX, TASKQ_PREPOPULATE | TASKQ_DYNAMIC); - arc_reclaim_thread_exit = B_FALSE; arc_dnlc_evicts_thread_exit = FALSE; arc_ksp = kstat_create("zfs", 0, "arcstats", "misc", KSTAT_TYPE_NAMED, @@ -7180,8 +7230,10 @@ arc_init(void) kstat_install(arc_ksp); } - (void) thread_create(NULL, 0, arc_reclaim_thread, NULL, 0, &p0, - TS_RUN, minclsyspri); + arc_adjust_zthr = zthr_create_timer(arc_adjust_cb_check, + arc_adjust_cb, NULL, SEC2NSEC(1)); + arc_reap_zthr = zthr_create_timer(arc_reap_cb_check, + arc_reap_cb, NULL, SEC2NSEC(1)); #ifdef _KERNEL arc_event_lowmem = EVENTHANDLER_REGISTER(vm_lowmem, arc_lowmem, NULL, @@ -7191,7 +7243,7 @@ arc_init(void) (void) thread_create(NULL, 0, arc_dnlc_evicts_thread, NULL, 0, &p0, TS_RUN, minclsyspri); - arc_dead = B_FALSE; + arc_initialized = B_TRUE; arc_warm = B_FALSE; /* @@ -7256,18 +7308,6 @@ arc_fini(void) EVENTHANDLER_DEREGISTER(vm_lowmem, arc_event_lowmem); #endif - mutex_enter(&arc_reclaim_lock); - arc_reclaim_thread_exit = B_TRUE; - /* - * The reclaim thread will set arc_reclaim_thread_exit back to - * B_FALSE when it is finished exiting; we're waiting for that. - */ - while (arc_reclaim_thread_exit) { - cv_signal(&arc_reclaim_thread_cv); - cv_wait(&arc_reclaim_thread_cv, &arc_reclaim_lock); - } - mutex_exit(&arc_reclaim_lock); - /* Use B_TRUE to ensure *all* buffers are evicted */ arc_flush(NULL, B_TRUE); @@ -7283,7 +7323,7 @@ arc_fini(void) } mutex_exit(&arc_dnlc_evicts_lock); - arc_dead = B_TRUE; + arc_initialized = B_FALSE; if (arc_ksp != NULL) { kstat_delete(arc_ksp); @@ -7304,12 +7344,18 @@ arc_fini(void) list_destroy(&arc_prune_list); mutex_destroy(&arc_prune_mtx); - mutex_destroy(&arc_reclaim_lock); - cv_destroy(&arc_reclaim_thread_cv); - cv_destroy(&arc_reclaim_waiters_cv); + (void) zthr_cancel(arc_adjust_zthr); + zthr_destroy(arc_adjust_zthr); + mutex_destroy(&arc_dnlc_evicts_lock); cv_destroy(&arc_dnlc_evicts_cv); + + (void) zthr_cancel(arc_reap_zthr); + zthr_destroy(arc_reap_zthr); + + mutex_destroy(&arc_adjust_lock); + cv_destroy(&arc_adjust_waiters_cv); arc_state_fini(); buf_fini(); Modified: stable/12/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zthr.h ============================================================================== --- stable/12/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zthr.h Thu Apr 25 14:39:52 2019 (r346673) +++ stable/12/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zthr.h Thu Apr 25 14:41:29 2019 (r346674) @@ -29,6 +29,7 @@ struct zthr { kmutex_t zthr_lock; kcondvar_t zthr_cv; boolean_t zthr_cancel; + hrtime_t zthr_wait_time; zthr_checkfunc_t *zthr_checkfunc; zthr_func_t *zthr_func; @@ -38,6 +39,9 @@ struct zthr { extern zthr_t *zthr_create(zthr_checkfunc_t checkfunc, zthr_func_t *func, void *arg); +extern zthr_t *zthr_create_timer(zthr_checkfunc_t *checkfunc, + zthr_func_t *func, void *arg, hrtime_t nano_wait); + extern void zthr_exit(zthr_t *t, int rc); extern void zthr_destroy(zthr_t *t); Modified: stable/12/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zthr.c ============================================================================== --- stable/12/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zthr.c Thu Apr 25 14:39:52 2019 (r346673) +++ stable/12/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zthr.c Thu Apr 25 14:41:29 2019 (r346674) @@ -47,6 +47,10 @@ * 3] When the zthr is done, it changes the indicator to stopped, allowing * a new cycle to start. * + * Besides being awakened by other threads, a zthr can be configured + * during creation to wakeup on it's own after a specified interval + * [see zthr_create_timer()]. + * * == ZTHR creation * * Every zthr needs three inputs to start running: @@ -74,6 +78,9 @@ * * To start a zthr: * zthr_t *zthr_pointer = zthr_create(checkfunc, func, args); + * or + * zthr_t *zthr_pointer = zthr_create_timer(checkfunc, func, + * args, max_sleep); * * After that you should be able to wakeup, cancel, and resume the * zthr from another thread using zthr_pointer. @@ -189,7 +196,13 @@ zthr_procedure(void *arg) mutex_enter(&t->zthr_lock); } else { /* go to sleep */ - cv_wait(&t->zthr_cv, &t->zthr_lock); + if (t->zthr_wait_time == 0) { + cv_wait(&t->zthr_cv, &t->zthr_lock); + } else { + (void) cv_timedwait_hires(&t->zthr_cv, + &t->zthr_lock, t->zthr_wait_time, + MSEC2NSEC(1), 0); + } } } mutex_exit(&t->zthr_lock); @@ -200,6 +213,18 @@ zthr_procedure(void *arg) zthr_t * zthr_create(zthr_checkfunc_t *checkfunc, zthr_func_t *func, void *arg) { + return (zthr_create_timer(checkfunc, func, arg, (hrtime_t)0)); +} + +/* + * Create a zthr with specified maximum sleep time. If the time + * in sleeping state exceeds max_sleep, a wakeup(do the check and + * start working if required) will be triggered. + */ +zthr_t * +zthr_create_timer(zthr_checkfunc_t *checkfunc, zthr_func_t *func, + void *arg, hrtime_t max_sleep) +{ zthr_t *t = kmem_zalloc(sizeof (*t), KM_SLEEP); mutex_init(&t->zthr_lock, NULL, MUTEX_DEFAULT, NULL); cv_init(&t->zthr_cv, NULL, CV_DEFAULT, NULL); @@ -208,6 +233,7 @@ zthr_create(zthr_checkfunc_t *checkfunc, zthr_func_t * t->zthr_checkfunc = checkfunc; t->zthr_func = func; t->zthr_arg = arg; + t->zthr_wait_time = max_sleep; t->zthr_thread = thread_create(NULL, 0, zthr_procedure, t, 0, &p0, TS_RUN, minclsyspri); From owner-svn-src-stable-12@freebsd.org Thu Apr 25 21:04:40 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 5BF3D15A2741; Thu, 25 Apr 2019 21:04:40 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 002A06BB2F; Thu, 25 Apr 2019 21:04:40 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id D60471652; Thu, 25 Apr 2019 21:04:39 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3PL4dwm070793; Thu, 25 Apr 2019 21:04:39 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3PL4dLm070790; Thu, 25 Apr 2019 21:04:39 GMT (envelope-from mav@FreeBSD.org) Message-Id: <201904252104.x3PL4dLm070790@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Thu, 25 Apr 2019 21:04:39 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346706 - in stable/12: sys/amd64/vmm/intel usr.sbin/bhyve X-SVN-Group: stable-12 X-SVN-Commit-Author: mav X-SVN-Commit-Paths: in stable/12: sys/amd64/vmm/intel usr.sbin/bhyve X-SVN-Commit-Revision: 346706 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 002A06BB2F X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.96 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-0.99)[-0.995,0]; NEURAL_HAM_SHORT(-0.96)[-0.962,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Apr 2019 21:04:40 -0000 Author: mav Date: Thu Apr 25 21:04:38 2019 New Revision: 346706 URL: https://svnweb.freebsd.org/changeset/base/346706 Log: MFC r339826 (by yuripv): Provide basic descriptions for VMX exit reason (from "Intel 64 and IA-32 Architectures Software Developer’s Manual Volume 3"). Add the document to SEE ALSO in bhyve.8 (and pet manlint here a bit). Modified: stable/12/sys/amd64/vmm/intel/vmcs.h stable/12/usr.sbin/bhyve/bhyve.8 stable/12/usr.sbin/bhyve/bhyverun.c Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/amd64/vmm/intel/vmcs.h ============================================================================== --- stable/12/sys/amd64/vmm/intel/vmcs.h Thu Apr 25 20:48:25 2019 (r346705) +++ stable/12/sys/amd64/vmm/intel/vmcs.h Thu Apr 25 21:04:38 2019 (r346706) @@ -338,6 +338,14 @@ vmcs_write(uint32_t encoding, uint64_t val) #define EXIT_REASON_WBINVD 54 #define EXIT_REASON_XSETBV 55 #define EXIT_REASON_APIC_WRITE 56 +#define EXIT_REASON_RDRAND 57 +#define EXIT_REASON_INVPCID 58 +#define EXIT_REASON_VMFUNC 59 +#define EXIT_REASON_ENCLS 60 +#define EXIT_REASON_RDSEED 61 +#define EXIT_REASON_PM_LOG_FULL 62 +#define EXIT_REASON_XSAVES 63 +#define EXIT_REASON_XRSTORS 64 /* * NMI unblocking due to IRET. Modified: stable/12/usr.sbin/bhyve/bhyve.8 ============================================================================== --- stable/12/usr.sbin/bhyve/bhyve.8 Thu Apr 25 20:48:25 2019 (r346705) +++ stable/12/usr.sbin/bhyve/bhyve.8 Thu Apr 25 21:04:38 2019 (r346706) @@ -376,7 +376,11 @@ Emergency write is advertised, but no-op at present. .Pp Framebuffer devices: .Bl -tag -width 10n -.It Oo rfb= Ns Oo Ar IP: Oc Ns Ar port Oc Ns Oo ,w= Ns Ar width Oc Ns Oo ,h= Ns Ar height Oc Ns Oo ,vga= Ns Ar vgaconf Oc Ns Oo Ns ,wait Oc Ns Oo ,password= Ns Ar password Oc +.It Xo +.Oo rfb= Ns Oo Ar IP\&: Oc Ns Ar port Oc Ns Oo ,w= Ns Ar width Oc Ns Oo ,h= Ns +.Ar height Oc Ns Oo ,vga= Ns Ar vgaconf Oc Ns Oo Ns ,wait Oc Ns Oo ,password= Ns +.Ar password Oc +.Xc .Bl -tag -width 8n .It Ar IPv4:port No or Ar [IPv6%zone]:port An @@ -407,8 +411,8 @@ and memory space .Pq 64KB at Ad 0xA0000 . The default .Dq io -option should be used for guests that attempt to issue BIOS -calls which result in I/O port queries, and fail to boot if I/O decode is disabled. +option should be used for guests that attempt to issue BIOS calls which result +in I/O port queries, and fail to boot if I/O decode is disabled. .Pp The .Dq on @@ -433,8 +437,8 @@ for configuration notes of particular guests. .It wait Instruct .Nm -to only boot upon the initiation of a VNC connection, simplifying the installation -of operating systems that require immediate keyboard input. +to only boot upon the initiation of a VNC connection, simplifying the +installation of operating systems that require immediate keyboard input. This can be removed for post-installation use. .It password This type of authentication is known to be cryptographically weak and is not @@ -506,8 +510,9 @@ General purpose registers can be queried for each virt registers such as floating-point and system registers cannot be queried. .Ss Memory Memory (including memory mapped I/O regions) can be read by the debugger, -but not written. Memory operations use virtual addresses that are resolved -to physical addresses via the current virtual CPU's active address translation. +but not written. +Memory operations use virtual addresses that are resolved to physical addresses +via the current virtual CPU's active address translation. .Ss Control The running guest can be interrupted by the debugger at any time .Pq for example, by pressing Ctrl-C in the debugger . @@ -618,6 +623,12 @@ bhyve -c 2 -m 4G -w -H \\ .Xr ethers 5 , .Xr bhyvectl 8 , .Xr bhyveload 8 +.Pp +.Rs +.%A Intel +.%B 64 and IA-32 Architectures Software Developer’s Manual +.%V Volume 3 +.Re .Sh HISTORY .Nm first appeared in Modified: stable/12/usr.sbin/bhyve/bhyverun.c ============================================================================== --- stable/12/usr.sbin/bhyve/bhyverun.c Thu Apr 25 20:48:25 2019 (r346705) +++ stable/12/usr.sbin/bhyve/bhyverun.c Thu Apr 25 21:04:38 2019 (r346706) @@ -38,6 +38,8 @@ __FBSDID("$FreeBSD$"); #include #include +#include + #include #include @@ -89,6 +91,73 @@ __FBSDID("$FreeBSD$"); #define MB (1024UL * 1024) #define GB (1024UL * MB) +static const char * const vmx_exit_reason_desc[] = { + [EXIT_REASON_EXCEPTION] = "Exception or non-maskable interrupt (NMI)", + [EXIT_REASON_EXT_INTR] = "External interrupt", + [EXIT_REASON_TRIPLE_FAULT] = "Triple fault", + [EXIT_REASON_INIT] = "INIT signal", + [EXIT_REASON_SIPI] = "Start-up IPI (SIPI)", + [EXIT_REASON_IO_SMI] = "I/O system-management interrupt (SMI)", + [EXIT_REASON_SMI] = "Other SMI", + [EXIT_REASON_INTR_WINDOW] = "Interrupt window", + [EXIT_REASON_NMI_WINDOW] = "NMI window", + [EXIT_REASON_TASK_SWITCH] = "Task switch", + [EXIT_REASON_CPUID] = "CPUID", + [EXIT_REASON_GETSEC] = "GETSEC", + [EXIT_REASON_HLT] = "HLT", + [EXIT_REASON_INVD] = "INVD", + [EXIT_REASON_INVLPG] = "INVLPG", + [EXIT_REASON_RDPMC] = "RDPMC", + [EXIT_REASON_RDTSC] = "RDTSC", + [EXIT_REASON_RSM] = "RSM", + [EXIT_REASON_VMCALL] = "VMCALL", + [EXIT_REASON_VMCLEAR] = "VMCLEAR", + [EXIT_REASON_VMLAUNCH] = "VMLAUNCH", + [EXIT_REASON_VMPTRLD] = "VMPTRLD", + [EXIT_REASON_VMPTRST] = "VMPTRST", + [EXIT_REASON_VMREAD] = "VMREAD", + [EXIT_REASON_VMRESUME] = "VMRESUME", + [EXIT_REASON_VMWRITE] = "VMWRITE", + [EXIT_REASON_VMXOFF] = "VMXOFF", + [EXIT_REASON_VMXON] = "VMXON", + [EXIT_REASON_CR_ACCESS] = "Control-register accesses", + [EXIT_REASON_DR_ACCESS] = "MOV DR", + [EXIT_REASON_INOUT] = "I/O instruction", + [EXIT_REASON_RDMSR] = "RDMSR", + [EXIT_REASON_WRMSR] = "WRMSR", + [EXIT_REASON_INVAL_VMCS] = + "VM-entry failure due to invalid guest state", + [EXIT_REASON_INVAL_MSR] = "VM-entry failure due to MSR loading", + [EXIT_REASON_MWAIT] = "MWAIT", + [EXIT_REASON_MTF] = "Monitor trap flag", + [EXIT_REASON_MONITOR] = "MONITOR", + [EXIT_REASON_PAUSE] = "PAUSE", + [EXIT_REASON_MCE_DURING_ENTRY] = + "VM-entry failure due to machine-check event", + [EXIT_REASON_TPR] = "TPR below threshold", + [EXIT_REASON_APIC_ACCESS] = "APIC access", + [EXIT_REASON_VIRTUALIZED_EOI] = "Virtualized EOI", + [EXIT_REASON_GDTR_IDTR] = "Access to GDTR or IDTR", + [EXIT_REASON_LDTR_TR] = "Access to LDTR or TR", + [EXIT_REASON_EPT_FAULT] = "EPT violation", + [EXIT_REASON_EPT_MISCONFIG] = "EPT misconfiguration", + [EXIT_REASON_INVEPT] = "INVEPT", + [EXIT_REASON_RDTSCP] = "RDTSCP", + [EXIT_REASON_VMX_PREEMPT] = "VMX-preemption timer expired", + [EXIT_REASON_INVVPID] = "INVVPID", + [EXIT_REASON_WBINVD] = "WBINVD", + [EXIT_REASON_XSETBV] = "XSETBV", + [EXIT_REASON_APIC_WRITE] = "APIC write", + [EXIT_REASON_RDRAND] = "RDRAND", + [EXIT_REASON_INVPCID] = "INVPCID", + [EXIT_REASON_VMFUNC] = "VMFUNC", + [EXIT_REASON_ENCLS] = "ENCLS", + [EXIT_REASON_RDSEED] = "RDSEED", + [EXIT_REASON_PM_LOG_FULL] = "Page-modification log full", + [EXIT_REASON_XSAVES] = "XSAVES", + [EXIT_REASON_XRSTORS] = "XRSTORS" +}; + typedef int (*vmexit_handler_t)(struct vmctx *, struct vm_exit *, int *vcpu); extern int vmexit_task_switch(struct vmctx *, struct vm_exit *, int *vcpu); @@ -506,14 +575,22 @@ vmexit_spinup_ap(struct vmctx *ctx, struct vm_exit *vm #define DEBUG_EPT_MISCONFIG #ifdef DEBUG_EPT_MISCONFIG -#define EXIT_REASON_EPT_MISCONFIG 49 #define VMCS_GUEST_PHYSICAL_ADDRESS 0x00002400 -#define VMCS_IDENT(x) ((x) | 0x80000000) static uint64_t ept_misconfig_gpa, ept_misconfig_pte[4]; static int ept_misconfig_ptenum; #endif +static const char * +vmexit_vmx_desc(uint32_t exit_reason) +{ + + if (exit_reason >= nitems(vmx_exit_reason_desc) || + vmx_exit_reason_desc[exit_reason] == NULL) + return ("Unknown"); + return (vmx_exit_reason_desc[exit_reason]); +} + static int vmexit_vmx(struct vmctx *ctx, struct vm_exit *vmexit, int *pvcpu) { @@ -523,7 +600,8 @@ vmexit_vmx(struct vmctx *ctx, struct vm_exit *vmexit, fprintf(stderr, "\trip\t\t0x%016lx\n", vmexit->rip); fprintf(stderr, "\tinst_length\t%d\n", vmexit->inst_length); fprintf(stderr, "\tstatus\t\t%d\n", vmexit->u.vmx.status); - fprintf(stderr, "\texit_reason\t%u\n", vmexit->u.vmx.exit_reason); + fprintf(stderr, "\texit_reason\t%u (%s)\n", vmexit->u.vmx.exit_reason, + vmexit_vmx_desc(vmexit->u.vmx.exit_reason)); fprintf(stderr, "\tqualification\t0x%016lx\n", vmexit->u.vmx.exit_qualification); fprintf(stderr, "\tinst_type\t\t%d\n", vmexit->u.vmx.inst_type); From owner-svn-src-stable-12@freebsd.org Thu Apr 25 21:28:31 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 33EF915A2E35; Thu, 25 Apr 2019 21:28:31 +0000 (UTC) (envelope-from rgrimes@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id A37626C93D; Thu, 25 Apr 2019 21:28:30 +0000 (UTC) (envelope-from rgrimes@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 89D2719C3; Thu, 25 Apr 2019 21:28:30 +0000 (UTC) (envelope-from rgrimes@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3PLSUiZ081932; Thu, 25 Apr 2019 21:28:30 GMT (envelope-from rgrimes@FreeBSD.org) Received: (from rgrimes@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3PLSSPk081924; Thu, 25 Apr 2019 21:28:28 GMT (envelope-from rgrimes@FreeBSD.org) Message-Id: <201904252128.x3PLSSPk081924@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: rgrimes set sender to rgrimes@FreeBSD.org using -f From: "Rodney W. Grimes" Date: Thu, 25 Apr 2019 21:28:28 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346710 - in stable/12: lib/libc/net sys/fs/nfsclient sys/netinet sys/netinet/netdump sys/netpfil/ipfw/nat64 sys/netpfil/pf X-SVN-Group: stable-12 X-SVN-Commit-Author: rgrimes X-SVN-Commit-Paths: in stable/12: lib/libc/net sys/fs/nfsclient sys/netinet sys/netinet/netdump sys/netpfil/ipfw/nat64 sys/netpfil/pf X-SVN-Commit-Revision: 346710 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: A37626C93D X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.96 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-0.99)[-0.994,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.96)[-0.961,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Apr 2019 21:28:31 -0000 Author: rgrimes Date: Thu Apr 25 21:28:28 2019 New Revision: 346710 URL: https://svnweb.freebsd.org/changeset/base/346710 Log: MFC: r345888: Use IN_foo() macros from sys/netinet/in.h inplace of handcrafted code There are a few places that use hand crafted versions of the macros from sys/netinet/in.h making it difficult to actually alter the values in use by these macros. Correct that by replacing handcrafted code with proper macro usage. Reviewed by: karels, kristof Approved by: bde (mentor, implicit) Sponsored by: John Gilmore Differential Revision: https://reviews.freebsd.org/D19317 Modified: stable/12/lib/libc/net/getnameinfo.c stable/12/sys/fs/nfsclient/nfs_clport.c stable/12/sys/netinet/in.c stable/12/sys/netinet/ip_input.c stable/12/sys/netinet/ip_output.c stable/12/sys/netinet/netdump/netdump_client.c stable/12/sys/netpfil/ipfw/nat64/nat64_translate.h stable/12/sys/netpfil/pf/pf.c Directory Properties: stable/12/ (props changed) Modified: stable/12/lib/libc/net/getnameinfo.c ============================================================================== --- stable/12/lib/libc/net/getnameinfo.c Thu Apr 25 21:25:32 2019 (r346709) +++ stable/12/lib/libc/net/getnameinfo.c Thu Apr 25 21:28:28 2019 (r346710) @@ -224,10 +224,8 @@ getnameinfo_inet(const struct afd *afd, case AF_INET: v4a = (u_int32_t) ntohl(((const struct sockaddr_in *)sa)->sin_addr.s_addr); - if (IN_MULTICAST(v4a) || IN_EXPERIMENTAL(v4a)) - flags |= NI_NUMERICHOST; - v4a >>= IN_CLASSA_NSHIFT; - if (v4a == 0) + if (IN_MULTICAST(v4a) || IN_EXPERIMENTAL(v4a) || + IN_ZERONET(v4a)) flags |= NI_NUMERICHOST; break; #ifdef INET6 Modified: stable/12/sys/fs/nfsclient/nfs_clport.c ============================================================================== --- stable/12/sys/fs/nfsclient/nfs_clport.c Thu Apr 25 21:25:32 2019 (r346709) +++ stable/12/sys/fs/nfsclient/nfs_clport.c Thu Apr 25 21:28:28 2019 (r346710) @@ -957,8 +957,7 @@ nfscl_getmyip(struct nfsmount *nmp, struct in6_addr *p if (error != 0) return (NULL); - if ((ntohl(nh_ext.nh_src.s_addr) >> IN_CLASSA_NSHIFT) == - IN_LOOPBACKNET) { + if (IN_LOOPBACK(ntohl(nh_ext.nh_src.s_addr))) { /* Ignore loopback addresses */ return (NULL); } Modified: stable/12/sys/netinet/in.c ============================================================================== --- stable/12/sys/netinet/in.c Thu Apr 25 21:25:32 2019 (r346709) +++ stable/12/sys/netinet/in.c Thu Apr 25 21:28:28 2019 (r346710) @@ -190,15 +190,10 @@ int in_canforward(struct in_addr in) { u_long i = ntohl(in.s_addr); - u_long net; - if (IN_EXPERIMENTAL(i) || IN_MULTICAST(i) || IN_LINKLOCAL(i)) + if (IN_EXPERIMENTAL(i) || IN_MULTICAST(i) || IN_LINKLOCAL(i) || + IN_ZERONET(i) || IN_LOOPBACK(i)) return (0); - if (IN_CLASSA(i)) { - net = i & IN_CLASSA_NET; - if (net == 0 || net == (IN_LOOPBACKNET << IN_CLASSA_NSHIFT)) - return (0); - } return (1); } Modified: stable/12/sys/netinet/ip_input.c ============================================================================== --- stable/12/sys/netinet/ip_input.c Thu Apr 25 21:25:32 2019 (r346709) +++ stable/12/sys/netinet/ip_input.c Thu Apr 25 21:28:28 2019 (r346710) @@ -501,10 +501,10 @@ ip_input(struct mbuf *m) IP_PROBE(receive, NULL, NULL, ip, m->m_pkthdr.rcvif, ip, NULL); - /* 127/8 must not appear on wire - RFC1122 */ + /* IN_LOOPBACK must not appear on the wire - RFC1122 */ ifp = m->m_pkthdr.rcvif; - if ((ntohl(ip->ip_dst.s_addr) >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET || - (ntohl(ip->ip_src.s_addr) >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET) { + if (IN_LOOPBACK(ntohl(ip->ip_dst.s_addr)) || + IN_LOOPBACK(ntohl(ip->ip_src.s_addr))) { if ((ifp->if_flags & IFF_LOOPBACK) == 0) { IPSTAT_INC(ips_badaddr); goto bad; Modified: stable/12/sys/netinet/ip_output.c ============================================================================== --- stable/12/sys/netinet/ip_output.c Thu Apr 25 21:25:32 2019 (r346709) +++ stable/12/sys/netinet/ip_output.c Thu Apr 25 21:28:28 2019 (r346710) @@ -588,9 +588,9 @@ sendit: } } - /* 127/8 must not appear on wire - RFC1122. */ - if ((ntohl(ip->ip_dst.s_addr) >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET || - (ntohl(ip->ip_src.s_addr) >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET) { + /* IN_LOOPBACK must not appear on the wire - RFC1122. */ + if (IN_LOOPBACK(ntohl(ip->ip_dst.s_addr)) || + IN_LOOPBACK(ntohl(ip->ip_src.s_addr))) { if ((ifp->if_flags & IFF_LOOPBACK) == 0) { IPSTAT_INC(ips_badaddr); error = EADDRNOTAVAIL; Modified: stable/12/sys/netinet/netdump/netdump_client.c ============================================================================== --- stable/12/sys/netinet/netdump/netdump_client.c Thu Apr 25 21:25:32 2019 (r346709) +++ stable/12/sys/netinet/netdump/netdump_client.c Thu Apr 25 21:28:28 2019 (r346710) @@ -557,8 +557,8 @@ netdump_handle_ip(struct mbuf **mb) } #ifdef INVARIANTS - if (((ntohl(ip->ip_dst.s_addr) >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET || - (ntohl(ip->ip_src.s_addr) >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET) && + if ((IN_LOOPBACK(ntohl(ip->ip_dst.s_addr)) || + IN_LOOPBACK(ntohl(ip->ip_src.s_addr))) && (m->m_pkthdr.rcvif->if_flags & IFF_LOOPBACK) == 0) { NETDDEBUG("Bad IP header (RFC1122)\n"); return; Modified: stable/12/sys/netpfil/ipfw/nat64/nat64_translate.h ============================================================================== --- stable/12/sys/netpfil/ipfw/nat64/nat64_translate.h Thu Apr 25 21:25:32 2019 (r346709) +++ stable/12/sys/netpfil/ipfw/nat64/nat64_translate.h Thu Apr 25 21:28:28 2019 (r346710) @@ -123,14 +123,9 @@ static inline int nat64_check_ip4(in_addr_t ia) { - /* IN_LOOPBACK */ - if ((ia & htonl(0xff000000)) == htonl(0x7f000000)) - return (1); - /* IN_LINKLOCAL */ - if ((ia & htonl(0xffff0000)) == htonl(0xa9fe0000)) - return (1); - /* IN_MULTICAST & IN_EXPERIMENTAL */ - if ((ia & htonl(0xe0000000)) == htonl(0xe0000000)) + /* These checks are ordered from most likely to least */ + if (IN_MULTICAST(ntohl(ia)) || IN_LOOPBACK(ntohl(ia)) || + IN_LINKLOCAL(ntohl(ia)) || IN_EXPERIMENTAL(ntohl(ia))) return (1); return (0); } Modified: stable/12/sys/netpfil/pf/pf.c ============================================================================== --- stable/12/sys/netpfil/pf/pf.c Thu Apr 25 21:25:32 2019 (r346709) +++ stable/12/sys/netpfil/pf/pf.c Thu Apr 25 21:28:28 2019 (r346710) @@ -6172,7 +6172,7 @@ done: pd.proto == IPPROTO_UDP) && s != NULL && s->nat_rule.ptr != NULL && (s->nat_rule.ptr->action == PF_RDR || s->nat_rule.ptr->action == PF_BINAT) && - (ntohl(pd.dst->v4.s_addr) >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET) + IN_LOOPBACK(ntohl(pd.dst->v4.s_addr))) m->m_flags |= M_SKIP_FIREWALL; if (action == PF_PASS && r->divert.port && ip_divert_ptr != NULL && From owner-svn-src-stable-12@freebsd.org Thu Apr 25 21:42:03 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A56CE15A31C3; Thu, 25 Apr 2019 21:42:03 +0000 (UTC) (envelope-from ngie@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 41F136CFBA; Thu, 25 Apr 2019 21:42:03 +0000 (UTC) (envelope-from ngie@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 1F9711CEF; Thu, 25 Apr 2019 21:42:03 +0000 (UTC) (envelope-from ngie@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3PLg3JP090230; Thu, 25 Apr 2019 21:42:03 GMT (envelope-from ngie@FreeBSD.org) Received: (from ngie@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3PLg3gH090229; Thu, 25 Apr 2019 21:42:03 GMT (envelope-from ngie@FreeBSD.org) Message-Id: <201904252142.x3PLg3gH090229@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ngie set sender to ngie@FreeBSD.org using -f From: Enji Cooper Date: Thu, 25 Apr 2019 21:42:02 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346711 - stable/12 X-SVN-Group: stable-12 X-SVN-Commit-Author: ngie X-SVN-Commit-Paths: stable/12 X-SVN-Commit-Revision: 346711 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 41F136CFBA X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.95 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-0.99)[-0.994,0]; NEURAL_HAM_SHORT(-0.96)[-0.960,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Apr 2019 21:42:03 -0000 Author: ngie Date: Thu Apr 25 21:42:02 2019 New Revision: 346711 URL: https://svnweb.freebsd.org/changeset/base/346711 Log: MFC r346056: Fix a typo when sanity checking in the bootstrap-tools target The path is incorrect for the linker in the error message. It should have been /usr/bin/ld, not /usr/bin/cc . Modified: stable/12/Makefile Directory Properties: stable/12/ (props changed) Modified: stable/12/Makefile ============================================================================== --- stable/12/Makefile Thu Apr 25 21:28:28 2019 (r346710) +++ stable/12/Makefile Thu Apr 25 21:42:02 2019 (r346711) @@ -570,7 +570,7 @@ universe-toolchain: .PHONY universe_prologue false; \ fi @if [ ! -e "${HOST_OBJTOP}/tmp/usr/bin/ld" ]; then \ - echo "Missing host linker at ${HOST_OBJTOP}/tmp/usr/bin/cc?" >&2; \ + echo "Missing host linker at ${HOST_OBJTOP}/tmp/usr/bin/ld?" >&2; \ false; \ fi @echo "--------------------------------------------------------------" From owner-svn-src-stable-12@freebsd.org Fri Apr 26 00:39:31 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id D11221582A8A; Fri, 26 Apr 2019 00:39:31 +0000 (UTC) (envelope-from mw@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 6952C72560; Fri, 26 Apr 2019 00:39:31 +0000 (UTC) (envelope-from mw@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4DC113CF7; Fri, 26 Apr 2019 00:39:31 +0000 (UTC) (envelope-from mw@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3Q0dVfd080820; Fri, 26 Apr 2019 00:39:31 GMT (envelope-from mw@FreeBSD.org) Received: (from mw@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3Q0dVMw080819; Fri, 26 Apr 2019 00:39:31 GMT (envelope-from mw@FreeBSD.org) Message-Id: <201904260039.x3Q0dVMw080819@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mw set sender to mw@FreeBSD.org using -f From: Marcin Wojtas Date: Fri, 26 Apr 2019 00:39:31 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346718 - stable/12/stand/efi/libefi X-SVN-Group: stable-12 X-SVN-Commit-Author: mw X-SVN-Commit-Paths: stable/12/stand/efi/libefi X-SVN-Commit-Revision: 346718 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 6952C72560 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.95 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-0.99)[-0.994,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.96)[-0.957,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Apr 2019 00:39:32 -0000 Author: mw Date: Fri Apr 26 00:39:30 2019 New Revision: 346718 URL: https://svnweb.freebsd.org/changeset/base/346718 Log: MFC r343911: Allow reading the UEFI variable size When loading bigger variables form UEFI it is necessary to know their size beforehand, so that an appropriate amount of memory can be allocated. The easiest way to do this is to try to read the variable with buffer size equal 0, expecting EFI_BUFFER_TOO_SMALL error to be returned. Allow such possible approach in efi_getenv routine. Submitted by: Kornel Duleba Obtained from: Semihalf Sponsored by: Stormshield Modified: stable/12/stand/efi/libefi/efienv.c Modified: stable/12/stand/efi/libefi/efienv.c ============================================================================== --- stable/12/stand/efi/libefi/efienv.c Thu Apr 25 22:53:55 2019 (r346717) +++ stable/12/stand/efi/libefi/efienv.c Fri Apr 26 00:39:30 2019 (r346718) @@ -49,7 +49,7 @@ efi_getenv(EFI_GUID *g, const char *v, void *data, siz return (EFI_OUT_OF_RESOURCES); dl = *len; rv = RS->GetVariable(uv, g, &attr, &dl, data); - if (rv == EFI_SUCCESS) + if (rv == EFI_SUCCESS || rv == EFI_BUFFER_TOO_SMALL) *len = dl; free(uv); return (rv); From owner-svn-src-stable-12@freebsd.org Fri Apr 26 00:48:56 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id D2BCF1582DE1; Fri, 26 Apr 2019 00:48:55 +0000 (UTC) (envelope-from mw@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 71163729FC; Fri, 26 Apr 2019 00:48:55 +0000 (UTC) (envelope-from mw@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 465063EAD; Fri, 26 Apr 2019 00:48:55 +0000 (UTC) (envelope-from mw@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3Q0mt0r086048; Fri, 26 Apr 2019 00:48:55 GMT (envelope-from mw@FreeBSD.org) Received: (from mw@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3Q0mr2o086036; Fri, 26 Apr 2019 00:48:53 GMT (envelope-from mw@FreeBSD.org) Message-Id: <201904260048.x3Q0mr2o086036@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mw set sender to mw@FreeBSD.org using -f From: Marcin Wojtas Date: Fri, 26 Apr 2019 00:48:53 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346719 - in stable/12: lib/libsecureboot lib/libsecureboot/efi lib/libsecureboot/h share/mk stand/efi/loader tools/build/options X-SVN-Group: stable-12 X-SVN-Commit-Author: mw X-SVN-Commit-Paths: in stable/12: lib/libsecureboot lib/libsecureboot/efi lib/libsecureboot/h share/mk stand/efi/loader tools/build/options X-SVN-Commit-Revision: 346719 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 71163729FC X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.96 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-0.99)[-0.995,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.96)[-0.963,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Apr 2019 00:48:56 -0000 Author: mw Date: Fri Apr 26 00:48:52 2019 New Revision: 346719 URL: https://svnweb.freebsd.org/changeset/base/346719 Log: MFC r344840: Extend libsecureboot(old libve) to obtain trusted certificates from UEFI and implement revocation UEFI related headers were copied from edk2. A new build option "MK_LOADER_EFI_SECUREBOOT" was added to allow loading of trusted anchors from UEFI. Certificate revocation support is also introduced. The forbidden certificates are loaded from dbx variable. Verification fails in two cases: There is a direct match between cert in dbx and the one in the chain. The CA used to sign the chain is found in dbx. One can also insert a hash of TBS section of a certificate into dbx. In this case verifications fails only if a direct match with a certificate in chain is found. Submitted by: Kornel Duleba Obtained from: Semihalf Sponsored by: Stormshield Added: stable/12/lib/libsecureboot/efi/ - copied from r344840, head/lib/libsecureboot/efi/ stable/12/tools/build/options/WITH_LOADER_EFI_SECUREBOOT - copied unchanged from r344840, head/tools/build/options/WITH_LOADER_EFI_SECUREBOOT Modified: stable/12/lib/libsecureboot/Makefile.inc stable/12/lib/libsecureboot/Makefile.libsa.inc stable/12/lib/libsecureboot/h/verify_file.h stable/12/lib/libsecureboot/libsecureboot-priv.h stable/12/lib/libsecureboot/local.trust.mk stable/12/lib/libsecureboot/verify_file.c stable/12/lib/libsecureboot/vets.c stable/12/share/mk/src.opts.mk stable/12/stand/efi/loader/Makefile stable/12/stand/efi/loader/main.c Modified: stable/12/lib/libsecureboot/Makefile.inc ============================================================================== --- stable/12/lib/libsecureboot/Makefile.inc Fri Apr 26 00:39:30 2019 (r346718) +++ stable/12/lib/libsecureboot/Makefile.inc Fri Apr 26 00:48:52 2019 (r346719) @@ -31,6 +31,17 @@ BRSSL_SRCS+= \ ${BEARSSL}/tools/xmem.c \ ${BEARSSL}/tools/vector.c +BRSSL_DEPS= \ + brf.c \ + vets.c \ + veta.c + +.if ${MK_LOADER_EFI_SECUREBOOT} != "no" +BRSSL_DEPS+= \ + efi_init.c \ + efi_variables.c +.endif + # we do not need/want nested objdirs OBJS_SRCS_FILTER = T R @@ -134,7 +145,7 @@ vse.h: echo 'NULL };' ) > ${.TARGET} -.for s in ${BRSSL_SRCS} brf.c vets.c veta.c +.for s in ${BRSSL_SRCS} ${BRSSL_DEPS} .ifdef BRSSL_SED $s: brssl.h .endif Modified: stable/12/lib/libsecureboot/Makefile.libsa.inc ============================================================================== --- stable/12/lib/libsecureboot/Makefile.libsa.inc Fri Apr 26 00:39:30 2019 (r346718) +++ stable/12/lib/libsecureboot/Makefile.libsa.inc Fri Apr 26 00:48:52 2019 (r346719) @@ -16,6 +16,19 @@ SRCS+= \ vepcr.c \ verify_file.c \ +# Build library with support for the UEFI based authentication +.if ${MK_LOADER_EFI_SECUREBOOT} == "yes" +SRCS+= \ + efi/efi_variables.c \ + efi/efi_init.c + +# Add includes required by efi part +CFLAGS+= \ + -I${SRCTOP}/stand/efi/include \ + -I${SRCTOP}/lib/libsecureboot/efi/include \ + -I${SRCTOP}/stand/efi/include/${MACHINE} +.endif + # this is the list of paths (relative to a file # that we need to verify) used to find a signed manifest. # the signature extensions in VE_SIGNATURE_EXT_LIST Modified: stable/12/lib/libsecureboot/h/verify_file.h ============================================================================== --- stable/12/lib/libsecureboot/h/verify_file.h Fri Apr 26 00:39:30 2019 (r346718) +++ stable/12/lib/libsecureboot/h/verify_file.h Fri Apr 26 00:48:52 2019 (r346719) @@ -40,6 +40,7 @@ struct stat; void ve_debug_set(int); int ve_status_get(int); +void ve_efi_init(void); int load_manifest(const char *, const char *, const char *, struct stat *); int verify_file(int, const char *, off_t, int); void verify_pcr_export(void); Modified: stable/12/lib/libsecureboot/libsecureboot-priv.h ============================================================================== --- stable/12/lib/libsecureboot/libsecureboot-priv.h Fri Apr 26 00:39:30 2019 (r346718) +++ stable/12/lib/libsecureboot/libsecureboot-priv.h Fri Apr 26 00:48:52 2019 (r346719) @@ -31,8 +31,15 @@ /* public api */ #include "libsecureboot.h" +typedef struct { + unsigned char *data; + size_t hash_size; +} hash_data; + size_t ve_trust_anchors_add(br_x509_certificate *, size_t); -char *fingerprint_info_lookup(int, const char *); +size_t ve_forbidden_anchors_add(br_x509_certificate *, size_t); +void ve_forbidden_digest_add(hash_data *digest, size_t); +char *fingerprint_info_lookup(int, const char *); br_x509_certificate * parse_certificates(unsigned char *, size_t, size_t *); int certificate_to_trust_anchor_inner(br_x509_trust_anchor *, @@ -44,5 +51,10 @@ int verify_rsa_digest(br_rsa_public_key *pkey, unsigned char *sdata, size_t slen); int openpgp_self_tests(void); + +int efi_secure_boot_enabled(void); +br_x509_certificate* efi_get_trusted_certs(size_t *count); +br_x509_certificate* efi_get_forbidden_certs(size_t *count); +hash_data* efi_get_forbidden_digests(size_t *count); #endif /* _LIBSECUREBOOT_PRIV_H_ */ Modified: stable/12/lib/libsecureboot/local.trust.mk ============================================================================== --- stable/12/lib/libsecureboot/local.trust.mk Fri Apr 26 00:39:30 2019 (r346718) +++ stable/12/lib/libsecureboot/local.trust.mk Fri Apr 26 00:48:52 2019 (r346719) @@ -7,27 +7,26 @@ # for each key will provide the appropriate certificate chain on request # force these for Junos -MANIFEST_SKIP_ALWAYS= boot +#MANIFEST_SKIP_ALWAYS= boot VE_HASH_LIST= \ SHA1 \ SHA256 \ - SHA384 + SHA384 \ + SHA512 VE_SIGNATURE_LIST= \ - ECDSA + ECDSA \ + RSA VE_SIGNATURE_EXT_LIST= \ - esig + esig \ + rsig VE_SELF_TESTS= yes .if ${MACHINE} == "host" && ${.CURDIR:T} == "tests" -# for testing -VE_HASH_LIST+= \ - SHA512 VE_SIGNATURE_LIST+= \ - RSA \ DEPRECATED_RSA_SHA1 VE_SIGNATURE_EXT_LIST+= \ @@ -88,7 +87,7 @@ vc_rsa.pem: rcerts.pem _2ndLAST_PEM_USE .endif # we take the mtime of this as our baseline time -BUILD_UTC_FILE= ecerts.pem +#BUILD_UTC_FILE= ecerts.pem #VE_DEBUG_LEVEL=3 #VE_VERBOSE_DEFAULT=1 @@ -97,7 +96,7 @@ BUILD_UTC_FILE= ecerts.pem .if empty(TRUST_ANCHORS) TRUST_ANCHORS!= cd ${.CURDIR} && 'ls' -1 *.pem t*.asc 2> /dev/null .endif -.if empty(TRUST_ANCHORS) +.if empty(TRUST_ANCHORS) && ${MK_LOADER_EFI_SECUREBOOT} != "yes" .error Need TRUST_ANCHORS see ${.CURDIR}/README.rst .endif .if ${TRUST_ANCHORS:T:Mt*.pem} != "" Modified: stable/12/lib/libsecureboot/verify_file.c ============================================================================== --- stable/12/lib/libsecureboot/verify_file.c Fri Apr 26 00:39:30 2019 (r346718) +++ stable/12/lib/libsecureboot/verify_file.c Fri Apr 26 00:48:52 2019 (r346719) @@ -346,7 +346,7 @@ verify_file(int fd, const char *filename, off_t off, i if (verbose || severity > VE_WANT) { #if defined(VE_DEBUG_LEVEL) && VE_DEBUG_LEVEL > 0 printf("Verified %s %llu,%llu\n", filename, - st.st_dev, st.st_ino); + (long long)st.st_dev, (long long)st.st_ino); #else printf("Verified %s\n", filename); #endif Modified: stable/12/lib/libsecureboot/vets.c ============================================================================== --- stable/12/lib/libsecureboot/vets.c Fri Apr 26 00:39:30 2019 (r346718) +++ stable/12/lib/libsecureboot/vets.c Fri Apr 26 00:48:52 2019 (r346719) @@ -49,8 +49,11 @@ __FBSDID("$FreeBSD$"); int DebugVe = 0; typedef VECTOR(br_x509_certificate) cert_list; +typedef VECTOR(hash_data) digest_list; static anchor_list trust_anchors = VEC_INIT; +static anchor_list forbidden_anchors = VEC_INIT; +static digest_list forbidden_digests = VEC_INIT; void ve_debug_set(int n) @@ -113,13 +116,76 @@ free_cert_contents(br_x509_certificate *xc) xfree(xc->data); } -/** - * @brief - * add certs to our trust store +/* ASN parsing related defines */ +#define ASN1_PRIMITIVE_TAG 0x1F +#define ASN1_INF_LENGTH 0x80 +#define ASN1_LENGTH_MASK 0x7F + +/* + * Get TBS part of certificate. + * Since BearSSL doesn't provide any API to do this, + * it has to be implemented here. */ -size_t -ve_trust_anchors_add(br_x509_certificate *xcs, size_t num) +static void* +X509_to_tbs(unsigned char* cert, size_t* output_size) { + unsigned char *result; + size_t tbs_size; + int size, i; + + if (cert == NULL) + return (NULL); + + /* Strip two sequences to get to the TBS section */ + for (i = 0; i < 2; i++) { + /* + * XXX: We don't need to support extended tags since + * they should not be present in certificates. + */ + if ((*cert & ASN1_PRIMITIVE_TAG) == ASN1_PRIMITIVE_TAG) + return (NULL); + + cert++; + + if (*cert == ASN1_INF_LENGTH) + return (NULL); + + size = *cert & ASN1_LENGTH_MASK; + tbs_size = 0; + + /* Size can either be stored on a single or multiple bytes */ + if (*cert & (ASN1_LENGTH_MASK + 1)) { + cert++; + while (*cert == 0 && size > 0) { + cert++; + size--; + } + while (size-- > 0) { + tbs_size <<= 8; + tbs_size |= *(cert++); + } + } + if (i == 0) + result = cert; + } + tbs_size += (cert - result); + + if (output_size != NULL) + *output_size = tbs_size; + + return (result); +} + +void +ve_forbidden_digest_add(hash_data *digest, size_t num) +{ + while (num--) + VEC_ADD(forbidden_digests, digest[num]); +} + +static size_t +ve_anchors_add(br_x509_certificate *xcs, size_t num, anchor_list *anchors) +{ br_x509_trust_anchor ta; size_t u; @@ -127,25 +193,42 @@ ve_trust_anchors_add(br_x509_certificate *xcs, size_t if (certificate_to_trust_anchor_inner(&ta, &xcs[u]) < 0) { break; } - VEC_ADD(trust_anchors, ta); + VEC_ADD(*anchors, ta); } return (u); } /** * @brief + * add certs to our trust store + */ +size_t +ve_trust_anchors_add(br_x509_certificate *xcs, size_t num) +{ + return (ve_anchors_add(xcs, num, &trust_anchors)); +} + +size_t +ve_forbidden_anchors_add(br_x509_certificate *xcs, size_t num) +{ + return (ve_anchors_add(xcs, num, &forbidden_anchors)); +} + +/** + * @brief * initialize our trust_anchors from ta_PEM */ int ve_trust_init(void) { +#ifdef TRUST_ANCHOR_STR br_x509_certificate *xcs; +#endif static int once = -1; size_t num; if (once >= 0) return (once); - once = 0; ve_utc_set(time(NULL)); #ifdef BUILD_UTC @@ -159,14 +242,12 @@ ve_trust_init(void) #ifdef TRUST_ANCHOR_STR xcs = parse_certificates(__DECONST(unsigned char *, TRUST_ANCHOR_STR), sizeof(TRUST_ANCHOR_STR), &num); - if (xcs == NULL) - return (0); - num = ve_trust_anchors_add(xcs, num); - once = (int) num; -#else - num = 0; + if (xcs != NULL) + num = ve_trust_anchors_add(xcs, num); #endif - return (num); + once = (int) VEC_LEN(trust_anchors); + + return (once); } /** @@ -177,7 +258,8 @@ ve_trust_init(void) static br_x509_pkey * verify_signer_xcs(br_x509_certificate *xcs, size_t num, - br_name_element *elts, size_t num_elts) + br_name_element *elts, size_t num_elts, + anchor_list *anchors) { br_x509_minimal_context mc; br_x509_certificate *xc; @@ -196,11 +278,11 @@ verify_signer_xcs(br_x509_certificate *xcs, } DEBUG_PRINTF(5, ("verify_signer: %zu trust anchors\n", - VEC_LEN(trust_anchors))); + VEC_LEN(*anchors))); br_x509_minimal_init(&mc, &br_sha256_vtable, - &VEC_ELT(trust_anchors, 0), - VEC_LEN(trust_anchors)); + &VEC_ELT(*anchors, 0), + VEC_LEN(*anchors)); #ifdef VE_ECDSA_SUPPORT br_x509_minimal_set_ecdsa(&mc, &br_ec_prime_i31, &br_ecdsa_i31_vrfy_asn1); @@ -255,10 +337,96 @@ verify_signer_xcs(br_x509_certificate *xcs, pk = xpkeydup(tpk); } } - VEC_CLEAREXT(chain, &free_cert_contents); + VEC_CLEAR(chain); return (pk); } +/* + * Check if digest of one of the certificates from verified chain + * is present in the forbidden database. + * Since UEFI allows to store three types of digests + * all of them have to be checked separately. + */ +static int +check_forbidden_digests(br_x509_certificate *xcs, size_t num) +{ + unsigned char sha256_digest[br_sha256_SIZE]; + unsigned char sha384_digest[br_sha384_SIZE]; + unsigned char sha512_digest[br_sha512_SIZE]; + void *tbs; + hash_data *digest; + br_hash_compat_context ctx; + const br_hash_class *md; + size_t tbs_len, i; + int have_sha256, have_sha384, have_sha512; + + if (VEC_LEN(forbidden_digests) == 0) + return (0); + + /* + * Iterate through certificates, extract their To-Be-Signed section, + * and compare its digest against the ones in the forbidden database. + */ + while (num--) { + tbs = X509_to_tbs(xcs[num].data, &tbs_len); + if (tbs == NULL) { + printf("Failed to obtain TBS part of certificate\n"); + return (1); + } + have_sha256 = have_sha384 = have_sha512 = 0; + + for (i = 0; i < VEC_LEN(forbidden_digests); i++) { + digest = &VEC_ELT(forbidden_digests, i); + switch (digest->hash_size) { + case br_sha256_SIZE: + if (!have_sha256) { + have_sha256 = 1; + md = &br_sha256_vtable; + md->init(&ctx.vtable); + md->update(&ctx.vtable, tbs, tbs_len); + md->out(&ctx.vtable, sha256_digest); + } + if (!memcmp(sha256_digest, + digest->data, + br_sha256_SIZE)) + return (1); + + break; + case br_sha384_SIZE: + if (!have_sha384) { + have_sha384 = 1; + md = &br_sha384_vtable; + md->init(&ctx.vtable); + md->update(&ctx.vtable, tbs, tbs_len); + md->out(&ctx.vtable, sha384_digest); + } + if (!memcmp(sha384_digest, + digest->data, + br_sha384_SIZE)) + return (1); + + break; + case br_sha512_SIZE: + if (!have_sha512) { + have_sha512 = 1; + md = &br_sha512_vtable; + md->init(&ctx.vtable); + md->update(&ctx.vtable, tbs, tbs_len); + md->out(&ctx.vtable, sha512_digest); + } + if (!memcmp(sha512_digest, + digest->data, + br_sha512_SIZE)) + return (1); + + break; + } + } + } + + return (0); +} + static br_x509_pkey * verify_signer(const char *certs, br_name_element *elts, size_t num_elts) @@ -266,15 +434,46 @@ verify_signer(const char *certs, br_x509_certificate *xcs; br_x509_pkey *pk; size_t num; - + + pk = NULL; + ve_trust_init(); xcs = read_certificates(certs, &num); if (xcs == NULL) { ve_error_set("cannot read certificates\n"); return (NULL); } - pk = verify_signer_xcs(xcs, num, elts, num_elts); - xfree(xcs); + + /* + * Check if either + * 1. There is a direct match between cert from forbidden_anchors + * and a cert from chain. + * 2. CA that signed the chain is found in forbidden_anchors. + */ + if (VEC_LEN(forbidden_anchors) > 0) + pk = verify_signer_xcs(xcs, num, elts, num_elts, &forbidden_anchors); + if (pk != NULL) { + ve_error_set("Certificate is on forbidden list\n"); + xfreepkey(pk); + pk = NULL; + goto out; + } + + pk = verify_signer_xcs(xcs, num, elts, num_elts, &trust_anchors); + if (pk == NULL) + goto out; + + /* + * Check if hash of tbs part of any certificate in chain + * is on the forbidden list. + */ + if (check_forbidden_digests(xcs, num)) { + ve_error_set("Certificate hash is on forbidden list\n"); + xfreepkey(pk); + pk = NULL; + } +out: + free_certificates(xcs, num); return (pk); } @@ -679,7 +878,8 @@ ve_self_tests(void) for (u = 0; u < num; u ++) { cn.len = sizeof(cn_buf); - if ((pk = verify_signer_xcs(&xcs[u], 1, &cn, 1)) != NULL) { + if ((pk = verify_signer_xcs(&xcs[u], 1, &cn, 1, &trust_anchors)) != NULL) { + free_cert_contents(&xcs[u]); once++; printf("Testing verify certificate: %s\tPassed\n", cn.status ? cn_buf : ""); Modified: stable/12/share/mk/src.opts.mk ============================================================================== --- stable/12/share/mk/src.opts.mk Fri Apr 26 00:39:30 2019 (r346718) +++ stable/12/share/mk/src.opts.mk Fri Apr 26 00:48:52 2019 (r346719) @@ -216,6 +216,7 @@ __DEFAULT_DEPENDENT_OPTIONS= \ CLANG_FULL/CLANG \ LLVM_TARGET_ALL/CLANG \ LOADER_VERIEXEC/BEARSSL \ + LOADER_EFI_SECUREBOOT/LOADER_VERIEXEC \ VERIEXEC/BEARSSL \ # MK_*_SUPPORT options which default to "yes" unless their corresponding Modified: stable/12/stand/efi/loader/Makefile ============================================================================== --- stable/12/stand/efi/loader/Makefile Fri Apr 26 00:39:30 2019 (r346718) +++ stable/12/stand/efi/loader/Makefile Fri Apr 26 00:48:52 2019 (r346719) @@ -81,6 +81,10 @@ HAVE_BCACHE= yes CFLAGS+= -DEFI_STAGING_SIZE=${EFI_STAGING_SIZE} .endif +.if ${MK_LOADER_EFI_SECUREBOOT} != "no" +CFLAGS+= -DEFI_SECUREBOOT +.endif + NEWVERSWHAT= "EFI loader" ${MACHINE} VERSION_FILE= ${.CURDIR}/../loader/version Modified: stable/12/stand/efi/loader/main.c ============================================================================== --- stable/12/stand/efi/loader/main.c Fri Apr 26 00:39:30 2019 (r346718) +++ stable/12/stand/efi/loader/main.c Fri Apr 26 00:48:52 2019 (r346719) @@ -963,6 +963,17 @@ main(int argc, CHAR16 *argv[]) BS->SetWatchdogTimer(0, 0, 0, NULL); /* + * Initialize the trusted/forbidden certificates from UEFI. + * They will be later used to verify the manifest(s), + * which should contain hashes of verified files. + * This needs to be initialized before any configuration files + * are loaded. + */ +#ifdef EFI_SECUREBOOT + ve_efi_init(); +#endif + + /* * Try and find a good currdev based on the image that was booted. * It might be desirable here to have a short pause to allow falling * through to the boot loader instead of returning instantly to follow Copied: stable/12/tools/build/options/WITH_LOADER_EFI_SECUREBOOT (from r344840, head/tools/build/options/WITH_LOADER_EFI_SECUREBOOT) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/12/tools/build/options/WITH_LOADER_EFI_SECUREBOOT Fri Apr 26 00:48:52 2019 (r346719, copy of r344840, head/tools/build/options/WITH_LOADER_EFI_SECUREBOOT) @@ -0,0 +1,5 @@ +.\" $FreeBSD$ +Enable building +.Xr loader 8 +with support for verification based on certificates obtained from UEFI. +.Pp From owner-svn-src-stable-12@freebsd.org Fri Apr 26 01:02:16 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 5745215831F4; Fri, 26 Apr 2019 01:02:16 +0000 (UTC) (envelope-from mw@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 05C6073077; Fri, 26 Apr 2019 01:02:16 +0000 (UTC) (envelope-from mw@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id D2F574228; Fri, 26 Apr 2019 01:02:15 +0000 (UTC) (envelope-from mw@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3Q12FcE096317; Fri, 26 Apr 2019 01:02:15 GMT (envelope-from mw@FreeBSD.org) Received: (from mw@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3Q12ERB096310; Fri, 26 Apr 2019 01:02:14 GMT (envelope-from mw@FreeBSD.org) Message-Id: <201904260102.x3Q12ERB096310@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mw set sender to mw@FreeBSD.org using -f From: Marcin Wojtas Date: Fri, 26 Apr 2019 01:02:14 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346720 - in stable/12/sys: conf dev/tpm modules/tpm X-SVN-Group: stable-12 X-SVN-Commit-Author: mw X-SVN-Commit-Paths: in stable/12/sys: conf dev/tpm modules/tpm X-SVN-Commit-Revision: 346720 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 05C6073077 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.96 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-0.99)[-0.995,0]; NEURAL_HAM_SHORT(-0.96)[-0.963,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Apr 2019 01:02:16 -0000 Author: mw Date: Fri Apr 26 01:02:14 2019 New Revision: 346720 URL: https://svnweb.freebsd.org/changeset/base/346720 Log: MFC r342084,r342251,r342271,r342285: Introduce TPM2.0 driver r342084 Introduce driver for TPM 2.0 in CRB and FIFO (TIS) modes r342251 Include the new TPM 2.0 driver in the TPM module. r342271 Fix obtaining RSP address in TPM CRB for non-amd64 platforms r342285 tpm(4): Fix GCC build after r342084 (TPM 2.0 driver commit) Submitted by: Kornel Duleba Obtained from: Semihalf Sponsored by: Stormshield Added: stable/12/sys/dev/tpm/tpm20.c - copied, changed from r342084, head/sys/dev/tpm/tpm20.c stable/12/sys/dev/tpm/tpm20.h - copied, changed from r342084, head/sys/dev/tpm/tpm20.h stable/12/sys/dev/tpm/tpm_crb.c - copied, changed from r342084, head/sys/dev/tpm/tpm_crb.c stable/12/sys/dev/tpm/tpm_tis.c - copied unchanged from r342084, head/sys/dev/tpm/tpm_tis.c Modified: stable/12/sys/conf/files.amd64 stable/12/sys/modules/tpm/Makefile Modified: stable/12/sys/conf/files.amd64 ============================================================================== --- stable/12/sys/conf/files.amd64 Fri Apr 26 00:48:52 2019 (r346719) +++ stable/12/sys/conf/files.amd64 Fri Apr 26 01:02:14 2019 (r346720) @@ -487,6 +487,9 @@ dev/syscons/scvesactl.c optional sc vga vesa dev/syscons/scvgarndr.c optional sc vga dev/syscons/scvtb.c optional sc dev/tpm/tpm.c optional tpm +dev/tpm/tpm20.c optional tpm +dev/tpm/tpm_crb.c optional tpm acpi +dev/tpm/tpm_tis.c optional tpm acpi dev/tpm/tpm_acpi.c optional tpm acpi dev/tpm/tpm_isa.c optional tpm isa dev/uart/uart_cpu_x86.c optional uart Copied and modified: stable/12/sys/dev/tpm/tpm20.c (from r342084, head/sys/dev/tpm/tpm20.c) ============================================================================== --- head/sys/dev/tpm/tpm20.c Fri Dec 14 16:14:36 2018 (r342084, copy source) +++ stable/12/sys/dev/tpm/tpm20.c Fri Apr 26 01:02:14 2019 (r346720) @@ -36,6 +36,22 @@ MALLOC_DEFINE(M_TPM20, "tpm_buffer", "buffer for tpm 2 static void tpm20_discard_buffer(void *arg); static int tpm20_save_state(device_t dev, bool suspend); +static d_open_t tpm20_open; +static d_close_t tpm20_close; +static d_read_t tpm20_read; +static d_write_t tpm20_write; +static d_ioctl_t tpm20_ioctl; + +static struct cdevsw tpm20_cdevsw = { + .d_version = D_VERSION, + .d_open = tpm20_open, + .d_close = tpm20_close, + .d_read = tpm20_read, + .d_write = tpm20_write, + .d_ioctl = tpm20_ioctl, + .d_name = "tpm20", +}; + int tpm20_read(struct cdev *dev, struct uio *uio, int flags) { @@ -162,7 +178,7 @@ tpm20_init(struct tpm_sc *sc) sc->pending_data_length = 0; make_dev_args_init(&args); - args.mda_devsw = &tpm_cdevsw; + args.mda_devsw = &tpm20_cdevsw; args.mda_uid = UID_ROOT; args.mda_gid = GID_WHEEL; args.mda_mode = TPM_CDEV_PERM_FLAG; Copied and modified: stable/12/sys/dev/tpm/tpm20.h (from r342084, head/sys/dev/tpm/tpm20.h) ============================================================================== --- head/sys/dev/tpm/tpm20.h Fri Dec 14 16:14:36 2018 (r342084, copy source) +++ stable/12/sys/dev/tpm/tpm20.h Fri Apr 26 01:02:14 2019 (r346720) @@ -124,22 +124,6 @@ int32_t tpm20_get_timeout(uint32_t command); int tpm20_init(struct tpm_sc *sc); void tpm20_release(struct tpm_sc *sc); -d_open_t tpm20_open; -d_close_t tpm20_close; -d_read_t tpm20_read; -d_write_t tpm20_write; -d_ioctl_t tpm20_ioctl; - -static struct cdevsw tpm_cdevsw = { - .d_version = D_VERSION, - .d_open = tpm20_open, - .d_close = tpm20_close, - .d_read = tpm20_read, - .d_write = tpm20_write, - .d_ioctl = tpm20_ioctl, - .d_name = "tpm20", -}; - /* Small helper routines for io ops */ static inline uint8_t RD1(struct tpm_sc *sc, bus_size_t off) @@ -153,12 +137,14 @@ RD4(struct tpm_sc *sc, bus_size_t off) return (bus_read_4(sc->mem_res, off)); } +#ifdef __amd64__ static inline uint64_t RD8(struct tpm_sc *sc, bus_size_t off) { return (bus_read_8(sc->mem_res, off)); } +#endif static inline void WR1(struct tpm_sc *sc, bus_size_t off, uint8_t val) { Copied and modified: stable/12/sys/dev/tpm/tpm_crb.c (from r342084, head/sys/dev/tpm/tpm_crb.c) ============================================================================== --- head/sys/dev/tpm/tpm_crb.c Fri Dec 14 16:14:36 2018 (r342084, copy source) +++ stable/12/sys/dev/tpm/tpm_crb.c Fri Apr 26 01:02:14 2019 (r346720) @@ -50,6 +50,7 @@ __FBSDID("$FreeBSD$"); #define TPM_CRB_CTRL_CMD_HADDR 0x60 #define TPM_CRB_CTRL_RSP_SIZE 0x64 #define TPM_CRB_CTRL_RSP_ADDR 0x68 +#define TPM_CRB_CTRL_RSP_HADDR 0x6c #define TPM_CRB_DATA_BUFFER 0x80 #define TPM_LOC_STATE_ESTB BIT(0) @@ -187,7 +188,12 @@ tpmcrb_attach(device_t dev) * addr is stored in two 4 byte neighboring registers, whereas RSP is * stored in a single 8 byte one. */ +#ifdef __amd64__ crb_sc->rsp_off = RD8(sc, TPM_CRB_CTRL_RSP_ADDR); +#else + crb_sc->rsp_off = RD4(sc, TPM_CRB_CTRL_RSP_ADDR); + crb_sc->rsp_off |= ((uint64_t) RD4(sc, TPM_CRB_CTRL_RSP_HADDR) << 32); +#endif crb_sc->cmd_off = RD4(sc, TPM_CRB_CTRL_CMD_LADDR); crb_sc->cmd_off |= ((uint64_t) RD4(sc, TPM_CRB_CTRL_CMD_HADDR) << 32); crb_sc->cmd_buf_size = RD4(sc, TPM_CRB_CTRL_CMD_SIZE); Copied: stable/12/sys/dev/tpm/tpm_tis.c (from r342084, head/sys/dev/tpm/tpm_tis.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/12/sys/dev/tpm/tpm_tis.c Fri Apr 26 01:02:14 2019 (r346720, copy of r342084, head/sys/dev/tpm/tpm_tis.c) @@ -0,0 +1,510 @@ +/*- + * Copyright (c) 2018 Stormshield. + * Copyright (c) 2018 Semihalf. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include "tpm20.h" + +/* + * TIS register space as defined in + * TCG_PC_Client_Platform_TPM_Profile_PTP_2.0_r1.03_v22 + */ +#define TPM_ACCESS 0x0 +#define TPM_INT_ENABLE 0x8 +#define TPM_INT_VECTOR 0xc +#define TPM_INT_STS 0x10 +#define TPM_INTF_CAPS 0x14 +#define TPM_STS 0x18 +#define TPM_DATA_FIFO 0x24 +#define TPM_INTF_ID 0x30 +#define TPM_XDATA_FIFO 0x80 +#define TPM_DID_VID 0xF00 +#define TPM_RID 0xF04 + +#define TPM_ACCESS_LOC_REQ BIT(1) +#define TPM_ACCESS_LOC_Seize BIT(3) +#define TPM_ACCESS_LOC_ACTIVE BIT(5) +#define TPM_ACCESS_LOC_RELINQUISH BIT(5) +#define TPM_ACCESS_VALID BIT(7) + +#define TPM_INT_ENABLE_GLOBAL_ENABLE BIT(31) +#define TPM_INT_ENABLE_CMD_RDY BIT(7) +#define TPM_INT_ENABLE_LOC_CHANGE BIT(2) +#define TPM_INT_ENABLE_STS_VALID BIT(1) +#define TPM_INT_ENABLE_DATA_AVAIL BIT(0) + +#define TPM_INT_STS_CMD_RDY BIT(7) +#define TPM_INT_STS_LOC_CHANGE BIT(2) +#define TPM_INT_STS_VALID BIT(1) +#define TPM_INT_STS_DATA_AVAIL BIT(0) + +#define TPM_INTF_CAPS_VERSION 0x70000000 +#define TPM_INTF_CAPS_TPM20 0x30000000 + +#define TPM_STS_VALID BIT(7) +#define TPM_STS_CMD_RDY BIT(6) +#define TPM_STS_CMD_START BIT(5) +#define TPM_STS_DATA_AVAIL BIT(4) +#define TPM_STS_DATA_EXPECTED BIT(3) +#define TPM_STS_BURST_MASK 0xFFFF00 +#define TPM_STS_BURST_OFFSET 0x8 + +static int tpmtis_transmit(struct tpm_sc *sc, size_t length); + +static int tpmtis_acpi_probe(device_t dev); +static int tpmtis_attach(device_t dev); +static int tpmtis_detach(device_t dev); + +static void tpmtis_intr_handler(void *arg); + +static ACPI_STATUS tpmtis_get_SIRQ_channel(ACPI_RESOURCE *res, void *arg); +static bool tpmtis_setup_intr(struct tpm_sc *sc); + +static bool tpmtis_read_bytes(struct tpm_sc *sc, size_t count, uint8_t *buf); +static bool tpmtis_write_bytes(struct tpm_sc *sc, size_t count, uint8_t *buf); +static bool tpmtis_request_locality(struct tpm_sc *sc, int locality); +static void tpmtis_relinquish_locality(struct tpm_sc *sc); +static bool tpmtis_go_ready(struct tpm_sc *sc); + +static bool tpm_wait_for_u32(struct tpm_sc *sc, bus_size_t off, + uint32_t mask, uint32_t val, int32_t timeout); +static uint16_t tpmtis_wait_for_burst(struct tpm_sc *sc); + +char *tpmtis_ids[] = {"MSFT0101", NULL}; + +static int +tpmtis_acpi_probe(device_t dev) +{ + struct resource *res; + int rid = 0; + uint32_t caps; + + if (ACPI_ID_PROBE(device_get_parent(dev), dev, tpmtis_ids) == NULL) + return (ENXIO); + + /* Check if device is in TPM 2.0 TIS mode */ + res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE); + if (res == NULL) + return (ENXIO); + + caps = bus_read_4(res, TPM_INTF_CAPS); + bus_release_resource(dev, SYS_RES_MEMORY, rid, res); + if ((caps & TPM_INTF_CAPS_VERSION) != TPM_INTF_CAPS_TPM20) + return (ENXIO); + + device_set_desc(dev, "Trusted Platform Module 2.0, FIFO mode"); + return (BUS_PROBE_DEFAULT); +} + +static int +tpmtis_attach(device_t dev) +{ + struct tpm_sc *sc; + int result; + + sc = device_get_softc(dev); + sc->dev = dev; + + sc->mem_rid = 0; + sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->mem_rid, + RF_ACTIVE); + if (sc->mem_res == NULL) + return (ENXIO); + + sc->irq_rid = 0; + sc->irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->irq_rid, + RF_ACTIVE | RF_SHAREABLE); + if (sc->irq_res != NULL) { + if (bus_setup_intr(dev, sc->irq_res, INTR_TYPE_MISC | INTR_MPSAFE, + NULL, tpmtis_intr_handler, sc, &sc->intr_cookie)) + sc->interrupts = false; + else + sc->interrupts = tpmtis_setup_intr(sc); + } else { + sc->interrupts = false; + } + + sc->intr_type = -1; + + sc->transmit = tpmtis_transmit; + + result = tpm20_init(sc); + if (result != 0) + tpmtis_detach(dev); + + return (result); +} + +static int +tpmtis_detach(device_t dev) +{ + struct tpm_sc *sc; + + sc = device_get_softc(dev); + + if (sc->intr_cookie != NULL) + bus_teardown_intr(dev, sc->irq_res, sc->intr_cookie); + + if (sc->irq_res != NULL) + bus_release_resource(dev, SYS_RES_IRQ, + sc->irq_rid, sc->irq_res); + + if (sc->mem_res != NULL) + bus_release_resource(dev, SYS_RES_MEMORY, + sc->mem_rid, sc->mem_res); + + tpm20_release(sc); + return (0); +} + +static ACPI_STATUS +tpmtis_get_SIRQ_channel(ACPI_RESOURCE *res, void *arg) +{ + struct tpm_sc *sc; + uint8_t channel; + + sc = (struct tpm_sc *)arg; + + switch (res->Type) { + case ACPI_RESOURCE_TYPE_IRQ: + channel = res->Data.Irq.Interrupts[0]; + break; + case ACPI_RESOURCE_TYPE_EXTENDED_IRQ: + channel = res->Data.ExtendedIrq.Interrupts[0]; + break; + default: + return (AE_OK); + } + + WR1(sc, TPM_INT_VECTOR, channel); + return (AE_OK); +} + +static bool +tpmtis_setup_intr(struct tpm_sc *sc) +{ + ACPI_STATUS status; + ACPI_HANDLE handle; + uint32_t irq_mask; + + handle = acpi_get_handle(sc->dev); + + if(!tpmtis_request_locality(sc, 0)) + return (false); + + irq_mask = RD4(sc, TPM_INT_ENABLE); + irq_mask |= TPM_INT_ENABLE_GLOBAL_ENABLE | + TPM_INT_ENABLE_DATA_AVAIL | + TPM_INT_ENABLE_LOC_CHANGE | + TPM_INT_ENABLE_CMD_RDY | + TPM_INT_ENABLE_STS_VALID; + WR4(sc, TPM_INT_ENABLE, irq_mask); + + status = AcpiWalkResources(handle, "_CRS", + tpmtis_get_SIRQ_channel, (void *)sc); + + tpmtis_relinquish_locality(sc); + + return (ACPI_SUCCESS(status)); +} + +static void +tpmtis_intr_handler(void *arg) +{ + struct tpm_sc *sc; + uint32_t status; + + sc = (struct tpm_sc *)arg; + status = RD4(sc, TPM_INT_STS); + + WR4(sc, TPM_INT_STS, status); + if (sc->intr_type != -1 && sc->intr_type & status) + wakeup(sc); +} + +static bool +tpm_wait_for_u32(struct tpm_sc *sc, bus_size_t off, uint32_t mask, uint32_t val, + int32_t timeout) +{ + + /* Check for condition */ + if ((RD4(sc, off) & mask) == val) + return (true); + + /* If interrupts are enabled sleep for timeout duration */ + if(sc->interrupts && sc->intr_type != -1) { + tsleep(sc, PWAIT, "TPM WITH INTERRUPTS", timeout / tick); + + sc->intr_type = -1; + return ((RD4(sc, off) & mask) == val); + } + + /* If we don't have interrupts poll the device every tick */ + while (timeout > 0) { + if ((RD4(sc, off) & mask) == val) + return (true); + + pause("TPM POLLING", 1); + timeout -= tick; + } + return (false); +} + +static uint16_t +tpmtis_wait_for_burst(struct tpm_sc *sc) +{ + int timeout; + uint16_t burst_count; + + timeout = TPM_TIMEOUT_A; + + while (timeout-- > 0) { + burst_count = (RD4(sc, TPM_STS) & TPM_STS_BURST_MASK) >> + TPM_STS_BURST_OFFSET; + if (burst_count > 0) + break; + + DELAY(1); + } + return (burst_count); +} + +static bool +tpmtis_read_bytes(struct tpm_sc *sc, size_t count, uint8_t *buf) +{ + uint16_t burst_count; + + while (count > 0) { + burst_count = tpmtis_wait_for_burst(sc); + if (burst_count == 0) + return (false); + + burst_count = MIN(burst_count, count); + count -= burst_count; + + while (burst_count-- > 0) + *buf++ = RD1(sc, TPM_DATA_FIFO); + } + + return (true); +} + +static bool +tpmtis_write_bytes(struct tpm_sc *sc, size_t count, uint8_t *buf) +{ + uint16_t burst_count; + + while (count > 0) { + burst_count = tpmtis_wait_for_burst(sc); + if (burst_count == 0) + return (false); + + burst_count = MIN(burst_count, count); + count -= burst_count; + + while (burst_count-- > 0) + WR1(sc, TPM_DATA_FIFO, *buf++); + } + + return (true); +} + + +static bool +tpmtis_request_locality(struct tpm_sc *sc, int locality) +{ + uint8_t mask; + int timeout; + + /* Currently we only support Locality 0 */ + if (locality != 0) + return (false); + + mask = TPM_ACCESS_LOC_ACTIVE | TPM_ACCESS_VALID; + timeout = TPM_TIMEOUT_A; + sc->intr_type = TPM_INT_STS_LOC_CHANGE; + + WR1(sc, TPM_ACCESS, TPM_ACCESS_LOC_REQ); + bus_barrier(sc->mem_res, TPM_ACCESS, 1, BUS_SPACE_BARRIER_WRITE); + if(sc->interrupts) { + tsleep(sc, PWAIT, "TPMLOCREQUEST with INTR", timeout / tick); + return ((RD1(sc, TPM_ACCESS) & mask) == mask); + } else { + while(timeout > 0) { + if ((RD1(sc, TPM_ACCESS) & mask) == mask) + return (true); + + pause("TPMLOCREQUEST POLLING", 1); + timeout -= tick; + } + } + + return (false); +} + +static void +tpmtis_relinquish_locality(struct tpm_sc *sc) +{ + + /* + * Interrupts can only be cleared when a locality is active. + * Clear them now in case interrupt handler didn't make it in time. + */ + if(sc->interrupts) + AND4(sc, TPM_INT_STS, RD4(sc, TPM_INT_STS)); + + OR1(sc, TPM_ACCESS, TPM_ACCESS_LOC_RELINQUISH); +} + +static bool +tpmtis_go_ready(struct tpm_sc *sc) +{ + uint32_t mask; + + mask = TPM_STS_CMD_RDY; + sc->intr_type = TPM_INT_STS_CMD_RDY; + + OR4(sc, TPM_STS, TPM_STS_CMD_RDY); + bus_barrier(sc->mem_res, TPM_STS, 4, BUS_SPACE_BARRIER_WRITE); + if (!tpm_wait_for_u32(sc, TPM_STS, mask, mask, TPM_TIMEOUT_B)) + return (false); + + AND4(sc, TPM_STS, ~TPM_STS_CMD_RDY); + return (true); +} + +static int +tpmtis_transmit(struct tpm_sc *sc, size_t length) +{ + size_t bytes_available; + uint32_t mask, curr_cmd; + int timeout; + + sx_assert(&sc->dev_lock, SA_XLOCKED); + + if (!tpmtis_request_locality(sc, 0)) { + device_printf(sc->dev, + "Failed to obtain locality\n"); + return (EIO); + } + if (!tpmtis_go_ready(sc)) { + device_printf(sc->dev, + "Failed to switch to ready state\n"); + return (EIO); + } + if (!tpmtis_write_bytes(sc, length, sc->buf)) { + device_printf(sc->dev, + "Failed to write cmd to device\n"); + return (EIO); + } + + mask = TPM_STS_VALID; + sc->intr_type = TPM_INT_STS_VALID; + if (!tpm_wait_for_u32(sc, TPM_STS, mask, mask, TPM_TIMEOUT_C)) { + device_printf(sc->dev, + "Timeout while waiting for valid bit\n"); + return (EIO); + } + if (RD4(sc, TPM_STS) & TPM_STS_DATA_EXPECTED) { + device_printf(sc->dev, + "Device expects more data even though we already" + " sent everything we had\n"); + return (EIO); + } + + /* + * Calculate timeout for current command. + * Command code is passed in bytes 6-10. + */ + curr_cmd = be32toh(*(uint32_t *) (&sc->buf[6])); + timeout = tpm20_get_timeout(curr_cmd); + + WR4(sc, TPM_STS, TPM_STS_CMD_START); + bus_barrier(sc->mem_res, TPM_STS, 4, BUS_SPACE_BARRIER_WRITE); + + mask = TPM_STS_DATA_AVAIL | TPM_STS_VALID; + sc->intr_type = TPM_INT_STS_DATA_AVAIL; + if (!tpm_wait_for_u32(sc, TPM_STS, mask, mask, timeout)) { + device_printf(sc->dev, + "Timeout while waiting for device to process cmd\n"); + /* + * Switching to ready state also cancels processing + * current command + */ + if (!tpmtis_go_ready(sc)) + return (EIO); + + /* + * After canceling a command we should get a response, + * check if there is one. + */ + sc->intr_type = TPM_INT_STS_DATA_AVAIL; + if (!tpm_wait_for_u32(sc, TPM_STS, mask, mask, TPM_TIMEOUT_C)) + return (EIO); + } + /* Read response header. Length is passed in bytes 2 - 6. */ + if(!tpmtis_read_bytes(sc, TPM_HEADER_SIZE, sc->buf)) { + device_printf(sc->dev, + "Failed to read response header\n"); + return (EIO); + } + bytes_available = be32toh(*(uint32_t *) (&sc->buf[2])); + + if (bytes_available > TPM_BUFSIZE || bytes_available < TPM_HEADER_SIZE) { + device_printf(sc->dev, + "Incorrect response size: %zu\n", + bytes_available); + return (EIO); + } + if(!tpmtis_read_bytes(sc, bytes_available - TPM_HEADER_SIZE, + &sc->buf[TPM_HEADER_SIZE])) { + device_printf(sc->dev, + "Failed to read response\n"); + return (EIO); + } + tpmtis_relinquish_locality(sc); + sc->pending_data_length = bytes_available; + + return (0); +} + +/* ACPI Driver */ +static device_method_t tpmtis_methods[] = { + DEVMETHOD(device_probe, tpmtis_acpi_probe), + DEVMETHOD(device_attach, tpmtis_attach), + DEVMETHOD(device_detach, tpmtis_detach), + DEVMETHOD(device_shutdown, tpm20_shutdown), + DEVMETHOD(device_suspend, tpm20_suspend), + {0, 0} +}; +static driver_t tpmtis_driver = { + "tpmtis", tpmtis_methods, sizeof(struct tpm_sc), +}; + +devclass_t tpmtis_devclass; +DRIVER_MODULE(tpmtis, acpi, tpmtis_driver, tpmtis_devclass, 0, 0); Modified: stable/12/sys/modules/tpm/Makefile ============================================================================== --- stable/12/sys/modules/tpm/Makefile Fri Apr 26 00:48:52 2019 (r346719) +++ stable/12/sys/modules/tpm/Makefile Fri Apr 26 01:02:14 2019 (r346720) @@ -7,5 +7,7 @@ KMOD= tpm SRCS= tpm.c bus_if.h device_if.h #Bus specific stuff. SRCS+= tpm_isa.c tpm_acpi.c isa_if.h opt_acpi.h acpi_if.h +#TPM 2.0 +SRCS+= tpm20.c tpm_crb.c tpm_tis.c .include From owner-svn-src-stable-12@freebsd.org Fri Apr 26 01:29:02 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 2D81D1583C5E; Fri, 26 Apr 2019 01:29:02 +0000 (UTC) (envelope-from mw@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id C431F74445; Fri, 26 Apr 2019 01:29:01 +0000 (UTC) (envelope-from mw@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id A8FC145CF; Fri, 26 Apr 2019 01:29:01 +0000 (UTC) (envelope-from mw@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3Q1T1Lp007074; Fri, 26 Apr 2019 01:29:01 GMT (envelope-from mw@FreeBSD.org) Received: (from mw@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3Q1T0JB007070; Fri, 26 Apr 2019 01:29:00 GMT (envelope-from mw@FreeBSD.org) Message-Id: <201904260129.x3Q1T0JB007070@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mw set sender to mw@FreeBSD.org using -f From: Marcin Wojtas Date: Fri, 26 Apr 2019 01:29:00 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346723 - in stable/12: sys/dev/tpm usr.sbin/acpi/acpidump X-SVN-Group: stable-12 X-SVN-Commit-Author: mw X-SVN-Commit-Paths: in stable/12: sys/dev/tpm usr.sbin/acpi/acpidump X-SVN-Commit-Revision: 346723 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: C431F74445 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.97 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_SHORT(-0.97)[-0.971,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_MEDIUM(-0.99)[-0.994,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Apr 2019 01:29:02 -0000 Author: mw Date: Fri Apr 26 01:29:00 2019 New Revision: 346723 URL: https://svnweb.freebsd.org/changeset/base/346723 Log: MFC r343438: Use ACPI TPM2 table to probe tpmtis and tpmcrb device Sponsored by: Stormshield Modified: stable/12/sys/dev/tpm/tpm20.h stable/12/sys/dev/tpm/tpm_crb.c stable/12/sys/dev/tpm/tpm_tis.c stable/12/usr.sbin/acpi/acpidump/acpi.c Modified: stable/12/sys/dev/tpm/tpm20.h ============================================================================== --- stable/12/sys/dev/tpm/tpm20.h Fri Apr 26 01:20:39 2019 (r346722) +++ stable/12/sys/dev/tpm/tpm20.h Fri Apr 26 01:29:00 2019 (r346723) @@ -93,6 +93,12 @@ __FBSDID("$FreeBSD$"); #define TPM_CDEV_NAME "tpm0" #define TPM_CDEV_PERM_FLAG 0600 + +#define TPM2_START_METHOD_ACPI 2 +#define TPM2_START_METHOD_TIS 6 +#define TPM2_START_METHOD_CRB 7 +#define TPM2_START_METHOD_CRB_ACPI 8 + struct tpm_sc { device_t dev; Modified: stable/12/sys/dev/tpm/tpm_crb.c ============================================================================== --- stable/12/sys/dev/tpm/tpm_crb.c Fri Apr 26 01:20:39 2019 (r346722) +++ stable/12/sys/dev/tpm/tpm_crb.c Fri Apr 26 01:29:00 2019 (r346723) @@ -104,26 +104,21 @@ char *tpmcrb_ids[] = {"MSFT0101", NULL}; static int tpmcrb_acpi_probe(device_t dev) { - struct resource *res; - int rid = 0; - uint32_t caps; + int err = 0; + ACPI_TABLE_TPM23 *tbl; + ACPI_STATUS status; if (ACPI_ID_PROBE(device_get_parent(dev), dev, tpmcrb_ids) == NULL) return (ENXIO); - /* Check if device is in CRB mode */ - res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE); - if (res == NULL) - return (ENXIO); + /*Find TPM2 Header*/ + status = AcpiGetTable(ACPI_SIG_TPM2, 1, (ACPI_TABLE_HEADER **) &tbl); + if(ACPI_FAILURE(status) || + tbl->StartMethod != TPM2_START_METHOD_CRB) + err = ENXIO; - caps = bus_read_4(res, TPM_CRB_INTF_ID); - bus_release_resource(dev, SYS_RES_MEMORY, rid, res); - - if ((caps & TPM_CRB_INTF_ID_TYPE) != TPM_CRB_INTF_ID_TYPE_CRB) - return (ENXIO); - device_set_desc(dev, "Trusted Platform Module 2.0, CRB mode"); - return (BUS_PROBE_DEFAULT); + return (err); } static ACPI_STATUS Modified: stable/12/sys/dev/tpm/tpm_tis.c ============================================================================== --- stable/12/sys/dev/tpm/tpm_tis.c Fri Apr 26 01:20:39 2019 (r346722) +++ stable/12/sys/dev/tpm/tpm_tis.c Fri Apr 26 01:29:00 2019 (r346723) @@ -100,25 +100,20 @@ char *tpmtis_ids[] = {"MSFT0101", NULL}; static int tpmtis_acpi_probe(device_t dev) { - struct resource *res; - int rid = 0; - uint32_t caps; + int err = 0; + ACPI_TABLE_TPM23 *tbl; + ACPI_STATUS status; if (ACPI_ID_PROBE(device_get_parent(dev), dev, tpmtis_ids) == NULL) return (ENXIO); + /*Find TPM2 Header*/ + status = AcpiGetTable(ACPI_SIG_TPM2, 1, (ACPI_TABLE_HEADER **) &tbl); + if(ACPI_FAILURE(status) || + tbl->StartMethod != TPM2_START_METHOD_TIS) + err = ENXIO; - /* Check if device is in TPM 2.0 TIS mode */ - res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE); - if (res == NULL) - return (ENXIO); - - caps = bus_read_4(res, TPM_INTF_CAPS); - bus_release_resource(dev, SYS_RES_MEMORY, rid, res); - if ((caps & TPM_INTF_CAPS_VERSION) != TPM_INTF_CAPS_TPM20) - return (ENXIO); - device_set_desc(dev, "Trusted Platform Module 2.0, FIFO mode"); - return (BUS_PROBE_DEFAULT); + return (err); } static int Modified: stable/12/usr.sbin/acpi/acpidump/acpi.c ============================================================================== --- stable/12/usr.sbin/acpi/acpidump/acpi.c Fri Apr 26 01:20:39 2019 (r346722) +++ stable/12/usr.sbin/acpi/acpidump/acpi.c Fri Apr 26 01:29:00 2019 (r346723) @@ -970,7 +970,18 @@ acpi_handle_tcpa(ACPI_TABLE_HEADER *sdp) printf(END_COMMENT); } - +static void acpi_handle_tpm2(ACPI_TABLE_HEADER *sdp) +{ + ACPI_TABLE_TPM2 *tpm2; + + printf (BEGIN_COMMENT); + acpi_print_sdt(sdp); + tpm2 = (ACPI_TABLE_TPM2 *) sdp; + printf ("\t\tControlArea=%lx\n", tpm2->ControlAddress); + printf ("\t\tStartMethod=%x\n", tpm2->StartMethod); + printf (END_COMMENT); +} + static const char * devscope_type2str(int type) { @@ -1769,6 +1780,8 @@ acpi_handle_rsdt(ACPI_TABLE_HEADER *rsdp) acpi_handle_wddt(sdp); else if (!memcmp(sdp->Signature, ACPI_SIG_LPIT, 4)) acpi_handle_lpit(sdp); + else if (!memcmp(sdp->Signature, ACPI_SIG_TPM2, 4)) + acpi_handle_tpm2(sdp); else { printf(BEGIN_COMMENT); acpi_print_sdt(sdp); From owner-svn-src-stable-12@freebsd.org Fri Apr 26 01:41:58 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id D59101584421; Fri, 26 Apr 2019 01:41:57 +0000 (UTC) (envelope-from mw@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 891F874D71; Fri, 26 Apr 2019 01:41:57 +0000 (UTC) (envelope-from mw@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 6500D48F1; Fri, 26 Apr 2019 01:41:57 +0000 (UTC) (envelope-from mw@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3Q1fv3p016255; Fri, 26 Apr 2019 01:41:57 GMT (envelope-from mw@FreeBSD.org) Received: (from mw@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3Q1fu9a016248; Fri, 26 Apr 2019 01:41:56 GMT (envelope-from mw@FreeBSD.org) Message-Id: <201904260141.x3Q1fu9a016248@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mw set sender to mw@FreeBSD.org using -f From: Marcin Wojtas Date: Fri, 26 Apr 2019 01:41:55 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346724 - in stable/12/sys: conf dev/random dev/tpm sys X-SVN-Group: stable-12 X-SVN-Commit-Author: mw X-SVN-Commit-Paths: in stable/12/sys: conf dev/random dev/tpm sys X-SVN-Commit-Revision: 346724 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 891F874D71 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.97 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-0.99)[-0.995,0]; NEURAL_HAM_SHORT(-0.97)[-0.972,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Apr 2019 01:41:58 -0000 Author: mw Date: Fri Apr 26 01:41:55 2019 New Revision: 346724 URL: https://svnweb.freebsd.org/changeset/base/346724 Log: MFC r345438,r345842,r346259,r346261: TPM as possible entropy source r345438: Allow using TPM as entropy source TPM has a built-in RNG, with its own entropy source. The driver was extended to harvest 16 random bytes from TPM every 10 seconds. A new build option "TPM_HARVEST" was introduced - for now, however, it is not enabled by default in the GENERIC config. r345842: Add a cv_wait to the TPM2.0 harvesting function r346259: tpm: Prevent session hijack r346261: Improve tpm20 style Submitted by: Kornel Duleba Obtained from: Semihalf Sponsored by: Stormshield Modified: stable/12/sys/conf/options stable/12/sys/dev/random/random_harvestq.c stable/12/sys/dev/tpm/tpm20.c stable/12/sys/dev/tpm/tpm20.h stable/12/sys/dev/tpm/tpm_crb.c stable/12/sys/dev/tpm/tpm_tis.c stable/12/sys/sys/random.h Modified: stable/12/sys/conf/options ============================================================================== --- stable/12/sys/conf/options Fri Apr 26 01:29:00 2019 (r346723) +++ stable/12/sys/conf/options Fri Apr 26 01:41:55 2019 (r346724) @@ -991,6 +991,9 @@ RANDOM_LOADABLE opt_global.h RANDOM_ENABLE_UMA opt_global.h RANDOM_ENABLE_ETHER opt_global.h +# This options turns TPM into entropy source. +TPM_HARVEST opt_tpm.h + # BHND(4) driver BHND_LOGLEVEL opt_global.h Modified: stable/12/sys/dev/random/random_harvestq.c ============================================================================== --- stable/12/sys/dev/random/random_harvestq.c Fri Apr 26 01:29:00 2019 (r346723) +++ stable/12/sys/dev/random/random_harvestq.c Fri Apr 26 01:41:55 2019 (r346724) @@ -315,6 +315,7 @@ static const char *random_source_descr[ENTROPYSOURCE] [RANDOM_PURE_BROADCOM] = "PURE_BROADCOM", [RANDOM_PURE_CCP] = "PURE_CCP", [RANDOM_PURE_DARN] = "PURE_DARN", + [RANDOM_PURE_TPM] = "PURE_TPM", /* "ENTROPYSOURCE" */ }; Modified: stable/12/sys/dev/tpm/tpm20.c ============================================================================== --- stable/12/sys/dev/tpm/tpm20.c Fri Apr 26 01:29:00 2019 (r346723) +++ stable/12/sys/dev/tpm/tpm20.c Fri Apr 26 01:41:55 2019 (r346724) @@ -28,13 +28,27 @@ #include __FBSDID("$FreeBSD$"); +#include + #include "tpm20.h" +#define TPM_HARVEST_SIZE 16 +/* + * Perform a harvest every 10 seconds. + * Since discrete TPMs are painfully slow + * we don't want to execute this too often + * as the chip is likely to be used by others too. + */ +#define TPM_HARVEST_INTERVAL 10000000 + MALLOC_DECLARE(M_TPM20); MALLOC_DEFINE(M_TPM20, "tpm_buffer", "buffer for tpm 2.0 driver"); static void tpm20_discard_buffer(void *arg); -static int tpm20_save_state(device_t dev, bool suspend); +#ifdef TPM_HARVEST +static void tpm20_harvest(void *arg); +#endif +static int tpm20_save_state(device_t dev, bool suspend); static d_open_t tpm20_open; static d_close_t tpm20_close; @@ -63,6 +77,10 @@ tpm20_read(struct cdev *dev, struct uio *uio, int flag callout_stop(&sc->discard_buffer_callout); sx_xlock(&sc->dev_lock); + if (sc->owner_tid != uio->uio_td->td_tid) { + sx_xunlock(&sc->dev_lock); + return (EPERM); + } bytes_to_transfer = MIN(sc->pending_data_length, uio->uio_resid); if (bytes_to_transfer > 0) { @@ -114,15 +132,18 @@ tpm20_write(struct cdev *dev, struct uio *uio, int fla result = sc->transmit(sc, byte_count); - if (result == 0) + if (result == 0) { callout_reset(&sc->discard_buffer_callout, TPM_READ_TIMEOUT / tick, tpm20_discard_buffer, sc); + sc->owner_tid = uio->uio_td->td_tid; + } sx_xunlock(&sc->dev_lock); return (result); } -static void tpm20_discard_buffer(void *arg) +static void +tpm20_discard_buffer(void *arg) { struct tpm_sc *sc; @@ -175,6 +196,11 @@ tpm20_init(struct tpm_sc *sc) sx_init(&sc->dev_lock, "TPM driver lock"); cv_init(&sc->buf_cv, "TPM buffer cv"); callout_init(&sc->discard_buffer_callout, 1); +#ifdef TPM_HARVEST + sc->harvest_ticks = TPM_HARVEST_INTERVAL / tick; + callout_init(&sc->harvest_callout, 1); + callout_reset(&sc->harvest_callout, 0, tpm20_harvest, sc); +#endif sc->pending_data_length = 0; make_dev_args_init(&args); @@ -195,6 +221,10 @@ void tpm20_release(struct tpm_sc *sc) { +#ifdef TPM_HARVEST + callout_drain(&sc->harvest_callout); +#endif + if (sc->buf != NULL) free(sc->buf, M_TPM20); @@ -217,14 +247,68 @@ tpm20_shutdown(device_t dev) return (tpm20_save_state(dev, false)); } +#ifdef TPM_HARVEST + +/* + * Get TPM_HARVEST_SIZE random bytes and add them + * into system entropy pool. + */ +static void +tpm20_harvest(void *arg) +{ + struct tpm_sc *sc; + unsigned char entropy[TPM_HARVEST_SIZE]; + uint16_t entropy_size; + int result; + uint8_t cmd[] = { + 0x80, 0x01, /* TPM_ST_NO_SESSIONS tag*/ + 0x00, 0x00, 0x00, 0x0c, /* cmd length */ + 0x00, 0x00, 0x01, 0x7b, /* cmd TPM_CC_GetRandom */ + 0x00, TPM_HARVEST_SIZE /* number of bytes requested */ + }; + + + sc = arg; + sx_xlock(&sc->dev_lock); + while (sc->pending_data_length != 0) + cv_wait(&sc->buf_cv, &sc->dev_lock); + + memcpy(sc->buf, cmd, sizeof(cmd)); + result = sc->transmit(sc, sizeof(cmd)); + if (result != 0) { + sx_xunlock(&sc->dev_lock); + return; + } + + /* Ignore response size */ + sc->pending_data_length = 0; + + /* The number of random bytes we got is placed right after the header */ + entropy_size = (uint16_t) sc->buf[TPM_HEADER_SIZE + 1]; + if (entropy_size > 0) { + entropy_size = MIN(entropy_size, TPM_HARVEST_SIZE); + memcpy(entropy, + sc->buf + TPM_HEADER_SIZE + sizeof(uint16_t), + entropy_size); + } + + sx_xunlock(&sc->dev_lock); + if (entropy_size > 0) + random_harvest_queue(entropy, entropy_size, RANDOM_PURE_TPM); + + callout_reset(&sc->harvest_callout, sc->harvest_ticks, tpm20_harvest, sc); +} +#endif /* TPM_HARVEST */ + static int tpm20_save_state(device_t dev, bool suspend) { struct tpm_sc *sc; uint8_t save_cmd[] = { - 0x80, 0x01, /* TPM_ST_NO_SESSIONS tag*/ + 0x80, 0x01, /* TPM_ST_NO_SESSIONS tag*/ 0x00, 0x00, 0x00, 0x0C, /* cmd length */ - 0x00, 0x00, 0x01, 0x45, 0x00, 0x00 /* cmd TPM_CC_Shutdown */ + 0x00, 0x00, 0x01, 0x45, /* cmd TPM_CC_Shutdown */ + 0x00, 0x00 /* TPM_SU_STATE */ }; sc = device_get_softc(dev); @@ -233,7 +317,7 @@ tpm20_save_state(device_t dev, bool suspend) * Inform the TPM whether we are going to suspend or reboot/shutdown. */ if (suspend) - save_cmd[11] = 1; /* TPM_SU_STATE */ + save_cmd[11] = 1; /* TPM_SU_STATE */ if (sc == NULL || sc->buf == NULL) return (0); Modified: stable/12/sys/dev/tpm/tpm20.h ============================================================================== --- stable/12/sys/dev/tpm/tpm20.h Fri Apr 26 01:29:00 2019 (r346723) +++ stable/12/sys/dev/tpm/tpm20.h Fri Apr 26 01:41:55 2019 (r346724) @@ -26,7 +26,7 @@ */ #ifndef _TPM20_H_ -#define _TPM20_H_ +#define _TPM20_H_ #include __FBSDID("$FreeBSD$"); @@ -55,49 +55,51 @@ __FBSDID("$FreeBSD$"); #include #include "opt_acpi.h" +#include "opt_tpm.h" + #define BIT(x) (1 << (x)) /* Timeouts in us */ -#define TPM_TIMEOUT_A 750000 -#define TPM_TIMEOUT_B 2000000 -#define TPM_TIMEOUT_C 200000 -#define TPM_TIMEOUT_D 30000 +#define TPM_TIMEOUT_A 750000 +#define TPM_TIMEOUT_B 2000000 +#define TPM_TIMEOUT_C 200000 +#define TPM_TIMEOUT_D 30000 /* * Generating RSA key pair takes ~(10-20s), which is significantly longer than * any timeout defined in spec. Because of that we need a new one. */ -#define TPM_TIMEOUT_LONG 40000000 +#define TPM_TIMEOUT_LONG 40000000 /* List of commands that require TPM_TIMEOUT_LONG time to complete */ -#define TPM_CC_CreatePrimary 0x00000131 +#define TPM_CC_CreatePrimary 0x00000131 #define TPM_CC_Create 0x00000153 #define TPM_CC_CreateLoaded 0x00000191 /* List of commands that require only TPM_TIMEOUT_C time to complete */ -#define TPM_CC_SequenceComplete 0x0000013e -#define TPM_CC_Startup 0x00000144 -#define TPM_CC_SequenceUpdate 0x0000015c -#define TPM_CC_GetCapability 0x0000017a -#define TPM_CC_PCR_Extend 0x00000182 -#define TPM_CC_EventSequenceComplete 0x00000185 -#define TPM_CC_HashSequenceStart 0x00000186 +#define TPM_CC_SequenceComplete 0x0000013e +#define TPM_CC_Startup 0x00000144 +#define TPM_CC_SequenceUpdate 0x0000015c +#define TPM_CC_GetCapability 0x0000017a +#define TPM_CC_PCR_Extend 0x00000182 +#define TPM_CC_EventSequenceComplete 0x00000185 +#define TPM_CC_HashSequenceStart 0x00000186 /* Timeout before data in read buffer is discarded */ -#define TPM_READ_TIMEOUT 500000 +#define TPM_READ_TIMEOUT 500000 -#define TPM_BUFSIZE 0x1000 +#define TPM_BUFSIZE 0x1000 -#define TPM_HEADER_SIZE 10 +#define TPM_HEADER_SIZE 10 -#define TPM_CDEV_NAME "tpm0" -#define TPM_CDEV_PERM_FLAG 0600 +#define TPM_CDEV_NAME "tpm0" +#define TPM_CDEV_PERM_FLAG 0600 -#define TPM2_START_METHOD_ACPI 2 -#define TPM2_START_METHOD_TIS 6 -#define TPM2_START_METHOD_CRB 7 -#define TPM2_START_METHOD_CRB_ACPI 8 +#define TPM2_START_METHOD_ACPI 2 +#define TPM2_START_METHOD_TIS 6 +#define TPM2_START_METHOD_CRB 7 +#define TPM2_START_METHOD_CRB_ACPI 8 struct tpm_sc { device_t dev; @@ -118,8 +120,13 @@ struct tpm_sc { uint8_t *buf; size_t pending_data_length; + lwpid_t owner_tid; struct callout discard_buffer_callout; +#ifdef TPM_HARVEST + struct callout harvest_callout; + int harvest_ticks; +#endif int (*transmit)(struct tpm_sc *, size_t); }; Modified: stable/12/sys/dev/tpm/tpm_crb.c ============================================================================== --- stable/12/sys/dev/tpm/tpm_crb.c Fri Apr 26 01:29:00 2019 (r346723) +++ stable/12/sys/dev/tpm/tpm_crb.c Fri Apr 26 01:41:55 2019 (r346724) @@ -34,47 +34,47 @@ __FBSDID("$FreeBSD$"); * CRB register space as defined in * TCG_PC_Client_Platform_TPM_Profile_PTP_2.0_r1.03_v22 */ -#define TPM_LOC_STATE 0x0 -#define TPM_LOC_CTRL 0x8 -#define TPM_LOC_STS 0xC -#define TPM_CRB_INTF_ID 0x30 -#define TPM_CRB_CTRL_EXT 0x38 -#define TPM_CRB_CTRL_REQ 0x40 -#define TPM_CRB_CTRL_STS 0x44 -#define TPM_CRB_CTRL_CANCEL 0x48 -#define TPM_CRB_CTRL_START 0x4C -#define TPM_CRB_INT_ENABLE 0x50 -#define TPM_CRB_INT_STS 0x54 -#define TPM_CRB_CTRL_CMD_SIZE 0x58 -#define TPM_CRB_CTRL_CMD_LADDR 0x5C -#define TPM_CRB_CTRL_CMD_HADDR 0x60 -#define TPM_CRB_CTRL_RSP_SIZE 0x64 -#define TPM_CRB_CTRL_RSP_ADDR 0x68 -#define TPM_CRB_CTRL_RSP_HADDR 0x6c -#define TPM_CRB_DATA_BUFFER 0x80 +#define TPM_LOC_STATE 0x0 +#define TPM_LOC_CTRL 0x8 +#define TPM_LOC_STS 0xC +#define TPM_CRB_INTF_ID 0x30 +#define TPM_CRB_CTRL_EXT 0x38 +#define TPM_CRB_CTRL_REQ 0x40 +#define TPM_CRB_CTRL_STS 0x44 +#define TPM_CRB_CTRL_CANCEL 0x48 +#define TPM_CRB_CTRL_START 0x4C +#define TPM_CRB_INT_ENABLE 0x50 +#define TPM_CRB_INT_STS 0x54 +#define TPM_CRB_CTRL_CMD_SIZE 0x58 +#define TPM_CRB_CTRL_CMD_LADDR 0x5C +#define TPM_CRB_CTRL_CMD_HADDR 0x60 +#define TPM_CRB_CTRL_RSP_SIZE 0x64 +#define TPM_CRB_CTRL_RSP_ADDR 0x68 +#define TPM_CRB_CTRL_RSP_HADDR 0x6c +#define TPM_CRB_DATA_BUFFER 0x80 -#define TPM_LOC_STATE_ESTB BIT(0) -#define TPM_LOC_STATE_ASSIGNED BIT(1) -#define TPM_LOC_STATE_ACTIVE_MASK 0x9C -#define TPM_LOC_STATE_VALID BIT(7) +#define TPM_LOC_STATE_ESTB BIT(0) +#define TPM_LOC_STATE_ASSIGNED BIT(1) +#define TPM_LOC_STATE_ACTIVE_MASK 0x9C +#define TPM_LOC_STATE_VALID BIT(7) -#define TPM_CRB_INTF_ID_TYPE_CRB 0x1 -#define TPM_CRB_INTF_ID_TYPE 0x7 +#define TPM_CRB_INTF_ID_TYPE_CRB 0x1 +#define TPM_CRB_INTF_ID_TYPE 0x7 -#define TPM_LOC_CTRL_REQUEST BIT(0) -#define TPM_LOC_CTRL_RELINQUISH BIT(1) +#define TPM_LOC_CTRL_REQUEST BIT(0) +#define TPM_LOC_CTRL_RELINQUISH BIT(1) -#define TPM_CRB_CTRL_REQ_GO_READY BIT(0) -#define TPM_CRB_CTRL_REQ_GO_IDLE BIT(1) +#define TPM_CRB_CTRL_REQ_GO_READY BIT(0) +#define TPM_CRB_CTRL_REQ_GO_IDLE BIT(1) -#define TPM_CRB_CTRL_STS_ERR_BIT BIT(0) -#define TPM_CRB_CTRL_STS_IDLE_BIT BIT(1) +#define TPM_CRB_CTRL_STS_ERR_BIT BIT(0) +#define TPM_CRB_CTRL_STS_IDLE_BIT BIT(1) -#define TPM_CRB_CTRL_CANCEL_CMD BIT(0) +#define TPM_CRB_CTRL_CANCEL_CMD BIT(0) -#define TPM_CRB_CTRL_START_CMD BIT(0) +#define TPM_CRB_CTRL_START_CMD BIT(0) -#define TPM_CRB_INT_ENABLE_BIT BIT(31) +#define TPM_CRB_INT_ENABLE_BIT BIT(31) struct tpmcrb_sc { struct tpm_sc base; @@ -166,7 +166,8 @@ tpmcrb_attach(device_t dev) return (ENXIO); if(!tpmcrb_request_locality(sc, 0)) { - tpmcrb_detach(dev); + bus_release_resource(dev, SYS_RES_MEMORY, + sc->mem_rid, sc->mem_res); return (ENXIO); } @@ -232,12 +233,12 @@ tpmcrb_detach(device_t dev) struct tpm_sc *sc; sc = device_get_softc(dev); + tpm20_release(sc); if (sc->mem_res != NULL) bus_release_resource(dev, SYS_RES_MEMORY, sc->mem_rid, sc->mem_res); - tpm20_release(sc); return (0); } Modified: stable/12/sys/dev/tpm/tpm_tis.c ============================================================================== --- stable/12/sys/dev/tpm/tpm_tis.c Fri Apr 26 01:29:00 2019 (r346723) +++ stable/12/sys/dev/tpm/tpm_tis.c Fri Apr 26 01:41:55 2019 (r346724) @@ -34,45 +34,45 @@ __FBSDID("$FreeBSD$"); * TIS register space as defined in * TCG_PC_Client_Platform_TPM_Profile_PTP_2.0_r1.03_v22 */ -#define TPM_ACCESS 0x0 -#define TPM_INT_ENABLE 0x8 -#define TPM_INT_VECTOR 0xc -#define TPM_INT_STS 0x10 -#define TPM_INTF_CAPS 0x14 -#define TPM_STS 0x18 -#define TPM_DATA_FIFO 0x24 -#define TPM_INTF_ID 0x30 -#define TPM_XDATA_FIFO 0x80 -#define TPM_DID_VID 0xF00 -#define TPM_RID 0xF04 +#define TPM_ACCESS 0x0 +#define TPM_INT_ENABLE 0x8 +#define TPM_INT_VECTOR 0xc +#define TPM_INT_STS 0x10 +#define TPM_INTF_CAPS 0x14 +#define TPM_STS 0x18 +#define TPM_DATA_FIFO 0x24 +#define TPM_INTF_ID 0x30 +#define TPM_XDATA_FIFO 0x80 +#define TPM_DID_VID 0xF00 +#define TPM_RID 0xF04 -#define TPM_ACCESS_LOC_REQ BIT(1) -#define TPM_ACCESS_LOC_Seize BIT(3) -#define TPM_ACCESS_LOC_ACTIVE BIT(5) -#define TPM_ACCESS_LOC_RELINQUISH BIT(5) -#define TPM_ACCESS_VALID BIT(7) +#define TPM_ACCESS_LOC_REQ BIT(1) +#define TPM_ACCESS_LOC_Seize BIT(3) +#define TPM_ACCESS_LOC_ACTIVE BIT(5) +#define TPM_ACCESS_LOC_RELINQUISH BIT(5) +#define TPM_ACCESS_VALID BIT(7) -#define TPM_INT_ENABLE_GLOBAL_ENABLE BIT(31) -#define TPM_INT_ENABLE_CMD_RDY BIT(7) -#define TPM_INT_ENABLE_LOC_CHANGE BIT(2) -#define TPM_INT_ENABLE_STS_VALID BIT(1) -#define TPM_INT_ENABLE_DATA_AVAIL BIT(0) +#define TPM_INT_ENABLE_GLOBAL_ENABLE BIT(31) +#define TPM_INT_ENABLE_CMD_RDY BIT(7) +#define TPM_INT_ENABLE_LOC_CHANGE BIT(2) +#define TPM_INT_ENABLE_STS_VALID BIT(1) +#define TPM_INT_ENABLE_DATA_AVAIL BIT(0) -#define TPM_INT_STS_CMD_RDY BIT(7) -#define TPM_INT_STS_LOC_CHANGE BIT(2) -#define TPM_INT_STS_VALID BIT(1) -#define TPM_INT_STS_DATA_AVAIL BIT(0) +#define TPM_INT_STS_CMD_RDY BIT(7) +#define TPM_INT_STS_LOC_CHANGE BIT(2) +#define TPM_INT_STS_VALID BIT(1) +#define TPM_INT_STS_DATA_AVAIL BIT(0) -#define TPM_INTF_CAPS_VERSION 0x70000000 -#define TPM_INTF_CAPS_TPM20 0x30000000 +#define TPM_INTF_CAPS_VERSION 0x70000000 +#define TPM_INTF_CAPS_TPM20 0x30000000 -#define TPM_STS_VALID BIT(7) -#define TPM_STS_CMD_RDY BIT(6) -#define TPM_STS_CMD_START BIT(5) -#define TPM_STS_DATA_AVAIL BIT(4) -#define TPM_STS_DATA_EXPECTED BIT(3) -#define TPM_STS_BURST_MASK 0xFFFF00 -#define TPM_STS_BURST_OFFSET 0x8 +#define TPM_STS_VALID BIT(7) +#define TPM_STS_CMD_RDY BIT(6) +#define TPM_STS_CMD_START BIT(5) +#define TPM_STS_DATA_AVAIL BIT(4) +#define TPM_STS_DATA_EXPECTED BIT(3) +#define TPM_STS_BURST_MASK 0xFFFF00 +#define TPM_STS_BURST_OFFSET 0x8 static int tpmtis_transmit(struct tpm_sc *sc, size_t length); @@ -93,6 +93,7 @@ static bool tpmtis_go_ready(struct tpm_sc *sc); static bool tpm_wait_for_u32(struct tpm_sc *sc, bus_size_t off, uint32_t mask, uint32_t val, int32_t timeout); + static uint16_t tpmtis_wait_for_burst(struct tpm_sc *sc); char *tpmtis_ids[] = {"MSFT0101", NULL}; @@ -161,6 +162,7 @@ tpmtis_detach(device_t dev) struct tpm_sc *sc; sc = device_get_softc(dev); + tpm20_release(sc); if (sc->intr_cookie != NULL) bus_teardown_intr(dev, sc->irq_res, sc->intr_cookie); @@ -173,7 +175,6 @@ tpmtis_detach(device_t dev) bus_release_resource(dev, SYS_RES_MEMORY, sc->mem_rid, sc->mem_res); - tpm20_release(sc); return (0); } Modified: stable/12/sys/sys/random.h ============================================================================== --- stable/12/sys/sys/random.h Fri Apr 26 01:29:00 2019 (r346723) +++ stable/12/sys/sys/random.h Fri Apr 26 01:41:55 2019 (r346724) @@ -90,6 +90,7 @@ enum random_entropy_source { RANDOM_PURE_BROADCOM, RANDOM_PURE_CCP, RANDOM_PURE_DARN, + RANDOM_PURE_TPM, ENTROPYSOURCE }; From owner-svn-src-stable-12@freebsd.org Fri Apr 26 02:16:58 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A5F3E1584D94; Fri, 26 Apr 2019 02:16:58 +0000 (UTC) (envelope-from mw@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id D545875B8D; Fri, 26 Apr 2019 02:16:57 +0000 (UTC) (envelope-from mw@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id AC9294E17; Fri, 26 Apr 2019 02:16:57 +0000 (UTC) (envelope-from mw@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3Q2GvoH032918; Fri, 26 Apr 2019 02:16:57 GMT (envelope-from mw@FreeBSD.org) Received: (from mw@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3Q2Gv71032917; Fri, 26 Apr 2019 02:16:57 GMT (envelope-from mw@FreeBSD.org) Message-Id: <201904260216.x3Q2Gv71032917@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mw set sender to mw@FreeBSD.org using -f From: Marcin Wojtas Date: Fri, 26 Apr 2019 02:16:57 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346726 - stable/12/usr.sbin/acpi/acpidump X-SVN-Group: stable-12 X-SVN-Commit-Author: mw X-SVN-Commit-Paths: stable/12/usr.sbin/acpi/acpidump X-SVN-Commit-Revision: 346726 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: D545875B8D X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.96 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-0.99)[-0.994,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.97)[-0.970,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Apr 2019 02:16:58 -0000 Author: mw Date: Fri Apr 26 02:16:57 2019 New Revision: 346726 URL: https://svnweb.freebsd.org/changeset/base/346726 Log: MFC r343455: Fix tpm2 acpidump compilation on 32-bit Modified: stable/12/usr.sbin/acpi/acpidump/acpi.c Modified: stable/12/usr.sbin/acpi/acpidump/acpi.c ============================================================================== --- stable/12/usr.sbin/acpi/acpidump/acpi.c Fri Apr 26 01:58:36 2019 (r346725) +++ stable/12/usr.sbin/acpi/acpidump/acpi.c Fri Apr 26 02:16:57 2019 (r346726) @@ -977,7 +977,7 @@ static void acpi_handle_tpm2(ACPI_TABLE_HEADER *sdp) printf (BEGIN_COMMENT); acpi_print_sdt(sdp); tpm2 = (ACPI_TABLE_TPM2 *) sdp; - printf ("\t\tControlArea=%lx\n", tpm2->ControlAddress); + printf ("\t\tControlArea=%jx\n", tpm2->ControlAddress); printf ("\t\tStartMethod=%x\n", tpm2->StartMethod); printf (END_COMMENT); } From owner-svn-src-stable-12@freebsd.org Fri Apr 26 11:12:56 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id D4D261590C5F; Fri, 26 Apr 2019 11:12:55 +0000 (UTC) (envelope-from mw@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 5188B8EAB3; Fri, 26 Apr 2019 11:12:55 +0000 (UTC) (envelope-from mw@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id DFB52AB33; Fri, 26 Apr 2019 11:12:53 +0000 (UTC) (envelope-from mw@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3QBCr6e017178; Fri, 26 Apr 2019 11:12:53 GMT (envelope-from mw@FreeBSD.org) Received: (from mw@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3QBCpiC017168; Fri, 26 Apr 2019 11:12:51 GMT (envelope-from mw@FreeBSD.org) Message-Id: <201904261112.x3QBCpiC017168@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mw set sender to mw@FreeBSD.org using -f From: Marcin Wojtas Date: Fri, 26 Apr 2019 11:12:51 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346737 - in stable/12: lib/libsecureboot lib/libsecureboot/h share/mk stand stand/common sys/conf sys/security/mac_veriexec_parser tools/build/options X-SVN-Group: stable-12 X-SVN-Commit-Author: mw X-SVN-Commit-Paths: in stable/12: lib/libsecureboot lib/libsecureboot/h share/mk stand stand/common sys/conf sys/security/mac_veriexec_parser tools/build/options X-SVN-Commit-Revision: 346737 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 5188B8EAB3 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.96 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-0.99)[-0.995,0]; NEURAL_HAM_SHORT(-0.96)[-0.965,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Apr 2019 11:12:56 -0000 Author: mw Date: Fri Apr 26 11:12:51 2019 New Revision: 346737 URL: https://svnweb.freebsd.org/changeset/base/346737 Log: MFC r345830: Create kernel module to parse Veriexec manifest based on envs Submitted by: Kornel Duleba Obtained from: Semihalf Sponsored by: Stormshield Added: stable/12/lib/libsecureboot/pass_manifest.c - copied unchanged from r345830, head/lib/libsecureboot/pass_manifest.c stable/12/sys/security/mac_veriexec_parser/ - copied from r345830, head/sys/security/mac_veriexec_parser/ stable/12/tools/build/options/WITH_LOADER_VERIEXEC_PASS_MANFIEST - copied unchanged from r345830, head/tools/build/options/WITH_LOADER_VERIEXEC_PASS_MANFIEST Modified: stable/12/lib/libsecureboot/Makefile.libsa.inc stable/12/lib/libsecureboot/h/verify_file.h stable/12/lib/libsecureboot/libsecureboot-priv.h stable/12/lib/libsecureboot/verify_file.c stable/12/share/mk/src.opts.mk stable/12/stand/common/boot.c stable/12/stand/common/module.c stable/12/stand/loader.mk stable/12/sys/conf/files Modified: stable/12/lib/libsecureboot/Makefile.libsa.inc ============================================================================== --- stable/12/lib/libsecureboot/Makefile.libsa.inc Fri Apr 26 09:06:29 2019 (r346736) +++ stable/12/lib/libsecureboot/Makefile.libsa.inc Fri Apr 26 11:12:51 2019 (r346737) @@ -29,6 +29,11 @@ CFLAGS+= \ -I${SRCTOP}/stand/efi/include/${MACHINE} .endif +.if ${MK_LOADER_VERIEXEC_PASS_MANIFEST} == "yes" +SRCS+= \ + pass_manifest.c +.endif + # this is the list of paths (relative to a file # that we need to verify) used to find a signed manifest. # the signature extensions in VE_SIGNATURE_EXT_LIST Modified: stable/12/lib/libsecureboot/h/verify_file.h ============================================================================== --- stable/12/lib/libsecureboot/h/verify_file.h Fri Apr 26 09:06:29 2019 (r346736) +++ stable/12/lib/libsecureboot/h/verify_file.h Fri Apr 26 11:12:51 2019 (r346737) @@ -32,6 +32,7 @@ #define VE_WANT 1 /* we want this verified */ #define VE_MUST 2 /* this must be verified */ +#define VE_NOT_CHECKED -42 #define VE_VERIFIED 1 /* all good */ #define VE_UNVERIFIED_OK 0 /* not verified but that's ok */ #define VE_NOT_VERIFYING 2 /* we are not verifying */ @@ -42,6 +43,8 @@ void ve_debug_set(int); int ve_status_get(int); void ve_efi_init(void); int load_manifest(const char *, const char *, const char *, struct stat *); +int pass_manifest(const char *, const char *); +int pass_manifest_export_envs(void); int verify_file(int, const char *, off_t, int); void verify_pcr_export(void); Modified: stable/12/lib/libsecureboot/libsecureboot-priv.h ============================================================================== --- stable/12/lib/libsecureboot/libsecureboot-priv.h Fri Apr 26 09:06:29 2019 (r346736) +++ stable/12/lib/libsecureboot/libsecureboot-priv.h Fri Apr 26 11:12:51 2019 (r346737) @@ -31,6 +31,8 @@ /* public api */ #include "libsecureboot.h" +struct stat; + typedef struct { unsigned char *data; size_t hash_size; @@ -49,6 +51,9 @@ int verify_rsa_digest(br_rsa_public_key *pkey, const unsigned char *hash_oid, unsigned char *mdata, size_t mlen, unsigned char *sdata, size_t slen); + +int is_verified(struct stat *stp); +void add_verify_status(struct stat *stp, int status); int openpgp_self_tests(void); Copied: stable/12/lib/libsecureboot/pass_manifest.c (from r345830, head/lib/libsecureboot/pass_manifest.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/12/lib/libsecureboot/pass_manifest.c Fri Apr 26 11:12:51 2019 (r346737, copy of r345830, head/lib/libsecureboot/pass_manifest.c) @@ -0,0 +1,152 @@ +/*- + * Copyright (c) 2019 Stormshield. + * Copyright (c) 2019 Semihalf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ +#include +__FBSDID("$FreeBSD$"); + +#include + +#include "libsecureboot-priv.h" +#include + +/* + * Values to pass to kernel by envs. + */ +static char manifest_path[MAXPATHLEN]; +static char manifest_prefix[MAXPATHLEN]; +static char manifest_hash[2 * br_sha256_SIZE + 2]; +static int manifest_present = 0; + +/* + * Verify and pass manifest path and digest to kernel through envs. + * The paths in manifest can be either absolute, + * or "prefix", if exists will be added to the ones that are not. + */ +int +pass_manifest(const char *path, const char *prefix) +{ + char *content; + struct stat st; + unsigned char digest[br_sha256_SIZE]; + const br_hash_class *md; + br_hash_compat_context ctx; + int rc; + + content = NULL; + md = &br_sha256_vtable; + + if (strnlen(path, MAXPATHLEN) == MAXPATHLEN || + strnlen(prefix, MAXPATHLEN) == MAXPATHLEN) + return (EINVAL); + + rc = stat(path, &st); + if (rc != 0) + goto out; + + if (!S_ISREG(st.st_mode)) { + rc = EINVAL; + goto out; + } + + rc = is_verified(&st); + + if (rc != VE_NOT_CHECKED && rc != VE_VERIFIED) { + rc = EPERM; + goto out; + } + + if (rc == VE_VERIFIED) + content = read_file(path, NULL); + else + content = (char *)verify_signed(path, VEF_VERBOSE); + + if (content == NULL) { + add_verify_status(&st, VE_FINGERPRINT_WRONG); + rc = EIO; + goto out; + } + + add_verify_status(&st, VE_VERIFIED); + + md->init(&ctx.vtable); + md->update(&ctx.vtable, content, st.st_size); + md->out(&ctx.vtable, digest); + + if (prefix == NULL) + manifest_prefix[0] = '\0'; + else + strcpy(manifest_prefix, prefix); + + strcpy(manifest_path, path); + + hexdigest(manifest_hash, 2 * br_sha256_SIZE + 2, + digest, br_sha256_SIZE); + manifest_hash[2*br_sha256_SIZE] = '\0'; + + manifest_present = 1; + rc = 0; + +out: + if (content != NULL) + free(content); + + return (rc); +} + +/* + * Set appropriate envs to inform kernel about manifest location and digest. + * This should be called right before boot so that envs can't be replaced. + */ +int +pass_manifest_export_envs() +{ + int rc; + + /* If we have nothing to pass make sure that envs are empty. */ + if (!manifest_present) { + unsetenv("veriexec.manifest_path"); + unsetenv("veriexec.manifest_hash"); + unsetenv("veriexec.manifest_prefix"); + return (0); + } + + rc = setenv("veriexec.manifest_path", manifest_path, 1); + if (rc != 0) + return (rc); + + rc = setenv("veriexec.manifest_hash", manifest_hash, 1); + if (rc != 0) { + unsetenv("veriexec.manifest_path"); + return (rc); + } + + if (manifest_prefix[0] != '\0') + rc = setenv("veriexec.manifest_prefix", manifest_prefix, 1); + + return (rc); +} + Modified: stable/12/lib/libsecureboot/verify_file.c ============================================================================== --- stable/12/lib/libsecureboot/verify_file.c Fri Apr 26 09:06:29 2019 (r346736) +++ stable/12/lib/libsecureboot/verify_file.c Fri Apr 26 11:12:51 2019 (r346737) @@ -36,8 +36,6 @@ __FBSDID("$FreeBSD$"); #include #include -#define VE_NOT_CHECKED -42 - #ifdef UNIT_TEST # include # define panic warn @@ -112,7 +110,7 @@ struct verify_status { struct verify_status *vs_next; }; -static int +int is_verified(struct stat *stp) { struct verify_status *vsp; @@ -126,7 +124,7 @@ is_verified(struct stat *stp) } /* most recent first, since most likely to see repeated calls. */ -static void +void add_verify_status(struct stat *stp, int status) { struct verify_status *vsp; Modified: stable/12/share/mk/src.opts.mk ============================================================================== --- stable/12/share/mk/src.opts.mk Fri Apr 26 09:06:29 2019 (r346736) +++ stable/12/share/mk/src.opts.mk Fri Apr 26 11:12:51 2019 (r346737) @@ -200,6 +200,7 @@ __DEFAULT_NO_OPTIONS = \ LIBSOFT \ LOADER_FIREWIRE \ LOADER_FORCE_LE \ + LOADER_VERIEXEC_PASS_MANIFEST \ NAND \ OFED_EXTRA \ OPENLDAP \ @@ -543,6 +544,10 @@ MK_LLDB:= no MK_CLANG_EXTRAS:= no MK_CLANG_FULL:= no MK_LLVM_COV:= no +.endif + +.if ${MK_LOADER_VERIEXEC} == "no" +MK_LOADER_VERIEXEC_PASS_MANIFEST := no .endif # Modified: stable/12/stand/common/boot.c ============================================================================== --- stable/12/stand/common/boot.c Fri Apr 26 09:06:29 2019 (r346736) +++ stable/12/stand/common/boot.c Fri Apr 26 11:12:51 2019 (r346737) @@ -108,6 +108,9 @@ command_boot(int argc, char *argv[]) #ifdef LOADER_VERIEXEC verify_pcr_export(); /* for measured boot */ +#ifdef LOADER_VERIEXEC_PASS_MANIFEST + pass_manifest_export_envs(); +#endif #endif /* Call the exec handler from the loader matching the kernel */ Modified: stable/12/stand/common/module.c ============================================================================== --- stable/12/stand/common/module.c Fri Apr 26 09:06:29 2019 (r346736) +++ stable/12/stand/common/module.c Fri Apr 26 11:12:51 2019 (r346737) @@ -159,6 +159,13 @@ command_load(int argc, char *argv[]) ve_debug_set(dflag); return (load_manifest(argv[1], prefix, skip, NULL)); } +#ifdef LOADER_VERIEXEC_PASS_MANIFEST + if (strncmp(typestr, "pass_manifest", 13) == 0) { + if (dflag > 0) + ve_debug_set(dflag); + return (pass_manifest(argv[1], prefix)); + } +#endif #endif fp = file_findfile(argv[1], typestr); Modified: stable/12/stand/loader.mk ============================================================================== --- stable/12/stand/loader.mk Fri Apr 26 09:06:29 2019 (r346736) +++ stable/12/stand/loader.mk Fri Apr 26 11:12:51 2019 (r346737) @@ -77,6 +77,10 @@ SRCS+= interp_simple.c CFLAGS+= -DLOADER_VERIEXEC -I${SRCTOP}/lib/libsecureboot/h .endif +.if ${MK_LOADER_VERIEXEC_PASS_MANIFEST} != "no" +CFLAGS+= -DLOADER_VERIEXEC_PASS_MANIFEST -I${SRCTOP}/lib/libsecureboot/h +.endif + .if defined(BOOT_PROMPT_123) CFLAGS+= -DBOOT_PROMPT_123 .endif Modified: stable/12/sys/conf/files ============================================================================== --- stable/12/sys/conf/files Fri Apr 26 09:06:29 2019 (r346736) +++ stable/12/sys/conf/files Fri Apr 26 11:12:51 2019 (r346737) @@ -4934,14 +4934,15 @@ security/mac_portacl/mac_portacl.c optional mac_portac security/mac_seeotheruids/mac_seeotheruids.c optional mac_seeotheruids security/mac_stub/mac_stub.c optional mac_stub security/mac_test/mac_test.c optional mac_test -security/mac_veriexec/mac_veriexec.c optional mac_veriexec -security/mac_veriexec/veriexec_fingerprint.c optional mac_veriexec -security/mac_veriexec/veriexec_metadata.c optional mac_veriexec -security/mac_veriexec/mac_veriexec_rmd160.c optional mac_veriexec_rmd160 -security/mac_veriexec/mac_veriexec_sha1.c optional mac_veriexec_sha1 -security/mac_veriexec/mac_veriexec_sha256.c optional mac_veriexec_sha256 -security/mac_veriexec/mac_veriexec_sha384.c optional mac_veriexec_sha384 -security/mac_veriexec/mac_veriexec_sha512.c optional mac_veriexec_sha512 +security/mac_veriexec/mac_veriexec.c optional mac_veriexec +security/mac_veriexec/veriexec_fingerprint.c optional mac_veriexec +security/mac_veriexec/veriexec_metadata.c optional mac_veriexec +security/mac_veriexec_parser/mac_veriexec_parser.c optional mac_veriexec mac_veriexec_parser +security/mac_veriexec/mac_veriexec_rmd160.c optional mac_veriexec_rmd160 +security/mac_veriexec/mac_veriexec_sha1.c optional mac_veriexec_sha1 +security/mac_veriexec/mac_veriexec_sha256.c optional mac_veriexec_sha256 +security/mac_veriexec/mac_veriexec_sha384.c optional mac_veriexec_sha384 +security/mac_veriexec/mac_veriexec_sha512.c optional mac_veriexec_sha512 teken/teken.c optional sc | vt ufs/ffs/ffs_alloc.c optional ffs ufs/ffs/ffs_balloc.c optional ffs Copied: stable/12/tools/build/options/WITH_LOADER_VERIEXEC_PASS_MANFIEST (from r345830, head/tools/build/options/WITH_LOADER_VERIEXEC_PASS_MANFIEST) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/12/tools/build/options/WITH_LOADER_VERIEXEC_PASS_MANFIEST Fri Apr 26 11:12:51 2019 (r346737, copy of r345830, head/tools/build/options/WITH_LOADER_VERIEXEC_PASS_MANFIEST) @@ -0,0 +1,8 @@ +.\" $FreeBSD$ +Enable building +.Xr loader 8 +with support to pass a verified manifest to kernel. +Kernel has to be build with a module to parse the manfiest. +.Pp +It depends on +.Va WITH_LOADER_VERIEXEC From owner-svn-src-stable-12@freebsd.org Fri Apr 26 12:59:24 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 12D65159397F; Fri, 26 Apr 2019 12:59:24 +0000 (UTC) (envelope-from kp@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id A97B26B842; Fri, 26 Apr 2019 12:59:23 +0000 (UTC) (envelope-from kp@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 99935BDDA; Fri, 26 Apr 2019 12:59:23 +0000 (UTC) (envelope-from kp@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3QCxNQh070149; Fri, 26 Apr 2019 12:59:23 GMT (envelope-from kp@FreeBSD.org) Received: (from kp@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3QCxN6c070148; Fri, 26 Apr 2019 12:59:23 GMT (envelope-from kp@FreeBSD.org) Message-Id: <201904261259.x3QCxN6c070148@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kp set sender to kp@FreeBSD.org using -f From: Kristof Provost Date: Fri, 26 Apr 2019 12:59:23 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346740 - stable/12/tests/sys/netpfil/pf X-SVN-Group: stable-12 X-SVN-Commit-Author: kp X-SVN-Commit-Paths: stable/12/tests/sys/netpfil/pf X-SVN-Commit-Revision: 346740 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: A97B26B842 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.95 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.996,0]; NEURAL_HAM_SHORT(-0.96)[-0.957,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Apr 2019 12:59:24 -0000 Author: kp Date: Fri Apr 26 12:59:23 2019 New Revision: 346740 URL: https://svnweb.freebsd.org/changeset/base/346740 Log: MFC r346347: pf tests: Fail the test if we can't set the rules The test should fail if pf rules can't be set. This is helpful both while writing tests and to verify that pfctl works as expected. Modified: stable/12/tests/sys/netpfil/pf/utils.subr Directory Properties: stable/12/ (props changed) Modified: stable/12/tests/sys/netpfil/pf/utils.subr ============================================================================== --- stable/12/tests/sys/netpfil/pf/utils.subr Fri Apr 26 12:55:52 2019 (r346739) +++ stable/12/tests/sys/netpfil/pf/utils.subr Fri Apr 26 12:59:23 2019 (r346740) @@ -40,6 +40,10 @@ pft_set_rules() printf "$1\n" shift done | jexec ${jname} pfctl -f - + if [ $? -ne 0 ]; + then + atf_fail "Failed to set PF rules in ${jname}" + fi } pft_cleanup() From owner-svn-src-stable-12@freebsd.org Fri Apr 26 13:00:23 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A8DA81593A0A; Fri, 26 Apr 2019 13:00:23 +0000 (UTC) (envelope-from kp@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4FBA26B99E; Fri, 26 Apr 2019 13:00:23 +0000 (UTC) (envelope-from kp@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 2E502BDDF; Fri, 26 Apr 2019 13:00:23 +0000 (UTC) (envelope-from kp@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3QD0NIE070306; Fri, 26 Apr 2019 13:00:23 GMT (envelope-from kp@FreeBSD.org) Received: (from kp@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3QD0NoC070305; Fri, 26 Apr 2019 13:00:23 GMT (envelope-from kp@FreeBSD.org) Message-Id: <201904261300.x3QD0NoC070305@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kp set sender to kp@FreeBSD.org using -f From: Kristof Provost Date: Fri, 26 Apr 2019 13:00:23 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346741 - stable/12/sys/netpfil/pf X-SVN-Group: stable-12 X-SVN-Commit-Author: kp X-SVN-Commit-Paths: stable/12/sys/netpfil/pf X-SVN-Commit-Revision: 346741 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 4FBA26B99E X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.95 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.996,0]; NEURAL_HAM_SHORT(-0.96)[-0.957,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Apr 2019 13:00:23 -0000 Author: kp Date: Fri Apr 26 13:00:22 2019 New Revision: 346741 URL: https://svnweb.freebsd.org/changeset/base/346741 Log: MFC r346349: pf: No need to M_NOWAIT in DIOCRSETTFLAGS Now that we don't hold a lock during DIOCRSETTFLAGS memory allocation we can use M_WAITOK. Pointed out by: glebius@ Modified: stable/12/sys/netpfil/pf/pf_ioctl.c Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/netpfil/pf/pf_ioctl.c ============================================================================== --- stable/12/sys/netpfil/pf/pf_ioctl.c Fri Apr 26 12:59:23 2019 (r346740) +++ stable/12/sys/netpfil/pf/pf_ioctl.c Fri Apr 26 13:00:22 2019 (r346741) @@ -3110,11 +3110,7 @@ DIOCCHANGEADDR_error: totlen = io->pfrio_size * sizeof(struct pfr_table); pfrts = mallocarray(io->pfrio_size, sizeof(struct pfr_table), - M_TEMP, M_NOWAIT); - if (pfrts == NULL) { - error = ENOMEM; - break; - } + M_TEMP, M_WAITOK); error = copyin(io->pfrio_buffer, pfrts, totlen); if (error) { free(pfrts, M_TEMP); From owner-svn-src-stable-12@freebsd.org Fri Apr 26 14:15:59 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 4266A15953F9; Fri, 26 Apr 2019 14:15:59 +0000 (UTC) (envelope-from kp@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id DA16D6E588; Fri, 26 Apr 2019 14:15:58 +0000 (UTC) (envelope-from kp@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id B3E93CBD3; Fri, 26 Apr 2019 14:15:58 +0000 (UTC) (envelope-from kp@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3QEFwKq012515; Fri, 26 Apr 2019 14:15:58 GMT (envelope-from kp@FreeBSD.org) Received: (from kp@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3QEFw4w012514; Fri, 26 Apr 2019 14:15:58 GMT (envelope-from kp@FreeBSD.org) Message-Id: <201904261415.x3QEFw4w012514@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kp set sender to kp@FreeBSD.org using -f From: Kristof Provost Date: Fri, 26 Apr 2019 14:15:58 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346746 - stable/12/sbin/pfctl X-SVN-Group: stable-12 X-SVN-Commit-Author: kp X-SVN-Commit-Paths: stable/12/sbin/pfctl X-SVN-Commit-Revision: 346746 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: DA16D6E588 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.94 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.996,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.95)[-0.947,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Apr 2019 14:15:59 -0000 Author: kp Date: Fri Apr 26 14:15:58 2019 New Revision: 346746 URL: https://svnweb.freebsd.org/changeset/base/346746 Log: MFC r346370: pfctl: Fix ifgroup check We cannot just assume that any name which ends with a letter is a group That's not been true since we allowed renaming of network interfaces. It's also not true for things like epair0a. Try to retrieve the group members for the name to check, since we'll get ENOENT if the group doesn't exist. Modified: stable/12/sbin/pfctl/pfctl_optimize.c Directory Properties: stable/12/ (props changed) Modified: stable/12/sbin/pfctl/pfctl_optimize.c ============================================================================== --- stable/12/sbin/pfctl/pfctl_optimize.c Fri Apr 26 13:49:06 2019 (r346745) +++ stable/12/sbin/pfctl/pfctl_optimize.c Fri Apr 26 14:15:58 2019 (r346746) @@ -1500,14 +1500,24 @@ superblock_inclusive(struct superblock *block, struct int interface_group(const char *ifname) { + int s; + struct ifgroupreq ifgr; + if (ifname == NULL || !ifname[0]) return (0); - /* Real interfaces must end in a number, interface groups do not */ - if (isdigit(ifname[strlen(ifname) - 1])) - return (0); - else - return (1); + s = get_query_socket(); + + memset(&ifgr, 0, sizeof(ifgr)); + strlcpy(ifgr.ifgr_name, ifname, IFNAMSIZ); + if (ioctl(s, SIOCGIFGMEMB, (caddr_t)&ifgr) == -1) { + if (errno == ENOENT) + return (0); + else + err(1, "SIOCGIFGMEMB"); + } + + return (1); } From owner-svn-src-stable-12@freebsd.org Fri Apr 26 17:21:13 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 43068159959A; Fri, 26 Apr 2019 17:21:13 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id DADF275A07; Fri, 26 Apr 2019 17:21:12 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id B6704EC7A; Fri, 26 Apr 2019 17:21:12 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3QHLCkv008387; Fri, 26 Apr 2019 17:21:12 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3QHLCdB008385; Fri, 26 Apr 2019 17:21:12 GMT (envelope-from mav@FreeBSD.org) Message-Id: <201904261721.x3QHLCdB008385@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Fri, 26 Apr 2019 17:21:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346757 - stable/12/sys/cam X-SVN-Group: stable-12 X-SVN-Commit-Author: mav X-SVN-Commit-Paths: stable/12/sys/cam X-SVN-Commit-Revision: 346757 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: DADF275A07 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.96 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.996,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.97)[-0.968,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Apr 2019 17:21:13 -0000 Author: mav Date: Fri Apr 26 17:21:12 2019 New Revision: 346757 URL: https://svnweb.freebsd.org/changeset/base/346757 Log: MFC r345656: Do not map small IOCTL buffers to KVA, but copy. CAM IOCTL interfaces traditionally mapped user-space data buffers to KVA. It was nice originally, but now it takes too much to handle respective TLB shootdowns, while small kernel memory allocations up to 64KB backed by UMA and accompanied by copyin()/copyout() can be much cheaper. For large buffers mapping still may have sense, and unmapped I/O would be even better, but the last unfortunately is more tricky, since unmapped I/O API is too specific to struct bio now. Sponsored by: iXsystems, Inc. Modified: stable/12/sys/cam/cam_periph.c stable/12/sys/cam/cam_periph.h Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/cam/cam_periph.c ============================================================================== --- stable/12/sys/cam/cam_periph.c Fri Apr 26 17:09:26 2019 (r346756) +++ stable/12/sys/cam/cam_periph.c Fri Apr 26 17:21:12 2019 (r346757) @@ -46,6 +46,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -104,6 +105,9 @@ TUNABLE_INT("kern.cam.periph_noresrc_delay", &periph_n static int periph_busy_delay = 500; TUNABLE_INT("kern.cam.periph_busy_delay", &periph_busy_delay); +static u_int periph_mapmem_thresh = 65536; +SYSCTL_UINT(_kern_cam, OID_AUTO, mapmem_thresh, CTLFLAG_RWTUN, + &periph_mapmem_thresh, 0, "Threshold for user-space buffer mapping"); void periphdriver_register(void *data) @@ -770,12 +774,12 @@ int cam_periph_mapmem(union ccb *ccb, struct cam_periph_map_info *mapinfo, u_int maxmap) { - int numbufs, i, j; - int flags[CAM_PERIPH_MAXMAPS]; + int numbufs, i; u_int8_t **data_ptrs[CAM_PERIPH_MAXMAPS]; u_int32_t lengths[CAM_PERIPH_MAXMAPS]; u_int32_t dirs[CAM_PERIPH_MAXMAPS]; + bzero(mapinfo, sizeof(*mapinfo)); if (maxmap == 0) maxmap = DFLTPHYS; /* traditional default */ else if (maxmap > MAXPHYS) @@ -886,8 +890,6 @@ cam_periph_mapmem(union ccb *ccb, struct cam_periph_ma */ for (i = 0; i < numbufs; i++) { - flags[i] = 0; - /* * The userland data pointer passed in may not be page * aligned. vmapbuf() truncates the address to a page @@ -905,15 +907,6 @@ cam_periph_mapmem(union ccb *ccb, struct cam_periph_ma (u_long)maxmap); return(E2BIG); } - - if (dirs[i] & CAM_DIR_OUT) { - flags[i] = BIO_WRITE; - } - - if (dirs[i] & CAM_DIR_IN) { - flags[i] = BIO_READ; - } - } /* @@ -927,7 +920,33 @@ cam_periph_mapmem(union ccb *ccb, struct cam_periph_ma PHOLD(curproc); for (i = 0; i < numbufs; i++) { + + /* Save the user's data address. */ + mapinfo->orig[i] = *data_ptrs[i]; + /* + * For small buffers use malloc+copyin/copyout instead of + * mapping to KVA to avoid expensive TLB shootdowns. For + * small allocations malloc is backed by UMA, and so much + * cheaper on SMP systems. + */ + if (lengths[i] <= periph_mapmem_thresh && + ccb->ccb_h.func_code != XPT_MMC_IO) { + *data_ptrs[i] = malloc(lengths[i], M_CAMPERIPH, + M_WAITOK); + if (dirs[i] != CAM_DIR_IN) { + if (copyin(mapinfo->orig[i], *data_ptrs[i], + lengths[i]) != 0) { + free(*data_ptrs[i], M_CAMPERIPH); + *data_ptrs[i] = mapinfo->orig[i]; + goto fail; + } + } else + bzero(*data_ptrs[i], lengths[i]); + continue; + } + + /* * Get the buffer. */ mapinfo->bp[i] = getpbuf(NULL); @@ -935,14 +954,12 @@ cam_periph_mapmem(union ccb *ccb, struct cam_periph_ma /* put our pointer in the data slot */ mapinfo->bp[i]->b_data = *data_ptrs[i]; - /* save the user's data address */ - mapinfo->bp[i]->b_caller1 = *data_ptrs[i]; - /* set the transfer length, we know it's < MAXPHYS */ mapinfo->bp[i]->b_bufsize = lengths[i]; /* set the direction */ - mapinfo->bp[i]->b_iocmd = flags[i]; + mapinfo->bp[i]->b_iocmd = (dirs[i] == CAM_DIR_OUT) ? + BIO_WRITE : BIO_READ; /* * Map the buffer into kernel memory. @@ -953,20 +970,12 @@ cam_periph_mapmem(union ccb *ccb, struct cam_periph_ma * vmapbuf() after the useracc() check. */ if (vmapbuf(mapinfo->bp[i], 1) < 0) { - for (j = 0; j < i; ++j) { - *data_ptrs[j] = mapinfo->bp[j]->b_caller1; - vunmapbuf(mapinfo->bp[j]); - relpbuf(mapinfo->bp[j], NULL); - } relpbuf(mapinfo->bp[i], NULL); - PRELE(curproc); - return(EACCES); + goto fail; } /* set our pointer to the new mapped area */ *data_ptrs[i] = mapinfo->bp[i]->b_data; - - mapinfo->num_bufs_used++; } /* @@ -975,11 +984,24 @@ cam_periph_mapmem(union ccb *ccb, struct cam_periph_ma * space with locks (on the buffer) held. */ for (i = 0; i < numbufs; i++) { - BUF_KERNPROC(mapinfo->bp[i]); + if (mapinfo->bp[i]) + BUF_KERNPROC(mapinfo->bp[i]); } - + mapinfo->num_bufs_used = numbufs; return(0); + +fail: + for (i--; i >= 0; i--) { + if (mapinfo->bp[i]) { + vunmapbuf(mapinfo->bp[i]); + relpbuf(mapinfo->bp[i], NULL); + } else + free(*data_ptrs[i], M_CAMPERIPH); + *data_ptrs[i] = mapinfo->orig[i]; + } + PRELE(curproc); + return(EACCES); } /* @@ -991,6 +1013,8 @@ cam_periph_unmapmem(union ccb *ccb, struct cam_periph_ { int numbufs, i; u_int8_t **data_ptrs[CAM_PERIPH_MAXMAPS]; + u_int32_t lengths[CAM_PERIPH_MAXMAPS]; + u_int32_t dirs[CAM_PERIPH_MAXMAPS]; if (mapinfo->num_bufs_used <= 0) { /* nothing to free and the process wasn't held. */ @@ -999,38 +1023,65 @@ cam_periph_unmapmem(union ccb *ccb, struct cam_periph_ switch (ccb->ccb_h.func_code) { case XPT_DEV_MATCH: - numbufs = min(mapinfo->num_bufs_used, 2); - - if (numbufs == 1) { - data_ptrs[0] = (u_int8_t **)&ccb->cdm.matches; - } else { + if (ccb->cdm.pattern_buf_len > 0) { data_ptrs[0] = (u_int8_t **)&ccb->cdm.patterns; + lengths[0] = ccb->cdm.pattern_buf_len; + dirs[0] = CAM_DIR_OUT; data_ptrs[1] = (u_int8_t **)&ccb->cdm.matches; + lengths[1] = ccb->cdm.match_buf_len; + dirs[1] = CAM_DIR_IN; + numbufs = 2; + } else { + data_ptrs[0] = (u_int8_t **)&ccb->cdm.matches; + lengths[0] = ccb->cdm.match_buf_len; + dirs[0] = CAM_DIR_IN; + numbufs = 1; } break; case XPT_SCSI_IO: case XPT_CONT_TARGET_IO: data_ptrs[0] = &ccb->csio.data_ptr; - numbufs = min(mapinfo->num_bufs_used, 1); + lengths[0] = ccb->csio.dxfer_len; + dirs[0] = ccb->ccb_h.flags & CAM_DIR_MASK; + numbufs = 1; break; case XPT_ATA_IO: data_ptrs[0] = &ccb->ataio.data_ptr; - numbufs = min(mapinfo->num_bufs_used, 1); + lengths[0] = ccb->ataio.dxfer_len; + dirs[0] = ccb->ccb_h.flags & CAM_DIR_MASK; + numbufs = 1; break; + case XPT_MMC_IO: + data_ptrs[0] = (u_int8_t **)&ccb->mmcio.cmd.data; + lengths[0] = sizeof(struct mmc_data *); + dirs[0] = ccb->ccb_h.flags & CAM_DIR_MASK; + data_ptrs[1] = (u_int8_t **)&ccb->mmcio.cmd.data->data; + lengths[1] = ccb->mmcio.cmd.data->len; + dirs[1] = ccb->ccb_h.flags & CAM_DIR_MASK; + numbufs = 2; + break; case XPT_SMP_IO: - numbufs = min(mapinfo->num_bufs_used, 2); data_ptrs[0] = &ccb->smpio.smp_request; + lengths[0] = ccb->smpio.smp_request_len; + dirs[0] = CAM_DIR_OUT; data_ptrs[1] = &ccb->smpio.smp_response; + lengths[1] = ccb->smpio.smp_response_len; + dirs[1] = CAM_DIR_IN; + numbufs = 2; break; - case XPT_DEV_ADVINFO: - numbufs = min(mapinfo->num_bufs_used, 1); - data_ptrs[0] = (uint8_t **)&ccb->cdai.buf; - break; case XPT_NVME_IO: case XPT_NVME_ADMIN: data_ptrs[0] = &ccb->nvmeio.data_ptr; - numbufs = min(mapinfo->num_bufs_used, 1); + lengths[0] = ccb->nvmeio.dxfer_len; + dirs[0] = ccb->ccb_h.flags & CAM_DIR_MASK; + numbufs = 1; break; + case XPT_DEV_ADVINFO: + data_ptrs[0] = (uint8_t **)&ccb->cdai.buf; + lengths[0] = ccb->cdai.bufsiz; + dirs[0] = CAM_DIR_IN; + numbufs = 1; + break; default: /* allow ourselves to be swapped once again */ PRELE(curproc); @@ -1039,14 +1090,22 @@ cam_periph_unmapmem(union ccb *ccb, struct cam_periph_ } for (i = 0; i < numbufs; i++) { - /* Set the user's pointer back to the original value */ - *data_ptrs[i] = mapinfo->bp[i]->b_caller1; + if (mapinfo->bp[i]) { + /* unmap the buffer */ + vunmapbuf(mapinfo->bp[i]); - /* unmap the buffer */ - vunmapbuf(mapinfo->bp[i]); + /* release the buffer */ + relpbuf(mapinfo->bp[i], NULL); + } else { + if (dirs[i] != CAM_DIR_OUT) { + copyout(*data_ptrs[i], mapinfo->orig[i], + lengths[i]); + } + free(*data_ptrs[i], M_CAMPERIPH); + } - /* release the buffer */ - relpbuf(mapinfo->bp[i], NULL); + /* Set the user's pointer back to the original value */ + *data_ptrs[i] = mapinfo->orig[i]; } /* allow ourselves to be swapped once again */ Modified: stable/12/sys/cam/cam_periph.h ============================================================================== --- stable/12/sys/cam/cam_periph.h Fri Apr 26 17:09:26 2019 (r346756) +++ stable/12/sys/cam/cam_periph.h Fri Apr 26 17:21:12 2019 (r346757) @@ -149,6 +149,7 @@ struct cam_periph { struct cam_periph_map_info { int num_bufs_used; + void *orig[CAM_PERIPH_MAXMAPS]; struct buf *bp[CAM_PERIPH_MAXMAPS]; }; From owner-svn-src-stable-12@freebsd.org Sat Apr 27 01:50:11 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E5CD915812C5; Sat, 27 Apr 2019 01:50:10 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 8BEC68FECE; Sat, 27 Apr 2019 01:50:10 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 63DF31C2C3; Sat, 27 Apr 2019 01:50:10 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3R1oAn3082880; Sat, 27 Apr 2019 01:50:10 GMT (envelope-from rmacklem@FreeBSD.org) Received: (from rmacklem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3R1oATR082879; Sat, 27 Apr 2019 01:50:10 GMT (envelope-from rmacklem@FreeBSD.org) Message-Id: <201904270150.x3R1oATR082879@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: rmacklem set sender to rmacklem@FreeBSD.org using -f From: Rick Macklem Date: Sat, 27 Apr 2019 01:50:10 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346772 - stable/12/usr.sbin/nfsdumpstate X-SVN-Group: stable-12 X-SVN-Commit-Author: rmacklem X-SVN-Commit-Paths: stable/12/usr.sbin/nfsdumpstate X-SVN-Commit-Revision: 346772 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 8BEC68FECE X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.93 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.996,0]; NEURAL_HAM_SHORT(-0.93)[-0.930,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 27 Apr 2019 01:50:11 -0000 Author: rmacklem Date: Sat Apr 27 01:50:09 2019 New Revision: 346772 URL: https://svnweb.freebsd.org/changeset/base/346772 Log: MFC: r346190 Fix nfsdumpstate(8) so that it can print out INET6 callback addresses. The patch adds support for printing of INET6 callback addresses. It also adds the #ifdef INET, INET6 as requested by bz@. Modified: stable/12/usr.sbin/nfsdumpstate/Makefile stable/12/usr.sbin/nfsdumpstate/nfsdumpstate.c Directory Properties: stable/12/ (props changed) Modified: stable/12/usr.sbin/nfsdumpstate/Makefile ============================================================================== --- stable/12/usr.sbin/nfsdumpstate/Makefile Sat Apr 27 00:53:41 2019 (r346771) +++ stable/12/usr.sbin/nfsdumpstate/Makefile Sat Apr 27 01:50:09 2019 (r346772) @@ -1,6 +1,15 @@ # $FreeBSD$ +.include + PROG= nfsdumpstate MAN= nfsdumpstate.8 + +.if ${MK_INET_SUPPORT} != "no" +CFLAGS+= -DINET +.endif +.if ${MK_INET6_SUPPORT} != "no" +CFLAGS+= -DINET6 +.endif .include Modified: stable/12/usr.sbin/nfsdumpstate/nfsdumpstate.c ============================================================================== --- stable/12/usr.sbin/nfsdumpstate/nfsdumpstate.c Sat Apr 27 00:53:41 2019 (r346771) +++ stable/12/usr.sbin/nfsdumpstate/nfsdumpstate.c Sat Apr 27 01:50:09 2019 (r346772) @@ -121,13 +121,14 @@ dump_openstate(void) { struct nfsd_dumplist dumplist; int cnt, i; + char nbuf[INET6_ADDRSTRLEN]; dumplist.ndl_size = DUMPSIZE; dumplist.ndl_list = (void *)dp; if (nfssvc(NFSSVC_DUMPCLIENTS, &dumplist) < 0) errx(1, "Can't perform dump clients syscall"); - printf("%-13s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %-15s %s\n", + printf("%-13s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %-45s %s\n", "Flags", "OpenOwner", "Open", "LockOwner", "Lock", "Deleg", "OldDeleg", "Clientaddr", "ClientID"); /* @@ -143,9 +144,23 @@ dump_openstate(void) dp[cnt].ndcl_nlocks, dp[cnt].ndcl_ndelegs, dp[cnt].ndcl_nolddelegs); - if (dp[cnt].ndcl_addrfam == AF_INET) - printf("%-15s ", + switch (dp[cnt].ndcl_addrfam) { +#ifdef INET + case AF_INET: + printf("%-45s ", inet_ntoa(dp[cnt].ndcl_cbaddr.sin_addr)); + break; +#endif +#ifdef INET6 + case AF_INET6: + if (inet_ntop(AF_INET6, &dp[cnt].ndcl_cbaddr.sin6_addr, + nbuf, sizeof(nbuf)) != NULL) + printf("%-45s ", nbuf); + else + printf("%-45s ", " "); + break; +#endif + } for (i = 0; i < dp[cnt].ndcl_clid.nclid_idlen; i++) printf("%02x", dp[cnt].ndcl_clid.nclid_id[i]); printf("\n"); From owner-svn-src-stable-12@freebsd.org Sat Apr 27 01:58:53 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 3819515815CA; Sat, 27 Apr 2019 01:58:53 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id D1844685D1; Sat, 27 Apr 2019 01:58:52 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id A79A31C467; Sat, 27 Apr 2019 01:58:52 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3R1wq8c087945; Sat, 27 Apr 2019 01:58:52 GMT (envelope-from rmacklem@FreeBSD.org) Received: (from rmacklem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3R1wqDj087941; Sat, 27 Apr 2019 01:58:52 GMT (envelope-from rmacklem@FreeBSD.org) Message-Id: <201904270158.x3R1wqDj087941@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: rmacklem set sender to rmacklem@FreeBSD.org using -f From: Rick Macklem Date: Sat, 27 Apr 2019 01:58:52 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346773 - in stable/12/sys: fs/nfsserver modules/nfsd X-SVN-Group: stable-12 X-SVN-Commit-Author: rmacklem X-SVN-Commit-Paths: in stable/12/sys: fs/nfsserver modules/nfsd X-SVN-Commit-Revision: 346773 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: D1844685D1 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.96 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.996,0]; NEURAL_HAM_SHORT(-0.96)[-0.961,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 27 Apr 2019 01:58:53 -0000 Author: rmacklem Date: Sat Apr 27 01:58:51 2019 New Revision: 346773 URL: https://svnweb.freebsd.org/changeset/base/346773 Log: MFC: r346191 Add support for INET6 addresses to the kernel code that dumps open/lock state. PR#223036 reported that INET6 callback addresses were not printed by nfsdumpstate(8). This kernel patch adds INET6 addresses to the dump structure, so that nfsdumpstate(8) can print them out, post-r346190. Modified: stable/12/sys/fs/nfsserver/nfs_nfsdserv.c stable/12/sys/fs/nfsserver/nfs_nfsdstate.c stable/12/sys/modules/nfsd/Makefile Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/fs/nfsserver/nfs_nfsdserv.c ============================================================================== --- stable/12/sys/fs/nfsserver/nfs_nfsdserv.c Sat Apr 27 01:50:09 2019 (r346772) +++ stable/12/sys/fs/nfsserver/nfs_nfsdserv.c Sat Apr 27 01:58:51 2019 (r346773) @@ -36,6 +36,8 @@ #include __FBSDID("$FreeBSD$"); +#include "opt_inet.h" +#include "opt_inet6.h" /* * nfs version 2, 3 and 4 server calls to vnode ops * - these routines generally have 3 phases @@ -3655,8 +3657,16 @@ nfsrvd_setclientid(struct nfsrv_descript *nd, __unused int i; int error = 0, idlen; struct nfsclient *clp = NULL; - struct sockaddr_in *rad; - u_char *verf, *ucp, *ucp2, addrbuf[24]; +#ifdef INET + struct sockaddr_in *rin; +#endif +#ifdef INET6 + struct sockaddr_in6 *rin6; +#endif +#if defined(INET) || defined(INET6) + u_char *ucp, *ucp2; +#endif + u_char *verf, *addrbuf; nfsquad_t clientid, confirm; if ((nd->nd_flag & ND_NFSV41) != 0) { @@ -3683,9 +3693,9 @@ nfsrvd_setclientid(struct nfsrv_descript *nd, __unused clp->lc_stateid = malloc(sizeof(struct nfsstatehead) * nfsrv_statehashsize, M_NFSDCLIENT, M_WAITOK); NFSINITSOCKMUTEX(&clp->lc_req.nr_mtx); - clp->lc_req.nr_nam = malloc(sizeof(*clp->lc_req.nr_nam), M_SONAME, + /* Allocated large enough for an AF_INET or AF_INET6 socket. */ + clp->lc_req.nr_nam = malloc(sizeof(struct sockaddr_in6), M_SONAME, M_WAITOK | M_ZERO); - NFSSOCKADDRSIZE(clp->lc_req.nr_nam, sizeof (struct sockaddr_in)); clp->lc_req.nr_cred = NULL; NFSBCOPY(verf, clp->lc_verf, NFSX_VERF); clp->lc_idlen = idlen; @@ -3727,17 +3737,46 @@ nfsrvd_setclientid(struct nfsrv_descript *nd, __unused */ nd->nd_repstat = nfsrv_setclient(nd, &clp, &clientid, &confirm, p); if (nd->nd_repstat == NFSERR_CLIDINUSE) { - if (clp->lc_flags & LCL_TCPCALLBACK) - (void) nfsm_strtom(nd, "tcp", 3); - else - (void) nfsm_strtom(nd, "udp", 3); - rad = NFSSOCKADDR(clp->lc_req.nr_nam, struct sockaddr_in *); - ucp = (u_char *)&rad->sin_addr.s_addr; - ucp2 = (u_char *)&rad->sin_port; - sprintf(addrbuf, "%d.%d.%d.%d.%d.%d", ucp[0] & 0xff, - ucp[1] & 0xff, ucp[2] & 0xff, ucp[3] & 0xff, - ucp2[0] & 0xff, ucp2[1] & 0xff); + /* + * 8 is the maximum length of the port# string. + */ + addrbuf = malloc(INET6_ADDRSTRLEN + 8, M_TEMP, M_WAITOK); + switch (clp->lc_req.nr_nam->sa_family) { +#ifdef INET + case AF_INET: + if (clp->lc_flags & LCL_TCPCALLBACK) + (void) nfsm_strtom(nd, "tcp", 3); + else + (void) nfsm_strtom(nd, "udp", 3); + rin = (struct sockaddr_in *)clp->lc_req.nr_nam; + ucp = (u_char *)&rin->sin_addr.s_addr; + ucp2 = (u_char *)&rin->sin_port; + sprintf(addrbuf, "%d.%d.%d.%d.%d.%d", ucp[0] & 0xff, + ucp[1] & 0xff, ucp[2] & 0xff, ucp[3] & 0xff, + ucp2[0] & 0xff, ucp2[1] & 0xff); + break; +#endif +#ifdef INET6 + case AF_INET6: + if (clp->lc_flags & LCL_TCPCALLBACK) + (void) nfsm_strtom(nd, "tcp6", 4); + else + (void) nfsm_strtom(nd, "udp6", 4); + rin6 = (struct sockaddr_in6 *)clp->lc_req.nr_nam; + ucp = inet_ntop(AF_INET6, &rin6->sin6_addr, addrbuf, + INET6_ADDRSTRLEN); + if (ucp != NULL) + i = strlen(ucp); + else + i = 0; + ucp2 = (u_char *)&rin6->sin6_port; + sprintf(&addrbuf[i], ".%d.%d", ucp2[0] & 0xff, + ucp2[1] & 0xff); + break; +#endif + } (void) nfsm_strtom(nd, addrbuf, strlen(addrbuf)); + free(addrbuf, M_TEMP); } if (clp) { free(clp->lc_req.nr_nam, M_SONAME); @@ -3938,7 +3977,12 @@ nfsrvd_exchangeid(struct nfsrv_descript *nd, __unused uint32_t sp4type, v41flags; uint64_t owner_minor; struct timespec verstime; - struct sockaddr_in *sad, *rad; +#ifdef INET + struct sockaddr_in *sin, *rin; +#endif +#ifdef INET6 + struct sockaddr_in6 *sin6, *rin6; +#endif if (nfs_rootfhset == 0 || nfsd_checkrootexp(nd) != 0) { nd->nd_repstat = NFSERR_WRONGSEC; @@ -3960,16 +4004,31 @@ nfsrvd_exchangeid(struct nfsrv_descript *nd, __unused clp->lc_stateid = malloc(sizeof(struct nfsstatehead) * nfsrv_statehashsize, M_NFSDCLIENT, M_WAITOK); NFSINITSOCKMUTEX(&clp->lc_req.nr_mtx); - clp->lc_req.nr_nam = malloc(sizeof(*clp->lc_req.nr_nam), M_SONAME, + /* Allocated large enough for an AF_INET or AF_INET6 socket. */ + clp->lc_req.nr_nam = malloc(sizeof(struct sockaddr_in6), M_SONAME, M_WAITOK | M_ZERO); - NFSSOCKADDRSIZE(clp->lc_req.nr_nam, sizeof (struct sockaddr_in)); - sad = NFSSOCKADDR(nd->nd_nam, struct sockaddr_in *); - rad = NFSSOCKADDR(clp->lc_req.nr_nam, struct sockaddr_in *); - rad->sin_family = AF_INET; - rad->sin_addr.s_addr = 0; - rad->sin_port = 0; - if (sad->sin_family == AF_INET) - rad->sin_addr.s_addr = sad->sin_addr.s_addr; + switch (nd->nd_nam->sa_family) { +#ifdef INET + case AF_INET: + rin = (struct sockaddr_in *)clp->lc_req.nr_nam; + sin = (struct sockaddr_in *)nd->nd_nam; + rin->sin_family = AF_INET; + rin->sin_len = sizeof(struct sockaddr_in); + rin->sin_port = 0; + rin->sin_addr.s_addr = sin->sin_addr.s_addr; + break; +#endif +#ifdef INET6 + case AF_INET6: + rin6 = (struct sockaddr_in6 *)clp->lc_req.nr_nam; + sin6 = (struct sockaddr_in6 *)nd->nd_nam; + rin6->sin6_family = AF_INET6; + rin6->sin6_len = sizeof(struct sockaddr_in6); + rin6->sin6_port = 0; + rin6->sin6_addr = sin6->sin6_addr; + break; +#endif + } clp->lc_req.nr_cred = NULL; NFSBCOPY(verf, clp->lc_verf, NFSX_VERF); clp->lc_idlen = idlen; Modified: stable/12/sys/fs/nfsserver/nfs_nfsdstate.c ============================================================================== --- stable/12/sys/fs/nfsserver/nfs_nfsdstate.c Sat Apr 27 01:50:09 2019 (r346772) +++ stable/12/sys/fs/nfsserver/nfs_nfsdstate.c Sat Apr 27 01:58:51 2019 (r346773) @@ -30,6 +30,8 @@ #include __FBSDID("$FreeBSD$"); +#include "opt_inet.h" +#include "opt_inet6.h" #ifndef APPLEKEXT #include #include @@ -248,7 +250,12 @@ nfsrv_setclient(struct nfsrv_descript *nd, struct nfsc struct nfsclient *clp = NULL, *new_clp = *new_clpp; int i, error = 0, ret; struct nfsstate *stp, *tstp; - struct sockaddr_in *sad, *rad; +#ifdef INET + struct sockaddr_in *sin, *rin; +#endif +#ifdef INET6 + struct sockaddr_in6 *sin6, *rin6; +#endif struct nfsdsession *sep, *nsep; int zapit = 0, gotit, hasstate = 0, igotlock; static u_int64_t confirm_index = 0; @@ -400,10 +407,24 @@ nfsrv_setclient(struct nfsrv_descript *nd, struct nfsc * If the uid doesn't match, return NFSERR_CLIDINUSE after * filling out the correct ipaddr and portnum. */ - sad = NFSSOCKADDR(new_clp->lc_req.nr_nam, struct sockaddr_in *); - rad = NFSSOCKADDR(clp->lc_req.nr_nam, struct sockaddr_in *); - sad->sin_addr.s_addr = rad->sin_addr.s_addr; - sad->sin_port = rad->sin_port; + switch (clp->lc_req.nr_nam->sa_family) { +#ifdef INET + case AF_INET: + sin = (struct sockaddr_in *)new_clp->lc_req.nr_nam; + rin = (struct sockaddr_in *)clp->lc_req.nr_nam; + sin->sin_addr.s_addr = rin->sin_addr.s_addr; + sin->sin_port = rin->sin_port; + break; +#endif +#ifdef INET6 + case AF_INET6: + sin6 = (struct sockaddr_in6 *)new_clp->lc_req.nr_nam; + rin6 = (struct sockaddr_in6 *)clp->lc_req.nr_nam; + sin6->sin6_addr = rin6->sin6_addr; + sin6->sin6_port = rin6->sin6_port; + break; +#endif + } NFSLOCKV4ROOTMUTEX(); nfsv4_unlock(&nfsv4rootfs_lock, 1); NFSUNLOCKV4ROOTMUTEX(); @@ -956,9 +977,13 @@ nfsrv_dumpaclient(struct nfsclient *clp, struct nfsd_d { struct nfsstate *stp, *openstp, *lckownstp; struct nfslock *lop; - struct sockaddr *sad; - struct sockaddr_in *rad; - struct sockaddr_in6 *rad6; + sa_family_t af; +#ifdef INET + struct sockaddr_in *rin; +#endif +#ifdef INET6 + struct sockaddr_in6 *rin6; +#endif dumpp->ndcl_nopenowners = dumpp->ndcl_nlockowners = 0; dumpp->ndcl_nopens = dumpp->ndcl_nlocks = 0; @@ -966,14 +991,21 @@ nfsrv_dumpaclient(struct nfsclient *clp, struct nfsd_d dumpp->ndcl_flags = clp->lc_flags; dumpp->ndcl_clid.nclid_idlen = clp->lc_idlen; NFSBCOPY(clp->lc_id, dumpp->ndcl_clid.nclid_id, clp->lc_idlen); - sad = NFSSOCKADDR(clp->lc_req.nr_nam, struct sockaddr *); - dumpp->ndcl_addrfam = sad->sa_family; - if (sad->sa_family == AF_INET) { - rad = (struct sockaddr_in *)sad; - dumpp->ndcl_cbaddr.sin_addr = rad->sin_addr; - } else { - rad6 = (struct sockaddr_in6 *)sad; - dumpp->ndcl_cbaddr.sin6_addr = rad6->sin6_addr; + af = clp->lc_req.nr_nam->sa_family; + dumpp->ndcl_addrfam = af; + switch (af) { +#ifdef INET + case AF_INET: + rin = (struct sockaddr_in *)clp->lc_req.nr_nam; + dumpp->ndcl_cbaddr.sin_addr = rin->sin_addr; + break; +#endif +#ifdef INET6 + case AF_INET6: + rin6 = (struct sockaddr_in6 *)clp->lc_req.nr_nam; + dumpp->ndcl_cbaddr.sin6_addr = rin6->sin6_addr; + break; +#endif } /* @@ -1014,9 +1046,13 @@ nfsrv_dumplocks(vnode_t vp, struct nfsd_dumplocks *ldu struct nfslock *lop; int cnt = 0; struct nfslockfile *lfp; - struct sockaddr *sad; - struct sockaddr_in *rad; - struct sockaddr_in6 *rad6; + sa_family_t af; +#ifdef INET + struct sockaddr_in *rin; +#endif +#ifdef INET6 + struct sockaddr_in6 *rin6; +#endif int ret; fhandle_t nfh; @@ -1058,14 +1094,22 @@ nfsrv_dumplocks(vnode_t vp, struct nfsd_dumplocks *ldu ldumpp[cnt].ndlck_clid.nclid_idlen = stp->ls_clp->lc_idlen; NFSBCOPY(stp->ls_clp->lc_id, ldumpp[cnt].ndlck_clid.nclid_id, stp->ls_clp->lc_idlen); - sad=NFSSOCKADDR(stp->ls_clp->lc_req.nr_nam, struct sockaddr *); - ldumpp[cnt].ndlck_addrfam = sad->sa_family; - if (sad->sa_family == AF_INET) { - rad = (struct sockaddr_in *)sad; - ldumpp[cnt].ndlck_cbaddr.sin_addr = rad->sin_addr; - } else { - rad6 = (struct sockaddr_in6 *)sad; - ldumpp[cnt].ndlck_cbaddr.sin6_addr = rad6->sin6_addr; + af = stp->ls_clp->lc_req.nr_nam->sa_family; + ldumpp[cnt].ndlck_addrfam = af; + switch (af) { +#ifdef INET + case AF_INET: + rin = (struct sockaddr_in *)stp->ls_clp->lc_req.nr_nam; + ldumpp[cnt].ndlck_cbaddr.sin_addr = rin->sin_addr; + break; +#endif +#ifdef INET6 + case AF_INET6: + rin6 = (struct sockaddr_in6 *) + stp->ls_clp->lc_req.nr_nam; + ldumpp[cnt].ndlck_cbaddr.sin6_addr = rin6->sin6_addr; + break; +#endif } stp = LIST_NEXT(stp, ls_file); cnt++; @@ -1090,14 +1134,22 @@ nfsrv_dumplocks(vnode_t vp, struct nfsd_dumplocks *ldu ldumpp[cnt].ndlck_clid.nclid_idlen = stp->ls_clp->lc_idlen; NFSBCOPY(stp->ls_clp->lc_id, ldumpp[cnt].ndlck_clid.nclid_id, stp->ls_clp->lc_idlen); - sad=NFSSOCKADDR(stp->ls_clp->lc_req.nr_nam, struct sockaddr *); - ldumpp[cnt].ndlck_addrfam = sad->sa_family; - if (sad->sa_family == AF_INET) { - rad = (struct sockaddr_in *)sad; - ldumpp[cnt].ndlck_cbaddr.sin_addr = rad->sin_addr; - } else { - rad6 = (struct sockaddr_in6 *)sad; - ldumpp[cnt].ndlck_cbaddr.sin6_addr = rad6->sin6_addr; + af = stp->ls_clp->lc_req.nr_nam->sa_family; + ldumpp[cnt].ndlck_addrfam = af; + switch (af) { +#ifdef INET + case AF_INET: + rin = (struct sockaddr_in *)stp->ls_clp->lc_req.nr_nam; + ldumpp[cnt].ndlck_cbaddr.sin_addr = rin->sin_addr; + break; +#endif +#ifdef INET6 + case AF_INET6: + rin6 = (struct sockaddr_in6 *) + stp->ls_clp->lc_req.nr_nam; + ldumpp[cnt].ndlck_cbaddr.sin6_addr = rin6->sin6_addr; + break; +#endif } lop = LIST_NEXT(lop, lo_lckfile); cnt++; @@ -1117,14 +1169,22 @@ nfsrv_dumplocks(vnode_t vp, struct nfsd_dumplocks *ldu ldumpp[cnt].ndlck_clid.nclid_idlen = stp->ls_clp->lc_idlen; NFSBCOPY(stp->ls_clp->lc_id, ldumpp[cnt].ndlck_clid.nclid_id, stp->ls_clp->lc_idlen); - sad=NFSSOCKADDR(stp->ls_clp->lc_req.nr_nam, struct sockaddr *); - ldumpp[cnt].ndlck_addrfam = sad->sa_family; - if (sad->sa_family == AF_INET) { - rad = (struct sockaddr_in *)sad; - ldumpp[cnt].ndlck_cbaddr.sin_addr = rad->sin_addr; - } else { - rad6 = (struct sockaddr_in6 *)sad; - ldumpp[cnt].ndlck_cbaddr.sin6_addr = rad6->sin6_addr; + af = stp->ls_clp->lc_req.nr_nam->sa_family; + ldumpp[cnt].ndlck_addrfam = af; + switch (af) { +#ifdef INET + case AF_INET: + rin = (struct sockaddr_in *)stp->ls_clp->lc_req.nr_nam; + ldumpp[cnt].ndlck_cbaddr.sin_addr = rin->sin_addr; + break; +#endif +#ifdef INET6 + case AF_INET6: + rin6 = (struct sockaddr_in6 *) + stp->ls_clp->lc_req.nr_nam; + ldumpp[cnt].ndlck_cbaddr.sin6_addr = rin6->sin6_addr; + break; +#endif } stp = LIST_NEXT(stp, ls_file); cnt++; @@ -3994,9 +4054,15 @@ nfsrv_getclientipaddr(struct nfsrv_descript *nd, struc { u_int32_t *tl; u_char *cp, *cp2; - int i, j; - struct sockaddr_in *rad, *sad; - u_char protocol[5], addr[24]; + int i, j, maxalen = 0, minalen = 0; + sa_family_t af; +#ifdef INET + struct sockaddr_in *rin, *sin; +#endif +#ifdef INET6 + struct sockaddr_in6 *rin6, *sin6; +#endif + u_char *addr; int error = 0, cantparse = 0; union { in_addr_t ival; @@ -4007,27 +4073,44 @@ nfsrv_getclientipaddr(struct nfsrv_descript *nd, struc u_char cval[2]; } port; - rad = NFSSOCKADDR(clp->lc_req.nr_nam, struct sockaddr_in *); - rad->sin_family = AF_INET; - rad->sin_len = sizeof (struct sockaddr_in); - rad->sin_addr.s_addr = 0; - rad->sin_port = 0; + /* 8 is the maximum length of the port# string. */ + addr = malloc(INET6_ADDRSTRLEN + 8, M_TEMP, M_WAITOK); clp->lc_req.nr_client = NULL; clp->lc_req.nr_lock = 0; + af = AF_UNSPEC; NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED); i = fxdr_unsigned(int, *tl); if (i >= 3 && i <= 4) { - error = nfsrv_mtostr(nd, protocol, i); + error = nfsrv_mtostr(nd, addr, i); if (error) goto nfsmout; - if (!strcmp(protocol, "tcp")) { +#ifdef INET + if (!strcmp(addr, "tcp")) { clp->lc_flags |= LCL_TCPCALLBACK; clp->lc_req.nr_sotype = SOCK_STREAM; clp->lc_req.nr_soproto = IPPROTO_TCP; - } else if (!strcmp(protocol, "udp")) { + af = AF_INET; + } else if (!strcmp(addr, "udp")) { clp->lc_req.nr_sotype = SOCK_DGRAM; clp->lc_req.nr_soproto = IPPROTO_UDP; - } else { + af = AF_INET; + } +#endif +#ifdef INET6 + if (af == AF_UNSPEC) { + if (!strcmp(addr, "tcp6")) { + clp->lc_flags |= LCL_TCPCALLBACK; + clp->lc_req.nr_sotype = SOCK_STREAM; + clp->lc_req.nr_soproto = IPPROTO_TCP; + af = AF_INET6; + } else if (!strcmp(addr, "udp6")) { + clp->lc_req.nr_sotype = SOCK_DGRAM; + clp->lc_req.nr_soproto = IPPROTO_UDP; + af = AF_INET6; + } + } +#endif + if (af == AF_UNSPEC) { cantparse = 1; } } else { @@ -4038,6 +4121,36 @@ nfsrv_getclientipaddr(struct nfsrv_descript *nd, struc goto nfsmout; } } + /* + * The caller has allocated clp->lc_req.nr_nam to be large enough + * for either AF_INET or AF_INET6 and zeroed out the contents. + * maxalen is set to the maximum length of the host IP address string + * plus 8 for the maximum length of the port#. + * minalen is set to the minimum length of the host IP address string + * plus 4 for the minimum length of the port#. + * These lengths do not include NULL termination, + * so INET[6]_ADDRSTRLEN - 1 is used in the calculations. + */ + switch (af) { +#ifdef INET + case AF_INET: + rin = (struct sockaddr_in *)clp->lc_req.nr_nam; + rin->sin_family = AF_INET; + rin->sin_len = sizeof(struct sockaddr_in); + maxalen = INET_ADDRSTRLEN - 1 + 8; + minalen = 7 + 4; + break; +#endif +#ifdef INET6 + case AF_INET6: + rin6 = (struct sockaddr_in6 *)clp->lc_req.nr_nam; + rin6->sin6_family = AF_INET6; + rin6->sin6_len = sizeof(struct sockaddr_in6); + maxalen = INET6_ADDRSTRLEN - 1 + 8; + minalen = 3 + 4; + break; +#endif + } NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED); i = fxdr_unsigned(int, *tl); if (i < 0) { @@ -4045,18 +4158,43 @@ nfsrv_getclientipaddr(struct nfsrv_descript *nd, struc goto nfsmout; } else if (i == 0) { cantparse = 1; - } else if (!cantparse && i <= 23 && i >= 11) { + } else if (!cantparse && i <= maxalen && i >= minalen) { error = nfsrv_mtostr(nd, addr, i); if (error) goto nfsmout; /* * Parse out the address fields. We expect 6 decimal numbers - * separated by '.'s. + * separated by '.'s for AF_INET and two decimal numbers + * preceeded by '.'s for AF_INET6. */ - cp = addr; - i = 0; - while (*cp && i < 6) { + cp = NULL; + switch (af) { +#ifdef INET6 + /* + * For AF_INET6, first parse the host address. + */ + case AF_INET6: + cp = strchr(addr, '.'); + if (cp != NULL) { + *cp++ = '\0'; + if (inet_pton(af, addr, &rin6->sin6_addr) == 1) + i = 4; + else { + cp = NULL; + cantparse = 1; + } + } + break; +#endif +#ifdef INET + case AF_INET: + cp = addr; + i = 0; + break; +#endif + } + while (cp != NULL && *cp && i < 6) { cp2 = cp; while (*cp2 && *cp2 != '.') cp2++; @@ -4080,11 +4218,30 @@ nfsrv_getclientipaddr(struct nfsrv_descript *nd, struc i++; } if (!cantparse) { - if (ip.ival != 0x0) { - rad->sin_addr.s_addr = htonl(ip.ival); - rad->sin_port = htons(port.sval); - } else { - cantparse = 1; + /* + * The host address INADDR_ANY is (mis)used to indicate + * "there is no valid callback address". + */ + switch (af) { +#ifdef INET6 + case AF_INET6: + if (!IN6_ARE_ADDR_EQUAL(&rin6->sin6_addr, + &in6addr_any)) + rin6->sin6_port = htons(port.sval); + else + cantparse = 1; + break; +#endif +#ifdef INET + case AF_INET: + if (ip.ival != INADDR_ANY) { + rin->sin_addr.s_addr = htonl(ip.ival); + rin->sin_port = htons(port.sval); + } else { + cantparse = 1; + } + break; +#endif } } } else { @@ -4096,14 +4253,32 @@ nfsrv_getclientipaddr(struct nfsrv_descript *nd, struc } } if (cantparse) { - sad = NFSSOCKADDR(nd->nd_nam, struct sockaddr_in *); - if (sad->sin_family == AF_INET) { - rad->sin_addr.s_addr = sad->sin_addr.s_addr; - rad->sin_port = 0x0; + switch (nd->nd_nam->sa_family) { +#ifdef INET + case AF_INET: + sin = (struct sockaddr_in *)nd->nd_nam; + rin = (struct sockaddr_in *)clp->lc_req.nr_nam; + rin->sin_family = AF_INET; + rin->sin_len = sizeof(struct sockaddr_in); + rin->sin_addr.s_addr = sin->sin_addr.s_addr; + rin->sin_port = 0x0; + break; +#endif +#ifdef INET6 + case AF_INET6: + sin6 = (struct sockaddr_in6 *)nd->nd_nam; + rin6 = (struct sockaddr_in6 *)clp->lc_req.nr_nam; + rin6->sin6_family = AF_INET6; + rin6->sin6_len = sizeof(struct sockaddr_in6); + rin6->sin6_addr = sin6->sin6_addr; + rin6->sin6_port = 0x0; + break; +#endif } clp->lc_program = 0; } nfsmout: + free(addr, M_TEMP); NFSEXITCODE2(error, nd); return (error); } Modified: stable/12/sys/modules/nfsd/Makefile ============================================================================== --- stable/12/sys/modules/nfsd/Makefile Sat Apr 27 01:50:09 2019 (r346772) +++ stable/12/sys/modules/nfsd/Makefile Sat Apr 27 01:58:51 2019 (r346773) @@ -14,6 +14,7 @@ SRCS= vnode_if.h \ nfs_nfsdport.c \ opt_ufs.h \ opt_nfs.h \ + opt_inet.h \ opt_inet6.h \ opt_kgssapi.h From owner-svn-src-stable-12@freebsd.org Sat Apr 27 02:05:05 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 73BA91581815; Sat, 27 Apr 2019 02:05:05 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 19C5469D8A; Sat, 27 Apr 2019 02:05:05 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id E74521C622; Sat, 27 Apr 2019 02:05:04 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3R2544S093097; Sat, 27 Apr 2019 02:05:04 GMT (envelope-from rmacklem@FreeBSD.org) Received: (from rmacklem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3R254MP093096; Sat, 27 Apr 2019 02:05:04 GMT (envelope-from rmacklem@FreeBSD.org) Message-Id: <201904270205.x3R254MP093096@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: rmacklem set sender to rmacklem@FreeBSD.org using -f From: Rick Macklem Date: Sat, 27 Apr 2019 02:05:04 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346774 - stable/12/usr.bin/nfsstat X-SVN-Group: stable-12 X-SVN-Commit-Author: rmacklem X-SVN-Commit-Paths: stable/12/usr.bin/nfsstat X-SVN-Commit-Revision: 346774 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 19C5469D8A X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.95 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.996,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.96)[-0.956,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 27 Apr 2019 02:05:05 -0000 Author: rmacklem Date: Sat Apr 27 02:05:04 2019 New Revision: 346774 URL: https://svnweb.freebsd.org/changeset/base/346774 Log: MFC: r346192 Fix printing of the line that starts with "LocalOpen...". When "nfsstat -E -c" was done, the title line starting with "LocalOpen..." was not being displayed. This was introduced by r328588. Modified: stable/12/usr.bin/nfsstat/nfsstat.c Directory Properties: stable/12/ (props changed) Modified: stable/12/usr.bin/nfsstat/nfsstat.c ============================================================================== --- stable/12/usr.bin/nfsstat/nfsstat.c Sat Apr 27 01:58:51 2019 (r346773) +++ stable/12/usr.bin/nfsstat/nfsstat.c Sat Apr 27 02:05:04 2019 (r346774) @@ -790,7 +790,7 @@ exp_intpr(int clientOnly, int serverOnly, int nfs41) (uintmax_t)ext_nfsstats.cllocalopenowners); xo_emit("{T:LocalOpen/%13.13s}{T:LocalLown/%13.13s}" - "{T:LocalLock\n"); + "{T:LocalLock/%13.13s}\n"); xo_emit("{:localopen/%13ju}{:locallown/%13ju}" "{:locallock/%13ju}\n", (uintmax_t)ext_nfsstats.cllocalopens, From owner-svn-src-stable-12@freebsd.org Sat Apr 27 04:00:52 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id D1C6A1584332; Sat, 27 Apr 2019 04:00:51 +0000 (UTC) (envelope-from cperciva@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 78A346D391; Sat, 27 Apr 2019 04:00:51 +0000 (UTC) (envelope-from cperciva@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 523BF1D94C; Sat, 27 Apr 2019 04:00:51 +0000 (UTC) (envelope-from cperciva@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3R40pgu053059; Sat, 27 Apr 2019 04:00:51 GMT (envelope-from cperciva@FreeBSD.org) Received: (from cperciva@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3R40o8t053056; Sat, 27 Apr 2019 04:00:50 GMT (envelope-from cperciva@FreeBSD.org) Message-Id: <201904270400.x3R40o8t053056@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: cperciva set sender to cperciva@FreeBSD.org using -f From: Colin Percival Date: Sat, 27 Apr 2019 04:00:50 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346780 - stable/12/usr.sbin/pkg X-SVN-Group: stable-12 X-SVN-Commit-Author: cperciva X-SVN-Commit-Paths: stable/12/usr.sbin/pkg X-SVN-Commit-Revision: 346780 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 78A346D391 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.94 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.996,0]; NEURAL_HAM_SHORT(-0.95)[-0.947,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 27 Apr 2019 04:00:52 -0000 Author: cperciva Date: Sat Apr 27 04:00:50 2019 New Revision: 346780 URL: https://svnweb.freebsd.org/changeset/base/346780 Log: MFC r346628: Split the pkg configuration file FreeBSD.conf into versions for {latest, quarterly} and use Makefile logic to decide which one to install (right now, unconditionally "latest"). Discussed with: gjb Added: stable/12/usr.sbin/pkg/FreeBSD.conf.latest - copied unchanged from r346628, head/usr.sbin/pkg/FreeBSD.conf.latest stable/12/usr.sbin/pkg/FreeBSD.conf.quarterly - copied unchanged from r346628, head/usr.sbin/pkg/FreeBSD.conf.quarterly Deleted: stable/12/usr.sbin/pkg/FreeBSD.conf Modified: stable/12/usr.sbin/pkg/Makefile Directory Properties: stable/12/ (props changed) Copied: stable/12/usr.sbin/pkg/FreeBSD.conf.latest (from r346628, head/usr.sbin/pkg/FreeBSD.conf.latest) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/12/usr.sbin/pkg/FreeBSD.conf.latest Sat Apr 27 04:00:50 2019 (r346780, copy of r346628, head/usr.sbin/pkg/FreeBSD.conf.latest) @@ -0,0 +1,16 @@ +# $FreeBSD$ +# +# To disable this repository, instead of modifying or removing this file, +# create a /usr/local/etc/pkg/repos/FreeBSD.conf file: +# +# mkdir -p /usr/local/etc/pkg/repos +# echo "FreeBSD: { enabled: no }" > /usr/local/etc/pkg/repos/FreeBSD.conf +# + +FreeBSD: { + url: "pkg+http://pkg.FreeBSD.org/${ABI}/latest", + mirror_type: "srv", + signature_type: "fingerprints", + fingerprints: "/usr/share/keys/pkg", + enabled: yes +} Copied: stable/12/usr.sbin/pkg/FreeBSD.conf.quarterly (from r346628, head/usr.sbin/pkg/FreeBSD.conf.quarterly) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/12/usr.sbin/pkg/FreeBSD.conf.quarterly Sat Apr 27 04:00:50 2019 (r346780, copy of r346628, head/usr.sbin/pkg/FreeBSD.conf.quarterly) @@ -0,0 +1,16 @@ +# $FreeBSD$ +# +# To disable this repository, instead of modifying or removing this file, +# create a /usr/local/etc/pkg/repos/FreeBSD.conf file: +# +# mkdir -p /usr/local/etc/pkg/repos +# echo "FreeBSD: { enabled: no }" > /usr/local/etc/pkg/repos/FreeBSD.conf +# + +FreeBSD: { + url: "pkg+http://pkg.FreeBSD.org/${ABI}/quarterly", + mirror_type: "srv", + signature_type: "fingerprints", + fingerprints: "/usr/share/keys/pkg", + enabled: yes +} Modified: stable/12/usr.sbin/pkg/Makefile ============================================================================== --- stable/12/usr.sbin/pkg/Makefile Sat Apr 27 02:43:27 2019 (r346779) +++ stable/12/usr.sbin/pkg/Makefile Sat Apr 27 04:00:50 2019 (r346780) @@ -1,6 +1,8 @@ # $FreeBSD$ -CONFS= FreeBSD.conf +PKGCONFBRANCH?= latest +CONFS= FreeBSD.conf.${PKGCONFBRANCH} +CONFSNAME= FreeBSD.conf CONFSDIR= /etc/pkg CONFSMODE= 644 PROG= pkg From owner-svn-src-stable-12@freebsd.org Sat Apr 27 04:12:34 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 2146A1584718; Sat, 27 Apr 2019 04:12:34 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id B78316D9EA; Sat, 27 Apr 2019 04:12:33 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 93B501DC75; Sat, 27 Apr 2019 04:12:33 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3R4CXEg062306; Sat, 27 Apr 2019 04:12:33 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3R4CWNX062303; Sat, 27 Apr 2019 04:12:32 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201904270412.x3R4CWNX062303@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Sat, 27 Apr 2019 04:12:32 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346781 - in stable/12: share/man/man4 sys/conf X-SVN-Group: stable-12 X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: in stable/12: share/man/man4 sys/conf X-SVN-Commit-Revision: 346781 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: B78316D9EA X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.94 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.996,0]; NEURAL_HAM_SHORT(-0.95)[-0.947,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 27 Apr 2019 04:12:34 -0000 Author: kevans Date: Sat Apr 27 04:12:32 2019 New Revision: 346781 URL: https://svnweb.freebsd.org/changeset/base/346781 Log: MFC r346307, r346618: Further DTB building consolidation/documentation r346307: fdt: further consolidate DTB building and revise manpage FDT_DTS_FILE was built separately with a rule in sys/conf/files and recreated the rules we used in dtb.mk. Now that we have other infrastructure to build a DTB along with the kernel, fold FDT_DTS_FILE into that since it doesn't have any special requirements. fdt(4) never got revised to mention the DTS/DTSO make options, so do that now. r346618: fdt: stop installing FDT_DTS_FILE r346307 inadvertently started installing FDT_DTS_FILE along with the kernel. While this isn't necessarily bad, it was not intended or discussed and it actively breaks some current setups that don't anticipate any .dtb being installed when it's using static fdt. This change could be reconsidered down the line, but it needs to be done with prior discussion. Fix it by pushing FDT_DTS_FILE build down into the raw dtb.build.mk bits. This technically allows modules building DTS to accidentally specify an FDT_DTS_FILE that gets built but isn't otherwise useful (since it's not installed), but I suspect this isn't a big deal and would get caught with any kind of testing -- and perhaps this might end up useful in some other way, for example by some module wanting to embed fdt in some other way than our current/normal mechanism. Modified: stable/12/share/man/man4/fdt.4 stable/12/sys/conf/dtb.build.mk stable/12/sys/conf/files stable/12/sys/conf/kern.post.mk Directory Properties: stable/12/ (props changed) Modified: stable/12/share/man/man4/fdt.4 ============================================================================== --- stable/12/share/man/man4/fdt.4 Sat Apr 27 04:00:50 2019 (r346780) +++ stable/12/share/man/man4/fdt.4 Sat Apr 27 04:12:32 2019 (r346781) @@ -28,7 +28,7 @@ .\" .\" $FreeBSD$ .\" -.Dd July 12, 2010 +.Dd March 28, 2019 .Dt FDT 4 .Os .Sh NAME @@ -139,6 +139,21 @@ support at the .Fx kernel level. .Bl -tag -width Ar +.It Va makeoptions DTS+=.dts +Specifies device tree source (DTS) files for a given kernel. +The indicated DTS files will be converted (compiled) into a binary form +along with building the kernel itself. +Any DTS file names not written as an absolute path must be specified relative +to the default location of DTS sources i.e., +.Pa sys/dts . +.It Va makeoptions DTSO+=.dtso +Specifies device tree source overlay (DTSO) files for a given kernel. +Overlay files will be built with the kernel as with the makeoption +.Va DTS +described above. +Overlay files specified as relative paths will be relative to the default +location of DTS overlays for the platform being built i.e., +.Pa sys/dts/arm/overlays . .It Va options FDT The primary option for enabling .Nm @@ -153,10 +168,9 @@ drivers, as well as helper routines and libraries. .It Va makeoptions FDT_DTS_FILE=.dts Specifies a preferred (default) device tree source (DTS) file for a given kernel. -The indicated DTS file will be converted (compiled) into a binary form -along with building the kernel itself. -The DTS file name is relative to the default location of DTS sources i.e. -.Pa sys/dts . +It will be built along with the kernel as if it were supplied via the makeoption +.Va DTS +described above. This makeoption is not mandatory unless FDT_DTB_STATIC is also defined (see below). .It Va options FDT_DTB_STATIC Modified: stable/12/sys/conf/dtb.build.mk ============================================================================== --- stable/12/sys/conf/dtb.build.mk Sat Apr 27 04:00:50 2019 (r346780) +++ stable/12/sys/conf/dtb.build.mk Sat Apr 27 04:12:32 2019 (r346781) @@ -43,7 +43,7 @@ DTBO=${DTSO:T:R:S/$/.dtbo/} # Add dependencies on the source file so that out-of-tree things can be included # without any .PATH additions. -.for _dts in ${DTS} +.for _dts in ${DTS} ${FDT_DTS_FILE} ${_dts:R:T}.dtb: ${_dts} .endfor Modified: stable/12/sys/conf/files ============================================================================== --- stable/12/sys/conf/files Sat Apr 27 04:00:50 2019 (r346780) +++ stable/12/sys/conf/files Sat Apr 27 04:12:32 2019 (r346781) @@ -19,17 +19,9 @@ bhnd_nvram_map_data.h optional bhnd \ compile-with "sh $S/dev/bhnd/tools/nvram_map_gen.sh $S/dev/bhnd/nvram/nvram_map -d" \ no-obj no-implicit-rule before-depend \ clean "bhnd_nvram_map_data.h" -# -# The 'fdt_dtb_file' target covers an actual DTB file name, which is derived -# from the specified source (DTS) file: .dts -> .dtb -# -fdt_dtb_file optional fdt fdt_dtb_static \ - compile-with "sh -c 'MACHINE=${MACHINE} $S/tools/fdt/make_dtb.sh $S ${FDT_DTS_FILE} ${.CURDIR}'" \ - no-obj no-implicit-rule before-depend \ - clean "${FDT_DTS_FILE:R}.dtb" fdt_static_dtb.h optional fdt fdt_dtb_static \ compile-with "sh -c 'MACHINE=${MACHINE} $S/tools/fdt/make_dtbh.sh ${FDT_DTS_FILE} ${.CURDIR}'" \ - dependency "fdt_dtb_file" \ + dependency "${FDT_DTS_FILE:T:R}.dtb" \ no-obj no-implicit-rule before-depend \ clean "fdt_static_dtb.h" feeder_eq_gen.h optional sound \ @@ -1786,7 +1778,7 @@ dev/fdt/fdt_pinctrl.c optional fdt fdt_pinctrl dev/fdt/fdt_pinctrl_if.m optional fdt fdt_pinctrl dev/fdt/fdt_slicer.c optional fdt cfi | fdt nand | fdt mx25l | fdt n25q | fdt at45d dev/fdt/fdt_static_dtb.S optional fdt fdt_dtb_static \ - dependency "fdt_dtb_file" + dependency "${FDT_DTS_FILE:T:R}.dtb" dev/fdt/simplebus.c optional fdt dev/fe/if_fe.c optional fe dev/fe/if_fe_pccard.c optional fe pccard Modified: stable/12/sys/conf/kern.post.mk ============================================================================== --- stable/12/sys/conf/kern.post.mk Sat Apr 27 04:00:50 2019 (r346780) +++ stable/12/sys/conf/kern.post.mk Sat Apr 27 04:12:32 2019 (r346781) @@ -8,7 +8,7 @@ # should be defined in the kern.pre.mk so that port makefiles can # override or augment them. -.if defined(DTS) || defined(DTSO) +.if defined(DTS) || defined(DTSO) || defined(FDT_DTS_FILE) .include "dtb.build.mk" KERNEL_EXTRA+= ${DTB} ${DTBO} From owner-svn-src-stable-12@freebsd.org Sat Apr 27 04:16:17 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E6A5D15847DB; Sat, 27 Apr 2019 04:16:16 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 8B1246DE1B; Sat, 27 Apr 2019 04:16:16 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 672781DCD3; Sat, 27 Apr 2019 04:16:16 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3R4GGkL063096; Sat, 27 Apr 2019 04:16:16 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3R4GGd6063095; Sat, 27 Apr 2019 04:16:16 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201904270416.x3R4GGd6063095@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Sat, 27 Apr 2019 04:16:16 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346782 - in stable: 11/usr.bin/dtc 12/usr.bin/dtc X-SVN-Group: stable-12 X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: in stable: 11/usr.bin/dtc 12/usr.bin/dtc X-SVN-Commit-Revision: 346782 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 8B1246DE1B X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.94 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.996,0]; NEURAL_HAM_SHORT(-0.95)[-0.946,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 27 Apr 2019 04:16:17 -0000 Author: kevans Date: Sat Apr 27 04:16:15 2019 New Revision: 346782 URL: https://svnweb.freebsd.org/changeset/base/346782 Log: MFC r346469: dtc(1): Pull in fix for segfault-upon-error condition Specifically, parse errors within a node would lead to a segfault due to an unconditional dereference after emitting the error. Modified: stable/12/usr.bin/dtc/fdt.cc Directory Properties: stable/12/ (props changed) Changes in other areas also in this revision: Modified: stable/11/usr.bin/dtc/fdt.cc Directory Properties: stable/11/ (props changed) Modified: stable/12/usr.bin/dtc/fdt.cc ============================================================================== --- stable/12/usr.bin/dtc/fdt.cc Sat Apr 27 04:12:32 2019 (r346781) +++ stable/12/usr.bin/dtc/fdt.cc Sat Apr 27 04:16:15 2019 (r346782) @@ -1622,7 +1622,10 @@ device_tree::parse_file(text_input_buffer &input, } input.next_token(); n = node::parse(input, *this, std::move(name), string_set(), string(), &defines); - n->name_is_path_reference = name_is_path_reference; + if (n) + { + n->name_is_path_reference = name_is_path_reference; + } } else { From owner-svn-src-stable-12@freebsd.org Sat Apr 27 04:39:45 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 51B7C1584FBB; Sat, 27 Apr 2019 04:39:45 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id EC0906EA22; Sat, 27 Apr 2019 04:39:44 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id C40D71E06A; Sat, 27 Apr 2019 04:39:44 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3R4dim7073843; Sat, 27 Apr 2019 04:39:44 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3R4dhar073837; Sat, 27 Apr 2019 04:39:43 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201904270439.x3R4dhar073837@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Sat, 27 Apr 2019 04:39:43 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346783 - in stable: 11/sys/conf 11/sys/net 12/sys/conf 12/sys/net X-SVN-Group: stable-12 X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: in stable: 11/sys/conf 11/sys/net 12/sys/conf 12/sys/net X-SVN-Commit-Revision: 346783 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: EC0906EA22 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.94 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.996,0]; NEURAL_HAM_SHORT(-0.95)[-0.949,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 27 Apr 2019 04:39:45 -0000 Author: kevans Date: Sat Apr 27 04:39:41 2019 New Revision: 346783 URL: https://svnweb.freebsd.org/changeset/base/346783 Log: MFC r345139, r345151, r346324, r346328: ether_gen_addr KPI if_bridge and if_vxlan conversion to this deterministic MAC address KPI has been MFC as well. This is potentially error prone as the generated address range for these has decreased, but I've deemed this acceptable for stable branches due to collisions for thees interfaces being easily remedied. I have no intention of switching anything else to this KPI in any stable branches. r345139: ether: centralize fake hwaddr generation We currently have two places with identical fake hwaddr generation -- if_vxlan and if_bridge. Lift it into if_ethersubr for reuse in other interfaces that may also need a fake addr. r345151: ether_fakeaddr: Use 'b' 's' 'd' for the prefix This has the advantage of being obvious to sniff out the designated prefix by eye and it has all the right bits set. Comment stolen from ffec. I've removed bryanv@'s pending question of using the FreeBSD OUI range -- no one has followed up on this with a definitive action, and there's no particular reason to shoot for it and the administrative overhead that comes with deciding exactly how to use it. r346324: net: adjust randomized address bits Give devices that need a MAC a 16-bit allocation out of the FreeBSD Foundation OUI range. Change the name ether_fakeaddr to ether_gen_addr now that we're dealing real MAC addresses with a real OUI rather than random locally-administered addresses. r346328: Compile sha1.c when ether support is included sha1 is used by ether_gen_addr after r346324. Perhaps in an ideal world we could detect that the kernel's been compiled without sha1_* bits included and silently fallback to arc4random instead because these platforms/kernel configs are far and few between. It's fairly lightweight, though, so just include it for now. Modified: stable/12/sys/conf/files stable/12/sys/net/ethernet.h stable/12/sys/net/ieee_oui.h stable/12/sys/net/if_bridge.c stable/12/sys/net/if_ethersubr.c stable/12/sys/net/if_vxlan.c Directory Properties: stable/12/ (props changed) Changes in other areas also in this revision: Modified: stable/11/sys/conf/files stable/11/sys/net/ethernet.h stable/11/sys/net/ieee_oui.h stable/11/sys/net/if_bridge.c stable/11/sys/net/if_ethersubr.c stable/11/sys/net/if_vxlan.c Directory Properties: stable/11/ (props changed) Modified: stable/12/sys/conf/files ============================================================================== --- stable/12/sys/conf/files Sat Apr 27 04:16:15 2019 (r346782) +++ stable/12/sys/conf/files Sat Apr 27 04:39:41 2019 (r346783) @@ -678,8 +678,8 @@ crypto/rijndael/rijndael-alg-fst.c optional crypto | e crypto/rijndael/rijndael-api-fst.c optional ekcd | geom_bde | random !random_loadable crypto/rijndael/rijndael-api.c optional crypto | ipsec | ipsec_support | \ wlan_ccmp -crypto/sha1.c optional carp | crypto | ipsec | \ - ipsec_support | netgraph_mppc_encryption | sctp +crypto/sha1.c optional carp | crypto | ether | ipsec | \ + ipsec_support | netgraph_mppc_encryption | sctp crypto/sha2/sha256c.c optional crypto | ekcd | geom_bde | ipsec | \ ipsec_support | random !random_loadable | sctp | zfs crypto/sha2/sha512c.c optional crypto | geom_bde | ipsec | \ Modified: stable/12/sys/net/ethernet.h ============================================================================== --- stable/12/sys/net/ethernet.h Sat Apr 27 04:16:15 2019 (r346782) +++ stable/12/sys/net/ethernet.h Sat Apr 27 04:39:41 2019 (r346783) @@ -422,6 +422,7 @@ void ether_vlan_mtap(struct bpf_if *, struct mbuf *, struct mbuf *ether_vlanencap(struct mbuf *, uint16_t); bool ether_8021q_frame(struct mbuf **mp, struct ifnet *ife, struct ifnet *p, uint16_t vid, uint8_t pcp); +void ether_gen_addr(struct ifnet *ifp, struct ether_addr *hwaddr); #ifdef _SYS_EVENTHANDLER_H_ /* new ethernet interface attached event */ Modified: stable/12/sys/net/ieee_oui.h ============================================================================== --- stable/12/sys/net/ieee_oui.h Sat Apr 27 04:16:15 2019 (r346782) +++ stable/12/sys/net/ieee_oui.h Sat Apr 27 04:39:41 2019 (r346783) @@ -67,3 +67,14 @@ /* Allocate 20 bits to bhyve */ #define OUI_FREEBSD_BHYVE_LOW OUI_FREEBSD(0x000001) #define OUI_FREEBSD_BHYVE_HIGH OUI_FREEBSD(0x0fffff) + +/* + * Allocate 16 bits for a pool to give to various interfaces that need a + * generated address, but don't quite need to slice off a whole section of + * the OUI (e.g. cloned interfaces, one-off NICs of various vendors). + * + * ether_gen_addr should be used to generate an address from this pool. + */ +#define OUI_FREEBSD_GENERATED_MASK 0x10ffff +#define OUI_FREEBSD_GENERATED_LOW OUI_FREEBSD(0x100000) +#define OUI_FREEBSD_GENERATED_HIGH OUI_FREEBSD(OU_FREEBSD_GENERATED_MASK) Modified: stable/12/sys/net/if_bridge.c ============================================================================== --- stable/12/sys/net/if_bridge.c Sat Apr 27 04:16:15 2019 (r346782) +++ stable/12/sys/net/if_bridge.c Sat Apr 27 04:39:41 2019 (r346783) @@ -226,7 +226,7 @@ struct bridge_softc { struct bstp_state sc_stp; /* STP state */ uint32_t sc_brtexceeded; /* # of cache drops */ struct ifnet *sc_ifaddr; /* member mac copied from */ - u_char sc_defaddr[6]; /* Default MAC address */ + struct ether_addr sc_defaddr; /* Default MAC address */ }; VNET_DEFINE_STATIC(struct mtx, bridge_list_mtx); @@ -671,16 +671,14 @@ bridge_clone_create(struct if_clone *ifc, int unit, ca getcredhostid(curthread->td_ucred, &hostid); do { if (fb || hostid == 0) { - arc4rand(sc->sc_defaddr, ETHER_ADDR_LEN, 1); - sc->sc_defaddr[0] &= ~1;/* clear multicast bit */ - sc->sc_defaddr[0] |= 2; /* set the LAA bit */ + ether_gen_addr(ifp, &sc->sc_defaddr); } else { - sc->sc_defaddr[0] = 0x2; - sc->sc_defaddr[1] = (hostid >> 24) & 0xff; - sc->sc_defaddr[2] = (hostid >> 16) & 0xff; - sc->sc_defaddr[3] = (hostid >> 8 ) & 0xff; - sc->sc_defaddr[4] = hostid & 0xff; - sc->sc_defaddr[5] = ifp->if_dunit & 0xff; + sc->sc_defaddr.octet[0] = 0x2; + sc->sc_defaddr.octet[1] = (hostid >> 24) & 0xff; + sc->sc_defaddr.octet[2] = (hostid >> 16) & 0xff; + sc->sc_defaddr.octet[3] = (hostid >> 8 ) & 0xff; + sc->sc_defaddr.octet[4] = hostid & 0xff; + sc->sc_defaddr.octet[5] = ifp->if_dunit & 0xff; } fb = 1; @@ -688,7 +686,7 @@ bridge_clone_create(struct if_clone *ifc, int unit, ca BRIDGE_LIST_LOCK(); LIST_FOREACH(sc2, &V_bridge_list, sc_list) { bifp = sc2->sc_ifp; - if (memcmp(sc->sc_defaddr, + if (memcmp(sc->sc_defaddr.octet, IF_LLADDR(bifp), ETHER_ADDR_LEN) == 0) { retry = 1; break; @@ -698,7 +696,7 @@ bridge_clone_create(struct if_clone *ifc, int unit, ca } while (retry == 1); bstp_attach(&sc->sc_stp, &bridge_ops); - ether_ifattach(ifp, sc->sc_defaddr); + ether_ifattach(ifp, sc->sc_defaddr.octet); /* Now undo some of the damage... */ ifp->if_baudrate = 0; ifp->if_type = IFT_BRIDGE; @@ -1019,7 +1017,7 @@ bridge_delete_member(struct bridge_softc *sc, struct b */ if (V_bridge_inherit_mac && sc->sc_ifaddr == ifs) { if (LIST_EMPTY(&sc->sc_iflist)) { - bcopy(sc->sc_defaddr, + bcopy(&sc->sc_defaddr, IF_LLADDR(sc->sc_ifp), ETHER_ADDR_LEN); sc->sc_ifaddr = NULL; } else { @@ -1190,7 +1188,7 @@ bridge_ioctl_add(struct bridge_softc *sc, void *arg) * the default randomly generated one. */ if (V_bridge_inherit_mac && LIST_EMPTY(&sc->sc_iflist) && - !memcmp(IF_LLADDR(sc->sc_ifp), sc->sc_defaddr, ETHER_ADDR_LEN)) { + !memcmp(IF_LLADDR(sc->sc_ifp), sc->sc_defaddr.octet, ETHER_ADDR_LEN)) { bcopy(IF_LLADDR(ifs), IF_LLADDR(sc->sc_ifp), ETHER_ADDR_LEN); sc->sc_ifaddr = ifs; EVENTHANDLER_INVOKE(iflladdr_event, sc->sc_ifp); Modified: stable/12/sys/net/if_ethersubr.c ============================================================================== --- stable/12/sys/net/if_ethersubr.c Sat Apr 27 04:16:15 2019 (r346782) +++ stable/12/sys/net/if_ethersubr.c Sat Apr 27 04:39:41 2019 (r346783) @@ -42,11 +42,13 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include #include @@ -54,6 +56,7 @@ #include #include +#include #include #include #include @@ -85,6 +88,8 @@ #endif #include +#include + #ifdef CTASSERT CTASSERT(sizeof (struct ether_header) == ETHER_ADDR_LEN * 2 + 2); CTASSERT(sizeof (struct ether_addr) == ETHER_ADDR_LEN); @@ -1366,6 +1371,39 @@ ether_8021q_frame(struct mbuf **mp, struct ifnet *ife, } } return (true); +} + +/* + * Allocate an address from the FreeBSD Foundation OUI. This uses a + * cryptographic hash function on the containing jail's UUID and the interface + * name to attempt to provide a unique but stable address. Pseudo-interfaces + * which require a MAC address should use this function to allocate + * non-locally-administered addresses. + */ +void +ether_gen_addr(struct ifnet *ifp, struct ether_addr *hwaddr) +{ +#define ETHER_GEN_ADDR_BUFSIZ HOSTUUIDLEN + IFNAMSIZ + 2 + SHA1_CTX ctx; + char buf[ETHER_GEN_ADDR_BUFSIZ]; + char uuid[HOSTUUIDLEN + 1]; + uint64_t addr; + int i, sz; + char digest[SHA1_RESULTLEN]; + + getcredhostuuid(curthread->td_ucred, uuid, sizeof(uuid)); + sz = snprintf(buf, ETHER_GEN_ADDR_BUFSIZ, "%s-%s", uuid, ifp->if_xname); + SHA1Init(&ctx); + SHA1Update(&ctx, buf, sz); + SHA1Final(digest, &ctx); + + addr = ((digest[0] << 16) | (digest[1] << 8) | digest[2]) & + OUI_FREEBSD_GENERATED_MASK; + addr = OUI_FREEBSD(addr); + for (i = 0; i < ETHER_ADDR_LEN; ++i) { + hwaddr->octet[i] = addr >> ((ETHER_ADDR_LEN - i - 1) * 8) & + 0xFF; + } } DECLARE_MODULE(ether, ether_mod, SI_SUB_INIT_IF, SI_ORDER_ANY); Modified: stable/12/sys/net/if_vxlan.c ============================================================================== --- stable/12/sys/net/if_vxlan.c Sat Apr 27 04:16:15 2019 (r346782) +++ stable/12/sys/net/if_vxlan.c Sat Apr 27 04:39:41 2019 (r346783) @@ -177,7 +177,7 @@ struct vxlan_softc { struct sysctl_oid *vxl_sysctl_node; struct sysctl_ctx_list vxl_sysctl_ctx; struct callout vxl_callout; - uint8_t vxl_hwaddr[ETHER_ADDR_LEN]; + struct ether_addr vxl_hwaddr; int vxl_mc_ifindex; struct ifnet *vxl_mc_ifp; struct ifmedia vxl_media; @@ -345,7 +345,6 @@ static int vxlan_clone_create(struct if_clone *, int, static void vxlan_clone_destroy(struct ifnet *); static uint32_t vxlan_mac_hash(struct vxlan_softc *, const uint8_t *); -static void vxlan_fakeaddr(struct vxlan_softc *); static int vxlan_media_change(struct ifnet *); static void vxlan_media_status(struct ifnet *, struct ifmediareq *); @@ -2755,8 +2754,8 @@ vxlan_clone_create(struct if_clone *ifc, int unit, cad ifmedia_add(&sc->vxl_media, IFM_ETHER | IFM_AUTO, 0, NULL); ifmedia_set(&sc->vxl_media, IFM_ETHER | IFM_AUTO); - vxlan_fakeaddr(sc); - ether_ifattach(ifp, sc->vxl_hwaddr); + ether_gen_addr(ifp, &sc->vxl_hwaddr); + ether_ifattach(ifp, sc->vxl_hwaddr.octet); ifp->if_baudrate = 0; ifp->if_hdrlen = 0; @@ -2825,20 +2824,6 @@ do { \ #undef mix return (c); -} - -static void -vxlan_fakeaddr(struct vxlan_softc *sc) -{ - - /* - * Generate a non-multicast, locally administered address. - * - * BMV: Should we use the FreeBSD OUI range instead? - */ - arc4rand(sc->vxl_hwaddr, ETHER_ADDR_LEN, 1); - sc->vxl_hwaddr[0] &= ~1; - sc->vxl_hwaddr[0] |= 2; } static int From owner-svn-src-stable-12@freebsd.org Sat Apr 27 04:51:58 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 7702C1585429; Sat, 27 Apr 2019 04:51:58 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 1B95A6F17B; Sat, 27 Apr 2019 04:51:58 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id EB77A1E380; Sat, 27 Apr 2019 04:51:57 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3R4pvmk083693; Sat, 27 Apr 2019 04:51:57 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3R4pvqJ083692; Sat, 27 Apr 2019 04:51:57 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201904270451.x3R4pvqJ083692@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Sat, 27 Apr 2019 04:51:57 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346784 - in stable: 11/sys/sys 12/sys/sys X-SVN-Group: stable-12 X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: in stable: 11/sys/sys 12/sys/sys X-SVN-Commit-Revision: 346784 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 1B95A6F17B X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.94 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.996,0]; NEURAL_HAM_SHORT(-0.95)[-0.946,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 27 Apr 2019 04:51:58 -0000 Author: kevans Date: Sat Apr 27 04:51:57 2019 New Revision: 346784 URL: https://svnweb.freebsd.org/changeset/base/346784 Log: Bump __FreeBSD_version for ether_gen_addr availability This is a direct commit to stable branches as the bump wasn't present in head. Modified: stable/12/sys/sys/param.h Changes in other areas also in this revision: Modified: stable/11/sys/sys/param.h Modified: stable/12/sys/sys/param.h ============================================================================== --- stable/12/sys/sys/param.h Sat Apr 27 04:39:41 2019 (r346783) +++ stable/12/sys/sys/param.h Sat Apr 27 04:51:57 2019 (r346784) @@ -60,7 +60,7 @@ * in the range 5 to 9. */ #undef __FreeBSD_version -#define __FreeBSD_version 1200507 /* Master, propagated to newvers */ +#define __FreeBSD_version 1200508 /* Master, propagated to newvers */ /* * __FreeBSD_kernel__ indicates that this system uses the kernel of FreeBSD, From owner-svn-src-stable-12@freebsd.org Sat Apr 27 05:35:21 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 3CFD01585DE2; Sat, 27 Apr 2019 05:35:21 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id D3EF970437; Sat, 27 Apr 2019 05:35:20 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id A084A1EA86; Sat, 27 Apr 2019 05:35:20 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3R5ZKZm005389; Sat, 27 Apr 2019 05:35:20 GMT (envelope-from markj@FreeBSD.org) Received: (from markj@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3R5ZKQd005388; Sat, 27 Apr 2019 05:35:20 GMT (envelope-from markj@FreeBSD.org) Message-Id: <201904270535.x3R5ZKQd005388@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: markj set sender to markj@FreeBSD.org using -f From: Mark Johnston Date: Sat, 27 Apr 2019 05:35:20 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346785 - stable/12/sys/modules/opensolaris X-SVN-Group: stable-12 X-SVN-Commit-Author: markj X-SVN-Commit-Paths: stable/12/sys/modules/opensolaris X-SVN-Commit-Revision: 346785 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: D3EF970437 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.96 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.996,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.96)[-0.964,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 27 Apr 2019 05:35:21 -0000 Author: markj Date: Sat Apr 27 05:35:20 2019 New Revision: 346785 URL: https://svnweb.freebsd.org/changeset/base/346785 Log: MFC r346440: Export cpu_core from opensolaris.ko. PR: 191462 Modified: stable/12/sys/modules/opensolaris/Makefile Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/modules/opensolaris/Makefile ============================================================================== --- stable/12/sys/modules/opensolaris/Makefile Sat Apr 27 04:51:57 2019 (r346784) +++ stable/12/sys/modules/opensolaris/Makefile Sat Apr 27 05:35:20 2019 (r346785) @@ -27,6 +27,8 @@ CFLAGS+= -I${SYSDIR}/cddl/compat/opensolaris \ -I${SYSDIR}/cddl/contrib/opensolaris/uts/common \ -I${SYSDIR} +EXPORT_SYMS= cpu_core + IGNORE_PRAGMA= 1 .include From owner-svn-src-stable-12@freebsd.org Sat Apr 27 19:45:35 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 068FF159B16A; Sat, 27 Apr 2019 19:45:35 +0000 (UTC) (envelope-from cperciva@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 9BB9D6C3D3; Sat, 27 Apr 2019 19:45:34 +0000 (UTC) (envelope-from cperciva@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4647927B5B; Sat, 27 Apr 2019 19:45:34 +0000 (UTC) (envelope-from cperciva@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3RJjYSI054139; Sat, 27 Apr 2019 19:45:34 GMT (envelope-from cperciva@FreeBSD.org) Received: (from cperciva@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3RJjYAe054138; Sat, 27 Apr 2019 19:45:34 GMT (envelope-from cperciva@FreeBSD.org) Message-Id: <201904271945.x3RJjYAe054138@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: cperciva set sender to cperciva@FreeBSD.org using -f From: Colin Percival Date: Sat, 27 Apr 2019 19:45:34 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346792 - stable/12/usr.sbin/pkg X-SVN-Group: stable-12 X-SVN-Commit-Author: cperciva X-SVN-Commit-Paths: stable/12/usr.sbin/pkg X-SVN-Commit-Revision: 346792 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 9BB9D6C3D3 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.96 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.997,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.96)[-0.962,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 27 Apr 2019 19:45:35 -0000 Author: cperciva Date: Sat Apr 27 19:45:33 2019 New Revision: 346792 URL: https://svnweb.freebsd.org/changeset/base/346792 Log: On non-x86 systems, use "quarterly" packages. x86 architectures have "latest" package builds on stable/*, so keep using those (they'll get switched over to "quarterly" during releases). Direct commit to stable/12 because using "latest" packages is appropriate for all architectures on HEAD. Discussed with: gjb Modified: stable/12/usr.sbin/pkg/Makefile Modified: stable/12/usr.sbin/pkg/Makefile ============================================================================== --- stable/12/usr.sbin/pkg/Makefile Sat Apr 27 19:32:33 2019 (r346791) +++ stable/12/usr.sbin/pkg/Makefile Sat Apr 27 19:45:33 2019 (r346792) @@ -1,5 +1,8 @@ # $FreeBSD$ +.if ${MACHINE} != "amd64" && ${MACHINE} != "i386" +PKGCONFBRANCH?= quarterly +.endif PKGCONFBRANCH?= latest CONFS= FreeBSD.conf.${PKGCONFBRANCH} CONFSNAME= FreeBSD.conf From owner-svn-src-stable-12@freebsd.org Sat Apr 27 19:48:16 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id C3BCB159B362; Sat, 27 Apr 2019 19:48:16 +0000 (UTC) (envelope-from cperciva@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 689A46C602; Sat, 27 Apr 2019 19:48:16 +0000 (UTC) (envelope-from cperciva@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 3E7CF27B5C; Sat, 27 Apr 2019 19:48:16 +0000 (UTC) (envelope-from cperciva@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3RJmGF1054295; Sat, 27 Apr 2019 19:48:16 GMT (envelope-from cperciva@FreeBSD.org) Received: (from cperciva@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3RJmFvc054294; Sat, 27 Apr 2019 19:48:15 GMT (envelope-from cperciva@FreeBSD.org) Message-Id: <201904271948.x3RJmFvc054294@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: cperciva set sender to cperciva@FreeBSD.org using -f From: Colin Percival Date: Sat, 27 Apr 2019 19:48:15 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346793 - in stable/12/sys: arm64/conf modules X-SVN-Group: stable-12 X-SVN-Commit-Author: cperciva X-SVN-Commit-Paths: in stable/12/sys: arm64/conf modules X-SVN-Commit-Revision: 346793 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 689A46C602 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.96 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.997,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.96)[-0.962,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 27 Apr 2019 19:48:16 -0000 Author: cperciva Date: Sat Apr 27 19:48:15 2019 New Revision: 346793 URL: https://svnweb.freebsd.org/changeset/base/346793 Log: MFC r345407,r345408: Add nvme to arm64 GENERIC, and build if_ena on arm64. These allow stable/12 to boot on Amazon EC2 "A1" family (arm64) instances. Sponsored by: https://www.patreon.com/cperciva Modified: stable/12/sys/arm64/conf/GENERIC stable/12/sys/modules/Makefile Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/arm64/conf/GENERIC ============================================================================== --- stable/12/sys/arm64/conf/GENERIC Sat Apr 27 19:45:33 2019 (r346792) +++ stable/12/sys/arm64/conf/GENERIC Sat Apr 27 19:48:15 2019 (r346793) @@ -151,6 +151,11 @@ device da # ATA/SCSI peripherals device pass # Passthrough device (direct ATA/SCSI access) +# NVM Express (NVMe) support +device nvme # base NVMe driver +options NVME_USE_NVD=0 # prefer the cam(4) based nda(4) driver +device nvd # expose NVMe namespaces as disks, depends on nvme + # MMC/SD/SDIO Card slot support device sdhci device sdhci_xenon # Marvell Xenon SD/MMC controller Modified: stable/12/sys/modules/Makefile ============================================================================== --- stable/12/sys/modules/Makefile Sat Apr 27 19:45:33 2019 (r346792) +++ stable/12/sys/modules/Makefile Sat Apr 27 19:48:15 2019 (r346793) @@ -496,6 +496,7 @@ SUBDIR+= fdt ${MACHINE_CPUARCH} == "i386" SUBDIR+= linprocfs SUBDIR+= linsysfs +_ena= ena .endif .if ${MK_NAND} != "no" || defined(ALL_MODULES) @@ -600,7 +601,6 @@ _drm2= drm2 .endif _ed= ed _em= em -_ena= ena _ep= ep _et= et _exca= exca