From patchwork Fri Aug 2 16:39:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Tyshchenko X-Patchwork-Id: 11073915 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0B85813AC for ; Fri, 2 Aug 2019 16:41:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F02202889C for ; Fri, 2 Aug 2019 16:41:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E267A286C8; Fri, 2 Aug 2019 16:41:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6DF3B286C8 for ; Fri, 2 Aug 2019 16:41:50 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htab7-0004AC-2r; Fri, 02 Aug 2019 16:40:05 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htab5-0003rU-2T for xen-devel@lists.xenproject.org; Fri, 02 Aug 2019 16:40:03 +0000 X-Inumbo-ID: 2bcc9853-b544-11e9-8980-bc764e045a96 Received: from mail-lj1-x242.google.com (unknown [2a00:1450:4864:20::242]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 2bcc9853-b544-11e9-8980-bc764e045a96; Fri, 02 Aug 2019 16:40:01 +0000 (UTC) Received: by mail-lj1-x242.google.com with SMTP id z28so19232458ljn.4 for ; Fri, 02 Aug 2019 09:40:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=PgnbDeNvPObShiypUWFNiBvgdeoIW4vOdanJkIbquHU=; b=HSXo8fMwXg+H/fqX2ZkHhDY2xTUzwB9OUKQ4yfEj/D0toSAN69fqtPsBjweF6rHLKA duBEFJIiKoRYIVzGFdXSagis9KmgzgwKZMheg1WzHBTqsSFIcvmV6mEDS4KxyYug1Vpl oVkZnP8dFWefZzXevddGUbheIjKuSv5cQBM1d1Wg+rl1F7yR727Yv2PSD3fV+sSvYSDw C2v6bZjLCDZdAyTwZXW5IsHuXphnxlxevBJTj5LoMP7Hyf7zagTOnhozVuKZ03m0aGw4 r+Of03NXaOBrWaT7IcpYaCWVGIAM366cFe0y6ntXAzhp6y3xgDEcQSl8MDrSpr5xpNa/ eMoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=PgnbDeNvPObShiypUWFNiBvgdeoIW4vOdanJkIbquHU=; b=WxUmiqP8UG3lxfC9Jg3/MSHklKx4f6feL6Ua6HhSfjkjFdnP/8JrxELTItjuHPHUhD uPd/lRiRs9xsY78xtb6GPPFRRqkDNGNgQ5nY1PX2+9XUOBdPAjQM0NBdqGkQCfgYnkOF RX2+h/SB8AaBKHhiIQcM1FAQnfo3KOGk4BEv4zXJDLJGjbN6q1tjsGgc6HXGr8EYWagm cPJndj/6H6/xZhP2EMvfUNnwmcssVEvBBV2mDqgG0Q/21ooSM2ZzrtdcUPDmpJZRAdgp 4zs0kQ7aamqPYawXg1YjcssvWOdtxY5vqj0fj6+PHan5Ufr793jxjY4S/VWaXn8RoWeK Decg== X-Gm-Message-State: APjAAAVdUy1QU3F22LXtMdG8uexM3/pxp4JxD9L4fv6S7p7GBNIeZKMW lEfCfG4YJayqa49V5aewkundLFT9zeU= X-Google-Smtp-Source: APXvYqxegN9WyW1h8rNRz4pRvBMM9euzIxGil77e1rujkTwpelpMo+uHq4RcCihb5QeKNPYhQN2Yag== X-Received: by 2002:a2e:3604:: with SMTP id d4mr21245116lja.85.1564764000324; Fri, 02 Aug 2019 09:40:00 -0700 (PDT) Received: from otyshchenko.kyiv.epam.com (ll-22.209.223.85.sovam.net.ua. [85.223.209.22]) by smtp.gmail.com with ESMTPSA id q6sm15378998lji.70.2019.08.02.09.39.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 02 Aug 2019 09:39:59 -0700 (PDT) From: Oleksandr Tyshchenko To: xen-devel@lists.xenproject.org Date: Fri, 2 Aug 2019 19:39:42 +0300 Message-Id: <1564763985-20312-4-git-send-email-olekstysh@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1564763985-20312-1-git-send-email-olekstysh@gmail.com> References: <1564763985-20312-1-git-send-email-olekstysh@gmail.com> Subject: [Xen-devel] [PATCH V2 3/6] [RFC] xen/common: Introduce _xrealloc function X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: sstabellini@kernel.org, Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Oleksandr Tyshchenko , julien.grall@arm.com, Jan Beulich MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Oleksandr Tyshchenko Next patch in this series will make use of it. Original patch was initially posted by Sameer Goel: https://lists.xen.org/archives/html/xen-devel/2017-06/msg00858.html This could be considered as another attempt to add it: https://www.mail-archive.com/kexec@lists.infradead.org/msg21335.html Signed-off-by: Oleksandr Tyshchenko CC: Andrew Cooper CC: George Dunlap CC: Ian Jackson CC: Jan Beulich CC: Julien Grall CC: Konrad Rzeszutek Wilk CC: Stefano Stabellini CC: Tim Deegan CC: Wei Liu --- [As it was previously discussed with Julien in IRC] The reason for this patch to be an RFC is that patch itself is not completely correct and I don't fully understand what/how should be done for this patch to be accepted. Or whether community even wants this to go in. So, to avoid bike shedding, the first target is to collect feedback from the maintainers. In a nutshell, the upcoming "iommu_fwspec" support on ARM is going to use xrealloc when adding new device ID. We really want to have "iommu_fwspec" support which will give us a generic abstract way to add new device to the IOMMU based on the generic IOMMU DT binding. This is how Linux does: https://github.com/torvalds/linux/blob/master/drivers/iommu/iommu.c#L2257 and we are doing the similar in next patch of this thread: "iommu/arm: Add lightweight iommu_fwspec support" --- xen/common/xmalloc_tlsf.c | 21 +++++++++++++++++++++ xen/include/xen/xmalloc.h | 1 + 2 files changed, 22 insertions(+) diff --git a/xen/common/xmalloc_tlsf.c b/xen/common/xmalloc_tlsf.c index 2076953..c080763 100644 --- a/xen/common/xmalloc_tlsf.c +++ b/xen/common/xmalloc_tlsf.c @@ -610,6 +610,27 @@ void *_xzalloc(unsigned long size, unsigned long align) return p ? memset(p, 0, size) : p; } +void *_xrealloc(void *p, unsigned long new_size, unsigned long align) +{ + void *new_p; + + if ( !new_size ) + { + xfree(p); + return NULL; + } + + new_p = _xmalloc(new_size, align); + + if ( new_p && p ) + { + memcpy(new_p, p, new_size); + xfree(p); + } + + return new_p; +} + void xfree(void *p) { struct bhdr *b; diff --git a/xen/include/xen/xmalloc.h b/xen/include/xen/xmalloc.h index b486fe4..63961ef 100644 --- a/xen/include/xen/xmalloc.h +++ b/xen/include/xen/xmalloc.h @@ -51,6 +51,7 @@ extern void xfree(void *); /* Underlying functions */ extern void *_xmalloc(unsigned long size, unsigned long align); extern void *_xzalloc(unsigned long size, unsigned long align); +extern void *_xrealloc(void *p, unsigned long new_size, unsigned long align); static inline void *_xmalloc_array( unsigned long size, unsigned long align, unsigned long num)