Received: by 10.213.65.68 with SMTP id h4csp23055imn; Thu, 15 Mar 2018 08:26:28 -0700 (PDT) X-Google-Smtp-Source: AG47ELuDhOnPTcZuEn6jknE7BugEwPJZU9PEPlwoEOacI0cnJQ17h5dn3Uzem8h5fDVMgyRT8h1h X-Received: by 10.98.60.15 with SMTP id j15mr8074298pfa.7.1521127588795; Thu, 15 Mar 2018 08:26:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521127588; cv=none; d=google.com; s=arc-20160816; b=BFBbiYrms/ezJkcHMpL0JwBku1QLd7S4EIEDMRtsTPCgFK1dg5SfI0JSkSR5vQzrwb CVfqY8bUNqmfDkVfB3H4fAY8XIArb2A7IsIstSq6ziofjj77fEYLv8GtDMWQwdyvtMQ0 6co4Ll4o7E2otyuGjfEGIlv7lk78yQFq/xQ1EVH71N4zGH0ZqlAxL08IEirHMbVBfelb cdXn3ZWMIT5EuNSCEcnsS1c8H2jD2EXSYNyzwSkT+qBBE/Y86spmWGk0u7MPfelFkZvc ztDAdekECrU4wUQe2h5BULWaJ63lZ6Zbhgcngjs54OSOg4xYut+7w6n+7vBhETo6S58A XLBA== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=kH8+VE8bRh4fKRVb00nr9i4JhaXNkFr2cfoizZUEuLY=; b=BFMbu7P4vgBAcRlK0mTVW8Fr6Q62EtpVHT+jmB1niG3Hgc037kCq6LFFoemDx/r4zp Vq3w/lQnpYb/NYuZoMd/SQ7RQkWsrCAhv/WjcLbykooZ9g/gz70HyrEdO7bRuAmvMthR GxSTWI12454HOSYhWx9fJJhOCibMjfn5hPIhIsmuyIqKrQ9GBB0SYKFhiFGYqkS4YqLq aVKSx9nZmgO9EfpT2AQSYxDa4IN8jU6j24W9SFkuITwV/Htyq3d7I8MpQUW6Zig5QzwJ U/97V+14df4pvfIDg9icoSb0a3dKX2a+nG4UmI0bilHZLhNdtF27CWBqvDuUmU3V/H5d oXSw== 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 p11-v6si4133086plo.619.2018.03.15.08.26.12; Thu, 15 Mar 2018 08:26:28 -0700 (PDT) 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 S932499AbeCOPZE (ORCPT + 99 others); Thu, 15 Mar 2018 11:25:04 -0400 Received: from foss.arm.com ([217.140.101.70]:41262 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751983AbeCOPZD (ORCPT ); Thu, 15 Mar 2018 11:25:03 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BBCDF1435; Thu, 15 Mar 2018 08:25:02 -0700 (PDT) Received: from [10.1.206.73] (en101.cambridge.arm.com [10.1.206.73]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 5BC723F487; Thu, 15 Mar 2018 08:25:00 -0700 (PDT) Subject: Re: [PATCH v1 13/16] kvm: arm64: Configure VTCR per VM To: Christoffer Dall Cc: Linux ARM , KVM , kvmarm@lists.cs.columbia.edu, Marc Zyngier , Linux Kernel Mailing List , Kristina Martsenko , Peter Maydell , Paolo Bonzini , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , Will Deacon , Ard Biesheuvel , Mark Rutland , Catalin Marinas , Christoffer Dall References: <20180109190414.4017-1-suzuki.poulose@arm.com> <20180109190414.4017-14-suzuki.poulose@arm.com> From: Suzuki K Poulose Message-ID: <514dda83-dd08-3318-b5a2-6c41fc1c992d@arm.com> Date: Thu, 15 Mar 2018 15:24:58 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Christoffer, On 08/02/18 18:04, Christoffer Dall wrote: > On Tue, Jan 09, 2018 at 07:04:08PM +0000, Suzuki K Poulose wrote: >> We set VTCR_EL2 very early during the stage2 init and don't >> touch it ever. This is fine as we had a fixed IPA size. This >> patch changes the behavior to set the VTCR for a given VM, >> depending on its stage2 table. The common configuration for >> VTCR is still performed during the early init. But the SL0 >> and T0SZ are programmed for each VM and is cleared once we >> exit the VM. >> >> Cc: Marc Zyngier >> Cc: Christoffer Dall >> Signed-off-by: Suzuki K Poulose >> diff --git a/arch/arm64/kvm/hyp/switch.c b/arch/arm64/kvm/hyp/switch.c >> index f7c651f3a8c0..523471f0af7b 100644 >> --- a/arch/arm64/kvm/hyp/switch.c >> +++ b/arch/arm64/kvm/hyp/switch.c >> @@ -157,11 +157,20 @@ static void __hyp_text __deactivate_traps(struct kvm_vcpu *vcpu) >> static void __hyp_text __activate_vm(struct kvm_vcpu *vcpu) >> { >> struct kvm *kvm = kern_hyp_va(vcpu->kvm); >> + u64 vtcr = read_sysreg(vtcr_el2); >> + >> + vtcr &= ~VTCR_EL2_PRIVATE_MASK; >> + vtcr |= VTCR_EL2_SL0(stage2_pt_levels(kvm)) | >> + VTCR_EL2_T0SZ(kvm_phys_shift(kvm)); >> + write_sysreg(vtcr, vtcr_el2); > > If we're writing VTCR_EL2 on each entry, do we really need to read the > value back first and calculate things on every entry to the VM? It > seems to me we should be able to compute the vtcr_el2 and store it on > struct kvm, and simply restore that per-VM value upon entering the VM? I took a look at this and we need to do this to make sure we retain the Hardware update of Access flags for stage2 (VTCR_EL2_HA) bits on the CPUs that has it and it is safe to run a mix of CPUs with and without the feature. >> write_sysreg(kvm->arch.vttbr, vttbr_el2); >> } >> >> static void __hyp_text __deactivate_vm(struct kvm_vcpu *vcpu) >> { >> + u64 vtcr = read_sysreg(vtcr_el2) & ~VTCR_EL2_PRIVATE_MASK; >> + >> + write_sysreg(vtcr, vtcr_el2); > > Why do we need to care about restoring VTCR when returning to the host? Yes, this can be skipped. Cheers Suzuki