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 AB882C4332F for ; Wed, 9 Nov 2022 17:44:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EF9A38E0001; Wed, 9 Nov 2022 12:44:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EA9C56B0073; Wed, 9 Nov 2022 12:44:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D71868E0001; Wed, 9 Nov 2022 12:44:07 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id C58E46B0072 for ; Wed, 9 Nov 2022 12:44:07 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 8DAC9807F7 for ; Wed, 9 Nov 2022 17:44:07 +0000 (UTC) X-FDA: 80114627334.24.C337E76 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf09.hostedemail.com (Postfix) with ESMTP id E4DFA140009 for ; Wed, 9 Nov 2022 17:44:06 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 3F1ECB81F4E for ; Wed, 9 Nov 2022 17:44:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EDC4BC433B5 for ; Wed, 9 Nov 2022 17:44:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668015844; bh=YMzmrAedbSqr4FpBqUaZNR2kutN3dEnWCq4xXQKIWcs=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=BSouoPnDRR06KzUFrjeQ3NIJUC+gFQnC/0npZ6nOwdZaby3XPQKwmN/NgXTopTfHI OVfUKMB5nwhCDicJ3W+FBuC83ktFczkn5fUja3OF2+bvqw6aihY+A8gsCNS4jSWIHb oFziW2cMuO2zCRTodotnLmTix4gbxqlzNy113EwLeirTRswan41yr5DI+SpLSa8PSA 7k0RkOnhMgcVQ6pHLq2M31kp3O5lQOgI9nqgrrPkEjgLt/jU42ImAL2IdziZrZhkcX 7JFn8My+kQRE/UmejMIikdqbywTw9U3dJJZxymdcms8fYnpILhD9QlP1+ZsCSqd4w1 qYKIdelkPIS+g== Received: by mail-ed1-f45.google.com with SMTP id x2so28257236edd.2 for ; Wed, 09 Nov 2022 09:44:03 -0800 (PST) X-Gm-Message-State: ACrzQf1vpdp0+iDUMwoiIzaCekLYoKNVuIV8fGf+4NgM5Qs1Lfx9DKh7 H/M/wbO8xXX/8Wm5Dj+ZQ7Ax/GUtVnnmMQljgb8= X-Google-Smtp-Source: AMsMyM78ijxOhQbiLUny5ISRpGvb9wiT05BlGR2qEdvUFRz6YZ7Abe6OxRYAycARUL8aLeX1NPW3NOy7cYa3cpjGOzg= X-Received: by 2002:aa7:d710:0:b0:463:bd7b:2b44 with SMTP id t16-20020aa7d710000000b00463bd7b2b44mr44868053edq.385.1668015842120; Wed, 09 Nov 2022 09:44:02 -0800 (PST) MIME-Version: 1.0 References: <20221107223921.3451913-1-song@kernel.org> <9e59a4e8b6f071cf380b9843cdf1e9160f798255.camel@intel.com> In-Reply-To: From: Song Liu Date: Wed, 9 Nov 2022 09:43:50 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH bpf-next v2 0/5] execmem_alloc for BPF programs To: Mike Rapoport Cc: "Edgecombe, Rick P" , "peterz@infradead.org" , "bpf@vger.kernel.org" , "linux-mm@kvack.org" , "hch@lst.de" , "x86@kernel.org" , "akpm@linux-foundation.org" , "mcgrof@kernel.org" , "Lu, Aaron" Content-Type: text/plain; charset="UTF-8" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1668015847; a=rsa-sha256; cv=none; b=E1Bfze7ck3yyIDBpU1tmfd+gFo+BiispZ814L3opMowz2xhqYVvtYrDNhB5IjZSmIji3ba guIzGx0LfIPDWW86L49gqvxexyT6x1L6B8IpF2M4+4CiAqeh4ogwp5gRbzSOyR6YSHOpaG cGbl/mAUljSQ+9VlEIp4f1d2QrNKiqw= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=BSouoPnD; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf09.hostedemail.com: domain of song@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=song@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1668015847; 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=Rdx5PqZudgzHxEDvDSfIWKTfwuHJIFS2CChMEbPtnJs=; b=LHhuMpJF5NY6s66xEh0O9lC2uld2X9OhPEYpZ5dLJYZCZWBEfRlj6D6pA0sYD3RXfvrRYW vJgtVjRl8x0Z404PClWshLn+ZMOj5M+8m/LoGkEB0+uQHsX+ntaA55UyahOxtN84GjXTa9 cKA4PBfJ5p+HbR49d+47PWbNXNr3BbE= Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=BSouoPnD; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf09.hostedemail.com: domain of song@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=song@kernel.org X-Rspam-User: X-Stat-Signature: ofn4w1tkdctm73mhshyp4hpnwruubcjy X-Rspamd-Queue-Id: E4DFA140009 X-Rspamd-Server: rspam05 X-HE-Tag: 1668015846-612465 X-Bogosity: Ham, tests=bogofilter, spamicity=0.001681, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, Nov 9, 2022 at 3:18 AM Mike Rapoport wrote: > [...] > > > > > > The proposed execmem_alloc() looks to me very much tailored for x86 > > > to be > > > used as a replacement for module_alloc(). Some architectures have > > > module_alloc() that is quite different from the default or x86 > > > version, so > > > I'd expect at least some explanation how modules etc can use execmem_ > > > APIs > > > without breaking !x86 architectures. > > > > I think this is fair, but I think we should ask ask ourselves - how > > much should we do in one step? > > I think that at least we need an evidence that execmem_alloc() etc can be > actually used by modules/ftrace/kprobes. Luis said that RFC v2 didn't work > for him at all, so having a core MM API for code allocation that only works > with BPF on x86 seems not right to me. While using execmem_alloc() et. al. in module support is difficult, folks are making progress with it. For example, the prototype would be more difficult before CONFIG_ARCH_WANTS_MODULES_DATA_IN_VMALLOC (introduced by Christophe). We also have other users that we can onboard soon: BPF trampoline on x86_64, BPF jit and trampoline on arm64, and maybe also on powerpc and s390. > > > For non-text_poke() architectures, the way you can make it work is have > > the API look like: > > execmem_alloc() <- Does the allocation, but necessarily usable yet > > execmem_write() <- Loads the mapping, doesn't work after finish() > > execmem_finish() <- Makes the mapping live (loaded, executable, ready) > > > > So for text_poke(): > > execmem_alloc() <- reserves the mapping > > execmem_write() <- text_pokes() to the mapping > > execmem_finish() <- does nothing > > > > And non-text_poke(): > > execmem_alloc() <- Allocates a regular RW vmalloc allocation > > execmem_write() <- Writes normally to it > > execmem_finish() <- does set_memory_ro()/set_memory_x() on it > > > > Non-text_poke() only gets the benefits of centralized logic, but the > > interface works for both. This is pretty much what the perm_alloc() RFC > > did to make it work with other arch's and modules. But to fit with the > > existing modules code (which is actually spread all over) and also > > handle RO sections, it also needed some additional bells and whistles. > > I'm less concerned about non-text_poke() part, but rather about > restrictions where code and data can live on different architectures and > whether these restrictions won't lead to inability to use the centralized > logic on, say, arm64 and powerpc. > > For instance, if we use execmem_alloc() for modules, it means that data > sections should be allocated separately with plain vmalloc(). Will this > work universally? Or this will require special care with additional > complexity in the modules code? > > > So the question I'm trying to ask is, how much should we target for the > > next step? I first thought that this functionality was so intertwined, > > it would be too hard to do iteratively. So if we want to try > > iteratively, I'm ok if it doesn't solve everything. > > With execmem_alloc() as the first step I'm failing to see the large > picture. If we want to use it for modules, how will we allocate RO data? > with similar rodata_alloc() that uses yet another tree in vmalloc? > How the caching of large pages in vmalloc can be made useful for use cases > like secretmem and PKS? If RO data causes problems with direct map fragmentation, we can use similar logic. I think we will need another tree in vmalloc for this case. Since the logic will be mostly identical, I personally don't think adding another tree is a big overhead. Thanks, Song