Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp2408306pxy; Tue, 3 Aug 2021 05:56:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzeb1UxnaTYNjQIaD19k67RZQmAYtAPZNM7LHHnKqkljh9rz2Ckv3KHNHapyMcPS+sjmKLa X-Received: by 2002:a05:6e02:f05:: with SMTP id x5mr193724ilj.268.1627995399195; Tue, 03 Aug 2021 05:56:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627995399; cv=none; d=google.com; s=arc-20160816; b=pmgFfctwpn924zPde8NuOqqBwR1cVfKkTvfo5NBVk+rYxrzcuP8qHqDS9PDwnkfalU O63pXkpg7SUOFaBNwUCuUFwFJy9YzyaWyDF+f8XISVf71F/Lve3eR8uKsucipBDyySOR XWuKbzi3PfFVl2Kl04vCVgjUrhPpJUdjjAc7jV014rQFBRaTfd8xmU6OP94H4xpqKKz/ TyRSG0lPbO9GmqLhpXB7JLH5ErKQr2fo9tuPMEcG+CXm1OvKiu8tvQ87/2SquX28YBkk edK6+IhPuivmQ5A20Hlslj2ifdLCGqYUhsrm0yjm7Q6z87oLtcY7xy3hOLYipm7xQVM7 5uRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from; bh=pQGJC5HChz65JRJOec4RmopSF/wG1sMUy4HZI0+PDS8=; b=QyQjZ/lUa8r/eiSkzKjJBne9PCXrid+bqIJrl0JmMIs1mVax3IdcZVKOoPKgX8yvv6 +CL2japV25s2plO7Fvl9spHwtGPVz9jeKUfohLVry2/pVUfFD79wcu6yryLxzlF0r4cK J7LQRGoFv6tJzuQVlT7YBJ4EnFMaLHMTFrVtazek6l+Mw8eeEpvCNBOAItoH7XFBI+qb hSUDgEcnBWzgpxNenxeAsXzFNGcOokTIe3r10s/bwqYxePE/C4c83M1I+iS8Xo2Z6ifm o/rXkQMI6lziN094byKMQa0zm0yj+c2X8ZdGxeOPKjsCJOpXDfADxdCWs4N9QcKSDznO Ja2w== 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 q15si15194194ile.132.2021.08.03.05.56.26; Tue, 03 Aug 2021 05:56:39 -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 S236100AbhHCMzp convert rfc822-to-8bit (ORCPT + 99 others); Tue, 3 Aug 2021 08:55:45 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:6646 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236094AbhHCMzl (ORCPT ); Tue, 3 Aug 2021 08:55:41 -0400 Received: from dggems705-chm.china.huawei.com (unknown [172.30.72.59]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4GfFB20Fmzz18Nbw; Tue, 3 Aug 2021 20:51:38 +0800 (CST) Received: from lhreml710-chm.china.huawei.com (10.201.108.61) by dggems705-chm.china.huawei.com (10.3.19.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Tue, 3 Aug 2021 20:55:27 +0800 Received: from lhreml710-chm.china.huawei.com ([169.254.81.184]) by lhreml710-chm.china.huawei.com ([169.254.81.184]) with mapi id 15.01.2176.012; Tue, 3 Aug 2021 13:55:25 +0100 From: Shameerali Kolothum Thodi To: Will Deacon CC: "linux-arm-kernel@lists.infradead.org" , "kvmarm@lists.cs.columbia.edu" , "linux-kernel@vger.kernel.org" , "maz@kernel.org" , "catalin.marinas@arm.com" , "james.morse@arm.com" , "julien.thierry.kdev@gmail.com" , "suzuki.poulose@arm.com" , "jean-philippe@linaro.org" , "Alexandru.Elisei@arm.com" , "qperret@google.com" , Linuxarm Subject: RE: [PATCH v3 4/4] KVM: arm64: Clear active_vmids on vCPU schedule out Thread-Topic: [PATCH v3 4/4] KVM: arm64: Clear active_vmids on vCPU schedule out Thread-Index: AQHXhGar1JrryboKrU+7h+yU/0K2/6thny2AgAAaZCA= Date: Tue, 3 Aug 2021 12:55:25 +0000 Message-ID: References: <20210729104009.382-1-shameerali.kolothum.thodi@huawei.com> <20210729104009.382-5-shameerali.kolothum.thodi@huawei.com> <20210803114034.GB30853@willie-the-truck> In-Reply-To: <20210803114034.GB30853@willie-the-truck> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.47.86.18] Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > -----Original Message----- > From: Will Deacon [mailto:will@kernel.org] > Sent: 03 August 2021 12:41 > To: Shameerali Kolothum Thodi > Cc: linux-arm-kernel@lists.infradead.org; kvmarm@lists.cs.columbia.edu; > linux-kernel@vger.kernel.org; maz@kernel.org; catalin.marinas@arm.com; > james.morse@arm.com; julien.thierry.kdev@gmail.com; > suzuki.poulose@arm.com; jean-philippe@linaro.org; > Alexandru.Elisei@arm.com; qperret@google.com; Linuxarm > > Subject: Re: [PATCH v3 4/4] KVM: arm64: Clear active_vmids on vCPU > schedule out > > On Thu, Jul 29, 2021 at 11:40:09AM +0100, Shameer Kolothum wrote: > > 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); > > +} > > I think this is very broken, as it will force everybody to take the > slow-path when they see an active_vmid of 0. Yes. I have seen that happening in my test setup. > It also doesn't solve the issue I mentioned before, as an active_vmid of 0 > means that the reserved vmid is preserved. > > Needs more thought... How about we clear all the active_vmids in kvm_arch_free_vm() if it matches the kvm_vmid->id ? But we may have to hold the lock there. Thanks, Shameer