Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp3664848rwd; Fri, 16 Jun 2023 23:28:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4bQZQEBC6wyj1agagWdIFJXE9ek4qmMFWPf07mkJpP3KxNTbniBuO/ua/WglFX6AjdxFV+ X-Received: by 2002:a05:6870:e28e:b0:1a6:a28b:6d8 with SMTP id v14-20020a056870e28e00b001a6a28b06d8mr1740404oad.14.1686983284472; Fri, 16 Jun 2023 23:28:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686983284; cv=none; d=google.com; s=arc-20160816; b=N+deCKsT+hebMJOP2C8vOtDdKcT6Ev5lytLD60I9Y+QAd0sktaOxOn5SBGkFk/i6Jy TUGiAVwbhzqQlbh9iwMHwigumhmeOB+Uxmw8XEndiV8dnd5KaI7fwonZo3D8Ml6sMNYk Acj1Oxc/Byr3rAJ5bq9eYDAWY6rsDDe6qUgXqaosCwN3B8oHYvRFIKUqZzYyDKTbtYKO U/ttZzcJl3xGdYTgq4VGLNDFtCALbYELWMeLxzy3iNhH/7YdZ4MmuK8vzrGl0au5mVuX +tAqkyF8MwMUSRX0/bq2XETlKNMI/3j/8SlPbu8i/10+Hmie9q4MjJWFDKXkafss0HWV u5Cg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=r38PRqppWJi5DCcO6dUaoG/+GxOnj7iRUGonn0Cy7rA=; b=U5GIOJNtXPssDX1OSCZRJEEOqdHhJ+618BrrxuzcLolP7CM5tw+U7iG3Z/icuEw7t8 KDNxuea+/0C3k95cRbc9Whl+7O1tD/CLVT5a5WxWTFpT9+UnbnnrT9pjxjPYEJyZgd3r nExbmvyoGWQ7pbh9xNHKHy1hJKnAfuyId94mdgbyNraqokQ6V/GgkeOHWZvxqMh8RASi 9nVyJoHktRr21b4eK5FumKn2B3eanrT03GaqnGnFoTsczgPJVCwaw9PvOCHbSOw6eIg9 rMGIygmIc2gLis1zmG1bTz+CG7d+5ysVS210t3BBpTD3lYXEKVSQe1P5bVF9LCMcUxwv +d+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="kpVRRR3/"; 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 2-20020a621902000000b00652dbdb97d5si1913293pfz.356.2023.06.16.23.27.50; Fri, 16 Jun 2023 23:28:04 -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="kpVRRR3/"; 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 S231702AbjFQGLK (ORCPT + 99 others); Sat, 17 Jun 2023 02:11:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229493AbjFQGLI (ORCPT ); Sat, 17 Jun 2023 02:11:08 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66EFE26AA; Fri, 16 Jun 2023 23:11:04 -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 0327E6068F; Sat, 17 Jun 2023 06:11:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 232F1C433C8; Sat, 17 Jun 2023 06:10:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686982263; bh=1X6Vc8+Xzykk7Z2p+5RPkPnfKk/mxTwRqvgQiLyFLcs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=kpVRRR3/peLouH5K6845IoDymP4RzHQ5X18L/qapqW+HSOSVD4Jxe+dS8ZHi81pu/ 6UGSL3ryafkglY404kB9NewuLJthdXrDKmiG1bUa/SbIGImcdFFTImcXA24Lrq1XBP b8jHFLQ6gc3Wlj/T62OORePu3DpO0oegza9UGNNTomGmTdYPVnUkXHwlXXNP8xNb6O mSUdao6gRKvwJRP5+ktwASUtigGyhHJfmUrvUL8UkoscW+emJo4VTKfMECcoxbnJ1O 71I0q0m7dm69SI0vCCHrQzATzQcgIJXdFUCmromH14CzN/7cF+UERF73BpE9q6ULNL UyjIthY/V8Lsw== Date: Sat, 17 Jun 2023 09:10:15 +0300 From: Mike Rapoport To: "Edgecombe, Rick P" Cc: "linux-kernel@vger.kernel.org" , "tglx@linutronix.de" , "mcgrof@kernel.org" , "deller@gmx.de" , "davem@davemloft.net" , "nadav.amit@gmail.com" , "linux@armlinux.org.uk" , "netdev@vger.kernel.org" , "linux-mips@vger.kernel.org" , "linux-riscv@lists.infradead.org" , "hca@linux.ibm.com" , "catalin.marinas@arm.com" , "kent.overstreet@linux.dev" , "puranjay12@gmail.com" , "linux-s390@vger.kernel.org" , "palmer@dabbelt.com" , "chenhuacai@kernel.org" , "tsbogend@alpha.franken.de" , "linux-trace-kernel@vger.kernel.org" , "linux-parisc@vger.kernel.org" , "christophe.leroy@csgroup.eu" , "x86@kernel.org" , "mpe@ellerman.id.au" , "mark.rutland@arm.com" , "rostedt@goodmis.org" , "linuxppc-dev@lists.ozlabs.org" , "will@kernel.org" , "dinguyen@kernel.org" , "naveen.n.rao@linux.ibm.com" , "sparclinux@vger.kernel.org" , "linux-modules@vger.kernel.org" , "bpf@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , "song@kernel.org" , "linux-mm@kvack.org" , "loongarch@lists.linux.dev" , "akpm@linux-foundation.org" Subject: Re: [PATCH v2 04/12] mm/execmem, arch: convert remaining overrides of module_alloc to execmem Message-ID: <20230617061015.GO52412@kernel.org> References: <20230616085038.4121892-1-rppt@kernel.org> <20230616085038.4121892-5-rppt@kernel.org> <15f5dff8217b1a2e16697d40e48dee6dd1f9b2f3.camel@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <15f5dff8217b1a2e16697d40e48dee6dd1f9b2f3.camel@intel.com> 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 04:16:28PM +0000, Edgecombe, Rick P wrote: > On Fri, 2023-06-16 at 11:50 +0300, Mike Rapoport wrote: > > -void *module_alloc(unsigned long size) > > -{ > > -???????gfp_t gfp_mask = GFP_KERNEL; > > -???????void *p; > > - > > -???????if (PAGE_ALIGN(size) > MODULES_LEN) > > -???????????????return NULL; > > +static struct execmem_params execmem_params = { > > +???????.modules = { > > +???????????????.flags = EXECMEM_KASAN_SHADOW, > > +???????????????.text = { > > +???????????????????????.alignment = MODULE_ALIGN, > > +???????????????}, > > +???????}, > > +}; > > Did you consider making these execmem_params's ro_after_init? Not that > it is security sensitive, but it's a nice hint to the reader that it is > only modified at init. And I guess basically free sanitizing of buggy > writes to it. Makes sense. > > ? > > -???????p = __vmalloc_node_range(size, MODULE_ALIGN, > > -??????????????????????????????? MODULES_VADDR + > > get_module_load_offset(), > > -??????????????????????????????? MODULES_END, gfp_mask, PAGE_KERNEL, > > -??????????????????????????????? VM_FLUSH_RESET_PERMS | > > VM_DEFER_KMEMLEAK, > > -??????????????????????????????? NUMA_NO_NODE, > > __builtin_return_address(0)); > > +struct execmem_params __init *execmem_arch_params(void) > > +{ > > +???????unsigned long start = MODULES_VADDR + > > get_module_load_offset(); > > I think we can drop the mutex's in get_module_load_offset() now, since > execmem_arch_params() should only be called once at init. Right. Even more, the entire get_module_load_offset() can be folded into execmem_arch_params() as if (IS_ENABLED(CONFIG_RANDOMIZE_BASE) && kaslr_enabled()) module_load_offset = get_random_u32_inclusive(1, 1024) * PAGE_SIZE; > > ? > > -???????if (p && (kasan_alloc_module_shadow(p, size, gfp_mask) < 0)) > > { > > -???????????????vfree(p); > > -???????????????return NULL; > > -???????} > > +???????execmem_params.modules.text.start = start; > > +???????execmem_params.modules.text.end = MODULES_END; > > +???????execmem_params.modules.text.pgprot = PAGE_KERNEL; > > ? > > -???????return p; > > +???????return &execmem_params; > > ?} > > ? > -- Sincerely yours, Mike.