Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp5989861pxv; Thu, 29 Jul 2021 03:46:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzcE+PumllmUA/dvE5eeoCXvCV4mfYSCfVOEk5rcJLbj7B4/DVxwC0Hgb7OZSu3+DXBl3ey X-Received: by 2002:a92:7f03:: with SMTP id a3mr3287116ild.254.1627555585769; Thu, 29 Jul 2021 03:46:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627555585; cv=none; d=google.com; s=arc-20160816; b=DL0D1XPLUcml+tiikry0oMoGpBYAsJZxEhIdBHM55eo2uKXL9L2RCLvf+z9AfQf79S 6bfzuiKwtv1vmZjALZ/Vih9rPIrQqoKEce5RDUjf4h397pEbYAhgbHRBDtVN9plZgrii G0tcMnws8Ikv800f/I48qHtUaX+e/3/+22ZTQ5B6DRYF4bDov9nP6q+Ud8aaXOL11i68 QAYGyfVPBb0hug30Ttucd6JZAX6b+Dxwy9/+OkMzvjbGjccrGKPKg6/IOlfEq1DktU0t EgLB72tgnRz+6cRI7NsEZIesOoBW9q+r40o5cUS4rISGh7DlzvtQ3D8f7NoQvnb9EXFv bHjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=EvjGBXf0LiGOhuPuwUyXy9zi+7Cg7W0MgL/76kclKB0=; b=Uc179dn69Z/dAP12y7Rq9JS5L7a86/vvnDrzJNfpN3sfaf9lbQw/XWE7/YlTrhebW6 I94jXmCb1zauj2RPEC9SpTrOG1apGfpuOC4C/ucIO/sMnLXVPKv902SMJs0XyRremENc l2805IsbCyTi21yBKRFvDXSfcCCr8dxBssUAzy7p1xY1j0UFhMvEof1yEJMwCSwcbvRV ZqEKnt/+nvT4bqzuVmFk/BmCruz7Q6tCsNN/spz2JM0RZPZAQ7UleYas0r9B4GIS08Eo ykfP+uA2yITuNFUEQj/q/at8Bm4CUhsfcH6B9riYnKb1fU7+M0nufB8nyTPUeEC/aoYX KuoA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p16si2848776ilj.162.2021.07.29.03.46.14; Thu, 29 Jul 2021 03:46:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236414AbhG2KoR (ORCPT + 99 others); Thu, 29 Jul 2021 06:44:17 -0400 Received: from frasgout.his.huawei.com ([185.176.79.56]:3522 "EHLO frasgout.his.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236292AbhG2KoP (ORCPT ); Thu, 29 Jul 2021 06:44:15 -0400 Received: from fraeml707-chm.china.huawei.com (unknown [172.18.147.206]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4Gb6NZ3C6lz6FG8P; Thu, 29 Jul 2021 18:34:54 +0800 (CST) Received: from lhreml710-chm.china.huawei.com (10.201.108.61) by fraeml707-chm.china.huawei.com (10.206.15.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Thu, 29 Jul 2021 12:44:11 +0200 Received: from A2006125610.china.huawei.com (10.47.90.183) by lhreml710-chm.china.huawei.com (10.201.108.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Thu, 29 Jul 2021 11:44:04 +0100 From: Shameer Kolothum To: , , CC: , , , , , , , , , Subject: [PATCH v3 4/4] KVM: arm64: Clear active_vmids on vCPU schedule out Date: Thu, 29 Jul 2021 11:40:09 +0100 Message-ID: <20210729104009.382-5-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20210729104009.382-1-shameerali.kolothum.thodi@huawei.com> References: <20210729104009.382-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.47.90.183] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To lhreml710-chm.china.huawei.com (10.201.108.61) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Like ASID allocator, we copy the active_vmids into the reserved_vmids on a rollover. But it's unlikely that every CPU will have a vCPU as current task and we may end up unnecessarily reserving the VMID space. Hence, clear active_vmids when scheduling out a vCPU. Suggested-by: Will Deacon Signed-off-by: Shameer Kolothum --- arch/arm64/include/asm/kvm_host.h | 1 + arch/arm64/kvm/arm.c | 1 + arch/arm64/kvm/vmid.c | 6 ++++++ 3 files changed, 8 insertions(+) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index bb993bce1363..d93141cb8d16 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -687,6 +687,7 @@ extern unsigned int kvm_arm_vmid_bits; int kvm_arm_vmid_alloc_init(void); void kvm_arm_vmid_alloc_free(void); void kvm_arm_vmid_update(struct kvm_vmid *kvm_vmid); +void kvm_arm_vmid_clear_active(void); static inline void kvm_arm_pvtime_vcpu_init(struct kvm_vcpu_arch *vcpu_arch) { diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 077e55a511a9..b134a1b89c84 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -435,6 +435,7 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu) kvm_timer_vcpu_put(vcpu); kvm_vgic_put(vcpu); kvm_vcpu_pmu_restore_host(vcpu); + kvm_arm_vmid_clear_active(); vcpu->cpu = -1; } diff --git a/arch/arm64/kvm/vmid.c b/arch/arm64/kvm/vmid.c index 5584e84aed95..5fd51f5445c1 100644 --- a/arch/arm64/kvm/vmid.c +++ b/arch/arm64/kvm/vmid.c @@ -116,6 +116,12 @@ static u64 new_vmid(struct kvm_vmid *kvm_vmid) return idx2vmid(vmid) | generation; } +/* Call with preemption disabled */ +void kvm_arm_vmid_clear_active(void) +{ + atomic64_set(this_cpu_ptr(&active_vmids), 0); +} + void kvm_arm_vmid_update(struct kvm_vmid *kvm_vmid) { unsigned long flags; -- 2.17.1