re: CVS commit: src/sys/arch/x86/x86

2020-06-24 Thread matthew green
"Jaromir Dolecek" writes:
> Module Name:  src
> Committed By: jdolecek
> Date: Wed Jun 24 22:28:08 UTC 2020
> 
> Modified Files:
>   src/sys/arch/x86/x86: multiboot2.c
> 
> Log Message:
> don't try allocating 16KB of scratch space on stack
> 
> it's too early for kmem_alloc(), so use static variable in BSS; it's used
> post reloc, so don't need to use the RELOC() macros
> 
> XXX compile-tested only on i386

this one is quite a lot of lost wasted space.  can you find a
way to reuse these pages?  or use the x86-specific ways to
get early memory...

thanks.


.mrg.


Re: CVS commit: src/sys/arch/x86/x86

2020-06-24 Thread Joerg Sonnenberger
On Wed, Jun 24, 2020 at 10:28:08PM +, Jaromir Dolecek wrote:
> Module Name:  src
> Committed By: jdolecek
> Date: Wed Jun 24 22:28:08 UTC 2020
> 
> Modified Files:
>   src/sys/arch/x86/x86: multiboot2.c
> 
> Log Message:
> don't try allocating 16KB of scratch space on stack
> 
> it's too early for kmem_alloc(), so use static variable in BSS; it's used
> post reloc, so don't need to use the RELOC() macros

Why? This is the initial early stack, not the normal LWP stack.

Joerg


Re: CVS commit: src/sys/arch/x86/x86

2020-06-06 Thread Christos Zoulas
In article <20200606135850.ge14...@pony.stderr.spb.ru>,
Valery Ushakov   wrote:
>On Sat, Jun 06, 2020 at 11:25:19 +0200, Kamil Rytarowski wrote:
>
>> On 06.06.2020 09:42, Simon Burge wrote:
>> > "Kamil Rytarowski" wrote:
>> > 
>> >> Module Name:  src
>> >> Committed By: kamil
>> >> Date: Fri Jun  5 21:48:04 UTC 2020
>> >>
>> >> Modified Files:
>> >>
>> >>   src/sys/arch/x86/x86: cpu_rng.c
>> >>
>> >> Log Message:
>> >>
>> >> Change const unsigned to preprocessor define
>> >>
>> >> Fixes GCC -O0 build with the stack protector.
>> > 
>> > Surely a gcc bug?  This almost certainly needs an
>> > /* XXX gcc stack protector -O0 bug */ comment and
>> > possibly an entry in doc/HACKS as well otherwise
>> > someone will come along later and de-uglify this
>> > change.
>> 
>> This is not really a GCC bug, as C const is not constexpr.  It's
>> also not the only place with such logic and such workaround.  C++
>> fixed it and have real const.
>
>Doesn't -Wvla help catching these?  Should we enable it?

I think it might catch too much... But we can try it...

christos




Re: CVS commit: src/sys/arch/x86/x86

2020-06-06 Thread Valery Ushakov
On Sat, Jun 06, 2020 at 11:25:19 +0200, Kamil Rytarowski wrote:

> On 06.06.2020 09:42, Simon Burge wrote:
> > "Kamil Rytarowski" wrote:
> > 
> >> Module Name:   src
> >> Committed By:  kamil
> >> Date:  Fri Jun  5 21:48:04 UTC 2020
> >>
> >> Modified Files:
> >>
> >>src/sys/arch/x86/x86: cpu_rng.c
> >>
> >> Log Message:
> >>
> >> Change const unsigned to preprocessor define
> >>
> >> Fixes GCC -O0 build with the stack protector.
> > 
> > Surely a gcc bug?  This almost certainly needs an
> > /* XXX gcc stack protector -O0 bug */ comment and
> > possibly an entry in doc/HACKS as well otherwise
> > someone will come along later and de-uglify this
> > change.
> 
> This is not really a GCC bug, as C const is not constexpr.  It's
> also not the only place with such logic and such workaround.  C++
> fixed it and have real const.

Doesn't -Wvla help catching these?  Should we enable it?

-uwe


Re: CVS commit: src/sys/arch/x86/x86

2020-06-06 Thread Kamil Rytarowski
On 06.06.2020 09:42, Simon Burge wrote:
> "Kamil Rytarowski" wrote:
> 
>> Module Name: src
>> Committed By:kamil
>> Date:Fri Jun  5 21:48:04 UTC 2020
>>
>> Modified Files:
>>
>>  src/sys/arch/x86/x86: cpu_rng.c
>>
>> Log Message:
>>
>> Change const unsigned to preprocessor define
>>
>> Fixes GCC -O0 build with the stack protector.
> 
> Surely a gcc bug?  This almost certainly needs an
> /* XXX gcc stack protector -O0 bug */ comment and
> possibly an entry in doc/HACKS as well otherwise
> someone will come along later and de-uglify this
> change.
> 
> Cheers,
> Simon.
> 

This is not really a GCC bug, as C const is not constexpr. It's also not
the only place with such logic and such workaround. C++ fixed it and
have real const.



signature.asc
Description: OpenPGP digital signature


Re: CVS commit: src/sys/arch/x86/x86

2020-06-06 Thread Simon Burge
"Kamil Rytarowski" wrote:

> Module Name:  src
> Committed By: kamil
> Date: Fri Jun  5 21:48:04 UTC 2020
>
> Modified Files:
>
>   src/sys/arch/x86/x86: cpu_rng.c
>
> Log Message:
>
> Change const unsigned to preprocessor define
>
> Fixes GCC -O0 build with the stack protector.

Surely a gcc bug?  This almost certainly needs an
/* XXX gcc stack protector -O0 bug */ comment and
possibly an entry in doc/HACKS as well otherwise
someone will come along later and de-uglify this
change.

Cheers,
Simon.


Re: CVS commit: src/sys/arch/x86/x86

2020-04-02 Thread Kengo NAKAHARA

Hi,

Hmm, but TSC drift is still observed on recent (high clock) CPUs.
I will have researched and fix later.

On 2020/04/03 12:05, Kengo NAKAHARA wrote:

Module Name:src
Committed By:   knakahara
Date:   Fri Apr  3 03:05:39 UTC 2020

Modified Files:
src/sys/arch/x86/x86: tsc.c

Log Message:
Fix TSC drift is observed almost every time wrongly.

Ths "TSC drift" in tsc_tc_init() means the cpu_cc_skew delta between
first measurement (in cpu_start_secondary) and second measurement
(in cpu_boot_secondary), that is, the TSC drift is expected to be
almost zero.  However, the second measument in current implementation
is added extra cpu_cc_skew accidentally, so current delta value means
almost cpu_cc_skew wrongly.

tsc_sync_bp and tsc_sync_ap should use rdtsc() to get raw values.

Advised by nonaka@n.o, thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/sys/arch/x86/x86/tsc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



--
//
Internet Initiative Japan Inc.

Device Engineering Section,
Product Development Department,
Product Division,
Technology Unit

Kengo NAKAHARA 


Re: CVS commit: src/sys/arch/x86/x86

2020-03-17 Thread Andrew Doran
On Tue, Mar 17, 2020 at 10:38:14PM +, Andrew Doran wrote:

> Log Message:
> - Change some expensive checks DEBUG -> DIAGNOSTIC.

That was meant to be the other way around, oops.

Andrew


Re: CVS commit: src/sys/arch/x86/x86

2019-12-03 Thread Andrew Doran
On Tue, Dec 03, 2019 at 01:14:14PM +0100, Kamil Rytarowski wrote:

> On 03.12.2019 12:50, Juergen Hannken-Illjes wrote:
> > Module Name:src
> > Committed By:   hannken
> > Date:   Tue Dec  3 11:50:45 UTC 2019
> > 
> > Modified Files:
> > src/sys/arch/x86/x86: x86_machdep.c
> > 
> > Log Message:
> > Make sure the assignment to "idepth" is done inside the loop to prevent
> > preemption between loop end and dereference of "l_cpu->ci_depth".
> > 
> > 
> > To generate a diff of this commit:
> > cvs rdiff -u -r1.131 -r1.132 src/sys/arch/x86/x86/x86_machdep.c
> > 
> > Please note that diffs are not public domain; they are subject to the
> > copyright notices on the relevant files.
> > 
> > 
> > Modified files:
> > 
> > Index: src/sys/arch/x86/x86/x86_machdep.c
> > diff -u src/sys/arch/x86/x86/x86_machdep.c:1.131 
> > src/sys/arch/x86/x86/x86_machdep.c:1.132
> > --- src/sys/arch/x86/x86/x86_machdep.c:1.131Tue Dec  3 11:50:16 2019
> > +++ src/sys/arch/x86/x86/x86_machdep.c  Tue Dec  3 11:50:45 2019
> > @@ -1,4 +1,4 @@
> > -/* $NetBSD: x86_machdep.c,v 1.131 2019/12/03 11:50:16 hannken Exp $
> > */
> > +/* $NetBSD: x86_machdep.c,v 1.132 2019/12/03 11:50:45 hannken Exp $
> > */
> >  
> >  /*-
> >   * Copyright (c) 2002, 2006, 2007 YAMAMOTO Takashi,
> > @@ -31,7 +31,7 @@
> >   */
> >  
> >  #include 
> > -__KERNEL_RCSID(0, "$NetBSD: x86_machdep.c,v 1.131 2019/12/03 11:50:16 
> > hannken Exp $");
> > +__KERNEL_RCSID(0, "$NetBSD: x86_machdep.c,v 1.132 2019/12/03 11:50:45 
> > hannken Exp $");
> >  
> >  #include "opt_modular.h"
> >  #include "opt_physmem.h"
> > @@ -350,7 +350,7 @@ bool
> >  cpu_intr_p(void)
> >  {
> > uint64_t ncsw;
> > -   int idepth;
> > +   volatile int idepth;
> > lwp_t *l;
> >  
> > l = curlwp;
> > 
> 
> Thanks!
> 
> This looks like to be in need to be propagated to:
> src/sys/arch/arm/arm/arm_machdep.c, src/sys/arch/mips/mips/cpu_subr.c,
> src/sys/arch/sparc/sparc/intr.c, src/sys/arch/sparc64/sparc64/machdep.c,
> src/sys/arch/usermode/dev/cpu.c,

I will take care of that later today.

Andrew




Re: CVS commit: src/sys/arch/x86/x86

2019-12-03 Thread Kamil Rytarowski
On 03.12.2019 12:50, Juergen Hannken-Illjes wrote:
> Module Name:  src
> Committed By: hannken
> Date: Tue Dec  3 11:50:45 UTC 2019
> 
> Modified Files:
>   src/sys/arch/x86/x86: x86_machdep.c
> 
> Log Message:
> Make sure the assignment to "idepth" is done inside the loop to prevent
> preemption between loop end and dereference of "l_cpu->ci_depth".
> 
> 
> To generate a diff of this commit:
> cvs rdiff -u -r1.131 -r1.132 src/sys/arch/x86/x86/x86_machdep.c
> 
> Please note that diffs are not public domain; they are subject to the
> copyright notices on the relevant files.
> 
> 
> Modified files:
> 
> Index: src/sys/arch/x86/x86/x86_machdep.c
> diff -u src/sys/arch/x86/x86/x86_machdep.c:1.131 
> src/sys/arch/x86/x86/x86_machdep.c:1.132
> --- src/sys/arch/x86/x86/x86_machdep.c:1.131  Tue Dec  3 11:50:16 2019
> +++ src/sys/arch/x86/x86/x86_machdep.cTue Dec  3 11:50:45 2019
> @@ -1,4 +1,4 @@
> -/*   $NetBSD: x86_machdep.c,v 1.131 2019/12/03 11:50:16 hannken Exp $
> */
> +/*   $NetBSD: x86_machdep.c,v 1.132 2019/12/03 11:50:45 hannken Exp $
> */
>  
>  /*-
>   * Copyright (c) 2002, 2006, 2007 YAMAMOTO Takashi,
> @@ -31,7 +31,7 @@
>   */
>  
>  #include 
> -__KERNEL_RCSID(0, "$NetBSD: x86_machdep.c,v 1.131 2019/12/03 11:50:16 
> hannken Exp $");
> +__KERNEL_RCSID(0, "$NetBSD: x86_machdep.c,v 1.132 2019/12/03 11:50:45 
> hannken Exp $");
>  
>  #include "opt_modular.h"
>  #include "opt_physmem.h"
> @@ -350,7 +350,7 @@ bool
>  cpu_intr_p(void)
>  {
>   uint64_t ncsw;
> - int idepth;
> + volatile int idepth;
>   lwp_t *l;
>  
>   l = curlwp;
> 

Thanks!

This looks like to be in need to be propagated to:
src/sys/arch/arm/arm/arm_machdep.c, src/sys/arch/mips/mips/cpu_subr.c,
src/sys/arch/sparc/sparc/intr.c, src/sys/arch/sparc64/sparc64/machdep.c,
src/sys/arch/usermode/dev/cpu.c,



signature.asc
Description: OpenPGP digital signature


CVS commit: src/sys/arch/x86/x86

2019-11-16 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat Nov 16 10:19:29 UTC 2019

Modified Files:
src/sys/arch/x86/x86: pmap.c

Log Message:
Add a NULL check on the structure pointer, not to retrieve its first field
if it is NULL. The previous code was not buggy strictly speaking. This
change probably doesn't change anything, except removing assumptions in the
compiler optimization passes, which too probably doesn't change anything in
this case.

Reported-by: syzbot+110b29c1973f38a38...@syzkaller.appspotmail.com


To generate a diff of this commit:
cvs rdiff -u -r1.340 -r1.341 src/sys/arch/x86/x86/pmap.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/x86/pmap.c
diff -u src/sys/arch/x86/x86/pmap.c:1.340 src/sys/arch/x86/x86/pmap.c:1.341
--- src/sys/arch/x86/x86/pmap.c:1.340	Thu Nov 14 17:09:23 2019
+++ src/sys/arch/x86/x86/pmap.c	Sat Nov 16 10:19:29 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.340 2019/11/14 17:09:23 maxv Exp $	*/
+/*	$NetBSD: pmap.c,v 1.341 2019/11/16 10:19:29 maxv Exp $	*/
 
 /*
  * Copyright (c) 2008, 2010, 2016, 2017 The NetBSD Foundation, Inc.
@@ -130,7 +130,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.340 2019/11/14 17:09:23 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.341 2019/11/16 10:19:29 maxv Exp $");
 
 #include "opt_user_ldt.h"
 #include "opt_lockdebug.h"
@@ -541,6 +541,8 @@ static inline struct pv_pte *
 pve_to_pvpte(struct pv_entry *pve)
 {
 
+	if (pve == NULL)
+		return NULL;
 	KASSERT((void *)>pve_pte == (void *)pve);
 	return >pve_pte;
 }



CVS commit: src/sys/arch/x86/x86

2019-11-16 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat Nov 16 10:19:29 UTC 2019

Modified Files:
src/sys/arch/x86/x86: pmap.c

Log Message:
Add a NULL check on the structure pointer, not to retrieve its first field
if it is NULL. The previous code was not buggy strictly speaking. This
change probably doesn't change anything, except removing assumptions in the
compiler optimization passes, which too probably doesn't change anything in
this case.

Reported-by: syzbot+110b29c1973f38a38...@syzkaller.appspotmail.com


To generate a diff of this commit:
cvs rdiff -u -r1.340 -r1.341 src/sys/arch/x86/x86/pmap.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/x86/x86

2019-11-07 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Fri Nov  8 04:15:02 UTC 2019

Modified Files:
src/sys/arch/x86/x86: intr.c

Log Message:
 Fix a bug that evcnt_detach() called twice when the idt vector is full.
OK'd by knakahara.


To generate a diff of this commit:
cvs rdiff -u -r1.146 -r1.147 src/sys/arch/x86/x86/intr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/x86/x86

2019-11-07 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Fri Nov  8 04:15:02 UTC 2019

Modified Files:
src/sys/arch/x86/x86: intr.c

Log Message:
 Fix a bug that evcnt_detach() called twice when the idt vector is full.
OK'd by knakahara.


To generate a diff of this commit:
cvs rdiff -u -r1.146 -r1.147 src/sys/arch/x86/x86/intr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/x86/intr.c
diff -u src/sys/arch/x86/x86/intr.c:1.146 src/sys/arch/x86/x86/intr.c:1.147
--- src/sys/arch/x86/x86/intr.c:1.146	Mon Jun 17 06:38:30 2019
+++ src/sys/arch/x86/x86/intr.c	Fri Nov  8 04:15:02 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.c,v 1.146 2019/06/17 06:38:30 msaitoh Exp $	*/
+/*	$NetBSD: intr.c,v 1.147 2019/11/08 04:15:02 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -133,7 +133,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.146 2019/06/17 06:38:30 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.147 2019/11/08 04:15:02 msaitoh Exp $");
 
 #include "opt_intrdebug.h"
 #include "opt_multiprocessor.h"
@@ -475,8 +475,10 @@ intr_free_io_intrsource_direct(struct in
 	SIMPLEQ_REMOVE(_interrupt_sources, isp, intrsource, is_list);
 
 	/* Is this interrupt established? */
-	if (isp->is_evname[0] != '\0')
+	if (isp->is_evname[0] != '\0') {
 		evcnt_detach(>is_evcnt);
+		isp->is_evname[0] = '\0';
+	}
 
 	kmem_free(isp->is_saved_evcnt,
 	sizeof(*(isp->is_saved_evcnt)) * ncpu);
@@ -679,6 +681,7 @@ intr_allocate_slot(struct pic *pic, int 
 	}
 	if (idtvec == 0) {
 		evcnt_detach(>ci_isources[slot]->is_evcnt);
+		ci->ci_isources[slot]->is_evname[0] = '\0';
 		ci->ci_isources[slot] = NULL;
 		return EBUSY;
 	}



CVS commit: src/sys/arch/x86/x86

2019-11-01 Thread Takahiro Kambe
Module Name:src
Committed By:   taca
Date:   Fri Nov  1 15:01:27 UTC 2019

Modified Files:
src/sys/arch/x86/x86: cpu_rng.c

Log Message:
Check CPU support of RDRAND before calling cpu_rng_rdrand().

cpu_earlyrng() checks CPU support of RDSEED and RDRAND before calling
cpu_rng_rdseed() and cpu_rng_rdrand().

But cpu_rng_rdseed() did not check CPU support of RDRAND and system had
crashed on such an environment.  There is no such case with real CPU but
some VM environment.

Fix kern/54655 and confirmed by msaitoh@.

Needs pullup to netbsd-9.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/x86/x86/cpu_rng.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/x86/cpu_rng.c
diff -u src/sys/arch/x86/x86/cpu_rng.c:1.9 src/sys/arch/x86/x86/cpu_rng.c:1.10
--- src/sys/arch/x86/x86/cpu_rng.c:1.9	Wed Aug 22 12:07:43 2018
+++ src/sys/arch/x86/x86/cpu_rng.c	Fri Nov  1 15:01:27 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu_rng.c,v 1.9 2018/08/22 12:07:43 maxv Exp $ */
+/* $NetBSD: cpu_rng.c,v 1.10 2019/11/01 15:01:27 taca Exp $ */
 
 /*-
  * Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -53,6 +53,8 @@ static enum {
 	CPU_RNG_VIA
 } cpu_rng_mode __read_mostly = CPU_RNG_NONE;
 
+static bool has_rdrand;
+
 bool
 cpu_rng_init(void)
 {
@@ -131,7 +133,10 @@ cpu_rng_rdseed(cpu_rng_t *out)
 	 * to be seeded even in this case.
 	 */
 exhausted:
-	return cpu_rng_rdrand(out);
+	if (has_rdrand)
+		return cpu_rng_rdrand(out);
+	else
+		return 0;
 }
 
 static size_t
@@ -213,7 +218,7 @@ cpu_earlyrng(void *out, size_t sz)
 	int i;
 
 	bool has_rdseed = (cpu_feature[5] & CPUID_SEF_RDSEED) != 0;
-	bool has_rdrand = (cpu_feature[1] & CPUID2_RDRAND) != 0;
+	has_rdrand = (cpu_feature[1] & CPUID2_RDRAND) != 0;
 
 	KASSERT(sz + sizeof(uint64_t) <= SHA512_DIGEST_LENGTH);
 



CVS commit: src/sys/arch/x86/x86

2019-11-01 Thread Takahiro Kambe
Module Name:src
Committed By:   taca
Date:   Fri Nov  1 15:01:27 UTC 2019

Modified Files:
src/sys/arch/x86/x86: cpu_rng.c

Log Message:
Check CPU support of RDRAND before calling cpu_rng_rdrand().

cpu_earlyrng() checks CPU support of RDSEED and RDRAND before calling
cpu_rng_rdseed() and cpu_rng_rdrand().

But cpu_rng_rdseed() did not check CPU support of RDRAND and system had
crashed on such an environment.  There is no such case with real CPU but
some VM environment.

Fix kern/54655 and confirmed by msaitoh@.

Needs pullup to netbsd-9.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/x86/x86/cpu_rng.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/x86/x86

2019-10-30 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Wed Oct 30 16:32:04 UTC 2019

Modified Files:
src/sys/arch/x86/x86: fpu.c

Log Message:
Style.


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 src/sys/arch/x86/x86/fpu.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/x86/x86

2019-10-30 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Wed Oct 30 16:32:04 UTC 2019

Modified Files:
src/sys/arch/x86/x86: fpu.c

Log Message:
Style.


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 src/sys/arch/x86/x86/fpu.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/x86/fpu.c
diff -u src/sys/arch/x86/x86/fpu.c:1.58 src/sys/arch/x86/x86/fpu.c:1.59
--- src/sys/arch/x86/x86/fpu.c:1.58	Sat Oct 12 06:31:04 2019
+++ src/sys/arch/x86/x86/fpu.c	Wed Oct 30 16:32:04 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: fpu.c,v 1.58 2019/10/12 06:31:04 maxv Exp $	*/
+/*	$NetBSD: fpu.c,v 1.59 2019/10/30 16:32:04 maxv Exp $	*/
 
 /*
  * Copyright (c) 2008, 2019 The NetBSD Foundation, Inc.  All
@@ -96,7 +96,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.58 2019/10/12 06:31:04 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.59 2019/10/30 16:32:04 maxv Exp $");
 
 #include "opt_multiprocessor.h"
 
@@ -784,16 +784,15 @@ process_read_xstate(struct lwp *l, struc
 	xstate->xs_xstate_bv = fpu_save->sv_xsave_hdr.xsh_xstate_bv;
 	KASSERT(!(xstate->xs_xstate_bv & ~xstate->xs_rfbm));
 
-#define COPY_COMPONENT(xcr0_val, xsave_val, field)\
-	if (xstate->xs_xstate_bv & xcr0_val) {	\
-		KASSERT(x86_xsave_offsets[xsave_val]\
-		>= sizeof(struct xsave_header));\
-		KASSERT(x86_xsave_sizes[xsave_val]\
-		>= sizeof(xstate -> field));\
-		\
-		memcpy( -> field,	\
-		(char*)fpu_save + x86_xsave_offsets[xsave_val],		\
-		sizeof(xstate -> field));	\
+#define COPY_COMPONENT(xcr0_val, xsave_val, field)			\
+	if (xstate->xs_xstate_bv & xcr0_val) {\
+		KASSERT(x86_xsave_offsets[xsave_val]			\
+		>= sizeof(struct xsave_header));			\
+		KASSERT(x86_xsave_sizes[xsave_val]			\
+		>= sizeof(xstate->field));\
+		memcpy(>field,	\
+		(char*)fpu_save + x86_xsave_offsets[xsave_val],	\
+		sizeof(xstate->field));\
 	}
 
 	COPY_COMPONENT(XCR0_YMM_Hi128, XSAVE_YMM_Hi128, xs_ymm_hi128);
@@ -846,8 +845,8 @@ process_write_xstate(struct lwp *l, cons
 	/* If XSAVE is supported, make sure that xstate_bv is set correctly. */
 	if (x86_fpu_save >= FPU_SAVE_XSAVE) {
 		/*
-		 * Bit-wise xstate->xs_rfbm ? xstate->xs_xstate_bv
-		 *  : fpu_save->sv_xsave_hdr.xsh_xstate_bv
+		 * Bit-wise "xstate->xs_rfbm ? xstate->xs_xstate_bv :
+		 *   fpu_save->sv_xsave_hdr.xsh_xstate_bv"
 		 */
 		fpu_save->sv_xsave_hdr.xsh_xstate_bv =
 		(fpu_save->sv_xsave_hdr.xsh_xstate_bv & ~xstate->xs_rfbm) |
@@ -865,8 +864,8 @@ process_write_xstate(struct lwp *l, cons
 	}
 
 	/*
-	 * Copy MXCSR if either SSE or AVX state is requested, to match the XSAVE
-	 * behavior for those flags.
+	 * Copy MXCSR if either SSE or AVX state is requested, to match the
+	 * XSAVE behavior for those flags.
 	 */
 	if (xstate->xs_xstate_bv & (XCR0_SSE|XCR0_YMM_Hi128)) {
 		/*
@@ -880,19 +879,17 @@ process_write_xstate(struct lwp *l, cons
 
 	if (xstate->xs_xstate_bv & XCR0_SSE) {
 		memcpy(_save->sv_xsave_hdr.xsh_fxsave[160],
-		xstate->xs_fxsave.fx_xmm,
-		sizeof(xstate->xs_fxsave.fx_xmm));
+		xstate->xs_fxsave.fx_xmm, sizeof(xstate->xs_fxsave.fx_xmm));
 	}
 
-#define COPY_COMPONENT(xcr0_val, xsave_val, field)\
-	if (xstate->xs_xstate_bv & xcr0_val) {	\
-		KASSERT(x86_xsave_offsets[xsave_val]\
-		>= sizeof(struct xsave_header));\
-		KASSERT(x86_xsave_sizes[xsave_val]\
-		>= sizeof(xstate -> field));\
-		\
-		memcpy((char*)fpu_save + x86_xsave_offsets[xsave_val],		\
-		 -> field, sizeof(xstate -> field));		\
+#define COPY_COMPONENT(xcr0_val, xsave_val, field)			\
+	if (xstate->xs_xstate_bv & xcr0_val) {\
+		KASSERT(x86_xsave_offsets[xsave_val]			\
+		>= sizeof(struct xsave_header));			\
+		KASSERT(x86_xsave_sizes[xsave_val]			\
+		>= sizeof(xstate->field));\
+		memcpy((char *)fpu_save + x86_xsave_offsets[xsave_val],	\
+		>field, sizeof(xstate->field));		\
 	}
 
 	COPY_COMPONENT(XCR0_YMM_Hi128, XSAVE_YMM_Hi128, xs_ymm_hi128);



CVS commit: src/sys/arch/x86/x86

2019-10-29 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Tue Oct 29 12:39:46 UTC 2019

Modified Files:
src/sys/arch/x86/x86: identcpu.c

Log Message:
Enable XSAVEOPT.


To generate a diff of this commit:
cvs rdiff -u -r1.97 -r1.98 src/sys/arch/x86/x86/identcpu.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/x86/x86

2019-10-29 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Tue Oct 29 12:39:46 UTC 2019

Modified Files:
src/sys/arch/x86/x86: identcpu.c

Log Message:
Enable XSAVEOPT.


To generate a diff of this commit:
cvs rdiff -u -r1.97 -r1.98 src/sys/arch/x86/x86/identcpu.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/x86/identcpu.c
diff -u src/sys/arch/x86/x86/identcpu.c:1.97 src/sys/arch/x86/x86/identcpu.c:1.98
--- src/sys/arch/x86/x86/identcpu.c:1.97	Mon Oct 21 10:09:24 2019
+++ src/sys/arch/x86/x86/identcpu.c	Tue Oct 29 12:39:46 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: identcpu.c,v 1.97 2019/10/21 10:09:24 maxv Exp $	*/
+/*	$NetBSD: identcpu.c,v 1.98 2019/10/29 12:39:46 maxv Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.97 2019/10/21 10:09:24 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.98 2019/10/29 12:39:46 maxv Exp $");
 
 #include "opt_xen.h"
 
@@ -804,11 +804,9 @@ cpu_probe_fpu(struct cpu_info *ci)
 
 	x86_fpu_save = FPU_SAVE_XSAVE;
 
-#if 0 /* XXX PR 52966 */
 	x86_cpuid2(0xd, 1, descs);
 	if (descs[0] & CPUID_PES1_XSAVEOPT)
 		x86_fpu_save = FPU_SAVE_XSAVEOPT;
-#endif
 
 	/* Get features and maximum size of the save area */
 	x86_cpuid(0xd, descs);



CVS commit: src/sys/arch/x86/x86

2019-10-21 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Mon Oct 21 10:09:24 UTC 2019

Modified Files:
src/sys/arch/x86/x86: identcpu.c

Log Message:
Call cpu_probe_fpu() only once (from cpu0), and style.


To generate a diff of this commit:
cvs rdiff -u -r1.96 -r1.97 src/sys/arch/x86/x86/identcpu.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/x86/identcpu.c
diff -u src/sys/arch/x86/x86/identcpu.c:1.96 src/sys/arch/x86/x86/identcpu.c:1.97
--- src/sys/arch/x86/x86/identcpu.c:1.96	Thu Oct  3 05:06:29 2019
+++ src/sys/arch/x86/x86/identcpu.c	Mon Oct 21 10:09:24 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: identcpu.c,v 1.96 2019/10/03 05:06:29 maxv Exp $	*/
+/*	$NetBSD: identcpu.c,v 1.97 2019/10/21 10:09:24 maxv Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.96 2019/10/03 05:06:29 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.97 2019/10/21 10:09:24 maxv Exp $");
 
 #include "opt_xen.h"
 
@@ -736,7 +736,7 @@ cpu_probe_vortex86(struct cpu_info *ci)
 }
 
 static void
-cpu_probe_old_fpu(struct cpu_info *ci)
+cpu_probe_fpu_old(struct cpu_info *ci)
 {
 #if defined(__i386__) && !defined(XENPV)
 
@@ -764,8 +764,7 @@ cpu_probe_fpu(struct cpu_info *ci)
 	/* If we have FXSAVE/FXRESTOR, use them. */
 	if ((ci->ci_feat_val[0] & CPUID_FXSR) == 0) {
 		i386_use_fxsave = 0;
-		/* Allow for no fpu even if cpuid is supported */
-		cpu_probe_old_fpu(ci);
+		cpu_probe_fpu_old(ci);
 		return;
 	}
 
@@ -788,14 +787,14 @@ cpu_probe_fpu(struct cpu_info *ci)
 	x86_fpu_save = FPU_SAVE_FXSAVE;
 	x86_fpu_save_size = sizeof(struct fxsave);
 
-	/* See if xsave (for AVX) is supported */
+	/* See if XSAVE is supported */
 	if ((ci->ci_feat_val[1] & CPUID2_XSAVE) == 0)
 		return;
 
 #ifdef XENPV
 	/*
 	 * Xen kernel can disable XSAVE via "no-xsave" option, in that case
-	 * XSAVE instructions like xrstor become privileged and trigger
+	 * the XSAVE/XRSTOR instructions become privileged and trigger
 	 * supervisor trap. OSXSAVE flag seems to be reliably set according
 	 * to whether XSAVE is actually available.
 	 */
@@ -843,7 +842,7 @@ cpu_probe(struct cpu_info *ci)
 
 	if (cpuid_level < 0) {
 		/* cpuid instruction not supported */
-		cpu_probe_old_fpu(ci);
+		cpu_probe_fpu_old(ci);
 		return;
 	}
 
@@ -949,7 +948,9 @@ cpu_probe(struct cpu_info *ci)
 	cpu_probe_geode(ci);
 	cpu_probe_vortex86(ci);
 
-	cpu_probe_fpu(ci);
+	if (ci == _info_primary) {
+		cpu_probe_fpu(ci);
+	}
 
 	x86_cpu_topology(ci);
 



CVS commit: src/sys/arch/x86/x86

2019-10-21 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Mon Oct 21 10:09:24 UTC 2019

Modified Files:
src/sys/arch/x86/x86: identcpu.c

Log Message:
Call cpu_probe_fpu() only once (from cpu0), and style.


To generate a diff of this commit:
cvs rdiff -u -r1.96 -r1.97 src/sys/arch/x86/x86/identcpu.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/x86/x86

2019-10-18 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Oct 18 16:26:38 UTC 2019

Modified Files:
src/sys/arch/x86/x86: vm_machdep.c

Log Message:
Remove unused call to savectx().


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/sys/arch/x86/x86/vm_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/x86/x86

2019-10-18 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Oct 18 16:26:38 UTC 2019

Modified Files:
src/sys/arch/x86/x86: vm_machdep.c

Log Message:
Remove unused call to savectx().


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/sys/arch/x86/x86/vm_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/x86/vm_machdep.c
diff -u src/sys/arch/x86/x86/vm_machdep.c:1.38 src/sys/arch/x86/x86/vm_machdep.c:1.39
--- src/sys/arch/x86/x86/vm_machdep.c:1.38	Sat Oct 12 06:31:04 2019
+++ src/sys/arch/x86/x86/vm_machdep.c	Fri Oct 18 16:26:38 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: vm_machdep.c,v 1.38 2019/10/12 06:31:04 maxv Exp $	*/
+/*	$NetBSD: vm_machdep.c,v 1.39 2019/10/18 16:26:38 maxv Exp $	*/
 
 /*-
  * Copyright (c) 1982, 1986 The Regents of the University of California.
@@ -80,7 +80,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.38 2019/10/12 06:31:04 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.39 2019/10/18 16:26:38 maxv Exp $");
 
 #include "opt_mtrr.h"
 
@@ -136,19 +136,11 @@ cpu_lwp_fork(struct lwp *l1, struct lwp 
 	struct switchframe *sf;
 	vaddr_t uv;
 
+	KASSERT(l1 == curlwp || l1 == );
+
 	pcb1 = lwp_getpcb(l1);
 	pcb2 = lwp_getpcb(l2);
 
-	/*
-	 * Sync the PCB before we copy it.
-	 */
-	if (l1 == curlwp) {
-		KASSERT(pcb1 == curpcb);
-		savectx(pcb1);
-	} else {
-		KASSERT(l1 == );
-	}
-
 	/* Copy the PCB from parent, except the FPU state. */
 	memcpy(pcb2, pcb1, offsetof(struct pcb, pcb_savefpu));
 



CVS commit: src/sys/arch/x86/x86

2019-10-18 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Fri Oct 18 14:59:22 UTC 2019

Modified Files:
src/sys/arch/x86/x86: multiboot2.c

Log Message:
Make compile with "options DEBUG".


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/x86/x86/multiboot2.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/x86/x86

2019-10-18 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Fri Oct 18 14:59:22 UTC 2019

Modified Files:
src/sys/arch/x86/x86: multiboot2.c

Log Message:
Make compile with "options DEBUG".


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/x86/x86/multiboot2.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/x86/multiboot2.c
diff -u src/sys/arch/x86/x86/multiboot2.c:1.1 src/sys/arch/x86/x86/multiboot2.c:1.2
--- src/sys/arch/x86/x86/multiboot2.c:1.1	Fri Oct 18 01:38:28 2019
+++ src/sys/arch/x86/x86/multiboot2.c	Fri Oct 18 14:59:22 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: multiboot2.c,v 1.1 2019/10/18 01:38:28 manu Exp $	*/
+/*	$NetBSD: multiboot2.c,v 1.2 2019/10/18 14:59:22 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2005, 2006 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: multiboot2.c,v 1.1 2019/10/18 01:38:28 manu Exp $");
+__KERNEL_RCSID(0, "$NetBSD: multiboot2.c,v 1.2 2019/10/18 14:59:22 hannken Exp $");
 
 #include "opt_multiboot.h"
 
@@ -784,6 +784,9 @@ multiboot2_print_info(void)
 	char *cp;
 	uint32_t total_size;
 	uint32_t reserved;
+#ifdef DEBUG
+	int i = 0;
+#endif
 
 	if (multiboot2_enabled == false)
 		goto out;



CVS commit: src/sys/arch/x86/x86

2019-10-17 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Fri Oct 18 00:56:25 UTC 2019

Modified Files:
src/sys/arch/x86/x86: efi.c

Log Message:
Fix EFI system table mapping in virtual space

Previous version was annoted as untested, and indeed it did not work.
New version uses the same approach as for ACPI table mapping.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/x86/x86/efi.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/x86/efi.c
diff -u src/sys/arch/x86/x86/efi.c:1.19 src/sys/arch/x86/x86/efi.c:1.20
--- src/sys/arch/x86/x86/efi.c:1.19	Mon Dec  3 19:46:43 2018
+++ src/sys/arch/x86/x86/efi.c	Fri Oct 18 00:56:25 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: efi.c,v 1.19 2018/12/03 19:46:43 cherry Exp $	*/
+/*	$NetBSD: efi.c,v 1.20 2019/10/18 00:56:25 manu Exp $	*/
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: efi.c,v 1.19 2018/12/03 19:46:43 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: efi.c,v 1.20 2019/10/18 00:56:25 manu Exp $");
 
 #include 
 #include 
@@ -37,6 +37,8 @@ __KERNEL_RCSID(0, "$NetBSD: efi.c,v 1.19
 #include 
 
 #include 
+#include 
+#include 
 #include 
 
 #include 
@@ -73,21 +75,19 @@ static vaddr_t
 efi_getva(paddr_t pa)
 {
 	vaddr_t va;
+	int rv;
 
 #ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS
 	if (mm_md_direct_mapped_phys(pa, ))
 		return va;
 #endif
 
-	/* XXX This code path is not tested. */
-	va = uvm_km_alloc(kernel_map, PAGE_SIZE, 0,
-	UVM_KMF_VAONLY | UVM_KMF_WAITVA);
-	if (va == 0) {
+	rv = _x86_memio_map(x86_bus_space_mem, pa, 
+	PAGE_SIZE, 0, (bus_space_handle_t *));   
+	if (rv != 0) {
 		aprint_debug("efi: unable to allocate va\n");
 		return 0;
 	}
-	pmap_kenter_pa(va, pa, VM_PROT_READ, 0);
-	pmap_update(pmap_kernel());
 
 	return va;
 }
@@ -107,10 +107,8 @@ efi_relva(paddr_t pa, vaddr_t va)
 	}
 #endif
 
-	/* XXX This code path is not tested. */
-	pmap_kremove(va, PAGE_SIZE);
-	pmap_update(pmap_kernel());
-	uvm_km_free(kernel_map, va, PAGE_SIZE, UVM_KMF_VAONLY);
+	(void)_x86_memio_unmap(x86_bus_space_mem, (bus_space_handle_t)va,
+	PAGE_SIZE, NULL);
 }
 
 /*



CVS commit: src/sys/arch/x86/x86

2019-10-17 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Fri Oct 18 00:56:25 UTC 2019

Modified Files:
src/sys/arch/x86/x86: efi.c

Log Message:
Fix EFI system table mapping in virtual space

Previous version was annoted as untested, and indeed it did not work.
New version uses the same approach as for ACPI table mapping.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/x86/x86/efi.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/x86/x86

2019-10-17 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu Oct 17 06:58:48 UTC 2019

Modified Files:
src/sys/arch/x86/x86: procfs_machdep.c

Log Message:
Add rdpru.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/sys/arch/x86/x86/procfs_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/x86/x86

2019-10-17 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu Oct 17 06:58:48 UTC 2019

Modified Files:
src/sys/arch/x86/x86: procfs_machdep.c

Log Message:
Add rdpru.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/sys/arch/x86/x86/procfs_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/x86/procfs_machdep.c
diff -u src/sys/arch/x86/x86/procfs_machdep.c:1.33 src/sys/arch/x86/x86/procfs_machdep.c:1.34
--- src/sys/arch/x86/x86/procfs_machdep.c:1.33	Wed Jul 24 04:58:26 2019
+++ src/sys/arch/x86/x86/procfs_machdep.c	Thu Oct 17 06:58:48 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: procfs_machdep.c,v 1.33 2019/07/24 04:58:26 msaitoh Exp $ */
+/*	$NetBSD: procfs_machdep.c,v 1.34 2019/10/17 06:58:48 msaitoh Exp $ */
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: procfs_machdep.c,v 1.33 2019/07/24 04:58:26 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: procfs_machdep.c,v 1.34 2019/10/17 06:58:48 msaitoh Exp $");
 
 #include 
 #include 
@@ -153,7 +153,7 @@ static const char * const x86_features[]
 	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
 
 	{ /* (13) AMD 0x8008 ebx */
-	"clzero", "irperf", "xsaveerptr", NULL, NULL, NULL, NULL, NULL,
+	"clzero", "irperf", "xsaveerptr", NULL, "rdpru", NULL, NULL, NULL,
 	NULL, "wbnoinvd", NULL, NULL, NULL, NULL, NULL, NULL,
 	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
 	NULL, "virt_ssbd", NULL, NULL, NULL, NULL, NULL, NULL},



CVS commit: src/sys/arch/x86/x86

2019-10-05 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat Oct  5 07:19:49 UTC 2019

Modified Files:
src/sys/arch/x86/x86: pmap.c

Log Message:
Switch to the new PTE naming:

PG_PVLIST -> PTE_PVLIST
PG_W  -> PTE_WIRED
PG_FRAME  -> PTE_FRAME

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.335 -r1.336 src/sys/arch/x86/x86/pmap.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/x86/x86

2019-10-05 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat Oct  5 07:19:49 UTC 2019

Modified Files:
src/sys/arch/x86/x86: pmap.c

Log Message:
Switch to the new PTE naming:

PG_PVLIST -> PTE_PVLIST
PG_W  -> PTE_WIRED
PG_FRAME  -> PTE_FRAME

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.335 -r1.336 src/sys/arch/x86/x86/pmap.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/x86/pmap.c
diff -u src/sys/arch/x86/x86/pmap.c:1.335 src/sys/arch/x86/x86/pmap.c:1.336
--- src/sys/arch/x86/x86/pmap.c:1.335	Wed Aug  7 06:23:48 2019
+++ src/sys/arch/x86/x86/pmap.c	Sat Oct  5 07:19:49 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.335 2019/08/07 06:23:48 maxv Exp $	*/
+/*	$NetBSD: pmap.c,v 1.336 2019/10/05 07:19:49 maxv Exp $	*/
 
 /*
  * Copyright (c) 2008, 2010, 2016, 2017 The NetBSD Foundation, Inc.
@@ -130,7 +130,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.335 2019/08/07 06:23:48 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.336 2019/10/05 07:19:49 maxv Exp $");
 
 #include "opt_user_ldt.h"
 #include "opt_lockdebug.h"
@@ -299,10 +299,10 @@ struct pmap *const kernel_pmap_ptr = 
 struct bootspace bootspace __read_mostly;
 struct slotspace slotspace __read_mostly;
 
-/* Set to PG_NX if supported. */
+/* Set to PTE_NX if supported. */
 pd_entry_t pmap_pg_nx __read_mostly = 0;
 
-/* Set to PG_G if supported. */
+/* Set to PTE_G if supported. */
 pd_entry_t pmap_pg_g __read_mostly = 0;
 
 /* Set to true if large pages are supported. */
@@ -512,10 +512,10 @@ static inline void
 pmap_stats_update_bypte(struct pmap *pmap, pt_entry_t npte, pt_entry_t opte)
 {
 	int resid_diff = ((npte & PTE_P) ? 1 : 0) - ((opte & PTE_P) ? 1 : 0);
-	int wired_diff = ((npte & PG_W) ? 1 : 0) - ((opte & PG_W) ? 1 : 0);
+	int wired_diff = ((npte & PTE_WIRED) ? 1 : 0) - ((opte & PTE_WIRED) ? 1 : 0);
 
-	KASSERT((npte & (PTE_P | PG_W)) != PG_W);
-	KASSERT((opte & (PTE_P | PG_W)) != PG_W);
+	KASSERT((npte & (PTE_P | PTE_WIRED)) != PTE_WIRED);
+	KASSERT((opte & (PTE_P | PTE_WIRED)) != PTE_WIRED);
 
 	pmap_stats_update(pmap, resid_diff, wired_diff);
 }
@@ -973,7 +973,7 @@ pmap_kremove1(vaddr_t sva, vsize_t len, 
 		}
 		KASSERTMSG((opte & PTE_PS) == 0,
 		"va %#" PRIxVADDR " is a large page", va);
-		KASSERTMSG((opte & PG_PVLIST) == 0,
+		KASSERTMSG((opte & PTE_PVLIST) == 0,
 		"va %#" PRIxVADDR " is a pv tracked page", va);
 	}
 	if (localonly) {
@@ -3507,12 +3507,12 @@ pmap_remove_pte(struct pmap *pmap, struc
 	/*
 	 * If we are not on a pv_head list - we are done.
 	 */
-	if ((opte & PG_PVLIST) == 0) {
+	if ((opte & PTE_PVLIST) == 0) {
 #ifndef DOM0OPS
 		KASSERTMSG((PHYS_TO_VM_PAGE(pmap_pte2pa(opte)) == NULL),
-		"managed page without PG_PVLIST for %#"PRIxVADDR, va);
+		"managed page without PTE_PVLIST for %#"PRIxVADDR, va);
 		KASSERTMSG((pmap_pv_tracked(pmap_pte2pa(opte)) == NULL),
-		"pv-tracked page without PG_PVLIST for %#"PRIxVADDR, va);
+		"pv-tracked page without PTE_PVLIST for %#"PRIxVADDR, va);
 #endif
 		return true;
 	}
@@ -3522,7 +3522,7 @@ pmap_remove_pte(struct pmap *pmap, struc
 		pp = VM_PAGE_TO_PP(pg);
 	} else if ((pp = pmap_pv_tracked(pmap_pte2pa(opte))) == NULL) {
 		paddr_t pa = pmap_pte2pa(opte);
-		panic("%s: PG_PVLIST with pv-untracked page"
+		panic("%s: PTE_PVLIST with pv-untracked page"
 		" va = %#"PRIxVADDR"pa = %#"PRIxPADDR" (%#"PRIxPADDR")",
 		__func__, va, pa, atop(pa));
 	}
@@ -4124,8 +4124,8 @@ pmap_unwire(struct pmap *pmap, vaddr_t v
 	opte = *ptep;
 	KASSERT(pmap_valid_entry(opte));
 
-	if (opte & PG_W) {
-		pt_entry_t npte = opte & ~PG_W;
+	if (opte & PTE_WIRED) {
+		pt_entry_t npte = opte & ~PTE_WIRED;
 
 		opte = pmap_pte_testset(ptep, npte);
 		pmap_stats_update_bypte(pmap, npte, opte);
@@ -4202,7 +4202,7 @@ pmap_enter_ma(struct pmap *pmap, vaddr_t
 	npte = ma | protection_codes[prot] | PTE_P;
 	npte |= pmap_pat_flags(flags);
 	if (wired)
-	npte |= PG_W;
+	npte |= PTE_WIRED;
 	if (va < VM_MAXUSER_ADDRESS)
 		npte |= PTE_U;
 
@@ -4224,11 +4224,11 @@ pmap_enter_ma(struct pmap *pmap, vaddr_t
 		new_pg = PHYS_TO_VM_PAGE(pa);
 	if (new_pg != NULL) {
 		/* This is a managed page */
-		npte |= PG_PVLIST;
+		npte |= PTE_PVLIST;
 		new_pp = VM_PAGE_TO_PP(new_pg);
 	} else if ((new_pp = pmap_pv_tracked(pa)) != NULL) {
 		/* This is an unmanaged pv-tracked page */
-		npte |= PG_PVLIST;
+		npte |= PTE_PVLIST;
 	} else {
 		new_pp = NULL;
 	}
@@ -4334,19 +4334,19 @@ pmap_enter_ma(struct pmap *pmap, vaddr_t
 	 * If the same page, we can skip pv_entry handling.
 	 */
 	if (((opte ^ npte) & (PTE_FRAME | PTE_P)) == 0) {
-		KASSERT(((opte ^ npte) & PG_PVLIST) == 0);
+		KASSERT(((opte ^ npte) & PTE_PVLIST) == 0);
 		goto same_pa;
 	}
 
 	/*
 	 * If old page is pv-tracked, remove pv_entry from its list.
 	 */
-	if ((~opte & (PTE_P | PG_PVLIST)) == 0) {
+	if ((~opte & (PTE_P | 

CVS commit: src/sys/arch/x86/x86

2019-09-18 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed Sep 18 15:07:08 UTC 2019

Modified Files:
src/sys/arch/x86/x86: patch.c

Log Message:
Switch to __noubsan in x86_hotpatch()


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/sys/arch/x86/x86/patch.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/x86/patch.c
diff -u src/sys/arch/x86/x86/patch.c:1.36 src/sys/arch/x86/x86/patch.c:1.37
--- src/sys/arch/x86/x86/patch.c:1.36	Tue May 28 13:20:23 2019
+++ src/sys/arch/x86/x86/patch.c	Wed Sep 18 15:07:08 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: patch.c,v 1.36 2019/05/28 13:20:23 kamil Exp $	*/
+/*	$NetBSD: patch.c,v 1.37 2019/09/18 15:07:08 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: patch.c,v 1.36 2019/05/28 13:20:23 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: patch.c,v 1.37 2019/09/18 15:07:08 kamil Exp $");
 
 #include "opt_lockdebug.h"
 #ifdef i386
@@ -133,11 +133,7 @@ patchbytes(void *addr, const uint8_t *by
 }
 
 /* The local variables have unknown alignment to UBSan */
-#if defined(__clang__)
-__attribute__((no_sanitize("undefined")))
-#else
-__attribute__((no_sanitize_undefined))
-#endif
+__noubsan
 void
 x86_hotpatch(uint32_t name, const uint8_t *bytes, size_t size)
 {



CVS commit: src/sys/arch/x86/x86

2019-09-18 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed Sep 18 15:07:08 UTC 2019

Modified Files:
src/sys/arch/x86/x86: patch.c

Log Message:
Switch to __noubsan in x86_hotpatch()


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/sys/arch/x86/x86/patch.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/x86/x86

2019-09-12 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Sep 12 06:39:47 UTC 2019

Modified Files:
src/sys/arch/x86/x86: identcpu.c

Log Message:
Fix a normally harmless race: initialize several global variables only on
cpu0, so we don't get eg cpu1 re-initializing them while cpu0 is using
them.


To generate a diff of this commit:
cvs rdiff -u -r1.94 -r1.95 src/sys/arch/x86/x86/identcpu.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/x86/x86

2019-09-12 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Sep 12 06:39:47 UTC 2019

Modified Files:
src/sys/arch/x86/x86: identcpu.c

Log Message:
Fix a normally harmless race: initialize several global variables only on
cpu0, so we don't get eg cpu1 re-initializing them while cpu0 is using
them.


To generate a diff of this commit:
cvs rdiff -u -r1.94 -r1.95 src/sys/arch/x86/x86/identcpu.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/x86/identcpu.c
diff -u src/sys/arch/x86/x86/identcpu.c:1.94 src/sys/arch/x86/x86/identcpu.c:1.95
--- src/sys/arch/x86/x86/identcpu.c:1.94	Mon Sep  9 05:36:21 2019
+++ src/sys/arch/x86/x86/identcpu.c	Thu Sep 12 06:39:47 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: identcpu.c,v 1.94 2019/09/09 05:36:21 msaitoh Exp $	*/
+/*	$NetBSD: identcpu.c,v 1.95 2019/09/12 06:39:47 maxv Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.94 2019/09/09 05:36:21 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.95 2019/09/12 06:39:47 maxv Exp $");
 
 #include "opt_xen.h"
 
@@ -837,8 +837,10 @@ cpu_probe(struct cpu_info *ci)
 	uint32_t miscbytes;
 	uint32_t brand[12];
 
-	cpu_vendor = i386_nocpuid_cpus[cputype << 1];
-	cpu_class = i386_nocpuid_cpus[(cputype << 1) + 1];
+	if (ci == _info_primary) {
+		cpu_vendor = i386_nocpuid_cpus[cputype << 1];
+		cpu_class = i386_nocpuid_cpus[(cputype << 1) + 1];
+	}
 
 	if (cpuid_level < 0) {
 		/* cpuid instruction not supported */
@@ -859,22 +861,24 @@ cpu_probe(struct cpu_info *ci)
 	ci->ci_vendor[1] = descs[3];
 	ci->ci_vendor[3] = 0;
 
-	if (memcmp(ci->ci_vendor, "GenuineIntel", 12) == 0)
-		cpu_vendor = CPUVENDOR_INTEL;
-	else if (memcmp(ci->ci_vendor,  "AuthenticAMD", 12) == 0)
-		cpu_vendor = CPUVENDOR_AMD;
-	else if (memcmp(ci->ci_vendor,  "CyrixInstead", 12) == 0)
-		cpu_vendor = CPUVENDOR_CYRIX;
-	else if (memcmp(ci->ci_vendor,  "Geode by NSC", 12) == 0)
-		cpu_vendor = CPUVENDOR_CYRIX;
-	else if (memcmp(ci->ci_vendor, "CentaurHauls", 12) == 0)
-		cpu_vendor = CPUVENDOR_IDT;
-	else if (memcmp(ci->ci_vendor, "GenuineTMx86", 12) == 0)
-		cpu_vendor = CPUVENDOR_TRANSMETA;
-	else if (memcmp(ci->ci_vendor, "Vortex86 SoC", 12) == 0)
-		cpu_vendor = CPUVENDOR_VORTEX86;
-	else
-		cpu_vendor = CPUVENDOR_UNKNOWN;
+	if (ci == _info_primary) {
+		if (memcmp(ci->ci_vendor, "GenuineIntel", 12) == 0)
+			cpu_vendor = CPUVENDOR_INTEL;
+		else if (memcmp(ci->ci_vendor, "AuthenticAMD", 12) == 0)
+			cpu_vendor = CPUVENDOR_AMD;
+		else if (memcmp(ci->ci_vendor, "CyrixInstead", 12) == 0)
+			cpu_vendor = CPUVENDOR_CYRIX;
+		else if (memcmp(ci->ci_vendor, "Geode by NSC", 12) == 0)
+			cpu_vendor = CPUVENDOR_CYRIX;
+		else if (memcmp(ci->ci_vendor, "CentaurHauls", 12) == 0)
+			cpu_vendor = CPUVENDOR_IDT;
+		else if (memcmp(ci->ci_vendor, "GenuineTMx86", 12) == 0)
+			cpu_vendor = CPUVENDOR_TRANSMETA;
+		else if (memcmp(ci->ci_vendor, "Vortex86 SoC", 12) == 0)
+			cpu_vendor = CPUVENDOR_VORTEX86;
+		else
+			cpu_vendor = CPUVENDOR_UNKNOWN;
+	}
 
 	if (cpuid_level >= 1) {
 		x86_cpuid(1, descs);
@@ -883,11 +887,13 @@ cpu_probe(struct cpu_info *ci)
 		ci->ci_feat_val[1] = descs[2];
 		ci->ci_feat_val[0] = descs[3];
 
-		/* Determine family + class. */
-		cpu_class = CPUID_TO_FAMILY(ci->ci_signature)
-		+ (CPUCLASS_386 - 3);
-		if (cpu_class > CPUCLASS_686)
-			cpu_class = CPUCLASS_686;
+		if (ci == _info_primary) {
+			/* Determine family + class. */
+			cpu_class = CPUID_TO_FAMILY(ci->ci_signature)
+			+ (CPUCLASS_386 - 3);
+			if (cpu_class > CPUCLASS_686)
+cpu_class = CPUCLASS_686;
+		}
 
 		/* CLFLUSH line size is next 8 bits */
 		if (ci->ci_feat_val[0] & CPUID_CFLUSH)



CVS commit: src/sys/arch/x86/x86

2019-08-30 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Fri Aug 30 13:29:17 UTC 2019

Modified Files:
src/sys/arch/x86/x86: spectre.c

Log Message:
 Use macro.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/arch/x86/x86/spectre.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/x86/x86

2019-08-30 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Fri Aug 30 13:29:17 UTC 2019

Modified Files:
src/sys/arch/x86/x86: spectre.c

Log Message:
 Use macro.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/arch/x86/x86/spectre.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/x86/spectre.c
diff -u src/sys/arch/x86/x86/spectre.c:1.29 src/sys/arch/x86/x86/spectre.c:1.30
--- src/sys/arch/x86/x86/spectre.c:1.29	Sat Jun  1 06:54:28 2019
+++ src/sys/arch/x86/x86/spectre.c	Fri Aug 30 13:29:17 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: spectre.c,v 1.29 2019/06/01 06:54:28 maxv Exp $	*/
+/*	$NetBSD: spectre.c,v 1.30 2019/08/30 13:29:17 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 2018-2019 NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: spectre.c,v 1.29 2019/06/01 06:54:28 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: spectre.c,v 1.30 2019/08/30 13:29:17 msaitoh Exp $");
 
 #include "opt_spectre.h"
 
@@ -435,7 +435,7 @@ v4_detect_method(void)
 break;
 			}
 	 		x86_cpuid(0x8008, descs);
-			if (descs[1] & __BIT(26)) {
+			if (descs[1] & CPUID_CAPEX_SSB_NO) {
 /* Not vulnerable to SpectreV4. */
 v4_mitigation_method = V4_MITIGATION_AMD_SSB_NO;
 return;



CVS commit: src/sys/arch/x86/x86

2019-08-30 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Fri Aug 30 07:53:47 UTC 2019

Modified Files:
src/sys/arch/x86/x86: cpu.c

Log Message:
avoid misalignment in 32 bit kernels and "mach cpu".


To generate a diff of this commit:
cvs rdiff -u -r1.171 -r1.172 src/sys/arch/x86/x86/cpu.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/x86/cpu.c
diff -u src/sys/arch/x86/x86/cpu.c:1.171 src/sys/arch/x86/x86/cpu.c:1.172
--- src/sys/arch/x86/x86/cpu.c:1.171	Wed May 29 16:54:41 2019
+++ src/sys/arch/x86/x86/cpu.c	Fri Aug 30 07:53:47 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.171 2019/05/29 16:54:41 maxv Exp $	*/
+/*	$NetBSD: cpu.c,v 1.172 2019/08/30 07:53:47 mrg Exp $	*/
 
 /*
  * Copyright (c) 2000-2012 NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.171 2019/05/29 16:54:41 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.172 2019/08/30 07:53:47 mrg Exp $");
 
 #include "opt_ddb.h"
 #include "opt_mpbios.h"		/* for MPDEBUG */
@@ -979,8 +979,14 @@ cpu_debug_dump(void)
 {
 	struct cpu_info *ci;
 	CPU_INFO_ITERATOR cii;
+	const char sixtyfour64space[] = 
+#ifdef _LP64
+			   ""
+#endif
+			   "";
 
-	db_printf("addr		dev	id	flags	ipis	curlwp 		fpcurlwp\n");
+	db_printf("addr		%sdev	id	flags	ipis	curlwp 		"
+		  "fpcurlwp\n", sixtyfour64space);
 	for (CPU_INFO_FOREACH(cii, ci)) {
 		db_printf("%p	%s	%ld	%x	%x	%10p	%10p\n",
 		ci,



CVS commit: src/sys/arch/x86/x86

2019-08-30 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Fri Aug 30 07:53:47 UTC 2019

Modified Files:
src/sys/arch/x86/x86: cpu.c

Log Message:
avoid misalignment in 32 bit kernels and "mach cpu".


To generate a diff of this commit:
cvs rdiff -u -r1.171 -r1.172 src/sys/arch/x86/x86/cpu.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/x86/x86

2019-07-23 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Wed Jul 24 04:58:26 UTC 2019

Modified Files:
src/sys/arch/x86/x86: procfs_machdep.c

Log Message:
Add avx512ifma, cqm_mbm_total, cqm_mbm_local and waitpkg


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/sys/arch/x86/x86/procfs_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/x86/procfs_machdep.c
diff -u src/sys/arch/x86/x86/procfs_machdep.c:1.32 src/sys/arch/x86/x86/procfs_machdep.c:1.33
--- src/sys/arch/x86/x86/procfs_machdep.c:1.32	Tue May 28 16:43:24 2019
+++ src/sys/arch/x86/x86/procfs_machdep.c	Wed Jul 24 04:58:26 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: procfs_machdep.c,v 1.32 2019/05/28 16:43:24 kamil Exp $ */
+/*	$NetBSD: procfs_machdep.c,v 1.33 2019/07/24 04:58:26 msaitoh Exp $ */
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: procfs_machdep.c,v 1.32 2019/05/28 16:43:24 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: procfs_machdep.c,v 1.33 2019/07/24 04:58:26 msaitoh Exp $");
 
 #include 
 #include 
@@ -129,7 +129,7 @@ static const char * const x86_features[]
 	"fsgsbase", "tsc_adjust", NULL, "bmi1", "hle", "avx2", NULL, "smep",
 	"bmi2", "erms", "invpcid", "rtm", "cqm", NULL, "mpx", "rdt_a",
 	"avx512f", "avx512dq", "rdseed", "adx",
-	"smap", NULL, NULL, "clflushopt",
+	"smap", "avx512ifma", NULL, "clflushopt",
 	"clwb", "intel_pt", "avx512pf", "avx512er",
 	"avx512cd", "sha_ni", "avx512bw", "avx512vl"},
 
@@ -146,7 +146,8 @@ static const char * const x86_features[]
 	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
 
 	{ /* (12) 0x000f:1 edx */
-	"cqm_occup_llc", NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+	"cqm_occup_llc", "cqm_mbm_total", "cqm_mbm_local", NULL,
+	NULL, NULL, NULL, NULL,
 	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
 	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
 	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
@@ -174,7 +175,7 @@ static const char * const x86_features[]
 
 	{ /* (16) 0x0007:0 ecx */
 	NULL, "avx512vbmi", "umip", "pku",
-	"ospke", NULL, "avx512_vbmi2", NULL,
+	"ospke", "waitpkg", "avx512_vbmi2", NULL,
 	"gfni", "vaes", "vpclmulqdq", "avx512_vnni",
 	"avx512_bitalg", "tme", "avx512_vpopcntdq", NULL,
 	"la57", NULL, NULL, NULL, NULL, NULL, "rdpid", NULL,



CVS commit: src/sys/arch/x86/x86

2019-07-23 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Wed Jul 24 04:58:26 UTC 2019

Modified Files:
src/sys/arch/x86/x86: procfs_machdep.c

Log Message:
Add avx512ifma, cqm_mbm_total, cqm_mbm_local and waitpkg


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/sys/arch/x86/x86/procfs_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/x86/x86

2019-06-13 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Fri Jun 14 03:35:31 UTC 2019

Modified Files:
src/sys/arch/x86/x86: bus_dma.c

Log Message:
KASSERT() -> KASSERTMSG() message in _bus_dmamem_alloc_range().


To generate a diff of this commit:
cvs rdiff -u -r1.78 -r1.79 src/sys/arch/x86/x86/bus_dma.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/x86/bus_dma.c
diff -u src/sys/arch/x86/x86/bus_dma.c:1.78 src/sys/arch/x86/x86/bus_dma.c:1.79
--- src/sys/arch/x86/x86/bus_dma.c:1.78	Sun Apr 21 06:37:21 2019
+++ src/sys/arch/x86/x86/bus_dma.c	Fri Jun 14 03:35:31 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: bus_dma.c,v 1.78 2019/04/21 06:37:21 maxv Exp $	*/
+/*	$NetBSD: bus_dma.c,v 1.79 2019/06/14 03:35:31 mrg Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2007 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.78 2019/04/21 06:37:21 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.79 2019/06/14 03:35:31 mrg Exp $");
 
 /*
  * The following is included because _bus_dma_uiomove is derived from
@@ -249,7 +249,8 @@ _bus_dmamem_alloc_range(bus_dma_tag_t t,
 			segs[curseg].ds_len += PAGE_SIZE;
 		} else {
 			curseg++;
-			KASSERT(curseg < nsegs);
+			KASSERTMSG(curseg < nsegs, "curseg %d size %llx",
+			curseg, (long long)size);
 			segs[curseg].ds_addr = curaddr;
 			segs[curseg].ds_len = PAGE_SIZE;
 		}



CVS commit: src/sys/arch/x86/x86

2019-06-13 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Fri Jun 14 03:35:31 UTC 2019

Modified Files:
src/sys/arch/x86/x86: bus_dma.c

Log Message:
KASSERT() -> KASSERTMSG() message in _bus_dmamem_alloc_range().


To generate a diff of this commit:
cvs rdiff -u -r1.78 -r1.79 src/sys/arch/x86/x86/bus_dma.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/x86/x86

2019-06-13 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu Jun 13 07:42:45 UTC 2019

Modified Files:
src/sys/arch/x86/x86: lapic.c

Log Message:
 lapic_dump(): Print CMCI and thermal local vector table, too.


To generate a diff of this commit:
cvs rdiff -u -r1.72 -r1.73 src/sys/arch/x86/x86/lapic.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/x86/lapic.c
diff -u src/sys/arch/x86/x86/lapic.c:1.72 src/sys/arch/x86/x86/lapic.c:1.73
--- src/sys/arch/x86/x86/lapic.c:1.72	Thu Jun 13 05:19:40 2019
+++ src/sys/arch/x86/x86/lapic.c	Thu Jun 13 07:42:45 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: lapic.c,v 1.72 2019/06/13 05:19:40 msaitoh Exp $	*/
+/*	$NetBSD: lapic.c,v 1.73 2019/06/13 07:42:45 msaitoh Exp $	*/
 
 /*-
  * Copyright (c) 2000, 2008 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lapic.c,v 1.72 2019/06/13 05:19:40 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lapic.c,v 1.73 2019/06/13 07:42:45 msaitoh Exp $");
 
 #include "acpica.h"
 #include "ioapic.h"
@@ -954,7 +954,9 @@ lapic_dump(void)
 	struct cpu_info *ci = curcpu();
 	const char *xname = device_xname(ci->ci_dev);
 
+	apic_format_redir(xname, "cmci", 0, 0, lapic_readreg(LAPIC_LVT_CMCI));
 	apic_format_redir(xname, "timer", 0, 0, lapic_readreg(LAPIC_LVTT));
+	apic_format_redir(xname, "thermal", 0, 0, lapic_readreg(LAPIC_TMINT));
 	apic_format_redir(xname, "pcint", 0, 0, lapic_readreg(LAPIC_PCINT));
 	apic_format_redir(xname, "lint", 0, 0, lapic_readreg(LAPIC_LVINT0));
 	apic_format_redir(xname, "lint", 1, 0, lapic_readreg(LAPIC_LVINT1));



CVS commit: src/sys/arch/x86/x86

2019-06-13 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu Jun 13 07:42:45 UTC 2019

Modified Files:
src/sys/arch/x86/x86: lapic.c

Log Message:
 lapic_dump(): Print CMCI and thermal local vector table, too.


To generate a diff of this commit:
cvs rdiff -u -r1.72 -r1.73 src/sys/arch/x86/x86/lapic.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/x86/x86

2019-06-13 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu Jun 13 07:28:17 UTC 2019

Modified Files:
src/sys/arch/x86/x86: apic.c ioapic.c

Log Message:
Whitespace fix. No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/x86/x86/apic.c
cvs rdiff -u -r1.59 -r1.60 src/sys/arch/x86/x86/ioapic.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/x86/apic.c
diff -u src/sys/arch/x86/x86/apic.c:1.8 src/sys/arch/x86/x86/apic.c:1.9
--- src/sys/arch/x86/x86/apic.c:1.8	Tue Dec 16 22:35:28 2008
+++ src/sys/arch/x86/x86/apic.c	Thu Jun 13 07:28:17 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: apic.c,v 1.8 2008/12/16 22:35:28 christos Exp $ */
+/* $NetBSD: apic.c,v 1.9 2019/06/13 07:28:17 msaitoh Exp $ */
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: apic.c,v 1.8 2008/12/16 22:35:28 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: apic.c,v 1.9 2019/06/13 07:28:17 msaitoh Exp $");
 
 #include 
 #include 
@@ -70,7 +70,6 @@ apic_format_redir(const char *where1, co
 		snprintb(buf, sizeof(buf), redirhifmt, redirhi);
 		printf(" %s", buf);
 	}
-		
 
 	printf("\n");
 }

Index: src/sys/arch/x86/x86/ioapic.c
diff -u src/sys/arch/x86/x86/ioapic.c:1.59 src/sys/arch/x86/x86/ioapic.c:1.60
--- src/sys/arch/x86/x86/ioapic.c:1.59	Mon Oct  8 08:05:08 2018
+++ src/sys/arch/x86/x86/ioapic.c	Thu Jun 13 07:28:17 2019
@@ -1,4 +1,4 @@
-/* 	$NetBSD: ioapic.c,v 1.59 2018/10/08 08:05:08 cherry Exp $	*/
+/* 	$NetBSD: ioapic.c,v 1.60 2019/06/13 07:28:17 msaitoh Exp $	*/
 
 /*-
  * Copyright (c) 2000, 2009 The NetBSD Foundation, Inc.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ioapic.c,v 1.59 2018/10/08 08:05:08 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ioapic.c,v 1.60 2019/06/13 07:28:17 msaitoh Exp $");
 
 #include "opt_ddb.h"
 
@@ -139,10 +139,10 @@ ioapic_unlock(struct ioapic_softc *sc, u
  * Register read/write routines.
  */
 static inline  uint32_t
-ioapic_read_ul(struct ioapic_softc *sc,int regid)
+ioapic_read_ul(struct ioapic_softc *sc, int regid)
 {
 	uint32_t val;
-	
+
 	*(sc->sc_reg) = regid;
 	val = *sc->sc_data;
 
@@ -150,7 +150,7 @@ ioapic_read_ul(struct ioapic_softc *sc,i
 }
 
 static inline  void
-ioapic_write_ul(struct ioapic_softc *sc,int regid, uint32_t val)
+ioapic_write_ul(struct ioapic_softc *sc, int regid, uint32_t val)
 {
 	*(sc->sc_reg) = regid;
 	*(sc->sc_data) = val;
@@ -170,7 +170,7 @@ ioapic_read(struct ioapic_softc *sc, int
 }
 
 static inline  void
-ioapic_write(struct ioapic_softc *sc,int regid, int val)
+ioapic_write(struct ioapic_softc *sc, int regid, int val)
 {
 	u_long flags;
 
@@ -233,7 +233,7 @@ ioapic_add(struct ioapic_softc *sc)
 }
 
 void
-ioapic_print_redir (struct ioapic_softc *sc, const char *why, int pin)
+ioapic_print_redir(struct ioapic_softc *sc, const char *why, int pin)
 {
 	uint32_t redirlo = ioapic_read(sc, IOAPIC_REDLO(pin));
 	uint32_t redirhi = ioapic_read(sc, IOAPIC_REDHI(pin));
@@ -255,15 +255,15 @@ ioapic_match(device_t parent, cfdata_t m
 /*
  * can't use bus_space_xxx as we don't have a bus handle ...
  */
-void 
+void
 ioapic_attach(device_t parent, device_t self, void *aux)
 {
-	struct ioapic_softc *sc = device_private(self);  
+	struct ioapic_softc *sc = device_private(self);
 	struct apic_attach_args *aaa = (struct apic_attach_args *)aux;
 	int apic_id;
 	uint32_t ver_sz;
 	int i;
-	
+
 	sc->sc_dev = self;
 	sc->sc_flags = aaa->flags;
 	sc->sc_pic.pic_apicid = aaa->apic_id;
@@ -287,7 +287,7 @@ ioapic_attach(device_t parent, device_t 
 		return;
 	}
 	sc->sc_reg = (volatile uint32_t *)(bh + IOAPIC_REG);
-	sc->sc_data = (volatile uint32_t *)(bh + IOAPIC_DATA);	
+	sc->sc_data = (volatile uint32_t *)(bh + IOAPIC_DATA);
 	}
 #endif
 	sc->sc_pa = aaa->apic_address;
@@ -332,7 +332,7 @@ ioapic_attach(device_t parent, device_t 
 		printf(", %s mode",
 		aaa->flags & IOAPIC_PICMODE ? "PIC" : "virtual wire");
 	}
-	
+
 	aprint_verbose(", version 0x%x, %d pins", sc->sc_apic_vers,
 	sc->sc_apic_sz);
 	aprint_normal("\n");
@@ -340,7 +340,7 @@ ioapic_attach(device_t parent, device_t 
 	sc->sc_pins = malloc(sizeof(struct ioapic_pin) * sc->sc_apic_sz,
 	M_DEVBUF, M_WAITOK);
 
-	for (i=0; isc_apic_sz; i++) {
+	for (i = 0; i < sc->sc_apic_sz; i++) {
 		uint32_t redlo, redhi;
 
 		sc->sc_pins[i].ip_next = NULL;
@@ -356,14 +356,14 @@ ioapic_attach(device_t parent, device_t 
 		 *
 		 * Expect all other interrupts to be PCI-like
 		 * level triggered on low.
-		 */  
+		 */
 		if (i >= 16)
 			redlo |= IOAPIC_REDLO_LEVEL | IOAPIC_REDLO_ACTLO;
 		redhi = (cpu_info_primary.ci_cpuid << IOAPIC_REDHI_DEST_SHIFT);
 		ioapic_write(sc, IOAPIC_REDHI(i), redhi);
 		ioapic_write(sc, IOAPIC_REDLO(i), redlo);
 	}
-	
+
 	/*
 	 * In case the APIC is not initialized to the correct ID
 	 * do it now.
@@ -377,10 +377,10 @@ ioapic_attach(device_t parent, device_t 

CVS commit: src/sys/arch/x86/x86

2019-06-13 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu Jun 13 07:28:17 UTC 2019

Modified Files:
src/sys/arch/x86/x86: apic.c ioapic.c

Log Message:
Whitespace fix. No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/x86/x86/apic.c
cvs rdiff -u -r1.59 -r1.60 src/sys/arch/x86/x86/ioapic.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/x86/x86

2019-06-12 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu Jun 13 05:19:40 UTC 2019

Modified Files:
src/sys/arch/x86/x86: lapic.c

Log Message:
No functional change:
- Simplify some code for readability.
- KNF a little.


To generate a diff of this commit:
cvs rdiff -u -r1.71 -r1.72 src/sys/arch/x86/x86/lapic.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/x86/x86

2019-06-12 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu Jun 13 05:19:40 UTC 2019

Modified Files:
src/sys/arch/x86/x86: lapic.c

Log Message:
No functional change:
- Simplify some code for readability.
- KNF a little.


To generate a diff of this commit:
cvs rdiff -u -r1.71 -r1.72 src/sys/arch/x86/x86/lapic.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/x86/lapic.c
diff -u src/sys/arch/x86/x86/lapic.c:1.71 src/sys/arch/x86/x86/lapic.c:1.72
--- src/sys/arch/x86/x86/lapic.c:1.71	Sat Mar  9 08:42:26 2019
+++ src/sys/arch/x86/x86/lapic.c	Thu Jun 13 05:19:40 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: lapic.c,v 1.71 2019/03/09 08:42:26 maxv Exp $	*/
+/*	$NetBSD: lapic.c,v 1.72 2019/06/13 05:19:40 msaitoh Exp $	*/
 
 /*-
  * Copyright (c) 2000, 2008 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lapic.c,v 1.71 2019/03/09 08:42:26 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lapic.c,v 1.72 2019/06/13 05:19:40 msaitoh Exp $");
 
 #include "acpica.h"
 #include "ioapic.h"
@@ -282,7 +282,8 @@ lapic_setup_bsp(paddr_t lapic_base)
 			vmt_hvcall(VM_CMD_GET_VCPU_INFO, regs);
 			if (ISSET(regs[0], VCPUINFO_VCPU_RESERVED) ||
 			!ISSET(regs[0], VCPUINFO_LEGACY_X2APIC))
-reason = "inside VMWare without intr redirection";
+reason = "inside VMWare without intr "
+"redirection";
 		} else if (vm_guest == VM_GUEST_XEN) {
 			reason = "due to running under XEN";
 		} else if (vm_guest == VM_GUEST_NO &&
@@ -295,14 +296,14 @@ lapic_setup_bsp(paddr_t lapic_base)
  * SandyBridge-based notebook BIOSes have a bug
  * which prevents booting AP in x2APIC mode.
  * Since the only way to detect mobile CPU is
- * to check northbridge pci id, which cannot be done
- * that early, disable x2APIC for all Lenovo and ASUS
- * SandyBridge machines.
+ * to check northbridge pci id, which cannot be
+ * done that early, disable x2APIC for all
+ * Lenovo and ASUS SandyBridge machines.
  */
 if (strcmp(hw_vendor, "LENOVO") == 0 ||
 strcmp(hw_vendor, "ASUSTeK Computer Inc.") == 0) {
-	reason =
-	"for a suspected SandyBridge BIOS bug";
+	reason = "for a suspected SandyBridge "
+	"BIOS bug";
 }
 			}
 		}
@@ -315,7 +316,8 @@ lapic_setup_bsp(paddr_t lapic_base)
 		if (reason == NULL)
 			x2apic_mode = true;
 		else
-			aprint_verbose("x2APIC available but disabled %s\n", reason);
+			aprint_verbose("x2APIC available but disabled %s\n",
+			reason);
 		if (x2apic_enable != x2apic_mode) {
 			if (bios_x2apic && !x2apic_enable)
 aprint_verbose("x2APIC disabled by user and "
@@ -335,17 +337,20 @@ lapic_setup_bsp(paddr_t lapic_base)
 #endif
 #if defined(DDB) && defined(MULTIPROCESSOR)
 #ifdef __x86_64__
-		set_idtgate([ddb_vec], _x2apic_ddbipi, 1, SDT_SYS386IGT,
-		SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
+		set_idtgate([ddb_vec], _x2apic_ddbipi, 1,
+		SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
 #else
-		/* Set DDB IPI handler in cpu_set_tss_gates() when cpu0 is attached. */
+		/*
+		 * Set DDB IPI handler in cpu_set_tss_gates() when cpu0 is
+		 * attached.
+		 */
 #endif
 #endif
 
 		x86_disable_intr();
 		lapic_enable_x2apic();
 #ifdef MULTIPROCESSOR
-		cpu_init_first();	/* catch up to changed cpu_number() */
+		cpu_init_first();	/* Catch up to changed cpu_number() */
 #endif
 		lapic_write_tpri(0);
 		x86_enable_intr();
@@ -391,7 +396,7 @@ lapic_map(paddr_t lapic_base)
 	invlpg(va);
 
 #ifdef MULTIPROCESSOR
-	cpu_init_first();	/* catch up to changed cpu_number() */
+	cpu_init_first();	/* Catch up to changed cpu_number() */
 #endif
 
 	lapic_write_tpri(0);
@@ -474,16 +479,19 @@ lapic_boot_init(paddr_t lapic_base)
 
 #ifdef MULTIPROCESSOR
 	idt_vec_reserve(LAPIC_IPI_VECTOR);
-	idt_vec_set(LAPIC_IPI_VECTOR, x2apic_mode ? Xintr_x2apic_ipi : Xintr_lapic_ipi);
+	idt_vec_set(LAPIC_IPI_VECTOR,
+	x2apic_mode ? Xintr_x2apic_ipi : Xintr_lapic_ipi);
+
 	idt_vec_reserve(LAPIC_TLB_VECTOR);
-	idt_vec_set(LAPIC_TLB_VECTOR, x2apic_mode ? Xintr_x2apic_tlb : Xintr_lapic_tlb);
+	idt_vec_set(LAPIC_TLB_VECTOR,
+	x2apic_mode ? Xintr_x2apic_tlb : Xintr_lapic_tlb);
 #endif
 	idt_vec_reserve(LAPIC_SPURIOUS_VECTOR);
 	idt_vec_set(LAPIC_SPURIOUS_VECTOR, Xintrspurious);
 
 	idt_vec_reserve(LAPIC_TIMER_VECTOR);
-	idt_vec_set(LAPIC_TIMER_VECTOR, x2apic_mode ? Xintr_x2apic_ltimer :
-	Xintr_lapic_ltimer);
+	idt_vec_set(LAPIC_TIMER_VECTOR,
+	x2apic_mode ? Xintr_x2apic_ltimer : Xintr_lapic_ltimer);
 }
 
 static uint32_t
@@ -864,7 +872,8 @@ static int
 x2apic_ipi_startup(int target, int vec)
 {
 
-	x2apic_write_icr(target, vec | LAPIC_DLMODE_STARTUP | LAPIC_LEVEL_ASSERT);
+	x2apic_write_icr(target,
+	vec | LAPIC_DLMODE_STARTUP | LAPIC_LEVEL_ASSERT);
 
 	return 0;
 }
@@ -943,15 +952,11 @@ void
 lapic_dump(void)
 {
 	struct cpu_info *ci = curcpu();
+	const char *xname = device_xname(ci->ci_dev);
 
-	

CVS commit: src/sys/arch/x86/x86

2019-06-04 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Jun  5 04:31:37 UTC 2019

Modified Files:
src/sys/arch/x86/x86: intr.c

Log Message:
Add TODO comments to support MSI multiple vectors on x86 systems.


To generate a diff of this commit:
cvs rdiff -u -r1.144 -r1.145 src/sys/arch/x86/x86/intr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/x86/intr.c
diff -u src/sys/arch/x86/x86/intr.c:1.144 src/sys/arch/x86/x86/intr.c:1.145
--- src/sys/arch/x86/x86/intr.c:1.144	Fri Feb 15 08:54:01 2019
+++ src/sys/arch/x86/x86/intr.c	Wed Jun  5 04:31:37 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.c,v 1.144 2019/02/15 08:54:01 nonaka Exp $	*/
+/*	$NetBSD: intr.c,v 1.145 2019/06/05 04:31:37 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -133,7 +133,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.144 2019/02/15 08:54:01 nonaka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.145 2019/06/05 04:31:37 knakahara Exp $");
 
 #include "opt_intrdebug.h"
 #include "opt_multiprocessor.h"
@@ -661,6 +661,19 @@ intr_allocate_slot(struct pic *pic, int 
 	if (pic == _pic) {
 		idtvec = ICU_OFFSET + pin;
 	} else {
+		/*
+		 * TODO to support MSI (not MSI-X) multiple vectors
+		 *
+		 * PCI Local Bus Specification Revision 3.0 says the devices
+		 * which use MSI multiple vectors increment the low order bits
+		 * of MSI message data.
+		 * On the other hand, Intel SDM "10.11.2 Message Data Register
+		 * Format" says the 7:0 bits of MSI message data mean Interrupt
+		 * Descriptor Table(IDT) vector.
+		 * As the result of these two documents, the IDT vectors which
+		 * are used by a device using MSI multiple vectors must be
+		 * continuous.
+		 */
 		idtvec = idt_vec_alloc(APIC_LEVEL(level), IDT_INTR_HIGH);
 	}
 	if (idtvec == 0) {



CVS commit: src/sys/arch/x86/x86

2019-06-04 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Jun  5 04:31:37 UTC 2019

Modified Files:
src/sys/arch/x86/x86: intr.c

Log Message:
Add TODO comments to support MSI multiple vectors on x86 systems.


To generate a diff of this commit:
cvs rdiff -u -r1.144 -r1.145 src/sys/arch/x86/x86/intr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/x86/x86

2019-06-03 Thread NONAKA Kimihiro
Module Name:src
Committed By:   nonaka
Date:   Mon Jun  3 09:51:04 UTC 2019

Modified Files:
src/sys/arch/x86/x86: hyperv.c

Log Message:
Use efi_probe().


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/x86/x86/hyperv.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/x86/hyperv.c
diff -u src/sys/arch/x86/x86/hyperv.c:1.3 src/sys/arch/x86/x86/hyperv.c:1.4
--- src/sys/arch/x86/x86/hyperv.c:1.3	Thu May 30 11:15:29 2019
+++ src/sys/arch/x86/x86/hyperv.c	Mon Jun  3 09:51:04 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: hyperv.c,v 1.3 2019/05/30 11:15:29 nonaka Exp $	*/
+/*	$NetBSD: hyperv.c,v 1.4 2019/06/03 09:51:04 nonaka Exp $	*/
 
 /*-
  * Copyright (c) 2009-2012,2016-2017 Microsoft Corp.
@@ -33,7 +33,7 @@
  */
 #include 
 #ifdef __KERNEL_RCSID
-__KERNEL_RCSID(0, "$NetBSD: hyperv.c,v 1.3 2019/05/30 11:15:29 nonaka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hyperv.c,v 1.4 2019/06/03 09:51:04 nonaka Exp $");
 #endif
 #ifdef __FBSDID
 __FBSDID("$FreeBSD: head/sys/dev/hyperv/vmbus/hyperv.c 331757 2018-03-30 02:25:12Z emaste $");
@@ -753,7 +753,7 @@ int
 hyperv_is_gen1(void)
 {
 
-	return !bootmethod_efi;
+	return !efi_probe();
 }
 
 void



CVS commit: src/sys/arch/x86/x86

2019-06-03 Thread NONAKA Kimihiro
Module Name:src
Committed By:   nonaka
Date:   Mon Jun  3 09:51:04 UTC 2019

Modified Files:
src/sys/arch/x86/x86: hyperv.c

Log Message:
Use efi_probe().


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/x86/x86/hyperv.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/x86/x86

2019-06-01 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat Jun  1 08:12:26 UTC 2019

Modified Files:
src/sys/arch/x86/x86: pmap.c

Log Message:
Fix two bugs in pmap_write_protect():

 * The mask should be ~PAGE_MASK, not PTE_FRAME. PTE_FRAME eliminates the
   higher bits, and that's not wanted.
 * The computation of tva is incorrect: if the VA is in kernel space we
   must take the canonical hole into account, and here we were not.

We've had these bugs basically forever. It meant that uvm_km_protect()
would never flush the correct VA, and a stale TLB entry would persist.

Fixes PR/54257. Since I added PCID support we execute invpcid in invlpg(),
and invpcid triggers a #GP if the address is non canonical, contrary to
invlpg. The wrong computation of the VA during a modload happened to hit
the canonical hole.


To generate a diff of this commit:
cvs rdiff -u -r1.333 -r1.334 src/sys/arch/x86/x86/pmap.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/x86/pmap.c
diff -u src/sys/arch/x86/x86/pmap.c:1.333 src/sys/arch/x86/x86/pmap.c:1.334
--- src/sys/arch/x86/x86/pmap.c:1.333	Mon May 27 18:36:37 2019
+++ src/sys/arch/x86/x86/pmap.c	Sat Jun  1 08:12:26 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.333 2019/05/27 18:36:37 maxv Exp $	*/
+/*	$NetBSD: pmap.c,v 1.334 2019/06/01 08:12:26 maxv Exp $	*/
 
 /*
  * Copyright (c) 2008, 2010, 2016, 2017 The NetBSD Foundation, Inc.
@@ -130,7 +130,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.333 2019/05/27 18:36:37 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.334 2019/06/01 08:12:26 maxv Exp $");
 
 #include "opt_user_ldt.h"
 #include "opt_lockdebug.h"
@@ -4017,7 +4017,7 @@ pmap_write_protect(struct pmap *pmap, va
 	pt_entry_t * const *pdes;
 	struct pmap *pmap2;
 	vaddr_t blockend, va;
-	int lvl;
+	int lvl, i;
 
 	KASSERT(curlwp->l_md.md_gc_pmap != pmap);
 
@@ -4034,8 +4034,8 @@ pmap_write_protect(struct pmap *pmap, va
 	if (!(prot & VM_PROT_EXECUTE))
 		bit_put = pmap_pg_nx;
 
-	sva &= PTE_FRAME;
-	eva &= PTE_FRAME;
+	sva &= ~PAGE_MASK;
+	eva &= ~PAGE_MASK;
 
 	/* Acquire pmap. */
 	kpreempt_disable();
@@ -4058,7 +4058,7 @@ pmap_write_protect(struct pmap *pmap, va
 		spte = [pl1_i(va)];
 		epte = [pl1_i(blockend)];
 
-		for (/* */; spte < epte; spte++) {
+		for (i = 0; spte < epte; spte++, i++) {
 			pt_entry_t opte, npte;
 
 			do {
@@ -4070,7 +4070,7 @@ pmap_write_protect(struct pmap *pmap, va
 			} while (pmap_pte_cas(spte, opte, npte) != opte);
 
 			if ((opte & PTE_D) != 0) {
-vaddr_t tva = x86_ptob(spte - ptes);
+vaddr_t tva = va + x86_ptob(i);
 pmap_tlb_shootdown(pmap, tva, opte,
 TLBSHOOT_WRITE_PROTECT);
 			}



CVS commit: src/sys/arch/x86/x86

2019-06-01 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat Jun  1 06:54:28 UTC 2019

Modified Files:
src/sys/arch/x86/x86: spectre.c

Log Message:
Mmh, check the highest leaf before calling x86_cpuid(), otherwise on old
CPUs we might be getting garbage. While here fix a typo.

Likely fixes PR/54256.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/arch/x86/x86/spectre.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/x86/x86

2019-06-01 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat Jun  1 06:54:28 UTC 2019

Modified Files:
src/sys/arch/x86/x86: spectre.c

Log Message:
Mmh, check the highest leaf before calling x86_cpuid(), otherwise on old
CPUs we might be getting garbage. While here fix a typo.

Likely fixes PR/54256.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/arch/x86/x86/spectre.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/x86/spectre.c
diff -u src/sys/arch/x86/x86/spectre.c:1.28 src/sys/arch/x86/x86/spectre.c:1.29
--- src/sys/arch/x86/x86/spectre.c:1.28	Sat May 18 08:54:38 2019
+++ src/sys/arch/x86/x86/spectre.c	Sat Jun  1 06:54:28 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: spectre.c,v 1.28 2019/05/18 08:54:38 maxv Exp $	*/
+/*	$NetBSD: spectre.c,v 1.29 2019/06/01 06:54:28 maxv Exp $	*/
 
 /*
  * Copyright (c) 2018-2019 NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: spectre.c,v 1.28 2019/05/18 08:54:38 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: spectre.c,v 1.29 2019/06/01 06:54:28 maxv Exp $");
 
 #include "opt_spectre.h"
 
@@ -673,6 +673,10 @@ mds_detect_method(void)
 		return;
 	}
 
+	if (cpuid_level < 7) {
+		return;
+	}
+
 	x86_cpuid(0x7, descs);
 	if (descs[3] & CPUID_SEF_ARCH_CAP) {
 		msr = rdmsr(MSR_IA32_ARCH_CAPABILITIES);
@@ -850,7 +854,7 @@ cpu_speculation_init(struct cpu_info *ci
 #endif
 
 	/*
-	 * Microarchectural Data Sampling.
+	 * Microarchitectural Data Sampling.
 	 *
 	 * cpu0 is the one that detects the method and sets the global
 	 * variable.



CVS commit: src/sys/arch/x86/x86

2019-05-30 Thread NONAKA Kimihiro
Module Name:src
Committed By:   nonaka
Date:   Fri May 31 03:10:31 UTC 2019

Modified Files:
src/sys/arch/x86/x86: consinit.c

Log Message:
Back out r1.30 change.

> tuck in include inside ifdef, from Ryosuke Moro

It was caused by the reporter's local change.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/x86/x86/consinit.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/x86/x86

2019-05-30 Thread NONAKA Kimihiro
Module Name:src
Committed By:   nonaka
Date:   Fri May 31 03:10:31 UTC 2019

Modified Files:
src/sys/arch/x86/x86: consinit.c

Log Message:
Back out r1.30 change.

> tuck in include inside ifdef, from Ryosuke Moro

It was caused by the reporter's local change.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/x86/x86/consinit.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/x86/consinit.c
diff -u src/sys/arch/x86/x86/consinit.c:1.30 src/sys/arch/x86/x86/consinit.c:1.31
--- src/sys/arch/x86/x86/consinit.c:1.30	Sun May 26 00:30:35 2019
+++ src/sys/arch/x86/x86/consinit.c	Fri May 31 03:10:31 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: consinit.c,v 1.30 2019/05/26 00:30:35 christos Exp $	*/
+/*	$NetBSD: consinit.c,v 1.31 2019/05/31 03:10:31 nonaka Exp $	*/
 
 /*
  * Copyright (c) 1998
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: consinit.c,v 1.30 2019/05/26 00:30:35 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: consinit.c,v 1.31 2019/05/31 03:10:31 nonaka Exp $");
 
 #include "opt_kgdb.h"
 #include "opt_puc.h"
@@ -92,8 +92,8 @@ __KERNEL_RCSID(0, "$NetBSD: consinit.c,v
 #endif
 
 #ifndef XEN
-#if NHVKBD > 0
 #include "hvkbd.h"
+#if NHVKBD > 0
 #include 
 #endif
 #endif



CVS commit: src/sys/arch/x86/x86

2019-05-30 Thread NONAKA Kimihiro
Module Name:src
Committed By:   nonaka
Date:   Thu May 30 11:15:29 UTC 2019

Modified Files:
src/sys/arch/x86/x86: hyperv.c

Log Message:
Avoid undefined reference to `hyperv_guid_video' without vmbus(4).


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/x86/x86/hyperv.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/x86/x86

2019-05-30 Thread NONAKA Kimihiro
Module Name:src
Committed By:   nonaka
Date:   Thu May 30 11:15:29 UTC 2019

Modified Files:
src/sys/arch/x86/x86: hyperv.c

Log Message:
Avoid undefined reference to `hyperv_guid_video' without vmbus(4).


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/x86/x86/hyperv.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/x86/hyperv.c
diff -u src/sys/arch/x86/x86/hyperv.c:1.2 src/sys/arch/x86/x86/hyperv.c:1.3
--- src/sys/arch/x86/x86/hyperv.c:1.2	Fri May 24 14:28:48 2019
+++ src/sys/arch/x86/x86/hyperv.c	Thu May 30 11:15:29 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: hyperv.c,v 1.2 2019/05/24 14:28:48 nonaka Exp $	*/
+/*	$NetBSD: hyperv.c,v 1.3 2019/05/30 11:15:29 nonaka Exp $	*/
 
 /*-
  * Copyright (c) 2009-2012,2016-2017 Microsoft Corp.
@@ -33,7 +33,7 @@
  */
 #include 
 #ifdef __KERNEL_RCSID
-__KERNEL_RCSID(0, "$NetBSD: hyperv.c,v 1.2 2019/05/24 14:28:48 nonaka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hyperv.c,v 1.3 2019/05/30 11:15:29 nonaka Exp $");
 #endif
 #ifdef __FBSDID
 __FBSDID("$FreeBSD: head/sys/dev/hyperv/vmbus/hyperv.c 331757 2018-03-30 02:25:12Z emaste $");
@@ -43,6 +43,7 @@ __FBSDID("$FreeBSD: head/sys/dev/hyperv/
 #include "lapic.h"
 #include "genfb.h"
 #include "opt_ddb.h"
+#include "vmbus.h"
 #include "wsdisplay.h"
 #endif
 
@@ -988,6 +989,7 @@ hyperv_modcmd(modcmd_t cmd, void *aux)
 	return rv;
 }
 
+#if NVMBUS > 0
 /*
  * genfb at vmbus
  */
@@ -1086,10 +1088,12 @@ populate_fbinfo(device_t dev, prop_dicti
 	}
 #endif
 }
+#endif
 
 device_t
 device_hyperv_register(device_t dev, void *aux)
 {
+#if NVMBUS > 0
 	device_t parent = device_parent(dev);
 
 	if (parent && device_is_a(parent, "vmbus") && !x86_found_console) {
@@ -1128,5 +1132,6 @@ device_hyperv_register(device_t dev, voi
 			return NULL;
 		}
 	}
+#endif
 	return NULL;
 }



CVS commit: src/sys/arch/x86/x86

2019-05-28 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Tue May 28 16:43:24 UTC 2019

Modified Files:
src/sys/arch/x86/x86: procfs_machdep.c

Log Message:
Avoid the 1<<31 construct

Shift unsigned int rather than signed one.

Detected with kUBSan when reading /proc/cpuinfo.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sys/arch/x86/x86/procfs_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/x86/procfs_machdep.c
diff -u src/sys/arch/x86/x86/procfs_machdep.c:1.31 src/sys/arch/x86/x86/procfs_machdep.c:1.32
--- src/sys/arch/x86/x86/procfs_machdep.c:1.31	Thu May 16 04:26:13 2019
+++ src/sys/arch/x86/x86/procfs_machdep.c	Tue May 28 16:43:24 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: procfs_machdep.c,v 1.31 2019/05/16 04:26:13 msaitoh Exp $ */
+/*	$NetBSD: procfs_machdep.c,v 1.32 2019/05/28 16:43:24 kamil Exp $ */
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: procfs_machdep.c,v 1.31 2019/05/16 04:26:13 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: procfs_machdep.c,v 1.32 2019/05/28 16:43:24 kamil Exp $");
 
 #include 
 #include 
@@ -235,7 +235,7 @@ procfs_getonefeatreg(uint32_t reg, const
 	size_t l;
 
 	for (size_t i = 0; i < 32; i++) {
-		if ((reg & (1 << i)) && table[i]) {
+		if ((reg & (1U << i)) && table[i]) {
 			l = snprintf(p, *left, "%s ", table[i]);
 			if (l < *left) {
 *left -= l;



CVS commit: src/sys/arch/x86/x86

2019-05-28 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Tue May 28 16:43:24 UTC 2019

Modified Files:
src/sys/arch/x86/x86: procfs_machdep.c

Log Message:
Avoid the 1<<31 construct

Shift unsigned int rather than signed one.

Detected with kUBSan when reading /proc/cpuinfo.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sys/arch/x86/x86/procfs_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/x86/x86

2019-05-28 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Tue May 28 13:20:23 UTC 2019

Modified Files:
src/sys/arch/x86/x86: patch.c

Log Message:
Disable sanitizer instrumentation in x86_hotpatch()

Local variables have empty (0-sized), unknown alignment to UBSan.
This is hard to workaround without mutating the code too much.


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/sys/arch/x86/x86/patch.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/x86/x86

2019-05-28 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Tue May 28 13:20:23 UTC 2019

Modified Files:
src/sys/arch/x86/x86: patch.c

Log Message:
Disable sanitizer instrumentation in x86_hotpatch()

Local variables have empty (0-sized), unknown alignment to UBSan.
This is hard to workaround without mutating the code too much.


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/sys/arch/x86/x86/patch.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/x86/patch.c
diff -u src/sys/arch/x86/x86/patch.c:1.35 src/sys/arch/x86/x86/patch.c:1.36
--- src/sys/arch/x86/x86/patch.c:1.35	Sat Jul 14 14:34:32 2018
+++ src/sys/arch/x86/x86/patch.c	Tue May 28 13:20:23 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: patch.c,v 1.35 2018/07/14 14:34:32 maxv Exp $	*/
+/*	$NetBSD: patch.c,v 1.36 2019/05/28 13:20:23 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: patch.c,v 1.35 2018/07/14 14:34:32 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: patch.c,v 1.36 2019/05/28 13:20:23 kamil Exp $");
 
 #include "opt_lockdebug.h"
 #ifdef i386
@@ -132,6 +132,12 @@ patchbytes(void *addr, const uint8_t *by
 	}
 }
 
+/* The local variables have unknown alignment to UBSan */
+#if defined(__clang__)
+__attribute__((no_sanitize("undefined")))
+#else
+__attribute__((no_sanitize_undefined))
+#endif
 void
 x86_hotpatch(uint32_t name, const uint8_t *bytes, size_t size)
 {



CVS commit: src/sys/arch/x86/x86

2019-05-27 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Mon May 27 18:36:37 UTC 2019

Modified Files:
src/sys/arch/x86/x86: cpu.c pmap.c svs.c

Log Message:
Change the effect of SVS on the TLB. Keep CR4_PGE set when SVS is enabled,
but don't use PTE_G on the kernel PTEs in general.

Add PTE_G on only a few pages, that are already leaked to userland and do
not contain secrets.

This slightly improves syscall performance.


To generate a diff of this commit:
cvs rdiff -u -r1.169 -r1.170 src/sys/arch/x86/x86/cpu.c
cvs rdiff -u -r1.332 -r1.333 src/sys/arch/x86/x86/pmap.c
cvs rdiff -u -r1.27 -r1.28 src/sys/arch/x86/x86/svs.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/x86/cpu.c
diff -u src/sys/arch/x86/x86/cpu.c:1.169 src/sys/arch/x86/x86/cpu.c:1.170
--- src/sys/arch/x86/x86/cpu.c:1.169	Mon May 27 17:32:36 2019
+++ src/sys/arch/x86/x86/cpu.c	Mon May 27 18:36:37 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.169 2019/05/27 17:32:36 maxv Exp $	*/
+/*	$NetBSD: cpu.c,v 1.170 2019/05/27 18:36:37 maxv Exp $	*/
 
 /*
  * Copyright (c) 2000-2012 NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.169 2019/05/27 17:32:36 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.170 2019/05/27 18:36:37 maxv Exp $");
 
 #include "opt_ddb.h"
 #include "opt_mpbios.h"		/* for MPDEBUG */
@@ -586,9 +586,6 @@ cpu_init(struct cpu_info *ci)
 
 	/* If global TLB caching is supported, enable it */
 	if (cpu_feature[0] & CPUID_PGE)
-#ifdef SVS
-		if (!svs_enabled)
-#endif
 		cr4 |= CR4_PGE;
 
 	/*

Index: src/sys/arch/x86/x86/pmap.c
diff -u src/sys/arch/x86/x86/pmap.c:1.332 src/sys/arch/x86/x86/pmap.c:1.333
--- src/sys/arch/x86/x86/pmap.c:1.332	Mon May 27 17:32:36 2019
+++ src/sys/arch/x86/x86/pmap.c	Mon May 27 18:36:37 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.332 2019/05/27 17:32:36 maxv Exp $	*/
+/*	$NetBSD: pmap.c,v 1.333 2019/05/27 18:36:37 maxv Exp $	*/
 
 /*
  * Copyright (c) 2008, 2010, 2016, 2017 The NetBSD Foundation, Inc.
@@ -130,7 +130,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.332 2019/05/27 17:32:36 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.333 2019/05/27 18:36:37 maxv Exp $");
 
 #include "opt_user_ldt.h"
 #include "opt_lockdebug.h"
@@ -1117,12 +1117,17 @@ pmap_bootstrap(vaddr_t kva_start)
 #if !defined(XENPV)
 	/*
 	 * Begin to enable global TLB entries if they are supported: add PTE_G
-	 * attribute to already mapped kernel pages.
+	 * attribute to already mapped kernel pages. Do that only if SVS is
+	 * disabled.
 	 *
 	 * The G bit has no effect until the CR4_PGE bit is set in CR4, which
 	 * happens later in cpu_init().
 	 */
+#ifdef SVS
+	if (!svs_enabled && (cpu_feature[0] & CPUID_PGE)) {
+#else
 	if (cpu_feature[0] & CPUID_PGE) {
+#endif
 		pmap_pg_g = PTE_G;
 		pmap_remap_global();
 	}

Index: src/sys/arch/x86/x86/svs.c
diff -u src/sys/arch/x86/x86/svs.c:1.27 src/sys/arch/x86/x86/svs.c:1.28
--- src/sys/arch/x86/x86/svs.c:1.27	Mon May 27 17:32:36 2019
+++ src/sys/arch/x86/x86/svs.c	Mon May 27 18:36:37 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: svs.c,v 1.27 2019/05/27 17:32:36 maxv Exp $	*/
+/*	$NetBSD: svs.c,v 1.28 2019/05/27 18:36:37 maxv Exp $	*/
 
 /*
  * Copyright (c) 2018-2019 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: svs.c,v 1.27 2019/05/27 17:32:36 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: svs.c,v 1.28 2019/05/27 18:36:37 maxv Exp $");
 
 #include "opt_svs.h"
 
@@ -268,7 +268,7 @@ svs_tree_add(struct cpu_info *ci, vaddr_
 }
 
 static void
-svs_page_add(struct cpu_info *ci, vaddr_t va)
+svs_page_add(struct cpu_info *ci, vaddr_t va, bool global)
 {
 	pd_entry_t *srcpde, *dstpde, pde;
 	size_t idx, pidx;
@@ -289,9 +289,10 @@ svs_page_add(struct cpu_info *ci, vaddr_
 		panic("%s: L2 page not mapped", __func__);
 	}
 	if (srcpde[idx] & PTE_PS) {
+		KASSERT(!global);
 		pa = srcpde[idx] & PTE_2MFRAME;
 		pa += (paddr_t)(va % NBPD_L2);
-		pde = (srcpde[idx] & ~(PTE_G|PTE_PS|PTE_2MFRAME)) | pa;
+		pde = (srcpde[idx] & ~(PTE_PS|PTE_2MFRAME)) | pa;
 
 		if (pmap_valid_entry(dstpde[pidx])) {
 			panic("%s: L1 page already mapped", __func__);
@@ -311,7 +312,17 @@ svs_page_add(struct cpu_info *ci, vaddr_
 	if (pmap_valid_entry(dstpde[pidx])) {
 		panic("%s: L1 page already mapped", __func__);
 	}
-	dstpde[pidx] = srcpde[idx] & ~(PTE_G);
+	dstpde[pidx] = srcpde[idx];
+
+	/*
+	 * If we want a global translation, mark both the src and dst with
+	 * PTE_G.
+	 */
+	if (global) {
+		srcpde[idx] |= PTE_G;
+		dstpde[pidx] |= PTE_G;
+		tlbflushg();
+	}
 }
 
 static void
@@ -394,14 +405,14 @@ svs_utls_init(struct cpu_info *ci)
 }
 
 static void
-svs_range_add(struct cpu_info *ci, vaddr_t va, size_t size)
+svs_range_add(struct cpu_info *ci, vaddr_t va, size_t size, bool global)
 {
 	size_t i, n;
 
 	KASSERT(size % PAGE_SIZE == 0);
 	n = size / PAGE_SIZE;
 	for (i = 0; i < n; i++) {
-		

CVS commit: src/sys/arch/x86/x86

2019-05-27 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Mon May 27 18:36:37 UTC 2019

Modified Files:
src/sys/arch/x86/x86: cpu.c pmap.c svs.c

Log Message:
Change the effect of SVS on the TLB. Keep CR4_PGE set when SVS is enabled,
but don't use PTE_G on the kernel PTEs in general.

Add PTE_G on only a few pages, that are already leaked to userland and do
not contain secrets.

This slightly improves syscall performance.


To generate a diff of this commit:
cvs rdiff -u -r1.169 -r1.170 src/sys/arch/x86/x86/cpu.c
cvs rdiff -u -r1.332 -r1.333 src/sys/arch/x86/x86/pmap.c
cvs rdiff -u -r1.27 -r1.28 src/sys/arch/x86/x86/svs.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/x86/x86

2019-05-25 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun May 26 00:30:35 UTC 2019

Modified Files:
src/sys/arch/x86/x86: consinit.c

Log Message:
tuck in include inside ifdef, from Ryosuke Moro


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/arch/x86/x86/consinit.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/x86/consinit.c
diff -u src/sys/arch/x86/x86/consinit.c:1.29 src/sys/arch/x86/x86/consinit.c:1.30
--- src/sys/arch/x86/x86/consinit.c:1.29	Fri May 24 10:28:48 2019
+++ src/sys/arch/x86/x86/consinit.c	Sat May 25 20:30:35 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: consinit.c,v 1.29 2019/05/24 14:28:48 nonaka Exp $	*/
+/*	$NetBSD: consinit.c,v 1.30 2019/05/26 00:30:35 christos Exp $	*/
 
 /*
  * Copyright (c) 1998
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: consinit.c,v 1.29 2019/05/24 14:28:48 nonaka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: consinit.c,v 1.30 2019/05/26 00:30:35 christos Exp $");
 
 #include "opt_kgdb.h"
 #include "opt_puc.h"
@@ -92,8 +92,8 @@ __KERNEL_RCSID(0, "$NetBSD: consinit.c,v
 #endif
 
 #ifndef XEN
-#include "hvkbd.h"
 #if NHVKBD > 0
+#include "hvkbd.h"
 #include 
 #endif
 #endif



CVS commit: src/sys/arch/x86/x86

2019-05-25 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun May 26 00:30:35 UTC 2019

Modified Files:
src/sys/arch/x86/x86: consinit.c

Log Message:
tuck in include inside ifdef, from Ryosuke Moro


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/arch/x86/x86/consinit.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/x86/x86

2019-05-25 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat May 25 21:02:33 UTC 2019

Modified Files:
src/sys/arch/x86/x86: fpu.c

Log Message:
Fix bug. We must fetch the whole FPU state, otherwise XSTATE_BV could be
outdated, and we could be filling the AVX registers with garbage.


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.53 src/sys/arch/x86/x86/fpu.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/x86/fpu.c
diff -u src/sys/arch/x86/x86/fpu.c:1.52 src/sys/arch/x86/x86/fpu.c:1.53
--- src/sys/arch/x86/x86/fpu.c:1.52	Sun May 19 08:46:15 2019
+++ src/sys/arch/x86/x86/fpu.c	Sat May 25 21:02:32 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: fpu.c,v 1.52 2019/05/19 08:46:15 maxv Exp $	*/
+/*	$NetBSD: fpu.c,v 1.53 2019/05/25 21:02:32 maxv Exp $	*/
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.  All
@@ -96,7 +96,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.52 2019/05/19 08:46:15 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.53 2019/05/25 21:02:32 maxv Exp $");
 
 #include "opt_multiprocessor.h"
 
@@ -827,7 +827,7 @@ process_write_fpregs_xmm(struct lwp *l, 
 {
 	union savefpu *fpu_save;
 
-	fpusave_lwp(l, false);
+	fpusave_lwp(l, true);
 	fpu_save = lwp_fpuarea(l);
 
 	if (i386_use_fxsave) {



CVS commit: src/sys/arch/x86/x86

2019-05-25 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat May 25 21:02:33 UTC 2019

Modified Files:
src/sys/arch/x86/x86: fpu.c

Log Message:
Fix bug. We must fetch the whole FPU state, otherwise XSTATE_BV could be
outdated, and we could be filling the AVX registers with garbage.


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.53 src/sys/arch/x86/x86/fpu.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/x86/x86

2019-05-19 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun May 19 07:43:17 UTC 2019

Modified Files:
src/sys/arch/x86/x86: genfb_machdep.c

Log Message:
correct order of parameters, has no effect as anything set here is
overwritten by the following reconfig.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/x86/x86/genfb_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/x86/genfb_machdep.c
diff -u src/sys/arch/x86/x86/genfb_machdep.c:1.12 src/sys/arch/x86/x86/genfb_machdep.c:1.13
--- src/sys/arch/x86/x86/genfb_machdep.c:1.12	Sat Feb 25 01:13:50 2017
+++ src/sys/arch/x86/x86/genfb_machdep.c	Sun May 19 07:43:17 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: genfb_machdep.c,v 1.12 2017/02/25 01:13:50 nonaka Exp $ */
+/* $NetBSD: genfb_machdep.c,v 1.13 2019/05/19 07:43:17 mlelstv Exp $ */
 
 /*-
  * Copyright (c) 2009 Jared D. McNeill 
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: genfb_machdep.c,v 1.12 2017/02/25 01:13:50 nonaka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: genfb_machdep.c,v 1.13 2019/05/19 07:43:17 mlelstv Exp $");
 
 #include "opt_mtrr.h"
 
@@ -196,7 +196,7 @@ x86_genfb_cnattach(void)
 	} else
 		ri->ri_bits = bits;
 	ri->ri_flg = RI_CENTER | RI_FULLCLEAR | RI_CLEAR;
-	rasops_init(ri, ri->ri_width / 8, ri->ri_height / 8);
+	rasops_init(ri, ri->ri_height / 8, ri->ri_width / 8);
 	ri->ri_caps = WSSCREEN_WSCOLORS;
 	rasops_reconfig(ri, ri->ri_height / ri->ri_font->fontheight,
 	ri->ri_width / ri->ri_font->fontwidth);



CVS commit: src/sys/arch/x86/x86

2019-05-19 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun May 19 07:43:17 UTC 2019

Modified Files:
src/sys/arch/x86/x86: genfb_machdep.c

Log Message:
correct order of parameters, has no effect as anything set here is
overwritten by the following reconfig.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/x86/x86/genfb_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/x86/x86

2019-05-18 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat May 18 13:44:57 UTC 2019

Modified Files:
src/sys/arch/x86/x86: identcpu.c

Log Message:
Enable EagerFPU by default. Sent on port-amd64@.


To generate a diff of this commit:
cvs rdiff -u -r1.89 -r1.90 src/sys/arch/x86/x86/identcpu.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/x86/x86

2019-05-18 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat May 18 08:54:38 UTC 2019

Modified Files:
src/sys/arch/x86/x86: spectre.c

Log Message:
Use XC_HIGHPRI for SpectreV2 to reduce the CPU downtime. We already do this
for MDS.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/arch/x86/x86/spectre.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/x86/x86

2019-05-18 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat May 18 08:54:38 UTC 2019

Modified Files:
src/sys/arch/x86/x86: spectre.c

Log Message:
Use XC_HIGHPRI for SpectreV2 to reduce the CPU downtime. We already do this
for MDS.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/arch/x86/x86/spectre.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/x86/spectre.c
diff -u src/sys/arch/x86/x86/spectre.c:1.27 src/sys/arch/x86/x86/spectre.c:1.28
--- src/sys/arch/x86/x86/spectre.c:1.27	Tue May 14 16:59:26 2019
+++ src/sys/arch/x86/x86/spectre.c	Sat May 18 08:54:38 2019
@@ -1,7 +1,7 @@
-/*	$NetBSD: spectre.c,v 1.27 2019/05/14 16:59:26 maxv Exp $	*/
+/*	$NetBSD: spectre.c,v 1.28 2019/05/18 08:54:38 maxv Exp $	*/
 
 /*
- * Copyright (c) 2018 NetBSD Foundation, Inc.
+ * Copyright (c) 2018-2019 NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -30,11 +30,11 @@
  */
 
 /*
- * Mitigations for the SpectreV2 and SpectreV4 CPU flaws.
+ * Mitigations for the SpectreV2, SpectreV4 and MDS CPU flaws.
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: spectre.c,v 1.27 2019/05/14 16:59:26 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: spectre.c,v 1.28 2019/05/18 08:54:38 maxv Exp $");
 
 #include "opt_spectre.h"
 
@@ -328,7 +328,7 @@ mitigation_v2_change(bool enabled)
 
 		printf("[+] %s SpectreV2 Mitigation...",
 		enabled ? "Enabling" : "Disabling");
-		xc = xc_broadcast(0, mitigation_v2_change_cpu,
+		xc = xc_broadcast(XC_HIGHPRI, mitigation_v2_change_cpu,
 		(void *)enabled, NULL);
 		xc_wait(xc);
 		printf(" done!\n");



CVS commit: src/sys/arch/x86/x86

2019-05-18 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat May 18 07:49:31 UTC 2019

Modified Files:
src/sys/arch/x86/x86: errata.c

Log Message:
Disable errata #1091. We are the only OS to apply it, and it seems to be
causing trouble to VirtualBox (PR/54143).


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/arch/x86/x86/errata.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/x86/x86

2019-05-18 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat May 18 07:49:31 UTC 2019

Modified Files:
src/sys/arch/x86/x86: errata.c

Log Message:
Disable errata #1091. We are the only OS to apply it, and it seems to be
causing trouble to VirtualBox (PR/54143).


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/arch/x86/x86/errata.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/x86/errata.c
diff -u src/sys/arch/x86/x86/errata.c:1.25 src/sys/arch/x86/x86/errata.c:1.26
--- src/sys/arch/x86/x86/errata.c:1.25	Sun Aug 12 05:43:42 2018
+++ src/sys/arch/x86/x86/errata.c	Sat May 18 07:49:31 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: errata.c,v 1.25 2018/08/12 05:43:42 maxv Exp $	*/
+/*	$NetBSD: errata.c,v 1.26 2019/05/18 07:49:31 maxv Exp $	*/
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -45,7 +45,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: errata.c,v 1.25 2018/08/12 05:43:42 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: errata.c,v 1.26 2019/05/18 07:49:31 maxv Exp $");
 
 #include 
 #include 
@@ -341,6 +341,7 @@ static errata_t errata[] = {
 		1049, FALSE, MSR_FP_CFG, x86_errata_set13,
 		x86_errata_setmsr, FP_CFG_ERRATA_1049
 	},
+#if 0	/* Should we apply this errata? The other OSes don't. */
 	/*
 	 * 1091: Address Boundary Crossing Load Operation May Receive
 	 * Stale Data
@@ -349,6 +350,7 @@ static errata_t errata[] = {
 		1091, FALSE, MSR_LS_CFG2, x86_errata_set13,
 		x86_errata_setmsr, LS_CFG2_ERRATA_1091
 	},
+#endif
 	/*
 	 * 1095: Potential Violation of Read Ordering In Lock Operation
 	 * In SMT (Simultaneous Multithreading) Mode



Re: CVS commit: src/sys/arch/x86/x86

2019-05-16 Thread Masanobu SAITOH
On 2019/05/16 13:20, Jason Thorpe wrote:
> 
> 
>> On May 15, 2019, at 9:19 PM, Maxime Villard  wrote:
>>
>> Le 16/05/2019 à 04:36, SAITOH Masanobu a écrit :
>>> Module Name:src
>>> Committed By:   msaitoh
>>> Date:   Thu May 16 02:36:30 UTC 2019
>>> Modified Files:
>>> src/sys/arch/x86/x86: procfs_machdep.c
>>> Log Message:
>>>  Use ci_feat_val[7] instead of directly getting cpuid 7 edx.
>>> To generate a diff of this commit:
>>> cvs rdiff -u -r1.28 -r1.29 src/sys/arch/x86/x86/procfs_machdep.c
>>> Please note that diffs are not public domain; they are subject to the
>>> copyright notices on the relevant files.
>>
>> The microcode updates CPUID7, if you read ci_feat_val you have the
>> initial value, not the updated value. So reading CPUID7 was the right
>> thing to do.
> 
> Should the microcode update procedure fix up the cached copy?

I think so, but our code doesn't do it.

 There are some code which copy a cpuid value to ci_feat_val[] and
modify some bits for workaround and use the copy. ci_feat_val[]
is better than trusting current cpuid values for consistency.

We should provide user an interface to know the current behavior
of the kernel. I think ci_feat_val[] is the data to explain the
behavior. If so, we should use ci_feat_val[] in x86/procfs_machdep.c.
But, sadly, ci_feat_val[] is not updated, so it might better to
use real cpuid value than ci_feat_val[]. The latest x86/procfs_machdep.c
(rev. 1.31) refers ci_feat_val[0..6] and not refer ci_feat_val[7].
It's inconsistent.

 If we update ci_feat_val, we should have callback function to
reflect the change. Callback is not required for many bits but
it's required for some others.

 I have a code locally to know which bit is changed after updating
microcode:

--
Index: x86/cpu_ucode_intel.c
===
RCS file: /cvsroot/src/sys/arch/x86/x86/cpu_ucode_intel.c,v
retrieving revision 1.17
diff -u -p -r1.17 cpu_ucode_intel.c
--- x86/cpu_ucode_intel.c   10 May 2019 18:21:01 -  1.17
+++ x86/cpu_ucode_intel.c   16 May 2019 04:28:13 -
@@ -178,9 +178,14 @@ cpu_ucode_intel_apply(struct cpu_ucode_s
 {
uint32_t ucodetarget, oucodeversion, nucodeversion;
struct intel1_ucode_header *uh;
+   struct cpu_info *ci;
+   struct cpu_info oldci;
+   int i;
int platformid, cpuid, error;
size_t newbufsize = 0;
void *uha;
+   uint64_t msr = 0;
+   u_int descs[4];
 
if (sc->loader_version != CPU_UCODE_LOADER_INTEL1 ||
cpuno != CPU_UCODE_CURRENT_CPU)
@@ -221,15 +226,62 @@ cpu_ucode_intel_apply(struct cpu_ucode_s
intel_getcurrentucode(, );
cpuid = curcpu()->ci_index;
 
-   kpreempt_enable();
-
if (nucodeversion != ucodetarget) {
+   kpreempt_enable();
error = EIO;
goto out;
}
 
-   printf("cpu %d: ucode 0x%x->0x%x\n", cpuid, oucodeversion,
-   nucodeversion);
+   ci = curcpu();
+   oldci = *ci;
+#if 1
+   /*
+* Update cpu_info.
+*
+* XXX cpu_probe() is currently not intended to call multiple time
+* on a cpu.
+*/
+   cpu_probe(curcpu());
+#endif
+   if (ci->ci_max_cpuid >= 7) {
+   x86_cpuid(7, descs);
+   if (descs[3] & CPUID_SEF_ARCH_CAP)
+   msr = rdmsr(MSR_IA32_ARCH_CAPABILITIES);
+   }
+   kpreempt_enable();
+
+   if ((ci->ci_max_cpuid >= 7) && (descs[3] & CPUID_SEF_ARCH_CAP))
+   printf("cpu%d: MSR_IA32_ARCH_CAPABILITIES=0x%lx\n", cpuid,
+   msr);
+   printf("cpu%d: ucode 0x%x->0x%x\n", cpuid,
+  oucodeversion, nucodeversion);
+   for (i = 0; i < __arraycount(ci->ci_feat_val); i++) {
+   uint32_t old, new, dif, set, unset;
+
+   old = oldci.ci_feat_val[i];
+   new = ci->ci_feat_val[i];
+   if (old != new) {
+   printf("cpu%d: ci_feat_val[%d] changed from %08x to "
+   "%08x\n", cpuid, i, old, new);
+   dif = old ^ new;
+   set = new & dif;
+   unset = old & dif;
+
+   if (set != 0)
+   printf("cpu%d:   set: %08x\n", cpuid, set);
+   if (unset != 0)
+   printf("cpu%d: unset: %08x\n", cpuid, unset);
+
+   /*
+* Call hook if you want to do something.
+*
+* WARNING. If HyperThreading is enabled and the
+* microcode is updated to new one, another CPU's
+* feature bits also be changed and we cannot hook
+* for the CPU here.
+*/
+   }
+   }
 
 out:
if (newbufsize != 0)
--

CVS commit: src/sys/arch/x86/x86

2019-05-15 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu May 16 04:26:13 UTC 2019

Modified Files:
src/sys/arch/x86/x86: procfs_machdep.c

Log Message:
 Revert rev. 1.29. Use current cpuid 7 edx value to print.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/x86/x86/procfs_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/x86/procfs_machdep.c
diff -u src/sys/arch/x86/x86/procfs_machdep.c:1.30 src/sys/arch/x86/x86/procfs_machdep.c:1.31
--- src/sys/arch/x86/x86/procfs_machdep.c:1.30	Thu May 16 02:42:19 2019
+++ src/sys/arch/x86/x86/procfs_machdep.c	Thu May 16 04:26:13 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: procfs_machdep.c,v 1.30 2019/05/16 02:42:19 msaitoh Exp $ */
+/*	$NetBSD: procfs_machdep.c,v 1.31 2019/05/16 04:26:13 msaitoh Exp $ */
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: procfs_machdep.c,v 1.30 2019/05/16 02:42:19 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: procfs_machdep.c,v 1.31 2019/05/16 04:26:13 msaitoh Exp $");
 
 #include 
 #include 
@@ -345,9 +345,11 @@ procfs_getonecpufeatures(struct cpu_info
 		diff = last - *left;
 	}
 
-	if (cpu_vendor == CPUVENDOR_INTEL) {
-		procfs_getonefeatreg(ci->ci_feat_val[7], x86_features[18],
-		p + diff, left);
+	if ((cpu_vendor == CPUVENDOR_INTEL)
+	&& (ci->ci_max_cpuid >= 0x0007)) {
+		x86_cpuid(0x0007, descs);
+		procfs_getonefeatreg(descs[3], x86_features[18], p + diff,
+		left);
 		diff = last - *left;
 	}
 



CVS commit: src/sys/arch/x86/x86

2019-05-15 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu May 16 04:26:13 UTC 2019

Modified Files:
src/sys/arch/x86/x86: procfs_machdep.c

Log Message:
 Revert rev. 1.29. Use current cpuid 7 edx value to print.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/x86/x86/procfs_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



Re: CVS commit: src/sys/arch/x86/x86

2019-05-15 Thread Masanobu SAITOH
On 2019/05/16 13:19, Maxime Villard wrote:
> Le 16/05/2019 à 04:36, SAITOH Masanobu a écrit :
>> Module Name:    src
>> Committed By:    msaitoh
>> Date:    Thu May 16 02:36:30 UTC 2019
>>
>> Modified Files:
>> src/sys/arch/x86/x86: procfs_machdep.c
>>
>> Log Message:
>>   Use ci_feat_val[7] instead of directly getting cpuid 7 edx.
>>
>>
>> To generate a diff of this commit:
>> cvs rdiff -u -r1.28 -r1.29 src/sys/arch/x86/x86/procfs_machdep.c
>>
>> Please note that diffs are not public domain; they are subject to the
>> copyright notices on the relevant files.
> 
> The microcode updates CPUID7, if you read ci_feat_val you have the
> initial value, not the updated value. So reading CPUID7 was the right
> thing to do.

 We have no callback or something like it to reflect the change
to ci_feat_val, so you're right.

I'll revert it.

-- 
---
SAITOH Masanobu (msai...@execsw.org
 msai...@netbsd.org)


Re: CVS commit: src/sys/arch/x86/x86

2019-05-15 Thread Jason Thorpe



> On May 15, 2019, at 9:19 PM, Maxime Villard  wrote:
> 
> Le 16/05/2019 à 04:36, SAITOH Masanobu a écrit :
>> Module Name: src
>> Committed By:msaitoh
>> Date:Thu May 16 02:36:30 UTC 2019
>> Modified Files:
>>  src/sys/arch/x86/x86: procfs_machdep.c
>> Log Message:
>>  Use ci_feat_val[7] instead of directly getting cpuid 7 edx.
>> To generate a diff of this commit:
>> cvs rdiff -u -r1.28 -r1.29 src/sys/arch/x86/x86/procfs_machdep.c
>> Please note that diffs are not public domain; they are subject to the
>> copyright notices on the relevant files.
> 
> The microcode updates CPUID7, if you read ci_feat_val you have the
> initial value, not the updated value. So reading CPUID7 was the right
> thing to do.

Should the microcode update procedure fix up the cached copy?

-- thorpej



Re: CVS commit: src/sys/arch/x86/x86

2019-05-15 Thread Maxime Villard

Le 16/05/2019 à 04:36, SAITOH Masanobu a écrit :

Module Name:src
Committed By:   msaitoh
Date:   Thu May 16 02:36:30 UTC 2019

Modified Files:
src/sys/arch/x86/x86: procfs_machdep.c

Log Message:
  Use ci_feat_val[7] instead of directly getting cpuid 7 edx.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/arch/x86/x86/procfs_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.


The microcode updates CPUID7, if you read ci_feat_val you have the
initial value, not the updated value. So reading CPUID7 was the right
thing to do.


CVS commit: src/sys/arch/x86/x86

2019-05-15 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu May 16 02:42:19 UTC 2019

Modified Files:
src/sys/arch/x86/x86: procfs_machdep.c

Log Message:
 Add md_clear.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/arch/x86/x86/procfs_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/x86/procfs_machdep.c
diff -u src/sys/arch/x86/x86/procfs_machdep.c:1.29 src/sys/arch/x86/x86/procfs_machdep.c:1.30
--- src/sys/arch/x86/x86/procfs_machdep.c:1.29	Thu May 16 02:36:30 2019
+++ src/sys/arch/x86/x86/procfs_machdep.c	Thu May 16 02:42:19 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: procfs_machdep.c,v 1.29 2019/05/16 02:36:30 msaitoh Exp $ */
+/*	$NetBSD: procfs_machdep.c,v 1.30 2019/05/16 02:42:19 msaitoh Exp $ */
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: procfs_machdep.c,v 1.29 2019/05/16 02:36:30 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: procfs_machdep.c,v 1.30 2019/05/16 02:42:19 msaitoh Exp $");
 
 #include 
 #include 
@@ -188,7 +188,7 @@ static const char * const x86_features[]
 
 	{ /* (18) Intel 0x0007 edx */
 	NULL, NULL, "avx512_4vnniw", "avx512_4fmaps", NULL, NULL, NULL, NULL,
-	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+	NULL, NULL, "md_clear", NULL, NULL, NULL, NULL, NULL,
 	NULL, NULL, "pconfig", NULL, NULL, NULL, NULL, NULL,
 	NULL, NULL, NULL, NULL,
 	"flush_l1d", "arch_capabilities", NULL, "ssbd"},



CVS commit: src/sys/arch/x86/x86

2019-05-15 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu May 16 02:42:19 UTC 2019

Modified Files:
src/sys/arch/x86/x86: procfs_machdep.c

Log Message:
 Add md_clear.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/arch/x86/x86/procfs_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/x86/x86

2019-05-15 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu May 16 02:36:30 UTC 2019

Modified Files:
src/sys/arch/x86/x86: procfs_machdep.c

Log Message:
 Use ci_feat_val[7] instead of directly getting cpuid 7 edx.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/arch/x86/x86/procfs_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/x86/x86

2019-05-15 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu May 16 02:36:30 UTC 2019

Modified Files:
src/sys/arch/x86/x86: procfs_machdep.c

Log Message:
 Use ci_feat_val[7] instead of directly getting cpuid 7 edx.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/arch/x86/x86/procfs_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/x86/procfs_machdep.c
diff -u src/sys/arch/x86/x86/procfs_machdep.c:1.28 src/sys/arch/x86/x86/procfs_machdep.c:1.29
--- src/sys/arch/x86/x86/procfs_machdep.c:1.28	Mon Feb 18 05:41:20 2019
+++ src/sys/arch/x86/x86/procfs_machdep.c	Thu May 16 02:36:30 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: procfs_machdep.c,v 1.28 2019/02/18 05:41:20 msaitoh Exp $ */
+/*	$NetBSD: procfs_machdep.c,v 1.29 2019/05/16 02:36:30 msaitoh Exp $ */
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: procfs_machdep.c,v 1.28 2019/02/18 05:41:20 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: procfs_machdep.c,v 1.29 2019/05/16 02:36:30 msaitoh Exp $");
 
 #include 
 #include 
@@ -345,11 +345,9 @@ procfs_getonecpufeatures(struct cpu_info
 		diff = last - *left;
 	}
 
-	if ((cpu_vendor == CPUVENDOR_INTEL)
-	&& (ci->ci_max_cpuid >= 0x0007)) {
-		x86_cpuid(0x0007, descs);
-		procfs_getonefeatreg(descs[3], x86_features[18], p + diff,
-		left);
+	if (cpu_vendor == CPUVENDOR_INTEL) {
+		procfs_getonefeatreg(ci->ci_feat_val[7], x86_features[18],
+		p + diff, left);
 		diff = last - *left;
 	}
 



Re: CVS commit: src/sys/arch/x86/x86

2019-01-06 Thread Cherry G . Mathew
Maxime Villard  writes:

> Can we do something about it now? It's been more than a week, and the issue is
> still there. NVMM still doesn't modload, same for procfs, and GENERIC_KASLR
> doesn't work either.
>
> This needs to be fixed now, and we should not start adding random hacks all
> over the place (like the one below).
>

Sorry for the delay - I've rolled back the changes.

http://mail-index.netbsd.org/source-changes/2019/01/06/msg102113.html

The XEN related ones I will roll back if enough people complain. I'm
meanwhile investigating other options.

Thanks for your patience.
-- 
~cherry


Re: CVS commit: src/sys/arch/x86/x86

2019-01-05 Thread Maxime Villard

Can we do something about it now? It's been more than a week, and the issue is
still there. NVMM still doesn't modload, same for procfs, and GENERIC_KASLR
doesn't work either.

This needs to be fixed now, and we should not start adding random hacks all
over the place (like the one below).


Le 05/01/2019 à 21:32, Christos Zoulas a écrit :

Module Name:src
Committed By:   christos
Date:   Sat Jan  5 20:32:02 UTC 2019

Modified Files:
src/sys/arch/x86/x86: procfs_machdep.c

Log Message:
Comment out rcr0 use until the weak symbol mess is undone.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/arch/x86/x86/procfs_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.


re: CVS commit: src/sys/arch/x86/x86

2018-12-04 Thread matthew green
Joerg Sonnenberger writes:
> On Tue, Dec 04, 2018 at 07:27:22PM +, Cherry G. Mathew wrote:
> > Module Name:src
> > Committed By:   cherry
> > Date:   Tue Dec  4 19:27:22 UTC 2018
> > 
> > Modified Files:
> > src/sys/arch/x86/x86: cpu.c intr.c
> > 
> > Log Message:
> > Hypothetically speaking, if one were to want to compile a
> > 
> > 'no options MULTIPROCESSOR'
> > 
> > kernel, these files may trip up the build.
> > 
> > Fix them by moving around the #defines as originally intended.
> 
> Well, MULTIPROCESSOR is *not* meant to be optional on x86.

true, but it's always been very simple to keep working.  i've
commited simple fixes like this maybe twice before..


.mrg.


Re: CVS commit: src/sys/arch/x86/x86

2018-12-04 Thread Joerg Sonnenberger
On Tue, Dec 04, 2018 at 07:27:22PM +, Cherry G. Mathew wrote:
> Module Name:  src
> Committed By: cherry
> Date: Tue Dec  4 19:27:22 UTC 2018
> 
> Modified Files:
>   src/sys/arch/x86/x86: cpu.c intr.c
> 
> Log Message:
> Hypothetically speaking, if one were to want to compile a
> 
> 'no options MULTIPROCESSOR'
> 
> kernel, these files may trip up the build.
> 
> Fix them by moving around the #defines as originally intended.

Well, MULTIPROCESSOR is *not* meant to be optional on x86.

Joerg


Re: CVS commit: src/sys/arch/x86/x86

2018-07-08 Thread Kamil Rytarowski
On 08.07.2018 15:56, Christos Zoulas wrote:
> In article <20180708092413.gb8...@mail.duskware.de>,
> Martin Husemann   wrote:
>> On Sun, Jul 08, 2018 at 10:49:53AM +0200, Jaromír Dole?ek wrote:
 Module Name:src
 Committed By:   kamil
 Date:   Sat Jul  7 23:05:50 UTC 2018

 Modified Files:
 src/sys/arch/x86/x86: mpbios.c

 Log Message:
 Remove unaligned access to mpbios_page[]

 Replace unaligned pointer dereference with a more portable construct that
 is free from Undefined Behavior semantics.

 sys/arch/x86/x86/mpbios.c:308:11, load of misaligned address 
 0x800031c7a413 for type 'const
>> __uint16_t' which requires 2 byte alignment
>>
>>
>> Can we please do NOT do such stupid changes?
>>
>> This is a bogus error message, please restore the original code!
> 
> These changes are pointless; how much code will we need to change
> to silence mis-aligned warnings? These changes are also dangerous
> when it comes to reading from devices (where multiple reads can
> behave differently). If you want to silence the warnings, use
> __attribute__, but even that is of questionable use. I'd venture
> to say, misaligned warnings on cpus where aligned access (to do
> the aligning) is costlier than direct misaligned accesses (like
> x86) are useless. In addition, it is not like we would ever turn
> on the force alignment bit on an x86 cpu and have things work!
> 
> So my preference would be to revert the change and take this up
> to tech-kern first (how misaligned accesses should be treated),
> because the situation is not that simple (when it comes to things
> like SSE operations etc.)
> http://pzemtsov.github.io/2016/11/06/bug-story-alignment-on-x86.html
> 
> 
> Best,
> 
> christos
> 

I've started a tech-kern discussion on the request.

Regarding the number of assignment issues to address:
 - acpica
 - mpbios.c [this one]
 - arch/x86/x86/patch.c [load of address with insufficient space]
 - sys/kern/subr_disk_mbr.c disklabel struct misaligned
 - IPv6, TCP
 - amd64/amd64/kobj_machdep.c (ELF)
 - XHCI

http://netbsd.org/~kamil/kubsan/0007-boot-real-hardware.txt

I'm going to revert it for a while, until there will be a conclusion.



signature.asc
Description: OpenPGP digital signature


Re: CVS commit: src/sys/arch/x86/x86

2018-07-08 Thread Kamil Rytarowski
On 08.07.2018 10:49, Jaromír Doleček wrote:
> Shouldn't this:
> 
> memtop |= (uint16_t)mpbios_page[0x414] << 8;
> 
> be actually << 16 to keep the same semantics?
> 

No. This is a 2-byte (x86 word) variable. One byte has to be stored with
the 8 bits shift.

If it would be differently it would probably brick the booting process.

> Jaromir
> Le dim. 8 juil. 2018 à 01:05, Kamil Rytarowski  a écrit :
>>
>> Module Name:src
>> Committed By:   kamil
>> Date:   Sat Jul  7 23:05:50 UTC 2018
>>
>> Modified Files:
>> src/sys/arch/x86/x86: mpbios.c
>>
>> Log Message:
>> Remove unaligned access to mpbios_page[]
>>
>> Replace unaligned pointer dereference with a more portable construct that
>> is free from Undefined Behavior semantics.
>>
>> sys/arch/x86/x86/mpbios.c:308:11, load of misaligned address 
>> 0x800031c7a413 for type 'const __uint16_t' which requires 2 byte 
>> alignment
>>
>> Detected with Kernel Undefined Behavior Sanitizer
>>
>>
>> To generate a diff of this commit:
>> cvs rdiff -u -r1.66 -r1.67 src/sys/arch/x86/x86/mpbios.c
>>
>> Please note that diffs are not public domain; they are subject to the
>> copyright notices on the relevant files.
>>




signature.asc
Description: OpenPGP digital signature


Re: CVS commit: src/sys/arch/x86/x86

2018-07-08 Thread Christos Zoulas
In article <20180708092413.gb8...@mail.duskware.de>,
Martin Husemann   wrote:
>On Sun, Jul 08, 2018 at 10:49:53AM +0200, Jaromír Dole?ek wrote:
>> > Module Name:src
>> > Committed By:   kamil
>> > Date:   Sat Jul  7 23:05:50 UTC 2018
>> >
>> > Modified Files:
>> > src/sys/arch/x86/x86: mpbios.c
>> >
>> > Log Message:
>> > Remove unaligned access to mpbios_page[]
>> >
>> > Replace unaligned pointer dereference with a more portable construct that
>> > is free from Undefined Behavior semantics.
>> >
>> > sys/arch/x86/x86/mpbios.c:308:11, load of misaligned address 
>> > 0x800031c7a413 for type 'const
>__uint16_t' which requires 2 byte alignment
>
>
>Can we please do NOT do such stupid changes?
>
>This is a bogus error message, please restore the original code!

These changes are pointless; how much code will we need to change
to silence mis-aligned warnings? These changes are also dangerous
when it comes to reading from devices (where multiple reads can
behave differently). If you want to silence the warnings, use
__attribute__, but even that is of questionable use. I'd venture
to say, misaligned warnings on cpus where aligned access (to do
the aligning) is costlier than direct misaligned accesses (like
x86) are useless. In addition, it is not like we would ever turn
on the force alignment bit on an x86 cpu and have things work!

So my preference would be to revert the change and take this up
to tech-kern first (how misaligned accesses should be treated),
because the situation is not that simple (when it comes to things
like SSE operations etc.)
http://pzemtsov.github.io/2016/11/06/bug-story-alignment-on-x86.html


Best,

christos



Re: CVS commit: src/sys/arch/x86/x86

2018-07-08 Thread Martin Husemann
On Sun, Jul 08, 2018 at 10:49:53AM +0200, Jaromír Dole?ek wrote:
> > Module Name:src
> > Committed By:   kamil
> > Date:   Sat Jul  7 23:05:50 UTC 2018
> >
> > Modified Files:
> > src/sys/arch/x86/x86: mpbios.c
> >
> > Log Message:
> > Remove unaligned access to mpbios_page[]
> >
> > Replace unaligned pointer dereference with a more portable construct that
> > is free from Undefined Behavior semantics.
> >
> > sys/arch/x86/x86/mpbios.c:308:11, load of misaligned address 
> > 0x800031c7a413 for type 'const __uint16_t' which requires 2 byte 
> > alignment


Can we please do NOT do such stupid changes?

This is a bogus error message, please restore the original code!

Martin


Re: CVS commit: src/sys/arch/x86/x86

2018-07-08 Thread Jaromír Doleček
Shouldn't this:

memtop |= (uint16_t)mpbios_page[0x414] << 8;

be actually << 16 to keep the same semantics?

Jaromir
Le dim. 8 juil. 2018 à 01:05, Kamil Rytarowski  a écrit :
>
> Module Name:src
> Committed By:   kamil
> Date:   Sat Jul  7 23:05:50 UTC 2018
>
> Modified Files:
> src/sys/arch/x86/x86: mpbios.c
>
> Log Message:
> Remove unaligned access to mpbios_page[]
>
> Replace unaligned pointer dereference with a more portable construct that
> is free from Undefined Behavior semantics.
>
> sys/arch/x86/x86/mpbios.c:308:11, load of misaligned address 
> 0x800031c7a413 for type 'const __uint16_t' which requires 2 byte alignment
>
> Detected with Kernel Undefined Behavior Sanitizer
>
>
> To generate a diff of this commit:
> cvs rdiff -u -r1.66 -r1.67 src/sys/arch/x86/x86/mpbios.c
>
> Please note that diffs are not public domain; they are subject to the
> copyright notices on the relevant files.
>


Re: CVS commit: src/sys/arch/x86/x86

2018-06-21 Thread Maxime Villard

Le 22/06/2018 à 03:40, matthew green a écrit :

"Maxime Villard" writes:

Module Name:src
Committed By:   maxv
Date:   Tue Jun 19 09:25:13 UTC 2018

Modified Files:
src/sys/arch/x86/x86: fpu.c

Log Message:
When using EagerFPU, create the fpu state in execve at IPL_HIGH.


why splhigh instead of kpreempt_disable()?


Nick Hudson asked me the same question yesterday, here's the relevant part
of my answer (quoting his mail, I guess he doesn't mind).

The fpu code already runs at splhigh, and this disables preemption. So I
used splhigh too.




 Message transféré 
Sujet : Re: Fwd: CVS commit: src/sys/arch/x86/x86
Date : Thu, 21 Jun 2018 07:23:33 +0100
De : Nick Hudson 
Pour : Maxime Villard 

On 21/06/2018 07:21, Maxime Villard wrote:

Le 21/06/2018 à 08:11, Nick Hudson a écrit :

On 21/06/2018 06:42, Maxime Villard wrote:

Le 21/06/2018 à 07:34, Maxime Villard a écrit :

Le 21/06/2018 à 07:21, Nick Hudson a écrit :

Surely, kpreempt_{disable,enable}() is what you really mean?

Nick


No, I mean splhigh. splhigh does prevent preemption, is that 
incorrect?


If you want to disable preemption then kpreempt_disable() is what you 
want.


If you want to disable interrupts (and as a consequence pre-emption) 
then splhigh is what you want.


I firmly believe you want the former.

Why disable interupts unnecessarily? This is "bad practice" and 
shouldn't be left for others to cargo cult copy.


There is a KASSERT in fpusave_cpu(), which I didn't introduce. We want
IPL_HIGH, unconditionally.

So no, I don't want the former, the FPU code wants the latter. Then we 
can say that maybe splhigh is not needed after all in fpusave_cpu; I won't 
risk introducing random races.


In the commit I said "disable preemption" because I had in mind the 
problem where a context switch occurs as a result of preemption.


Up to you... really don't know why FPU code needs interrupts disabled.


re: CVS commit: src/sys/arch/x86/x86

2018-06-21 Thread matthew green
"Maxime Villard" writes:
> Module Name:  src
> Committed By: maxv
> Date: Tue Jun 19 09:25:13 UTC 2018
> 
> Modified Files:
>   src/sys/arch/x86/x86: fpu.c
> 
> Log Message:
> When using EagerFPU, create the fpu state in execve at IPL_HIGH.

why splhigh instead of kpreempt_disable()?


.mrg.


Re: CVS commit: src/sys/arch/x86/x86

2018-06-08 Thread Jason Thorpe



> On Jun 7, 2018, at 7:59 AM, m...@netbsd.org wrote:
> 
> You've changed a default and selectively fixed the one driver that
> people noticed breaks from it. How do you know the rest aren't broken?

As you know, there is very little certainty in this world.  For example, how 
can I be certain that I won’t be hit by a bus when crossing the street? (Pun 
intended.)  At best, I can take precautions to minimize my risk.

In this case, here are the precautions I have taken:

- I have used a method of probing for i2c devices that is widely considered to 
be the best approach for doing so in a general way.

- The method I have selected is equivalent to the SMBus “quick” command.

- The overwhelming majority of “intelligent” i2c controllers that provide an 
“exec” interface to our i2c subsystem are, in fact, specifically SMBus 
controllers, and thus will, by their nature, support this operation.

- The other general-purpose “intelligent” i2c controllers that provide an 
“exec” interface should also, at the hardware layer, should support this 
operation because it’s a completely legal i2c bus sequence that should be free 
of side-effects.

- Per a lengthy discussion on tech-kern, we know of a specific, odd case of 
“intelligent” i2c controller that is fairly neutered, which we have 
special-cased.  It is truly the odd-ball.

- For the non-intelligent i2c controllers that use the i2c subsystem’s bit-bang 
logic, if this method doesn’t work, it’s simply a software bug that should be 
fixed.

Of course, you’re also ignoring the fact that i2c configuration was already 
somewhat broken in -current on a bunch of platforms, due to the effects of 
fixing another bug.  So, at the very least, this is moving the needle forward 
after a consensus among various stakeholders that this was a good approach.

In all my years of being involved with NetBSD, I have always made a good faith 
effort to improve the system to benefit the community, and attempt to correct 
my mistakes promptly when I make them.  If there’s one thing I’m certain of, 
it’s that.




> 
> On Thu, Jun 07, 2018 at 01:35:31PM +, Jason R Thorpe wrote:
>> Module Name: src
>> Committed By:thorpej
>> Date:Thu Jun  7 13:35:31 UTC 2018
>> 
>> Modified Files:
>>  src/sys/arch/x86/x86: x86_autoconf.c
>> 
>> Log Message:
>> In device_register(), if the device is an "iic" child of "imcsmb",
>> attach a I2C_PROP_INDIRECT_DEVICE_WHITELIST property that limits
>> the allowed devices to "spdmem" and "sdtemp".  Also set the
>> I2C_PROP_INDIRECT_PROBE_STRATEGY property to I2C_PROBE_STRATEGY_NONE,
>> since that controller can't issue any of the "quick" commands.
>> 
>> XXX It would be nice to be able to do this in the imcsmb driver
>> itself, but the way autoconfiguration works makes that infeasible.
>> 
>> 
>> To generate a diff of this commit:
>> cvs rdiff -u -r1.76 -r1.77 src/sys/arch/x86/x86/x86_autoconf.c
>> 
>> Please note that diffs are not public domain; they are subject to the
>> copyright notices on the relevant files.
>> 
> 
>> Modified files:
>> 
>> Index: src/sys/arch/x86/x86/x86_autoconf.c
>> diff -u src/sys/arch/x86/x86/x86_autoconf.c:1.76 
>> src/sys/arch/x86/x86/x86_autoconf.c:1.77
>> --- src/sys/arch/x86/x86/x86_autoconf.c:1.76 Thu Nov  9 01:02:56 2017
>> +++ src/sys/arch/x86/x86/x86_autoconf.c  Thu Jun  7 13:35:31 2018
>> @@ -1,4 +1,4 @@
>> -/*  $NetBSD: x86_autoconf.c,v 1.76 2017/11/09 01:02:56 christos Exp $   
>> */
>> +/*  $NetBSD: x86_autoconf.c,v 1.77 2018/06/07 13:35:31 thorpej Exp $
>> */
>> 
>> /*-
>>  * Copyright (c) 1990 The Regents of the University of California.
>> @@ -35,7 +35,7 @@
>>  */
>> 
>> #include 
>> -__KERNEL_RCSID(0, "$NetBSD: x86_autoconf.c,v 1.76 2017/11/09 01:02:56 
>> christos Exp $");
>> +__KERNEL_RCSID(0, "$NetBSD: x86_autoconf.c,v 1.77 2018/06/07 13:35:31 
>> thorpej Exp $");
>> 
>> #include 
>> #include 
>> @@ -54,6 +54,8 @@ __KERNEL_RCSID(0, "$NetBSD: x86_autoconf
>> #include 
>> #include 
>> 
>> +#include 
>> +
>> #include "acpica.h"
>> #include "wsdisplay.h"
>> 
>> @@ -547,6 +549,36 @@ device_register(device_t dev, void *aux)
>> {
>>  device_t isaboot, pciboot;
>> 
>> +/*
>> + * The Intel Integrated Memory Controller has a built-in i2c
>> + * controller that's rather limited in capability; it is intended
>> + * only for reading memory module EERPOMs and sensors.
>> + */
>> +if (device_is_a(dev, "iic") &&
>> +device_is_a(dev->dv_parent, "imcsmb")) {
>> +static const char *imcsmb_device_whitelist[] = {
>> +"spdmem",
>> +"sdtemp",
>> +NULL,
>> +};
>> +prop_array_t whitelist = prop_array_create();
>> +prop_dictionary_t props = device_properties(dev);
>> +int i;
>> +
>> +for (i = 0; imcsmb_device_whitelist[i] != NULL; i++) {
>> +prop_string_t pstr = prop_string_create_cstring_nocopy(
>> +   

  1   2   3   >