Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 454E8C433F5 for ; Sat, 7 May 2022 11:26:24 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.323681.545464 (Exim 4.92) (envelope-from ) id 1nnIZd-0003v6-SB; Sat, 07 May 2022 11:26:09 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 323681.545464; Sat, 07 May 2022 11:26:09 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nnIZd-0003uz-Oh; Sat, 07 May 2022 11:26:09 +0000 Received: by outflank-mailman (input) for mailman id 323681; Sat, 07 May 2022 11:26:07 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nnIZb-0003ut-Sj for xen-devel@lists.xenproject.org; Sat, 07 May 2022 11:26:07 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nnIZb-0005Lh-JK; Sat, 07 May 2022 11:26:07 +0000 Received: from gw1.octic.net ([81.187.162.82] helo=[10.0.1.102]) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nnIZb-0001EV-DZ; Sat, 07 May 2022 11:26:07 +0000 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" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:From: References:Cc:To:Subject:MIME-Version:Date:Message-ID; bh=zO5nDulVJvMCj0o0muvGfrPjkZiTuCeyskrlGulD5V4=; b=wVCneGceeoFVk/B7hgP26fzwC5 0pjNrMUd46y3sMdNpw6oHLxxaTzqtOpjtQjHQh528dEV2jjR+KiRW145yisJ6bASH2fB9go9EB2Pw 8Ok4TL+vxVhwxtneAw0nNhS5/u2OZBDeMbVz+oqCCUCHUhwAo5XW2xPsCV9ZpSqhdcHg=; Message-ID: Date: Sat, 7 May 2022 12:26:05 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.8.1 Subject: Re: [PATCH v2 8/9] xen/arm: create shared memory nodes in guest device tree To: Stefano Stabellini , Penny Zheng Cc: xen-devel@lists.xenproject.org, wei.chen@arm.com, Bertrand Marquis , Volodymyr Babchuk References: <20220506072502.2177828-1-Penny.Zheng@arm.com> <20220506072502.2177828-9-Penny.Zheng@arm.com> From: Julien Grall In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi, On 07/05/2022 02:09, Stefano Stabellini wrote: > On Fri, 6 May 2022, Penny Zheng wrote: >> We expose the shared memory to the domU using the "xen,shared-memory-v1" >> reserved-memory binding. See >> Documentation/devicetree/bindings/reserved-memory/xen,shared-memory.txt >> in Linux for the corresponding device tree binding. >> >> To save the cost of re-parsing shared memory device tree configuration when >> creating shared memory nodes in guest device tree, this commit adds new field >> "shm_mem" to store shm-info per domain. >> >> For each shared memory region, a range is exposed under >> the /reserved-memory node as a child node. Each range sub-node is >> named xen-shmem@
and has the following properties: >> - compatible: >> compatible = "xen,shared-memory-v1" >> - reg: >> the base guest physical address and size of the shared memory region >> - xen,id: >> a string that identifies the shared memory region. >> >> Signed-off-by: Penny Zheng >> --- >> v2 change: >> - using xzalloc >> - shm_id should be uint8_t >> - make reg a local variable >> - add #address-cells and #size-cells properties >> - fix alignment >> --- >> xen/arch/arm/domain_build.c | 144 ++++++++++++++++++++++++++++++ >> xen/arch/arm/include/asm/domain.h | 1 + >> xen/arch/arm/include/asm/setup.h | 1 + >> 3 files changed, 146 insertions(+) >> >> diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c >> index 8d299a3616..f08606d2c0 100644 >> --- a/xen/arch/arm/domain_build.c >> +++ b/xen/arch/arm/domain_build.c >> @@ -894,6 +894,26 @@ static int __init allocate_shared_memory(struct domain *d, >> return ret; >> } >> >> +static int __init append_shm_bank_to_domain(struct domain *d, >> + paddr_t start, paddr_t size, >> + u32 shm_id) >> +{ >> + /* Allocate memory at first insertion. */ >> + if ( d->arch.shm_mem == NULL ) >> + { >> + d->arch.shm_mem = xzalloc(struct meminfo); >> + if ( d->arch.shm_mem == NULL ) >> + return -ENOMEM; >> + } >> + >> + d->arch.shm_mem->bank[d->arch.shm_mem->nr_banks].start = start; >> + d->arch.shm_mem->bank[d->arch.shm_mem->nr_banks].size = size; >> + d->arch.shm_mem->bank[d->arch.shm_mem->nr_banks].shm_id = shm_id; >> + d->arch.shm_mem->nr_banks++; bank[] is a fixed size array. So we should check we don't overflow. >> + >> + return 0; >> +} > > Can we call xfree(d->arch.shm_mem) at domain destruction? > > Even better, we might be able to call it earlier, soon after the > make_resv_memory_node() call because we don't need it any longer after > that? If this is only used during domain build, then the field should move to kernel_info. With that, there will also be no concern on whether we need to allocate the structure or not. Cheers, -- Julien Grall