Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp3537845rwi; Tue, 1 Nov 2022 23:28:45 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5XEjP7suRtGSIFmDS9B4IBAhm3yqHlOYmU7w7rZQ0P4KloVZR+c5F+2XQAMAEe/jXpFHWU X-Received: by 2002:a05:6402:884:b0:461:1ed:579f with SMTP id e4-20020a056402088400b0046101ed579fmr22766203edy.413.1667370525256; Tue, 01 Nov 2022 23:28:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667370525; cv=none; d=google.com; s=arc-20160816; b=Di2QkUdxkhR4szTyCqZ1HFNsDbIGMb5rPtl8zN3TZ3GdqWn9/OtQFqdA85lGBxn/fE gpvJ5cDlYJlr91iUzscVVzEIjYJsFKGgoPJFraF6yzHiToyaZ6XPYCbP/9p8hlu3HOiK 7oOVzRy6wG5NS6wNjwAvIkzFlXPcYo3p0xinnBeTlfwlCSfVT1AsMayEnbSNL/wDyqho +crPaAkIHnklfLmNEw04FoWPJlZesF3xhmc03DYsidQAb7CGRSZqPuReMOW2uCY8nuKS MaEvrmLiVsga3tKI5jjYVxAiXRVBnchDsSscpPc/f7aKyFTdEufWqbiGbrCw60NiRv9x HsSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=MdCDShNvZjAimR1T0ES7aOkdszY3FR9uuQklUU3q+CM=; b=oYBIEEqB046TQM2LTMcjVwv3GlGA1PISGYLnRQrCYV0HT+/A/T0yVKMd8xwUraw+Pw 5VtTRPcB0e3jECodgH2q1ypv2KxPcIoGQhdHjwDqzg4HEfZpqegLLZWVbenAfocwhw68 HMejazHE3rQXc1J2M5UfUAd2FCS48vzYPiZ6sJToYgshvxE762bUZRssC02AbNqi9jjD Z3xRgqDSHCiQW1N6tFpeThxjvHtqGZgFHX0M3Nrdg+oDWIGpksRotU4CYzBHeFyFSLxn g0X81Ru1c2vSejKuxK5xZITQukAmCE/2VzL6BvN+10YoUNNPUjTCfV9bniE4UeNQa02Q 9cQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=LwDIJLJQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id oz35-20020a1709077da300b007abafd4d7d0si17003728ejc.702.2022.11.01.23.28.17; Tue, 01 Nov 2022 23:28:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=LwDIJLJQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229487AbiKBGY1 (ORCPT + 96 others); Wed, 2 Nov 2022 02:24:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229561AbiKBGYX (ORCPT ); Wed, 2 Nov 2022 02:24:23 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A7C025EB8; Tue, 1 Nov 2022 23:24:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1667370262; x=1698906262; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hNotXspumrnx35AzALaMaKY1rG2NnMLZH3HRDC+yCBw=; b=LwDIJLJQE8BhJVR1li/x4OIHu4/uUFKfu037mpH4/H8Fabv39ozea0EP ZXTs7XcYI1tEAmfHk31ef4XzldR8/gxEk6mQyZROJ6Unog/y0/OzPxcoo sU7xTH/uaegv8NKZ2dDTGyhwMqadmmGgaV1+bzJwTrBai30JduKuXRjdT /VOc2xnEVZ0C5AW0PSgOtP4Q8ujNSFMiTIFedHnimNNJsQ2x9x0w4G/vm 82GEHaXq0jjrMAOMjsakSMr7ExVYcbZW8XAh9rQwg5rJwn192w18AbXQS 9jC9z9mIf+Tj83BNJqFdk1fK4s05xcOlCYrBoAmlh1VhP4HCzdwJD2nvs Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10518"; a="296765005" X-IronPort-AV: E=Sophos;i="5.95,232,1661842800"; d="scan'208";a="296765005" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Nov 2022 23:24:21 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10518"; a="703146396" X-IronPort-AV: E=Sophos;i="5.95,232,1661842800"; d="scan'208";a="703146396" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Nov 2022 23:24:21 -0700 From: isaku.yamahata@intel.com To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Paolo Bonzini , Sean Christopherson , Marc Zyngier Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com Subject: [PATCH 1/4] KVM: Remove on_each_cpu(hardware_disable_nolock) in kvm_exit() Date: Tue, 1 Nov 2022 23:24:08 -0700 Message-Id: <439b5f7115c5df3e1440fe694269badb19390d55.1667369456.git.isaku.yamahata@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-5.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Isaku Yamahata hardware_enable/disable_nolock() check if the hardware is already enabled/disabled and work as nop when they are called multiple times. Also kvm_usage_count tracks the number of the existing VMs. When VM is created/destroyed by kvm_create/destroy_vm(), hardware_enable/disable_all() and module_get/put() are called. It means when kvm module is removed, it's guaranteed that there is no vm (kvm_usage_count = 0) and that hardware_disable_nolock() was called on each cpus. Although the module exit function, kvm_exit(), calls on_each_cpu(hardware_disable_nolock), it's essentially nop. Eliminate nop call in kvm_exit() and add WARN_ON(kvm_usage_count) to prove that there is no remaining VMs. Signed-off-by: Isaku Yamahata --- virt/kvm/kvm_main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 1376a47fedee..a8c4e62b29ca 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -5945,6 +5945,8 @@ void kvm_exit(void) { int cpu; + WARN_ON(kvm_usage_count); + debugfs_remove_recursive(kvm_debugfs_dir); misc_deregister(&kvm_dev); for_each_possible_cpu(cpu) @@ -5954,7 +5956,6 @@ void kvm_exit(void) unregister_syscore_ops(&kvm_syscore_ops); unregister_reboot_notifier(&kvm_reboot_notifier); cpuhp_remove_state_nocalls(CPUHP_AP_KVM_STARTING); - on_each_cpu(hardware_disable_nolock, NULL, 1); kvm_arch_hardware_unsetup(); kvm_arch_exit(); kvm_irqfd_exit(); -- 2.25.1