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: 114953 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp848233qgn; Thu, 5 Oct 2017 10:44:38 -0700 (PDT) X-Received: by 10.36.68.207 with SMTP id o198mr821662ita.74.1507225477952; Thu, 05 Oct 2017 10:44:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507225477; cv=none; d=google.com; s=arc-20160816; b=qLwVd7Zdal+kAMpI0C424ylZQHFxf/fvUBWPoGV842C3L5IDODc4/+HHoZRQNDUDej 377Qj5kc1apLcwRniXTqVsdPH+k8p3EoSx7GgilbKMMl9gnP97fpHEEdyTZHeuPQlgJu byQEHaLR2U0Ln8gM6o4UVeDg1qAujtAgwJGKfRAxxo0tPSXoL4xbq4V3LnGoO/533hEj ZFDRryuA2ZlwOfAVXxCNgCv5CAmh7fO/9voN5zjEbN3UMdbvXOOlmCXKI4kxRTZ3V6Et t2uFz+E2gp3AZB/2rPgEcT8qbfwudVliZZYVLA3HMi14D7U3ns0I7Kf+9gC+V2LJDqVi pxZw== 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=U+4c0a08NZdwYT8VjyvTvKTh75YxJGnAO0kin8oN/5tkUlAQXFe5XwYNZv1LT38ly4 AWTOWbixwD+/JgQ8o/DiInkD6kVjtq2mRX/YJl4LHu9mXh54czC3adtNHnVSIx6+yv+l MIXyAYAP0djEqhUyb/HawLTZdjw7YGCgpmeEvBHsgHnsN+6vxy2vDkhwRIIWlRgziEel WI01kTfFguwKY2OJOne27UjyoB1UbdiJlY7XQ1lrO1tw7CeMfWY+j/XuHJOdtajZEVly +y0iQMypMPmKsmv+ri0qWWY1Lq9fPS4FjKdH9Tt3QCeKRWK0OKVkBalJqZrqwA6Q1Uon 0XJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=enhj/DXi; 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 r90si677789ioe.128.2017.10.05.10.44.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Oct 2017 10:44:37 -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=enhj/DXi; 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 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" 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);