From patchwork Mon Aug 14 10:38:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Murzin X-Patchwork-Id: 9898511 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1057F602BA for ; Mon, 14 Aug 2017 10:40:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F096F2074F for ; Mon, 14 Aug 2017 10:40:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E53D622B1F; Mon, 14 Aug 2017 10:40:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 69C872074F for ; Mon, 14 Aug 2017 10:40:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=LNZMFy+XXKsGP7UwFpu1z0J9/y7EpCoO4Z3MTCCGDkw=; b=F4a5mXjLRVXXMv463JJBsWAuqn BcUo6G+sd4YaPR6o1m1jXZ9RWEdMb91qUQLxKLUO5vhFd1M7KvurRF7Eh24aaRbG4LzTKX9Sq88bh 6hIXNknFkRGJw0Wg1HCRuNSTboGxyPaLacboooScEIjS0Oq0dgo2g88xj3gf8fSvHnhyWeX8ahWD3 xMVdoCMA/D//HjT35ltuO6cMrfcKOvjQhchkGtKqSFNmJqT8RmGC9GZU8uiDTcV1XtGQjyR1TiYA0 QqWcfQ6JWVSilMqpB2Nq9WA1033u44Tg74ECKYRuycfCz5s0iq881sCfVR3Z/OzUptMwn9HMJE4vL TNEZqeKg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dhCmq-0007Od-07; Mon, 14 Aug 2017 10:39:56 +0000 Received: from foss.arm.com ([217.140.101.70]) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dhCmV-0006vg-FJ for linux-arm-kernel@lists.infradead.org; Mon, 14 Aug 2017 10:39:37 +0000 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 CD80B15BE; Mon, 14 Aug 2017 03:39:17 -0700 (PDT) Received: from login2.euhpc.arm.com (login2.euhpc.arm.com [10.6.26.144]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 9C2FF3F3E1; Mon, 14 Aug 2017 03:39:16 -0700 (PDT) From: Vladimir Murzin To: linux-arm-kernel@lists.infradead.org Subject: [RFC PATCH 2/3] arm64: KVM: Support Common Not Private translations Date: Mon, 14 Aug 2017 11:38:53 +0100 Message-Id: <1502707134-10853-3-git-send-email-vladimir.murzin@arm.com> X-Mailer: git-send-email 2.0.0 In-Reply-To: <1502707134-10853-1-git-send-email-vladimir.murzin@arm.com> References: <1502707134-10853-1-git-send-email-vladimir.murzin@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170814_033935_603522_6F35BCE0 X-CRM114-Status: UNSURE ( 7.35 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, catalin.marinas@arm.com, james.morse@arm.com, kbuild-all@01.org, marc.zyngier@arm.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP We rely on cpufeature framework to detect and enable CNP so for KVM we need to patch hyp to set CNP bit just before TTBR0_EL2 gets written. For the guest it is enough to update VTTBR_EL2 with CNP bit just before it gets scheduled. Signed-off-by: Vladimir Murzin --- arch/arm64/kvm/hyp-init.S | 4 ++++ arch/arm64/kvm/hyp/switch.c | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/hyp-init.S b/arch/arm64/kvm/hyp-init.S index 3f96155..4fd31b3 100644 --- a/arch/arm64/kvm/hyp-init.S +++ b/arch/arm64/kvm/hyp-init.S @@ -63,6 +63,10 @@ __do_hyp_init: cmp x0, #HVC_STUB_HCALL_NR b.lo __kvm_handle_stub_hvc +alternative_if ARM64_HAS_CNP + orr x0, x0, #TTBR_CNP_BIT +alternative_else_nop_endif + msr ttbr0_el2, x0 mrs x4, tcr_el1 diff --git a/arch/arm64/kvm/hyp/switch.c b/arch/arm64/kvm/hyp/switch.c index 945e79c..a1f3bf2 100644 --- a/arch/arm64/kvm/hyp/switch.c +++ b/arch/arm64/kvm/hyp/switch.c @@ -150,7 +150,11 @@ 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); - write_sysreg(kvm->arch.vttbr, vttbr_el2); + u64 val = kvm->arch.vttbr; + + if (system_supports_cnp()) + val |= TTBR_CNP_BIT; + write_sysreg(val, vttbr_el2); } static void __hyp_text __deactivate_vm(struct kvm_vcpu *vcpu)