Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp913793lqt; Fri, 19 Apr 2024 14:42:56 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUELpcOQa5G9VZqw02EJq7Lij1W2gV/pK8OBHXAJwfNgWOTLraIIkMkq4wijl5/CUFcK46hX5EBopZP93aJFdW+JI7aHAcxhAv31Udptg== X-Google-Smtp-Source: AGHT+IGjJoKKEx4MLSNCtM+1ljcSJw94vecdvvN13EfVAfOpwzPVuQYqmf9g9D0QYhPG0Dq3LDJM X-Received: by 2002:a5d:4a81:0:b0:343:e52a:f51e with SMTP id o1-20020a5d4a81000000b00343e52af51emr1854147wrq.47.1713562976011; Fri, 19 Apr 2024 14:42:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713562975; cv=pass; d=google.com; s=arc-20160816; b=KdBQgLMQ5nBhFm7rUl5d+IDvbb+jjHun/8qZ1Fns9Bo2FjuL3cMR1LJAc1rhUHhVjh aq4u209sFegMj387ss77Y/PZLj1xkOuy9Uzi2hlBu8owqDa/DEeecXwXRToa1TDMmL5o FioOQlwQuFxQGLYHuOEYu9/hy05BR4EHP7bWb8Ceb3YBX20UrfO43EsyoSn9c9qPuI+j Mu9uZSyXVq1qS4i7PJKIIdCvH5Pnsznsrleq/5KTpmR9N83beAXPnaK9AcF3j7Ki3WTc Cue/CMRM5iYkudF7Y9oMe4fK3yCtjhJG7oNSS5f/tLbbxi9SATWTK3zr07zKdmry6YvE BXNg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=Af6anyP9dkFAnpnHgVPwZT72TVuxloyY0iL0DnoDdx0=; fh=xN/9mrwu7p/w0UjyF89CHIhnBtnarF4h3Q9drf4NgVs=; b=SJh5cO5MX4n5hZlH1UsDTUFLkaKOiL9Ht9Sa8uWDl1nznYm1ad5NWoh4Cs1kFEUr9V xS/uSnMCWzNs3oXB1ZUjc9ExQ9KbWJfJ2CXar2v2r4pLfDY5QtZac6Sy5gJ+1bNW38Rh 2lMvcwjGnT6XRYtSftTFf4MV9V2PNb5pdoPdHWOlTmmj2FXK8EDQ9kUjfAyBXrjUvV0D Olp3Y7PYQiYZqn/9BGzR9otXLi61hvlttBafnJOdG9NO4YxyH1YKZWe9EzaVkx7Sf389 wtETdpM6baP/tfqvRnRMq+iiP6nZ/LyNEwq/Ks9n1YQ3Iy4iP0zsYAXJ4Pnw4HhSXuxn HCJQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="S3GIF3P/"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-151977-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151977-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id u3-20020a1709064ac300b00a51dccf86b3si2514716ejt.737.2024.04.19.14.42.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 14:42:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-151977-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="S3GIF3P/"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-151977-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151977-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 9079B1F22A6D for ; Fri, 19 Apr 2024 21:42:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B825813D2A6; Fri, 19 Apr 2024 21:42:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="S3GIF3P/" 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 9AFA213CF83; Fri, 19 Apr 2024 21:42:30 +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=1713562951; cv=none; b=cazohCjQntChEdyj2M3HDCzuE4mejGNeXiLENMWI0fTKFEXIicbvWKO+4LCZiKoZkunO5/3kH5JOIZSQ8oSkFUwFwmuQ1VI1yC/hahrR5CRXgxQ0RNkw+Vb56AHU3s/gXeqcM0OJllVUTvMaf+V7h/Za5sIXn+tVWKHX9MGaePw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713562951; c=relaxed/simple; bh=TCFccoU0QynIlhNVSwfE9PBflv6m2g3eer2smjEjHo0=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=EH/PPm6n+1GFffV4eCyFCu44GODztqpIPITkiLlC0LPGtDxEdKTuFjMJWnlratHLjsmHJ3aU2Px4aVuB11bHa64vUhcVb4tzbEVj5aRsLsc8LZ283MuQwF/PRoy+5jkPpykqJyyl/RiytDZjQMM+Upq2MSTywuXs9kXQgeCx4xQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=S3GIF3P/; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 37403C4AF0B; Fri, 19 Apr 2024 21:42:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713562950; bh=TCFccoU0QynIlhNVSwfE9PBflv6m2g3eer2smjEjHo0=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=S3GIF3P/lDyeKxFIF4pk3NB4voyc3jDBvrFx7J4R0RQPC7qB48PFG4JdR+LWTb5VG TVulfp4sZtTnavHG7YfjZx+qr0QC9dnKVswTmcKFscRs89DTdJ23BJZNcgr5rE8cTP GCYa7AVlhR6m2vNKGUfB4+E4ZP2+XMRA/mcbxKvZziVuxteHhStK2mndLtDfNVjE2Q rzZN4Ndc6tabVJQRtfseS5l8TWvfuyZ7Mgpj8k3neEzSInMxgygeIakC9HPWB8pW1A KTMwYXzpirJYjOMMHMhlNA3kWiCrgIQzk8AyhFrzS/yZyyqTAd0BMIA4fStLj4N5Cc q3NQekhLjCLew== Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-516d2b9cd69so3034818e87.2; Fri, 19 Apr 2024 14:42:30 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCUU60prFRWB6VKhtng5Uq8uprJ4pnlQJhq3BvWZPthcxwoC5zi3YZYEIJIsORsFh4uUQno3c2ENqcb3GO0BnMJy3U5bIsD0oFJdLBCv/gkEyxKfty0MTukwGUPq5VRA5HqPYsOrot0jkgfXjYjXOsKXH13B9hlzi91guyoB4neAm7It/gloqfGWsOS4Zw/ZqSPO2b6PobgniVy2ZkYB53tzvCNj8CBI7yT6eKS50pkeLeBQi78GKGSAAEsNxKgPpRmt55aovdklsaMpUz8XNUwWqr2M4D0ux8G+xi7oB0cxhLEy60udwNwUtOGmaMb1PysHr1HPj4X5IIuMg8MlqdRwsOWKlRF6r2sFZe0QTtwVZl5RB45w1RKWZRvGV1DLweFCgYKdptzeRflh3rvDugEJNkWTubWBPLahdnQUho2TD2rQydosGIksvZo= X-Gm-Message-State: AOJu0YzFFLhSlRvGvDmc/YE9tvA6UFuX3e5OXU47SvW8ghwd9J4HiLEB pTTy74IhfnHLOGIPqkeXeyQ6DBytR2hq1uL/xmxlKaMwiW+63Q5DTLwdYX3OmsyxwSahBSzT0NN 7h4SOseSPZTrCdyUXhH9Lcny4RYg= X-Received: by 2002:a19:5f4d:0:b0:519:5b84:1038 with SMTP id a13-20020a195f4d000000b005195b841038mr1897119lfj.20.1713562948432; Fri, 19 Apr 2024 14:42:28 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: In-Reply-To: From: Song Liu Date: Fri, 19 Apr 2024 14:42:16 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v4 05/15] mm: introduce execmem_alloc() and execmem_free() To: Mike Rapoport 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Apr 19, 2024 at 1:00=E2=80=AFPM Mike Rapoport wro= te: > > On Fri, Apr 19, 2024 at 10:32:39AM -0700, Song Liu wrote: > > On Fri, Apr 19, 2024 at 10:03=E2=80=AFAM Mike Rapoport wrote: > > [...] > > > > > > > > > > [1] https://lore.kernel.org/all/20240411160526.2093408-1-rppt@ker= nel.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 =3D __execmem_cache_alloc(size); > > > > if (p) > > > > return p; > > > > err =3D execmem_cache_populate(range, size); > > > > ... > > > > } > > > > > > > > We are calling __execmem_cache_alloc() without range. For this to w= ork, > > > > 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 s= pace. > > > > > > For other architectures this indeed needs to be fixed with passing th= e > > > 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 Th= omas) > > 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 c= heck we can share cached pages between module text and kprobe, which is not efficient. Did I miss something? Thanks, Song