Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1975273pxb; Fri, 5 Mar 2021 04:33:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJy36PYOiuDKxmbu1txEAcUpExFH4YuXku+0BqiA3SbGesiRy8Wp6/ElntYisM+J2XBK0se9 X-Received: by 2002:aa7:d642:: with SMTP id v2mr8991962edr.257.1614947624573; Fri, 05 Mar 2021 04:33:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614947624; cv=none; d=google.com; s=arc-20160816; b=uWLLWK/5Zn0H9agIQKJW+w2RsFkmtWPGueae9qjmlGvcGZasLw9EIo5F+DJR4UJErS 5WqGd2LmT1Bp5wukw3EsR8+OWhnKfnlOWh7g4PHpmFrqc3ZsAJjQUkjLLAvWRbSeWptg AY9lrK/Ub7z+NvZvEDyMaIk+wm41BmZpJlreca5vWw4nJCHxGRuctzHTU5tcw2OmomW9 DDdxk41KdmwBS6HvJwjv/ibSDF07lsYIKXMyUjVYMDXUKicn9Evlk6ICFspYZHWz2SpT JxF7ibf7D6ay1YZY0TZSAvUcEgUcsWH9KXsJ3X59B82WdDqSFfugOumE0DZt52npVjUd mV2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=DkkR4mdfmvpVKelDl64Z5TGaxyIpYzJHCDnnuEfXPfI=; b=CWuzKY+7nFqMWuq5UoZRFPiCR/y4hpyq7TzFT65cL1nFxY7V811iC/RK32FXPd3chE d1oQg6DQ6DIC1gMil9FueQzgB/BPyFO4kSfZtjb+COW7b5Ad2mwV5Z/wXf1Kntw2LYQ4 6mUButXnDTIZ6W0oah1GbqvNATzS2Oku48fSOF/s9XyLBZ27Kmtmv9ByXwEMtkHmriN0 TJBS5IgEEgf4HRthR3SYLQspTfDT+Lw6Sm0CiN9ESEe5KqvQIGub3E0bfTmKas/7Sm44 ZhqQ4zJw3KrA3yfd4xVyfiRRlQihfPoZzimfgmnw7Si9NSMH6Dxk606XiLwsTdwDf2fC wLMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=FNufSG4y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cm2si1376320edb.549.2021.03.05.04.33.21; Fri, 05 Mar 2021 04:33:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=FNufSG4y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231812AbhCEMcf (ORCPT + 99 others); Fri, 5 Mar 2021 07:32:35 -0500 Received: from mail.kernel.org ([198.145.29.99]:42162 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232404AbhCEMbq (ORCPT ); Fri, 5 Mar 2021 07:31:46 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6440465013; Fri, 5 Mar 2021 12:31:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614947506; bh=G80eKNMqk+J+q5wvs2LWGwmOXh5IjT2rjcuv5l+YbQY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FNufSG4yZhsFXfTPYZo8dx1jGD6Gj3pNHUIenlXNDqnHjZMkAw09nuRYYkrZhYU5o rTyBghuK0XGh2Uo0CwlFiZpoK0lhIb3jgPreQvOnvHy2Ag+8nzZwG1DrzyBv1IIfR4 9X74wg7MGf0AdF3wl5txc9oY7owz9XHEy3Ljut18= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= , Juergen Gross , Jan Beulich Subject: [PATCH 5.10 088/102] xen: fix p2m size in dom0 for disabled memory hotplug case Date: Fri, 5 Mar 2021 13:21:47 +0100 Message-Id: <20210305120907.615438324@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210305120903.276489876@linuxfoundation.org> References: <20210305120903.276489876@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Juergen Gross commit 882213990d32fd224340a4533f6318dd152be4b2 upstream. Since commit 9e2369c06c8a18 ("xen: add helpers to allocate unpopulated memory") foreign mappings are using guest physical addresses allocated via ZONE_DEVICE functionality. This will result in problems for the case of no balloon memory hotplug being configured, as the p2m list will only cover the initial memory size of the domain. Any ZONE_DEVICE allocated address will be outside the p2m range and thus a mapping can't be established with that memory address. Fix that by extending the p2m size for that case. At the same time add a check for a to be created mapping to be within the p2m limits in order to detect errors early. While changing a comment, remove some 32-bit leftovers. This is XSA-369. Fixes: 9e2369c06c8a18 ("xen: add helpers to allocate unpopulated memory") Cc: # 5.9 Reported-by: Marek Marczykowski-Górecki Signed-off-by: Juergen Gross Reviewed-by: Jan Beulich Signed-off-by: Juergen Gross Signed-off-by: Greg Kroah-Hartman --- arch/x86/include/asm/xen/page.h | 12 ++++++++++++ arch/x86/xen/p2m.c | 10 ++++++---- arch/x86/xen/setup.c | 25 +++---------------------- 3 files changed, 21 insertions(+), 26 deletions(-) --- a/arch/x86/include/asm/xen/page.h +++ b/arch/x86/include/asm/xen/page.h @@ -87,6 +87,18 @@ clear_foreign_p2m_mapping(struct gnttab_ #endif /* + * The maximum amount of extra memory compared to the base size. The + * main scaling factor is the size of struct page. At extreme ratios + * of base:extra, all the base memory can be filled with page + * structures for the extra memory, leaving no space for anything + * else. + * + * 10x seems like a reasonable balance between scaling flexibility and + * leaving a practically usable system. + */ +#define XEN_EXTRA_MEM_RATIO (10) + +/* * Helper functions to write or read unsigned long values to/from * memory, when the access may fault. */ --- a/arch/x86/xen/p2m.c +++ b/arch/x86/xen/p2m.c @@ -416,6 +416,9 @@ void __init xen_vmalloc_p2m_tree(void) xen_p2m_last_pfn = xen_max_p2m_pfn; p2m_limit = (phys_addr_t)P2M_LIMIT * 1024 * 1024 * 1024 / PAGE_SIZE; + if (!p2m_limit && IS_ENABLED(CONFIG_XEN_UNPOPULATED_ALLOC)) + p2m_limit = xen_start_info->nr_pages * XEN_EXTRA_MEM_RATIO; + vm.flags = VM_ALLOC; vm.size = ALIGN(sizeof(unsigned long) * max(xen_max_p2m_pfn, p2m_limit), PMD_SIZE * PMDS_PER_MID_PAGE); @@ -652,10 +655,9 @@ bool __set_phys_to_machine(unsigned long pte_t *ptep; unsigned int level; - if (unlikely(pfn >= xen_p2m_size)) { - BUG_ON(mfn != INVALID_P2M_ENTRY); - return true; - } + /* Only invalid entries allowed above the highest p2m covered frame. */ + if (unlikely(pfn >= xen_p2m_size)) + return mfn == INVALID_P2M_ENTRY; /* * The interface requires atomic updates on p2m elements. --- a/arch/x86/xen/setup.c +++ b/arch/x86/xen/setup.c @@ -59,18 +59,6 @@ static struct { } xen_remap_buf __initdata __aligned(PAGE_SIZE); static unsigned long xen_remap_mfn __initdata = INVALID_P2M_ENTRY; -/* - * The maximum amount of extra memory compared to the base size. The - * main scaling factor is the size of struct page. At extreme ratios - * of base:extra, all the base memory can be filled with page - * structures for the extra memory, leaving no space for anything - * else. - * - * 10x seems like a reasonable balance between scaling flexibility and - * leaving a practically usable system. - */ -#define EXTRA_MEM_RATIO (10) - static bool xen_512gb_limit __initdata = IS_ENABLED(CONFIG_XEN_512GB); static void __init xen_parse_512gb(void) @@ -790,20 +778,13 @@ char * __init xen_memory_setup(void) extra_pages += max_pages - max_pfn; /* - * Clamp the amount of extra memory to a EXTRA_MEM_RATIO - * factor the base size. On non-highmem systems, the base - * size is the full initial memory allocation; on highmem it - * is limited to the max size of lowmem, so that it doesn't - * get completely filled. + * Clamp the amount of extra memory to a XEN_EXTRA_MEM_RATIO + * factor the base size. * * Make sure we have no memory above max_pages, as this area * isn't handled by the p2m management. - * - * In principle there could be a problem in lowmem systems if - * the initial memory is also very large with respect to - * lowmem, but we won't try to deal with that here. */ - extra_pages = min3(EXTRA_MEM_RATIO * min(max_pfn, PFN_DOWN(MAXMEM)), + extra_pages = min3(XEN_EXTRA_MEM_RATIO * min(max_pfn, PFN_DOWN(MAXMEM)), extra_pages, max_pages - max_pfn); i = 0; addr = xen_e820_table.entries[0].addr;