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: 117698 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp928040qgn; Wed, 1 Nov 2017 07:05:42 -0700 (PDT) X-Google-Smtp-Source: ABhQp+RuWvy8Zh3xz+8fkz48UMwPo/pcHATKWN8/rv/3RPuP1lWIHebwcdR+N8Q2bq+mnbGW+lkK X-Received: by 10.36.14.207 with SMTP id 198mr650469ite.66.1509545142648; Wed, 01 Nov 2017 07:05:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509545142; cv=none; d=google.com; s=arc-20160816; b=kgWDJLuD1ox/U8gOAsPZTDEt8wRRyFdgGVhk9c5W5nuktOZ+NIIhSVlPKig8bTlryW njqtz8xnAXqx60MpLfBEX6hKq2+wRKc1shQ9nbl7Z55/vqQpFoU9JekhE5HN2+5n27Bc HJrVWvehRkDsrvzQF9dnp5O0z2p9g9ItvsbmEV+W1RNB4v4PkZfkJLDajp7zjuFiJcw2 GEPubZGRxmAzMXt6T45hiJLjerTnHtYF4UsVHslaLShWDo5hHH9RYExsfvfQ4y54uQ4X zR5pSxEff2YYcidbjW34ayI6c/mrnLykj9Fnv5ndcWWe8CURj6aGoY6+xgz8U54VFBdv KyZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:cc:references:in-reply-to:message-id:date:to :from:dkim-signature:arc-authentication-results; bh=wGN7/Oj6mq9DHjcHIhGFfCd5EgxMXkB4mvbWTsD3RPw=; b=GWr/xvCWjPf1ajZNU3m7ZkB/6vLx2izaZnLrzxv48Y3FpIkkWXUnrAMpMMiBXbGHV0 b9glNaJE/1zoN4Y+PtixOIViLS5NG800eozFp+CEfGums4N/O5gFzEJEjYJQQTDm5Zq0 W5GZBDI5RwCshNCTklcseythvDFcMOlqPsi2nNGkd4ufMOuF95yTbe82hMyd/ju2Jnyb 3CGZB6Cdyu3q4T9QmDAe/sZsG7LA/TXwRXP6pAOY/uC/3NqLOtxepUYmTYFA7BE3e+9O iANxUKtW3x7WxUs391b+zGCpZqvjoezsA2QoDnCAwacmkIcdvJ/0LR4+fxfY4n/ycgDl EJLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=a2IQRJda; spf=neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) smtp.mailfrom=xen-devel-bounces@lists.xen.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id m133si1043260itb.99.2017.11.01.07.05.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Nov 2017 07:05:42 -0700 (PDT) Received-SPF: neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) client-ip=192.237.175.120; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=a2IQRJda; spf=neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) smtp.mailfrom=xen-devel-bounces@lists.xen.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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-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" 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);