Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp292240pxv; Wed, 21 Jul 2021 23:29:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJypAy4aWPPtDrSUIQQ9Z1YXnlYIKl19T463PZnGUTEibYkSEQNHe6YpryM5h6Fc9jCgyCLc X-Received: by 2002:a92:c503:: with SMTP id r3mr26758821ilg.148.1626935349759; Wed, 21 Jul 2021 23:29:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626935349; cv=none; d=google.com; s=arc-20160816; b=ia+NmYqnyHNP51OcaFB6stQXCMDqTa5bVJuuBO+88AIGShv7oa4tFbkAartqj6ID/L I3TyMFClBJTs26YSjIP+bKKPNXr86umYUdQwi/bB9onB9OsINDZpYm727JpA4vW2gxnt oENaczSnTTgNNFhhKaUDmRNm1+WY2LeGwVig3ZP/yMwWIIyNBAbepv3oH/3AByk8ELuX wZCANxjgwTGH0nqgKFLI0ykcJ8cNeFhQuLHE3+ash/sdQ1mwcyXLTNJC9tQxixMrsHd9 caBKrNfmSbokOKozj3yqX55K++NruPdtRA+8E8QF1l7eqVdkMUijMK02FZn8gVDtsexS JIFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=7MxYbCUwRXzhpe2pjIXtTncvKQgnb3H6mPXsxrt4ARk=; b=lYD3fIKT8K56YVLSImnPwx4NQXpHt6k9CcPJcrofy8+tBVxCXwNKa/44OSoE0S13bs WpeoagyLiOtgm3Rlf6WF95lF9SWiADTvBXj86ioy9vmOsZsmJCIg3Mi9jz1eZXe3aSkh ASC5AsgLCIpv8ri2TIsxZGYl881VgWtnM3UEyOxWcNVDlAZDod7p5Bnk5vL9Cv1HPX08 y7EL4I6/xfl78WBJsVLpmnvTqkKZdovtiMFKzg251zlFuAQBzRQDFJwALb6DeYNKcv13 Q/4xcuKW9z7Y+Z+NzxofxkPoBFwFN9/WVbj3zBETmqAXZGh3hCDF3Q919AbZhhcODZm7 Jp9g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p7si21808782iop.92.2021.07.21.23.28.58; Wed, 21 Jul 2021 23:29:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230339AbhGVFrR (ORCPT + 99 others); Thu, 22 Jul 2021 01:47:17 -0400 Received: from mga01.intel.com ([192.55.52.88]:46906 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230331AbhGVFrP (ORCPT ); Thu, 22 Jul 2021 01:47:15 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10052"; a="233387054" X-IronPort-AV: E=Sophos;i="5.84,260,1620716400"; d="scan'208";a="233387054" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jul 2021 23:27:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.84,260,1620716400"; d="scan'208";a="512385844" Received: from louislifei-optiplex-7050.sh.intel.com ([10.239.154.151]) by fmsmga002.fm.intel.com with ESMTP; 21 Jul 2021 23:27:48 -0700 From: Fei Li To: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, Shuo Liu , Reinette Chatre , Zhi Wang , Fei Li , yu1.wang@intel.com Subject: [PATCH] virt: acrn: Do hcall_destroy_vm() before resource release Date: Thu, 22 Jul 2021 14:27:36 +0800 Message-Id: <20210722062736.15050-1-fei1.li@intel.com> X-Mailer: git-send-email 2.17.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Shuo Liu The ACRN hypervisor has scenarios which could run a real-time guest VM. The real-time guest VM occupies dedicated CPU cores, be assigned with dedicated PCI devices. It can run without the Service VM after boot up. hcall_destroy_vm() returns failure when a real-time guest VM refuses. The clearing of flag ACRN_VM_FLAG_DESTROYED causes some kernel resource double-freed in a later acrn_vm_destroy(). Do hcall_destroy_vm() before resource release to drop this chance to destroy the VM if hypercall fails. Fixes: 9c5137aedd11 ("virt: acrn: Introduce VM management interfaces") Signed-off-by: Shuo Liu Signed-off-by: Fei Li --- drivers/virt/acrn/vm.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/virt/acrn/vm.c b/drivers/virt/acrn/vm.c index 0d002a355a93..fbc9f1042000 100644 --- a/drivers/virt/acrn/vm.c +++ b/drivers/virt/acrn/vm.c @@ -64,6 +64,14 @@ int acrn_vm_destroy(struct acrn_vm *vm) test_and_set_bit(ACRN_VM_FLAG_DESTROYED, &vm->flags)) return 0; + ret = hcall_destroy_vm(vm->vmid); + if (ret < 0) { + dev_err(acrn_dev.this_device, + "Failed to destroy VM %u\n", vm->vmid); + clear_bit(ACRN_VM_FLAG_DESTROYED, &vm->flags); + return ret; + } + /* Remove from global VM list */ write_lock_bh(&acrn_vm_list_lock); list_del_init(&vm->list); @@ -78,14 +86,6 @@ int acrn_vm_destroy(struct acrn_vm *vm) vm->monitor_page = NULL; } - ret = hcall_destroy_vm(vm->vmid); - if (ret < 0) { - dev_err(acrn_dev.this_device, - "Failed to destroy VM %u\n", vm->vmid); - clear_bit(ACRN_VM_FLAG_DESTROYED, &vm->flags); - return ret; - } - acrn_vm_all_ram_unmap(vm); dev_dbg(acrn_dev.this_device, "VM %u destroyed.\n", vm->vmid); base-commit: c453db6cd96418c79702eaf38259002755ab23ff -- 2.17.1