From patchwork Thu Oct 5 17:42:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 9987665 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 6FE466029B for ; Thu, 5 Oct 2017 17:45:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5A9E628D14 for ; Thu, 5 Oct 2017 17:45:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4F4F628D16; Thu, 5 Oct 2017 17:45:04 +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=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RCVD_IN_SORBS_SPAM,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 2361128D17 for ; Thu, 5 Oct 2017 17:45:03 +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 1e0AAW-00014P-1b; Thu, 05 Oct 2017 17:42:44 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e0AAU-00012U-FW for xen-devel@lists.xen.org; Thu, 05 Oct 2017 17:42:42 +0000 Received: from [85.158.137.68] by server-1.bemta-3.messagelabs.com id 96/EB-02047-11F66D95; Thu, 05 Oct 2017 17:42:41 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrCIsWRWlGSWpSXmKPExsVyMfTOGl2B/Gu RBquvW1ks+biYxYHR4+ju30wBjFGsmXlJ+RUJrBkvmw8zFlxRq2g/vJO5gfGHbBcjJ4eQwGRG ie7F7l2MXBwsAvOYJXZc/MYM4kgI9LNKTD11gxWkSkIgT+Jl13kmCDtN4t+cDewQdqXEl80rg OIcQJPUJNa8iQLpFRLoY5K4MfkAI0icTUBHYt2MWpByEQFpiWufLzOC2MwC0RLXfh8CaxUWiJ D4PssdJMwioCpxb95isE28AjYS5xc8ZIPYJC+xq+0i2DWcArYS63vusEPcbyOxfMVZ5gmMggs YGVYxqhenFpWlFuka6iUVZaZnlOQmZuboGhoY6+WmFhcnpqfmJCYV6yXn525iBIYaAxDsYFz+ 0ekQoyQHk5Ior1fWtUghvqT8lMqMxOKM+KLSnNTiQ4wyHBxKErz8eUA5waLU9NSKtMwcYNDDp CU4eJREeOVB0rzFBYm5xZnpEKlTjJYcF+5c+sPEcWDPLSDZcfPuHyYhlrz8vFQpcd49uUANAi ANGaV5cONgkXmJUVZKmJcR6EAhnoLUotzMElT5V4ziHIxKwrx/QKbwZOaVwG19BXQQE9BBc5q ugBxUkoiQkmpgzC2dtPArd/4nrofKN0N7z4jvfnq8/oPyBl3lrhV/HWSmxnqvqr8nENcftPpv ieu96A3V81u8vjh2ZtsvXjjTU/6ueQwDw1vRN7WWthsnV+9eX2fCd7gtdvfLgAfW2lntst9Wt XW8XNCSuuOJiX+BWJnxjF1xbz458yxwrL5g1jy9RMP3W+RPJZbijERDLeai4kQAATDnZccCAA A= X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-10.tower-31.messagelabs.com!1507225360!117421887!1 X-Originating-IP: [209.85.220.172] 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 12512 invoked from network); 5 Oct 2017 17:42:40 -0000 Received: from mail-qk0-f172.google.com (HELO mail-qk0-f172.google.com) (209.85.220.172) by server-10.tower-31.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 5 Oct 2017 17:42:40 -0000 Received: by mail-qk0-f172.google.com with SMTP id l194so5505053qke.13 for ; Thu, 05 Oct 2017 10:42:40 -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=I36YDcdVKgwsPPKvceFw4AWZsTp6g82Fn4s6nFHEY48=; b=enhj/DXiLeGW5TsuMgcltHk0TCcAXE+tX3mQsx86Q3R105Tl42QPf00DeYdV99TcaH u6dshrzNvKEXZDF0skfTCh+o8yBzQZABhbNgevkgPK0QVMSZZHXK/tGAy8gHG6x1cX1w RD4e91FleRWubRpEW6RfMutQYSAoumfgsT7Tg= 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=I36YDcdVKgwsPPKvceFw4AWZsTp6g82Fn4s6nFHEY48=; b=U9LKAsA1ShwEFxsROBs9VgiVNBi5HiYSnQFzpfxyrdxPX5Je414v9UGM5jz4PyGj9a iUxYZZUNIeKGTq4fNHegNb6tCLIGPdStLnvgeNcR/A9IYodx81GeVN3Wkwh+vP7KX5qP +spWm0ycFaU749946px+Ku4JDjVA+IKVfZAibXLsSiDmS5V0fvdE4wv8ln9TlL+fFpJO c0rx3o+5nfbcRNoarhEWdlWB9H9DrHgxABYqV6glWcBOe2hbqDiutNSPXKQm/Y5ZkqAN gFdA++HqYnyhRApxDg4e3v5mGvcjIRtPwqPZcvsn1d+pVdT+iBElSvkwp0qfZwFEr3ZN cMyQ== X-Gm-Message-State: AMCzsaWXvfdLya/2X1TSWB6kUJ9/b9cF7RfD6/gfut9g2qUo4VLublq9 U3eK2rHrHJnpI29eyHmesWM6t73dZh4= X-Google-Smtp-Source: AOwi7QDnS1JP2mepuLenmFBmfBPQIfBs8cZB5DRcch4h4v1STurQ1gyO3HkchsnouXh3r3mdfptlAQ== X-Received: by 10.55.22.13 with SMTP id g13mr32467689qkh.153.1507225359614; Thu, 05 Oct 2017 10:42:39 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com ([2001:41d0:1:6c23::1]) by smtp.gmail.com with ESMTPSA id y63sm11815084qky.75.2017.10.05.10.42.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Oct 2017 10:42:39 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Date: Thu, 5 Oct 2017 18:42:21 +0100 Message-Id: <20171005174222.29161-9-julien.grall@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171005174222.29161-1-julien.grall@linaro.org> References: <20171005174222.29161-1-julien.grall@linaro.org> Cc: Julien Grall , Konrad Rzeszutek Wilk Subject: [Xen-devel] [PATCH v2 8/9] 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. Also add a couple of missing newlines suggested by Andrew in the code. Signed-off-by: Julien Grall Reviewed-by: Andrew Cooper --- Cc: Konrad Rzeszutek Wilk Changes in v2: - Add missing newlines - Add Andrew's reviewed-by --- xen/common/tmem_xen.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/xen/common/tmem_xen.c b/xen/common/tmem_xen.c index 20f74b268f..bd52e44faf 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,17 @@ 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 +93,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 +130,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 +157,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 +170,8 @@ 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 +187,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);