From patchwork Thu Jul 26 05:43:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Mackerras X-Patchwork-Id: 10545233 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 53719A635 for ; Thu, 26 Jul 2018 05:44:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 41B1C2A944 for ; Thu, 26 Jul 2018 05:44:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 35DA62A96A; Thu, 26 Jul 2018 05:44:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D3B272A944 for ; Thu, 26 Jul 2018 05:44:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728899AbeGZG74 (ORCPT ); Thu, 26 Jul 2018 02:59:56 -0400 Received: from ozlabs.org ([203.11.71.1]:45483 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728146AbeGZG7z (ORCPT ); Thu, 26 Jul 2018 02:59:55 -0400 Received: by ozlabs.org (Postfix, from userid 1003) id 41bgz06h3Mz9rvt; Thu, 26 Jul 2018 15:44:44 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1532583884; bh=Fd9y5t21KQV4bJzo8aawwtOUwgXqVmn1pLf7ZEeSe6M=; h=Date:From:To:Cc:Subject:From; b=wLdLAP2C7KeYTowfX0/NVAKBIVNiItr/Ps6QRYvl8yMUd+VMkDcvPRQogBYNpIfXJ dMG9FTStR7w/0u/suEfieIhPh9j5mQUFCB7LFuiwGfAUG0yHSw7Poq6SftIgHSWesy E2SSe8pwMSlpXhAKlt7gfNGhslwhgQ3FMeFqCXOnQqXKL7/jEFhBg04eAZkXnnOks/ NEv1wyUIrXhuMu1lGGwQQoEpadWHqTUhkgAdmbSyyH75v+JeMDQ+vL8wOzEZ4+OyGZ EZ0QOXTCRSoSLX+CiHhA+K/gRZtWRn6VDcATIroX1lnYRAORid6lsFkvY84Yns/YcB bO8EDmEq9M+KQ== Date: Thu, 26 Jul 2018 15:43:54 +1000 From: Paul Mackerras To: kvm@vger.kernel.org, kvm-ppc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Cc: Sam Bobroff , David Gibson Subject: [PATCH 1/2] KVM: PPC: Book3S HV: Allow creating max number of VCPUs on POWER9 Message-ID: <20180726054353.GB1672@fergus> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Commit 1e175d2 ("KVM: PPC: Book3S HV: Pack VCORE IDs to access full VCPU ID space", 2018-07-25) allowed use of VCPU IDs up to KVM_MAX_VCPU_ID on POWER9 in all guest SMT modes and guest emulated hardware SMT modes. However, with the current definition of KVM_MAX_VCPU_ID, a guest SMT mode of 1 and an emulated SMT mode of 8, it is only possible to create KVM_MAX_VCPUS / 2 VCPUS, because threads_per_subcore is 4 on POWER9 CPUs. (Using an emulated SMT mode of 8 is useful when migrating VMs to or from POWER8 hosts.) This increases KVM_MAX_VCPU_ID to 8 * KVM_MAX_VCPUS when HV KVM is configured in, so that a full complement of KVM_MAX_VCPUS VCPUs can be created on POWER9 in all guest SMT modes and emulated hardware SMT modes. Signed-off-by: Paul Mackerras Tested-by: Sam Bobroff --- This and the next patch apply on my kvm-ppc-next branch, which includes Sam Bobroff's patch "KVM: PPC: Book3S HV: Pack VCORE IDs to access full VCPU ID space". arch/powerpc/include/asm/kvm_host.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/include/asm/kvm_host.h b/arch/powerpc/include/asm/kvm_host.h index 5b9e660..906bcbdf 100644 --- a/arch/powerpc/include/asm/kvm_host.h +++ b/arch/powerpc/include/asm/kvm_host.h @@ -42,7 +42,14 @@ #define KVM_USER_MEM_SLOTS 512 #include -#define KVM_MAX_VCPU_ID (threads_per_subcore * KVM_MAX_VCORES) + +#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE +#include /* for MAX_SMT_THREADS */ +#define KVM_MAX_VCPU_ID (MAX_SMT_THREADS * KVM_MAX_VCORES) + +#else +#define KVM_MAX_VCPU_ID KVM_MAX_VCPUS +#endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */ #define __KVM_HAVE_ARCH_INTC_INITIALIZED From patchwork Thu Jul 26 05:44:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Mackerras X-Patchwork-Id: 10545231 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C30649093 for ; Thu, 26 Jul 2018 05:44:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ABA252A944 for ; Thu, 26 Jul 2018 05:44:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9DD0D2A96A; Thu, 26 Jul 2018 05:44:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 278FD2A944 for ; Thu, 26 Jul 2018 05:44:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728808AbeGZG7z (ORCPT ); Thu, 26 Jul 2018 02:59:55 -0400 Received: from ozlabs.org ([203.11.71.1]:54165 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727070AbeGZG7z (ORCPT ); Thu, 26 Jul 2018 02:59:55 -0400 Received: by ozlabs.org (Postfix, from userid 1003) id 41bgz0687fz9s21; Thu, 26 Jul 2018 15:44:44 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1532583884; bh=2Y6qB/dcU7qsza1Bpiw+I2J00uTnDdFjbrruS8INHFo=; h=Date:From:To:Cc:Subject:From; b=iKgbvBKcpF+kqEhV7Eq5HL/yv09bwFesn986y/0czYJ9OddDdRo6pGNCWexe7ZEup ZcoauEMUKdPUuGF6M5vIVVVae5b2tE1Uv2x2ocanrA8Ka+wpFRaQBNg+6khMPBfvGq gSB5A01c7//szv/wJAGE5djKBWM2baPg+JNvLY9YyZSQ4IxQIya2tsLZy4JyTUriUy i7I6i4BWDlcmD0BWCls3q9SLetrqXjkokfhtSxzZyaGmlJ6MNv0yyHI9t7jeeBzGPv oJUgfGtOErrquP/9bHo0519ecZYkd44pz3Oj+pN9rYuegZbLQrVxzDH7jm5LgMwfQK 5dWqbpr28FFhQ== Date: Thu, 26 Jul 2018 15:44:34 +1000 From: Paul Mackerras To: kvm@vger.kernel.org, kvm-ppc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Cc: Sam Bobroff , David Gibson Subject: [PATCH 2/2] KVM: PPC: Book3S HV: Read kvm->arch.emul_smt_mode under kvm->lock Message-ID: <20180726054434.GC1672@fergus> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Commit 1e175d2 ("KVM: PPC: Book3S HV: Pack VCORE IDs to access full VCPU ID space", 2018-07-25) added code that uses kvm->arch.emul_smt_mode before any VCPUs are created. However, userspace can change kvm->arch.emul_smt_mode at any time up until the first VCPU is created. Hence it is (theoretically) possible for the check in kvmppc_core_vcpu_create_hv() to race with another userspace thread changing kvm->arch.emul_smt_mode. This fixes it by moving the test that uses kvm->arch.emul_smt_mode into the block where kvm->lock is held. Signed-off-by: Paul Mackerras --- arch/powerpc/kvm/book3s_hv.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c index 785245e..113f815 100644 --- a/arch/powerpc/kvm/book3s_hv.c +++ b/arch/powerpc/kvm/book3s_hv.c @@ -1989,16 +1989,10 @@ static struct kvm_vcpu *kvmppc_core_vcpu_create_hv(struct kvm *kvm, unsigned int id) { struct kvm_vcpu *vcpu; - int err = -EINVAL; + int err; int core; struct kvmppc_vcore *vcore; - if (id >= (KVM_MAX_VCPUS * kvm->arch.emul_smt_mode) && - cpu_has_feature(CPU_FTR_ARCH_300)) { - pr_devel("DNCI: VCPU ID too high\n"); - goto out; - } - err = -ENOMEM; vcpu = kmem_cache_zalloc(kvm_vcpu_cache, GFP_KERNEL); if (!vcpu) @@ -2055,8 +2049,13 @@ static struct kvm_vcpu *kvmppc_core_vcpu_create_hv(struct kvm *kvm, vcore = NULL; err = -EINVAL; if (cpu_has_feature(CPU_FTR_ARCH_300)) { - BUG_ON(kvm->arch.smt_mode != 1); - core = kvmppc_pack_vcpu_id(kvm, id); + if (id >= (KVM_MAX_VCPUS * kvm->arch.emul_smt_mode)) { + pr_devel("KVM: VCPU ID too high\n"); + core = KVM_MAX_VCORES; + } else { + BUG_ON(kvm->arch.smt_mode != 1); + core = kvmppc_pack_vcpu_id(kvm, id); + } } else { core = id / kvm->arch.smt_mode; }