Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0F782C433B4 for ; Fri, 9 Apr 2021 13:23:48 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C3A8D61106 for ; Fri, 9 Apr 2021 13:23:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C3A8D61106 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.107833.206097 (Exim 4.92) (envelope-from ) id 1lUr6X-0004Lr-W7; Fri, 09 Apr 2021 13:23:21 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 107833.206097; Fri, 09 Apr 2021 13:23:21 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lUr6X-0004Lk-T3; Fri, 09 Apr 2021 13:23:21 +0000 Received: by outflank-mailman (input) for mailman id 107833; Fri, 09 Apr 2021 13:23:21 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lUr6W-0004Lf-Sh for xen-devel@lists.xenproject.org; Fri, 09 Apr 2021 13:23:20 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id c5ef3842-18e1-47b4-9f26-f06e6da1593a; Fri, 09 Apr 2021 13:23:20 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 33800B0D1; Fri, 9 Apr 2021 13:23:19 +0000 (UTC) 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: c5ef3842-18e1-47b4-9f26-f06e6da1593a 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=1617974599; 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=u+GSWSxRnFu2ymxORhPVe2l7To6rRzYw1ekr3JmHBFg=; b=JB0iSkiVvMJTxiMDHYKLdPpIuTcI/Koi1YqD8Xna65udZKQ7BiywfMVbR54wOcq9LMQVyj oOUx/BuzM8Q5FGgB3W9SaABzIhZ7QIGO4AvxGL9f3+ZZ2yCU6cZENz+7E9WJtEVfH+TpH9 MhVkuTlWdmoTHzJaTw08tqqU9OLmig4= Subject: Re: [PATCH 09/11] kexec: avoid effectively open-coding xzalloc_flex_struct() To: Andrew Cooper Cc: George Dunlap , "xen-devel@lists.xenproject.org" References: <4ea9c4a3-74c0-1722-fa5d-3930be99ef4a@suse.com> <8131c6f5-ed8c-98ae-376a-fe8f7b63a790@citrix.com> From: Jan Beulich Message-ID: Date: Fri, 9 Apr 2021 15:23:18 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.9.0 MIME-Version: 1.0 In-Reply-To: <8131c6f5-ed8c-98ae-376a-fe8f7b63a790@citrix.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit On 09.04.2021 14:54, Andrew Cooper wrote: > On 08/04/2021 13:21, Jan Beulich wrote: >> There is a difference in generated code: xzalloc_bytes() forces >> SMP_CACHE_BYTES alignment. I think we not only don't need this here, but >> actually don't want it. >> >> Signed-off-by: Jan Beulich > > This honestly looks like a backwards step.  In particular, ... > >> >> --- 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)); > > ... this is far more error prone than the code you replaced, seeing as > there is now a chance that it can underflow. You're kidding, aren't you? sizeof_cpu_notes() can't possibly return a value which would allow underflow here. There would be bigger issues than the underflow if any such happened, in particular with any theoretical underflow here simply resulting in the allocation to fail. The original code is type-unsafe and requests more alignment than necessary. Besides objecting to my present way of addressing this, I would find it rather helpful if you could mention some kind of alternative you'd consider acceptable. As said in the cover letter, I think mid-term we ought to do away with xmalloc_bytes(). Hence some alternative would be needed here anyway. Jan