From patchwork Mon Jul 18 13:19:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 9234575 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id EEE9160756 for ; Mon, 18 Jul 2016 13:19:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E0C5326AE3 for ; Mon, 18 Jul 2016 13:19:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D5C9C26B4A; Mon, 18 Jul 2016 13:19:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3BE5826AE3 for ; Mon, 18 Jul 2016 13:19:43 +0000 (UTC) Received: from localhost ([::1]:46771 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bP8SU-0000qB-W1 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 18 Jul 2016 09:19:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54743) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bP8S1-0000nC-PL for qemu-devel@nongnu.org; Mon, 18 Jul 2016 09:19:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bP8Ru-0004BU-MA for qemu-devel@nongnu.org; Mon, 18 Jul 2016 09:19:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49836) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bP8Ru-0004BP-DZ; Mon, 18 Jul 2016 09:19:06 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F13CD64062; Mon, 18 Jul 2016 13:19:05 +0000 (UTC) Received: from thh440s.str.redhat.com. (dhcp-192-219.str.redhat.com [10.33.192.219]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u6IDJ4ln012853; Mon, 18 Jul 2016 09:19:05 -0400 From: Thomas Huth To: qemu-ppc@nongnu.org, david@gibson.dropbear.id.au Date: Mon, 18 Jul 2016 15:19:04 +0200 Message-Id: <1468847944-24533-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 18 Jul 2016 13:19:06 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] ppc: Huge page detection mechanism fixes - Episode III X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org, Greg Kurz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP After already fixing two issues with the huge page detection mechanism (see commit 159d2e39a860 and 86b50f2e1bef), Greg Kurz noticed another case that caused the guest to crash where QEMU announces huge pages though they should not be available for the guest: qemu-system-ppc64 -enable-kvm ... -mem-path /dev/hugepages \ -m 1G,slots=4,maxmem=32G -object memory-backend-ram,policy=default,size=1G,id=mem-mem1 \ -device pc-dimm,id=dimm-mem1,memdev=mem-mem1 -smp 2 \ -numa node,nodeid=0 -numa node,nodeid=1 That means if there is a global mem-path option, we still have to look at the memory-backend objects that have been specified additionally and return their minimum page size if that value is smaller than the page size of the main memory. Reported-by: Greg Kurz Signed-off-by: Thomas Huth Reviewed-by: Greg Kurz Tested-by: Greg Kurz --- target-ppc/kvm.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c index 7a8f555..97ab450 100644 --- a/target-ppc/kvm.c +++ b/target-ppc/kvm.c @@ -366,10 +366,13 @@ static int find_max_supported_pagesize(Object *obj, void *opaque) static long getrampagesize(void) { long hpsize = LONG_MAX; + long mainrampagesize; Object *memdev_root; if (mem_path) { - return gethugepagesize(mem_path); + mainrampagesize = gethugepagesize(mem_path); + } else { + mainrampagesize = getpagesize(); } /* it's possible we have memory-backend objects with @@ -383,28 +386,26 @@ static long getrampagesize(void) * backend isn't backed by hugepages. */ memdev_root = object_resolve_path("/objects", NULL); - if (!memdev_root) { - return getpagesize(); + if (memdev_root) { + object_child_foreach(memdev_root, find_max_supported_pagesize, &hpsize); } - - object_child_foreach(memdev_root, find_max_supported_pagesize, &hpsize); - - if (hpsize == LONG_MAX || hpsize == getpagesize()) { - return getpagesize(); + if (hpsize == LONG_MAX) { + /* No additional memory regions found ==> Report main RAM page size */ + return mainrampagesize; } /* If NUMA is disabled or the NUMA nodes are not backed with a - * memory-backend, then there is at least one node using "normal" - * RAM. And since normal RAM has not been configured with "-mem-path" - * (what we've checked earlier here already), we can not use huge pages! + * memory-backend, then there is at least one node using "normal" RAM, + * so if its page size is smaller we have got to report that size instead. */ - if (nb_numa_nodes == 0 || numa_info[0].node_memdev == NULL) { + if (hpsize > mainrampagesize && + (nb_numa_nodes == 0 || numa_info[0].node_memdev == NULL)) { static bool warned; if (!warned) { error_report("Huge page support disabled (n/a for main memory)."); warned = true; } - return getpagesize(); + return mainrampagesize; } return hpsize;