Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp2469448lqt; Mon, 22 Apr 2024 11:32:51 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWx8aY1cDBYbAGDP5YtfXO85a7hjEDVXuoQFZTJ8lsBhYDvbPMCz6phat9Tj7A+G+45E3o8AnbdoUXjDPDIDYFpB1hN5uUOpV4GcG2Owg== X-Google-Smtp-Source: AGHT+IFropYz13gzeP0s8Sp9G6kwKaopBb0bSP6k3Aum4Hxr9vYUqAfTKpI4qNdhihFWx+MMD+eQ X-Received: by 2002:a17:902:aa92:b0:1e4:fea2:29b7 with SMTP id d18-20020a170902aa9200b001e4fea229b7mr10843156plr.59.1713810771434; Mon, 22 Apr 2024 11:32:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713810771; cv=pass; d=google.com; s=arc-20160816; b=DlLkcOl+DpRU21J9BPxZpOcuU4H2jJSAYnh1uk7FIQVkTury8sZ70mmtv5JRAPKusk Kx06cJFuT1H9J8LtBFJLjMTc7jMuDtqg3mj+ivSwj+V38OF08uDFpm6mYbRoAkQvpaVV b5+vFq1MbkPAMZnS0Hv412olE/XSqpHoeV0u0FBD+ranURUxWALFZd2O7yiloekGcRKj M5xpqX1GM5A16lfK0XKT48XjVNtyZkwdt5XAYVNlhPeSOt3WgcK0GxhmPK0a5eg7ktIM Yr/cN4hXMvzmQcfEDzhKMccE5qjt1CM9jfiKqXpZhB/mfcm8NJJEjxNg5JA3lx4Vnxtr 5Icw== 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=41bQmayZLa9F2TS6BjEFSDm7V8S6LLEq/o95h7wxG6E=; fh=ZsLB1lIaOPB3jGPNhrOuTpoKnXwAvXAVM4epj3yjqF4=; b=T4Bo3iOgp3SEjcDvfBdD1MHt3P+79AlL3Uq7/rUsjj48GOH4qShZz90WBbi21Cu60v 6n27Me3N/nl9mUvtPE+Y8gaCM6h6LvbNlbZUfiyMDTNfQXELPljE2/GEF51PRvd93h9V QYfvPgkcihDjqZ07xD0zApBewHOGVBS5n7RUejfLBQQd1pT+KDNbpfR5yuNkuefpE2bq 0mzk3BU2LnqB3GVdbyYo0O6lz6U19tFckhfgV/bDCPcyPNIRrKvhfqV/4KEpAWoeOnUL kGmbbo5UZo4IhZjPX+Wrf0DE/euyX/tQU8SDfhxFeDLYt/OUwHzkfwFV2/XU30jq7Zrf gMhw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=WFjAm3nG; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-153837-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-153837-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id b4-20020a170902650400b001e8b73582e6si1475669plk.196.2024.04.22.11.32.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 11:32:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-153837-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=WFjAm3nG; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-153837-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-153837-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id A0E0EB2233F for ; Mon, 22 Apr 2024 18:32:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BB7F01514F7; Mon, 22 Apr 2024 18:32:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="WFjAm3nG" 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 A85A41847; Mon, 22 Apr 2024 18:32:16 +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=1713810736; cv=none; b=QznZ5pBJl0AHmDy48WduUBUcGmD1B5IijLy07IEf5r/lnv88qxYRvA5oQaYlwdAlpqc1GVY1w1jWVl0QJqGwczxeeYfnZSSyAcfepfHnjKaKOF2nbfqgLPQaF761qomi9Pp7CLQeTv3/4Q6nT+jkRFMRRAHrU+7khNTTDfbwIaI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713810736; c=relaxed/simple; bh=41bQmayZLa9F2TS6BjEFSDm7V8S6LLEq/o95h7wxG6E=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=l28eZyiFEZGZ1i/VsciXHLakue8jpER4MkOl+eJHmzT4EU9NaymBI9aKgNE9lZM/8yoE6WRNH4NyIldiPpWKYf1t9kvuTHhyts5SEsj2/ZLFCkaNrcxQpiqy6FhTHbHod+xQPd+97s1/vPOsXJ5KKbqXRqeBgtbDl/8gOtm5gBA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WFjAm3nG; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3AA94C4AF0B; Mon, 22 Apr 2024 18:32:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713810736; bh=41bQmayZLa9F2TS6BjEFSDm7V8S6LLEq/o95h7wxG6E=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=WFjAm3nG7XUTrBnb9o2ks89OQgjxiSe5eWX8YxXd1sW0hbIxt8VjaFgdNY7jwwl/k AfWjBBQkR55Va8AnJ9aZ9HNo3aWGj92Hg8yQfe6AZc/sgCyr09/ddJev56eXLxhUbk bYRNUKDXSWSv0PHnlWydUHx0kp/IGq0ZRSR0xO71ow/Lfv7EI3MTbMaLFw4v7bXSFJ 3STUYz/yJHlp6VqKWBeoWQO13+U5j6+pSZw+u4eCUWHpkY832oOPrwYV84rmuYW4C/ bOCj02N41ZbDl+Gdwcz6EkWfYsWwZ5MhWh4lcO8wHP44/mjOjwNi1xfPxSrEJkKHPw nRWV7XhBkaFPQ== Received: by mail-lj1-f171.google.com with SMTP id 38308e7fff4ca-2da08b06e0dso56752861fa.2; Mon, 22 Apr 2024 11:32:16 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCVAiL4f0XpoTnbX2tsCYaeKCYRiAi5LlPsAXRg2XqaLnBfw0mAuWdG/n2s/rm1fN67yq2GFli/x7nix6Ci20zGBFF2tfTCPkpcU/cIUBXZfkl7bWOQ674srKDnADgriyGJjKil0QaqrFI6dYTBROAkgPQKjtNQoJOgjlaRxPYZtdGQ1xcGmfmo0LD51lKKVhfV+73d6mxcL3emy2Up/snWYvkBkSLoI6l8HPx139+GJVqJqGWEqCwbslJXVJ+i8E6ipAnU54pLeSVwJhoM1dTOLgvLRzXWjcDvU2C4oMB/Tgx3uj0qCNRGpKIrpvjSk81tsEbxLki9rk8infjoGwWTgUgZ/U+KECMhad5na35inrctV6TP7qU+I+9l7U++LRZ9ZsqeiFMXTp8B2pjo9iEXyJe6o+/8L3LQDsvbol2gD9M6TJmM+Tb/uvUQ= X-Gm-Message-State: AOJu0YzIVj4kudDkOfIdSzPU7qWk5hi4ACyrTbrFxV2xQk0sd40r9cdc G+YEaqz2iHHiLezycD0rMYEcmoO8FS2eYfkJpBR1rkwmo709PQ8NsIDTsIZrqnsyZnn0247incU B6rCbtRT3RUAl8E2ws3o7ouKDoIs= X-Received: by 2002:a2e:9496:0:b0:2d8:1d29:23a8 with SMTP id c22-20020a2e9496000000b002d81d2923a8mr6582027ljh.29.1713810734431; Mon, 22 Apr 2024 11:32:14 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240420181121.d6c7be11a6f98dc2462f8b41@kernel.org> In-Reply-To: <20240420181121.d6c7be11a6f98dc2462f8b41@kernel.org> From: Song Liu Date: Mon, 22 Apr 2024 11:32:02 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v4 05/15] mm: introduce execmem_alloc() and execmem_free() To: Masami Hiramatsu Cc: Mike Rapoport , 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 Hi Masami and Mike, On Sat, Apr 20, 2024 at 2:11=E2=80=AFAM Masami Hiramatsu wrote: [...] > > > > > > IIUC, we need to update __execmem_cache_alloc() to take a range point= er as > > > input. module text will use "range" for EXECMEM_MODULE_TEXT, while kp= robe > > > will use "range" for EXECMEM_KPROBE. Without "map to" concept or shar= ing > > > the "range" object, we will have to compare different range parameter= s to check > > > we can share cached pages between module text and kprobe, which is no= t > > > efficient. Did I miss something? > > Song, thanks for trying to eplain. I think I need to explain why I used > module_alloc() originally. > > This depends on how kprobe features are implemented on the architecture, = and > how much features are supported on kprobes. > > Because kprobe jump optimization and kprobe jump-back optimization need t= o > use a jump instruction to jump into the trampoline and jump back from the > trampoline directly, if the architecuture jmp instruction supports +-2GB = range > like x86, it needs to allocate the trampoline buffer inside such address = space. > This requirement is similar to the modules (because module function needs= to > call other functions in the kernel etc.), at least kprobes on x86 used > module_alloc(). > > However, if an architecture only supports breakpoint/trap based kprobe, > it does not need to consider whether the execmem is allocated. > > > > > We can always share large ROX pages as long as they are within the corr= ect > > address space. The permissions for them are ROX and the alignment > > differences are due to KASAN and this is handled during allocation of t= he > > large page to refill the cache. __execmem_cache_alloc() only needs to l= imit > > the search for the address space of the range. > > So I don't think EXECMEM_KPROBE always same as EXECMEM_MODULE_TEXT, it > should be configured for each arch. Especially, if it is only used for > searching parameter, it looks OK to me. Thanks for the explanation! I was thinking "we can have EXECMEM_KPROBE share the same parameters as EXECMEM_MODULE_TEXT for all architectures". But this thought is built on to= p of assumptions on future changes/improvements within multiple sub systems. At this moment, I have no objections moving forward with current execmem AP= Is. Thanks, Song