Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp1227331rdg; Fri, 13 Oct 2023 14:27:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE9oET1s+QdbzLxhVJkU56tX/K0fqj8yljVlqF6Let11qmVoiQBaoV8nHbb6CMgaItqKoLM X-Received: by 2002:a05:6a20:1593:b0:155:5c28:ea74 with SMTP id h19-20020a056a20159300b001555c28ea74mr30080244pzj.12.1697232479110; Fri, 13 Oct 2023 14:27:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697232479; cv=none; d=google.com; s=arc-20160816; b=iIm14SyKKlJYLY+nLD0zEE7yF5q2QjyNwEYwvprAXXxiPizK+oQ1YPgXaLB52Y+50Q HKiQh7Gy79SSKknAckjqJmPwkqCkxRW+8Yb/L1ajYpR5vxh2rzHnl72xFH+ne2iO6Si/ 0Pv2DsY0Xet+QPmV4Xp+QJQH5MnNCCw9Gj4c7YDsc+x6aFbFI51j9PIAd7KaXL8opPQc cGNmC4eKEm0qhU7ul25Jzzaybst5ispBwomDKTQhma/tHBBIy8WMK4Pc+ouLuxJ7NwOi LWryE+8QFcuwT1sCucsLra4+2eQq4vzB9gA/fJEtLIfij4zSQ07DsdjGLVArKkJGWj++ 0m/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=mtsbovs15s43CkdO6JUReym2p8ycE9LPuxt+485Y15w=; fh=luN1T+TZmJdWrv2MwLqOcKf0btUR/zj1LntAQkciNa8=; b=gOpK2CPz03lszMRj0Mfga3IKuujGtFDga242D86AH94gdqCqgNEv22kMs1uapfoQTf dDmjqOyyquBlSf3DanB/ENnwFOZ78rmLvWyPFMNKzntg5VSpQUofzA0QYxxY8P6HsAzG JYOQ4rjE0R58DMBwVevVvHZ7oWYkKYHC+U45WBh3DjvRWUk3wSSIjHYwb0AuhDbzjOkv 0ZoGgGWdHPU/7USkBa5ltiEGmV3bvD9LYTnmrdF124WgB7GnXpzQKMyIhAR6GV7A/s49 1nOvGrqjMwCQU+TLXbPD5Z2EDo0T+YSk+YYpadbDZ+Hwu0NELCIcXH3IbBeibazLAeKQ NIww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=EJbm9wWF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id be3-20020a656e43000000b00589ab0ae2edsi5183761pgb.649.2023.10.13.14.27.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 14:27:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=EJbm9wWF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id ABE7A83BD9A6; Fri, 13 Oct 2023 14:27:52 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232034AbjJMV1i (ORCPT + 99 others); Fri, 13 Oct 2023 17:27:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229763AbjJMV1g (ORCPT ); Fri, 13 Oct 2023 17:27:36 -0400 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D88DD95; Fri, 13 Oct 2023 14:27:34 -0700 (PDT) Received: by mail-ed1-x52c.google.com with SMTP id 4fb4d7f45d1cf-53dd752685fso4542618a12.3; Fri, 13 Oct 2023 14:27:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697232453; x=1697837253; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=mtsbovs15s43CkdO6JUReym2p8ycE9LPuxt+485Y15w=; b=EJbm9wWF08yNmkfzXOZ9cxxOV8Ct97T32kIsyxgVUrcAOd8krAJm96J5ADnQ5idGyN WGrSSwGsvp/Sd0A0DKpkhGPfeggWbN6DIPUOvlo7H/KLAUEJ9yTGYmpt4t9lubZstuVf 1LVjXKtWBQxW7faKc0g7kQlPhqfjYK8E9dpDJMV/3XXcabGk2XGTCCw2o1PDvUIa1bH8 XLr1ripUTlp3W+WumpFHc7eB409u9+kTuy3gPg/cayOz7Qi6fF3KY6VLnZWuEvvN0axT tqCSdHwAbC2DpkPKy7OicZkSNik93fJhbc+ynDA0Lg/XCC2fn85ZX5+EB4fMz1bKZg4p LVfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697232453; x=1697837253; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mtsbovs15s43CkdO6JUReym2p8ycE9LPuxt+485Y15w=; b=dnhCzPfoGSdKlO7oNuFUxCFqoF3W+PgaDmRmmqtk5eMVjuME7pxBgPS/jDgfySx0fs vif0hjdNyahO1oc7CuIyfm4cOZavws7gZbkVJDEgfsfAkQIC38EHn2jGXB+Dlu29tn4G C7emNzvErasv9OaRCX45bwNY5ncYjlPY4qRDvkffSiA2sExnoCaoEwZbp5aYgRVDrqNa qipp8q905M9SzLx7Sg9Ug+RvR8vNjmlmVCTFFGbtH7sPHPKydSvw0+WNYGJ9bRQNB7s5 Wwqct/SZkrKUDDJ4IiadXLabBq2j5uJQsAYepBnAnFBa4RBd6Zrv9ZbQDG0CZCtqCosG AL4A== X-Gm-Message-State: AOJu0YyUk3UTwVwKnBATAK1o/4RxDDSouYEW5Hyt4mfzlc6faN+dsEHZ z27Oz0lxWQKu0ZwvXlvI5ofZfbnu7jWf37oujkQ= X-Received: by 2002:a05:6402:f25:b0:53d:d4e7:af5f with SMTP id i37-20020a0564020f2500b0053dd4e7af5fmr9178654eda.13.1697232453169; Fri, 13 Oct 2023 14:27:33 -0700 (PDT) MIME-Version: 1.0 References: <20231011120857.251943-1-zhouchuyi@bytedance.com> <20231011120857.251943-6-zhouchuyi@bytedance.com> In-Reply-To: <20231011120857.251943-6-zhouchuyi@bytedance.com> From: Andrii Nakryiko Date: Fri, 13 Oct 2023 14:27:21 -0700 Message-ID: Subject: Re: [PATCH bpf-next v5 5/8] bpf: teach the verifier to enforce css_iter and task_iter in RCU CS To: Chuyi Zhou Cc: bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@kernel.org, tj@kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.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 (pete.vger.email [0.0.0.0]); Fri, 13 Oct 2023 14:27:52 -0700 (PDT) On Wed, Oct 11, 2023 at 5:09=E2=80=AFAM Chuyi Zhou wrote: > > css_iter and task_iter should be used in rcu section. Specifically, in > sleepable progs explicit bpf_rcu_read_lock() is needed before use these > iters. In normal bpf progs that have implicit rcu_read_lock(), it's OK to > use them directly. > > This patch adds a new a KF flag KF_RCU_PROTECTED for bpf_iter_task_new an= d > bpf_iter_css_new. It means the kfunc should be used in RCU CS. We check > whether we are in rcu cs before we want to invoke this kfunc. If the rcu > protection is guaranteed, we would let st->type =3D PTR_TO_STACK | MEM_RC= U. > Once user do rcu_unlock during the iteration, state MEM_RCU of regs would > be cleared. is_iter_reg_valid_init() will reject if reg->type is UNTRUSTE= D. > > It is worth noting that currently, bpf_rcu_read_unlock does not > clear the state of the STACK_ITER reg, since bpf_for_each_spilled_reg > only considers STACK_SPILL. This patch also let bpf_for_each_spilled_reg > search STACK_ITER. > > Signed-off-by: Chuyi Zhou > --- > include/linux/bpf_verifier.h | 19 ++++++++------ > include/linux/btf.h | 1 + > kernel/bpf/helpers.c | 4 +-- > kernel/bpf/verifier.c | 50 ++++++++++++++++++++++++++++-------- > 4 files changed, 53 insertions(+), 21 deletions(-) > LGTM. Acked-by: Andrii Nakryiko