From patchwork Thu Sep 22 18:20:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaku Yamahata X-Patchwork-Id: 12985661 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 16B4DC6FA82 for ; Thu, 22 Sep 2022 18:22:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232202AbiIVSW4 (ORCPT ); Thu, 22 Sep 2022 14:22:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231882AbiIVSWh (ORCPT ); Thu, 22 Sep 2022 14:22:37 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19F6750508; Thu, 22 Sep 2022 11:21:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1663870902; x=1695406902; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HGmt/VHs6fVj/w1+ZNhXhm615xxkOdQNshHUklQnVBE=; b=BEk08WiFn0DwUveX1QNOcGIDNSjKzD5Np5v1eAbTaIBP/r9gkelxUxnT VzCJP2Z9Fwlf/+3DLQ5ODOUx3YINmhrsa4tg9g9Rb+JyoDrxj9rnHV7Jm nxJ3ndQvfDNsBTdB7r82xyrjRhtnHb+3109cvd80YllZq05UKVb+ST4fa Kq5syzpRpt6iJfNp/lX6YsGIIEXbUSqWAvDd2rJ00qvljcG8Mv0+xtaY0 GSk3i7XscB1jg4Bya+RI42BnKdWdeDCHWXirR5a2TUJU4hSlEBPG24wBv tbfEoiLQJUwJMf+NM/zErtv2iZcF2A8Tzl/FkX9Tewo3hyXkc24qGOupk A==; X-IronPort-AV: E=McAfee;i="6500,9779,10478"; a="326712886" X-IronPort-AV: E=Sophos;i="5.93,337,1654585200"; d="scan'208";a="326712886" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2022 11:21:21 -0700 X-IronPort-AV: E=Sophos;i="5.93,337,1654585200"; d="scan'208";a="653086745" 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:21 -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 15/30] KVM: Add arch hook for cpu offline event Date: Thu, 22 Sep 2022 11:20:44 -0700 Message-Id: <1bed181569380dfa3c7bc5c6b3f0acc1de01217e.1663869838.git.isaku.yamahata@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Isaku Yamahata Factor out the logic on cpu offline 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 | 30 +++++++++++++++++++----------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 013b33a19030..f3a79d55ca8c 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 int kvm_arch_online_cpu(unsigned int cpu, int usage_count); +int kvm_arch_offline_cpu(unsigned int cpu, int usage_count); int kvm_arch_reboot(int val); int kvm_arch_suspend(int usage_count); void kvm_arch_resume(int usage_count); diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 4c535ae412a7..ad9b8b7d21fa 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -1174,6 +1174,21 @@ int __weak kvm_arch_online_cpu(unsigned int cpu, int usage_count) return ret; } +int __weak kvm_arch_offline_cpu(unsigned int cpu, int usage_count) +{ + if (usage_count) { + /* + * arch callback kvm_arch_hardware_disable() assumes that + * preemption is disabled for historical reason. Disable + * preemption until all arch callbacks are fixed. + */ + preempt_disable(); + hardware_disable_nolock(NULL); + preempt_enable(); + } + return 0; +} + int __weak kvm_arch_reboot(int val) { on_each_cpu(hardware_disable_nolock, NULL, 1); @@ -5137,19 +5152,12 @@ static void hardware_disable_nolock(void *junk) static int kvm_offline_cpu(unsigned int cpu) { + int ret; + mutex_lock(&kvm_lock); - if (kvm_usage_count) { - /* - * arch callback kvm_arch_hardware_disable() assumes that - * preemption is disabled for historical reason. Disable - * preemption until all arch callbacks are fixed. - */ - preempt_disable(); - hardware_disable_nolock(NULL); - preempt_enable(); - } + ret = kvm_arch_offline_cpu(cpu, kvm_usage_count); mutex_unlock(&kvm_lock); - return 0; + return ret; } static void kvm_del_vm(void)