Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp6852017rwd; Mon, 19 Jun 2023 13:34:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7MMXx7x6NmJxndHRYi8ZDIXGRQT55kkwgUrXyoH/g4eh6N95omC95CSi+nNRC8JeREXs7p X-Received: by 2002:a05:6a00:1804:b0:667:e17e:85bc with SMTP id y4-20020a056a00180400b00667e17e85bcmr11136952pfa.0.1687206844242; Mon, 19 Jun 2023 13:34:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687206844; cv=none; d=google.com; s=arc-20160816; b=RnJ2PfPUvUVPsZiGG/nLt0BeZLLSBoGArxKPXSqAEQZxTFTa7Q16x7ODmFmSGALhKH PMDxOGytv34gnv3WdY0/odOxUJHSGVxE4UAdZx3PnqlyLpeNJNvxXT+0tvxpAmv1jINx kmIs2JTlrwoAQcPNNf5K1MkBkkUPFxFE28fiAyuTg0jmo8PVBy/nsyLgJrDCfgcWSAwF PblXPHWZCGx2pI8RPg7WG2RaZYaV3i9NED5diY+Ji+SU+6MrOpjqViW9QTNTWVORpI8V ODimpRrThvaAYlyBh0XA//bnzZbJ8YpY3EzSH7uDL0uEwy+ARW6wPOvVcE5ijZdLB8nm ev5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version:dkim-signature; bh=UmEEut0OCJI0jheFei8v4KFIgPFEx+9Zr0oYZPTVJvw=; b=ln1IDOzKZIyHb8yGYn53aAwQvsPbKxe18miz6KBPafMPlHA8BQjfz2eVghydSBAbbQ YK7KbspbfN+OdOsUFltsdHKLo1Ia5bbnN6rMdE8v/Z1xoNMX00zojyR7V5uC1VKbjtX4 HCjtA6SD0yB/y8mlHKZRDMEZWaGNkxHD2rdcfw99pM9inYDrTxySGMe3F2XtpIs4xmbH IfxsKR310cqVaJWfWWpLxSAyIbh1Znys3Jne+1edno9cLkXvp9kAyIU1Y7k3sD3DD97X 5i6g5jrhEbHkZ/xWy360yzFy/H4Cjw96bRHJPU2jOR0KGvAjoN6UCXsHke8LByDsmVKt JgPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=ML1POuSF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q11-20020aa7842b000000b006436618b22bsi205961pfn.155.2023.06.19.13.33.51; Mon, 19 Jun 2023 13:34:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=ML1POuSF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230245AbjFSUSj (ORCPT + 99 others); Mon, 19 Jun 2023 16:18:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230187AbjFSUSc (ORCPT ); Mon, 19 Jun 2023 16:18:32 -0400 Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45A8FD3; Mon, 19 Jun 2023 13:18:30 -0700 (PDT) Received: by mail-pg1-x52d.google.com with SMTP id 41be03b00d2f7-53fbf2c42bfso3185177a12.3; Mon, 19 Jun 2023 13:18:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687205909; x=1689797909; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=UmEEut0OCJI0jheFei8v4KFIgPFEx+9Zr0oYZPTVJvw=; b=ML1POuSF5TNYpNiqkU7Wmm/FZLBDFoP32DY+WPylpmv43DoaA/AoXnTGG2wwzhld3j kjkKToRZCKl1S0ycKV+IUNrHAQ8Dvck3h+D7ZuCxy/PFvkOP44vPViwvWsYYl0BBuNgy b/5HPeUCxmK/jPGro6a0V6gtwlQJxSWG+MjbaRDV7mR48t508gCxLWi7cw8WSlTAdLEO 3p+win9LgLE5lOsK+rw7eJ7na0iRAHUh7i2pWPNrn0k/YllS2kfgOgB31VmT4hCseChr k2Wm+WLNvD9nhPcsjkRc0OVcXyGOSUiyWGCOpqitL1ReK2kli6NusXAAxFAtCrHDui7k NzgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687205909; x=1689797909; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UmEEut0OCJI0jheFei8v4KFIgPFEx+9Zr0oYZPTVJvw=; b=It+aTU9JCM2y7jL4p7lJlCjfG6o20JcbSLehxu66Jm7q+BrmhwyasusDO7rtoEYi0K NQC42j8tDLAiznlhd9DM+8ji0LNBcwmYv4s6Wd5EYYYOgs2BLMp/9JZJf2MEorJpzz15 qYBYq6EcyQwBh68GSgejoX8hbxuwkwUmA5iFIiIo+L9ktPqpHDfCefrQVFH4t5HymodN VMMjSjzQrvwLpQnZk3AFvwIDid3Ym95fETh/4F/BAzBwmlRgfZ+IRx6cYR0NX/uJMgC3 VRJi8WxiHl5cSH+u4ZFuCqDwUL4XbrpqAshCkqXHXDL3mBanL547g8fkomBST3m8drWn PKRw== X-Gm-Message-State: AC+VfDxw8bplcNLipbtq/ZaFPEuPUKARHC4Hn+6fqHRohKEldkAiOKiB LaBTrPeAOLr9MLpyTpcTXXM= X-Received: by 2002:a05:6a21:78a9:b0:10a:cb95:5aa3 with SMTP id bf41-20020a056a2178a900b0010acb955aa3mr14231287pzc.7.1687205909086; Mon, 19 Jun 2023 13:18:29 -0700 (PDT) Received: from smtpclient.apple ([66.170.99.1]) by smtp.gmail.com with ESMTPSA id k18-20020a637b52000000b005538bf7e3d6sm87568pgn.88.2023.06.19.13.18.26 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Jun 2023 13:18:28 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.600.7\)) Subject: Re: [PATCH v2 02/12] mm: introduce execmem_text_alloc() and jit_text_alloc() From: Nadav Amit In-Reply-To: Date: Mon, 19 Jun 2023 13:18:15 -0700 Cc: Mike Rapoport , Mark Rutland , Kees Cook , Linux Kernel Mailing List , Andrew Morton , Catalin Marinas , Christophe Leroy , "David S. Miller" , Dinh Nguyen , Heiko Carstens , Helge Deller , Huacai Chen , Kent Overstreet , Luis Chamberlain , Michael Ellerman , "Naveen N. Rao" , Palmer Dabbelt , Puranjay Mohan , Rick P Edgecombe , "Russell King (Oracle)" , Steven Rostedt , Thomas Bogendoerfer , Thomas Gleixner , Will Deacon , bpf , linux-arm-kernel@lists.infradead.org, linux-mips@vger.kernel.org, linux-mm , linux-modules@vger.kernel.org, linux-parisc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-s390 , linux-trace-kernel@vger.kernel.org, linuxppc-dev , loongarch@lists.linux.dev, netdev@vger.kernel.org, sparclinux@vger.kernel.org, the arch/x86 maintainers Content-Transfer-Encoding: quoted-printable Message-Id: <7F566E60-C371-449B-992B-0C435AD6016B@gmail.com> References: <20230616085038.4121892-1-rppt@kernel.org> <20230616085038.4121892-3-rppt@kernel.org> <20230618080027.GA52412@kernel.org> To: Andy Lutomirski , Song Liu X-Mailer: Apple Mail (2.3731.600.7) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 Jun 19, 2023, at 10:09 AM, Andy Lutomirski wrote: >=20 > But jit_text_alloc() can't do this, because the order of operations = doesn't match. With jit_text_alloc(), the executable mapping shows up = before the text is populated, so there is no atomic change from = not-there to populated-and-executable. Which means that there is an = opportunity for CPUs, speculatively or otherwise, to start filling = various caches with intermediate states of the text, which means that = various architectures (even x86!) may need serialization. >=20 > For eBPF- and module- like use cases, where JITting/code gen is quite = coarse-grained, perhaps something vaguely like: >=20 > jit_text_alloc() -> returns a handle and an executable virtual = address, but does *not* map it there > jit_text_write() -> write to that handle > jit_text_map() -> map it and synchronize if needed (no sync needed on = x86, I think) Andy, would you mind explaining why you think a sync is not needed? I = mean I have a =E2=80=9Cfeeling=E2=80=9D that perhaps TSO can guarantee = something based on the order of write and page-table update. Is that the = argument? On this regard, one thing that I clearly do not understand is why = *today* it is ok for users of bpf_arch_text_copy() not to call = text_poke_sync(). Am I missing something?