From patchwork Thu Aug 1 11:12:37 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bharat Bhushan X-Patchwork-Id: 263972 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 6F74F2C0129 for ; Thu, 1 Aug 2013 21:18:16 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753662Ab3HALSK (ORCPT ); Thu, 1 Aug 2013 07:18:10 -0400 Received: from mail-db9lp0251.outbound.messaging.microsoft.com ([213.199.154.251]:57174 "EHLO db9outboundpool.messaging.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753779Ab3HALSI (ORCPT ); Thu, 1 Aug 2013 07:18:08 -0400 Received: from mail21-db9-R.bigfish.com (10.174.16.236) by DB9EHSOBE032.bigfish.com (10.174.14.95) with Microsoft SMTP Server id 14.1.225.22; Thu, 1 Aug 2013 11:18:07 +0000 Received: from mail21-db9 (localhost [127.0.0.1]) by mail21-db9-R.bigfish.com (Postfix) with ESMTP id 3E5C74003C7; Thu, 1 Aug 2013 11:18:07 +0000 (UTC) X-Forefront-Antispam-Report: CIP:70.37.183.190; KIP:(null); UIP:(null); IPV:NLI; H:mail.freescale.net; RD:none; EFVD:NLI X-SpamScore: 6 X-BigFish: VS6(zcb8kzzz1f42h208ch1ee6h1de0h1fdah2073h1202h1e76h1d1ah1d2ah1fc6h1082kzz1de098h8275bh1de097hz2dh2a8h668h839he5bhf0ah107ah1288h12a5h12a9h12bdh12e5h137ah139eh13b6h1441h1504h1537h162dh1631h1758h1898h18e1h1946h19b5h1ad9h1b0ah1b2fh1fb3h1d0ch1d2eh1d3fh1dfeh1dffh1e1dh1e23h1155h) Received: from mail21-db9 (localhost.localdomain [127.0.0.1]) by mail21-db9 (MessageSwitch) id 1375355885532739_1403; Thu, 1 Aug 2013 11:18:05 +0000 (UTC) Received: from DB9EHSMHS011.bigfish.com (unknown [10.174.16.241]) by mail21-db9.bigfish.com (Postfix) with ESMTP id 72D08160049; Thu, 1 Aug 2013 11:18:05 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by DB9EHSMHS011.bigfish.com (10.174.14.21) with Microsoft SMTP Server (TLS) id 14.16.227.3; Thu, 1 Aug 2013 11:18:04 +0000 Received: from tx30smr01.am.freescale.net (10.81.153.31) by 039-SN1MMR1-004.039d.mgd.msft.net (10.84.1.14) with Microsoft SMTP Server (TLS) id 14.3.136.1; Thu, 1 Aug 2013 11:18:02 +0000 Received: from freescale.com ([10.232.15.72]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with SMTP id r71BHug1018366; Thu, 1 Aug 2013 04:17:58 -0700 Received: by freescale.com (sSMTP sendmail emulation); Thu, 01 Aug 2013 16:43:16 +0530 From: Bharat Bhushan To: , , , , , CC: Bharat Bhushan , Bharat Bhushan Subject: [PATCH 5/6 v2] kvm: powerpc: booke: Add linux pte lookup like booke3s Date: Thu, 1 Aug 2013 16:42:37 +0530 Message-ID: <1375355558-19187-6-git-send-email-Bharat.Bhushan@freescale.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1375355558-19187-1-git-send-email-Bharat.Bhushan@freescale.com> References: <1375355558-19187-1-git-send-email-Bharat.Bhushan@freescale.com> MIME-Version: 1.0 X-OriginatorOrg: freescale.com X-FOPE-CONNECTOR: Id%0$Dn%*$RO%0$TLS%0$FQDN%$TlsDn% Sender: kvm-ppc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm-ppc@vger.kernel.org KVM need to lookup linux pte for getting TLB attributes (WIMGE). This is similar to how book3s does. This will be used in follow-up patches. Signed-off-by: Bharat Bhushan --- v1->v2 - This is a new change in this version arch/powerpc/include/asm/kvm_booke.h | 73 ++++++++++++++++++++++++++++++++++ 1 files changed, 73 insertions(+), 0 deletions(-) diff --git a/arch/powerpc/include/asm/kvm_booke.h b/arch/powerpc/include/asm/kvm_booke.h index d3c1eb3..903624d 100644 --- a/arch/powerpc/include/asm/kvm_booke.h +++ b/arch/powerpc/include/asm/kvm_booke.h @@ -102,4 +102,77 @@ static inline ulong kvmppc_get_msr(struct kvm_vcpu *vcpu) { return vcpu->arch.shared->msr; } + +/* + * Lock and read a linux PTE. If it's present and writable, atomically + * set dirty and referenced bits and return the PTE, otherwise return 0. + */ +static inline pte_t kvmppc_read_update_linux_pte(pte_t *p, int writing) +{ + pte_t pte; + +#ifdef PTE_ATOMIC_UPDATES + pte_t tmp; + /* wait until _PAGE_BUSY is clear then set it atomically */ +#ifdef CONFIG_PPC64 + __asm__ __volatile__ ( + "1: ldarx %0,0,%3\n" + " andi. %1,%0,%4\n" + " bne- 1b\n" + " ori %1,%0,%4\n" + " stdcx. %1,0,%3\n" + " bne- 1b" + : "=&r" (pte), "=&r" (tmp), "=m" (*p) + : "r" (p), "i" (_PAGE_BUSY) + : "cc"); +#else + __asm__ __volatile__ ( + "1: lwarx %0,0,%3\n" + " andi. %1,%0,%4\n" + " bne- 1b\n" + " ori %1,%0,%4\n" + " stwcx. %1,0,%3\n" + " bne- 1b" + : "=&r" (pte), "=&r" (tmp), "=m" (*p) + : "r" (p), "i" (_PAGE_BUSY) + : "cc"); +#endif +#else + pte = pte_val(*p); +#endif + + if (pte_present(pte)) { + pte = pte_mkyoung(pte); + if (writing && pte_write(pte)) + pte = pte_mkdirty(pte); + } + + *p = pte; /* clears _PAGE_BUSY */ + + return pte; +} + +static inline pte_t lookup_linux_pte(pgd_t *pgdir, unsigned long hva, + int writing, unsigned long *pte_sizep) +{ + pte_t *ptep; + unsigned long ps = *pte_sizep; + unsigned int shift; + + ptep = find_linux_pte_or_hugepte(pgdir, hva, &shift); + if (!ptep) + return __pte(0); + if (shift) + *pte_sizep = 1ul << shift; + else + *pte_sizep = PAGE_SIZE; + + if (ps > *pte_sizep) + return __pte(0); + if (!pte_present(*ptep)) + return __pte(0); + + return kvmppc_read_update_linux_pte(ptep, writing); +} + #endif /* __ASM_KVM_BOOKE_H__ */