From patchwork Wed Mar 23 17:17:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 12789980 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 77F1AC433F5 for ; Wed, 23 Mar 2022 17:18:29 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.293991.499647 (Exim 4.92) (envelope-from ) id 1nX4cj-0004z1-Kn; Wed, 23 Mar 2022 17:18:17 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 293991.499647; Wed, 23 Mar 2022 17:18:17 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nX4cj-0004yt-Hg; Wed, 23 Mar 2022 17:18:17 +0000 Received: by outflank-mailman (input) for mailman id 293991; Wed, 23 Mar 2022 17:18:15 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nX4ch-0004wT-QS for xen-devel@lists.xenproject.org; Wed, 23 Mar 2022 17:18:15 +0000 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [2607:f8b0:4864:20::1036]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 38bbd616-aacd-11ec-8fbc-03012f2f19d4; Wed, 23 Mar 2022 18:18:14 +0100 (CET) Received: by mail-pj1-x1036.google.com with SMTP id m22so2398981pja.0 for ; Wed, 23 Mar 2022 10:18:14 -0700 (PDT) Received: from localhost.localdomain (198.red-83-50-65.dynamicip.rima-tde.net. [83.50.65.198]) by smtp.gmail.com with ESMTPSA id l20-20020a056a00141400b004f65cedfb09sm498798pfu.48.2022.03.23.10.18.07 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 23 Mar 2022 10:18:12 -0700 (PDT) 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: 38bbd616-aacd-11ec-8fbc-03012f2f19d4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RdGe7OSna0pa6P1DCbP+tWeGpoxvWEJQjOuJ7sjX7ZM=; b=LfJoFD5fOViBkuqfE0KI6EMWLe6oYelEsiQii6kQMJ+pxD0zqcY9STqOMnDFSlW73M 92ZYIUVnSjAEyM+0RN1XniYK9pmWDuGBo+SVmGf4sOHKTxRnTx7RfBfiXxSWznfHXIkq 0ct06cT/vEr1W7QFb/EO+MjqCSN9t4/1zOTBHtezxjV3AkxnCTB6PF9fzrALv+p62nuR RTbDk67z0FYbVHfgSJqkxdDjD0ZVlUCIoQNiEBHCeZ0g3oW9bGRNmiBQyv4PmC07JGLY 6pTUzjjLplNCGttiMQwTUmcJa0rxUNYiG8FiTe/ZrvXei+d0TJRUFxqUTgIUFjRYdCGL ZQAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RdGe7OSna0pa6P1DCbP+tWeGpoxvWEJQjOuJ7sjX7ZM=; b=vJ9bBhoiwUWPSm1Ymhqpd7TvsUkbCy+jWMNDlnrxvaT9Q1wqLIq7a3nwoD3q4IUJxg 9Pwv3cG6tPkcneNc1uPxg03wTW3C0xuUanHoAHScPBVWdglHZk7PEO90iWbljFXK5zbr UFPfZxTYN8PO7NIGplaoU78WRf9U8dSdqIygvgJirSiVuKMvPvzZqhHXp56kfqc45gCx 15IgKi4RjF8Af9zelcDE+/ecMVYKsG9QyCNBtF55AvHqZlJUeU5Nl9HMVhMyTdmf84T6 8rDnVS4Dh8zZELC3fn7jD2WqOTtKQ3UJn8oheOrKoAo1ooWtO1BkBYcTdFVG694B1UZZ 8vpw== X-Gm-Message-State: AOAM531KJBV0Iz3XDwI2qD4WWNfY9qghurxs1WWkPFFgGts9DQKsC7ym xTZo+SQPofPM6cfCSbXmzfg= X-Google-Smtp-Source: ABdhPJw8FuyQ7wLlVvP9x+Z8gtO3cPHdbxET9VHqz4Un8qAadu86lw/vl8rV1uYpDaorpMWUtuAyqg== X-Received: by 2002:a17:90b:1c07:b0:1c7:5324:c68e with SMTP id oc7-20020a17090b1c0700b001c75324c68emr802630pjb.202.1648055893334; Wed, 23 Mar 2022 10:18:13 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Wenchao Wang , Laurent Vivier , David Hildenbrand , Yanan Wang , Cameron Esfahani , Marcelo Tosatti , Sunil Muthuswamy , Anthony Perard , haxm-team@intel.com, Paul Durrant , Richard Henderson , xen-devel@lists.xenproject.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Roman Bolshakov , Reinoud Zandijk , Marcel Apfelbaum , Kamil Rytarowski , Paolo Bonzini , Peter Xu , Eduardo Habkost , Stefano Stabellini , Thomas Huth , Colin Xu , Mark Kanda Subject: [PATCH v4 01/13] cpu: Free cpu->cpu_ases in cpu_address_space_destroy() Date: Wed, 23 Mar 2022 18:17:39 +0100 Message-Id: <20220323171751.78612-2-philippe.mathieu.daude@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220323171751.78612-1-philippe.mathieu.daude@gmail.com> References: <20220323171751.78612-1-philippe.mathieu.daude@gmail.com> MIME-Version: 1.0 From: Mark Kanda Create cpu_address_space_destroy() to free a CPU's cpu_ases list. vCPU hotunplug related leak reported by Valgrind: ==132362== 216 bytes in 1 blocks are definitely lost in loss record 7,119 of 8,549 ==132362== at 0x4C3ADBB: calloc (vg_replace_malloc.c:1117) ==132362== by 0x69EE4CD: g_malloc0 (in /usr/lib64/libglib-2.0.so.0.5600.4) ==132362== by 0x7E34AF: cpu_address_space_init (physmem.c:751) ==132362== by 0x45053E: qemu_init_vcpu (cpus.c:635) ==132362== by 0x76B4A7: x86_cpu_realizefn (cpu.c:6520) ==132362== by 0x9343ED: device_set_realized (qdev.c:531) ==132362== by 0x93E26F: property_set_bool (object.c:2273) ==132362== by 0x93C23E: object_property_set (object.c:1408) ==132362== by 0x9406DC: object_property_set_qobject (qom-qobject.c:28) ==132362== by 0x93C5A9: object_property_set_bool (object.c:1477) ==132362== by 0x933C81: qdev_realize (qdev.c:333) ==132362== by 0x455E9A: qdev_device_add_from_qdict (qdev-monitor.c:713) Signed-off-by: Mark Kanda Tested-by: Philippe Mathieu-Daudé Message-Id: <20220321141409.3112932-5-mark.kanda@oracle.com> Signed-off-by: Philippe Mathieu-Daudé --- cpu.c | 1 + include/exec/cpu-common.h | 7 +++++++ softmmu/physmem.c | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/cpu.c b/cpu.c index be1f8b074c..59352a1487 100644 --- a/cpu.c +++ b/cpu.c @@ -174,6 +174,7 @@ void cpu_exec_unrealizefn(CPUState *cpu) tcg_exec_unrealizefn(cpu); } + cpu_address_space_destroy(cpu); cpu_list_remove(cpu); } diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h index 50a7d2912e..b17ad61ae4 100644 --- a/include/exec/cpu-common.h +++ b/include/exec/cpu-common.h @@ -111,6 +111,13 @@ size_t qemu_ram_pagesize_largest(void); */ void cpu_address_space_init(CPUState *cpu, int asidx, const char *prefix, MemoryRegion *mr); +/** + * cpu_address_space_destroy: + * @cpu: CPU for this address space + * + * Cleanup CPU's cpu_ases list. + */ +void cpu_address_space_destroy(CPUState *cpu); void cpu_physical_memory_rw(hwaddr addr, void *buf, hwaddr len, bool is_write); diff --git a/softmmu/physmem.c b/softmmu/physmem.c index 43ae70fbe2..aec61ca07a 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -762,6 +762,11 @@ void cpu_address_space_init(CPUState *cpu, int asidx, } } +void cpu_address_space_destroy(CPUState *cpu) +{ + g_free(cpu->cpu_ases); +} + AddressSpace *cpu_get_address_space(CPUState *cpu, int asidx) { /* Return the AddressSpace corresponding to the specified index */