From e53750f3c3716385a8b4af9f3100874db7533111 Mon Sep 17 00:00:00 2001 From: purplerain Date: Mon, 11 Dec 2023 19:42:54 +0000 Subject: [PATCH] sync with OpenBSD -current --- distrib/sets/lists/comp/mi | 1 + etc/etc.armv7/login.conf | 4 +- etc/etc.i386/login.conf | 4 +- .../lib/ExtUtils/MM_Unix.pm | 2 +- .../Pod-Perldoc/lib/Pod/Perldoc/BaseTo.pm | 2 +- .../cpan/Pod-Perldoc/lib/Pod/Perldoc/ToMan.pm | 2 +- lib/libc/arch/DEFS.h | 7 +- lib/libc/arch/alpha/SYS.h | 3 +- lib/libc/arch/hppa/SYS.h | 7 +- lib/libc/arch/i386/DEFS.h | 3 +- lib/libc/arch/m88k/DEFS.h | 3 +- lib/libc/arch/mips64/SYS.h | 3 +- lib/libc/arch/powerpc64/DEFS.h | 3 +- lib/libc/arch/riscv64/DEFS.h | 3 +- lib/libc/arch/sh/SYS.h | 3 +- lib/libc/sys/Makefile.inc | 6 +- lib/libc/sys/pinsyscalls.2 | 76 +++++ libexec/ld.so/aarch64/SYS.h | 3 +- libexec/ld.so/alpha/SYS.h | 3 +- libexec/ld.so/amd64/SYS.h | 3 +- libexec/ld.so/arm/SYS.h | 5 +- libexec/ld.so/hppa/SYS.h | 3 +- libexec/ld.so/i386/SYS.h | 3 +- libexec/ld.so/m88k/SYS.h | 3 +- libexec/ld.so/mips64/SYS.h | 3 +- libexec/ld.so/powerpc/SYS.h | 3 +- libexec/ld.so/powerpc64/SYS.h | 3 +- libexec/ld.so/riscv64/SYS.h | 3 +- libexec/ld.so/sh/SYS.h | 3 +- libexec/ld.so/sparc64/SYS.h | 3 +- regress/lib/libcrypto/evp/evp_test.c | 3 +- share/man/man4/acpi.4 | 6 +- share/man/man4/man4.arm64/Makefile | 4 +- share/man/man4/man4.arm64/ampchwm.4 | 48 ++++ sys/arch/amd64/amd64/vmm_machdep.c | 21 +- sys/arch/amd64/include/pmap.h | 3 +- sys/arch/arm/include/pmap.h | 3 +- sys/arch/arm64/arm64/pmap.c | 9 +- sys/arch/arm64/conf/GENERIC | 3 +- sys/arch/arm64/conf/files.arm64 | 6 +- sys/arch/arm64/dev/ampchwm.c | 272 ++++++++++++++++++ sys/arch/arm64/include/pmap.h | 6 +- sys/arch/i386/include/pmap.h | 3 +- sys/dev/ic/nvmereg.h | 14 +- sys/dev/pci/drm/amd/amdgpu/amdgpu_drv.c | 2 + sys/dev/pci/drm/amd/amdgpu/gfx_v11_0.c | 8 + .../pci/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 8 +- sys/dev/pci/drm/amd/display/dc/dc.h | 19 +- sys/dev/pci/drm/amd/display/dc/dc_stream.h | 11 + .../amd/display/dc/dcn10/dcn10_cm_common.c | 19 +- .../amd/display/dc/dcn10/dcn10_cm_common.h | 1 + .../amd/display/dc/dcn10/dcn10_hw_sequencer.c | 2 +- .../drm/amd/display/dc/dcn20/dcn20_hwseq.c | 6 +- .../drm/amd/display/dc/dcn30/dcn30_dwb_cm.c | 2 +- .../drm/amd/display/dc/dcn30/dcn30_hwseq.c | 39 +-- .../amd/display/dc/dcn314/dcn314_resource.c | 2 +- .../drm/amd/display/dc/dcn32/dcn32_hwseq.c | 8 +- .../pci/drm/amd/display/dc/dml/dc_features.h | 7 + .../drm/amd/display/dc/dml/dcn20/dcn20_fpu.c | 15 +- .../drm/amd/display/dc/dml/dcn32/dcn32_fpu.c | 3 +- .../amd/display/dc/dml/display_mode_enums.h | 25 ++ .../drm/amd/display/dc/dml/display_mode_vba.h | 9 + .../pci/drm/amd/display/dc/inc/core_types.h | 7 + .../pci/drm/amd/display/dc/inc/hw/hw_shared.h | 7 + sys/dev/pci/drm/amd/display/dmub/dmub_srv.h | 14 + .../pci/drm/amd/display/dmub/src/dmub_dcn20.c | 5 + .../pci/drm/amd/display/dmub/src/dmub_dcn20.h | 2 + .../pci/drm/amd/display/dmub/src/dmub_dcn31.c | 5 + .../pci/drm/amd/display/dmub/src/dmub_dcn31.h | 2 + .../pci/drm/amd/display/dmub/src/dmub_dcn32.c | 5 + .../pci/drm/amd/display/dmub/src/dmub_dcn32.h | 2 + .../pci/drm/amd/display/dmub/src/dmub_srv.c | 30 ++ .../include/asic_reg/gc/gc_11_0_0_offset.h | 2 + .../drm/amd/pm/swsmu/smu13/aldebaran_ppt.c | 5 +- sys/dev/pci/drm/dma-resv.c | 2 +- sys/dev/pci/drm/include/linux/dma-fence.h | 8 + sys/dev/pv/if_vio.c | 25 +- sys/dev/usb/ugold.c | 14 +- sys/kern/init_main.c | 3 +- sys/net/if_pflow.c | 75 +++-- sys/net/if_pflow.h | 8 +- sys/sys/acct.h | 3 +- usr.bin/lastcomm/lastcomm.1 | 8 +- usr.bin/lastcomm/lastcomm.c | 3 +- usr.sbin/rpki-client/extern.h | 3 +- usr.sbin/rpki-client/mft.c | 14 +- usr.sbin/rpki-client/parser.c | 20 +- 87 files changed, 852 insertions(+), 180 deletions(-) create mode 100644 lib/libc/sys/pinsyscalls.2 create mode 100644 share/man/man4/man4.arm64/ampchwm.4 create mode 100644 sys/arch/arm64/dev/ampchwm.c diff --git a/distrib/sets/lists/comp/mi b/distrib/sets/lists/comp/mi index e075fb6f2..a6013023a 100644 --- a/distrib/sets/lists/comp/mi +++ b/distrib/sets/lists/comp/mi @@ -1694,6 +1694,7 @@ ./usr/share/man/man2/open.2 ./usr/share/man/man2/pathconf.2 ./usr/share/man/man2/pinsyscall.2 +./usr/share/man/man2/pinsyscalls.2 ./usr/share/man/man2/pipe.2 ./usr/share/man/man2/pledge.2 ./usr/share/man/man2/poll.2 diff --git a/etc/etc.armv7/login.conf b/etc/etc.armv7/login.conf index 0f0982cef..289006aaf 100644 --- a/etc/etc.armv7/login.conf +++ b/etc/etc.armv7/login.conf @@ -1,4 +1,4 @@ -# $OpenBSD: login.conf,v 1.14 2023/11/14 12:48:46 jsg Exp $ +# $OpenBSD: login.conf,v 1.15 2023/12/11 19:52:40 kettenis Exp $ # # Sample login.conf file. See login.conf(5) for details. @@ -71,7 +71,7 @@ daemon:\ # Staff have fewer restrictions and can login even when nologins are set. # staff:\ - :datasize-cur=512M:\ + :datasize-cur=1536M:\ :datasize-max=infinity:\ :maxproc-max=512:\ :maxproc-cur=128:\ diff --git a/etc/etc.i386/login.conf b/etc/etc.i386/login.conf index 6743d477f..ffc19dd44 100644 --- a/etc/etc.i386/login.conf +++ b/etc/etc.i386/login.conf @@ -1,4 +1,4 @@ -# $OpenBSD: login.conf,v 1.18 2023/11/13 20:19:45 sthen Exp $ +# $OpenBSD: login.conf,v 1.19 2023/12/11 19:52:40 kettenis Exp $ # # Sample login.conf file. See login.conf(5) for details. @@ -70,7 +70,7 @@ daemon:\ # Staff have fewer restrictions and can login even when nologins are set. # staff:\ - :datasize-cur=512M:\ + :datasize-cur=768M:\ :datasize-max=infinity:\ :maxproc-max=512:\ :maxproc-cur=128:\ diff --git a/gnu/usr.bin/perl/cpan/ExtUtils-MakeMaker/lib/ExtUtils/MM_Unix.pm b/gnu/usr.bin/perl/cpan/ExtUtils-MakeMaker/lib/ExtUtils/MM_Unix.pm index dec0a08f6..40e11d8e2 100644 --- a/gnu/usr.bin/perl/cpan/ExtUtils-MakeMaker/lib/ExtUtils/MM_Unix.pm +++ b/gnu/usr.bin/perl/cpan/ExtUtils-MakeMaker/lib/ExtUtils/MM_Unix.pm @@ -34,7 +34,7 @@ BEGIN { $Is{SunOS4} = $^O eq 'sunos'; $Is{Solaris} = $^O eq 'solaris'; $Is{SunOS} = $Is{SunOS4} || $Is{Solaris}; - $Is{BSD} = ($^O =~ /^(?:free|net|open)bsd$/ or + $Is{BSD} = ($^O =~ /^(?:free|net|open|sec)bsd$/ or grep( $^O eq $_, qw(bsdos interix dragonfly) ) ); $Is{Android} = $^O =~ /android/; diff --git a/gnu/usr.bin/perl/cpan/Pod-Perldoc/lib/Pod/Perldoc/BaseTo.pm b/gnu/usr.bin/perl/cpan/Pod-Perldoc/lib/Pod/Perldoc/BaseTo.pm index fcfa03748..69c315ece 100644 --- a/gnu/usr.bin/perl/cpan/Pod-Perldoc/lib/Pod/Perldoc/BaseTo.pm +++ b/gnu/usr.bin/perl/cpan/Pod-Perldoc/lib/Pod/Perldoc/BaseTo.pm @@ -34,8 +34,8 @@ BEGIN { *is_hpux = $^O =~ m/hpux/ ? \&TRUE : \&FALSE unless defined &is_hpux; *is_openbsd = $^O =~ m/openbsd/ ? \&TRUE : \&FALSE unless defined &is_openbsd; *is_freebsd = $^O =~ m/freebsd/ ? \&TRUE : \&FALSE unless defined &is_freebsd; + *is_secbsd = $^O =~ m/secbsd/ ? \&TRUE : \&FALSE unless defined &is_secbsd; *is_bitrig = $^O =~ m/bitrig/ ? \&TRUE : \&FALSE unless defined &is_bitrig; - *is_secbsd = $^O =~ m/bitrig/ ? \&TRUE : \&FALSE unless defined &is_secbsd; } sub _perldoc_elem { diff --git a/gnu/usr.bin/perl/cpan/Pod-Perldoc/lib/Pod/Perldoc/ToMan.pm b/gnu/usr.bin/perl/cpan/Pod-Perldoc/lib/Pod/Perldoc/ToMan.pm index d8e42b170..ddb2cfed5 100644 --- a/gnu/usr.bin/perl/cpan/Pod-Perldoc/lib/Pod/Perldoc/ToMan.pm +++ b/gnu/usr.bin/perl/cpan/Pod-Perldoc/lib/Pod/Perldoc/ToMan.pm @@ -63,7 +63,7 @@ sub init { sub _roffer_candidates { my( $self ) = @_; - if( $self->is_openbsd || $self->is_freebsd || $self->is_bitrig ) { qw( mandoc groff nroff ) } + if( $self->is_openbsd || $self->is_freebsd || $self->is_bitrig || $self->is_secbsd ) { qw( mandoc groff nroff ) } else { qw( groff nroff mandoc ) } } diff --git a/lib/libc/arch/DEFS.h b/lib/libc/arch/DEFS.h index d9852ecb1..38cfcdec0 100644 --- a/lib/libc/arch/DEFS.h +++ b/lib/libc/arch/DEFS.h @@ -1,4 +1,4 @@ -/* $OpenBSD: DEFS.h,v 1.2 2023/12/10 16:45:50 deraadt Exp $ */ +/* $OpenBSD: DEFS.h,v 1.4 2023/12/11 22:24:15 kettenis Exp $ */ /* * Copyright (c) 2015,2018,2021 Philip Guenther * @@ -20,8 +20,10 @@ /* ARM just had to be different... */ #ifndef __arm__ # define _FUNC_TYPE @function +# define _PROGBITS @progbits #else # define _FUNC_TYPE #function +# define _PROGBITS %progbits #endif /* @@ -69,7 +71,8 @@ #define _END(x) .size x, . - x #define PINSYSCALL(sysno, label) \ - .pushsection .openbsd.syscalls,"",@progbits; \ + .pushsection .openbsd.syscalls,"",_PROGBITS; \ + .p2align 2; \ .long label; \ .long sysno; \ .popsection; diff --git a/lib/libc/arch/alpha/SYS.h b/lib/libc/arch/alpha/SYS.h index 62adccb89..d7e3f79ac 100644 --- a/lib/libc/arch/alpha/SYS.h +++ b/lib/libc/arch/alpha/SYS.h @@ -1,4 +1,4 @@ -/* $OpenBSD: SYS.h,v 1.17 2023/12/10 16:45:50 deraadt Exp $ */ +/* $OpenBSD: SYS.h,v 1.18 2023/12/11 22:24:15 kettenis Exp $ */ /* $NetBSD: SYS.h,v 1.4 1996/10/17 03:03:53 cgd Exp $ */ /* @@ -58,6 +58,7 @@ #define PINSYSCALL(sysno, label) \ .pushsection .openbsd.syscalls,"",@progbits; \ + .p2align 2; \ .long label; \ .long sysno; \ .popsection; diff --git a/lib/libc/arch/hppa/SYS.h b/lib/libc/arch/hppa/SYS.h index 6c0f54747..2e78cff63 100644 --- a/lib/libc/arch/hppa/SYS.h +++ b/lib/libc/arch/hppa/SYS.h @@ -1,4 +1,4 @@ -/* $OpenBSD: SYS.h,v 1.24 2023/12/10 16:45:51 deraadt Exp $ */ +/* $OpenBSD: SYS.h,v 1.26 2023/12/11 22:24:15 kettenis Exp $ */ /* * Copyright (c) 1998-2002 Michael Shalayeff @@ -69,6 +69,7 @@ #define PINSYSCALL(sysno, label) \ .pushsection .openbsd.syscalls,"",@progbits !\ + .p2align 2 !\ .long label !\ .long sysno !\ .popsection @@ -120,8 +121,8 @@ SYSENTRY(x) !\ stw rp, HPPA_FRAME_ERP(sr0,sp) !\ ldil L%SYSCALLGATE, r1 !\ 97: ble 4(sr7, r1) !\ - PINSYSCALL(__CONCAT(SYS_,x), 97b) !\ - ldi __CONCAT(SYS_,x), t1 !\ + PINSYSCALL(__CONCAT(SYS_,y), 97b) !\ + ldi __CONCAT(SYS_,y), t1 !\ ldw HPPA_FRAME_ERP(sr0,sp), rp !\ bv r0(rp) !\ nop !\ diff --git a/lib/libc/arch/i386/DEFS.h b/lib/libc/arch/i386/DEFS.h index c8ae4a29b..07efc8fa8 100644 --- a/lib/libc/arch/i386/DEFS.h +++ b/lib/libc/arch/i386/DEFS.h @@ -1,4 +1,4 @@ -/* $OpenBSD: DEFS.h,v 1.4 2023/12/10 16:45:51 deraadt Exp $ */ +/* $OpenBSD: DEFS.h,v 1.5 2023/12/11 22:24:15 kettenis Exp $ */ /* * Copyright (c) 2017 Philip Guenther * @@ -50,6 +50,7 @@ #define PINSYSCALL(sysno, label) \ .pushsection .openbsd.syscalls,"",@progbits; \ + .p2align 2; \ .long label; \ .long sysno; \ .popsection; diff --git a/lib/libc/arch/m88k/DEFS.h b/lib/libc/arch/m88k/DEFS.h index 804636ee8..5260e40bd 100644 --- a/lib/libc/arch/m88k/DEFS.h +++ b/lib/libc/arch/m88k/DEFS.h @@ -1,4 +1,4 @@ -/* $OpenBSD: DEFS.h,v 1.4 2023/12/10 16:45:51 deraadt Exp $ */ +/* $OpenBSD: DEFS.h,v 1.5 2023/12/11 22:24:15 kettenis Exp $ */ #include @@ -26,6 +26,7 @@ #define PINSYSCALL(sysno, label) \ .pushsection .openbsd.syscalls,"",@progbits; \ + .p2align 2; \ .long label; \ .long sysno; \ .popsection; diff --git a/lib/libc/arch/mips64/SYS.h b/lib/libc/arch/mips64/SYS.h index c9ac6b24c..16b5a6fda 100644 --- a/lib/libc/arch/mips64/SYS.h +++ b/lib/libc/arch/mips64/SYS.h @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $OpenBSD: SYS.h,v 1.13 2023/12/10 16:45:51 deraadt Exp $ + * $OpenBSD: SYS.h,v 1.14 2023/12/11 22:24:16 kettenis Exp $ */ #include @@ -127,6 +127,7 @@ #define PINSYSCALL(sysno, label) \ .pushsection .openbsd.syscalls,"",@progbits; \ + .p2align 2; \ .long label; \ .long sysno; \ .popsection; diff --git a/lib/libc/arch/powerpc64/DEFS.h b/lib/libc/arch/powerpc64/DEFS.h index 3b8c93320..9c90a1b1d 100644 --- a/lib/libc/arch/powerpc64/DEFS.h +++ b/lib/libc/arch/powerpc64/DEFS.h @@ -1,4 +1,4 @@ -/* $OpenBSD: DEFS.h,v 1.2 2023/12/10 16:45:52 deraadt Exp $ */ +/* $OpenBSD: DEFS.h,v 1.3 2023/12/11 22:24:16 kettenis Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. @@ -70,6 +70,7 @@ #define PINSYSCALL(sysno, label) \ .pushsection .openbsd.syscalls,"",@progbits; \ + .p2align 2; \ .long label; \ .long sysno; \ .popsection; diff --git a/lib/libc/arch/riscv64/DEFS.h b/lib/libc/arch/riscv64/DEFS.h index a2c61dda9..09bc27bef 100644 --- a/lib/libc/arch/riscv64/DEFS.h +++ b/lib/libc/arch/riscv64/DEFS.h @@ -1,4 +1,4 @@ -/* $OpenBSD: DEFS.h,v 1.2 2023/12/10 16:45:52 deraadt Exp $ */ +/* $OpenBSD: DEFS.h,v 1.3 2023/12/11 22:24:16 kettenis Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. * All rights reserved. @@ -60,6 +60,7 @@ #define PINSYSCALL(sysno, label) \ .pushsection .openbsd.syscalls,"",@progbits; \ + .p2align 2; \ .long label; \ .long sysno; \ .popsection; diff --git a/lib/libc/arch/sh/SYS.h b/lib/libc/arch/sh/SYS.h index cd5dbeaaf..cb3fd7ef1 100644 --- a/lib/libc/arch/sh/SYS.h +++ b/lib/libc/arch/sh/SYS.h @@ -1,4 +1,4 @@ -/* $OpenBSD: SYS.h,v 1.14 2023/12/10 16:45:52 deraadt Exp $ */ +/* $OpenBSD: SYS.h,v 1.15 2023/12/11 22:24:16 kettenis Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. * All rights reserved. @@ -87,6 +87,7 @@ #define PINSYSCALL(sysno, label) \ .pushsection .openbsd.syscalls,"",@progbits; \ + .p2align 2; \ .long label; \ .long sysno; \ .popsection; diff --git a/lib/libc/sys/Makefile.inc b/lib/libc/sys/Makefile.inc index f941b558d..3d23e9611 100644 --- a/lib/libc/sys/Makefile.inc +++ b/lib/libc/sys/Makefile.inc @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.inc,v 1.174 2023/08/20 15:17:53 visa Exp $ +# $OpenBSD: Makefile.inc,v 1.175 2023/12/11 00:34:24 deraadt Exp $ # $NetBSD: Makefile.inc,v 1.35 1995/10/16 23:49:07 jtc Exp $ # @(#)Makefile.inc 8.1 (Berkeley) 6/17/93 @@ -208,8 +208,8 @@ MAN+= __get_tcb.2 __thrsigdivert.2 __thrsleep.2 _exit.2 accept.2 \ mimmutable.2 minherit.2 mkdir.2 mkfifo.2 mknod.2 mlock.2 \ mlockall.2 mmap.2 mount.2 mprotect.2 mquery.2 msyscall.2 msgctl.2 \ msgget.2 msgrcv.2 msgsnd.2 msync.2 munmap.2 nanosleep.2 \ - nfssvc.2 open.2 pathconf.2 pinsyscall.2 pipe.2 pledge.2 poll.2 \ - profil.2 ptrace.2 quotactl.2 read.2 readlink.2 reboot.2 recv.2 \ + nfssvc.2 open.2 pathconf.2 pinsyscall.2 pinsyscalls.2 pipe.2 pledge.2 \ + poll.2 profil.2 ptrace.2 quotactl.2 read.2 readlink.2 reboot.2 recv.2 \ rename.2 revoke.2 rmdir.2 sched_yield.2 select.2 semctl.2 semget.2 \ semop.2 send.2 setgroups.2 setpgid.2 setregid.2 \ setresuid.2 setreuid.2 setsid.2 sendsyslog.2 setuid.2 shmat.2 \ diff --git a/lib/libc/sys/pinsyscalls.2 b/lib/libc/sys/pinsyscalls.2 new file mode 100644 index 000000000..bbbe4ab67 --- /dev/null +++ b/lib/libc/sys/pinsyscalls.2 @@ -0,0 +1,76 @@ +.\" $OpenBSD: pinsyscalls.2,v 1.1 2023/12/11 00:34:24 deraadt Exp $ +.\" +.\" Copyright (c) 2023 Theo de Raadt +.\" +.\" Permission to use, copy, modify, and distribute this software for any +.\" purpose with or without fee is hereby granted, provided that the above +.\" copyright notice and this permission notice appear in all copies. +.\" +.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +.\" +.Dd $Mdocdate: December 11 2023 $ +.Dt PINSYSCALLS 2 +.Os +.Sh NAME +.Nm pinsyscalls +.Nd pin system call entry to precise locations in the address space +.Sh SYNOPSIS +.In sys/types.h +.Ft int +.Fn pinsyscalls "void *start" "size_t len" "uint *pintable" "size_t pintablesize" +.Sh DESCRIPTION +The +.Fn pinsyscalls +system call specifies the +.Va start +to +.Va start + len +range in the address space where the system call entry instructions are found, +and furthermore provides a table of uint offsets from that +.Va start +(indexed by the system call number) to +provide the precise location for the system call instruction required +for that system call number. +.Pp +.Fn pinsyscalls +is only called by the shared library linker +.Xr ld.so 1 +to tell the kernel where system calls are found in the dynamic library +.Pa libc.so +(the filename is actually /usr/lib/libc.so.major.minor). +.Pp +A similar setup operation is done automatically by the kernel for +the system calls found in +.Xr ld.so 1 +and in static executables. +.Pp +Once the kernel knows the specific location in the address space where +a specific system call must be entered from, any attempt to use a different +system call entry instruction to perform a non-corresponding system call +operation will fail with signal +.Dv SIGABRT . +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +.Fn pinsyscalls +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +Process already has a system call pinning table loaded. +.It Bq Er EPERM +A static binary tried to call +.Fn pinsyscalls . +.It Bq Er ERANGE +At least one system call offset is out of bounds. +.El +.Sh HISTORY +The +.Fn pinsyscalls +system call first appeared in +.Ox 7.4 . diff --git a/libexec/ld.so/aarch64/SYS.h b/libexec/ld.so/aarch64/SYS.h index c308acf5b..4fcae52bc 100644 --- a/libexec/ld.so/aarch64/SYS.h +++ b/libexec/ld.so/aarch64/SYS.h @@ -1,4 +1,4 @@ -/* $OpenBSD: SYS.h,v 1.6 2023/12/10 16:45:50 deraadt Exp $ */ +/* $OpenBSD: SYS.h,v 1.7 2023/12/11 22:29:23 deraadt Exp $ */ /* * Copyright (c) 2016 Dale Rahn @@ -31,6 +31,7 @@ #define PINSYSCALL(sysno, label) \ .pushsection .openbsd.syscalls,"",@progbits ;\ + .p2align 2 ;\ .long label ;\ .long sysno ;\ .popsection diff --git a/libexec/ld.so/alpha/SYS.h b/libexec/ld.so/alpha/SYS.h index 3d0d14054..62b4d67b0 100644 --- a/libexec/ld.so/alpha/SYS.h +++ b/libexec/ld.so/alpha/SYS.h @@ -1,4 +1,4 @@ -/* $OpenBSD: SYS.h,v 1.4 2023/12/10 16:45:50 deraadt Exp $ */ +/* $OpenBSD: SYS.h,v 1.5 2023/12/11 22:29:24 deraadt Exp $ */ /* * Copyright (c) 2001 Niklas Hallqvist @@ -63,6 +63,7 @@ #define PINSYSCALL(sysno, label) \ .pushsection .openbsd.syscalls,"",@progbits ;\ + .p2align 2 ;\ .long label ;\ .long sysno ;\ .popsection diff --git a/libexec/ld.so/amd64/SYS.h b/libexec/ld.so/amd64/SYS.h index e160da920..51c055ef4 100644 --- a/libexec/ld.so/amd64/SYS.h +++ b/libexec/ld.so/amd64/SYS.h @@ -1,4 +1,4 @@ -/* $OpenBSD: SYS.h,v 1.4 2023/12/10 16:45:50 deraadt Exp $ */ +/* $OpenBSD: SYS.h,v 1.5 2023/12/11 22:29:24 deraadt Exp $ */ /* * Copyright (c) 2002,2004 Dale Rahn @@ -32,6 +32,7 @@ #define PINSYSCALL(sysno, label) \ .pushsection .openbsd.syscalls,"",@progbits ;\ + .p2align 2 ;\ .long label ;\ .long sysno ;\ .popsection diff --git a/libexec/ld.so/arm/SYS.h b/libexec/ld.so/arm/SYS.h index 79f59756e..46786154c 100644 --- a/libexec/ld.so/arm/SYS.h +++ b/libexec/ld.so/arm/SYS.h @@ -1,4 +1,4 @@ -/* $OpenBSD: SYS.h,v 1.4 2023/12/10 16:45:50 deraadt Exp $ */ +/* $OpenBSD: SYS.h,v 1.6 2023/12/11 22:29:24 deraadt Exp $ */ /* * Copyright (c) 2004 Dale Rahn @@ -30,7 +30,8 @@ #include #define PINSYSCALL(sysno, label) \ - .pushsection .openbsd.syscalls,"",@progbits ;\ + .pushsection .openbsd.syscalls,"",%progbits ;\ + .p2align 2 ;\ .long label ;\ .long sysno ;\ .popsection diff --git a/libexec/ld.so/hppa/SYS.h b/libexec/ld.so/hppa/SYS.h index 07707835a..403daa853 100644 --- a/libexec/ld.so/hppa/SYS.h +++ b/libexec/ld.so/hppa/SYS.h @@ -1,4 +1,4 @@ -/* $OpenBSD: SYS.h,v 1.2 2023/12/10 16:45:50 deraadt Exp $ */ +/* $OpenBSD: SYS.h,v 1.3 2023/12/11 22:29:24 deraadt Exp $ */ /* * Copyright (c) 2004 Michael Shalayeff @@ -35,6 +35,7 @@ #define PINSYSCALL(sysno, label) \ .pushsection .openbsd.syscalls,"",@progbits !\ + .p2align 2 !\ .long label !\ .long sysno !\ .popsection diff --git a/libexec/ld.so/i386/SYS.h b/libexec/ld.so/i386/SYS.h index b714c503b..7d09eb565 100644 --- a/libexec/ld.so/i386/SYS.h +++ b/libexec/ld.so/i386/SYS.h @@ -1,4 +1,4 @@ -/* $OpenBSD: SYS.h,v 1.2 2023/12/10 16:45:50 deraadt Exp $ */ +/* $OpenBSD: SYS.h,v 1.3 2023/12/11 22:29:24 deraadt Exp $ */ /* * Copyright (c) 2002 Dale Rahn @@ -32,6 +32,7 @@ #define PINSYSCALL(sysno, label) \ .pushsection .openbsd.syscalls,"",@progbits ;\ + .p2align 2 ;\ .long label ;\ .long sysno ;\ .popsection diff --git a/libexec/ld.so/m88k/SYS.h b/libexec/ld.so/m88k/SYS.h index c1528b2bc..0db37ef11 100644 --- a/libexec/ld.so/m88k/SYS.h +++ b/libexec/ld.so/m88k/SYS.h @@ -1,4 +1,4 @@ -/* $OpenBSD: SYS.h,v 1.5 2023/12/10 16:45:50 deraadt Exp $ */ +/* $OpenBSD: SYS.h,v 1.6 2023/12/11 22:29:24 deraadt Exp $ */ /* * Copyright (c) 2013 Miodrag Vallat. @@ -46,6 +46,7 @@ #define PINSYSCALL(sysno, label) \ .pushsection .openbsd.syscalls,"",@progbits ;\ + .p2align 2 ;\ .long label ;\ .long sysno ;\ .popsection diff --git a/libexec/ld.so/mips64/SYS.h b/libexec/ld.so/mips64/SYS.h index 1dbc8a7e0..1d5764f9a 100644 --- a/libexec/ld.so/mips64/SYS.h +++ b/libexec/ld.so/mips64/SYS.h @@ -1,4 +1,4 @@ -/* $OpenBSD: SYS.h,v 1.2 2023/12/10 16:45:50 deraadt Exp $ */ +/* $OpenBSD: SYS.h,v 1.3 2023/12/11 22:29:24 deraadt Exp $ */ /* * Copyright (c) 1998-2002 Opsycon AB, Sweden. @@ -31,6 +31,7 @@ #define PINSYSCALL(sysno, label) \ .pushsection .openbsd.syscalls,"",@progbits ;\ + .p2align 2 ;\ .long label ;\ .long sysno ;\ .popsection diff --git a/libexec/ld.so/powerpc/SYS.h b/libexec/ld.so/powerpc/SYS.h index 9da670134..ba2a0f964 100644 --- a/libexec/ld.so/powerpc/SYS.h +++ b/libexec/ld.so/powerpc/SYS.h @@ -1,4 +1,4 @@ -/* $OpenBSD: SYS.h,v 1.5 2023/12/10 16:45:50 deraadt Exp $ */ +/* $OpenBSD: SYS.h,v 1.6 2023/12/11 22:29:24 deraadt Exp $ */ /* * Copyright (c) 1999 Dale Rahn @@ -31,6 +31,7 @@ #define PINSYSCALL(sysno, label) \ .pushsection .openbsd.syscalls,"",@progbits ;\ + .p2align 2 ;\ .long label ;\ .long sysno ;\ .popsection diff --git a/libexec/ld.so/powerpc64/SYS.h b/libexec/ld.so/powerpc64/SYS.h index 7671f3606..a7c324136 100644 --- a/libexec/ld.so/powerpc64/SYS.h +++ b/libexec/ld.so/powerpc64/SYS.h @@ -1,4 +1,4 @@ -/* $OpenBSD: SYS.h,v 1.3 2023/12/10 16:45:50 deraadt Exp $ */ +/* $OpenBSD: SYS.h,v 1.4 2023/12/11 22:29:24 deraadt Exp $ */ /* * Copyright (c) 1999 Dale Rahn @@ -31,6 +31,7 @@ #define PINSYSCALL(sysno, label) \ .pushsection .openbsd.syscalls,"",@progbits ;\ + .p2align 2 ;\ .long label ;\ .long sysno ;\ .popsection diff --git a/libexec/ld.so/riscv64/SYS.h b/libexec/ld.so/riscv64/SYS.h index 3d6537fae..6bd81b756 100644 --- a/libexec/ld.so/riscv64/SYS.h +++ b/libexec/ld.so/riscv64/SYS.h @@ -1,4 +1,4 @@ -/* $OpenBSD: SYS.h,v 1.2 2023/12/10 16:45:50 deraadt Exp $ */ +/* $OpenBSD: SYS.h,v 1.3 2023/12/11 22:29:25 deraadt Exp $ */ /* * Copyright (c) 2016 Dale Rahn @@ -31,6 +31,7 @@ #define PINSYSCALL(sysno, label) \ .pushsection .openbsd.syscalls,"",@progbits ;\ + .p2align 2 ;\ .long label ;\ .long sysno ;\ .popsection diff --git a/libexec/ld.so/sh/SYS.h b/libexec/ld.so/sh/SYS.h index 4f9350229..df4333c09 100644 --- a/libexec/ld.so/sh/SYS.h +++ b/libexec/ld.so/sh/SYS.h @@ -1,4 +1,4 @@ -/* $OpenBSD: SYS.h,v 1.3 2023/12/10 16:45:50 deraadt Exp $ */ +/* $OpenBSD: SYS.h,v 1.4 2023/12/11 22:29:25 deraadt Exp $ */ /* * Copyright (c) 2006 Dale Rahn @@ -31,6 +31,7 @@ #define PINSYSCALL(sysno, label) \ .pushsection .openbsd.syscalls,"",@progbits ;\ + .p2align 2 ;\ .long label ;\ .long sysno ;\ .popsection diff --git a/libexec/ld.so/sparc64/SYS.h b/libexec/ld.so/sparc64/SYS.h index 7a29f2b57..fa7e8a97a 100644 --- a/libexec/ld.so/sparc64/SYS.h +++ b/libexec/ld.so/sparc64/SYS.h @@ -1,4 +1,4 @@ -/* $OpenBSD: SYS.h,v 1.5 2023/12/10 16:45:50 deraadt Exp $ */ +/* $OpenBSD: SYS.h,v 1.6 2023/12/11 22:29:25 deraadt Exp $ */ /* $NetBSD: rtld_start.S,v 1.5 2001/08/14 22:17:48 eeh Exp $ */ /* @@ -70,6 +70,7 @@ #define PINSYSCALL(sysno, label) \ .pushsection .openbsd.syscalls,"",@progbits ;\ + .p2align 2 ;\ .long label ;\ .long sysno ;\ .popsection diff --git a/regress/lib/libcrypto/evp/evp_test.c b/regress/lib/libcrypto/evp/evp_test.c index b1f7d59c2..cf50c15fc 100644 --- a/regress/lib/libcrypto/evp/evp_test.c +++ b/regress/lib/libcrypto/evp/evp_test.c @@ -1,4 +1,4 @@ -/* $OpenBSD: evp_test.c,v 1.10 2023/12/08 08:30:04 tb Exp $ */ +/* $OpenBSD: evp_test.c,v 1.11 2023/12/10 19:20:06 tb Exp $ */ /* * Copyright (c) 2022 Joel Sing * Copyright (c) 2023 Theo Buehler @@ -601,7 +601,6 @@ obj_name_cb(const OBJ_NAME *obj_name, void *do_all_arg) previous, obj_name->name); } - arg->failure |= arg_copy.failure; } diff --git a/share/man/man4/acpi.4 b/share/man/man4/acpi.4 index d77a16309..7472cdb21 100644 --- a/share/man/man4/acpi.4 +++ b/share/man/man4/acpi.4 @@ -1,4 +1,4 @@ -.\" $OpenBSD: acpi.4,v 1.72 2023/04/27 19:26:06 jmc Exp $ +.\" $OpenBSD: acpi.4,v 1.73 2023/12/11 15:21:14 jmc Exp $ .\" .\" Copyright (c) 2006 Alexander Yurchenko .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: April 27 2023 $ +.Dd $Mdocdate: December 11 2023 $ .Dt ACPI 4 .Os .Sh NAME @@ -98,6 +98,8 @@ ACPI video output ASUSTeK AI Booster ACPI ATK0110 temperature, voltage, and fan sensor .It Xr amdgpio 4 AMD GPIO controller +.It Xr ampchwm 4 +Ampere Altra fine-grained power telemetry .It Xr aplgpio 4 Intel Apollo Lake GPIO controller .It Xr asmc 4 diff --git a/share/man/man4/man4.arm64/Makefile b/share/man/man4/man4.arm64/Makefile index d765cfaa4..e0912e65f 100644 --- a/share/man/man4/man4.arm64/Makefile +++ b/share/man/man4/man4.arm64/Makefile @@ -1,6 +1,6 @@ -# $OpenBSD: Makefile,v 1.32 2022/12/17 12:02:00 kettenis Exp $ +# $OpenBSD: Makefile,v 1.33 2023/12/11 11:17:34 claudio Exp $ -MAN= agintc.4 agtimer.4 ampintc.4 \ +MAN= agintc.4 agtimer.4 ampchwm.4 ampintc.4 \ aplaudio.4 aplcpu.4 apldart.4 apldma.4 apldog.4 aplefuse.4 \ aplhidev.4 apliic.4 aplintc.4 aplmbox.4 aplmca.4 aplnco.4 aplns.4 \ aplpcie.4 aplpinctrl.4 aplpmgr.4 aplpmu.4 aplpwm.4 \ diff --git a/share/man/man4/man4.arm64/ampchwm.4 b/share/man/man4/man4.arm64/ampchwm.4 new file mode 100644 index 000000000..76555eacd --- /dev/null +++ b/share/man/man4/man4.arm64/ampchwm.4 @@ -0,0 +1,48 @@ +.\" $OpenBSD: ampchwm.4,v 1.2 2023/12/11 15:21:15 jmc Exp $ +.\" +.\" Copyright (c) 2023 Claudio Jeker +.\" +.\" Permission to use, copy, modify, and distribute this software for any +.\" purpose with or without fee is hereby granted, provided that the above +.\" copyright notice and this permission notice appear in all copies. +.\" +.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +.\" +.Dd $Mdocdate: December 11 2023 $ +.Dt AMPCHWM 4 arm64 +.Os +.Sh NAME +.Nm ampchwm +.Nd Ampere Altra fine-grained power telemetry +.Sh SYNOPSIS +.Cd "ampchwm* at acpi?" +.Sh DESCRIPTION +The +.Nm +driver provides support for the per-core power telemetry firmware interface +found on the Ampere Altra SoC. +.Pp +Sensor values are made available through the +.Xr sysctl 8 +interface. +.Sh SEE ALSO +.Xr intro 4 , +.Xr sensorsd 8 , +.Xr sysctl 8 +.Sh HISTORY +The +.Nm +driver first appeared in +.Ox 7.5 . +.Sh AUTHORS +.An -nosplit +The +.Nm +driver was written by +.An Claudio Jeker Aq Mt claudio@openbsd.org . diff --git a/sys/arch/amd64/amd64/vmm_machdep.c b/sys/arch/amd64/amd64/vmm_machdep.c index 82decbd3f..8d8557471 100644 --- a/sys/arch/amd64/amd64/vmm_machdep.c +++ b/sys/arch/amd64/amd64/vmm_machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vmm_machdep.c,v 1.11 2023/11/26 13:02:44 dv Exp $ */ +/* $OpenBSD: vmm_machdep.c,v 1.12 2023/12/10 21:25:14 dv Exp $ */ /* * Copyright (c) 2014 Mike Larkin * @@ -1055,6 +1055,7 @@ start_vmm_on_cpu(struct cpu_info *ci) { uint64_t msr; uint32_t cr4; + struct vmx_invept_descriptor vid; /* No VMM mode? exit. */ if ((ci->ci_vmm_flags & CI_VMM_VMX) == 0 && @@ -1081,11 +1082,6 @@ start_vmm_on_cpu(struct cpu_info *ci) ci->ci_vmxon_region->vr_revision = ci->ci_vmm_cap.vcc_vmx.vmx_vmxon_revision; - /* Set CR4.VMXE */ - cr4 = rcr4(); - cr4 |= CR4_VMXE; - lcr4(cr4); - /* Enable VMX */ msr = rdmsr(MSR_IA32_FEATURE_CONTROL); if (msr & IA32_FEATURE_CONTROL_LOCK) { @@ -1097,9 +1093,18 @@ start_vmm_on_cpu(struct cpu_info *ci) wrmsr(MSR_IA32_FEATURE_CONTROL, msr); } - /* Enter VMX mode */ + /* Set CR4.VMXE */ + cr4 = rcr4(); + cr4 |= CR4_VMXE; + lcr4(cr4); + + /* Enter VMX mode and clear EPTs on this cpu */ if (vmxon((uint64_t *)&ci->ci_vmxon_region_pa)) - return; + panic("vmxon failed"); + + memset(&vid, 0, sizeof(vid)); + if (invept(IA32_VMX_INVEPT_GLOBAL_CTX, &vid)) + panic("invept failed"); } } diff --git a/sys/arch/amd64/include/pmap.h b/sys/arch/amd64/include/pmap.h index e60ee9ceb..211fba595 100644 --- a/sys/arch/amd64/include/pmap.h +++ b/sys/arch/amd64/include/pmap.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pmap.h,v 1.86 2023/04/13 15:23:21 miod Exp $ */ +/* $OpenBSD: pmap.h,v 1.87 2023/12/11 22:12:52 kettenis Exp $ */ /* $NetBSD: pmap.h,v 1.1 2003/04/26 18:39:46 fvdl Exp $ */ /* @@ -375,6 +375,7 @@ extern const long nbpd[], nkptpmax[]; #define pmap_valid_entry(E) ((E) & PG_V) /* is PDE or PTE valid? */ #define pmap_proc_iflush(p,va,len) /* nothing */ +#define pmap_init_percpu() do { /* nothing */ } while (0) #define pmap_unuse_final(p) /* nothing */ #define pmap_remove_holes(vm) do { /* nothing */ } while (0) diff --git a/sys/arch/arm/include/pmap.h b/sys/arch/arm/include/pmap.h index 284bca166..7ae17811e 100644 --- a/sys/arch/arm/include/pmap.h +++ b/sys/arch/arm/include/pmap.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pmap.h,v 1.54 2023/04/13 15:23:22 miod Exp $ */ +/* $OpenBSD: pmap.h,v 1.55 2023/12/11 22:12:53 kettenis Exp $ */ /* $NetBSD: pmap.h,v 1.76 2003/09/06 09:10:46 rearnsha Exp $ */ /* @@ -241,6 +241,7 @@ extern struct pmap kernel_pmap_store; #define pmap_deactivate(p) do { /* nothing */ } while (0) +#define pmap_init_percpu() do { /* nothing */ } while (0) #define pmap_unuse_final(p) do { /* nothing */ } while (0) #define pmap_remove_holes(vm) do { /* nothing */ } while (0) diff --git a/sys/arch/arm64/arm64/pmap.c b/sys/arch/arm64/arm64/pmap.c index e40c0e874..0bdf6b3c5 100644 --- a/sys/arch/arm64/arm64/pmap.c +++ b/sys/arch/arm64/arm64/pmap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pmap.c,v 1.99 2023/08/10 19:29:32 kettenis Exp $ */ +/* $OpenBSD: pmap.c,v 1.100 2023/12/11 22:12:53 kettenis Exp $ */ /* * Copyright (c) 2008-2009,2014-2016 Dale Rahn * @@ -1872,6 +1872,13 @@ pmap_postinit(void) npages * PAGE_SIZE, VM_MAP_INTRSAFE, FALSE, NULL); } +void +pmap_init_percpu(void) +{ + pool_cache_init(&pmap_pted_pool); + pool_cache_init(&pmap_vp_pool); +} + void pmap_update(pmap_t pm) { diff --git a/sys/arch/arm64/conf/GENERIC b/sys/arch/arm64/conf/GENERIC index 1f9b08cac..41f70a58f 100644 --- a/sys/arch/arm64/conf/GENERIC +++ b/sys/arch/arm64/conf/GENERIC @@ -1,4 +1,4 @@ -# $OpenBSD: GENERIC,v 1.277 2023/07/22 22:43:53 patrick Exp $ +# $OpenBSD: GENERIC,v 1.278 2023/12/11 11:15:44 claudio Exp $ # # GENERIC machine description file # @@ -52,6 +52,7 @@ acpiiort* at acpi? smmu* at acpiiort? acpipci* at acpi? pci* at acpipci? +ampchwm* at acpi? acpipwrres* at acpi? acpitz* at acpi? ahci* at acpi? diff --git a/sys/arch/arm64/conf/files.arm64 b/sys/arch/arm64/conf/files.arm64 index 9ec032f24..4414dd8d9 100644 --- a/sys/arch/arm64/conf/files.arm64 +++ b/sys/arch/arm64/conf/files.arm64 @@ -1,4 +1,4 @@ -# $OpenBSD: files.arm64,v 1.66 2023/01/14 12:11:11 kettenis Exp $ +# $OpenBSD: files.arm64,v 1.67 2023/12/11 11:15:44 claudio Exp $ maxpartitions 16 maxusers 2 8 128 @@ -279,6 +279,10 @@ file arch/arm64/dev/acpipci.c acpipci attach smmu at acpiiort with smmu_acpi file arch/arm64/dev/smmu_acpi.c smmu_acpi +device ampchwm +attach ampchwm at acpi +file arch/arm64/dev/ampchwm.c ampchwm + device apm attach apm at mainbus file arch/arm64/dev/apm.c apm needs-flag diff --git a/sys/arch/arm64/dev/ampchwm.c b/sys/arch/arm64/dev/ampchwm.c new file mode 100644 index 000000000..2115e0d40 --- /dev/null +++ b/sys/arch/arm64/dev/ampchwm.c @@ -0,0 +1,272 @@ +/* $OpenBSD: ampchwm.c,v 1.1 2023/12/11 11:15:44 claudio Exp $ */ +/* + * Copyright (c) 2023 Claudio Jeker + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +int ampchwm_match(struct device *, void *, void *); +void ampchwm_attach(struct device *, struct device *, void *); + +#define HWMON_ID 0x304d5748 +#define HWMON_UNIT_CELSIUS 0x01 +#define HWMON_UNIT_JOULES 0x10 +#define HWMON_UNIT_MILIJOULES 0x11 +#define HWMON_UNIT_MICROJOULES 0x12 +#define HWMON_MAX_METRIC_COUNT 2 + +union metrics_hdr { + uint64_t data; + struct { + uint32_t id; + uint16_t version; + uint16_t count; + }; +}; + +union metric_hdr { + uint64_t data[3]; + struct { + char label[16]; + uint8_t unit; + uint8_t data_size; + uint16_t data_count; + uint32_t pad; + }; +}; + + +struct ampchwm_softc { + struct device sc_dev; + struct acpi_softc *sc_acpi; + struct aml_node *sc_node; + + bus_space_tag_t sc_iot; + bus_space_handle_t sc_ioh; + size_t sc_size; + + uint16_t sc_count; + struct { + struct ksensor *sc_sens; + uint16_t sc_sens_offset; + uint16_t sc_sens_count; + uint16_t sc_sens_size; + uint16_t sc_sens_unit; + } sc_metrics[HWMON_MAX_METRIC_COUNT]; + + struct ksensordev sc_sensdev; + struct sensor_task *sc_sens_task; +}; + +const struct cfattach ampchwm_ca = { + sizeof(struct ampchwm_softc), ampchwm_match, ampchwm_attach +}; + +struct cfdriver ampchwm_cd = { + NULL, "ampchwm", DV_DULL +}; + +const char *ampchwm_hids[] = { + "AMPC0005", + NULL +}; + +int ampchwm_attach_sensors(struct ampchwm_softc *, int, + union metric_hdr *, uint16_t *); +void ampchwm_refresh_sensors(void *); +void ampchwm_update_sensor(struct ampchwm_softc *, int, int); + + +int +ampchwm_match(struct device *parent, void *match, void *aux) +{ + struct acpi_attach_args *aaa = aux; + struct cfdata *cf = match; + + if (aaa->aaa_naddr < 1) + return (0); + return (acpi_matchhids(aaa, ampchwm_hids, cf->cf_driver->cd_name)); +} + +void +ampchwm_attach(struct device *parent, struct device *self, void *aux) +{ + struct ampchwm_softc *sc = (struct ampchwm_softc *)self; + struct acpi_attach_args *aaa = aux; + union metrics_hdr hdr; + union metric_hdr metric; + uint16_t offset = 0; + int i; + + sc->sc_acpi = (struct acpi_softc *)parent; + sc->sc_node = aaa->aaa_node; + + printf(" %s", sc->sc_node->name); + printf(" addr 0x%llx/0x%llx", aaa->aaa_addr[0], aaa->aaa_size[0]); + + sc->sc_iot = aaa->aaa_bst[0]; + sc->sc_size = aaa->aaa_size[0]; + + if (bus_space_map(sc->sc_iot, aaa->aaa_addr[0], aaa->aaa_size[0], + 0, &sc->sc_ioh)) { + printf(": can't map registers\n"); + return; + } + + bus_space_read_region_8(sc->sc_iot, sc->sc_ioh, offset, &hdr.data, 1); + + if (hdr.id != HWMON_ID) { + printf(": bad id %x\n", hdr.id); + goto unmap; + } + + printf(": ver %d", hdr.version); + + strlcpy(sc->sc_sensdev.xname, sc->sc_dev.dv_xname, + sizeof(sc->sc_sensdev.xname)); + + offset += sizeof(hdr); + for (i = 0; i < hdr.count; i++) { + bus_space_read_region_8(sc->sc_iot, sc->sc_ioh, offset, + metric.data, 3); + if (ampchwm_attach_sensors(sc, i, &metric, &offset)) + goto unmap; + } + sc->sc_count = MIN(hdr.count, HWMON_MAX_METRIC_COUNT); + + sensordev_install(&sc->sc_sensdev); + sc->sc_sens_task = sensor_task_register(sc, ampchwm_refresh_sensors, 1); + printf("\n"); + + return; +unmap: + bus_space_unmap(sc->sc_iot, sc->sc_ioh, sc->sc_size); + return; +} + +int +ampchwm_attach_sensors(struct ampchwm_softc *sc, int num, + union metric_hdr *metric, uint16_t *offsetp) +{ + uint16_t off = *offsetp; + int i, count = 0; + + if (num >= HWMON_MAX_METRIC_COUNT) { + if (num == HWMON_MAX_METRIC_COUNT) + printf(" ignoring extra metrics"); + return 0; + } + + off += sizeof(*metric); + /* skip 0 values since those are disabled cores */ + for (i = 0; i < metric->data_count; i++) { + if (bus_space_read_8(sc->sc_iot, sc->sc_ioh, + off + i * 8) == 0) + continue; + count++; + } + + sc->sc_metrics[num].sc_sens = mallocarray(count, + sizeof(struct ksensor), M_DEVBUF, M_NOWAIT); + if (sc->sc_metrics[num].sc_sens == NULL) { + printf(" out of memory\n"); + return -1; + } + + sc->sc_metrics[num].sc_sens_offset = off; + sc->sc_metrics[num].sc_sens_count = count; + sc->sc_metrics[num].sc_sens_unit = metric->unit; + if (metric->data_size == 0) + sc->sc_metrics[num].sc_sens_size = 8; + else + sc->sc_metrics[num].sc_sens_size = 4; + + for (i = 0; i < count; i++) { + struct ksensor *s = &sc->sc_metrics[num].sc_sens[i]; + + strlcpy(s->desc, metric->label, sizeof(s->desc)); + if (metric->unit == HWMON_UNIT_CELSIUS) + s->type = SENSOR_TEMP; + else + s->type = SENSOR_ENERGY; + sensor_attach(&sc->sc_sensdev, s); + + ampchwm_update_sensor(sc, num, i); + } + + off += metric->data_count * 8; + + printf(", %d \"%s\"", count, metric->label); + *offsetp = off; + return 0; +} + +void +ampchwm_refresh_sensors(void *arg) +{ + struct ampchwm_softc *sc = arg; + int num, i; + + for (num = 0; num < sc->sc_count; num++) + for (i = 0; i < sc->sc_metrics[num].sc_sens_count; i++) + ampchwm_update_sensor(sc, num, i); +} + +void +ampchwm_update_sensor(struct ampchwm_softc *sc, int num, int i) +{ + struct ksensor *s; + uint64_t v; + + KASSERT(i < sc->sc_metrics[num].sc_sens_count); + + s = &sc->sc_metrics[num].sc_sens[i]; + if (sc->sc_metrics[num].sc_sens_size == 8) { + v = bus_space_read_8(sc->sc_iot, sc->sc_ioh, + sc->sc_metrics[num].sc_sens_offset + i * sizeof(v)); + } else { + v = bus_space_read_4(sc->sc_iot, sc->sc_ioh, + sc->sc_metrics[num].sc_sens_offset + i * sizeof(v)); + } + + if (v == 0) { + s->flags = SENSOR_FUNKNOWN; + s->status = SENSOR_S_UNKNOWN; + } else { + s->flags = 0; + s->status = SENSOR_S_OK; + } + + switch (sc->sc_metrics[num].sc_sens_unit) { + case HWMON_UNIT_CELSIUS: + s->value = v * 1000 * 1000 + 273150000; + break; + case HWMON_UNIT_JOULES: + v *= 1000; + case HWMON_UNIT_MILIJOULES: + v *= 1000; + case HWMON_UNIT_MICROJOULES: + s->value = v; + break; + } +} diff --git a/sys/arch/arm64/include/pmap.h b/sys/arch/arm64/include/pmap.h index edb0789f5..2aef08193 100644 --- a/sys/arch/arm64/include/pmap.h +++ b/sys/arch/arm64/include/pmap.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pmap.h,v 1.24 2023/06/10 19:30:48 kettenis Exp $ */ +/* $OpenBSD: pmap.h,v 1.25 2023/12/11 22:12:53 kettenis Exp $ */ /* * Copyright (c) 2008,2009,2014 Dale Rahn * @@ -101,6 +101,9 @@ extern struct pmap kernel_pmap_; vaddr_t pmap_bootstrap(long kvo, paddr_t lpt1, long kernelstart, long kernelend, long ram_start, long ram_end); +void pmap_postinit(void); +void pmap_init_percpu(void); + void pmap_kenter_cache(vaddr_t va, paddr_t pa, vm_prot_t prot, int cacheable); void pmap_page_ro(pmap_t pm, vaddr_t va, vm_prot_t prot); void pmap_page_rw(pmap_t pm, vaddr_t va); @@ -118,7 +121,6 @@ struct pv_entry; /* investigate */ #define pmap_unuse_final(p) do { /* nothing */ } while (0) int pmap_fault_fixup(pmap_t, vaddr_t, vm_prot_t); -void pmap_postinit(void); #define __HAVE_PMAP_MPSAFE_ENTER_COW diff --git a/sys/arch/i386/include/pmap.h b/sys/arch/i386/include/pmap.h index f552c7c5b..e7e222bea 100644 --- a/sys/arch/i386/include/pmap.h +++ b/sys/arch/i386/include/pmap.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pmap.h,v 1.93 2023/04/13 15:23:22 miod Exp $ */ +/* $OpenBSD: pmap.h,v 1.94 2023/12/11 22:12:53 kettenis Exp $ */ /* $NetBSD: pmap.h,v 1.44 2000/04/24 17:18:18 thorpej Exp $ */ /* @@ -210,6 +210,7 @@ extern struct pool pmap_pv_pool; #define pmap_valid_entry(E) ((E) & PG_V) /* is PDE or PTE valid? */ #define pmap_proc_iflush(p,va,len) /* nothing */ +#define pmap_init_percpu() do { /* nothing */ } while (0) #define pmap_unuse_final(p) /* nothing */ #define pmap_remove_holes(vm) do { /* nothing */ } while (0) diff --git a/sys/dev/ic/nvmereg.h b/sys/dev/ic/nvmereg.h index 180dbbf7e..92395cd0b 100644 --- a/sys/dev/ic/nvmereg.h +++ b/sys/dev/ic/nvmereg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: nvmereg.h,v 1.11 2016/11/15 12:01:11 mpi Exp $ */ +/* $OpenBSD: nvmereg.h,v 1.12 2023/12/11 14:27:09 krw Exp $ */ /* * Copyright (c) 2014 David Gwynne @@ -204,12 +204,12 @@ struct nvme_cqe { u_int16_t flags; #define NVME_CQE_DNR (1 << 15) #define NVME_CQE_M (1 << 14) -#define NVME_CQE_SCT(_f) ((_f) & (0x07 << 8)) -#define NVME_CQE_SCT_GENERIC (0x00 << 8) -#define NVME_CQE_SCT_COMMAND (0x01 << 8) -#define NVME_CQE_SCT_MEDIAERR (0x02 << 8) -#define NVME_CQE_SCT_VENDOR (0x07 << 8) -#define NVME_CQE_SC(_f) ((_f) & (0x7f << 1)) +#define NVME_CQE_SCT(_f) ((_f) & (0x07 << 9)) +#define NVME_CQE_SCT_GENERIC (0x00 << 9) +#define NVME_CQE_SCT_COMMAND (0x01 << 9) +#define NVME_CQE_SCT_MEDIAERR (0x02 << 9) +#define NVME_CQE_SCT_VENDOR (0x07 << 9) +#define NVME_CQE_SC(_f) ((_f) & (0xff << 1)) #define NVME_CQE_SC_SUCCESS (0x00 << 1) #define NVME_CQE_SC_INVALID_OPCODE (0x01 << 1) #define NVME_CQE_SC_INVALID_FIELD (0x02 << 1) diff --git a/sys/dev/pci/drm/amd/amdgpu/amdgpu_drv.c b/sys/dev/pci/drm/amd/amdgpu/amdgpu_drv.c index 54a9b67bb..55ac12d9e 100644 --- a/sys/dev/pci/drm/amd/amdgpu/amdgpu_drv.c +++ b/sys/dev/pci/drm/amd/amdgpu/amdgpu_drv.c @@ -2205,6 +2205,8 @@ retry_init: pm_runtime_mark_last_busy(ddev->dev); pm_runtime_put_autosuspend(ddev->dev); + pci_wake_from_d3(pdev, TRUE); + /* * For runpm implemented via BACO, PMFW will handle the * timing for BACO in and out: diff --git a/sys/dev/pci/drm/amd/amdgpu/gfx_v11_0.c b/sys/dev/pci/drm/amd/amdgpu/gfx_v11_0.c index e7c03a018..f08f49974 100644 --- a/sys/dev/pci/drm/amd/amdgpu/gfx_v11_0.c +++ b/sys/dev/pci/drm/amd/amdgpu/gfx_v11_0.c @@ -82,6 +82,10 @@ MODULE_FIRMWARE("amdgpu/gc_11_0_4_me.bin"); MODULE_FIRMWARE("amdgpu/gc_11_0_4_mec.bin"); MODULE_FIRMWARE("amdgpu/gc_11_0_4_rlc.bin"); +static const struct soc15_reg_golden golden_settings_gc_11_0[] = { + SOC15_REG_GOLDEN_VALUE(GC, 0, regTCP_CNTL, 0x20000000, 0x20000000) +}; + static const struct soc15_reg_golden golden_settings_gc_11_0_1[] = { SOC15_REG_GOLDEN_VALUE(GC, 0, regCGTT_GS_NGG_CLK_CTRL, 0x9fff8fff, 0x00000010), @@ -274,6 +278,10 @@ static void gfx_v11_0_init_golden_registers(struct amdgpu_device *adev) default: break; } + soc15_program_register_sequence(adev, + golden_settings_gc_11_0, + (const u32)ARRAY_SIZE(golden_settings_gc_11_0)); + } static void gfx_v11_0_write_data_to_reg(struct amdgpu_ring *ring, int eng_sel, diff --git a/sys/dev/pci/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/sys/dev/pci/drm/amd/display/amdgpu_dm/amdgpu_dm.c index 4074c1c9e..8f4b44f43 100644 --- a/sys/dev/pci/drm/amd/display/amdgpu_dm/amdgpu_dm.c +++ b/sys/dev/pci/drm/amd/display/amdgpu_dm/amdgpu_dm.c @@ -6151,7 +6151,7 @@ int amdgpu_dm_connector_atomic_set_property(struct drm_connector *connector, dm_new_state->underscan_enable = val; ret = 0; } else if (property == adev->mode_info.abm_level_property) { - dm_new_state->abm_level = val; + dm_new_state->abm_level = val ?: ABM_LEVEL_IMMEDIATE_DISABLE; ret = 0; } @@ -6196,7 +6196,8 @@ int amdgpu_dm_connector_atomic_get_property(struct drm_connector *connector, *val = dm_state->underscan_enable; ret = 0; } else if (property == adev->mode_info.abm_level_property) { - *val = dm_state->abm_level; + *val = (dm_state->abm_level != ABM_LEVEL_IMMEDIATE_DISABLE) ? + dm_state->abm_level : 0; ret = 0; } @@ -6276,7 +6277,8 @@ void amdgpu_dm_connector_funcs_reset(struct drm_connector *connector) state->pbn = 0; if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) - state->abm_level = amdgpu_dm_abm_level; + state->abm_level = amdgpu_dm_abm_level ?: + ABM_LEVEL_IMMEDIATE_DISABLE; __drm_atomic_helper_connector_reset(connector, &state->base); } diff --git a/sys/dev/pci/drm/amd/display/dc/dc.h b/sys/dev/pci/drm/amd/display/dc/dc.h index 0dc4a9d1d..f50e28730 100644 --- a/sys/dev/pci/drm/amd/display/dc/dc.h +++ b/sys/dev/pci/drm/amd/display/dc/dc.h @@ -499,9 +499,12 @@ enum dcn_zstate_support_state { DCN_ZSTATE_SUPPORT_ALLOW_Z10_ONLY, DCN_ZSTATE_SUPPORT_DISALLOW, }; -/* - * For any clocks that may differ per pipe - * only the max is stored in this structure + +/** + * dc_clocks - DC pipe clocks + * + * For any clocks that may differ per pipe only the max is stored in this + * structure */ struct dc_clocks { int dispclk_khz; @@ -528,6 +531,16 @@ struct dc_clocks { bool prev_p_state_change_support; bool fclk_prev_p_state_change_support; int num_ways; + + /** + * @fw_based_mclk_switching + * + * DC has a mechanism that leverage the variable refresh rate to switch + * memory clock in cases that we have a large latency to achieve the + * memory clock change and a short vblank window. DC has some + * requirements to enable this feature, and this field describes if the + * system support or not such a feature. + */ bool fw_based_mclk_switching; bool fw_based_mclk_switching_shut_down; int prev_num_ways; diff --git a/sys/dev/pci/drm/amd/display/dc/dc_stream.h b/sys/dev/pci/drm/amd/display/dc/dc_stream.h index cb8d2410a..03f0a39c6 100644 --- a/sys/dev/pci/drm/amd/display/dc/dc_stream.h +++ b/sys/dev/pci/drm/amd/display/dc/dc_stream.h @@ -202,7 +202,18 @@ struct dc_stream_state { bool use_vsc_sdp_for_colorimetry; bool ignore_msa_timing_param; + /** + * @allow_freesync: + * + * It say if Freesync is enabled or not. + */ bool allow_freesync; + + /** + * @vrr_active_variable: + * + * It describes if VRR is in use. + */ bool vrr_active_variable; bool freesync_on_desktop; diff --git a/sys/dev/pci/drm/amd/display/dc/dcn10/dcn10_cm_common.c b/sys/dev/pci/drm/amd/display/dc/dcn10/dcn10_cm_common.c index 7a00fe525..3538973bd 100644 --- a/sys/dev/pci/drm/amd/display/dc/dcn10/dcn10_cm_common.c +++ b/sys/dev/pci/drm/amd/display/dc/dcn10/dcn10_cm_common.c @@ -308,7 +308,10 @@ bool cm_helper_convert_to_custom_float( #define NUMBER_REGIONS 32 #define NUMBER_SW_SEGMENTS 16 -bool cm_helper_translate_curve_to_hw_format( +#define DC_LOGGER \ + ctx->logger + +bool cm_helper_translate_curve_to_hw_format(struct dc_context *ctx, const struct dc_transfer_func *output_tf, struct pwl_params *lut_params, bool fixpoint) { @@ -482,10 +485,18 @@ bool cm_helper_translate_curve_to_hw_format( rgb->delta_green = dc_fixpt_sub(rgb_plus_1->green, rgb->green); rgb->delta_blue = dc_fixpt_sub(rgb_plus_1->blue, rgb->blue); + if (fixpoint == true) { - rgb->delta_red_reg = dc_fixpt_clamp_u0d10(rgb->delta_red); - rgb->delta_green_reg = dc_fixpt_clamp_u0d10(rgb->delta_green); - rgb->delta_blue_reg = dc_fixpt_clamp_u0d10(rgb->delta_blue); + uint32_t red_clamp = dc_fixpt_clamp_u0d14(rgb->delta_red); + uint32_t green_clamp = dc_fixpt_clamp_u0d14(rgb->delta_green); + uint32_t blue_clamp = dc_fixpt_clamp_u0d14(rgb->delta_blue); + + if (red_clamp >> 10 || green_clamp >> 10 || blue_clamp >> 10) + DC_LOG_WARNING("Losing delta precision while programming shaper LUT."); + + rgb->delta_red_reg = red_clamp & 0x3ff; + rgb->delta_green_reg = green_clamp & 0x3ff; + rgb->delta_blue_reg = blue_clamp & 0x3ff; rgb->red_reg = dc_fixpt_clamp_u0d14(rgb->red); rgb->green_reg = dc_fixpt_clamp_u0d14(rgb->green); rgb->blue_reg = dc_fixpt_clamp_u0d14(rgb->blue); diff --git a/sys/dev/pci/drm/amd/display/dc/dcn10/dcn10_cm_common.h b/sys/dev/pci/drm/amd/display/dc/dcn10/dcn10_cm_common.h index 3b8cd7410..0a68b63d6 100644 --- a/sys/dev/pci/drm/amd/display/dc/dcn10/dcn10_cm_common.h +++ b/sys/dev/pci/drm/amd/display/dc/dcn10/dcn10_cm_common.h @@ -106,6 +106,7 @@ bool cm_helper_convert_to_custom_float( bool fixpoint); bool cm_helper_translate_curve_to_hw_format( + struct dc_context *ctx, const struct dc_transfer_func *output_tf, struct pwl_params *lut_params, bool fixpoint); diff --git a/sys/dev/pci/drm/amd/display/dc/dcn10/dcn10_hw_sequencer.c b/sys/dev/pci/drm/amd/display/dc/dcn10/dcn10_hw_sequencer.c index 394027118..d84579da6 100644 --- a/sys/dev/pci/drm/amd/display/dc/dcn10/dcn10_hw_sequencer.c +++ b/sys/dev/pci/drm/amd/display/dc/dcn10/dcn10_hw_sequencer.c @@ -1867,7 +1867,7 @@ bool dcn10_set_output_transfer_func(struct dc *dc, struct pipe_ctx *pipe_ctx, /* dcn10_translate_regamma_to_hw_format takes 750us, only do it when full * update. */ - else if (cm_helper_translate_curve_to_hw_format( + else if (cm_helper_translate_curve_to_hw_format(dc->ctx, stream->out_transfer_func, &dpp->regamma_params, false)) { dpp->funcs->dpp_program_regamma_pwl( diff --git a/sys/dev/pci/drm/amd/display/dc/dcn20/dcn20_hwseq.c b/sys/dev/pci/drm/amd/display/dc/dcn20/dcn20_hwseq.c index fbc188812..9bd6a5716 100644 --- a/sys/dev/pci/drm/amd/display/dc/dcn20/dcn20_hwseq.c +++ b/sys/dev/pci/drm/amd/display/dc/dcn20/dcn20_hwseq.c @@ -843,7 +843,7 @@ bool dcn20_set_output_transfer_func(struct dc *dc, struct pipe_ctx *pipe_ctx, params = &stream->out_transfer_func->pwl; else if (pipe_ctx->stream->out_transfer_func->type == TF_TYPE_DISTRIBUTED_POINTS && - cm_helper_translate_curve_to_hw_format( + cm_helper_translate_curve_to_hw_format(dc->ctx, stream->out_transfer_func, &mpc->blender_params, false)) params = &mpc->blender_params; @@ -872,7 +872,7 @@ bool dcn20_set_blend_lut( if (plane_state->blend_tf->type == TF_TYPE_HWPWL) blend_lut = &plane_state->blend_tf->pwl; else if (plane_state->blend_tf->type == TF_TYPE_DISTRIBUTED_POINTS) { - cm_helper_translate_curve_to_hw_format( + cm_helper_translate_curve_to_hw_format(plane_state->ctx, plane_state->blend_tf, &dpp_base->regamma_params, false); blend_lut = &dpp_base->regamma_params; @@ -894,7 +894,7 @@ bool dcn20_set_shaper_3dlut( if (plane_state->in_shaper_func->type == TF_TYPE_HWPWL) shaper_lut = &plane_state->in_shaper_func->pwl; else if (plane_state->in_shaper_func->type == TF_TYPE_DISTRIBUTED_POINTS) { - cm_helper_translate_curve_to_hw_format( + cm_helper_translate_curve_to_hw_format(plane_state->ctx, plane_state->in_shaper_func, &dpp_base->shaper_params, true); shaper_lut = &dpp_base->shaper_params; diff --git a/sys/dev/pci/drm/amd/display/dc/dcn30/dcn30_dwb_cm.c b/sys/dev/pci/drm/amd/display/dc/dcn30/dcn30_dwb_cm.c index 6a3d3a0ec..701c7d8bc 100644 --- a/sys/dev/pci/drm/amd/display/dc/dcn30/dcn30_dwb_cm.c +++ b/sys/dev/pci/drm/amd/display/dc/dcn30/dcn30_dwb_cm.c @@ -280,7 +280,7 @@ bool dwb3_ogam_set_input_transfer_func( dwb_ogam_lut = kzalloc(sizeof(*dwb_ogam_lut), GFP_KERNEL); if (dwb_ogam_lut) { - cm_helper_translate_curve_to_hw_format( + cm_helper_translate_curve_to_hw_format(dwbc->ctx, in_transfer_func_dwb_ogam, dwb_ogam_lut, false); diff --git a/sys/dev/pci/drm/amd/display/dc/dcn30/dcn30_hwseq.c b/sys/dev/pci/drm/amd/display/dc/dcn30/dcn30_hwseq.c index a1b312483..53262f6bc 100644 --- a/sys/dev/pci/drm/amd/display/dc/dcn30/dcn30_hwseq.c +++ b/sys/dev/pci/drm/amd/display/dc/dcn30/dcn30_hwseq.c @@ -91,8 +91,8 @@ bool dcn30_set_blend_lut( return result; } -static bool dcn30_set_mpc_shaper_3dlut( - struct pipe_ctx *pipe_ctx, const struct dc_stream_state *stream) +static bool dcn30_set_mpc_shaper_3dlut(struct pipe_ctx *pipe_ctx, + const struct dc_stream_state *stream) { struct dpp *dpp_base = pipe_ctx->plane_res.dpp; int mpcc_id = pipe_ctx->plane_res.hubp->inst; @@ -104,19 +104,18 @@ static bool dcn30_set_mpc_shaper_3dlut( const struct pwl_params *shaper_lut = NULL; //get the shaper lut params if (stream->func_shaper) { - if (stream->func_shaper->type == TF_TYPE_HWPWL) + if (stream->func_shaper->type == TF_TYPE_HWPWL) { shaper_lut = &stream->func_shaper->pwl; - else if (stream->func_shaper->type == TF_TYPE_DISTRIBUTED_POINTS) { - cm_helper_translate_curve_to_hw_format( - stream->func_shaper, - &dpp_base->shaper_params, true); + } else if (stream->func_shaper->type == TF_TYPE_DISTRIBUTED_POINTS) { + cm_helper_translate_curve_to_hw_format(stream->ctx, stream->func_shaper, + &dpp_base->shaper_params, true); shaper_lut = &dpp_base->shaper_params; } } if (stream->lut3d_func && - stream->lut3d_func->state.bits.initialized == 1 && - stream->lut3d_func->state.bits.rmu_idx_valid == 1) { + stream->lut3d_func->state.bits.initialized == 1 && + stream->lut3d_func->state.bits.rmu_idx_valid == 1) { if (stream->lut3d_func->state.bits.rmu_mux_num == 0) mpcc_id_projected = stream->lut3d_func->state.bits.mpc_rmu0_mux; else if (stream->lut3d_func->state.bits.rmu_mux_num == 1) @@ -125,20 +124,22 @@ static bool dcn30_set_mpc_shaper_3dlut( mpcc_id_projected = stream->lut3d_func->state.bits.mpc_rmu2_mux; if (mpcc_id_projected != mpcc_id) BREAK_TO_DEBUGGER(); - /*find the reason why logical layer assigned a differant mpcc_id into acquire_post_bldn_3dlut*/ + /* find the reason why logical layer assigned a different + * mpcc_id into acquire_post_bldn_3dlut + */ acquired_rmu = mpc->funcs->acquire_rmu(mpc, mpcc_id, - stream->lut3d_func->state.bits.rmu_mux_num); + stream->lut3d_func->state.bits.rmu_mux_num); if (acquired_rmu != stream->lut3d_func->state.bits.rmu_mux_num) BREAK_TO_DEBUGGER(); - result = mpc->funcs->program_3dlut(mpc, - &stream->lut3d_func->lut_3d, - stream->lut3d_func->state.bits.rmu_mux_num); - result = mpc->funcs->program_shaper(mpc, shaper_lut, - stream->lut3d_func->state.bits.rmu_mux_num); - } else - /*loop through the available mux and release the requested mpcc_id*/ - mpc->funcs->release_rmu(mpc, mpcc_id); + result = mpc->funcs->program_3dlut(mpc, &stream->lut3d_func->lut_3d, + stream->lut3d_func->state.bits.rmu_mux_num); + result = mpc->funcs->program_shaper(mpc, shaper_lut, + stream->lut3d_func->state.bits.rmu_mux_num); + } else { + // loop through the available mux and release the requested mpcc_id + mpc->funcs->release_rmu(mpc, mpcc_id); + } return result; } diff --git a/sys/dev/pci/drm/amd/display/dc/dcn314/dcn314_resource.c b/sys/dev/pci/drm/amd/display/dc/dcn314/dcn314_resource.c index 503ab45b4..6b8abdb5c 100644 --- a/sys/dev/pci/drm/amd/display/dc/dcn314/dcn314_resource.c +++ b/sys/dev/pci/drm/amd/display/dc/dcn314/dcn314_resource.c @@ -884,7 +884,7 @@ static const struct dc_plane_cap plane_cap = { static const struct dc_debug_options debug_defaults_drv = { .disable_z10 = false, .enable_z9_disable_interface = true, - .minimum_z8_residency_time = 2000, + .minimum_z8_residency_time = 2100, .psr_skip_crtc_disable = true, .disable_dmcu = true, .force_abm_enable = false, diff --git a/sys/dev/pci/drm/amd/display/dc/dcn32/dcn32_hwseq.c b/sys/dev/pci/drm/amd/display/dc/dcn32/dcn32_hwseq.c index 4af01ba3f..6f4915c40 100644 --- a/sys/dev/pci/drm/amd/display/dc/dcn32/dcn32_hwseq.c +++ b/sys/dev/pci/drm/amd/display/dc/dcn32/dcn32_hwseq.c @@ -530,7 +530,7 @@ static bool dcn32_set_mpc_shaper_3dlut( if (stream->func_shaper->type == TF_TYPE_HWPWL) shaper_lut = &stream->func_shaper->pwl; else if (stream->func_shaper->type == TF_TYPE_DISTRIBUTED_POINTS) { - cm_helper_translate_curve_to_hw_format( + cm_helper_translate_curve_to_hw_format(stream->ctx, stream->func_shaper, &dpp_base->shaper_params, true); shaper_lut = &dpp_base->shaper_params; @@ -566,8 +566,7 @@ bool dcn32_set_mcm_luts( if (plane_state->blend_tf->type == TF_TYPE_HWPWL) lut_params = &plane_state->blend_tf->pwl; else if (plane_state->blend_tf->type == TF_TYPE_DISTRIBUTED_POINTS) { - cm_helper_translate_curve_to_hw_format( - plane_state->blend_tf, + cm3_helper_translate_curve_to_hw_format(plane_state->blend_tf, &dpp_base->regamma_params, false); lut_params = &dpp_base->regamma_params; } @@ -581,8 +580,7 @@ bool dcn32_set_mcm_luts( else if (plane_state->in_shaper_func->type == TF_TYPE_DISTRIBUTED_POINTS) { // TODO: dpp_base replace ASSERT(false); - cm_helper_translate_curve_to_hw_format( - plane_state->in_shaper_func, + cm3_helper_translate_curve_to_hw_format(plane_state->in_shaper_func, &dpp_base->shaper_params, true); lut_params = &dpp_base->shaper_params; } diff --git a/sys/dev/pci/drm/amd/display/dc/dml/dc_features.h b/sys/dev/pci/drm/amd/display/dc/dml/dc_features.h index 74e86732e..2cbdd7542 100644 --- a/sys/dev/pci/drm/amd/display/dc/dml/dc_features.h +++ b/sys/dev/pci/drm/amd/display/dc/dml/dc_features.h @@ -29,6 +29,13 @@ #define DC__PRESENT 1 #define DC__PRESENT__1 1 #define DC__NUM_DPP 4 + +/** + * @DC__VOLTAGE_STATES: + * + * Define the maximum amount of states supported by the ASIC. Every ASIC has a + * specific number of states; this macro defines the maximum number of states. + */ #define DC__VOLTAGE_STATES 20 #define DC__NUM_DPP__4 1 #define DC__NUM_DPP__0_PRESENT 1 diff --git a/sys/dev/pci/drm/amd/display/dc/dml/dcn20/dcn20_fpu.c b/sys/dev/pci/drm/amd/display/dc/dml/dcn20/dcn20_fpu.c index dbe5d2efa..9d224bb2b 100644 --- a/sys/dev/pci/drm/amd/display/dc/dml/dcn20/dcn20_fpu.c +++ b/sys/dev/pci/drm/amd/display/dc/dml/dcn20/dcn20_fpu.c @@ -948,10 +948,8 @@ static enum dcn_zstate_support_state decide_zstate_support(struct dc *dc, struc { int plane_count; int i; - unsigned int min_dst_y_next_start_us; plane_count = 0; - min_dst_y_next_start_us = 0; for (i = 0; i < dc->res_pool->pipe_count; i++) { if (context->res_ctx.pipe_ctx[i].plane_state) plane_count++; @@ -973,26 +971,15 @@ static enum dcn_zstate_support_state decide_zstate_support(struct dc *dc, struc else if (context->stream_count == 1 && context->streams[0]->signal == SIGNAL_TYPE_EDP) { struct dc_link *link = context->streams[0]->sink->link; struct dc_stream_status *stream_status = &context->stream_status[0]; - struct dc_stream_state *current_stream = context->streams[0]; int minmum_z8_residency = dc->debug.minimum_z8_residency_time > 0 ? dc->debug.minimum_z8_residency_time : 1000; bool allow_z8 = context->bw_ctx.dml.vba.StutterPeriod > (double)minmum_z8_residency; bool is_pwrseq0 = link->link_index == 0; - bool isFreesyncVideo; - - isFreesyncVideo = current_stream->adjust.v_total_min == current_stream->adjust.v_total_max; - isFreesyncVideo = isFreesyncVideo && current_stream->timing.v_total < current_stream->adjust.v_total_min; - for (i = 0; i < dc->res_pool->pipe_count; i++) { - if (context->res_ctx.pipe_ctx[i].stream == current_stream && isFreesyncVideo) { - min_dst_y_next_start_us = context->res_ctx.pipe_ctx[i].dlg_regs.min_dst_y_next_start_us; - break; - } - } /* Don't support multi-plane configurations */ if (stream_status->plane_count > 1) return DCN_ZSTATE_SUPPORT_DISALLOW; - if (is_pwrseq0 && (context->bw_ctx.dml.vba.StutterPeriod > 5000.0 || min_dst_y_next_start_us > 5000)) + if (is_pwrseq0 && context->bw_ctx.dml.vba.StutterPeriod > 5000.0) return DCN_ZSTATE_SUPPORT_ALLOW; else if (is_pwrseq0 && link->psr_settings.psr_version == DC_PSR_VERSION_1 && !link->panel_config.psr.disable_psr) return allow_z8 ? DCN_ZSTATE_SUPPORT_ALLOW_Z8_Z10_ONLY : DCN_ZSTATE_SUPPORT_ALLOW_Z10_ONLY; diff --git a/sys/dev/pci/drm/amd/display/dc/dml/dcn32/dcn32_fpu.c b/sys/dev/pci/drm/amd/display/dc/dml/dcn32/dcn32_fpu.c index c89b761bc..85e0d1c2a 100644 --- a/sys/dev/pci/drm/amd/display/dc/dml/dcn32/dcn32_fpu.c +++ b/sys/dev/pci/drm/amd/display/dc/dml/dcn32/dcn32_fpu.c @@ -1788,6 +1788,7 @@ void dcn32_calculate_wm_and_dlg_fpu(struct dc *dc, struct dc_state *context, int i, pipe_idx, vlevel_temp = 0; double dcfclk = dcn3_2_soc.clock_limits[0].dcfclk_mhz; double dcfclk_from_validation = context->bw_ctx.dml.vba.DCFCLKState[vlevel][context->bw_ctx.dml.vba.maxMpcComb]; + double dram_speed_from_validation = context->bw_ctx.dml.vba.DRAMSpeed; double dcfclk_from_fw_based_mclk_switching = dcfclk_from_validation; bool pstate_en = context->bw_ctx.dml.vba.DRAMClockChangeSupport[vlevel][context->bw_ctx.dml.vba.maxMpcComb] != dm_dram_clock_change_unsupported; @@ -1921,7 +1922,7 @@ void dcn32_calculate_wm_and_dlg_fpu(struct dc *dc, struct dc_state *context, } if (dc->clk_mgr->bw_params->wm_table.nv_entries[WM_C].valid) { - min_dram_speed_mts = context->bw_ctx.dml.vba.DRAMSpeed; + min_dram_speed_mts = dram_speed_from_validation; min_dram_speed_mts_margin = 160; context->bw_ctx.dml.soc.dram_clock_change_latency_us = diff --git a/sys/dev/pci/drm/amd/display/dc/dml/display_mode_enums.h b/sys/dev/pci/drm/amd/display/dc/dml/display_mode_enums.h index f394b3f39..0bffae95f 100644 --- a/sys/dev/pci/drm/amd/display/dc/dml/display_mode_enums.h +++ b/sys/dev/pci/drm/amd/display/dc/dml/display_mode_enums.h @@ -105,14 +105,39 @@ enum source_macro_tile_size { enum cursor_bpp { dm_cur_2bit = 0, dm_cur_32bit = 1, dm_cur_64bit = 2 }; + +/** + * @enum clock_change_support - It represents possible reasons to change the DRAM clock. + * + * DC may change the DRAM clock during its execution, and this enum tracks all + * the available methods. Note that every ASIC has their specific way to deal + * with these clock switch. + */ enum clock_change_support { + /** + * @dm_dram_clock_change_uninitialized: If you see this, we might have + * a code initialization issue + */ dm_dram_clock_change_uninitialized = 0, + + /** + * @dm_dram_clock_change_vactive: Support DRAM switch in VActive + */ dm_dram_clock_change_vactive, + + /** + * @dm_dram_clock_change_vblank: Support DRAM switch in VBlank + */ dm_dram_clock_change_vblank, + dm_dram_clock_change_vactive_w_mall_full_frame, dm_dram_clock_change_vactive_w_mall_sub_vp, dm_dram_clock_change_vblank_w_mall_full_frame, dm_dram_clock_change_vblank_w_mall_sub_vp, + + /** + * @dm_dram_clock_change_unsupported: Do not support DRAM switch + */ dm_dram_clock_change_unsupported }; diff --git a/sys/dev/pci/drm/amd/display/dc/dml/display_mode_vba.h b/sys/dev/pci/drm/amd/display/dc/dml/display_mode_vba.h index 2b34b02db..81e53e67c 100644 --- a/sys/dev/pci/drm/amd/display/dc/dml/display_mode_vba.h +++ b/sys/dev/pci/drm/amd/display/dc/dml/display_mode_vba.h @@ -419,6 +419,15 @@ struct vba_vars_st { double MinPixelChunkSizeBytes; unsigned int DCCMetaBufferSizeBytes; // Pipe/Plane Parameters + + /** @VoltageLevel: + * Every ASIC has a fixed number of DPM states, and some devices might + * have some particular voltage configuration that does not map + * directly to the DPM states. This field tells how many states the + * target device supports; even though this field combines the DPM and + * special SOC voltages, it mostly matches the total number of DPM + * states. + */ int VoltageLevel; double FabricClock; double DRAMSpeed; diff --git a/sys/dev/pci/drm/amd/display/dc/inc/core_types.h b/sys/dev/pci/drm/amd/display/dc/inc/core_types.h index 4a968de5b..dbc7f674a 100644 --- a/sys/dev/pci/drm/amd/display/dc/inc/core_types.h +++ b/sys/dev/pci/drm/amd/display/dc/inc/core_types.h @@ -115,6 +115,13 @@ struct resource_funcs { int vlevel); void (*update_soc_for_wm_a)( struct dc *dc, struct dc_state *context); + + /** + * @populate_dml_pipes - Populate pipe data struct + * + * Returns: + * Total of pipes available in the specific ASIC. + */ int (*populate_dml_pipes)( struct dc *dc, struct dc_state *context, diff --git a/sys/dev/pci/drm/amd/display/dc/inc/hw/hw_shared.h b/sys/dev/pci/drm/amd/display/dc/inc/hw/hw_shared.h index cd2be7298..a819f0f97 100644 --- a/sys/dev/pci/drm/amd/display/dc/inc/hw/hw_shared.h +++ b/sys/dev/pci/drm/amd/display/dc/inc/hw/hw_shared.h @@ -35,6 +35,13 @@ ******************************************************************************/ #define MAX_AUDIOS 7 + +/** + * @MAX_PIPES: + * + * Every ASIC support a fixed number of pipes; MAX_PIPES defines a large number + * to be used inside loops and for determining array sizes. + */ #define MAX_PIPES 6 #define MAX_DIG_LINK_ENCODERS 7 #define MAX_DWB_PIPES 1 diff --git a/sys/dev/pci/drm/amd/display/dmub/dmub_srv.h b/sys/dev/pci/drm/amd/display/dmub/dmub_srv.h index a21fe7b03..aaabaab49 100644 --- a/sys/dev/pci/drm/amd/display/dmub/dmub_srv.h +++ b/sys/dev/pci/drm/amd/display/dmub/dmub_srv.h @@ -332,6 +332,8 @@ struct dmub_srv_hw_funcs { void (*setup_mailbox)(struct dmub_srv *dmub, const struct dmub_region *inbox1); + uint32_t (*get_inbox1_wptr)(struct dmub_srv *dmub); + uint32_t (*get_inbox1_rptr)(struct dmub_srv *dmub); void (*set_inbox1_wptr)(struct dmub_srv *dmub, uint32_t wptr_offset); @@ -590,6 +592,18 @@ enum dmub_status dmub_srv_hw_init(struct dmub_srv *dmub, */ enum dmub_status dmub_srv_hw_reset(struct dmub_srv *dmub); +/** + * dmub_srv_sync_inbox1() - sync sw state with hw state + * @dmub: the dmub service + * + * Sync sw state with hw state when resume from S0i3 + * + * Return: + * DMUB_STATUS_OK - success + * DMUB_STATUS_INVALID - unspecified error + */ +enum dmub_status dmub_srv_sync_inbox1(struct dmub_srv *dmub); + /** * dmub_srv_cmd_queue() - queues a command to the DMUB * @dmub: the dmub service diff --git a/sys/dev/pci/drm/amd/display/dmub/src/dmub_dcn20.c b/sys/dev/pci/drm/amd/display/dmub/src/dmub_dcn20.c index a6540e270..98dad0d47 100644 --- a/sys/dev/pci/drm/amd/display/dmub/src/dmub_dcn20.c +++ b/sys/dev/pci/drm/amd/display/dmub/src/dmub_dcn20.c @@ -282,6 +282,11 @@ void dmub_dcn20_setup_mailbox(struct dmub_srv *dmub, REG_WRITE(DMCUB_INBOX1_SIZE, inbox1->top - inbox1->base); } +uint32_t dmub_dcn20_get_inbox1_wptr(struct dmub_srv *dmub) +{ + return REG_READ(DMCUB_INBOX1_WPTR); +} + uint32_t dmub_dcn20_get_inbox1_rptr(struct dmub_srv *dmub) { return REG_READ(DMCUB_INBOX1_RPTR); diff --git a/sys/dev/pci/drm/amd/display/dmub/src/dmub_dcn20.h b/sys/dev/pci/drm/amd/display/dmub/src/dmub_dcn20.h index c2e5831ac..1df128e57 100644 --- a/sys/dev/pci/drm/amd/display/dmub/src/dmub_dcn20.h +++ b/sys/dev/pci/drm/amd/display/dmub/src/dmub_dcn20.h @@ -202,6 +202,8 @@ void dmub_dcn20_setup_windows(struct dmub_srv *dmub, void dmub_dcn20_setup_mailbox(struct dmub_srv *dmub, const struct dmub_region *inbox1); +uint32_t dmub_dcn20_get_inbox1_wptr(struct dmub_srv *dmub); + uint32_t dmub_dcn20_get_inbox1_rptr(struct dmub_srv *dmub); void dmub_dcn20_set_inbox1_wptr(struct dmub_srv *dmub, uint32_t wptr_offset); diff --git a/sys/dev/pci/drm/amd/display/dmub/src/dmub_dcn31.c b/sys/dev/pci/drm/amd/display/dmub/src/dmub_dcn31.c index 89d24fb70..5e952541e 100644 --- a/sys/dev/pci/drm/amd/display/dmub/src/dmub_dcn31.c +++ b/sys/dev/pci/drm/amd/display/dmub/src/dmub_dcn31.c @@ -242,6 +242,11 @@ void dmub_dcn31_setup_mailbox(struct dmub_srv *dmub, REG_WRITE(DMCUB_INBOX1_SIZE, inbox1->top - inbox1->base); } +uint32_t dmub_dcn31_get_inbox1_wptr(struct dmub_srv *dmub) +{ + return REG_READ(DMCUB_INBOX1_WPTR); +} + uint32_t dmub_dcn31_get_inbox1_rptr(struct dmub_srv *dmub) { return REG_READ(DMCUB_INBOX1_RPTR); diff --git a/sys/dev/pci/drm/amd/display/dmub/src/dmub_dcn31.h b/sys/dev/pci/drm/amd/display/dmub/src/dmub_dcn31.h index eb6241094..89c5a948b 100644 --- a/sys/dev/pci/drm/amd/display/dmub/src/dmub_dcn31.h +++ b/sys/dev/pci/drm/amd/display/dmub/src/dmub_dcn31.h @@ -204,6 +204,8 @@ void dmub_dcn31_setup_windows(struct dmub_srv *dmub, void dmub_dcn31_setup_mailbox(struct dmub_srv *dmub, const struct dmub_region *inbox1); +uint32_t dmub_dcn31_get_inbox1_wptr(struct dmub_srv *dmub); + uint32_t dmub_dcn31_get_inbox1_rptr(struct dmub_srv *dmub); void dmub_dcn31_set_inbox1_wptr(struct dmub_srv *dmub, uint32_t wptr_offset); diff --git a/sys/dev/pci/drm/amd/display/dmub/src/dmub_dcn32.c b/sys/dev/pci/drm/amd/display/dmub/src/dmub_dcn32.c index 9c20516be..d2f03f797 100644 --- a/sys/dev/pci/drm/amd/display/dmub/src/dmub_dcn32.c +++ b/sys/dev/pci/drm/amd/display/dmub/src/dmub_dcn32.c @@ -266,6 +266,11 @@ void dmub_dcn32_setup_mailbox(struct dmub_srv *dmub, REG_WRITE(DMCUB_INBOX1_SIZE, inbox1->top - inbox1->base); } +uint32_t dmub_dcn32_get_inbox1_wptr(struct dmub_srv *dmub) +{ + return REG_READ(DMCUB_INBOX1_WPTR); +} + uint32_t dmub_dcn32_get_inbox1_rptr(struct dmub_srv *dmub) { return REG_READ(DMCUB_INBOX1_RPTR); diff --git a/sys/dev/pci/drm/amd/display/dmub/src/dmub_dcn32.h b/sys/dev/pci/drm/amd/display/dmub/src/dmub_dcn32.h index 7d1a6eb4d..f15336b6e 100644 --- a/sys/dev/pci/drm/amd/display/dmub/src/dmub_dcn32.h +++ b/sys/dev/pci/drm/amd/display/dmub/src/dmub_dcn32.h @@ -206,6 +206,8 @@ void dmub_dcn32_setup_windows(struct dmub_srv *dmub, void dmub_dcn32_setup_mailbox(struct dmub_srv *dmub, const struct dmub_region *inbox1); +uint32_t dmub_dcn32_get_inbox1_wptr(struct dmub_srv *dmub); + uint32_t dmub_dcn32_get_inbox1_rptr(struct dmub_srv *dmub); void dmub_dcn32_set_inbox1_wptr(struct dmub_srv *dmub, uint32_t wptr_offset); diff --git a/sys/dev/pci/drm/amd/display/dmub/src/dmub_srv.c b/sys/dev/pci/drm/amd/display/dmub/src/dmub_srv.c index c33278759..e951fd837 100644 --- a/sys/dev/pci/drm/amd/display/dmub/src/dmub_srv.c +++ b/sys/dev/pci/drm/amd/display/dmub/src/dmub_srv.c @@ -167,6 +167,7 @@ static bool dmub_srv_hw_setup(struct dmub_srv *dmub, enum dmub_asic asic) funcs->backdoor_load = dmub_dcn20_backdoor_load; funcs->setup_windows = dmub_dcn20_setup_windows; funcs->setup_mailbox = dmub_dcn20_setup_mailbox; + funcs->get_inbox1_wptr = dmub_dcn20_get_inbox1_wptr; funcs->get_inbox1_rptr = dmub_dcn20_get_inbox1_rptr; funcs->set_inbox1_wptr = dmub_dcn20_set_inbox1_wptr; funcs->is_supported = dmub_dcn20_is_supported; @@ -243,6 +244,7 @@ static bool dmub_srv_hw_setup(struct dmub_srv *dmub, enum dmub_asic asic) funcs->backdoor_load = dmub_dcn31_backdoor_load; funcs->setup_windows = dmub_dcn31_setup_windows; funcs->setup_mailbox = dmub_dcn31_setup_mailbox; + funcs->get_inbox1_wptr = dmub_dcn31_get_inbox1_wptr; funcs->get_inbox1_rptr = dmub_dcn31_get_inbox1_rptr; funcs->set_inbox1_wptr = dmub_dcn31_set_inbox1_wptr; funcs->setup_out_mailbox = dmub_dcn31_setup_out_mailbox; @@ -281,6 +283,7 @@ static bool dmub_srv_hw_setup(struct dmub_srv *dmub, enum dmub_asic asic) funcs->backdoor_load_zfb_mode = dmub_dcn32_backdoor_load_zfb_mode; funcs->setup_windows = dmub_dcn32_setup_windows; funcs->setup_mailbox = dmub_dcn32_setup_mailbox; + funcs->get_inbox1_wptr = dmub_dcn32_get_inbox1_wptr; funcs->get_inbox1_rptr = dmub_dcn32_get_inbox1_rptr; funcs->set_inbox1_wptr = dmub_dcn32_set_inbox1_wptr; funcs->setup_out_mailbox = dmub_dcn32_setup_out_mailbox; @@ -666,6 +669,27 @@ enum dmub_status dmub_srv_hw_init(struct dmub_srv *dmub, return DMUB_STATUS_OK; } +enum dmub_status dmub_srv_sync_inbox1(struct dmub_srv *dmub) +{ + if (!dmub->sw_init) + return DMUB_STATUS_INVALID; + + if (dmub->hw_funcs.get_inbox1_rptr && dmub->hw_funcs.get_inbox1_wptr) { + uint32_t rptr = dmub->hw_funcs.get_inbox1_rptr(dmub); + uint32_t wptr = dmub->hw_funcs.get_inbox1_wptr(dmub); + + if (rptr > dmub->inbox1_rb.capacity || wptr > dmub->inbox1_rb.capacity) { + return DMUB_STATUS_HW_FAILURE; + } else { + dmub->inbox1_rb.rptr = rptr; + dmub->inbox1_rb.wrpt = wptr; + dmub->inbox1_last_wptr = dmub->inbox1_rb.wrpt; + } + } + + return DMUB_STATUS_OK; +} + enum dmub_status dmub_srv_hw_reset(struct dmub_srv *dmub) { if (!dmub->sw_init) @@ -694,6 +718,11 @@ enum dmub_status dmub_srv_cmd_queue(struct dmub_srv *dmub, if (!dmub->hw_init) return DMUB_STATUS_INVALID; + if (dmub->inbox1_rb.rptr > dmub->inbox1_rb.capacity || + dmub->inbox1_rb.wrpt > dmub->inbox1_rb.capacity) { + return DMUB_STATUS_HW_FAILURE; + } + if (dmub_rb_push_front(&dmub->inbox1_rb, cmd)) return DMUB_STATUS_OK; @@ -964,6 +993,7 @@ enum dmub_status dmub_srv_wait_for_inbox0_ack(struct dmub_srv *dmub, uint32_t ti ack = dmub->hw_funcs.read_inbox0_ack_register(dmub); if (ack) return DMUB_STATUS_OK; + udelay(1); } return DMUB_STATUS_TIMEOUT; } diff --git a/sys/dev/pci/drm/amd/include/asic_reg/gc/gc_11_0_0_offset.h b/sys/dev/pci/drm/amd/include/asic_reg/gc/gc_11_0_0_offset.h index c92c4b832..4bff1ef8a 100644 --- a/sys/dev/pci/drm/amd/include/asic_reg/gc/gc_11_0_0_offset.h +++ b/sys/dev/pci/drm/amd/include/asic_reg/gc/gc_11_0_0_offset.h @@ -6369,6 +6369,8 @@ #define regTCP_INVALIDATE_BASE_IDX 1 #define regTCP_STATUS 0x19a1 #define regTCP_STATUS_BASE_IDX 1 +#define regTCP_CNTL 0x19a2 +#define regTCP_CNTL_BASE_IDX 1 #define regTCP_CNTL2 0x19a3 #define regTCP_CNTL2_BASE_IDX 1 #define regTCP_DEBUG_INDEX 0x19a5 diff --git a/sys/dev/pci/drm/amd/pm/swsmu/smu13/aldebaran_ppt.c b/sys/dev/pci/drm/amd/pm/swsmu/smu13/aldebaran_ppt.c index 4ee364060..175247efc 100644 --- a/sys/dev/pci/drm/amd/pm/swsmu/smu13/aldebaran_ppt.c +++ b/sys/dev/pci/drm/amd/pm/swsmu/smu13/aldebaran_ppt.c @@ -258,8 +258,11 @@ static int aldebaran_tables_init(struct smu_context *smu) } smu_table->ecc_table = kzalloc(tables[SMU_TABLE_ECCINFO].size, GFP_KERNEL); - if (!smu_table->ecc_table) + if (!smu_table->ecc_table) { + kfree(smu_table->metrics_table); + kfree(smu_table->gpu_metrics_table); return -ENOMEM; + } return 0; } diff --git a/sys/dev/pci/drm/dma-resv.c b/sys/dev/pci/drm/dma-resv.c index d3f7c01f3..0f2e297ee 100644 --- a/sys/dev/pci/drm/dma-resv.c +++ b/sys/dev/pci/drm/dma-resv.c @@ -301,7 +301,7 @@ void dma_resv_add_fence(struct dma_resv *obj, struct dma_fence *fence, dma_resv_list_entry(fobj, i, obj, &old, &old_usage); if ((old->context == fence->context && old_usage >= usage && - dma_fence_is_later(fence, old)) || + dma_fence_is_later_or_same(fence, old)) || dma_fence_is_signaled(old)) { dma_resv_list_set(fobj, i, fence, usage); dma_fence_put(old); diff --git a/sys/dev/pci/drm/include/linux/dma-fence.h b/sys/dev/pci/drm/include/linux/dma-fence.h index b6942e4b7..8c06d399a 100644 --- a/sys/dev/pci/drm/include/linux/dma-fence.h +++ b/sys/dev/pci/drm/include/linux/dma-fence.h @@ -113,6 +113,14 @@ dma_fence_is_later(struct dma_fence *a, struct dma_fence *b) return __dma_fence_is_later(a->seqno, b->seqno, a->ops); } +static inline bool +dma_fence_is_later_or_same(struct dma_fence *a, struct dma_fence *b) +{ + if (a == b) + return true; + return dma_fence_is_later(a, b); +} + static inline void dma_fence_set_error(struct dma_fence *fence, int error) { diff --git a/sys/dev/pv/if_vio.c b/sys/dev/pv/if_vio.c index 5c9a05faf..787b6a520 100644 --- a/sys/dev/pv/if_vio.c +++ b/sys/dev/pv/if_vio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_vio.c,v 1.27 2023/12/09 10:36:05 jan Exp $ */ +/* $OpenBSD: if_vio.c,v 1.28 2023/12/11 09:40:42 jan Exp $ */ /* * Copyright (c) 2012 Stefan Fritsch, Alexander Fiveg. @@ -749,27 +749,22 @@ again: hdr = &sc->sc_tx_hdrs[slot]; memset(hdr, 0, sc->sc_hdr_size); if (m->m_pkthdr.csum_flags & (M_TCP_CSUM_OUT|M_UDP_CSUM_OUT)) { - struct mbuf *mip; - struct ip *ip; - int ehdrlen = ETHER_HDR_LEN; - int ipoff; + struct ether_extracted ext; + + ether_extract_headers(m, &ext); + hdr->csum_start = sizeof(*ext.eh); #if NVLAN > 0 - struct ether_vlan_header *eh; - - eh = mtod(m, struct ether_vlan_header *); - if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) - ehdrlen += ETHER_VLAN_ENCAP_LEN; + if (ext.evh) + hdr->csum_start = sizeof(*ext.evh); #endif - if (m->m_pkthdr.csum_flags & M_TCP_CSUM_OUT) hdr->csum_offset = offsetof(struct tcphdr, th_sum); else hdr->csum_offset = offsetof(struct udphdr, uh_sum); - mip = m_getptr(m, ehdrlen, &ipoff); - KASSERT(mip != NULL && mip->m_len - ipoff >= sizeof(*ip)); - ip = (struct ip *)(mip->m_data + ipoff); - hdr->csum_start = ehdrlen + (ip->ip_hl << 2); + if (ext.ip4) + hdr->csum_start += ext.ip4->ip_hl << 2; + hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM; } diff --git a/sys/dev/usb/ugold.c b/sys/dev/usb/ugold.c index 9d1a30b2d..7f7dfad21 100644 --- a/sys/dev/usb/ugold.c +++ b/sys/dev/usb/ugold.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ugold.c,v 1.25 2023/12/08 06:33:48 miod Exp $ */ +/* $OpenBSD: ugold.c,v 1.26 2023/12/10 19:03:37 miod Exp $ */ /* * Copyright (c) 2013 Takayoshi SASANO @@ -609,6 +609,18 @@ ugold_intr(struct uhidev *addr, void *ibuf, u_int len) break; default: if (!sc->sc_type) { + /* + * During initialization, some devices need a bit + * more time to submit their identification string. + */ + if (len == sc->sc_model_len && + !memcmp(sc->sc_model, buf, len)) { +#ifdef UGOLD_DEBUG + printf("%s: duplicate string component\n", + sc->sc_hdev.sc_dev.dv_xname); +#endif + break; + } /* * Exact sensor type is not known yet, type command * returns arbitrary string. diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c index a068716bd..c0cb959b3 100644 --- a/sys/kern/init_main.c +++ b/sys/kern/init_main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: init_main.c,v 1.322 2023/08/29 16:19:34 claudio Exp $ */ +/* $OpenBSD: init_main.c,v 1.323 2023/12/11 22:12:53 kettenis Exp $ */ /* $NetBSD: init_main.c,v 1.84.4.1 1996/06/02 09:08:06 mrg Exp $ */ /* @@ -400,6 +400,7 @@ main(void *framep) /* Enable per-CPU data. */ mbcpuinit(); kqueue_init_percpu(); + pmap_init_percpu(); uvm_init_percpu(); evcount_init_percpu(); diff --git a/sys/net/if_pflow.c b/sys/net/if_pflow.c index 67e8282b8..4fa69b9d6 100644 --- a/sys/net/if_pflow.c +++ b/sys/net/if_pflow.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_pflow.c,v 1.102 2023/12/08 23:15:44 mvs Exp $ */ +/* $OpenBSD: if_pflow.c,v 1.104 2023/12/12 00:03:31 mvs Exp $ */ /* * Copyright (c) 2011 Florian Obser @@ -62,8 +62,23 @@ #define DPRINTF(x) #endif -SLIST_HEAD(, pflow_softc) pflowif_list; -struct pflowstats pflowstats; +SMR_SLIST_HEAD(, pflow_softc) pflowif_list; + +enum pflowstat_counters { + pflow_flows, + pflow_packets, + pflow_onomem, + pflow_oerrors, + pflow_ncounters, +}; + +struct cpumem *pflow_counters; + +static inline void +pflowstat_inc(enum pflowstat_counters c) +{ + counters_inc(pflow_counters, c); +} void pflowattach(int); int pflow_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, @@ -113,7 +128,8 @@ struct if_clone pflow_cloner = void pflowattach(int npflow) { - SLIST_INIT(&pflowif_list); + SMR_SLIST_INIT(&pflowif_list); + pflow_counters = counters_alloc(pflow_ncounters); if_clone_attach(&pflow_cloner); } @@ -268,9 +284,8 @@ pflow_clone_create(struct if_clone *ifc, int unit) task_set(&pflowif->sc_outputtask, pflow_output_process, pflowif); /* Insert into list of pflows */ - NET_LOCK(); - SLIST_INSERT_HEAD(&pflowif_list, pflowif, sc_next); - NET_UNLOCK(); + KERNEL_ASSERT_LOCKED(); + SMR_SLIST_INSERT_HEAD_LOCKED(&pflowif_list, pflowif, sc_next); return (0); } @@ -284,9 +299,12 @@ pflow_clone_destroy(struct ifnet *ifp) NET_LOCK(); sc->sc_dying = 1; - SLIST_REMOVE(&pflowif_list, sc, pflow_softc, sc_next); NET_UNLOCK(); + KERNEL_ASSERT_LOCKED(); + SMR_SLIST_REMOVE_LOCKED(&pflowif_list, sc, pflow_softc, sc_next); + smr_barrier(); + timeout_del(&sc->sc_tmo); timeout_del(&sc->sc_tmo6); timeout_del(&sc->sc_tmo_tmpl); @@ -513,7 +531,6 @@ pflowioctl(struct ifnet *ifp, u_long cmd, caddr_t data) if ((ifp->if_flags & IFF_UP) && sc->so != NULL) { ifp->if_flags |= IFF_RUNNING; mtx_enter(&sc->sc_mtx); - sc->sc_gcounter = pflowstats.pflow_flows; /* send templates on startup */ if (sc->sc_version == PFLOW_PROTO_10) pflow_sendout_ipfix_tmpl(sc); @@ -577,7 +594,6 @@ pflowioctl(struct ifnet *ifp, u_long cmd, caddr_t data) if ((ifp->if_flags & IFF_UP) && sc->so != NULL) { ifp->if_flags |= IFF_RUNNING; mtx_enter(&sc->sc_mtx); - sc->sc_gcounter = pflowstats.pflow_flows; if (sc->sc_version == PFLOW_PROTO_10) pflow_sendout_ipfix_tmpl(sc); mtx_leave(&sc->sc_mtx); @@ -646,14 +662,14 @@ pflow_get_mbuf(struct pflow_softc *sc, u_int16_t set_id) MGETHDR(m, M_DONTWAIT, MT_DATA); if (m == NULL) { - pflowstats.pflow_onomem++; + pflowstat_inc(pflow_onomem); return (NULL); } MCLGET(m, M_DONTWAIT); if ((m->m_flags & M_EXT) == 0) { m_free(m); - pflowstats.pflow_onomem++; + pflowstat_inc(pflow_onomem); return (NULL); } @@ -812,7 +828,7 @@ export_pflow(struct pf_state *st) sk = st->key[st->direction == PF_IN ? PF_SK_WIRE : PF_SK_STACK]; - SLIST_FOREACH(sc, &pflowif_list, sc_next) { + SMR_SLIST_FOREACH(sc, &pflowif_list, sc_next) { mtx_enter(&sc->sc_mtx); switch (sc->sc_version) { case PFLOW_PROTO_5: @@ -898,8 +914,7 @@ copy_flow_to_m(struct pflow_flow *flow, struct pflow_softc *sc) (sc->sc_count * sizeof(struct pflow_flow)), sizeof(struct pflow_flow), flow, M_NOWAIT); - if (pflowstats.pflow_flows == sc->sc_gcounter) - pflowstats.pflow_flows++; + pflowstat_inc(pflow_flows); sc->sc_gcounter++; sc->sc_count++; @@ -928,8 +943,7 @@ copy_flow_ipfix_4_to_m(struct pflow_ipfix_flow4 *flow, struct pflow_softc *sc) (sc->sc_count4 * sizeof(struct pflow_ipfix_flow4)), sizeof(struct pflow_ipfix_flow4), flow, M_NOWAIT); - if (pflowstats.pflow_flows == sc->sc_gcounter) - pflowstats.pflow_flows++; + pflowstat_inc(pflow_flows); sc->sc_gcounter++; sc->sc_count4++; @@ -957,8 +971,7 @@ copy_flow_ipfix_6_to_m(struct pflow_ipfix_flow6 *flow, struct pflow_softc *sc) (sc->sc_count6 * sizeof(struct pflow_ipfix_flow6)), sizeof(struct pflow_ipfix_flow6), flow, M_NOWAIT); - if (pflowstats.pflow_flows == sc->sc_gcounter) - pflowstats.pflow_flows++; + pflowstat_inc(pflow_flows); sc->sc_gcounter++; sc->sc_count6++; @@ -1114,7 +1127,7 @@ pflow_sendout_v5(struct pflow_softc *sc) return (0); } - pflowstats.pflow_packets++; + pflowstat_inc(pflow_packets); h = mtod(m, struct pflow_header *); h->count = htons(sc->sc_count); @@ -1171,14 +1184,14 @@ pflow_sendout_ipfix(struct pflow_softc *sc, sa_family_t af) return (0); } - pflowstats.pflow_packets++; + pflowstat_inc(pflow_packets); set_hdr = mtod(m, struct pflow_set_header *); set_hdr->set_length = htons(set_length); /* populate pflow_header */ M_PREPEND(m, sizeof(struct pflow_v10_header), M_DONTWAIT); if (m == NULL) { - pflowstats.pflow_onomem++; + pflowstat_inc(pflow_onomem); return (ENOBUFS); } h10 = mtod(m, struct pflow_v10_header *); @@ -1215,12 +1228,12 @@ pflow_sendout_ipfix_tmpl(struct pflow_softc *sc) m_freem(m); return (0); } - pflowstats.pflow_packets++; + pflowstat_inc(pflow_packets); /* populate pflow_header */ M_PREPEND(m, sizeof(struct pflow_v10_header), M_DONTWAIT); if (m == NULL) { - pflowstats.pflow_onomem++; + pflowstat_inc(pflow_onomem); return (ENOBUFS); } h10 = mtod(m, struct pflow_v10_header *); @@ -1260,11 +1273,23 @@ pflow_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, return (ENOTDIR); switch (name[0]) { - case NET_PFLOW_STATS: + case NET_PFLOW_STATS: { + uint64_t counters[pflow_ncounters]; + struct pflowstats pflowstats; + if (newp != NULL) return (EPERM); + + counters_read(pflow_counters, counters, pflow_ncounters, NULL); + + pflowstats.pflow_flows = counters[pflow_flows]; + pflowstats.pflow_packets = counters[pflow_packets]; + pflowstats.pflow_onomem = counters[pflow_onomem]; + pflowstats.pflow_oerrors = counters[pflow_oerrors]; + return (sysctl_struct(oldp, oldlenp, newp, newlen, &pflowstats, sizeof(pflowstats))); + } default: return (EOPNOTSUPP); } diff --git a/sys/net/if_pflow.h b/sys/net/if_pflow.h index 430ddb3c0..a4cc724d0 100644 --- a/sys/net/if_pflow.h +++ b/sys/net/if_pflow.h @@ -1,4 +1,4 @@ -/* $OpenBSD: if_pflow.h,v 1.20 2023/12/08 23:13:40 mvs Exp $ */ +/* $OpenBSD: if_pflow.h,v 1.22 2023/12/12 00:03:31 mvs Exp $ */ /* * Copyright (c) 2008 Henning Brauer @@ -169,6 +169,8 @@ struct pflow_ipfix_flow6 { #ifdef _KERNEL +#include + /* * Locks used to protect struct members and global data * I immutable after creation @@ -190,7 +192,7 @@ struct pflow_softc { unsigned int sc_maxcount; /* [m] */ unsigned int sc_maxcount4; /* [m] */ unsigned int sc_maxcount6; /* [m] */ - u_int64_t sc_gcounter; /* [m] */ + u_int32_t sc_gcounter; /* [m] */ u_int32_t sc_sequence; /* [m] */ struct timeout sc_tmo; struct timeout sc_tmo6; @@ -207,7 +209,7 @@ struct pflow_softc { mbuf */ struct mbuf *sc_mbuf6; /* [m] current cumulative mbuf */ - SLIST_ENTRY(pflow_softc) sc_next; + SMR_SLIST_ENTRY(pflow_softc) sc_next; }; extern struct pflow_softc *pflowif; diff --git a/sys/sys/acct.h b/sys/sys/acct.h index 6a7f51ddf..bd2ec2470 100644 --- a/sys/sys/acct.h +++ b/sys/sys/acct.h @@ -1,4 +1,4 @@ -/* $OpenBSD: acct.h,v 1.13 2023/02/21 14:31:07 deraadt Exp $ */ +/* $OpenBSD: acct.h,v 1.14 2023/12/11 00:39:43 deraadt Exp $ */ /* $NetBSD: acct.h,v 1.16 1995/03/26 20:23:52 jtc Exp $ */ /*- @@ -67,6 +67,7 @@ struct acct { #define ATRAP 0x00000040 /* memory access violation */ #define AUNVEIL 0x00000080 /* unveil access violation */ #define AEXECVE 0x00000100 /* execve from wrong libc stub */ +#define APINSYS 0x00000200 /* syscall pin violation */ u_int32_t ac_flag; /* accounting flags */ }; diff --git a/usr.bin/lastcomm/lastcomm.1 b/usr.bin/lastcomm/lastcomm.1 index 5fc0bb1da..45ac20873 100644 --- a/usr.bin/lastcomm/lastcomm.1 +++ b/usr.bin/lastcomm/lastcomm.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: lastcomm.1,v 1.25 2023/02/21 14:31:07 deraadt Exp $ +.\" $OpenBSD: lastcomm.1,v 1.26 2023/12/11 00:40:31 deraadt Exp $ .\" $NetBSD: lastcomm.1,v 1.5 1995/10/22 01:43:41 ghudson Exp $ .\" .\" Copyright (c) 1980, 1990, 1993 @@ -30,7 +30,7 @@ .\" .\" @(#)lastcomm.1 8.1 (Berkeley) 6/6/93 .\" -.Dd $Mdocdate: February 21 2023 $ +.Dd $Mdocdate: December 11 2023 $ .Dt LASTCOMM 1 .Os .Sh NAME @@ -122,6 +122,10 @@ pointer was not in stack memory. The command was terminated due to a .Xr pledge 2 violation. +.It Li S +The command tried to execute a system call from the wrong +system call instruction, see +.Xr pinsyscalls 2 . .It Li T The command did a memory access violation detected by a processor trap. diff --git a/usr.bin/lastcomm/lastcomm.c b/usr.bin/lastcomm/lastcomm.c index 230787388..865860503 100644 --- a/usr.bin/lastcomm/lastcomm.c +++ b/usr.bin/lastcomm/lastcomm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lastcomm.c,v 1.33 2023/02/21 14:31:07 deraadt Exp $ */ +/* $OpenBSD: lastcomm.c,v 1.34 2023/12/11 00:40:31 deraadt Exp $ */ /* $NetBSD: lastcomm.c,v 1.9 1995/10/22 01:43:42 ghudson Exp $ */ /* @@ -178,6 +178,7 @@ flagbits(int f) BIT(ATRAP, 'T'); BIT(AUNVEIL, 'U'); BIT(AEXECVE, 'E'); + BIT(APINSYS, 'S'); *p = '\0'; return (flags); } diff --git a/usr.sbin/rpki-client/extern.h b/usr.sbin/rpki-client/extern.h index 571b2d849..9bb95edb2 100644 --- a/usr.sbin/rpki-client/extern.h +++ b/usr.sbin/rpki-client/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.195 2023/11/24 14:05:47 job Exp $ */ +/* $OpenBSD: extern.h,v 1.196 2023/12/11 19:05:20 job Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons * @@ -210,6 +210,7 @@ struct mft { char *sia; /* SIA signedObject */ char *ski; /* SKI */ char *crl; /* CRL file name */ + unsigned char mfthash[SHA256_DIGEST_LENGTH]; unsigned char crlhash[SHA256_DIGEST_LENGTH]; time_t signtime; /* CMS signing-time attribute */ time_t thisupdate; /* from the eContent */ diff --git a/usr.sbin/rpki-client/mft.c b/usr.sbin/rpki-client/mft.c index 0e4af6e1f..8fd3755f1 100644 --- a/usr.sbin/rpki-client/mft.c +++ b/usr.sbin/rpki-client/mft.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mft.c,v 1.99 2023/10/13 12:06:49 job Exp $ */ +/* $OpenBSD: mft.c,v 1.100 2023/12/11 15:50:23 job Exp $ */ /* * Copyright (c) 2022 Theo Buehler * Copyright (c) 2019 Kristaps Dzonsons @@ -545,8 +545,9 @@ mft_read(struct ibuf *b) } /* - * Compare two MFT files, returns 1 if first MFT is preferred and 0 if second - * MFT should be used. + * Compare the manifestNumber of two MFT files. + * Returns 1 if first MFT should be used, 0 if both are equal, and -1 if the + * second MFT should be used. */ int mft_compare(const struct mft *a, const struct mft *b) @@ -556,16 +557,19 @@ mft_compare(const struct mft *a, const struct mft *b) if (b == NULL) return 1; if (a == NULL) - return 0; + return -1; r = strlen(a->seqnum) - strlen(b->seqnum); if (r > 0) /* seqnum in a is longer -> higher */ return 1; if (r < 0) /* seqnum in a is shorter -> smaller */ - return 0; + return -1; r = strcmp(a->seqnum, b->seqnum); if (r > 0) /* a is greater, prefer a */ return 1; + if (r < 0) /* b is greater, prefer b */ + return -1; + return 0; } diff --git a/usr.sbin/rpki-client/parser.c b/usr.sbin/rpki-client/parser.c index 61a66db01..c2fffa989 100644 --- a/usr.sbin/rpki-client/parser.c +++ b/usr.sbin/rpki-client/parser.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parser.c,v 1.101 2023/12/09 00:44:18 job Exp $ */ +/* $OpenBSD: parser.c,v 1.103 2023/12/11 19:05:20 job Exp $ */ /* * Copyright (c) 2019 Claudio Jeker * Copyright (c) 2019 Kristaps Dzonsons @@ -280,6 +280,10 @@ proc_parser_mft_pre(struct entity *entp, enum location loc, char **file, free(der); return NULL; } + + if (!EVP_Digest(der, len, mft->mfthash, NULL, EVP_sha256(), NULL)) + errx(1, "EVP_Digest failed"); + free(der); *crl = parse_load_crl_from_mft(entp, mft, DIR_TEMP, crlfile); @@ -361,7 +365,7 @@ proc_parser_mft(struct entity *entp, struct mft **mp, char **crlfile, struct crl *crl, *crl1, *crl2; char *file, *file1, *file2, *crl1file, *crl2file; const char *err1, *err2; - int warned = 0; + int r, warned = 0; *mp = NULL; *crlmtime = 0; @@ -376,7 +380,17 @@ proc_parser_mft(struct entity *entp, struct mft **mp, char **crlfile, if (err2 != NULL) err1 = err2; - if (mft_compare(mft1, mft2) == 1) { + r = mft_compare(mft1, mft2); + if (r == -1 && mft1 != NULL && mft2 != NULL) + warnx("%s: manifest replay detected (expected >= #%s, got #%s)", + file1, mft2->seqnum, mft1->seqnum); + + if (r == 0 && memcmp(mft1->mfthash, mft2->mfthash, + SHA256_DIGEST_LENGTH) != 0) + warnx("%s: manifest misissuance, #%s was recycled", + file1, mft1->seqnum); + + if (r == 1) { *mp = proc_parser_mft_post(file1, mft1, entp->path, err1, &warned); if (*mp == NULL) {