public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: "Jose E. Marchesi" <jose.marchesi@oracle.com>
To: Eduard Zingerman <eddyz87@gmail.com>
Cc: yonghong.song@linux.dev, bpf@vger.kernel.org,
	Nick Desaulniers <ndesaulniers@google.com>
Subject: Re: Usage of "p" constraint in BPF inline asm
Date: Fri, 11 Aug 2023 19:22:08 +0200	[thread overview]
Message-ID: <87h6p5ebpb.fsf@oracle.com> (raw)
In-Reply-To: <83b2fb306e34a76b07c4625df1ab2d00a183043f.camel@gmail.com> (Eduard Zingerman's message of "Fri, 11 Aug 2023 19:12:03 +0300")


Thanks.  I will give it a try.

> On Fri, 2023-08-11 at 16:10 +0200, Jose E. Marchesi wrote:
>> > Do you need any help with the environment itself?
>> > (I can describe my setup if you need that).
>> 
>> That would be useful yes, thank you.
>
> There are several things needed:
> - bpf-next source code:
>   https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git
> - Specific kernel configuration
> - QEMU to run selftests in
> - Root file system for QEMU to boot
> - Means to kickstart tests execution inside the VM.
>
> There is a script vmtest.sh located in the kernel repository:
>
>     tools/testing/selftests/bpf/vmtest.sh
>     
> Which takes care of kernel configuration, compilation, selftests
> compilation, qemu rootfs image download and test execution.
>
> This is not exactly what I use but I tested in right now and it works
> with a few caveats. Explaining my setup would take longer so I'll
> start with this one. I will submit patches with fixes for caveats.
>
> ## Caveat #1: libc version
>
> The script downloads rootfs image from predefined location on github
> (aws?) and that image is based on debian bullseye. libc version on my
> system is newer, so there is an error when test binaries built on my
> system are executed inside VM. So, I have to prepare my own rootfs
> image and point vmtest.sh to it. It might not be a problem in your
> case, if so -- skip the rest of the section.
>
> Unfortunately, there is no option to override rootfs via command line
> of that script, so the following patch is needed:
>
> ```diff
> diff --git a/tools/testing/selftests/bpf/vmtest.sh b/tools/testing/selftests/bpf/vmtest.sh
> index 685034528018..3d0c7e7c0135 100755
> --- a/tools/testing/selftests/bpf/vmtest.sh
> +++ b/tools/testing/selftests/bpf/vmtest.sh
> @@ -124,6 +124,15 @@ download_rootfs()
>                 exit 1
>         fi
>  
> +        echo "download_rootfs: $ROOTFS_OVERRIDE"
> +        if [[ "$ROOTFS_OVERRIDE" != "" ]]; then
> +            if [[ ! -e $ROOTFS_OVERRIDE ]]; then
> +               echo "Can't find rootfs image referred to by ROOTFS_OVERRIDE: $ROOTFS_OVERRIDE"
> +               exit 1
> +            fi
> +            cat $ROOTFS_OVERRIDE | zstd -d | sudo tar -C "$dir" -x
> +            exit
> +        fi
>         download "${ARCH}/libbpf-vmtest-rootfs-$rootfsversion.tar.zst" |
>                 zstd -d | sudo tar -C "$dir" -x
>  }
> ```
>
>
> Here is how to prepare the disk image for bookworm:
>
>     $ git clone https://github.com/libbpf/ci libbpf-ci
>     $ cd libbpf-ci
>     $ sudo ./rootfs/mkrootfs_debian.sh -d bookworm
>       # !! eddy -- is my user name locally, update accordingly
>     $ sudo chown eddy libbpf-vmtest-rootfs-2023.08.11-bookworm-amd64.tar.zst
>     $ export ROOTFS_OVERRIDE=$(realpath libbpf-vmtest-rootfs-2023.08.11-bookworm-amd64.tar.zst)
>
> Script stores Qemu disk image in ~/.bpf_selftests/root.img .
> We need to prepare/update that image using the following command:
>
>       # !! make sure ROOTFS_OVERRIDE is set
>     $ cd <kernel-sources>
>     $ cd tools/testing/selftests/bpf
>     $ ./vmtest.sh -i
>
> (Note: script uses sudo internally, so it might ask for password).
>
> ## Caveat #2: make headers
>
> Kernel compilation command requires the following patch:
>
> ```diff
> diff --git a/tools/testing/selftests/bpf/vmtest.sh b/tools/testing/selftests/bpf/vmtest.sh
> index 685034528018..3d0c7e7c0135 100755
> --- a/tools/testing/selftests/bpf/vmtest.sh
> +++ b/tools/testing/selftests/bpf/vmtest.sh
> @@ -137,6 +146,7 @@ recompile_kernel()
>  
>         ${make_command} olddefconfig
>         ${make_command}
> +        ${make_command} headers
>  }
>  
>  mount_image()
> ```
>
> ## Running tests
>
> Running tests is simple:
>
>     $ cd <kernel-sources>
>     $ cd tools/testing/selftests/bpf
>     $ ./vmtest.sh -- ./test_verifier
>
> The script will rebuild both kernel and selftests if necessary.
> The log should look as follows:
>
>     $ ./vmtest.sh -- ./test_verifier
>     Output directory: /home/eddy/.bpf_selftests
>     ... build log ....
>     [    0.000000] Linux version 6.5.0-rc4-g2adbb7637fd1-dirty ...
>     ... boot log ...
>     + /etc/rcS.d/S50-startup
>     ./test_verifier
>     #0/u BPF_ATOMIC_AND without fetch OK
>     #0/p BPF_ATOMIC_AND without fetch OK
>     #1/u BPF_ATOMIC_AND with fetch OK
>     ... test_verifier log ...
>     #524/p wide load from bpf_sock_addr.msg_src_ip6[3] OK
>     Summary: 790 PASSED, 0 SKIPPED, 0 FAILED
>     [    3.724015] ACPI: PM: Preparing to enter system sleep state S5
>     [    3.725169] reboot: Power down
>     Logs saved in /home/eddy/.bpf_selftests/bpf_selftests.2023-08-11_18-53-05.log
>
> ## Selecting individual tests
>
> For test_verifier individual tests could be selected using command:
>
>     $ ./vmtest.sh -- ./test_verifier -vv 42
>
> (-vv forces detailed logging).
>
> For test_progs/test_progs-no_alu32/test_progs-cpuv4 using the
> following command:
>
>     $ ./vmtest.sh -- ./test_progs-cpuv4 -vvv -a verifier_ldsx
>
> (-a stands for allow and filters tests by names).
>
> `test_maps` do not take any options AFAIK.
>
> ---
>
> Hope this helps.
> Feel free to ask about any issues, or we can have a call in zoom.

      reply	other threads:[~2023-08-11 17:27 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-10 10:35 Usage of "p" constraint in BPF inline asm Jose E. Marchesi
2023-08-10 17:26 ` Yonghong Song
2023-08-10 17:39   ` Jose E. Marchesi
2023-08-10 17:45     ` Yonghong Song
2023-08-10 19:01       ` Eduard Zingerman
2023-08-10 19:10         ` Jose E. Marchesi
2023-08-10 19:38           ` Eduard Zingerman
2023-08-11 12:01             ` Jose E. Marchesi
2023-08-11 12:18               ` Eduard Zingerman
2023-08-11 12:27                 ` Eduard Zingerman
2023-08-11 14:10                 ` Jose E. Marchesi
2023-08-11 16:12                   ` Eduard Zingerman
2023-08-11 17:22                     ` Jose E. Marchesi [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87h6p5ebpb.fsf@oracle.com \
    --to=jose.marchesi@oracle.com \
    --cc=bpf@vger.kernel.org \
    --cc=eddyz87@gmail.com \
    --cc=ndesaulniers@google.com \
    --cc=yonghong.song@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox