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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2E897CCA47C for ; Tue, 12 Jul 2022 08:26:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A8276940055; Tue, 12 Jul 2022 04:26:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A325D940033; Tue, 12 Jul 2022 04:26:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 92123940055; Tue, 12 Jul 2022 04:26:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 83B1D940033 for ; Tue, 12 Jul 2022 04:26:39 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 5753A75C for ; Tue, 12 Jul 2022 08:26:39 +0000 (UTC) X-FDA: 79677766518.01.D134475 Received: from mail-vs1-f42.google.com (mail-vs1-f42.google.com [209.85.217.42]) by imf02.hostedemail.com (Postfix) with ESMTP id E40E78002A for ; Tue, 12 Jul 2022 08:26:38 +0000 (UTC) Received: by mail-vs1-f42.google.com with SMTP id 125so448732vsx.7 for ; Tue, 12 Jul 2022 01:26:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=s0Z4vxArFrtPl1OZaeTk/GWzOczAj8yegl1UmLNk3fA=; b=mgzUm+wL6rBKcHmQIlyKp7WQA4JtH54DKPQDilTeabjFdd4SkIUcH3NiR9R2f4gX1t Ntt4NiUxrku7htqSfrNcx+zyoRKgLatwE6ukBtS2mDw3L0A0PIIIgS5Lnsz0VnYP0t+F aHUaDDiOBtkjvWBJR+wCoZvfpK5kaeZfzjE107ZfgALbY15mnN9TyPmqcZdJINCklecW p5ABuYh0YSG1NvcePpVabJcjleBgbKy0XyUMV7PHT2KCAM/TaN0TheqYeZ/kk7dsOz1G n/6vuFeYExE0oompVOk2jbWtqPpryTorNKlf6ez5lYnckcUBkM28Fph78Tp4KA6ZI9EW vPcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=s0Z4vxArFrtPl1OZaeTk/GWzOczAj8yegl1UmLNk3fA=; b=1ZfMmHOGxNp5bfFXowXFoL/KlP3+s4bpfwFbe0QOoOZ8/AcTJQPxlrIAarDBkXnKo3 QY1aYpBA1z1taJX6qvoOu6QnnuGd2s6w6bV7K2vGCxNl5H/P7i9YN5gcSmkKiNICpqZ6 QDhL251k2oqhW0fjZ3ddCrFtWc2DPSZjSclwc72WTeGamm0pwH5LD6vUJKrXuDFrQWiZ 2nHRIfTmQIVB2lsX+ReQLvsrAp4cGZ8E53f00URu89NGXewBTZP3ap2+Yugcs++vbcyy RPFXam5VblV53WzQ3+qs/f9/U0aC+SZUvtHoAeeuS5KPETfMPVYrhsLTEydRkv9geDLD hNvg== X-Gm-Message-State: AJIora8E7Rhzua/VGyj9uA/bWN7rwPYy3olEp2+/qyl6yBdkBJ7qe2Tn 4CbXgPV45qWbpDB1cvAYHeOa7n3qpzQKiWScFzw= X-Google-Smtp-Source: AGRyM1usqPhc15zIZPmpyOUraReWLoqzvUkw8yv0HyEHextWjJTOxHdOnFhlRU5y5A6vrft1dq+l4vSb41AGKgJ5qUo= X-Received: by 2002:a67:af11:0:b0:357:5b18:d7b9 with SMTP id v17-20020a67af11000000b003575b18d7b9mr3412309vsl.35.1657614398185; Tue, 12 Jul 2022 01:26:38 -0700 (PDT) MIME-Version: 1.0 References: <20220709154457.57379-1-laoar.shao@gmail.com> <20220709154457.57379-3-laoar.shao@gmail.com> <05e5931e-98a7-d7b4-4775-7c17fad57450@fb.com> In-Reply-To: From: Yafang Shao Date: Tue, 12 Jul 2022 16:26:01 +0800 Message-ID: Subject: Re: [PATCH bpf-next v3 2/2] bpf: Warn on non-preallocated case for missed trace types To: Yonghong Song Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin Lau , Song Liu , john fastabend , KP Singh , Quentin Monnet , Roman Gushchin , Hao Luo , Shakeel Butt , bpf , Linux MM Content-Type: text/plain; charset="UTF-8" ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=mgzUm+wL; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf02.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.217.42 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1657614398; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=s0Z4vxArFrtPl1OZaeTk/GWzOczAj8yegl1UmLNk3fA=; b=yvuRukNkmKTfStuDmnUdovlTd3+ugV43QqnSjgR+w9IBGW33fQhwIZQ2nnoN60qff9uKS5 pT9FOFdng27k9GdaUpj+AveRsEMX38gOaosK2UA+Qyu4I36net0+cTcDqBR0BfYZucI5j4 6TVJKOMIYBS/60v62+SiqTq7hIPXPvg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1657614398; a=rsa-sha256; cv=none; b=Nz1RgYKhls4ATjancPQpoP/qeRvHDXlOnddsJS9hiRyMraV3BrDyRlI6yAGsc6GfUde54R vslwsbCnwFcft7Qfc+TxLGMs0RZ+z3sgD17g402c5TyFKS0TFAfkDGNu4GvGvoCh1a8d8m QIng/7e/LHjVZiJ9ypgz67aTq1ZqRv8= X-Rspam-User: Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=mgzUm+wL; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf02.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.217.42 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com X-Stat-Signature: q5gp3bnsrgrqh9upaqdbuqhy875b1z63 X-Rspamd-Queue-Id: E40E78002A X-Rspamd-Server: rspam04 X-HE-Tag: 1657614398-858794 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Jul 12, 2022 at 3:04 AM Yonghong Song wrote: > > > > On 7/10/22 11:48 PM, Yafang Shao wrote: > > On Mon, Jul 11, 2022 at 1:51 AM Yonghong Song wrote: > >> > >> > >> > >> On 7/9/22 8:44 AM, Yafang Shao wrote: > >>> The raw tracepoint may cause unexpected memory allocation if we set > >>> BPF_F_NO_PREALLOC. So let's warn on it. > >> > >> Please extend raw_tracepoint to other attach types which > >> may cause runtime map allocations. > >> > > > > Per my understanding, it is safe to allocate memory in a non-process > > context as long as we don't allow blocking it. > > So this issue doesn't matter with whether it causes runtime map > > allocations or not, while it really matters with the tracepoint or > > kprobe. > > Regarding the tracepoint or kprobe, if we don't use non-preallocated > > maps, it may allocate other extra memory besides the map element > > itself. > > I have verified that it is safe to use non-preallocated maps in > > BPF_TRACE_ITER or BPF_TRACE_FENTRY. > > So filtering out BPF_TRACE_RAW_TP only is enough. > > >>> > >>> Signed-off-by: Yafang Shao > >>> --- > >>> kernel/bpf/verifier.c | 18 +++++++++++++----- > >>> 1 file changed, 13 insertions(+), 5 deletions(-) > >>> > >>> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c > >>> index e3cf6194c24f..3cd8260827e0 100644 > >>> --- a/kernel/bpf/verifier.c > >>> +++ b/kernel/bpf/verifier.c > >>> @@ -12574,14 +12574,20 @@ static int check_map_prealloc(struct bpf_map *map) > >>> !(map->map_flags & BPF_F_NO_PREALLOC); > >>> } > >>> > >>> -static bool is_tracing_prog_type(enum bpf_prog_type type) > >>> +static bool is_tracing_prog_type(enum bpf_prog_type prog_type, > >>> + enum bpf_attach_type attach_type) > >>> { > >>> - switch (type) { > >>> + switch (prog_type) { > >>> case BPF_PROG_TYPE_KPROBE: > >>> case BPF_PROG_TYPE_TRACEPOINT: > >>> case BPF_PROG_TYPE_PERF_EVENT: > >>> case BPF_PROG_TYPE_RAW_TRACEPOINT: > >>> + case BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE: > >>> return true; > >>> + case BPF_PROG_TYPE_TRACING: > >>> + if (attach_type == BPF_TRACE_RAW_TP) > >>> + return true; > >> > >> As Alexei mentioned earlier, here we should have > >> if (attach_type != BPF_TRACE_ITER) > >> return true; > > > > That will break selftests/bpf/progs/timer.c, because it uses timer in fentry. > > Okay. Let us remove BPF_PROG_TYPE_TRACING from this patch for now. > fentry/fexit/fmod may attach any kallsyms functions and many of them > are called in process context and non-preallocated hashmap totally fine. > It is not good to prohibit non-preallocated hashmap for any > fentry/fexit/fmod bpf programs. > Got it. I will do it. -- Regards Yafang