From patchwork Fri Aug 9 12:14:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 170911 Delivered-To: patch@linaro.org Received: by 2002:a92:512:0:0:0:0:0 with SMTP id q18csp9921997ile; Fri, 9 Aug 2019 05:16:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqybEWdOLbOham3esA57MkjRaWGxAP9BhCz5GkSzRdAzQ4MyQluuGH2uJKf95lbYaWwSESub X-Received: by 2002:a6b:8e47:: with SMTP id q68mr15745457iod.88.1565352971789; Fri, 09 Aug 2019 05:16:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565352971; cv=none; d=google.com; s=arc-20160816; b=o0PfLhciYyOWa1l5t+eNOuXzraWt2XNxzThqP7qqm3jOqWZPJP8tpWAOtEJKu9AxC8 I5hG2QWhv68Wj5QrbJj2dE1phGq8QuE+goXR1eMpsa6A4KoUHI2Vbx9Yoofq1IWLSvqq DojVuLj2p54nroU+FO+xoZO/MielHD8Y3by2UkjJl8xEMY2eW6yTpkm5TriZZS1TG88D EACQtIv46Vh+OLGVunALlrMOdUukZlM7ZnxMwgNP03s8HXMsLutpjqcNUFHs90vKCwri gQbUChd3tB0Tg0x6oEhRc0Zxxbow+P85RAubvINccR4pDeixKO7Eo4JgFDuCLLRX88c2 +StQ== 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:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:message-id:date:to:from; bh=wwEhmXQFK+pLKQNyoQaF9ajCYmExY1JUn6auXD67hjw=; b=lP/kQ5sE8EAE6Lo/7vNA+Dqb803W6qaw6sILHD8aQwlngNNNz6KBhjbH+rO5zguLuY SZ1zynBsNMIi2l1DMHNyJRIu4OKsjWhsgPJrznF0ljsM/2OHSoKslS6EHiM8oLby32AS woyMihcjR75fUoCOVplBLvjOo+OV6K4xRhEoy9H2BjZiVOb0DpR2bz350UPB49PHhS2V 0oOlTHFIiWiwcHKZvxHz0FLcJjyrZBS/1dZ1tHuH5u9RWe4VOkguVN4CUWUf3O7Egvvq z6iKLjFfSE9i83xhq/affoBiGXJVdacqRPi0AsOl7G3PM4WZjMs5lAoF1WExDtqBU3TY Jyyw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id n26si57546805ioh.135.2019.08.09.05.16.11 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 09 Aug 2019 05:16:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hw3nK-0001iq-QM; Fri, 09 Aug 2019 12:14:54 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hw3nJ-0001ii-Nt for xen-devel@lists.xenproject.org; Fri, 09 Aug 2019 12:14:53 +0000 X-Inumbo-ID: 494a55cc-ba9f-11e9-ad35-7fd1043a7b75 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 494a55cc-ba9f-11e9-ad35-7fd1043a7b75; Fri, 09 Aug 2019 12:14:50 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 006491596; Fri, 9 Aug 2019 05:14:50 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4DA043F706; Fri, 9 Aug 2019 05:14:48 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Fri, 9 Aug 2019 13:14:40 +0100 Message-Id: <20190809121440.5668-1-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 Subject: [Xen-devel] [PATCH] xen/page_alloc: Keep away MFN 0 from the buddy allocator X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Jeff Kubascik , Tim Deegan , Julien Grall , Jan Beulich , Stewart.Hildebrand@dornerworks.com, Jarvis.Roach@dornerworks.com MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Combining of buddies happens only such that the resulting larger buddy is still order-aligned. To cross a zone boundary while merging, the implication is that both the buddy [0, 2^n-1] and the buddy [2^n, 2^(n+1)] are free. Ideally we want to fix the allocator, but for now we can just prevent adding the MFN 0 in the allocator. On x86, the MFN 0 is already kept away from the buddy allocator. So the bug can only happen on Arm platform where the first memory bank is starting at 0. As this is a specific to the allocator, the MFN 0 is removed in the common code to cater all the architectures (current and future). Reported-by: Jeff Kubascik Signed-off-by: Julien Grall Reviewed-by: Jan Beulich Acked-by: Stefano Stabellini Tested-by: Stefano Stabellini Signed-off-by: Jeff Kubascik Tested-by: Stewart Hildebrand --- Cc: Jarvis.Roach@dornerworks.com Cc: Stewart.Hildebrand@dornerworks.com I am not sure I fully understood the exact problem when MFN 0 is given to the allocator. Feel free to suggest a better explanation. Can anyone able to reproduce the bug test where the patch effectively solve the crash? --- xen/common/page_alloc.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 453b303b5b..42b8a8ce23 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -1759,6 +1759,18 @@ static void init_heap_pages( bool idle_scrub = false; /* + * Keep MFN 0 away from the buddy allocator to avoid crossing zone + * boundary when merging two buddies. + */ + if ( !mfn_x(page_to_mfn(pg)) ) + { + if ( nr_pages-- <= 1 ) + return; + pg++; + } + + + /* * Some pages may not go through the boot allocator (e.g reserved * memory at boot but released just after --- kernel, initramfs, * etc.).