From nobody Tue Feb 10 01:15:06 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1619017144; cv=none; d=zohomail.com; s=zohoarc; b=ImuvrEYvWAGNYPXW52/oBR9T31OYZ/h3TAk6Vq8c6p1o34Gbca6h0OhMRrK9z+Ihju3GP4vZbbIzbMZt8K8iu12H5CCLQFDigCKDzrtHPD4SryNHtOdo05MmEN0rZOD25uq/wXiEdcud4X9X0lrY4pzLN4rtR2zLbYoOsAGnzAI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619017144; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=TEBD/fYXGTJrgtLtgU6ekKg6T1yeMv6RYI14JcXg8j8=; b=NGPRKRfsDdzHULzo+RUYfwgmcsL0iBlyJ5a6S1WQUgdqIz7FNz8wDJrhsw+Av3HfxAa4GbzqD7DRnC9a1Zc0ePTmayWi8wAW7gTQSlYNxqmzt8JXnfLx4cQAfxlCtjtog6L02ToH/MkAAEpZnCFFFiOjOvZfv5KyhIaLUdxt0Yg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1619017144349600.59779639628; Wed, 21 Apr 2021 07:59:04 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.114802.218857 (Exim 4.92) (envelope-from ) id 1lZEJX-0008Rg-GL; Wed, 21 Apr 2021 14:58:51 +0000 Received: by outflank-mailman (output) from mailman id 114802.218857; Wed, 21 Apr 2021 14:58:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lZEJX-0008RZ-DD; Wed, 21 Apr 2021 14:58:51 +0000 Received: by outflank-mailman (input) for mailman id 114802; Wed, 21 Apr 2021 14:58:49 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lZEJV-0008RJ-R6 for xen-devel@lists.xenproject.org; Wed, 21 Apr 2021 14:58:49 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id ec5dbab9-d98d-48be-ae11-d491971b14e5; Wed, 21 Apr 2021 14:58:49 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 4E330B4D5; Wed, 21 Apr 2021 14:58:48 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: ec5dbab9-d98d-48be-ae11-d491971b14e5 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1619017128; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TEBD/fYXGTJrgtLtgU6ekKg6T1yeMv6RYI14JcXg8j8=; b=c1iQM0N8Kr/7EMMA3fDMO/lAq3vlxDYh+Qu+6yeO5vSsNcW3uc5pvAUBgKtyuudjrWINRx 9XEv1TLdeMKPxZeZCZD19wWaF0rINC3StebQxVMf3rY7UawdDIgHWZoBZHqSxeTFvEe5Yc FbDBohSc2bSuuFNvyT4cwW4HRj88EDw= Subject: [PATCH v2 6/8] kexec: avoid effectively open-coding xzalloc_flex_struct() From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , George Dunlap References: <091b4b91-712f-3526-78d1-80d31faf8e41@suse.com> Message-ID: <7d6c30d8-c121-11f5-4ac9-49bad43a2a19@suse.com> Date: Wed, 21 Apr 2021 16:58:48 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.0 MIME-Version: 1.0 In-Reply-To: <091b4b91-712f-3526-78d1-80d31faf8e41@suse.com> Content-Language: en-US Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" 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 --- 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 =3D NULL; + struct elf_notes { + Elf_Note first; + unsigned char more[]; + } *notes =3D NULL; int ret =3D 0; int nr_bytes =3D 0; =20 @@ -477,7 +480,8 @@ static int kexec_init_cpu_notes(const un =20 /* If we dont care about the position of allocation, malloc. */ if ( low_crashinfo_mode =3D=3D LOW_CRASHINFO_NONE ) - note =3D xzalloc_bytes(nr_bytes); + notes =3D xzalloc_flex_struct(struct elf_notes, more, + nr_bytes - sizeof(notes->first)); =20 /* Protect the write into crash_notes[] with a spinlock, as this funct= ion * 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 =3D alloc_from_crash_heap(nr_bytes); + notes =3D alloc_from_crash_heap(nr_bytes); =20 - crash_notes[cpu].start =3D note; + crash_notes[cpu].start =3D ¬es->first; crash_notes[cpu].size =3D nr_bytes; spin_unlock(&crash_notes_lock); =20 /* If the allocation failed, and another CPU did not beat us, give * up with ENOMEM. */ - if ( ! note ) + if ( ! notes ) ret =3D -ENOMEM; /* else all is good so lets set up the notes. */ else { + Elf_Note *note =3D ¬es->first; + /* Set up CORE note. */ setup_note(note, "CORE", NT_PRSTATUS, sizeof(ELF_Prstatus)); note =3D ELFNOTE_NEXT(note);