From patchwork Thu Sep 14 12:58:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 9953021 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 DFE0A602C9 for ; Thu, 14 Sep 2017 13:01:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AB874290CC for ; Thu, 14 Sep 2017 13:01:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A0280290CF; Thu, 14 Sep 2017 13:01:46 +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 40E63290CC for ; Thu, 14 Sep 2017 13:01:46 +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 1dsTjY-0004Mf-MC; Thu, 14 Sep 2017 12:59:08 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dsTjX-0004Lc-EY for xen-devel@lists.xenproject.org; Thu, 14 Sep 2017 12:59:07 +0000 Received: from [85.158.137.68] by server-6.bemta-3.messagelabs.com id 2A/27-02225-A1D7AB95; Thu, 14 Sep 2017 12:59:06 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprIIsWRWlGSWpSXmKPExsXitHSDva5U7a5 Ig97FXBbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8af93eYC36qVdz8upe1gbFfuouRk0NCwF/i 6f/v7CA2m4CyxM/OXjYQW0RAT6LpwHPGLkYuDmaBOYwSU+d2MYIkhAXsJebNfsPcxcjBwSKgK nHjYyFImFfAQmLm22uMEDPlJXa1XWQFsTkFLCW6PrxkArGFgGp6L+1nh7AVJDqmH2OC6BWUOD nzCQuIzSwgIXHwxQvmCYy8s5CkZiFJLWBkWsWoUZxaVJZapGtkopdUlJmeUZKbmJmja2hgrJe bWlycmJ6ak5hUrJecn7uJERg89QwMjDsYXx33O8QoycGkJMq7V3dnpBBfUn5KZUZicUZ8UWlO avEhRhkODiUJXt2aXZFCgkWp6akVaZk5wDCGSUtw8CiJ8PqApHmLCxJzizPTIVKnGHU5Om7e/ cMkxJKXn5cqJc57oxqoSACkKKM0D24ELKYuMcpKCfMyMjAwCPEUpBblZpagyr9iFOdgVBLm/Q MyhSczrwRu0yugI5iAjjhzegfIESWJCCmpBsb82KImIWYmrpWyJuwnfig/Mt+q7vKXyeF59Zk CvcVBm5wOOh+Nea3ta/ZZJzG5tceS/Xbhis9xL8oy11p2Hopxyy67Yp8x84Z1w+/nBc9Mbis0 PXrQKlnxLLoscbLehpRXAgbs339Esht+UD8y72oGF5+Zzq3t50N+c2skzly9Mnj9uoKibCWW4 oxEQy3mouJEADcjUAqkAgAA X-Env-Sender: prvs=423b67c62=wei.liu2@citrix.com X-Msg-Ref: server-11.tower-31.messagelabs.com!1505393943!83924404!2 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 2500 invoked from network); 14 Sep 2017 12:59:05 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-11.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 14 Sep 2017 12:59:05 -0000 X-IronPort-AV: E=Sophos;i="5.42,393,1500940800"; d="scan'208";a="447834051" From: Wei Liu To: Xen-devel Date: Thu, 14 Sep 2017 13:58:32 +0100 Message-ID: <20170914125852.22129-4-wei.liu2@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170914125852.22129-1-wei.liu2@citrix.com> References: <20170914125852.22129-1-wei.liu2@citrix.com> MIME-Version: 1.0 Cc: George Dunlap , Andrew Cooper , Wei Liu , Jan Beulich Subject: [Xen-devel] [PATCH v5 03/23] x86/mm: move update_intpte to pv/mm.h 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 While at it, change the type of preserve_ad to bool. Also move UPDATE_ENTRY there. Signed-off-by: Wei Liu Acked-by: Jan Beulich --- xen/arch/x86/mm.c | 65 ---------------------------------------------------- xen/arch/x86/pv/mm.h | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 65 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index faa161b767..504a0a2a6a 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -139,14 +139,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. */ @@ -1848,63 +1840,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.h b/xen/arch/x86/pv/mm.h index 5b5dbff433..2563d280a5 100644 --- a/xen/arch/x86/pv/mm.h +++ b/xen/arch/x86/pv/mm.h @@ -18,4 +18,69 @@ static inline l1_pgentry_t guest_get_eff_l1e(unsigned long linear) return l1e; } +/* + * 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 + +/* + * 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, + bool 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)) + #endif /* __PV_MM_H__ */