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 */ From patchwork Wed Mar 23 17:17:40 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: 12789981 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 89175C433EF for ; Wed, 23 Mar 2022 17:18:40 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.293995.499659 (Exim 4.92) (envelope-from ) id 1nX4cv-0005S9-SU; Wed, 23 Mar 2022 17:18:29 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 293995.499659; Wed, 23 Mar 2022 17:18:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nX4cv-0005S2-PR; Wed, 23 Mar 2022 17:18:29 +0000 Received: by outflank-mailman (input) for mailman id 293995; Wed, 23 Mar 2022 17:18:28 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nX4ct-0004Zy-Ry for xen-devel@lists.xenproject.org; Wed, 23 Mar 2022 17:18:27 +0000 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [2607:f8b0:4864:20::1035]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 4019c6a7-aacd-11ec-a405-831a346695d4; Wed, 23 Mar 2022 18:18:27 +0100 (CET) Received: by mail-pj1-x1035.google.com with SMTP id o3-20020a17090a3d4300b001c6bc749227so2492351pjf.1 for ; Wed, 23 Mar 2022 10:18:27 -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 s6-20020a056a0008c600b004f667b8a6b6sm448750pfu.193.2022.03.23.10.18.19 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 23 Mar 2022 10:18:25 -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: 4019c6a7-aacd-11ec-a405-831a346695d4 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=Kr2xMtMFIyMaJvHp1QmAibj3cqEfTuMfM82zkP/aCIo=; b=GzQ9UQBsumIhsWs2W2K2ffiFYxEFSk/uJQDwHsoJE62lVsznZpDAk+rbusDkg4/pXh oYRTWwWf3XXjgqFP4meFBl7xIZslLNSKyF5Y1Nkqv7BIN9qrP/HEZc2GPulKuv+eyy0Q CSLUBGrImnHkarTBPYHhqd4Bz5klN6S1366sxNVa10mTmSfYbuDDmi6EMLlX9llM8fg1 Rm4ZEgKbpo0wmx0loAPNkIBIdsbxwIgizQ0MiPiw3WJfDKD7pBaLfqF/gCCtKxZBp7LS gRHq1IcA4FNU/hF6TniJKOWUVqcOHD5j7pUDrlVzfih8abviJtAdwMVwFP6x0OrQ4GyB ud3w== 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=Kr2xMtMFIyMaJvHp1QmAibj3cqEfTuMfM82zkP/aCIo=; b=nHHTaCFZaE6QoD/OuDLxcFvMeu05SRdgOgaO8m89OLe5t9A/k7m9s00Cki4J0Rtfex Ig5+FtLmNW795Tjg5/aI45IQEN3mmyaes3qJ/Zkj4ImW7glqpDyvk3BM+zTwaZ+jLaOt 35l/zwMbfO9S8q83bhJYoeRpAc+D6M2Hh5CjVByzcy26kXCpTwpEpJo80laOQ9vHDHev u4CugEET9JJFLZL7H9Cyx3WRtMJVRxUNIizvVIIZwetFDfsU6tR51wMGrxjT/99bHUwl TZcxpfNtLm9HVVDOC/BOL+1kSUBrQR/UmPb7DYefhMEJjNUGRoicN6BxRA3iSupEYt0c GR+A== X-Gm-Message-State: AOAM531aEnvK/QuxiidNDp69DFZA0wxPsF/w6vQvmsg7j9LDVC4KNu+q +bP67QJIdgMIjgzgaC1TTfc= X-Google-Smtp-Source: ABdhPJyp9ousXQMjN1mFJdianu0WkJ5NuwBi+VzVmYIuZ9KnREKdbkqv1O8I5j4eIk26Y9GvJf6XJA== X-Received: by 2002:a17:902:834a:b0:14f:3337:35de with SMTP id z10-20020a170902834a00b0014f333735demr1074863pln.8.1648055905736; Wed, 23 Mar 2022 10:18:25 -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 02/13] target/i386/kvm: Free xsave_buf when destroying vCPU Date: Wed, 23 Mar 2022 18:17:40 +0100 Message-Id: <20220323171751.78612-3-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: Philippe Mathieu-Daudé Fix vCPU hot-unplug related leak reported by Valgrind: ==132362== 4,096 bytes in 1 blocks are definitely lost in loss record 8,440 of 8,549 ==132362== at 0x4C3B15F: memalign (vg_replace_malloc.c:1265) ==132362== by 0x4C3B288: posix_memalign (vg_replace_malloc.c:1429) ==132362== by 0xB41195: qemu_try_memalign (memalign.c:53) ==132362== by 0xB41204: qemu_memalign (memalign.c:73) ==132362== by 0x7131CB: kvm_init_xsave (kvm.c:1601) ==132362== by 0x7148ED: kvm_arch_init_vcpu (kvm.c:2031) ==132362== by 0x91D224: kvm_init_vcpu (kvm-all.c:516) ==132362== by 0x9242C9: kvm_vcpu_thread_fn (kvm-accel-ops.c:40) ==132362== by 0xB2EB26: qemu_thread_start (qemu-thread-posix.c:556) ==132362== by 0x7EB2159: start_thread (in /usr/lib64/libpthread-2.28.so) ==132362== by 0x9D45DD2: clone (in /usr/lib64/libc-2.28.so) Reported-by: Mark Kanda Tested-by: Mark Kanda Signed-off-by: Philippe Mathieu-Daudé --- target/i386/kvm/kvm.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index ef2c68a6f4..e93440e774 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -2072,6 +2072,8 @@ int kvm_arch_destroy_vcpu(CPUState *cs) X86CPU *cpu = X86_CPU(cs); CPUX86State *env = &cpu->env; + g_free(env->xsave_buf); + if (cpu->kvm_msr_buf) { g_free(cpu->kvm_msr_buf); cpu->kvm_msr_buf = NULL; From patchwork Wed Mar 23 17:17:41 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: 12789982 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 DE760C433F5 for ; Wed, 23 Mar 2022 17:18:52 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.293997.499670 (Exim 4.92) (envelope-from ) id 1nX4d8-0005zs-4w; Wed, 23 Mar 2022 17:18:42 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 293997.499670; Wed, 23 Mar 2022 17:18:42 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nX4d8-0005zj-1v; Wed, 23 Mar 2022 17:18:42 +0000 Received: by outflank-mailman (input) for mailman id 293997; Wed, 23 Mar 2022 17:18:40 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nX4d5-0004Zy-Vq for xen-devel@lists.xenproject.org; Wed, 23 Mar 2022 17:18:40 +0000 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [2607:f8b0:4864:20::62b]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 475d90b2-aacd-11ec-a405-831a346695d4; Wed, 23 Mar 2022 18:18:39 +0100 (CET) Received: by mail-pl1-x62b.google.com with SMTP id n18so2155934plg.5 for ; Wed, 23 Mar 2022 10:18:39 -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 f14-20020a63380e000000b0038253c4d5casm342070pga.36.2022.03.23.10.18.31 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 23 Mar 2022 10:18:37 -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: 475d90b2-aacd-11ec-a405-831a346695d4 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=bDnsp64dy23km8dL17HIpLYraoqdROmh6JM8WZ9QnxQ=; b=TgUmKBfMFNwRucBsohiY5JY8e9ioh62vGGPA59RsGbh//g7DqYEp6Ab52+czdRAyY8 NP7JPeqO100BsBFOc/Ay4dhLNWNwRFNW03vJZd3riU8UJJWvYnCfPYB4pocDoGekJKUT EzAgZEJWkWoFt7AzL3aW+DcXjjEkdSBB2D7fwnNkzE01zFwCOgVJ7C0f1jNlgcaaL4GN MhaEpPpi7sWKWo2nMSg2I6MHW3HNXf4tqK4IqiAVB37OJeIwt+hp+9OnIiguj3TblBIw fUkPOD4SvMNhJbqs6CnecPk4971sAW1ktFQ1pBjZQ9c/VJNicw0UzYoWQqC6arJevJXa g6rw== 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=bDnsp64dy23km8dL17HIpLYraoqdROmh6JM8WZ9QnxQ=; b=fbqV6WNR+FPinQ/XW/6doC3D1nuV9wYXRFOTJR+sAeLaFABbxMmhxyCmA3Bi9G04tu 86NzRjuyMWj1zX5jynj88mkbqyBY5+DkBJB5JbkKL7N8XlLM3jDa/lk7hULidVo/q+8B BpGKEwKrlXbQQdR0pxEKS4RnL5EgxebgSX/ph3ZDBOqNZfhUmgu3Eg3BqTXncnoCka6D VwCvVxklHIqnsy1DkuQU450Hiz/HkXFQSnlITUePzILRkoYFVmsPuU3SRCyHxkPOYHFB q66u9rb0szn9ea+K4jyuayESbtwO6zemzE0Ic2HfiIidUaAGprrzOYSsyGJuM655FGAV NGQQ== X-Gm-Message-State: AOAM532u0oFQqaJGWcRgOqyqYUZ5Bkcv77PRVrKBiQBNqEI+/DEIYRho WvU94JxXiyn9eusWJncvHXM= X-Google-Smtp-Source: ABdhPJySoRv6SjqjiKCV5e8zH/IZey9o/1x0EduXwu4cNLj3RBjr1JlgyWZQVPeGljHAEFYooB4q3Q== X-Received: by 2002:a17:90a:19d2:b0:1be:d815:477f with SMTP id 18-20020a17090a19d200b001bed815477fmr804349pjj.23.1648055917873; Wed, 23 Mar 2022 10:18:37 -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 , Igor Mammedov Subject: [PATCH v4 03/13] target/i386/hvf: Free resources when vCPU is destroyed Date: Wed, 23 Mar 2022 18:17:41 +0100 Message-Id: <20220323171751.78612-4-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: Philippe Mathieu-Daudé Both xsave_buf and hvf_caps are allocated in hvf_arch_init_vcpu(), free them in hvf_arch_vcpu_destroy(). Reported-by: Mark Kanda Suggested-by: Igor Mammedov Signed-off-by: Philippe Mathieu-Daudé --- target/i386/hvf/hvf.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c index fc12c02fb2..39fa4641b9 100644 --- a/target/i386/hvf/hvf.c +++ b/target/i386/hvf/hvf.c @@ -163,7 +163,9 @@ void hvf_arch_vcpu_destroy(CPUState *cpu) X86CPU *x86_cpu = X86_CPU(cpu); CPUX86State *env = &x86_cpu->env; + g_free(env->xsave_buf); g_free(env->hvf_mmio_buf); + g_free(hvf_state->hvf_caps); } static void init_tsc_freq(CPUX86State *env) From patchwork Wed Mar 23 17:17:42 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: 12789983 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 DBA18C433F5 for ; Wed, 23 Mar 2022 17:19:03 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.294001.499681 (Exim 4.92) (envelope-from ) id 1nX4dJ-0006VS-E1; Wed, 23 Mar 2022 17:18:53 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 294001.499681; Wed, 23 Mar 2022 17:18:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nX4dJ-0006VE-As; Wed, 23 Mar 2022 17:18:53 +0000 Received: by outflank-mailman (input) for mailman id 294001; Wed, 23 Mar 2022 17:18:52 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nX4dH-0004Zy-SL for xen-devel@lists.xenproject.org; Wed, 23 Mar 2022 17:18:51 +0000 Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [2607:f8b0:4864:20::52b]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 4e44ff65-aacd-11ec-a405-831a346695d4; Wed, 23 Mar 2022 18:18:51 +0100 (CET) Received: by mail-pg1-x52b.google.com with SMTP id c11so1654462pgu.11 for ; Wed, 23 Mar 2022 10:18:51 -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 y9-20020a056a00180900b004faa45a2230sm455168pfa.210.2022.03.23.10.18.43 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 23 Mar 2022 10:18:49 -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: 4e44ff65-aacd-11ec-a405-831a346695d4 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=R7g63uMCtTkVNfRXBZkshJ0Wiw4mo6s3K6WysQFVeHQ=; b=EMCnSQO4I48BMsxvvg3i3Lpu7MpcHIBM0VPU1LmYCuVl/RlXBQKnI+aX6Rw5+Otp1s 8IIMhkhQPGFAd7938UkWmV4lBtqZCbG9FdGo8U8RK3KvsKQbLGAa0c0IrtuSOjDJjuSV QFauhI8kpDEcO0CLjjNlJcZcwM0mAHerEv/s6+nsiQVem/Cxo3XuGDnC60sV25zy8Fr3 R6tcgTKLH53w67BvarZnpfob+GRcW9FPC96YnIAXa78jP8pjuvS3DMa/3hObSK9vvZeU ObQvhKX5xWReNbdvvifVE7tLNNOUGXQ9hqL23HPdi01BtJXokaAH3+6DQf7r2EYk52H9 xHiQ== 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=R7g63uMCtTkVNfRXBZkshJ0Wiw4mo6s3K6WysQFVeHQ=; b=t9IAeuKFnloQHtE8HzVp2o8n9iOKyePbYPVpHPfikhxpJBNySLrbMBssI4ol3bUdg+ GjCeobCus0t42jyjjQMfwFC7pJfJincbSv9ZG+7YX3SmgEade9aNwlr6QrG63uJRiTdn P3n+wjscDlTd+5+qvyzEXV41ITWzF23OR5Un6J4TzTqt4eMUUHoQ55TmmwExOFOhyolT i4YWvsPSH4ey6aUhBFQQ6BUlvPAjxAG4ItAdDIndB9h5iCwrbLSFp98VFPFy++aMFgfY LfhRiyKST7raS0NNYbQqjGJlPxhBbAwr42ibFnM/6zoZbBL5oR2oAFtoA6caUzlE9QlR JV2w== X-Gm-Message-State: AOAM533SgP11lGmpzM0yWRV24dj35U63DJ7QzINihm7hBjEku0yX6Cjt papq/YCxXs3usetV5rMe1H0= X-Google-Smtp-Source: ABdhPJwsqttKPum5jvLljX6MsvisPeyZTYUskQFajfuzSlqwRvUxcgnszNBQqCwAUxI0R7csaGC+rA== X-Received: by 2002:a05:6a00:1d85:b0:4fa:9dba:f1f2 with SMTP id z5-20020a056a001d8500b004fa9dbaf1f2mr956040pfw.31.1648055929515; Wed, 23 Mar 2022 10:18:49 -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 Subject: [PATCH v4 04/13] accel/hvf: Remove pointless assertion Date: Wed, 23 Mar 2022 18:17:42 +0100 Message-Id: <20220323171751.78612-5-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: Philippe Mathieu-Daudé Both the comment and the hvf_enabled() check are duplicated at the beginning of hvf_cpu_thread_fn(), which is the thread callback created by hvf_start_vcpu_thread(). Remove. Signed-off-by: Philippe Mathieu-Daudé --- accel/hvf/hvf-accel-ops.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/accel/hvf/hvf-accel-ops.c b/accel/hvf/hvf-accel-ops.c index 54457c76c2..5c33dc602e 100644 --- a/accel/hvf/hvf-accel-ops.c +++ b/accel/hvf/hvf-accel-ops.c @@ -446,12 +446,6 @@ static void hvf_start_vcpu_thread(CPUState *cpu) { char thread_name[VCPU_THREAD_NAME_SIZE]; - /* - * HVF currently does not support TCG, and only runs in - * unrestricted-guest mode. - */ - assert(hvf_enabled()); - cpu->thread = g_malloc0(sizeof(QemuThread)); cpu->halt_cond = g_malloc0(sizeof(QemuCond)); qemu_cond_init(cpu->halt_cond); From patchwork Wed Mar 23 17:17:43 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: 12790006 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 98DAFC433EF for ; Wed, 23 Mar 2022 17:35:30 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.294026.499758 (Exim 4.92) (envelope-from ) id 1nX4tA-0004Rw-Ss; Wed, 23 Mar 2022 17:35:16 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 294026.499758; Wed, 23 Mar 2022 17:35:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nX4tA-0004Rp-PM; Wed, 23 Mar 2022 17:35:16 +0000 Received: by outflank-mailman (input) for mailman id 294026; Wed, 23 Mar 2022 17:35:16 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nX4dT-0004Zy-K0 for xen-devel@lists.xenproject.org; Wed, 23 Mar 2022 17:19:03 +0000 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [2607:f8b0:4864:20::631]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 5561da2e-aacd-11ec-a405-831a346695d4; Wed, 23 Mar 2022 18:19:02 +0100 (CET) Received: by mail-pl1-x631.google.com with SMTP id c23so2183651plo.0 for ; Wed, 23 Mar 2022 10:19:02 -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 u15-20020a056a00098f00b004faa58d44eesm455060pfg.145.2022.03.23.10.18.55 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 23 Mar 2022 10:19:01 -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: 5561da2e-aacd-11ec-a405-831a346695d4 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=0hihgfEmLJPNBEh4WW6rYf49XmgK0ovI41W1a0emuNk=; b=MrdYb7945anCfYH1VRiFA5pAW7S4hoZOOF1Pdv+2ZTrCvIPQ0tdNE6NgZGHvIaYl6F plkh3wIlaqYoXktAcEAtQmOqlHJdMmidt+Oa/wnRaHYaNMUJZ9CkCSrlqjquwFaZdWSC HPnXLzJcabcEufzwkRoVTxfpe1EHQA8+scJQyC9OkHIYWUa2UKWUlEhDYRHbD8EXQtLR hGXTs3LTe0tNECvEc0QQ3gavKzuFIBW5V+W6pGyNgy0F8X1RKcixk5n93FXcTecHiIep G1WrbmTHafbZqiFIsAW0M4VWI5qRob0xYjL9jnDgfVfth7/f271rS43Pm6WxxiTOI/Ta havA== 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=0hihgfEmLJPNBEh4WW6rYf49XmgK0ovI41W1a0emuNk=; b=1OfMaxDMPcPasAsY7fbV2TiWVgXCVPfg6D625qP50cS7Yxzu0413ZYLJSLAkHYKOiN +h2Y+haFNJeWqgk2NRZpPtA1Sqo+SCjPECnctUuPi2WgxLL2c4LMHYjRqX1/FNjsavTw +4HQr3Wm6JCj3DSid5XlvBbvk9+jE+A005PhVLGtyhtfd10d3eJ2nJ9FrocaoH0U3qvf lKzPRkjjk1qS9tdpl9MKGNE35PCOvQmGZizcgZkCT6dzQARAdC3NSwi3LdM6tu4rvkF6 EFmOmretVXFfJYYQ4NwcDPhkfz9ngw+XbH5LVbmKHKqeNTD8RsYKCy/s99+pzI4JXrx0 N+yQ== X-Gm-Message-State: AOAM531itduDtQnQVXu3zavZTAypP/HBBC+IdP2e3emVysmw7Fq/D7SG r+0ok+S8J5O8KWvQQkrYhwQ= X-Google-Smtp-Source: ABdhPJwdV5/nAguIIYnMM8I+otidppMXPEnBBQGuuNIH21Igt/CypcRNRBAVG30eApAdY410n71pzg== X-Received: by 2002:a17:90a:8581:b0:1b2:7541:af6c with SMTP id m1-20020a17090a858100b001b27541af6cmr842235pjn.48.1648055941418; Wed, 23 Mar 2022 10:19:01 -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 Subject: [PATCH v4 05/13] accel/tcg: Init TCG cflags in vCPU thread handler Date: Wed, 23 Mar 2022 18:17:43 +0100 Message-Id: <20220323171751.78612-6-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: Philippe Mathieu-Daudé Move TCG cflags initialization to thread handler. Remove the duplicated assert checks. Signed-off-by: Philippe Mathieu-Daudé --- accel/tcg/tcg-accel-ops-mttcg.c | 5 ++--- accel/tcg/tcg-accel-ops-rr.c | 7 +++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/accel/tcg/tcg-accel-ops-mttcg.c b/accel/tcg/tcg-accel-ops-mttcg.c index ea2b741deb..80609964a6 100644 --- a/accel/tcg/tcg-accel-ops-mttcg.c +++ b/accel/tcg/tcg-accel-ops-mttcg.c @@ -71,6 +71,8 @@ static void *mttcg_cpu_thread_fn(void *arg) assert(tcg_enabled()); g_assert(!icount_enabled()); + tcg_cpu_init_cflags(cpu, current_machine->smp.max_cpus > 1); + rcu_register_thread(); force_rcu.notifier.notify = mttcg_force_rcu; force_rcu.cpu = cpu; @@ -140,9 +142,6 @@ void mttcg_start_vcpu_thread(CPUState *cpu) { char thread_name[VCPU_THREAD_NAME_SIZE]; - g_assert(tcg_enabled()); - tcg_cpu_init_cflags(cpu, current_machine->smp.max_cpus > 1); - cpu->thread = g_new0(QemuThread, 1); cpu->halt_cond = g_malloc0(sizeof(QemuCond)); qemu_cond_init(cpu->halt_cond); diff --git a/accel/tcg/tcg-accel-ops-rr.c b/accel/tcg/tcg-accel-ops-rr.c index b287110766..de8af32af7 100644 --- a/accel/tcg/tcg-accel-ops-rr.c +++ b/accel/tcg/tcg-accel-ops-rr.c @@ -153,7 +153,9 @@ static void *rr_cpu_thread_fn(void *arg) Notifier force_rcu; CPUState *cpu = arg; - assert(tcg_enabled()); + g_assert(tcg_enabled()); + tcg_cpu_init_cflags(cpu, false); + rcu_register_thread(); force_rcu.notify = rr_force_rcu; rcu_add_force_rcu_notifier(&force_rcu); @@ -276,9 +278,6 @@ void rr_start_vcpu_thread(CPUState *cpu) static QemuCond *single_tcg_halt_cond; static QemuThread *single_tcg_cpu_thread; - g_assert(tcg_enabled()); - tcg_cpu_init_cflags(cpu, false); - if (!single_tcg_cpu_thread) { cpu->thread = g_new0(QemuThread, 1); cpu->halt_cond = g_new0(QemuCond, 1); From patchwork Wed Mar 23 17:17:44 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: 12790007 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 14F6CC433EF for ; Wed, 23 Mar 2022 17:36:08 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.294031.499769 (Exim 4.92) (envelope-from ) id 1nX4tq-00051q-5w; Wed, 23 Mar 2022 17:35:58 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 294031.499769; Wed, 23 Mar 2022 17:35:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nX4tq-00051j-1v; Wed, 23 Mar 2022 17:35:58 +0000 Received: by outflank-mailman (input) for mailman id 294031; Wed, 23 Mar 2022 17:35:57 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nX4df-0004Zy-AL for xen-devel@lists.xenproject.org; Wed, 23 Mar 2022 17:19:15 +0000 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [2607:f8b0:4864:20::634]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 5c6eb699-aacd-11ec-a405-831a346695d4; Wed, 23 Mar 2022 18:19:14 +0100 (CET) Received: by mail-pl1-x634.google.com with SMTP id x2so2149951plm.7 for ; Wed, 23 Mar 2022 10:19: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 5-20020a17090a1a4500b001c54dc9061esm266865pjl.51.2022.03.23.10.19.07 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 23 Mar 2022 10:19: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: 5c6eb699-aacd-11ec-a405-831a346695d4 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=ARhouW8OXYXIRPQjyAafjquDP6FUc0ZjucITbhHVg5E=; b=qrmYjLiXax41wynkldUk46+CTEMhEwNtecSEajm0opdutnFDwZFnb5R/0qKYGW240d Xfip76+lUKk9ny0xZ6YhE00J4TKeGUMnJ8SoGN13GNg0qwOnowPKMtRWHdotb/gtDf5D MtRHQsTElQmEIKX9ZZdHDbTe5WtCrvk7tdOYhyQM3qFOeBHzl9lmse0tjqCeQBy7UGAO ybhOz4GI6Y3MO4ukQmThEULFFMRC2oMeKASkkcCP/dzLf46Qozna5NyY8TjPqJE1DQEs GnXGhPd1I7iqkj+/YcGjrCQJ3XokcBCDvDTZ5EW8eBPnuLOf/HAk1jK7Hlg+t8pJiPz7 v+sQ== 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=ARhouW8OXYXIRPQjyAafjquDP6FUc0ZjucITbhHVg5E=; b=lMnf/fuGLay5TZ7Z5DIGDug+/cODlT1IjdyDM59/QXU+QMTqdnIIxy07ralCIyOr5c IuDH3RibmXuhH2l4s7XoRzR3Ac5fAvmkQthoB043MT0rQ28F/6Nq4xfiTxIsSuY6ILbG 1d4LE/rmsI3NYKZgd695trQfQOFSBmzoPovEAwKz0AUz4fPNkoU2JQKGq34xUlDh+nZB f24u2ikLKhTWUM623h26ZfFrQGXX4mdjhMlkmPtvmu0e2oevHG65C8KW7qBp0XHo9+SZ j6R/fec/yQP+MmWXdsU8HsOPYOZQ83otJJJkSqR66+oe9cn9kGuSfAj/m1mj0L3PtrEE iQtQ== X-Gm-Message-State: AOAM5317H5StRMbcyzH6XpSPNoev3jMad4DdnMfxQoCBIZXiVKGjZvbq oCwrGA1LBaCC9/qucDvcwRg= X-Google-Smtp-Source: ABdhPJzLdZtFm+tMEOoscqkjQAgJQZm9yuu7A4C9NQT5lLkj2BUY8yeJrCTrFbO4ucEGmuTjUPWoUA== X-Received: by 2002:a17:902:bf07:b0:14f:a3a7:97a0 with SMTP id bi7-20020a170902bf0700b0014fa3a797a0mr1005569plb.105.1648055953255; Wed, 23 Mar 2022 10:19: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 Subject: [PATCH v4 06/13] accel/tcg: Reorganize tcg_accel_ops_init() Date: Wed, 23 Mar 2022 18:17:44 +0100 Message-Id: <20220323171751.78612-7-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: Philippe Mathieu-Daudé Reorg TCG AccelOpsClass initialization to emphasis icount mode share more code with single-threaded TCG. Signed-off-by: Philippe Mathieu-Daudé --- accel/tcg/tcg-accel-ops.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/accel/tcg/tcg-accel-ops.c b/accel/tcg/tcg-accel-ops.c index ea7dcad674..d2181ea1e5 100644 --- a/accel/tcg/tcg-accel-ops.c +++ b/accel/tcg/tcg-accel-ops.c @@ -98,16 +98,17 @@ static void tcg_accel_ops_init(AccelOpsClass *ops) ops->create_vcpu_thread = mttcg_start_vcpu_thread; ops->kick_vcpu_thread = mttcg_kick_vcpu_thread; ops->handle_interrupt = tcg_handle_interrupt; - } else if (icount_enabled()) { - ops->create_vcpu_thread = rr_start_vcpu_thread; - ops->kick_vcpu_thread = rr_kick_vcpu_thread; - ops->handle_interrupt = icount_handle_interrupt; - ops->get_virtual_clock = icount_get; - ops->get_elapsed_ticks = icount_get; } else { ops->create_vcpu_thread = rr_start_vcpu_thread; ops->kick_vcpu_thread = rr_kick_vcpu_thread; - ops->handle_interrupt = tcg_handle_interrupt; + + if (icount_enabled()) { + ops->handle_interrupt = icount_handle_interrupt; + ops->get_virtual_clock = icount_get; + ops->get_elapsed_ticks = icount_get; + } else { + ops->handle_interrupt = tcg_handle_interrupt; + } } } From patchwork Wed Mar 23 17:17:45 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: 12790005 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 9F82CC433EF for ; Wed, 23 Mar 2022 17:34:12 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.294015.499736 (Exim 4.92) (envelope-from ) id 1nX4ru-0002wI-W8; Wed, 23 Mar 2022 17:33:58 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 294015.499736; Wed, 23 Mar 2022 17:33:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nX4ru-0002wB-Rv; Wed, 23 Mar 2022 17:33:58 +0000 Received: by outflank-mailman (input) for mailman id 294015; Wed, 23 Mar 2022 17:33:57 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nX4dr-0004Zy-E8 for xen-devel@lists.xenproject.org; Wed, 23 Mar 2022 17:19:27 +0000 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [2607:f8b0:4864:20::434]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 639b15f3-aacd-11ec-a405-831a346695d4; Wed, 23 Mar 2022 18:19:26 +0100 (CET) Received: by mail-pf1-x434.google.com with SMTP id u17so1963987pfk.11 for ; Wed, 23 Mar 2022 10:19:26 -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 a24-20020a637f18000000b003821e17819csm354438pgd.61.2022.03.23.10.19.19 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 23 Mar 2022 10:19:24 -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: 639b15f3-aacd-11ec-a405-831a346695d4 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=qDaNpZGuS1pck7ljrYFEMbUPV6qyv4FTweWO+b6dthQ=; b=T/qLqQeIJbWYsc9iaC9cBJMrxMVXpFG/QUiJyPoZd2LdVpzgu4IXrjsjtgh7JucAvy K7XpwsgzEr4aysFsdfXZmw3r4NYiJ3DWcc8JZSOA6Tl3BokPzJQNj2so5OQV1hh6HwEd K1QxKLSW49T2dyO8ay7JL+g882pp7zrdo93r7w/Lf9Ytie2vCQEYjBetUSMwG2E36vDl O1T8FHb+t6UP2pO29Px3c/CN3Z5Qpup501aDNB/0R3S7yzRNJBBBqU6RsNi2V43JnUir +2yzv/A6XJFzT3jeRvNmug8zR6Gv0G3QKmEJL2xM7jyr2axrPlstTpbbBI6cVPxAa6d7 uTWA== 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=qDaNpZGuS1pck7ljrYFEMbUPV6qyv4FTweWO+b6dthQ=; b=wp2rxRnMbJRes1RM7Hq5I1eNTJ4aGEiMsNJlYoAiQ7bZbMe3lOZ7vr5vQNyNusJMLQ 7klhajUDgZHKsPsgeiRxah2Rbc/Oe6JebIJqE6vGiifbPcA5oXeic5W9udJuOW4dkTdy MasP9ha1TqXBcRayTGxpXE8b5/7/Tkfm4FeUqZI5fysgt2pM5zg0BhBUUDUO7Yh2iclE G67aXQnGMI5J4OSLBJxLHdJh+5sd/YyZF3wZKbjJjy8yeCHgUOp+FM5qHe97fsTAJZrI 3eL9/0Eyi003bWEOd5dSeIAR874vaGeFeXehg6EV7L36QBSKHZ3bRWvKiLBuoVfUsaBi NgBQ== X-Gm-Message-State: AOAM530QHjQiYOnPXAzYIi5ejLX19J0W43QZjWeqqiFWHYx+bQZy92vi iCJOSxuF7UeLqSW1F/A5Ghw= X-Google-Smtp-Source: ABdhPJysELA1SacEi6NLWr6VDuEztyIdr+gkkW330J+PSAAiBOd3a1EdmuP7lIO3WbruDTaR69cscQ== X-Received: by 2002:a63:cf09:0:b0:372:d564:8024 with SMTP id j9-20020a63cf09000000b00372d5648024mr705074pgg.251.1648055965298; Wed, 23 Mar 2022 10:19:25 -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 Subject: [PATCH v4 07/13] accel-ops: Introduce create_vcpu_thread_precheck / postcheck handlers Date: Wed, 23 Mar 2022 18:17:45 +0100 Message-Id: <20220323171751.78612-8-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: Philippe Mathieu-Daudé Introduce precheck/postcheck handlers which will help to refactor code common to the various create_vcpu_thread() implementations. Signed-off-by: Philippe Mathieu-Daudé --- include/sysemu/accel-ops.h | 4 ++++ softmmu/cpus.c | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/include/sysemu/accel-ops.h b/include/sysemu/accel-ops.h index 6013c9444c..26b542d35c 100644 --- a/include/sysemu/accel-ops.h +++ b/include/sysemu/accel-ops.h @@ -31,6 +31,10 @@ struct AccelOpsClass { bool (*cpus_are_resettable)(void); void (*create_vcpu_thread)(CPUState *cpu); /* MANDATORY NON-NULL */ + /* If non-NULL, return whether common vCPU thread must be created */ + bool (*create_vcpu_thread_precheck)(CPUState *cpu); + void (*create_vcpu_thread_postcheck)(CPUState *cpu); + void (*kick_vcpu_thread)(CPUState *cpu); bool (*cpu_thread_is_idle)(CPUState *cpu); diff --git a/softmmu/cpus.c b/softmmu/cpus.c index 7b75bb66d5..857e2081ba 100644 --- a/softmmu/cpus.c +++ b/softmmu/cpus.c @@ -637,7 +637,13 @@ void qemu_init_vcpu(CPUState *cpu) /* accelerators all implement the AccelOpsClass */ g_assert(cpus_accel != NULL && cpus_accel->create_vcpu_thread != NULL); - cpus_accel->create_vcpu_thread(cpu); + if (cpus_accel->create_vcpu_thread_precheck == NULL + || cpus_accel->create_vcpu_thread_precheck(cpu)) { + cpus_accel->create_vcpu_thread(cpu); + } + if (cpus_accel->create_vcpu_thread_postcheck) { + cpus_accel->create_vcpu_thread_postcheck(cpu); + } while (!cpu->created) { qemu_cond_wait(&qemu_cpu_cond, &qemu_global_mutex); From patchwork Wed Mar 23 17:17:46 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: 12789997 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 38074C433EF for ; Wed, 23 Mar 2022 17:28:05 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.294007.499714 (Exim 4.92) (envelope-from ) id 1nX4lv-0001Es-0m; Wed, 23 Mar 2022 17:27:47 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 294007.499714; Wed, 23 Mar 2022 17:27:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nX4lu-0001El-Si; Wed, 23 Mar 2022 17:27:46 +0000 Received: by outflank-mailman (input) for mailman id 294007; Wed, 23 Mar 2022 17:27:46 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nX4e3-0004Zy-1B for xen-devel@lists.xenproject.org; Wed, 23 Mar 2022 17:19:39 +0000 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [2607:f8b0:4864:20::632]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 6a8ccecb-aacd-11ec-a405-831a346695d4; Wed, 23 Mar 2022 18:19:38 +0100 (CET) Received: by mail-pl1-x632.google.com with SMTP id c23so2185288plo.0 for ; Wed, 23 Mar 2022 10:19:38 -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 d25-20020a639919000000b00364f999aed5sm349409pge.20.2022.03.23.10.19.31 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 23 Mar 2022 10:19:36 -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: 6a8ccecb-aacd-11ec-a405-831a346695d4 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=hGzoIEiqotEx27Bg+Z4eL5zpKSfKxDxE5VGRYeUpF1U=; b=YN2nPW6qFv/FXMaZbHoge7dvyFY38/0TL7t4FHhvZ3ROq4ndXz7aVe/WYlNC1die01 TcD+kFy/xidXVPGx7gpqZ75SywkLL2EYPJoDBotF8TIRl44RYN5JTM1qKjZv3d6GIfqU jWotsaKHFfCdSkhPSpjxx+SuvENG8Rj/Mv3l0DwhQfohsPpFU6t73UPPj8CSrbQfuBkd 9Z/VXAQWYd7J2zxrjtJ/gWD5iowxhsrQ7vwQGuFXZNP0fMUeSz4fBHXmC/cKAe6dYlVs NCh7inykD23K3nAQkmHK7E/YkkRS5g4L8ZmGYcKNVOwgDWWwZ2QenCCnu2L1vwreGob1 13sg== 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=hGzoIEiqotEx27Bg+Z4eL5zpKSfKxDxE5VGRYeUpF1U=; b=rBCS/tiuUZ4/diJtDaF+KZ8G/B7f7HuHnnjl/H+WBQMVSwrRZ0WaQik0FmkAodny5a 5axPAz7gEVBfOig4Un2xJWLbvR746jpfF+DKRC0gJ8tnGjgWlMg5FbapV6Tw4/aiLMVf fWg1J+bvXeG0+gaxEMlg2jXVteSOWUEmVZFZrXrueFlWzE8spKikbe365aUJQxTU5XVy xhrshLgVPpnGNt0soQv6mE4MT6oj1Qentj3HPFwupLXxTNyGVTLo4YX5vbP1BZ/4xb3Y jrZXTF4fBp7DLZVTu76XBdG+UGz+u4BtS7duew9euWISBRBwDYow05IG9G8r5oxlh55u I5QQ== X-Gm-Message-State: AOAM530snBK1T5Ljo3eIilyrOH8LinSzF8IvT+UClhtlkQ616SHevwYP Pr9lSGQarWlbEHUGd2bWVLc= X-Google-Smtp-Source: ABdhPJypHL2FuS5xBRJ7IZra6e8WHCycd0JJ50I5gNrC37pYhlUHgXYCXbDEv97OJjTv0XckGdi+gQ== X-Received: by 2002:a17:902:8543:b0:154:9588:52ab with SMTP id d3-20020a170902854300b00154958852abmr1177032plo.50.1648055976951; Wed, 23 Mar 2022 10:19:36 -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 Subject: [PATCH v4 08/13] accel/tcg: Extract rr_create_vcpu_thread_precheck() Date: Wed, 23 Mar 2022 18:17:46 +0100 Message-Id: <20220323171751.78612-9-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: Philippe Mathieu-Daudé We are going to extract common pattern from rr_start_vcpu_thread(). First extract the rr_create_vcpu_thread_precheck() helper. Signed-off-by: Philippe Mathieu-Daudé --- accel/tcg/tcg-accel-ops-rr.c | 7 +++++++ accel/tcg/tcg-accel-ops-rr.h | 1 + 2 files changed, 8 insertions(+) diff --git a/accel/tcg/tcg-accel-ops-rr.c b/accel/tcg/tcg-accel-ops-rr.c index de8af32af7..3da684b8e6 100644 --- a/accel/tcg/tcg-accel-ops-rr.c +++ b/accel/tcg/tcg-accel-ops-rr.c @@ -272,6 +272,13 @@ static void *rr_cpu_thread_fn(void *arg) return NULL; } +static QemuThread *single_tcg_cpu_thread; + +bool rr_create_vcpu_thread_precheck(CPUState *cpu) +{ + return !single_tcg_cpu_thread; +} + void rr_start_vcpu_thread(CPUState *cpu) { char thread_name[VCPU_THREAD_NAME_SIZE]; diff --git a/accel/tcg/tcg-accel-ops-rr.h b/accel/tcg/tcg-accel-ops-rr.h index 54f6ae6e86..e2273b66d4 100644 --- a/accel/tcg/tcg-accel-ops-rr.h +++ b/accel/tcg/tcg-accel-ops-rr.h @@ -15,6 +15,7 @@ /* Kick all RR vCPUs. */ void rr_kick_vcpu_thread(CPUState *unused); +bool rr_create_vcpu_thread_precheck(CPUState *cpu); /* start the round robin vcpu thread */ void rr_start_vcpu_thread(CPUState *cpu); From patchwork Wed Mar 23 17:17:47 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: 12789984 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 79423C433EF for ; Wed, 23 Mar 2022 17:20:06 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.294003.499692 (Exim 4.92) (envelope-from ) id 1nX4eH-0007TR-Pp; Wed, 23 Mar 2022 17:19:53 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 294003.499692; Wed, 23 Mar 2022 17:19:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nX4eH-0007TK-MM; Wed, 23 Mar 2022 17:19:53 +0000 Received: by outflank-mailman (input) for mailman id 294003; Wed, 23 Mar 2022 17:19:52 +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 1nX4eG-0007T4-Bn for xen-devel@lists.xenproject.org; Wed, 23 Mar 2022 17:19:52 +0000 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [2607:f8b0:4864:20::434]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 71c1a642-aacd-11ec-8fbc-03012f2f19d4; Wed, 23 Mar 2022 18:19:50 +0100 (CET) Received: by mail-pf1-x434.google.com with SMTP id u22so1978514pfg.6 for ; Wed, 23 Mar 2022 10:19:50 -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 h10-20020a056a00230a00b004faa0f67c3esm515084pfh.23.2022.03.23.10.19.42 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 23 Mar 2022 10:19:48 -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: 71c1a642-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=pYl7PFx6HJtSTXEwRh0v4jjLcljevjvNsnI/ABIkNpc=; b=AVu5Njemv6HLmOsdKQ+VfG9+68Y75QCUvSBWjlFuBjz/HNiGqkYCNDiZx3nYu9plDG UF7gb7VVoz34sG1mev5yCvoNrsQ1z8IWtvbq8+aDO+pYuGeK/DFV2qzT8BBc6poAy1Ll lOEl1BAafr+0lbjC4zH66PCSBb7+R1xkhdgQxWxYoeJlwK3WLMcfEGBgnF+sjnGbStK4 a9SLdMMRZo/bJUh14Z6gnY4UjA5DdwaI6pbaa9fmRZtN7HA6P8qF3KsTh8w0VYYU2kuV 0AUyXjYRd81y11ZlUPISW8rgQ5pc3ziJB920CpKR3PJuR1zGs+XHXjL8xkJmc2RZcs4z JHdg== 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=pYl7PFx6HJtSTXEwRh0v4jjLcljevjvNsnI/ABIkNpc=; b=Z6vpjQOT/GhD6PV5F1enpK2ZvHz6mol000TVSQS20LdBx2kMKuJ09TKd13vhbxw/FK 1Z5fOn7p6tP38cjt1nibFz0DgqP2li6FKvS/cdb1zYB1fOqOPLfMTjkIDahp7b9cMHSa SBWBQUiql7h1mVIXzArBkSwpP82fLtpr/D+jSil1Z69iwyF+ASnVTKUKDKT72opp33/K iCcd2kLWJ/a1FUKEgWFx6BtnV4jDAq1kDSsLSSAKwL+ZUQ12Tnj/xdnVzoF+w4Y4VlwF EuRz44JhyvLVqEOsr02dMhadlVlAHPA1SwVOaaweEL+z/bTe39i50ioVRZUzHwW9nuJA OkAA== X-Gm-Message-State: AOAM530ONtrQ//u9fzkcHZ82HdbvAMjV9eI4BFbMm3JG1mFT64QpqogR X3kE8QooYLq2yDJILDpByCY= X-Google-Smtp-Source: ABdhPJxwe0fvqNFuFM35WUTu/PR9vPZnoQaBkNABrXApSmPztgel1hVfca2uBIR7EEKKmqRyCL7USA== X-Received: by 2002:a63:4d56:0:b0:382:9ad9:d28d with SMTP id n22-20020a634d56000000b003829ad9d28dmr691452pgl.45.1648055988955; Wed, 23 Mar 2022 10:19:48 -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 Subject: [PATCH v4 09/13] accel/all: Extract common_vcpu_thread_create() Date: Wed, 23 Mar 2022 18:17:47 +0100 Message-Id: <20220323171751.78612-10-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: Philippe Mathieu-Daudé All accelerators implement a very similar create_vcpu_thread() handler. Extract the common part as common_vcpu_thread_create(), which only requires the AccelOpsClass::vcpu_thread_fn() routine and the accelerator AccelOpsClass::thread_name for debugging purpose. The single exception is TCG/RR which re-use a single vCPU. Have it use the same logic by using the .precheck/.postcheck handlers. Signed-off-by: Philippe Mathieu-Daudé --- accel/accel-softmmu.c | 2 +- accel/dummy-cpus.c | 15 +-------------- accel/hvf/hvf-accel-ops.c | 18 +++--------------- accel/kvm/kvm-accel-ops.c | 17 +++-------------- accel/qtest/qtest.c | 3 ++- accel/tcg/tcg-accel-ops-mttcg.c | 22 +--------------------- accel/tcg/tcg-accel-ops-mttcg.h | 3 +-- accel/tcg/tcg-accel-ops-rr.c | 21 +++------------------ accel/tcg/tcg-accel-ops-rr.h | 6 ++++-- accel/tcg/tcg-accel-ops.c | 6 ++++-- accel/xen/xen-all.c | 2 +- include/sysemu/accel-ops.h | 3 ++- include/sysemu/cpus.h | 4 ++-- softmmu/cpus.c | 23 ++++++++++++++++++++--- target/i386/hax/hax-accel-ops.c | 20 ++------------------ target/i386/nvmm/nvmm-accel-ops.c | 17 +++-------------- target/i386/whpx/whpx-accel-ops.c | 20 +++----------------- 17 files changed, 56 insertions(+), 146 deletions(-) diff --git a/accel/accel-softmmu.c b/accel/accel-softmmu.c index 67276e4f52..7800df0234 100644 --- a/accel/accel-softmmu.c +++ b/accel/accel-softmmu.c @@ -77,7 +77,7 @@ void accel_init_ops_interfaces(AccelClass *ac) /* * all accelerators need to define ops, providing at least a mandatory - * non-NULL create_vcpu_thread operation. + * non-NULL vcpu_thread_fn operation. */ g_assert(ops != NULL); if (ops->ops_init) { diff --git a/accel/dummy-cpus.c b/accel/dummy-cpus.c index 10429fdfb2..9840057969 100644 --- a/accel/dummy-cpus.c +++ b/accel/dummy-cpus.c @@ -18,7 +18,7 @@ #include "qemu/main-loop.h" #include "hw/core/cpu.h" -static void *dummy_cpu_thread_fn(void *arg) +void *dummy_vcpu_thread_fn(void *arg) { CPUState *cpu = arg; sigset_t waitset; @@ -57,16 +57,3 @@ static void *dummy_cpu_thread_fn(void *arg) rcu_unregister_thread(); return NULL; } - -void dummy_start_vcpu_thread(CPUState *cpu) -{ - char thread_name[VCPU_THREAD_NAME_SIZE]; - - cpu->thread = g_malloc0(sizeof(QemuThread)); - cpu->halt_cond = g_malloc0(sizeof(QemuCond)); - qemu_cond_init(cpu->halt_cond); - snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/DUMMY", - cpu->cpu_index); - qemu_thread_create(cpu->thread, thread_name, dummy_cpu_thread_fn, cpu, - QEMU_THREAD_JOINABLE); -} diff --git a/accel/hvf/hvf-accel-ops.c b/accel/hvf/hvf-accel-ops.c index 5c33dc602e..91d65036b4 100644 --- a/accel/hvf/hvf-accel-ops.c +++ b/accel/hvf/hvf-accel-ops.c @@ -442,25 +442,13 @@ static void *hvf_cpu_thread_fn(void *arg) return NULL; } -static void hvf_start_vcpu_thread(CPUState *cpu) -{ - char thread_name[VCPU_THREAD_NAME_SIZE]; - - cpu->thread = g_malloc0(sizeof(QemuThread)); - cpu->halt_cond = g_malloc0(sizeof(QemuCond)); - qemu_cond_init(cpu->halt_cond); - - snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/HVF", - cpu->cpu_index); - qemu_thread_create(cpu->thread, thread_name, hvf_cpu_thread_fn, - cpu, QEMU_THREAD_JOINABLE); -} - static void hvf_accel_ops_class_init(ObjectClass *oc, void *data) { AccelOpsClass *ops = ACCEL_OPS_CLASS(oc); - ops->create_vcpu_thread = hvf_start_vcpu_thread; + ops->thread_name = "HVF"; + ops->vcpu_thread_fn = hvf_cpu_thread_fn; + ops->kick_vcpu_thread = hvf_kick_vcpu_thread; ops->synchronize_post_reset = hvf_cpu_synchronize_post_reset; diff --git a/accel/kvm/kvm-accel-ops.c b/accel/kvm/kvm-accel-ops.c index c4244a23c6..3d13efce0f 100644 --- a/accel/kvm/kvm-accel-ops.c +++ b/accel/kvm/kvm-accel-ops.c @@ -61,19 +61,6 @@ static void *kvm_vcpu_thread_fn(void *arg) return NULL; } -static void kvm_start_vcpu_thread(CPUState *cpu) -{ - char thread_name[VCPU_THREAD_NAME_SIZE]; - - cpu->thread = g_malloc0(sizeof(QemuThread)); - cpu->halt_cond = g_malloc0(sizeof(QemuCond)); - qemu_cond_init(cpu->halt_cond); - snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/KVM", - cpu->cpu_index); - qemu_thread_create(cpu->thread, thread_name, kvm_vcpu_thread_fn, - cpu, QEMU_THREAD_JOINABLE); -} - static bool kvm_vcpu_thread_is_idle(CPUState *cpu) { return !kvm_halt_in_kernel(); @@ -88,7 +75,9 @@ static void kvm_accel_ops_class_init(ObjectClass *oc, void *data) { AccelOpsClass *ops = ACCEL_OPS_CLASS(oc); - ops->create_vcpu_thread = kvm_start_vcpu_thread; + ops->thread_name = "KVM"; + ops->vcpu_thread_fn = kvm_vcpu_thread_fn; + ops->cpu_thread_is_idle = kvm_vcpu_thread_is_idle; ops->cpus_are_resettable = kvm_cpus_are_resettable; ops->synchronize_post_reset = kvm_cpu_synchronize_post_reset; diff --git a/accel/qtest/qtest.c b/accel/qtest/qtest.c index f6056ac836..1d0b1c855c 100644 --- a/accel/qtest/qtest.c +++ b/accel/qtest/qtest.c @@ -50,7 +50,8 @@ static void qtest_accel_ops_class_init(ObjectClass *oc, void *data) { AccelOpsClass *ops = ACCEL_OPS_CLASS(oc); - ops->create_vcpu_thread = dummy_start_vcpu_thread; + ops->vcpu_thread_fn = dummy_vcpu_thread_fn; + ops->get_virtual_clock = qtest_get_virtual_clock; }; diff --git a/accel/tcg/tcg-accel-ops-mttcg.c b/accel/tcg/tcg-accel-ops-mttcg.c index 80609964a6..c7836332d7 100644 --- a/accel/tcg/tcg-accel-ops-mttcg.c +++ b/accel/tcg/tcg-accel-ops-mttcg.c @@ -63,7 +63,7 @@ static void mttcg_force_rcu(Notifier *notify, void *data) * current CPUState for a given thread. */ -static void *mttcg_cpu_thread_fn(void *arg) +void *mttcg_vcpu_thread_fn(void *arg) { MttcgForceRcuNotifier force_rcu; CPUState *cpu = arg; @@ -137,23 +137,3 @@ void mttcg_kick_vcpu_thread(CPUState *cpu) { cpu_exit(cpu); } - -void mttcg_start_vcpu_thread(CPUState *cpu) -{ - char thread_name[VCPU_THREAD_NAME_SIZE]; - - cpu->thread = g_new0(QemuThread, 1); - cpu->halt_cond = g_malloc0(sizeof(QemuCond)); - qemu_cond_init(cpu->halt_cond); - - /* create a thread per vCPU with TCG (MTTCG) */ - snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/TCG", - cpu->cpu_index); - - qemu_thread_create(cpu->thread, thread_name, mttcg_cpu_thread_fn, - cpu, QEMU_THREAD_JOINABLE); - -#ifdef _WIN32 - cpu->hThread = qemu_thread_get_handle(cpu->thread); -#endif -} diff --git a/accel/tcg/tcg-accel-ops-mttcg.h b/accel/tcg/tcg-accel-ops-mttcg.h index 9fdc5a2ab5..b61aff5c1d 100644 --- a/accel/tcg/tcg-accel-ops-mttcg.h +++ b/accel/tcg/tcg-accel-ops-mttcg.h @@ -13,7 +13,6 @@ /* kick MTTCG vCPU thread */ void mttcg_kick_vcpu_thread(CPUState *cpu); -/* start an mttcg vCPU thread */ -void mttcg_start_vcpu_thread(CPUState *cpu); +void *mttcg_vcpu_thread_fn(void *arg); #endif /* TCG_CPUS_MTTCG_H */ diff --git a/accel/tcg/tcg-accel-ops-rr.c b/accel/tcg/tcg-accel-ops-rr.c index 3da684b8e6..006b787289 100644 --- a/accel/tcg/tcg-accel-ops-rr.c +++ b/accel/tcg/tcg-accel-ops-rr.c @@ -148,7 +148,7 @@ static void rr_force_rcu(Notifier *notify, void *data) * elsewhere. */ -static void *rr_cpu_thread_fn(void *arg) +void *rr_vcpu_thread_fn(void *arg) { Notifier force_rcu; CPUState *cpu = arg; @@ -279,28 +279,13 @@ bool rr_create_vcpu_thread_precheck(CPUState *cpu) return !single_tcg_cpu_thread; } -void rr_start_vcpu_thread(CPUState *cpu) +void rr_create_vcpu_thread_postcheck(CPUState *cpu) { - char thread_name[VCPU_THREAD_NAME_SIZE]; static QemuCond *single_tcg_halt_cond; - static QemuThread *single_tcg_cpu_thread; - - if (!single_tcg_cpu_thread) { - cpu->thread = g_new0(QemuThread, 1); - cpu->halt_cond = g_new0(QemuCond, 1); - qemu_cond_init(cpu->halt_cond); - - /* share a single thread for all cpus with TCG */ - snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "ALL CPUs/TCG"); - qemu_thread_create(cpu->thread, thread_name, - rr_cpu_thread_fn, - cpu, QEMU_THREAD_JOINABLE); + if (! single_tcg_cpu_thread) { single_tcg_halt_cond = cpu->halt_cond; single_tcg_cpu_thread = cpu->thread; -#ifdef _WIN32 - cpu->hThread = qemu_thread_get_handle(cpu->thread); -#endif } else { /* we share the thread */ cpu->thread = single_tcg_cpu_thread; diff --git a/accel/tcg/tcg-accel-ops-rr.h b/accel/tcg/tcg-accel-ops-rr.h index e2273b66d4..a1e75e7afb 100644 --- a/accel/tcg/tcg-accel-ops-rr.h +++ b/accel/tcg/tcg-accel-ops-rr.h @@ -16,7 +16,9 @@ void rr_kick_vcpu_thread(CPUState *unused); bool rr_create_vcpu_thread_precheck(CPUState *cpu); -/* start the round robin vcpu thread */ -void rr_start_vcpu_thread(CPUState *cpu); +void rr_create_vcpu_thread_postcheck(CPUState *cpu); +bool rr_destroy_vcpu_thread_precheck(CPUState *cpu); + +void *rr_vcpu_thread_fn(void *arg); #endif /* TCG_CPUS_RR_H */ diff --git a/accel/tcg/tcg-accel-ops.c b/accel/tcg/tcg-accel-ops.c index d2181ea1e5..127dd6fee5 100644 --- a/accel/tcg/tcg-accel-ops.c +++ b/accel/tcg/tcg-accel-ops.c @@ -95,11 +95,13 @@ void tcg_handle_interrupt(CPUState *cpu, int mask) static void tcg_accel_ops_init(AccelOpsClass *ops) { if (qemu_tcg_mttcg_enabled()) { - ops->create_vcpu_thread = mttcg_start_vcpu_thread; + ops->vcpu_thread_fn = mttcg_vcpu_thread_fn; ops->kick_vcpu_thread = mttcg_kick_vcpu_thread; ops->handle_interrupt = tcg_handle_interrupt; } else { - ops->create_vcpu_thread = rr_start_vcpu_thread; + ops->vcpu_thread_fn = rr_vcpu_thread_fn; + ops->create_vcpu_thread_precheck = rr_create_vcpu_thread_precheck; + ops->create_vcpu_thread_postcheck = rr_create_vcpu_thread_postcheck; ops->kick_vcpu_thread = rr_kick_vcpu_thread; if (icount_enabled()) { diff --git a/accel/xen/xen-all.c b/accel/xen/xen-all.c index 69aa7d018b..ef40f626e2 100644 --- a/accel/xen/xen-all.c +++ b/accel/xen/xen-all.c @@ -219,7 +219,7 @@ static void xen_accel_ops_class_init(ObjectClass *oc, void *data) { AccelOpsClass *ops = ACCEL_OPS_CLASS(oc); - ops->create_vcpu_thread = dummy_start_vcpu_thread; + ops->vcpu_thread_fn = dummy_vcpu_thread_fn; } static const TypeInfo xen_accel_ops_type = { diff --git a/include/sysemu/accel-ops.h b/include/sysemu/accel-ops.h index 26b542d35c..caf337f61f 100644 --- a/include/sysemu/accel-ops.h +++ b/include/sysemu/accel-ops.h @@ -30,7 +30,8 @@ struct AccelOpsClass { bool (*cpus_are_resettable)(void); - void (*create_vcpu_thread)(CPUState *cpu); /* MANDATORY NON-NULL */ + const char *thread_name; + void *(*vcpu_thread_fn)(void *arg); /* MANDATORY NON-NULL */ /* If non-NULL, return whether common vCPU thread must be created */ bool (*create_vcpu_thread_precheck)(CPUState *cpu); void (*create_vcpu_thread_postcheck)(CPUState *cpu); diff --git a/include/sysemu/cpus.h b/include/sysemu/cpus.h index b5c87d48b3..bf5629c58f 100644 --- a/include/sysemu/cpus.h +++ b/include/sysemu/cpus.h @@ -9,8 +9,8 @@ void cpus_register_accel(const AccelOpsClass *i); /* accel/dummy-cpus.c */ -/* Create a dummy vcpu for AccelOpsClass->create_vcpu_thread */ -void dummy_start_vcpu_thread(CPUState *); +/* Create a dummy vcpu for AccelOpsClass->vcpu_thread_fn */ +void *dummy_vcpu_thread_fn(void *arg); /* interface available for cpus accelerator threads */ diff --git a/softmmu/cpus.c b/softmmu/cpus.c index 857e2081ba..cf430ac486 100644 --- a/softmmu/cpus.c +++ b/softmmu/cpus.c @@ -601,6 +601,22 @@ void resume_all_vcpus(void) } } +static void common_vcpu_thread_create(CPUState *cpu) +{ + char thread_name[VCPU_THREAD_NAME_SIZE]; + + cpu->thread = g_new0(QemuThread, 1); + cpu->halt_cond = g_new0(QemuCond, 1); + qemu_cond_init(cpu->halt_cond); + snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/%s", + cpu->cpu_index, cpus_accel->thread_name ?: "DUMMY"); + qemu_thread_create(cpu->thread, thread_name, cpus_accel->vcpu_thread_fn, + cpu, QEMU_THREAD_JOINABLE); +#ifdef _WIN32 + cpu->hThread = qemu_thread_get_handle(cpu->thread); +#endif +} + void cpu_remove_sync(CPUState *cpu) { cpu->stop = true; @@ -614,7 +630,7 @@ void cpu_remove_sync(CPUState *cpu) void cpus_register_accel(const AccelOpsClass *ops) { assert(ops != NULL); - assert(ops->create_vcpu_thread != NULL); /* mandatory */ + assert(ops->vcpu_thread_fn != NULL); /* mandatory */ cpus_accel = ops; } @@ -636,10 +652,11 @@ void qemu_init_vcpu(CPUState *cpu) } /* accelerators all implement the AccelOpsClass */ - g_assert(cpus_accel != NULL && cpus_accel->create_vcpu_thread != NULL); + g_assert(cpus_accel != NULL && cpus_accel->vcpu_thread_fn != NULL); + if (cpus_accel->create_vcpu_thread_precheck == NULL || cpus_accel->create_vcpu_thread_precheck(cpu)) { - cpus_accel->create_vcpu_thread(cpu); + common_vcpu_thread_create(cpu); } if (cpus_accel->create_vcpu_thread_postcheck) { cpus_accel->create_vcpu_thread_postcheck(cpu); diff --git a/target/i386/hax/hax-accel-ops.c b/target/i386/hax/hax-accel-ops.c index 18114fe34d..2fc2a9b8a4 100644 --- a/target/i386/hax/hax-accel-ops.c +++ b/target/i386/hax/hax-accel-ops.c @@ -57,28 +57,12 @@ static void *hax_cpu_thread_fn(void *arg) return NULL; } -static void hax_start_vcpu_thread(CPUState *cpu) -{ - char thread_name[VCPU_THREAD_NAME_SIZE]; - - cpu->thread = g_new0(QemuThread, 1); - cpu->halt_cond = g_new0(QemuCond, 1); - qemu_cond_init(cpu->halt_cond); - - snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/HAX", - cpu->cpu_index); - qemu_thread_create(cpu->thread, thread_name, hax_cpu_thread_fn, - cpu, QEMU_THREAD_JOINABLE); -#ifdef _WIN32 - cpu->hThread = qemu_thread_get_handle(cpu->thread); -#endif -} - static void hax_accel_ops_class_init(ObjectClass *oc, void *data) { AccelOpsClass *ops = ACCEL_OPS_CLASS(oc); - ops->create_vcpu_thread = hax_start_vcpu_thread; + ops->thread_name = "HAX"; + ops->vcpu_thread_fn = hax_cpu_thread_fn; ops->kick_vcpu_thread = hax_kick_vcpu_thread; ops->synchronize_post_reset = hax_cpu_synchronize_post_reset; diff --git a/target/i386/nvmm/nvmm-accel-ops.c b/target/i386/nvmm/nvmm-accel-ops.c index 6c46101ac1..a6dc73aa35 100644 --- a/target/i386/nvmm/nvmm-accel-ops.c +++ b/target/i386/nvmm/nvmm-accel-ops.c @@ -60,19 +60,6 @@ static void *qemu_nvmm_cpu_thread_fn(void *arg) return NULL; } -static void nvmm_start_vcpu_thread(CPUState *cpu) -{ - char thread_name[VCPU_THREAD_NAME_SIZE]; - - cpu->thread = g_new0(QemuThread, 1); - cpu->halt_cond = g_new0(QemuCond, 1); - qemu_cond_init(cpu->halt_cond); - snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/NVMM", - cpu->cpu_index); - qemu_thread_create(cpu->thread, thread_name, qemu_nvmm_cpu_thread_fn, - cpu, QEMU_THREAD_JOINABLE); -} - /* * Abort the call to run the virtual processor by another thread, and to * return the control to that thread. @@ -87,7 +74,9 @@ static void nvmm_accel_ops_class_init(ObjectClass *oc, void *data) { AccelOpsClass *ops = ACCEL_OPS_CLASS(oc); - ops->create_vcpu_thread = nvmm_start_vcpu_thread; + ops->thread_name = "NVMM"; + ops->vcpu_thread_fn = qemu_nvmm_cpu_thread_fn; + ops->kick_vcpu_thread = nvmm_kick_vcpu_thread; ops->synchronize_post_reset = nvmm_cpu_synchronize_post_reset; diff --git a/target/i386/whpx/whpx-accel-ops.c b/target/i386/whpx/whpx-accel-ops.c index dd2a9f7657..6498eb2060 100644 --- a/target/i386/whpx/whpx-accel-ops.c +++ b/target/i386/whpx/whpx-accel-ops.c @@ -60,22 +60,6 @@ static void *whpx_cpu_thread_fn(void *arg) return NULL; } -static void whpx_start_vcpu_thread(CPUState *cpu) -{ - char thread_name[VCPU_THREAD_NAME_SIZE]; - - cpu->thread = g_new0(QemuThread, 1); - cpu->halt_cond = g_new0(QemuCond, 1); - qemu_cond_init(cpu->halt_cond); - snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/WHPX", - cpu->cpu_index); - qemu_thread_create(cpu->thread, thread_name, whpx_cpu_thread_fn, - cpu, QEMU_THREAD_JOINABLE); -#ifdef _WIN32 - cpu->hThread = qemu_thread_get_handle(cpu->thread); -#endif -} - static void whpx_kick_vcpu_thread(CPUState *cpu) { if (!qemu_cpu_is_self(cpu)) { @@ -92,7 +76,9 @@ static void whpx_accel_ops_class_init(ObjectClass *oc, void *data) { AccelOpsClass *ops = ACCEL_OPS_CLASS(oc); - ops->create_vcpu_thread = whpx_start_vcpu_thread; + ops->thread_name = "WHPX"; + ops->vcpu_thread_fn = whpx_cpu_thread_fn; + ops->kick_vcpu_thread = whpx_kick_vcpu_thread; ops->cpu_thread_is_idle = whpx_vcpu_thread_is_idle; From patchwork Wed Mar 23 17:17:48 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: 12790003 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 3C53DC433FE for ; Wed, 23 Mar 2022 17:34:12 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.294016.499742 (Exim 4.92) (envelope-from ) id 1nX4rv-0002zy-EB; Wed, 23 Mar 2022 17:33:59 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 294016.499742; Wed, 23 Mar 2022 17:33:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nX4rv-0002zY-5w; Wed, 23 Mar 2022 17:33:59 +0000 Received: by outflank-mailman (input) for mailman id 294016; Wed, 23 Mar 2022 17:33:57 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nX4eQ-0004Zy-P3 for xen-devel@lists.xenproject.org; Wed, 23 Mar 2022 17:20:02 +0000 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [2607:f8b0:4864:20::1032]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 78af94f3-aacd-11ec-a405-831a346695d4; Wed, 23 Mar 2022 18:20:02 +0100 (CET) Received: by mail-pj1-x1032.google.com with SMTP id b8so2367589pjb.4 for ; Wed, 23 Mar 2022 10:20:01 -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 oo17-20020a17090b1c9100b001bf0ccc59c2sm7189967pjb.16.2022.03.23.10.19.54 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 23 Mar 2022 10:20:00 -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: 78af94f3-aacd-11ec-a405-831a346695d4 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=f+HL4Abo/9emIoVYr4nPcZWANTfk8HbxwtFhwWh4T4E=; b=R38CVVHJgH8kHmGn0ZOyhoWZ33CV6mzkknIiqbfMkEd3nlYmXum5LYE5EuR9nOh5dV 4p+1F+9RocXuE6X/etkgzAlBdiSWWmatjKQnx2IG0DXq/5XQUfkek0cJmgKz3CvRAv+Q ZEQD4UjM+CuFPFnvkD7N3P9I3mXgm6KY1NLl24qU0ZpnRER1x6XTt68YoiVIlyjwivDY O6oJvDcjzbgtgV5VVYi1YxOK5p8sfe9NSUl24zEhnSJ+u/RzIPghmhV5VRqXDLHTZfDz 1fSHXii1iS47EJJoenarBJh84GnRVtK24aTa2pye2VI1SSKFMWmBWKuqZTE/MxejwKcS YLCQ== 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=f+HL4Abo/9emIoVYr4nPcZWANTfk8HbxwtFhwWh4T4E=; b=7Z9fcWjK8IhhaMXbDSHqml5IKiGSzeX13Dr966VmkzFWX2jh6fCg/+jVZbJM/+b093 TZWTnwqnIreAlBOsi59PJCWvkKQb+/lAmfIKOrat2PBSGZDdghtGZWszjhOfL61Og5hY 3H1IVGqNI5y0peZDKw4q54FHvFieMODKQx1bRY/DIikhc/fgVJo3lqYzna2KAPyBDyRZ 9lSjHncs/lOAPnjrsqzmv1fM6lQOqUn0GWJKVmj6clXVfsKkplhDgFrAVvtQp7obfTDr baeFxa4fY9VYQHKXpdgxriIyPEptXg9RcnO+JUuKj0i9XArFQjzW4TSzVFFZzgDWhT1l 2Qew== X-Gm-Message-State: AOAM531Q5Dw7tZjYISjIvmMOriPJnoV/hdJmFtigziA32hmKVuCxxGoI Z/z8GdlyoicnXvSYyfH4SdU= X-Google-Smtp-Source: ABdhPJwUGIANIvoDBDf1d6wuhMbglFjfjHX2yL7VBu0eJlXm38w4pEE/zj+JRqSDdW4aqPv9Y3LI/A== X-Received: by 2002:a17:90a:8d85:b0:1b8:a215:e3e4 with SMTP id d5-20020a17090a8d8500b001b8a215e3e4mr12881119pjo.175.1648056000652; Wed, 23 Mar 2022 10:20:00 -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 Subject: [PATCH v4 10/13] accel-ops: Introduce common_vcpu_thread_destroy() and .precheck handler Date: Wed, 23 Mar 2022 18:17:48 +0100 Message-Id: <20220323171751.78612-11-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: Philippe Mathieu-Daudé Introduce an empty common_vcpu_thread_destroy() function, and provide a AccelOpsClass::destroy_vcpu_thread_precheck() callback so accelerators can choose whether to call common_vcpu_thread_destroy. Signed-off-by: Philippe Mathieu-Daudé --- include/sysemu/accel-ops.h | 2 ++ softmmu/cpus.c | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/include/sysemu/accel-ops.h b/include/sysemu/accel-ops.h index caf337f61f..b47f6de3f9 100644 --- a/include/sysemu/accel-ops.h +++ b/include/sysemu/accel-ops.h @@ -35,6 +35,8 @@ struct AccelOpsClass { /* If non-NULL, return whether common vCPU thread must be created */ bool (*create_vcpu_thread_precheck)(CPUState *cpu); void (*create_vcpu_thread_postcheck)(CPUState *cpu); + /* If non-NULL, return whether common vCPU thread must be destroyed */ + bool (*destroy_vcpu_thread_precheck)(CPUState *cpu); void (*kick_vcpu_thread)(CPUState *cpu); bool (*cpu_thread_is_idle)(CPUState *cpu); diff --git a/softmmu/cpus.c b/softmmu/cpus.c index cf430ac486..37325b3b8d 100644 --- a/softmmu/cpus.c +++ b/softmmu/cpus.c @@ -617,6 +617,10 @@ static void common_vcpu_thread_create(CPUState *cpu) #endif } +static void common_vcpu_thread_destroy(CPUState *cpu) +{ +} + void cpu_remove_sync(CPUState *cpu) { cpu->stop = true; @@ -625,6 +629,11 @@ void cpu_remove_sync(CPUState *cpu) qemu_mutex_unlock_iothread(); qemu_thread_join(cpu->thread); qemu_mutex_lock_iothread(); + + if (cpus_accel->destroy_vcpu_thread_precheck == NULL + || cpus_accel->destroy_vcpu_thread_precheck(cpu)) { + common_vcpu_thread_destroy(cpu); + } } void cpus_register_accel(const AccelOpsClass *ops) From patchwork Wed Mar 23 17:17:49 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: 12789985 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 54E06C433FE for ; Wed, 23 Mar 2022 17:20:30 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.294004.499703 (Exim 4.92) (envelope-from ) id 1nX4ee-0000EV-7V; Wed, 23 Mar 2022 17:20:16 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 294004.499703; Wed, 23 Mar 2022 17:20:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nX4ee-0000EO-3z; Wed, 23 Mar 2022 17:20:16 +0000 Received: by outflank-mailman (input) for mailman id 294004; Wed, 23 Mar 2022 17:20:14 +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 1nX4ec-0007T4-Hz for xen-devel@lists.xenproject.org; Wed, 23 Mar 2022 17:20:14 +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 7fb285ef-aacd-11ec-8fbc-03012f2f19d4; Wed, 23 Mar 2022 18:20:13 +0100 (CET) Received: by mail-pj1-x1036.google.com with SMTP id m22so2405557pja.0 for ; Wed, 23 Mar 2022 10:20:13 -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 d24-20020a637358000000b003823aefde04sm336971pgn.86.2022.03.23.10.20.06 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 23 Mar 2022 10:20: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: 7fb285ef-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=MsX1ZkecFTiI7JDWgHH13CsFxdulVP/faYY6Ho3L9NU=; b=WiW4MrCr//Z88g+PXSFrPmTGMoceaVHESi73affp7lvaELZrmIQzuoUOKQHWdxEGR1 NO8SV9ARJQk3egmkmUIPnlIThomv8Lit2KqxTc39Z2U2FpA9dGoRpDFaiV7jNk13qUza 7zTfMC78Yc9mIXAGObaiUFBGpvB4UERocSaZSl7rhPntj8Gi1+FoC3nfqPiNjeGgZmPh TRMYKUG2CwwJHNw1Jqgv/qe0wIDn26xQq8oJkIoqzDAj6WG0NmljbJFdXSn/JSJOqJKV ad67bhyOCOEqsfPGFGJ1vRiL63Vd3PXt65wKeeSdZ40GLF1FXc9OTqtSP/xBz7j9+tjc hyJA== 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=MsX1ZkecFTiI7JDWgHH13CsFxdulVP/faYY6Ho3L9NU=; b=6UdX6dVP5cjODG+BvQRiZCDSG7NudnyjoZc1zvFHYIsNWSZxKzdYBSFaRODybwFrUF IglWoVtqdU1I2+N37dEW7wlBluulRalPPMUNTfbPmz2+4xv5uKRtcnFLmN/rGhyUmF15 3vR8xrGF/xyhfRKTWM8FbXio/E0rGRs3lAhSMllQH3hsb7o0p1l6DXShKHDlPQqPPNH+ /igIeDdGQz/WytUQU1/rkHHBpZ9oqSu7Vm0TQ+CA7A1uSqI46U78LOmiW2JYcc6ZXccF +W+diRUr2Au4ZTDFSL4M5nM9nTcx7pWGlapsbBZnmJ8eoNcXX1FT16XR2mdhOo3n+eDb KtnQ== X-Gm-Message-State: AOAM53233n7n9i/tRrqEuAXs6cV73RPw0zFFEnnEdUo1qdfBLkL4OyXR UUdl+Z5DQOSJBk6j8JPVKN0= X-Google-Smtp-Source: ABdhPJyjcb2sZqeH87rq3zUZWSVN13XuvvacgYKtkqz+CZvHLPq51GDtssoIVmULExUOmBBtc3gkrA== X-Received: by 2002:a17:90a:5291:b0:1bb:ef4d:947d with SMTP id w17-20020a17090a529100b001bbef4d947dmr12885297pjh.243.1648056012464; Wed, 23 Mar 2022 10:20:12 -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 Subject: [PATCH v4 11/13] accel/tcg: Add rr_destroy_vcpu_thread_precheck() Date: Wed, 23 Mar 2022 18:17:49 +0100 Message-Id: <20220323171751.78612-12-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: Philippe Mathieu-Daudé TCG/RR is special and creates a single vCPU. It only have to release its resources once. Implement the .precheck() for that purpose. Signed-off-by: Philippe Mathieu-Daudé --- accel/tcg/tcg-accel-ops-rr.c | 9 +++++++++ accel/tcg/tcg-accel-ops.c | 1 + 2 files changed, 10 insertions(+) diff --git a/accel/tcg/tcg-accel-ops-rr.c b/accel/tcg/tcg-accel-ops-rr.c index 006b787289..6fe8e20356 100644 --- a/accel/tcg/tcg-accel-ops-rr.c +++ b/accel/tcg/tcg-accel-ops-rr.c @@ -295,3 +295,12 @@ void rr_create_vcpu_thread_postcheck(CPUState *cpu) cpu->created = true; } } + +bool rr_destroy_vcpu_thread_precheck(CPUState *cpu) +{ + if (single_tcg_cpu_thread) { + single_tcg_cpu_thread = NULL; + return true; + } + return false; +} diff --git a/accel/tcg/tcg-accel-ops.c b/accel/tcg/tcg-accel-ops.c index 127dd6fee5..0b0dbcc47a 100644 --- a/accel/tcg/tcg-accel-ops.c +++ b/accel/tcg/tcg-accel-ops.c @@ -102,6 +102,7 @@ static void tcg_accel_ops_init(AccelOpsClass *ops) ops->vcpu_thread_fn = rr_vcpu_thread_fn; ops->create_vcpu_thread_precheck = rr_create_vcpu_thread_precheck; ops->create_vcpu_thread_postcheck = rr_create_vcpu_thread_postcheck; + ops->destroy_vcpu_thread_precheck = rr_destroy_vcpu_thread_precheck; ops->kick_vcpu_thread = rr_kick_vcpu_thread; if (icount_enabled()) { From patchwork Wed Mar 23 17:17:50 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: 12790008 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 20E7EC433FE for ; Wed, 23 Mar 2022 17:36:25 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.294033.499780 (Exim 4.92) (envelope-from ) id 1nX4u6-0005VV-DT; Wed, 23 Mar 2022 17:36:14 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 294033.499780; Wed, 23 Mar 2022 17:36:14 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nX4u6-0005VO-9g; Wed, 23 Mar 2022 17:36:14 +0000 Received: by outflank-mailman (input) for mailman id 294033; Wed, 23 Mar 2022 17:36:13 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nX4ep-0004Zy-1T for xen-devel@lists.xenproject.org; Wed, 23 Mar 2022 17:20:27 +0000 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [2607:f8b0:4864:20::62f]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 872bd760-aacd-11ec-a405-831a346695d4; Wed, 23 Mar 2022 18:20:26 +0100 (CET) Received: by mail-pl1-x62f.google.com with SMTP id k6so2138366plg.12 for ; Wed, 23 Mar 2022 10:20:26 -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 o24-20020a17090a5b1800b001c6aaafa5fbsm282644pji.24.2022.03.23.10.20.18 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 23 Mar 2022 10:20:24 -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: 872bd760-aacd-11ec-a405-831a346695d4 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=ed6iY8pMEzMkAOvdT6TEMCudwvjmYJcGMMpCaTIv/yU=; b=RyKgoe5HgJCJpFJvPNUJVGX9nExg70mZzCcSsKHkmRw2HUwXJBO+ViJY8Cg1JFjM2H G0OgG2uMd3kfN/cqwIfkckDdV0ro4mD03PEFsBMGgIFVHwNisdMFtViW7UEW0QokyJ18 /1sVuSemm0/QC9FQEH4gtz9xLl3QWzTjGmS6U6thAkmdoZhRJ3tRO1ZYnvykNZfNtAY7 hsT8RrSJ2JYd++oXi25BCbjpyRPtyPQS4TfqKZj1OE2g3DX3iSvXB/fb6naDgvDbxoVg v/pUtMjxZ1idxkWkbRDhcEj5lEdEAR20mwKPOE/HmsGKZUkhhIAWrUbX6M9OiZDfFKNS ulEA== 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=ed6iY8pMEzMkAOvdT6TEMCudwvjmYJcGMMpCaTIv/yU=; b=i278VbzLftkQZp95rC7K7vxypA5PJEp5DEBFWhwvEw9DgsK+SoUP+CkzaZnKCmH0Uf c1PWrnJygLgCiDJwHMbq1H8byi5VfA8ABsy3J4NlbCfdVRCh2QFbd86kgCTYVRpJn0l+ g0trnk4/9dgou/Z+WVzp4j6W1qVIfbRSAz3A7SO89UpbT1ItnSCETXtUlYH1No2jMvY4 XRS1zwSRMjfCaSjMbcpJNdUs41h7YebXF8bCO/Fq9/1TlwLbS0RtZnr568b4Gdg/vmaJ R43oCxHcGusQSmvQfKpjjTRJpzdt6PTP3l25CDbDvDLxDE36p+xBLH25cASqZDU7XneV 1RUg== X-Gm-Message-State: AOAM530kqP6uzTlSr38ts8QZ3oXqRNr2Qc6IRddLeyipkZ8AHdHgl27s A/kRx3nIcoJbZk1vtdbVDHs= X-Google-Smtp-Source: ABdhPJwqx6x4zfaaNXs3hip1MrGQWDzMJ1aziOlNPCMVNNhEzttDkRqQAwuDm1jVkFyWnxpwXzRJYA== X-Received: by 2002:a17:903:2406:b0:14d:6447:990c with SMTP id e6-20020a170903240600b0014d6447990cmr1048970plo.22.1648056024958; Wed, 23 Mar 2022 10:20:24 -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 12/13] softmmu/cpus: Free cpu->thread in generic_destroy_vcpu_thread() Date: Wed, 23 Mar 2022 18:17:50 +0100 Message-Id: <20220323171751.78612-13-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 Free cpu->thread in a new AccelOpsClass::destroy_vcpu_thread() handler generic_destroy_vcpu_thread(). vCPU hotunplug related leak reported by Valgrind: ==102631== 8 bytes in 1 blocks are definitely lost in loss record 1,037 of 8,555 ==102631== at 0x4C3ADBB: calloc (vg_replace_malloc.c:1117) ==102631== by 0x69EE4CD: g_malloc0 (in /usr/lib64/libglib-2.0.so.0.5600.4) ==102631== by 0x92443A: kvm_start_vcpu_thread (kvm-accel-ops.c:68) ==102631== by 0x4505C2: qemu_init_vcpu (cpus.c:643) ==102631== by 0x76B4D1: x86_cpu_realizefn (cpu.c:6520) ==102631== by 0x9344A7: device_set_realized (qdev.c:531) ==102631== by 0x93E329: property_set_bool (object.c:2273) ==102631== by 0x93C2F8: object_property_set (object.c:1408) ==102631== by 0x940796: object_property_set_qobject (qom-qobject.c:28) ==102631== by 0x93C663: object_property_set_bool (object.c:1477) ==102631== by 0x933D3B: qdev_realize (qdev.c:333) ==102631== by 0x455EC4: qdev_device_add_from_qdict (qdev-monitor.c:713) Signed-off-by: Mark Kanda Message-Id: <20220321141409.3112932-3-mark.kanda@oracle.com> Signed-off-by: Philippe Mathieu-Daudé --- softmmu/cpus.c | 1 + 1 file changed, 1 insertion(+) diff --git a/softmmu/cpus.c b/softmmu/cpus.c index 37325b3b8d..efa8397f04 100644 --- a/softmmu/cpus.c +++ b/softmmu/cpus.c @@ -619,6 +619,7 @@ static void common_vcpu_thread_create(CPUState *cpu) static void common_vcpu_thread_destroy(CPUState *cpu) { + g_free(cpu->thread); } void cpu_remove_sync(CPUState *cpu) From patchwork Wed Mar 23 17:17:51 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: 12790004 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 1CD60C433F5 for ; Wed, 23 Mar 2022 17:34:12 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.294014.499725 (Exim 4.92) (envelope-from ) id 1nX4rt-0002fn-PQ; Wed, 23 Mar 2022 17:33:57 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 294014.499725; Wed, 23 Mar 2022 17:33:57 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nX4rt-0002fg-KF; Wed, 23 Mar 2022 17:33:57 +0000 Received: by outflank-mailman (input) for mailman id 294014; Wed, 23 Mar 2022 17:33:57 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nX4f1-0004Zy-UB for xen-devel@lists.xenproject.org; Wed, 23 Mar 2022 17:20:40 +0000 Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [2607:f8b0:4864:20::52e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 8ed3205c-aacd-11ec-a405-831a346695d4; Wed, 23 Mar 2022 18:20:39 +0100 (CET) Received: by mail-pg1-x52e.google.com with SMTP id c2so1663318pga.10 for ; Wed, 23 Mar 2022 10:20:39 -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 y12-20020a17090a784c00b001c6bdafc995sm5775028pjl.3.2022.03.23.10.20.31 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 23 Mar 2022 10:20:37 -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: 8ed3205c-aacd-11ec-a405-831a346695d4 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=32I90XyrSsgFhoTvAz7kFHmgBFJVrEU2lmj8L6zrA7w=; b=HziQehOw9rA6WaAjt6GWtN96OEZQKNeqtt8BUYKzQhy7osdWurjWlBG20QGQW/EB+F jeu4GS9/mQNcxaXFiYXQHD+Newqzq1veJVbG2jRb7R8WXmdqG/gVdrZDjIlDxW4lRXOq I71naYjPm4YaQCCMtZQaseOvo60Lz/IkNWzSHUBWsfnNXC2oOABAKojB2mfg+D9g7D1D aCifnKvwu9gBP/efpCWO8b9KL2IWYDxFdNbknFbXsjBT6YGAcCikhEVWZMzFhjo4Dyoi m5OUOkfn3o+MT9iQ4opD1tk8fsbzJgw5Qcb9c/JxYjHFhN6Q4eH03QkTyrPcQEV21Vlq Vusg== 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=32I90XyrSsgFhoTvAz7kFHmgBFJVrEU2lmj8L6zrA7w=; b=hoDzNMtLr98gAiXwnT/9dSSVZLcHaMv7grg300hG6EcH2/SCBDDeauoRmhCeSoIPkQ hxq1T1k7Bk8at4m+qenGo5nvQZ4wnI+ambWD8LI5m2bwU7AfOJNSR39twij1Y138V6Dz eJt75pXFs4JJX9hwmoFDyt4HLJiOgPWCg7DsgEfHXViQXwxBzx707TDib0c7JAWg91k/ mYwowiTZoy+kMEBHd3c0Pe8gXIfShW3k5xFIRk/AMf8pYkx0j8wagp/tlHZd/4MlOAf/ tWjnuY179qMERV9V8tLcVCMABuF67ovzX12UwrTjs8IsW9S6/E4VaHl2UKqTxq7D3XBY bitw== X-Gm-Message-State: AOAM533wR8LDc1ymNWwEtJl6sk/h4zpUJMwjD1Rhifbo8Yo3fEAemuWd 64z8Z2/sBDG34TLy50t8E6o= X-Google-Smtp-Source: ABdhPJzitqpHPUzN1FOlO6Xy6wxyKTy6324HAUZa9Y29UTDRmfk9C7LuqvIVu5doI3n8WNcv+vf6iw== X-Received: by 2002:a63:1e52:0:b0:380:ae84:256e with SMTP id p18-20020a631e52000000b00380ae84256emr758991pgm.84.1648056037806; Wed, 23 Mar 2022 10:20:37 -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 13/13] softmmu/cpus: Free cpu->halt_cond in generic_destroy_vcpu_thread() Date: Wed, 23 Mar 2022 18:17:51 +0100 Message-Id: <20220323171751.78612-14-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 vCPU hotunplug related leak reported by Valgrind: ==102631== 56 bytes in 1 blocks are definitely lost in loss record 5,089 of 8,555 ==102631== at 0x4C3ADBB: calloc (vg_replace_malloc.c:1117) ==102631== by 0x69EE4CD: g_malloc0 (in /usr/lib64/libglib-2.0.so.0.5600.4) ==102631== by 0x924452: kvm_start_vcpu_thread (kvm-accel-ops.c:69) ==102631== by 0x4505C2: qemu_init_vcpu (cpus.c:643) ==102631== by 0x76B4D1: x86_cpu_realizefn (cpu.c:6520) ==102631== by 0x9344A7: device_set_realized (qdev.c:531) ==102631== by 0x93E329: property_set_bool (object.c:2273) ==102631== by 0x93C2F8: object_property_set (object.c:1408) ==102631== by 0x940796: object_property_set_qobject (qom-qobject.c:28) ==102631== by 0x93C663: object_property_set_bool (object.c:1477) ==102631== by 0x933D3B: qdev_realize (qdev.c:333) ==102631== by 0x455EC4: qdev_device_add_from_qdict (qdev-monitor.c:713) Signed-off-by: Mark Kanda Message-Id: <20220321141409.3112932-4-mark.kanda@oracle.com> Signed-off-by: Philippe Mathieu-Daudé --- softmmu/cpus.c | 1 + 1 file changed, 1 insertion(+) diff --git a/softmmu/cpus.c b/softmmu/cpus.c index efa8397f04..23bed29545 100644 --- a/softmmu/cpus.c +++ b/softmmu/cpus.c @@ -620,6 +620,7 @@ static void common_vcpu_thread_create(CPUState *cpu) static void common_vcpu_thread_destroy(CPUState *cpu) { g_free(cpu->thread); + g_free(cpu->halt_cond); } void cpu_remove_sync(CPUState *cpu)