From patchwork Wed Nov 1 14:03:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 10036343 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 523DA6032D for ; Wed, 1 Nov 2017 14:06:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2DC2728BB5 for ; Wed, 1 Nov 2017 14:06:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 20C6728BBA; Wed, 1 Nov 2017 14:06:07 +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 6F69728BB5 for ; Wed, 1 Nov 2017 14:06:06 +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 1e9tc8-0007th-Q5; Wed, 01 Nov 2017 14:03:28 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e9tc7-0007sV-4j for xen-devel@lists.xen.org; Wed, 01 Nov 2017 14:03:27 +0000 Received: from [85.158.143.35] by server-4.bemta-6.messagelabs.com id 4A/38-30895-E24D9F95; Wed, 01 Nov 2017 14:03:26 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrJIsWRWlGSWpSXmKPExsVyMbThiK7elZ+ RBjPO81gs+biYxYHR4+ju30wBjFGsmXlJ+RUJrBkvmw8zFlxRq2g/vJO5gfGHbBcjF4eQwARG iaVTXzF1MXJysAjMY5Z4dEMYJCEh0M8q0b3jIitIQkIgT6Ktv5MRwk6T6GzqZYOwqyTa3x4Fi nMATVKTWPMmCmJoN5PEngu7WEHibAI6Eutm1IKUiwhIS1z7fBlsDLNAtMS134fA9goLJEqcOf WDCaScRUBV4vc/MZAwr4CNxO/eFhaITfISu9ougk3kFLCVWHbFHCQsBFRyu+EE+wRGwQWMDKs Y1YtTi8pSi3RN9JKKMtMzSnITM3N0DQ3M9HJTi4sT01NzEpOK9ZLzczcxAgONAQh2MHZf9j/E KMnBpCTKu9Pxe6QQX1J+SmVGYnFGfFFpTmrxIUYZDg4lCV6Dyz8jhQSLUtNTK9Iyc4AhD5OW4 OBREuFVAEnzFhck5hZnpkOkTjHac1y4c+kPE8eBPbeAZMfNu0Dy2czXDcxCLHn5ealS4ryeIG 0CIG0ZpXlwQ2ExeolRVkqYlxHoTCGegtSi3MwSVPlXjOIcjErCvMcvAU3hycwrgdv9CugsJqC zvCR+gJxVkoiQkmpgzNjAdz3sgsjET6sc1Zdc3ef8R7nWmG2CikGJ4LWfS3NYt5xXiIqYd35b keIN69lR9VvZeli2KbXYidnP5vEvd3k1K+Hfb0+1oGN+i31+6ZddD1tZvn3G7Vsl2ySfzn+7c H7tiv8ik2a16ESdU7DxMfG7xvJ/A9fj7013f628qe/S+/qlqvut6UosxRmJhlrMRcWJAG9L0q TMAgAA X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-2.tower-21.messagelabs.com!1509545006!66022001!1 X-Originating-IP: [209.85.128.196] 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 7303 invoked from network); 1 Nov 2017 14:03:26 -0000 Received: from mail-wr0-f196.google.com (HELO mail-wr0-f196.google.com) (209.85.128.196) by server-2.tower-21.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 1 Nov 2017 14:03:26 -0000 Received: by mail-wr0-f196.google.com with SMTP id 15so2037189wrb.5 for ; Wed, 01 Nov 2017 07:03:26 -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=a2IQRJdadRsXnkNjJeLgl4keeG6+6VhzSbgYQ8i+aJaYG31V4d1bYXBsfKBrWTzlxE JB+pgidpYb+tFkUCWI3pbDAFmnU9kqhhsvSPA8cXvFcXl6nSt26FInpQrCJLdbwhQID3 I5jM9oxiw8fFf/x4Br/xmXFqosbgVvTDS8xNA= 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=COGug3Z5z06Wl1gbDhK1WB3XAKsV63gw6UryZDKBnJH9seWL2ogQjs8vlDlUJRRPJl +/Cx6izUk5F6S1QfVunJbw1CmkBSNVdO18U9RLlrIu6fuEFE7NJpEzETcu6Sxo/8tLgB a3vRfdV4Xpdbc7BCMBQNxhzwnzy2G4zoXdJt2Ydxgtbhhvy+Q77sJr0jEek41axtdqPh 8SOsdxTNSn66ESMX/nKFNjfRkgYhhn5weGZ+r7QMHvoBzLIizPtaiJNuRsr3QeQnX+Iz 6o39kKf7mhv83+mNMvVQIKghIE9PNeDVLaoikeaEhc5tzz7Dl8d0P8hfZzbePcHF2rrc /e+w== X-Gm-Message-State: AMCzsaVPE0sjunIwqrnnjTxCM4EGwZKgE44Vj4cPlA/JtOyZbGrhpPxG ErK/5opEh+Nxfmc1ulywovzD1gBkGMo= X-Google-Smtp-Source: ABhQp+Rof5qAi9aPBhtE4ztb8UfWDM0nQ8z6DI6obT03tIuNowRTvqbIeT4PH9pmliBKrlcNVL47dw== X-Received: by 10.223.166.146 with SMTP id t18mr5256884wrc.64.1509545005384; Wed, 01 Nov 2017 07:03:25 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com ([2001:41d0:1:6c23::1]) by smtp.gmail.com with ESMTPSA id w4sm595582wrc.17.2017.11.01.07.03.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Nov 2017 07:03:24 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Date: Wed, 1 Nov 2017 14:03:15 +0000 Message-Id: <20171101140316.31333-4-julien.grall@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171101140316.31333-1-julien.grall@linaro.org> References: <20171101140316.31333-1-julien.grall@linaro.org> Cc: Julien Grall , Konrad Rzeszutek Wilk Subject: [Xen-devel] [PATCH v3 for-next 3/4] 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 Acked-by: Konrad Rzeszutek Wilk --- 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);