Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp609702lqo; Thu, 16 May 2024 16:35:48 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX0O5NkW4KluJ4frNpvNHEfdiEgQvXn05dnlGSkLLChhJyP3SLn02P8KQjDPCmwVG25s7EAYJlmgkF/WrNzk0lDYq9t5pIOFEPNEFnSQg== X-Google-Smtp-Source: AGHT+IFRnI8mVeJ+h11ZDvVUCz32xDnCPsf19qSACi7nPvPh0EcbMKSF5S82itg/hx95RI6gXdjc X-Received: by 2002:a05:6a20:5a95:b0:1af:6428:1812 with SMTP id adf61e73a8af0-1afd1417a8cmr32404760637.4.1715902548470; Thu, 16 May 2024 16:35:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715902548; cv=pass; d=google.com; s=arc-20160816; b=qHSm7ikaLxIAanUOLv+SkbXXSlpOtOdnw45pk68h5kG9ma0UwubRC5eJzz48dVJKHU 5W1FOY8ZHTPV9fnmfvCrnS6FMX247JWR3SE5ARy3jSJ/hrfcubFPiUxArO2pY+DjXkJi uBlsJzo9iu19xktmWxiRGlsFYGO2c8+H4vZCIMp2s3a2hen6O1txtLn+4Umxm55qrhP1 OekogQ5jMSMMErlTjnuisLoCcCl5HxarRuPE7vrkO4bklpxUO4EbuMxe+lPii669x9UV jGARASJFH7pUqrizoCWMmPHwaImBk/v8pSeCZ24Mru6NJK4zhcYh2uMwfQ7q+RhUaGJS BFlg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=6bF9AeLnq02T/LkapzdDY3Cm1n0qYV5VbfFUYaRFQz0=; fh=zGpUnUrk9qRbu8eobSL6XHTlO44raHbN2lvlDwBDdmw=; b=Dtw/j2nU0f23Ox/M4qMdpykMOEb1YNEj6r1D5wpvGZ6csrOrnFm/07VPSuaxX+FnHm 65STjnuwHVGH5IllTlOHB5+8lUfEqmGupkM3BNM3DrMIHjlKk1slni9bZ2w8+UdGi2dI xcinygXz12HNZprnT1YTF4jQa4c7eoMouI27xfUaym5YqyWBwUBtWKgsttA5DzNuJNAf IN7/ZcE5NgMyIwr9TwxMzaz4iO6iy3Erk2zuUKrsY8FAxfrCWF8MvYIsH7w/GGrNw1Vm D3stsKg+xq7cSG+2yWWi5XS3B/isqnRZelrYsVbaboQ5brEnJzAHeKviQuur2Y651wLb bYtQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@canb.auug.org.au header.s=201702 header.b=H8sP+vGh; arc=pass (i=1 spf=pass spfdomain=canb.auug.org.au dkim=pass dkdomain=canb.auug.org.au dmarc=pass fromdomain=canb.auug.org.au); spf=pass (google.com: domain of linux-kernel+bounces-181638-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181638-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canb.auug.org.au Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-657df567e09si3454839a12.877.2024.05.16.16.35.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 May 2024 16:35:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-181638-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@canb.auug.org.au header.s=201702 header.b=H8sP+vGh; arc=pass (i=1 spf=pass spfdomain=canb.auug.org.au dkim=pass dkdomain=canb.auug.org.au dmarc=pass fromdomain=canb.auug.org.au); spf=pass (google.com: domain of linux-kernel+bounces-181638-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181638-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canb.auug.org.au 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 B5109283221 for ; Thu, 16 May 2024 23:35:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 692752C697; Thu, 16 May 2024 23:35:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=canb.auug.org.au header.i=@canb.auug.org.au header.b="H8sP+vGh" Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) (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 DE2CA273FC; Thu, 16 May 2024 23:35:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=150.107.74.76 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715902539; cv=none; b=hwbflAhteTXQR42lNRFMEMXS/HYMvi9CViQTCK/iR+X+yjIILh0SRF3hCeSPbRhSuSiV7J9R59Oa793Cop3qte67tx+7pbelSfma0Y+ZYBIv6+dqCS/f5CXKGSlsK5FP52GoDgqRNxuLAtI9t3lcQ70zcT+U/m7Tdd5RpolPKOU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715902539; c=relaxed/simple; bh=j1SWaBMvTu0L2kibND4NHcBtbdsRTcHCxYXklPzrO/g=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kMqSn8XLa80q60YbPT0w1sZnALdm0tBPqKHaQiNZs+daHOaz5ppNWbVgBHa1exurghhGWxAteQd7TicqkIOKxYg+ly40N03g76bMB2XyadIgppU5DCirxWCfqARhRA3g50rh3JmoivK00EiXjhbIGFcyFHxPearB8QsYogjjQHc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canb.auug.org.au; spf=pass smtp.mailfrom=canb.auug.org.au; dkim=pass (2048-bit key) header.d=canb.auug.org.au header.i=@canb.auug.org.au header.b=H8sP+vGh; arc=none smtp.client-ip=150.107.74.76 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canb.auug.org.au Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=canb.auug.org.au DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canb.auug.org.au; s=201702; t=1715902535; bh=6bF9AeLnq02T/LkapzdDY3Cm1n0qYV5VbfFUYaRFQz0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=H8sP+vGhxjWAUsWuyo4pr7m2mlvY++qKvpPyHgwerXbMaLQALC5hElte8MzgZgzvT OmJEUPkhkcg5WFQSC8k5qiVPGz3pBAp+6gBRTiILpBKZxewBvAo5/hoEduYtEthaaJ lHMA2SOsqHkxI2lXgQ0kfHgA586wOrVQoxcy2xVikjA3IHnzjJMbJgIeeycqgEQEWJ X0PkRdSwucKbYdQY8ZP7R1g8kCAP5GBz2P9iFQaBFhNpjfyS4jdSM8YtYWXxh/aWJW plQl1Cv7Kr5/8SjwoCzSkIwW4XDXWPxKehHs/WDkJEFjwoTXE5lmZX3m6V1MzsLzOk rVtnCYgAYmvqQ== Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4VgRKf6wdNz4wx5; Fri, 17 May 2024 09:35:34 +1000 (AEST) Date: Fri, 17 May 2024 09:35:34 +1000 From: Stephen Rothwell To: Andrew Morton Cc: Luis Chamberlain , Linux Kernel Mailing List , Linux Next Mailing List , "Mike Rapoport (IBM)" , Suren Baghdasaryan Subject: Re: linux-next: manual merge of the modules tree with the mm tree Message-ID: <20240517093534.4523ced1@canb.auug.org.au> In-Reply-To: <20240517092347.469578bb@canb.auug.org.au> References: <20240412120421.27d86c34@canb.auug.org.au> <20240517092347.469578bb@canb.auug.org.au> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: multipart/signed; boundary="Sig_/+GpPVZ/a26kCsEcdLiUERnx"; protocol="application/pgp-signature"; micalg=pgp-sha256 --Sig_/+GpPVZ/a26kCsEcdLiUERnx Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Hi all, On Fri, 17 May 2024 09:23:47 +1000 Stephen Rothwell = wrote: > > On Fri, 12 Apr 2024 12:04:21 +1000 Stephen Rothwell wrote: > > > > Today's linux-next merge of the modules tree got a conflict in: > >=20 > > kernel/module/main.c > >=20 > > between commit: > >=20 > > 58782d7a7ccd ("lib: prevent module unloading if memory is not freed") > >=20 > > from the mm-unstable branch of the mm tree and commit: > >=20 > > a4ee8c9b86bd ("module: make module_memory_{alloc,free} more self-cont= ained") > >=20 > > from the modules tree. > >=20 >=20 > This is now a conflict between the mm-stable tree and Linus' tree. The actual final resolution (due to more patches) is below. --=20 Cheers, Stephen Rothwell diff --cc kernel/module/main.c index 91e185607d4b,2d25eebc549d..d18a94b973e1 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@@ -56,8 -56,8 +56,9 @@@ #include #include #include + #include #include +#include #include #include "internal.h" =20 @@@ -1188,50 -1198,32 +1189,54 @@@ void __weak module_arch_freeing_init(st { } =20 -static bool mod_mem_use_vmalloc(enum mod_mem_type type) +static int module_memory_alloc(struct module *mod, enum mod_mem_type type) { - return IS_ENABLED(CONFIG_ARCH_WANTS_MODULES_DATA_IN_VMALLOC) && - mod_mem_type_is_core_data(type); -} + unsigned int size =3D PAGE_ALIGN(mod->mem[type].size); + enum execmem_type execmem_type; + void *ptr; =20 -static void *module_memory_alloc(unsigned int size, enum mod_mem_type typ= e) -{ - if (mod_mem_use_vmalloc(type)) - return vzalloc(size); - return module_alloc(size); + mod->mem[type].size =3D size; + + if (mod_mem_type_is_data(type)) + execmem_type =3D EXECMEM_MODULE_DATA; + else + execmem_type =3D EXECMEM_MODULE_TEXT; + + ptr =3D execmem_alloc(execmem_type, size); + if (!ptr) + return -ENOMEM; + + /* + * The pointer to these blocks of memory are stored on the module + * structure and we keep that around so long as the module is + * around. We only free that memory when we unload the module. + * Just mark them as not being a leak then. The .init* ELF + * sections *do* get freed after boot so we *could* treat them + * slightly differently with kmemleak_ignore() and only grey + * them out as they work as typical memory allocations which + * *do* eventually get freed, but let's just keep things simple + * and avoid *any* false positives. + */ + kmemleak_not_leak(ptr); + + memset(ptr, 0, size); + mod->mem[type].base =3D ptr; + + return 0; } =20 - static void module_memory_free(struct module *mod, enum mod_mem_type type) -static void module_memory_free(void *ptr, enum mod_mem_type type, ++static void module_memory_free(struct module *mod, enum mod_mem_type type, + bool unload_codetags) { + void *ptr =3D mod->mem[type].base; + + if (!unload_codetags && mod_mem_type_is_core_data(type)) + return; +=20 - if (mod_mem_use_vmalloc(type)) - vfree(ptr); - else - module_memfree(ptr); + execmem_free(ptr); } =20 - static void free_mod_mem(struct module *mod) + static void free_mod_mem(struct module *mod, bool unload_codetags) { for_each_mod_mem_type(type) { struct module_memory *mod_mem =3D &mod->mem[type]; @@@ -1242,12 -1234,13 +1247,12 @@@ /* Free lock-classes; relies on the preceding sync_rcu(). */ lockdep_free_key_range(mod_mem->base, mod_mem->size); if (mod_mem->size) - module_memory_free(mod, type); - module_memory_free(mod_mem->base, type, - unload_codetags); ++ module_memory_free(mod, type, unload_codetags); } =20 /* MOD_DATA hosts mod, so free it at last */ lockdep_free_key_range(mod->mem[MOD_DATA].base, mod->mem[MOD_DATA].size); - module_memory_free(mod, MOD_DATA); - module_memory_free(mod->mem[MOD_DATA].base, MOD_DATA, unload_codetags); ++ module_memory_free(mod, MOD_DATA, unload_codetags); } =20 /* Free a module, remove from lists, etc. */ @@@ -2287,7 -2309,7 +2299,7 @@@ static int move_module(struct module *m return 0; out_enomem: for (t--; t >=3D 0; t--) - module_memory_free(mod, t); - module_memory_free(mod->mem[t].base, t, true); ++ module_memory_free(mod, t, true); return ret; } =20 --Sig_/+GpPVZ/a26kCsEcdLiUERnx Content-Type: application/pgp-signature Content-Description: OpenPGP digital signature -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEENIC96giZ81tWdLgKAVBC80lX0GwFAmZGmEYACgkQAVBC80lX 0GxZnQf/bzCmOLSwZA5hA9NNOyKsZz5wEKQknGEwrasXpBVki6AggR9VSKii2guV K/AwOtwXLt7k3Lkb4L8sasZnNqzrEr1YsaroZPCBL8KPJEUkd04wj8kF3X67PCrj Nfl/khZaBvMz9MAQKv759CTztPXe/TMzgER72atY47tg4GEpStcqXGT4N9J0rgGz kbo3IPRIkCK2UiHjfVZZABiWbys++4X0A9jzas5dXenCYuA7oVBtTQLkJ8IeNLfq s3aw8/f7J0iWOYGkpGhqERt/JjMH6+XtBRuFTzCWzi+a3OuiqvcV4eBcAIA6plif KFQnEqc8KrRR9f2j+ZfBZKyE9XXN2g== =g1oP -----END PGP SIGNATURE----- --Sig_/+GpPVZ/a26kCsEcdLiUERnx--