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: 114786 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp3428453qgn; Wed, 4 Oct 2017 11:17:30 -0700 (PDT) X-Received: by 10.36.122.68 with SMTP id a65mr28082569itc.97.1507141050500; Wed, 04 Oct 2017 11:17:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507141050; cv=none; d=google.com; s=arc-20160816; b=NECQ24Yyc6gmUDeSyQRo0cWCdl4dAKCtio6P3j5gJfFnuSxcN1ke8M9Y8ai7bUqP/x 5jz8UQgvfzKvZdwsMj/boY3PRJXcS6JEpg3PdNFYRtLeKPU3Gs5qCQxPte92C0YzzHP3 3yOgpyJWKaacy5hslkAmwH47YlUWaDTJVchnr8DgoJM/T1E19gUbI7Hk+8b4B1mjbGbj 0Fbk7Ojn8bgTHXC3qPtloxyXQd17muu7tT7Oip/Leuld+waESqBxSZ0rG9qhbbGUfGbm SLi8qqnF4NQML+ImOZ7BG7DAd9YFdwjUvheqB/6VfqqTMHIxVsQIdHYFvfBTykP4e1NN jpCA== 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=knnjqN+UKnJGgbQcQ6HU0W3CRBEdQuBE3AfHL8KxKA4=; b=yQrt50Xh6CTNYF8M88gxv7T0CP18F7UDJps1Pt39sw5v+zwYu9xhGPHryIMjgk8/my Ja2KLCmmI0XOUL5kR5dTeIDnq7del0RqMKqjqo6S/82ffrcnkHRVmOPgT9eIB6WCAW9Y qr0Xz8na6gJKYpBtyKqiBYIvD8pQ+uA0lK4fhzSfeXB70BB0fGQvbOkfYZvC1YkTE4hN IE9PKq16CCvwxkJjR9C899Uy5JuNfT0/f3KxE6kGmpUCh342EKk45lUu+xzTdw5Rp8DG xoNLssziWV7cclB1iQGSikWXLUAG8SEd4jjfz/zPhFPSN0MCdA83gitzFioQSAUgS4IQ VsYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=g2Uj8ujE; 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 l134si12926016itc.168.2017.10.04.11.17.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Oct 2017 11:17:30 -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=g2Uj8ujE; 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 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" 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);