Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp777589lqt; Fri, 19 Apr 2024 10:04:00 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXdsfhojgNxhA0pgZYRzMwbmKrZGAUKRz6jCHULPzxgpu/IyUjtZPeR47Kcte5ffdTKqz0SKa9T8L68UrjVOLBkC/SKXFcy18+8jHULaA== X-Google-Smtp-Source: AGHT+IH42ZWGNtVY5JGBMtSskryFCTSdD0Q+aEYLc1/w1iIrOxhkGvVxc+gRsB3DKHbILKBmw4vX X-Received: by 2002:a17:90a:d704:b0:2a2:b308:1371 with SMTP id y4-20020a17090ad70400b002a2b3081371mr2859107pju.43.1713546240635; Fri, 19 Apr 2024 10:04:00 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713546240; cv=pass; d=google.com; s=arc-20160816; b=tlfu2xs0kcwVipr6vWpiX2JUE4VTrCe/XX8/54tWyQBapxmxuvSe+MHIhGtJ3pQmDx +UP55KFbwmmSp34ZJzZdguJKM5YIFW6dNLHkF6Jg90ugi17E0um2dYz+B9+4wQuIyjES Vjq1FDduMlHtHax9r5xs+hladBa2EV5lEShk3t199SJ0KxlMgjWacqd6pxfXqmI1pE7e AzMeV+Jg9wEjnMctG7nW0MpENOBMxCUykfKdYZ4skrYGlzR++CRKbLRaZA3p1Fsy5LFc 9UU728yXBoticWrl9IWbvty1Wb/Eu05SPBcW2wzc0Wwqak+YgRu+SU7MjkomXU3ITXMG Z8Rg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=44xV6d58ZNpw3J5Ed8XtYHaQPh5X7ILHToSXrtCi6o8=; fh=7CWc0oMXKDuCd1dK8m8iSHqZvuyVE5zY2SjGNC+50Rw=; b=rj+8I1jclNbKKxu8Awje6UyGjYrkd/6fndU1HBMqwFW9A+4/aLCxPrbyCiMZQly7Aj 7QNB8ovui+Xm5GK2kaO1+5xgSIv+jglJrwK3g9rX0ZYOAuRPtsE+0MkR7ejw0ta2Poc6 evOd/E7supuDGeBKCN/UW/jwK4FQUy5Ar85BrtBVSs3D+73PuV3LEJilIyy8ExwpcEqE sHe8ZuQvkWefksS90CZPEArF6PKioBGmmGlsYMXGuqp1rdHOF3RQUnI3/fxIiv8gSbL6 Z6zH+rijD2h2F78C5wyuEZTmtehSxO1wAUVPVDBhYzzmnqYifAruTisoRxEBdgh4cwdO TS+w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RUL9Opqg; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-151803-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151803-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d16-20020a17090ab31000b002abd8a0e651si3299015pjr.96.2024.04.19.10.04.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 10:04:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-151803-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RUL9Opqg; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-151803-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151803-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 4E4B4282591 for ; Fri, 19 Apr 2024 17:03:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6E4DD13AD08; Fri, 19 Apr 2024 17:03:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="RUL9Opqg" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4608712FB05; Fri, 19 Apr 2024 17:03:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713546219; cv=none; b=nsMz7ChFXQUquMH/1LJKq3fciYWxhRA0ojHrmOV2zgTnLwgDSI0uP3hI7whCDzM4lKcWELNsxkiG1+OSwAe9W2bB2tcaIZ3x1bAP9WILtbK3eH43ra+5gZZcbmjef9ZEjunkP+6Yr4ESfrCzPz0zhhRmFW47WgGlxNBIr4aoa34= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713546219; c=relaxed/simple; bh=jFxi5qZrScF2xjH3z+fMU0rA+S3WPw/R5/k/PlfLlD4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=M4ek9+vpT8JzKWf48sYDBD4TxWUGYKv1hvrhUh3Nxip5z2b4Fob52CcB8CoHsXPt/W9HDsthfVmv2LjwHOndiQcFEbyBDywszlnNn/inRk2Nv3mrWehTUbqJpLdaW7CA7ZT0ICC3p1ge+5Moq7+VQFeIAPBt3ijBXdevda2RjWA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RUL9Opqg; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 20D36C3277B; Fri, 19 Apr 2024 17:03:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713546218; bh=jFxi5qZrScF2xjH3z+fMU0rA+S3WPw/R5/k/PlfLlD4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=RUL9Opqg9lVQKyIEyIuq2xjKwlBEmIHBH/IVoveA6aP2JLQi0uzPvTDRn7OmSzfgD nIb4g/5o2RBtfUp3FCsBZLo4UMhQBN8itmVTPuHB1vCt7tnCtqGOlM7w17hYv3aiWy FPRpIYW/h0QBF2/1gYcg2KSSl6cBIyHw8P1BRp78GQ/1rnAZNqj1HgINRQQE2y6kx8 pa/lP0BVFbrI+oqwHSJpzLJUH1OONwzfgc8jyKWmKgwbnoS/jGKAA+PE+NrL1eKBBr VPLO+D3Fy9QluAkUMgIaLcYTb9+hJ5Az7wIHrpBlSplLPGXqXzT9s0UFhk3C1grs7n akOPXTz5YdCXA== Date: Fri, 19 Apr 2024 20:02:17 +0300 From: Mike Rapoport To: Song Liu Cc: Mark Rutland , Peter Zijlstra , linux-kernel@vger.kernel.org, Alexandre Ghiti , Andrew Morton , Bjorn Topel , Catalin Marinas , Christophe Leroy , "David S. Miller" , Dinh Nguyen , Donald Dutile , Eric Chanudet , Heiko Carstens , Helge Deller , Huacai Chen , Kent Overstreet , Luis Chamberlain , Michael Ellerman , Nadav Amit , Palmer Dabbelt , Puranjay Mohan , Rick Edgecombe , Russell King , Steven Rostedt , Thomas Bogendoerfer , Thomas Gleixner , Will Deacon , bpf@vger.kernel.org, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mips@vger.kernel.org, linux-mm@kvack.org, linux-modules@vger.kernel.org, linux-parisc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, loongarch@lists.linux.dev, netdev@vger.kernel.org, sparclinux@vger.kernel.org, x86@kernel.org Subject: Re: [PATCH v4 05/15] mm: introduce execmem_alloc() and execmem_free() Message-ID: References: <20240415075241.GF40213@noisy.programming.kicks-ass.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Fri, Apr 19, 2024 at 08:54:40AM -0700, Song Liu wrote: > On Thu, Apr 18, 2024 at 11:56 PM Mike Rapoport wrote: > > > > On Thu, Apr 18, 2024 at 02:01:22PM -0700, Song Liu wrote: > > > On Thu, Apr 18, 2024 at 10:54 AM Mike Rapoport wrote: > > > > > > > > On Thu, Apr 18, 2024 at 09:13:27AM -0700, Song Liu wrote: > > > > > On Thu, Apr 18, 2024 at 8:37 AM Mike Rapoport wrote: > > > > > > > > > > > > > > > > I'm looking at execmem_types more as definition of the consumers, maybe I > > > > > > > > should have named the enum execmem_consumer at the first place. > > > > > > > > > > > > > > I think looking at execmem_type from consumers' point of view adds > > > > > > > unnecessary complexity. IIUC, for most (if not all) archs, ftrace, kprobe, > > > > > > > and bpf (and maybe also module text) all have the same requirements. > > > > > > > Did I miss something? > > > > > > > > > > > > It's enough to have one architecture with different constrains for kprobes > > > > > > and bpf to warrant a type for each. > > > > > > > > > > AFAICT, some of these constraints can be changed without too much work. > > > > > > > > But why? > > > > I honestly don't understand what are you trying to optimize here. A few > > > > lines of initialization in execmem_info? > > > > > > IIUC, having separate EXECMEM_BPF and EXECMEM_KPROBE makes it > > > harder for bpf and kprobe to share the same ROX page. In many use cases, > > > a 2MiB page (assuming x86_64) is enough for all BPF, kprobe, ftrace, and > > > module text. It is not efficient if we have to allocate separate pages for each > > > of these use cases. If this is not a problem, the current approach works. > > > > The caching of large ROX pages does not need to be per type. > > > > In the POC I've posted for caching of large ROX pages on x86 [1], the cache is > > global and to make kprobes and bpf use it it's enough to set a flag in > > execmem_info. > > > > [1] https://lore.kernel.org/all/20240411160526.2093408-1-rppt@kernel.org > > For the ROX to work, we need different users (module text, kprobe, etc.) to have > the same execmem_range. From [1]: > > static void *execmem_cache_alloc(struct execmem_range *range, size_t size) > { > ... > p = __execmem_cache_alloc(size); > if (p) > return p; > err = execmem_cache_populate(range, size); > ... > } > > We are calling __execmem_cache_alloc() without range. For this to work, > we can only call execmem_cache_alloc() with one execmem_range. Actually, on x86 this will "just work" because everything shares the same address space :) The 2M pages in the cache will be in the modules space, so __execmem_cache_alloc() will always return memory from that address space. For other architectures this indeed needs to be fixed with passing the range to __execmem_cache_alloc() and limiting search in the cache for that range. > Did I miss something? > > Thanks, > Song -- Sincerely yours, Mike.