Re: git: 27202b98dc2d - main - jail: Use atomic(9) instead of CK atomics

From: Mateusz Guzik <mjguzik_at_gmail.com>
Date: Wed, 08 Feb 2023 22:14:09 UTC
On 2/7/23, Mark Johnston <markj@freebsd.org> wrote:
> The branch main has been updated by markj:
>
> URL:
> https://cgit.FreeBSD.org/src/commit/?id=27202b98dc2d3361f4b5395a93488fc60c3f9af9
>
> commit 27202b98dc2d3361f4b5395a93488fc60c3f9af9
> Author:     Mark Johnston <markj@FreeBSD.org>
> AuthorDate: 2023-02-07 19:35:44 +0000
> Commit:     Mark Johnston <markj@FreeBSD.org>
> CommitDate: 2023-02-07 20:10:24 +0000
>
>     jail: Use atomic(9) instead of CK atomics
>
>     There's no reason to use one over the other here, let's prefer the
>     interface that's used elsewhere in the kernel.
>
>     No functional change intended.
>
>     Reviewed by:    mjg
>     Sponsored by:   Klara, Inc.
>     Differential Revision:  https://reviews.freebsd.org/D38360
> ---
>  sys/kern/kern_jail.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/sys/kern/kern_jail.c b/sys/kern/kern_jail.c
> index 4c1e3ff40c58..75be0df85448 100644
> --- a/sys/kern/kern_jail.c
> +++ b/sys/kern/kern_jail.c
> @@ -771,7 +771,7 @@ prison_ip_set(struct prison *pr, const pr_family_t af,
> struct prison_ip *new)
>  	mem = &pr->pr_addrs[af];
>
>  	old = *mem;
> -	ck_pr_store_ptr(mem, new);
> +	atomic_store_ptr(mem, new);
>  	prison_ip_free(old);
>  }
>
> @@ -897,7 +897,7 @@ prison_ip_check(const struct prison *pr, const
> pr_family_t af,
>  	    in_epoch(net_epoch_preempt) ||
>  	    sx_xlocked(&allprison_lock));
>
> -	pip = ck_pr_load_ptr(&pr->pr_addrs[af]);
> +	pip = atomic_load_ptr(&pr->pr_addrs[af]);
>  	if (__predict_false(pip == NULL))
>  		return (EAFNOSUPPORT);
>
>

so apparently this breaks kasan builds:
/usr/src/sys/kern/kern_jail.c:900:8: error: cast from 'struct
prison_ip *const *' to 'volatile unsigned long *' drops const
qualifier [-Werror,-Wcast-qual]
        pip = atomic_load_ptr(&pr->pr_addrs[af]);
              ^
/usr/src/sys/sys/atomic_san.h:272:64: note: expanded from macro
'atomic_load_ptr'
        __retptr = (void *)ATOMIC_SAN(load_ptr)((volatile uintptr_t
*)(x));     \
                                                                      ^
/usr/src/sys/kern/kern_jail.c:900:8: error: cannot assign to variable
'__retptr' with const-qualified type 'typeof (*&pr->pr_addrs[af])'
(aka 'struct prison_ip *const')
        pip = atomic_load_ptr(&pr->pr_addrs[af]);
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/src/sys/sys/atomic_san.h:272:11: note: expanded from macro
'atomic_load_ptr'
        __retptr = (void *)ATOMIC_SAN(load_ptr)((volatile uintptr_t
*)(x));     \
        ~~~~~~~~ ^
/usr/src/sys/kern/kern_jail.c:900:8: note: variable '__retptr'
declared const here
        pip = atomic_load_ptr(&pr->pr_addrs[af]);
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/src/sys/sys/atomic_san.h:271:15: note: expanded from macro
'atomic_load_ptr'
        __typeof(*x) __retptr;
         \
        ~~~~~~~~~~~~~^~~~~~~~
2 errors generated.


-- 
Mateusz Guzik <mjguzik gmail.com>