vmd: sync DPADD with LDADD

2018-06-23 Thread Gleydson Soares
sync DPADD with LDADD adding missing ${LIBPTHREAD} to ensure
that binary is rebuilt in case of pthread library changes.
Index: Makefile
===
RCS file: /cvs/src/usr.sbin/vmd/Makefile,v
retrieving revision 1.17
diff -u -p -r1.17 Makefile
--- Makefile3 Jan 2018 05:39:56 -   1.17
+++ Makefile24 Jun 2018 05:31:47 -
@@ -15,7 +15,7 @@ CFLAGS+=  -Wshadow -Wpointer-arith -Wcast
 CFLAGS+=   -Wsign-compare
 
 LDADD+=-lutil -lpthread -levent
-DPADD+=${LIBUTIL} ${LIBEVENT}
+DPADD+=${LIBUTIL} ${LIBPTHREAD} ${LIBEVENT}
 
 YFLAGS=
 


spamlogd: add missing ${LIBCRYPTO} to DPADD

2018-06-23 Thread Gleydson Soares
add missing ${LIBCRYPTO}

Index: Makefile
===
RCS file: /cvs/src/libexec/spamlogd/Makefile,v
retrieving revision 1.7
diff -u -p -r1.7 Makefile
--- Makefile21 Aug 2013 16:13:30 -  1.7
+++ Makefile24 Jun 2018 04:04:42 -
@@ -6,7 +6,7 @@ MAN=spamlogd.8
 
 CFLAGS+= -Wall -Wstrict-prototypes -I${.CURDIR}/../spamd
 LDADD+= -lpcap -lcrypto
-DPADD+=${LIBPCAP}
+DPADD+=${LIBPCAP} ${LIBCRYPTO}
 .PATH:  ${.CURDIR}/../spamd
 
 .include 



sasyncd: remove redundant memset() call

2018-06-23 Thread Gleydson Soares
calloc() already filled all the memory block to 0, zap memset().
Index: pfkey.c
===
RCS file: /cvs/src/usr.sbin/sasyncd/pfkey.c,v
retrieving revision 1.28
diff -u -p -r1.28 pfkey.c
--- pfkey.c 18 Apr 2017 02:29:56 -  1.28
+++ pfkey.c 24 Jun 2018 04:36:51 -
@@ -115,7 +115,6 @@ pfkey_send_flush(struct syncpeer *p)
static u_int32_t seq = 1;
 
if (m) {
-   memset(m, 0, sizeof *m);
m->sadb_msg_version = PF_KEY_V2;
m->sadb_msg_seq = seq++;
m->sadb_msg_type = SADB_FLUSH;


[diff] deleting lo(4) with rdomain

2018-06-23 Thread Denis Fondras
Here is a diff to allow deletion of lo(4) created by rdomain.

Of course, lo(4) cannot be deleted while the rdomain is used on another
interface. rtable is still available after all the interfaces are out of the
rdomain though.

[denis@visigoth:~] doas ifconfig em0 rdomain 3
[denis@visigoth:~] ifconfig 
lo0: flags=8049 mtu 32768
index 4 priority 0 llprio 3
groups: lo
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x4
inet 127.0.0.1 netmask 0xff00
em0: flags=8843 rdomain 3 mtu 1500
lladdr 8c:16:45:57:e4:91
index 2 priority 0 llprio 3
media: Ethernet autoselect (none)
status: no carrier
lo3: flags=8008 rdomain 3 mtu 32768
index 7 priority 0 llprio 3
groups: lo
[denis@visigoth:~] doas ifconfig lo3 -rdomain
ifconfig: SIOCSIFRDOMAIN: Operation not permitted
[denis@visigoth:~] doas ifconfig em0 -rdomain
[denis@visigoth:~] doas ifconfig lo3 -rdomain
[denis@visigoth:~] ifconfig 
lo0: flags=8049 mtu 32768
index 4 priority 0 llprio 3
groups: lo
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x4
inet 127.0.0.1 netmask 0xff00
em0: flags=8843 mtu 1500
lladdr 8c:16:45:57:e4:91
index 2 priority 0 llprio 3
media: Ethernet autoselect (none)
status: no carrier
lo3: flags=8008 mtu 32768
index 7 priority 0 llprio 3
groups: lo
[denis@visigoth:~] doas ifconfig lo3 destroy
[denis@visigoth:~] ifconfig
lo0: flags=8049 mtu 32768
index 4 priority 0 llprio 3
groups: lo
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x4
inet 127.0.0.1 netmask 0xff00
em0: flags=8843 mtu 1500
lladdr 8c:16:45:57:e4:91
index 2 priority 0 llprio 3
media: Ethernet autoselect (none)
status: no carrier

Because the kernel panics when manipulating rdomain on enc(4), I added a check
to disallow that (the kernel panic is not linked to this change, it
preexisted).


Index: if.c
===
RCS file: /cvs/src/sys/net/if.c,v
retrieving revision 1.556
diff -u -p -r1.556 if.c
--- if.c21 Jun 2018 07:40:43 -  1.556
+++ if.c23 Jun 2018 19:41:05 -
@@ -1729,43 +1729,53 @@ if_setlladdr(struct ifnet *ifp, const ui
return (0);
 }
 
+struct ifnet *
+rdomain_isused(struct ifnet *ifp, int rdomain)
+{
+   struct ifnet *ifp_;
+
+   TAILQ_FOREACH(ifp_, , if_list) {
+   if (ifp_ == ifp)
+   continue;
+   if (ifp_->if_rdomain == rdomain)
+   return (ifp_);
+   }
+   return (NULL);
+}
+
 int
 if_setrdomain(struct ifnet *ifp, int rdomain)
 {
struct ifreq ifr;
int error, up = 0, s;
+   struct ifnet *loifp;
+   char loifname[IFNAMSIZ];
+   unsigned int unit = rdomain;
 
if (rdomain < 0 || rdomain > RT_TABLEID_MAX)
return (EINVAL);
 
+   if (strncmp(ifp->if_xname, "enc", 3) == 0)
+   return (EPERM);
+
/*
 * Create the routing table if it does not exist, including its
 * loopback interface with unit == rdomain.
 */
-   if (!rtable_exists(rdomain)) {
-   struct ifnet *loifp;
-   char loifname[IFNAMSIZ];
-   unsigned int unit = rdomain;
-
-   snprintf(loifname, sizeof(loifname), "lo%u", unit);
-   error = if_clone_create(loifname, 0);
-
-   if ((loifp = ifunit(loifname)) == NULL)
-   return (ENXIO);
-
-   /* Do not error out if creating the default lo(4) interface */
-   if (error && (ifp != loifp || error != EEXIST))
+   if (!rtable_exists(rdomain))
+   if ((error = rtable_add(rdomain)))
return (error);
 
-   if ((error = rtable_add(rdomain)) == 0)
-   rtable_l2set(rdomain, rdomain, loifp->if_index);
-   if (error) {
-   if_clone_destroy(loifname);
-   return (error);
-   }
+   snprintf(loifname, sizeof(loifname), "lo%u", unit);
+   error = if_clone_create(loifname, 0);
+   if (error && error != EEXIST)
+   return (error);
 
-   loifp->if_rdomain = rdomain;
-   }
+   if ((loifp = ifunit(loifname)) == NULL)
+   return (ENXIO);
+
+   rtable_l2set(rdomain, rdomain, loifp->if_index);
+   loifp->if_rdomain = rdomain;
 
/* make sure that the routing table is a real rdomain */
if (rdomain != rtable_l2(rdomain))
@@ -1773,7 +1783,8 @@ if_setrdomain(struct ifnet *ifp, int rdo
 
if (rdomain != ifp->if_rdomain) {
if ((ifp->if_flags & IFF_LOOPBACK) &&
-   (ifp->if_index == rtable_loindex(ifp->if_rdomain)))
+   (ifp->if_index == 

Add XSDT and arm64 support to acpidump(8)

2018-06-23 Thread Mark Kettenis
The diff below adds arm64 support to acpidump(8).  It renames
bios_acpi_addr() into efi_acpi_addr() and duplicates the function
because on arm64 I just need to read a 64-bit integer I'm considering
changing amd64 to use a variable with the same name to get rid of the
#ifdef.  The code that grovels through low memory to discover the ACPI
tables is only enabled for amd64 and i386 now.

Since on my arm64 system there is no RSDT, this adds support for using
the XSDT instead.  There is a fair bit of code reorg to handle the
discovery of the RSD PTR table as the pointer to the XSDT won't be
there on ACPI 1.0 systems.

ok?


Index: usr.sbin/acpidump/Makefile
===
RCS file: /cvs/src/usr.sbin/acpidump/Makefile,v
retrieving revision 1.6
diff -u -p -r1.6 Makefile
--- usr.sbin/acpidump/Makefile  24 Jan 2017 00:20:28 -  1.6
+++ usr.sbin/acpidump/Makefile  23 Jun 2018 14:37:02 -
@@ -1,6 +1,7 @@
 # $OpenBSD: Makefile,v 1.6 2017/01/24 00:20:28 deraadt Exp $
 
-.if (${MACHINE} == "i386") || (${MACHINE} == "amd64")
+.if ${MACHINE} == "amd64" || ${MACHINE} == "arm64" || \
+${MACHINE} == "i386"
 PROG= acpidump
 SRCS= acpidump.c
 LDADD= -lkvm
Index: usr.sbin/acpidump/acpidump.c
===
RCS file: /cvs/src/usr.sbin/acpidump/acpidump.c,v
retrieving revision 1.17
diff -u -p -r1.17 acpidump.c
--- usr.sbin/acpidump/acpidump.c26 Sep 2016 19:58:26 -  1.17
+++ usr.sbin/acpidump/acpidump.c23 Jun 2018 14:37:02 -
@@ -30,7 +30,6 @@
 #include 
 #include 
 #include 
-#include 
 
 #include 
 #include 
@@ -58,8 +57,13 @@ struct ACPIrsdp {
u_char  signature[8];
u_char  sum;
u_char  oem[6];
-   u_char  res;
+   u_char  rev;
u_int32_t   addr;
+#define SIZEOF_RSDP_REV_0  20
+   u_int32_t   len;
+   u_int64_t   xaddr;
+   u_char  xsum;
+   u_char  xres[3];
 } __packed;
 
 struct ACPIsdt {
@@ -174,6 +178,7 @@ int acpi_checksum(void *_p, size_t _leng
 struct acpi_user_mapping *acpi_user_find_mapping(vm_offset_t _pa, size_t 
_size);
 void   *acpi_map_physical(vm_offset_t _pa, size_t _size);
 void   acpi_user_init(void);
+struct ACPIrsdp *acpi_check_rsd_ptr(vm_offset_t _pa);
 struct ACPIrsdp *acpi_find_rsd_ptr(void);
 void   acpi_print_string(char *_s, size_t _length);
 void   acpi_print_rsd_ptr(struct ACPIrsdp *_rp);
@@ -181,14 +186,16 @@ struct ACPIsdt *acpi_map_sdt(vm_offset_t
 void   aml_dump(struct ACPIsdt *_hdr);
 void   acpi_print_sdt(struct ACPIsdt *_sdp);
 void   acpi_print_rsdt(struct ACPIsdt *_rsdp);
+void   acpi_print_xsdt(struct ACPIsdt *_rsdp);
 void   acpi_print_facp(struct FACPbody *_facp);
 void   acpi_print_dsdt(struct ACPIsdt *_dsdp);
 void   acpi_handle_dsdt(struct ACPIsdt *_dsdp);
 void   acpi_handle_facp(struct FACPbody *_facp);
 void   acpi_handle_rsdt(struct ACPIsdt *_rsdp);
+void   acpi_handle_xsdt(struct ACPIsdt *_rsdp);
 void   asl_dump_from_devmem(void);
 void   usage(void);
-u_long bios_acpi_addr(void);
+u_long efi_acpi_addr(void);
 
 
 struct ACPIsdt dsdt_header = {
@@ -264,41 +271,47 @@ acpi_user_init(void)
 }
 
 struct ACPIrsdp *
+acpi_check_rsd_ptr(vm_offset_t pa)
+{
+   struct ACPIrsdp rp;
+   
+   lseek(acpi_mem_fd, pa, SEEK_SET);
+   read(acpi_mem_fd, , SIZEOF_RSDP_REV_0);
+   if (memcmp(rp.signature, "RSD PTR ", 8) != 0)
+   return NULL;
+
+   if (rp.rev >= 2) {
+   read(acpi_mem_fd, &(rp.len),
+   sizeof(struct ACPIrsdp) - SIZEOF_RSDP_REV_0);
+   if (acpi_checksum(, sizeof(struct ACPIrsdp)) == 0)
+   return acpi_map_physical(pa, sizeof(struct ACPIrsdp));
+   }
+
+   if (acpi_checksum(, SIZEOF_RSDP_REV_0) == 0)
+   return (acpi_map_physical(pa, SIZEOF_RSDP_REV_0));
+
+   return NULL;
+}
+
+struct ACPIrsdp *
 acpi_find_rsd_ptr(void)
 {
-   int i;
-   u_int8_tbuf[sizeof(struct ACPIrsdp)];
+   struct ACPIrsdp *rp;
u_long  addr;
 
-   if ((addr = bios_acpi_addr()) != 0) {
-   lseek(acpi_mem_fd, addr, SEEK_SET);
-   read(acpi_mem_fd, buf, 16);
-   if (!memcmp(buf, "RSD PTR ", 8)) {
-   read(acpi_mem_fd, buf + 16,
-   sizeof(struct ACPIrsdp) - 16);
-   if (!acpi_checksum(buf, sizeof(struct ACPIrsdp)))
-   return (acpi_map_physical(addr,
-   sizeof(struct ACPIrsdp)));
-   }
-   lseek(acpi_mem_fd, 0, SEEK_SET);
+   if ((addr = efi_acpi_addr()) != 0) {
+   if ((rp = acpi_check_rsd_ptr(addr)))
+   return rp;
}
-   for (i = 0; i < 1024 * 1024; i += 16) {
-   lseek(acpi_mem_fd, i, SEEK_SET);
-   

ACPI on OpenBSD/arm64

2018-06-23 Thread Mark Kettenis
The lates generation of 64-bit ARM server hardware seems to be
ACPI-only.  This obviously fills me with a tremendous amount of joy.
ACPi is clearly superior to device trees.  So much more superior that
they you have to embed snippets of device tree properties into your
AML to make it do anything useful on stuff that isn't 100%
bog-standard hardware [1].

Well, enough sarcasm.  Maybe this is even a good thing since it
encourages ARM server vendors from being too creative and simply stick
everything of interest behind a PCIe host bridge.

I have some ideas on how to support ACPI on OpenBSD/arm64.  As a first
stap, I'd like to make acpidump(4) work.  The diff below adds a little
bit of kernel code to stick the address where the ACPI tables can be
found into a global variable.

ok?


[1] https://lwn.net/Articles/612062/

Index: dev/acpi/efi.h
===
RCS file: /cvs/src/sys/dev/acpi/efi.h,v
retrieving revision 1.2
diff -u -p -r1.2 efi.h
--- dev/acpi/efi.h  4 Jan 2018 14:30:08 -   1.2
+++ dev/acpi/efi.h  23 Jun 2018 14:13:57 -
@@ -13,7 +13,6 @@ typedef uint64_t  UINT64;
 typedef u_long UINTN;
 typedef uint16_t   CHAR16;
 typedef void   VOID;
-typedef uint32_t   EFI_GUID[4];
 typedef uint64_t   EFI_PHYSICAL_ADDRESS;
 typedef uint64_t   EFI_VIRTUAL_ADDRESS;
 typedef UINTN  EFI_STATUS;
@@ -23,6 +22,17 @@ typedef VOID *EFI_SIMPLE_TEXT_INPUT_PRO
 typedef VOID   *EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL;
 typedef VOID   *EFI_BOOT_SERVICES;
 
+typedef struct {
+   UINT32  Data1;
+   UINT16  Data2;
+   UINT16  Data3;
+   UINT8   Data4[8];
+} EFI_GUID;
+
+#define EFI_ACPI_20_TABLE_GUID \
+  { 0x8868e871, 0xe4f1, 0x11d3, \
+{ 0xbc, 0x22, 0x00, 0x80, 0xc7, 0x3c, 0x88, 0x81} }
+
 typedef enum {
EfiReservedMemoryType,
EfiLoaderCode,
@@ -130,4 +140,6 @@ typedef struct {
 
 #define EFI_SUCCESS0
 
-#endif /* _MACHINE_EFI_H_ */
+#defineefi_guidcmp(_a, _b) memcmp((_a), (_b), sizeof(EFI_GUID))
+
+#endif /* _DEV_ACPI_EFI_H_ */
Index: arch/arm64/dev/efi.c
===
RCS file: /cvs/src/sys/arch/arm64/dev/efi.c,v
retrieving revision 1.4
diff -u -p -r1.4 efi.c
--- arch/arm64/dev/efi.c6 Apr 2018 19:09:05 -   1.4
+++ arch/arm64/dev/efi.c23 Jun 2018 14:13:57 -
@@ -41,6 +41,8 @@ extern uint32_t mmap_desc_ver;
 
 extern EFI_MEMORY_DESCRIPTOR *mmap;
 
+uint64_t efi_acpi_table;
+
 struct efi_softc {
struct device   sc_dev;
struct pmap *sc_pm;
@@ -168,18 +170,25 @@ efi_attach(struct device *parent, struct
}
 
/*
-* The FirmwareVendor field has been converted from a physical
-* pointer to a virtual pointer, so we have to activate our
-* pmap to access it.
+* The FirmwareVendor and ConfigurationTable fields have been
+* converted from a physical pointer to a virtual pointer, so
+* we have to activate our pmap to access them.
 */
+   efi_enter(sc);
if (st->FirmwareVendor) {
printf("%s: ", sc->sc_dev.dv_xname);
-   efi_enter(sc);
for (i = 0; st->FirmwareVendor[i]; i++)
printf("%c", st->FirmwareVendor[i]);
-   efi_leave(sc);
printf(" rev 0x%x\n", st->FirmwareRevision);
}
+   for (i = 0; i < st->NumberOfTableEntries; i++) {
+   EFI_CONFIGURATION_TABLE *ct = >ConfigurationTable[i];
+   static EFI_GUID acpi_guid = EFI_ACPI_20_TABLE_GUID;
+
+   if (efi_guidcmp(_guid, >VendorGuid) == 0)
+   efi_acpi_table = (uint64_t)ct->VendorTable;
+   }
+   efi_leave(sc);
 
if (rs == NULL)
return;
@@ -278,4 +287,3 @@ efi_settime(struct todr_chip_handle *han
return EIO;
return 0;
 }
-



Re: uipc_domain.c : use constant instead of value

2018-06-23 Thread Alexander Bluhm
On Sat, Jun 23, 2018 at 03:57:06PM +0200, Denis Fondras wrote:
> Cosmetic change.

OK bluhm@

> Index: uipc_domain.c
> ===
> RCS file: /cvs/src/sys/kern/uipc_domain.c,v
> retrieving revision 1.55
> diff -u -p -r1.55 uipc_domain.c
> --- uipc_domain.c 23 Nov 2017 13:45:46 -  1.55
> +++ uipc_domain.c 23 Jun 2018 13:48:51 -
> @@ -141,7 +141,7 @@ pffindproto(int family, int protocol, in
>   const struct protosw *pr;
>   const struct protosw *maybe = NULL;
>  
> - if (family == 0)
> + if (family == PF_UNSPEC)
>   return (NULL);
>  
>   dp = pffinddomain(family);
> @@ -176,7 +176,7 @@ net_sysctl(int *name, u_int namelen, voi
>   return (EISDIR);/* overloaded */
>   family = name[0];
>  
> - if (family == 0)
> + if (family == PF_UNSPEC)
>   return (0);
>  #if NBPFILTER > 0
>   if (family == PF_BPF)



uipc_domain.c : use constant instead of value

2018-06-23 Thread Denis Fondras
Cosmetic change.

Index: uipc_domain.c
===
RCS file: /cvs/src/sys/kern/uipc_domain.c,v
retrieving revision 1.55
diff -u -p -r1.55 uipc_domain.c
--- uipc_domain.c   23 Nov 2017 13:45:46 -  1.55
+++ uipc_domain.c   23 Jun 2018 13:48:51 -
@@ -141,7 +141,7 @@ pffindproto(int family, int protocol, in
const struct protosw *pr;
const struct protosw *maybe = NULL;
 
-   if (family == 0)
+   if (family == PF_UNSPEC)
return (NULL);
 
dp = pffinddomain(family);
@@ -176,7 +176,7 @@ net_sysctl(int *name, u_int namelen, voi
return (EISDIR);/* overloaded */
family = name[0];
 
-   if (family == 0)
+   if (family == PF_UNSPEC)
return (0);
 #if NBPFILTER > 0
if (family == PF_BPF)



Re: Save and restore FPU state around signal handlers on armv7

2018-06-23 Thread Markus Hennecke
On Sat, 23 Jun 2018, Mark Kettenis wrote:

> > Date: Fri, 22 Jun 2018 17:16:14 +0200 (CEST)
> > From: Mark Kettenis 
> > 
> > It takes the alpha/hppa/mips64 approach of storing the state in struct
> > sigcontext instead of using a pointer.  Using unsigned int and
> > unsigned long long instead of uint32_t and uint64_t here to avoid
> > having to include other headers.  But I suppose I could include
> > include  and use __uint32_t and __uint64_t if people
> > prefer that.
> > 
> > This is an ABI break.  Code that plays tricks with sigcontext, like
> > copying structs around or looks at the internals will have to be
> > recompiled.  But we don't really support that, so I'm inclined to just
> > go aead.
> > 
> > This fixes the corruption in ksh/sh that is currently preventing snaps
> > from being built.  At least in combination with the setjmp fix I
> > mailed out wednesday and Dale's ast fix.
> > 
> > ok?
> 
> Better diff that gives the signal handler a clean FPU state and make
> sure we reset the FPU state if the signal handler was the first to use
> the FPU.  This no longer calls vfp_discard().  Instead it just sets
> pcb_fpcpu to NULL.  That is enough to force reloading of the FPU
> state.
> 
> ok?

I just finished a system build for armv7 using your setjmp patch. After 
that I built a kernel with this patch and started and finished a xenocara 
build running with that kernel successfully. Source was from 21st. This 
was the first successful xenocara build on my cubieboard2 in weeks.

> 
> 
> Index: arch/arm/arm/sig_machdep.c
> ===
> RCS file: /cvs/src/sys/arch/arm/arm/sig_machdep.c,v
> retrieving revision 1.16
> diff -u -p -r1.16 sig_machdep.c
> --- arch/arm/arm/sig_machdep.c12 Apr 2018 17:13:43 -  1.16
> +++ arch/arm/arm/sig_machdep.c22 Jun 2018 22:10:19 -
> @@ -51,11 +51,11 @@
>  #include 
>  #include 
>  
> -#include 
> -
>  #include 
>  #include 
>  #include 
> +
> +#include 
>  #include 
>  
>  #include 
> @@ -80,6 +80,7 @@ sendsig(sig_t catcher, int sig, int retu
> union sigval val)
>  {
>   struct proc *p = curproc;
> + struct pcb *pcb = >p_addr->u_pcb;
>   struct trapframe *tf;
>   struct sigframe *fp, frame;
>   struct sigacts *psp = p->p_p->ps_sigacts;
> @@ -130,6 +131,16 @@ sendsig(sig_t catcher, int sig, int retu
>   /* Save signal mask. */
>   frame.sf_sc.sc_mask = returnmask;
>  
> + /* Save FPU registers. */
> + frame.sf_sc.sc_fpused = pcb->pcb_flags & PCB_FPU;
> + if (frame.sf_sc.sc_fpused) {
> + frame.sf_sc.sc_fpscr = pcb->pcb_fpstate.fp_scr;
> + memcpy(_sc.sc_fpreg, >pcb_fpstate.fp_reg,
> +sizeof(pcb->pcb_fpstate.fp_reg));
> + pcb->pcb_flags &= ~PCB_FPU;
> + pcb->pcb_fpcpu = NULL;
> + }
> +
>   if (psp->ps_siginfo & sigmask(sig)) {
>   frame.sf_sip = >sf_si;
>   initsiginfo(_si, sig, code, type, val);
> @@ -176,6 +187,7 @@ sys_sigreturn(struct proc *p, void *v, r
>   syscallarg(struct sigcontext *) sigcntxp;
>   } */ *uap = v;
>   struct sigcontext ksc, *scp = SCARG(uap, sigcntxp);
> + struct pcb *pcb = >p_addr->u_pcb;
>   struct trapframe *tf;
>  
>   if (PROC_PC(p) != p->p_p->ps_sigcoderet) {
> @@ -227,6 +239,18 @@ sys_sigreturn(struct proc *p, void *v, r
>  
>   /* Restore signal mask. */
>   p->p_sigmask = ksc.sc_mask & ~sigcantmask;
> +
> + /* Restore FPU registers. */
> + if (ksc.sc_fpused) {
> + pcb->pcb_fpstate.fp_scr = ksc.sc_fpscr;
> + memcpy(>pcb_fpstate.fp_reg, _fpreg,
> + sizeof(pcb->pcb_fpstate.fp_reg));
> + pcb->pcb_flags |= PCB_FPU;
> + pcb->pcb_fpcpu = NULL;
> + } else {
> + pcb->pcb_flags &= ~PCB_FPU;
> + pcb->pcb_fpcpu = NULL;
> + }
>  
>   return (EJUSTRETURN);
>  }
> Index: arch/arm/include/signal.h
> ===
> RCS file: /cvs/src/sys/arch/arm/include/signal.h,v
> retrieving revision 1.9
> diff -u -p -r1.9 signal.h
> --- arch/arm/include/signal.h 10 May 2016 18:39:43 -  1.9
> +++ arch/arm/include/signal.h 22 Jun 2018 22:10:19 -
> @@ -82,6 +82,10 @@ struct sigcontext {
>   unsigned int sc_usr_lr;
>   unsigned int sc_svc_lr;
>   unsigned int sc_pc;
> +
> + unsigned int sc_fpused;
> + unsigned int sc_fpscr;
> + unsigned long long sc_fpreg[32];
>  };
>  #endif /* __BSD_VISIBLE || __XPG_VISIBLE >= 420 */
>  #endif /* !_LOCORE */
> 
> 



Re: SA_RESETHAND race (or the mpv(1) hanging story)

2018-06-23 Thread Hiltjo Posthuma
On Fri, Mar 16, 2018 at 02:40:00PM +0100, Hiltjo Posthuma wrote:
> On Fri, Mar 16, 2018 at 02:29:24PM +0100, Hiltjo Posthuma wrote:
> > On Thu, Mar 15, 2018 at 03:27:47PM +0100, Martin Pieuchot wrote:
> > > On 05/03/18(Mon) 21:26, Hiltjo Posthuma wrote:
> > > > >  [...]
> > > > > I tried your patch on a source build of about 25 februari on amd64. I 
> > > > > still
> > > > > notice mpv hanging when I try to close it or when the video ends.
> > > 
> > > Thanks for reporting.  This is a different issue.
> > > 
> > > > > Let me know how/if I can help you further with testing.
> > > 
> > > Could you tell me how to reproduce the problem?
> > > 
> > > > Updated to source of ~4 March:
> > > > 
> > > > OpenBSD ren.laptop 6.3 GENERIC.MP#0 amd64
> > > > 
> > > > When I do a backtrace on the hanged mpv I get:
> > > > 
> > > > 
> > > > $ gdb mpv pid
> > > > $ bt
> > > 
> > > Could you get the backtrace of all the threads?
> > > 
> > > Something like: 'thr apply all bt'
> > > 
> > > > #0  _thread_sys___thrsleep () at -:3
> > > > #1  0x117420965ea4 in _sem_wait (sem=0x1174219ffc40, 
> > > > tryonly=564132932, abstime=0x0,
> > > > delayed_cancel=0x11738fa402f0) at 
> > > > /usr/src/lib/librthread/rthread_sem.c:74
> > > > #2  0x1174209650bf in pthread_join (thread=0x1174219ffc40, 
> > > > retval=0x0)
> > > > at /usr/src/lib/librthread/rthread.c:304
> > > > #3  0x1173ec0a9d5b in SDL_WaitThread_REAL () from 
> > > > /usr/local/lib/libSDL2.so.0.4
> > > > #4  0x1173ec05b64a in close_audio_device () from 
> > > > /usr/local/lib/libSDL2.so.0.4
> > > > #5  0x1173ec05a1e2 in SDL_AudioQuit_REAL () from 
> > > > /usr/local/lib/libSDL2.so.0.4
> > > > #6  0x1173ec05703b in SDL_QuitSubSystem_REAL () from 
> > > > /usr/local/lib/libSDL2.so.0.4
> > > > #7  0x11713bf135e9 in ao_uninit (ao=0x11740b004740) at 
> > > > ../audio/out/ao.c:336
> > > > #8  0x11713bf561fe in uninit_audio_out (mpctx=0x1173a2d8b840) at 
> > > > ../player/audio.c:280
> > > > #9  0x11713bf6efd2 in mp_destroy (mpctx=0x1173a2d8b840) at 
> > > > ../player/main.c:166
> > > > #10 0x11713bf6fbe1 in mpv_main (argc=Variable "argc" is not 
> > > > available.
> > > > ) at ../player/main.c:243
> > > > #11 0x11713bf03156 in _start () from /usr/local/bin/mpv
> > > > #12 0x in ?? ()
> > > > (gdb)
> > > 
> > 
> > Hi,
> > 
> > I rebuild base and xenocara from source yesterday and rebuild and 
> > reinstalled
> > mpv.
> > 
> > The hang always happens after a video ends. I've not had any issues with 
> > other
> > programs I think. When the hang happens mpv doesn't response to SIGTERM,
> > so SIGKILL is needed.
> > 
> 
> To clarify a bit more:
> 
> The hang (the mpv window doesn't respond anymore) >>when it happens<< always
> happens after a video ends so far.
> 
> I'm not able to provide a test-case that reproduces it consistently yet.
> 

Hi,

Is anyone using mpv also able to reproduce the hang issue?

I have tried to study the libpthread and rthread code on -current, but it is
not my area of expertise. I think the issue happened before the recent futex
code changes also.

Another issue (that might be related):

The CPU usage is extremely high on mpv compared to ffplay or mplayer.  With a
ktrace on a 10 second video it has 1.3million gettimeofday() calls.  The mpv
port could be updated to detect it can use the clock_gettime(CLOCK_MONOTONIC,
...).  mplayer and ffplay don't use threads for waiting, so my guess it is also
a threading issue.

The version is ports is also about 2 years old and could use some love by the
maintainer.

-- 
Kind regards,
Hiltjo



Re: ksh "clear-screen" editing command

2018-06-23 Thread Nicholas Marriott
Never mind, should have finished reading the later emails ;-).



On Sat, Jun 23, 2018 at 09:02:24AM +0100, Nicholas Marriott wrote:
> Hi
> 
> I think you should not pass NULL to the last argument of setupterm(),
> from terminfo(3):
> 
>   If errret is null, setupterm prints an error message upon finding an
>   error and exits.
> 
> 
> 
> On Sat, Jun 16, 2018 at 04:16:57PM -0600, Todd C. Miller wrote:
> > On Sat, 16 Jun 2018 14:50:40 +0200, Mark Kettenis wrote:
> > 
> > > To be honest, I find the whole idea of invoking an external program to
> > > clear the screen insane.
> > 
> > Linking with curses doesn't increase the size a huge amount since
> > we just need to query terminfo.
> > 
> > textdatabss dec hex
> > 529120  12584   57024   598728  922c8   /bin/ksh
> > 595671  21904   57024   674599  a4b27   ./obj/ksh
> > 
> >  - todd
> > 
> > Index: bin/ksh/Makefile
> > ===
> > RCS file: /cvs/src/bin/ksh/Makefile,v
> > retrieving revision 1.38
> > diff -u -p -u -r1.38 Makefile
> > --- bin/ksh/Makefile6 Jan 2018 16:28:58 -   1.38
> > +++ bin/ksh/Makefile16 Jun 2018 22:00:32 -
> > @@ -1,6 +1,9 @@
> >  #  $OpenBSD: Makefile,v 1.38 2018/01/06 16:28:58 millert Exp $
> >  
> >  PROG=  ksh
> > +DPADD+=${LIBCURSES}
> > +LDADD+=-lcurses
> > +
> >  SRCS=  alloc.c c_ksh.c c_sh.c c_test.c c_ulimit.c edit.c emacs.c 
> > eval.c \
> > exec.c expr.c history.c io.c jobs.c lex.c mail.c main.c \
> > misc.c path.c shf.c syn.c table.c trap.c tree.c tty.c var.c \
> > Index: bin/ksh/edit.c
> > ===
> > RCS file: /cvs/src/bin/ksh/edit.c,v
> > retrieving revision 1.65
> > diff -u -p -u -r1.65 edit.c
> > --- bin/ksh/edit.c  9 Apr 2018 17:53:36 -   1.65
> > +++ bin/ksh/edit.c  16 Jun 2018 22:09:17 -
> > @@ -138,10 +138,10 @@ x_flush(void)
> > shf_flush(shl_out);
> >  }
> >  
> > -void
> > +int
> >  x_putc(int c)
> >  {
> > -   shf_putc(c, shl_out);
> > +   return shf_putc(c, shl_out);
> >  }
> >  
> >  void
> > Index: bin/ksh/edit.h
> > ===
> > RCS file: /cvs/src/bin/ksh/edit.h,v
> > retrieving revision 1.11
> > diff -u -p -u -r1.11 edit.h
> > --- bin/ksh/edit.h  26 Jan 2016 17:39:31 -  1.11
> > +++ bin/ksh/edit.h  16 Jun 2018 22:09:27 -
> > @@ -37,7 +37,7 @@ extern X_chars edchars;
> >  /* edit.c */
> >  intx_getc(void);
> >  void   x_flush(void);
> > -void   x_putc(int);
> > +intx_putc(int);
> >  void   x_puts(const char *);
> >  bool   x_mode(bool);
> >  intpromptlen(const char *, const char **);
> > Index: bin/ksh/emacs.c
> > ===
> > RCS file: /cvs/src/bin/ksh/emacs.c,v
> > retrieving revision 1.84
> > diff -u -p -u -r1.84 emacs.c
> > --- bin/ksh/emacs.c 16 Jan 2018 17:17:18 -  1.84
> > +++ bin/ksh/emacs.c 16 Jun 2018 22:12:24 -
> > @@ -21,6 +21,10 @@
> >  #include 
> >  #include 
> >  #include 
> > +#ifndef SMALL
> > +# include 
> > +# include 
> > +#endif
> >  
> >  #include "sh.h"
> >  #include "edit.h"
> > @@ -28,6 +32,7 @@
> >  static Areaaedit;
> >  #defineAEDIT /* area for kill ring and macro defns */
> >  
> > +#undef CTRL
> >  #defineCTRL(x) ((x) == '?' ? 0x7F : (x) & 0x1F)/* 
> > ASCII */
> >  #defineUNCTRL(x)   ((x) == 0x7F ? '?' : (x) | 0x40)/* 
> > ASCII */
> >  
> > @@ -146,6 +151,7 @@ static int  isu8cont(unsigned char);
> >  /* proto's for keybindings */
> >  static int x_abort(int);
> >  static int x_beg_hist(int);
> > +static int x_clear_screen(int);
> >  static int x_comp_comm(int);
> >  static int x_comp_file(int);
> >  static int x_complete(int);
> > @@ -202,6 +208,7 @@ static int  x_debug_info(int);
> >  static const struct x_ftab x_ftab[] = {
> > { x_abort,  "abort",0 },
> > { x_beg_hist,   "beginning-of-history", 0 },
> > +   { x_clear_screen,   "clear-screen", 0 },
> > { x_comp_comm,  "complete-command", 0 },
> > { x_comp_file,  "complete-file",0 },
> > { x_complete,   "complete", 0 },
> > @@ -1004,12 +1011,19 @@ x_draw_line(int c)
> >  {
> > x_redraw(-1);
> > return KSTD;
> > +}
> >  
> > +static int
> > +x_clear_screen(int c)
> > +{
> > +   x_redraw(-2);
> > +   return KSTD;
> >  }
> >  
> > -/* Redraw (part of) the line.  If limit is < 0, the everything is redrawn
> > - * on a NEW line, otherwise limit is the screen column up to which needs
> > - * redrawing.
> > +/* Redraw (part of) the line.
> > + * A non-negative limit is the screen column up to which needs
> > + * redrawing. A limit of -1 redraws on a new line, while a limit
> > + * of -2 (attempts to) 

Re: ksh "clear-screen" editing command

2018-06-23 Thread Nicholas Marriott
Hi

I think you should not pass NULL to the last argument of setupterm(),
from terminfo(3):

  If errret is null, setupterm prints an error message upon finding an
  error and exits.
  


On Sat, Jun 16, 2018 at 04:16:57PM -0600, Todd C. Miller wrote:
> On Sat, 16 Jun 2018 14:50:40 +0200, Mark Kettenis wrote:
> 
> > To be honest, I find the whole idea of invoking an external program to
> > clear the screen insane.
> 
> Linking with curses doesn't increase the size a huge amount since
> we just need to query terminfo.
> 
> textdatabss dec hex
> 529120  12584   57024   598728  922c8   /bin/ksh
> 595671  21904   57024   674599  a4b27   ./obj/ksh
> 
>  - todd
> 
> Index: bin/ksh/Makefile
> ===
> RCS file: /cvs/src/bin/ksh/Makefile,v
> retrieving revision 1.38
> diff -u -p -u -r1.38 Makefile
> --- bin/ksh/Makefile  6 Jan 2018 16:28:58 -   1.38
> +++ bin/ksh/Makefile  16 Jun 2018 22:00:32 -
> @@ -1,6 +1,9 @@
>  #$OpenBSD: Makefile,v 1.38 2018/01/06 16:28:58 millert Exp $
>  
>  PROG=ksh
> +DPADD+=  ${LIBCURSES}
> +LDADD+=  -lcurses
> +
>  SRCS=alloc.c c_ksh.c c_sh.c c_test.c c_ulimit.c edit.c emacs.c 
> eval.c \
>   exec.c expr.c history.c io.c jobs.c lex.c mail.c main.c \
>   misc.c path.c shf.c syn.c table.c trap.c tree.c tty.c var.c \
> Index: bin/ksh/edit.c
> ===
> RCS file: /cvs/src/bin/ksh/edit.c,v
> retrieving revision 1.65
> diff -u -p -u -r1.65 edit.c
> --- bin/ksh/edit.c9 Apr 2018 17:53:36 -   1.65
> +++ bin/ksh/edit.c16 Jun 2018 22:09:17 -
> @@ -138,10 +138,10 @@ x_flush(void)
>   shf_flush(shl_out);
>  }
>  
> -void
> +int
>  x_putc(int c)
>  {
> - shf_putc(c, shl_out);
> + return shf_putc(c, shl_out);
>  }
>  
>  void
> Index: bin/ksh/edit.h
> ===
> RCS file: /cvs/src/bin/ksh/edit.h,v
> retrieving revision 1.11
> diff -u -p -u -r1.11 edit.h
> --- bin/ksh/edit.h26 Jan 2016 17:39:31 -  1.11
> +++ bin/ksh/edit.h16 Jun 2018 22:09:27 -
> @@ -37,7 +37,7 @@ extern X_chars edchars;
>  /* edit.c */
>  int  x_getc(void);
>  void x_flush(void);
> -void x_putc(int);
> +int  x_putc(int);
>  void x_puts(const char *);
>  bool x_mode(bool);
>  int  promptlen(const char *, const char **);
> Index: bin/ksh/emacs.c
> ===
> RCS file: /cvs/src/bin/ksh/emacs.c,v
> retrieving revision 1.84
> diff -u -p -u -r1.84 emacs.c
> --- bin/ksh/emacs.c   16 Jan 2018 17:17:18 -  1.84
> +++ bin/ksh/emacs.c   16 Jun 2018 22:12:24 -
> @@ -21,6 +21,10 @@
>  #include 
>  #include 
>  #include 
> +#ifndef SMALL
> +# include 
> +# include 
> +#endif
>  
>  #include "sh.h"
>  #include "edit.h"
> @@ -28,6 +32,7 @@
>  static   Areaaedit;
>  #define  AEDIT /* area for kill ring and macro defns */
>  
> +#undef CTRL
>  #define  CTRL(x) ((x) == '?' ? 0x7F : (x) & 0x1F)/* 
> ASCII */
>  #define  UNCTRL(x)   ((x) == 0x7F ? '?' : (x) | 0x40)/* 
> ASCII */
>  
> @@ -146,6 +151,7 @@ static intisu8cont(unsigned char);
>  /* proto's for keybindings */
>  static int   x_abort(int);
>  static int   x_beg_hist(int);
> +static int   x_clear_screen(int);
>  static int   x_comp_comm(int);
>  static int   x_comp_file(int);
>  static int   x_complete(int);
> @@ -202,6 +208,7 @@ static intx_debug_info(int);
>  static const struct x_ftab x_ftab[] = {
>   { x_abort,  "abort",0 },
>   { x_beg_hist,   "beginning-of-history", 0 },
> + { x_clear_screen,   "clear-screen", 0 },
>   { x_comp_comm,  "complete-command", 0 },
>   { x_comp_file,  "complete-file",0 },
>   { x_complete,   "complete", 0 },
> @@ -1004,12 +1011,19 @@ x_draw_line(int c)
>  {
>   x_redraw(-1);
>   return KSTD;
> +}
>  
> +static int
> +x_clear_screen(int c)
> +{
> + x_redraw(-2);
> + return KSTD;
>  }
>  
> -/* Redraw (part of) the line.  If limit is < 0, the everything is redrawn
> - * on a NEW line, otherwise limit is the screen column up to which needs
> - * redrawing.
> +/* Redraw (part of) the line.
> + * A non-negative limit is the screen column up to which needs
> + * redrawing. A limit of -1 redraws on a new line, while a limit
> + * of -2 (attempts to) clear the screen.
>   */
>  static void
>  x_redraw(int limit)
> @@ -1018,9 +1032,23 @@ x_redraw(int limit)
>   char*cp;
>  
>   x_adj_ok = 0;
> - if (limit == -1)
> + if (limit == -2) {
> + int ret = -1;
> +#ifndef SMALL
> + char *str, *term = str_val(global("TERM"));
> + if (term && *term) {
> + setupterm(term, 1,