Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp1047591lqt; Fri, 19 Apr 2024 21:24:27 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWLEqMSP47SYKoc5wggsL8uz3cyyeC3jj+K7PhzsvJ8Z+1YM634XZNuLrkok8neE/qUqjq2JpyIkrgXnYFEGeritaxnvAoeZg8RgBQPPA== X-Google-Smtp-Source: AGHT+IH8QtbgSsmhzNOovmxJTfNkOAkT6crcHu4Ta1XpmhtVs0DSC8lnxIstyxW/lc1mCw8jmj2b X-Received: by 2002:a05:6a20:2583:b0:1a9:3e65:3488 with SMTP id k3-20020a056a20258300b001a93e653488mr5007892pzd.25.1713587067259; Fri, 19 Apr 2024 21:24:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713587067; cv=pass; d=google.com; s=arc-20160816; b=EL/WyK8ZLErGu46Tk30ZmuuqDsEfxtiuP+G/VOpYZIQswu5IXo2WtyegArRA6sqOST 8BSmbv6CFvZtGJsDig4krg63Uvy8j6IUgiAqLPXeG11BJkZeLKfBAfSCG1FmRSLt1Nzu uPnMwh2qn/1C2DMaNjIK4MvN23VezRvTJilfr6AvE4TXdS6tD92YDJDEdXMykmAeI1jx mS0rbWMEsAdI2vXvD2XFn5srCDy8D7XYKc/KLskP0/4xABox5uIiTYiLwL+VIzPti427 +0w3zDPvIVXKzQQjO1Yy9DQdYfW3nlEcGEBJ7mS3/yBy+VtuXA9bMTGK0QMmiyq1OCvp DRoQ== 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=FmPV+S9mTj64z9Rk3869An1iLCleEG/n5/oegN1VC3E=; fh=7CWc0oMXKDuCd1dK8m8iSHqZvuyVE5zY2SjGNC+50Rw=; b=yrTt2aiVxF1orMhaadP02Sc829nAw4XEImiKjVbcFkBXMU+I0JNJS5hXWn2qzF6ioY 9C9SlMroSxGP3y9VyukVX+sd05dvDwnGCBAnELRDZrKnQt9aWu7AjrgGZOqcGSBgB//B sjU/KJcNVIPGc+yewTvcHJI/WRjxWO8+8oIsBpNGhSaPeDQDMMOKTzzqEyuGGZaEI6+x oUcCmgfK7incYOGF6Fn3eujQD9A1wg9baksPz9XKMJe1MOTBo8ZVaSoGYSDU2zvWiXgZ aLw5LvY1Mcd5ptOh+Bs7otwPt6LJETiXjOewo/wdTm09xfug+BjKNgfA4ypuZrPvt8IY GGaw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YhvasTWv; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-152126-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-152126-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. [139.178.88.99]) by mx.google.com with ESMTPS id c24-20020a631c58000000b005dc8b2148ccsi4077703pgm.836.2024.04.19.21.24.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 21:24:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-152126-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YhvasTWv; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-152126-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-152126-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 E22562813AD for ; Sat, 20 Apr 2024 04:24:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0B8B4FBEF; Sat, 20 Apr 2024 04:24:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="YhvasTWv" 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 E7469625; Sat, 20 Apr 2024 04:24:12 +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=1713587053; cv=none; b=VhWLqgak1Me5Cq17UDoX0QXk5gkU+nrxjDO8pZPvjSfj9wdd6re/jCFHzfxqtTYo8mur88T2jhfgBCNc3y2AAbsRUDEQ9DI5HbL5TpAq33FX2m0IJzD79DUYiegmUH9tj2dAQMnq56wncp5pNuq6/pJRWi43VnntYAppSasH6gE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713587053; c=relaxed/simple; bh=XIe/vC5nJoDDEu9/Q7ZoXeJlkdIzu3x0dG0pVHSQyaU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=d/F3neD3QRJUKWQQrsGReOJCd+id8uImiaYCDBFlCN1puOdsR7K4TtL+9KwScLfGZ6B+uxNZcg6TXPXy8rzXEikkur2n5rfEuGJ+qM4ICOq7CQpbGshFuy1tQ/sse2zqGqjMfqM6U2FRv+QXhb/B0VfeN6sdV9pt8q3w1sYUOn4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YhvasTWv; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 83904C072AA; Sat, 20 Apr 2024 04:24:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713587052; bh=XIe/vC5nJoDDEu9/Q7ZoXeJlkdIzu3x0dG0pVHSQyaU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=YhvasTWvPZXPkThPYjnuTXJtKsDsFI6ZK4Bt9IvngW4VcopIHwZq0rN2TN47VCWUq FBJkDpR2DtP+unWDJY8C7sJEQiAOVs8L9KzXsojOjPLi6kQ9YDHioYtZ6nUFM1e0iU J5CLWhI8Oh/UQKju6kDG7HnVFfwfwBxuIE1OR267WnG9gRFiBTNZwpWVx17pWQtTrY fdbuHV6o8S3vVJ6wqWsJuIqtAsaxpsI2nzHYz53bqy1qeEbZ3ljz7qw9wo3USiXNjB OSy86A07SSbIPPzvVI3U5+/bWUkfoO6zoETP+0NHBuzBlMRXY9HoUBu5v7wjVTOH+s DowdwAPfYuE4g== Date: Sat, 20 Apr 2024 07:22:50 +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: 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 02:42:16PM -0700, Song Liu wrote: > On Fri, Apr 19, 2024 at 1:00 PM Mike Rapoport wrote: > > > > On Fri, Apr 19, 2024 at 10:32:39AM -0700, Song Liu wrote: > > > On Fri, Apr 19, 2024 at 10:03 AM Mike Rapoport wrote: > > > [...] > > > > > > > > > > > > [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. > > > > > > I think we at least need the "map to" concept (initially proposed by Thomas) > > > to get this work. For example, EXECMEM_BPF and EXECMEM_KPROBE > > > maps to EXECMEM_MODULE_TEXT, so that all these actually share > > > the same range. > > > > Why? > > IIUC, we need to update __execmem_cache_alloc() to take a range pointer as > input. module text will use "range" for EXECMEM_MODULE_TEXT, while kprobe > will use "range" for EXECMEM_KPROBE. Without "map to" concept or sharing > the "range" object, we will have to compare different range parameters to check > we can share cached pages between module text and kprobe, which is not > efficient. Did I miss something? We can always share large ROX pages as long as they are within the correct address space. The permissions for them are ROX and the alignment differences are due to KASAN and this is handled during allocation of the large page to refill the cache. __execmem_cache_alloc() only needs to limit the search for the address space of the range. And regardless, they way we deal with sharing of the cache can be sorted out later. > Thanks, > Song -- Sincerely yours, Mike.