From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 1DDA7459BF; Tue, 17 Sep 2024 16:32:57 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0BFA1402D8; Tue, 17 Sep 2024 16:32:57 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id E05A240261 for ; Tue, 17 Sep 2024 16:32:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1726583575; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=bo2PUVg47dB12z8tcA9dPePRr8Rk9mwS4W91qT7j+Gc=; b=RQ92rLXZ/ngQJIbxLoJQVl97Zc1Ola4r0PgG5PfiEUlEeoWfxpOiF5OWdUHI5TOnQME27e Ptpuh4DS8Ve/whnVbGxCfLI3yGwmG07tJJNwXbQSSzHE6P+rUXZtDk6oA6M1TWNtBBNagr 6mKW/5xjJoVdylLp44bHVvBgqK9NWNM= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-266-m720DP44O-Kzsx1V27J_0g-1; Tue, 17 Sep 2024 10:32:52 -0400 X-MC-Unique: m720DP44O-Kzsx1V27J_0g-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B4A671953953; Tue, 17 Sep 2024 14:32:50 +0000 (UTC) Received: from [10.39.208.31] (unknown [10.39.208.31]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id AFAE51955F54; Tue, 17 Sep 2024 14:32:47 +0000 (UTC) Message-ID: Date: Tue, 17 Sep 2024 16:32:44 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC v3 1/3] uapi: introduce kernel uAPI headers import To: David Marchand Cc: dev@dpdk.org, techboard@dpdk.org, thomas@monjalon.net, mb@smartsharesystems.com, stephen@networkplumber.org References: <20240911193224.1966122-1-maxime.coquelin@redhat.com> <20240911193224.1966122-2-maxime.coquelin@redhat.com> From: Maxime Coquelin Autocrypt: addr=maxime.coquelin@redhat.com; keydata= xsFNBFOEQQIBEADjNLYZZqghYuWv1nlLisptPJp+TSxE/KuP7x47e1Gr5/oMDJ1OKNG8rlNg kLgBQUki3voWhUbMb69ybqdMUHOl21DGCj0BTU3lXwapYXOAnsh8q6RRM+deUpasyT+Jvf3a gU35dgZcomRh5HPmKMU4KfeA38cVUebsFec1HuJAWzOb/UdtQkYyZR4rbzw8SbsOemtMtwOx YdXodneQD7KuRU9IhJKiEfipwqk2pufm2VSGl570l5ANyWMA/XADNhcEXhpkZ1Iwj3TWO7XR uH4xfvPl8nBsLo/EbEI7fbuUULcAnHfowQslPUm6/yaGv6cT5160SPXT1t8U9QDO6aTSo59N jH519JS8oeKZB1n1eLDslCfBpIpWkW8ZElGkOGWAN0vmpLfdyiqBNNyS3eGAfMkJ6b1A24un /TKc6j2QxM0QK4yZGfAxDxtvDv9LFXec8ENJYsbiR6WHRHq7wXl/n8guyh5AuBNQ3LIK44x0 KjGXP1FJkUhUuruGyZsMrDLB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eTJSvJ8TIPL4uyfzhjHhlkCU0mw7Pscyxn DE8G0UYMEaNgaZap8dcGMYH/96EfE5s/nTX0M6MXV0yots7U2BDb4soLCxLOJz4tAFDtNFtA wLBhXRSvWhdBJZiig/9CG3dXmKfi2H+wdUCSvEFHRpgo7GK8/Kh3vGhgKmnnxhl8ACBaGy9n fxjSxjSO6rj4/MeenmlJw1yebzkX8ZmaSi8BHe+n6jTGEFNrbiOdWpJgc5yHIZZnwXaW54QT UhhSjDL1rV2B4F28w30jYmlRmm2RdN7iCZfbyP3dvFQTzQ4ySquuPkIGcOOHrvZzxbRjzMx1 Mwqu3GQ= In-Reply-To: X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On 9/17/24 13:36, David Marchand wrote: > On Wed, Sep 11, 2024 at 9:32 PM Maxime Coquelin > wrote: >> >> This patch introduces uAPI headers import into the DPDK >> repository. This import is possible thanks to Linux Kernel >> licence exception for syscalls: >> >> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/LICENSES/exceptions/Linux-syscall-note >> >> Header files are have to be explicitly imported. >> >> Guidelines are provided in the documentation, and helper >> scripts are also provided to ensure proper importation of the >> header (unmodified content from a released Kernel version): >> - import-linux-uapi.sh: used to add and update headers and >> their dependencies to linux-headers/uapi/ >> - check-linux-uapi.sh: used to check all headers are valid >> >> Signed-off-by: Maxime Coquelin > > I have been trying this script to import linux/vfio.h and cleanup its > usage in DPDK. > > There is one issue that was raised. > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/uapi/linux/vfio.h#n1573 > > struct vfio_bitmap { > __u64 pgsize; /* page size for bitmap in bytes */ > __u64 size; /* in bytes */ > __u64 __user *data; /* one bit per page */ > }; > > The __user annotation is sanitized by the headers install script in > the kernel, but the dpdk import script is missing this part. > Such sanitizations breaks the check script. > > We could invert the logic in the check script: instead of "restoring" > an imported header, the check would convert a freshly downloaded > header and compare it against the imported header in dpdk. > One thing though is that we would need a copy of the "conversion" > function in the two scripts. > > One idea.. can we have a single script? I think your suggestion makes sense. Will implement it in v1 with other nits you suggest below. Thanks, Maxime > # Interactive mode, with questions about what to import if dependencies exist: > $ devtools/linux-uapi.sh import linux/vfio.h v6.10 > > # Non interactive mode, the script uses the version file and imported headers: > $ devtools/linux-uapi.sh check > > > Regardless of this suggestion, I have some nits about the shell scripts below: > >> --- >> devtools/check-linux-uapi.sh | 85 ++++++++++++++++++ >> devtools/import-linux-uapi.sh | 119 +++++++++++++++++++++++++ >> doc/guides/contributing/index.rst | 1 + >> doc/guides/contributing/linux_uapi.rst | 71 +++++++++++++++ >> linux-headers/uapi/.gitignore | 4 + >> linux-headers/uapi/version | 1 + >> meson.build | 8 +- >> 7 files changed, 287 insertions(+), 2 deletions(-) >> create mode 100755 devtools/check-linux-uapi.sh >> create mode 100755 devtools/import-linux-uapi.sh >> create mode 100644 doc/guides/contributing/linux_uapi.rst >> create mode 100644 linux-headers/uapi/.gitignore >> create mode 100644 linux-headers/uapi/version >> >> diff --git a/devtools/check-linux-uapi.sh b/devtools/check-linux-uapi.sh >> new file mode 100755 >> index 0000000000..fc42c03169 >> --- /dev/null >> +++ b/devtools/check-linux-uapi.sh >> @@ -0,0 +1,85 @@ >> +#!/bin/sh > > It should not be too hard to pass -e, see suggestions. > > >> +# SPDX-License-Identifier: BSD-3-Clause >> +# Copyright (c) 2024 Red Hat, Inc. >> + >> +# >> +# Check Linux Kernel uAPI header files >> +# >> + >> +base_url="https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/plain/include/uapi/" >> +base_path="linux-headers/uapi/" >> +errors=0 >> +version="" >> + >> +print_usage() >> +{ >> + echo "Usage: $(basename $0) [-h]" >> +} >> + >> +check_uapi_header() { >> + path=$1 >> + file=${1#$base_path} >> + >> + cp -f $path $tmpinput1 >> + >> + # Restore includes fixups done by import-linux-uapi.sh >> + sed -i "s|//#include |#include |g" $tmpinput1 >> + sed -i "s|#include > + >> + url="${base_url}${file}?h=${version}" >> + echo -n "Checking $file... " >> + curl -s -f -o $tmpinput2 $url >> + if [ $? -ne 0 ]; then > > I always have trouble remembering the value of $?... maybe simpler: > if ! curl -s -f -o $tmpinput2 $url; then > > Doing so makes it possible to pass a -e in the shebang. > >> + echo "Failed to download $url" >> + exit 1 > > And this is a shell function, prefer return 1, rather than make the > whole script exit. > >> + fi >> + >> + diff -q $tmpinput1 $tmpinput2 >/dev/null >> + if [ $? -ne 0 ]; then > > Idem: > if ! diff -q $tmpinput1 $tmpinput2 >/dev/null > >> + echo "KO" >> + diff -u $tmpinput1 $tmpinput2 >> + errors=$((errors+1)) > > Touching the global variable errors should be done by the caller from > my pov, so here, return 1. > >> + else >> + echo "OK" >> + fi >> +} >> + >> +while getopts hv ARG ; do >> + case $ARG in >> + h ) >> + print_usage >> + exit 0 >> + ;; >> + ? ) >> + print_usage >> + exit 1 >> + ;; >> + esac >> +done >> + >> +shift $(($OPTIND - 1)) >> +if [ $# -ne 0 ]; then >> + print_usage >> + exit 1 >> +fi >> + >> +cd $(dirname $0)/.. >> + >> +tmpinput1=$(mktemp -t dpdk.checkuapi.XXXXXX) >> +tmpinput2=$(mktemp -t dpdk.checkuapi.XXXXXX) >> +trap "rm -f '$tmpinput1 $tmpinput2'" INT >> + >> +version=$(< ${base_path}/version) >> + >> +echo "Checking imported headers for version ${version}" >> + >> +for filename in $(find $base_path -name "*.h" -type f); do >> + check_uapi_header "${filename}" > No need for > And I would increment the global var errors here, so something like: > check_uapi_header "${filename}" || errors=$((errors + 1)) > >> +done >> + >> +echo "$errors error(s) found" >> + >> +rm -f $tmpinput1 $tmpinput2 >> +trap - INT >> + >> +exit $errors >> diff --git a/devtools/import-linux-uapi.sh b/devtools/import-linux-uapi.sh >> new file mode 100755 >> index 0000000000..ff15e23821 >> --- /dev/null >> +++ b/devtools/import-linux-uapi.sh >> @@ -0,0 +1,119 @@ >> +#!/bin/sh > > Similarly, I would try to make this script runable with -e. > > >> +# SPDX-License-Identifier: BSD-3-Clause >> +# Copyright (c) 2024 Red Hat, Inc. >> + >> +# >> +# Import Linux Kernel uAPI header file >> +# >> + >> +base_url="https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/plain/include/uapi/" >> +base_path="linux-headers/uapi/" >> +version="" >> +file="" >> + >> +print_usage() >> +{ >> + echo "Usage: $(basename $0) [-h] [-a FILE] [-u VERSION]" >> + echo "-a FILE import Linux header file. E.g. linux/vfio.h" >> + echo "-u VERSION update imported list of Linux headers to a given version. E.g. v6.10" >> +} >> + >> +version_valid() { > > The name is strange, this is comparing versions iiuc. > version_older_than() maybe ? > > >> + printf '%s\n%s' "$1" "$2" | sort -C -V >> +} >> + >> +update_headers() >> +{ >> + local header=${filename//"$base_path"} > > ${filename%$base_path} > >> + local url >> + local path >> + >> + echo "Updating to $version" >> + while IFS= read -d '' -r filename; do > > for filename in $(find $base_path -name "*.h" -type f) > >> + header=${filename//"$base_path"/} > > header=${filename%$base_path} > >> + url="${base_url}${header}?h=${version}" >> + path="${base_path}${header}" >> + curl -s -f -o $path $url > > Maybe log an explicit error if curl fails, like in the check script. > > >> + done < <(find $base_path -name "*.h" -type f -print0) >> +} >> + >> +import_header() >> +{ >> + local include >> + local import >> + local header=$1 >> + >> + local url="${base_url}${header}?h=${version}" >> + local path="${base_path}${header}" >> + >> + curl -s -f --create-dirs -o $path $url > > Log an error if failing. > > >> + >> + for include in $(sed -ne 's/^#include <\(.*\)>$/\1/p' $path); do >> + if [ ! -f "${base_path}${include}" ]; then >> + read -p "Import $include (y/n): " import < /dev/tty && [ "$import" = 'y' ] || continue > > Do we really need to force /dev/tty ? > >> + echo "Importing $include for $path" >> + import_header "$include" >> + fi >> + done >> +} >> + >> +fixup_includes() >> +{ >> + local path=$1 >> + >> + # Do not include linux/compiler.h as done by make headers >> + sed -i "s|^#include |//#include |g" $path >> + >> + # Prepend include path with "uapi/" if the header is imported >> + for include in $(sed -ne 's/^#include <\(.*\)>$/\1/p' $path); do >> + if [ -f "${base_path}${include}" ]; then >> + sed -i "s|${include}|uapi/${include}|g" $path >> + fi >> + done >> +} >> + >> +while getopts a:u:hv opt ; do >> + case ${opt} in >> + a ) >> + file=$OPTARG >> + ;; >> + u ) >> + version=$OPTARG >> + ;; >> + h ) >> + print_usage >> + exit 0 >> + ;; >> + ? ) >> + print_usage >> + exit 1 >> + ;; >> + esac >> +done >> + >> +cd $(dirname $0)/.. >> + >> +current_version=$(< ${base_path}/version) >> + >> +if [ -n "${version}" ]; then >> + version_valid "$version" "$current_version" >> + if [ $? -eq 0 ]; then > > if version_older_than "$version" "$current_version"; then > >> + echo "Headers already up to date ($current_version >= $version)" >> + version=$current_version >> + else >> + update_headers >> + fi >> +else >> + echo "Version not specified, using current version ($current_version)" >> + version=$current_version >> +fi >> + >> +if [ -n "${file}" ]; then >> + import_header $file >> +fi >> + >> +for filename in $(find $base_path -name "*.h" -type f); do >> + fixup_includes "${filename}" > No need for >> +done >> + >> +echo $version > ${base_path}/version > >