From patchwork Thu Mar 24 14:44:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 64375 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp697294lbc; Thu, 24 Mar 2016 07:48:04 -0700 (PDT) X-Received: by 10.140.216.212 with SMTP id m203mr11708321qhb.37.1458830866371; Thu, 24 Mar 2016 07:47:46 -0700 (PDT) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id f11si6816857qgf.11.2016.03.24.07.47.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 Mar 2016 07:47:46 -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; 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 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1aj6Wy-0002ss-Df; Thu, 24 Mar 2016 14:46:36 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1aj6Ww-0002sS-SZ for xen-devel@lists.xen.org; Thu, 24 Mar 2016 14:46:34 +0000 Received: from [193.109.254.147] by server-1.bemta-14.messagelabs.com id BC/FE-30565-ACDF3F65; Thu, 24 Mar 2016 14:46:34 +0000 X-Env-Sender: shannon.zhao@linaro.org X-Msg-Ref: server-12.tower-27.messagelabs.com!1458830791!33564805!1 X-Originating-IP: [209.85.220.49] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.11; banners=-,-,- X-VirusChecked: Checked Received: (qmail 44262 invoked from network); 24 Mar 2016 14:46:33 -0000 Received: from mail-pa0-f49.google.com (HELO mail-pa0-f49.google.com) (209.85.220.49) by server-12.tower-27.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 24 Mar 2016 14:46:33 -0000 Received: by mail-pa0-f49.google.com with SMTP id tt10so23977929pab.3 for ; Thu, 24 Mar 2016 07:46:32 -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=jd+tO6TZERp6CTxm802KCOIn/rKY/M7IhCQ8NBZkt28=; b=A7atIB3+VByazao0TgJJ3Mxm7AKDGfAjnzNYS8oPli26kf1EldOA9YEBosS0N3rz/s Jg3XlwMogWu31rWkxqm6GAZ/j+8brXFpqP9PUHJc4vlW9YfZ7NoVqmRIP7/oKIn861c6 PsI4/F9T5DaSTe6KOEOeOTd6mXDIid+xUFtCs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=jd+tO6TZERp6CTxm802KCOIn/rKY/M7IhCQ8NBZkt28=; b=YU7+woHO8Rjmxp7VjYsfI5/YNV/a1d0AwT+Wp/NfB71p6u+8Syah4TPY32UQ8bd1R0 qzOcgJqAjtKKoRENvFRGQjlLAr8DXtJ0Vn0P4T8Qv9FLvo6VAnMcqijNXeBbTzsd1O06 ZEY/1q8lNZ05sTqlJXZ+MIqH1rGmRDQOdVu5AV95yOh2tliY40xLa/D4GiIhR2BU/VEB E4h5oL1SwQAL/SX9oJQtse6tKLeQ3KbdHRqAvvMBib4pp51X3RsR7apan3EP6gilCrh1 oyylqd+zls9E+1a0cVrwy6D7VuJFubBBuI0r9y+8CKivJ0C797c0Dw8gqHT+ZXeW31Fj aMnw== X-Gm-Message-State: AD7BkJKUhgNDjlLs/mPrxukJoLX8yfpFKeZFjc5+h9PL3wKMAjaW5QrrvVBySIrnLmBReICA X-Received: by 10.66.225.177 with SMTP id rl17mr13441368pac.46.1458830791148; Thu, 24 Mar 2016 07:46:31 -0700 (PDT) Received: from localhost.localdomain ([104.238.45.135]) by smtp.gmail.com with ESMTPSA id lq10sm10780673pab.36.2016.03.24.07.46.24 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 24 Mar 2016 07:46:30 -0700 (PDT) From: Shannon Zhao To: linux-arm-kernel@lists.infradead.org, stefano.stabellini@citrix.com, david.vrabel@citrix.com Date: Thu, 24 Mar 2016 22:44:22 +0800 Message-Id: <1458830676-27075-4-git-send-email-shannon.zhao@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1458830676-27075-1-git-send-email-shannon.zhao@linaro.org> References: <1458830676-27075-1-git-send-email-shannon.zhao@linaro.org> Cc: devicetree@vger.kernel.org, linux-efi@vger.kernel.org, catalin.marinas@arm.com, will.deacon@arm.com, linux-kernel@vger.kernel.org, peter.huangpeng@huawei.com, julien.grall@arm.com, shannon.zhao@linaro.org, zhaoshenglong@huawei.com, xen-devel@lists.xen.org Subject: [Xen-devel] [PATCH v7 03/17] Xen: xlate: Use page_to_xen_pfn instead of page_to_pfn 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" Make xen_xlate_map_ballooned_pages work with 64K pages. In that case Kernel pages are 64K in size but Xen pages remain 4K in size. Xen pfns refer to 4K pages. Signed-off-by: Shannon Zhao Reviewed-by: Stefano Stabellini --- drivers/xen/xlate_mmu.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/drivers/xen/xlate_mmu.c b/drivers/xen/xlate_mmu.c index 9692656..28f728b 100644 --- a/drivers/xen/xlate_mmu.c +++ b/drivers/xen/xlate_mmu.c @@ -207,9 +207,12 @@ int __init xen_xlate_map_ballooned_pages(xen_pfn_t **gfns, void **virt, void *vaddr; int rc; unsigned int i; + unsigned long nr_pages; + xen_pfn_t xen_pfn = 0; BUG_ON(nr_grant_frames == 0); - pages = kcalloc(nr_grant_frames, sizeof(pages[0]), GFP_KERNEL); + nr_pages = DIV_ROUND_UP(nr_grant_frames, XEN_PFN_PER_PAGE); + pages = kcalloc(nr_pages, sizeof(pages[0]), GFP_KERNEL); if (!pages) return -ENOMEM; @@ -218,22 +221,25 @@ int __init xen_xlate_map_ballooned_pages(xen_pfn_t **gfns, void **virt, kfree(pages); return -ENOMEM; } - rc = alloc_xenballooned_pages(nr_grant_frames, pages); + rc = alloc_xenballooned_pages(nr_pages, pages); if (rc) { - pr_warn("%s Couldn't balloon alloc %ld pfns rc:%d\n", __func__, - nr_grant_frames, rc); + pr_warn("%s Couldn't balloon alloc %ld pages rc:%d\n", __func__, + nr_pages, rc); kfree(pages); kfree(pfns); return rc; } - for (i = 0; i < nr_grant_frames; i++) - pfns[i] = page_to_pfn(pages[i]); + for (i = 0; i < nr_grant_frames; i++) { + if ((i % XEN_PFN_PER_PAGE) == 0) + xen_pfn = page_to_xen_pfn(pages[i / XEN_PFN_PER_PAGE]); + pfns[i] = pfn_to_gfn(xen_pfn++); + } - vaddr = vmap(pages, nr_grant_frames, 0, PAGE_KERNEL); + vaddr = vmap(pages, nr_pages, 0, PAGE_KERNEL); if (!vaddr) { - pr_warn("%s Couldn't map %ld pfns rc:%d\n", __func__, - nr_grant_frames, rc); - free_xenballooned_pages(nr_grant_frames, pages); + pr_warn("%s Couldn't map %ld pages rc:%d\n", __func__, + nr_pages, rc); + free_xenballooned_pages(nr_pages, pages); kfree(pages); kfree(pfns); return -ENOMEM;