Re: svn commit: r346645 - in head/sys: compat/linuxkpi/common/include/linux compat/linuxkpi/common/src sys

2019-04-24 Thread Li-Wen Hsu
On Thu, Apr 25, 2019 at 5:31 AM Tycho Nightingale  wrote:
>
> Author: tychon
> Date: Wed Apr 24 20:30:45 2019
> New Revision: 346645
> URL: https://svnweb.freebsd.org/changeset/base/346645
...
> Modified: head/sys/compat/linuxkpi/common/src/linux_pci.c
> ==
> --- head/sys/compat/linuxkpi/common/src/linux_pci.c Wed Apr 24 19:56:02 
> 2019(r346644)
> +++ head/sys/compat/linuxkpi/common/src/linux_pci.c Wed Apr 24 20:30:45 
> 2019(r346645)
...
> +PCTRIE_DEFINE(LINUX_DMA, linux_dma_obj, dma_addr, linux_dma_trie_alloc,
> +linux_dma_trie_free);

Here we got errors in build on 32-bit platforms use gcc:

/usr/src/sys/compat/linuxkpi/common/src/linux_pci.c:456:1: error:
static_assert failed due to requirement 'sizeof (((struct
linux_dma_obj *)0)->dma_addr) == sizeof(unsigned long long)'
"compile-time assertion failed"
PCTRIE_DEFINE(LINUX_DMA, linux_dma_obj, dma_addr, linux_dma_trie_alloc,
^~~
/usr/src/sys/sys/pctrie.h:41:10: note: expanded from macro 'PCTRIE_DEFINE'
\
^
/usr/src/sys/sys/systm.h:120:21: note: expanded from macro '\
CTASSERT'
#define CTASSERT(x) _Static_assert(x, "compile-time assertion failed")
^  ~
/usr/src/sys/compat/linuxkpi/common/src/linux_pci.c:456:1: error:
incompatible pointer types returning 'dma_addr_t *' (aka 'unsigned int
*') from a function with result type 'uint64_t *' (aka 'unsigned long
long *') [-Werror,-Wincompatible-pointer-types]
PCTRIE_DEFINE(LINUX_DMA, linux_dma_obj, dma_addr, linux_dma_trie_alloc,
^~~
/usr/src/sys/sys/pctrie.h:63:9: note: expanded from macro 'PCTRIE_DEFINE'
return &ptr->field; \
   ^~~
2 errors generated.
*** [linux_pci.o] Error code 1

make[4]: stopped in /usr/src/sys/modules/linuxkpi

Can you check this?  Full build log is available at:
https://ci.freebsd.org/job/FreeBSD-head-armv7-build/4250/console

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


Re: svn commit: r346593 - head/sys/sys

2019-04-24 Thread Wojciech Macek
Intel does not reorder reads against the condition "if" here. I know for
sure that ARM does, but therestill might be some other architectures that
also suffers such behavior - I just don't have any means to verify.
I remember the discussion for rS302292 where we agreed that this kind of
patches should be the least impacting in perfomrance as possible. Adding
unconditional memory barrier causes significant performance drop on Intel,
where in fact, the issue was never seen.

Wojtek

czw., 25 kwi 2019 o 06:08 Mark Johnston  napisał(a):

> On Tue, Apr 23, 2019 at 06:36:32AM +, Wojciech Macek wrote:
> > Author: wma
> > Date: Tue Apr 23 06:36:32 2019
> > New Revision: 346593
> > URL: https://svnweb.freebsd.org/changeset/base/346593
> >
> > Log:
> >   This patch offers a workaround to buf_ring reordering
> >   visible on armv7 and armv8. Similar issue to rS302292.
> >
> >   Obtained from: Semihalf
> >   Authored by:   Michal Krawczyk 
> >   Approved by:   wma
> >   Differential Revision: https://reviews.freebsd.org/D19932
> >
> > Modified:
> >   head/sys/sys/buf_ring.h
> >
> > Modified: head/sys/sys/buf_ring.h
> >
> ==
> > --- head/sys/sys/buf_ring.h   Tue Apr 23 04:06:26 2019(r346592)
> > +++ head/sys/sys/buf_ring.h   Tue Apr 23 06:36:32 2019(r346593)
> > @@ -310,14 +310,23 @@ buf_ring_peek_clear_sc(struct buf_ring *br)
> >   if (!mtx_owned(br->br_lock))
> >   panic("lock not held on single consumer dequeue");
> >  #endif
> > - /*
> > -  * I believe it is safe to not have a memory barrier
> > -  * here because we control cons and tail is worst case
> > -  * a lagging indicator so we worst case we might
> > -  * return NULL immediately after a buffer has been enqueued
> > -  */
> > +
> >   if (br->br_cons_head == br->br_prod_tail)
> >   return (NULL);
> > +
> > +#if defined(__arm__) || defined(__aarch64__)
> > + /*
> > +  * The barrier is required there on ARM and ARM64 to ensure, that
> > +  * br->br_ring[br->br_cons_head] will not be fetched before the
> above
> > +  * condition is checked.
> > +  * Without the barrier, it is possible, that buffer will be fetched
> > +  * before the enqueue will put mbuf into br, then, in the
> meantime, the
> > +  * enqueue will update the array and the br_prod_tail, and the
> > +  * conditional check will be true, so we will return previously
> fetched
> > +  * (and invalid) buffer.
> > +  */
> > + atomic_thread_fence_acq();
> > +#endif
>
> Why is it specific to ARM?
>
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r346593 - head/sys/sys

2019-04-24 Thread Mark Johnston
On Tue, Apr 23, 2019 at 06:36:32AM +, Wojciech Macek wrote:
> Author: wma
> Date: Tue Apr 23 06:36:32 2019
> New Revision: 346593
> URL: https://svnweb.freebsd.org/changeset/base/346593
> 
> Log:
>   This patch offers a workaround to buf_ring reordering
>   visible on armv7 and armv8. Similar issue to rS302292.
>   
>   Obtained from: Semihalf
>   Authored by:   Michal Krawczyk 
>   Approved by:   wma
>   Differential Revision: https://reviews.freebsd.org/D19932
> 
> Modified:
>   head/sys/sys/buf_ring.h
> 
> Modified: head/sys/sys/buf_ring.h
> ==
> --- head/sys/sys/buf_ring.h   Tue Apr 23 04:06:26 2019(r346592)
> +++ head/sys/sys/buf_ring.h   Tue Apr 23 06:36:32 2019(r346593)
> @@ -310,14 +310,23 @@ buf_ring_peek_clear_sc(struct buf_ring *br)
>   if (!mtx_owned(br->br_lock))
>   panic("lock not held on single consumer dequeue");
>  #endif   
> - /*
> -  * I believe it is safe to not have a memory barrier
> -  * here because we control cons and tail is worst case
> -  * a lagging indicator so we worst case we might
> -  * return NULL immediately after a buffer has been enqueued
> -  */
> +
>   if (br->br_cons_head == br->br_prod_tail)
>   return (NULL);
> +
> +#if defined(__arm__) || defined(__aarch64__)
> + /*
> +  * The barrier is required there on ARM and ARM64 to ensure, that
> +  * br->br_ring[br->br_cons_head] will not be fetched before the above
> +  * condition is checked.
> +  * Without the barrier, it is possible, that buffer will be fetched
> +  * before the enqueue will put mbuf into br, then, in the meantime, the
> +  * enqueue will update the array and the br_prod_tail, and the
> +  * conditional check will be true, so we will return previously fetched
> +  * (and invalid) buffer.
> +  */
> + atomic_thread_fence_acq();
> +#endif

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


svn commit: r346657 - head/sys/dev/uart

2019-04-24 Thread Rebecca Cran
Author: bcran
Date: Thu Apr 25 02:16:48 2019
New Revision: 346657
URL: https://svnweb.freebsd.org/changeset/base/346657

Log:
  ACPI SPCR: handle BaudRate=0
  
  From 
https://github.com/tianocore/edk2-platforms/commit/7d8dc6544c93a5f5a03c83316489ba8700946e9f
  
  "The mcbin (and likely others) have a nonstandard uart clock. This means
  that the earlycon programming will incorrectly set the baud rate if it is
  specified. The way around this is to tell the kernel to continue using the
  preprogrammed baud rate. This is done by setting the baud to 0."
  
  Our drivers (uart_dev_ns8250) do respect zero, but SPCR would error. Let's
  not error.
  
  Submitted by: Greg V 
  Reviewed by:  mw, imp, bcran
  Differential Revision:https://reviews.freebsd.org/D19914

Modified:
  head/sys/dev/uart/uart_cpu_arm64.c

Modified: head/sys/dev/uart/uart_cpu_arm64.c
==
--- head/sys/dev/uart/uart_cpu_arm64.c  Thu Apr 25 00:58:11 2019
(r346656)
+++ head/sys/dev/uart/uart_cpu_arm64.c  Thu Apr 25 02:16:48 2019
(r346657)
@@ -128,6 +128,13 @@ uart_cpu_acpi_probe(struct uart_class **classp, bus_sp
goto out;
 
switch(spcr->BaudRate) {
+   case 0:
+   /*
+* A BaudRate of 0 is a special value which means not to
+* change the rate that's already programmed.
+*/
+   *baud = 0;
+   break;
case 3:
*baud = 9600;
break;
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r346654 - head/tools/boot

2019-04-24 Thread Ian Lepore
Author: ian
Date: Thu Apr 25 00:08:15 2019
New Revision: 346654
URL: https://svnweb.freebsd.org/changeset/base/346654

Log:
  For the geli-gpt-zfs test images, both bios and uefi flavors, add a dummy
  ufs partition as p2, and put the zfs partition at p3, to test the ability
  of the zfs probe code to find a zfs pool on something other than the first
  partition.

Modified:
  head/tools/boot/rootgen.sh

Modified: head/tools/boot/rootgen.sh
==
--- head/tools/boot/rootgen.sh  Wed Apr 24 23:52:38 2019(r346653)
+++ head/tools/boot/rootgen.sh  Thu Apr 25 00:08:15 2019(r346654)
@@ -487,15 +487,20 @@ mk_geli_gpt_zfs_legacy() {
 bios=$7
 pool=geli-gpt-zfs-legacy
 
-dd if=/dev/zero of=${img} count=1 seek=$(( 200 * 1024 * 1024 / 512 ))
+# Note that in this flavor we create an empty p2 ufs partition, and put
+# the bootable zfs stuff on p3, just to test the ability of the zfs probe
+# probe routines to find a pool on a partition other than the first one.
+
+dd if=/dev/zero of=${img} count=1 seek=$(( 300 * 1024 * 1024 / 512 ))
 md=$(mdconfig -f ${img})
 gpart create -s gpt ${md}
 gpart add -t freebsd-boot -s 400k -a 4k${md}   # <= ~540k
+gpart add -t freebsd-ufs -s 100m ${md}
 gpart add -t freebsd-zfs -l root $md
 # install-boot will make this bootable
-echo ${passphrase} | geli init -bg -e AES-XTS -i ${iterations} -J - -l 256 
-s 4096 ${md}p2
-echo ${passphrase} | geli attach -j - ${md}p2
-zpool create -O mountpoint=none -R ${mntpt} ${pool} ${md}p2.eli
+echo ${passphrase} | geli init -bg -e AES-XTS -i ${iterations} -J - -l 256 
-s 4096 ${md}p3
+echo ${passphrase} | geli attach -j - ${md}p3
+zpool create -O mountpoint=none -R ${mntpt} ${pool} ${md}p3.eli
 zpool set bootfs=${pool} ${pool}
 zfs create -po mountpoint=/ ${pool}/ROOT/default
 # NB: The online guides go nuts customizing /var and other mountpoints 
here, no need
@@ -516,7 +521,7 @@ EOF
 zpool set bootfs=${pool}/ROOT/default ${pool}
 zpool set autoexpand=on ${pool}
 zpool export ${pool}
-geli detach ${md}p2
+geli detach ${md}p3
 ${SRCTOP}/tools/boot/install-boot.sh -g ${geli} -s ${scheme} -f ${fs} -b 
${bios} -d ${src} ${md}
 mdconfig -d -u ${md}
 }
@@ -531,15 +536,20 @@ mk_geli_gpt_zfs_uefi() {
 bios=$7
 pool=geli-gpt-zfs-uefi
 
-dd if=/dev/zero of=${img} count=1 seek=$(( 200 * 1024 * 1024 / 512 ))
+# Note that in this flavor we create an empty p2 ufs partition, and put
+# the bootable zfs stuff on p3, just to test the ability of the zfs probe
+# probe routines to find a pool on a partition other than the first one.
+
+dd if=/dev/zero of=${img} count=1 seek=$(( 300 * 1024 * 1024 / 512 ))
 md=$(mdconfig -f ${img})
 gpart create -s gpt ${md}
 gpart add -t efi -s ${espsize}k -a 4k ${md}
+gpart add -t freebsd-ufs -s 100m ${md}
 gpart add -t freebsd-zfs -l root $md
 # install-boot will make this bootable
-echo ${passphrase} | geli init -bg -e AES-XTS -i ${iterations} -J - -l 256 
-s 4096 ${md}p2
-echo ${passphrase} | geli attach -j - ${md}p2
-zpool create -O mountpoint=none -R ${mntpt} ${pool} ${md}p2.eli
+echo ${passphrase} | geli init -bg -e AES-XTS -i ${iterations} -J - -l 256 
-s 4096 ${md}p3
+echo ${passphrase} | geli attach -j - ${md}p3
+zpool create -O mountpoint=none -R ${mntpt} ${pool} ${md}p3.eli
 zpool set bootfs=${pool} ${pool}
 zfs create -po mountpoint=/ ${pool}/ROOT/default
 # NB: The online guides go nuts customizing /var and other mountpoints 
here, no need
@@ -560,7 +570,7 @@ EOF
 zpool set bootfs=${pool}/ROOT/default ${pool}
 zpool set autoexpand=on ${pool}
 zpool export ${pool}
-geli detach ${md}p2
+geli detach ${md}p3
 ${SRCTOP}/tools/boot/install-boot.sh -g ${geli} -s ${scheme} -f ${fs} -b 
${bios} -d ${src} ${md}
 mdconfig -d -u ${md}
 }
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r346653 - head/tools/boot

2019-04-24 Thread Ian Lepore
Author: ian
Date: Wed Apr 24 23:52:38 2019
New Revision: 346653
URL: https://svnweb.freebsd.org/changeset/base/346653

Log:
  The zfs module has grown a dependency on zcl_nfs4.ko, so copy it into all
  the test images.

Modified:
  head/tools/boot/rootgen.sh

Modified: head/tools/boot/rootgen.sh
==
--- head/tools/boot/rootgen.sh  Wed Apr 24 23:51:12 2019(r346652)
+++ head/tools/boot/rootgen.sh  Wed Apr 24 23:52:38 2019(r346653)
@@ -110,6 +110,7 @@ mk_nogeli_gpt_zfs_legacy() {
 zfs_load=YES
 opensolaris_load=YES
 EOF
+cp /boot/kernel/acl_nfs4.ko ${mntpt}/boot/kernel/acl_nfs4.ko
 cp /boot/kernel/zfs.ko ${mntpt}/boot/kernel/zfs.ko
 cp /boot/kernel/opensolaris.ko ${mntpt}/boot/kernel/opensolaris.ko
 # end tweaks
@@ -148,6 +149,7 @@ mk_nogeli_gpt_zfs_uefi() {
 zfs_load=YES
 opensolaris_load=YES
 EOF
+cp /boot/kernel/acl_nfs4.ko ${mntpt}/boot/kernel/acl_nfs4.ko
 cp /boot/kernel/zfs.ko ${mntpt}/boot/kernel/zfs.ko
 cp /boot/kernel/opensolaris.ko ${mntpt}/boot/kernel/opensolaris.ko
 # end tweaks
@@ -187,6 +189,7 @@ mk_nogeli_gpt_zfs_both() {
 zfs_load=YES
 opensolaris_load=YES
 EOF
+cp /boot/kernel/acl_nfs4.ko ${mntpt}/boot/kernel/acl_nfs4.ko
 cp /boot/kernel/zfs.ko ${mntpt}/boot/kernel/zfs.ko
 cp /boot/kernel/opensolaris.ko ${mntpt}/boot/kernel/opensolaris.ko
 # end tweaks
@@ -268,6 +271,7 @@ mk_nogeli_mbr_zfs_legacy() {
 zfs_load=YES
 opensolaris_load=YES
 EOF
+cp /boot/kernel/acl_nfs4.ko ${mntpt}/boot/kernel/acl_nfs4.ko
 cp /boot/kernel/zfs.ko ${mntpt}/boot/kernel/zfs.ko
 cp /boot/kernel/opensolaris.ko ${mntpt}/boot/kernel/opensolaris.ko
 # end tweaks
@@ -309,6 +313,7 @@ mk_nogeli_mbr_zfs_uefi() {
 zfs_load=YES
 opensolaris_load=YES
 EOF
+cp /boot/kernel/acl_nfs4.ko ${mntpt}/boot/kernel/acl_nfs4.ko
 cp /boot/kernel/zfs.ko ${mntpt}/boot/kernel/zfs.ko
 cp /boot/kernel/opensolaris.ko ${mntpt}/boot/kernel/opensolaris.ko
 # end tweaks
@@ -350,6 +355,7 @@ mk_nogeli_mbr_zfs_both() {
 zfs_load=YES
 opensolaris_load=YES
 EOF
+cp /boot/kernel/acl_nfs4.ko ${mntpt}/boot/kernel/acl_nfs4.ko
 cp /boot/kernel/zfs.ko ${mntpt}/boot/kernel/zfs.ko
 cp /boot/kernel/opensolaris.ko ${mntpt}/boot/kernel/opensolaris.ko
 # end tweaks
@@ -500,6 +506,7 @@ zfs_load=YES
 opensolaris_load=YES
 geom_eli_load=YES
 EOF
+cp /boot/kernel/acl_nfs4.ko ${mntpt}/boot/kernel/acl_nfs4.ko
 cp /boot/kernel/zfs.ko ${mntpt}/boot/kernel/zfs.ko
 cp /boot/kernel/opensolaris.ko ${mntpt}/boot/kernel/opensolaris.ko
 cp /boot/kernel/geom_eli.ko ${mntpt}/boot/kernel/geom_eli.ko
@@ -543,6 +550,7 @@ zfs_load=YES
 opensolaris_load=YES
 geom_eli_load=YES
 EOF
+cp /boot/kernel/acl_nfs4.ko ${mntpt}/boot/kernel/acl_nfs4.ko
 cp /boot/kernel/zfs.ko ${mntpt}/boot/kernel/zfs.ko
 cp /boot/kernel/opensolaris.ko ${mntpt}/boot/kernel/opensolaris.ko
 cp /boot/kernel/geom_eli.ko ${mntpt}/boot/kernel/geom_eli.ko
@@ -587,6 +595,7 @@ zfs_load=YES
 opensolaris_load=YES
 geom_eli_load=YES
 EOF
+cp /boot/kernel/acl_nfs4.ko ${mntpt}/boot/kernel/acl_nfs4.ko
 cp /boot/kernel/zfs.ko ${mntpt}/boot/kernel/zfs.ko
 cp /boot/kernel/opensolaris.ko ${mntpt}/boot/kernel/opensolaris.ko
 cp /boot/kernel/geom_eli.ko ${mntpt}/boot/kernel/geom_eli.ko
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r346652 - head/tools/boot

2019-04-24 Thread Ian Lepore
Author: ian
Date: Wed Apr 24 23:51:12 2019
New Revision: 346652
URL: https://svnweb.freebsd.org/changeset/base/346652

Log:
  Complain and exit the script if the 'make install' phase fails.  Also,
  there is no need to install any debug files.

Modified:
  head/tools/boot/rootgen.sh

Modified: head/tools/boot/rootgen.sh
==
--- head/tools/boot/rootgen.sh  Wed Apr 24 23:35:10 2019(r346651)
+++ head/tools/boot/rootgen.sh  Wed Apr 24 23:51:12 2019(r346652)
@@ -783,7 +783,11 @@ EOF
 # XXX
 cp /boot/device.hints ${DESTDIR}/boot/device.hints
 # Assume we're already built
-make install DESTDIR=${DESTDIR} MK_MAN=no MK_INSTALL_AS_USER=yes
+make install DESTDIR=${DESTDIR} MK_MAN=no MK_INSTALL_AS_USER=yes 
WITHOUT_DEBUG_FILES=yes
+if [ $? -ne 0 ]; then
+echo "make install failed"
+exit 1
+fi
 # Copy init, /bin/sh, minimal libraries and testing /etc/rc
 mkdir -p ${DESTDIR}/sbin ${DESTDIR}/bin \
   ${DESTDIR}/lib ${DESTDIR}/libexec \
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r346651 - head/usr.sbin/kldxref

2019-04-24 Thread John Baldwin
Author: jhb
Date: Wed Apr 24 23:35:10 2019
New Revision: 346651
URL: https://svnweb.freebsd.org/changeset/base/346651

Log:
  Parse MIPS relocations to unbreak kldxref on MIPS.
  
  Parse the R_MIPS_32 and R_MIPS_64 relocations.  Both Elf_Rel and
  Elf_Rela relocations are handled since O32 MIPS uses Elf_Rel while N64
  uses Elf_Rela.  Note that R_MIPS_32 is only handled for 32-bit mips
  and R_MIPS_64 for 64-bit.  N32 is untested.
  
  Reviewed by:  imp
  Sponsored by: DARPA
  Differential Revision:https://reviews.freebsd.org/D19870

Added:
  head/usr.sbin/kldxref/ef_mips.c   (contents, props changed)

Added: head/usr.sbin/kldxref/ef_mips.c
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/usr.sbin/kldxref/ef_mips.c Wed Apr 24 23:35:10 2019
(r346651)
@@ -0,0 +1,99 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2019 John Baldwin 
+ *
+ * This software was developed by SRI International and the University of
+ * Cambridge Computer Laboratory (Department of Computer Science and
+ * Technology) under DARPA contract HR0011-18-C-0016 ("ECATS"), as part of the
+ * DARPA SSITH research programme.
+ *
+ * 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$
+ */
+
+#include 
+#include 
+
+#include 
+#include 
+
+#include "ef.h"
+
+/*
+ * Apply relocations to the values we got from the file. `relbase' is the
+ * target relocation address of the section, and `dataoff' is the target
+ * relocation address of the data in `dest'.
+ */
+int
+ef_reloc(struct elf_file *ef, const void *reldata, int reltype, Elf_Off 
relbase,
+Elf_Off dataoff, size_t len, void *dest)
+{
+   Elf_Addr *where, val;
+   const Elf_Rel *rel;
+   const Elf_Rela *rela;
+   Elf_Addr addend, addr;
+   Elf_Size rtype, symidx;
+
+   switch (reltype) {
+   case EF_RELOC_REL:
+   rel = (const Elf_Rel *)reldata;
+   where = (Elf_Addr *)((char *)dest + relbase + rel->r_offset -
+   dataoff);
+   addend = 0;
+   rtype = ELF_R_TYPE(rel->r_info);
+   symidx = ELF_R_SYM(rel->r_info);
+   break;
+   case EF_RELOC_RELA:
+   rela = (const Elf_Rela *)reldata;
+   where = (Elf_Addr *)((char *)dest + relbase + rela->r_offset -
+   dataoff);
+   addend = rela->r_addend;
+   rtype = ELF_R_TYPE(rela->r_info);
+   symidx = ELF_R_SYM(rela->r_info);
+   break;
+   default:
+   return (EINVAL);
+   }
+
+   if ((char *)where < (char *)dest || (char *)where >= (char *)dest + len)
+   return (0);
+
+   if (reltype == EF_RELOC_REL)
+   addend = *where;
+
+   switch (rtype) {
+#ifdef __LP64__
+   case R_MIPS_64: /* S + A */
+#else
+   case R_MIPS_32: /* S + A */
+#endif
+   addr = EF_SYMADDR(ef, symidx);
+   val = addr + addend;
+   *where = val;
+   break;
+   default:
+   warnx("unhandled relocation type %d", (int)rtype);
+   }
+   return (0);
+}
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r346650 - head/sys/dev/cxgbe/crypto

2019-04-24 Thread John Baldwin
Author: jhb
Date: Wed Apr 24 23:31:46 2019
New Revision: 346650
URL: https://svnweb.freebsd.org/changeset/base/346650

Log:
  Add support for AES-CCM to ccr(4).
  
  This is fairly similar to the AES-GCM support in ccr(4) in that it will
  fall back to software for certain cases (requests with only AAD and
  requests that are too large).
  
  Tested by:cryptocheck, cryptotest.py
  MFC after:1 month
  Sponsored by: Chelsio Communications

Modified:
  head/sys/dev/cxgbe/crypto/t4_crypto.c
  head/sys/dev/cxgbe/crypto/t4_crypto.h

Modified: head/sys/dev/cxgbe/crypto/t4_crypto.c
==
--- head/sys/dev/cxgbe/crypto/t4_crypto.c   Wed Apr 24 23:27:39 2019
(r346649)
+++ head/sys/dev/cxgbe/crypto/t4_crypto.c   Wed Apr 24 23:31:46 2019
(r346650)
@@ -150,6 +150,10 @@ struct ccr_session_gmac {
char ghash_h[GMAC_BLOCK_LEN];
 };
 
+struct ccr_session_ccm_mac {
+   int hash_len;
+};
+
 struct ccr_session_blkcipher {
unsigned int cipher_mode;
unsigned int key_len;
@@ -162,10 +166,11 @@ struct ccr_session_blkcipher {
 struct ccr_session {
bool active;
int pending;
-   enum { HASH, HMAC, BLKCIPHER, AUTHENC, GCM } mode;
+   enum { HASH, HMAC, BLKCIPHER, AUTHENC, GCM, CCM } mode;
union {
struct ccr_session_hmac hmac;
struct ccr_session_gmac gmac;
+   struct ccr_session_ccm_mac ccm_mac;
};
struct ccr_session_blkcipher blkcipher;
 };
@@ -208,6 +213,8 @@ struct ccr_softc {
uint64_t stats_authenc_decrypt;
uint64_t stats_gcm_encrypt;
uint64_t stats_gcm_decrypt;
+   uint64_t stats_ccm_encrypt;
+   uint64_t stats_ccm_decrypt;
uint64_t stats_wr_nomem;
uint64_t stats_inflight;
uint64_t stats_mac_error;
@@ -383,7 +390,7 @@ ccr_populate_wreq(struct ccr_softc *sc, struct chcr_wr
 u_int wr_len, u_int imm_len, u_int sgl_len, u_int hash_size,
 struct cryptop *crp)
 {
-   u_int cctx_size;
+   u_int cctx_size, idata_len;
 
cctx_size = sizeof(struct _key_ctx) + kctx_len;
crwr->wreq.op_to_cctx_size = htobe32(
@@ -417,9 +424,11 @@ ccr_populate_wreq(struct ccr_softc *sc, struct chcr_wr
((wr_len - sizeof(struct fw_crypto_lookaside_wr)) / 16));
 
crwr->sc_imm.cmd_more = htobe32(V_ULPTX_CMD(ULP_TX_SC_IMM) |
-   V_ULP_TX_SC_MORE(imm_len != 0 ? 0 : 1));
-   crwr->sc_imm.len = htobe32(wr_len - offsetof(struct chcr_wr, sec_cpl) -
-   sgl_len);
+   V_ULP_TX_SC_MORE(sgl_len != 0 ? 1 : 0));
+   idata_len = wr_len - offsetof(struct chcr_wr, sec_cpl) - sgl_len;
+   if (imm_len % 16 != 0)
+   idata_len -= 16 - imm_len % 16;
+   crwr->sc_imm.len = htobe32(idata_len);
 }
 
 static int
@@ -1567,6 +1576,481 @@ out:
 }
 
 static void
+generate_ccm_b0(struct cryptodesc *crda, struct cryptodesc *crde,
+u_int hash_size_in_response, const char *iv, char *b0)
+{
+   u_int i, payload_len;
+
+   /* NB: L is already set in the first byte of the IV. */
+   memcpy(b0, iv, CCM_B0_SIZE);
+
+   /* Set length of hash in bits 3 - 5. */
+   b0[0] |= (((hash_size_in_response - 2) / 2) << 3);
+
+   /* Store the payload length as a big-endian value. */
+   payload_len = crde->crd_len;
+   for (i = 0; i < iv[0]; i++) {
+   b0[CCM_CBC_BLOCK_LEN - 1 - i] = payload_len;
+   payload_len >>= 8;
+   }
+
+   /*
+* If there is AAD in the request, set bit 6 in the flags
+* field and store the AAD length as a big-endian value at the
+* start of block 1.  This only assumes a 16-bit AAD length
+* since T6 doesn't support large AAD sizes.
+*/
+   if (crda->crd_len != 0) {
+   b0[0] |= (1 << 6);
+   *(uint16_t *)(b0 + CCM_B0_SIZE) = htobe16(crda->crd_len);
+   }
+}
+
+static int
+ccr_ccm(struct ccr_softc *sc, struct ccr_session *s, struct cryptop *crp,
+struct cryptodesc *crda, struct cryptodesc *crde)
+{
+   char iv[CHCR_MAX_CRYPTO_IV_LEN];
+   struct ulptx_idata *idata;
+   struct chcr_wr *crwr;
+   struct wrqe *wr;
+   char *dst;
+   u_int iv_len, kctx_len, op_type, transhdr_len, wr_len;
+   u_int aad_len, b0_len, hash_size_in_response, imm_len;
+   u_int aad_start, aad_stop, cipher_start, cipher_stop, auth_insert;
+   u_int hmac_ctrl, input_len;
+   int dsgl_nsegs, dsgl_len;
+   int sgl_nsegs, sgl_len;
+   int error;
+
+   if (s->blkcipher.key_len == 0)
+   return (EINVAL);
+
+   /*
+* The crypto engine doesn't handle CCM requests with an empty
+* payload, so handle those in software instead.
+*/
+   if (crde->crd_len == 0)
+   return (EMSGSIZE);
+
+   /*
+* AAD is only permitted before the cipher/plain text, not
+* after.
+*/
+   if (crd

svn commit: r346649 - head/sys/opencrypto

2019-04-24 Thread John Baldwin
Author: jhb
Date: Wed Apr 24 23:27:39 2019
New Revision: 346649
URL: https://svnweb.freebsd.org/changeset/base/346649

Log:
  Don't panic for empty CCM requests.
  
  A request to encrypt an empty payload without any AAD is unusual, but
  it is defined behavior.  Removing this assertion removes a panic and
  instead returns the correct tag for an empty buffer.
  
  Reviewed by:  cem, sef
  MFC after:2 weeks
  Sponsored by: Chelsio Communications
  Differential Revision:https://reviews.freebsd.org/D20043

Modified:
  head/sys/opencrypto/cbc_mac.c

Modified: head/sys/opencrypto/cbc_mac.c
==
--- head/sys/opencrypto/cbc_mac.c   Wed Apr 24 23:18:10 2019
(r346648)
+++ head/sys/opencrypto/cbc_mac.c   Wed Apr 24 23:27:39 2019
(r346649)
@@ -82,9 +82,6 @@ AES_CBC_MAC_Reinit(struct aes_cbc_mac_ctx *ctx, const 
uint8_t *bp = b0, flags = 0;
uint8_t L = 0;
uint64_t dataLength = ctx->cryptDataLength;
-   
-   KASSERT(ctx->authDataLength != 0 || ctx->cryptDataLength != 0,
-   ("Auth Data and Data lengths cannot both be 0"));
 
KASSERT(nonceLen >= 7 && nonceLen <= 13,
("nonceLen must be between 7 and 13 bytes"));
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r346648 - head/sys/dev/cxgbe/crypto

2019-04-24 Thread John Baldwin
Author: jhb
Date: Wed Apr 24 23:18:10 2019
New Revision: 346648
URL: https://svnweb.freebsd.org/changeset/base/346648

Log:
  Fix requests for "plain" SHA digests of an empty buffer.
  
  To workaround limitations in the crypto engine, empty buffers are
  handled by manually constructing the final length block as the payload
  passed to the crypto engine and disabling the normal "final" handling.
  For HMAC this length block should hold the length of a single block
  since the hash is actually the hash of the IPAD digest, but for
  "plain" SHA the length should be zero instead.
  
  Reported by:  NIST SHA1 test failure
  MFC after:2 weeks
  Sponsored by: Chelsio Communications

Modified:
  head/sys/dev/cxgbe/crypto/t4_crypto.c

Modified: head/sys/dev/cxgbe/crypto/t4_crypto.c
==
--- head/sys/dev/cxgbe/crypto/t4_crypto.c   Wed Apr 24 23:10:19 2019
(r346647)
+++ head/sys/dev/cxgbe/crypto/t4_crypto.c   Wed Apr 24 23:18:10 2019
(r346648)
@@ -537,8 +537,9 @@ ccr_hash(struct ccr_softc *sc, struct ccr_session *s, 
dst = (char *)(crwr + 1) + kctx_len + DUMMY_BYTES;
if (crd->crd_len == 0) {
dst[0] = 0x80;
-   *(uint64_t *)(dst + axf->blocksize - sizeof(uint64_t)) =
-   htobe64(axf->blocksize << 3);
+   if (s->mode == HMAC)
+   *(uint64_t *)(dst + axf->blocksize - sizeof(uint64_t)) =
+   htobe64(axf->blocksize << 3);
} else if (imm_len != 0)
crypto_copydata(crp->crp_flags, crp->crp_buf, crd->crd_skip,
crd->crd_len, dst);
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r346647 - head/sys/dev/acpi_support

2019-04-24 Thread Oleksandr Tymoshenko
Author: gonzo
Date: Wed Apr 24 23:10:19 2019
New Revision: 346647
URL: https://svnweb.freebsd.org/changeset/base/346647

Log:
  [acpi_ibm] Add support for newer Thinkpad models
  
  Add support for newer Thinkpad models with id LEN0268. Was tested on
  Thinkpad T480 and ThinkPad X1 Yoga 2nd gen.
  
  PR:   229120
  Submitted by: Ali Abdallah 
  MFC after:1 week

Modified:
  head/sys/dev/acpi_support/acpi_ibm.c

Modified: head/sys/dev/acpi_support/acpi_ibm.c
==
--- head/sys/dev/acpi_support/acpi_ibm.cWed Apr 24 22:35:29 2019
(r346646)
+++ head/sys/dev/acpi_support/acpi_ibm.cWed Apr 24 23:10:19 2019
(r346647)
@@ -349,7 +349,7 @@ static devclass_t acpi_ibm_devclass;
 DRIVER_MODULE(acpi_ibm, acpi, acpi_ibm_driver, acpi_ibm_devclass,
  0, 0);
 MODULE_DEPEND(acpi_ibm, acpi, 1, 1, 1);
-static char*ibm_ids[] = {"IBM0068", "LEN0068", NULL};
+static char*ibm_ids[] = {"IBM0068", "LEN0068", "LEN0268", NULL};
 
 static void
 ibm_led(void *softc, int onoff)
@@ -428,9 +428,14 @@ static int
 acpi_ibm_attach(device_t dev)
 {
int i;
+   int hkey;
struct acpi_ibm_softc   *sc;
char *maker, *product;
-   devclass_t  ec_devclass;
+   ACPI_OBJECT_LIST input;
+   ACPI_OBJECT params[1];
+   ACPI_OBJECT out_obj;
+   ACPI_BUFFER result;
+   devclass_t ec_devclass;
 
ACPI_FUNCTION_TRACE((char *)(uintptr_t) __func__);
 
@@ -465,15 +470,42 @@ acpi_ibm_attach(device_t dev)
"initialmask", CTLFLAG_RD,
&sc->events_initialmask, 0, "Initial eventmask");
 
-   /* The availmask is the bitmask of supported events */
-   if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
-   IBM_NAME_EVENTS_AVAILMASK, &sc->events_availmask)))
+   if (ACPI_SUCCESS (acpi_GetInteger(sc->handle, "MHKV", &hkey))) {
+   device_printf(dev, "Firmware version is 0x%X\n", hkey);
+   switch(hkey >> 8)
+   {
+   case 1:
+   /* The availmask is the bitmask of supported 
events */
+   if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
+   IBM_NAME_EVENTS_AVAILMASK, 
&sc->events_availmask)))
+   sc->events_availmask = 0x;
+   break;
+
+   case 2:
+   result.Length = sizeof(out_obj);
+   result.Pointer = &out_obj;
+   params[0].Type = ACPI_TYPE_INTEGER;
+   params[0].Integer.Value = 1;
+   input.Pointer = params;
+   input.Count = 1;
+
+   sc->events_availmask = 0x;
+
+   if (ACPI_SUCCESS(AcpiEvaluateObject (sc->handle,
+   IBM_NAME_EVENTS_AVAILMASK, &input, 
&result)))
+   sc->events_availmask = 
out_obj.Integer.Value;
+   break;
+   default:
+   device_printf(dev, "Unknown firmware version 
0x%x\n", hkey);
+   break;
+   }
+   } else
sc->events_availmask = 0x;
 
SYSCTL_ADD_UINT(sc->sysctl_ctx,
-   SYSCTL_CHILDREN(sc->sysctl_tree), OID_AUTO,
-   "availmask", CTLFLAG_RD,
-   &sc->events_availmask, 0, "Mask of supported events");
+   SYSCTL_CHILDREN(sc->sysctl_tree), OID_AUTO,
+   "availmask", CTLFLAG_RD,
+   &sc->events_availmask, 0, "Mask of supported 
events");
}
 
/* Hook up proc nodes */
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r346646 - head/tools/boot

2019-04-24 Thread Rebecca Cran
Author: bcran
Date: Wed Apr 24 22:35:29 2019
New Revision: 346646
URL: https://svnweb.freebsd.org/changeset/base/346646

Log:
  Fix install-boot.sh and rootgen.sh UEFI bugs
  
  tools/boot/install-boot.sh was assuming that if a device was passed in,
  it should operate on the current system and run efibootmgr etc. to
  update the boot manager. However, rootgen.sh passes a md(4) device and
  not a fixed disk.
  
  Add a -u option to install-boot.sh to tell it to update the system
  in-place and run efibootmgr etc.
  
  Also, source install-boot.sh in rootgen.sh to allow it to find and
  call make_esp_file etc. And pass the loader file to make_esp_file instead
  of a directory name.
  
  Reported by:  ian
  Reviewed by:  ian,imp,tsoome
  Differential Revision:https://reviews.freebsd.org/D19992

Modified:
  head/tools/boot/install-boot.sh
  head/tools/boot/rootgen.sh

Modified: head/tools/boot/install-boot.sh
==
--- head/tools/boot/install-boot.sh Wed Apr 24 20:30:45 2019
(r346645)
+++ head/tools/boot/install-boot.sh Wed Apr 24 22:35:29 2019
(r346646)
@@ -134,29 +134,37 @@ make_esp_device() {
 echo "Copying loader to /EFI/freebsd on ESP"
 cp "${file}" "${mntpt}/EFI/freebsd/loader.efi"
 
-existingbootentryloaderfile=$(efibootmgr -v | grep 
"${mntpt}//EFI/freebsd/loader.efi")
+if [ -n "${updatesystem}" ]; then
+existingbootentryloaderfile=$(efibootmgr -v | grep 
"${mntpt}//EFI/freebsd/loader.efi")
 
-if [ -z "$existingbootentryloaderfile" ]; then
-# Try again without the double forward-slash in the path
-existingbootentryloaderfile=$(efibootmgr -v | grep 
"${mntpt}/EFI/freebsd/loader.efi")
-fi
-
-if [ -z "$existingbootentryloaderfile" ]; then
-echo "Creating UEFI boot entry for FreeBSD"
-efibootmgr --create --label FreeBSD --loader 
"${mntpt}/EFI/freebsd/loader.efi" > /dev/null
-if [ $? -ne 0 ]; then
-die "Failed to create new boot entry"
+if [ -z "$existingbootentryloaderfile" ]; then
+# Try again without the double forward-slash in the path
+existingbootentryloaderfile=$(efibootmgr -v | grep 
"${mntpt}/EFI/freebsd/loader.efi")
 fi
 
-# When creating new entries, efibootmgr doesn't mark them active, so 
we need to
-# do so. It doesn't make it easy to find which entry it just added, so 
rely on
-# the fact that it places the new entry first in BootOrder.
-bootorder=$(efivar --name 
8be4df61-93ca-11d2-aa0d-00e098032b8c-BootOrder --print --no-name --hex | head 
-1)
-bootentry=$(echo "${bootorder}" | cut -w -f 3)$(echo "${bootorder}" | 
cut -w -f 2)
-echo "Marking UEFI boot entry ${bootentry} active"
-efibootmgr --activate "${bootentry}" > /dev/null
+if [ -z "$existingbootentryloaderfile" ]; then
+echo "Creating UEFI boot entry for FreeBSD"
+efibootmgr --create --label FreeBSD --loader 
"${mntpt}/EFI/freebsd/loader.efi" > /dev/null
+if [ $? -ne 0 ]; then
+die "Failed to create new boot entry"
+fi
+
+# When creating new entries, efibootmgr doesn't mark them active, 
so we need to
+# do so. It doesn't make it easy to find which entry it just 
added, so rely on
+# the fact that it places the new entry first in BootOrder.
+bootorder=$(efivar --name 
8be4df61-93ca-11d2-aa0d-00e098032b8c-BootOrder --print --no-name --hex | head 
-1)
+bootentry=$(echo "${bootorder}" | cut -w -f 3)$(echo 
"${bootorder}" | cut -w -f 2)
+echo "Marking UEFI boot entry ${bootentry} active"
+efibootmgr --activate "${bootentry}" > /dev/null
+else
+echo "Existing UEFI FreeBSD boot entry found: not creating a new 
one"
+fi
 else
-echo "Existing UEFI FreeBSD boot entry found: not creating a new one"
+   # Configure for booting from removable media
+   if [ ! -d "${mntpt}/EFI/BOOT" ]; then
+   mkdir -p "${mntpt}/EFI/BOOT"
+   fi
+   cp "${file}" "${mntpt}/EFI/BOOT/${efibootname}.efi"
 fi
 
 umount "${mntpt}"
@@ -362,6 +370,8 @@ usage() {
printf ' -f fs filesystem type: ufs or zfs\n'
printf ' -g geli   yes or no\n'
printf ' -hthis help/usage text\n'
+   printf ' -uRun commands such as efibootmgr to update the\n'
+   printf '   currently running system\n'
printf ' -o optargsoptional arguments\n'
printf ' -s scheme mbr or gpt\n'
exit 0
@@ -372,7 +382,7 @@ srcroot=/
 # Note: we really don't support geli boot in this script yet.
 geli=nogeli
 
-while getopts "b:d:f:g:ho:s:" opt; do
+while getopts "b:d:f:g:ho:s:u" opt; do
 case "$opt" in
b)
bios=${OPTARG}
@@ -388,6 +398,9 @@ while getopts "b:d:f:g:ho:s:" op

svn commit: r346645 - in head/sys: compat/linuxkpi/common/include/linux compat/linuxkpi/common/src sys

2019-04-24 Thread Tycho Nightingale
Author: tychon
Date: Wed Apr 24 20:30:45 2019
New Revision: 346645
URL: https://svnweb.freebsd.org/changeset/base/346645

Log:
  LinuxKPI should use bus_dma(9) to be compatible with an IOMMU
  
  Reviewed by:  hselasky, kib
  Tested by:greg@unrelenting.technology
  Sponsored by: Dell EMC Isilon
  Differential Revision:https://reviews.freebsd.org/D19845

Modified:
  head/sys/compat/linuxkpi/common/include/linux/device.h
  head/sys/compat/linuxkpi/common/include/linux/dma-mapping.h
  head/sys/compat/linuxkpi/common/include/linux/dmapool.h
  head/sys/compat/linuxkpi/common/include/linux/pci.h
  head/sys/compat/linuxkpi/common/include/linux/scatterlist.h
  head/sys/compat/linuxkpi/common/src/linux_pci.c
  head/sys/sys/param.h

Modified: head/sys/compat/linuxkpi/common/include/linux/device.h
==
--- head/sys/compat/linuxkpi/common/include/linux/device.h  Wed Apr 24 
19:56:02 2019(r346644)
+++ head/sys/compat/linuxkpi/common/include/linux/device.h  Wed Apr 24 
20:30:45 2019(r346645)
@@ -105,7 +105,7 @@ struct device {
struct class*class;
void(*release)(struct device *dev);
struct kobject  kobj;
-   uint64_t*dma_mask;
+   void*dma_priv;
void*driver_data;
unsigned intirq;
 #defineLINUX_IRQ_INVALID   65535

Modified: head/sys/compat/linuxkpi/common/include/linux/dma-mapping.h
==
--- head/sys/compat/linuxkpi/common/include/linux/dma-mapping.h Wed Apr 24 
19:56:02 2019(r346644)
+++ head/sys/compat/linuxkpi/common/include/linux/dma-mapping.h Wed Apr 24 
20:30:45 2019(r346645)
@@ -90,6 +90,16 @@ struct dma_map_ops {
 
 #defineDMA_BIT_MASK(n) ((2ULL << ((n) - 1)) - 1ULL)
 
+int linux_dma_tag_init(struct device *dev, u64 mask);
+void *linux_dma_alloc_coherent(struct device *dev, size_t size,
+dma_addr_t *dma_handle, gfp_t flag);
+dma_addr_t linux_dma_map_phys(struct device *dev, vm_paddr_t phys, size_t len);
+void linux_dma_unmap(struct device *dev, dma_addr_t dma_addr, size_t size);
+int linux_dma_map_sg_attrs(struct device *dev, struct scatterlist *sgl,
+int nents, enum dma_data_direction dir, struct dma_attrs *attrs);
+void linux_dma_unmap_sg_attrs(struct device *dev, struct scatterlist *sg,
+int nents, enum dma_data_direction dir, struct dma_attrs *attrs);
+
 static inline int
 dma_supported(struct device *dev, u64 mask)
 {
@@ -102,11 +112,10 @@ static inline int
 dma_set_mask(struct device *dev, u64 dma_mask)
 {
 
-   if (!dev->dma_mask || !dma_supported(dev, dma_mask))
+   if (!dev->dma_priv || !dma_supported(dev, dma_mask))
return -EIO;
 
-   *dev->dma_mask = dma_mask;
-   return (0);
+   return (linux_dma_tag_init(dev, dma_mask));
 }
 
 static inline int
@@ -134,24 +143,7 @@ static inline void *
 dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
 gfp_t flag)
 {
-   vm_paddr_t high;
-   size_t align;
-   void *mem;
-
-   if (dev != NULL && dev->dma_mask)
-   high = *dev->dma_mask;
-   else if (flag & GFP_DMA32)
-   high = BUS_SPACE_MAXADDR_32BIT;
-   else
-   high = BUS_SPACE_MAXADDR;
-   align = PAGE_SIZE << get_order(size);
-   mem = (void *)kmem_alloc_contig(size, flag, 0, high, align, 0,
-   VM_MEMATTR_DEFAULT);
-   if (mem)
-   *dma_handle = vtophys(mem);
-   else
-   *dma_handle = 0;
-   return (mem);
+   return (linux_dma_alloc_coherent(dev, size, dma_handle, flag));
 }
 
 static inline void *
@@ -164,25 +156,27 @@ dma_zalloc_coherent(struct device *dev, size_t size, d
 
 static inline void
 dma_free_coherent(struct device *dev, size_t size, void *cpu_addr,
-dma_addr_t dma_handle)
+dma_addr_t dma_addr)
 {
 
+   linux_dma_unmap(dev, dma_addr, size);
kmem_free((vm_offset_t)cpu_addr, size);
 }
 
-/* XXX This only works with no iommu. */
 static inline dma_addr_t
 dma_map_single_attrs(struct device *dev, void *ptr, size_t size,
 enum dma_data_direction dir, struct dma_attrs *attrs)
 {
 
-   return vtophys(ptr);
+   return (linux_dma_map_phys(dev, vtophys(ptr), size));
 }
 
 static inline void
-dma_unmap_single_attrs(struct device *dev, dma_addr_t addr, size_t size,
+dma_unmap_single_attrs(struct device *dev, dma_addr_t dma_addr, size_t size,
 enum dma_data_direction dir, struct dma_attrs *attrs)
 {
+
+   linux_dma_unmap(dev, dma_addr, size);
 }
 
 static inline dma_addr_t
@@ -190,26 +184,23 @@ dma_map_page_attrs(struct device *dev, struct page *pa
 size_t size, enum dma_data_direction dir, unsigned long attrs)
 {
 
-   return (VM_PAGE_TO_PHYS(page) + offset);
+   return (linux_dma_map_phys(dev, VM_PAGE_TO_PHYS(page) + offset, size));
 }
 
 static inline

svn commit: r346644 - head/sys/geom

2019-04-24 Thread Alexander Motin
Author: mav
Date: Wed Apr 24 19:56:02 2019
New Revision: 346644
URL: https://svnweb.freebsd.org/changeset/base/346644

Log:
  Call delist_dev() before destroy_dev_sched_cb().
  
  destroy_dev_sched_cb() is excessively asynchronous, and during media change
  retaste new provider may appear sooner then device of the previous one get
  destroyed.
  
  MFC after:1 week
  Sponsored by: iXsystems, Inc.

Modified:
  head/sys/geom/geom_dev.c

Modified: head/sys/geom/geom_dev.c
==
--- head/sys/geom/geom_dev.cWed Apr 24 18:24:22 2019(r346643)
+++ head/sys/geom/geom_dev.cWed Apr 24 19:56:02 2019(r346644)
@@ -863,6 +863,7 @@ g_dev_orphan(struct g_consumer *cp)
(void)clear_dumper(curthread);
 
/* Destroy the struct cdev *so we get no more requests */
+   delist_dev(dev);
destroy_dev_sched_cb(dev, g_dev_callback, cp);
 }
 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r346643 - head/sys/x86/x86

2019-04-24 Thread Conrad Meyer
Author: cem
Date: Wed Apr 24 18:24:22 2019
New Revision: 346643
URL: https://svnweb.freebsd.org/changeset/base/346643

Log:
  x86: Halt non-BSP CPUs on panic IPI_STOP
  
  We may need the BSP to reboot, but we don't need any AP CPU that isn't the
  panic thread.  Any CPU landing in this routine during panic isn't the panic
  thread, so we can just detect !BSP && panic and shut down the logical core.
  
  The savings can be demonstrated in a bhyve guest with multiple cores; before
  this change, N guest threads would spin at 100% CPU.  After this change,
  only one or two threads spin (depending on if the panicing CPU was the BSP
  or not).
  
  Konstantin points out that this may break any future patches which allow
  switching ddb(4) CPUs after panic and examining CPU-local state that cannot
  be inspected remotely.  In the event that such a mechanism is incorporated,
  this behavior could be made configurable by tunable/sysctl.
  
  Reviewed by:  kib
  Sponsored by: Dell EMC Isilon
  Differential Revision:https://reviews.freebsd.org/D20019

Modified:
  head/sys/x86/x86/mp_x86.c

Modified: head/sys/x86/x86/mp_x86.c
==
--- head/sys/x86/x86/mp_x86.c   Wed Apr 24 17:30:50 2019(r346642)
+++ head/sys/x86/x86/mp_x86.c   Wed Apr 24 18:24:22 2019(r346643)
@@ -1406,8 +1406,17 @@ cpustop_handler(void)
CPU_SET_ATOMIC(cpu, &stopped_cpus);
 
/* Wait for restart */
-   while (!CPU_ISSET(cpu, &started_cpus))
-   ia32_pause();
+   while (!CPU_ISSET(cpu, &started_cpus)) {
+   ia32_pause();
+
+   /*
+* Halt non-BSP CPUs on panic -- we're never going to need them
+* again, and might as well save power / release resources
+* (e.g., overprovisioned VM infrastructure).
+*/
+   while (__predict_false(!IS_BSP() && panicstr != NULL))
+   halt();
+   }
 
cpustop_handler_post(cpu);
 }
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


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

2019-04-24 Thread Dmitry Chagin
вт, 16 апр. 2019 г. в 16:26, Ed Maste :

> Author: emaste
> Date: Tue Apr 16 13:26:31 2019
> New Revision: 346273
> URL: https://svnweb.freebsd.org/changeset/base/346273
>
> Log:
>   correct readlinkat(2) return type
>
>
Hi, Ed
make sysent?



>   r176215 corrected readlink(2)'s return type and the type of the last
>   argument.  readlink(2) was introduced in r177788 after being developed
>   as part of Google Summer of Code 2007; it appears to have inherited the
>   wrong return type.
>
>   Man pages and header files were already ssize_t; update syscalls.master
>   to match.
>
>   PR:   197915
>   Submitted by: Henning Petersen 
>   MFC after:2 weeks
>
> Modified:
>   head/sys/compat/freebsd32/syscalls.master
>   head/sys/kern/syscalls.master
>
> Modified: head/sys/compat/freebsd32/syscalls.master
>
> ==
> --- head/sys/compat/freebsd32/syscalls.master   Tue Apr 16 12:40:49 2019
>   (r346272)
> +++ head/sys/compat/freebsd32/syscalls.master   Tue Apr 16 13:26:31 2019
>   (r346273)
> @@ -963,7 +963,7 @@
> uint32_t dev); }
>  499AUE_OPENAT_RWTC NOPROTO { int openat(int fd, const char *path, \
> int flag, mode_t mode); }
> -500AUE_READLINKAT  NOPROTO { int readlinkat(int fd, const char *path,
> \
> +500AUE_READLINKAT  NOPROTO { ssize_t readlinkat(int fd, const char
> *path, \
> char *buf, size_t bufsize); }
>  501AUE_RENAMEATNOPROTO { int renameat(int oldfd, const char *old,
> \
> int newfd, const char *new); }
>
> Modified: head/sys/kern/syscalls.master
>
> ==
> --- head/sys/kern/syscalls.master   Tue Apr 16 12:40:49 2019
> (r346272)
> +++ head/sys/kern/syscalls.master   Tue Apr 16 13:26:31 2019
> (r346273)
> @@ -2716,7 +2716,7 @@
> );
> }
>  500AUE_READLINKAT  STD {
> -   int readlinkat(
> +   ssize_t readlinkat(
> int fd,
> _In_z_ const char *path,
> _Out_writes_bytes_(bufsize) char *buf,
>
>
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r346641 - head/lib/libvgl

2019-04-24 Thread Bruce Evans
Author: bde
Date: Wed Apr 24 16:03:35 2019
New Revision: 346641
URL: https://svnweb.freebsd.org/changeset/base/346641

Log:
  Avoid hiding and unhiding the mouse cursor when copying bitmaps to the
  screen.  Instead, copy a merged bitmap 1 line at a time.
  
  This fixes flashing of the cursor and is faster in all modes (especially
  in planar modes).

Modified:
  head/lib/libvgl/bitmap.c
  head/lib/libvgl/mouse.c
  head/lib/libvgl/vgl.h

Modified: head/lib/libvgl/bitmap.c
==
--- head/lib/libvgl/bitmap.cWed Apr 24 15:54:18 2019(r346640)
+++ head/lib/libvgl/bitmap.cWed Apr 24 16:03:35 2019(r346641)
@@ -167,8 +167,17 @@ int
 __VGLBitmapCopy(VGLBitmap *src, int srcx, int srcy,
  VGLBitmap *dst, int dstx, int dsty, int width, int hight)
 {
-  int srcline, dstline, yend, yextra, ystep;
-
+  byte *buffer, *p;
+  int mousemerge, srcline, dstline, yend, yextra, ystep;
+  
+  mousemerge = 0;
+  if (hight < 0) {
+hight = -hight;
+mousemerge = (dst == VGLDisplay &&
+ VGLMouseOverlap(dstx, dsty, width, hight));
+if (mousemerge)
+  buffer = alloca(width*src->PixelBytes);
+  }
   if (srcx>src->VXsize || srcy>src->VYsize
|| dstx>dst->VXsize || dsty>dst->VYsize)
 return -1;  
@@ -204,8 +213,13 @@ __VGLBitmapCopy(VGLBitmap *src, int srcx, int srcy,
   }
   for (srcline = srcy + yextra, dstline = dsty + yextra; srcline != yend;
srcline += ystep, dstline += ystep) {
-WriteVerticalLine(dst, dstx, dstline, width, 
-  src->Bitmap+(srcline*src->VXsize+srcx)*dst->PixelBytes);
+p = src->Bitmap+(srcline*src->VXsize+srcx)*dst->PixelBytes;
+if (mousemerge && VGLMouseOverlap(dstx, dstline, width, 1)) {
+  bcopy(p, buffer, width*src->PixelBytes);
+  p = buffer;
+  VGLMouseMerge(dstx, dstline, width, p);
+}
+WriteVerticalLine(dst, dstx, dstline, width, p);
   }
   return 0;
 }
@@ -214,36 +228,29 @@ int
 VGLBitmapCopy(VGLBitmap *src, int srcx, int srcy,
  VGLBitmap *dst, int dstx, int dsty, int width, int hight)
 {
-  int error, mouseoverlap;
+  int error;
 
+  if (hight < 0)
+return -1;
   if (src == VGLDisplay)
 src = &VGLVDisplay;
   if (src->Type != MEMBUF)
 return -1; /* invalid */
   if (dst == VGLDisplay) {
 VGLMouseFreeze();
-mouseoverlap = VGLMouseOverlap(dstx, dsty, width, hight);
-if (mouseoverlap)
-  VGLMousePointerHide();
+__VGLBitmapCopy(src, srcx, srcy, &VGLVDisplay, dstx, dsty, width, hight);
 error = __VGLBitmapCopy(src, srcx, srcy, &VGLVDisplay, dstx, dsty,
 width, hight);
-if (error != 0) {
-  if (mouseoverlap)
-VGLMousePointerShow();
-  VGLMouseUnFreeze();
+if (error != 0)
   return error;
-}
 src = &VGLVDisplay;
 srcx = dstx;
 srcy = dsty;
   } else if (dst->Type != MEMBUF)
 return -1; /* invalid */
-  error = __VGLBitmapCopy(src, srcx, srcy, dst, dstx, dsty, width, hight);
-  if (dst == VGLDisplay) {
-if (mouseoverlap)
-  VGLMousePointerShow();
+  error = __VGLBitmapCopy(src, srcx, srcy, dst, dstx, dsty, width, -hight);
+  if (dst == VGLDisplay)
 VGLMouseUnFreeze();
-  }
   return error;
 }
 

Modified: head/lib/libvgl/mouse.c
==
--- head/lib/libvgl/mouse.c Wed Apr 24 15:54:18 2019(r346640)
+++ head/lib/libvgl/mouse.c Wed Apr 24 16:03:35 2019(r346641)
@@ -356,6 +356,25 @@ VGLMouseOverlap(int x, int y, int width, int hight)
 }
 
 void
+VGLMouseMerge(int x, int y, int width, byte *line)
+{
+  int pos, x1, xend, xstart;
+
+  xstart = x;
+  if (xstart < VGLMouseXpos)
+xstart = VGLMouseXpos;
+  xend = x + width;
+  if (xend > VGLMouseXpos + MOUSE_IMG_SIZE)
+xend = VGLMouseXpos + MOUSE_IMG_SIZE;
+  for (x1 = xstart; x1 < xend; x1++) {
+pos = (y - VGLMouseYpos) * MOUSE_IMG_SIZE + x1 - VGLMouseXpos;
+if (VGLMouseAndMask->Bitmap[pos])
+  bcopy(&VGLMouseOrMask->Bitmap[pos * VGLDisplay->PixelBytes],
+&line[(x1 - x) * VGLDisplay->PixelBytes], VGLDisplay->PixelBytes);
+  }
+}
+
+void
 VGLMouseUnFreeze()
 {
   INTON();

Modified: head/lib/libvgl/vgl.h
==
--- head/lib/libvgl/vgl.h   Wed Apr 24 15:54:18 2019(r346640)
+++ head/lib/libvgl/vgl.h   Wed Apr 24 16:03:35 2019(r346641)
@@ -136,6 +136,7 @@ void VGLMouseRestore(void);
 int VGLMouseStatus(int *x, int *y, char *buttons);
 void VGLMouseFreeze(void);
 int VGLMouseFreezeXY(int x, int y);
+void VGLMouseMerge(int x, int y, int width, byte *line);
 int VGLMouseOverlap(int x, int y, int width, int hight);
 void VGLMouseUnFreeze(void);
 /* simple.c */
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send 

svn commit: r346639 - head/lib/libvgl

2019-04-24 Thread Bruce Evans
Author: bde
Date: Wed Apr 24 15:35:29 2019
New Revision: 346639
URL: https://svnweb.freebsd.org/changeset/base/346639

Log:
  Refactor mouse freezing and fix some minor bugs.
  
  VGLMouseFreeze() now only defers mouse signals and leaves it to higher
  levels to hide and unhide the mouse cursor if necessary.  (It is never
  necessary, but is done to simplify the implementation.  It is slow and
  flashes the cursor.  It is still done for copying bitmaps and clearing.)
  
  VGLMouseUnFreeze() now only undoes 1 level of freezing.  Its old
  optimization to reduce mouse redrawing is too hard to do with unhiding
  in higher levels, and its undoing of multiple levels was a historical
  mistake.
  
  VGLMouseOverlap() determines if a region overlaps the (full) mouse region.
  
  VGLMouseFreezeXY() is the freezing and a precise overlap check combined
  for the special case of writing a single pixel.  This is the single-pixel
  case of the old VGLMouseFreeze() with cleanups.
  
  Fixes:
  - check in more cases that the application didn't pass an invalid VIDBUF
  - check for errors from copying a bitmap to the shadow buffer
  - freeze the mouse before writing to the shadow buffer in all cases.  This
was not done for the case of writing a single pixel (there was a race)
  - don't spell the #defined values for VGLMouseShown as 0, 1 or boolean.

Modified:
  head/lib/libvgl/bitmap.c
  head/lib/libvgl/mouse.c
  head/lib/libvgl/simple.c
  head/lib/libvgl/vgl.h

Modified: head/lib/libvgl/bitmap.c
==
--- head/lib/libvgl/bitmap.cWed Apr 24 15:02:59 2019(r346638)
+++ head/lib/libvgl/bitmap.cWed Apr 24 15:35:29 2019(r346639)
@@ -214,23 +214,36 @@ int
 VGLBitmapCopy(VGLBitmap *src, int srcx, int srcy,
  VGLBitmap *dst, int dstx, int dsty, int width, int hight)
 {
-  int error;
+  int error, mouseoverlap;
 
   if (src == VGLDisplay)
 src = &VGLVDisplay;
   if (src->Type != MEMBUF)
 return -1; /* invalid */
   if (dst == VGLDisplay) {
-VGLMouseFreeze(dstx, dsty, width, hight, 0);
-__VGLBitmapCopy(src, srcx, srcy, &VGLVDisplay, dstx, dsty, width, hight);
+VGLMouseFreeze();
+mouseoverlap = VGLMouseOverlap(dstx, dsty, width, hight);
+if (mouseoverlap)
+  VGLMousePointerHide();
+error = __VGLBitmapCopy(src, srcx, srcy, &VGLVDisplay, dstx, dsty,
+width, hight);
+if (error != 0) {
+  if (mouseoverlap)
+VGLMousePointerShow();
+  VGLMouseUnFreeze();
+  return error;
+}
 src = &VGLVDisplay;
 srcx = dstx;
 srcy = dsty;
   } else if (dst->Type != MEMBUF)
 return -1; /* invalid */
   error = __VGLBitmapCopy(src, srcx, srcy, dst, dstx, dsty, width, hight);
-  if (dst == VGLDisplay)
+  if (dst == VGLDisplay) {
+if (mouseoverlap)
+  VGLMousePointerShow();
 VGLMouseUnFreeze();
+  }
   return error;
 }
 

Modified: head/lib/libvgl/mouse.c
==
--- head/lib/libvgl/mouse.c Wed Apr 24 15:02:59 2019(r346638)
+++ head/lib/libvgl/mouse.c Wed Apr 24 15:35:29 2019(r346639)
@@ -89,7 +89,7 @@ static VGLBitmap VGLMouseStdOrMask = 
 VGLBITMAP_INITIALIZER(MEMBUF, MOUSE_IMG_SIZE, MOUSE_IMG_SIZE, StdOrMask);
 static VGLBitmap *VGLMouseAndMask, *VGLMouseOrMask;
 static int VGLMouseVisible = 0;
-static int VGLMouseShown = 0;
+static int VGLMouseShown = VGL_MOUSEHIDE;
 static int VGLMouseXpos = 0;
 static int VGLMouseYpos = 0;
 static int VGLMouseButtons = 0;
@@ -316,48 +316,47 @@ VGLMouseStatus(int *x, int *y, char *buttons)
   return VGLMouseShown;
 }
 
-int
-VGLMouseFreeze(int x, int y, int width, int hight, u_long color)
+void
+VGLMouseFreeze(void)
 {
-INTOFF();
-if (width > 1 || hight > 1 || (color & 0xc000) == 0) { /* bitmap */
-  if (VGLMouseShown == 1) {
-int overlap;
+  INTOFF();
+}
 
-if (x > VGLMouseXpos)
-  overlap = (VGLMouseXpos + MOUSE_IMG_SIZE) - x;
-else
-  overlap = (x + width) - VGLMouseXpos;
-if (overlap > 0) {
-  if (y > VGLMouseYpos)
-overlap = (VGLMouseYpos + MOUSE_IMG_SIZE) - y;
-  else
-overlap = (y + hight) - VGLMouseYpos;
-  if (overlap > 0)
-VGLMousePointerHide();
-} 
-  }
-}
-else { /* bit */
-  if (VGLMouseShown &&
-  x >= VGLMouseXpos && x < VGLMouseXpos + MOUSE_IMG_SIZE &&
-  y >= VGLMouseYpos && y < VGLMouseYpos + MOUSE_IMG_SIZE) {
-if (color & 0x8000) {  /* Set */
-  if (VGLMouseAndMask->Bitmap 
-[(y-VGLMouseYpos)*MOUSE_IMG_SIZE+(x-VGLMouseXpos)]) {
-return 1;
-  }   
-}   
-  }   
-}
+int
+VGLMouseFreezeXY(int x, int y)
+{
+  INTOFF();
+  if (VGLMouseShown != VGL_MOUSESHOW)
+return 0;
+  if (x >= VGLMouseXpos && x <

svn commit: r346634 - head/sys/dev/cadence

2019-04-24 Thread Ruslan Bukin
Author: br
Date: Wed Apr 24 13:44:30 2019
New Revision: 346634
URL: https://svnweb.freebsd.org/changeset/base/346634

Log:
  Add support for Cadence network controller found in HiFive Unleashed board.
  
  Reviewed by:  markj
  Sponsored by: DARPA, AFRL
  Differential Revision:https://reviews.freebsd.org/D19798

Modified:
  head/sys/dev/cadence/if_cgem.c

Modified: head/sys/dev/cadence/if_cgem.c
==
--- head/sys/dev/cadence/if_cgem.c  Wed Apr 24 13:41:46 2019
(r346633)
+++ head/sys/dev/cadence/if_cgem.c  Wed Apr 24 13:44:30 2019
(r346634)
@@ -98,6 +98,12 @@ __FBSDID("$FreeBSD$");
 #define CGEM_CKSUM_ASSIST  (CSUM_IP | CSUM_TCP | CSUM_UDP | \
 CSUM_TCP_IPV6 | CSUM_UDP_IPV6)
 
+static struct ofw_compat_data compat_data[] = {
+   { "cadence,gem",1 },
+   { "cdns,macb",  1 },
+   { NULL, 0 },
+};
+
 struct cgem_softc {
if_tifp;
struct mtx  sc_mtx;
@@ -1635,7 +1641,7 @@ cgem_probe(device_t dev)
if (!ofw_bus_status_okay(dev))
return (ENXIO);
 
-   if (!ofw_bus_is_compatible(dev, "cadence,gem"))
+   if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0)
return (ENXIO);
 
device_set_desc(dev, "Cadence CGEM Gigabit Ethernet Interface");
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r346633 - head/sys/riscv/riscv

2019-04-24 Thread Ruslan Bukin
Author: br
Date: Wed Apr 24 13:41:46 2019
New Revision: 346633
URL: https://svnweb.freebsd.org/changeset/base/346633

Log:
  Implement pic_pre_ithread(), pic_post_ithread().
  
  Reviewed by:  markj
  Sponsored by: DARPA, AFRL
  Differential Revision:https://reviews.freebsd.org/D19819

Modified:
  head/sys/riscv/riscv/plic.c

Modified: head/sys/riscv/riscv/plic.c
==
--- head/sys/riscv/riscv/plic.c Wed Apr 24 13:32:04 2019(r346632)
+++ head/sys/riscv/riscv/plic.c Wed Apr 24 13:41:46 2019(r346633)
@@ -249,6 +249,30 @@ plic_attach(device_t dev)
return (intr_pic_claim_root(sc->dev, xref, plic_intr, sc, 0));
 }
 
+static void
+plic_pre_ithread(device_t dev, struct intr_irqsrc *isrc)
+{
+   struct plic_softc *sc;
+   struct plic_irqsrc *src;
+
+   sc = device_get_softc(dev);
+   src = (struct plic_irqsrc *)isrc;
+
+   WR4(sc, PLIC_PRIORITY(src->irq), 0);
+}
+
+static void
+plic_post_ithread(device_t dev, struct intr_irqsrc *isrc)
+{
+   struct plic_softc *sc;
+   struct plic_irqsrc *src;
+
+   sc = device_get_softc(dev);
+   src = (struct plic_irqsrc *)isrc;
+
+   WR4(sc, PLIC_PRIORITY(src->irq), 1);
+}
+
 static device_method_t plic_methods[] = {
DEVMETHOD(device_probe, plic_probe),
DEVMETHOD(device_attach,plic_attach),
@@ -256,6 +280,8 @@ static device_method_t plic_methods[] = {
DEVMETHOD(pic_disable_intr, plic_disable_intr),
DEVMETHOD(pic_enable_intr,  plic_enable_intr),
DEVMETHOD(pic_map_intr, plic_map_intr),
+   DEVMETHOD(pic_pre_ithread,  plic_pre_ithread),
+   DEVMETHOD(pic_post_ithread, plic_post_ithread),
 
DEVMETHOD_END
 };
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r346632 - head/sys/net

2019-04-24 Thread Andrew Gallatin
Author: gallatin
Date: Wed Apr 24 13:32:04 2019
New Revision: 346632
URL: https://svnweb.freebsd.org/changeset/base/346632

Log:
  iflib: Add pfil hooks
  
  As with mlx5en, the idea is to drop unwanted traffic as early
  in receive as possible, before mbufs are allocated and anything
  is passed up the stack.  This can save considerable CPU time
  when a machine is under a flooding style DOS attack.
  
  The major change here is to remove the unneeded abstraction where
  callers of rxd_frag_to_sd() get back a pointer to the mbuf ring, and
  are responsible for NULL'ing that mbuf themselves. Now this happens
  directly in rxd_frag_to_sd(), and it returns an mbuf. This allows us
  to use the decision (and potentially mbuf) returned by the pfil
  hooks. The driver can now recycle mbufs to avoid re-allocation when
  packets are dropped.
  
  Reviewed by:  marius  (shurd and erj also provided feedback)
  Sponsored by: Netflix
  Differential Revision:https://reviews.freebsd.org/D19645

Modified:
  head/sys/net/iflib.c

Modified: head/sys/net/iflib.c
==
--- head/sys/net/iflib.cWed Apr 24 13:15:56 2019(r346631)
+++ head/sys/net/iflib.cWed Apr 24 13:32:04 2019(r346632)
@@ -59,6 +59,7 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -432,6 +433,7 @@ struct iflib_rxq {
if_ctx_tifr_ctx;
iflib_fl_t  ifr_fl;
uint64_tifr_rx_irq;
+   struct pfil_head*pfil;
uint16_tifr_id;
uint8_t ifr_lro_enabled;
uint8_t ifr_nfl;
@@ -451,7 +453,6 @@ struct iflib_rxq {
 
 typedef struct if_rxsd {
caddr_t *ifsd_cl;
-   struct mbuf **ifsd_m;
iflib_fl_t ifsd_fl;
qidx_t ifsd_cidx;
 } *if_rxsd_t;
@@ -652,7 +653,6 @@ static int iflib_fast_intrs;
 static int iflib_rx_unavail;
 static int iflib_rx_ctx_inactive;
 static int iflib_rx_if_input;
-static int iflib_rx_mbuf_null;
 static int iflib_rxd_flush;
 
 static int iflib_verbose_debug;
@@ -669,8 +669,6 @@ SYSCTL_INT(_net_iflib, OID_AUTO, rx_ctx_inactive, CTLF
   &iflib_rx_ctx_inactive, 0, "# times rxeof called with 
inactive context");
 SYSCTL_INT(_net_iflib, OID_AUTO, rx_if_input, CTLFLAG_RD,
   &iflib_rx_if_input, 0, "# times rxeof called if_input");
-SYSCTL_INT(_net_iflib, OID_AUTO, rx_mbuf_null, CTLFLAG_RD,
-  &iflib_rx_mbuf_null, 0, "# times rxeof got null mbuf");
 SYSCTL_INT(_net_iflib, OID_AUTO, rxd_flush, CTLFLAG_RD,
 &iflib_rxd_flush, 0, "# times rxd_flush called");
 SYSCTL_INT(_net_iflib, OID_AUTO, verbose_debug, CTLFLAG_RW,
@@ -689,7 +687,7 @@ iflib_debug_reset(void)
iflib_task_fn_rxs = iflib_rx_intr_enables = iflib_fast_intrs =
iflib_rx_unavail =
iflib_rx_ctx_inactive = iflib_rx_if_input =
-   iflib_rx_mbuf_null = iflib_rxd_flush = 0;
+   iflib_rxd_flush = 0;
 }
 
 #else
@@ -2002,11 +2000,12 @@ _iflib_fl_refill(if_ctx_t ctx, iflib_fl_t fl, int coun
bus_dmamap_sync(fl->ifl_buf_tag, sd_map[frag_idx],
BUS_DMASYNC_PREREAD);
 
-   MPASS(sd_m[frag_idx] == NULL);
-   if ((m = m_gethdr(M_NOWAIT, MT_NOINIT)) == NULL) {
-   break;
+   if (sd_m[frag_idx] == NULL) {
+   if ((m = m_gethdr(M_NOWAIT, MT_NOINIT)) == NULL) {
+   break;
+   }
+   sd_m[frag_idx] = m;
}
-   sd_m[frag_idx] = m;
bit_set(fl->ifl_rx_bitmap, frag_idx);
 #if MEMORY_LOGGING
fl->ifl_m_enqueued++;
@@ -2483,13 +2482,15 @@ prefetch_pkts(iflib_fl_t fl, int cidx)
prefetch(fl->ifl_sds.ifsd_cl[(cidx + 4) & (nrxd-1)]);
 }
 
-static void
-rxd_frag_to_sd(iflib_rxq_t rxq, if_rxd_frag_t irf, int unload, if_rxsd_t sd)
+static struct mbuf *
+rxd_frag_to_sd(iflib_rxq_t rxq, if_rxd_frag_t irf, bool unload, if_rxsd_t sd,
+int *pf_rv, if_rxd_info_t ri)
 {
-   int flid, cidx;
bus_dmamap_t map;
iflib_fl_t fl;
-   int next;
+   caddr_t payload;
+   struct mbuf *m;
+   int flid, cidx, len, next;
 
map = NULL;
flid = irf->irf_flid;
@@ -2497,7 +2498,7 @@ rxd_frag_to_sd(iflib_rxq_t rxq, if_rxd_frag_t irf, int
fl = &rxq->ifr_fl[flid];
sd->ifsd_fl = fl;
sd->ifsd_cidx = cidx;
-   sd->ifsd_m = &fl->ifl_sds.ifsd_m[cidx];
+   m = fl->ifl_sds.ifsd_m[cidx];
sd->ifsd_cl = &fl->ifl_sds.ifsd_cl[cidx];
fl->ifl_credits--;
 #if MEMORY_LOGGING
@@ -2513,39 +2514,89 @@ rxd_frag_to_sd(iflib_rxq_t rxq, if_rxd_frag_t irf, int
/* not valid assert if bxe really does SGE from non-contiguous elements 
*/
MPASS(fl->ifl_cidx == cidx);
bus_dmamap_sync(fl->ifl_buf_tag, map, BUS_DMASYNC_PO

svn commit: r346631 - head/lib/libvgl

2019-04-24 Thread Bruce Evans
Author: bde
Date: Wed Apr 24 13:15:56 2019
New Revision: 346631
URL: https://svnweb.freebsd.org/changeset/base/346631

Log:
  Fix some races and screeen clearing in VGLEnd().
  
  The mouse signal SIGUSR2 was not turned off for normal termination and
  in some other cases.  Thus mouse signals arriving after the frame
  buffer was unmapped always caused fatal traps.  The fatal traps occurred
  about 1 time in 5 if the mouse was wiggled while vgl is ending.
  
  The screen switch signal SIGUSR1 was turned off after clearing the
  flag that it sets.  Unlike the mouse signal, this signal is handled
  synchronously, but VGLEnd() does screen clearing which does the
  synchronous handling.  This race is harder to lose.  I think it can
  get vgl into deadlocked state (waiting in the screen switch handler
  with SIGUSR1 to leave that state already turned off).
  
  Turn off the mouse cursor before clearing the screen in VGLEnd().
  Otherwise, clearing is careful to not clear the mouse cursor.  Undrawing
  an active mouse cursor uses a lot of state, so is dangerous for abnormal
  termination, but so is clearing.  Clearing is slow and is usually not
  needed, since the kernel also does it (not quite right).

Modified:
  head/lib/libvgl/main.c

Modified: head/lib/libvgl/main.c
==
--- head/lib/libvgl/main.c  Wed Apr 24 09:05:45 2019(r346630)
+++ head/lib/libvgl/main.c  Wed Apr 24 13:15:56 2019(r346631)
@@ -73,11 +73,11 @@ struct vt_mode smode;
 
   if (!VGLInitDone)
 return;
-  VGLInitDone = 0;
+  signal(SIGUSR1, SIG_IGN);
+  signal(SIGUSR2, SIG_IGN);
   VGLSwitchPending = 0;
   VGLAbortPending = 0;
-
-  signal(SIGUSR1, SIG_IGN);
+  VGLMousePointerHide();
 
   if (VGLMem != MAP_FAILED) {
 VGLClear(VGLDisplay, 0);
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r346630 - in head: sbin/ifconfig share/man/man4 sys/modules/if_gre sys/net sys/netinet sys/netinet6

2019-04-24 Thread Andrey V. Elsukov
Author: ae
Date: Wed Apr 24 09:05:45 2019
New Revision: 346630
URL: https://svnweb.freebsd.org/changeset/base/346630

Log:
  Add GRE-in-UDP encapsulation support as defined in RFC8086.
  
  This GRE-in-UDP encapsulation allows the UDP source port field to be
  used as an entropy field for load-balancing of GRE traffic in transit
  networks. Also most of multiqueue network cards are able distribute
  incoming UDP datagrams to different NIC queues, while very little are
  able do this for GRE packets.
  
  When an administrator enables UDP encapsulation with command
  `ifconfig gre0 udpencap`, the driver creates kernel socket, that binds
  to tunnel source address and after udp_set_kernel_tunneling() starts
  receiving of all UDP packets destined to 4754 port. Each kernel socket
  maintains list of tunnels with different destination addresses. Thus
  when several tunnels use the same source address, they all handled by
  single socket.  The IP[V6]_BINDANY socket option is used to be able bind
  socket to source address even if it is not yet available in the system.
  This may happen on system boot, when gre(4) interface is created before
  source address become available. The encapsulation and sending of packets
  is done directly from gre(4) into ip[6]_output() without using sockets.
  
  Reviewed by:  eugen
  MFC after:1 month
  Relnotes: yes
  Differential Revision:https://reviews.freebsd.org/D19921

Modified:
  head/sbin/ifconfig/ifgre.c
  head/share/man/man4/gre.4
  head/sys/modules/if_gre/Makefile
  head/sys/net/if_gre.c
  head/sys/net/if_gre.h
  head/sys/netinet/ip_gre.c
  head/sys/netinet6/ip6_gre.c

Modified: head/sbin/ifconfig/ifgre.c
==
--- head/sbin/ifconfig/ifgre.c  Wed Apr 24 06:41:52 2019(r346629)
+++ head/sbin/ifconfig/ifgre.c  Wed Apr 24 09:05:45 2019(r346630)
@@ -44,15 +44,16 @@ __FBSDID("$FreeBSD$");
 
 #include "ifconfig.h"
 
-#defineGREBITS "\020\01ENABLE_CSUM\02ENABLE_SEQ"
+#defineGREBITS "\020\01ENABLE_CSUM\02ENABLE_SEQ\03UDPENCAP"
 
 static void gre_status(int s);
 
 static void
 gre_status(int s)
 {
-   uint32_t opts = 0;
+   uint32_t opts, port;
 
+   opts = 0;
ifr.ifr_data = (caddr_t)&opts;
if (ioctl(s, GREGKEY, &ifr) == 0)
if (opts != 0)
@@ -60,6 +61,11 @@ gre_status(int s)
opts = 0;
if (ioctl(s, GREGOPTS, &ifr) != 0 || opts == 0)
return;
+
+   port = 0;
+   ifr.ifr_data = (caddr_t)&port;
+   if (ioctl(s, GREGPORT, &ifr) == 0 && port != 0)
+   printf("\tudpport: %u\n", port);
printb("\toptions", opts, GREBITS);
putchar('\n');
 }
@@ -77,6 +83,18 @@ setifgrekey(const char *val, int dummy __unused, int s
 }
 
 static void
+setifgreport(const char *val, int dummy __unused, int s,
+const struct afswtch *afp)
+{
+   uint32_t udpport = strtol(val, NULL, 0);
+
+   strlcpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
+   ifr.ifr_data = (caddr_t)&udpport;
+   if (ioctl(s, GRESPORT, (caddr_t)&ifr) < 0)
+   warn("ioctl (set udpport)");
+}
+
+static void
 setifgreopts(const char *val, int d, int s, const struct afswtch *afp)
 {
uint32_t opts;
@@ -101,10 +119,13 @@ setifgreopts(const char *val, int d, int s, const stru
 
 static struct cmd gre_cmds[] = {
DEF_CMD_ARG("grekey",   setifgrekey),
+   DEF_CMD_ARG("udpport",  setifgreport),
DEF_CMD("enable_csum", GRE_ENABLE_CSUM, setifgreopts),
DEF_CMD("-enable_csum",-GRE_ENABLE_CSUM,setifgreopts),
DEF_CMD("enable_seq", GRE_ENABLE_SEQ,   setifgreopts),
DEF_CMD("-enable_seq",-GRE_ENABLE_SEQ,  setifgreopts),
+   DEF_CMD("udpencap", GRE_UDPENCAP,   setifgreopts),
+   DEF_CMD("-udpencap",-GRE_UDPENCAP,  setifgreopts),
 };
 static struct afswtch af_gre = {
.af_name= "af_gre",

Modified: head/share/man/man4/gre.4
==
--- head/share/man/man4/gre.4   Wed Apr 24 06:41:52 2019(r346629)
+++ head/share/man/man4/gre.4   Wed Apr 24 09:05:45 2019(r346630)
@@ -29,7 +29,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd June 2, 2015
+.Dd April 24, 2019
 .Dt GRE 4
 .Os
 .Sh NAME
@@ -89,7 +89,45 @@ A value of 0 disables the key option.
 Enables checksum calculation for outgoing packets.
 .It Ar enable_seq
 Enables use of sequence number field in the GRE header for outgoing packets.
+.It Ar udpencap
+Enables UDP-in-GRE encapsulation (see the
+.Sx GRE-IN-UDP ENCAPSULATION
+Section below for details).
+.It Ar udpport
+Set the source UDP port for outgoing packets.
+A value of 0 disables the persistence of source UDP port for outgoing packets.
+See the
+.Sx GRE-IN-UDP ENCAPSULATION
+Section below for details.
 .El
+.Sh GRE-IN-UDP ENCAPSULATION
+The
+.Nm
+supports GRE in UDP encapsulation as defined in RFC 8086.
+A GRE in