Re: [PATCH v2 bpf-next 1/3] bpf: Add casts to keep sparse quiet.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Jul 2, 2024 at 7:25 AM Sebastian Andrzej Siewior
<bigeasy@xxxxxxxxxxxxx> wrote:
>
> sparse complains about wrong data types within the BPF callbacks.
> Functions like bpf_l3_csum_replace() are invoked with a specific set of
> arguments and its further usage is based on a flag. So it can not be set
> right upfront.
> There is also access to variables in struct bpf_nh_params and struct
> bpf_xfrm_state which should be __be32. The content comes directly
> from the BPF program so conversion is already right.
>
> Add __force casts for the right data type and update the members in
> struct bpf_xfrm_state and bpf_nh_params in order to keep sparse happy.
>
> Reported-by: kernel test robot <lkp@xxxxxxxxx>
> Closes: https://lore.kernel.org/oe-kbuild-all/202406261217.A4hdCnYa-lkp@xxxxxxxxx
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@xxxxxxxxxxxxx>
> ---
>  include/linux/filter.h         |  2 +-
>  include/uapi/linux/bpf.h       |  6 +++---
>  net/core/filter.c              | 18 ++++++++++--------
>  tools/include/uapi/linux/bpf.h |  6 +++---
>  4 files changed, 17 insertions(+), 15 deletions(-)
>
> diff --git a/include/linux/filter.h b/include/linux/filter.h
> index 02ddcfdf94c46..15aee0143f1cf 100644
> --- a/include/linux/filter.h
> +++ b/include/linux/filter.h
> @@ -728,7 +728,7 @@ struct bpf_skb_data_end {
>  struct bpf_nh_params {
>         u32 nh_family;
>         union {
> -               u32 ipv4_nh;
> +               __be32 ipv4_nh;
>                 struct in6_addr ipv6_nh;
>         };
>  };
> diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
> index 25ea393cf084b..f45b03706e4e9 100644
> --- a/include/uapi/linux/bpf.h
> +++ b/include/uapi/linux/bpf.h
> @@ -6290,12 +6290,12 @@ struct bpf_tunnel_key {
>   */
>  struct bpf_xfrm_state {
>         __u32 reqid;
> -       __u32 spi;      /* Stored in network byte order */
> +       __be32 spi;     /* Stored in network byte order */
>         __u16 family;
>         __u16 ext;      /* Padding, future use. */
>         union {
> -               __u32 remote_ipv4;      /* Stored in network byte order */
> -               __u32 remote_ipv6[4];   /* Stored in network byte order */
> +               __be32 remote_ipv4;     /* Stored in network byte order */
> +               __be32 remote_ipv6[4];  /* Stored in network byte order */
>         };
>  };

I don't think we should be changing uapi because of sparse.
I would ignore the warnings.
pw-bot: cr





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux