Received: by 2002:ac2:596f:0:0:0:0:0 with SMTP id h15csp597503lfp; Fri, 22 Jul 2022 16:09:52 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tQZ76Qn/eMyE96YzJ93PsanZdF1CfBEatM1IeHjXyIGTZEKCtoJND1HoU7fsJTAB5D7TYD X-Received: by 2002:a37:b986:0:b0:6b5:5067:b1e3 with SMTP id j128-20020a37b986000000b006b55067b1e3mr1770817qkf.749.1658531392819; Fri, 22 Jul 2022 16:09:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658531392; cv=none; d=google.com; s=arc-20160816; b=PNNeGBfKp9Uoghb6bedOywuWMU4CFfmWtPyM23BTEXzJT8JSe0T4LYW94h+HSmyg91 2Tl9q/XddnCwTA42aFZAYHQoYmihKdJzr4VMRPsrmn/8+wDzhFyheil8DGnfl/ZnwdTX N+PLncsaoEY7Fxu8OX5dZFbCGb0yn93nnxlQaI8IXhmrFSvVSnHRNyS5zhCBDPLfqiAX me0zaKv9JtwyUWqOUjCO/FRBQQ3ltpGfAcmgP62j9gKEu6y3EOA88ZUHO3GRFUEmOhrl 8RxDW/ZhjY9bJVpblL4huK4qd7A2SmOFGZXMNlz6XynrIuTAcW40qglUe51BWBoVawdA LXCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version:references :message-id:in-reply-to:subject:cc:to:from:date; bh=ORB/8rBDulAmqrtxGi67upBF1YNYziAF4nakdfnIMl0=; b=ErABx91en5Z6CVz6igqIN5UvBCnjOWUbLhzf2c5Xn+M7/hlQiu5QRsNDRLmoA9dPU3 JTo4S1U6Hcggwdg/alPWoQEQnDEKnGmWRIT8q7IvjRM76cgS+2/h5lc6jd2I1m6Fq+/w 7E9kZxDEpTWEofpAys/bgHNgotN2vDDrmot+s7xOMqnZrxpIpQSar1jNxZ627yUL5rK4 MnZpjHMSp5GvRejirrRpWYhM69tHMXacVVP+KHVWZwrNhy47q8DoqIhjEqGfsbY79HWQ e8GFb6mOiakO9VvjK0gs56HhhuemhnCh8V2eW2uZmsOgr6l0KjRUHChYRPP+ukuku5lS np/A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=eik.bme.hu Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id w13-20020a05620a424d00b006b5bedee6a7si4133238qko.101.2022.07.22.16.09.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 22 Jul 2022 16:09:52 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=eik.bme.hu Received: from localhost ([::1]:40178 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oF1mK-0002xH-Br for alex.bennee@linaro.org; Fri, 22 Jul 2022 19:09:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56128) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oF1m6-0002x5-5i; Fri, 22 Jul 2022 19:09:38 -0400 Received: from zero.eik.bme.hu ([152.66.115.2]:57722) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oF1m3-0003O0-As; Fri, 22 Jul 2022 19:09:37 -0400 Received: from zero.eik.bme.hu (blah.eik.bme.hu [152.66.115.182]) by localhost (Postfix) with SMTP id 9575C746381; Sat, 23 Jul 2022 01:09:29 +0200 (CEST) Received: by zero.eik.bme.hu (Postfix, from userid 432) id 5718A74637E; Sat, 23 Jul 2022 01:09:29 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by zero.eik.bme.hu (Postfix) with ESMTP id 55535745702; Sat, 23 Jul 2022 01:09:29 +0200 (CEST) Date: Sat, 23 Jul 2022 01:09:29 +0200 (CEST) From: BALATON Zoltan To: Daniel Henrique Barboza cc: qemu-devel@nongnu.org, Alistair Francis , David Gibson , Peter Maydell , qemu-arm@nongnu.org Subject: Re: [PATCH for-7.2 01/10] hw/arm/boot.c: do not free machine->fdt in arm_load_dtb() In-Reply-To: <20220722200007.1602174-2-danielhb413@gmail.com> Message-ID: References: <20220722200007.1602174-1-danielhb413@gmail.com> <20220722200007.1602174-2-danielhb413@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed X-Spam-Probability: 8% Received-SPF: pass client-ip=152.66.115.2; envelope-from=balaton@eik.bme.hu; helo=zero.eik.bme.hu X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-arm@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org Sender: "Qemu-arm" X-TUID: UBzU97BG7eNA On Fri, 22 Jul 2022, Daniel Henrique Barboza wrote: > At this moment, arm_load_dtb() can free machine->fdt when > binfo->dtb_filename is NULL. If there's no 'dtb_filename', 'fdt' will be > retrieved by binfo->get_dtb(). If get_dtb() returns machine->fdt, as is > the case of machvirt_dtb() from hw/arm/virt.c, fdt now has a pointer to > machine->fdt. And, in that case, the existing g_free(fdt) at the end of > arm_load_dtb() will make machine->fdt point to an invalid memory region. > > This is not an issue right now because there's no code that access > machine->fdt after arm_load_dtb(), but we're going to add a couple do > FDT HMP commands that will rely on machine->fdt being valid. > > Instead of freeing 'fdt' at the end of arm_load_dtb(), assign it to > machine->fdt. This will allow the FDT of ARM machines that relies on > arm_load_dtb() to be accessed later on. > > Since all ARM machines allocates the FDT only once, we don't need to > worry about leaking the existing FDT during a machine reset (which is > something that other machines have to look after, e.g. the ppc64 pSeries > machine). > > Cc: Peter Maydell > Cc: qemu-arm@nongnu.org > Signed-off-by: Daniel Henrique Barboza > --- > hw/arm/boot.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/hw/arm/boot.c b/hw/arm/boot.c > index ada2717f76..1d9c6047b1 100644 > --- a/hw/arm/boot.c > +++ b/hw/arm/boot.c > @@ -684,7 +684,8 @@ int arm_load_dtb(hwaddr addr, const struct arm_boot_info *binfo, > */ > rom_add_blob_fixed_as("dtb", fdt, size, addr, as); > > - g_free(fdt); > + /* Update ms->fdt pointer */ > + ms->fdt = fdt; Not sure this comment is useful as it just states what the assignment does so provides no further info. Regards, BALATON Zoltan > > return size; > >