From patchwork Thu Nov 14 14:59:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 179451 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp11170169ilf; Thu, 14 Nov 2019 07:00:13 -0800 (PST) X-Google-Smtp-Source: APXvYqwccPEPoX8abwUZA7uyiY0CWy/TJCOMAIB+4ORYJVVMIPi1su7sobkfy0j6L1o1S2jrVECQ X-Received: by 2002:a05:6402:883:: with SMTP id e3mr1767221edy.32.1573743612882; Thu, 14 Nov 2019 07:00:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573743612; cv=none; d=google.com; s=arc-20160816; b=XtIisEHv1FN16G826aPGyzP6TjudG2EhJOpesUn4G6XJKT+yaU1E/igqfD6oJQxDdb u8CtjbqIA3D+ShhugbQn3Uwl40/1NhCWaglDGRJLZF+p4gevosxPh1z5b5RaeI02Q8Fm 65PUM5OVDxay6OECHJZ4AUINl1b++3yHZij89NOYBi7YHE6jKdIhm8F9bvJ/eFtDIrPf Cn7Jj/+m9plYbr4qrWLLnUAdunC7ksIBkyoj2YgZP8TDl5yjf4SdgU4TNVG1Lc0y9F1k 1FnT3IANI7KtPwIZbz2oFYfKyPnI1DUnj7y5ivm1THELuehwj6kaQWB3lLrwWhw82eaE YSnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=ll/JgHjCtv3FaR0mZfjhrg0KpztudlfPt00tIZAFMXQ=; b=aazR7auIGWmJzysfNOZe1TssOK2er/kY77buZ3NiTkLDr/rIZCVjR0T2L6TAyQxVWW DMqxryJlE8r95EmPHxkbozQtkSZHzyNCbfTcMcW9GHWmkVUGaeHxA93+X0Zo3wjJi1rj 6bUTWrSAOIz/QrON9iKB/ioEwq28jbOtzVBBVV6sxq+d8tUXBhcpj7qCtshXdURF4Kuw wRc9rJFfqARILf13yqX9jttDdIKItMNmR++pMShRmuxtWqGKhxWDNX6/r3QcGBFo+gqQ bNopsXLi+htJT3QbF0i1diQWtDZGCUGDcOLTV3fNr7DRBpjbA6XFvjQuU8O3a8Re7AxC KkIQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id gs14si3604239ejb.347.2019.11.14.07.00.12; Thu, 14 Nov 2019 07:00:12 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726953AbfKNPAL (ORCPT + 26 others); Thu, 14 Nov 2019 10:00:11 -0500 Received: from foss.arm.com ([217.140.110.172]:44650 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726766AbfKNPAF (ORCPT ); Thu, 14 Nov 2019 10:00:05 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 84A00328; Thu, 14 Nov 2019 07:00:04 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 663033F52E; Thu, 14 Nov 2019 07:00:03 -0800 (PST) From: Suzuki K Poulose To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, james.morse@arm.com, will@kernel.org, catalin.marinas@arm.com, mark.rutland@arm.com, maz@kernel.org, suzuki.poulose@arm.com Subject: [PATCH 5/5] KVM: arm/arm64: Don't invoke defacto-CnP on first run Date: Thu, 14 Nov 2019 14:59:18 +0000 Message-Id: <20191114145918.235339-6-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191114145918.235339-1-suzuki.poulose@arm.com> References: <20191114145918.235339-1-suzuki.poulose@arm.com> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: James Morse When KVM finds itself switching between two vCPUs of the same VM on one physical CPU it has to invalidate the TLB for this VMID to avoid unintended sharing of TLB entries between vCPU. This is done by tracking the 'last_vcpu_ran' as a percpu variable for each vm. kvm_arch_init_vm() is careful to initialise these to an impossible vcpu id, but we never check for this. The first time vm_arch_vcpu_load() is called on a new physical CPU, we will fail the last_ran check and invalidate the TLB. Now that we have an errata workaround in this path, it means we trigger the workaround whenever a guest is migrated to a new CPU. Check for the impossible vcpu id, and skip defacto-CnP. Signed-off-by: James Morse Signed-off-by: Suzuki K Poulose --- virt/kvm/arm/arm.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) -- 2.23.0 diff --git a/virt/kvm/arm/arm.c b/virt/kvm/arm/arm.c index ac9e017df7c9..6f729739cf6f 100644 --- a/virt/kvm/arm/arm.c +++ b/virt/kvm/arm/arm.c @@ -366,7 +366,7 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) * We might get preempted before the vCPU actually runs, but * over-invalidation doesn't affect correctness. */ - if (*last_ran != vcpu->vcpu_id) { + if (*last_ran != -1 && *last_ran != vcpu->vcpu_id) { kvm_call_hyp(__kvm_tlb_flush_local_vmid, vcpu); /* @@ -374,9 +374,8 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) * conditions for Cortex-A77 erratum 1542418. */ kvm_workaround_1542418_vmid_rollover(); - - *last_ran = vcpu->vcpu_id; } + *last_ran = vcpu->vcpu_id; vcpu->cpu = cpu; vcpu->arch.host_cpu_context = &cpu_data->host_ctxt;