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 A95D7C433F5 for ; Thu, 21 Apr 2022 21:36:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0CC316B0072; Thu, 21 Apr 2022 17:36:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 07E1A6B0073; Thu, 21 Apr 2022 17:36:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E362D6B0074; Thu, 21 Apr 2022 17:36:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.a.hostedemail.com [64.99.140.24]) by kanga.kvack.org (Postfix) with ESMTP id D52BA6B0072 for ; Thu, 21 Apr 2022 17:36:14 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id A8EE2232E1 for ; Thu, 21 Apr 2022 21:36:14 +0000 (UTC) X-FDA: 79382194668.18.46E20F3 Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) by imf19.hostedemail.com (Postfix) with ESMTP id 0B32C1A001A for ; Thu, 21 Apr 2022 21:36:11 +0000 (UTC) Received: by mail-ed1-f49.google.com with SMTP id z99so8145743ede.5 for ; Thu, 21 Apr 2022 14:36:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Nl/sxTqX3tPVuNmSVZ0W9Oabdpfd0rG/HOuhpDMx8IU=; b=SGD9XjL10rEx9mfSetxfZDlzHyWhah/RqUC1yuJDs6G0kwXr3WaCGrlxPbDhZrektk vMEv5vROGWM1yTs+l7MxtDylQphutpR87FxU5d1udkQrNd3uJmHojGgHG1MGJot8wiAh JNzYAMieKMZP8RTasxN1p6T3tb37MEirFAfFE= 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=Nl/sxTqX3tPVuNmSVZ0W9Oabdpfd0rG/HOuhpDMx8IU=; b=4apsFk4+KLUrUpk+3ywgtKM5ynKLk+iFRWyREfrsoKOBs106Ht2/iULduR3i6C+g5M VBWOOou65hNpZMp8iMSMnqsNtFANBRDX5FGh5Y3IWN+o9R4bKOBg59TVIo8gfSfaoIrR Ep4bzf2cy7w0EufD3UUGNaKUHKI3p33VYx3kAcgjlH5MuBxHXFfh2h6P2//URABKD7cg qNopDdcEznJ5kFKLEj1kYLWLjKzofDSYfszNw/5MMU1isMvhR/5COIlYbKGkYgRkitdU AettLtIvCuEuU2RcVKtXXjL82dA6OQ1H9mKNHOeTqyIWQ/BivT0e0Fn0saefrHOLna1U 24yQ== X-Gm-Message-State: AOAM530H28IC10lHFJteUypLo7r2i7jfWBHbsW+1TeeZkSIAnggCA1oM Ax3Uv/9FpmAkO05EA68OJpcTFiAZbnfZUVn94qY= X-Google-Smtp-Source: ABdhPJxgNagdmpWkiaaW2Iwb/HdogCsPoCyJ7Y8wj3ynpoHHNo0rWNJ4DCrUmFZ53kAOBHX+f8Wtww== X-Received: by 2002:a05:6402:5d4:b0:424:e64b:36a5 with SMTP id n20-20020a05640205d400b00424e64b36a5mr1617992edx.23.1650576972483; Thu, 21 Apr 2022 14:36:12 -0700 (PDT) Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com. [209.85.208.41]) by smtp.gmail.com with ESMTPSA id kw3-20020a170907770300b006d2a835ac33sm69950ejc.197.2022.04.21.14.35.26 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 21 Apr 2022 14:35:54 -0700 (PDT) Received: by mail-ed1-f41.google.com with SMTP id e30so4622842eda.0 for ; Thu, 21 Apr 2022 14:35:26 -0700 (PDT) X-Received: by 2002:a05:6512:108b:b0:470:90b9:fb51 with SMTP id j11-20020a056512108b00b0047090b9fb51mr927158lfg.52.1650576516819; Thu, 21 Apr 2022 14:28:36 -0700 (PDT) MIME-Version: 1.0 References: <20220421072212.608884-1-song@kernel.org> In-Reply-To: From: Linus Torvalds Date: Thu, 21 Apr 2022 14:28:20 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH bpf] bpf: invalidate unused part of bpf_prog_pack To: Song Liu Cc: Alexei Starovoitov , bpf , Linux-MM , Linux Kernel Mailing List , Alexei Starovoitov , Daniel Borkmann , Kernel Team , Andrew Morton , "Edgecombe, Rick P" , Christoph Hellwig , Andrii Nakryiko Content-Type: text/plain; charset="UTF-8" X-Rspam-User: X-Rspamd-Queue-Id: 0B32C1A001A X-Stat-Signature: mmky65oqr7u8darfuufik1zxjo8m4je6 Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=google header.b=SGD9XjL1; spf=pass (imf19.hostedemail.com: domain of torvalds@linuxfoundation.org designates 209.85.208.49 as permitted sender) smtp.mailfrom=torvalds@linuxfoundation.org; dmarc=none X-Rspamd-Server: rspam01 X-HE-Tag: 1650576971-953967 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 Thu, Apr 21, 2022 at 12:41 PM Song Liu wrote: > > The extra logic I had in the original patch was to erase the memory > when a BPF program is freed. In this case, the memory will be > returned to the bpf_prog_pack, and stays as RO+X. Actually, I > am not quite sure whether we need this logic. If not, we only need > the much simpler version. Oh, I think it would be good to do at free time too. I just would want that to use the same function we already have for the allocation-time thing, instead of introducing completely new infrastructure. That was what looked very odd to me. Now, the _smallest_ patch would likely be to just save away that 'bpf_fill_ill_insns' function pointer in the 'struct bpf_prog_pack' thing. It's admittedly kind of silly to do, but it matches that whole silly "let's pass around a function pointer to a fixed function" model at allocation time. I say that's silly, because it's a fixed architecture function and we could just call it directly. The only valid function there is jit_fill_hole(), and the only reason it uses that function pointer seems to be that it's never been exposed as a real function. So passing it along as a function seems to be _purely_ for the silly reason that people haven't agreed on a name, and different architectures use different names (ie power uses 'bpf_jit_fill_ill_insns()', RISC-V calls it 'bpf_fill_ill_insns()', and everybody else seems to use 'jit_fill_hole'. I don't know why that decision was made. It looks like a bad one to me, honestly. Why not just agree on a name - I suggest 'bpf_jit_fill_hole()' - and just get rid of that stupid 'bpf_jit_fill_hole_t' type name that only exists because of this thing? The bpf headers seem to literally have agreed on a name for that function -type- only in order to be able to disagree on the name of the function -name-, and then pass it along as a function pointer argument instead of just calling it directly. Very counter-productive. Linus