Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp3740717rwn; Sat, 10 Sep 2022 19:43:12 -0700 (PDT) X-Google-Smtp-Source: AA6agR4C8Itze+lhyiXwGhTvhNm7w/hltRLpQVtOj8jVC91kViRCJ2wuJ9hrtiq8yk3qkfHvcL5b X-Received: by 2002:a05:6402:4310:b0:451:3b07:9114 with SMTP id m16-20020a056402431000b004513b079114mr5153016edc.153.1662864192597; Sat, 10 Sep 2022 19:43:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662864192; cv=none; d=google.com; s=arc-20160816; b=iuY0pLzY9lBkgLJwbHhJAIcIJ9AP7fGspzLjaYAFx5G6f8Ry7AkGnYIRoEkzj2834H QZzhaD+2HyFF46q6lOXxWyaKfKmBIXNI+2XxC/8aB0LJcBqMrGq6tuaMOzsYmeDdS2j6 beTGaRiOpTZj0D2oxQEZpFGsd4Y6T8Q/1gVQJTu77caj9ayfa1Rgd1BZaAN4wz29YAzQ 3y5tktAFQCsFUmxHAXB6jyLz4caAMxDzZQGD6NIIgXft/K4OzBU1+Jw2x2zt9bMtDunH lp0hu/qi6O/jmBcldRiZQYxws0ueP8IlDl0UuGcNnAS+5NNpQT0WScArQkig1U9DS6Gr LTNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=UUuq/PLXlwBkLkLIfY/mJJB+6YLD1Vf243Iys/4Xjy0=; b=IilTttwdvXsA7P8kB+SakIxkbUnaeeCm3VIaOp9b0GKP4rDelyHVHdzQ0Sell+bht/ Pel6qmxSe9Q6lUZ4J0dPQb7atVQ6z56ieHkgXjFSzxmL/NR3fKVdk7njup3exU6c5nOA NUZvZu2GPq+SD92YkXK4Cd3AzDq5i/kA6q0rhH4wI4X6vdRWFLq7VjXG4LAmStQDlvdD Ew2P26dr2Ct0IEvpuKrPSMQSWxb6p0o4Ol0PsEbLlAViSBlmR/14h/ftYBV0jAAhtE90 DJzXAfV4f2qt1pPbr09dfAE8rbvvftcTyDu+6yUcT1ukXNKqTFerCqhvOGVXmU+VkCVs A/ZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Ih3iCDMR; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d14-20020a056402516e00b0044e69ba81e1si3583822ede.168.2022.09.10.19.42.27; Sat, 10 Sep 2022 19:43:12 -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=@gmail.com header.s=20210112 header.b=Ih3iCDMR; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229623AbiIKCjx (ORCPT + 99 others); Sat, 10 Sep 2022 22:39:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229531AbiIKCjv (ORCPT ); Sat, 10 Sep 2022 22:39:51 -0400 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83C1A1056A; Sat, 10 Sep 2022 19:39:49 -0700 (PDT) Received: by mail-pj1-x102c.google.com with SMTP id p1-20020a17090a2d8100b0020040a3f75eso5078232pjd.4; Sat, 10 Sep 2022 19:39:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date; bh=UUuq/PLXlwBkLkLIfY/mJJB+6YLD1Vf243Iys/4Xjy0=; b=Ih3iCDMRR8Mb+bnWvQUIqZ8SML690b4DBTYahWeQcG2vVfkOcAYtcWzuJYojGs5yzR ytJvUM/WUNMGUqQ2P5PIHfcAtJxVo3L0KZPRtmZS6q75VPL7Uo4thSyEv3Au0a4V7D9M NGr1m0xUQF65pH+z+MKS04QABI6BuV403/2UQK4XLzj9xvILEoxTmdMI5+k6a5QM1lgv DAv/NbDhJHOuPriEg+AwsCRI50od9pSKwXx29ysDeTviF+t3u13JJgVeg+1lmqgUFZyF LsIJBrQUNAXNyhVobm55vM4yYxcNOrOOB1IQxR/Bmhg7SBwLRrCt/A/LIBTCljzkrHdJ AErw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date; bh=UUuq/PLXlwBkLkLIfY/mJJB+6YLD1Vf243Iys/4Xjy0=; b=vNJDOmykunjJtymPRsUgeAEAKcea1tzNj4XNn/RReU2yerhAUzJbuZu55KHHINqdKC EEzADpkHJTTe6lroL6bO44b4jJme4J29QHwCsLV8zQMz4f9g1NiMPLW9/O12vNp6UkCC o4gMcfFv+WkTD0UJQ6aWz4riUlbgxFCRR+aaPdaSF9226+UlCpZewzVwX5VgAp29ZOZo wX2hnKnjhfKZK2D3cvgJG/0s9fG0odAia1uStOXIhdx9AQZPhKQ+SmQ0a//yjL8Ucj2/ 971PL9150MUFu2GoPCWRwZ/BQMFiLsFnVt0NQfNaJruhubT4ipjg1FCq+MA28ObsUezN UMRg== X-Gm-Message-State: ACgBeo10Qhd/fO66SxMcbxPxpVoAa1SJ0kk5MqTrg7rnZthmWHDHbkqg wWWtPMNQ7rTaNNiwqB/MIbzsGhWIBlYpQw== X-Received: by 2002:a17:90a:e7d2:b0:202:8f4b:bf6b with SMTP id kb18-20020a17090ae7d200b002028f4bbf6bmr9970404pjb.195.1662863988846; Sat, 10 Sep 2022 19:39:48 -0700 (PDT) Received: from localhost ([192.55.55.56]) by smtp.gmail.com with ESMTPSA id 38-20020a631666000000b0041d95d805d6sm2854968pgw.57.2022.09.10.19.39.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Sep 2022 19:39:48 -0700 (PDT) Date: Sat, 10 Sep 2022 19:39:45 -0700 From: Isaku Yamahata To: Chao Gao Cc: isaku.yamahata@intel.com, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Paolo Bonzini , Sean Christopherson , Marc Zyngier , Will Deacon , Yuan Yao , isaku.yamahata@gmail.com, Kai Huang , Atish Patra , Shaokun Zhang , Qi Liu , John Garry , Daniel Lezcano , Huang Ying , Huacai Chen Subject: Re: [PATCH v4 11/26] KVM: Add arch hooks for PM events with empty stub Message-ID: <20220911023945.GD699006@ls.amr.corp.intel.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 On Fri, Sep 09, 2022 at 12:34:39PM +0800, Chao Gao wrote: > On Thu, Sep 08, 2022 at 04:25:27PM -0700, isaku.yamahata@intel.com wrote: > >From: Isaku Yamahata > > > >Add arch hooks for reboot, suspend, resume, and CPU-online/offline events > >with empty stub functions. > > > >Suggested-by: Sean Christopherson > >Signed-off-by: Isaku Yamahata > >--- > > include/linux/kvm_host.h | 6 +++++ > > virt/kvm/Makefile.kvm | 2 +- > > virt/kvm/kvm_arch.c | 44 ++++++++++++++++++++++++++++++ > > virt/kvm/kvm_main.c | 58 +++++++++++++++++++++++++--------------- > > 4 files changed, 88 insertions(+), 22 deletions(-) > > create mode 100644 virt/kvm/kvm_arch.c > > > >diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h > >index eab352902de7..dd2a6d98d4de 100644 > >--- a/include/linux/kvm_host.h > >+++ b/include/linux/kvm_host.h > >@@ -1448,6 +1448,12 @@ int kvm_arch_post_init_vm(struct kvm *kvm); > > void kvm_arch_pre_destroy_vm(struct kvm *kvm); > > int kvm_arch_create_vm_debugfs(struct kvm *kvm); > > > >+int kvm_arch_suspend(int usage_count); > >+void kvm_arch_resume(int usage_count); > >+int kvm_arch_reboot(int val); > >+int kvm_arch_online_cpu(unsigned int cpu, int usage_count); > >+int kvm_arch_offline_cpu(unsigned int cpu, int usage_count); > > Why not extract each of them with one separate patch? Do you mean one patch for each arch callback? They are convoluted. See the comment below. > >diff --git a/virt/kvm/kvm_arch.c b/virt/kvm/kvm_arch.c > >new file mode 100644 > >index 000000000000..4748a76bcb03 > >--- /dev/null > >+++ b/virt/kvm/kvm_arch.c > >@@ -0,0 +1,44 @@ > >+// SPDX-License-Identifier: GPL-2.0-only > >+/* > >+ * kvm_arch.c: kvm default arch hooks for hardware enabling/disabling > >+ * Copyright (c) 2022 Intel Corporation. > >+ * > >+ * Author: > >+ * Isaku Yamahata > >+ * > >+ */ > >+ > >+#include > >+ > >+/* > >+ * Called after the VM is otherwise initialized, but just before adding it to > >+ * the vm_list. > >+ */ > >+__weak int kvm_arch_post_init_vm(struct kvm *kvm) > >+{ > >+ return 0; > >+} > > use "int __weak" to comply with kernel's convension. Will fix. > > static int kvm_offline_cpu(unsigned int cpu) > > { > >+ int ret = 0; > >+ > > mutex_lock(&kvm_lock); > > if (kvm_usage_count) { > > /* > >@@ -5069,10 +5067,15 @@ static int kvm_offline_cpu(unsigned int cpu) > > */ > > preempt_disable(); > > hardware_disable_nolock(NULL); > >+ ret = kvm_arch_offline_cpu(cpu, kvm_usage_count); > >+ if (ret) { > >+ (void)hardware_enable_nolock(NULL); > >+ atomic_set(&hardware_enable_failed, 0); > > The error-handling code ignores hardware enabling failure which looks > weird to me. If you extract kvm_arch_offline_cpu() directly like what > you do in patch 14 (rather than add a stub function first and then move > some code to the stub function), the error-handling code isn't needed. I did it for x86 tsc fix. It relates to suspend/resume. I would split those - introduce suspend/resuem/reboot arch hooks - fix x86 tsc issue - move - introduce cpu online/offline arch hooks - move out PM hooks. probably this can be combined into the previous one. -- Isaku Yamahata