Re: power of 2 revisited

2021-12-30 Thread Ted Bullock
On 2021-12-29 10:18 p.m., Jonathan Gray wrote:
> On Wed, Dec 29, 2021 at 09:27:34PM -0700, Ted Bullock wrote:
>> This is around documenting peculiar behaviour around power of 2 math in
>> the kernel.
>>
>> I'm wondering if it's worth documenting the peculiarities here, and
>> possibly putting an actually mathematically correct check somewhere in
>> the kernel or maybe userland? Perhaps hypothetical PEER REVIEWED
>> functions with prototypes like isnpotu(uint64_t n) or isnpot(int64_t n).
>>
>> Is this at all worthwhile? Maybe this would help stop people from
>> incorrectly reinventing the wheel?
>>
>> For instance in the kernel right now there is :
>> radeon_check_pot_argument
>> IS_POWER_OF_2
>> is_power_of_2
>> is_power_of_2_u64
>> powerof2
>> probably others too.
> 
> IS_POWER_OF_2 and is_power_of_2_u64 are inteldrm specific
> is_power_of_2 is a linux interface.
> 
> radeon_check_pot_argument should be replaced in linux by
> is_power_of_2.
> https://lists.freedesktop.org/archives/amd-gfx/2021-December/073108.html
> 
> No code outside of drm should be using the linux interfaces and
> I don't think we should be documenting them.

I've taken some time to write what I believe is correct implementations
of the power of two tests for both signed and unsigned cases and written
a manual for both the original powerof2() macro and my functions. Unlike
the macro these actually give the correct response for 0 and INT_MIN. I
also performed a fairly extensive namespace collision search and didn't
find any function name collisions but this was not exhaustive.

The goal here is to provide a mathematically correct power of two test
and associated documentation. I put the new tests in sys/params.h
because the old (inaccurate) test from bsd 4.3 tahoe has the macro
there.

I deliberately did not correct the logic of the macro as per the thread
years ago here : https://marc.info/?t=14432152764&r=1&w=2

I used int for the return type though in the c99 era it could be bool I
suppose; maybe 23 years since that standard was published is too soon to
use bool. :P

I hope that people can use this. Please review.

I wrote a short test program to verify I'm not crazy as well. Here are
the results:

Calculating powers of two:
powerof2(INT_MIN): true
powerof2(-2): false
powerof2(0): true
powerof2(2): true
powerof2(4): true
powerof2(8): true
powerof2(16): true
powerof2(INT_MAX): false

isupow2(0): false
isupow2(2): true
isupow2(4): true
isupow2(8): true
isupow2(16): true
isupow2(77): false
isupow2(UINT_MAX): false

isnpow2(INT_MIN): false
isnpow2(-2): false
isnpow2(0): false
isnpow2(2): true
isnpow2(4): true
isnpow2(8): true
isnpow2(16): true
isnpow2(INT_MAX): false

Index: sys/sys/param.h
===
RCS file: /cvs/src/sys/sys/param.h,v
retrieving revision 1.135
diff -u -p -u -p -r1.135 param.h
--- sys/sys/param.h 19 Sep 2021 16:55:01 -  1.135
+++ sys/sys/param.h 31 Dec 2021 00:33:45 -
@@ -186,7 +186,17 @@
 #definehowmany(x, y)   (((x)+((y)-1))/(y))
 #endif
 #defineroundup(x, y)   x)+((y)-1))/(y))*(y))
-#define powerof2(x)x)-1)&(x))==0)
+#definepowerof2(x) x)-1)&(x))==0)
+static inline int
+isupow2(uint64_t u)
+{
+   return ((u & (u - 1)) == 0) && (u != 0);
+}
+static inline int
+isnpow2(int64_t n)
+{
+   return ((n & (n - 1)) == 0) && (n > 0);
+}

 /* Macros for min/max. */
 #defineMIN(a,b) (((a)<(b))?(a):(b))


Also inline here is the complete text of the manual I wrote:



.\" Copyright (c) 2021 Ted Bullock 
.\"
.\" 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$
.Dt powerof2 3
.Os
.Sh NAME
.Nm powerof2
.Nm isupow2
.Nm is2pow2
.Nd tests integer for power of two
.Sh SYNOPSIS
.In sys/params.h
.Fd #define powerof2(x) x)-1)&(x))==0)
.Ft int
.Fo isupow2
.Fa "uint64_t"
.Fc
.Ft int
.Fo isnpow2
.Fa "int64_t"
.Fc
.Sh DESCRIPTION
These tests check if an integer value is a power of two.
.Pp
The
.Fn powerof2
macro expands to a logical expression that relies on comparing the binary
complement of the
.Fa x
parameter. When
.Fa x
is an
.Vt integer
or
.Vt unsigned
power of two, the binary complement will be
.Fa x - 1
and the expression will evaluate as true. This test incorrectly identifies
zero and
.Dv INT_M

qq

2021-12-30 Thread Shadrock Uhuru

From: Stuart Henderson 
To: misc@openbsd.org
Date: Tue, 28 Dec 2021 12:55:27 - (UTC)
Subject: Re: raspberry pi 3b+ how to boot with hdmi



On 2021-12-28, Shadrock Uhuru  wrote:
hi everyone
i have successfully installed the latest snapshot onto a rpi3b+
using a serial cable,
after rebooting still with the serial cable everything startup fine,
when i try to reboot with a hdmi monitor connected
i get a few line at startup then the screen goes blank,
what configuration do i change to make the hdmi monitor the primary
display when booting ?



See the text around "To use video output on the framebuffer instead"
in the INSTALL.arm64 file distributed with the install sets.


hi stuart
thanks for the reply,
i now have output on the hdmi monitor,
one thing that i've noticed is the boot up information
stops after displaying the date and doesn't proceed to the login prompt,
i can ping and ssh into the pi but no login prompt,
is there still something i need to do ?

shadrock



Re : Re: Limitations of nested pf macros

2021-12-30 Thread Marin BERNARD
> I think it's expected. This is a simple construct and trying to use
> it for something more complicated is likely to run into problems.
> Manual pages usually talk about what is supported rather than what
> isn't (it's difficult to evaluate all the things somebody might
> try and explain why it won't work).
> I would recommend writing rules like { $macro } rather than including
> { } characters within the macro, so you can switch between single
> addresses and lists of addresses easily, and can chain them together
> if needed. For something more complicated I'd recommend using tables
> instead.

Thank you for your answer. I understand. I was reluctant to create tables for 
lists as small as 2-10 items, but it seems to be the way to go indeed.


publickey - lists@olivarim.com - 0xFD5D9CF2.asc
Description: application/pgp-keys


signature.asc
Description: OpenPGP digital signature


Re: Suspend/hibernate broken [upgrade: 6.9 to 7.0] (solution)

2021-12-30 Thread Dave Voutila


Clint Pachl  writes:

> This is how I got suspend and hibernate working again on my Huawei
> Matebook after upgrading to 7.0 release. I thought I'd share here in
> case it helps someone else.
>
>
> SYNOPSIS:
>
> Initiating a "sleep" state blanks the screen and illuminates the
> keyboard (indicating sleep is immenent); but the laptop would never go
> to sleep. It would also never wake up. However, pressing the power
> button cleanly shutdown the system.
>
> After comparing the 7.0 dmesg with an older version (6.6), I noticed
> this difference:
>
> tpm0 at acpi0 TPM_ addr 0xfed40040/0x1000: timed out waiting for
> validity
>
> acpi(4) confirmed that the TPM does connect to the ACPI driver. The
> kernel error message above is a good hint that the TPM could be
> preventing suspend and hibernate.

Quite possible.

>
>
> SOLUTION #1:
>
> I disabled TPM in the kernel at the boot prompt (i.e., boot -c). Within
> UKC, "tpm" matched another device. I disabled TPM specifying the device
> number (devno) of the tpm0 device.
>
>   UKC> list tpm
>   UKC> disable 433
>
> If this is the solution for you, make it permanent using the kernel
> configuration file, bsd.re-config(5).
>
>
> SOLUTION #2:
>
> There is a "TCM/TPM" setting in BIOS; I disabled it. Booting the
> base 7.0 kernel (TPM enabled) also fixed "sleep" modes.
>
> This is the solution I decided to use.
>

This is the best approach.

>
> REQUEST FOR COMMENT:
>
> I'm not sure if disabling TPM like this creates a security issue.
> Please let me know if there are negative repercussions.
>

The tpm driver exists only to assist suspend/hibernate. It's not used
for anything involving "security."

> Also, is this a bug that should be reported to bugs@?
>

Any chance you can try -current? Or maybe provide a copy of
/var/db/acpi/TPM.*? You can either disassemble it with iasl from the
acpica port, provide an inline hex dump via hexdump(1), or the
binary. It can tell me what the TPM start method is that your hardware
wants the OS to use.

I recently added support to -current for a start method seen in some TPM
2.0 devices, but it doesn't support all known methods. It might allow
you to avoid disabling in the BIOS.

A full dmesg would also be appreciated.

>
> ACPI from 7.0 DMESG:
>
> "ELAN2201" at acpi0 not configured
> "INT0E0C" at acpi0 not configured
> "INT33A1" at acpi0 not configured
> "INT3400" at acpi0 not configured
> "INT3403" at acpi0 not configured
> "INT3403" at acpi0 not configured
> "INT3403" at acpi0 not configured
> "INT3403" at acpi0 not configured
> "INT3403" at acpi0 not configured
> "INT344B" at acpi0 not configured
> "PNP0C14" at acpi0 not configured
> "PNP0C14" at acpi0 not configured
> "PNP0C14" at acpi0 not configured
> "WDT0001" at acpi0 not configured
> acpi0 at bios0: ACPI 5.0
> acpi0: sleep states S0 S3 S4 S5
> acpi0: tables DSDT FACP UEFI UEFI ECDT SSDT MSDM SSDT SSDT TPM2 SSDT
> SSDT SSDT ASPT BOOT HPET APIC MCFG SSDT WSMT SSDT DBGP DBG2 SSDT SSDT
> DMAR NHLT FPDT BGRT acpi0: wakeup devices GLAN(S4) XHC_(S3) XDCI(S4)
> HDAS(S4) RP01(S4) PXSX(S4) RP02(S4) PXSX(S4) RP03(S4) PXSX(S4) RP04(S4)
> PXSX(S4) RP05(S4) PXSX(S4) RP06(S4) PXSX(S4) [...] acpiac0 at acpi0: AC
> unit online acpials0 at acpi0: ALSD acpibat0 at acpi0: BAT0 model
> "BASE-BAT" serial 123456789 type Li oem "Kollur" acpibtn0 at acpi0:
> LID_ acpibtn1 at acpi0: PWRB acpicmos0 at acpi0
> acpicpu0 at acpi0: C3(200@1034 mwait.1@0x60), C2(200@151 mwait.1@0x33),
> C1(1000@1 mwait.1), PSS
> acpicpu1 at acpi0: C3(200@1034 mwait.1@0x60), C2(200@151 mwait.1@0x33),
> C1(1000@1 mwait.1), PSS acpicpu2 at acpi0: C3(200@1034 mwait.1@0x60),
> C2(200@151 mwait.1@0x33), C1(1000@1 mwait.1), PSS acpicpu3 at acpi0:
> C3(200@1034 mwait.1@0x60), C2(200@151 mwait.1@0x33), C1(1000@1
> mwait.1), PSS acpiec0 at acpi0 acpihpet0 at acpi0: 2399 Hz
> acpimadt0 at acpi0 addr 0xfee0: PC-AT compat
> acpimcfg0 at acpi0
> acpimcfg0: addr 0xe000, bus 0-255
> acpipci0 at acpi0 PCI0: 0x 0x0011 0x0001
> acpiprt0 at acpi0: bus 0 (PCI0)
> acpiprt1 at acpi0: bus -1 (RP01)
> acpiprt10 at acpi0: bus -1 (RP10)
> acpiprt11 at acpi0: bus -1 (RP11)
> acpiprt12 at acpi0: bus -1 (RP12)
> acpiprt13 at acpi0: bus -1 (RP13)
> acpiprt14 at acpi0: bus -1 (RP14)
> acpiprt15 at acpi0: bus -1 (RP15)
> acpiprt16 at acpi0: bus -1 (RP16)
> acpiprt17 at acpi0: bus -1 (RP17)
> acpiprt18 at acpi0: bus -1 (RP18)
> acpiprt19 at acpi0: bus -1 (RP19)
> acpiprt2 at acpi0: bus -1 (RP02)
> acpiprt20 at acpi0: bus -1 (RP20)
> acpiprt21 at acpi0: bus -1 (RP21)
> acpiprt22 at acpi0: bus -1 (RP22)
> acpiprt23 at acpi0: bus -1 (RP23)
> acpiprt24 at acpi0: bus -1 (RP24)
> acpiprt3 at acpi0: bus -1 (RP03)
> acpiprt4 at acpi0: bus -1 (RP04)
> acpiprt5 at acpi0: bus -1 (RP05)
> acpiprt6 at acpi0: bus -1 (RP06)
> acpiprt7 at acpi0: bus 1 (RP07)
> acpiprt8 at acpi0: bus -1 (RP08)
> acpiprt9 at acpi0: bus 2 (RP09)
> acpipwrres0 at acpi0: WRST
> acpipwrres1 at acpi0: WRST
> acpipwrres10 at acpi0: WRST
> acpipwrres11 at acpi0: WRST
> ac

Re: Limitations of nested pf macros

2021-12-30 Thread Stuart Henderson
On 2021-12-30, Marin BERNARD  wrote:
> While building a pf ruleset, I found out that trying to nest macros
> results in syntax errors, unless the original macros were defined
> with double (nested) quoting (e.g.: "'0.0.0.0/0'" or "\"0.0.0.0/0\"").
>
> I've read the man pages and the OpenBSD FAQ, but could not find any
> internal reference to this. I was able to fix my ruleset thanks to a
> post on serverfault [1]. Yet, I was not able to nest macros more
> than one level deep, since triple quoting the macro value also
> triggers syntax errors.
>
> Is this limitation expected ? If so, how can I help to have it
> documented somewhere ?

I think it's expected. This is a simple construct and trying to use
it for something more complicated is likely to run into problems.
Manual pages usually talk about what is supported rather than what
isn't (it's difficult to evaluate all the things somebody might
try and explain why it won't work).

I would recommend writing rules like { $macro } rather than including
{ } characters within the macro, so you can switch between single
addresses and lists of addresses easily, and can chain them together
if needed. For something more complicated I'd recommend using tables
instead.




Ynt: howto separate isakmpd syslogs into another file

2021-12-30 Thread Hayri Can KAVAK
Thanks Martijn; it worked by creating these files.

Gönderen: Martijn van Duren  adına 
owner-m...@openbsd.org 
Gönderildi: 30 Aralık 2021 Perşembe 12:46
Kime: Hayri Can KAVAK ; misc@openbsd.org 

Konu: Re: howto separate isakmpd syslogs into another file

On Thu, 2021-12-30 at 08:59 +, Hayri Can KAVAK wrote:
> Hello,
>
> I'm trying to separate isakmpd/ipsec logs to another file instead of 
> /var/log/messages.
> Here my config at the top of /etc/syslog.conf
> !!isakmpd
> daemon.info 
> /var/log/ipsec_info.log
> daemon.debug
> /var/log/ipsec_debug.log
> !*
>
> I restarted syslogd & isakmpd but nothing changed. It still logs to 
> /var/log/messages.
> How can i achieve this?
>
> Thanks in advance.

The files /var/log/ipsec_{info,debug}.log need to exist before logging
to them (and loaded in by sending SIGHUP to syslog(8)). syslogd(8) will
not try to create the files. From syslogd(8):

The logfiles already have to exist with the correct permissions.


The default syslog.conf doesn't write messages for DAEMON to
/var/log/messages, they should end up in /var/log/daemon. But without
seeing your full syslog.conf I can't say what's going on there.

Hope this helps.

martijn@



Limitations of nested pf macros

2021-12-30 Thread Marin BERNARD
Hi,

I'm using OpenBSD 7.0.

While building a pf ruleset, I found out that trying to nest macros
results in syntax errors, unless the original macros were defined
with double (nested) quoting (e.g.: "'0.0.0.0/0'" or "\"0.0.0.0/0\"").

I've read the man pages and the OpenBSD FAQ, but could not find any
internal reference to this. I was able to fix my ruleset thanks to a
post on serverfault [1]. Yet, I was not able to nest macros more
than one level deep, since triple quoting the macro value also
triggers syntax errors.

Is this limitation expected ? If so, how can I help to have it
documented somewhere ?

Thank you,

[1]: 
https://serverfault.com/questions/575876/expanding-a-macro-containing-a-subnet-ip-address-with-prefix-cidr-in-a-list-us


publickey - lists@olivarim.com - 0xFD5D9CF2.asc
Description: application/pgp-keys


signature.asc
Description: OpenPGP digital signature


Re: howto separate isakmpd syslogs into another file

2021-12-30 Thread Martijn van Duren
On Thu, 2021-12-30 at 08:59 +, Hayri Can KAVAK wrote:
> Hello,
> 
> I'm trying to separate isakmpd/ipsec logs to another file instead of 
> /var/log/messages.
> Here my config at the top of /etc/syslog.conf
> !!isakmpd
> daemon.info 
> /var/log/ipsec_info.log
> daemon.debug
> /var/log/ipsec_debug.log
> !*
> 
> I restarted syslogd & isakmpd but nothing changed. It still logs to 
> /var/log/messages.
> How can i achieve this?
> 
> Thanks in advance.

The files /var/log/ipsec_{info,debug}.log need to exist before logging
to them (and loaded in by sending SIGHUP to syslog(8)). syslogd(8) will
not try to create the files. From syslogd(8):

The logfiles already have to exist with the correct permissions.


The default syslog.conf doesn't write messages for DAEMON to
/var/log/messages, they should end up in /var/log/daemon. But without
seeing your full syslog.conf I can't say what's going on there.

Hope this helps.

martijn@



howto separate isakmpd syslogs into another file

2021-12-30 Thread Hayri Can KAVAK
Hello,

I'm trying to separate isakmpd/ipsec logs to another file instead of 
/var/log/messages.
Here my config at the top of /etc/syslog.conf
!!isakmpd
daemon.info /var/log/ipsec_info.log
daemon.debug/var/log/ipsec_debug.log
!*

I restarted syslogd & isakmpd but nothing changed. It still logs to 
/var/log/messages.
How can i achieve this?

Thanks in advance.


Re: full disk encryption with keydisk

2021-12-30 Thread Stefan Sperling
On Wed, Dec 29, 2021 at 05:22:19PM -0500, openbsd-m...@pyr3x.com wrote:
> Hello,
> 
> I'm using full disk encryption via the softraid subsystem and bioctl with a
> keydisk. I have a second drive that I'm backing up the root filesystem to
> via ROOTBACKUP=1 and the proper fstab entry.
> 
> I'd like to be able to reuse the same keydisk to decrypt the second drive.
> It appears there is no way to inform bioctl to reuse a correctly formatted
> keydisk, so it overwrites it each time. Right now I've opted to use a
> passfile for the second drive and confirmed I could boot to it by entering
> the passphrase via 'boot sr1a:/bsd -a' -- but I'd prefer to simply let it
> pickup the keydisk. Is there something I'm missing?

Two different crypto volumes cannot use the same RAID type disklabel
slice as a keydisk.

However, you can create two distinct RAID type disklabel slices on your
key disk device (1MB per slice should be sufficient), and then pass one
of each of those slices to bioctl -k when you create your two crypto volumes.
This way, a single physical disk device will be able to unlock both volumes.