From 951aae1a1a6f0a38aa87fdf9ffdf33edd58ae799 Mon Sep 17 00:00:00 2001 From: purplerain Date: Sat, 24 Feb 2024 21:16:08 +0000 Subject: [PATCH] sync with OpenBSD -current --- distrib/sets/lists/comp/mi | 1 + lib/libcrypto/aes/asm/aes-x86_64.pl | 26 +- lib/libcrypto/aes/asm/aesni-sha1-x86_64.pl | 8 +- lib/libcrypto/aes/asm/aesni-x86_64.pl | 36 ++- lib/libcrypto/aes/asm/bsaes-x86_64.pl | 28 +- lib/libcrypto/aes/asm/vpaes-x86_64.pl | 28 +- lib/libcrypto/bn/arch/amd64/bignum_add.S | 2 +- lib/libcrypto/bn/arch/amd64/bignum_cmadd.S | 2 +- lib/libcrypto/bn/arch/amd64/bignum_cmul.S | 2 +- lib/libcrypto/bn/arch/amd64/bignum_mul.S | 2 +- .../bn/arch/amd64/bignum_mul_4_8_alt.S | 2 +- .../bn/arch/amd64/bignum_mul_8_16_alt.S | 2 +- lib/libcrypto/bn/arch/amd64/bignum_sqr.S | 2 +- .../bn/arch/amd64/bignum_sqr_4_8_alt.S | 2 +- .../bn/arch/amd64/bignum_sqr_8_16_alt.S | 2 +- lib/libcrypto/bn/arch/amd64/bignum_sub.S | 2 +- lib/libcrypto/bn/arch/amd64/word_clz.S | 2 +- lib/libcrypto/bn/asm/modexp512-x86_64.pl | 10 +- lib/libcrypto/bn/asm/x86_64-mont.pl | 6 +- lib/libcrypto/bn/asm/x86_64-mont5.pl | 10 +- lib/libcrypto/bn/s2n_bignum_internal.h | 6 + lib/libcrypto/camellia/asm/cmll-x86_64.pl | 16 +- lib/libcrypto/err/err.c | 20 +- lib/libcrypto/evp/evp_cipher.c | 6 +- lib/libcrypto/md5/asm/md5-x86_64.pl | 2 +- lib/libcrypto/modes/asm/ghash-x86_64.pl | 10 +- lib/libcrypto/perlasm/x86_64-xlate.pl | 16 + lib/libcrypto/rc4/asm/rc4-md5-x86_64.pl | 4 +- lib/libcrypto/rc4/asm/rc4-x86_64.pl | 4 +- lib/libcrypto/sha/asm/sha1-x86_64.pl | 8 +- lib/libcrypto/sha/asm/sha512-x86_64.pl | 2 +- lib/libcrypto/whrlpool/asm/wp-x86_64.pl | 2 +- lib/libcrypto/x86_64cpuid.pl | 4 +- share/man/man9/Makefile | 4 +- share/man/man9/clockintr_bind.9 | 296 ++++++++++++++++++ sys/arch/amd64/amd64/cpu.c | 4 +- sys/dev/ic/qwx.c | 8 +- sys/dev/ic/qwxvar.h | 4 +- usr.sbin/btrace/btrace.c | 123 +++++--- 39 files changed, 531 insertions(+), 183 deletions(-) create mode 100644 share/man/man9/clockintr_bind.9 diff --git a/distrib/sets/lists/comp/mi b/distrib/sets/lists/comp/mi index a54f944c1..c548e1f55 100644 --- a/distrib/sets/lists/comp/mi +++ b/distrib/sets/lists/comp/mi @@ -3105,6 +3105,7 @@ ./usr/share/man/man9/bus_dma.9 ./usr/share/man/man9/bus_space.9 ./usr/share/man/man9/clockintr.9 +./usr/share/man/man9/clockintr_bind.9 ./usr/share/man/man9/cond_init.9 ./usr/share/man/man9/config_attach.9 ./usr/share/man/man9/config_defer.9 diff --git a/lib/libcrypto/aes/asm/aes-x86_64.pl b/lib/libcrypto/aes/asm/aes-x86_64.pl index d0fbb23f4..70ec2e34e 100755 --- a/lib/libcrypto/aes/asm/aes-x86_64.pl +++ b/lib/libcrypto/aes/asm/aes-x86_64.pl @@ -318,7 +318,7 @@ $code.=<<___; .type _x86_64_AES_encrypt,\@abi-omnipotent .align 16 _x86_64_AES_encrypt: - endbr64 + _CET_ENDBR xor 0($key),$s0 # xor with key xor 4($key),$s1 xor 8($key),$s2 @@ -549,7 +549,7 @@ $code.=<<___; .type _x86_64_AES_encrypt_compact,\@abi-omnipotent .align 16 _x86_64_AES_encrypt_compact: - endbr64 + _CET_ENDBR lea 128($sbox),$inp # size optimization mov 0-128($inp),$acc1 # prefetch Te4 mov 32-128($inp),$acc2 @@ -595,7 +595,7 @@ $code.=<<___; .hidden asm_AES_encrypt asm_AES_encrypt: AES_encrypt: - endbr64 + _CET_ENDBR push %rbx push %rbp push %r12 @@ -887,7 +887,7 @@ $code.=<<___; .type _x86_64_AES_decrypt,\@abi-omnipotent .align 16 _x86_64_AES_decrypt: - endbr64 + _CET_ENDBR xor 0($key),$s0 # xor with key xor 4($key),$s1 xor 8($key),$s2 @@ -1142,7 +1142,7 @@ $code.=<<___; .type _x86_64_AES_decrypt_compact,\@abi-omnipotent .align 16 _x86_64_AES_decrypt_compact: - endbr64 + _CET_ENDBR lea 128($sbox),$inp # size optimization mov 0-128($inp),$acc1 # prefetch Td4 mov 32-128($inp),$acc2 @@ -1197,7 +1197,7 @@ $code.=<<___; .hidden asm_AES_decrypt asm_AES_decrypt: AES_decrypt: - endbr64 + _CET_ENDBR push %rbx push %rbp push %r12 @@ -1297,7 +1297,7 @@ $code.=<<___; .type AES_set_encrypt_key,\@function,3 .align 16 AES_set_encrypt_key: - endbr64 + _CET_ENDBR push %rbx push %rbp push %r12 # redundant, but allows to share @@ -1323,7 +1323,7 @@ AES_set_encrypt_key: .type _x86_64_AES_set_encrypt_key,\@abi-omnipotent .align 16 _x86_64_AES_set_encrypt_key: - endbr64 + _CET_ENDBR mov %esi,%ecx # %ecx=bits mov %rdi,%rsi # %rsi=userKey mov %rdx,%rdi # %rdi=key @@ -1569,7 +1569,7 @@ $code.=<<___; .type AES_set_decrypt_key,\@function,3 .align 16 AES_set_decrypt_key: - endbr64 + _CET_ENDBR push %rbx push %rbp push %r12 @@ -1669,7 +1669,7 @@ $code.=<<___; .hidden asm_AES_cbc_encrypt asm_AES_cbc_encrypt: AES_cbc_encrypt: - endbr64 + _CET_ENDBR cmp \$0,%rdx # check length je .Lcbc_epilogue pushfq @@ -2561,7 +2561,7 @@ $code.=<<___; .type block_se_handler,\@abi-omnipotent .align 16 block_se_handler: - endbr64 + _CET_ENDBR push %rsi push %rdi push %rbx @@ -2620,7 +2620,7 @@ block_se_handler: .type key_se_handler,\@abi-omnipotent .align 16 key_se_handler: - endbr64 + _CET_ENDBR push %rsi push %rdi push %rbx @@ -2678,7 +2678,7 @@ key_se_handler: .type cbc_se_handler,\@abi-omnipotent .align 16 cbc_se_handler: - endbr64 + _CET_ENDBR push %rsi push %rdi push %rbx diff --git a/lib/libcrypto/aes/asm/aesni-sha1-x86_64.pl b/lib/libcrypto/aes/asm/aesni-sha1-x86_64.pl index 879d16793..5eb5b7bf6 100644 --- a/lib/libcrypto/aes/asm/aesni-sha1-x86_64.pl +++ b/lib/libcrypto/aes/asm/aesni-sha1-x86_64.pl @@ -89,7 +89,7 @@ $code.=<<___; .type aesni_cbc_sha1_enc,\@abi-omnipotent .align 16 aesni_cbc_sha1_enc: - endbr64 + _CET_ENDBR # caller should check for SSSE3 and AES-NI bits mov OPENSSL_ia32cap_P+0(%rip),%r10d mov OPENSSL_ia32cap_P+4(%rip),%r11d @@ -133,7 +133,7 @@ $code.=<<___; .type aesni_cbc_sha1_enc_ssse3,\@function,6 .align 16 aesni_cbc_sha1_enc_ssse3: - endbr64 + _CET_ENDBR mov `($win64?56:8)`(%rsp),$inp # load 7th argument #shr \$6,$len # debugging artefact #jz .Lepilogue_ssse3 # debugging artefact @@ -652,7 +652,7 @@ $code.=<<___; .type aesni_cbc_sha1_enc_avx,\@function,6 .align 16 aesni_cbc_sha1_enc_avx: - endbr64 + _CET_ENDBR mov `($win64?56:8)`(%rsp),$inp # load 7th argument #shr \$6,$len # debugging artefact #jz .Lepilogue_avx # debugging artefact @@ -1103,7 +1103,7 @@ $code.=<<___; .type ssse3_handler,\@abi-omnipotent .align 16 ssse3_handler: - endbr64 + _CET_ENDBR push %rsi push %rdi push %rbx diff --git a/lib/libcrypto/aes/asm/aesni-x86_64.pl b/lib/libcrypto/aes/asm/aesni-x86_64.pl index e09635d1f..726384085 100644 --- a/lib/libcrypto/aes/asm/aesni-x86_64.pl +++ b/lib/libcrypto/aes/asm/aesni-x86_64.pl @@ -242,7 +242,7 @@ $code.=<<___; .type ${PREFIX}_encrypt,\@abi-omnipotent .align 16 ${PREFIX}_encrypt: - endbr64 + _CET_ENDBR movups ($inp),$inout0 # load input mov 240($key),$rounds # key->rounds ___ @@ -256,7 +256,7 @@ $code.=<<___; .type ${PREFIX}_decrypt,\@abi-omnipotent .align 16 ${PREFIX}_decrypt: - endbr64 + _CET_ENDBR movups ($inp),$inout0 # load input mov 240($key),$rounds # key->rounds ___ @@ -286,7 +286,7 @@ $code.=<<___; .type _aesni_${dir}rypt3,\@abi-omnipotent .align 16 _aesni_${dir}rypt3: - endbr64 + _CET_ENDBR $movkey ($key),$rndkey0 shr \$1,$rounds $movkey 16($key),$rndkey1 @@ -331,7 +331,7 @@ $code.=<<___; .type _aesni_${dir}rypt4,\@abi-omnipotent .align 16 _aesni_${dir}rypt4: - endbr64 + _CET_ENDBR $movkey ($key),$rndkey0 shr \$1,$rounds $movkey 16($key),$rndkey1 @@ -377,7 +377,7 @@ $code.=<<___; .type _aesni_${dir}rypt6,\@abi-omnipotent .align 16 _aesni_${dir}rypt6: - endbr64 + _CET_ENDBR $movkey ($key),$rndkey0 shr \$1,$rounds $movkey 16($key),$rndkey1 @@ -442,7 +442,7 @@ $code.=<<___; .type _aesni_${dir}rypt8,\@abi-omnipotent .align 16 _aesni_${dir}rypt8: - endbr64 + _CET_ENDBR $movkey ($key),$rndkey0 shr \$1,$rounds $movkey 16($key),$rndkey1 @@ -531,7 +531,7 @@ $code.=<<___; .type aesni_ecb_encrypt,\@function,5 .align 16 aesni_ecb_encrypt: - endbr64 + _CET_ENDBR and \$-16,$len jz .Lecb_ret @@ -838,7 +838,7 @@ $code.=<<___; .type aesni_ccm64_encrypt_blocks,\@function,6 .align 16 aesni_ccm64_encrypt_blocks: - endbr64 + _CET_ENDBR ___ $code.=<<___ if ($win64); lea -0x58(%rsp),%rsp @@ -919,6 +919,7 @@ $code.=<<___; .type aesni_ccm64_decrypt_blocks,\@function,6 .align 16 aesni_ccm64_decrypt_blocks: + _CET_ENDBR ___ $code.=<<___ if ($win64); lea -0x58(%rsp),%rsp @@ -1027,7 +1028,7 @@ $code.=<<___; .type aesni_ctr32_encrypt_blocks,\@function,5 .align 16 aesni_ctr32_encrypt_blocks: - endbr64 + _CET_ENDBR lea (%rsp),%rax push %rbp sub \$$frame_size,%rsp @@ -1319,6 +1320,7 @@ $code.=<<___; .type aesni_xts_encrypt,\@function,6 .align 16 aesni_xts_encrypt: + _CET_ENDBR lea (%rsp),%rax push %rbp sub \$$frame_size,%rsp @@ -1713,6 +1715,7 @@ $code.=<<___; .type aesni_xts_decrypt,\@function,6 .align 16 aesni_xts_decrypt: + _CET_ENDBR lea (%rsp),%rax push %rbp sub \$$frame_size,%rsp @@ -2150,6 +2153,7 @@ $code.=<<___; .type ${PREFIX}_cbc_encrypt,\@function,6 .align 16 ${PREFIX}_cbc_encrypt: + _CET_ENDBR test $len,$len # check length jz .Lcbc_ret @@ -2491,7 +2495,7 @@ $code.=<<___; .type ${PREFIX}_set_decrypt_key,\@abi-omnipotent .align 16 ${PREFIX}_set_decrypt_key: - endbr64 + _CET_ENDBR sub \$8,%rsp call __aesni_set_encrypt_key shl \$4,$bits # rounds-1 after _aesni_set_encrypt_key @@ -2542,7 +2546,7 @@ $code.=<<___; .type ${PREFIX}_set_encrypt_key,\@abi-omnipotent .align 16 ${PREFIX}_set_encrypt_key: - endbr64 + _CET_ENDBR __aesni_set_encrypt_key: sub \$8,%rsp mov \$-1,%rax @@ -2764,7 +2768,7 @@ $code.=<<___ if ($PREFIX eq "aesni"); .type ecb_se_handler,\@abi-omnipotent .align 16 ecb_se_handler: - endbr64 + _CET_ENDBR push %rsi push %rdi push %rbx @@ -2784,7 +2788,7 @@ ecb_se_handler: .type ccm64_se_handler,\@abi-omnipotent .align 16 ccm64_se_handler: - endbr64 + _CET_ENDBR push %rsi push %rdi push %rbx @@ -2826,7 +2830,7 @@ ccm64_se_handler: .type ctr32_se_handler,\@abi-omnipotent .align 16 ctr32_se_handler: - endbr64 + _CET_ENDBR push %rsi push %rdi push %rbx @@ -2862,7 +2866,7 @@ ctr32_se_handler: .type xts_se_handler,\@abi-omnipotent .align 16 xts_se_handler: - endbr64 + _CET_ENDBR push %rsi push %rdi push %rbx @@ -2904,7 +2908,7 @@ $code.=<<___; .type cbc_se_handler,\@abi-omnipotent .align 16 cbc_se_handler: - endbr64 + _CET_ENDBR push %rsi push %rdi push %rbx diff --git a/lib/libcrypto/aes/asm/bsaes-x86_64.pl b/lib/libcrypto/aes/asm/bsaes-x86_64.pl index f7cf13810..f8e326c0d 100644 --- a/lib/libcrypto/aes/asm/bsaes-x86_64.pl +++ b/lib/libcrypto/aes/asm/bsaes-x86_64.pl @@ -813,7 +813,7 @@ $code.=<<___; .type _bsaes_encrypt8,\@abi-omnipotent .align 64 _bsaes_encrypt8: - endbr64 + _CET_ENDBR lea .LBS0(%rip), $const # constants table movdqa ($key), @XMM[9] # round 0 key @@ -878,7 +878,7 @@ $code.=<<___; .type _bsaes_decrypt8,\@abi-omnipotent .align 64 _bsaes_decrypt8: - endbr64 + _CET_ENDBR lea .LBS0(%rip), $const # constants table movdqa ($key), @XMM[9] # round 0 key @@ -970,7 +970,7 @@ $code.=<<___; .type _bsaes_key_convert,\@abi-omnipotent .align 16 _bsaes_key_convert: - endbr64 + _CET_ENDBR lea .Lmasks(%rip), $const movdqu ($inp), %xmm7 # load round 0 key lea 0x10($inp), $inp @@ -1060,7 +1060,7 @@ $code.=<<___; .type bsaes_enc_key_convert,\@function,2 .align 16 bsaes_enc_key_convert: - endbr64 + _CET_ENDBR mov 240($inp),%r10d # pass rounds mov $inp,%rcx # pass key mov $out,%rax # pass key schedule @@ -1075,7 +1075,7 @@ bsaes_enc_key_convert: .align 16 bsaes_encrypt_128: .Lenc128_loop: - endbr64 + _CET_ENDBR movdqu 0x00($inp), @XMM[0] # load input movdqu 0x10($inp), @XMM[1] movdqu 0x20($inp), @XMM[2] @@ -1108,7 +1108,7 @@ bsaes_encrypt_128: .type bsaes_dec_key_convert,\@function,2 .align 16 bsaes_dec_key_convert: - endbr64 + _CET_ENDBR mov 240($inp),%r10d # pass rounds mov $inp,%rcx # pass key mov $out,%rax # pass key schedule @@ -1123,7 +1123,7 @@ bsaes_dec_key_convert: .type bsaes_decrypt_128,\@function,4 .align 16 bsaes_decrypt_128: - endbr64 + _CET_ENDBR .Ldec128_loop: movdqu 0x00($inp), @XMM[0] # load input movdqu 0x10($inp), @XMM[1] @@ -1169,7 +1169,7 @@ $code.=<<___; .type bsaes_ecb_encrypt_blocks,\@abi-omnipotent .align 16 bsaes_ecb_encrypt_blocks: - endbr64 + _CET_ENDBR mov %rsp, %rax .Lecb_enc_prologue: push %rbp @@ -1371,7 +1371,7 @@ $code.=<<___; .type bsaes_ecb_decrypt_blocks,\@abi-omnipotent .align 16 bsaes_ecb_decrypt_blocks: - endbr64 + _CET_ENDBR mov %rsp, %rax .Lecb_dec_prologue: push %rbp @@ -1577,7 +1577,7 @@ $code.=<<___; .type bsaes_cbc_encrypt,\@abi-omnipotent .align 16 bsaes_cbc_encrypt: - endbr64 + _CET_ENDBR ___ $code.=<<___ if ($win64); mov 48(%rsp),$arg6 # pull direction flag @@ -1865,7 +1865,7 @@ $code.=<<___; .type bsaes_ctr32_encrypt_blocks,\@abi-omnipotent .align 16 bsaes_ctr32_encrypt_blocks: - endbr64 + _CET_ENDBR mov %rsp, %rax .Lctr_enc_prologue: push %rbp @@ -2107,7 +2107,7 @@ $code.=<<___; .type bsaes_xts_encrypt,\@abi-omnipotent .align 16 bsaes_xts_encrypt: - endbr64 + _CET_ENDBR mov %rsp, %rax .Lxts_enc_prologue: push %rbp @@ -2489,7 +2489,7 @@ $code.=<<___; .type bsaes_xts_decrypt,\@abi-omnipotent .align 16 bsaes_xts_decrypt: - endbr64 + _CET_ENDBR mov %rsp, %rax .Lxts_dec_prologue: push %rbp @@ -2966,7 +2966,7 @@ $code.=<<___; .type se_handler,\@abi-omnipotent .align 16 se_handler: - endbr64 + _CET_ENDBR push %rsi push %rdi push %rbx diff --git a/lib/libcrypto/aes/asm/vpaes-x86_64.pl b/lib/libcrypto/aes/asm/vpaes-x86_64.pl index f15580c0e..93ee89b3b 100644 --- a/lib/libcrypto/aes/asm/vpaes-x86_64.pl +++ b/lib/libcrypto/aes/asm/vpaes-x86_64.pl @@ -82,7 +82,7 @@ $code.=<<___; .type _vpaes_encrypt_core,\@abi-omnipotent .align 16 _vpaes_encrypt_core: - endbr64 + _CET_ENDBR mov %rdx, %r9 mov \$16, %r11 mov 240(%rdx),%eax @@ -173,7 +173,7 @@ _vpaes_encrypt_core: .type _vpaes_decrypt_core,\@abi-omnipotent .align 16 _vpaes_decrypt_core: - endbr64 + _CET_ENDBR mov %rdx, %r9 # load key mov 240(%rdx),%eax movdqa %xmm9, %xmm1 @@ -281,7 +281,7 @@ _vpaes_decrypt_core: .type _vpaes_schedule_core,\@abi-omnipotent .align 16 _vpaes_schedule_core: - endbr64 + _CET_ENDBR # rdi = key # rsi = size in bits # rdx = buffer @@ -467,7 +467,7 @@ _vpaes_schedule_core: .type _vpaes_schedule_192_smear,\@abi-omnipotent .align 16 _vpaes_schedule_192_smear: - endbr64 + _CET_ENDBR pshufd \$0x80, %xmm6, %xmm0 # d c 0 0 -> c 0 0 0 pxor %xmm0, %xmm6 # -> c+d c 0 0 pshufd \$0xFE, %xmm7, %xmm0 # b a _ _ -> b b b a @@ -499,7 +499,7 @@ _vpaes_schedule_192_smear: .type _vpaes_schedule_round,\@abi-omnipotent .align 16 _vpaes_schedule_round: - endbr64 + _CET_ENDBR # extract rcon from xmm8 pxor %xmm1, %xmm1 palignr \$15, %xmm8, %xmm1 @@ -567,7 +567,7 @@ _vpaes_schedule_low_round: .type _vpaes_schedule_transform,\@abi-omnipotent .align 16 _vpaes_schedule_transform: - endbr64 + _CET_ENDBR movdqa %xmm9, %xmm1 pandn %xmm0, %xmm1 psrld \$4, %xmm1 @@ -606,7 +606,7 @@ _vpaes_schedule_transform: .type _vpaes_schedule_mangle,\@abi-omnipotent .align 16 _vpaes_schedule_mangle: - endbr64 + _CET_ENDBR movdqa %xmm0, %xmm4 # save xmm0 for later movdqa .Lk_mc_forward(%rip),%xmm5 test %rcx, %rcx @@ -680,7 +680,7 @@ _vpaes_schedule_mangle: .type ${PREFIX}_set_encrypt_key,\@function,3 .align 16 ${PREFIX}_set_encrypt_key: - endbr64 + _CET_ENDBR ___ $code.=<<___ if ($win64); lea -0xb8(%rsp),%rsp @@ -729,7 +729,7 @@ $code.=<<___; .type ${PREFIX}_set_decrypt_key,\@function,3 .align 16 ${PREFIX}_set_decrypt_key: - endbr64 + _CET_ENDBR ___ $code.=<<___ if ($win64); lea -0xb8(%rsp),%rsp @@ -783,7 +783,7 @@ $code.=<<___; .type ${PREFIX}_encrypt,\@function,3 .align 16 ${PREFIX}_encrypt: - endbr64 + _CET_ENDBR ___ $code.=<<___ if ($win64); lea -0xb8(%rsp),%rsp @@ -827,7 +827,7 @@ $code.=<<___; .type ${PREFIX}_decrypt,\@function,3 .align 16 ${PREFIX}_decrypt: - endbr64 + _CET_ENDBR ___ $code.=<<___ if ($win64); lea -0xb8(%rsp),%rsp @@ -877,7 +877,7 @@ $code.=<<___; .type ${PREFIX}_cbc_encrypt,\@function,6 .align 16 ${PREFIX}_cbc_encrypt: - endbr64 + _CET_ENDBR xchg $key,$len ___ ($len,$key)=($key,$len); @@ -961,7 +961,7 @@ $code.=<<___; .type _vpaes_preheat,\@abi-omnipotent .align 16 _vpaes_preheat: - endbr64 + _CET_ENDBR lea .Lk_s0F(%rip), %r10 movdqa -0x20(%r10), %xmm10 # .Lk_inv movdqa -0x10(%r10), %xmm11 # .Lk_inv+16 @@ -1092,7 +1092,7 @@ $code.=<<___; .type se_handler,\@abi-omnipotent .align 16 se_handler: - endbr64 + _CET_ENDBR push %rsi push %rdi push %rbx diff --git a/lib/libcrypto/bn/arch/amd64/bignum_add.S b/lib/libcrypto/bn/arch/amd64/bignum_add.S index 06298ca69..5fe4aae7a 100644 --- a/lib/libcrypto/bn/arch/amd64/bignum_add.S +++ b/lib/libcrypto/bn/arch/amd64/bignum_add.S @@ -49,7 +49,7 @@ S2N_BN_SYMBOL(bignum_add): - endbr64 + _CET_ENDBR #if WINDOWS_ABI push rdi diff --git a/lib/libcrypto/bn/arch/amd64/bignum_cmadd.S b/lib/libcrypto/bn/arch/amd64/bignum_cmadd.S index 5ad712749..25ba17bce 100644 --- a/lib/libcrypto/bn/arch/amd64/bignum_cmadd.S +++ b/lib/libcrypto/bn/arch/amd64/bignum_cmadd.S @@ -54,7 +54,7 @@ S2N_BN_SYMBOL(bignum_cmadd): - endbr64 + _CET_ENDBR #if WINDOWS_ABI push rdi diff --git a/lib/libcrypto/bn/arch/amd64/bignum_cmul.S b/lib/libcrypto/bn/arch/amd64/bignum_cmul.S index 9199c8f48..12f785d63 100644 --- a/lib/libcrypto/bn/arch/amd64/bignum_cmul.S +++ b/lib/libcrypto/bn/arch/amd64/bignum_cmul.S @@ -51,7 +51,7 @@ S2N_BN_SYMBOL(bignum_cmul): - endbr64 + _CET_ENDBR #if WINDOWS_ABI push rdi diff --git a/lib/libcrypto/bn/arch/amd64/bignum_mul.S b/lib/libcrypto/bn/arch/amd64/bignum_mul.S index 2d7ed1909..a3552679a 100644 --- a/lib/libcrypto/bn/arch/amd64/bignum_mul.S +++ b/lib/libcrypto/bn/arch/amd64/bignum_mul.S @@ -59,7 +59,7 @@ S2N_BN_SYMBOL(bignum_mul): - endbr64 + _CET_ENDBR #if WINDOWS_ABI push rdi diff --git a/lib/libcrypto/bn/arch/amd64/bignum_mul_4_8_alt.S b/lib/libcrypto/bn/arch/amd64/bignum_mul_4_8_alt.S index f02b09b28..70ff69e37 100644 --- a/lib/libcrypto/bn/arch/amd64/bignum_mul_4_8_alt.S +++ b/lib/libcrypto/bn/arch/amd64/bignum_mul_4_8_alt.S @@ -72,7 +72,7 @@ adc h, rdx S2N_BN_SYMBOL(bignum_mul_4_8_alt): - endbr64 + _CET_ENDBR #if WINDOWS_ABI push rdi diff --git a/lib/libcrypto/bn/arch/amd64/bignum_mul_8_16_alt.S b/lib/libcrypto/bn/arch/amd64/bignum_mul_8_16_alt.S index 97be83e1f..066403b07 100644 --- a/lib/libcrypto/bn/arch/amd64/bignum_mul_8_16_alt.S +++ b/lib/libcrypto/bn/arch/amd64/bignum_mul_8_16_alt.S @@ -72,7 +72,7 @@ adc h, rdx S2N_BN_SYMBOL(bignum_mul_8_16_alt): - endbr64 + _CET_ENDBR #if WINDOWS_ABI push rdi diff --git a/lib/libcrypto/bn/arch/amd64/bignum_sqr.S b/lib/libcrypto/bn/arch/amd64/bignum_sqr.S index c4a0cabf3..54e3f5944 100644 --- a/lib/libcrypto/bn/arch/amd64/bignum_sqr.S +++ b/lib/libcrypto/bn/arch/amd64/bignum_sqr.S @@ -62,7 +62,7 @@ #define llshort ebp S2N_BN_SYMBOL(bignum_sqr): - endbr64 + _CET_ENDBR #if WINDOWS_ABI push rdi diff --git a/lib/libcrypto/bn/arch/amd64/bignum_sqr_4_8_alt.S b/lib/libcrypto/bn/arch/amd64/bignum_sqr_4_8_alt.S index b228414dc..7c534ae90 100644 --- a/lib/libcrypto/bn/arch/amd64/bignum_sqr_4_8_alt.S +++ b/lib/libcrypto/bn/arch/amd64/bignum_sqr_4_8_alt.S @@ -71,7 +71,7 @@ adc c, 0 S2N_BN_SYMBOL(bignum_sqr_4_8_alt): - endbr64 + _CET_ENDBR #if WINDOWS_ABI push rdi diff --git a/lib/libcrypto/bn/arch/amd64/bignum_sqr_8_16_alt.S b/lib/libcrypto/bn/arch/amd64/bignum_sqr_8_16_alt.S index 04efeec7e..ac0b6f96c 100644 --- a/lib/libcrypto/bn/arch/amd64/bignum_sqr_8_16_alt.S +++ b/lib/libcrypto/bn/arch/amd64/bignum_sqr_8_16_alt.S @@ -103,7 +103,7 @@ adc c, 0 S2N_BN_SYMBOL(bignum_sqr_8_16_alt): - endbr64 + _CET_ENDBR #if WINDOWS_ABI push rdi diff --git a/lib/libcrypto/bn/arch/amd64/bignum_sub.S b/lib/libcrypto/bn/arch/amd64/bignum_sub.S index 11a9bd7ed..3ff8a3051 100644 --- a/lib/libcrypto/bn/arch/amd64/bignum_sub.S +++ b/lib/libcrypto/bn/arch/amd64/bignum_sub.S @@ -49,7 +49,7 @@ S2N_BN_SYMBOL(bignum_sub): - endbr64 + _CET_ENDBR #if WINDOWS_ABI push rdi diff --git a/lib/libcrypto/bn/arch/amd64/word_clz.S b/lib/libcrypto/bn/arch/amd64/word_clz.S index 464a9d90f..3926fcd4b 100644 --- a/lib/libcrypto/bn/arch/amd64/word_clz.S +++ b/lib/libcrypto/bn/arch/amd64/word_clz.S @@ -30,7 +30,7 @@ .text S2N_BN_SYMBOL(word_clz): - endbr64 + _CET_ENDBR #if WINDOWS_ABI push rdi diff --git a/lib/libcrypto/bn/asm/modexp512-x86_64.pl b/lib/libcrypto/bn/asm/modexp512-x86_64.pl index af78fff54..8645d5adc 100644 --- a/lib/libcrypto/bn/asm/modexp512-x86_64.pl +++ b/lib/libcrypto/bn/asm/modexp512-x86_64.pl @@ -347,7 +347,7 @@ $code.=<<___; .type MULADD_128x512,\@abi-omnipotent .align 16 MULADD_128x512: - endbr64 + _CET_ENDBR ___ &MULSTEP_512([map("%r$_",(8..15))], "(+8*0)(%rcx)", "%rsi", "%rbp", "%rbx"); $code.=<<___; @@ -415,7 +415,7 @@ $code.=<<___; .type mont_reduce,\@abi-omnipotent .align 16 mont_reduce: - endbr64 + _CET_ENDBR ___ my $STACK_DEPTH = 8; @@ -678,7 +678,7 @@ $code.=<<___; .type mont_mul_a3b,\@abi-omnipotent .align 16 mont_mul_a3b: - endbr64 + _CET_ENDBR # # multiply tmp = src1 * src2 # For multiply: dst = rcx, src1 = rdi, src2 = rsi @@ -1080,7 +1080,7 @@ $code.=<<___; .type sqr_reduce,\@abi-omnipotent .align 16 sqr_reduce: - endbr64 + _CET_ENDBR mov (+$pResult_offset+8)(%rsp), %rcx ___ &SQR_512("%rsp+$tmp16_offset+8", "%rcx", [map("%r$_",(10..15,8..9))], "%rbx", "%rbp", "%rsi", "%rdi"); @@ -1110,7 +1110,7 @@ $code.=<<___; .globl mod_exp_512 .type mod_exp_512,\@function,4 mod_exp_512: - endbr64 + _CET_ENDBR push %rbp push %rbx push %r12 diff --git a/lib/libcrypto/bn/asm/x86_64-mont.pl b/lib/libcrypto/bn/asm/x86_64-mont.pl index a6ff073c6..134c212fe 100755 --- a/lib/libcrypto/bn/asm/x86_64-mont.pl +++ b/lib/libcrypto/bn/asm/x86_64-mont.pl @@ -63,7 +63,7 @@ $code=<<___; .type bn_mul_mont,\@function,6 .align 16 bn_mul_mont: - endbr64 + _CET_ENDBR test \$3,${num}d jnz .Lmul_enter cmp \$8,${num}d @@ -279,7 +279,7 @@ $code.=<<___; .align 16 bn_mul4x_mont: .Lmul4x_enter: - endbr64 + _CET_ENDBR push %rbx push %rbp push %r12 @@ -708,7 +708,7 @@ $code.=<<___; .align 16 bn_sqr4x_mont: .Lsqr4x_enter: - endbr64 + _CET_ENDBR push %rbx push %rbp push %r12 diff --git a/lib/libcrypto/bn/asm/x86_64-mont5.pl b/lib/libcrypto/bn/asm/x86_64-mont5.pl index 3b3325a6c..38751ec5d 100755 --- a/lib/libcrypto/bn/asm/x86_64-mont5.pl +++ b/lib/libcrypto/bn/asm/x86_64-mont5.pl @@ -57,7 +57,7 @@ $code=<<___; .type bn_mul_mont_gather5,\@function,6 .align 64 bn_mul_mont_gather5: - endbr64 + _CET_ENDBR test \$3,${num}d jnz .Lmul_enter cmp \$8,${num}d @@ -388,7 +388,7 @@ $code.=<<___; .type bn_mul4x_mont_gather5,\@function,6 .align 16 bn_mul4x_mont_gather5: - endbr64 + _CET_ENDBR .Lmul4x_enter: mov ${num}d,${num}d movd `($win64?56:8)`(%rsp),%xmm5 # load 7th argument @@ -927,7 +927,7 @@ $code.=<<___; .type bn_scatter5,\@abi-omnipotent .align 16 bn_scatter5: - endbr64 + _CET_ENDBR cmp \$0, $num jz .Lscatter_epilogue lea ($tbl,$idx,8),$tbl @@ -946,7 +946,7 @@ bn_scatter5: .type bn_gather5,\@abi-omnipotent .align 16 bn_gather5: - endbr64 + _CET_ENDBR .LSEH_begin_bn_gather5: # Win64 thing, but harmless in other cases # I can't trust assembler to use specific encoding:-( .byte 0x4c,0x8d,0x14,0x24 # lea (%rsp),%r10 @@ -1057,7 +1057,7 @@ $code.=<<___; .type mul_handler,\@abi-omnipotent .align 16 mul_handler: - endbr64 + _CET_ENDBR push %rsi push %rdi push %rbx diff --git a/lib/libcrypto/bn/s2n_bignum_internal.h b/lib/libcrypto/bn/s2n_bignum_internal.h index f41368833..b82db7d01 100644 --- a/lib/libcrypto/bn/s2n_bignum_internal.h +++ b/lib/libcrypto/bn/s2n_bignum_internal.h @@ -18,6 +18,12 @@ # define S2N_BN_SYMBOL(name) name #endif +#ifdef __CET__ +# include +#else +# define _CET_ENDBR +#endif + #define S2N_BN_SYM_VISIBILITY_DIRECTIVE(name) .globl S2N_BN_SYMBOL(name) #ifdef S2N_BN_HIDE_SYMBOLS # ifdef __APPLE__ diff --git a/lib/libcrypto/camellia/asm/cmll-x86_64.pl b/lib/libcrypto/camellia/asm/cmll-x86_64.pl index 3ceed3e89..187f0596d 100644 --- a/lib/libcrypto/camellia/asm/cmll-x86_64.pl +++ b/lib/libcrypto/camellia/asm/cmll-x86_64.pl @@ -116,7 +116,7 @@ $code=<<___; .type Camellia_EncryptBlock,\@abi-omnipotent .align 16 Camellia_EncryptBlock: - endbr64 + _CET_ENDBR movl \$128,%eax subl $arg0d,%eax movl \$3,$arg0d @@ -129,7 +129,7 @@ Camellia_EncryptBlock: .align 16 .Lenc_rounds: Camellia_EncryptBlock_Rounds: - endbr64 + _CET_ENDBR push %rbx push %rbp push %r13 @@ -178,7 +178,7 @@ Camellia_EncryptBlock_Rounds: .type _x86_64_Camellia_encrypt,\@abi-omnipotent .align 16 _x86_64_Camellia_encrypt: - endbr64 + _CET_ENDBR xor 0($key),@S[1] xor 4($key),@S[0] # ^=key[0-3] xor 8($key),@S[3] @@ -229,7 +229,7 @@ $code.=<<___; .type Camellia_DecryptBlock,\@abi-omnipotent .align 16 Camellia_DecryptBlock: - endbr64 + _CET_ENDBR movl \$128,%eax subl $arg0d,%eax movl \$3,$arg0d @@ -242,7 +242,7 @@ Camellia_DecryptBlock: .align 16 .Ldec_rounds: Camellia_DecryptBlock_Rounds: - endbr64 + _CET_ENDBR push %rbx push %rbp push %r13 @@ -291,7 +291,7 @@ Camellia_DecryptBlock_Rounds: .type _x86_64_Camellia_decrypt,\@abi-omnipotent .align 16 _x86_64_Camellia_decrypt: - endbr64 + _CET_ENDBR xor 0($key),@S[1] xor 4($key),@S[0] # ^=key[0-3] xor 8($key),@S[3] @@ -406,7 +406,7 @@ $code.=<<___; .type Camellia_Ekeygen,\@function,3 .align 16 Camellia_Ekeygen: - endbr64 + _CET_ENDBR push %rbx push %rbp push %r13 @@ -637,7 +637,7 @@ $code.=<<___; .type Camellia_cbc_encrypt,\@function,6 .align 16 Camellia_cbc_encrypt: - endbr64 + _CET_ENDBR cmp \$0,%rdx je .Lcbc_abort push %rbx diff --git a/lib/libcrypto/err/err.c b/lib/libcrypto/err/err.c index 4b4be213b..036396bc1 100644 --- a/lib/libcrypto/err/err.c +++ b/lib/libcrypto/err/err.c @@ -1,4 +1,4 @@ -/* $OpenBSD: err.c,v 1.56 2023/07/28 10:23:19 tb Exp $ */ +/* $OpenBSD: err.c,v 1.58 2024/02/24 07:53:01 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -328,17 +328,14 @@ err_string_data_cmp(const ERR_STRING_DATA *a, const ERR_STRING_DATA *b) } static IMPLEMENT_LHASH_COMP_FN(err_string_data, ERR_STRING_DATA) -static -LHASH_OF(ERR_STRING_DATA) *int_err_get(int create) +static LHASH_OF(ERR_STRING_DATA) * +int_err_get(int create) { LHASH_OF(ERR_STRING_DATA) *ret = NULL; CRYPTO_w_lock(CRYPTO_LOCK_ERR); - if (!int_error_hash && create) { - CRYPTO_push_info("int_err_get (err.c)"); + if (!int_error_hash && create) int_error_hash = lh_ERR_STRING_DATA_new(); - CRYPTO_pop_info(); - } if (int_error_hash) ret = int_error_hash; CRYPTO_w_unlock(CRYPTO_LOCK_ERR); @@ -425,17 +422,14 @@ err_state_cmp(const ERR_STATE *a, const ERR_STATE *b) } static IMPLEMENT_LHASH_COMP_FN(err_state, ERR_STATE) -static -LHASH_OF(ERR_STATE) *int_thread_get(int create) +static LHASH_OF(ERR_STATE) * +int_thread_get(int create) { LHASH_OF(ERR_STATE) *ret = NULL; CRYPTO_w_lock(CRYPTO_LOCK_ERR); - if (!int_thread_hash && create) { - CRYPTO_push_info("int_thread_get (err.c)"); + if (!int_thread_hash && create) int_thread_hash = lh_ERR_STATE_new(); - CRYPTO_pop_info(); - } if (int_thread_hash) { int_thread_hash_references++; ret = int_thread_hash; diff --git a/lib/libcrypto/evp/evp_cipher.c b/lib/libcrypto/evp/evp_cipher.c index 12fa6e1d2..c2a88a559 100644 --- a/lib/libcrypto/evp/evp_cipher.c +++ b/lib/libcrypto/evp/evp_cipher.c @@ -1,4 +1,4 @@ -/* $OpenBSD: evp_cipher.c,v 1.19 2024/02/18 15:53:54 tb Exp $ */ +/* $OpenBSD: evp_cipher.c,v 1.20 2024/02/24 08:00:37 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -804,10 +804,6 @@ EVP_CIPHER_CTX_key_length(const EVP_CIPHER_CTX *ctx) int EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *ctx, int key_len) { - /* XXX - remove this. It's unused. */ - if (ctx->cipher->flags & EVP_CIPH_CUSTOM_KEY_LENGTH) - return EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_SET_KEY_LENGTH, - key_len, NULL); if (ctx->key_len == key_len) return 1; if (key_len > 0 && (ctx->cipher->flags & EVP_CIPH_VARIABLE_LENGTH)) { diff --git a/lib/libcrypto/md5/asm/md5-x86_64.pl b/lib/libcrypto/md5/asm/md5-x86_64.pl index 06d69094f..5001c3472 100755 --- a/lib/libcrypto/md5/asm/md5-x86_64.pl +++ b/lib/libcrypto/md5/asm/md5-x86_64.pl @@ -128,7 +128,7 @@ $code .= < +#else +#define _CET_ENDBR +#endif + +___ +} + print "#include \"x86_arch.h\"\n"; while($line=<>) { diff --git a/lib/libcrypto/rc4/asm/rc4-md5-x86_64.pl b/lib/libcrypto/rc4/asm/rc4-md5-x86_64.pl index 50d9f0444..094138cdf 100644 --- a/lib/libcrypto/rc4/asm/rc4-md5-x86_64.pl +++ b/lib/libcrypto/rc4/asm/rc4-md5-x86_64.pl @@ -109,7 +109,7 @@ $code.=<<___; .globl $func .type $func,\@function,$nargs $func: - endbr64 + _CET_ENDBR cmp \$0,$len je .Labort push %rbx @@ -454,7 +454,7 @@ $code.=<<___; .type RC4_set_key,\@function,3 .align 16 RC4_set_key: - endbr64 + _CET_ENDBR lea 8($dat),$dat lea ($inp,$len),$inp neg $len diff --git a/lib/libcrypto/rc4/asm/rc4-x86_64.pl b/lib/libcrypto/rc4/asm/rc4-x86_64.pl index c9dfdcb7d..89e46882a 100755 --- a/lib/libcrypto/rc4/asm/rc4-x86_64.pl +++ b/lib/libcrypto/rc4/asm/rc4-x86_64.pl @@ -128,7 +128,7 @@ $code=<<___; .type RC4,\@function,4 .align 16 RC4: - endbr64 + _CET_ENDBR or $len,$len jne .Lentry ret @@ -435,7 +435,7 @@ $code.=<<___; .type RC4_set_key,\@function,3 .align 16 RC4_set_key: - endbr64 + _CET_ENDBR lea 8($dat),$dat lea ($inp,$len),$inp neg $len diff --git a/lib/libcrypto/sha/asm/sha1-x86_64.pl b/lib/libcrypto/sha/asm/sha1-x86_64.pl index e15ff47f8..e080251df 100755 --- a/lib/libcrypto/sha/asm/sha1-x86_64.pl +++ b/lib/libcrypto/sha/asm/sha1-x86_64.pl @@ -222,7 +222,7 @@ $code.=<<___; .type sha1_block_data_order,\@function,3 .align 16 sha1_block_data_order: - endbr64 + _CET_ENDBR mov OPENSSL_ia32cap_P+0(%rip),%r9d mov OPENSSL_ia32cap_P+4(%rip),%r8d test \$IA32CAP_MASK1_SSSE3,%r8d # check SSSE3 bit @@ -310,7 +310,7 @@ $code.=<<___; .align 16 sha1_block_data_order_ssse3: _ssse3_shortcut: - endbr64 + _CET_ENDBR push %rbx push %rbp push %r12 @@ -731,7 +731,7 @@ $code.=<<___; .align 16 sha1_block_data_order_avx: _avx_shortcut: - endbr64 + _CET_ENDBR push %rbx push %rbp push %r12 @@ -1102,7 +1102,7 @@ $code.=<<___; .type se_handler,\@abi-omnipotent .align 16 se_handler: - endbr64 + _CET_ENDBR push %rsi push %rdi push %rbx diff --git a/lib/libcrypto/sha/asm/sha512-x86_64.pl b/lib/libcrypto/sha/asm/sha512-x86_64.pl index 120693fee..f7a4dad2c 100755 --- a/lib/libcrypto/sha/asm/sha512-x86_64.pl +++ b/lib/libcrypto/sha/asm/sha512-x86_64.pl @@ -175,7 +175,7 @@ $code=<<___; .type $func,\@function,4 .align 16 $func: - endbr64 + _CET_ENDBR push %rbx push %rbp push %r12 diff --git a/lib/libcrypto/whrlpool/asm/wp-x86_64.pl b/lib/libcrypto/whrlpool/asm/wp-x86_64.pl index 7958f6d28..2a3902430 100644 --- a/lib/libcrypto/whrlpool/asm/wp-x86_64.pl +++ b/lib/libcrypto/whrlpool/asm/wp-x86_64.pl @@ -57,7 +57,7 @@ $code=<<___; .type $func,\@function,3 .align 16 $func: - endbr64 + _CET_ENDBR push %rbx push %rbp push %r12 diff --git a/lib/libcrypto/x86_64cpuid.pl b/lib/libcrypto/x86_64cpuid.pl index dc56732a2..5e85c40c9 100644 --- a/lib/libcrypto/x86_64cpuid.pl +++ b/lib/libcrypto/x86_64cpuid.pl @@ -18,7 +18,7 @@ print<<___; .extern OPENSSL_cpuid_setup .hidden OPENSSL_cpuid_setup .section .init - endbr64 + _CET_ENDBR call OPENSSL_cpuid_setup .extern OPENSSL_ia32cap_P @@ -30,7 +30,7 @@ print<<___; .type OPENSSL_ia32_cpuid,\@abi-omnipotent .align 16 OPENSSL_ia32_cpuid: - endbr64 + _CET_ENDBR mov %rbx,%r8 # save %rbx xor %eax,%eax diff --git a/share/man/man9/Makefile b/share/man/man9/Makefile index c990a8ae7..4bf92b282 100644 --- a/share/man/man9/Makefile +++ b/share/man/man9/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.309 2023/12/21 02:57:14 jsg Exp $ +# $OpenBSD: Makefile,v 1.310 2024/02/24 16:21:32 cheloha Exp $ # $NetBSD: Makefile,v 1.4 1996/01/09 03:23:01 thorpej Exp $ # Makefile for section 9 (kernel function and variable) manual pages. @@ -9,7 +9,7 @@ MAN= aml_evalnode.9 atomic_add_int.9 atomic_cas_uint.9 \ audio.9 autoconf.9 \ bemtoh32.9 bio_register.9 bintimeadd.9 boot.9 bpf_mtap.9 buffercache.9 \ bufq_init.9 bus_dma.9 bus_space.9 \ - clockintr.9 \ + clockintr.9 clockintr_bind.9 \ copy.9 cond_init.9 config_attach.9 config_defer.9 counters_alloc.9 \ cpumem_get.9 crypto.9 \ delay.9 disk.9 disklabel.9 dma_alloc.9 dohooks.9 \ diff --git a/share/man/man9/clockintr_bind.9 b/share/man/man9/clockintr_bind.9 new file mode 100644 index 000000000..38b89fbd3 --- /dev/null +++ b/share/man/man9/clockintr_bind.9 @@ -0,0 +1,296 @@ +.\" $OpenBSD: clockintr_bind.9,v 1.1 2024/02/24 16:21:32 cheloha Exp $ +.\" +.\" Copyright (c) 2023-2024 Scott Cheloha +.\" +.\" 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: February 24 2024 $ +.Dt CLOCKINTR_BIND 9 +.Os +.Sh NAME +.Nm clockintr_bind , +.Nm clockintr_schedule , +.Nm clockintr_advance , +.Nm clockintr_cancel , +.Nm clockintr_unbind , +.Nm clockintr_stagger , +.Nm clockrequest_advance +.Nd execute a function in a clock interrupt context +.Sh SYNOPSIS +.In sys/clockintr.h +.Ft void +.Fo clockintr_bind +.Fa "struct clockintr *cl" +.Fa "struct cpu_info *cpu" +.Fa "void (*callback)(struct clockrequest *cr, void *cf, void *arg)" +.Fa "void *arg" +.Fc +.Ft void +.Fo clockintr_schedule +.Fa "struct clockintr *cl" +.Fa "uint64_t abs" +.Fc +.Ft uint64_t +.Fo clockintr_advance +.Fa "struct clockintr *cl" +.Fa "uint64_t interval" +.Fc +.Ft void +.Fo clockintr_cancel +.Fa "struct clockintr *cl" +.Fc +.Ft void +.Fo clockintr_unbind +.Fa "struct clockintr *cl" +.Fa "uint32_t flags" +.Fc +.Ft void +.Fo clockintr_stagger +.Fa "struct clockintr *cl" +.Fa "uint64_t interval" +.Fa "uint32_t numer" +.Fa "uint32_t denom" +.Fc +.Ft uint64_t +.Fo clockrequest_advance +.Fa "struct clockrequest *cr" +.Fa "uint64_t interval" +.Fc +.\" .Fn clockrequest_advance_random is intentionally undocumented. +.\" It may be removed in the future. New code should not use it. +.Sh DESCRIPTION +The clock interrupt subsystem schedules functions for asynchronous execution +from the clock interrupt context on a particular CPU. +.Pp +Clock interrupts are well-suited for timekeeping, +scheduling, +and statistical profiling. +Applications with more relaxed latency requirements should use timeouts +to schedule asynchronous execution; +see +.Xr timeout_add 9 +for details. +.Pp +The +.Fn clockintr_bind +function initializes the clock interrupt object +.Fa cl . +When +.Fa cl +expires, +its +.Fa callback +function is executed from the +.Dv IPL_CLOCK +context on its host +.Fa cpu +without any locks or mutexes. +The callback function must not block. +Its parameters are as follows: +.Bl -tag -width indent +.It Fa cr +A private +.Vt clockrequest +object. +May be used to request rescheduling; +see +.Fn clockrequest_advance +below. +.It Fa cf +The +.Fa cpu Ns 's +current machine-dependent clockframe. +.It Fa arg +The +.Fa arg +given to +.Fn clockintr_bind . +.El +.Pp +The memory pointed to by +.Fa cl +must be zeroed before it is first bound. +It is an error to use +.Fa cl +as argument to any other function in the +.Vt clockintr +API before it is bound. +It is an error to rebind +.Fa cl +without first unbinding it; +see +.Fn clockintr_unbind +below. +.Pp +The +.Fn clockintr_schedule +function schedules +.Fa cl +to expire at the absolute time +.Fa abs +on the system uptime clock. +The subsystem will never execute +.Fa cl Ns 's +callback function before this expiration time, +though its execution may be delayed by other activity on the system. +.Pp +The +.Fn clockintr_advance +function schedules +.Fa cl +to expire at the next terminus of the given +.Fa interval , +a non-zero count of nanoseconds, +relative to +.Fa cl Ns 's +current expiration time. +Periodic clock interrupts should be scheduled with +.Fn clockintr_advance +to keep the execution period from drifting. +.Pp +The +.Fn clockintr_cancel +function cancels any pending expiration of +.Fa cl . +.Pp +The +.Fn clockintr_unbind +function cancels any pending expiration of +.Fa cl +and severs the binding between +.Fa cl +and its host +.Fa cpu . +Upon return, +.Fa cl +may be rebound with +.Fn clockintr_bind . +The call may be configured with zero or more of the following +.Fa flags : +.Bl -tag -width CL_BARRIER +.It Dv CL_BARRIER +If +.Fa cl Ns 's +callback function is executing, +block until it returns. +By default, +the caller does not block. +Useful when +.Fa arg +is a shared reference. +.El +.Pp +The +.Fn clockintr_stagger +function resets +.Fa cl Ns 's +expiration time to a fraction of the given +.Fa interval , +a count of nanoseconds. +Specifically, +.Fa cl Ns 's +expiration time is reset to +.Pq Fa interval Ms / Fa denom Ms * Fa numer . +Periodic clock interrupts bound to multiple CPUs may be staggered +to reduce the likelihood that their callback functions will execute +simultaneously and compete for a shared resource. +It is an error if +.Fa numer +is greater than or equal to +.Fa denom . +It is an error if +.Fa cl +is already scheduled to expire. +.Pp +The +.Fn clockrequest_advance +function is similar to +.Fn clockintr_advance , +except that +(a) it may only be called during the execution of a +.Fa callback +function, +(b) it accepts a +.Vt clockrequest +pointer as argument, +and (c) scheduling requests submitted with the interface are not fulfilled +until the callback function returns. +When the callback function returns, +scheduling requests are only committed to the underlying clock interrupt +object if that object was not manipulated during the execution of the +callback function. +Otherwise, +outstanding requests are discarded. +.Sh CONTEXT +The +.Fn clockintr_bind +function may only be called from process context. +.Pp +The +.Fn clockintr_advance , +.Fn clockintr_cancel , +.Fn clockintr_schedule , +and +.Fn clockintr_stagger +functions may be called from process context or from interrupt context. +.Pp +The +.Fn clockintr_unbind +function may normally be called from process context or from interrupt context. +However, +if the +.Dv CL_BARRIER +flag is set in +.Fa flags , +the function may only be called from process context. +.Pp +The +.Fn clockrequest_advance +function may only be called during execution of a +.Fa callback +function. +.Sh RETURN VALUES +The +.Fn clockintr_advance +and +.Fn clockrequest_advance +functions return the number of +.Fa interval Ns s +that have elapsed since +.Fa cl +was scheduled to expire, +or zero if +.Fa cl +has not yet expired. +.Sh CODE REFERENCES +.Pa sys/kern/kern_clockintr.c +.Sh SEE ALSO +.Xr microtime 9 , +.Xr spl 9 , +.Xr timeout 9 +.Rs +.%A Richard McDougall +.%A Jim Mauro +.%B Solaris Internals: Solaris 10 and OpenSolaris Kernel Architecture +.%I Prentice Hall +.%I Sun Microsystems Press +.%D 2nd Edition, 2007 +.%P pp. 912\(en925 +.Re +.Sh HISTORY +The +.Vt clockintr +and +.Vt clockrequest +APIs first appeared in +.Ox 7.5 . diff --git a/sys/arch/amd64/amd64/cpu.c b/sys/arch/amd64/amd64/cpu.c index c28946b09..d82b11801 100644 --- a/sys/arch/amd64/amd64/cpu.c +++ b/sys/arch/amd64/amd64/cpu.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.c,v 1.181 2024/02/18 05:42:50 guenther Exp $ */ +/* $OpenBSD: cpu.c,v 1.182 2024/02/24 17:00:05 deraadt Exp $ */ /* $NetBSD: cpu.c,v 1.1 2003/04/26 18:39:26 fvdl Exp $ */ /*- @@ -1260,7 +1260,7 @@ cpu_fix_msrs(struct cpu_info *ci) #ifndef SMALL_KERNEL if (ci->ci_feature_sefflags_edx & SEFF0EDX_IBT) { msr = rdmsr(MSR_S_CET); - wrmsr(MSR_S_CET, msr | MSR_CET_ENDBR_EN); + wrmsr(MSR_S_CET, (msr & ~MSR_CET_NO_TRACK_EN) | MSR_CET_ENDBR_EN); lcr4(rcr4() | CR4_CET); } #endif diff --git a/sys/dev/ic/qwx.c b/sys/dev/ic/qwx.c index 0966fe6dd..9c4450034 100644 --- a/sys/dev/ic/qwx.c +++ b/sys/dev/ic/qwx.c @@ -1,4 +1,4 @@ -/* $OpenBSD: qwx.c,v 1.51 2024/02/22 21:21:35 stsp Exp $ */ +/* $OpenBSD: qwx.c,v 1.52 2024/02/24 15:21:39 cheloha Exp $ */ /* * Copyright 2023 Stefan Sperling @@ -23155,7 +23155,7 @@ qwx_dp_rx_tid_del_func(struct qwx_dp *dp, void *ctx, struct qwx_softc *sc = dp->sc; struct dp_rx_tid *rx_tid = ctx; struct dp_reo_cache_flush_elem *elem, *tmp; - time_t now; + uint64_t now; if (status == HAL_REO_CMD_DRAIN) { goto free_desc; @@ -23170,7 +23170,7 @@ qwx_dp_rx_tid_del_func(struct qwx_dp *dp, void *ctx, if (!elem) goto free_desc; - now = gettime(); + now = getnsecuptime(); elem->ts = now; memcpy(&elem->data, rx_tid, sizeof(*rx_tid)); @@ -23188,7 +23188,7 @@ qwx_dp_rx_tid_del_func(struct qwx_dp *dp, void *ctx, /* Flush and invalidate aged REO desc from HW cache */ TAILQ_FOREACH_SAFE(elem, &dp->reo_cmd_cache_flush_list, entry, tmp) { if (dp->reo_cmd_cache_flush_count > DP_REO_DESC_FREE_THRESHOLD || - now < elem->ts + DP_REO_DESC_FREE_TIMEOUT_MS) { + now >= elem->ts + MSEC_TO_NSEC(DP_REO_DESC_FREE_TIMEOUT_MS)) { TAILQ_REMOVE(&dp->reo_cmd_cache_flush_list, elem, entry); dp->reo_cmd_cache_flush_count--; #ifdef notyet diff --git a/sys/dev/ic/qwxvar.h b/sys/dev/ic/qwxvar.h index f7ced75ec..694ce81a0 100644 --- a/sys/dev/ic/qwxvar.h +++ b/sys/dev/ic/qwxvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: qwxvar.h,v 1.22 2024/02/22 09:08:08 stsp Exp $ */ +/* $OpenBSD: qwxvar.h,v 1.23 2024/02/24 15:21:39 cheloha Exp $ */ /* * Copyright (c) 2018-2019 The Linux Foundation. @@ -1041,7 +1041,7 @@ struct dp_rx_tid { struct dp_reo_cache_flush_elem { TAILQ_ENTRY(dp_reo_cache_flush_elem) entry; struct dp_rx_tid data; - unsigned long ts; + uint64_t ts; }; TAILQ_HEAD(dp_reo_cmd_cache_flush_head, dp_reo_cache_flush_elem); diff --git a/usr.sbin/btrace/btrace.c b/usr.sbin/btrace/btrace.c index 881c2acba..4450e98b8 100644 --- a/usr.sbin/btrace/btrace.c +++ b/usr.sbin/btrace/btrace.c @@ -1,4 +1,4 @@ -/* $OpenBSD: btrace.c,v 1.85 2024/02/12 15:12:09 mpi Exp $ */ +/* $OpenBSD: btrace.c,v 1.88 2024/02/24 19:42:54 mpi Exp $ */ /* * Copyright (c) 2019 - 2023 Martin Pieuchot @@ -1089,6 +1089,7 @@ stmt_store(struct bt_stmt *bs, struct dt_evt *dtev) { struct bt_arg *ba = SLIST_FIRST(&bs->bs_args); struct bt_var *bvar, *bv = bs->bs_var; + struct map *map; assert(SLIST_NEXT(ba, ba_next) == NULL); @@ -1106,18 +1107,34 @@ stmt_store(struct bt_stmt *bs, struct dt_evt *dtev) bv->bv_type = bvar->bv_type; bv->bv_value = bvar->bv_value; break; + case B_AT_MAP: + bvar = ba->ba_value; + map = (struct map *)bvar->bv_value; + /* Uninitialized map */ + if (map == NULL) + bv->bv_value = 0; + else + bv->bv_value = map_get(map, ba2hash(ba->ba_key, dtev)); + bv->bv_type = B_VT_LONG; /* XXX should we type map? */ + break; case B_AT_TUPLE: bv->bv_value = baeval(ba, dtev); bv->bv_type = B_VT_TUPLE; break; case B_AT_BI_PID: case B_AT_BI_TID: + case B_AT_BI_CPU: case B_AT_BI_NSECS: + case B_AT_BI_RETVAL: case B_AT_BI_ARG0 ... B_AT_BI_ARG9: case B_AT_OP_PLUS ... B_AT_OP_LOR: bv->bv_value = baeval(ba, dtev); bv->bv_type = B_VT_LONG; break; + case B_AT_BI_COMM: + case B_AT_BI_KSTACK: + case B_AT_BI_USTACK: + case B_AT_BI_PROBE: case B_AT_FN_STR: bv->bv_value = baeval(ba, dtev); bv->bv_type = B_VT_STR; @@ -1797,6 +1814,58 @@ ba2str(struct bt_arg *ba, struct dt_evt *dtev) return str; } +int +ba2flags(struct bt_arg *ba) +{ + int flags = 0; + + assert(ba->ba_type != B_AT_MAP); + assert(ba->ba_type != B_AT_TUPLE); + + switch (ba->ba_type) { + case B_AT_STR: + case B_AT_LONG: + case B_AT_TMEMBER: + case B_AT_VAR: + case B_AT_HIST: + case B_AT_NIL: + break; + case B_AT_BI_KSTACK: + flags |= DTEVT_KSTACK; + break; + case B_AT_BI_USTACK: + flags |= DTEVT_USTACK; + break; + case B_AT_BI_COMM: + flags |= DTEVT_EXECNAME; + break; + case B_AT_BI_CPU: + case B_AT_BI_PID: + case B_AT_BI_TID: + case B_AT_BI_NSECS: + break; + case B_AT_BI_ARG0 ... B_AT_BI_ARG9: + flags |= DTEVT_FUNCARGS; + break; + case B_AT_BI_RETVAL: + case B_AT_BI_PROBE: + break; + case B_AT_MF_COUNT: + case B_AT_MF_MAX: + case B_AT_MF_MIN: + case B_AT_MF_SUM: + case B_AT_FN_STR: + break; + case B_AT_OP_PLUS ... B_AT_OP_LOR: + flags |= ba2dtflags(ba->ba_value); + break; + default: + xabort("invalid argument type %d", ba->ba_type); + } + + return flags; +} + /* * Return dt(4) flags indicating which data should be recorded by the * kernel, if any, for a given `ba'. @@ -1813,51 +1882,15 @@ ba2dtflags(struct bt_arg *ba) do { if (ba->ba_type == B_AT_MAP) - bval = ba->ba_key; - else - bval = ba; + flags |= ba2flags(ba->ba_key); + else if (ba->ba_type == B_AT_TUPLE) { + bval = ba->ba_value; + do { + flags |= ba2flags(bval); + } while ((bval = SLIST_NEXT(bval, ba_next)) != NULL); + } else + flags |= ba2flags(ba); - switch (bval->ba_type) { - case B_AT_STR: - case B_AT_LONG: - case B_AT_TUPLE: - case B_AT_TMEMBER: - case B_AT_VAR: - case B_AT_HIST: - case B_AT_NIL: - break; - case B_AT_BI_KSTACK: - flags |= DTEVT_KSTACK; - break; - case B_AT_BI_USTACK: - flags |= DTEVT_USTACK; - break; - case B_AT_BI_COMM: - flags |= DTEVT_EXECNAME; - break; - case B_AT_BI_CPU: - case B_AT_BI_PID: - case B_AT_BI_TID: - case B_AT_BI_NSECS: - break; - case B_AT_BI_ARG0 ... B_AT_BI_ARG9: - flags |= DTEVT_FUNCARGS; - break; - case B_AT_BI_RETVAL: - case B_AT_BI_PROBE: - break; - case B_AT_MF_COUNT: - case B_AT_MF_MAX: - case B_AT_MF_MIN: - case B_AT_MF_SUM: - case B_AT_FN_STR: - break; - case B_AT_OP_PLUS ... B_AT_OP_LOR: - flags |= ba2dtflags(bval->ba_value); - break; - default: - xabort("invalid argument type %d", bval->ba_type); - } } while ((ba = SLIST_NEXT(ba, ba_next)) != NULL); --recursions;