From patchwork Sat Nov 15 08:19:08 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Smarduch X-Patchwork-Id: 5311051 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id ED218C11AC for ; Sat, 15 Nov 2014 08:24:19 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E1B34201BC for ; Sat, 15 Nov 2014 08:24:18 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CB26020155 for ; Sat, 15 Nov 2014 08:24:17 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XpYaJ-000602-9x; Sat, 15 Nov 2014 08:19:55 +0000 Received: from mailout4.w2.samsung.com ([211.189.100.14] helo=usmailout4.samsung.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XpYaB-0005h8-7S for linux-arm-kernel@lists.infradead.org; Sat, 15 Nov 2014 08:19:47 +0000 Received: from uscpsbgex3.samsung.com (u124.gpu85.samsung.co.kr [203.254.195.124]) by usmailout4.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0NF200ERKN4KYI80@usmailout4.samsung.com> for linux-arm-kernel@lists.infradead.org; Sat, 15 Nov 2014 03:19:32 -0500 (EST) X-AuditID: cbfec37c-b7f9f6d000006015-c1-54670c948c91 Received: from usmmp1.samsung.com ( [203.254.195.77]) by uscpsbgex3.samsung.com (USCPEXMTA) with SMTP id C9.9B.24597.49C07645; Sat, 15 Nov 2014 03:19:32 -0500 (EST) Received: from sisasmtp.sisa.samsung.com ([105.144.21.116]) by usmmp1.samsung.com (Oracle Communications Messaging Server 7u4-27.01(7.0.4.27.0) 64bit (built Aug 30 2012)) with ESMTP id <0NF200IGNN4JOK50@usmmp1.samsung.com>; Sat, 15 Nov 2014 03:19:32 -0500 (EST) Received: from mjsmard-530U3C-530U4C-532U3C.sisa.samsung.com (105.144.129.79) by SISAEX02SJ.sisa.samsung.com (105.144.21.116) with Microsoft SMTP Server (TLS) id 14.3.123.3; Sat, 15 Nov 2014 00:19:30 -0800 From: m.smarduch@samsung.com To: christoffer.dall@linaro.org, marc.zyngier@arm.com Subject: [PATCH v2 1/3] KVM: arm64: ARMv8 header changes for page logging Date: Sat, 15 Nov 2014 00:19:08 -0800 Message-id: <1416039550-28125-2-git-send-email-m.smarduch@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1416039550-28125-1-git-send-email-m.smarduch@samsung.com> References: <1416039550-28125-1-git-send-email-m.smarduch@samsung.com> MIME-version: 1.0 X-Originating-IP: [105.144.129.79] X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrDLMWRmVeSWpSXmKPExsVy+t9hX90pPOkhBgt6hC3eL+thtHjx+h+j xZyphRYfTx1nt9j0+Bqrxd87/9gs9m/7x+rA7rFm3hpGjzvX9rB5nN+0htlj85J6j/f7rrJ5 fN4kF8AWxWWTkpqTWZZapG+XwJXRfuY9Y8EciYpFx6YwNjCeE+li5OSQEDCRuP79HhOELSZx 4d56ti5GLg4hgWWMEl9+XmeFcHqZJC4uWc0C4VxklPj7q4UdpIVNQEbi4fQmoBYODhEBU4nm Ng6QGmaBbYwSP148ZwapERbwlOj/egesnkVAVaK5eQ5YnFfATaLn4HtmkF4JAQWJOZNsQMKc Au4Se45vZwGxhYBKdrx+zgZRLijxY/I9FpByZgEJieeflSBKVCW23XzOCPGAksS0w1fZJzAK zULSMQuhYwEj0ypGsdLi5ILipPTUCmO94sTc4tK8dL3k/NxNjJAYqNnBeO+rzSFGAQ5GJR7e hulpIUKsiWXFlbmHGCU4mJVEeCdwpYcI8aYkVlalFuXHF5XmpBYfYmTi4JRqYBTuao7Ji7ig 6vr2hVLwkT/HW2x/rtYIqmrOMDl8beocnW+1ulz7Z9wxk5Q57Fd3Yplpr6WSpeZU/0k53UZX 5ywouV44YdbfftvQOoPN+1s2ln49FPuy+UTY+csPTbh6Z0j/O7+Mbc4L5lcZLx9PTt17cuai 4NX9asYqTxiNLL94ZM5qWqTEYaLEUpyRaKjFXFScCABfmXn/XwIAAA== X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141115_001947_348948_C5F68E17 X-CRM114-Status: UNSURE ( 8.16 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -5.0 (-----) Cc: kvm@vger.kernel.org, catalin.marinas@arm.com, pbonzini@redhat.com, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, Mario Smarduch X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Mario Smarduch This patch adds arm64 helpers to write protect pmds/ptes and retrieve permissions while logging dirty pages. Also adds prototype to write protect a memory slot and adds a pmd define to check for read-only pmds. Signed-off-by: Mario Smarduch Reviewed-by: Christoffer Dall --- arch/arm64/include/asm/kvm_asm.h | 1 + arch/arm64/include/asm/kvm_host.h | 1 + arch/arm64/include/asm/kvm_mmu.h | 20 ++++++++++++++++++++ arch/arm64/include/asm/pgtable-hwdef.h | 1 + 4 files changed, 23 insertions(+) diff --git a/arch/arm64/include/asm/kvm_asm.h b/arch/arm64/include/asm/kvm_asm.h index 4838421..4f7310f 100644 --- a/arch/arm64/include/asm/kvm_asm.h +++ b/arch/arm64/include/asm/kvm_asm.h @@ -126,6 +126,7 @@ extern char __kvm_hyp_vector[]; extern void __kvm_flush_vm_context(void); extern void __kvm_tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa); +extern void __kvm_tlb_flush_vmid(struct kvm *kvm); extern int __kvm_vcpu_run(struct kvm_vcpu *vcpu); diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index e10c45a..7548dbc 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -196,6 +196,7 @@ struct kvm_vcpu *kvm_arm_get_running_vcpu(void); struct kvm_vcpu __percpu **kvm_get_running_vcpus(void); u64 kvm_call_hyp(void *hypfn, ...); +void kvm_mmu_wp_memory_region(struct kvm *kvm, int slot); int handle_exit(struct kvm_vcpu *vcpu, struct kvm_run *run, int exception_index); diff --git a/arch/arm64/include/asm/kvm_mmu.h b/arch/arm64/include/asm/kvm_mmu.h index 8e138c7..8b0ffe3 100644 --- a/arch/arm64/include/asm/kvm_mmu.h +++ b/arch/arm64/include/asm/kvm_mmu.h @@ -121,6 +121,26 @@ static inline void kvm_set_s2pmd_writable(pmd_t *pmd) pmd_val(*pmd) |= PMD_S2_RDWR; } +static inline void kvm_set_s2pte_readonly(pte_t *pte) +{ + pte_val(*pte) = (pte_val(*pte) & ~PTE_S2_RDWR) | PTE_S2_RDONLY; +} + +static inline bool kvm_s2pte_readonly(pte_t *pte) +{ + return (pte_val(*pte) & PTE_S2_RDWR) == PTE_S2_RDONLY; +} + +static inline void kvm_set_s2pmd_readonly(pmd_t *pmd) +{ + pmd_val(*pmd) = (pmd_val(*pmd) & ~PMD_S2_RDWR) | PMD_S2_RDONLY; +} + +static inline bool kvm_s2pmd_readonly(pmd_t *pmd) +{ + return (pmd_val(*pmd) & PMD_S2_RDWR) == PMD_S2_RDONLY; +} + #define kvm_pgd_addr_end(addr, end) pgd_addr_end(addr, end) #define kvm_pud_addr_end(addr, end) pud_addr_end(addr, end) #define kvm_pmd_addr_end(addr, end) pmd_addr_end(addr, end) diff --git a/arch/arm64/include/asm/pgtable-hwdef.h b/arch/arm64/include/asm/pgtable-hwdef.h index 88174e0..5f930cc 100644 --- a/arch/arm64/include/asm/pgtable-hwdef.h +++ b/arch/arm64/include/asm/pgtable-hwdef.h @@ -119,6 +119,7 @@ #define PTE_S2_RDONLY (_AT(pteval_t, 1) << 6) /* HAP[2:1] */ #define PTE_S2_RDWR (_AT(pteval_t, 3) << 6) /* HAP[2:1] */ +#define PMD_S2_RDONLY (_AT(pmdval_t, 1) << 6) /* HAP[2:1] */ #define PMD_S2_RDWR (_AT(pmdval_t, 3) << 6) /* HAP[2:1] */ /*