Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp3088399rwd; Fri, 16 Jun 2023 12:03:31 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7Cc/8Nv/jvRzbhZfEReWOVYdACVrUUw7Q8kaCPdqCOUHLEgHJCXmQ29a6aKTRA1WNPzzD4 X-Received: by 2002:a05:6a20:3c86:b0:10b:bf2d:71bb with SMTP id b6-20020a056a203c8600b0010bbf2d71bbmr4218697pzj.27.1686942210763; Fri, 16 Jun 2023 12:03:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686942210; cv=none; d=google.com; s=arc-20160816; b=XHxz2enAHMORhZv4myVd2hh/SfaREweET1KGVLHPJ4OlLYSsw2fho97q2KpH1ATiWW mfOe3rfyUZ23FUILmgUO2I9nuYxo5Kc73nfTkTlp0V9HfhzGd80CSKir8ENoPcKa0CqN 66TBJy8Kf4kuMq7uN1NJ711T9oJFr1B7LTRLk7nmD5WeHlsF9NOqmRHCJ4te4Bvil6nE aR+dFfJZuoDWuN6mTZ1TqtnatD7N0gVfAoCztGdzAB9rypRpc6YsuU5FMZrE0BqM1Sn+ 7CT4OALAxQptWfk8s74j2tsLw0s8UC9zf2tcrs7JQZyefVdiUFxTYeioVDYIOOMtiEb5 mGFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=BdYJO6pcmmzGR77QxUIYaK1RYrkkIcAvnn4QKk2l5rE=; b=lg2k1b+V86ScPUM1503xafqrB3EqNLgMikrCqoG9o3AcgpQJR0nGIeWYK91tvUPq1T EIArDGu0E0b7FSAt77d6ZQvBMna/D3My2caSqfcbMl/eNVr8WZcnWDKO97kFpexY1w9i 8X9qYvawMlNa1ksiN+aig9PvrELB4I1xa7brsICsAyhmxbNXjX8u0o/Ux5e4gTHXIWV7 /1m+jYJPvLs7aABTES9JM7G3RjC1JMQnML0Lz3PtbzkT89ilQnrjzzrrZAKi7QVSma+n OoXddWBKF8I325vqfcfWmvYjRtm+pbuV6ToyWFp1rnM1Iu6g4mKE2N8dcTf8G17TFv29 5VSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VAiGa0I3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h71-20020a63834a000000b005537c209b83si1659886pge.462.2023.06.16.12.03.15; Fri, 16 Jun 2023 12:03:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VAiGa0I3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345291AbjFPSyb (ORCPT + 99 others); Fri, 16 Jun 2023 14:54:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345367AbjFPSy0 (ORCPT ); Fri, 16 Jun 2023 14:54:26 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15D3C3A9D; Fri, 16 Jun 2023 11:54:10 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A5D0C63303; Fri, 16 Jun 2023 18:54:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 11526C433A9; Fri, 16 Jun 2023 18:54:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686941649; bh=Yn4AaKJNeoRa5k6Rpqw8rOaWUpFfj0b/8Nallv5Pzds=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=VAiGa0I3VACBcfckeYjIsmg+o/Lg4sS9yo0qhzfoNoM8HW3/yOwai3153O/GUAXbj YJtd0QtbYHxESgW/1famknmpEyl1VcqqZbhSsOi11zU9/ZMOErIBdZBoGkIJK30tWt unGcQ+mitBz6SxYbCiSHZpCoP8hgQukNeXy1UbCOP0F5ZH682Nli8SfcUiRSggpyfA eBElWbeNqWyPxCKgFRONE3eKcW6XHG/HLKpP7a6yELMQu7jW7a8McQDjl83mpuO51f IpRYwyGRjNbRqpToW+gHjtGgDrWOf+YGXI32hL/bT3NIgnBpJWshrLsqdj1cuzU+Nn 8iQhg6Wj6381A== Received: by mail-lf1-f44.google.com with SMTP id 2adb3069b0e04-4f611ac39c5so1473711e87.2; Fri, 16 Jun 2023 11:54:08 -0700 (PDT) X-Gm-Message-State: AC+VfDwmHOtdCIK0tW0WmUXAj//MrcdUuJ+KWS+wKAHJwCKNzvtDC/Ao u5LNahUCuO/+on0bAqCQpkUaO1gnY+NXz0cMia4= X-Received: by 2002:a19:7b05:0:b0:4f6:d9e:7c3b with SMTP id w5-20020a197b05000000b004f60d9e7c3bmr2147967lfc.44.1686941646932; Fri, 16 Jun 2023 11:54:06 -0700 (PDT) MIME-Version: 1.0 References: <20230616085038.4121892-1-rppt@kernel.org> <20230616085038.4121892-5-rppt@kernel.org> In-Reply-To: <20230616085038.4121892-5-rppt@kernel.org> From: Song Liu Date: Fri, 16 Jun 2023 11:53:54 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 04/12] mm/execmem, arch: convert remaining overrides of module_alloc to execmem To: Mike Rapoport Cc: linux-kernel@vger.kernel.org, Andrew Morton , Catalin Marinas , Christophe Leroy , "David S. Miller" , Dinh Nguyen , Heiko Carstens , Helge Deller , Huacai Chen , Kent Overstreet , Luis Chamberlain , Mark Rutland , Michael Ellerman , Nadav Amit , "Naveen N. Rao" , Palmer Dabbelt , Puranjay Mohan , Rick Edgecombe , Russell King , Steven Rostedt , Thomas Bogendoerfer , Thomas Gleixner , Will Deacon , bpf@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 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 16, 2023 at 1:51=E2=80=AFAM Mike Rapoport wro= te: [...] > diff --git a/arch/arm64/kernel/module.c b/arch/arm64/kernel/module.c > index 5af4975caeb5..c3d999f3a3dd 100644 > --- a/arch/arm64/kernel/module.c > +++ b/arch/arm64/kernel/module.c > @@ -17,56 +17,50 @@ > #include > #include > #include > +#include > #include > #include > #include > #include > > -void *module_alloc(unsigned long size) > +static struct execmem_params execmem_params =3D { > + .modules =3D { > + .flags =3D EXECMEM_KASAN_SHADOW, > + .text =3D { > + .alignment =3D MODULE_ALIGN, > + }, > + }, > +}; > + > +struct execmem_params __init *execmem_arch_params(void) > { > u64 module_alloc_end =3D module_alloc_base + MODULES_VSIZE; > - gfp_t gfp_mask =3D GFP_KERNEL; > - void *p; > - > - /* Silence the initial allocation */ > - if (IS_ENABLED(CONFIG_ARM64_MODULE_PLTS)) > - gfp_mask |=3D __GFP_NOWARN; > > - if (IS_ENABLED(CONFIG_KASAN_GENERIC) || > - IS_ENABLED(CONFIG_KASAN_SW_TAGS)) > - /* don't exceed the static module region - see below */ > - module_alloc_end =3D MODULES_END; > + execmem_params.modules.text.pgprot =3D PAGE_KERNEL; > + execmem_params.modules.text.start =3D module_alloc_base; I think I mentioned this earlier. For arm64 with CONFIG_RANDOMIZE_BASE, module_alloc_base is not yet set when execmem_arch_params() is called. So we will need some extra logic for this. Thanks, Song > + execmem_params.modules.text.end =3D module_alloc_end; > > - p =3D __vmalloc_node_range(size, MODULE_ALIGN, module_alloc_base, > - module_alloc_end, gfp_mask, PAGE_KERNEL, = VM_DEFER_KMEMLEAK, > - NUMA_NO_NODE, __builtin_return_address(0)= ); > - > - if (!p && IS_ENABLED(CONFIG_ARM64_MODULE_PLTS) && > + /* > + * KASAN without KASAN_VMALLOC can only deal with module > + * allocations being served from the reserved module region, > + * since the remainder of the vmalloc region is already > + * backed by zero shadow pages, and punching holes into it > + * is non-trivial. Since the module region is not randomized > + * when KASAN is enabled without KASAN_VMALLOC, it is even > + * less likely that the module region gets exhausted, so we > + * can simply omit this fallback in that case. > + */ > + if (IS_ENABLED(CONFIG_ARM64_MODULE_PLTS) && > (IS_ENABLED(CONFIG_KASAN_VMALLOC) || > (!IS_ENABLED(CONFIG_KASAN_GENERIC) && > - !IS_ENABLED(CONFIG_KASAN_SW_TAGS)))) > - /* > - * KASAN without KASAN_VMALLOC can only deal with module > - * allocations being served from the reserved module regi= on, > - * since the remainder of the vmalloc region is already > - * backed by zero shadow pages, and punching holes into i= t > - * is non-trivial. Since the module region is not randomi= zed > - * when KASAN is enabled without KASAN_VMALLOC, it is eve= n > - * less likely that the module region gets exhausted, so = we > - * can simply omit this fallback in that case. > - */ > - p =3D __vmalloc_node_range(size, MODULE_ALIGN, module_all= oc_base, > - module_alloc_base + SZ_2G, GFP_KERNEL, > - PAGE_KERNEL, 0, NUMA_NO_NODE, > - __builtin_return_address(0)); > - > - if (p && (kasan_alloc_module_shadow(p, size, gfp_mask) < 0)) { > - vfree(p); > - return NULL; > + !IS_ENABLED(CONFIG_KASAN_SW_TAGS)))) { > + unsigned long end =3D module_alloc_base + SZ_2G; > + > + execmem_params.modules.text.fallback_start =3D module_all= oc_base; > + execmem_params.modules.text.fallback_end =3D end; > } > > - /* Memory is intended to be executable, reset the pointer tag. */ > - return kasan_reset_tag(p); > + return &execmem_params; > } > > enum aarch64_reloc_op {