Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp931148pxb; Fri, 22 Apr 2022 14:39:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz2FYGlxOGOaQR27dX1O9zBj8MqNULtKxRW8+FBm/1LTm9K3hsWbMBS4lZqA4A2jlokTotC X-Received: by 2002:a17:90b:1644:b0:1d2:98ef:bd4f with SMTP id il4-20020a17090b164400b001d298efbd4fmr18493987pjb.228.1650663544323; Fri, 22 Apr 2022 14:39:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650663544; cv=none; d=google.com; s=arc-20160816; b=ZOAOxDzGUPeckFYvOEwBxRT+qOdVFSHZsyByl8uGRaOdHD9mKzgWPa8/IfG7yoOipn 8yEi8LZdM4sfoZUi6I41GDiRKiqpvix5CowcWoukfaJT3fLRamjVUIUyVYi95JoMmfJC P3DaANptwM6XtZKUleeDsBbVf4cW5fE8qfBKTL1enOUAWQg6RC+Cy/Tlg2C763JjOQuz /aMVPL2M0oD/ekUUVUbfurHiggbpyVRF2MfI+UsEhaA7zbajmCK9BGRtmai4mBrdNdtM iwMaoT8+/XCvWwLanK3HHcJOOFfISY7EXpERPy5Wq7feRLmszS6mNlFcK3njc/TNytw8 f2Kg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=Nl/sxTqX3tPVuNmSVZ0W9Oabdpfd0rG/HOuhpDMx8IU=; b=JYD/cz/tU84JOY2vB104uFt/GiswouBgrgu19TKVTH7JuUdHEbgQgVQ5jvndwRq2E4 CGZQcCOPMViar1ZYZZjbkw0Tu6AF30c93D0FOs4rsS/pewhV2yB2HpFF8K7kzOhkV0Q8 5vQn+EJtsncn638+xMCfQO59XgzJo/83N5AXsigLaEGVxRjBK7lsGFjc7XF9NuPFTYyh L9PqFYnaLtycGcvq7TRicN4pItUtdL4RBD0EZjj1UBfP6lRaHJMtVYultBD3LMG6PHzy rGjkggKzBZghM2BCnGiFGVrgJxF0zzOD3zLbWRZLQq70oNmUmmG7VSnJhVwWqxTwt3cr EMQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=SGD9XjL1; 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 Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id f5-20020a17090a654500b001d20ca072f6si11737036pjs.134.2022.04.22.14.39.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 14:39:04 -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=@linux-foundation.org header.s=google header.b=SGD9XjL1; 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E0A2F30C8A0; Fri, 22 Apr 2022 12:46:26 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442101AbiDUVh7 (ORCPT + 99 others); Thu, 21 Apr 2022 17:37:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231443AbiDUVh7 (ORCPT ); Thu, 21 Apr 2022 17:37:59 -0400 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29E0B3EA85 for ; Thu, 21 Apr 2022 14:35:08 -0700 (PDT) Received: by mail-ed1-x52b.google.com with SMTP id 21so8161182edv.1 for ; Thu, 21 Apr 2022 14:35:08 -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=Aep8XzOw8F0cVQuJcJe7pBtv4wD136Oz/57fQgRp9psglvhlqmMBUcwNr6XrVzFgqk k+4ygmg9N7VASkabP8XImqVu8SnGHsjbjGChTVVLEhxfbhLGn0AFxkux0+I1LpS8LzlZ b+0ditF9bYxR8GIYQkeu/MTGBcuBVURwFuGmct4A0qbIO+ZL3Yc5NTeHMUyU6OoNcg3I x/kRRBlsmisC9fSFSiU38PPU7/OUlx5IrWmrzJOIVM29PDOnrMB8kk0l8elO45Smn75W u5g2kdjF3rsgsiBxWvSsu7MF5jG16tNE0vwkkdWqfKAAEFFUq6DRjCVNVpK9ft2bIEPY cImA== X-Gm-Message-State: AOAM531TLp7IDdyv+yMzd6g9MRh6WMOleuMywojR/gFlHXwSBmJO3NYs 3ec3zlP04o/QytsdDCmtFjI/Xkf/zQrEMaIZwZU= X-Received: by 2002:aa7:d311:0:b0:423:e539:8581 with SMTP id p17-20020aa7d311000000b00423e5398581mr1576439edq.111.1650576906446; Thu, 21 Apr 2022 14:35:06 -0700 (PDT) Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com. [209.85.221.43]) by smtp.gmail.com with ESMTPSA id t4-20020a1709067c0400b006ef810aab6fsm69301ejo.213.2022.04.21.14.34.50 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 21 Apr 2022 14:34:51 -0700 (PDT) Received: by mail-wr1-f43.google.com with SMTP id u3so8414913wrg.3 for ; Thu, 21 Apr 2022 14:34:50 -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-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE 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 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