From patchwork Wed Oct 4 18:15:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 9985277 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 4909860586 for ; Wed, 4 Oct 2017 18:17:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F9A528BD4 for ; Wed, 4 Oct 2017 18:17:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3472B28BD7; Wed, 4 Oct 2017 18:17:48 +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.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID 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 7DE8928BD4 for ; Wed, 4 Oct 2017 18:17:47 +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 1dzoCv-000245-VB; Wed, 04 Oct 2017 18:15:45 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dzoCu-00022u-Ow for xen-devel@lists.xen.org; Wed, 04 Oct 2017 18:15:44 +0000 Received: from [85.158.139.211] by server-7.bemta-5.messagelabs.com id 9C/F8-02220-05525D95; Wed, 04 Oct 2017 18:15:44 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrOIsWRWlGSWpSXmKPExsVyMfTGJl1/1au RBsfmSlgs+biYxYHR4+ju30wBjFGsmXlJ+RUJrBnzJy9nKfipUjF56mzWBsaLMl2MXBxCAhMY JSYtamYCcVgE5jFLvLn4gBXEkRDoZ5VYtuwiSxcjJ5CTJ/Hv2QpWCDtNYsPkXnYIu0ri0bPDQ N0cQKPUJNa8iYKY2s8kceDwXlaQOJuAjsS6GbUg5SIC0hLXPl9mBLGZBaIlrv0+xARiCwuESv x+fwDMZhFQlfi+eBlYDa+AtcSGbeeh1spL7Gq7CGZzCthIzJrSDlYjBFTT136adQKj4AJGhlW MGsWpRWWpRbpGBnpJRZnpGSW5iZk5uoYGpnq5qcXFiempOYlJxXrJ+bmbGIEBV8/AwLiDsXG2 3yFGSQ4mJVHeWfJXI4X4kvJTKjMSizPii0pzUosPMcpwcChJ8N5UBsoJFqWmp1akZeYAQx8mL cHBoyTCuxUkzVtckJhbnJkOkTrFaMlx4c6lP0wcB/bcApIdN+/+YRJiycvPS5US530P0iAA0p BRmgc3DhaflxhlpYR5GRkYGIR4ClKLcjNLUOVfMYpzMCoJ85qqAE3hycwrgdv6CuggJqCD5jR dATmoJBEhJdXAyOmvc9TgedZCJSETTY+G5NXfY3l+RWhMb5H9flz+4NMj4aVaMTER0bsOy4t8 SJmtwvikwDGudKK+huzilAxfr4eHVl6cp/m8nWGe9EEJV87K10u+WK2Iy85gkP7uphhV5ng3g 70x2l+6TXqPyKfCPfIai4UEd9R15bywYLoxj09M+n539B4lluKMREMt5qLiRACblmIwygIAAA == X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-15.tower-206.messagelabs.com!1507140942!100574630!1 X-Originating-IP: [209.85.216.178] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 20228 invoked from network); 4 Oct 2017 18:15:43 -0000 Received: from mail-qt0-f178.google.com (HELO mail-qt0-f178.google.com) (209.85.216.178) by server-15.tower-206.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 4 Oct 2017 18:15:43 -0000 Received: by mail-qt0-f178.google.com with SMTP id k1so9909815qti.2 for ; Wed, 04 Oct 2017 11:15:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=cUNVyTHnL8NP0V5d0jARUJ1tCxz1AQjzcvO2htXzJ10=; b=g2Uj8ujEM1VoUo6jMc/I5OWTuXDy+2FgJsIg1cINRa2Gv6A5JJKTA9lgKU1Cw9NVDi Zh+ZL+li7RHe+3q6ztb2mtoXTqUTPFoqSjzPcYG7tElDxFld6Wl1kE96vVEWvJAJSeKg JBrXjsCosxAN6c1oSxWYVYK937f953wLJNfD0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=cUNVyTHnL8NP0V5d0jARUJ1tCxz1AQjzcvO2htXzJ10=; b=QyjrmHFB9qvuIn5j9ewmJeLFRA20RwTWVoWlsM/cvwog0PnXWcFEnEoBdhIytIDK07 33h6cJcD1E2G9I7MXbpYxv5U5dZmAOgRkSUQqy7B2AWAJMXu1D6UXz7ftKLxNBW3UDg7 HH7r1WJCPe+yY9P5ZwSomD7Z0IwQuIvrx2PB00/cFsKbfF7oyQHde5URwvEYjZI4wGRl 7iESWp+k/r3+fsSqm8d64vS3GRYRs1afhzfirpScVr+HA/yS8nox/o40SVnwwrkh6MIm RPoo+0DIHif9N6ZzOsJQev3/obijT+ekK8hSApjKK8YZP0KcrR9U+7xyYbZhvpdCV/i0 eOww== X-Gm-Message-State: AMCzsaXLQk5qmh6b71dLowJZwQOHkyCk/JaFKiBzF1B8LCzVHztLs46j dsULmm5Jh+hoDH08FHDipqLvjfSCSKk= X-Google-Smtp-Source: AOwi7QA4c/ijGZOTtfxkpKi6wzaB3V+rcZE0HfT4rKePQxujC4rCBEYd61sOVaLJHiIma4N7vgjU0A== X-Received: by 10.200.27.28 with SMTP id y28mr30936925qtj.297.1507140941965; Wed, 04 Oct 2017 11:15:41 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com ([2001:41d0:1:6c23::1]) by smtp.gmail.com with ESMTPSA id l188sm10210622qkd.43.2017.10.04.11.15.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Oct 2017 11:15:41 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Date: Wed, 4 Oct 2017 19:15:25 +0100 Message-Id: <20171004181526.9405-7-julien.grall@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171004181526.9405-1-julien.grall@linaro.org> References: <20171004181526.9405-1-julien.grall@linaro.org> Cc: Julien Grall , Konrad Rzeszutek Wilk Subject: [Xen-devel] [PATCH 6/7] xen/tmem: Convert the file common/tmem_xen.c to use typesafe MFN 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: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP The file common/tmem_xen.c is now converted to use typesafe. This is requiring to override the macro page_to_mfn to make it work with mfn_t. Note that all variables converted to mfn_t havem there initial value, when set, switch from 0 to INVALID_MFN. This is fine because the initial values was always overriden before used. Signed-off-by: Julien Grall --- Cc: Konrad Rzeszutek Wilk --- xen/common/tmem_xen.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/xen/common/tmem_xen.c b/xen/common/tmem_xen.c index 20f74b268f..8dc031514a 100644 --- a/xen/common/tmem_xen.c +++ b/xen/common/tmem_xen.c @@ -14,6 +14,10 @@ #include #include +/* Override macros from asm/page.h to make them work with mfn_t */ +#undef page_to_mfn +#define page_to_mfn(pg) _mfn(__page_to_mfn(pg)) + bool __read_mostly opt_tmem; boolean_param("tmem", opt_tmem); @@ -31,7 +35,7 @@ static DEFINE_PER_CPU_READ_MOSTLY(unsigned char *, dstmem); static DEFINE_PER_CPU_READ_MOSTLY(void *, scratch_page); #if defined(CONFIG_ARM) -static inline void *cli_get_page(xen_pfn_t cmfn, unsigned long *pcli_mfn, +static inline void *cli_get_page(xen_pfn_t cmfn, mfn_t *pcli_mfn, struct page_info **pcli_pfp, bool cli_write) { ASSERT_UNREACHABLE(); @@ -39,14 +43,14 @@ static inline void *cli_get_page(xen_pfn_t cmfn, unsigned long *pcli_mfn, } static inline void cli_put_page(void *cli_va, struct page_info *cli_pfp, - unsigned long cli_mfn, bool mark_dirty) + mfn_t cli_mfn, bool mark_dirty) { ASSERT_UNREACHABLE(); } #else #include -static inline void *cli_get_page(xen_pfn_t cmfn, unsigned long *pcli_mfn, +static inline void *cli_get_page(xen_pfn_t cmfn, mfn_t *pcli_mfn, struct page_info **pcli_pfp, bool cli_write) { p2m_type_t t; @@ -68,16 +72,16 @@ static inline void *cli_get_page(xen_pfn_t cmfn, unsigned long *pcli_mfn, *pcli_mfn = page_to_mfn(page); *pcli_pfp = page; - return map_domain_page(_mfn(*pcli_mfn)); + return map_domain_page(*pcli_mfn); } static inline void cli_put_page(void *cli_va, struct page_info *cli_pfp, - unsigned long cli_mfn, bool mark_dirty) + mfn_t cli_mfn, bool mark_dirty) { if ( mark_dirty ) { put_page_and_type(cli_pfp); - paging_mark_dirty(current->domain, _mfn(cli_mfn)); + paging_mark_dirty(current->domain, cli_mfn); } else put_page(cli_pfp); @@ -88,14 +92,14 @@ static inline void cli_put_page(void *cli_va, struct page_info *cli_pfp, int tmem_copy_from_client(struct page_info *pfp, xen_pfn_t cmfn, tmem_cli_va_param_t clibuf) { - unsigned long tmem_mfn, cli_mfn = 0; + mfn_t tmem_mfn, cli_mfn = INVALID_MFN; char *tmem_va, *cli_va = NULL; struct page_info *cli_pfp = NULL; int rc = 1; ASSERT(pfp != NULL); tmem_mfn = page_to_mfn(pfp); - tmem_va = map_domain_page(_mfn(tmem_mfn)); + tmem_va = map_domain_page(tmem_mfn); if ( guest_handle_is_null(clibuf) ) { cli_va = cli_get_page(cmfn, &cli_mfn, &cli_pfp, 0); @@ -125,7 +129,7 @@ int tmem_compress_from_client(xen_pfn_t cmfn, unsigned char *wmem = this_cpu(workmem); char *scratch = this_cpu(scratch_page); struct page_info *cli_pfp = NULL; - unsigned long cli_mfn = 0; + mfn_t cli_mfn = INVALID_MFN; void *cli_va = NULL; if ( dmem == NULL || wmem == NULL ) @@ -152,7 +156,7 @@ int tmem_compress_from_client(xen_pfn_t cmfn, int tmem_copy_to_client(xen_pfn_t cmfn, struct page_info *pfp, tmem_cli_va_param_t clibuf) { - unsigned long tmem_mfn, cli_mfn = 0; + mfn_t tmem_mfn, cli_mfn = INVALID_MFN; char *tmem_va, *cli_va = NULL; struct page_info *cli_pfp = NULL; int rc = 1; @@ -165,7 +169,7 @@ int tmem_copy_to_client(xen_pfn_t cmfn, struct page_info *pfp, return -EFAULT; } tmem_mfn = page_to_mfn(pfp); - tmem_va = map_domain_page(_mfn(tmem_mfn)); + tmem_va = map_domain_page(tmem_mfn); if ( cli_va ) { memcpy(cli_va, tmem_va, PAGE_SIZE); @@ -181,7 +185,7 @@ int tmem_copy_to_client(xen_pfn_t cmfn, struct page_info *pfp, int tmem_decompress_to_client(xen_pfn_t cmfn, void *tmem_va, size_t size, tmem_cli_va_param_t clibuf) { - unsigned long cli_mfn = 0; + mfn_t cli_mfn = INVALID_MFN; struct page_info *cli_pfp = NULL; void *cli_va = NULL; char *scratch = this_cpu(scratch_page);