From patchwork Wed Oct 11 12:19:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Murzin X-Patchwork-Id: 9999537 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 D19046037F for ; Wed, 11 Oct 2017 12:31:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C117F28A03 for ; Wed, 11 Oct 2017 12:31:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B425F28A24; Wed, 11 Oct 2017 12:31:15 +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=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED 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 4F3B428A21 for ; Wed, 11 Oct 2017 12:31:14 +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=ILatF6vm+psjZ2HrJS16ytZy86 53gLG+v32NzTixxJNxryyOP8iPku65qHS8jwlrotImgW0YqoJ92urLhO17aVl6KzzpnX1NGxwd5O8 nKJKMcwVtzWOwKs+LhQ51zCdY+94DziXbiCiPqoS9b/eVQ9t3TMti2f+Wi0XsCR7RZRVPl+lH32HY cxeCXYBbqCwVHcc6kRkizWF9sXeVnBsNV0sXYX/Eu+mOR6+OAkK6dK/VeXExPOiufOu5me/0njhWm U/SwzK8riyjaIohRA2/xSI1cgiS/gl9EHWBa8bjAmDT2X8W1z+ZPUPFPd0BUeCc1ned31YJvB1e87 4+EIav5w==; 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 1e2GAF-00050J-Jg; Wed, 11 Oct 2017 12:31:07 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e2G9D-0002Db-W8 for linux-arm-kernel@bombadil.infradead.org; Wed, 11 Oct 2017 12:30:04 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=qH25OMKx/7qlQ1tbyt15pvDgdLJBhTmki2+ZzPM4KGY=; b=qaZ5kbGCZ0hZ/xKuCBVHjJJly RSG9WNThrjDZBAZhyla9hEMn6HjoknG33520IQsRC3Ua7X5NdvsvpUZOIeFIWl8mlVhR+l8ecm8Sk rmMecJ334xYGWOauOYROsGP3iiTw2E8Ev7kcoHsilD7L4nVEZ+iPdl3QKdVOKH1gYV8G3B1esiNcK 64IxIbzSawW2+7rjnpw4mq/NshEhLOrnCmie/PvsLO81iw5J6UYOeZr0nYN3R5rQIx0q+9gCDFJex 4lgQnXzP5AiyMoXIRth1du7Wn5eSnmW2a5EMh9KyrmYuwpr8i/ywycEVAmOCIswWG0X0dCN+nda7I 6SmALISuw==; Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70] helo=foss.arm.com) by casper.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1e2G03-0003Kl-1o for linux-arm-kernel@lists.infradead.org; Wed, 11 Oct 2017 12:20:38 +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 5E34715AD; Wed, 11 Oct 2017 05:20:14 -0700 (PDT) Received: from bc-c10-2-5.euhpc.arm.com. (bc-c10-2-5.euhpc.arm.com [10.6.5.26]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D0D873F483; Wed, 11 Oct 2017 05:20:12 -0700 (PDT) From: Vladimir Murzin To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 2/3] arm64: KVM: Support Common Not Private translations Date: Wed, 11 Oct 2017 13:19:54 +0100 Message-Id: <1507724395-13735-3-git-send-email-vladimir.murzin@arm.com> X-Mailer: git-send-email 2.0.0 In-Reply-To: <1507724395-13735-1-git-send-email-vladimir.murzin@arm.com> References: <1507724395-13735-1-git-send-email-vladimir.murzin@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171011_132035_349773_60EB0AC3 X-CRM114-Status: UNSURE ( 8.16 ) 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, marc.zyngier@arm.com, catalin.marinas@arm.com, james.morse@arm.com, kbuild-all@01.org, kvmarm@lists.cs.columbia.edu, christoffer.dall@linaro.org 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)