From patchwork Thu Oct 5 17:42:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 114955 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp848267qgn; Thu, 5 Oct 2017 10:44:40 -0700 (PDT) X-Received: by 10.36.94.130 with SMTP id h124mr32358145itb.2.1507225480415; Thu, 05 Oct 2017 10:44:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507225480; cv=none; d=google.com; s=arc-20160816; b=TbulP0c+pOEiCE9B+V65PJUYWkJoq+YPq0An0grEOtBq30azyK6+AvzIh8yYm/7UgP /wNB8KHjezdqoBj3CiQ96YcQtzwQCiH2Qt9+OKT+qh1MVLAzy3RnzkEpYMcyqC77nZ+Q +tR6sk0Ym/k4fuas6Lm4qo3P/qCbf83n000SXD/+YGiOXECrKTPG7WptRdQjaDmnXhVl fnUQwuJ9P4Z/1BcXvMeNKcUk9qJ0NkaljJEiGEy/I2fvv9SFY27bQ/MpwlRccT+UTrIe mRgdYwJDkGywFGyDyO35ARXza5S4IvGOGtg71Ft0x4WiKqeX5VSpAi8HEl7SC6s+dH3I XP0w== 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=cJ5x3sCsaROmt3jk5OIwt4XUR0eflg8wSjsVcYmG5y8=; b=M7576Te1B5XCv04VsuU16aBmP8mwdDQ6PtGCAlCNiT75b91fzUkZuJejWZljGZLljB iabQxU2uPLybGEt78+apBBIJIPfjrICAeUuhH5OQHZHqzbvmF0TTnlpou+AJUAxdGk5K r2HekuW5UBnI4SgXF19772e1zRC938gjvaA0qAxGj01xKn2Ol2PpwApwh8Q7QpjGf/Gj 8mgs7/iMx0vl116L6Ge0l1b72WucfCwgSszg4LmfkeFjDm+AD8ySUB7u5Gb4Zujfu0qv dYgt5pv202rKZq9qX5OPTRufTiOGR68taEwaGgNPg1X8fLZpZm1epfsA9zDXwlTNX3B8 cE0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=AHv4rDd8; 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 o194si15076632ioo.340.2017.10.05.10.44.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Oct 2017 10:44:40 -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=AHv4rDd8; 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 1e0AAS-00011E-IT; Thu, 05 Oct 2017 17:42:40 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e0AAR-0000z9-FM for xen-devel@lists.xen.org; Thu, 05 Oct 2017 17:42:39 +0000 Received: from [193.109.254.147] by server-5.bemta-6.messagelabs.com id 37/D8-03453-E0F66D95; Thu, 05 Oct 2017 17:42:38 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrEIsWRWlGSWpSXmKPExsVyMfTOVl2+/Gu RBjvmMlks+biYxYHR4+ju30wBjFGsmXlJ+RUJrBnP7x5kLzhnVjFv3XPGBsYvGl2MXBxCAhMZ JS7eOMXYxcjJwSIwj1ni7XtDkISEQD+rxLVZ68ESEgJ5Ej/+fQSyOYDsNImuRXoQZpXElDXhI KaQgJrEmjdRECP7mCSedT1iA4mzCehIrJtRCzJEREBa4trny2ADmQW0JH6eWwJWIiwQIfHljy TEAaoSs7oms4CEeQVsJC7vSoVYLy+xq+0iK4jNKWArsb7nDjuILQRUsnzFWeYJjIILGBlWMWo UpxaVpRbpGhnrJRVlpmeU5CZm5ugaGpjp5aYWFyemp+YkJhXrJefnbmIEhhkDEOxg/DM/8BCj JAeTkiivV9a1SCG+pPyUyozE4oz4otKc1OJDjDIcHEoSvPx5QDnBotT01Iq0zBxgwMOkJTh4l ER4n+YCpXmLCxJzizPTIVKnGC05Lty59IeJ48CeW0Cy4+bdP0xCLHn5ealS4rzGIPMEQBoySv PgxsGi8hKjrJQwLyPQgUI8BalFuZklqPKvGMU5GJWEeQ+CrOXJzCuB2/oK6CAmoIPmNF0BOag kESEl1cAoPOVAoEjF+U1fvsr6WtjtM1aL2NqlwfSl0//+Y6+OnVl+u21b3fP8X73ctq52w9VN B02Mq491vm22TJB3vXbm9relH4+JBV0oO+UtUqsS4f76J88JU9Ofu291T+mRFo581c7L9evS8 79+4UcfJ2o8zfmqlLa6T+FW44Ly2Vtu/tL4lpFsW6GuxFKckWioxVxUnAgA9A3xAcUCAAA= X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-2.tower-27.messagelabs.com!1507225357!50752389!1 X-Originating-IP: [209.85.220.181] 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 16849 invoked from network); 5 Oct 2017 17:42:37 -0000 Received: from mail-qk0-f181.google.com (HELO mail-qk0-f181.google.com) (209.85.220.181) by server-2.tower-27.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 5 Oct 2017 17:42:37 -0000 Received: by mail-qk0-f181.google.com with SMTP id s14so2251185qks.6 for ; Thu, 05 Oct 2017 10:42:37 -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=IbrwkmISdeyT/h3aspC38nqOUgqTwVCohE7dZ/T7lq4=; b=AHv4rDd82nfz9nh6SRjNb8T3Ix8GagWfIde0aHZuislnO4FE4mudh3eXoqV3YH/Lts fvUfqd0l4OvqX9t2IXQNmzwTZ3KyOVmdBRqrm/2awBYyYnksDExhUO9wEqUN/9dMLQas 84CcPJ56mtQaRtbCNmLEIp8zMJFe2nLTWwhuw= 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=IbrwkmISdeyT/h3aspC38nqOUgqTwVCohE7dZ/T7lq4=; b=YgV/7TqmcWSNx2thFgqrwciLe809sUUwUKuxGRtEBbhb1nzAQS9VM2aZvjtZG2Fef3 Ry0j577Sxlx/HwoCGl8jgsngK77G3DBI7AhT5omyGZwLuZd1IJ5+J/fBawA3hxtvYlTT M7TAVkkP4K8VWHWy42oe0YB5II38c66SFDQxyWPkudLEFJZeRf0R0lz4LpeXCW8tWCyb 3HPGwGrJCOd4PIHkEHMew76+nmkIWzkMzeeDt7LrP3wPiMQX1/zkZOZqvFRGAgAE6Ej5 453i5hCDPq0cfnvMUKosusP1GJMjV470xwVLC0AWkSnYaafoEAE86ca+/6d1yZbT7noZ lsTg== X-Gm-Message-State: AMCzsaVsVqZHr1qxQ2IV20bPqTsVv/KPbXD9HDrJ2/BWgHrPK1Pbjqgq Gc911rhauDWn4UVKB4qYeq6g8HT1lH0= X-Google-Smtp-Source: AOwi7QAHEdFXeA9g+uaDtljM1LeC1irNtc/4PPJbUeyBxNdSf5hSaU4taT/DCMYIPzpQ1o8uF6e6YA== X-Received: by 10.55.178.65 with SMTP id b62mr31887532qkf.348.1507225356627; Thu, 05 Oct 2017 10:42:36 -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.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Oct 2017 10:42:36 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Date: Thu, 5 Oct 2017 18:42:19 +0100 Message-Id: <20171005174222.29161-7-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 Subject: [Xen-devel] [PATCH v2 6/9] xen/kexec, kimage: Convert kexec and kimage to use typesafe mfn_t 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" At the same time, correctly align one the prototype changed. Signed-off-by: Julien Grall Reviewed-by: Andrew Cooper --- xen/common/kexec.c | 16 ++++++++-------- xen/common/kimage.c | 30 ++++++++++++++++++------------ xen/include/xen/kimage.h | 4 ++-- 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/xen/common/kexec.c b/xen/common/kexec.c index fcc68bd4d8..c14cbb2b9c 100644 --- a/xen/common/kexec.c +++ b/xen/common/kexec.c @@ -905,11 +905,11 @@ static uint16_t kexec_load_v1_arch(void) #endif } -static int kexec_segments_add_segment( - unsigned int *nr_segments, xen_kexec_segment_t *segments, - unsigned long mfn) +static int kexec_segments_add_segment(unsigned int *nr_segments, + xen_kexec_segment_t *segments, + mfn_t mfn) { - paddr_t maddr = (paddr_t)mfn << PAGE_SHIFT; + paddr_t maddr = mfn_to_maddr(mfn); unsigned int n = *nr_segments; /* Need a new segment? */ @@ -930,7 +930,7 @@ static int kexec_segments_add_segment( return 0; } -static int kexec_segments_from_ind_page(unsigned long mfn, +static int kexec_segments_from_ind_page(mfn_t mfn, unsigned int *nr_segments, xen_kexec_segment_t *segments, bool_t compat) @@ -939,7 +939,7 @@ static int kexec_segments_from_ind_page(unsigned long mfn, kimage_entry_t *entry; int ret = 0; - page = map_domain_page(_mfn(mfn)); + page = map_domain_page(mfn); /* * Walk the indirection page list, adding destination pages to the @@ -961,7 +961,7 @@ static int kexec_segments_from_ind_page(unsigned long mfn, break; case IND_INDIRECTION: unmap_domain_page(page); - entry = page = map_domain_page(_mfn(mfn)); + entry = page = map_domain_page(mfn); continue; case IND_DONE: goto done; @@ -990,7 +990,7 @@ static int kexec_do_load_v1(xen_kexec_load_v1_t *load, int compat) xen_kexec_segment_t *segments; uint16_t arch; unsigned int nr_segments = 0; - unsigned long ind_mfn = load->image.indirection_page >> PAGE_SHIFT; + mfn_t ind_mfn = maddr_to_mfn(load->image.indirection_page); int ret; arch = kexec_load_v1_arch(); diff --git a/xen/common/kimage.c b/xen/common/kimage.c index 07587896a4..afd8292cc1 100644 --- a/xen/common/kimage.c +++ b/xen/common/kimage.c @@ -23,6 +23,12 @@ #include +/* Override macros from asm/page.h to make them work with mfn_t */ +#undef mfn_to_page +#define mfn_to_page(mfn) __mfn_to_page(mfn_x(mfn)) +#undef page_to_mfn +#define page_to_mfn(pg) _mfn(__page_to_mfn(pg)) + /* * When kexec transitions to the new kernel there is a one-to-one * mapping between physical and virtual addresses. On processors @@ -76,7 +82,7 @@ static struct page_info *kimage_alloc_zeroed_page(unsigned memflags) if ( !page ) return NULL; - clear_domain_page(_mfn(page_to_mfn(page))); + clear_domain_page(page_to_mfn(page)); return page; } @@ -405,7 +411,7 @@ static struct page_info *kimage_alloc_crash_control_page(struct kexec_image *ima if ( page ) { image->next_crash_page = hole_end; - clear_domain_page(_mfn(page_to_mfn(page))); + clear_domain_page(page_to_mfn(page)); } return page; @@ -641,7 +647,7 @@ static struct page_info *kimage_alloc_page(struct kexec_image *image, *old = (addr & ~PAGE_MASK) | IND_SOURCE; unmap_domain_page(old); - page = mfn_to_page(mfn_x(old_mfn)); + page = mfn_to_page(old_mfn); break; } else @@ -840,11 +846,11 @@ kimage_entry_t *kimage_entry_next(kimage_entry_t *entry, bool_t compat) return entry + 1; } -unsigned long kimage_entry_mfn(kimage_entry_t *entry, bool_t compat) +mfn_t kimage_entry_mfn(kimage_entry_t *entry, bool_t compat) { if ( compat ) - return *(uint32_t *)entry >> PAGE_SHIFT; - return *entry >> PAGE_SHIFT; + return maddr_to_mfn(*(uint32_t *)entry); + return maddr_to_mfn(*entry); } unsigned long kimage_entry_ind(kimage_entry_t *entry, bool_t compat) @@ -854,7 +860,7 @@ unsigned long kimage_entry_ind(kimage_entry_t *entry, bool_t compat) return *entry & 0xf; } -int kimage_build_ind(struct kexec_image *image, unsigned long ind_mfn, +int kimage_build_ind(struct kexec_image *image, mfn_t ind_mfn, bool_t compat) { void *page; @@ -862,7 +868,7 @@ int kimage_build_ind(struct kexec_image *image, unsigned long ind_mfn, int ret = 0; paddr_t dest = KIMAGE_NO_DEST; - page = map_domain_page(_mfn(ind_mfn)); + page = map_domain_page(ind_mfn); if ( !page ) return -ENOMEM; @@ -873,7 +879,7 @@ int kimage_build_ind(struct kexec_image *image, unsigned long ind_mfn, for ( entry = page; ; ) { unsigned long ind; - unsigned long mfn; + mfn_t mfn; ind = kimage_entry_ind(entry, compat); mfn = kimage_entry_mfn(entry, compat); @@ -881,14 +887,14 @@ int kimage_build_ind(struct kexec_image *image, unsigned long ind_mfn, switch ( ind ) { case IND_DESTINATION: - dest = (paddr_t)mfn << PAGE_SHIFT; + dest = mfn_to_maddr(mfn); ret = kimage_set_destination(image, dest); if ( ret < 0 ) goto done; break; case IND_INDIRECTION: unmap_domain_page(page); - page = map_domain_page(_mfn(mfn)); + page = map_domain_page(mfn); entry = page; continue; case IND_DONE: @@ -913,7 +919,7 @@ int kimage_build_ind(struct kexec_image *image, unsigned long ind_mfn, goto done; } - copy_domain_page(_mfn(page_to_mfn(xen_page)), _mfn(mfn)); + copy_domain_page(page_to_mfn(xen_page), mfn); put_page(guest_page); ret = kimage_add_page(image, page_to_maddr(xen_page)); diff --git a/xen/include/xen/kimage.h b/xen/include/xen/kimage.h index d10ebf7844..cbfb9e9054 100644 --- a/xen/include/xen/kimage.h +++ b/xen/include/xen/kimage.h @@ -48,9 +48,9 @@ struct page_info *kimage_alloc_control_page(struct kexec_image *image, unsigned memflags); kimage_entry_t *kimage_entry_next(kimage_entry_t *entry, bool_t compat); -unsigned long kimage_entry_mfn(kimage_entry_t *entry, bool_t compat); +mfn_t kimage_entry_mfn(kimage_entry_t *entry, bool_t compat); unsigned long kimage_entry_ind(kimage_entry_t *entry, bool_t compat); -int kimage_build_ind(struct kexec_image *image, unsigned long ind_mfn, +int kimage_build_ind(struct kexec_image *image, mfn_t ind_mfn, bool_t compat); #endif /* __ASSEMBLY__ */