From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34075) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WzToi-00015K-SG for qemu-devel@nongnu.org; Tue, 24 Jun 2014 12:43:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WzToY-00046d-D7 for qemu-devel@nongnu.org; Tue, 24 Jun 2014 12:43:32 -0400 Received: from e23smtp07.au.ibm.com ([202.81.31.140]:48833) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WzToX-00043N-KN for qemu-devel@nongnu.org; Tue, 24 Jun 2014 12:43:22 -0400 Received: from /spool/local by e23smtp07.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 25 Jun 2014 02:43:18 +1000 From: Alexey Kardashevskiy Date: Wed, 25 Jun 2014 02:43:09 +1000 Message-Id: <1403628191-5574-5-git-send-email-aik@ozlabs.ru> In-Reply-To: <1403628191-5574-1-git-send-email-aik@ozlabs.ru> References: <1403628191-5574-1-git-send-email-aik@ozlabs.ru> Subject: [Qemu-devel] [PATCH v2 4/6] spapr: Split memory nodes to power-of-two blocks List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Alexey Kardashevskiy , qemu-ppc@nongnu.org, Alexander Graf Linux kernel expects nodes to have power-of-two size and does WARN_ON if this is not the case: [ 0.041456] WARNING: at drivers/base/memory.c:115 which is: === /* Validate blk_sz is a power of 2 and not less than section size */ if ((block_sz & (block_sz - 1)) || (block_sz < MIN_MEMORY_BLOCK_SIZE)) { WARN_ON(1); block_sz = MIN_MEMORY_BLOCK_SIZE; } === This splits memory nodes into set of smaller blocks with a size which is a power of two. This makes sure the start address of every node is aligned to the node size. Signed-off-by: Alexey Kardashevskiy --- Changes: v2: * tiny code cleanup in "sizetmp = MIN(sizetmp, 1 << (ffs(mem_start) - 1))" * updated commit log with a piece of kernel code doing WARN_ON --- hw/ppc/spapr.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 64f48de..0ec1dfc 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -719,8 +719,18 @@ static int spapr_populate_memory(sPAPREnvironment *spapr, void *fdt) mem_start += spapr->rma_size; node_size -= spapr->rma_size; } - spapr_populate_memory_node(fdt, i, mem_start, node_size); - mem_start += node_size; + for ( ; node_size; ) { + hwaddr sizetmp = pow2floor(node_size); + + /* mem_start != 0 here */ + if (ffs(mem_start) < ffs(sizetmp)) { + sizetmp = 1 << (ffs(mem_start) - 1); + } + + spapr_populate_memory_node(fdt, i, mem_start, sizetmp); + node_size -= sizetmp; + mem_start += sizetmp; + } } return 0; -- 2.0.0