From nobody Thu Apr 2 16:39:46 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B446ECAAD8 for ; Thu, 22 Sep 2022 18:22:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232488AbiIVSWC (ORCPT ); Thu, 22 Sep 2022 14:22:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231972AbiIVSVc (ORCPT ); Thu, 22 Sep 2022 14:21:32 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 921CF10AB27; Thu, 22 Sep 2022 11:21:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1663870886; x=1695406886; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3j7AGT1eIC/BE0MhW+coP+8A6Ov/SyQoyWvgLPvXMnc=; b=SyvpkJdP7b70ZGFSZNoWMCFSyTUjmW89uB7vQViUZg2fqYVGuZmz2pZX g3YXqPLqHK++29qmF9Nns9hAfhYIVWoGf6OfHHuRecMfzzqTTC/YXA0q4 gefPLShTnwQjVP88WCcbjE8oKoGskmlMPP/5JdbQBQit5xeVm6W92nedh pfMKE9jMH07w5UsDb9FLIIs800TfC1f9gxfelivAyC/cyXlJTDP5E8O2N Nsh5ctFyaFdYkIebXhQllQm6bKq4rFiilPmHBU4Wh91KPKRJVHn6W9nqq 5qp/tp2oqp7tiPgI6gB+wz28N99xeXrOG+Y30z5pX3EAiKcY045UkoZrQ A==; X-IronPort-AV: E=McAfee;i="6500,9779,10478"; a="386675992" X-IronPort-AV: E=Sophos;i="5.93,337,1654585200"; d="scan'208";a="386675992" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2022 11:21:20 -0700 X-IronPort-AV: E=Sophos;i="5.93,337,1654585200"; d="scan'208";a="653086727" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2022 11:21:19 -0700 From: isaku.yamahata@intel.com To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Paolo Bonzini , Sean Christopherson , Thomas Gleixner , Marc Zyngier , Will Deacon Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com, Kai Huang , Chao Gao , Atish Patra , Shaokun Zhang , Daniel Lezcano , Huang Ying , Huacai Chen , Dave Hansen , Borislav Petkov Subject: [PATCH v5 12/30] KVM: Add arch hook for suspend Date: Thu, 22 Sep 2022 11:20:41 -0700 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Isaku Yamahata Factor out the logic on suspend event as arch callback. Later kvm/x86 will override it. Suggested-by: Sean Christopherson Signed-off-by: Isaku Yamahata --- include/linux/kvm_host.h | 1 + virt/kvm/kvm_main.c | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 084ee8a13e9f..861aad8812ff 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -1435,6 +1435,7 @@ static inline void kvm_create_vcpu_debugfs(struct kvm= _vcpu *vcpu) {} #endif =20 int kvm_arch_reboot(int val); +int kvm_arch_suspend(int usage_count); =20 int kvm_arch_hardware_enable(void); void kvm_arch_hardware_disable(void); diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 58385000b73f..0ebe43a695e5 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -1148,6 +1148,17 @@ int __weak kvm_arch_reboot(int val) return NOTIFY_OK; } =20 +int __weak kvm_arch_suspend(int usage_count) +{ + if (usage_count) + /* + * Because kvm_suspend() is called with interrupt disabled, no + * need to disable preemption. + */ + hardware_disable_nolock(NULL); + return 0; +} + /* * Called just after removing the VM from the vm_list, but before doing any * other destruction. @@ -5753,15 +5764,7 @@ static int kvm_suspend(void) * locking. */ lockdep_assert_not_held(&kvm_lock); - - if (kvm_usage_count) { - /* - * Because kvm_suspend() is called with interrupt disabled, no - * need to disable preemption. - */ - hardware_disable_nolock(NULL); - } - return 0; + return kvm_arch_suspend(kvm_usage_count); } =20 static void kvm_resume(void) --=20 2.25.1