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 06800C433EF for ; Wed, 18 May 2022 03:36:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229660AbiERDgK (ORCPT ); Tue, 17 May 2022 23:36:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229450AbiERDfv (ORCPT ); Tue, 17 May 2022 23:35:51 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E98A362A2E; Tue, 17 May 2022 20:35:47 -0700 (PDT) Received: from kwepemi500013.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4L2zB823mRz1JCCQ; Wed, 18 May 2022 11:34:24 +0800 (CST) Received: from [10.67.111.192] (10.67.111.192) by kwepemi500013.china.huawei.com (7.221.188.120) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Wed, 18 May 2022 11:35:44 +0800 Message-ID: Date: Wed, 18 May 2022 11:35:43 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Subject: Re: [PATCH bpf-next v4 3/6] bpf: Move is_valid_bpf_tramp_flags() to the public trampoline code Content-Language: en-US To: Alexei Starovoitov CC: , , , , , Catalin Marinas , Will Deacon , Steven Rostedt , Ingo Molnar , Daniel Borkmann , Alexei Starovoitov , Zi Shen Lim , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , "David S . Miller" , Hideaki YOSHIFUJI , David Ahern , Thomas Gleixner , Borislav Petkov , Dave Hansen , , , Shuah Khan , Jakub Kicinski , Jesper Dangaard Brouer , Mark Rutland , Pasha Tatashin , Ard Biesheuvel , Daniel Kiss , Steven Price , Sudeep Holla , Marc Zyngier , Peter Collingbourne , Mark Brown , Delyan Kratunov , Kumar Kartikeya Dwivedi References: <20220517071838.3366093-1-xukuohai@huawei.com> <20220517071838.3366093-4-xukuohai@huawei.com> <20220517155349.4jk5oymnjvrasw2p@MacBook-Pro.local> From: Xu Kuohai In-Reply-To: <20220517155349.4jk5oymnjvrasw2p@MacBook-Pro.local> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.67.111.192] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemi500013.china.huawei.com (7.221.188.120) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 5/17/2022 11:53 PM, Alexei Starovoitov wrote: > On Tue, May 17, 2022 at 03:18:35AM -0400, Xu Kuohai wrote: >> >> +static bool is_valid_bpf_tramp_flags(unsigned int flags) >> +{ >> + if ((flags & BPF_TRAMP_F_RESTORE_REGS) && >> + (flags & BPF_TRAMP_F_SKIP_FRAME)) >> + return false; >> + >> + /* BPF_TRAMP_F_RET_FENTRY_RET is only used by bpf_struct_ops, >> + * and it must be used alone. >> + */ >> + if ((flags & BPF_TRAMP_F_RET_FENTRY_RET) && >> + (flags & ~BPF_TRAMP_F_RET_FENTRY_RET)) >> + return false; >> + >> + return true; >> +} >> + >> +int bpf_prepare_trampoline(struct bpf_tramp_image *tr, void *image, >> + void *image_end, const struct btf_func_model *m, >> + u32 flags, struct bpf_tramp_links *tlinks, >> + void *orig_call) >> +{ >> + if (!is_valid_bpf_tramp_flags(flags)) >> + return -EINVAL; >> + >> + return arch_prepare_bpf_trampoline(tr, image, image_end, m, flags, >> + tlinks, orig_call); >> +} > > It's an overkill to introduce a new helper function just to validate > flags that almost compile time constants. > The flags are not user supplied. > Please move /* BPF_TRAMP_F_RET_FENTRY_RET is only used by bpf_struct_ops ... */ > comment to bpf_struct_ops.c right before it calls arch_prepare_bpf_trampoline() > And add a comment to trampoline.c saying that BPF_TRAMP_F_RESTORE_REGS > and BPF_TRAMP_F_SKIP_FRAME should not be set together. > We could add a warn_on there or in arch code, but feels like overkill. > . OK, will fix in next version.