Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp2645499rdb; Fri, 8 Dec 2023 14:47:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IE5023yB+9hSbxaHroYRvE+Ezd43JZjEC3xJkG0ExZvlDIg+Iv0MVcVO05ri70Gh9HMKayJ X-Received: by 2002:a05:6870:55ce:b0:1fb:75b:2fa6 with SMTP id qk14-20020a05687055ce00b001fb075b2fa6mr951187oac.61.1702075636065; Fri, 08 Dec 2023 14:47:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702075636; cv=none; d=google.com; s=arc-20160816; b=NeJPJMIZVlm/plfzFhH7QLrrroWLnuGSIZv1QvKgoJtHAsyKt0z+uLFcPTdNTLhf48 xFaDuf0thNwkMA0h7pbRko+6ehkgH1EDClmtU6V44kp/ieKE5glAtD8PDRH7TVGL3mhB hmAsx7dPNt3Zy72q9d6EuJpcZoAjxPWWtNPuJpj63i/yo6HC43OOvcR94Q6ug8ivis1E i9b+S9YD9OJKZ49E0jv/2lbJcaTyqSZCRrJGH+BjIuc4PKdpwoUaOXnjM9L+Z47tBY2y cvj/Br5/hX9V6JAxzPAwBO1kz4cMvWTtQxM0x+Y2gJvILTvt7NhhIjmb5PMz0vGHrohc v0jQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=9AtZTt6OGfjsPDJQOtDfx5Cu6irtFkmWZMjDyBOLAY8=; fh=31pHNESfIDSRXSirSss2cSA7Q2Y3tA2WaWyHSS2Dgno=; b=Y5J7MzbvKFbe1pkldSyL59AVdrtcBsyC/NY+JoDnhhIc+Vv9M6+INlathzCB+wzNrW EEmOSr8OG3O6Jv5/fHQfZsn0qUExBYy6mCi0NLR3fgQlHPePiQdOpmyYGaAzqtHKcRWn udB+5q6hGWHlqx6mkdSf5jE7ss5qOW8yNIT5YoK/HQIfoAQRgCyE/nO3U6CXFkItxZn7 n5bkcOQxcdvWCo+iKEFLbBUgdmoSbsbgjHqqBJoyWvSVzg8tUWCYqJTMNQoBTH7wppVC wifoE9SMWqW97zY0IiyOP9CCulDsO2un6/lyhFHf6zwIU6biFW+Zt/+8nWwmwM/TKleS BAkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=anFV4EKn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id l66-20020a632545000000b005c14c9b2d90si2237631pgl.59.2023.12.08.14.47.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 14:47:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=anFV4EKn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 11DD6807C860; Fri, 8 Dec 2023 14:47:13 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229725AbjLHWqt (ORCPT + 99 others); Fri, 8 Dec 2023 17:46:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229525AbjLHWqs (ORCPT ); Fri, 8 Dec 2023 17:46:48 -0500 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39250AC; Fri, 8 Dec 2023 14:46:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Transfer-Encoding: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description; bh=9AtZTt6OGfjsPDJQOtDfx5Cu6irtFkmWZMjDyBOLAY8=; b=anFV4EKnBK8gQJUQaPbHBdGbmh b2Y7tMQ6hHkQDT5vgOGk/97h6xyIa4MDZnDQV4WFLZMH0Moc2XQBReqMlEddNf22x5eaw0zAoXtGq dyQwgTqMZqIOn/1N4xYUukkUwd2BIl/rwN+ayXO0Y2NWwvxlGU3Yxjp8/bdR9jO8fTnclXdXuFPiN /eQ1qV70Ux813zNWm90BtR+BVtsuhQ7+lpHQtd95lVHbKAbeBGyJQhSdn2Nf39E/FRT7aa1T5sy3K KtlIjlSiXtHdzhKo1SHrWhL9Azqgm2vU4mbnqe/RW5vhus/b8/1CvhOM+ExeLbzwwDLJKGTkrTFIZ Ez+2V7qQ==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rBjba-006iqm-2j; Fri, 08 Dec 2023 22:46:00 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id C66943003F0; Fri, 8 Dec 2023 23:45:57 +0100 (CET) Date: Fri, 8 Dec 2023 23:45:57 +0100 From: Peter Zijlstra To: Alexei Starovoitov Cc: Jiri Olsa , Song Liu , Song Liu , Paul Walmsley , Palmer Dabbelt , Albert Ou , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , X86 ML , "H. Peter Anvin" , "David S. Miller" , David Ahern , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Arnd Bergmann , Sami Tolvanen , Kees Cook , Nathan Chancellor , Nick Desaulniers , linux-riscv , LKML , Network Development , bpf , linux-arch , clang-built-linux , Josh Poimboeuf , Joao Moreira , Mark Rutland Subject: Re: [PATCH v2 2/2] x86/cfi,bpf: Fix BPF JIT call Message-ID: <20231208224557.GH36716@noisy.programming.kicks-ass.net> References: <20231207093105.GA28727@noisy.programming.kicks-ass.net> <20231208102940.GB28727@noisy.programming.kicks-ass.net> <20231208134041.GD28727@noisy.programming.kicks-ass.net> <20231208172152.GD36716@noisy.programming.kicks-ass.net> <20231208203535.GG36716@noisy.programming.kicks-ass.net> <20231208205241.GK28727@noisy.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Fri, 08 Dec 2023 14:47:13 -0800 (PST) On Fri, Dec 08, 2023 at 12:58:01PM -0800, Alexei Starovoitov wrote: > On Fri, Dec 8, 2023 at 12:52 PM Peter Zijlstra wrote: > > > > On Fri, Dec 08, 2023 at 12:41:03PM -0800, Alexei Starovoitov wrote: > > > On Fri, Dec 8, 2023 at 12:35 PM Peter Zijlstra wrote: > > > > > > -__bpf_kfunc void bpf_task_release(struct task_struct *p) > > > > +__bpf_kfunc void bpf_task_release(void *p) > > > > > > Yeah. That won't work. We need a wrapper. > > > Since bpf prog is also calling it directly. > > > In progs/task_kfunc_common.h > > > void bpf_task_release(struct task_struct *p) __ksym; > > > > > > than later both libbpf and the verifier check that > > > what bpf prog is calling actually matches the proto > > > of what is in the kernel. > > > Effectively we're doing strong prototype check at load time. > > > > I'm still somewhat confused on how this works, where does BPF get the > > address of the function from? and what should I call the wrapper? > > It starts with > register_btf_id_dtor_kfuncs() that takes a set of btf_ids: > {btf_id_of_type, btf_id_of_dtor_function}, ... > > Then based on btf_id_of_dtor_function we find its type proto, name, do checks, > and eventually: > addr = kallsyms_lookup_name(dtor_func_name); > field->kptr.dtor = (void *)addr; > > bpf_task_release(struct task_struct *p) would need to stay as-is, > but we can have a wrapper > void bpf_task_release_dtor(void *p) > { > bpf_task_release(p); > } > > And adjust the above lookup with extra "_dtor" suffix. > > > > btw instead of EXPORT_SYMBOL_GPL(bpf_task_release) > > > can __ADDRESSABLE be used ? > > > Since it's not an export symbol. > > > > No __ADDRESSABLE() is expressly ignored, but we have IBT_NOSEAL() that > > should do it. I'll rename the thing and lift it out of x86 to avoid > > breaking all other arch builds. > > Makes sense. Ok, did that. Current patches (on top of bpf-next) are here: git://git.kernel.org/pub/scm/linux/kernel/git/peterz/queue.git x86/cfi (really should try and write better changelogs, but it's too late) The test_progs thing still doesn't run to completion, the next problem seems to be bpf_throw(): [ 247.720159] ? die+0xa4/0xd0 [ 247.720216] ? do_trap+0xa5/0x180 [ 247.720281] ? __cfi_bpf_prog_8ac473954ac6d431_F+0xd/0x10 [ 247.720368] ? __cfi_bpf_prog_8ac473954ac6d431_F+0xd/0x10 [ 247.720459] ? do_error_trap+0xba/0x120 [ 247.720525] ? __cfi_bpf_prog_8ac473954ac6d431_F+0xd/0x10 [ 247.720614] ? handle_invalid_op+0x2c/0x40 [ 247.720684] ? __cfi_bpf_prog_8ac473954ac6d431_F+0xd/0x10 [ 247.720775] ? exc_invalid_op+0x38/0x60 [ 247.720840] ? asm_exc_invalid_op+0x1a/0x20 [ 247.720909] ? 0xffffffffc001ba54 [ 247.720971] ? __cfi_bpf_prog_8ac473954ac6d431_F+0xd/0x10 [ 247.721063] ? bpf_throw+0x9b/0xf0 [ 247.721126] ? bpf_test_run+0x108/0x350 [ 247.721191] ? bpf_prog_5555714b685bf0cf_exception_throw_always_1+0x26/0x26 [ 247.721301] ? bpf_test_run+0x108/0x350 [ 247.721368] bpf_test_run+0x212/0x350 [ 247.721433] ? slab_build_skb+0x22/0x110 [ 247.721503] bpf_prog_test_run_skb+0x347/0x4a0 But I'm too tired to think staight. Is this a bpf_callback_t vs bpf_exception_cb difference? I'll prod more later. Zzzz..