From patchwork Mon Aug 5 14:27:02 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bharat Bhushan X-Patchwork-Id: 2838716 Return-Path: X-Original-To: patchwork-kvm@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 6FBD7BF535 for ; Mon, 5 Aug 2013 14:27:16 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6E750201CB for ; Mon, 5 Aug 2013 14:27:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 823CD201C8 for ; Mon, 5 Aug 2013 14:27:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753738Ab3HEO1J (ORCPT ); Mon, 5 Aug 2013 10:27:09 -0400 Received: from co9ehsobe002.messaging.microsoft.com ([207.46.163.25]:54298 "EHLO co9outboundpool.messaging.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753596Ab3HEO1H (ORCPT ); Mon, 5 Aug 2013 10:27:07 -0400 Received: from mail99-co9-R.bigfish.com (10.236.132.237) by CO9EHSOBE034.bigfish.com (10.236.130.97) with Microsoft SMTP Server id 14.1.225.22; Mon, 5 Aug 2013 14:27:06 +0000 Received: from mail99-co9 (localhost [127.0.0.1]) by mail99-co9-R.bigfish.com (Postfix) with ESMTP id 95A4B48029E; Mon, 5 Aug 2013 14:27:06 +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: -1 X-BigFish: VS-1(zcb8kz98dI9371I936eI542I1432Izz1f42h208ch1ee6h1de0h1fdah2073h1202h1e76h1d1ah1d2ah1fc6hzz1de098h8275dh1de097hz2dh2a8h668h839h8e2h8e3h93fhd25hf0ah1288h12a5h12a9h12bdh137ah13b6h1441h1504h1537h153bh15d0h162dh1631h1758h18e1h1946h19b5h1ad9h1b0ah1b2fh1fb3h1d0ch1d2eh1d3fh1dfeh1dffh1e1dhbe9i1155h) Received: from mail99-co9 (localhost.localdomain [127.0.0.1]) by mail99-co9 (MessageSwitch) id 1375712824342659_6500; Mon, 5 Aug 2013 14:27:04 +0000 (UTC) Received: from CO9EHSMHS024.bigfish.com (unknown [10.236.132.230]) by mail99-co9.bigfish.com (Postfix) with ESMTP id 3B693240047; Mon, 5 Aug 2013 14:27:04 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by CO9EHSMHS024.bigfish.com (10.236.130.34) with Microsoft SMTP Server (TLS) id 14.16.227.3; Mon, 5 Aug 2013 14:27:03 +0000 Received: from 039-SN2MPN1-012.039d.mgd.msft.net ([169.254.2.154]) by 039-SN1MMR1-005.039d.mgd.msft.net ([::1]) with mapi id 14.03.0136.001; Mon, 5 Aug 2013 14:27:02 +0000 From: Bhushan Bharat-R65777 To: Benjamin Herrenschmidt CC: Wood Scott-B07421 , "agraf@suse.de" , "kvm-ppc@vger.kernel.org" , "kvm@vger.kernel.org" , "linuxppc-dev@lists.ozlabs.org" Subject: RE: [PATCH 5/6 v2] kvm: powerpc: booke: Add linux pte lookup like booke3s Thread-Topic: [PATCH 5/6 v2] kvm: powerpc: booke: Add linux pte lookup like booke3s Thread-Index: AQHOjqjJuSw3JXBjzUCv6kTieIkVGJmCilWAgAAFEgCAADo7YIAAG6KAgAPMJKA= Date: Mon, 5 Aug 2013 14:27:02 +0000 Message-ID: <6A3DF150A5B70D4F9B66A25E3F7C888D070FAD49@039-SN2MPN1-012.039d.mgd.msft.net> References: <1375355558-19187-1-git-send-email-Bharat.Bhushan@freescale.com> <1375355558-19187-6-git-send-email-Bharat.Bhushan@freescale.com> <1375484319.26902.4.camel@snotra.buserror.net> <1375485408.15999.67.camel@pasglop> <6A3DF150A5B70D4F9B66A25E3F7C888D070F8FCC@039-SN2MPN1-012.039d.mgd.msft.net> <1375503847.15999.80.camel@pasglop> In-Reply-To: <1375503847.15999.80.camel@pasglop> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.214.249.39] MIME-Version: 1.0 X-OriginatorOrg: freescale.com X-FOPE-CONNECTOR: Id%0$Dn%*$RO%0$TLS%0$FQDN%$TlsDn% Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 > -----Original Message----- > From: Benjamin Herrenschmidt [mailto:benh@kernel.crashing.org] > Sent: Saturday, August 03, 2013 9:54 AM > To: Bhushan Bharat-R65777 > Cc: Wood Scott-B07421; agraf@suse.de; kvm-ppc@vger.kernel.org; > kvm@vger.kernel.org; linuxppc-dev@lists.ozlabs.org > Subject: Re: [PATCH 5/6 v2] kvm: powerpc: booke: Add linux pte lookup like > booke3s > > On Sat, 2013-08-03 at 02:58 +0000, Bhushan Bharat-R65777 wrote: > > One of the problem I saw was that if I put this code in > > asm/pgtable-32.h and asm/pgtable-64.h then pte_persent() and other > > friend function (on which this code depends) are defined in pgtable.h. > > And pgtable.h includes asm/pgtable-32.h and asm/pgtable-64.h before it > > defines pte_present() and friends functions. > > > > Ok I move wove this in asm/pgtable*.h, initially I fought with myself > > to take this code in pgtable* but finally end up doing here (got > > biased by book3s :)). > > Is there a reason why these routines can not be completely generic in pgtable.h > ? How about the generic function: diff --git a/arch/powerpc/include/asm/pgtable-ppc64.h b/arch/powerpc/include/asm/pgtable-ppc64.h index d257d98..21daf28 100644 --- a/arch/powerpc/include/asm/pgtable-ppc64.h +++ b/arch/powerpc/include/asm/pgtable-ppc64.h @@ -221,6 +221,27 @@ static inline unsigned long pte_update(struct mm_struct *mm, return old; } +static inline unsigned long pte_read(pte_t *p) +{ +#ifdef PTE_ATOMIC_UPDATES + pte_t pte; + pte_t tmp; + __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"); + + return pte; +#else + return pte_val(*p); +#endif +#endif +} static inline int __ptep_test_and_clear_young(struct mm_struct *mm, unsigned long addr, pte_t *ptep) { diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h index 690c8c2..dad712c 100644 --- a/arch/powerpc/include/asm/pgtable.h +++ b/arch/powerpc/include/asm/pgtable.h @@ -254,6 +254,45 @@ static inline pte_t *find_linux_pte_or_hugepte(pgd_t *pgdir, unsigned long ea, } #endif /* !CONFIG_HUGETLB_PAGE */ +static inline pte_t lookup_linux_pte(pgd_t *pgdir, unsigned long hva, + int writing, unsigned long *pte_sizep) +{ + pte_t *ptep; + pte_t pte; + 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); + +#ifdef CONFIG_PPC64 + /* Lock PTE (set _PAGE_BUSY) and read */ + pte = pte_read(ptep); +#else + pte = pte_val(*ptep); +#endif + if (pte_present(pte)) { + pte = pte_mkyoung(pte); + if (writing && pte_write(pte)) + pte = pte_mkdirty(pte); + } + + *ptep = __pte(pte); /* 64bit: Also unlock pte (clear _PAGE_BUSY) */ + + return pte; +} + #endif /* __ASSEMBLY__ */ #endif /* __KERNEL__ */