From patchwork Thu Aug 17 14:44:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 9906487 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 363746038C for ; Thu, 17 Aug 2017 14:47:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 24B8028B2D for ; Thu, 17 Aug 2017 14:47:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 19DC528B37; Thu, 17 Aug 2017 14:47:44 +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, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 59E9628B2D for ; Thu, 17 Aug 2017 14:47:43 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1diM3M-0001ET-Lv; Thu, 17 Aug 2017 14:45:44 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1diM3L-0001CK-LY for xen-devel@lists.xenproject.org; Thu, 17 Aug 2017 14:45:43 +0000 Received: from [193.109.254.147] by server-8.bemta-6.messagelabs.com id 19/C5-09901-61CA5995; Thu, 17 Aug 2017 14:45:42 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprIIsWRWlGSWpSXmKPExsXitHSDva7Ymqm RBie+yFt83zKZyYHR4/CHKywBjFGsmXlJ+RUJrBk37sYXbDOseNS+iLGBsVm5i5GTQ0LAX+LP 03YWEJtNQFniZ2cvG4gtIqAn0XTgOWMXIxcHs8AcRompc7sYQRLCAvYSN3beZAKxWQRUJZacX McOYvMKWEpsuvqZHWKovMSutousIDYnUPzQpMXMILaQgIXE7A/t7BC2gkTH9GNMEL2CEidnPg E7gllAQuLgixfMExh5ZyFJzUKSWsDItIpRozi1qCy1SNfYWC+pKDM9oyQ3MTNH19DATC83tbg 4MT01JzGpWC85P3cTIzB4GIBgB+PO9YGHGCU5mJREeX/PmhIpxJeUn1KZkVicEV9UmpNafIhR hoNDSYL38aqpkUKCRanpqRVpmTnAMIZJS3DwKInw/gdJ8xYXJOYWZ6ZDpE4x6nK8mvD/G5MQS 15+XqqUOG/kaqAiAZCijNI8uBGwmLrEKCslzMsIdJQQT0FqUW5mCar8K0ZxDkYlYd7rIKt4Mv NK4Da9AjqCCeiIK+2TQI4oSURISTUwKkya9S1c/brBn3PmctbWN6qn3HhYNrM7XzdGT+LolPx N9+wjEmZzr//TWt9VqG6jNvdfq6RpeXHi/YtMJbNsMj5q6OtfDhf/5vWCXW3z8od8djW/Krb7 HS94Xy64YeLyaIETEU+q98dleDi4TxRz+/BiyUm7/kcel6UvTkt9X/bh+e4ZkoLxSizFGYmGW sxFxYkAULxfVaQCAAA= X-Env-Sender: prvs=395e6b081=wei.liu2@citrix.com X-Msg-Ref: server-10.tower-27.messagelabs.com!1502981136!89057399!4 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 40833 invoked from network); 17 Aug 2017 14:45:42 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-10.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 17 Aug 2017 14:45:42 -0000 X-IronPort-AV: E=Sophos;i="5.41,388,1498521600"; d="scan'208";a="444178357" From: Wei Liu To: Xen-devel Date: Thu, 17 Aug 2017 15:44:34 +0100 Message-ID: <20170817144456.18989-10-wei.liu2@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170817144456.18989-1-wei.liu2@citrix.com> References: <20170817144456.18989-1-wei.liu2@citrix.com> MIME-Version: 1.0 Cc: George Dunlap , Andrew Cooper , Wei Liu , Jan Beulich Subject: [Xen-devel] [PATCH v4 09/31] x86/mm: rename and move update_intpte X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP That function is only used by PV guests supporting code, add pv_ prefix. Export it via pv/mm.h. Move UPDATE_ENTRY as well. Signed-off-by: Wei Liu --- Now it is no longer an inline function, but I don't think that matters much. --- xen/arch/x86/mm.c | 65 --------------------------------------------- xen/arch/x86/pv/mm.c | 54 +++++++++++++++++++++++++++++++++++++ xen/include/asm-x86/pv/mm.h | 16 +++++++++++ 3 files changed, 70 insertions(+), 65 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index d25d314673..dc4ac5592a 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -133,14 +133,6 @@ l1_pgentry_t __section(".bss.page_aligned") __aligned(PAGE_SIZE) l1_fixmap[L1_PAGETABLE_ENTRIES]; -/* - * PTE updates can be done with ordinary writes except: - * 1. Debug builds get extra checking by using CMPXCHG[8B]. - */ -#if !defined(NDEBUG) -#define PTE_UPDATE_WITH_CMPXCHG -#endif - paddr_t __read_mostly mem_hotplug; /* Private domain structs for DOMID_XEN and DOMID_IO. */ @@ -1812,63 +1804,6 @@ void page_unlock(struct page_info *page) } while ( (y = cmpxchg(&page->u.inuse.type_info, x, nx)) != x ); } -/* - * How to write an entry to the guest pagetables. - * Returns false for failure (pointer not valid), true for success. - */ -static inline bool update_intpte( - intpte_t *p, intpte_t old, intpte_t new, unsigned long mfn, - struct vcpu *v, int preserve_ad) -{ - bool rv = true; - -#ifndef PTE_UPDATE_WITH_CMPXCHG - if ( !preserve_ad ) - { - rv = paging_write_guest_entry(v, p, new, _mfn(mfn)); - } - else -#endif - { - intpte_t t = old; - - for ( ; ; ) - { - intpte_t _new = new; - - if ( preserve_ad ) - _new |= old & (_PAGE_ACCESSED | _PAGE_DIRTY); - - rv = paging_cmpxchg_guest_entry(v, p, &t, _new, _mfn(mfn)); - if ( unlikely(rv == 0) ) - { - gdprintk(XENLOG_WARNING, - "Failed to update %" PRIpte " -> %" PRIpte - ": saw %" PRIpte "\n", old, _new, t); - break; - } - - if ( t == old ) - break; - - /* Allowed to change in Accessed/Dirty flags only. */ - BUG_ON((t ^ old) & ~(intpte_t)(_PAGE_ACCESSED|_PAGE_DIRTY)); - - old = t; - } - } - return rv; -} - -/* - * Macro that wraps the appropriate type-changes around update_intpte(). - * Arguments are: type, ptr, old, new, mfn, vcpu - */ -#define UPDATE_ENTRY(_t,_p,_o,_n,_m,_v,_ad) \ - update_intpte(&_t ## e_get_intpte(*(_p)), \ - _t ## e_get_intpte(_o), _t ## e_get_intpte(_n), \ - (_m), (_v), (_ad)) - /* * PTE flags that a guest may change without re-validating the PTE. * All other bits affect translation, caching, or Xen's safety. diff --git a/xen/arch/x86/pv/mm.c b/xen/arch/x86/pv/mm.c index aa2ce34145..2cb5995e62 100644 --- a/xen/arch/x86/pv/mm.c +++ b/xen/arch/x86/pv/mm.c @@ -24,6 +24,13 @@ #include +/* + * PTE updates can be done with ordinary writes except: + * 1. Debug builds get extra checking by using CMPXCHG[8B]. + */ +#if !defined(NDEBUG) +#define PTE_UPDATE_WITH_CMPXCHG +#endif /* Read a PV guest's l1e that maps this virtual address. */ void pv_get_guest_eff_l1e(unsigned long addr, l1_pgentry_t *eff_l1e) @@ -56,6 +63,53 @@ void pv_get_guest_eff_kern_l1e(struct vcpu *v, unsigned long addr, toggle_guest_mode(v); } +/* + * How to write an entry to the guest pagetables. + * Returns false for failure (pointer not valid), true for success. + */ +bool pv_update_intpte(intpte_t *p, intpte_t old, intpte_t new, + unsigned long mfn, struct vcpu *v, int preserve_ad) +{ + bool rv = true; + +#ifndef PTE_UPDATE_WITH_CMPXCHG + if ( !preserve_ad ) + { + rv = paging_write_guest_entry(v, p, new, _mfn(mfn)); + } + else +#endif + { + intpte_t t = old; + + for ( ; ; ) + { + intpte_t _new = new; + + if ( preserve_ad ) + _new |= old & (_PAGE_ACCESSED | _PAGE_DIRTY); + + rv = paging_cmpxchg_guest_entry(v, p, &t, _new, _mfn(mfn)); + if ( unlikely(rv == 0) ) + { + gdprintk(XENLOG_WARNING, + "Failed to update %" PRIpte " -> %" PRIpte + ": saw %" PRIpte "\n", old, _new, t); + break; + } + + if ( t == old ) + break; + + /* Allowed to change in Accessed/Dirty flags only. */ + BUG_ON((t ^ old) & ~(intpte_t)(_PAGE_ACCESSED|_PAGE_DIRTY)); + + old = t; + } + } + return rv; +} + /* * Local variables: * mode: C diff --git a/xen/include/asm-x86/pv/mm.h b/xen/include/asm-x86/pv/mm.h index 19dbc3b66c..72c04c684f 100644 --- a/xen/include/asm-x86/pv/mm.h +++ b/xen/include/asm-x86/pv/mm.h @@ -28,6 +28,17 @@ void pv_get_guest_eff_l1e(unsigned long addr, l1_pgentry_t *eff_l1e); void pv_get_guest_eff_kern_l1e(struct vcpu *v, unsigned long addr, void *eff_l1e); +bool pv_update_intpte(intpte_t *p, intpte_t old, intpte_t new, + unsigned long mfn, struct vcpu *v, int preserve_ad); +/* + * Macro that wraps the appropriate type-changes around update_intpte(). + * Arguments are: type, ptr, old, new, mfn, vcpu + */ +#define UPDATE_ENTRY(_t,_p,_o,_n,_m,_v,_ad) \ + pv_update_intpte(&_t ## e_get_intpte(*(_p)), \ + _t ## e_get_intpte(_o), _t ## e_get_intpte(_n), \ + (_m), (_v), (_ad)) + #else static inline void pv_get_guest_eff_l1e(unsigned long addr, @@ -38,6 +49,11 @@ static inline void pv_get_guest_eff_kern_l1e(struct vcpu *v, unsigned long addr, void *eff_l1e) {} +static inline bool pv_update_intpte(intpte_t *p, intpte_t old, intpte_t new, + unsigned long mfn, struct vcpu *v, + int preserve_ad) +{ return false; } + #endif #endif /* __X86_PV_MM_H__ */