Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp2550055pxy; Tue, 3 Aug 2021 09:00:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy7hK/vpu1TkpKGYGATwmiaWToeZDztDWB6EiyoaMN437c1NdMfvM2+zFgMK4+F23hDZlJO X-Received: by 2002:a05:651c:1794:: with SMTP id bn20mr15565117ljb.140.1628006438045; Tue, 03 Aug 2021 09:00:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628006438; cv=none; d=google.com; s=arc-20160816; b=OWkLubSPfYprE9EHpm1KuZrs+DzSryNvEhEk7XXAtGC+e1ZmI9OX26z+ELr3ph3l0f pA8NM3zBsmTlZlOYVEiYThZWMoERX2TMZxeYDQ0Ll7caNGPdoma27pd56cPVsa8MWIB9 5RIOAuUYJks6sXFMvSASW9lKNSYhkVpi06l5oTeKZeHBjuYUCwhSkZcZBXC+/hzidnLb +8g961iVHynreS2zKusOX80WHrawYIk9ozGmbODno+Y0KVFDHUFvymyajCwrTKBi0T05 1dlz8nEkhWZfVDecqZps1MVFdJuBqP1SssHBwPD6ltXXpv4eo9OjnOAynCcdIJN4zb8C XKQQ== 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=muQPJBJ83ym6OQ+XHYE0YUkc5rbPtiDks14Y8CdynkU=; b=HEm8BfL07Tia5SQ8cVQz4Swo0r7254o/t7i1R6kPnhkISKR6bOEb3+VyRbAoWZQMfV Jp2lTfgHubTiecDrtX6FKiJlMtqLOwP4LJNkJpAM4Oowv5l45i+2KaTrcYvMUcaDJWV8 uBLIup1MPYeJM5FlX3V35gZDZY64WkTqN34YEcQdZR2o6bZRsr2+Gjth9fDYzYC/RodF 5h5HP7eqttlqLUn7SSm6lnJTdq1ia7x6PxiYdJ8rbSmgRspEfFEiZQ5w7iqchcqYAp5c XoI7pPZN0tJNgM7rJ5sGf+xHx8Wtm9250Zax/7V+JsKQDsMb3rcwKSH9FTNeBw8ot+g6 X0Ww== 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 f13si13496845edw.513.2021.08.03.09.00.13; Tue, 03 Aug 2021 09:00:38 -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 S237169AbhHCP41 convert rfc822-to-8bit (ORCPT + 99 others); Tue, 3 Aug 2021 11:56:27 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:4025 "EHLO szxga06-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237143AbhHCP40 (ORCPT ); Tue, 3 Aug 2021 11:56:26 -0400 Received: from dggems703-chm.china.huawei.com (unknown [172.30.72.60]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4GfKCL1Y7lzmmZs; Tue, 3 Aug 2021 23:53:02 +0800 (CST) Received: from lhreml710-chm.china.huawei.com (10.201.108.61) by dggems703-chm.china.huawei.com (10.3.19.180) 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 23:56:10 +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 16:56:09 +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/6thny2AgAAaZCCAACXigIAAEl3Q Date: Tue, 3 Aug 2021 15:56:08 +0000 Message-ID: <58bf7a27a4c440c685c6b1e7c9325441@huawei.com> References: <20210729104009.382-1-shameerali.kolothum.thodi@huawei.com> <20210729104009.382-5-shameerali.kolothum.thodi@huawei.com> <20210803114034.GB30853@willie-the-truck> <20210803153036.GA31125@willie-the-truck> In-Reply-To: <20210803153036.GA31125@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="us-ascii" 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 16:31 > 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 Tue, Aug 03, 2021 at 12:55:25PM +0000, Shameerali Kolothum Thodi > wrote: > > > > 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. > > Why didn't you say so?! Sorry. I thought of getting some performance numbers with and without this patch and measure the impact. But didn't quite get time to finish it yet. > > > > 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 > > I think we have to be really careful not to run into the "suspended > animation" problem described in ae120d9edfe9 ("ARM: 7767/1: let the ASID > allocator handle suspended animation") if we go down this road. Ok. I will go through that. > Maybe something along the lines of: > > ROLLOVER > > * Take lock > * Inc generation > => This will force everybody down the slow path > * Record active VMIDs > * Broadcast TLBI > => Only active VMIDs can be dirty > => Reserve active VMIDs and mark as allocated > > VCPU SCHED IN > > * Set active VMID > * Check generation > * If mismatch then: > * Take lock > * Try to match a reserved VMID > * If no reserved VMID, allocate new > > VCPU SCHED OUT > > * Clear active VMID > > but I'm not daft enough to think I got it right first time. I think it > needs both implementing *and* modelling in TLA+ before we merge it! > Ok. I need some time to digest the above first :). On another note, how serious do you think is the problem of extra reservation of the VMID space? Just wondering if we can skip this patch for now or not.. Thanks, Shameer