Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp950249pxb; Fri, 22 Apr 2022 15:08:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxo7eQ7FKY/b1llc3Q+cg4bky2tfKxjVfmkhgw0E3G2SSdwIv2GaNKoBAilM5Egavu1VA25 X-Received: by 2002:a63:9043:0:b0:3aa:edc4:af96 with SMTP id a64-20020a639043000000b003aaedc4af96mr1040687pge.36.1650665302372; Fri, 22 Apr 2022 15:08:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650665302; cv=none; d=google.com; s=arc-20160816; b=ZItM7sijEY/0exborhEgykiVojfOo0t5mAebOHrpz9BgcOK8R3zgCaCgnrIfoC6riu ajx2xVdQbq4JSSfwyy32NxVfTJ6hZE/sEGSd55E6//ED+CjrYS0ZCH/Y3yBBQxYOKql3 S5FzSr5RWsF9kbT76q/PfVpDfkzvD14nTKXh8r9zfFqSXOQ4sd0nBYxvs77WFW4xO6Sr ftikgG0RmU41RKuWUZzRO89tS4ofS5+QPIY/7rkaNKxdshHEViNWxFyPoVMDpLBBnmxP xQnprugJmNdwbVFyYVsA7p1vYQ00cyz+s6s/vPUn3ktFNxrUX+xj/WSRMhK0NyP4vTfk tu5A== 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=+9cAYvb1fajnuuWroVGBAQg2SyMPi+ao+icYUcRJyvU=; b=I3b1hEg5G3E93pHN1gUndzaw2Qsvzw9y962pTJGasJwU+UW/SfG5151Ws41FfBgkQy +6rMGsyREY2exnyzRz214EXI6yqEvM39GsHV04eEj+GZhwxWzyP6kJDS/7g/wBjxnxPz QDGfQzcdNWWzwejwVf4RU+wPyvrAcumygkibD4OgtEJ8RN3I/YtMoanP7gguNOlK0EQr 6oCGbGnHdGknzj0AlTRNSwfsc0e8kEaCSWDAQEE2/bjqLJjzbU1pTxRsL3S6cFDpkH2i /udJeuZmLR1NIOdh5fFqbzt7c5EwJpZopEudKeH1qBOtIEOW5RL5XmMSnyT0b7QeJch0 YxOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=GN446Qiv; 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 pl17-20020a17090b269100b001d7eae3307bsi3182777pjb.40.2022.04.22.15.08.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 15:08:22 -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=GN446Qiv; 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 CA4F438E9EA; Fri, 22 Apr 2022 13:14:44 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442482AbiDUWdl (ORCPT + 99 others); Thu, 21 Apr 2022 18:33:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1442479AbiDUWdi (ORCPT ); Thu, 21 Apr 2022 18:33:38 -0400 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A87C3A739 for ; Thu, 21 Apr 2022 15:30:47 -0700 (PDT) Received: by mail-lf1-x132.google.com with SMTP id x33so11161927lfu.1 for ; Thu, 21 Apr 2022 15:30:47 -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:content-transfer-encoding; bh=+9cAYvb1fajnuuWroVGBAQg2SyMPi+ao+icYUcRJyvU=; b=GN446QivH3vBBLm/lBdLdrQsSdaGiQFAOD0yQkse5mbC3iu1rO495JlJwm5qbIfZyk i/nWhcq/hJuvqAnpg/6yVZ4qDSrZwS4DuiJSB9qv1XoAa0u69k5zn6ksqP6ATEQZDK3g JYVFBovhxc1lT2JRbxK3kBBtrE8OgoR0iTq4Q= 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:content-transfer-encoding; bh=+9cAYvb1fajnuuWroVGBAQg2SyMPi+ao+icYUcRJyvU=; b=JA/09jRIwvwKUT6vSrtFmpNKPE07W8kWqjcjaIPH+FGbBfh8v3DRYsjCryAwfjMLT0 XiMj/by1MvG7HDQxkwtovcXTmWU6j/4/BZgicFwsDoUvBBo9HZqBl4DPTLrX88a4KvGz wYhNP0QUZDMaDgXHV53CAVNgN7pzPajJkCpOhRQcXepqC0knHta5v6ebCFsWNl5eVNrm OJ3R/KfN3PNVQlEAtrg7q3xu7zRpTIYWqeESMK/mrsaKbn3INyiH4jLhufunbrJn1jY0 jij4VO2ZFAVwvfGFT4hQrc8TbcMgYj/+UO1YFNMxbEZ5LVGmtVAy4Rk2SAqjqYRlN2qm u3UA== X-Gm-Message-State: AOAM53361NLfCZYQecWbg6Hf2BH4p6vLiNvbnBv2ejgamY+R640qwXbV p7iFfbK2wv8N0FuEh2jX2jAIwZuGGVJqCkmnsho= X-Received: by 2002:a05:6512:3f01:b0:46b:a5ba:3b89 with SMTP id y1-20020a0565123f0100b0046ba5ba3b89mr1101397lfa.28.1650580245707; Thu, 21 Apr 2022 15:30:45 -0700 (PDT) Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com. [209.85.208.172]) by smtp.gmail.com with ESMTPSA id v6-20020a2ea446000000b0024b0abb3984sm17267ljn.134.2022.04.21.15.30.42 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 21 Apr 2022 15:30:43 -0700 (PDT) Received: by mail-lj1-f172.google.com with SMTP id 17so7469703lji.1 for ; Thu, 21 Apr 2022 15:30:42 -0700 (PDT) X-Received: by 2002:a2e:9041:0:b0:24a:ce83:dcb4 with SMTP id n1-20020a2e9041000000b0024ace83dcb4mr1064274ljg.291.1650580242430; Thu, 21 Apr 2022 15:30:42 -0700 (PDT) MIME-Version: 1.0 References: <20220421072212.608884-1-song@kernel.org> <1A4FF473-0988-48BE-9993-0F5E9F0AAC95@fb.com> In-Reply-To: <1A4FF473-0988-48BE-9993-0F5E9F0AAC95@fb.com> From: Linus Torvalds Date: Thu, 21 Apr 2022 15:30:26 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH bpf] bpf: invalidate unused part of bpf_prog_pack To: Song Liu Cc: Song Liu , 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" Content-Transfer-Encoding: quoted-printable 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 2:53 PM Song Liu wrote: > > However, we cannot really use the same function at free time. The > huge page is RO+X at free time, but we are only zeroing out a chunk > of it. So regular memset/memcpy won=E2=80=99t work. Instead, we will need > something like bpf_arch_text_copy(). I actually think bpf_arch_text_copy() is another horribly badly done thing. It seems only implemented on x86 (I'm not sure how anything else is supposed to work, I didn't go look), and there it is horribly badly done, using __text_poke() that does all these magical things just to make it atomic wrt concurrent code execution. None of which is *AT*ALL* relevant for this case, since concurrent code execution simply isn't a thing (and if it were, you would already have lost). And if that wasn't pointless enough, it does all that magic "map the page writably at a different virtual address using poking_addr in poking_mm" and a different address space entirely. All of that is required for REAL KERNEL CODE. But the thing is, for bpf_prog_pack, all of that is just completely pointless and stupid complexity. We already *have* the other non-executable address that is writable: it's the actual pages that got vmalloc'ed. Just use vmalloc_to_page() and it's RIGHT THERE. At which point you just use the same bpf_jit_fill_hole() function, and you're done. In other words, all of this seems excessively stupidly done, for no good reason. It's only making it much too complicated, and just not doing the right thing at all. Linus