From patchwork Sat Mar 5 16:52:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 8511161 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 8C29A9F372 for ; Sat, 5 Mar 2016 16:56:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 85BFF20254 for ; Sat, 5 Mar 2016 16:56:27 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id 7B3022022A for ; Sat, 5 Mar 2016 16:56:26 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xen.org with esmtp (Exim 4.84) (envelope-from ) id 1acFRZ-0007Qg-67; Sat, 05 Mar 2016 16:52:41 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.84) (envelope-from ) id 1acFRX-0007Qa-Vx for xen-devel@lists.xen.org; Sat, 05 Mar 2016 16:52:40 +0000 Received: from [85.158.137.68] by server-9.bemta-3.messagelabs.com id 70/6A-03814-7DE0BD65; Sat, 05 Mar 2016 16:52:39 +0000 X-Env-Sender: prvs=865bc1a8f=Andrew.Cooper3@citrix.com X-Msg-Ref: server-2.tower-31.messagelabs.com!1457196757!27122171!1 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 8.11; banners=-,-,- X-VirusChecked: Checked Received: (qmail 10244 invoked from network); 5 Mar 2016 16:52:38 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-2.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 5 Mar 2016 16:52:38 -0000 X-IronPort-AV: E=Sophos;i="5.22,541,1449532800"; d="scan'208";a="336817450" From: Andrew Cooper To: Xen-devel Date: Sat, 5 Mar 2016 16:52:34 +0000 Message-ID: <1457196754-6299-1-git-send-email-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.1.4 MIME-Version: 1.0 X-DLP: MIA2 Cc: George Dunlap , Andrew Cooper , Doug Goldstein , Jan Beulich , Tim Deegan Subject: [Xen-devel] [PATCH] xen/mm: Fix page_list_* helpers to evaluate all their arguments 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-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, 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 If an architecture does not provide a custom page_list_entry, default page_list_* helpers are provided, wrapping list_head as an underlying type for page_list_head. The two declarations of the page_list_* helpers differ between defines and static inline functions, where the defines discard some of their parameters. This causes a compilation failure if CONFIG_BIGMEM and debug=n in p2m-pod.c: p2m-pod.c: In function ‘p2m_pod_cache_add’: p2m-pod.c:72:20: error: unused variable ‘d’ [-Werror=unused-variable] struct domain *d = p2m->domain; ^ cc1: all warnings being treated as errors because the use of d outside of the !NDEBUG section doesn't get evaluated as a parameter by page_list_del(). Fix this by turning all #defines into static inline functions, so all parameters are evaluated even if they are not used. Doing this reveals that const-correctness of page_list_{next,prev}() is suspect, taking a const pointer and returning a non-const one. It is left functioning as it did before, with an explicit typecast to remove constness. While editing this area, correct the return type of page_list_empty from int to bool_t. Reported-by: Doug Goldstein Signed-off-by: Andrew Cooper Reviewed-by: Doug Goldstein --- CC: Jan Beulich CC: Tim Deegan CC: George Dunlap --- xen/include/xen/mm.h | 95 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 74 insertions(+), 21 deletions(-) diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h index a795dd6..38e12b7 100644 --- a/xen/include/xen/mm.h +++ b/xen/include/xen/mm.h @@ -220,7 +220,7 @@ struct page_list_head # define INIT_PAGE_LIST_HEAD(head) ((head)->tail = (head)->next = NULL) # define INIT_PAGE_LIST_ENTRY(ent) ((ent)->prev = (ent)->next = PAGE_LIST_NULL) -static inline int +static inline bool_t page_list_empty(const struct page_list_head *head) { return !head->next; @@ -392,31 +392,84 @@ page_list_splice(struct page_list_head *list, struct page_list_head *head) # define PAGE_LIST_HEAD LIST_HEAD # define INIT_PAGE_LIST_HEAD INIT_LIST_HEAD # define INIT_PAGE_LIST_ENTRY INIT_LIST_HEAD -# define page_list_empty list_empty -# define page_list_first(hd) \ - list_first_entry(hd, struct page_info, list) -# define page_list_last(hd) \ - list_last_entry(hd, struct page_info, list) -# define page_list_next(pg, hd) list_next_entry(pg, list) -# define page_list_prev(pg, hd) list_prev_entry(pg, list) -# define page_list_add(pg, hd) list_add(&(pg)->list, hd) -# define page_list_add_tail(pg, hd) list_add_tail(&(pg)->list, hd) -# define page_list_del(pg, hd) list_del(&(pg)->list) -# define page_list_del2(pg, hd1, hd2) list_del(&(pg)->list) -# define page_list_remove_head(hd) (!page_list_empty(hd) ? \ - ({ \ - struct page_info *__pg = page_list_first(hd); \ - list_del(&__pg->list); \ - __pg; \ - }) : NULL) -# define page_list_move(dst, src) (!list_empty(src) ? \ - list_replace_init(src, dst) : (void)0) + +static inline bool_t +page_list_empty(const struct page_list_head *head) +{ + return list_empty(head); +} +static inline struct page_info * +page_list_first(const struct page_list_head *head) +{ + return list_first_entry(head, struct page_info, list); +} +static inline struct page_info * +page_list_last(const struct page_list_head *head) +{ + return list_last_entry(head, struct page_info, list); +} +static inline struct page_info * +page_list_next(const struct page_info *page, + const struct page_list_head *head) +{ + return list_next_entry((struct page_info *)page, list); +} +static inline struct page_info * +page_list_prev(const struct page_info *page, + const struct page_list_head *head) +{ + return list_prev_entry((struct page_info *)page, list); +} +static inline void +page_list_add(struct page_info *page, struct page_list_head *head) +{ + list_add(&page->list, head); +} +static inline void +page_list_add_tail(struct page_info *page, struct page_list_head *head) +{ + list_add_tail(&page->list, head); +} +static inline void +page_list_del(struct page_info *page, struct page_list_head *head) +{ + list_del(&page->list); +} +static inline void +page_list_del2(struct page_info *page, struct page_list_head *head1, + struct page_list_head *head2) +{ + list_del(&page->list); +} +static inline struct page_info * +page_list_remove_head(struct page_list_head *head) +{ + struct page_info *pg; + + if ( page_list_empty(head) ) + return NULL; + + pg = page_list_first(head); + list_del(&pg->list); + return pg; +} +static inline void +page_list_move(struct page_list_head *dst, struct page_list_head *src) +{ + if ( !list_empty(src) ) + list_replace_init(src, dst); +} +static inline void +page_list_splice(struct page_list_head *list, struct page_list_head *head) +{ + list_splice(list, head); +} + # define page_list_for_each(pos, head) list_for_each_entry(pos, head, list) # define page_list_for_each_safe(pos, tmp, head) \ list_for_each_entry_safe(pos, tmp, head, list) # define page_list_for_each_safe_reverse(pos, tmp, head) \ list_for_each_entry_safe_reverse(pos, tmp, head, list) -# define page_list_splice(list, hd) list_splice(list, hd) #endif static inline unsigned int get_order_from_bytes(paddr_t size)