Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3593388rwb; Mon, 3 Oct 2022 18:14:33 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7OT/bxhtaiddL5NHrYmZeM/s5PW6Kc+NeQJMde+G7K+5KJNaBruokuo/PgciW+CEnua2Ae X-Received: by 2002:a17:907:272a:b0:78c:79d0:d9ee with SMTP id d10-20020a170907272a00b0078c79d0d9eemr3649671ejl.57.1664846072946; Mon, 03 Oct 2022 18:14:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664846072; cv=none; d=google.com; s=arc-20160816; b=Qbyd4irbSFbNKKSeovysGHPq1yWQScvBqk5jdQy4h6KIc2CdxTSQ/3lEViW8xdKsLt TQtUjc4rISvICIqxxdcmOfUFqlgrEBJ6nKn1fovXDxx02eo93tFQg+fgjchigZprO5hJ pElQ88c8Fq0TJvUg8zL/a80bqYsY6ym7fAnMLo80UBY0OTg+Ve3m9ot8rDUt7ugUXU2e eLT4ojJo+Oyl4eMtSsILrXDy6GMchXgs8y164NX18vtoW/LcLSr5mQGsFp7y5AjmAW5j SvrdCPS52FwiB4fOg+6TX7lC4/lnxoPdyK/lNvoC9n8sOTkwW4cPLGE81WNpG8/qrXd9 U6Kw== 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=XkfaP4z8rj8m1nh6hzVG/ifhPmRZtFcqbAYS1A6pGEo=; b=zHO0ofvckPLIInMzoFotTg9rqU/z3ukXaNDne4bN+iUfRjS4+WOFL69Me0Nx8vJ0jz ZV11qTVE2Dl1BrcB8Xr1tjjzoh6Dz7Fivi/7oUL7Rkd0Hbg6gR26dyOK7MpTB8Q1rfdj FfqDOUEx3gOTQatk2Rf8IP3j7seGuH0Dbtz37NMCO4sd2oseCYKvOMSAoYH47b/u5rYI qWgnZR1rjWELbIHVzMNGeglOpIYbpk0ptxC7StC5oLyuMyn1JM1tztUKHROXMko0uw/P IdexncuaaogWWko5AR5O8jTnHr3/pjYqlkP2ar0/hHXF4ycNbStmGKwmKHxaOVnJeEup vnXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=lKYgrQhQ; 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 l20-20020a056402255400b00450f1234f3esi11140982edb.199.2022.10.03.18.14.07; Mon, 03 Oct 2022 18:14:32 -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=lKYgrQhQ; 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 S229799AbiJDAQ0 (ORCPT + 99 others); Mon, 3 Oct 2022 20:16:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229453AbiJDAQZ (ORCPT ); Mon, 3 Oct 2022 20:16:25 -0400 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D296A23162; Mon, 3 Oct 2022 17:16:24 -0700 (PDT) Received: by mail-pj1-x1035.google.com with SMTP id b15so3283116pje.1; Mon, 03 Oct 2022 17:16:24 -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=XkfaP4z8rj8m1nh6hzVG/ifhPmRZtFcqbAYS1A6pGEo=; b=lKYgrQhQnpLRRsjvAnLEKjzljiOftYXFK3YUYDNscfVaWakvRjcq6K41PYn/5zsJYv //nibRVRyneMtjhIi5meWQxp+foUp19LDSPTEOB/mM1jVUdlVmD+iqbW2nm592LFIf1w t4yMdwOCKYFX8QfsEH5B73FCyN5s/0QbJVI4jhaj5TTBbCCppceh/OxOVvXQBSr8zcyx mgjHU3rFpHqVtMVwClaouaEHj43fvxfRQFJEVLNl9PXtfHQPrbHdfpBC8bhcEYWyzLjg UwMWuoovtQLW8L8i5KM+xXcTzgSQPK8v4ERUFw6xSysPdHwYArR6sWOvRAPiR/u5r28O b5yQ== 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=XkfaP4z8rj8m1nh6hzVG/ifhPmRZtFcqbAYS1A6pGEo=; b=oUAcqyEw9wOhy2y/3yzkH5QlMs75ggVLYlSbJXmg9iUbXN6wZNIihVe83ogB57ujIu rKJkHbp5qwEOkB+HgkkvP3EztvHnus/8seqtHy6gK5g/1YpeqDq2z/Fh/1V3ZjnzoOFw MTpgcohp7GhFEBvwOt0HgZV9p6sQZFmUJOsuE+Ha5jWN0P4Y6f1D9b4QoaXtVVD0/o2/ IdqyXa1B4f6NsBvlKHsLk0moChCJNzcUkqbksqPQWvBTIvJco6VaQRQncMm2GGDJ+KLx kIkOka6L+wBLKPKKvABbigxiXwy8wa137rRcdvQjwT2kEO9SX/bqDzcokV9jSEA/M52U rQ3w== X-Gm-Message-State: ACrzQf11alvk1gtDmdxV62AQWEVM1XQZw9QEvwTqV23cxXr0O8XTnX+c Co1lLyruS2X4fq0YlrjbSyw= X-Received: by 2002:a17:90b:30d5:b0:20a:6453:43f with SMTP id hi21-20020a17090b30d500b0020a6453043fmr14904562pjb.74.1664842584177; Mon, 03 Oct 2022 17:16:24 -0700 (PDT) Received: from localhost ([192.55.54.55]) by smtp.gmail.com with ESMTPSA id j10-20020a17090a31ca00b0020aacde1964sm1839620pjf.32.2022.10.03.17.16.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Oct 2022 17:16:23 -0700 (PDT) Date: Mon, 3 Oct 2022 17:16:21 -0700 From: Isaku Yamahata To: isaku.yamahata@intel.com Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Paolo Bonzini , Sean Christopherson , Thomas Gleixner , Marc Zyngier , Will Deacon , isaku.yamahata@gmail.com, Kai Huang , Chao Gao , Atish Patra , Shaokun Zhang , Daniel Lezcano , Huang Ying , Huacai Chen , Dave Hansen , Borislav Petkov Subject: Re: [PATCH v5 10/30] KVM: Add arch hooks when VM is added/deleted Message-ID: <20221004001621.GJ2414580@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 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 Thu, Sep 22, 2022 at 11:20:39AM -0700, isaku.yamahata@intel.com wrote: > From: Isaku Yamahata > > and pass kvm_usage_count with kvm_lock. Move kvm_arch_post_init_vm() under > kvm_arch_add_vm(). Replace enable/disable_hardware_all() with the default > implementation of kvm_arch_add/del_vm(). Later kvm_arch_post_init_vm() is > deleted once x86 overrides kvm_arch_add_vm(). > > Suggested-by: Sean Christopherson > Signed-off-by: Isaku Yamahata > --- > include/linux/kvm_host.h | 2 + > virt/kvm/kvm_main.c | 121 ++++++++++++++++++++------------------- > 2 files changed, 65 insertions(+), 58 deletions(-) > > diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h > index eab352902de7..3fbb01bbac98 100644 > --- a/include/linux/kvm_host.h > +++ b/include/linux/kvm_host.h > @@ -1445,6 +1445,8 @@ int kvm_arch_vcpu_should_kick(struct kvm_vcpu *vcpu); > bool kvm_arch_dy_runnable(struct kvm_vcpu *vcpu); > bool kvm_arch_dy_has_pending_interrupt(struct kvm_vcpu *vcpu); > int kvm_arch_post_init_vm(struct kvm *kvm); > +int kvm_arch_add_vm(struct kvm *kvm, int usage_count); > +int kvm_arch_del_vm(int usage_count); > void kvm_arch_pre_destroy_vm(struct kvm *kvm); > int kvm_arch_create_vm_debugfs(struct kvm *kvm); > > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c > index c4b908553726..e2c8823786ff 100644 > --- a/virt/kvm/kvm_main.c > +++ b/virt/kvm/kvm_main.c > @@ -142,8 +142,9 @@ static int kvm_no_compat_open(struct inode *inode, struct file *file) > #define KVM_COMPAT(c) .compat_ioctl = kvm_no_compat_ioctl, \ > .open = kvm_no_compat_open > #endif > -static int hardware_enable_all(void); > -static void hardware_disable_all(void); > +static void hardware_enable_nolock(void *junk); > +static void hardware_disable_nolock(void *junk); > +static void kvm_del_vm(void); > > static void kvm_io_bus_destroy(struct kvm_io_bus *bus); > > @@ -1106,6 +1107,41 @@ int __weak kvm_arch_post_init_vm(struct kvm *kvm) > return 0; > } > > +/* > + * Called after the VM is otherwise initialized, but just before adding it to > + * the vm_list. > + */ > +int __weak kvm_arch_add_vm(struct kvm *kvm, int usage_count) > +{ > + int r = 0; > + > + if (usage_count != 1) > + return 0; Oops. This line should be. + return kvm_arch_post_init_vm(kvm); "KVM: x86: Duplicate arch callbacks related to pm events and compat check" should have same line. "KVM: Eliminate kvm_arch_post_init_vm()" should include kvm_mmu_post_init_vm(). It creates a kernel thread. kvm unit test didn't catch it. Thanks, > + > + atomic_set(&hardware_enable_failed, 0); > + on_each_cpu(hardware_enable_nolock, NULL, 1); > + > + if (atomic_read(&hardware_enable_failed)) { > + r = -EBUSY; > + goto err; > + } > + > + r = kvm_arch_post_init_vm(kvm); > +err: > + if (r) > + on_each_cpu(hardware_disable_nolock, NULL, 1); > + return r; > +} > + > +int __weak kvm_arch_del_vm(int usage_count) > +{ > + if (usage_count) > + return 0; > + > + on_each_cpu(hardware_disable_nolock, NULL, 1); > + return 0; > +} > + > /* > * Called just after removing the VM from the vm_list, but before doing any > * other destruction. -- Isaku Yamahata