Re: svn commit: r338437 - in head/sys: amd64/amd64 amd64/include arm64/arm64 arm64/include conf dev/efidev modules/efirt sys

2018-09-04 Thread Konstantin Belousov
On Tue, Sep 04, 2018 at 08:48:15AM -0700, Conrad Meyer wrote:
> Hi Konstantin,
> 
> On Sun, Sep 2, 2018 at 2:37 PM, Konstantin Belousov  wrote:
> > Author: kib
> > Date: Sun Sep  2 21:37:05 2018
> > New Revision: 338437
> > URL: https://svnweb.freebsd.org/changeset/base/338437
> >
> > Log:
> >   Catch exceptions during EFI RT calls on amd64.
> >
> >   This appeared to be required to have EFI RT support and EFI RTC
> >   enabled by default, because there are too many reports of faulting
> >   calls on many different machines.  The knob is added to leave the
> >   exceptions unhandled to allow to debug the actual bugs.
> > ...
> >
> > Modified: head/sys/dev/efidev/efirt.c
> > ==
> > --- head/sys/dev/efidev/efirt.c Sun Sep  2 21:16:43 2018(r338436)
> > +++ head/sys/dev/efidev/efirt.c Sun Sep  2 21:37:05 2018(r338437)
> > ...
> > @@ -346,30 +413,35 @@ efi_get_time_capabilities(struct efi_tmcap *tmcap)
> >  int
> >  efi_reset_system(void)
> >  {
> > -   int error;
> > +   struct efirt_callinfo ec;
> >
> > -   error = efi_enter();
> > -   if (error != 0)
> > -   return (error);
> > -   efi_runtime->rt_reset(EFI_RESET_WARM, 0, 0, NULL);
> > -   efi_leave();
> > -   return (EIO);
> > +   if (efi_runtime == NULL)
> > +   return (ENXIO);
> > +   bzero(, sizeof(ec));
> > +   ec.ec_name = "rt_reset";
> > +   ec.ec_argcnt = 4;
> > +   ec.ec_arg1 = (uintptr_t)EFI_RESET_WARM;
> > +   ec.ec_arg1 = (uintptr_t)0;
> > +   ec.ec_arg1 = (uintptr_t)0;
> > +   ec.ec_arg1 = (uintptr_t)NULL;
> 
> Coverity warns about ec_arg1 being overwritten before use ??? should
> these be ec_arg2, 3, 4?  CID 1395456.
Indeed, thank you for reporting.

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


Re: svn commit: r338437 - in head/sys: amd64/amd64 amd64/include arm64/arm64 arm64/include conf dev/efidev modules/efirt sys

2018-09-04 Thread Conrad Meyer
Hi Konstantin,

On Sun, Sep 2, 2018 at 2:37 PM, Konstantin Belousov  wrote:
> Author: kib
> Date: Sun Sep  2 21:37:05 2018
> New Revision: 338437
> URL: https://svnweb.freebsd.org/changeset/base/338437
>
> Log:
>   Catch exceptions during EFI RT calls on amd64.
>
>   This appeared to be required to have EFI RT support and EFI RTC
>   enabled by default, because there are too many reports of faulting
>   calls on many different machines.  The knob is added to leave the
>   exceptions unhandled to allow to debug the actual bugs.
> ...
>
> Modified: head/sys/dev/efidev/efirt.c
> ==
> --- head/sys/dev/efidev/efirt.c Sun Sep  2 21:16:43 2018(r338436)
> +++ head/sys/dev/efidev/efirt.c Sun Sep  2 21:37:05 2018(r338437)
> ...
> @@ -346,30 +413,35 @@ efi_get_time_capabilities(struct efi_tmcap *tmcap)
>  int
>  efi_reset_system(void)
>  {
> -   int error;
> +   struct efirt_callinfo ec;
>
> -   error = efi_enter();
> -   if (error != 0)
> -   return (error);
> -   efi_runtime->rt_reset(EFI_RESET_WARM, 0, 0, NULL);
> -   efi_leave();
> -   return (EIO);
> +   if (efi_runtime == NULL)
> +   return (ENXIO);
> +   bzero(, sizeof(ec));
> +   ec.ec_name = "rt_reset";
> +   ec.ec_argcnt = 4;
> +   ec.ec_arg1 = (uintptr_t)EFI_RESET_WARM;
> +   ec.ec_arg1 = (uintptr_t)0;
> +   ec.ec_arg1 = (uintptr_t)0;
> +   ec.ec_arg1 = (uintptr_t)NULL;

Coverity warns about ec_arg1 being overwritten before use — should
these be ec_arg2, 3, 4?  CID 1395456.

> +   ec.ec_fptr = EFI_RT_METHOD_PA(rt_reset);
> +   return (efi_call());
>  }

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


svn commit: r338437 - in head/sys: amd64/amd64 amd64/include arm64/arm64 arm64/include conf dev/efidev modules/efirt sys

2018-09-02 Thread Konstantin Belousov
Author: kib
Date: Sun Sep  2 21:37:05 2018
New Revision: 338437
URL: https://svnweb.freebsd.org/changeset/base/338437

Log:
  Catch exceptions during EFI RT calls on amd64.
  
  This appeared to be required to have EFI RT support and EFI RTC
  enabled by default, because there are too many reports of faulting
  calls on many different machines.  The knob is added to leave the
  exceptions unhandled to allow to debug the actual bugs.
  
  Reviewed by:  kevans
  Sponsored by: The FreeBSD Foundation
  MFC after:1 week
  Approved by:re (rgrimes)
  Differential revision:https://reviews.freebsd.org/D16972

Added:
  head/sys/amd64/amd64/efirt_support.S   (contents, props changed)
Modified:
  head/sys/amd64/amd64/efirt_machdep.c
  head/sys/amd64/amd64/genassym.c
  head/sys/amd64/include/efi.h
  head/sys/arm64/arm64/efirt_machdep.c
  head/sys/arm64/include/efi.h
  head/sys/conf/files.amd64
  head/sys/dev/efidev/efirt.c
  head/sys/modules/efirt/Makefile
  head/sys/sys/efi.h

Modified: head/sys/amd64/amd64/efirt_machdep.c
==
--- head/sys/amd64/amd64/efirt_machdep.cSun Sep  2 21:16:43 2018
(r338436)
+++ head/sys/amd64/amd64/efirt_machdep.cSun Sep  2 21:37:05 2018
(r338437)
@@ -55,6 +55,7 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -266,6 +267,7 @@ efi_arch_enter(void)
 
curpmap = PCPU_GET(curpmap);
PMAP_LOCK_ASSERT(curpmap, MA_OWNED);
+   curthread->td_md.md_efirt_dis_pf = vm_fault_disable_pagefaults();
 
/*
 * IPI TLB shootdown handler invltlb_pcid_handler() reloads
@@ -300,6 +302,7 @@ efi_arch_leave(void)
curpmap->pm_pcids[PCPU_GET(cpuid)].pm_pcid : 0));
if (!pmap_pcid_enabled)
invltlb();
+   vm_fault_enable_pagefaults(curthread->td_md.md_efirt_dis_pf);
 }
 
 /* XXX debug stuff */

Added: head/sys/amd64/amd64/efirt_support.S
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/sys/amd64/amd64/efirt_support.SSun Sep  2 21:37:05 2018
(r338437)
@@ -0,0 +1,116 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2018 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Konstantin Belousov 
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * 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 "assym.inc"
+
+   .text
+ENTRY(efi_rt_arch_call)
+   pushq   %rbp
+   movq%rsp, %rbp
+
+   movq%rbx, EC_RBX(%rdi)
+   movq%rsp, EC_RSP(%rdi)
+   movq%rbp, EC_RBP(%rdi)
+   movq%r12, EC_R12(%rdi)
+   movq%r13, EC_R13(%rdi)
+   movq%r14, EC_R14(%rdi)
+   movq%r15, EC_R15(%rdi)
+   movqPCPU(CURTHREAD), %rax
+   movq%rdi, TD_MD+MD_EFIRT_TMP(%rax)
+   movqPCPU(CURPCB), %rsi
+
+   movlEC_ARGCNT(%rdi), %ecx
+   movl%ecx, %ebx
+   movl$4, %eax
+   cmpl%eax, %ecx
+   cmovbl  %eax, %ecx
+   shll$3, %ecx
+   subq%rcx, %rsp
+
+   cmpl$0, %ebx
+   jz  1f
+   movqEC_ARG1(%rdi), %rcx
+   decl%ebx
+   jz  1f
+   movqEC_ARG2(%rdi), %rdx
+   decl%ebx
+   jz  1f
+   movqEC_ARG3(%rdi), %r8
+   decl%ebx
+   jz  1f
+   movqEC_ARG4(%rdi), %r9
+   decl%ebx
+   jz  1f
+   movqEC_ARG5(%rdi), %rax
+   movq%rax, 4*8(%rsp)
+   decl%ebx
+   jz  1f
+   movq