From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 01571C3DA66 for ; Fri, 25 Aug 2023 08:09:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243388AbjHYIJX (ORCPT ); Fri, 25 Aug 2023 04:09:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241806AbjHYIIz (ORCPT ); Fri, 25 Aug 2023 04:08:55 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92AC51FF7 for ; Fri, 25 Aug 2023 01:08:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692950890; 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; bh=l9YDmP7EGByhxJ360XVPZoot7p/wWLTefjiD4Jsf+DI=; b=GwaRkEGyx2uLhrr+xchNYu6dlAFFFVO9kJzpQlJB2xkcHAQUxXERky14aixh1bE9gdfdPG c8DKM6NTDRdWnoq12KDaw2Ku34wPn/urn8DX2ZieYwwTzvX09hL0DY5k5zy1lgdsw8biU/ Ny3Iz7fWBtLuG0AwZMvgGB2UR2srsZc= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-650-Hc88rSiKM1ueFlgf5Zo96g-1; Fri, 25 Aug 2023 04:08:09 -0400 X-MC-Unique: Hc88rSiKM1ueFlgf5Zo96g-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-3fe4f953070so5615975e9.2 for ; Fri, 25 Aug 2023 01:08:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692950887; x=1693555687; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:subject:from:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=l9YDmP7EGByhxJ360XVPZoot7p/wWLTefjiD4Jsf+DI=; b=Ybdz92fdMkOFHEhO5cYgXO9vYD0EYgCTkWEABPp9b2CH/6EJRhsObI+NKE0/hMxm7B 6r65lSOyddqAeNSZrYNCQeQaPZA8RQAXs5RzIBpd8QNVJnlGWNnii8uFsh2BlWQ4rTj4 eRBDmynXF9E5tVZLUlQym6cSuLtZt5Aru7YCRwyGRJJbRVUlTSmHKB0uZLCgMunFQXci lJQBy2FnXrxlLXzfXglWwMmvHG73MXF1kx9whck4ZVSuafb+gxgRAzvLKukldlkYwX72 KTWu2OlM5ww5lgwxgOozcN0S3VXOwFRydPXkRZd5OzTvvke2ZbCYUX0p0NT46nTNs5Eg qkcg== X-Gm-Message-State: AOJu0Yxgq1nbpfQm0Pe/YrUoKgzsvnc/3mZNxU2i7ztJmuzurZjPkCKs O7YPEi09XhDk3gBAgoq7R9Zije3COHAYYEQ5EKLT2qqN7Ux1UPgmT42YayLEgcZNLBKH74VnJNg YhPd6lLaJ5/Cd12HhjVL1gpme X-Received: by 2002:a7b:cc8e:0:b0:401:b3a5:ec03 with SMTP id p14-20020a7bcc8e000000b00401b3a5ec03mr1618534wma.1.1692950887384; Fri, 25 Aug 2023 01:08:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHB2QDeCnpUSinediuR+3DhAUb/uZh+8tLlW2HtMVIOL3fzEOVQGLx576P+9vuPymPt0laUbA== X-Received: by 2002:a7b:cc8e:0:b0:401:b3a5:ec03 with SMTP id p14-20020a7bcc8e000000b00401b3a5ec03mr1618519wma.1.1692950887063; Fri, 25 Aug 2023 01:08:07 -0700 (PDT) Received: from ?IPV6:2a01:e0a:2bc:381::432? ([2a01:e0a:2bc:381::432]) by smtp.gmail.com with ESMTPSA id k2-20020a7bc302000000b003fc06169ab3sm4672896wmj.20.2023.08.25.01.08.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 25 Aug 2023 01:08:06 -0700 (PDT) Message-ID: <56ba8125-2c6f-a9c9-d498-0ca1c153dcb2@redhat.com> Date: Fri, 25 Aug 2023 10:08:05 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 From: Benjamin Tissoires Subject: Re: selftests: hid: trouble building with clang due to missing header To: Justin Stitt Cc: Nick Desaulniers , linux-kselftest@vger.kernel.org, bpf@vger.kernel.org, linux-input@vger.kernel.org, Linux Kernel Mailing List , Nathan Chancellor , Kees Cook References: <20230822214220.jjx3srik4mteeond@google.com> Content-Language: en-US In-Reply-To: <20230822214220.jjx3srik4mteeond@google.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 22, 2023 at 11:42 PM Justin Stitt wrote: > > > > > Which kernel are you trying to test? > > > > > I tested your 2 commands on v6.5-rc7 and it just works. > > > > > > > > I'm also on v6.5-rc7 (706a741595047797872e669b3101429ab8d378ef) > > > > > > > > I ran these exact commands: > > > > | $ make mrproper > > > > | $ make LLVM=1 ARCH=x86_64 headers > > > > | $ make LLVM=1 ARCH=x86_64 -j128 -C tools/testing/selftests > > > > TARGETS=hid &> out > > > > > > > > and here's the contents of `out` (still warnings/errors): > > > > https://gist.github.com/JustinStitt/d0c30180a2a2e046c32d5f0ce5f59c6d > > > > > > > > I have a feeling I'm doing something fundamentally incorrectly. Any ideas? > > > > > > Sigh... there is a high chance my Makefile is not correct and uses the > > > installed headers (I was running the exact same commands, but on a > > > v6.4-rc7+ kernel). > > > > > > But sorry, it will have to wait for tomorrow if you want me to have a > > > look at it. It's 11:35 PM here, and I need to go to bed > > Take it easy. Thanks for the prompt responses here! I'd like to get > > the entire kselftest make target building with Clang so that we can > > close [1]. Sorry I got urgent matters to tackle yesterday. It took me a while to understand what was going on, and I finally found it. struct hid_bpf_ctx is internal to the kernel, and so is declared in vmlinux.h, that we generate through BTF. But to generate the vmlinux.h with the correct symbols, these need to be present in the running kernel. And that's where we had a fundamental difference: I was running my compilations on a kernel v6.3+ (6.4.11) with that symbol available, and you are probably not. The bpf folks are using a clever trick to force the compilation[2]. And I think the following patch would work for you: --- From bb9eccb7a896ba4b3a35ed12a248e6d6cfed2df6 Mon Sep 17 00:00:00 2001 From: Benjamin Tissoires Date: Fri, 25 Aug 2023 10:02:32 +0200 Subject: [PATCH] selftests/hid: ensure we can compile the tests on kernels pre-6.3 For the hid-bpf tests to compile, we need to have the definition of struct hid_bpf_ctx. This definition is an internal one from the kernel and it is supposed to be defined in the generated vmlinux.h. This vmlinux.h header is generated based on the currently running kernel or if the kernel was already compiled in the tree. If you just compile the selftests without compiling the kernel beforehand and you are running on a 6.2 kernel, you'll end up with a vmlinux.h without the hid_bpf_ctx definition. Use the clever trick from tools/testing/selftests/bpf/progs/bpf_iter.h to force the definition of that symbol in case we don't find it in the BTF. Signed-off-by: Benjamin Tissoires --- tools/testing/selftests/hid/progs/hid.c | 3 --- .../selftests/hid/progs/hid_bpf_helpers.h | 20 +++++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/hid/progs/hid.c b/tools/testing/selftests/hid/progs/hid.c index 88c593f753b5..1e558826b809 100644 --- a/tools/testing/selftests/hid/progs/hid.c +++ b/tools/testing/selftests/hid/progs/hid.c @@ -1,8 +1,5 @@ // SPDX-License-Identifier: GPL-2.0 /* Copyright (c) 2022 Red hat */ -#include "vmlinux.h" -#include -#include #include "hid_bpf_helpers.h" char _license[] SEC("license") = "GPL"; diff --git a/tools/testing/selftests/hid/progs/hid_bpf_helpers.h b/tools/testing/selftests/hid/progs/hid_bpf_helpers.h index 4fff31dbe0e7..749097f8f4d9 100644 --- a/tools/testing/selftests/hid/progs/hid_bpf_helpers.h +++ b/tools/testing/selftests/hid/progs/hid_bpf_helpers.h @@ -5,6 +5,26 @@ #ifndef __HID_BPF_HELPERS_H #define __HID_BPF_HELPERS_H +/* "undefine" structs in vmlinux.h, because we "override" them below */ +#define hid_bpf_ctx hid_bpf_ctx___not_used +#include "vmlinux.h" +#undef hid_bpf_ctx + +#include +#include + + +struct hid_bpf_ctx { + __u32 index; + const struct hid_device *hid; + __u32 allocated_size; + enum hid_report_type report_type; + union { + __s32 retval; + __s32 size; + }; +}; + /* following are kfuncs exported by HID for HID-BPF */ extern __u8 *hid_bpf_get_data(struct hid_bpf_ctx *ctx, unsigned int offset, -- 2.41.0 --- Would you mind testing it? Cheers, Benjamin [2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/testing/selftests/bpf/progs/bpf_iter.h#n3