Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp115100iob; Tue, 17 May 2022 20:43:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxL4USXjpczMEmXg6xMUvgCGbATfCH6N9Rkb5C+iAn65RtX5GwfqyFdA558Bhjnm4a6NwXw X-Received: by 2002:a17:90a:db95:b0:1df:37e7:6a28 with SMTP id h21-20020a17090adb9500b001df37e76a28mr17489852pjv.204.1652845394513; Tue, 17 May 2022 20:43:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652845394; cv=none; d=google.com; s=arc-20160816; b=punQvB4cPRp7ioY8Q6UWQ/DHAgH81VDrexc+KjfUxJ6sd1Ccw7m11H995p1o7EEk2p deTcsxDcamGRsmWqJbXpUOVuHv5RwvdoT6kMVWVt/Lq+rLyIsxRa62K8JPNTFkTYF4aT 0NXF4MFx5IHgOsSZq5LelKr6mCSEEKIZAEXO4tYEUHLBrnZYJv3TP5qhBhELyLn9eJ4n CAI0OnNaNtT7OnOLvz0Eiw6M2tkeIc2tOx1qgnfCvN8OMimpeF65JFU52BohXOw1pXG0 GsH9PnjttQ8mVAxfDM87/Bf6h5Rqrxp0rcLRlEbg/s+vv564og7qU/2mK7tiaYHcQgpg T3HQ== 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-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=rmBZXjHGe6pjrZrcbSckkH/iPjlINFANkKf9gszWPYU=; b=e4kVB6mpRC44k6t6LoUYs2rVoVp/pbJXFo3mwyN0iFMXyZm6pj49/FnZxiRU8eWgMW lRpJ0bngBYBCzvKi7hCC1gOseRGMN6utqExgdwu3jGqeU0VTrfzIN8EI9BNb321cNihP BVFnhMl0s/ZSTS3M/mjCLCHPjTRq18LhZEX9YQvO5pFyFggU4nZckO09UCXqYgznq/+H BBwrkKneJ1G9YAtGFtLNj+wf0DPTeUAzYiMAfslYCypOiRSI8bC0FtZgd3KiTwtEI8XU VFNNIZkx5/9pymcHX+jF/fJ0uYvpILRuYLZyl8papqUVuxOWGiOKkwbvMeyPO7XY1Fxy x4dA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=mCL2WZQf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id l17-20020a63f311000000b003db070de83bsi1063031pgh.451.2022.05.17.20.43.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 20:43:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=mCL2WZQf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id AA72C7CDC9; Tue, 17 May 2022 20:30:21 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350465AbiEQPyJ (ORCPT + 99 others); Tue, 17 May 2022 11:54:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350662AbiEQPyC (ORCPT ); Tue, 17 May 2022 11:54:02 -0400 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C62D950B26; Tue, 17 May 2022 08:53:54 -0700 (PDT) Received: by mail-pg1-x532.google.com with SMTP id 137so17293266pgb.5; Tue, 17 May 2022 08:53:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=rmBZXjHGe6pjrZrcbSckkH/iPjlINFANkKf9gszWPYU=; b=mCL2WZQfUMWu4xy6yy7X1+ebSif5rAu/jKymgNsJYYzZFnA9ugCrwiihsPYjvzThIU DFn5Lk91C0tZGoeUNkgplThRXBMayt2xcmaeF/kI+0KvGVR+kIISN5RmRdDJqe7Oadm+ ApJfECbPyywghswoV+jBSpOdkrBps9EXktTRVf3Url5a8fO/0L7wfegdHmd2rnO/VKqr 5aIFJRbhhBTCl8CG9Fz4O9HHJKwwrK9Rxg2vuvpaHSd9SFQ95LPDBKs/Xs2D02Uy/oXT ZFn7YQQsYYxadnuLDDRi0dvdKAfQu/UzUbSJrsKeXA9Nrm8fbp9Bp3m1fdX1C87JU/JQ FXxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=rmBZXjHGe6pjrZrcbSckkH/iPjlINFANkKf9gszWPYU=; b=Ib3dDUlTM04ry+BsbBJCGicKyfD0/9WIB+k0j8S6lgvmCrayRA2OM/3KYcnpChQHEa YHGfzKJpQtQXXyWQlFXSCjnZOUVRV5qVeVqfERpxWHgm+3PqUfnhgt1SwnfYLoZKPh0Z RSQOSYxo2Q5qO7xOHRKvsdOD/HjG46gWHysagO571KmfEWVkVA6zBf+TgVSw6CX0YF+L QztLEkEaBOsZGsi5N7WMW7ixsMCoWMeyK1E4RrbNXpi+Ucb9F3Wqfqpq3dTdHhMfdnOw LFC/Auv2sMTNW8+jV0Hrid8yRvHxMqj1/1oPNo5pNyk52iMC611MEgxS5TjxT+H32dht iTsQ== X-Gm-Message-State: AOAM530j5FON1Djz9qZ5xcdpYGD1PkNHYtIYQpBTuyFwixC/CdWCkh77 HQ83wXMvDO4/v0SbDbDPquk= X-Received: by 2002:a63:8442:0:b0:3c6:4271:cad with SMTP id k63-20020a638442000000b003c642710cadmr20242021pgd.275.1652802834212; Tue, 17 May 2022 08:53:54 -0700 (PDT) Received: from MacBook-Pro.local ([2620:10d:c090:500::2:c22a]) by smtp.gmail.com with ESMTPSA id d14-20020a62f80e000000b0050dc76281fdsm6932pfh.215.2022.05.17.08.53.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 08:53:53 -0700 (PDT) Date: Tue, 17 May 2022 08:53:49 -0700 From: Alexei Starovoitov To: Xu Kuohai Cc: bpf@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, 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 , x86@kernel.org, hpa@zytor.com, 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 Subject: Re: [PATCH bpf-next v4 3/6] bpf: Move is_valid_bpf_tramp_flags() to the public trampoline code Message-ID: <20220517155349.4jk5oymnjvrasw2p@MacBook-Pro.local> References: <20220517071838.3366093-1-xukuohai@huawei.com> <20220517071838.3366093-4-xukuohai@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220517071838.3366093-4-xukuohai@huawei.com> X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 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.