From patchwork Mon Aug 1 16:59:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 9254557 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 5D33A6075F for ; Mon, 1 Aug 2016 17:02:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 49A9C284A9 for ; Mon, 1 Aug 2016 17:02:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3BFB4284AD; Mon, 1 Aug 2016 17:02:03 +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 99CA8284A9 for ; Mon, 1 Aug 2016 17:02:02 +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 1bUGZ4-00057x-J4; Mon, 01 Aug 2016 16:59:42 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bUGZ3-00057h-Hc for xen-devel@lists.xen.org; Mon, 01 Aug 2016 16:59:41 +0000 Received: from [85.158.139.211] by server-6.bemta-5.messagelabs.com id 1D/0A-29022-CFF7F975; Mon, 01 Aug 2016 16:59:40 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrJIsWRWlGSWpSXmKPExsXitHSDve6f+vn hBovX8Fos+biYxYHR4+ju30wBjFGsmXlJ+RUJrBnX125kLLghXTGt+TNjA+MNsS5GTg4JAX+J Lyv2MYHYbAL6ErtffAKzRQTUJU53XGTtYuTiYBY4yihxa855RpCEsEC0xJw9rSwgNouAisSrC VPYQWxeAU+Ji60n2SCGykmcP/6TuYuRg4NTwE7izi5RkLCQgK3EnEU72SDKBSVOznwCNoZZQF OidftvdghbXqJ562xmiHo1iWv9l9ghRnJL3D49lXkCI/8sJO2zkLTPQtK+gJF5FaNGcWpRWWq RrpGxXlJRZnpGSW5iZo6uoYGpXm5qcXFiempOYlKxXnJ+7iZGYBDWMzAw7mDc0e53iFGSg0lJ lDehYH64EF9SfkplRmJxRnxRaU5q8SFGGQ4OJQleRmBQCwkWpaanVqRl5gDjASYtwcGjJML7r g4ozVtckJhbnJkOkTrFqCglzvsTJCEAksgozYNrg8XgJUZZKWFeRgYGBiGegtSi3MwSVPlXjO IcjErCvLNBpvBk5pXATX8FtJgJaHGi/RyQxSWJCCmpBkYpvx8cp0InFMQ3fu4UUzx64/iG28f sznx7Ysewq6dw5VyJXUe75zcFrJ8+qWl539ZT8jK6LG0mtzZpZa/l87b9+pRNWdrAzn+abcg0 8f0XLn2/HLhHoaB6zq7+/F6b5k9vZwYHOL4sPuzubF74I0776R237Xpp08+5aZZIn05de0yla 4lVipcSS3FGoqEWc1FxIgBevobvvAIAAA== X-Env-Sender: prvs=0144eb958=Andrew.Cooper3@citrix.com X-Msg-Ref: server-3.tower-206.messagelabs.com!1470070778!48756768!1 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: 8.77; banners=-,-,- X-VirusChecked: Checked Received: (qmail 28678 invoked from network); 1 Aug 2016 16:59:39 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-3.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 1 Aug 2016 16:59:39 -0000 X-IronPort-AV: E=Sophos;i="5.28,456,1464652800"; d="scan'208";a="376708616" From: Andrew Cooper To: Xen-devel Date: Mon, 1 Aug 2016 17:59:36 +0100 Message-ID: <1470070776-19018-1-git-send-email-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <721651f7-8dc1-5c7d-5f26-11902905e2e2@citrix.com> References: <721651f7-8dc1-5c7d-5f26-11902905e2e2@citrix.com> MIME-Version: 1.0 X-DLP: MIA2 Cc: George Dunlap , Andrew Cooper , Tim Deegan , Jan Beulich , Tamas K Lengyel Subject: [Xen-devel] [PATCH v2 2/2] x86/mm: Annotate gfn_get_* helpers as requiring non-NULL parameters 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 Introduce and use the nonnull attribute to help the compiler catch NULL parameters being passed to function which require their parameters not to be NULL. Experimentally, GCC 4.9 on Debian Jessie only warns of non-NULL-ness from immediate callers, so propagate the attributes out to all helpers. A sample error looks like: mem_sharing.c: In function ‘mem_sharing_nominate_page’: mem_sharing.c:884:13: error: null argument where non-null required (argument 3) [-Werror=nonnull] amfn = get_gfn_type_access(ap2m, gfn, NULL, &ap2ma, 0, NULL); ^ As part of this, replace the get_gfn_type_access() macro with an equivalent static inline function for extra type safety, and the ability to be annotated. Signed-off-by: Andrew Cooper Acked-by: Jan Beulich Acked-by: George Dunlap --- CC: Jan Beulich CC: Tim Deegan CC: George Dunlap CC: Tamas K Lengyel v2: * s/nonnull/__nonnull__/ * Tolerate the p2m parameter being NULL --- xen/include/asm-x86/p2m.h | 19 +++++++++++-------- xen/include/xen/compiler.h | 1 + 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/xen/include/asm-x86/p2m.h b/xen/include/asm-x86/p2m.h index 194020e..035ca92 100644 --- a/xen/include/asm-x86/p2m.h +++ b/xen/include/asm-x86/p2m.h @@ -380,9 +380,9 @@ void p2m_unlock_and_tlb_flush(struct p2m_domain *p2m); * After calling any of the variants below, caller needs to use * put_gfn. ****/ -mfn_t __get_gfn_type_access(struct p2m_domain *p2m, unsigned long gfn, - p2m_type_t *t, p2m_access_t *a, p2m_query_t q, - unsigned int *page_order, bool_t locked); +mfn_t __nonnull(3, 4) __get_gfn_type_access( + struct p2m_domain *p2m, unsigned long gfn, p2m_type_t *t, + p2m_access_t *a, p2m_query_t q, unsigned int *page_order, bool_t locked); /* Read a particular P2M table, mapping pages as we go. Most callers * should _not_ call this directly; use the other get_gfn* functions @@ -391,13 +391,16 @@ mfn_t __get_gfn_type_access(struct p2m_domain *p2m, unsigned long gfn, * If the lookup succeeds, the return value is != INVALID_MFN and * *page_order is filled in with the order of the superpage (if any) that * the entry was found in. */ -#define get_gfn_type_access(p, g, t, a, q, o) \ - __get_gfn_type_access((p), (g), (t), (a), (q), (o), 1) +static inline mfn_t __nonnull(3, 4) get_gfn_type_access( + struct p2m_domain *p2m, unsigned long gfn, p2m_type_t *t, + p2m_access_t *a, p2m_query_t q, unsigned int *page_order) +{ + return __get_gfn_type_access(p2m, gfn, t, a, q, page_order, true); +} /* General conversion function from gfn to mfn */ -static inline mfn_t get_gfn_type(struct domain *d, - unsigned long gfn, p2m_type_t *t, - p2m_query_t q) +static inline mfn_t __nonnull(3) get_gfn_type( + struct domain *d, unsigned long gfn, p2m_type_t *t, p2m_query_t q) { p2m_access_t a; return get_gfn_type_access(p2m_get_hostp2m(d), gfn, t, &a, q, NULL); diff --git a/xen/include/xen/compiler.h b/xen/include/xen/compiler.h index 892455b..f3e8d95 100644 --- a/xen/include/xen/compiler.h +++ b/xen/include/xen/compiler.h @@ -61,6 +61,7 @@ #define __maybe_unused __attribute__((__unused__)) #define __must_check __attribute__((__warn_unused_result__)) +#define __nonnull(...) __attribute__((__nonnull__(__VA_ARGS__))) #define offsetof(a,b) __builtin_offsetof(a,b)