From patchwork Wed Oct 19 08:22:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 4525 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp203555wrs; Wed, 19 Oct 2022 01:43:24 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4nFXGg8DZgmKOSi8PHXLxpX2mH0kXvmMMtbsSFtiGuv87sekXt1ug+dX46Z9Wz8AJN2BAg X-Received: by 2002:a17:907:168c:b0:78d:8b6c:a209 with SMTP id hc12-20020a170907168c00b0078d8b6ca209mr6128875ejc.185.1666169003824; Wed, 19 Oct 2022 01:43:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666169003; cv=none; d=google.com; s=arc-20160816; b=r6MMHOXb4kZDOtoL58wWBcDE4VmIvQ89XkKIoKHPaQlXSD146W5vUoMq+ywWD17O/B wjsIm8clSWMwaSX7ll7OEwXHYqngTzR+jfQLKQVwFQhMiqZoi4kbr1gWC1ZYEgWSwBjC Cfs1q1sjTDco+JfJ+ZTDhv9nIj/xOaRsTU6VSHVlw0CY1eVO+5aj14OYm0A8oCkcBp3o mpj7Hm6R93fkZ7kjXgWvOxDw6jqW+ghJHRO/j/Ibfse6XrgSWLtPANxgzF0ARKVNCjF6 MPqSRozw0ZiZ8/SLAj7gaHSPF5LjrNb6G/2rHsWchkWyYLFENFKabb7OWT/JPFXmcKHf lPYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=642PGjFqDZ0CGtOhYVSVDmanyvQBYmUfzM1qcwgz9LE=; b=CDbJKA7BdT2GsJEBgv8vhy1iaofDrACEpviY/EtIrHUkaMt1i7Zv1RzgYMLomgYvoE t2YxzYzzS+765wlRlIfdnRIDi9qK7kXKxEEDuZCvB/p1JS06L15u/Pg+mZ6zX2b+sLBn JIgkSPRdJi7o5CljY8ZpFa3mYUg8c+HzISNAobhM/gNcbXm5dnA1xJ75AtTEIGEr8aW0 w9G3zNfxFnOE7mSYXSUnaQXIncwaUh9xLNX5sF2nFHLQEAXJP2sstLT4cY8YPbr0mKgW 7umwhg08i1ot+W/RpMxwDxA0RsGOzzG5KFUkAFPgsB3cd4GNt/X/UiElIqVHyD4ZO8Vj PZ5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xp8LemG4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h9-20020a05640250c900b00458bc949b45si16217451edb.488.2022.10.19.01.42.59; Wed, 19 Oct 2022 01:43:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xp8LemG4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231187AbiJSImW (ORCPT + 99 others); Wed, 19 Oct 2022 04:42:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230294AbiJSIl3 (ORCPT ); Wed, 19 Oct 2022 04:41:29 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C758A7EFFB; Wed, 19 Oct 2022 01:39:17 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id BF652617E8; Wed, 19 Oct 2022 08:39:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 95E69C433D7; Wed, 19 Oct 2022 08:39:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666168756; bh=CJh7BEGtcX3x0wey5F8aR0SgwStg4GuMXPmHzzulGjc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xp8LemG4PfsYLsu6Nl8h/LFAFYI0FSYHGf1gVquXAaZqlPLVnj/kuxunZ5SHiZ6xm AHyanN3gfFXtHLVJqE4w7jrPYEoOlx1z8x696lce1g0co0USNT92VTYKFTEM65H/do aDl07haLg4G8KvH3N7z5CBemyp8tfcfcmO07Bui0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Joanne Koong , Roberto Sassu , Yonghong Song , KP Singh , Alexei Starovoitov Subject: [PATCH 6.0 044/862] btf: Export bpf_dynptr definition Date: Wed, 19 Oct 2022 10:22:11 +0200 Message-Id: <20221019083251.945344355@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747104829471639334?= X-GMAIL-MSGID: =?utf-8?q?1747104829471639334?= From: Roberto Sassu commit 00f146413ccb6c84308e559281449755c83f54c5 upstream. eBPF dynamic pointers is a new feature recently added to upstream. It binds together a pointer to a memory area and its size. The internal kernel structure bpf_dynptr_kern is not accessible by eBPF programs in user space. They instead see bpf_dynptr, which is then translated to the internal kernel structure by the eBPF verifier. The problem is that it is not possible to include at the same time the uapi include linux/bpf.h and the vmlinux BTF vmlinux.h, as they both contain the definition of some structures/enums. The compiler complains saying that the structures/enums are redefined. As bpf_dynptr is defined in the uapi include linux/bpf.h, this makes it impossible to include vmlinux.h. However, in some cases, e.g. when using kfuncs, vmlinux.h has to be included. The only option until now was to include vmlinux.h and add the definition of bpf_dynptr directly in the eBPF program source code from linux/bpf.h. Solve the problem by using the same approach as for bpf_timer (which also follows the same scheme with the _kern suffix for the internal kernel structure). Add the following line in one of the dynamic pointer helpers, bpf_dynptr_from_mem(): BTF_TYPE_EMIT(struct bpf_dynptr); Cc: stable@vger.kernel.org Cc: Joanne Koong Fixes: 97e03f521050c ("bpf: Add verifier support for dynptrs") Signed-off-by: Roberto Sassu Acked-by: Yonghong Song Tested-by: KP Singh Link: https://lore.kernel.org/r/20220920075951.929132-3-roberto.sassu@huaweicloud.com Signed-off-by: Alexei Starovoitov Signed-off-by: Greg Kroah-Hartman --- kernel/bpf/helpers.c | 2 ++ 1 file changed, 2 insertions(+) --- a/kernel/bpf/helpers.c +++ b/kernel/bpf/helpers.c @@ -1468,6 +1468,8 @@ BPF_CALL_4(bpf_dynptr_from_mem, void *, { int err; + BTF_TYPE_EMIT(struct bpf_dynptr); + err = bpf_dynptr_check_size(size); if (err) goto error;