From: Jan Beulich <jbeulich@suse.com> To: "xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org> Cc: Andrew Cooper <andrew.cooper3@citrix.com>, George Dunlap <george.dunlap@citrix.com> Subject: [PATCH v2 6/8] kexec: avoid effectively open-coding xzalloc_flex_struct() Date: Wed, 21 Apr 2021 16:58:48 +0200 [thread overview] Message-ID: <7d6c30d8-c121-11f5-4ac9-49bad43a2a19@suse.com> (raw) In-Reply-To: <091b4b91-712f-3526-78d1-80d31faf8e41@suse.com> There is a difference in generated code: xzalloc_bytes() forces SMP_CACHE_BYTES alignment. But if code really cared about such higher than default alignment, it should request so explicitly rather than using a type-unsafe interface. And if e.g. cache line sharing was a concern, the allocator itself should arrange to avoid such. Signed-off-by: Jan Beulich <jbeulich@suse.com> --- a/xen/common/kexec.c +++ b/xen/common/kexec.c @@ -463,7 +463,10 @@ static void * alloc_from_crash_heap(cons /* Allocate a crash note buffer for a newly onlined cpu. */ static int kexec_init_cpu_notes(const unsigned long cpu) { - Elf_Note * note = NULL; + struct elf_notes { + Elf_Note first; + unsigned char more[]; + } *notes = NULL; int ret = 0; int nr_bytes = 0; @@ -477,7 +480,8 @@ static int kexec_init_cpu_notes(const un /* If we dont care about the position of allocation, malloc. */ if ( low_crashinfo_mode == LOW_CRASHINFO_NONE ) - note = xzalloc_bytes(nr_bytes); + notes = xzalloc_flex_struct(struct elf_notes, more, + nr_bytes - sizeof(notes->first)); /* Protect the write into crash_notes[] with a spinlock, as this function * is on a hotplug path and a hypercall path. */ @@ -490,26 +494,28 @@ static int kexec_init_cpu_notes(const un spin_unlock(&crash_notes_lock); /* Always return ok, because whether we successfully allocated or not, * another CPU has successfully allocated. */ - xfree(note); + xfree(notes); } else { /* If we care about memory possition, alloc from the crash heap, * also protected by the crash_notes_lock. */ if ( low_crashinfo_mode > LOW_CRASHINFO_NONE ) - note = alloc_from_crash_heap(nr_bytes); + notes = alloc_from_crash_heap(nr_bytes); - crash_notes[cpu].start = note; + crash_notes[cpu].start = ¬es->first; crash_notes[cpu].size = nr_bytes; spin_unlock(&crash_notes_lock); /* If the allocation failed, and another CPU did not beat us, give * up with ENOMEM. */ - if ( ! note ) + if ( ! notes ) ret = -ENOMEM; /* else all is good so lets set up the notes. */ else { + Elf_Note *note = ¬es->first; + /* Set up CORE note. */ setup_note(note, "CORE", NT_PRSTATUS, sizeof(ELF_Prstatus)); note = ELFNOTE_NEXT(note);
next prev parent reply other threads:[~2021-04-21 14:59 UTC|newest] Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-04-21 14:54 [PATCH v2 0/8] assorted replacement of x[mz]alloc_bytes() Jan Beulich 2021-04-21 14:56 ` [PATCH v2 1/8] x86/MCE: avoid effectively open-coding xmalloc_array() Jan Beulich 2021-04-21 14:56 ` [PATCH v2 2/8] x86/HVM: " Jan Beulich 2021-04-21 14:57 ` [PATCH v2 3/8] x86/oprofile: " Jan Beulich 2021-04-21 14:57 ` [PATCH v2 4/8] x86/IRQ: avoid over-alignment in alloc_pirq_struct() Jan Beulich 2021-04-21 14:58 ` [PATCH v2 5/8] EFI/runtime: avoid effectively open-coding x{m,z}alloc_array() Jan Beulich 2021-04-21 14:58 ` Jan Beulich [this message] 2021-04-21 14:59 ` [PATCH v2 7/8] video/lfb: avoid effectively open-coding xzalloc_array() Jan Beulich 2021-04-21 14:59 ` [PATCH v2 8/8] Arm/optee: don't open-code xzalloc_flex_struct() Jan Beulich 2021-05-03 13:53 ` Ping: " Jan Beulich 2021-05-04 23:49 ` Volodymyr Babchuk 2021-04-21 15:23 ` [PATCH v2 0/8] assorted replacement of x[mz]alloc_bytes() Andrew Cooper 2021-04-21 15:32 ` Jan Beulich 2021-04-23 9:44 ` Jan Beulich
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=7d6c30d8-c121-11f5-4ac9-49bad43a2a19@suse.com \ --to=jbeulich@suse.com \ --cc=andrew.cooper3@citrix.com \ --cc=george.dunlap@citrix.com \ --cc=xen-devel@lists.xenproject.org \ --subject='Re: [PATCH v2 6/8] kexec: avoid effectively open-coding xzalloc_flex_struct()' \ /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
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).