stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Rusty Russell <rusty@rustcorp.com.au>,
	Jim Hull <jim.hull@hp.com>
Subject: [ 04/15] module: do percpu allocation after uniqueness check.  No, really!
Date: Thu, 11 Jul 2013 15:19:34 -0700	[thread overview]
Message-ID: <20130711221256.493148140@linuxfoundation.org> (raw)
In-Reply-To: <20130711221255.925669600@linuxfoundation.org>

3.9-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Rusty Russell <rusty@rustcorp.com.au>

commit 8d8022e8aba85192e937f1f0f7450e256d66ae5c upstream.

v3.8-rc1-5-g1fb9341 was supposed to stop parallel kvm loads exhausting
percpu memory on large machines:

    Now we have a new state MODULE_STATE_UNFORMED, we can insert the
    module into the list (and thus guarantee its uniqueness) before we
    allocate the per-cpu region.

In my defence, it didn't actually say the patch did this.  Just that
we "can".

This patch actually *does* it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Tested-by: Jim Hull <jim.hull@hp.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 kernel/module.c |   34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)

--- a/kernel/module.c
+++ b/kernel/module.c
@@ -2939,7 +2939,6 @@ static struct module *layout_and_allocat
 {
 	/* Module within temporary copy. */
 	struct module *mod;
-	Elf_Shdr *pcpusec;
 	int err;
 
 	mod = setup_load_info(info, flags);
@@ -2954,17 +2953,10 @@ static struct module *layout_and_allocat
 	err = module_frob_arch_sections(info->hdr, info->sechdrs,
 					info->secstrings, mod);
 	if (err < 0)
-		goto out;
+		return ERR_PTR(err);
 
-	pcpusec = &info->sechdrs[info->index.pcpu];
-	if (pcpusec->sh_size) {
-		/* We have a special allocation for this section. */
-		err = percpu_modalloc(mod,
-				      pcpusec->sh_size, pcpusec->sh_addralign);
-		if (err)
-			goto out;
-		pcpusec->sh_flags &= ~(unsigned long)SHF_ALLOC;
-	}
+	/* We will do a special allocation for per-cpu sections later. */
+	info->sechdrs[info->index.pcpu].sh_flags &= ~(unsigned long)SHF_ALLOC;
 
 	/* Determine total sizes, and put offsets in sh_entsize.  For now
 	   this is done generically; there doesn't appear to be any
@@ -2975,17 +2967,22 @@ static struct module *layout_and_allocat
 	/* Allocate and move to the final place */
 	err = move_module(mod, info);
 	if (err)
-		goto free_percpu;
+		return ERR_PTR(err);
 
 	/* Module has been copied to its final place now: return it. */
 	mod = (void *)info->sechdrs[info->index.mod].sh_addr;
 	kmemleak_load_module(mod, info);
 	return mod;
+}
 
-free_percpu:
-	percpu_modfree(mod);
-out:
-	return ERR_PTR(err);
+static int alloc_module_percpu(struct module *mod, struct load_info *info)
+{
+	Elf_Shdr *pcpusec = &info->sechdrs[info->index.pcpu];
+	if (!pcpusec->sh_size)
+		return 0;
+
+	/* We have a special allocation for this section. */
+	return percpu_modalloc(mod, pcpusec->sh_size, pcpusec->sh_addralign);
 }
 
 /* mod is no longer valid after this! */
@@ -3249,6 +3246,11 @@ static int load_module(struct load_info
 	}
 #endif
 
+	/* To avoid stressing percpu allocator, do this once we're unique. */
+	err = alloc_module_percpu(mod, info);
+	if (err)
+		goto unlink_mod;
+
 	/* Now module is in final location, initialize linked lists, etc. */
 	err = module_unload_init(mod);
 	if (err)



  parent reply	other threads:[~2013-07-11 22:19 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-11 22:19 [ 00/15] 3.9.10-stable review Greg Kroah-Hartman
2013-07-11 22:19 ` [ 01/15] libceph: Fix NULL pointer dereference in auth client code Greg Kroah-Hartman
2013-07-11 22:19 ` [ 02/15] ceph: fix sleeping function called from invalid context Greg Kroah-Hartman
2013-07-11 22:19 ` [ 03/15] drivers/cdrom/cdrom.c: use kzalloc() for failing hardware Greg Kroah-Hartman
2013-07-11 22:19 ` Greg Kroah-Hartman [this message]
2013-07-11 22:19 ` [ 05/15] charger-manager: Ensure event is not used as format string Greg Kroah-Hartman
2013-07-11 22:19 ` [ 06/15] hpfs: better test for errors Greg Kroah-Hartman
2013-07-11 22:19 ` [ 07/15] block: do not pass disk names as format strings Greg Kroah-Hartman
2013-07-11 22:19 ` [ 08/15] crypto: sanitize argument for format string Greg Kroah-Hartman
2013-07-11 22:19 ` [ 09/15] MAINTAINERS: add stable_kernel_rules.txt to stable maintainer information Greg Kroah-Hartman
2013-07-11 22:19 ` [ 10/15] futex: Take hugepages into account when generating futex_key Greg Kroah-Hartman
2013-07-11 22:19 ` [ 11/15] Revert "serial: 8250_pci: add support for another kind of NetMos Technology PCI 9835 Multi-I/O Controller" Greg Kroah-Hartman
2013-07-11 22:19 ` [ 12/15] nfsd4: fix decoding of compounds across page boundaries Greg Kroah-Hartman
2013-07-11 22:19 ` [ 13/15] KVM: VMX: mark unusable segment as nonpresent Greg Kroah-Hartman
2013-07-11 22:19 ` [ 14/15] SCSI: sd: Fix parsing of temporary cache mode prefix Greg Kroah-Hartman
2013-07-11 22:19 ` [ 15/15] Revert "memcg: avoid dangling reference count in creation failure" Greg Kroah-Hartman
2013-07-12 17:23 ` [ 00/15] 3.9.10-stable review Shuah Khan
2013-07-12 22:05 ` Guenter Roeck
2013-07-13  1:32   ` Greg Kroah-Hartman
2013-07-13  4:16 ` Satoru Takeuchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130711221256.493148140@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=jim.hull@hp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rusty@rustcorp.com.au \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).