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

2020-11-18 Thread Peter Grehan
Author: grehan
Date: Thu Nov 19 07:23:39 2020
New Revision: 367834
URL: https://svnweb.freebsd.org/changeset/base/367834

Log:
  Advance RIP after userspace instruction decode
  
  Add update to RIP after a userspace instruction decode (as is done for
  the in-kernel counterpart of this case).
  
  Submitted by: adam_fenn.io
  Reviewed by:  cem, markj
  Approved by:  grehan (bhyve)
  MFC after:3 weeks
  Differential Revision:https://reviews.freebsd.org/D27243

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

Modified: head/usr.sbin/bhyve/bhyverun.c
==
--- head/usr.sbin/bhyve/bhyverun.c  Thu Nov 19 06:30:25 2020
(r367833)
+++ head/usr.sbin/bhyve/bhyverun.c  Thu Nov 19 07:23:39 2020
(r367834)
@@ -766,7 +766,11 @@ vmexit_inst_emul(struct vmctx *ctx, struct vm_exit *vm
vie_restart(vie);
mode = vmexit->u.inst_emul.paging.cpu_mode;
cs_d = vmexit->u.inst_emul.cs_d;
-   (void)vmm_decode_instruction(mode, cs_d, vie);
+   if (vmm_decode_instruction(mode, cs_d, vie) != 0)
+   goto fail;
+   if (vm_set_register(ctx, *pvcpu, VM_REG_GUEST_RIP,
+   vmexit->rip + vie->num_processed) != 0)
+   goto fail;
}
 
err = emulate_mem(ctx, *pvcpu, vmexit->u.inst_emul.gpa,
@@ -777,15 +781,17 @@ vmexit_inst_emul(struct vmctx *ctx, struct vm_exit *vm
EPRINTLN("Unhandled memory access to 0x%lx\n",
vmexit->u.inst_emul.gpa);
}
-
-   fprintf(stderr, "Failed to emulate instruction sequence [ ");
-   for (i = 0; i < vie->num_valid; i++)
-   fprintf(stderr, "%02x", vie->inst[i]);
-   FPRINTLN(stderr, " ] at 0x%lx", vmexit->rip);
-   return (VMEXIT_ABORT);
+   goto fail;
}
 
return (VMEXIT_CONTINUE);
+
+fail:
+   fprintf(stderr, "Failed to emulate instruction sequence [ ");
+   for (i = 0; i < vie->num_valid; i++)
+   fprintf(stderr, "%02x", vie->inst[i]);
+   FPRINTLN(stderr, " ] at 0x%lx", vmexit->rip);
+   return (VMEXIT_ABORT);
 }
 
 static pthread_mutex_t resetcpu_mtx = PTHREAD_MUTEX_INITIALIZER;
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r367833 - in head/sys: kern security/mac sys

2020-11-18 Thread Mateusz Guzik
Author: mjg
Date: Thu Nov 19 06:30:25 2020
New Revision: 367833
URL: https://svnweb.freebsd.org/changeset/base/367833

Log:
  pipe: allow for lockless pipe_stat
  
  pipes get stated all thet time and this avoidably contributed to contention.
  The pipe lock is only held to accomodate MAC and to check the type.
  
  Since normally there is no probe for pipe stat depessimize this by having the
  flag.
  
  The pipe_state field gets modified with locks held all the time and it's not
  feasible to convert them to use atomic store. Move the type flag away to a
  separate variable as a simple cleanup and to provide stable field to read.
  Use short for both fields to avoid growing the struct.
  
  While here short-circuit MAC for pipe_poll as well.

Modified:
  head/sys/kern/sys_pipe.c
  head/sys/security/mac/mac_framework.c
  head/sys/security/mac/mac_framework.h
  head/sys/security/mac/mac_pipe.c
  head/sys/sys/pipe.h

Modified: head/sys/kern/sys_pipe.c
==
--- head/sys/kern/sys_pipe.cThu Nov 19 05:46:59 2020(r367832)
+++ head/sys/kern/sys_pipe.cThu Nov 19 06:30:25 2020(r367833)
@@ -140,7 +140,7 @@ __FBSDID("$FreeBSD$");
 /* #define PIPE_NODIRECT */
 
 #define PIPE_PEER(pipe)\
-   (((pipe)->pipe_state & PIPE_NAMED) ? (pipe) : ((pipe)->pipe_peer))
+   (((pipe)->pipe_type & PIPE_TYPE_NAMED) ? (pipe) : ((pipe)->pipe_peer))
 
 /*
  * interfaces to the outside world
@@ -403,7 +403,7 @@ pipe_named_ctor(struct pipe **ppipe, struct thread *td
error = pipe_paircreate(td, );
if (error != 0)
return (error);
-   pp->pp_rpipe.pipe_state |= PIPE_NAMED;
+   pp->pp_rpipe.pipe_type |= PIPE_TYPE_NAMED;
*ppipe = >pp_rpipe;
return (0);
 }
@@ -413,7 +413,7 @@ pipe_dtor(struct pipe *dpipe)
 {
struct pipe *peer;
 
-   peer = (dpipe->pipe_state & PIPE_NAMED) != 0 ? dpipe->pipe_peer : NULL;
+   peer = (dpipe->pipe_type & PIPE_TYPE_NAMED) != 0 ? dpipe->pipe_peer : 
NULL;
funsetown(>pipe_sigio);
pipeclose(dpipe);
if (peer != NULL) {
@@ -1328,7 +1328,7 @@ pipe_truncate(struct file *fp, off_t length, struct uc
int error;
 
cpipe = fp->f_data;
-   if (cpipe->pipe_state & PIPE_NAMED)
+   if (cpipe->pipe_type & PIPE_TYPE_NAMED)
error = vnops.fo_truncate(fp, length, active_cred, td);
else
error = invfo_truncate(fp, length, active_cred, td);
@@ -1443,7 +1443,7 @@ pipe_poll(struct file *fp, int events, struct ucred *a
 
levents = events &
(POLLIN | POLLINIGNEOF | POLLPRI | POLLRDNORM | POLLRDBAND);
-   if (rpipe->pipe_state & PIPE_NAMED && fp->f_flag & FREAD && levents &&
+   if (rpipe->pipe_type & PIPE_TYPE_NAMED && fp->f_flag & FREAD && levents 
&&
fp->f_pipegen == rpipe->pipe_wgen)
events |= POLLINIGNEOF;
 
@@ -1496,23 +1496,22 @@ pipe_stat(struct file *fp, struct stat *ub, struct ucr
 #endif
 
pipe = fp->f_data;
-   PIPE_LOCK(pipe);
 #ifdef MAC
-   error = mac_pipe_check_stat(active_cred, pipe->pipe_pair);
-   if (error) {
+   if (mac_pipe_check_stat_enabled()) {
+   PIPE_LOCK(pipe);
+   error = mac_pipe_check_stat(active_cred, pipe->pipe_pair);
PIPE_UNLOCK(pipe);
-   return (error);
+   if (error) {
+   return (error);
+   }
}
 #endif
 
/* For named pipes ask the underlying filesystem. */
-   if (pipe->pipe_state & PIPE_NAMED) {
-   PIPE_UNLOCK(pipe);
+   if (pipe->pipe_type & PIPE_TYPE_NAMED) {
return (vnops.fo_stat(fp, ub, active_cred, td));
}
 
-   PIPE_UNLOCK(pipe);
-
bzero(ub, sizeof(*ub));
ub->st_mode = S_IFIFO;
ub->st_blksize = PAGE_SIZE;
@@ -1554,7 +1553,7 @@ pipe_chmod(struct file *fp, mode_t mode, struct ucred 
int error;
 
cpipe = fp->f_data;
-   if (cpipe->pipe_state & PIPE_NAMED)
+   if (cpipe->pipe_type & PIPE_TYPE_NAMED)
error = vn_chmod(fp, mode, active_cred, td);
else
error = invfo_chmod(fp, mode, active_cred, td);
@@ -1569,7 +1568,7 @@ pipe_chown(struct file *fp, uid_t uid, gid_t gid, stru
int error;
 
cpipe = fp->f_data;
-   if (cpipe->pipe_state & PIPE_NAMED)
+   if (cpipe->pipe_type & PIPE_TYPE_NAMED)
error = vn_chown(fp, uid, gid, active_cred, td);
else
error = invfo_chown(fp, uid, gid, active_cred, td);
@@ -1758,7 +1757,7 @@ filt_piperead(struct knote *kn, long hint)
kn->kn_data = rpipe->pipe_pages.cnt;
 
if ((rpipe->pipe_state & PIPE_EOF) != 0 &&
-   ((rpipe->pipe_state & PIPE_NAMED) == 0 ||
+   ((rpipe->pipe_type & PIPE_TYPE_NAMED) == 0 ||
fp->f_pipegen != rpipe->pipe_wgen)) {
kn->kn_flags |= 

svn commit: r367832 - in head/contrib/openpam: . lib/libpam

2020-11-18 Thread Dag-Erling Smørgrav
Author: des
Date: Thu Nov 19 05:46:59 2020
New Revision: 367832
URL: https://svnweb.freebsd.org/changeset/base/367832

Log:
  Merge upstream r948: fix race condition in openpam_ttyconv(3).

Modified:
  head/contrib/openpam/CREDITS
  head/contrib/openpam/lib/libpam/openpam_ttyconv.c
Directory Properties:
  head/contrib/openpam/   (props changed)

Modified: head/contrib/openpam/CREDITS
==
--- head/contrib/openpam/CREDITSThu Nov 19 05:44:41 2020
(r367831)
+++ head/contrib/openpam/CREDITSThu Nov 19 05:46:59 2020
(r367832)
@@ -18,6 +18,7 @@ ideas:
Ankita Pal 
Baptiste Daroussin 
Brian Fundakowski Feldman 
+   Brooks Davis 
Christos Zoulas 
Daniel Richard G. 
Darren J. Moffat 

Modified: head/contrib/openpam/lib/libpam/openpam_ttyconv.c
==
--- head/contrib/openpam/lib/libpam/openpam_ttyconv.c   Thu Nov 19 05:44:41 
2020(r367831)
+++ head/contrib/openpam/lib/libpam/openpam_ttyconv.c   Thu Nov 19 05:46:59 
2020(r367832)
@@ -94,12 +94,6 @@ prompt_tty(int ifd, int ofd, const char *message, char
int pos, ret;
char ch;
 
-   /* write prompt */
-   if (write(ofd, message, strlen(message)) < 0) {
-   openpam_log(PAM_LOG_ERROR, "write(): %m");
-   return (-1);
-   }
-
/* turn echo off if requested */
slflag = 0; /* prevent bogus uninitialized variable warning */
if (!echo) {
@@ -113,6 +107,12 @@ prompt_tty(int ifd, int ofd, const char *message, char
openpam_log(PAM_LOG_ERROR, "tcsetattr(): %m");
return (-1);
}
+   }
+
+   /* write prompt */
+   if (write(ofd, message, strlen(message)) < 0) {
+   openpam_log(PAM_LOG_ERROR, "write(): %m");
+   return (-1);
}
 
/* install signal handlers */
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r367831 - in vendor/openpam/dist: . lib/libpam

2020-11-18 Thread Dag-Erling Smørgrav
Author: des
Date: Thu Nov 19 05:44:41 2020
New Revision: 367831
URL: https://svnweb.freebsd.org/changeset/base/367831

Log:
  Merge upstream r948: fix race condition in openpam_ttyconv(3).

Modified:
  vendor/openpam/dist/CREDITS
  vendor/openpam/dist/lib/libpam/openpam_ttyconv.c

Modified: vendor/openpam/dist/CREDITS
==
--- vendor/openpam/dist/CREDITS Thu Nov 19 04:28:39 2020(r367830)
+++ vendor/openpam/dist/CREDITS Thu Nov 19 05:44:41 2020(r367831)
@@ -18,6 +18,7 @@ ideas:
Ankita Pal 
Baptiste Daroussin 
Brian Fundakowski Feldman 
+   Brooks Davis 
Christos Zoulas 
Daniel Richard G. 
Darren J. Moffat 

Modified: vendor/openpam/dist/lib/libpam/openpam_ttyconv.c
==
--- vendor/openpam/dist/lib/libpam/openpam_ttyconv.cThu Nov 19 04:28:39 
2020(r367830)
+++ vendor/openpam/dist/lib/libpam/openpam_ttyconv.cThu Nov 19 05:44:41 
2020(r367831)
@@ -94,12 +94,6 @@ prompt_tty(int ifd, int ofd, const char *message, char
int pos, ret;
char ch;
 
-   /* write prompt */
-   if (write(ofd, message, strlen(message)) < 0) {
-   openpam_log(PAM_LOG_ERROR, "write(): %m");
-   return (-1);
-   }
-
/* turn echo off if requested */
slflag = 0; /* prevent bogus uninitialized variable warning */
if (!echo) {
@@ -113,6 +107,12 @@ prompt_tty(int ifd, int ofd, const char *message, char
openpam_log(PAM_LOG_ERROR, "tcsetattr(): %m");
return (-1);
}
+   }
+
+   /* write prompt */
+   if (write(ofd, message, strlen(message)) < 0) {
+   openpam_log(PAM_LOG_ERROR, "write(): %m");
+   return (-1);
}
 
/* install signal handlers */
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


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

2020-11-18 Thread Mark Johnston
On Wed, Nov 18, 2020 at 03:37:36PM -0800, John Baldwin wrote:
> On 11/18/20 2:16 PM, Mateusz Guzik wrote:
> > On 11/17/20, John Baldwin  wrote:
> >> On 11/14/20 11:22 AM, Mateusz Guzik wrote:
> > Interested parties can check the consumer (also seen in the diff) to
> > see this is for consistency. I don't think any comments are warranted
> > in the header.
> 
> I did read the consumer, and there didn't seem tremendous value in the
> extra line there.
> 
> >> These changes would benefit from review.
> >>
> > 
> > I don't think it's feasible to ask for review for everything lest it
> > degardes to rubber stamping and I don't think this change warranted
> > it, regardless of the cosmetic issues which can always show up.
> 
> That is not consistent with the direction the project is moving.  If you
> check the commit logs of other high-volume committers such as markj@,
> kib@, or myself, you will find that a substantial number of those commits
> are reviewed (typically in phabricator) without preventing us from
> making useful progress.  Also, while the previous core did not mandate
> reviews, we moved closer to it when the Pre-Commit Review chapter was
> added to the Committer's Guide:
> 
> https://www.freebsd.org/doc/en_US.ISO8859-1/articles/committers-guide/pre-commit-review.html
> 
> In the related thread on developers@ we indicated that while weren't yet
> making pre-commit review mandatory, we collectively want to move in that
> direction.

So, I personally don't really like the idea of mandatory reviews.  It's
a drag, especially for volunteers.  It works ok in areas that have
active maintainers, but lots of FreeBSD does not.  For instance, pretty
much every change to sys/vm gets a review, but only by convention.  It's
not perfect, and in particular it discourages me from making some
changes both because getting review is a hassle and because I don't want
to spam other VM developers (especially volunteers) with minor things.
If all changes require some sort of sign-off, even if it's effectively
rubber-stamping, I fear it'll discourage a lot of small, worthwhile
contributions while also burning out reviewers.  Meanwhile, we had
issues for a long time where changes to the CSPRNG code were blocked for
lack of review, and we have some problems with the LOCALBASE changes
despite review.

For better or worse, FreeBSD has no sole technical authority to direct
development.  More than many other projects, we rely on consensus and
more broadly the ability of developers to engage with each other even
when their communication styles differ.  Since Phabricator was
introduced it's been a lot easier to get feedback on patches, and
non-committers have a better vehicle to propose patches.  No edict was
needed for that.  On the other hand, FCP doesn't seem to have been
successful.  I suspect that mailing lists are sufficient for the same
purpose that FCP is for; if someone doesn't care to socialize some
changes on the lists, it's unlikely that they'll do so in a FCP, and
because FreeBSD has no one who can really mandate development process,
FCP doesn't buy us much.  I tried adding RELNOTES so that it's easier
for us to advertise our work to users; it's worked so-so, and I suspect
that a lot of developers don't care about advertising their work or just
don't know about RELNOTES.  Our development processes end up being
largely dictated by social norms, which are influenced by the most
prolific committers.

Mateusz is making a lot of commits to the kernel without any review.
Most other committers would try to get a review for similar changes.
For what it's worth I personally trust Mateusz to make well-reasoned
changes, and to own his bugs.  He does regularly ask for review and
testing and I don't spend as much time as I should on his reviews.  The
problem, though, is the default assumption that most changes are not
worth reviewing at all because they're small, mechanical, no one cares,
whatever.  It's worth soliciting review if only so that at least one
other person has an idea of what's changing in the tree, because there
_will_ come a time when it helps that person make changes of their own,
or find a bug.  Even if a reviewer doesn't deeply understand a diff,
they might suggest stylistic changes that make the code more readable,
or comment on related code in a way that's useful later.  Similarly,
verbose commit logs can seem pointless but are a huge help down the
road.  I know this is a common observation but it comes up all the time
for me.

With regard to the future direction of src development, I would propose
a middle ground.  Most, if not all, changes should get a Phabricator
review.  There should be some minimum period between creation of that
review and a commit.  The developer should make some effort to cc active
committers to the code.  Some areas of the tree will have stricter
rules, but in general absence of feedback means that it's ok to commit.
Exceptions might apply to build fixes, etc..  This still imposes 

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

2020-11-18 Thread Mateusz Guzik
On 11/19/20, John Baldwin  wrote:
> On 11/18/20 2:16 PM, Mateusz Guzik wrote:
>> On 11/17/20, John Baldwin  wrote:
>>> On 11/14/20 11:22 AM, Mateusz Guzik wrote:
>> Interested parties can check the consumer (also seen in the diff) to
>> see this is for consistency. I don't think any comments are warranted
>> in the header.
>
> I did read the consumer, and there didn't seem tremendous value in the
> extra line there.
>

One thing to note is that there are more thing to batch than currently
implemented, meaning the established pattern is going get more users.
With everyone implementing the same routines, even if nops, it is
pretty clear what's going on. In contrast if random calls are missing
the reader is left wondering if there is a bug.

Either way I see no reason to either comment add a comment in the
header nor to remove the nop func.

>>> These changes would benefit from review.
>>>
>>
>> I don't think it's feasible to ask for review for everything lest it
>> degardes to rubber stamping and I don't think this change warranted
>> it, regardless of the cosmetic issues which can always show up.
>
> That is not consistent with the direction the project is moving.  If you
> check the commit logs of other high-volume committers such as markj@,
> kib@, or myself, you will find that a substantial number of those commits
> are reviewed (typically in phabricator) without preventing us from
> making useful progress.  Also, while the previous core did not mandate
> reviews, we moved closer to it when the Pre-Commit Review chapter was
> added to the Committer's Guide:
>
> https://www.freebsd.org/doc/en_US.ISO8859-1/articles/committers-guide/pre-commit-review.html
>
> In the related thread on developers@ we indicated that while weren't yet
> making pre-commit review mandatory, we collectively want to move in that
> direction.
>

If you exclude bite-size commits, you will see I am getting reviews
for thing which are outside of my work area or which include design
choices. Past that other people keep committing without reviews
anyway. That said, it may be this patch indeed should have been
reviewed, but as it is I don't think this is the case.

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


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

2020-11-18 Thread Mateusz Guzik
Author: mjg
Date: Thu Nov 19 04:28:39 2020
New Revision: 367830
URL: https://svnweb.freebsd.org/changeset/base/367830

Log:
  cred: fix minor nits in r367695
  
  Noted by: jhb

Modified:
  head/sys/kern/kern_prot.c
  head/sys/sys/ucred.h

Modified: head/sys/kern/kern_prot.c
==
--- head/sys/kern/kern_prot.c   Thu Nov 19 04:27:51 2020(r367829)
+++ head/sys/kern/kern_prot.c   Thu Nov 19 04:28:39 2020(r367830)
@@ -2082,6 +2082,7 @@ crfree_final(struct ucred *cr)
__func__, cr->cr_users, cr));
KASSERT(cr->cr_ref == 0, ("%s: ref %d not == 0 on cred %p",
__func__, cr->cr_ref, cr));
+
/*
 * Some callers of crget(), such as nfs_statfs(), allocate a temporary
 * credential, but don't allocate a uidinfo structure.

Modified: head/sys/sys/ucred.h
==
--- head/sys/sys/ucred.hThu Nov 19 04:27:51 2020(r367829)
+++ head/sys/sys/ucred.hThu Nov 19 04:28:39 2020(r367830)
@@ -128,12 +128,13 @@ credbatch_prep(struct credbatch *crb)
crb->ref = 0;
 }
 void   credbatch_add(struct credbatch *crb, struct thread *td);
+
 static inline void
 credbatch_process(struct credbatch *crb __unused)
 {
 
 }
-void   credbatch_add(struct credbatch *crb, struct thread *td);
+
 void   credbatch_final(struct credbatch *crb);
 
 void   change_egid(struct ucred *newcred, gid_t egid);
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r367829 - head/sys/kern

2020-11-18 Thread Mateusz Guzik
Author: mjg
Date: Thu Nov 19 04:27:51 2020
New Revision: 367829
URL: https://svnweb.freebsd.org/changeset/base/367829

Log:
  smp: fix smp_rendezvous_cpus_retry usage before smp starts
  
  Since none of the other CPUs are running there is nobody to clear their
  entries and the routine spins indefinitely.

Modified:
  head/sys/kern/subr_smp.c

Modified: head/sys/kern/subr_smp.c
==
--- head/sys/kern/subr_smp.cThu Nov 19 03:59:21 2020(r367828)
+++ head/sys/kern/subr_smp.cThu Nov 19 04:27:51 2020(r367829)
@@ -896,6 +896,21 @@ smp_rendezvous_cpus_retry(cpuset_t map,
int cpu;
 
/*
+* Only one CPU to execute on.
+*/
+   if (!smp_started) {
+   spinlock_enter();
+   if (setup_func != NULL)
+   setup_func(arg);
+   if (action_func != NULL)
+   action_func(arg);
+   if (teardown_func != NULL)
+   teardown_func(arg);
+   spinlock_exit();
+   return;
+   }
+
+   /*
 * Execute an action on all specified CPUs while retrying until they
 * all acknowledge completion.
 */
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r367828 - in head/sys: amd64/amd64 dev/mem powerpc/aim vm

2020-11-18 Thread Mark Johnston
Author: markj
Date: Thu Nov 19 03:59:21 2020
New Revision: 367828
URL: https://svnweb.freebsd.org/changeset/base/367828

Log:
  vm_phys: Try to clean up NUMA KPIs
  
  It can useful for code outside the VM system to look up the NUMA domain
  of a page backing a virtual or physical address, specifically when
  creating NUMA-aware data structures.  We have _vm_phys_domain() for
  this, but the leading underscore implies that it's an internal function,
  and vm_phys.h has dependencies on a number of other headers.
  
  Rename vm_phys_domain() to vm_page_domain(), and _vm_phys_domain() to
  vm_phys_domain().  Make the latter an inline function.
  
  Add _vm_phys.h and define struct vm_phys_seg there so that it's easier
  to use in other headers.  Include it from vm_page.h so that
  vm_page_domain() can be defined there.
  
  Include machine/vmparam.h from _vm_phys.h since it depends directly on
  some constants defined there.
  
  Reviewed by:  alc
  Reviewed by:  dougm, kib (earlier versions)
  Differential Revision:https://reviews.freebsd.org/D27207

Added:
  head/sys/vm/_vm_phys.h   (contents, props changed)
Modified:
  head/sys/amd64/amd64/mp_machdep.c
  head/sys/amd64/amd64/pmap.c
  head/sys/dev/mem/memdev.c
  head/sys/powerpc/aim/mmu_oea64.c
  head/sys/powerpc/aim/mmu_radix.c
  head/sys/vm/uma_core.c
  head/sys/vm/vm_kern.c
  head/sys/vm/vm_page.c
  head/sys/vm/vm_page.h
  head/sys/vm/vm_pagequeue.h
  head/sys/vm/vm_phys.c
  head/sys/vm/vm_phys.h
  head/sys/vm/vm_reserv.c

Modified: head/sys/amd64/amd64/mp_machdep.c
==
--- head/sys/amd64/amd64/mp_machdep.c   Thu Nov 19 02:53:29 2020
(r367827)
+++ head/sys/amd64/amd64/mp_machdep.c   Thu Nov 19 03:59:21 2020
(r367828)
@@ -380,7 +380,7 @@ mp_realloc_pcpu(int cpuid, int domain)
vm_offset_t oa, na;
 
oa = (vm_offset_t)&__pcpu[cpuid];
-   if (_vm_phys_domain(pmap_kextract(oa)) == domain)
+   if (vm_phys_domain(pmap_kextract(oa)) == domain)
return;
m = vm_page_alloc_domain(NULL, 0, domain,
VM_ALLOC_NORMAL | VM_ALLOC_NOOBJ);

Modified: head/sys/amd64/amd64/pmap.c
==
--- head/sys/amd64/amd64/pmap.c Thu Nov 19 02:53:29 2020(r367827)
+++ head/sys/amd64/amd64/pmap.c Thu Nov 19 03:59:21 2020(r367828)
@@ -452,7 +452,7 @@ static __inline int
 pc_to_domain(struct pv_chunk *pc)
 {
 
-   return (_vm_phys_domain(DMAP_TO_PHYS((vm_offset_t)pc)));
+   return (vm_phys_domain(DMAP_TO_PHYS((vm_offset_t)pc)));
 }
 #else
 static __inline int
@@ -4611,7 +4611,7 @@ pmap_page_array_startup(long pages)
end = start + pages * sizeof(struct vm_page);
for (va = start; va < end; va += NBPDR) {
pfn = first_page + (va - start) / sizeof(struct vm_page);
-   domain = _vm_phys_domain(ptoa(pfn));
+   domain = vm_phys_domain(ptoa(pfn));
pdpe = pmap_pdpe(kernel_pmap, va);
if ((*pdpe & X86_PG_V) == 0) {
pa = vm_phys_early_alloc(domain, PAGE_SIZE);
@@ -5147,7 +5147,7 @@ retry:
pc->pc_map[0] = PC_FREE0 & ~1ul;/* preallocated bit 0 */
pc->pc_map[1] = PC_FREE1;
pc->pc_map[2] = PC_FREE2;
-   pvc = _chunks[_vm_phys_domain(m->phys_addr)];
+   pvc = _chunks[vm_phys_domain(m->phys_addr)];
mtx_lock(>pvc_lock);
TAILQ_INSERT_TAIL(>pvc_list, pc, pc_lru);
mtx_unlock(>pvc_lock);

Modified: head/sys/dev/mem/memdev.c
==
--- head/sys/dev/mem/memdev.c   Thu Nov 19 02:53:29 2020(r367827)
+++ head/sys/dev/mem/memdev.c   Thu Nov 19 03:59:21 2020(r367828)
@@ -111,7 +111,7 @@ memioctl(struct cdev *dev, u_long cmd, caddr_t data, i
>td_proc->p_vmspace->vm_pmap, me->me_vaddr);
if (me->me_paddr != 0) {
me->me_state = ME_STATE_MAPPED;
-   me->me_domain = _vm_phys_domain(me->me_paddr);
+   me->me_domain = vm_phys_domain(me->me_paddr);
} else {
me->me_state = ME_STATE_VALID;
}

Modified: head/sys/powerpc/aim/mmu_oea64.c
==
--- head/sys/powerpc/aim/mmu_oea64.cThu Nov 19 02:53:29 2020
(r367827)
+++ head/sys/powerpc/aim/mmu_oea64.cThu Nov 19 03:59:21 2020
(r367828)
@@ -3470,7 +3470,7 @@ moea64_page_array_startup(long pages)
}
 
for (i = 0; phys_avail[i + 1] != 0; i+= 2) {
-   domain = _vm_phys_domain(phys_avail[i]);
+   domain = vm_phys_domain(phys_avail[i]);
KASSERT(domain < MAXMEMDOM,
("Invalid phys_avail NUMA domain 

svn commit: r367827 - head/sys/conf

2020-11-18 Thread Mark Johnston
Author: markj
Date: Thu Nov 19 02:53:29 2020
New Revision: 367827
URL: https://svnweb.freebsd.org/changeset/base/367827

Log:
  Move kern_clocksource.c to sys/conf/files
  
  Sponsored by: The FreeBSD Foundation

Modified:
  head/sys/conf/files
  head/sys/conf/files.amd64
  head/sys/conf/files.arm
  head/sys/conf/files.arm64
  head/sys/conf/files.i386
  head/sys/conf/files.mips
  head/sys/conf/files.powerpc
  head/sys/conf/files.riscv

Modified: head/sys/conf/files
==
--- head/sys/conf/files Thu Nov 19 02:50:48 2020(r367826)
+++ head/sys/conf/files Thu Nov 19 02:53:29 2020(r367827)
@@ -3777,6 +3777,7 @@ kern/ksched.c optional 
_kposix_priority_scheduling
 kern/kern_acct.c   standard
 kern/kern_alq.coptional alq
 kern/kern_clock.c  standard
+kern/kern_clocksource.cstandard
 kern/kern_condvar.cstandard
 kern/kern_conf.c   standard
 kern/kern_cons.c   standard

Modified: head/sys/conf/files.amd64
==
--- head/sys/conf/files.amd64   Thu Nov 19 02:50:48 2020(r367826)
+++ head/sys/conf/files.amd64   Thu Nov 19 02:53:29 2020(r367827)
@@ -388,7 +388,6 @@ dev/xen/pci/xen_acpi_pci.c  optionalxenhvm
 dev/xen/pci/xen_pci.c  optionalxenhvm
 isa/syscons_isa.c  optionalsc
 isa/vga_isa.c  optionalvga
-kern/kern_clocksource.cstandard
 kern/imgact_aout.c optional compat_aout
 kern/link_elf_obj.cstandard
 #

Modified: head/sys/conf/files.arm
==
--- head/sys/conf/files.arm Thu Nov 19 02:50:48 2020(r367826)
+++ head/sys/conf/files.arm Thu Nov 19 02:53:29 2020(r367827)
@@ -1,7 +1,5 @@
 # $FreeBSD$
 
-kern/kern_clocksource.cstandard
-
 arm/arm/autoconf.c standard
 arm/arm/bcopy_page.S   standard
 arm/arm/bcopyinout.S   standard

Modified: head/sys/conf/files.arm64
==
--- head/sys/conf/files.arm64   Thu Nov 19 02:50:48 2020(r367826)
+++ head/sys/conf/files.arm64   Thu Nov 19 02:53:29 2020(r367827)
@@ -367,7 +367,6 @@ dev/vnic/thunder_bgx.c  optionalvnic pci
 dev/vnic/thunder_mdio_fdt.coptionalvnic fdt
 dev/vnic/thunder_mdio.coptionalvnic
 dev/vnic/lmac_if.m optionalinet | inet6 | vnic
-kern/kern_clocksource.cstandard
 kern/msi_if.m  optionalintrng
 kern/pic_if.m  optionalintrng
 kern/subr_devmap.c standard

Modified: head/sys/conf/files.i386
==
--- head/sys/conf/files.i386Thu Nov 19 02:50:48 2020(r367826)
+++ head/sys/conf/files.i386Thu Nov 19 02:53:29 2020(r367827)
@@ -211,7 +211,6 @@ i386/pci/pci_cfgreg.c   optional pci
 i386/pci/pci_pir.c optional pci
 isa/syscons_isa.c  optional sc
 isa/vga_isa.c  optional vga
-kern/kern_clocksource.cstandard
 kern/imgact_aout.c optional compat_aout
 kern/subr_sfbuf.c  standard
 libkern/divdi3.c   standard

Modified: head/sys/conf/files.mips
==
--- head/sys/conf/files.mipsThu Nov 19 02:50:48 2020(r367826)
+++ head/sys/conf/files.mipsThu Nov 19 02:53:29 2020(r367827)
@@ -48,7 +48,6 @@ mips/mips/uma_machdep.c   standard
 mips/mips/vm_machdep.c standard
 
 # misc opt-in bits
-kern/kern_clocksource.cstandard
 kern/link_elf_obj.cstandard
 kern/subr_atomic64.c   optionalmips | mipsel | mipshf 
| mipselhf
 kern/subr_busdma_bufalloc.cstandard

Modified: head/sys/conf/files.powerpc
==
--- head/sys/conf/files.powerpc Thu Nov 19 02:50:48 2020(r367826)
+++ head/sys/conf/files.powerpc Thu Nov 19 02:53:29 2020(r367827)
@@ -110,7 +110,6 @@ dev/tsec/if_tsec_fdt.c  optionaltsec 
 dev/uart/uart_cpu_powerpc.coptionaluart
 dev/usb/controller/ehci_fsl.c  optionalehci mpc85xx
 dev/vt/hw/ofwfb/ofwfb.coptionalvt aim
-kern/kern_clocksource.cstandard
 kern/subr_atomic64.c   optionalpowerpc | powerpcspe
 kern/subr_dummy_vdso_tc.c  standard
 kern/syscalls.coptionalktr

Modified: 

svn commit: r367826 - in head/sys: arm/arm arm/include conf kern

2020-11-18 Thread Mark Johnston
Author: markj
Date: Thu Nov 19 02:50:48 2020
New Revision: 367826
URL: https://svnweb.freebsd.org/changeset/base/367826

Log:
  Remove NO_EVENTTIMERS support
  
  The arm configs that required it have been removed from the tree.
  Removing this option makes the callout code easier to read and
  discourages developers from adding new configs without eventtimer
  drivers.
  
  Reviewed by:  ian, imp, mav
  Sponsored by: The FreeBSD Foundation
  Differential Revision:https://reviews.freebsd.org/D27270

Modified:
  head/sys/arm/arm/machdep.c
  head/sys/arm/include/machdep.h
  head/sys/conf/options
  head/sys/conf/options.arm
  head/sys/kern/kern_et.c
  head/sys/kern/kern_timeout.c

Modified: head/sys/arm/arm/machdep.c
==
--- head/sys/arm/arm/machdep.c  Thu Nov 19 02:44:08 2020(r367825)
+++ head/sys/arm/arm/machdep.c  Thu Nov 19 02:50:48 2020(r367826)
@@ -48,7 +48,6 @@
 #include "opt_kstack_pages.h"
 #include "opt_platform.h"
 #include "opt_sched.h"
-#include "opt_timer.h"
 
 #include 
 __FBSDID("$FreeBSD$");
@@ -304,16 +303,12 @@ cpu_idle(int busy)
 
CTR2(KTR_SPARE2, "cpu_idle(%d) at %d", busy, curcpu);
spinlock_enter();
-#ifndef NO_EVENTTIMERS
if (!busy)
cpu_idleclock();
-#endif
if (!sched_runnable())
cpu_sleep(0);
-#ifndef NO_EVENTTIMERS
if (!busy)
cpu_activeclock();
-#endif
spinlock_exit();
CTR2(KTR_SPARE2, "cpu_idle(%d) at %d done", busy, curcpu);
 }
@@ -325,22 +320,7 @@ cpu_idle_wakeup(int cpu)
return (0);
 }
 
-#ifdef NO_EVENTTIMERS
-/*
- * Most ARM platforms don't need to do anything special to init their clocks
- * (they get intialized during normal device attachment), and by not defining a
- * cpu_initclocks() function they get this generic one.  Any platform that 
needs
- * to do something special can just provide their own implementation, which 
will
- * override this one due to the weak linkage.
- */
 void
-arm_generic_initclocks(void)
-{
-}
-__weak_reference(arm_generic_initclocks, cpu_initclocks);
-
-#else
-void
 cpu_initclocks(void)
 {
 
@@ -353,7 +333,6 @@ cpu_initclocks(void)
cpu_initclocks_bsp();
 #endif
 }
-#endif
 
 #ifdef PLATFORM
 void

Modified: head/sys/arm/include/machdep.h
==
--- head/sys/arm/include/machdep.h  Thu Nov 19 02:44:08 2020
(r367825)
+++ head/sys/arm/include/machdep.h  Thu Nov 19 02:50:48 2020
(r367826)
@@ -39,7 +39,6 @@ vm_offset_t parse_boot_param(struct arm_boot_params *a
 void arm_parse_fdt_bootargs(void);
 void arm_print_kenv(void);
 
-void arm_generic_initclocks(void);
 int arm_get_vfpstate(struct thread *td, void *args);
 
 /* Board-specific attributes */

Modified: head/sys/conf/options
==
--- head/sys/conf/options   Thu Nov 19 02:44:08 2020(r367825)
+++ head/sys/conf/options   Thu Nov 19 02:50:48 2020(r367826)
@@ -180,7 +180,6 @@ NEW_PCIBopt_global.h
 NO_ADAPTIVE_MUTEXESopt_adaptive_mutexes.h
 NO_ADAPTIVE_RWLOCKS
 NO_ADAPTIVE_SX
-NO_EVENTTIMERS opt_timer.h
 NO_OBSOLETE_CODE   opt_global.h
 NO_SYSCTL_DESCRopt_global.h
 NSWBUF_MIN opt_param.h

Modified: head/sys/conf/options.arm
==
--- head/sys/conf/options.arm   Thu Nov 19 02:44:08 2020(r367825)
+++ head/sys/conf/options.arm   Thu Nov 19 02:50:48 2020(r367826)
@@ -6,7 +6,6 @@ ARM_KERN_DIRECTMAP  opt_vm.h
 ARM_L2_PIPTopt_global.h
 ARM_MANY_BOARD opt_global.h
 ARM_WANT_TP_ADDRESSopt_global.h
-COUNTS_PER_SEC opt_timer.h
 CPSW_ETHERSWITCH   opt_cpsw.h
 CPU_ARM9E  opt_global.h
 CPU_ARM1176opt_global.h
@@ -61,7 +60,6 @@ SOC_ROCKCHIP_RK3188   opt_global.h
 SOC_TI_AM335X  opt_global.h
 SOC_TEGRA2 opt_global.h
 XSCALE_CACHE_READ_WRITE_ALLOCATE   opt_global.h
-XSACLE_DISABLE_CCNTopt_timer.h
 VERBOSE_INIT_ARM   opt_global.h
 VM_MAXUSER_ADDRESS opt_global.h
 GFB_DEBUG  opt_gfb.h

Modified: head/sys/kern/kern_et.c
==
--- head/sys/kern/kern_et.c Thu Nov 19 02:44:08 2020(r367825)
+++ head/sys/kern/kern_et.c Thu Nov 19 02:50:48 2020(r367826)
@@ -37,8 +37,6 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 
-#include "opt_timer.h"
-
 SLIST_HEAD(et_eventtimers_list, eventtimer);
 static struct et_eventtimers_list eventtimers = 
SLIST_HEAD_INITIALIZER(et_eventtimers);
 
@@ -130,9 +128,7 @@ void
 et_change_frequency(struct eventtimer *et, uint64_t newfreq)
 {
 
-#ifndef NO_EVENTTIMERS
cpu_et_frequency(et, newfreq);
-#endif
 }
 
 /*

Modified: head/sys/kern/kern_timeout.c

svn commit: r367825 - stable/12/sys/dev/nvme

2020-11-18 Thread Alexander Motin
Author: mav
Date: Thu Nov 19 02:44:08 2020
New Revision: 367825
URL: https://svnweb.freebsd.org/changeset/base/367825

Log:
  MFC r367625: Fix panic if NVMe is detached before the intrhook call.

Modified:
  stable/12/sys/dev/nvme/nvme.c
  stable/12/sys/dev/nvme/nvme_ctrlr.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/dev/nvme/nvme.c
==
--- stable/12/sys/dev/nvme/nvme.c   Thu Nov 19 02:20:38 2020
(r367824)
+++ stable/12/sys/dev/nvme/nvme.c   Thu Nov 19 02:44:08 2020
(r367825)
@@ -145,9 +145,14 @@ nvme_attach(device_t dev)
 }
 
 int
-nvme_detach (device_t dev)
+nvme_detach(device_t dev)
 {
struct nvme_controller  *ctrlr = DEVICE2SOFTC(dev);
+
+   if (ctrlr->config_hook.ich_arg != NULL) {
+   config_intrhook_disestablish(>config_hook);
+   ctrlr->config_hook.ich_arg = NULL;
+   }
 
nvme_ctrlr_destruct(ctrlr, dev);
return (0);

Modified: stable/12/sys/dev/nvme/nvme_ctrlr.c
==
--- stable/12/sys/dev/nvme/nvme_ctrlr.c Thu Nov 19 02:20:38 2020
(r367824)
+++ stable/12/sys/dev/nvme/nvme_ctrlr.c Thu Nov 19 02:44:08 2020
(r367825)
@@ -1099,6 +1099,7 @@ nvme_ctrlr_start_config_hook(void *arg)
 fail:
nvme_ctrlr_fail(ctrlr);
config_intrhook_disestablish(>config_hook);
+   ctrlr->config_hook.ich_arg = NULL;
return;
}
 
@@ -1116,6 +1117,7 @@ fail:
 
nvme_sysctl_initialize_ctrlr(ctrlr);
config_intrhook_disestablish(>config_hook);
+   ctrlr->config_hook.ich_arg = NULL;
 
ctrlr->is_initialized = 1;
nvme_notify_new_controller(ctrlr);
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r367824 - head/sbin/savecore

2020-11-18 Thread Gleb Smirnoff
Author: glebius
Date: Thu Nov 19 02:20:38 2020
New Revision: 367824
URL: https://svnweb.freebsd.org/changeset/base/367824

Log:
  Add '-u' switch that would uncompress cores that were compressed by
  kernel during dump time.
  
  A real life scenario is that cores are compressed to reduce
  size of dumpon partition, but we either don't care about space
  in the /var/crash or we have a filesystem level compression of
  /var/crash. And we want cores to be uncompressed in /var/crash
  because we'd like to instantily read them with kgdb. In this
  case we want kernel to write cores compressed, but savecore(1)
  write them uncompressed.
  
  Reviewed by:  markj, gallatin
  Relnotes: yes
  Differential Revision:https://reviews.freebsd.org/D27245

Modified:
  head/sbin/savecore/Makefile
  head/sbin/savecore/savecore.8
  head/sbin/savecore/savecore.c

Modified: head/sbin/savecore/Makefile
==
--- head/sbin/savecore/Makefile Thu Nov 19 00:03:15 2020(r367823)
+++ head/sbin/savecore/Makefile Thu Nov 19 02:20:38 2020(r367824)
@@ -6,8 +6,10 @@ VAR_CRASH= /var/crash
 VAR_CRASH_MODE=0750
 CONFSDIR=  VAR_CRASH
 PROG=  savecore
-LIBADD=xo z
+LIBADD=xo z zstd
 MAN=   savecore.8
+
+CFLAGS+=   -I${SRCTOP}/sys/contrib/zstd/lib
 
 .include 
 

Modified: head/sbin/savecore/savecore.8
==
--- head/sbin/savecore/savecore.8   Thu Nov 19 00:03:15 2020
(r367823)
+++ head/sbin/savecore/savecore.8   Thu Nov 19 02:20:38 2020
(r367824)
@@ -28,7 +28,7 @@
 .\" From: @(#)savecore.8   8.1 (Berkeley) 6/5/93
 .\" $FreeBSD$
 .\"
-.Dd March 17, 2018
+.Dd November 17, 2020
 .Dt SAVECORE 8
 .Os
 .Sh NAME
@@ -45,7 +45,7 @@
 .Op Ar device ...
 .Nm
 .Op Fl -libxo
-.Op Fl fkvz
+.Op Fl fkuvz
 .Op Fl m Ar maxdumps
 .Op Ar directory Op Ar device ...
 .Sh DESCRIPTION
@@ -92,6 +92,8 @@ Once the number of stored dumps is equal to
 .Ar maxdumps
 the counter will restart from
 .Dv 0 .
+.It Fl u
+Uncompress the dump in case it was compressed by the kernel.
 .It Fl v
 Print out some additional debugging information.
 Specify twice for more information.

Modified: head/sbin/savecore/savecore.c
==
--- head/sbin/savecore/savecore.c   Thu Nov 19 00:03:15 2020
(r367823)
+++ head/sbin/savecore/savecore.c   Thu Nov 19 02:20:38 2020
(r367824)
@@ -86,6 +86,9 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
+#defineZ_SOLO
+#include 
+#include 
 
 #include 
 #include 
@@ -102,7 +105,7 @@ __FBSDID("$FreeBSD$");
 
 static cap_channel_t *capsyslog;
 static fileargs_t *capfa;
-static bool checkfor, compress, clear, force, keep;/* flags */
+static bool checkfor, compress, uncompress, clear, force, keep;/* 
flags */
 static int verbose;
 static int nfound, nsaved, nerr;   /* statistics */
 static int maxdumps;
@@ -441,22 +444,155 @@ compare_magic(const struct kerneldumpheader *kdh, cons
 #define BLOCKSIZE (1<<12)
 #define BLOCKMASK (~(BLOCKSIZE-1))
 
+static size_t
+sparsefwrite(const char *buf, size_t nr, FILE *fp)
+{
+   size_t nw, he, hs;
+
+   for (nw = 0; nw < nr; nw = he) {
+   /* find a contiguous block of zeroes */
+   for (hs = nw; hs < nr; hs += BLOCKSIZE) {
+   for (he = hs; he < nr && buf[he] == 0; ++he)
+   /* nothing */ ;
+   /* is the hole long enough to matter? */
+   if (he >= hs + BLOCKSIZE)
+   break;
+   }
+
+   /* back down to a block boundary */
+   he &= BLOCKMASK;
+
+   /*
+* 1) Don't go beyond the end of the buffer.
+* 2) If the end of the buffer is less than
+*BLOCKSIZE bytes away, we're at the end
+*of the file, so just grab what's left.
+*/
+   if (hs + BLOCKSIZE > nr)
+   hs = he = nr;
+
+   /*
+* At this point, we have a partial ordering:
+* nw <= hs <= he <= nr
+* If hs > nw, buf[nw..hs] contains non-zero
+* data. If he > hs, buf[hs..he] is all zeroes.
+*/
+   if (hs > nw)
+   if (fwrite(buf + nw, hs - nw, 1, fp) != 1)
+   break;
+   if (he > hs)
+   if (fseeko(fp, he - hs, SEEK_CUR) == -1)
+   break;
+   }
+
+   return (nw);
+}
+
+static char *zbuf;
+static size_t zbufsize;
+
+static size_t
+GunzipWrite(z_stream *z, char *in, size_t insize, FILE *fp)
+{
+   static bool firstblock = true;  /* XXX not re-entrable/usable 

Re: svn commit: r367813 - head/lib/libutil

2020-11-18 Thread Mateusz Guzik
On 11/19/20, Stefan Esser  wrote:
> Am 18.11.20 um 23:39 schrieb Jessica Clarke:
>> On 18 Nov 2020, at 22:32, Stefan Esser  wrote:
>>>
>>> Am 18.11.20 um 22:40 schrieb Mateusz Guzik:
> +{
> + static const int localbase_oid[2] = {CTL_USER, USER_LOCALBASE};
 There is no use for this to be static.
>>>
>>> Why not? This makes it part of the constant initialized data of
>>> the library, which is more efficient under run-time and memory
>>> space aspects than initializing them on the stack.
>>>
>>> What do I miss?
>>
>> What is more efficient is not so clear-cut, it depends on things like
>> the architecture, microarchitecture and ABI. Allocating a small buffer
>> on the stack is extremely cheap (the memory will almost certainly be in
>> the L1 cache), whereas globally-allocated storage is less likely to be
>> in the cache due to being spread out, and on some architecture/ABI
>> combinations will incur additional indirection through the GOT. Also, 8
>> bytes of additional stack use is lost in the noise.
>
> The memory latency of the extra access to the constant will be hidden in
> the noise. The data will probably be in a page that has already been
> accessed (so no TLB load penalty) and modern CPUs will be able to deal
> with the cache miss (if any, because the cache line may already be
> loaded depending on other data near-by).
>
> Yes, I do agree that a stack local variable could have been used and
> it could have been created with little effort by a modern multi-issue
> CPU. The code size would have been larger, though, by some 10 to 20
> bytes, I'd assume - but I doubt a single path through this code is
> measurable, much less observable in practice.
>
> We are talking about nano-seconds here (even if the cache line did
> not contain the constant data, it would probably be accessed just a
> few instructions further down and incur the same latency then).
>
> I have followed CPU development over more than 45 years and know many
> architectures and their specifics, but the time were I have programmed
> drivers in assembly and counted instruction cycles is long gone.
>
> This is nitpicking at a level that I do not want to continue. I'm not
> opposed to achieving efficiency where it is relevant. This function is
> providing useful functionality and I do not mind a wasted microsecond,
> it is not relevant here. (This was different if it was wasted within
> a tight loop - but it is not, it is typically called once if at all).
>
> Feel free to replace my code with your implementation, if you think it
> is not acceptable as written by me.
>
> I just wanted to provide an implementation of this functionality to
> be used in a number of programs where other developers had expressed
> interest in such a feature (and one of these programs has been worked
> on by me in recent weeks, so I'm now able to make use of it myself).
>

The entire localbase saga is getting way out of hand.

To address this e-mail and things you wrote in another reply, my
comlaints are very simple and are not getting less valid for not being
raised sooner. I just was not watching any of this until recent
fallout.

For the change at hand, there has to be a reason to use a static
symbol. Standard example is catching otherwise expensive to obtain
data. For that the static localbase pointer makes perfect sense, while
the static lookup array does not have any justification that I see.
Bringing cache, TLB or whatever microarchitectural details into the
discussion is beyond not warranted.

More importantly though the commit comes with a self-confessed memory
leak and is a show stopper.

That said, I'll see about patching this up.

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


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

2020-11-18 Thread Ian Lepore
On Wed, 2020-11-18 at 15:37 -0800, John Baldwin wrote:
> On 11/18/20 2:16 PM, Mateusz Guzik wrote:
> > On 11/17/20, John Baldwin  wrote:
> > > On 11/14/20 11:22 AM, Mateusz Guzik wrote:
> > 
> > Interested parties can check the consumer (also seen in the diff)
> > to
> > see this is for consistency. I don't think any comments are
> > warranted
> > in the header.
> 
> I did read the consumer, and there didn't seem tremendous value in
> the
> extra line there.
> 
> > > These changes would benefit from review.
> > > 
> > 
> > I don't think it's feasible to ask for review for everything lest
> > it
> > degardes to rubber stamping and I don't think this change warranted
> > it, regardless of the cosmetic issues which can always show up.
> 
> That is not consistent with the direction the project is moving.  If
> you
> check the commit logs of other high-volume committers such as markj@,
> kib@, or myself, you will find that a substantial number of those
> commits
> are reviewed (typically in phabricator) without preventing us from
> making useful progress.  Also, while the previous core did not
> mandate
> reviews, we moved closer to it when the Pre-Commit Review chapter was
> added to the Committer's Guide:
> 
> 
https://www.freebsd.org/doc/en_US.ISO8859-1/articles/committers-guide/pre-commit-review.html
> 
> In the related thread on developers@ we indicated that while weren't
> yet
> making pre-commit review mandatory, we collectively want to move in
> that
> direction.
> 

Yeah, the direction the project is moving is to drive away the few
remaining prolific contributors with policies that take all the
satisfaction out of working on freebsd.  There's a reason I've gone
from being in the top ten commiters list in 2019 to having around a
dozen commits in 2020.  (Harrison Bergeron lives, it seems, but the
world has so many more Diana Moon Glampers to counter with.)

-- Ian


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


svn commit: r367823 - head/lib/libc/string

2020-11-18 Thread Ed Maste
Author: emaste
Date: Thu Nov 19 00:03:15 2020
New Revision: 367823
URL: https://svnweb.freebsd.org/changeset/base/367823

Log:
  libc: fix undefined behavior from signed overflow in strstr and memmem
  
  unsigned char promotes to int, which can overflow when shifted left by
  24 bits or more. this has been reported multiple times but then
  forgotten. it's expected to be benign UB, but can trap when built with
  explicit overflow catching (ubsan or similar). fix it now.
  
  note that promotion to uint32_t is safe and portable even outside of
  the assumptions usually made in musl, since either uint32_t has rank
  at least unsigned int, so that no further default promotions happen,
  or int is wide enough that the shift can't overflow. this is a
  desirable property to have in case someone wants to reuse the code
  elsewhere.
  
  musl commit: 593caa456309714402ca4cb77c3770f4c24da9da
  
  Obtained from:musl

Modified:
  head/lib/libc/string/memmem.c
  head/lib/libc/string/strstr.c

Modified: head/lib/libc/string/memmem.c
==
--- head/lib/libc/string/memmem.c   Thu Nov 19 00:02:12 2020
(r367822)
+++ head/lib/libc/string/memmem.c   Thu Nov 19 00:03:15 2020
(r367823)
@@ -41,8 +41,8 @@ twobyte_memmem(const unsigned char *h, size_t k, const
 static char *
 threebyte_memmem(const unsigned char *h, size_t k, const unsigned char *n)
 {
-   uint32_t nw = n[0] << 24 | n[1] << 16 | n[2] << 8;
-   uint32_t hw = h[0] << 24 | h[1] << 16 | h[2] << 8;
+   uint32_t nw = (uint32_t)n[0] << 24 | n[1] << 16 | n[2] << 8;
+   uint32_t hw = (uint32_t)h[0] << 24 | h[1] << 16 | h[2] << 8;
for (h += 3, k -= 3; k; k--, hw = (hw | *h++) << 8)
if (hw == nw)
return (char *)h - 3;
@@ -52,8 +52,8 @@ threebyte_memmem(const unsigned char *h, size_t k, con
 static char *
 fourbyte_memmem(const unsigned char *h, size_t k, const unsigned char *n)
 {
-   uint32_t nw = n[0] << 24 | n[1] << 16 | n[2] << 8 | n[3];
-   uint32_t hw = h[0] << 24 | h[1] << 16 | h[2] << 8 | h[3];
+   uint32_t nw = (uint32_t)n[0] << 24 | n[1] << 16 | n[2] << 8 | n[3];
+   uint32_t hw = (uint32_t)h[0] << 24 | h[1] << 16 | h[2] << 8 | h[3];
for (h += 4, k -= 4; k; k--, hw = hw << 8 | *h++)
if (hw == nw)
return (char *)h - 4;

Modified: head/lib/libc/string/strstr.c
==
--- head/lib/libc/string/strstr.c   Thu Nov 19 00:02:12 2020
(r367822)
+++ head/lib/libc/string/strstr.c   Thu Nov 19 00:03:15 2020
(r367823)
@@ -40,8 +40,8 @@ twobyte_strstr(const unsigned char *h, const unsigned 
 static char *
 threebyte_strstr(const unsigned char *h, const unsigned char *n)
 {
-   uint32_t nw = n[0] << 24 | n[1] << 16 | n[2] << 8;
-   uint32_t hw = h[0] << 24 | h[1] << 16 | h[2] << 8;
+   uint32_t nw = (uint32_t)n[0] << 24 | n[1] << 16 | n[2] << 8;
+   uint32_t hw = (uint32_t)h[0] << 24 | h[1] << 16 | h[2] << 8;
for (h += 2; *h && hw != nw; hw = (hw | *++h) << 8)
;
return *h ? (char *)h - 2 : 0;
@@ -50,8 +50,8 @@ threebyte_strstr(const unsigned char *h, const unsigne
 static char *
 fourbyte_strstr(const unsigned char *h, const unsigned char *n)
 {
-   uint32_t nw = n[0] << 24 | n[1] << 16 | n[2] << 8 | n[3];
-   uint32_t hw = h[0] << 24 | h[1] << 16 | h[2] << 8 | h[3];
+   uint32_t nw = (uint32_t)n[0] << 24 | n[1] << 16 | n[2] << 8 | n[3];
+   uint32_t hw = (uint32_t)h[0] << 24 | h[1] << 16 | h[2] << 8 | h[3];
for (h += 3; *h && hw != nw; hw = hw << 8 | *++h)
;
return *h ? (char *)h - 3 : 0;
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r367822 - head/lib/libc/string

2020-11-18 Thread Ed Maste
Author: emaste
Date: Thu Nov 19 00:02:12 2020
New Revision: 367822
URL: https://svnweb.freebsd.org/changeset/base/367822

Log:
  libc: optimize memmem two-way bad character shift
  
  first, the condition (mem && k < p) is redundant, because mem being
  nonzero implies the needle is periodic with period exactly p, in which
  case any byte that appears in the needle must appear in the last p
  bytes of the needle, bounding the shift (k) by p.
  
  second, the whole point of replacing the shift k by mem (=l-p) is to
  prevent shifting by less than mem when discarding the memory on shift,
  in which case linear time could not be guaranteed. but as written, the
  check also replaced shifts greater than mem by mem, reducing the
  benefit of the shift. there is no possible benefit to this reduction of
  the shift; since mem is being cleared, the full shift is valid and
  more optimal. so only replace the shift by mem when it would be less
  than mem.
  
  musl commits:
  8f5a820d147da36bcdbddd201b35d293699dacd8
  122d67f846cb0be2c9e1c3880db9eb9545bbe38c
  
  Obtained from:musl
  MFC after:2 weeks

Modified:
  head/lib/libc/string/memmem.c

Modified: head/lib/libc/string/memmem.c
==
--- head/lib/libc/string/memmem.c   Wed Nov 18 22:01:34 2020
(r367821)
+++ head/lib/libc/string/memmem.c   Thu Nov 19 00:02:12 2020
(r367822)
@@ -153,8 +153,8 @@ twoway_memmem(const unsigned char *h, const unsigned c
if (BITOP(byteset, h[l - 1], &)) {
k = l - shift[h[l - 1]];
if (k) {
-   if (mem0 && mem && k < p)
-   k = l - p;
+   if (k < mem)
+   k = mem;
h += k;
mem = 0;
continue;
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


Trouver des nouveaux clients

2020-11-18 Thread l...@aproximeo.fr
Bonjour,

Pour votre information, vous pouvez gratuitement trouver plein de nouveaux
clients en vous inscrivant sur la 1ère plateforme de proximité en
cliquant ici

.

Plus d'infos en cliquant ici

.

Excellente journée !

Luc HIDOUX

Responsable Commercial 



--

 This message was sent to svn-src-all@freebsd.org by l...@aproximeo.fr

 To forward this message, please do not use the forward button of your
email application, because this message was made specifically for you only.
Instead use the forward page

in our newsletter system.

 To change your details and to choose which lists to be subscribed to,
visit your personal preferences page


 Or you can opt-out completely

from all future mailings.

 


-- powered by phpList, www.phplist.com --


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


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

2020-11-18 Thread John Baldwin
On 11/18/20 2:16 PM, Mateusz Guzik wrote:
> On 11/17/20, John Baldwin  wrote:
>> On 11/14/20 11:22 AM, Mateusz Guzik wrote:
> Interested parties can check the consumer (also seen in the diff) to
> see this is for consistency. I don't think any comments are warranted
> in the header.

I did read the consumer, and there didn't seem tremendous value in the
extra line there.

>> These changes would benefit from review.
>>
> 
> I don't think it's feasible to ask for review for everything lest it
> degardes to rubber stamping and I don't think this change warranted
> it, regardless of the cosmetic issues which can always show up.

That is not consistent with the direction the project is moving.  If you
check the commit logs of other high-volume committers such as markj@,
kib@, or myself, you will find that a substantial number of those commits
are reviewed (typically in phabricator) without preventing us from
making useful progress.  Also, while the previous core did not mandate
reviews, we moved closer to it when the Pre-Commit Review chapter was
added to the Committer's Guide:

https://www.freebsd.org/doc/en_US.ISO8859-1/articles/committers-guide/pre-commit-review.html

In the related thread on developers@ we indicated that while weren't yet
making pre-commit review mandatory, we collectively want to move in that
direction.

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


Re: svn commit: r367813 - head/lib/libutil

2020-11-18 Thread Stefan Esser

Am 18.11.20 um 23:39 schrieb Jessica Clarke:

On 18 Nov 2020, at 22:32, Stefan Esser  wrote:


Am 18.11.20 um 22:40 schrieb Mateusz Guzik:

+{
+   static const int localbase_oid[2] = {CTL_USER, USER_LOCALBASE};

There is no use for this to be static.


Why not? This makes it part of the constant initialized data of
the library, which is more efficient under run-time and memory
space aspects than initializing them on the stack.

What do I miss?


What is more efficient is not so clear-cut, it depends on things like
the architecture, microarchitecture and ABI. Allocating a small buffer
on the stack is extremely cheap (the memory will almost certainly be in
the L1 cache), whereas globally-allocated storage is less likely to be
in the cache due to being spread out, and on some architecture/ABI
combinations will incur additional indirection through the GOT. Also, 8
bytes of additional stack use is lost in the noise.


The memory latency of the extra access to the constant will be hidden in 
the noise. The data will probably be in a page that has already been

accessed (so no TLB load penalty) and modern CPUs will be able to deal
with the cache miss (if any, because the cache line may already be
loaded depending on other data near-by).

Yes, I do agree that a stack local variable could have been used and
it could have been created with little effort by a modern multi-issue
CPU. The code size would have been larger, though, by some 10 to 20
bytes, I'd assume - but I doubt a single path through this code is
measurable, much less observable in practice.

We are talking about nano-seconds here (even if the cache line did
not contain the constant data, it would probably be accessed just a
few instructions further down and incur the same latency then).

I have followed CPU development over more than 45 years and know many
architectures and their specifics, but the time were I have programmed
drivers in assembly and counted instruction cycles is long gone.

This is nitpicking at a level that I do not want to continue. I'm not
opposed to achieving efficiency where it is relevant. This function is
providing useful functionality and I do not mind a wasted microsecond,
it is not relevant here. (This was different if it was wasted within
a tight loop - but it is not, it is typically called once if at all).

Feel free to replace my code with your implementation, if you think it
is not acceptable as written by me.

I just wanted to provide an implementation of this functionality to
be used in a number of programs where other developers had expressed
interest in such a feature (and one of these programs has been worked
on by me in recent weeks, so I'm now able to make use of it myself).

Regards, STefan



OpenPGP_signature
Description: OpenPGP digital signature


Re: svn commit: r367813 - head/lib/libutil

2020-11-18 Thread Brooks Davis
On Thu, Nov 19, 2020 at 12:05:51AM +0100, Stefan Esser wrote:
> Am 18.11.20 um 23:14 schrieb Jessica Clarke:
> > On 18 Nov 2020, at 21:52, Stefan Esser  wrote:
> >> Am 18.11.20 um 22:15 schrieb Jessica Clarke:
> >>> On 18 Nov 2020, at 19:44, Stefan E??er  wrote:
>  +/*
>  + * Check for some other thread already having
>  + * set localbase - this should use atomic ops.
>  + * The amount of memory allocated above may leak,
>  + * if a parallel update in another thread is not
>  + * detected and the non-NULL pointer is overwritten.
>  + */
> >>> Why was this committed with a known racy/leaky implementation?
> >>
> >> Because the alternatives that I offered for discussion were
> >> less acceptable.
> > 
> > That has no bearing over whether this one is.
> 
> Three alternatives have been discussed:
> 
> 1) static buffer of size MAXPATHLEN
> 2) dynamically allocated buffer (as committed)
> 3) dynamically allocated buffer filled by a constructor
> 
> 1) has been rejected, since it adds 1 KB of bss to each program
> that is linked with libutil, whether it uses getlocalbase() or
> not.
> 
> 3) has been rejected since it causes 1 getenv() and 2 sysctl()
> calls when the program linked with libutil starts, independently
> of whether getlocalbase() is used or not.
> 
> 2) has been selected, since it is only called when needed and it
> does not pre-allocate a large buffer.
> 
> Which other alternative do you want to suggest?
> 
> Did you have a look at the review announced on the -current list
> and mentioned in the commit?
> 
> >>> What happens if I set the value with a sysctl and call this?
> >>
> >> You'll get the value set with sysctl, unless overridden by the
> >> environment variable. There is a window of a few nano-seconds
> >> where a thread executing in parallel on another core might be
> >> able to set the localbase variable (between the test for NULL
> >> in this function and the assignment to it). The value that will
> >> be returned by either thread will be identical, so there is no
> >> risk of corruption of the result.
> > 
> > But if I call getlocalbase, then set it via sysctl, then call
> > getlocalbase again, I see the old value. If, however, I omit the first
> > getlocalbase, I see the new value. This differs from how getenv/setenv
> > of the value work, where you always see the up-to-date value. Maybe you
> > think that's a feature, but it's something to watch out for and
> > explicitly call out in the documentation.
> 
> Actual programs call getlocalbase() exactly once and create the
> required pathes from the value returned.
> 
> It is possible to copy the value from the environment to a buffer,
> but at added complexity and introducing another race condition.
> 
> The program itself might have modified its environment and then
> use an inconsistent value when it calls getlocalbase() again
> thereafter. But why would you want to do this - it seems to be
> a complicated way lof foot-shooting to me.
> 
> I'm not a native speaker of English and not best qualified to
> clearly express this in the man-page. Feel free to commit any
> clarification or suggest an addition for me to commit.
> 
> > You also misunderstand all the subtleties of multithreading here. There
> > are no acquire/release pairs so it is entirely legal for Thread 2 to
> > read Thread 1's initialised value for localbase before the contents of
> > it are visible (i.e. the pointer is initialised but the data is
> > garbage).
> 
> Yes, and thread 2's value will be identical to the one from
> thread 1, just in a different heap location, unless there is a
> write to the sysctl variable in the kernel at just the same
> time. And you cannot protect against this race and you'll get
> either the old or new value.
> 
> > The `(volatile const char*)localbase` cast is also a complete waste of
> > time. You probably meant to write `(const char * volatile)localbase`
> > but even then that does nothing useful as the cast is too late. What
> > you really were trying to write was
> > `*(const char * volatile *)`, but you need proper atomics
> > anyway for this to be safe.
> 
> I was not sure about the correct volatile declaration, I've got
> to admit. It was in the review and I did not get any comments
> regarding that specific modifier. The goal was to enforce the
> access to the localbase pointer in memory after returning from
> the sysctl to shorten the window.
> 
> Perhaps I should just have completely ignore any multi-threading
> issues and accepted that an overlapping execution of this function
> would allocate multiple sysctl destination buffers but loose all
> references but one in the assignment to localbase.
> 
> It will not happen in practice, it just does not make sense to
> call this function more than once in a program.
> 
> >> This unlikely case may actually leak a heap allocated string
> >> of 

Re: svn commit: r367813 - head/lib/libutil

2020-11-18 Thread Stefan Esser

Am 18.11.20 um 23:14 schrieb Jessica Clarke:

On 18 Nov 2020, at 21:52, Stefan Esser  wrote:

Am 18.11.20 um 22:15 schrieb Jessica Clarke:

On 18 Nov 2020, at 19:44, Stefan Eßer  wrote:

+   /*
+* Check for some other thread already having
+* set localbase - this should use atomic ops.
+* The amount of memory allocated above may leak,
+* if a parallel update in another thread is not
+* detected and the non-NULL pointer is overwritten.
+*/

Why was this committed with a known racy/leaky implementation?


Because the alternatives that I offered for discussion were
less acceptable.


That has no bearing over whether this one is.


Three alternatives have been discussed:

1) static buffer of size MAXPATHLEN
2) dynamically allocated buffer (as committed)
3) dynamically allocated buffer filled by a constructor

1) has been rejected, since it adds 1 KB of bss to each program
that is linked with libutil, whether it uses getlocalbase() or
not.

3) has been rejected since it causes 1 getenv() and 2 sysctl()
calls when the program linked with libutil starts, independently
of whether getlocalbase() is used or not.

2) has been selected, since it is only called when needed and it
does not pre-allocate a large buffer.

Which other alternative do you want to suggest?

Did you have a look at the review announced on the -current list
and mentioned in the commit?


What happens if I set the value with a sysctl and call this?


You'll get the value set with sysctl, unless overridden by the
environment variable. There is a window of a few nano-seconds
where a thread executing in parallel on another core might be
able to set the localbase variable (between the test for NULL
in this function and the assignment to it). The value that will
be returned by either thread will be identical, so there is no
risk of corruption of the result.


But if I call getlocalbase, then set it via sysctl, then call
getlocalbase again, I see the old value. If, however, I omit the first
getlocalbase, I see the new value. This differs from how getenv/setenv
of the value work, where you always see the up-to-date value. Maybe you
think that's a feature, but it's something to watch out for and
explicitly call out in the documentation.


Actual programs call getlocalbase() exactly once and create the
required pathes from the value returned.

It is possible to copy the value from the environment to a buffer,
but at added complexity and introducing another race condition.

The program itself might have modified its environment and then
use an inconsistent value when it calls getlocalbase() again
thereafter. But why would you want to do this - it seems to be
a complicated way lof foot-shooting to me.

I'm not a native speaker of English and not best qualified to
clearly express this in the man-page. Feel free to commit any
clarification or suggest an addition for me to commit.


You also misunderstand all the subtleties of multithreading here. There
are no acquire/release pairs so it is entirely legal for Thread 2 to
read Thread 1's initialised value for localbase before the contents of
it are visible (i.e. the pointer is initialised but the data is
garbage).


Yes, and thread 2's value will be identical to the one from
thread 1, just in a different heap location, unless there is a
write to the sysctl variable in the kernel at just the same
time. And you cannot protect against this race and you'll get
either the old or new value.


The `(volatile const char*)localbase` cast is also a complete waste of
time. You probably meant to write `(const char * volatile)localbase`
but even then that does nothing useful as the cast is too late. What
you really were trying to write was
`*(const char * volatile *)`, but you need proper atomics
anyway for this to be safe.


I was not sure about the correct volatile declaration, I've got
to admit. It was in the review and I did not get any comments
regarding that specific modifier. The goal was to enforce the
access to the localbase pointer in memory after returning from
the sysctl to shorten the window.

Perhaps I should just have completely ignore any multi-threading
issues and accepted that an overlapping execution of this function
would allocate multiple sysctl destination buffers but loose all
references but one in the assignment to localbase.

It will not happen in practice, it just does not make sense to
call this function more than once in a program.


This unlikely case may actually leak a heap allocated string
of typically tens of bytes (but with negligible probability).

But this really is a non-issue, since there should never be a
reason to invoke this function in a multi-threaded context.


Why not? There could easily be code out there calling getenv in a
multi-threaded context so this is inadequate as a replacement. Yes it's
inefficient but it's perfectly legal and imaginable.


Yes, calling getenv() 

Re: svn commit: r367813 - head/lib/libutil

2020-11-18 Thread Jessica Clarke
On 18 Nov 2020, at 22:32, Stefan Esser  wrote:
> 
> Am 18.11.20 um 22:40 schrieb Mateusz Guzik:
>>> +{
>>> +   static const int localbase_oid[2] = {CTL_USER, USER_LOCALBASE};
>> There is no use for this to be static.
> 
> Why not? This makes it part of the constant initialized data of
> the library, which is more efficient under run-time and memory
> space aspects than initializing them on the stack.
> 
> What do I miss?

What is more efficient is not so clear-cut, it depends on things like
the architecture, microarchitecture and ABI. Allocating a small buffer
on the stack is extremely cheap (the memory will almost certainly be in
the L1 cache), whereas globally-allocated storage is less likely to be
in the cache due to being spread out, and on some architecture/ABI
combinations will incur additional indirection through the GOT. Also, 8
bytes of additional stack use is lost in the noise.

Jess

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


Re: svn commit: r367813 - head/lib/libutil

2020-11-18 Thread Stefan Esser

Am 18.11.20 um 22:40 schrieb Mateusz Guzik:

+{
+   static const int localbase_oid[2] = {CTL_USER, USER_LOCALBASE};


There is no use for this to be static.


Why not? This makes it part of the constant initialized data of
the library, which is more efficient under run-time and memory
space aspects than initializing them on the stack.

What do I miss?


+   char *tmppath;
+   size_t tmplen;
+   static const char *localbase = NULL;
+
+   if (issetugid() == 0) {
+   tmppath = getenv("LOCALBASE");
+   if (tmppath != NULL && tmppath[0] != '\0')
+   return (tmppath);
+   }
+   if (sysctl(localbase_oid, 2, NULL, , NULL, 0) == 0 &&
+   (tmppath = malloc(tmplen)) != NULL &&
+   sysctl(localbase_oid, 2, tmppath, , NULL, 0) == 0) {


Apart from the concurrency issue mentioned in the comment this is just
very wasteful. Instead you can have a small local buffer, say 128
bytes and pass that to be populated. The sysctl handler than can
populate that and return an error if the size is too small. I don't
know if sysclt api allows it to return the set size as it is. Worst
case you can just retry with a bigger malloced buffer.


You obviously did not follow the development of this code in the
review. It used to have such a buffer, but this was rejected, since
only very few of the programs that link against this library are
going to call this function.

Allocating a small buffer and replacing it with a larger one if it
was too small adds needless complexity to this program and needs more
code. It is not sensible (IMHO) to reduce the number of system calls
by 1 for the small number of programs that use this feature, and which
perform at least tens of other system calls at start-up.


Once you get the result you can malloc a buffer and
atomic_cmpset_rel_ptr localbase to point to it. If this fails, another
thread got the result, you free your buffer and return (localbase).


Yes, I wrote that I could use atomics, feel free to modify the program
accordingly. It will not make a difference in practice, since there is
no good reason to call this function from within a multi-threaded
context at all, and none of the candidates to be modified to use this
function in base do.


Also the kernel counter part completely unnecessarily comes with a
static 1KB buffer to hold what typically is going to be nothing. This
should also be allocated as needed. Worst case you can add a trivial
lock around it.


The kernel buffer does already exist and you did not complain about
that buffer, when it has been committed. A size of PATHNAMEMAX is
used to allow for any valid path name to be set from the loader.
If there is consensus that the value should be limited to e.g. 64 or
128 bytes, this is trivially changed in kern_mib.c.

I'd be more worried, if this buffer existed not as a single instance
in the kernel but e.g. per process, but this is not the case.

Feel free to make this a dynamically allocated variable, but make
sure that you do not increase the code size by as much as you reduce
the static storage required.

I do not need the dynamic assignment to localbase at all, and I have
suggested to introduce a kernel build option (e.g. WITH_LOCALBASE_VAR)
to control compilation of kernel and library with this function or to
return just the constant string _PATH_LOCALBASE or "/usr/local".

But there were very strong requests for this dynamically set localbase
and I have provided an implementation that is functional and easy to
use.

Regards, STefan



OpenPGP_signature
Description: OpenPGP digital signature


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

2020-11-18 Thread Mateusz Guzik
On 11/17/20, John Baldwin  wrote:
> On 11/14/20 11:22 AM, Mateusz Guzik wrote:
>> Author: mjg
>> Date: Sat Nov 14 19:22:02 2020
>> New Revision: 367695
>> URL: https://svnweb.freebsd.org/changeset/base/367695
>>
>> Log:
>>   thread: batch credential freeing
>>
>> Modified:
>>   head/sys/kern/kern_prot.c
>>   head/sys/kern/kern_thread.c
>>   head/sys/sys/ucred.h
>>
>> Modified: head/sys/kern/kern_prot.c
>> ==
>> --- head/sys/kern/kern_prot.cSat Nov 14 19:21:46 2020
>> (r367694)
>> +++ head/sys/kern/kern_prot.cSat Nov 14 19:22:02 2020
>> (r367695)
>> @@ -2007,6 +2071,17 @@ crfree(struct ucred *cr)
>>  mtx_unlock(>cr_mtx);
>>  return;
>>  }
>> +crfree_final(cr);
>> +}
>> +
>> +static void
>> +crfree_final(struct ucred *cr)
>> +{
>> +
>> +KASSERT(cr->cr_users == 0, ("%s: users %d not == 0 on cred %p",
>> +__func__, cr->cr_users, cr));
>> +KASSERT(cr->cr_ref == 0, ("%s: ref %d not == 0 on cred %p",
>> +__func__, cr->cr_ref, cr));
>>  /*
>
> Please add blank lines before comments.  It's in style(9) and I've noticed
> a pattern in your changes of not including them.
>

Ok.

>> Modified: head/sys/sys/ucred.h
>> ==
>> --- head/sys/sys/ucred.h Sat Nov 14 19:21:46 2020(r367694)
>> +++ head/sys/sys/ucred.h Sat Nov 14 19:22:02 2020(r367695)
>> @@ -114,6 +114,28 @@ struct xucred {
>>  struct proc;
>>  struct thread;
>>
>> +struct credbatch {
>> +struct ucred *cred;
>> +int users;
>> +int ref;
>> +};
>> +
>> +static inline void
>> +credbatch_prep(struct credbatch *crb)
>> +{
>> +crb->cred = NULL;
>> +crb->users = 0;
>> +crb->ref = 0;
>> +}
>> +voidcredbatch_add(struct credbatch *crb, struct thread *td);
>> +static inline void
>> +credbatch_process(struct credbatch *crb)
>> +{
>> +
>> +}
>> +voidcredbatch_add(struct credbatch *crb, struct thread *td);
>> +voidcredbatch_final(struct credbatch *crb);
>> +
>
> Do not mix prototypes and inlines, especially without spaces
> around the prototype in the middle.  Also, the kernel uses __inline
> rather than inline (for better or for worse).

The kernel has a huge mix of inline and __inline, to the point where
my impression was that __inline is obsolete.

>  Better would be:
>
> static __inline void
> credbatch_prep()
> {
>   ...
> }
>
> static __inline void
> credbatch_process()
> {
>   ...
> }
>
> void credbatch_add();
> void credbatch_final();
>

I disagree. The current header order follows how these routines are used.

> It seems you just have a duplicate credbatch_add() in fact.
>

Indeed, I'll whack it.

> Also, why have an empty inline function?
>

Interested parties can check the consumer (also seen in the diff) to
see this is for consistency. I don't think any comments are warranted
in the header.

> These changes would benefit from review.
>

I don't think it's feasible to ask for review for everything lest it
degardes to rubber stamping and I don't think this change warranted
it, regardless of the cosmetic issues which can always show up.

> --
> John Baldwin
>


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


Re: svn commit: r367813 - head/lib/libutil

2020-11-18 Thread Jessica Clarke
On 18 Nov 2020, at 21:52, Stefan Esser  wrote:
> Am 18.11.20 um 22:15 schrieb Jessica Clarke:
>> On 18 Nov 2020, at 19:44, Stefan Eßer  wrote:
>>> +   /*
>>> +* Check for some other thread already having
>>> +* set localbase - this should use atomic ops.
>>> +* The amount of memory allocated above may leak,
>>> +* if a parallel update in another thread is not
>>> +* detected and the non-NULL pointer is overwritten.
>>> +*/
>> Why was this committed with a known racy/leaky implementation?
> 
> Because the alternatives that I offered for discussion were
> less acceptable.

That has no bearing over whether this one is.

>> What happens if I set the value with a sysctl and call this?
> 
> You'll get the value set with sysctl, unless overridden by the
> environment variable. There is a window of a few nano-seconds
> where a thread executing in parallel on another core might be
> able to set the localbase variable (between the test for NULL
> in this function and the assignment to it). The value that will
> be returned by either thread will be identical, so there is no
> risk of corruption of the result.

But if I call getlocalbase, then set it via sysctl, then call
getlocalbase again, I see the old value. If, however, I omit the first
getlocalbase, I see the new value. This differs from how getenv/setenv
of the value work, where you always see the up-to-date value. Maybe you
think that's a feature, but it's something to watch out for and
explicitly call out in the documentation.

You also misunderstand all the subtleties of multithreading here. There
are no acquire/release pairs so it is entirely legal for Thread 2 to
read Thread 1's initialised value for localbase before the contents of
it are visible (i.e. the pointer is initialised but the data is
garbage).

The `(volatile const char*)localbase` cast is also a complete waste of
time. You probably meant to write `(const char * volatile)localbase`
but even then that does nothing useful as the cast is too late. What
you really were trying to write was
`*(const char * volatile *)`, but you need proper atomics
anyway for this to be safe.

> This unlikely case may actually leak a heap allocated string
> of typically tens of bytes (but with negligible probability).
> 
> But this really is a non-issue, since there should never be a
> reason to invoke this function in a multi-threaded context.

Why not? There could easily be code out there calling getenv in a
multi-threaded context so this is inadequate as a replacement. Yes it's
inefficient but it's perfectly legal and imaginable.

Also if malloc returns NULL I would quite like that to be an error for
the function and not silently fall back on _PATH_LOCALBASE.

> The result should be constant for the duration of execution
> of the process (expect severe inconsistencies if that was not
> the case) and all programs in base that are candidates for the
> use of this function are non-threaded (and if they were multi-
> threaded, then I'd expect this call to occur during start-up
> of the program before any further threads are created).
> 
> So, this is a non-issue and the comment tries to explain it.
> Did I fail to make this clear in the comment? Maybe I should
> have written "could use atomic ops" instead?
> 
> Use of atomics or locks could prevent the race-condition. But
> since I do not expect this function to be called from within
> threads (it just doesn't make sense), the tiny time window of
> a few nano-seconds which might lead to a double assignment to
> the target variable (with one pointer value being lost), and
> the worst case loss of 1KB of heap space in that case (more
> likely 10 to 20 bytes rounded up to a 16 or 32 byte chunk), I
> do not consider the complexities of either a lock or atomic ops
> to be justified.
> 
> Regards, STefan
> 

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


Re: svn commit: r367813 - head/lib/libutil

2020-11-18 Thread Stefan Esser



Am 18.11.20 um 22:27 schrieb Jessica Clarke:

On 18 Nov 2020, at 21:15, Jessica Clarke  wrote:


On 18 Nov 2020, at 19:44, Stefan Eßer  wrote:

+   /*
+* Check for some other thread already having
+* set localbase - this should use atomic ops.
+* The amount of memory allocated above may leak,
+* if a parallel update in another thread is not
+* detected and the non-NULL pointer is overwritten.
+*/


Why was this committed with a known racy/leaky implementation?

What happens if I set the value with a sysctl and call this?


Notably, you go to all this trouble to have a localbase variable that
gets set, but you never actually use it properly as a cache since you
do the full lookup and only then realise that you already had a
(possibly stale) value cached.


Do you want to suggest a better implementation?

As explained in another mail, this case should never happen, since
the function is not called in a multi-threaded context and if it
was, then the test before the assignment reduces the time window
of vulnerability to a few nanoseconds, and if a collision did
occur the amount of heap space lost is negligible.

Or do you think, that the assignment should directly go to the
localbase variable, not to tmppath? That would significantly
enlarge the window of vulnerability, and the code that protects
against this case (though not perfectly) seems worth it.

To give some context (slightly simplified):

if (tmppath = malloc(tmplen)) != NULL &&
sysctl(localbase_oid, 2, tmppath, , NULL, 0) == 0) {
if (tmppath[0] != '\0' &&
(volatile const char*)localbase == NULL)
localbase = tmppath;
else
free((void*)tmppath);
return (localbase);

If localbase == NULL then localbase is set to tmppath, but another core
could execute exactly the same instructions in the same few nanoseconds.

The assignment could also have been marked volatile to force the write
to memory, but since this is a library function called from another
compile unit and the value is returned into that other context, I think
the write will happen immediately, anyway.

I know about architectures with non-coherent caches and other issues
that could increase the time window, but as said before, I do not expect
this function to be called in a multi-threaded context, but thought the
protection against a collision in the much larger time window covering
the malloc and sysctl system call might still be worth the 1 extra line
of code required to go through a stack allocated tmppath instead of
directly assigning to localbase.

Regards, STefan



OpenPGP_signature
Description: OpenPGP digital signature


svn commit: r367821 - head/lib/libc/string

2020-11-18 Thread Ed Maste
Author: emaste
Date: Wed Nov 18 22:01:34 2020
New Revision: 367821
URL: https://svnweb.freebsd.org/changeset/base/367821

Log:
  clang-format libc string functions imported from musl
  
  We have adopted these and don't consider them 'contrib' code, so bring
  them closer to style(9).  This is a followon to r315467 and r351700.
  
  MFC after:1 week
  Sponsored by: The FreeBSD Foundation

Modified:
  head/lib/libc/string/memchr.c
  head/lib/libc/string/memmem.c
  head/lib/libc/string/strstr.c

Modified: head/lib/libc/string/memchr.c
==
--- head/lib/libc/string/memchr.c   Wed Nov 18 21:26:14 2020
(r367820)
+++ head/lib/libc/string/memchr.c   Wed Nov 18 22:01:34 2020
(r367821)
@@ -25,30 +25,35 @@
 #include 
 __FBSDID("$FreeBSD$");
 
-#include 
-#include 
 #include 
+#include 
+#include 
 
 #define SS (sizeof(size_t))
-#define ALIGN (sizeof(size_t)-1)
-#define ONES ((size_t)-1/UCHAR_MAX)
-#define HIGHS (ONES * (UCHAR_MAX/2+1))
-#define HASZERO(x) (((x)-ONES) & ~(x) & HIGHS)
+#define ALIGN (sizeof(size_t) - 1)
+#define ONES ((size_t)-1 / UCHAR_MAX)
+#define HIGHS (ONES * (UCHAR_MAX / 2 + 1))
+#define HASZERO(x) (((x)-ONES) & ~(x))
 
-void *memchr(const void *src, int c, size_t n)
+void *
+memchr(const void *src, int c, size_t n)
 {
const unsigned char *s = src;
c = (unsigned char)c;
 #ifdef __GNUC__
-   for (; ((uintptr_t)s & ALIGN) && n && *s != c; s++, n--);
+   for (; ((uintptr_t)s & ALIGN) && n && *s != c; s++, n--)
+   ;
if (n && *s != c) {
typedef size_t __attribute__((__may_alias__)) word;
const word *w;
size_t k = ONES * c;
-   for (w = (const void *)s; n>=SS && !HASZERO(*w^k); w++, n-=SS);
+   for (w = (const void *)s; n >= SS && !HASZERO(*w ^ k);
+w++, n -= SS)
+   ;
s = (const void *)w;
}
 #endif
-   for (; n && *s != c; s++, n--);
+   for (; n && *s != c; s++, n--)
+   ;
return n ? (void *)s : 0;
 }

Modified: head/lib/libc/string/memmem.c
==
--- head/lib/libc/string/memmem.c   Wed Nov 18 21:26:14 2020
(r367820)
+++ head/lib/libc/string/memmem.c   Wed Nov 18 22:01:34 2020
(r367821)
@@ -25,40 +25,47 @@
 #include 
 __FBSDID("$FreeBSD$");
 
-#include 
 #include 
+#include 
 
-static char *twobyte_memmem(const unsigned char *h, size_t k, const unsigned 
char *n)
+static char *
+twobyte_memmem(const unsigned char *h, size_t k, const unsigned char *n)
 {
-   uint16_t nw = n[0]<<8 | n[1], hw = h[0]<<8 | h[1];
-   for (h+=2, k-=2; k; k--, hw = hw<<8 | *h++)
-   if (hw == nw) return (char *)h-2;
-   return hw == nw ? (char *)h-2 : 0;
+   uint16_t nw = n[0] << 8 | n[1], hw = h[0] << 8 | h[1];
+   for (h += 2, k -= 2; k; k--, hw = hw << 8 | *h++)
+   if (hw == nw)
+   return (char *)h - 2;
+   return hw == nw ? (char *)h - 2 : 0;
 }
 
-static char *threebyte_memmem(const unsigned char *h, size_t k, const unsigned 
char *n)
+static char *
+threebyte_memmem(const unsigned char *h, size_t k, const unsigned char *n)
 {
-   uint32_t nw = n[0]<<24 | n[1]<<16 | n[2]<<8;
-   uint32_t hw = h[0]<<24 | h[1]<<16 | h[2]<<8;
-   for (h+=3, k-=3; k; k--, hw = (hw|*h++)<<8)
-   if (hw == nw) return (char *)h-3;
-   return hw == nw ? (char *)h-3 : 0;
+   uint32_t nw = n[0] << 24 | n[1] << 16 | n[2] << 8;
+   uint32_t hw = h[0] << 24 | h[1] << 16 | h[2] << 8;
+   for (h += 3, k -= 3; k; k--, hw = (hw | *h++) << 8)
+   if (hw == nw)
+   return (char *)h - 3;
+   return hw == nw ? (char *)h - 3 : 0;
 }
 
-static char *fourbyte_memmem(const unsigned char *h, size_t k, const unsigned 
char *n)
+static char *
+fourbyte_memmem(const unsigned char *h, size_t k, const unsigned char *n)
 {
-   uint32_t nw = n[0]<<24 | n[1]<<16 | n[2]<<8 | n[3];
-   uint32_t hw = h[0]<<24 | h[1]<<16 | h[2]<<8 | h[3];
-   for (h+=4, k-=4; k; k--, hw = hw<<8 | *h++)
-   if (hw == nw) return (char *)h-4;
-   return hw == nw ? (char *)h-4 : 0;
+   uint32_t nw = n[0] << 24 | n[1] << 16 | n[2] << 8 | n[3];
+   uint32_t hw = h[0] << 24 | h[1] << 16 | h[2] << 8 | h[3];
+   for (h += 4, k -= 4; k; k--, hw = hw << 8 | *h++)
+   if (hw == nw)
+   return (char *)h - 4;
+   return hw == nw ? (char *)h - 4 : 0;
 }
 
-#define MAX(a,b) ((a)>(b)?(a):(b))
-#define MIN(a,b) ((a)<(b)?(a):(b))
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
 
-#define BITOP(a,b,op) \
- ((a)[(size_t)(b)/(8*sizeof *(a))] op (size_t)1<<((size_t)(b)%(8*sizeof *(a
+#define BITOP(a, b, op) \
+   ((a)[(size_t)(b) / (8 * sizeof 

Re: svn commit: r367813 - head/lib/libutil

2020-11-18 Thread Stefan Esser



Am 18.11.20 um 22:15 schrieb Jessica Clarke:

On 18 Nov 2020, at 19:44, Stefan Eßer  wrote:

+   /*
+* Check for some other thread already having
+* set localbase - this should use atomic ops.
+* The amount of memory allocated above may leak,
+* if a parallel update in another thread is not
+* detected and the non-NULL pointer is overwritten.
+*/


Why was this committed with a known racy/leaky implementation?


Because the alternatives that I offered for discussion were
less acceptable.


What happens if I set the value with a sysctl and call this?


You'll get the value set with sysctl, unless overridden by the
environment variable. There is a window of a few nano-seconds
where a thread executing in parallel on another core might be
able to set the localbase variable (between the test for NULL
in this function and the assignment to it). The value that will
be returned by either thread will be identical, so there is no
risk of corruption of the result.

This unlikely case may actually leak a heap allocated string
of typically tens of bytes (but with negligible probability).

But this really is a non-issue, since there should never be a
reason to invoke this function in a multi-threaded context.

The result should be constant for the duration of execution
of the process (expect severe inconsistencies if that was not
the case) and all programs in base that are candidates for the
use of this function are non-threaded (and if they were multi-
threaded, then I'd expect this call to occur during start-up
of the program before any further threads are created).

So, this is a non-issue and the comment tries to explain it.
Did I fail to make this clear in the comment? Maybe I should
have written "could use atomic ops" instead?

Use of atomics or locks could prevent the race-condition. But
since I do not expect this function to be called from within
threads (it just doesn't make sense), the tiny time window of
a few nano-seconds which might lead to a double assignment to
the target variable (with one pointer value being lost), and
the worst case loss of 1KB of heap space in that case (more
likely 10 to 20 bytes rounded up to a 16 or 32 byte chunk), I
do not consider the complexities of either a lock or atomic ops
to be justified.

Regards, STefan



OpenPGP_signature
Description: OpenPGP digital signature


Re: svn commit: r367813 - head/lib/libutil

2020-11-18 Thread Jessica Clarke
On 18 Nov 2020, at 21:40, Mateusz Guzik  wrote:
> 
> On 11/18/20, Stefan Eßer  wrote:
>> Author: se
>> Date: Wed Nov 18 19:44:30 2020
>> New Revision: 367813
>> URL: https://svnweb.freebsd.org/changeset/base/367813
>> 
>> Log:
>>  Add function getlocalbase() to libutil.
>> 
>>  This function returns the path to the local software base directory, by
>>  default "/usr/local" (or the value of _PATH_LOCALBASE in include/paths.h
>>  when building the world).
>> 
>>  The value returned can be overridden by 2 methods:
>> 
>>  - the LOCALBASE environment variable (ignored by SUID programs)
>>  - else a non-default user.localbase sysctl value
>> 
>>  Reviewed by:hps (earlier version)
>>  Relnotes:   yes
>>  Differential Revision:  https://reviews.freebsd.org/D27236
>> 
>> Added:
>>  head/lib/libutil/getlocalbase.3   (contents, props changed)
>>  head/lib/libutil/getlocalbase.c   (contents, props changed)
>> Modified:
>>  head/lib/libutil/Makefile
>>  head/lib/libutil/libutil.h
>> 
>> Modified: head/lib/libutil/Makefile
>> ==
>> --- head/lib/libutil/MakefileWed Nov 18 19:35:30 2020
>> (r367812)
>> +++ head/lib/libutil/MakefileWed Nov 18 19:44:30 2020
>> (r367813)
>> @@ -12,7 +12,8 @@ PACKAGE=   runtime
>> LIB= util
>> SHLIB_MAJOR= 9
>> 
>> -SRCS=   _secure_path.c auth.c expand_number.c flopen.c fparseln.c 
>> gr_util.c
>> \
>> +SRCS=   _secure_path.c auth.c expand_number.c flopen.c fparseln.c \
>> +getlocalbase.c  gr_util.c \
>>  hexdump.c humanize_number.c kinfo_getfile.c \
>>  kinfo_getallproc.c kinfo_getproc.c kinfo_getvmmap.c \
>>  kinfo_getvmobject.c kld.c \
>> @@ -30,7 +31,7 @@ CFLAGS+= -DINET6
>> 
>> CFLAGS+= -I${.CURDIR} -I${SRCTOP}/lib/libc/gen/
>> 
>> -MAN+=   expand_number.3 flopen.3 fparseln.3 hexdump.3 \
>> +MAN+=   expand_number.3 flopen.3 fparseln.3 getlocalbase.3 hexdump.3 \
>>  humanize_number.3 kinfo_getallproc.3 kinfo_getfile.3 \
>>  kinfo_getproc.3 kinfo_getvmmap.3 kinfo_getvmobject.3 kld.3 \
>>  login_auth.3 login_cap.3 \
>> 
>> Added: head/lib/libutil/getlocalbase.3
>> ==
>> --- /dev/null00:00:00 1970   (empty, because file is newly added)
>> +++ head/lib/libutil/getlocalbase.3  Wed Nov 18 19:44:30 2020
>> (r367813)
>> @@ -0,0 +1,99 @@
>> +.\"
>> +.\" SPDX-License-Identifier: BSD-2-Clause-FreeBSD
>> +.\"
>> +.\" Copyright 2020 Scott Long
>> +.\" Copyright 2020 Stefan Eßer
>> +.\"
>> +.\" 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$
>> +.\"
>> +.Dd November 18, 2020
>> +.Dt GETLOCALBASE 3
>> +.Os
>> +.Sh NAME
>> +.Nm getlocalbase
>> +.Nd "return the path to the local software directory"
>> +.Sh LIBRARY
>> +.Lb libutil
>> +.Sh SYNOPSIS
>> +.In libutil.h
>> +.Ft const char*
>> +.Fn getlocalbase "void"
>> +.Sh DESCRIPTION
>> +The
>> +.Fn getlocalbase
>> +function returns the path to the local software base directory.
>> +Normally this is the
>> +.Pa /usr/local
>> +directory.
>> +First the
>> +.Ev LOCALBASE
>> +environment variable is checked.
>> +If that does not exist then the
>> +.Va user.localbase
>> +sysctl is checked.
>> +If that also does not exist then the value of the
>> +.Dv _PATH_LOCALBASE
>> +compile-time variable is used.
>> +If that is undefined then the default of
>> +.Pa /usr/local
>> +is used.
>> +.Pp
>> +The value returned by the
>> +.Fn getlocalbase
>> +function shall not be modified.
>> +.Sh IMPLEMENTATION NOTES
>> +Calls to
>> +.Fn getlocalbase
>> +will perform a setugid 

Re: svn commit: r367813 - head/lib/libutil

2020-11-18 Thread Mateusz Guzik
On 11/18/20, Stefan Eßer  wrote:
> Author: se
> Date: Wed Nov 18 19:44:30 2020
> New Revision: 367813
> URL: https://svnweb.freebsd.org/changeset/base/367813
>
> Log:
>   Add function getlocalbase() to libutil.
>
>   This function returns the path to the local software base directory, by
>   default "/usr/local" (or the value of _PATH_LOCALBASE in include/paths.h
>   when building the world).
>
>   The value returned can be overridden by 2 methods:
>
>   - the LOCALBASE environment variable (ignored by SUID programs)
>   - else a non-default user.localbase sysctl value
>
>   Reviewed by:hps (earlier version)
>   Relnotes:   yes
>   Differential Revision:  https://reviews.freebsd.org/D27236
>
> Added:
>   head/lib/libutil/getlocalbase.3   (contents, props changed)
>   head/lib/libutil/getlocalbase.c   (contents, props changed)
> Modified:
>   head/lib/libutil/Makefile
>   head/lib/libutil/libutil.h
>
> Modified: head/lib/libutil/Makefile
> ==
> --- head/lib/libutil/Makefile Wed Nov 18 19:35:30 2020(r367812)
> +++ head/lib/libutil/Makefile Wed Nov 18 19:44:30 2020(r367813)
> @@ -12,7 +12,8 @@ PACKAGE=runtime
>  LIB= util
>  SHLIB_MAJOR= 9
>
> -SRCS=_secure_path.c auth.c expand_number.c flopen.c fparseln.c 
> gr_util.c
> \
> +SRCS=_secure_path.c auth.c expand_number.c flopen.c fparseln.c \
> + getlocalbase.c  gr_util.c \
>   hexdump.c humanize_number.c kinfo_getfile.c \
>   kinfo_getallproc.c kinfo_getproc.c kinfo_getvmmap.c \
>   kinfo_getvmobject.c kld.c \
> @@ -30,7 +31,7 @@ CFLAGS+= -DINET6
>
>  CFLAGS+= -I${.CURDIR} -I${SRCTOP}/lib/libc/gen/
>
> -MAN+=expand_number.3 flopen.3 fparseln.3 hexdump.3 \
> +MAN+=expand_number.3 flopen.3 fparseln.3 getlocalbase.3 hexdump.3 \
>   humanize_number.3 kinfo_getallproc.3 kinfo_getfile.3 \
>   kinfo_getproc.3 kinfo_getvmmap.3 kinfo_getvmobject.3 kld.3 \
>   login_auth.3 login_cap.3 \
>
> Added: head/lib/libutil/getlocalbase.3
> ==
> --- /dev/null 00:00:00 1970   (empty, because file is newly added)
> +++ head/lib/libutil/getlocalbase.3   Wed Nov 18 19:44:30 2020
> (r367813)
> @@ -0,0 +1,99 @@
> +.\"
> +.\" SPDX-License-Identifier: BSD-2-Clause-FreeBSD
> +.\"
> +.\" Copyright 2020 Scott Long
> +.\" Copyright 2020 Stefan Eßer
> +.\"
> +.\" 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$
> +.\"
> +.Dd November 18, 2020
> +.Dt GETLOCALBASE 3
> +.Os
> +.Sh NAME
> +.Nm getlocalbase
> +.Nd "return the path to the local software directory"
> +.Sh LIBRARY
> +.Lb libutil
> +.Sh SYNOPSIS
> +.In libutil.h
> +.Ft const char*
> +.Fn getlocalbase "void"
> +.Sh DESCRIPTION
> +The
> +.Fn getlocalbase
> +function returns the path to the local software base directory.
> +Normally this is the
> +.Pa /usr/local
> +directory.
> +First the
> +.Ev LOCALBASE
> +environment variable is checked.
> +If that does not exist then the
> +.Va user.localbase
> +sysctl is checked.
> +If that also does not exist then the value of the
> +.Dv _PATH_LOCALBASE
> +compile-time variable is used.
> +If that is undefined then the default of
> +.Pa /usr/local
> +is used.
> +.Pp
> +The value returned by the
> +.Fn getlocalbase
> +function shall not be modified.
> +.Sh IMPLEMENTATION NOTES
> +Calls to
> +.Fn getlocalbase
> +will perform a setugid check on the running binary before checking the
> +environment.
> +.Sh RETURN VALUES
> +The
> +.Fn getlocalbase
> +function always succeeds and returns a pointer to a string, whose length
> +may exceed 

Re: svn commit: r367813 - head/lib/libutil

2020-11-18 Thread Jessica Clarke
On 18 Nov 2020, at 21:15, Jessica Clarke  wrote:
> 
> On 18 Nov 2020, at 19:44, Stefan Eßer  wrote:
>> +/*
>> + * Check for some other thread already having 
>> + * set localbase - this should use atomic ops.
>> + * The amount of memory allocated above may leak,
>> + * if a parallel update in another thread is not
>> + * detected and the non-NULL pointer is overwritten.
>> + */
> 
> Why was this committed with a known racy/leaky implementation?
> 
> What happens if I set the value with a sysctl and call this?

Notably, you go to all this trouble to have a localbase variable that
gets set, but you never actually use it properly as a cache since you
do the full lookup and only then realise that you already had a
(possibly stale) value cached.

Jess

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


svn commit: r367820 - head/sys/kern

2020-11-18 Thread Mariusz Zaborski
Author: oshogbo
Date: Wed Nov 18 21:26:14 2020
New Revision: 367820
URL: https://svnweb.freebsd.org/changeset/base/367820

Log:
  Add CTLFLAG_MPSAFE to the suser_enabled sysctl.
  
  Pointed out by:   mjg

Modified:
  head/sys/kern/kern_priv.c

Modified: head/sys/kern/kern_priv.c
==
--- head/sys/kern/kern_priv.c   Wed Nov 18 21:07:08 2020(r367819)
+++ head/sys/kern/kern_priv.c   Wed Nov 18 21:26:14 2020(r367820)
@@ -107,8 +107,8 @@ sysctl_kern_suser_enabled(SYSCTL_HANDLER_ARGS)
 }
 
 SYSCTL_PROC(_security_bsd, OID_AUTO, suser_enabled, CTLTYPE_INT |
-CTLFLAG_RWTUN | CTLFLAG_PRISON, 0, 0, _kern_suser_enabled, "I",
-"Processes with uid 0 have privilege");
+CTLFLAG_RWTUN | CTLFLAG_PRISON | CTLFLAG_MPSAFE, 0, 0,
+_kern_suser_enabled, "I", "Processes with uid 0 have privilege");
 
 static int unprivileged_mlock = 1;
 SYSCTL_INT(_security_bsd, OID_AUTO, unprivileged_mlock, CTLFLAG_RWTUN,
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


Re: svn commit: r367819 - in head: sys/kern sys/sys usr.sbin/jail

2020-11-18 Thread Mariusz Zaborski
Hello Mateusz,

Thank you for pointing out this. I will fix those.

Thanks,
Mariusz

On Wed, 18 Nov 2020 at 22:15, Mateusz Guzik  wrote:
>
> On 11/18/20, Mariusz Zaborski  wrote:
> > Author: oshogbo
> > Date: Wed Nov 18 21:07:08 2020
> > New Revision: 367819
> > URL: https://svnweb.freebsd.org/changeset/base/367819
> >
> > Log:
> >   jail: introduce per jail suser_enabled setting
> >
> >   The suser_enable sysctl allows to remove a privileged rights from uid 0.
> >   This change introduce per jail setting which allow to make root a
> >   normal user.
> >
> >   Reviewed by:jamie
> >   Previous version reviewed by:   kevans, emaste, markj, me_igalic.co
> >   Discussed with: pjd
> >   Differential Revision:  https://reviews.freebsd.org/D27128
> >
> > Modified:
> >   head/sys/kern/kern_jail.c
> >   head/sys/kern/kern_priv.c
> >   head/sys/sys/jail.h
> >   head/usr.sbin/jail/jail.8
> >
> > Modified: head/sys/kern/kern_jail.c
> > ==
> > --- head/sys/kern/kern_jail.c Wed Nov 18 20:59:58 2020(r367818)
> > +++ head/sys/kern/kern_jail.c Wed Nov 18 21:07:08 2020(r367819)
> > @@ -199,12 +199,14 @@ static struct bool_flags pr_flag_allow[NBBY * NBPW] =
> >
> >   {"allow.read_msgbuf", "allow.noread_msgbuf", PR_ALLOW_READ_MSGBUF},
> >   {"allow.unprivileged_proc_debug", "allow.nounprivileged_proc_debug",
> >PR_ALLOW_UNPRIV_DEBUG},
> > + {"allow.suser", "allow.nosuser", PR_ALLOW_SUSER},
> >  };
> >  const size_t pr_flag_allow_size = sizeof(pr_flag_allow);
> >
> >  #define  JAIL_DEFAULT_ALLOW  (PR_ALLOW_SET_HOSTNAME | \
> >PR_ALLOW_RESERVED_PORTS | \
> > -  PR_ALLOW_UNPRIV_DEBUG)
> > +  PR_ALLOW_UNPRIV_DEBUG | \
> > +  PR_ALLOW_SUSER)
> >  #define  JAIL_DEFAULT_ENFORCE_STATFS 2
> >  #define  JAIL_DEFAULT_DEVFS_RSNUM0
> >  static unsigned jail_default_allow = JAIL_DEFAULT_ALLOW;
> > @@ -3815,6 +3817,8 @@ SYSCTL_JAIL_PARAM(_allow, read_msgbuf, CTLTYPE_INT |
> > C
> >  "B", "Jail may read the kernel message buffer");
> >  SYSCTL_JAIL_PARAM(_allow, unprivileged_proc_debug, CTLTYPE_INT |
> > CTLFLAG_RW,
> >  "B", "Unprivileged processes may use process debugging facilities");
> > +SYSCTL_JAIL_PARAM(_allow, suser, CTLTYPE_INT | CTLFLAG_RW,
> > +"B", "Processes in jail with uid 0 have privilege");
> >
> >  SYSCTL_JAIL_PARAM_SUBNODE(allow, mount, "Jail mount/unmount permission
> > flags");
> >  SYSCTL_JAIL_PARAM(_allow_mount, , CTLTYPE_INT | CTLFLAG_RW,
> >
> > Modified: head/sys/kern/kern_priv.c
> > ==
> > --- head/sys/kern/kern_priv.c Wed Nov 18 20:59:58 2020(r367818)
> > +++ head/sys/kern/kern_priv.c Wed Nov 18 21:07:08 2020(r367819)
> > @@ -3,6 +3,7 @@
> >   *
> >   * Copyright (c) 2006 nCircle Network Security, Inc.
> >   * Copyright (c) 2009 Robert N. M. Watson
> > + * Copyright (c) 2020 Mariusz Zaborski 
> >   * All rights reserved.
> >   *
> >   * This software was developed by Robert N. M. Watson for the TrustedBSD
> > @@ -36,6 +37,9 @@ __FBSDID("$FreeBSD$");
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> > +#include 
> > +#include 
> >  #include 
> >  #include 
> >  #include 
> > @@ -54,10 +58,58 @@ __FBSDID("$FreeBSD$");
> >   * userland programs, and should not be done without careful consideration
> > of
> >   * the consequences.
> >   */
> > -static int __read_mostly suser_enabled = 1;
> > -SYSCTL_INT(_security_bsd, OID_AUTO, suser_enabled, CTLFLAG_RWTUN,
> > -_enabled, 0, "processes with uid 0 have privilege");
> >
> > +static bool
> > +suser_enabled(struct ucred *cred)
> > +{
> > +
> > + return (prison_allow(cred, PR_ALLOW_SUSER) ? true : false);
> > +}
> > +
>
> This converts a variable read into a function call to prison_allow.
> prison_allow should be converted into an inline func and put in a
> header.
>
> Also:
> /* This is an atomic read, so no locking is necessary. */
> return (cred->cr_prison->pr_allow & flag);
>
> happens to probably work in practice, but is wrong. Short of
> atomic_store to modify and atomic_load to obtain the content can be
> arbitrarily mangled during concurrent concurrent write.
>
> > +static void inline
> > +prison_suser_set(struct prison *pr, int enabled)
> > +{
> > +
> > + if (enabled) {
> > + pr->pr_allow |= PR_ALLOW_SUSER;
> > + } else {
> > + pr->pr_allow &= ~PR_ALLOW_SUSER;
> > + }
> > +}
> > +
> > +static int
> > +sysctl_kern_suser_enabled(SYSCTL_HANDLER_ARGS)
> > +{
> > + struct prison *pr, *cpr;
> > + struct ucred *cred;
> > + int descend, error, enabled;
> > +
> > + cred = req->td->td_ucred;
> > + enabled = suser_enabled(cred);
> > +
> > + error = 

Re: svn commit: r367813 - head/lib/libutil

2020-11-18 Thread Jessica Clarke
On 18 Nov 2020, at 19:44, Stefan Eßer  wrote:
> + /*
> +  * Check for some other thread already having 
> +  * set localbase - this should use atomic ops.
> +  * The amount of memory allocated above may leak,
> +  * if a parallel update in another thread is not
> +  * detected and the non-NULL pointer is overwritten.
> +  */

Why was this committed with a known racy/leaky implementation?

What happens if I set the value with a sysctl and call this?

Jess

> + if (tmppath[0] != '\0' &&
> + (volatile const char*)localbase == NULL)
> + localbase = tmppath;
> + else
> + free((void*)tmppath);
> + return (localbase);
> + }
> + return (_PATH_LOCALBASE);
> +}

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


Re: svn commit: r367819 - in head: sys/kern sys/sys usr.sbin/jail

2020-11-18 Thread Mateusz Guzik
On 11/18/20, Mariusz Zaborski  wrote:
> Author: oshogbo
> Date: Wed Nov 18 21:07:08 2020
> New Revision: 367819
> URL: https://svnweb.freebsd.org/changeset/base/367819
>
> Log:
>   jail: introduce per jail suser_enabled setting
>
>   The suser_enable sysctl allows to remove a privileged rights from uid 0.
>   This change introduce per jail setting which allow to make root a
>   normal user.
>
>   Reviewed by:jamie
>   Previous version reviewed by:   kevans, emaste, markj, me_igalic.co
>   Discussed with: pjd
>   Differential Revision:  https://reviews.freebsd.org/D27128
>
> Modified:
>   head/sys/kern/kern_jail.c
>   head/sys/kern/kern_priv.c
>   head/sys/sys/jail.h
>   head/usr.sbin/jail/jail.8
>
> Modified: head/sys/kern/kern_jail.c
> ==
> --- head/sys/kern/kern_jail.c Wed Nov 18 20:59:58 2020(r367818)
> +++ head/sys/kern/kern_jail.c Wed Nov 18 21:07:08 2020(r367819)
> @@ -199,12 +199,14 @@ static struct bool_flags pr_flag_allow[NBBY * NBPW] =
>
>   {"allow.read_msgbuf", "allow.noread_msgbuf", PR_ALLOW_READ_MSGBUF},
>   {"allow.unprivileged_proc_debug", "allow.nounprivileged_proc_debug",
>PR_ALLOW_UNPRIV_DEBUG},
> + {"allow.suser", "allow.nosuser", PR_ALLOW_SUSER},
>  };
>  const size_t pr_flag_allow_size = sizeof(pr_flag_allow);
>
>  #define  JAIL_DEFAULT_ALLOW  (PR_ALLOW_SET_HOSTNAME | \
>PR_ALLOW_RESERVED_PORTS | \
> -  PR_ALLOW_UNPRIV_DEBUG)
> +  PR_ALLOW_UNPRIV_DEBUG | \
> +  PR_ALLOW_SUSER)
>  #define  JAIL_DEFAULT_ENFORCE_STATFS 2
>  #define  JAIL_DEFAULT_DEVFS_RSNUM0
>  static unsigned jail_default_allow = JAIL_DEFAULT_ALLOW;
> @@ -3815,6 +3817,8 @@ SYSCTL_JAIL_PARAM(_allow, read_msgbuf, CTLTYPE_INT |
> C
>  "B", "Jail may read the kernel message buffer");
>  SYSCTL_JAIL_PARAM(_allow, unprivileged_proc_debug, CTLTYPE_INT |
> CTLFLAG_RW,
>  "B", "Unprivileged processes may use process debugging facilities");
> +SYSCTL_JAIL_PARAM(_allow, suser, CTLTYPE_INT | CTLFLAG_RW,
> +"B", "Processes in jail with uid 0 have privilege");
>
>  SYSCTL_JAIL_PARAM_SUBNODE(allow, mount, "Jail mount/unmount permission
> flags");
>  SYSCTL_JAIL_PARAM(_allow_mount, , CTLTYPE_INT | CTLFLAG_RW,
>
> Modified: head/sys/kern/kern_priv.c
> ==
> --- head/sys/kern/kern_priv.c Wed Nov 18 20:59:58 2020(r367818)
> +++ head/sys/kern/kern_priv.c Wed Nov 18 21:07:08 2020(r367819)
> @@ -3,6 +3,7 @@
>   *
>   * Copyright (c) 2006 nCircle Network Security, Inc.
>   * Copyright (c) 2009 Robert N. M. Watson
> + * Copyright (c) 2020 Mariusz Zaborski 
>   * All rights reserved.
>   *
>   * This software was developed by Robert N. M. Watson for the TrustedBSD
> @@ -36,6 +37,9 @@ __FBSDID("$FreeBSD$");
>  #include 
>  #include 
>  #include 
> +#include 
> +#include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -54,10 +58,58 @@ __FBSDID("$FreeBSD$");
>   * userland programs, and should not be done without careful consideration
> of
>   * the consequences.
>   */
> -static int __read_mostly suser_enabled = 1;
> -SYSCTL_INT(_security_bsd, OID_AUTO, suser_enabled, CTLFLAG_RWTUN,
> -_enabled, 0, "processes with uid 0 have privilege");
>
> +static bool
> +suser_enabled(struct ucred *cred)
> +{
> +
> + return (prison_allow(cred, PR_ALLOW_SUSER) ? true : false);
> +}
> +

This converts a variable read into a function call to prison_allow.
prison_allow should be converted into an inline func and put in a
header.

Also:
/* This is an atomic read, so no locking is necessary. */
return (cred->cr_prison->pr_allow & flag);

happens to probably work in practice, but is wrong. Short of
atomic_store to modify and atomic_load to obtain the content can be
arbitrarily mangled during concurrent concurrent write.

> +static void inline
> +prison_suser_set(struct prison *pr, int enabled)
> +{
> +
> + if (enabled) {
> + pr->pr_allow |= PR_ALLOW_SUSER;
> + } else {
> + pr->pr_allow &= ~PR_ALLOW_SUSER;
> + }
> +}
> +
> +static int
> +sysctl_kern_suser_enabled(SYSCTL_HANDLER_ARGS)
> +{
> + struct prison *pr, *cpr;
> + struct ucred *cred;
> + int descend, error, enabled;
> +
> + cred = req->td->td_ucred;
> + enabled = suser_enabled(cred);
> +
> + error = sysctl_handle_int(oidp, , 0, req);
> + if (error || !req->newptr)
> + return (error);
> +
> + pr = cred->cr_prison;
> + sx_slock(_lock);
> + mtx_lock(>pr_mtx);
> +
> + prison_suser_set(pr, enabled);
> + if (!enabled) {
> + FOREACH_PRISON_DESCENDANT_LOCKED(pr, cpr, descend) {
> + prison_suser_set(cpr, 0);
> + }
> + }
> + 

svn commit: r367819 - in head: sys/kern sys/sys usr.sbin/jail

2020-11-18 Thread Mariusz Zaborski
Author: oshogbo
Date: Wed Nov 18 21:07:08 2020
New Revision: 367819
URL: https://svnweb.freebsd.org/changeset/base/367819

Log:
  jail: introduce per jail suser_enabled setting
  
  The suser_enable sysctl allows to remove a privileged rights from uid 0.
  This change introduce per jail setting which allow to make root a
  normal user.
  
  Reviewed by:  jamie
  Previous version reviewed by: kevans, emaste, markj, me_igalic.co
  Discussed with:   pjd
  Differential Revision:https://reviews.freebsd.org/D27128

Modified:
  head/sys/kern/kern_jail.c
  head/sys/kern/kern_priv.c
  head/sys/sys/jail.h
  head/usr.sbin/jail/jail.8

Modified: head/sys/kern/kern_jail.c
==
--- head/sys/kern/kern_jail.c   Wed Nov 18 20:59:58 2020(r367818)
+++ head/sys/kern/kern_jail.c   Wed Nov 18 21:07:08 2020(r367819)
@@ -199,12 +199,14 @@ static struct bool_flags pr_flag_allow[NBBY * NBPW] = 
{"allow.read_msgbuf", "allow.noread_msgbuf", PR_ALLOW_READ_MSGBUF},
{"allow.unprivileged_proc_debug", "allow.nounprivileged_proc_debug",
 PR_ALLOW_UNPRIV_DEBUG},
+   {"allow.suser", "allow.nosuser", PR_ALLOW_SUSER},
 };
 const size_t pr_flag_allow_size = sizeof(pr_flag_allow);
 
 #defineJAIL_DEFAULT_ALLOW  (PR_ALLOW_SET_HOSTNAME | \
 PR_ALLOW_RESERVED_PORTS | \
-PR_ALLOW_UNPRIV_DEBUG)
+PR_ALLOW_UNPRIV_DEBUG | \
+PR_ALLOW_SUSER)
 #defineJAIL_DEFAULT_ENFORCE_STATFS 2
 #defineJAIL_DEFAULT_DEVFS_RSNUM0
 static unsigned jail_default_allow = JAIL_DEFAULT_ALLOW;
@@ -3815,6 +3817,8 @@ SYSCTL_JAIL_PARAM(_allow, read_msgbuf, CTLTYPE_INT | C
 "B", "Jail may read the kernel message buffer");
 SYSCTL_JAIL_PARAM(_allow, unprivileged_proc_debug, CTLTYPE_INT | CTLFLAG_RW,
 "B", "Unprivileged processes may use process debugging facilities");
+SYSCTL_JAIL_PARAM(_allow, suser, CTLTYPE_INT | CTLFLAG_RW,
+"B", "Processes in jail with uid 0 have privilege");
 
 SYSCTL_JAIL_PARAM_SUBNODE(allow, mount, "Jail mount/unmount permission flags");
 SYSCTL_JAIL_PARAM(_allow_mount, , CTLTYPE_INT | CTLFLAG_RW,

Modified: head/sys/kern/kern_priv.c
==
--- head/sys/kern/kern_priv.c   Wed Nov 18 20:59:58 2020(r367818)
+++ head/sys/kern/kern_priv.c   Wed Nov 18 21:07:08 2020(r367819)
@@ -3,6 +3,7 @@
  *
  * Copyright (c) 2006 nCircle Network Security, Inc.
  * Copyright (c) 2009 Robert N. M. Watson
+ * Copyright (c) 2020 Mariusz Zaborski 
  * All rights reserved.
  *
  * This software was developed by Robert N. M. Watson for the TrustedBSD
@@ -36,6 +37,9 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -54,10 +58,58 @@ __FBSDID("$FreeBSD$");
  * userland programs, and should not be done without careful consideration of
  * the consequences.
  */
-static int __read_mostly   suser_enabled = 1;
-SYSCTL_INT(_security_bsd, OID_AUTO, suser_enabled, CTLFLAG_RWTUN,
-_enabled, 0, "processes with uid 0 have privilege");
 
+static bool
+suser_enabled(struct ucred *cred)
+{
+
+   return (prison_allow(cred, PR_ALLOW_SUSER) ? true : false);
+}
+
+static void inline
+prison_suser_set(struct prison *pr, int enabled)
+{
+
+   if (enabled) {
+   pr->pr_allow |= PR_ALLOW_SUSER;
+   } else {
+   pr->pr_allow &= ~PR_ALLOW_SUSER;
+   }
+}
+
+static int
+sysctl_kern_suser_enabled(SYSCTL_HANDLER_ARGS)
+{
+   struct prison *pr, *cpr;
+   struct ucred *cred;
+   int descend, error, enabled;
+
+   cred = req->td->td_ucred;
+   enabled = suser_enabled(cred);
+
+   error = sysctl_handle_int(oidp, , 0, req);
+   if (error || !req->newptr)
+   return (error);
+
+   pr = cred->cr_prison;
+   sx_slock(_lock);
+   mtx_lock(>pr_mtx);
+
+   prison_suser_set(pr, enabled);
+   if (!enabled) {
+   FOREACH_PRISON_DESCENDANT_LOCKED(pr, cpr, descend) {
+   prison_suser_set(cpr, 0);
+   }
+   }
+   mtx_unlock(>pr_mtx);
+   sx_sunlock(_lock);
+   return (0);
+}
+
+SYSCTL_PROC(_security_bsd, OID_AUTO, suser_enabled, CTLTYPE_INT |
+CTLFLAG_RWTUN | CTLFLAG_PRISON, 0, 0, _kern_suser_enabled, "I",
+"Processes with uid 0 have privilege");
+
 static int unprivileged_mlock = 1;
 SYSCTL_INT(_security_bsd, OID_AUTO, unprivileged_mlock, CTLFLAG_RWTUN,
 _mlock, 0, "Allow non-root users to call mlock(2)");
@@ -186,7 +238,7 @@ priv_check_cred(struct ucred *cred, int priv)
 * superuser policy to be globally disabled, although this is
 * currenty of limited utility.
 */
-   if (suser_enabled) {
+   if 

svn commit: r367818 - head/sys/kern

2020-11-18 Thread Mariusz Zaborski
Author: oshogbo
Date: Wed Nov 18 20:59:58 2020
New Revision: 367818
URL: https://svnweb.freebsd.org/changeset/base/367818

Log:
  Fix style nits.

Modified:
  head/sys/kern/kern_jail.c
  head/sys/kern/kern_priv.c

Modified: head/sys/kern/kern_jail.c
==
--- head/sys/kern/kern_jail.c   Wed Nov 18 20:20:03 2020(r367817)
+++ head/sys/kern/kern_jail.c   Wed Nov 18 20:59:58 2020(r367818)
@@ -3739,9 +3739,9 @@ SYSCTL_JAIL_PARAM_STRING(, name, CTLFLAG_RW, MAXHOSTNA
 SYSCTL_JAIL_PARAM_STRING(, path, CTLFLAG_RDTUN, MAXPATHLEN, "Jail root path");
 SYSCTL_JAIL_PARAM(, securelevel, CTLTYPE_INT | CTLFLAG_RW,
 "I", "Jail secure level");
-SYSCTL_JAIL_PARAM(, osreldate, CTLTYPE_INT | CTLFLAG_RDTUN, "I", 
+SYSCTL_JAIL_PARAM(, osreldate, CTLTYPE_INT | CTLFLAG_RDTUN, "I",
 "Jail value for kern.osreldate and uname -K");
-SYSCTL_JAIL_PARAM_STRING(, osrelease, CTLFLAG_RDTUN, OSRELEASELEN, 
+SYSCTL_JAIL_PARAM_STRING(, osrelease, CTLFLAG_RDTUN, OSRELEASELEN,
 "Jail value for kern.osrelease and uname -r");
 SYSCTL_JAIL_PARAM(, enforce_statfs, CTLTYPE_INT | CTLFLAG_RW,
 "I", "Jail cannot see all mounted file systems");

Modified: head/sys/kern/kern_priv.c
==
--- head/sys/kern/kern_priv.c   Wed Nov 18 20:20:03 2020(r367817)
+++ head/sys/kern/kern_priv.c   Wed Nov 18 20:59:58 2020(r367818)
@@ -54,7 +54,7 @@ __FBSDID("$FreeBSD$");
  * userland programs, and should not be done without careful consideration of
  * the consequences.
  */
-static int __read_mostly   suser_enabled = 1;
+static int __read_mostly   suser_enabled = 1;
 SYSCTL_INT(_security_bsd, OID_AUTO, suser_enabled, CTLFLAG_RWTUN,
 _enabled, 0, "processes with uid 0 have privilege");
 
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r367817 - head/sys/fs/msdosfs

2020-11-18 Thread Conrad Meyer
Author: cem
Date: Wed Nov 18 20:20:03 2020
New Revision: 367817
URL: https://svnweb.freebsd.org/changeset/base/367817

Log:
  msdosfs(5): Fix debug-only format string
  
  No functional change; MSDOSFS_DEBUG isn't a real build option, so this isn't
  covered by LINT kernels.

Modified:
  head/sys/fs/msdosfs/msdosfs_vfsops.c

Modified: head/sys/fs/msdosfs/msdosfs_vfsops.c
==
--- head/sys/fs/msdosfs/msdosfs_vfsops.cWed Nov 18 20:00:55 2020
(r367816)
+++ head/sys/fs/msdosfs/msdosfs_vfsops.cWed Nov 18 20:20:03 2020
(r367817)
@@ -792,7 +792,7 @@ msdosfs_unmount(struct mount *mp, int mntflags)
printf("freef %p, freeb %p, mount %p\n",
TAILQ_NEXT(vp, v_vnodelist), vp->v_vnodelist.tqe_prev,
vp->v_mount);
-   printf("cleanblkhd %p, dirtyblkhd %p, numoutput %ld, type %d\n",
+   printf("cleanblkhd %p, dirtyblkhd %p, numoutput %d, type %d\n",
TAILQ_FIRST(>v_bufobj.bo_clean.bv_hd),
TAILQ_FIRST(>v_bufobj.bo_dirty.bv_hd),
vp->v_bufobj.bo_numoutput, vp->v_type);
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r367816 - in head: sbin/nvmecontrol usr.sbin/mailwrapper usr.sbin/pkg

2020-11-18 Thread Stefan Eßer
Author: se
Date: Wed Nov 18 20:00:55 2020
New Revision: 367816
URL: https://svnweb.freebsd.org/changeset/base/367816

Log:
  Make use of the getlocalbase() function for run-time adjustment of the
  local software base directory, as committed in SVN rev. 367813.
  
  The pkg and mailwrapper programs used the LOCALBASE environment variable
  for this purpose and this functionality is preserved by getlocalbase().
  
  After this change, the value of the user.localbase sysctl variable is used
  if present (and not overridden in the environment).
  
  The nvmecontrol program gains support of a dynamic path to its plugin
  directory with this update.
  
  Differential Revision:https://reviews.freebsd.org/D27237

Modified:
  head/sbin/nvmecontrol/comnd.c
  head/sbin/nvmecontrol/nvmecontrol.c
  head/usr.sbin/mailwrapper/mailwrapper.c
  head/usr.sbin/pkg/Makefile
  head/usr.sbin/pkg/config.c
  head/usr.sbin/pkg/pkg.c

Modified: head/sbin/nvmecontrol/comnd.c
==
--- head/sbin/nvmecontrol/comnd.c   Wed Nov 18 19:55:24 2020
(r367815)
+++ head/sbin/nvmecontrol/comnd.c   Wed Nov 18 20:00:55 2020
(r367816)
@@ -287,7 +287,7 @@ bad_arg:
  * Loads all the .so's from the specified directory.
  */
 void
-cmd_load_dir(const char *dir __unused, cmd_load_cb_t cb __unused, void *argp 
__unused)
+cmd_load_dir(const char *dir, cmd_load_cb_t cb, void *argp)
 {
DIR *d;
struct dirent *dent;

Modified: head/sbin/nvmecontrol/nvmecontrol.c
==
--- head/sbin/nvmecontrol/nvmecontrol.c Wed Nov 18 19:55:24 2020
(r367815)
+++ head/sbin/nvmecontrol/nvmecontrol.c Wed Nov 18 20:00:55 2020
(r367816)
@@ -38,6 +38,7 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -178,11 +179,13 @@ get_nsid(int fd, char **ctrlr_str, uint32_t *nsid)
 int
 main(int argc, char *argv[])
 {
+   static char dir[MAXPATHLEN];
 
cmd_init();
 
cmd_load_dir("/lib/nvmecontrol", NULL, NULL);
-   cmd_load_dir(_PATH_LOCALBASE "/lib/nvmecontrol", NULL, NULL);
+   snprintf(dir, MAXPATHLEN, "%s/lib/nvmecontrol", getlocalbase());
+   cmd_load_dir(dir, NULL, NULL);
 
cmd_dispatch(argc, argv, NULL);
 

Modified: head/usr.sbin/mailwrapper/mailwrapper.c
==
--- head/usr.sbin/mailwrapper/mailwrapper.c Wed Nov 18 19:55:24 2020
(r367815)
+++ head/usr.sbin/mailwrapper/mailwrapper.c Wed Nov 18 20:00:55 2020
(r367816)
@@ -106,7 +106,7 @@ main(int argc, char *argv[], char *envp[])
addarg(, argv[0]);
 
snprintf(localmailerconf, MAXPATHLEN, "%s/etc/mail/mailer.conf",
-   getenv("LOCALBASE") ? getenv("LOCALBASE") : _PATH_LOCALBASE);
+   getlocalbase());
 
mailerconf = localmailerconf;
if ((config = fopen(localmailerconf, "r")) == NULL)

Modified: head/usr.sbin/pkg/Makefile
==
--- head/usr.sbin/pkg/Makefile  Wed Nov 18 19:55:24 2020(r367815)
+++ head/usr.sbin/pkg/Makefile  Wed Nov 18 20:00:55 2020(r367816)
@@ -25,6 +25,6 @@ MAN=  pkg.7
 
 CFLAGS+=-I${SRCTOP}/contrib/libucl/include
 .PATH: ${SRCTOP}/contrib/libucl/include
-LIBADD=archive fetch ucl sbuf crypto ssl
+LIBADD=archive fetch ucl sbuf crypto ssl util
 
 .include 

Modified: head/usr.sbin/pkg/config.c
==
--- head/usr.sbin/pkg/config.c  Wed Nov 18 19:55:24 2020(r367815)
+++ head/usr.sbin/pkg/config.c  Wed Nov 18 20:00:55 2020(r367816)
@@ -40,6 +40,7 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -455,9 +456,8 @@ config_init(void)
}
 
/* Read LOCALBASE/etc/pkg.conf first. */
-   localbase = getenv("LOCALBASE") ? getenv("LOCALBASE") : _PATH_LOCALBASE;
-   snprintf(confpath, sizeof(confpath), "%s/etc/pkg.conf",
-   localbase);
+   localbase = getlocalbase();
+   snprintf(confpath, sizeof(confpath), "%s/etc/pkg.conf", localbase);
 
if (access(confpath, F_OK) == 0 && read_conf_file(confpath,
CONFFILE_PKG))

Modified: head/usr.sbin/pkg/pkg.c
==
--- head/usr.sbin/pkg/pkg.c Wed Nov 18 19:55:24 2020(r367815)
+++ head/usr.sbin/pkg/pkg.c Wed Nov 18 20:00:55 2020(r367816)
@@ -43,12 +43,12 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
 #include 
-#include 
 #include 
 
 #include 
@@ -1045,8 +1045,7 @@ main(int argc, char *argv[])
pkgarg = NULL;
yes = false;
 
-   snprintf(pkgpath, MAXPATHLEN, "%s/sbin/pkg",

svn commit: r367815 - head/contrib/llvm-project/llvm/lib/Support/Unix

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

Log:
  For llvm's internal function which retrieves the number of available
  "hardware threads", use cpuset_getaffinity(2) on FreeBSD, so it will
  honor processor sets configured by the cpuset(1) command.
  
  This should make it possible to avoid e.g. lld creating a huge number of
  threads on a machine with many cores, even for linking simple programs.
  
  This will also be submitted upstream.
  
  Submitted by: mjg
  MFC after:1 week

Modified:
  head/contrib/llvm-project/llvm/lib/Support/Unix/Threading.inc

Modified: head/contrib/llvm-project/llvm/lib/Support/Unix/Threading.inc
==
--- head/contrib/llvm-project/llvm/lib/Support/Unix/Threading.inc   Wed Nov 
18 19:47:24 2020(r367814)
+++ head/contrib/llvm-project/llvm/lib/Support/Unix/Threading.inc   Wed Nov 
18 19:55:24 2020(r367815)
@@ -26,6 +26,10 @@
 #include  // For pthread_getthreadid_np() / pthread_set_name_np()
 #endif
 
+#if defined(__FreeBSD__)
+#include 
+#endif
+
 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
 #include 
 #include 
@@ -282,6 +286,13 @@ SetThreadPriorityResult llvm::set_thread_priority(Thre
 #include 
 
 int computeHostNumHardwareThreads() {
+#ifdef __FreeBSD__
+  cpuset_t mask;
+  CPU_ZERO();
+  if (cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, -1, sizeof(mask),
+ ) == 0)
+return CPU_COUNT();
+#endif
 #ifdef __linux__
   cpu_set_t Set;
   if (sched_getaffinity(0, sizeof(Set), ) == 0)
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r367814 - head/sys/sys

2020-11-18 Thread Mateusz Guzik
Author: mjg
Date: Wed Nov 18 19:47:24 2020
New Revision: 367814
URL: https://svnweb.freebsd.org/changeset/base/367814

Log:
  fd: reorder struct file to reduce false sharing
  
  The size on LP64 is 80 bytes, which is just more than a cacheline, does
  not lend itself to easy shrinking and rounding up to 2 would be a huge
  waste given NOFREE marker.
  
  The least which can be done is to reorder it so that most commonly used
  fields are less likely to span different lines, and consequently suffer
  less false sharing.
  
  With the change at hand most commonly used fields land in the same line
  about 3/4 of the time, as opposed to 2/4.

Modified:
  head/sys/sys/file.h

Modified: head/sys/sys/file.h
==
--- head/sys/sys/file.h Wed Nov 18 19:44:30 2020(r367813)
+++ head/sys/sys/file.h Wed Nov 18 19:47:24 2020(r367814)
@@ -177,14 +177,14 @@ struct fadvise_info {
 };
 
 struct file {
+   volatile u_int  f_flag; /* see fcntl.h */
+   volatile u_int  f_count;/* reference count */
void*f_data;/* file descriptor specific data */
struct fileops  *f_ops; /* File operations */
-   struct ucred*f_cred;/* associated credentials. */
struct vnode*f_vnode;   /* NULL or applicable vnode */
+   struct ucred*f_cred;/* associated credentials. */
short   f_type; /* descriptor type */
short   f_vnread_flags; /* (f) Sleep lock for f_offset */
-   volatile u_int  f_flag; /* see fcntl.h */
-   volatile u_int  f_count;/* reference count */
/*
 *  DTYPE_VNODE specific fields.
 */
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r367813 - head/lib/libutil

2020-11-18 Thread Stefan Eßer
Author: se
Date: Wed Nov 18 19:44:30 2020
New Revision: 367813
URL: https://svnweb.freebsd.org/changeset/base/367813

Log:
  Add function getlocalbase() to libutil.
  
  This function returns the path to the local software base directory, by
  default "/usr/local" (or the value of _PATH_LOCALBASE in include/paths.h
  when building the world).
  
  The value returned can be overridden by 2 methods:
  
  - the LOCALBASE environment variable (ignored by SUID programs)
  - else a non-default user.localbase sysctl value
  
  Reviewed by:  hps (earlier version)
  Relnotes: yes
  Differential Revision:https://reviews.freebsd.org/D27236

Added:
  head/lib/libutil/getlocalbase.3   (contents, props changed)
  head/lib/libutil/getlocalbase.c   (contents, props changed)
Modified:
  head/lib/libutil/Makefile
  head/lib/libutil/libutil.h

Modified: head/lib/libutil/Makefile
==
--- head/lib/libutil/Makefile   Wed Nov 18 19:35:30 2020(r367812)
+++ head/lib/libutil/Makefile   Wed Nov 18 19:44:30 2020(r367813)
@@ -12,7 +12,8 @@ PACKAGE=  runtime
 LIB=   util
 SHLIB_MAJOR= 9
 
-SRCS=  _secure_path.c auth.c expand_number.c flopen.c fparseln.c gr_util.c \
+SRCS=  _secure_path.c auth.c expand_number.c flopen.c fparseln.c \
+   getlocalbase.c  gr_util.c \
hexdump.c humanize_number.c kinfo_getfile.c \
kinfo_getallproc.c kinfo_getproc.c kinfo_getvmmap.c \
kinfo_getvmobject.c kld.c \
@@ -30,7 +31,7 @@ CFLAGS+= -DINET6
 
 CFLAGS+= -I${.CURDIR} -I${SRCTOP}/lib/libc/gen/
 
-MAN+=  expand_number.3 flopen.3 fparseln.3 hexdump.3 \
+MAN+=  expand_number.3 flopen.3 fparseln.3 getlocalbase.3 hexdump.3 \
humanize_number.3 kinfo_getallproc.3 kinfo_getfile.3 \
kinfo_getproc.3 kinfo_getvmmap.3 kinfo_getvmobject.3 kld.3 \
login_auth.3 login_cap.3 \

Added: head/lib/libutil/getlocalbase.3
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/lib/libutil/getlocalbase.3 Wed Nov 18 19:44:30 2020
(r367813)
@@ -0,0 +1,99 @@
+.\"
+.\" SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+.\"
+.\" Copyright 2020 Scott Long
+.\" Copyright 2020 Stefan Eßer
+.\"
+.\" 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$
+.\"
+.Dd November 18, 2020
+.Dt GETLOCALBASE 3
+.Os
+.Sh NAME
+.Nm getlocalbase
+.Nd "return the path to the local software directory"
+.Sh LIBRARY
+.Lb libutil
+.Sh SYNOPSIS
+.In libutil.h
+.Ft const char*
+.Fn getlocalbase "void"
+.Sh DESCRIPTION
+The
+.Fn getlocalbase
+function returns the path to the local software base directory.
+Normally this is the
+.Pa /usr/local
+directory.
+First the
+.Ev LOCALBASE
+environment variable is checked.
+If that does not exist then the
+.Va user.localbase
+sysctl is checked.
+If that also does not exist then the value of the
+.Dv _PATH_LOCALBASE
+compile-time variable is used.
+If that is undefined then the default of
+.Pa /usr/local
+is used.
+.Pp
+The value returned by the
+.Fn getlocalbase
+function shall not be modified.
+.Sh IMPLEMENTATION NOTES
+Calls to
+.Fn getlocalbase
+will perform a setugid check on the running binary before checking the
+environment.
+.Sh RETURN VALUES
+The
+.Fn getlocalbase
+function always succeeds and returns a pointer to a string, whose length
+may exceed MAXPATHLEN if it has been derived from the environment variable
+LOCALBASE.
+No length checks are performed on the result.
+.Sh ENVIRONMENT
+The
+.Fn getlocalbase
+library function retrieves the
+.Ev LOCALBASE
+environment variable.
+.Sh ERRORS
+The
+.Fn getlocalbase
+function always succeeds.

svn commit: r367812 - head/sys/dev/usb/net

2020-11-18 Thread Li-Wen Hsu
Author: lwhsu
Date: Wed Nov 18 19:35:30 2020
New Revision: 367812
URL: https://svnweb.freebsd.org/changeset/base/367812

Log:
  ipheth(4): Fix for iOS 14
  
  Fix USB tethering for iOS 14.
  
  Inspired by:  https://github.com/libimobiledevice/libimobiledevice/issues/1038
  
  PR:   249979
  Reviewed by:  hselasky
  MFC after:2 weeks
  Differential Revision:https://reviews.freebsd.org/D27250

Modified:
  head/sys/dev/usb/net/if_iphethvar.h

Modified: head/sys/dev/usb/net/if_iphethvar.h
==
--- head/sys/dev/usb/net/if_iphethvar.h Wed Nov 18 19:23:30 2020
(r367811)
+++ head/sys/dev/usb/net/if_iphethvar.h Wed Nov 18 19:35:30 2020
(r367812)
@@ -39,7 +39,7 @@
 #defineIPHETH_USBINTF_SUBCLASS 253
 #defineIPHETH_USBINTF_PROTO1
 
-#defineIPHETH_BUF_SIZE 1516
+#defineIPHETH_BUF_SIZE 1514
 #defineIPHETH_TX_TIMEOUT   5000/* ms */
 
 #defineIPHETH_RX_FRAMES_MAX1
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r367811 - head/lib/msun/tests

2020-11-18 Thread Alfredo Dal'Ava Junior
Author: alfredo
Date: Wed Nov 18 19:23:30 2020
New Revision: 367811
URL: https://svnweb.freebsd.org/changeset/base/367811

Log:
  msun tests: use standard floating-point exception flags on lrint and fenv 
tests
  
  Some platforms have additional architecture-specific floating-point flags.
  Msun test cases lrint and test_fegsetenv (fenv) expects only standard flags,
  so make sure to mask them appropriately.
  
  This makes test pass on PowerPC64.
  
  Reviewed by:  jhibbits, ngie
  Sponsored by: Eldorado Research Institute (eldorado.org.br)
  Differential Revision:https://reviews.freebsd.org/D27202

Modified:
  head/lib/msun/tests/fenv_test.c
  head/lib/msun/tests/lrint_test.c

Modified: head/lib/msun/tests/fenv_test.c
==
--- head/lib/msun/tests/fenv_test.c Wed Nov 18 19:22:24 2020
(r367810)
+++ head/lib/msun/tests/fenv_test.c Wed Nov 18 19:23:30 2020
(r367811)
@@ -43,13 +43,7 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 
-/*
- * Implementations are permitted to define additional exception flags
- * not specified in the standard, so it is not necessarily true that
- * FE_ALL_EXCEPT == ALL_STD_EXCEPT.
- */
-#defineALL_STD_EXCEPT  (FE_DIVBYZERO | FE_INEXACT | FE_INVALID | \
-FE_OVERFLOW | FE_UNDERFLOW)
+#include "test-utils.h"
 
 #defineNEXCEPTS(sizeof(std_excepts) / sizeof(std_excepts[0]))
 
@@ -373,7 +367,13 @@ test_fegsetenv(void)
assert(fegetround() == FE_TONEAREST);
 
assert(fesetenv() == 0);
-   assert(fetestexcept(FE_ALL_EXCEPT) == excepts);
+
+   /* 
+* Some platforms like powerpc may set extra exception bits. 
Since
+* only standard exceptions are tested, mask against 
ALL_STD_EXCEPT 
+*/
+   assert((fetestexcept(FE_ALL_EXCEPT) & ALL_STD_EXCEPT) == 
excepts);
+
assert(fegetround() == FE_DOWNWARD);
assert(fesetenv() == 0);
assert(fetestexcept(FE_ALL_EXCEPT) == 0);

Modified: head/lib/msun/tests/lrint_test.c
==
--- head/lib/msun/tests/lrint_test.cWed Nov 18 19:22:24 2020
(r367810)
+++ head/lib/msun/tests/lrint_test.cWed Nov 18 19:23:30 2020
(r367811)
@@ -41,6 +41,8 @@ __FBSDID("$FreeBSD$");
 #include 
 #endif
 
+#include "test-utils.h"
+
 /*
  * XXX The volatile here is to avoid gcc's bogus constant folding and work
  * around the lack of support for the FENV_ACCESS pragma.
@@ -49,7 +51,8 @@ __FBSDID("$FreeBSD$");
volatile double _d = x; \
assert(feclearexcept(FE_ALL_EXCEPT) == 0);  \
assert((func)(_d) == (result) || fetestexcept(FE_INVALID)); \
-   assert(fetestexcept(FE_ALL_EXCEPT) == (excepts));   \
+   assert((fetestexcept(FE_ALL_EXCEPT) & ALL_STD_EXCEPT)   \
+   == (excepts));  \
 } while (0)
 
 #definetestall(x, result, excepts) do {
\
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r367810 - head/usr.sbin/mergemaster

2020-11-18 Thread Warner Losh
Author: imp
Date: Wed Nov 18 19:22:24 2020
New Revision: 367810
URL: https://svnweb.freebsd.org/changeset/base/367810

Log:
  mergemaster: handle symbolic links during update.
  
  /etc/os-release is now a symbolic link to a generated file. Make
  mergemaster cope with symbolic links generically. I'm no longer
  a big mergemaster user, so this has only been lightly tested
  by me, though Kimura-san has ran it through its paces.
  
  Submitted by: Yasushiro KIMURA-san
  PR: 242212
  MFC After: 2 weeks

Modified:
  head/usr.sbin/mergemaster/mergemaster.sh

Modified: head/usr.sbin/mergemaster/mergemaster.sh
==
--- head/usr.sbin/mergemaster/mergemaster.shWed Nov 18 18:40:58 2020
(r367809)
+++ head/usr.sbin/mergemaster/mergemaster.shWed Nov 18 19:22:24 2020
(r367810)
@@ -1093,6 +1093,7 @@ for COMPFILE in `find . | sort` ; do
   fi
 done
 
+# Compare regular files
 for COMPFILE in `find . -type f | sort`; do
 
   # First, check to see if the file exists in DESTDIR.  If not, the
@@ -1182,6 +1183,119 @@ for COMPFILE in `find . -type f | sort`; do
   fi # Yes, the file still remains to be checked
 done # This is for the for way up there at the beginning of the comparison
 
+ask_answer_for_symbolic_link () {
+  HANDLE_COMPSYMLINK=''
+  while true; do
+echo "  Use 'd' to delete the temporary ${COMPSYMLINK}"
+echo "  Use 'i' to install the temporary ${COMPSYMLINK}"
+echo ''
+echo "  Default is to leave the temporary symbolic link to deal with by 
hand"
+echo ''
+echo -n "How should I deal with this? [Leave it for later] "
+read HANDLE_COMPSYMLINK
+case ${HANDLE_COMPSYMLINK} in
+  ''|[dDiI])
+break
+;;
+  *)
+echo "invalid choice: ${HANDLE_COMPSYMLINK}"
+echo ''
+HANDLE_COMPSYMLINK=''
+;;
+esac
+  done
+}
+
+install_symbolic_link () {
+  rm -f ${DESTDIR}${COMPSYMLINK#.} > /dev/null 2>&1
+  if [ -L ${DESTDIR}${COMPSYMLINK#.} ]; then
+return 1
+  fi
+  cp -a ${COMPSYMLINK} ${DESTDIR}${COMPSYMLINK#.} > /dev/null 2>&1
+  if [ ! -L ${DESTDIR}${COMPSYMLINK#.} ]; then
+return 1
+  fi
+  return 0
+}
+
+handle_symbolic_link () {
+  case ${HANDLE_COMPSYMLINK} in
+[dD])
+  rm ${COMPSYMLINK}
+  echo ''
+  echo "   *** Deleting ${COMPSYMLINK}"
+  echo ''
+  return 1
+  ;;
+[iI])
+  echo ''
+  if install_symbolic_link; then
+rm ${COMPSYMLINK}
+echo "   *** ${COMPSYMLINK} installed successfully"
+return 2
+  else
+echo "   *** Problem installing ${COMPSYMLINK}, it will remain to 
merge by hand"
+return 3
+  fi
+  echo ''
+  ;;
+'')
+  echo ''
+  echo "   *** ${COMPSYMLINK} will remain for your consideration"
+  echo ''
+  return 0
+  ;;
+  esac
+}
+
+# Compare symblic links
+for COMPSYMLINK in `find . -type l | sort`; do
+  if [ ! -L "${DESTDIR}${COMPSYMLINK#.}" ]; then
+if [ -n "${AUTO_RUN}" -a -z "${AUTO_INSTALL}" ]; then
+  echo "   *** ${COMPSYMLINK} will remain for your consideration"
+  continue
+else
+  echo ''
+  echo "  *** There is no installed version of ${COMPSYMLINK}"
+  echo ''
+  if [ -n "${AUTO_INSTALL}" ]; then
+HANDLE_COMPSYMLINK="i"
+  else
+ask_answer_for_symbolic_link
+  fi
+  handle_symbolic_link
+  if [ -n "${AUTO_INSTALL}" -a $? -eq 2 ]; then
+AUTO_INSTALLED_FILES="${AUTO_INSTALLED_FILES}  
${DESTDIR}${COMPSYMLINK#.}
+"
+  fi
+fi
+  elif [ $(readlink ${COMPSYMLINK}) = $(readlink ${DESTDIR}${COMPSYMLINK#.}) 
]; then
+echo " *** Temp ${COMPSYMLINK} and installed are the same, deleting"
+rm ${COMPSYMLINK}
+  else
+if [ -n "${AUTO_RUN}" -a -z "${AUTO_UPGRADE}" ]; then
+  echo "   *** ${COMPSYMLINK} will remain for your consideration"
+  continue
+else
+  echo ''
+  echo " *** Target of temp symbolic link is differnt from that of 
installed one"
+  echo " Temp (${COMPSYMLINK}): $(readlink ${COMPSYMLINK})"
+  echo " Installed (${DESTDIR}${COMPSYMLINK#.})): $(readlink 
${DESTDIR}${COMPSYMLINK#.})"
+  echo ''
+  if [ -n "${AUTO_UPGRADE}" ]; then
+HANDLE_COMPSYMLINK="i"
+  else
+ask_answer_for_symbolic_link
+  fi
+  handle_symbolic_link
+  if [ -n "${AUTO_UPGRADE}" -a $? -eq 2 ]; then
+AUTO_UPGRADED_FILES="${AUTO_UPGRADED_FILES}  
${DESTDIR}${COMPSYMLINK#.}
+"
+  fi
+fi
+  fi
+done
+
 echo ''
 echo "*** Comparison complete"
 
@@ -1193,10 +1307,10 @@ fi
 
 echo ''
 
-TEST_FOR_FILES=`find ${TEMPROOT} -type f -size +0 2>/dev/null`
+TEST_FOR_FILES=`find ${TEMPROOT} -type f -size +0 -or -type l 2>/dev/null`
 if [ -n "${TEST_FOR_FILES}" ]; then
   echo "*** Files that remain for you to merge by hand:"
-  find "${TEMPROOT}" -type f -size +0 | sort
+  find "${TEMPROOT}" -type f -size +0 -or -type l | sort
   echo ''
 
   

svn commit: r367809 - head/contrib/elftoolchain/elfcopy

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

Log:
  When elftoolchain's objcopy (or strip) is rewriting a file in-place,
  make it create the temporary file in the same directory as the source
  file by default, instead of always using $TMPDIR or /tmp. If creating
  that file fails because the directory is not writable, also fallback to
  $TMPDIR or /tmp.
  
  This has also been submitted upstream as:
  https://sourceforge.net/p/elftoolchain/tickets/597/
  
  Reported by:  cem
  PR:   250872
  MFC after:2 weeks

Modified:
  head/contrib/elftoolchain/elfcopy/archive.c
  head/contrib/elftoolchain/elfcopy/elfcopy.h
  head/contrib/elftoolchain/elfcopy/main.c

Modified: head/contrib/elftoolchain/elfcopy/archive.c
==
--- head/contrib/elftoolchain/elfcopy/archive.c Wed Nov 18 17:50:33 2020
(r367808)
+++ head/contrib/elftoolchain/elfcopy/archive.c Wed Nov 18 18:40:58 2020
(r367809)
@@ -68,7 +68,7 @@ process_ar_obj(struct elfcopy *ecp, struct ar_obj *obj
int  fd;
 
/* Output to a temporary file. */
-   create_tempfile(, );
+   create_tempfile(NULL, , );
if ((ecp->eout = elf_begin(fd, ELF_C_WRITE, NULL)) == NULL)
errx(EXIT_FAILURE, "elf_begin() failed: %s",
elf_errmsg(-1));

Modified: head/contrib/elftoolchain/elfcopy/elfcopy.h
==
--- head/contrib/elftoolchain/elfcopy/elfcopy.h Wed Nov 18 17:50:33 2020
(r367808)
+++ head/contrib/elftoolchain/elfcopy/elfcopy.h Wed Nov 18 18:40:58 2020
(r367809)
@@ -298,7 +298,7 @@ voidcreate_scn(struct elfcopy *_ecp);
 void   create_srec(struct elfcopy *_ecp, int _ifd, int _ofd, const char *_ofn);
 void   create_symtab(struct elfcopy *_ecp);
 void   create_symtab_data(struct elfcopy *_ecp);
-void   create_tempfile(char **_fn, int *_fd);
+void   create_tempfile(const char *_src, char **_fn, int *_fd);
 void   finalize_external_symtab(struct elfcopy *_ecp);
 void   free_elf(struct elfcopy *_ecp);
 void   free_sec_act(struct elfcopy *_ecp);

Modified: head/contrib/elftoolchain/elfcopy/main.c
==
--- head/contrib/elftoolchain/elfcopy/main.cWed Nov 18 17:50:33 2020
(r367808)
+++ head/contrib/elftoolchain/elfcopy/main.cWed Nov 18 18:40:58 2020
(r367809)
@@ -512,44 +512,57 @@ free_elf(struct elfcopy *ecp)
 
 /* Create a temporary file. */
 void
-create_tempfile(char **fn, int *fd)
+create_tempfile(const char *src, char **fn, int *fd)
 {
+   static const char _TEMPDIR[] = "/tmp/";
+   static const char _TEMPFILE[] = "ecp.";
const char  *tmpdir;
-   char*cp, *tmpf;
-   size_t   tlen, plen;
+   char*tmpf;
+   size_t   tlen, slen, plen;
 
-#define_TEMPFILE "ecp."
-#define_TEMPFILEPATH "/tmp/ecp."
-
if (fn == NULL || fd == NULL)
return;
-   /* Repect TMPDIR environment variable. */
-   tmpdir = getenv("TMPDIR");
-   if (tmpdir != NULL && *tmpdir != '\0') {
-   tlen = strlen(tmpdir);
-   plen = strlen(_TEMPFILE);
-   tmpf = malloc(tlen + plen + 2);
+   for (;;) {
+   if (src == NULL) {
+   /* Respect TMPDIR environment variable. */
+   tmpdir = getenv("TMPDIR");
+   if (tmpdir == NULL || *tmpdir == '\0')
+   tmpdir = _TEMPDIR;
+   tlen = strlen(tmpdir);
+   slen = tmpdir[tlen - 1] == '/' ? 0 : 1;
+   } else {
+   /* Create temporary file relative to source file. */
+   if ((tmpdir = strrchr(src, '/')) == NULL) {
+   /* No path, only use a template filename. */
+   tlen = 0;
+   } else {
+   /* Append the template after the slash. */
+   tlen = ++tmpdir - src;
+   tmpdir = src;
+   }
+   slen = 0;
+   }
+   plen = strlen(_TEMPFILE) + 1;
+   tmpf = malloc(tlen + slen + plen);
if (tmpf == NULL)
err(EXIT_FAILURE, "malloc failed");
-   strncpy(tmpf, tmpdir, tlen);
-   cp = [tlen - 1];
-   if (*cp++ != '/')
-   *cp++ = '/';
-   strncpy(cp, _TEMPFILE, plen);
-   cp[plen] = '\0';
-   } else {
-   tmpf = strdup(_TEMPFILEPATH);
-   if (tmpf == NULL)
-   err(EXIT_FAILURE, "strdup 

svn commit: r367808 - vendor/NetBSD/bmake

2020-11-18 Thread Simon J. Gerraty
Author: sjg
Date: Wed Nov 18 17:50:33 2020
New Revision: 367808
URL: https://svnweb.freebsd.org/changeset/base/367808

Log:
  Retain missing/sys/cdefs.h to support build on non-FreeBSD

Modified:
  vendor/NetBSD/bmake/import.sh

Modified: vendor/NetBSD/bmake/import.sh
==
--- vendor/NetBSD/bmake/import.sh   Wed Nov 18 17:37:01 2020
(r367807)
+++ vendor/NetBSD/bmake/import.sh   Wed Nov 18 17:50:33 2020
(r367808)
@@ -65,7 +65,7 @@ tar zxf $TARBALL
 
 # steps unique to bmake
 VERSION=`grep '^_MAKE_VERSION' bmake/VERSION | sed 's,.*=[[:space:]]*,,'`
-rm -rf bmake/missing
+#rm -rf bmake/missing
 
 # the rest should be common
 ('cd' dist && $SVN list -R) | grep -v '/$' | sort > $TF.old
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r367807 - head/sys/mips/cavium

2020-11-18 Thread Justin Hibbits
Author: jhibbits
Date: Wed Nov 18 17:37:01 2020
New Revision: 367807
URL: https://svnweb.freebsd.org/changeset/base/367807

Log:
  Fix octeon_pmc post-r334827
  
  MFC after:3 days
  Sponsored by: Juniper Networks, Inc

Modified:
  head/sys/mips/cavium/octeon_pmc.c

Modified: head/sys/mips/cavium/octeon_pmc.c
==
--- head/sys/mips/cavium/octeon_pmc.c   Wed Nov 18 16:21:37 2020
(r367806)
+++ head/sys/mips/cavium/octeon_pmc.c   Wed Nov 18 17:37:01 2020
(r367807)
@@ -111,7 +111,7 @@ octeon_pmc_intr(void *arg)
struct trapframe *tf = PCPU_GET(curthread)->td_intr_frame;
 
if (pmc_intr)
-   (*pmc_intr)(PCPU_GET(tf);
+   (*pmc_intr)(tf);
 
return (FILTER_HANDLED);
 }
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r367806 - head/sys/kern

2020-11-18 Thread John Baldwin
Author: jhb
Date: Wed Nov 18 16:21:37 2020
New Revision: 367806
URL: https://svnweb.freebsd.org/changeset/base/367806

Log:
  Fix a few nits in vn_printf().
  
  - Mask out recently added VV_* bits to avoid printing them twice.
  
  - Keep VI_LOCKed on the same line as the rest of the flags.
  
  Reviewed by:  kib
  Obtained from:CheriBSD
  Sponsored by: DARPA
  Differential Revision:https://reviews.freebsd.org/D27261

Modified:
  head/sys/kern/vfs_subr.c

Modified: head/sys/kern/vfs_subr.c
==
--- head/sys/kern/vfs_subr.cWed Nov 18 15:25:38 2020(r367805)
+++ head/sys/kern/vfs_subr.cWed Nov 18 16:21:37 2020(r367806)
@@ -4080,8 +4080,9 @@ vn_printf(struct vnode *vp, const char *fmt, ...)
if (vp->v_vflag & VV_READLINK)
strlcat(buf, "|VV_READLINK", sizeof(buf));
flags = vp->v_vflag & ~(VV_ROOT | VV_ISTTY | VV_NOSYNC | VV_ETERNALDEV |
-   VV_CACHEDLABEL | VV_COPYONWRITE | VV_SYSTEM | VV_PROCDEP |
-   VV_NOKNOTE | VV_DELETED | VV_MD | VV_FORCEINSMQ);
+   VV_CACHEDLABEL | VV_VMSIZEVNLOCK | VV_COPYONWRITE | VV_SYSTEM |
+   VV_PROCDEP | VV_NOKNOTE | VV_DELETED | VV_MD | VV_FORCEINSMQ |
+   VV_READLINK);
if (flags != 0) {
snprintf(buf2, sizeof(buf2), "|VV(0x%lx)", flags);
strlcat(buf, buf2, sizeof(buf));
@@ -4109,9 +4110,10 @@ vn_printf(struct vnode *vp, const char *fmt, ...)
snprintf(buf2, sizeof(buf2), "|VMP(0x%lx)", flags);
strlcat(buf, buf2, sizeof(buf));
}
-   printf("flags (%s)\n", buf + 1);
+   printf("flags (%s)", buf + 1);
if (mtx_owned(VI_MTX(vp)))
printf(" VI_LOCKed");
+   printf("\n");
if (vp->v_object != NULL)
printf("v_object %p ref %d pages %d "
"cleanbuf %d dirtybuf %d\n",
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


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

2020-11-18 Thread Kyle Evans
On Tue, Nov 17, 2020 at 1:51 PM Brooks Davis  wrote:
>
> On Tue, Nov 17, 2020 at 11:59:50AM -0600, Kyle Evans wrote:
> > On Tue, Nov 17, 2020 at 11:11 AM Brooks Davis  wrote:
> > >
> > > On Tue, Nov 17, 2020 at 03:36:58AM +, Kyle Evans wrote:
> > > > Modified: head/sys/compat/freebsd32/freebsd32.h
> > > > ==
> > > > --- head/sys/compat/freebsd32/freebsd32.h Tue Nov 17 03:34:01 2020  
> > > >   (r367743)
> > > > +++ head/sys/compat/freebsd32/freebsd32.h Tue Nov 17 03:36:58 2020  
> > > >   (r367744)
> > > > @@ -94,6 +94,27 @@ struct itimerval32 {
> > > >   struct timeval32 it_value;
> > > >  };
> > > >
> > > > +struct umtx_time32 {
> > > > + struct  timespec32  _timeout;
> > > > + uint32_t_flags;
> > > > + uint32_t_clockid;
> > > > +};
> > > > +
> > > > +struct umtx_robust_lists_params_compat32 {
> > > > + uint32_trobust_list_offset;
> > > > + uint32_trobust_priv_list_offset;
> > > > + uint32_trobust_inact_offset;
> > > > +};
> > > > +
> > > > +struct umutex32 {
> > > > + volatile __lwpid_t  m_owner;/* Owner of the mutex */
> > > > + __uint32_t  m_flags;/* Flags of the mutex */
> > > > + __uint32_t  m_ceilings[2];  /* Priority protect 
> > > > ceiling */
> > > > + __uint32_t  m_rb_lnk;   /* Robust linkage */
> > > > + __uint32_t  m_pad;
> > > > + __uint32_t  m_spare[2];
> > > > +};
> > > > +
> > > >  #define FREEBSD4_MFSNAMELEN  16
> > > >  #define FREEBSD4_MNAMELEN(88 - 2 * sizeof(int32_t))
> > > >
> > > >
> > > > Modified: head/sys/compat/freebsd32/freebsd32_misc.c
> > > > ==
> > > > --- head/sys/compat/freebsd32/freebsd32_misc.cTue Nov 17 
> > > > 03:34:01 2020(r367743)
> > > > +++ head/sys/compat/freebsd32/freebsd32_misc.cTue Nov 17 
> > > > 03:36:58 2020(r367744)
> > > > @@ -84,6 +84,7 @@ __FBSDID("$FreeBSD$");
> > > >  #include 
> > > >  #include 
> > > >  #include 
> > > > +#include 
> > > >  #include 
> > > >  #include 
> > > >  #include 
> > > > @@ -3764,4 +3765,12 @@ freebsd32_sched_rr_get_interval(struct thread 
> > > > *td,
> > > >   error = copyout(, uap->interval, sizeof(ts32));
> > > >   }
> > > >   return (error);
> > > > +}
> > > > +
> > > > +int
> > > > +freebsd32__umtx_op(struct thread *td, struct freebsd32__umtx_op_args 
> > > > *uap)
> > > > +{
> > > > +
> > > > + return (kern__umtx_op(td, uap->obj, uap->op, uap->val, uap->uaddr,
> > > > + uap->uaddr2, _native_ops32));
> > > >  }
> > > >
> > >
> > > Putting any of this under compat/freebsd32 seems like a somewhat
> > > odd choice since all the work is done in kern_umtx.h.  In CheriBSD,
> > > everything just lives there so nothing has to be exposed in headers.
> > >
> >
> > I have no strong opinion here -- my initial impression of the
> > suggestion to move the struct definitions into freebsd32 was that:
> >
> > 1.) One can then quickly reference the definition of, e.g., timespec32
> > when I'm looking at a umtx_time32, and
> > 2.) It'd be 'cleaner', requiring less #ifdef soup in kern_umtx.c
> >
> > The follow-up patch muddies the waters a lot, as we end up using the
> > compat32 definitions on all 64-bit platforms anyways even without
> > compat32. I don't object to moving any/all of this back, if you think
> > that's better.
>
> (1) makes sense to me.  I'm less convinced of (2) especially given the
> followup.  As a rule, I've been removing compat bits from headers when
> they only need to be defined in a single .c file.  If nothing else, I
> don't like that it presents a somewhat-false implication that the
> interfaces are public (and there have been quite a few cases where they
> weren't correctly guarded with _KERNEL).
>

Sure- I've got this queued up:
https://people.freebsd.org/~kevans/umtx32.diff -> the next diff in
line will immediately remove that first COMPAT_FREEBSD32 block after
umtx_copyops is defined.

Thanks,

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


svn commit: r367805 - head/sys/dev/ena

2020-11-18 Thread Marcin Wojtas
Author: mw
Date: Wed Nov 18 15:25:38 2020
New Revision: 367805
URL: https://svnweb.freebsd.org/changeset/base/367805

Log:
  Update ENA driver version to v2.3.0
  
  The v2.3.0 introduces new ena_com layer, ENI metrics updates and SPDX
  license tags.
  
  Submitted by:   Michal Krawczyk 
  Obtained from:  Semihalf
  Sponsored by:   Amazon, Inc
  MFC after:  1 week
  Differential revision:  https://reviews.freebsd.org/D27120

Modified:
  head/sys/dev/ena/ena.h

Modified: head/sys/dev/ena/ena.h
==
--- head/sys/dev/ena/ena.h  Wed Nov 18 15:23:43 2020(r367804)
+++ head/sys/dev/ena/ena.h  Wed Nov 18 15:25:38 2020(r367805)
@@ -40,7 +40,7 @@
 #include "ena-com/ena_eth_com.h"
 
 #define DRV_MODULE_VER_MAJOR   2
-#define DRV_MODULE_VER_MINOR   2
+#define DRV_MODULE_VER_MINOR   3
 #define DRV_MODULE_VER_SUBMINOR 0
 
 #define DRV_MODULE_NAME"ena"
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r367804 - head/share/man/man4

2020-11-18 Thread Nick Hibma
Author: n_hibma
Date: Wed Nov 18 15:23:43 2020
New Revision: 367804
URL: https://svnweb.freebsd.org/changeset/base/367804

Log:
  Fix mandoc lint warnings.

Modified:
  head/share/man/man4/ng_tag.4

Modified: head/share/man/man4/ng_tag.4
==
--- head/share/man/man4/ng_tag.4Wed Nov 18 15:20:01 2020
(r367803)
+++ head/share/man/man4/ng_tag.4Wed Nov 18 15:23:43 2020
(r367804)
@@ -150,9 +150,7 @@ If
 .Va strip
 flag is non-zero, then found tag is deleted from list of packet tags.
 .It Dv NGM_TAG_GET_HOOKIN Pq Ic gethookin
-This command takes an
-.Tn ASCII
-string argument, the hook name, and returns the
+This command takes an ASCII string argument, the hook name, and returns the
 corresponding
 .Vt "struct ng_tag_hookin"
 as shown above.
@@ -176,22 +174,16 @@ Other variables mean basically the same as in
 .Vt "struct ng_tag_hookin"
 shown above, except used for setting values in a new tag.
 .It Dv NGM_TAG_GET_HOOKOUT Pq Ic gethookout
-This command takes an
-.Tn ASCII
-string argument, the hook name, and returns the
+This command takes an ASCII string argument, the hook name, and returns the
 corresponding
 .Vt "struct ng_tag_hookout"
 as shown above.
 .It Dv NGM_TAG_GET_STATS Pq Ic getstats
-This command takes an
-.Tn ASCII
-string argument, the hook name, and returns the
+This command takes an ASCII string argument, the hook name, and returns the
 statistics associated with the hook as a
 .Vt "struct ng_tag_hookstat" .
 .It Dv NGM_TAG_CLR_STATS Pq Ic clrstats
-This command takes an
-.Tn ASCII
-string argument, the hook name, and clears the
+This command takes an ASCII string argument, the hook name, and clears the
 statistics associated with the hook.
 .It Dv NGM_TAG_GETCLR_STATS Pq Ic getclrstats
 This command is identical to
@@ -199,7 +191,7 @@ This command is identical to
 except that the statistics are also atomically cleared.
 .El
 .Pp
-.Em Note:
+.Em Note :
 statistics counters as well as three statistics messages above work
 only if code was compiled with the
 .Dv NG_TAG_DEBUG
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


Re: svn commit: r367713 - head/sys/kern

2020-11-18 Thread Mateusz Guzik
On 11/18/20, Konstantin Belousov  wrote:
> On Tue, Nov 17, 2020 at 03:36:31PM +0100, Mateusz Guzik wrote:
>> On 11/17/20, Konstantin Belousov  wrote:
>> > On Tue, Nov 17, 2020 at 04:15:12AM +0100, Mateusz Guzik wrote:
>> >> On 11/17/20, Konstantin Belousov  wrote:
>> >> > On Mon, Nov 16, 2020 at 03:09:19AM +, Mateusz Guzik wrote:
>> >> >> Author: mjg
>> >> >> Date: Mon Nov 16 03:09:18 2020
>> >> >> New Revision: 367713
>> >> >> URL: https://svnweb.freebsd.org/changeset/base/367713
>> >> >>
>> >> >> Log:
>> >> >>   select: replace reference counting with memory barriers in selfd
>> >> >>
>> >> >>   Refcounting was added to combat a race between selfdfree and
>> >> >> doselwakup,
>> >> >>   but it adds avoidable overhead.
>> >> >>
>> >> >>   selfdfree detects it can free the object by ->sf_si == NULL, thus
>> >> >> we
>> >> >> can
>> >> >>   ensure that the condition only holds after all accesses are
>> >> >> completed.
>> >> >>
>> >> >> Modified:
>> >> >>   head/sys/kern/sys_generic.c
>> >> >>
>> >> >> Modified: head/sys/kern/sys_generic.c
>> >> >> ==
>> >> >> --- head/sys/kern/sys_generic.cSun Nov 15 22:49:28 2020
>> >> >> (r367712)
>> >> >> +++ head/sys/kern/sys_generic.cMon Nov 16 03:09:18 2020
>> >> >> (r367713)
>> >> >> @@ -156,7 +156,6 @@ struct selfd {
>> >> >>struct mtx  *sf_mtx;/* Pointer to selinfo 
>> >> >> mtx. */
>> >> >>struct seltd*sf_td; /* (k) owning seltd. */
>> >> >>void*sf_cookie; /* (k) fd or pollfd. */
>> >> >> -  u_int   sf_refs;
>> >> >>  };
>> >> >>
>> >> >>  MALLOC_DEFINE(M_SELFD, "selfd", "selfd");
>> >> >> @@ -1704,16 +1703,17 @@ static void
>> >> >>  selfdfree(struct seltd *stp, struct selfd *sfp)
>> >> >>  {
>> >> >>STAILQ_REMOVE(>st_selq, sfp, selfd, sf_link);
>> >> >> -  if (sfp->sf_si != NULL) {
>> >> >> +  /*
>> >> >> +   * Paired with doselwakeup.
>> >> >> +   */
>> >> >> +  if (atomic_load_acq_ptr((uintptr_t *)>sf_si) !=
>> >> >> (uintptr_t)NULL)
>> >> >> {
>> >> > This could be != 0.
>> >> >
>> >> >>mtx_lock(sfp->sf_mtx);
>> >> >>if (sfp->sf_si != NULL) {
>> >> >>TAILQ_REMOVE(>sf_si->si_tdlist, sfp, 
>> >> >> sf_threads);
>> >> >> -  refcount_release(>sf_refs);
>> >> >>}
>> >> >>mtx_unlock(sfp->sf_mtx);
>> >> >>}
>> >> >> -  if (refcount_release(>sf_refs))
>> >> >> -  free(sfp, M_SELFD);
>> >> >> +  free(sfp, M_SELFD);
>> >> > What guarantees that doselwakeup() finished with sfp ?
>> >> >
>> >>
>> >> Release semantics provided by atomic_store_rel_ptr -- it means the
>> >> NULL store is the last access, neither CPU nor the compiler are going
>> >> to reorder preceding loads/stores past it.
>> > It only guarantees that if we observed NULL as the result of load.
>> >
>>
>> If that did not happen selfdfree takes the lock. If the entry is still
>> there, it removes it and doselwakeup will not see it after it takes
>> the lock. If the entry is not there, doselwaekup is done with it
>> because it released the lock.
>
> I still do not understand it.  selfdfree() indeed takes sf_mtx and rechecks
> sf_si.  But what prevents doselwakeup() to store NULL into sf_si at any
> moment. e.g. after free() is done ? selfdfree() takes seltd mutex, not
> selinfo.
>

That's the same lock.

In selrecord:
mtxp = sip->si_mtx;
if (mtxp == NULL)
mtxp = mtx_pool_find(mtxpool_select, sip);

   /*
 * Initialize the sfp and queue it in the thread.
 */
sfp->sf_si = sip;
sfp->sf_mtx = mtxp;
STAILQ_INSERT_TAIL(>st_selq, sfp, sf_link);
/*
 * Now that we've locked the sip, check for initialization.
 */
mtx_lock(mtxp);
if (sip->si_mtx == NULL) {
sip->si_mtx = mtxp;
TAILQ_INIT(>si_tdlist);
}

Then doselwakeup mtx_lock(sip->si_mtx) serializes against mtx_lock(sfp->sf_mtx)

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


svn commit: r367803 - head/sys/dev/ena

2020-11-18 Thread Marcin Wojtas
Author: mw
Date: Wed Nov 18 15:20:01 2020
New Revision: 367803
URL: https://svnweb.freebsd.org/changeset/base/367803

Log:
  Rename descriptions of the supported ENA devices
  
  Some of the PCI ID were described as ENA with LLQ support - it's not
  fully accurate and because of that, their names were changed.
  
  Instead of LLQ, use RSERV0 for the description of those devices.
  
  Submitted by:   Michal Krawczyk 
  Obtained from:  Semihalf
  Sponsored by:   Amazon, Inc
  MFC after:  1 week
  Differential revision:  https://reviews.freebsd.org/D27119

Modified:
  head/sys/dev/ena/ena.c
  head/sys/dev/ena/ena.h

Modified: head/sys/dev/ena/ena.c
==
--- head/sys/dev/ena/ena.c  Wed Nov 18 15:17:55 2020(r367802)
+++ head/sys/dev/ena/ena.c  Wed Nov 18 15:20:01 2020(r367803)
@@ -179,9 +179,9 @@ static char ena_version[] = DEVICE_NAME DRV_MODULE_NAM
 
 static ena_vendor_info_t ena_vendor_info_array[] = {
 { PCI_VENDOR_ID_AMAZON, PCI_DEV_ID_ENA_PF, 0},
-{ PCI_VENDOR_ID_AMAZON, PCI_DEV_ID_ENA_LLQ_PF, 0},
+{ PCI_VENDOR_ID_AMAZON, PCI_DEV_ID_ENA_PF_RSERV0, 0},
 { PCI_VENDOR_ID_AMAZON, PCI_DEV_ID_ENA_VF, 0},
-{ PCI_VENDOR_ID_AMAZON, PCI_DEV_ID_ENA_LLQ_VF, 0},
+{ PCI_VENDOR_ID_AMAZON, PCI_DEV_ID_ENA_VF_RSERV0, 0},
 /* Last entry */
 { 0, 0, 0 }
 };

Modified: head/sys/dev/ena/ena.h
==
--- head/sys/dev/ena/ena.h  Wed Nov 18 15:17:55 2020(r367802)
+++ head/sys/dev/ena/ena.h  Wed Nov 18 15:20:01 2020(r367803)
@@ -150,10 +150,10 @@
  */
 #definePCI_VENDOR_ID_AMAZON0x1d0f
 
-#definePCI_DEV_ID_ENA_PF   0x0ec2
-#definePCI_DEV_ID_ENA_LLQ_PF   0x1ec2
-#definePCI_DEV_ID_ENA_VF   0xec20
-#definePCI_DEV_ID_ENA_LLQ_VF   0xec21
+#definePCI_DEV_ID_ENA_PF   0x0ec2
+#definePCI_DEV_ID_ENA_PF_RSERV00x1ec2
+#definePCI_DEV_ID_ENA_VF   0xec20
+#definePCI_DEV_ID_ENA_VF_RSERV00xec21
 
 /*
  * Flags indicating current ENA driver state
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r367802 - head/sys/dev/ena

2020-11-18 Thread Marcin Wojtas
Author: mw
Date: Wed Nov 18 15:17:55 2020
New Revision: 367802
URL: https://svnweb.freebsd.org/changeset/base/367802

Log:
  Add ENI metrics for the ENA driver
  
  The new HAL allows the driver to read extra ENI stats. Exact meaning of
  each of them can be found in base/ena_defs/ena_admin_defs.h file and
  structure ena_admin_eni_stats.
  
  Those stats are being updated inside of the timer service, which is
  executed every second.
  ENI metrics are turned off by default. They can be enabled, using the
  sysctl node: dev.ena.X.eni_metrics.update_delay
  0 value in this node means that the update is turned off. Other values
  determine how many seconds must pass, before ENI metrics will be
  updated.
  
  They can be acquired, using sysctl:
  
  sysctl dev.ena.X.eni_metrics
  
  Where X stands for the interface number.
  
  Submitted by:   Michal Krawczyk 
  Obtained from:  Semihalf
  Sponsored by:   Amazon, Inc
  MFC after:  1 week
  Differential revision: https://reviews.freebsd.org/D27118

Modified:
  head/sys/dev/ena/ena.c
  head/sys/dev/ena/ena.h
  head/sys/dev/ena/ena_sysctl.c

Modified: head/sys/dev/ena/ena.c
==
--- head/sys/dev/ena/ena.c  Wed Nov 18 15:07:34 2020(r367801)
+++ head/sys/dev/ena/ena.c  Wed Nov 18 15:17:55 2020(r367802)
@@ -172,6 +172,7 @@ static int  ena_enable_msix_and_set_admin_interrupts(st
 static void ena_update_on_link_change(void *, struct ena_admin_aenq_entry *);
 static voidunimplemented_aenq_handler(void *,
 struct ena_admin_aenq_entry *);
+static int ena_copy_eni_metrics(struct ena_adapter *);
 static voidena_timer_service(void *);
 
 static char ena_version[] = DEVICE_NAME DRV_MODULE_NAME " v" 
DRV_MODULE_VERSION;
@@ -3215,6 +3216,44 @@ static void ena_update_hints(struct ena_adapter *adapt
}
 }
 
+/**
+ * ena_copy_eni_metrics - Get and copy ENI metrics from the HW.
+ * @adapter: ENA device adapter
+ *
+ * Returns 0 on success, EOPNOTSUPP if current HW doesn't support those metrics
+ * and other error codes on failure.
+ *
+ * This function can possibly cause a race with other calls to the admin queue.
+ * Because of that, the caller should either lock this function or make sure
+ * that there is no race in the current context.
+ */
+static int
+ena_copy_eni_metrics(struct ena_adapter *adapter)
+{
+   static bool print_once = true;
+   int rc;
+
+   rc = ena_com_get_eni_stats(adapter->ena_dev, >eni_metrics);
+
+   if (rc != 0) {
+   if (rc == ENA_COM_UNSUPPORTED) {
+   if (print_once) {
+   device_printf(adapter->pdev,
+   "Retrieving ENI metrics is not 
supported.\n");
+   print_once = false;
+   } else {
+   ena_trace(NULL, ENA_DBG,
+   "Retrieving ENI metrics is not 
supported.\n");
+   }
+   } else {
+   device_printf(adapter->pdev,
+   "Failed to get ENI metrics: %d\n", rc);
+   }
+   }
+
+   return (rc);
+}
+
 static void
 ena_timer_service(void *data)
 {
@@ -3229,6 +3268,38 @@ ena_timer_service(void *data)
check_for_missing_completions(adapter);
 
check_for_empty_rx_ring(adapter);
+
+   /*
+* User controller update of the ENI metrics.
+* If the delay was set to 0, then the stats shouldn't be updated at
+* all.
+* Otherwise, wait 'eni_metrics_sample_interval' seconds, before
+* updating stats.
+* As timer service is executed every second, it's enough to increment
+* appropriate counter each time the timer service is executed.
+*/
+   if ((adapter->eni_metrics_sample_interval != 0) &&
+   (++adapter->eni_metrics_sample_interval_cnt >=
+adapter->eni_metrics_sample_interval)) {
+   /*
+* There is no race with other admin queue calls, as:
+*   - Timer service runs after interface is up, so all
+* configuration calls to the admin queue are finished.
+*   - After interface is up, the driver doesn't use (at least
+* for now) other functions writing to the admin queue.
+*
+* It may change in the future, so in that situation, the lock
+* will be needed. ENA_LOCK_*() cannot be used for that purpose,
+* as callout ena_timer_service is protected by them. It could
+* lead to the deadlock if callout_drain() would hold the lock
+* before ena_copy_eni_metrics() was executed. It's advised to
+* use separate lock in that situation which will be used only
+* for the admin queue.
+*/
+   

svn commit: r367801 - in head: share/man/man4 sys/dev/ena sys/modules/ena

2020-11-18 Thread Marcin Wojtas
Author: mw
Date: Wed Nov 18 15:07:34 2020
New Revision: 367801
URL: https://svnweb.freebsd.org/changeset/base/367801

Log:
  Add SPDX license tag to the ENA driver files
  
  Refering to guide: https://wiki.freebsd.org/SPDX the SPDX tag should not
  replace the standard license text, however it should be added over the
  standard license text to make the automation easier.
  
  Because of that, the old license was kept, but the SPDX tag was added
  on top of every ENA driver file.
  
  Submited by:Michal Krawczyk 
  Obtained from:  Semihalf
  Sponsored by:   Amazon, Inc
  MFC after:  1 week
  Differential revision:  https://reviews.freebsd.org/D27117

Modified:
  head/share/man/man4/ena.4
  head/sys/dev/ena/ena.c
  head/sys/dev/ena/ena.h
  head/sys/dev/ena/ena_datapath.c
  head/sys/dev/ena/ena_datapath.h
  head/sys/dev/ena/ena_netmap.c
  head/sys/dev/ena/ena_netmap.h
  head/sys/dev/ena/ena_sysctl.c
  head/sys/dev/ena/ena_sysctl.h
  head/sys/modules/ena/Makefile

Modified: head/share/man/man4/ena.4
==
--- head/share/man/man4/ena.4   Wed Nov 18 15:02:12 2020(r367800)
+++ head/share/man/man4/ena.4   Wed Nov 18 15:07:34 2020(r367801)
@@ -1,4 +1,6 @@
-.\" Copyright (c) 2015-2017 Amazon.com, Inc. or its affiliates.
+.\" SPDX-License-Identifier: BSD-2-Clause
+.\"
+.\" Copyright (c) 2015-2020 Amazon.com, Inc. or its affiliates.
 .\" All rights reserved.
 .\"
 .\" Redistribution and use in source and binary forms, with or without

Modified: head/sys/dev/ena/ena.c
==
--- head/sys/dev/ena/ena.c  Wed Nov 18 15:02:12 2020(r367800)
+++ head/sys/dev/ena/ena.c  Wed Nov 18 15:07:34 2020(r367801)
@@ -1,5 +1,5 @@
 /*-
- * BSD LICENSE
+ * SPDX-License-Identifier: BSD-2-Clause
  *
  * Copyright (c) 2015-2020 Amazon.com, Inc. or its affiliates.
  * All rights reserved.

Modified: head/sys/dev/ena/ena.h
==
--- head/sys/dev/ena/ena.h  Wed Nov 18 15:02:12 2020(r367800)
+++ head/sys/dev/ena/ena.h  Wed Nov 18 15:07:34 2020(r367801)
@@ -1,5 +1,5 @@
 /*-
- * BSD LICENSE
+ * SPDX-License-Identifier: BSD-2-Clause
  *
  * Copyright (c) 2015-2020 Amazon.com, Inc. or its affiliates.
  * All rights reserved.

Modified: head/sys/dev/ena/ena_datapath.c
==
--- head/sys/dev/ena/ena_datapath.c Wed Nov 18 15:02:12 2020
(r367800)
+++ head/sys/dev/ena/ena_datapath.c Wed Nov 18 15:07:34 2020
(r367801)
@@ -1,5 +1,5 @@
 /*-
- * BSD LICENSE
+ * SPDX-License-Identifier: BSD-2-Clause
  *
  * Copyright (c) 2015-2020 Amazon.com, Inc. or its affiliates.
  * All rights reserved.

Modified: head/sys/dev/ena/ena_datapath.h
==
--- head/sys/dev/ena/ena_datapath.h Wed Nov 18 15:02:12 2020
(r367800)
+++ head/sys/dev/ena/ena_datapath.h Wed Nov 18 15:07:34 2020
(r367801)
@@ -1,5 +1,5 @@
 /*-
- * BSD LICENSE
+ * SPDX-License-Identifier: BSD-2-Clause
  *
  * Copyright (c) 2015-2020 Amazon.com, Inc. or its affiliates.
  * All rights reserved.

Modified: head/sys/dev/ena/ena_netmap.c
==
--- head/sys/dev/ena/ena_netmap.c   Wed Nov 18 15:02:12 2020
(r367800)
+++ head/sys/dev/ena/ena_netmap.c   Wed Nov 18 15:07:34 2020
(r367801)
@@ -1,5 +1,5 @@
 /*-
- * BSD LICENSE
+ * SPDX-License-Identifier: BSD-2-Clause
  *
  * Copyright (c) 2015-2020 Amazon.com, Inc. or its affiliates.
  * All rights reserved.

Modified: head/sys/dev/ena/ena_netmap.h
==
--- head/sys/dev/ena/ena_netmap.h   Wed Nov 18 15:02:12 2020
(r367800)
+++ head/sys/dev/ena/ena_netmap.h   Wed Nov 18 15:07:34 2020
(r367801)
@@ -1,5 +1,5 @@
 /*-
- * BSD LICENSE
+ * SPDX-License-Identifier: BSD-2-Clause
  *
  * Copyright (c) 2015-2020 Amazon.com, Inc. or its affiliates.
  * All rights reserved.

Modified: head/sys/dev/ena/ena_sysctl.c
==
--- head/sys/dev/ena/ena_sysctl.c   Wed Nov 18 15:02:12 2020
(r367800)
+++ head/sys/dev/ena/ena_sysctl.c   Wed Nov 18 15:07:34 2020
(r367801)
@@ -1,5 +1,5 @@
 /*-
- * BSD LICENSE
+ * SPDX-License-Identifier: BSD-2-Clause
  *
  * Copyright (c) 2015-2020 Amazon.com, Inc. or its affiliates.
  * All rights reserved.

Modified: head/sys/dev/ena/ena_sysctl.h
==
--- head/sys/dev/ena/ena_sysctl.h   Wed Nov 18 15:02:12 2020
(r367800)
+++ head/sys/dev/ena/ena_sysctl.h   Wed Nov 18 15:07:34 2020
(r367801)
@@ -1,5 

svn commit: r367800 - head/sys/dev/ena

2020-11-18 Thread Marcin Wojtas
Author: mw
Date: Wed Nov 18 15:02:12 2020
New Revision: 367800
URL: https://svnweb.freebsd.org/changeset/base/367800

Log:
  Add Rx offsets support for the ENA driver
  
  For the first descriptor in a chain the data may start at an offset.
  It is optional feature of some devices, so the driver must ack that
  it supports it.
  
  The data pointer of the mbuf is simply shifted by the given value.
  
  Submitted by:   Maciej Bielski 
  Submitted by:   Michal Krawczyk 
  Obtained from:  Semihalf
  Sponsored by:   Amazon, Inc
  MFC after:  1 week
  Differential revision:  https://reviews.freebsd.org/D27116

Modified:
  head/sys/dev/ena/ena.c
  head/sys/dev/ena/ena_datapath.c

Modified: head/sys/dev/ena/ena.c
==
--- head/sys/dev/ena/ena.c  Wed Nov 18 14:59:22 2020(r367799)
+++ head/sys/dev/ena/ena.c  Wed Nov 18 15:02:12 2020(r367800)
@@ -2797,6 +2797,8 @@ ena_config_host_info(struct ena_com_dev *ena_dev, devi
(DRV_MODULE_VER_MINOR << ENA_ADMIN_HOST_INFO_MINOR_SHIFT) |
(DRV_MODULE_VER_SUBMINOR << 
ENA_ADMIN_HOST_INFO_SUB_MINOR_SHIFT);
host_info->num_cpus = mp_ncpus;
+   host_info->driver_supported_features =
+   ENA_ADMIN_HOST_INFO_RX_OFFSET_MASK;
 
rc = ena_com_set_host_attributes(ena_dev);
if (unlikely(rc != 0)) {

Modified: head/sys/dev/ena/ena_datapath.c
==
--- head/sys/dev/ena/ena_datapath.c Wed Nov 18 14:59:22 2020
(r367799)
+++ head/sys/dev/ena/ena_datapath.c Wed Nov 18 15:02:12 2020
(r367800)
@@ -431,6 +431,10 @@ ena_rx_mbuf(struct ena_ring *rx_ring, struct ena_com_r
mbuf->m_flags |= M_PKTHDR;
mbuf->m_pkthdr.len = len;
mbuf->m_len = len;
+   // Only for the first segment the data starts at specific offset
+   mbuf->m_data = mtodo(mbuf, ena_rx_ctx->pkt_offset);
+   ena_trace(NULL, ENA_DBG | ENA_RXPTH,
+   "Mbuf data offset=%u\n", ena_rx_ctx->pkt_offset);
mbuf->m_pkthdr.rcvif = rx_ring->que->adapter->ifp;
 
/* Fill mbuf with hash key and it's interpretation for optimization */
@@ -575,6 +579,8 @@ ena_rx_cleanup(struct ena_ring *rx_ring)
ena_rx_ctx.ena_bufs = rx_ring->ena_bufs;
ena_rx_ctx.max_bufs = adapter->max_rx_sgl_size;
ena_rx_ctx.descs = 0;
+   ena_rx_ctx.pkt_offset = 0;
+
bus_dmamap_sync(io_cq->cdesc_addr.mem_handle.tag,
io_cq->cdesc_addr.mem_handle.map, BUS_DMASYNC_POSTREAD);
rc = ena_com_rx_pkt(io_cq, io_sq, _rx_ctx);
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r367799 - in head/sys: contrib/ena-com contrib/ena-com/ena_defs dev/ena

2020-11-18 Thread Marcin Wojtas
Author: mw
Date: Wed Nov 18 14:59:22 2020
New Revision: 367799
URL: https://svnweb.freebsd.org/changeset/base/367799

Log:
  Adjust ENA driver files to latest ena-com changes
  
  * Use the new API of ena_trace_*
  * Fix typo syndrom --> syndrome
  * Remove validation of the Rx req ID (already performed in the ena-com)
  * Remove usage of deprecated ENA_ASSERT macro
  
  Submitted by:   Ido Segev 
  Submitted by:   Michal Krawczyk 
  Obtained from:  Semihalf
  Sponsored by:   Amazon, Inc
  MFC after:  1 week
  Differential revision:  https://reviews.freebsd.org/D27115

Modified:
  head/sys/contrib/ena-com/ena_com.c
  head/sys/contrib/ena-com/ena_com.h
  head/sys/contrib/ena-com/ena_defs/ena_admin_defs.h
  head/sys/contrib/ena-com/ena_defs/ena_common_defs.h
  head/sys/contrib/ena-com/ena_defs/ena_eth_io_defs.h
  head/sys/contrib/ena-com/ena_defs/ena_gen_info.h
  head/sys/contrib/ena-com/ena_defs/ena_regs_defs.h
  head/sys/contrib/ena-com/ena_eth_com.c
  head/sys/contrib/ena-com/ena_eth_com.h
  head/sys/contrib/ena-com/ena_plat.h
  head/sys/dev/ena/ena.c
  head/sys/dev/ena/ena.h
  head/sys/dev/ena/ena_datapath.c
  head/sys/dev/ena/ena_netmap.c
Directory Properties:
  head/sys/contrib/ena-com/   (props changed)

Modified: head/sys/contrib/ena-com/ena_com.c
==
--- head/sys/contrib/ena-com/ena_com.c  Wed Nov 18 14:55:49 2020
(r367798)
+++ head/sys/contrib/ena-com/ena_com.c  Wed Nov 18 14:59:22 2020
(r367799)
@@ -1,5 +1,5 @@
 /*-
- * BSD LICENSE
+ * SPDX-License-Identifier: BSD-3-Clause
  *
  * Copyright (c) 2015-2020 Amazon.com, Inc. or its affiliates.
  * All rights reserved.
@@ -70,9 +70,9 @@
 
 #define ENA_REGS_ADMIN_INTR_MASK 1
 
-#define ENA_MIN_POLL_US 100
+#define ENA_MIN_ADMIN_POLL_US 100
 
-#define ENA_MAX_POLL_US 5000
+#define ENA_MAX_ADMIN_POLL_US 5000
 
 /*/
 /*/
@@ -106,7 +106,7 @@ static int ena_com_mem_addr_set(struct ena_com_dev *en
   dma_addr_t addr)
 {
if ((addr & GENMASK_ULL(ena_dev->dma_addr_bits - 1, 0)) != addr) {
-   ena_trc_err("dma address has more bits that the device 
supports\n");
+   ena_trc_err(ena_dev, "DMA address has more bits that the device 
supports\n");
return ENA_COM_INVAL;
}
 
@@ -116,16 +116,17 @@ static int ena_com_mem_addr_set(struct ena_com_dev *en
return 0;
 }
 
-static int ena_com_admin_init_sq(struct ena_com_admin_queue *queue)
+static int ena_com_admin_init_sq(struct ena_com_admin_queue *admin_queue)
 {
-   struct ena_com_admin_sq *sq = >sq;
-   u16 size = ADMIN_SQ_SIZE(queue->q_depth);
+   struct ena_com_dev *ena_dev = admin_queue->ena_dev;
+   struct ena_com_admin_sq *sq = _queue->sq;
+   u16 size = ADMIN_SQ_SIZE(admin_queue->q_depth);
 
-   ENA_MEM_ALLOC_COHERENT(queue->q_dmadev, size, sq->entries, sq->dma_addr,
+   ENA_MEM_ALLOC_COHERENT(admin_queue->q_dmadev, size, sq->entries, 
sq->dma_addr,
   sq->mem_handle);
 
if (!sq->entries) {
-   ena_trc_err("memory allocation failed\n");
+   ena_trc_err(ena_dev, "Memory allocation failed\n");
return ENA_COM_NO_MEM;
}
 
@@ -138,16 +139,17 @@ static int ena_com_admin_init_sq(struct ena_com_admin_
return 0;
 }
 
-static int ena_com_admin_init_cq(struct ena_com_admin_queue *queue)
+static int ena_com_admin_init_cq(struct ena_com_admin_queue *admin_queue)
 {
-   struct ena_com_admin_cq *cq = >cq;
-   u16 size = ADMIN_CQ_SIZE(queue->q_depth);
+   struct ena_com_dev *ena_dev = admin_queue->ena_dev;
+   struct ena_com_admin_cq *cq = _queue->cq;
+   u16 size = ADMIN_CQ_SIZE(admin_queue->q_depth);
 
-   ENA_MEM_ALLOC_COHERENT(queue->q_dmadev, size, cq->entries, cq->dma_addr,
+   ENA_MEM_ALLOC_COHERENT(admin_queue->q_dmadev, size, cq->entries, 
cq->dma_addr,
   cq->mem_handle);
 
if (!cq->entries)  {
-   ena_trc_err("memory allocation failed\n");
+   ena_trc_err(ena_dev, "Memory allocation failed\n");
return ENA_COM_NO_MEM;
}
 
@@ -157,22 +159,22 @@ static int ena_com_admin_init_cq(struct ena_com_admin_
return 0;
 }
 
-static int ena_com_admin_init_aenq(struct ena_com_dev *dev,
+static int ena_com_admin_init_aenq(struct ena_com_dev *ena_dev,
   struct ena_aenq_handlers *aenq_handlers)
 {
-   struct ena_com_aenq *aenq = >aenq;
+   struct ena_com_aenq *aenq = _dev->aenq;
u32 addr_low, addr_high, aenq_caps;
u16 size;
 
-   dev->aenq.q_depth = ENA_ASYNC_QUEUE_DEPTH;
+   ena_dev->aenq.q_depth = ENA_ASYNC_QUEUE_DEPTH;
size = ADMIN_AENQ_SIZE(ENA_ASYNC_QUEUE_DEPTH);
-   

svn commit: r367797 - head/sys/net

2020-11-18 Thread Andrew Gallatin
Author: gallatin
Date: Wed Nov 18 14:55:49 2020
New Revision: 367797
URL: https://svnweb.freebsd.org/changeset/base/367797

Log:
  LACP: When suppressing distributing, return ENOBUFS
  
  When links come and go, lacp goes into a "suppress distributing" mode
  where it drops traffic for 3 seconds. When in this mode, lagg/lacp
  historiclally drops traffic with ENETDOWN. That return value causes TCP
  to close any connection where it gets that value back from the lower
  parts of the stack.  This means that any TCP connection with active
  traffic during a 3-second windown when an LACP link comes or goes
  would get closed.
  
  TCP treats return values of ENOBUFS as transient errors, and re-schedules
  transmission later. So rather than returning ENETDOWN, lets
  return ENOBUFS instead.  This allows TCP connections to be preserved.
  
  I've tested this by repeatedly bouncing links on a Netlfix CDN server
  under a moderate (20Gb/s) load and overved ENOBUFS reported back to
  the TCP stack (as reported by a RACK TCP sysctl).
  
  Reviewed by:  jhb, jtl, rrs
  Sponsored by: Netflix
  Differential Revision:https://reviews.freebsd.org/D27188

Modified:
  head/sys/net/ieee8023ad_lacp.c
  head/sys/net/ieee8023ad_lacp.h
  head/sys/net/if_lagg.c

Modified: head/sys/net/ieee8023ad_lacp.c
==
--- head/sys/net/ieee8023ad_lacp.c  Wed Nov 18 14:54:55 2020
(r367796)
+++ head/sys/net/ieee8023ad_lacp.c  Wed Nov 18 14:55:49 2020
(r367797)
@@ -832,7 +832,8 @@ lacp_stop(struct lagg_softc *sc)
 }
 
 struct lagg_port *
-lacp_select_tx_port_by_hash(struct lagg_softc *sc, uint32_t hash, uint8_t 
numa_domain)
+lacp_select_tx_port_by_hash(struct lagg_softc *sc, uint32_t hash,
+uint8_t numa_domain, int *err)
 {
struct lacp_softc *lsc = LACP_SOFTC(sc);
struct lacp_portmap *pm;
@@ -842,12 +843,14 @@ lacp_select_tx_port_by_hash(struct lagg_softc *sc, uin
 
if (__predict_false(lsc->lsc_suppress_distributing)) {
LACP_DPRINTF((NULL, "%s: waiting transit\n", __func__));
+   *err = ENOBUFS;
return (NULL);
}
 
pm = >lsc_pmap[lsc->lsc_activemap];
if (pm->pm_count == 0) {
LACP_DPRINTF((NULL, "%s: no active aggregator\n", __func__));
+   *err = ENETDOWN;
return (NULL);
}
 
@@ -879,7 +882,7 @@ lacp_select_tx_port_by_hash(struct lagg_softc *sc, uin
 }
 
 struct lagg_port *
-lacp_select_tx_port(struct lagg_softc *sc, struct mbuf *m)
+lacp_select_tx_port(struct lagg_softc *sc, struct mbuf *m, int *err)
 {
struct lacp_softc *lsc = LACP_SOFTC(sc);
uint32_t hash;
@@ -892,7 +895,7 @@ lacp_select_tx_port(struct lagg_softc *sc, struct mbuf
hash = m_ether_tcpip_hash(sc->sc_flags, m, lsc->lsc_hashkey);
 
numa_domain = m->m_pkthdr.numa_domain;
-   return (lacp_select_tx_port_by_hash(sc, hash, numa_domain));
+   return (lacp_select_tx_port_by_hash(sc, hash, numa_domain, err));
 }
 
 /*

Modified: head/sys/net/ieee8023ad_lacp.h
==
--- head/sys/net/ieee8023ad_lacp.h  Wed Nov 18 14:54:55 2020
(r367796)
+++ head/sys/net/ieee8023ad_lacp.h  Wed Nov 18 14:55:49 2020
(r367797)
@@ -292,8 +292,10 @@ struct lacp_softc {
 #define LACP_LOCK_ASSERT(_lsc) mtx_assert(&(_lsc)->lsc_mtx, MA_OWNED)
 
 struct mbuf*lacp_input(struct lagg_port *, struct mbuf *);
-struct lagg_port *lacp_select_tx_port(struct lagg_softc *, struct mbuf *);
-struct lagg_port *lacp_select_tx_port_by_hash(struct lagg_softc *, uint32_t, 
uint8_t);
+struct lagg_port *lacp_select_tx_port(struct lagg_softc *, struct mbuf *,
+int *);
+struct lagg_port *lacp_select_tx_port_by_hash(struct lagg_softc *, uint32_t,
+uint8_t, int *);
 void   lacp_attach(struct lagg_softc *);
 void   lacp_detach(void *);
 void   lacp_init(struct lagg_softc *);

Modified: head/sys/net/if_lagg.c
==
--- head/sys/net/if_lagg.c  Wed Nov 18 14:54:55 2020(r367796)
+++ head/sys/net/if_lagg.c  Wed Nov 18 14:55:49 2020(r367797)
@@ -1763,6 +1763,7 @@ lookup_snd_tag_port(struct ifnet *ifp, uint32_t flowid
struct lagg_port *lp;
struct lagg_lb *lb;
uint32_t hash, p;
+   int err;
 
sc = ifp->if_softc;
 
@@ -1783,7 +1784,7 @@ lookup_snd_tag_port(struct ifnet *ifp, uint32_t flowid
flowtype == M_HASHTYPE_NONE)
return (NULL);
hash = flowid >> sc->flowid_shift;
-   return (lacp_select_tx_port_by_hash(sc, hash, numa_domain));
+   return (lacp_select_tx_port_by_hash(sc, hash, numa_domain, 
));
default:
return (NULL);
}
@@ -2580,12 +2581,13 @@ static int
 

svn commit: r367798 - vendor-sys/ena-com/2.3.0

2020-11-18 Thread Marcin Wojtas
Author: mw
Date: Wed Nov 18 14:55:49 2020
New Revision: 367798
URL: https://svnweb.freebsd.org/changeset/base/367798

Log:
  Upgrade ENA HAL to v2.3.0
  
  Sponsored by: Amazon, Inc.

Added:
  vendor-sys/ena-com/2.3.0/
 - copied from r367796, vendor-sys/ena-com/dist/
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r367796 - in vendor-sys/ena-com/dist: . ena_defs

2020-11-18 Thread Marcin Wojtas
Author: mw
Date: Wed Nov 18 14:54:55 2020
New Revision: 367796
URL: https://svnweb.freebsd.org/changeset/base/367796

Log:
  Upgrade ENA HAL to the latest version (26/10/20)
  
  Add support for the ENI metrics, bug fix for destroying wait event and
  also other minor bug fixes, improvements, etc.
  
  Submitted by:   Ido Segev 
  Obtained from:  Amazon, Inc.

Modified:
  vendor-sys/ena-com/dist/ena_com.c
  vendor-sys/ena-com/dist/ena_com.h
  vendor-sys/ena-com/dist/ena_defs/ena_admin_defs.h
  vendor-sys/ena-com/dist/ena_defs/ena_common_defs.h
  vendor-sys/ena-com/dist/ena_defs/ena_eth_io_defs.h
  vendor-sys/ena-com/dist/ena_defs/ena_gen_info.h
  vendor-sys/ena-com/dist/ena_defs/ena_regs_defs.h
  vendor-sys/ena-com/dist/ena_eth_com.c
  vendor-sys/ena-com/dist/ena_eth_com.h
  vendor-sys/ena-com/dist/ena_plat.h

Modified: vendor-sys/ena-com/dist/ena_com.c
==
--- vendor-sys/ena-com/dist/ena_com.c   Wed Nov 18 14:50:12 2020
(r367795)
+++ vendor-sys/ena-com/dist/ena_com.c   Wed Nov 18 14:54:55 2020
(r367796)
@@ -1,5 +1,5 @@
 /*-
- * BSD LICENSE
+ * SPDX-License-Identifier: BSD-3-Clause
  *
  * Copyright (c) 2015-2020 Amazon.com, Inc. or its affiliates.
  * All rights reserved.
@@ -70,9 +70,9 @@
 
 #define ENA_REGS_ADMIN_INTR_MASK 1
 
-#define ENA_MIN_POLL_US 100
+#define ENA_MIN_ADMIN_POLL_US 100
 
-#define ENA_MAX_POLL_US 5000
+#define ENA_MAX_ADMIN_POLL_US 5000
 
 /*/
 /*/
@@ -106,7 +106,7 @@ static int ena_com_mem_addr_set(struct ena_com_dev *en
   dma_addr_t addr)
 {
if ((addr & GENMASK_ULL(ena_dev->dma_addr_bits - 1, 0)) != addr) {
-   ena_trc_err("dma address has more bits that the device 
supports\n");
+   ena_trc_err(ena_dev, "DMA address has more bits that the device 
supports\n");
return ENA_COM_INVAL;
}
 
@@ -116,16 +116,17 @@ static int ena_com_mem_addr_set(struct ena_com_dev *en
return 0;
 }
 
-static int ena_com_admin_init_sq(struct ena_com_admin_queue *queue)
+static int ena_com_admin_init_sq(struct ena_com_admin_queue *admin_queue)
 {
-   struct ena_com_admin_sq *sq = >sq;
-   u16 size = ADMIN_SQ_SIZE(queue->q_depth);
+   struct ena_com_dev *ena_dev = admin_queue->ena_dev;
+   struct ena_com_admin_sq *sq = _queue->sq;
+   u16 size = ADMIN_SQ_SIZE(admin_queue->q_depth);
 
-   ENA_MEM_ALLOC_COHERENT(queue->q_dmadev, size, sq->entries, sq->dma_addr,
+   ENA_MEM_ALLOC_COHERENT(admin_queue->q_dmadev, size, sq->entries, 
sq->dma_addr,
   sq->mem_handle);
 
if (!sq->entries) {
-   ena_trc_err("memory allocation failed\n");
+   ena_trc_err(ena_dev, "Memory allocation failed\n");
return ENA_COM_NO_MEM;
}
 
@@ -138,16 +139,17 @@ static int ena_com_admin_init_sq(struct ena_com_admin_
return 0;
 }
 
-static int ena_com_admin_init_cq(struct ena_com_admin_queue *queue)
+static int ena_com_admin_init_cq(struct ena_com_admin_queue *admin_queue)
 {
-   struct ena_com_admin_cq *cq = >cq;
-   u16 size = ADMIN_CQ_SIZE(queue->q_depth);
+   struct ena_com_dev *ena_dev = admin_queue->ena_dev;
+   struct ena_com_admin_cq *cq = _queue->cq;
+   u16 size = ADMIN_CQ_SIZE(admin_queue->q_depth);
 
-   ENA_MEM_ALLOC_COHERENT(queue->q_dmadev, size, cq->entries, cq->dma_addr,
+   ENA_MEM_ALLOC_COHERENT(admin_queue->q_dmadev, size, cq->entries, 
cq->dma_addr,
   cq->mem_handle);
 
if (!cq->entries)  {
-   ena_trc_err("memory allocation failed\n");
+   ena_trc_err(ena_dev, "Memory allocation failed\n");
return ENA_COM_NO_MEM;
}
 
@@ -157,22 +159,22 @@ static int ena_com_admin_init_cq(struct ena_com_admin_
return 0;
 }
 
-static int ena_com_admin_init_aenq(struct ena_com_dev *dev,
+static int ena_com_admin_init_aenq(struct ena_com_dev *ena_dev,
   struct ena_aenq_handlers *aenq_handlers)
 {
-   struct ena_com_aenq *aenq = >aenq;
+   struct ena_com_aenq *aenq = _dev->aenq;
u32 addr_low, addr_high, aenq_caps;
u16 size;
 
-   dev->aenq.q_depth = ENA_ASYNC_QUEUE_DEPTH;
+   ena_dev->aenq.q_depth = ENA_ASYNC_QUEUE_DEPTH;
size = ADMIN_AENQ_SIZE(ENA_ASYNC_QUEUE_DEPTH);
-   ENA_MEM_ALLOC_COHERENT(dev->dmadev, size,
+   ENA_MEM_ALLOC_COHERENT(ena_dev->dmadev, size,
aenq->entries,
aenq->dma_addr,
aenq->mem_handle);
 
if (!aenq->entries) {
-   ena_trc_err("memory allocation failed\n");
+   ena_trc_err(ena_dev, "Memory allocation failed\n");
return ENA_COM_NO_MEM;
}

svn commit: r367795 - in head/sys: contrib/ena-com dev/ena

2020-11-18 Thread Marcin Wojtas
Author: mw
Date: Wed Nov 18 14:50:12 2020
New Revision: 367795
URL: https://svnweb.freebsd.org/changeset/base/367795

Log:
  Fix completion descriptors alignment for the ENA
  
  The latest generation hardware requires IO CQ (completion queue)
  descriptors memory to be aligned to a 4K. It needs that feature for
  the best performance.
  
  Allocating unaligned descriptors will have a big performance impact as
  the packet processing in a HW won't be optimized properly. For that
  purpose adjust ena_dma_alloc() to support it.
  
  It's a critical fix, especially for the arm64 EC2 instances.
  
  Submitted by: Ido Segev 
  Obtained from: Amazon, Inc
  MFC after: 1 week
  Differential revision:  https://reviews.freebsd.org/D27114

Modified:
  head/sys/contrib/ena-com/ena_com.c
  head/sys/contrib/ena-com/ena_com.h
  head/sys/contrib/ena-com/ena_plat.h
  head/sys/dev/ena/ena.c
Directory Properties:
  head/sys/contrib/ena-com/   (props changed)

Modified: head/sys/contrib/ena-com/ena_com.c
==
--- head/sys/contrib/ena-com/ena_com.c  Wed Nov 18 14:32:48 2020
(r367794)
+++ head/sys/contrib/ena-com/ena_com.c  Wed Nov 18 14:50:12 2020
(r367795)
@@ -449,19 +449,21 @@ static int ena_com_init_io_cq(struct ena_com_dev *ena_
size = io_cq->cdesc_entry_size_in_bytes * io_cq->q_depth;
io_cq->bus = ena_dev->bus;
 
-   ENA_MEM_ALLOC_COHERENT_NODE(ena_dev->dmadev,
-   size,
-   io_cq->cdesc_addr.virt_addr,
-   io_cq->cdesc_addr.phys_addr,
-   io_cq->cdesc_addr.mem_handle,
-   ctx->numa_node,
-   prev_node);
+   ENA_MEM_ALLOC_COHERENT_NODE_ALIGNED(ena_dev->dmadev,
+   size,
+   io_cq->cdesc_addr.virt_addr,
+   io_cq->cdesc_addr.phys_addr,
+   io_cq->cdesc_addr.mem_handle,
+   ctx->numa_node,
+   prev_node,
+   ENA_CDESC_RING_SIZE_ALIGNMENT);
if (!io_cq->cdesc_addr.virt_addr) {
-   ENA_MEM_ALLOC_COHERENT(ena_dev->dmadev,
-  size,
-  io_cq->cdesc_addr.virt_addr,
-  io_cq->cdesc_addr.phys_addr,
-  io_cq->cdesc_addr.mem_handle);
+   ENA_MEM_ALLOC_COHERENT_ALIGNED(ena_dev->dmadev,
+  size,
+  io_cq->cdesc_addr.virt_addr,
+  io_cq->cdesc_addr.phys_addr,
+  io_cq->cdesc_addr.mem_handle,
+  ENA_CDESC_RING_SIZE_ALIGNMENT);
}
 
if (!io_cq->cdesc_addr.virt_addr) {

Modified: head/sys/contrib/ena-com/ena_com.h
==
--- head/sys/contrib/ena-com/ena_com.h  Wed Nov 18 14:32:48 2020
(r367794)
+++ head/sys/contrib/ena-com/ena_com.h  Wed Nov 18 14:50:12 2020
(r367795)
@@ -51,6 +51,8 @@
 #define ADMIN_CQ_SIZE(depth)   ((depth) * sizeof(struct ena_admin_acq_entry))
 #define ADMIN_AENQ_SIZE(depth) ((depth) * sizeof(struct ena_admin_aenq_entry))
 
+#define ENA_CDESC_RING_SIZE_ALIGNMENT  (1 << 12) /* 4K */
+
 /*/
 /*/
 /* ENA adaptive interrupt moderation settings */

Modified: head/sys/contrib/ena-com/ena_plat.h
==
--- head/sys/contrib/ena-com/ena_plat.h Wed Nov 18 14:32:48 2020
(r367794)
+++ head/sys/contrib/ena-com/ena_plat.h Wed Nov 18 14:50:12 2020
(r367795)
@@ -106,6 +106,8 @@ extern struct ena_bus_space ebs;
 #define ENA_ADMQ   (1 << 8) /* Detailed info about admin queue.  */
 #define ENA_NETMAP (1 << 9) /* Detailed info about netmap.   */
 
+#define DEFAULT_ALLOC_ALIGNMENT8
+
 extern int ena_log_level;
 
 #define ena_trace_raw(level, fmt, args...) \
@@ -285,7 +287,7 @@ typedef uint64_t ena_time_t;
 void   ena_dmamap_callback(void *arg, bus_dma_segment_t *segs, int nseg,
 int error);
 intena_dma_alloc(device_t dmadev, bus_size_t size, ena_mem_handle_t *dma,
-int mapflags);
+int mapflags, bus_size_t alignment);
 
 static inline uint32_t
 ena_reg_read32(struct ena_bus *bus, bus_size_t offset)
@@ -313,19 +315,29 @@ ena_reg_read32(struct ena_bus *bus, bus_size_t offset)
(void)(size); 

svn commit: r367794 - vendor-sys/ena-com/2.2.1

2020-11-18 Thread Marcin Wojtas
Author: mw
Date: Wed Nov 18 14:32:48 2020
New Revision: 367794
URL: https://svnweb.freebsd.org/changeset/base/367794

Log:
  Upgrade ena-com to v2.2.1
  
  An upgrade contains the cdesc allocation alignment fix.
  
  Obtained from: Amazon, Inc

Added:
  vendor-sys/ena-com/2.2.1/
 - copied from r367793, vendor-sys/ena-com/dist/
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r367793 - vendor-sys/ena-com/dist

2020-11-18 Thread Marcin Wojtas
Author: mw
Date: Wed Nov 18 14:30:59 2020
New Revision: 367793
URL: https://svnweb.freebsd.org/changeset/base/367793

Log:
  ena-com: Fix ena-com to allocate cdesc aligned to 4k
  
  The latest generation hardware requires IO CQ (completion queue)
  descriptors memory to be aligned to a 4K. It needs that feature for
  the best performance.
  
  Allocating unaligned descriptors will have a big performance impact as
  the packet processing in a HW won't be optimized properly.
  
  It's a critical fix, especially for the arm64 EC2 instances.

Modified:
  vendor-sys/ena-com/dist/ena_com.c
  vendor-sys/ena-com/dist/ena_com.h
  vendor-sys/ena-com/dist/ena_plat.h

Modified: vendor-sys/ena-com/dist/ena_com.c
==
--- vendor-sys/ena-com/dist/ena_com.c   Wed Nov 18 14:27:47 2020
(r367792)
+++ vendor-sys/ena-com/dist/ena_com.c   Wed Nov 18 14:30:59 2020
(r367793)
@@ -449,19 +449,21 @@ static int ena_com_init_io_cq(struct ena_com_dev *ena_
size = io_cq->cdesc_entry_size_in_bytes * io_cq->q_depth;
io_cq->bus = ena_dev->bus;
 
-   ENA_MEM_ALLOC_COHERENT_NODE(ena_dev->dmadev,
-   size,
-   io_cq->cdesc_addr.virt_addr,
-   io_cq->cdesc_addr.phys_addr,
-   io_cq->cdesc_addr.mem_handle,
-   ctx->numa_node,
-   prev_node);
+   ENA_MEM_ALLOC_COHERENT_NODE_ALIGNED(ena_dev->dmadev,
+   size,
+   io_cq->cdesc_addr.virt_addr,
+   io_cq->cdesc_addr.phys_addr,
+   io_cq->cdesc_addr.mem_handle,
+   ctx->numa_node,
+   prev_node,
+   ENA_CDESC_RING_SIZE_ALIGNMENT);
if (!io_cq->cdesc_addr.virt_addr) {
-   ENA_MEM_ALLOC_COHERENT(ena_dev->dmadev,
-  size,
-  io_cq->cdesc_addr.virt_addr,
-  io_cq->cdesc_addr.phys_addr,
-  io_cq->cdesc_addr.mem_handle);
+   ENA_MEM_ALLOC_COHERENT_ALIGNED(ena_dev->dmadev,
+  size,
+  io_cq->cdesc_addr.virt_addr,
+  io_cq->cdesc_addr.phys_addr,
+  io_cq->cdesc_addr.mem_handle,
+  ENA_CDESC_RING_SIZE_ALIGNMENT);
}
 
if (!io_cq->cdesc_addr.virt_addr) {

Modified: vendor-sys/ena-com/dist/ena_com.h
==
--- vendor-sys/ena-com/dist/ena_com.h   Wed Nov 18 14:27:47 2020
(r367792)
+++ vendor-sys/ena-com/dist/ena_com.h   Wed Nov 18 14:30:59 2020
(r367793)
@@ -51,6 +51,8 @@
 #define ADMIN_CQ_SIZE(depth)   ((depth) * sizeof(struct ena_admin_acq_entry))
 #define ADMIN_AENQ_SIZE(depth) ((depth) * sizeof(struct ena_admin_aenq_entry))
 
+#define ENA_CDESC_RING_SIZE_ALIGNMENT  (1 << 12) /* 4K */
+
 /*/
 /*/
 /* ENA adaptive interrupt moderation settings */

Modified: vendor-sys/ena-com/dist/ena_plat.h
==
--- vendor-sys/ena-com/dist/ena_plat.h  Wed Nov 18 14:27:47 2020
(r367792)
+++ vendor-sys/ena-com/dist/ena_plat.h  Wed Nov 18 14:30:59 2020
(r367793)
@@ -106,6 +106,8 @@ extern struct ena_bus_space ebs;
 #define ENA_ADMQ   (1 << 8) /* Detailed info about admin queue.  */
 #define ENA_NETMAP (1 << 9) /* Detailed info about netmap.   */
 
+#define DEFAULT_ALLOC_ALIGNMENT8
+
 extern int ena_log_level;
 
 #define ena_trace_raw(level, fmt, args...) \
@@ -285,7 +287,7 @@ typedef uint64_t ena_time_t;
 void   ena_dmamap_callback(void *arg, bus_dma_segment_t *segs, int nseg,
 int error);
 intena_dma_alloc(device_t dmadev, bus_size_t size, ena_mem_handle_t *dma,
-int mapflags);
+int mapflags, bus_size_t alignment);
 
 static inline uint32_t
 ena_reg_read32(struct ena_bus *bus, bus_size_t offset)
@@ -313,19 +315,29 @@ ena_reg_read32(struct ena_bus *bus, bus_size_t offset)
(void)(size);   \
free(ptr, M_DEVBUF);\
} while (0)
-#define ENA_MEM_ALLOC_COHERENT_NODE(dmadev, size, virt, phys, handle, node, \
-dev_node)  \
+#define 

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

2020-11-18 Thread Mark Johnston
Author: markj
Date: Wed Nov 18 14:27:47 2020
New Revision: 367792
URL: https://svnweb.freebsd.org/changeset/base/367792

Log:
  MFC r367596:
  iflib: Free full mbuf chains when draining transmit queues

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

Modified: stable/12/sys/net/iflib.c
==
--- stable/12/sys/net/iflib.c   Wed Nov 18 14:27:24 2020(r367791)
+++ stable/12/sys/net/iflib.c   Wed Nov 18 14:27:47 2020(r367792)
@@ -1860,7 +1860,7 @@ iflib_txsd_free(if_ctx_t ctx, iflib_txq_t txq, int i)
bus_dmamap_unload(txq->ift_tso_buf_tag,
txq->ift_sds.ifsd_tso_map[i]);
}
-   m_free(*mp);
+   m_freem(*mp);
DBG_COUNTER_INC(tx_frees);
*mp = NULL;
 }
@@ -3680,7 +3680,7 @@ iflib_txq_drain(struct ifmp_ring *r, uint32_t cidx, ui
DBG_COUNTER_INC(txq_drain_flushing);
for (i = 0; i < avail; i++) {
if (__predict_true(r->items[(cidx + i) & (r->size-1)] 
!= (void *)txq))
-   m_free(r->items[(cidx + i) & (r->size-1)]);
+   m_freem(r->items[(cidx + i) & (r->size-1)]);
r->items[(cidx + i) & (r->size-1)] = NULL;
}
return (avail);
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r367791 - in stable/12/sys: kern sys

2020-11-18 Thread Mark Johnston
Author: markj
Date: Wed Nov 18 14:27:24 2020
New Revision: 367791
URL: https://svnweb.freebsd.org/changeset/base/367791

Log:
  MFC r367588:
  Fix a pair of races in SIGIO registration

Modified:
  stable/12/sys/kern/kern_descrip.c
  stable/12/sys/kern/kern_exit.c
  stable/12/sys/kern/kern_proc.c
  stable/12/sys/sys/signalvar.h
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/kern/kern_descrip.c
==
--- stable/12/sys/kern/kern_descrip.c   Wed Nov 18 13:52:13 2020
(r367790)
+++ stable/12/sys/kern/kern_descrip.c   Wed Nov 18 14:27:24 2020
(r367791)
@@ -954,6 +954,40 @@ unlock:
return (error);
 }
 
+static void
+sigiofree(struct sigio *sigio)
+{
+   crfree(sigio->sio_ucred);
+   free(sigio, M_SIGIO);
+}
+
+static struct sigio *
+funsetown_locked(struct sigio *sigio)
+{
+   struct proc *p;
+   struct pgrp *pg;
+
+   SIGIO_ASSERT_LOCKED();
+
+   if (sigio == NULL)
+   return (NULL);
+   *(sigio->sio_myref) = NULL;
+   if (sigio->sio_pgid < 0) {
+   pg = sigio->sio_pgrp;
+   PGRP_LOCK(pg);
+   SLIST_REMOVE(>sio_pgrp->pg_sigiolst, sigio,
+   sigio, sio_pgsigio);
+   PGRP_UNLOCK(pg);
+   } else {
+   p = sigio->sio_proc;
+   PROC_LOCK(p);
+   SLIST_REMOVE(>sio_proc->p_sigiolst, sigio,
+   sigio, sio_pgsigio);
+   PROC_UNLOCK(p);
+   }
+   return (sigio);
+}
+
 /*
  * If sigio is on the list associated with a process or process group,
  * disable signalling from the device, remove sigio from the list and
@@ -964,92 +998,82 @@ funsetown(struct sigio **sigiop)
 {
struct sigio *sigio;
 
+   /* Racy check, consumers must provide synchronization. */
if (*sigiop == NULL)
return;
+
SIGIO_LOCK();
-   sigio = *sigiop;
-   if (sigio == NULL) {
-   SIGIO_UNLOCK();
-   return;
-   }
-   *(sigio->sio_myref) = NULL;
-   if ((sigio)->sio_pgid < 0) {
-   struct pgrp *pg = (sigio)->sio_pgrp;
-   PGRP_LOCK(pg);
-   SLIST_REMOVE(>sio_pgrp->pg_sigiolst, sigio,
-   sigio, sio_pgsigio);
-   PGRP_UNLOCK(pg);
-   } else {
-   struct proc *p = (sigio)->sio_proc;
-   PROC_LOCK(p);
-   SLIST_REMOVE(>sio_proc->p_sigiolst, sigio,
-   sigio, sio_pgsigio);
-   PROC_UNLOCK(p);
-   }
+   sigio = funsetown_locked(*sigiop);
SIGIO_UNLOCK();
-   crfree(sigio->sio_ucred);
-   free(sigio, M_SIGIO);
+   if (sigio != NULL)
+   sigiofree(sigio);
 }
 
 /*
- * Free a list of sigio structures.
- * We only need to lock the SIGIO_LOCK because we have made ourselves
- * inaccessible to callers of fsetown and therefore do not need to lock
- * the proc or pgrp struct for the list manipulation.
+ * Free a list of sigio structures.  The caller must ensure that new sigio
+ * structures cannot be added after this point.  For process groups this is
+ * guaranteed using the proctree lock; for processes, the P_WEXIT flag serves
+ * as an interlock.
  */
 void
 funsetownlst(struct sigiolst *sigiolst)
 {
struct proc *p;
struct pgrp *pg;
-   struct sigio *sigio;
+   struct sigio *sigio, *tmp;
 
+   /* Racy check. */
sigio = SLIST_FIRST(sigiolst);
if (sigio == NULL)
return;
+
p = NULL;
pg = NULL;
 
+   SIGIO_LOCK();
+   sigio = SLIST_FIRST(sigiolst);
+   if (sigio == NULL) {
+   SIGIO_UNLOCK();
+   return;
+   }
+
/*
-* Every entry of the list should belong
-* to a single proc or pgrp.
+* Every entry of the list should belong to a single proc or pgrp.
 */
if (sigio->sio_pgid < 0) {
pg = sigio->sio_pgrp;
-   PGRP_LOCK_ASSERT(pg, MA_NOTOWNED);
+   sx_assert(_lock, SX_XLOCKED);
+   PGRP_LOCK(pg);
} else /* if (sigio->sio_pgid > 0) */ {
p = sigio->sio_proc;
-   PROC_LOCK_ASSERT(p, MA_NOTOWNED);
+   PROC_LOCK(p);
+   KASSERT((p->p_flag & P_WEXIT) != 0,
+   ("%s: process %p is not exiting", __func__, p));
}
 
-   SIGIO_LOCK();
-   while ((sigio = SLIST_FIRST(sigiolst)) != NULL) {
-   *(sigio->sio_myref) = NULL;
+   SLIST_FOREACH(sigio, sigiolst, sio_pgsigio) {
+   *sigio->sio_myref = NULL;
if (pg != NULL) {
KASSERT(sigio->sio_pgid < 0,
("Proc sigio in pgrp sigio list"));
KASSERT(sigio->sio_pgrp == pg,
("Bogus pgrp in sigio list"));
-   

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

2020-11-18 Thread Andrey V. Elsukov
Author: ae
Date: Wed Nov 18 13:52:13 2020
New Revision: 367790
URL: https://svnweb.freebsd.org/changeset/base/367790

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

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

Modified: stable/12/sys/net/if_lagg.c
==
--- stable/12/sys/net/if_lagg.c Wed Nov 18 13:47:11 2020(r367789)
+++ stable/12/sys/net/if_lagg.c Wed Nov 18 13:52:13 2020(r367790)
@@ -1033,7 +1033,8 @@ lagg_port_output(struct ifnet *ifp, struct mbuf *m,
switch (dst->sa_family) {
case pseudo_AF_HDRCMPLT:
case AF_UNSPEC:
-   return ((*lp->lp_output)(ifp, m, dst, ro));
+   if (lp != NULL)
+   return ((*lp->lp_output)(ifp, m, dst, ro));
}
 
/* drop any other frames */
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r367789 - in head/sys/compat/linuxkpi/common/include: asm linux

2020-11-18 Thread Hans Petter Selasky
Author: hselasky
Date: Wed Nov 18 13:47:11 2020
New Revision: 367789
URL: https://svnweb.freebsd.org/changeset/base/367789

Log:
  Allow LinuxKPI types to be used in bootloaders, by checking for the
  _STANDALONE definition.
  
  No functional change intended.
  
  MFC after:1 week
  Sponsored by: Mellanox Technologies // NVIDIA Networking

Modified:
  head/sys/compat/linuxkpi/common/include/asm/types.h
  head/sys/compat/linuxkpi/common/include/linux/types.h

Modified: head/sys/compat/linuxkpi/common/include/asm/types.h
==
--- head/sys/compat/linuxkpi/common/include/asm/types.h Wed Nov 18 13:45:32 
2020(r367788)
+++ head/sys/compat/linuxkpi/common/include/asm/types.h Wed Nov 18 13:47:11 
2020(r367789)
@@ -31,7 +31,7 @@
 #ifndef_ASM_TYPES_H_
 #define_ASM_TYPES_H_
 
-#ifdef _KERNEL
+#if defined(_KERNEL) || defined(_STANDALONE)
 
 #include 
 
@@ -59,6 +59,6 @@ typedef vm_paddr_t dma64_addr_t;
 
 typedef unsigned short umode_t;
 
-#endif /* _KERNEL */
+#endif /* _KERNEL || _STANDALONE */
 
 #endif /* _ASM_TYPES_H_ */

Modified: head/sys/compat/linuxkpi/common/include/linux/types.h
==
--- head/sys/compat/linuxkpi/common/include/linux/types.h   Wed Nov 18 
13:45:32 2020(r367788)
+++ head/sys/compat/linuxkpi/common/include/linux/types.h   Wed Nov 18 
13:47:11 2020(r367789)
@@ -57,8 +57,10 @@ typedef uint16_t __aligned_u16 __aligned(sizeof(uint16
 typedef uint32_t __aligned_u32 __aligned(sizeof(uint32_t));
 typedef uint64_t __aligned_u64 __aligned(sizeof(uint64_t));
 
+#ifdef _KERNEL
 typedef unsigned short ushort;
 typedef unsigned intuint;
+#endif
 typedef unsigned long ulong;
 typedef unsigned gfp_t;
 typedef off_t loff_t;
@@ -67,7 +69,7 @@ typedef uint16_t __bitwise__ __sum16;
 typedef unsigned long pgoff_t;
 typedef unsigned __poll_t;
 
-typedef u64 phys_addr_t;
+typedef uint64_t phys_addr_t;
 
 typedef size_t __kernel_size_t;
 
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r367788 - head/sys/modules/linuxkpi

2020-11-18 Thread Hans Petter Selasky
Author: hselasky
Date: Wed Nov 18 13:45:32 2020
New Revision: 367788
URL: https://svnweb.freebsd.org/changeset/base/367788

Log:
  Add missing header file when building the LinuxKPI module separately.
  
  MFC after:1 week
  Sponsored by: Mellanox Technologies // NVIDIA Networking

Modified:
  head/sys/modules/linuxkpi/Makefile

Modified: head/sys/modules/linuxkpi/Makefile
==
--- head/sys/modules/linuxkpi/Makefile  Wed Nov 18 13:22:22 2020
(r367787)
+++ head/sys/modules/linuxkpi/Makefile  Wed Nov 18 13:45:32 2020
(r367788)
@@ -25,7 +25,7 @@ SRCS= linux_compat.c \
 
 .if ${MACHINE_CPUARCH} == "aarch64" || ${MACHINE_CPUARCH} == "amd64" || \
 ${MACHINE_CPUARCH} == "i386"
-SRCS+= opt_acpi.h linux_acpi.c
+SRCS+= opt_acpi.h acpi_if.h linux_acpi.c
 .endif
 
 SRCS+= ${LINUXKPI_GENSRCS}
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r367787 - in head: stand/kshim sys/dev/usb

2020-11-18 Thread Hans Petter Selasky
Author: hselasky
Date: Wed Nov 18 13:22:22 2020
New Revision: 367787
URL: https://svnweb.freebsd.org/changeset/base/367787

Log:
  Fix build of USB bootloader code by adding checks for _STANDALONE being 
defined.
  Currently the USB bootloader code is not part of buildworld.
  
  MFC after:1 week
  Sponsored by: Mellanox Technologies // NVIDIA Networking

Modified:
  head/stand/kshim/bsd_kernel.h
  head/sys/dev/usb/usb.h
  head/sys/dev/usb/usb_pf.h
  head/sys/dev/usb/usbdi.h
  head/sys/dev/usb/usbhid.h

Modified: head/stand/kshim/bsd_kernel.h
==
--- head/stand/kshim/bsd_kernel.h   Wed Nov 18 09:00:05 2020
(r367786)
+++ head/stand/kshim/bsd_kernel.h   Wed Nov 18 13:22:22 2020
(r367787)
@@ -27,9 +27,12 @@
 #ifndef _BSD_KERNEL_H_
 #define_BSD_KERNEL_H_
 
-#define_KERNEL
+#if !defined(_STANDALONE)
+#error "_STANDALONE is not defined!"
+#endif
+
 #undef __FreeBSD_version
-#define__FreeBSD_version 110
+#define__FreeBSD_version 130
 
 #include 
 #include 

Modified: head/sys/dev/usb/usb.h
==
--- head/sys/dev/usb/usb.h  Wed Nov 18 09:00:05 2020(r367786)
+++ head/sys/dev/usb/usb.h  Wed Nov 18 13:22:22 2020(r367787)
@@ -41,7 +41,7 @@
 #ifndef _USB_STANDARD_H_
 #define_USB_STANDARD_H_
 
-#if defined(_KERNEL)
+#if defined(_KERNEL) || defined(_STANDALONE)
 #ifndef USB_GLOBAL_INCLUDE_FILE
 #include "opt_usb.h"
 #endif
@@ -57,7 +57,7 @@ SYSCTL_DECL(_hw_usb);
 
 MALLOC_DECLARE(M_USB);
 MALLOC_DECLARE(M_USBDEV);
-#endif /* _KERNEL */
+#endif /* _KERNEL || _STANDALONE */
 
 #ifndef USB_GLOBAL_INCLUDE_FILE
 #include 

Modified: head/sys/dev/usb/usb_pf.h
==
--- head/sys/dev/usb/usb_pf.h   Wed Nov 18 09:00:05 2020(r367786)
+++ head/sys/dev/usb/usb_pf.h   Wed Nov 18 13:22:22 2020(r367787)
@@ -113,10 +113,10 @@ extern uint8_t usbpf_framehdr_size_ok[
 #defineUSBPF_XFERTAP_SUBMIT0
 #defineUSBPF_XFERTAP_DONE  1
 
-#ifdef _KERNEL
+#if defined(_KERNEL) || defined(_STANDALONE)
 void   usbpf_attach(struct usb_bus *);
 void   usbpf_detach(struct usb_bus *);
 void   usbpf_xfertap(struct usb_xfer *, int);
-#endif
+#endif /* _KERNEL || _STANDALONE */
+#endif /* _DEV_USB_PF_H */
 
-#endif

Modified: head/sys/dev/usb/usbdi.h
==
--- head/sys/dev/usb/usbdi.hWed Nov 18 09:00:05 2020(r367786)
+++ head/sys/dev/usb/usbdi.hWed Nov 18 13:22:22 2020(r367787)
@@ -88,7 +88,7 @@ typedef enum {/* keep in sync with usb_errstr_table *
 #defineUSB_NO_TIMEOUT 0
 #defineUSB_DEFAULT_TIMEOUT 5000/* 5000 ms = 5 seconds */
 
-#if defined(_KERNEL)
+#if defined(_KERNEL) || defined(_STANDALONE)
 /* typedefs */
 
 typedef void (usb_callback_t)(struct usb_xfer *, usb_error_t);
@@ -709,5 +709,5 @@ void*usb_fifo_softc(struct usb_fifo *fifo);
 void   usb_fifo_set_close_zlp(struct usb_fifo *, uint8_t);
 void   usb_fifo_set_write_defrag(struct usb_fifo *, uint8_t);
 void   usb_fifo_free(struct usb_fifo *f);
-#endif /* _KERNEL */
-#endif /* _USB_USBDI_H_ */
+#endif /* _KERNEL || _STANDALONE */
+#endif /* _USB_USBDI_H_ */

Modified: head/sys/dev/usb/usbhid.h
==
--- head/sys/dev/usb/usbhid.h   Wed Nov 18 09:00:05 2020(r367786)
+++ head/sys/dev/usb/usbhid.h   Wed Nov 18 13:22:22 2020(r367787)
@@ -205,7 +205,7 @@ struct usb_hid_descriptor {
 #defineHUM_INCH0x13
 #defineHUM_DEGREE  0x14
 
-#ifdef _KERNEL
+#if defined(_KERNEL) || defined(_STANDALONE)
 struct usb_config_descriptor;
 
 enum hid_kind {
@@ -274,5 +274,5 @@ usb_error_t usbd_req_get_hid_desc(struct usb_device *u
 int32_thid_item_resolution(struct hid_item *hi);
 inthid_is_mouse(const void *d_ptr, uint16_t d_len);
 inthid_is_keyboard(const void *d_ptr, uint16_t d_len);
-#endif /* _KERNEL */
-#endif /* _USB_HID_H_ */
+#endif /* _KERNEL || _STANDALONE */
+#endif /* _USB_HID_H_ */
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r367786 - stable/12/share/man/man7

2020-11-18 Thread Mateusz Piotrowski
Author: 0mp (doc,ports committer)
Date: Wed Nov 18 09:00:05 2020
New Revision: 367786
URL: https://svnweb.freebsd.org/changeset/base/367786

Log:
  MFC r367552:
  
  Do not document MOTIFLIB in ports(7)
  
  Perhaps it made sense in 1998 (r32836), but now it feels a bit out of
  place.  We tend to avoid documenting non-essential ports variables in
  the manual page (we try to document them in the Porter's Handbook instead).

Modified:
  stable/12/share/man/man7/ports.7
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/share/man/man7/ports.7
==
--- stable/12/share/man/man7/ports.7Wed Nov 18 04:35:49 2020
(r367785)
+++ stable/12/share/man/man7/ports.7Wed Nov 18 09:00:05 2020
(r367786)
@@ -25,7 +25,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd November 1, 2020
+.Dd November 10, 2020
 .Dt PORTS 7
 .Os
 .Sh NAME
@@ -464,9 +464,6 @@ Normally
 .Xr fetch 1 .
 .It Va FORCE_PKG_REGISTER
 If set, overwrite any existing package registration on the system.
-.It Va MOTIFLIB
-Location of
-.Pa "libXm\&." Ns Brq Pa a , Ns Pa so .
 .It Va INTERACTIVE
 If defined, only operate on a port if it requires interaction.
 .It Va BATCH
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"