From patchwork Wed Jan 10 19:07:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Punit Agrawal X-Patchwork-Id: 10155925 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 4C714601A1 for ; Wed, 10 Jan 2018 19:09:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3FDDD283CB for ; Wed, 10 Jan 2018 19:09:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3228328587; Wed, 10 Jan 2018 19:09:03 +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 D9B2C283CB for ; Wed, 10 Jan 2018 19:09:01 +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=XrunVb20jDA3XgpC3Dj9i441YSBt1UAW1KxswCNefIc=; b=MnC27Cdy4V3npeYHxXzuzeJ//6 cVYszohrRqU84g9AlY3Lo4CNCMoPSkXKofZUQ9X2JBxjZBkyvcnsq3ammiMg6rD0wcX/EPR9WoGHf DTk3AIPMi1qlq13fUVO0CAyy+QGYlCQ85gXC3ez/eiQNAvoleZB1bwhbNlf02ZmZyxvbqV3RAQ/Zo JH5Kh3+XEVvpqjbcnW12UTA+L0pfgB4JViYpw2sYj96MT5ouJ3OMBFD+vrFPHYWbdZCbJ29k8ht+6 KdrEJB+qplk+r16b3LtePMJpJa4gJilW27f3Yip2JFDvHvOYabt+Cah7XT7noqXsFEV9ZOZt4ns4l id1Qw3fg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1eZLkC-0003AS-Ej; Wed, 10 Jan 2018 19:09:00 +0000 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70] helo=foss.arm.com) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1eZLjs-0002Vc-BU for linux-arm-kernel@lists.infradead.org; Wed, 10 Jan 2018 19:08:58 +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 3D5ED1529; Wed, 10 Jan 2018 11:08:30 -0800 (PST) Received: from localhost (e105922-lin.cambridge.arm.com [10.1.207.29]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B2B693F581; Wed, 10 Jan 2018 11:08:29 -0800 (PST) From: Punit Agrawal To: kvmarm@lists.cs.columbia.edu Subject: [RFC 3/4] KVM: arm/arm64: Refactor Stage2 PMD hugepages support Date: Wed, 10 Jan 2018 19:07:28 +0000 Message-Id: <20180110190729.18383-4-punit.agrawal@arm.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180110190729.18383-1-punit.agrawal@arm.com> References: <20180110190729.18383-1-punit.agrawal@arm.com> X-ARM-No-Footer: FoSSMail X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180110_110840_909345_085D9AEA X-CRM114-Status: UNSURE ( 9.64 ) 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: suzuki.poulose@arm.com, Marc Zyngier , Punit Agrawal , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Christoffer Dall 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 Refactor the stage2 PMD hugepages support to split out constructing the PMD into a separate function. A similar pattern of code will be followed when introducing PUD hugepages at stage 2 where we need to split support between architecure specific and common code. There is no functional change with this patch. Signed-off-by: Punit Agrawal Cc: Christoffer Dall Cc: Marc Zyngier --- virt/kvm/arm/mmu.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/virt/kvm/arm/mmu.c b/virt/kvm/arm/mmu.c index 02eefda5d71e..f02219a91b19 100644 --- a/virt/kvm/arm/mmu.c +++ b/virt/kvm/arm/mmu.c @@ -1282,6 +1282,17 @@ static void kvm_send_hwpoison_signal(unsigned long address, send_sig_info(SIGBUS, &info, current); } +static pmd_t stage2_build_pmd(kvm_pfn_t pfn, pgprot_t mem_type, bool writable) +{ + pmd_t pmd = pfn_pmd(pfn, mem_type); + + pmd = pmd_mkhuge(pmd); + if (writable) + pmd = kvm_s2pmd_mkwrite(pmd); + + return pmd; +} + static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, struct kvm_memory_slot *memslot, unsigned long hva, unsigned long fault_status) @@ -1386,12 +1397,11 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, hugetlb = transparent_hugepage_adjust(&pfn, &fault_ipa); if (hugetlb) { - pmd_t new_pmd = pfn_pmd(pfn, mem_type); - new_pmd = pmd_mkhuge(new_pmd); - if (writable) { - new_pmd = kvm_s2pmd_mkwrite(new_pmd); + pmd_t new_pmd = stage2_build_pmd(pfn, mem_type, writable); + + if (writable) kvm_set_pfn_dirty(pfn); - } + coherent_cache_guest_page(vcpu, pfn, PMD_SIZE); ret = stage2_set_pmd_huge(kvm, memcache, fault_ipa, &new_pmd); } else {