Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752124AbdLXJ3h (ORCPT ); Sun, 24 Dec 2017 04:29:37 -0500 Received: from mail-by2nam01on0072.outbound.protection.outlook.com ([104.47.34.72]:60160 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751182AbdLXJ30 (ORCPT ); Sun, 24 Dec 2017 04:29:26 -0500 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Christian.Koenig@amd.com; Subject: Re: [PATCH v3] xen/balloon: Mark unallocated host memory as UNUSABLE To: Boris Ostrovsky , xen-devel@lists.xen.org, linux-kernel@vger.kernel.org Cc: jgross@suse.com, helgaas@kernel.org, JBeulich@suse.com References: <1513778746-6155-1-git-send-email-boris.ostrovsky@oracle.com> From: =?UTF-8?Q?Christian_K=c3=b6nig?= Message-ID: Date: Sun, 24 Dec 2017 10:29:12 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: <1513778746-6155-1-git-send-email-boris.ostrovsky@oracle.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Originating-IP: [2a02:908:1251:7981:c594:f15e:ebef:c917] X-ClientProxiedBy: DB6PR0402CA0010.eurprd04.prod.outlook.com (10.172.243.148) To CY4PR12MB1301.namprd12.prod.outlook.com (10.168.168.138) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d9e6c347-2df4-4f11-589d-08d54ab0d248 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(5600026)(4604075)(48565401081)(2017052603307)(7153060);SRVR:CY4PR12MB1301; X-Microsoft-Exchange-Diagnostics: 1;CY4PR12MB1301;3:mMFNKZIGFQlr1s7m4TF3ET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1hahEVY3jJ6nskYlNMeOj2/za+Lts1rL0SiPWacuOUhuVgYd6iKMNsKOxAENuVb2GBoveRWzv7LdoBhgdoXULBGiT5OQ1KMUI6Wi9EM0Co8K0SqVmgadnH0GlZBj5ITbnmiATNKZZnO9XTYCSbk6NEwnvPmJopZkUgxeidLWh4i2Y3hVmOx9lKn4kgm++vID2UMkPWHRGALEMgtfTZYQzIyZL9eN7pvq1k1bZR784cVE8BcEvQtlSvlHbLCtpNgEWxeAxPTXKDDz/eJqJVGXKAN9aOamVO7v9BS616h0fpYEMgb6AkaViGV348WhQ;4:aEkJEEX60AGQIo4R1xTfsHHKif2Uqt/atctJ2EU2732y/wIyI3KahMlob0qNpYopYFR+MT71IqPSNW1VO7BBjlwHpE5YMSomdXvF3UGwr2UA+VJHOrcR/W9Mh9TMAKmIofGWoD+6oBBZKb705CRYjycvjNkhCr+qiOy2Ege2Viqm+FAwkPltXyKeo1gX1WFL0N94UxR93G+3rbd0nGaIKtq6JaswENgqUThbPnK0+ol5dPGvOUCyQ2GEUdr2pm/HKofKok36oYEFu0jKxv0lX7A8OoU+0XkiulVZGZz4AISIso2Ycpo9iX8r008xAYLboeyCexrEGSrcz0mSZULlxt7pnuGDqMDxkTEBRFA8PwvnLV2wG+WWjsHvEcpouHQb X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110)(788757137089)(146099531331640); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040470)(2401047)(8121501046)(5005006)(3002001)(10201501046)(93006095)(93001095)(3231023)(944501072)(6055026)(6041268)(20161123562045)(20161123560045)(20161123558120)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:CY4PR12MB1301;BCL:0;PCL:0;RULEID:(100000803101)(100110400095);SRVR:CY4PR12MB1301; X-Forefront-PRVS: 05315CBE52 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(366004)(39860400002)(376002)(396003)(346002)(39380400002)(199004)(189003)(105586002)(8936002)(65806001)(106356001)(97736004)(65956001)(36756003)(68736007)(2950100002)(2870700001)(52116002)(83506002)(25786009)(81156014)(2486003)(64126003)(52396003)(52146003)(5660300001)(81166006)(8676002)(23676004)(76176011)(6666003)(67846002)(58126008)(65826007)(47776003)(305945005)(2906002)(316002)(6486002)(229853002)(59450400001)(31696002)(6116002)(4326008)(575784001)(86362001)(386003)(50466002)(31686004)(1706002)(478600001)(7736002)(6246003)(72206003)(53936002);DIR:OUT;SFP:1101;SCL:1;SRVR:CY4PR12MB1301;H:[IPv6:2a02:908:1251:7981:c594:f15e:ebef:c917];FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtDWTRQUjEyTUIxMzAxOzIzOm9NdTRxaFVwc3Z4UkRhWnNUYjVVc2lwcjRZ?= =?utf-8?B?cUxSZ0FFaCsyM3BQLzlKZzc3RUt2T09Memw0dHBFclVFTFB0dGlvQnI4Uzhv?= =?utf-8?B?VXdsTmNhckhSSDlXc0hEaGU0dXY4a2VvNXFYKytZOFFQd3IzOG1QSzQyYWF4?= =?utf-8?B?RTZoUnZESndVVFNHZkJPSEhleEdBZXIrYWwwL0c0cXJHUzRNWEFPZE9WK1A3?= =?utf-8?B?ai9uWmgvenpta29GYW1VaWdmcWx2NHMwZC9XWDhOTXRKRThsdFF4b0JGb2pC?= =?utf-8?B?eUdpTWVXUXRTZTlNL1BJam5GbG96UlFDMGJuU2pCdUJ4UlFZQ1BtUmYwNzhI?= =?utf-8?B?QSt5SWFZQXVnMUY1VkdUMGpVc0tVNVBBTVIyZmpqOHBJaUNSY0puQVYrYmI4?= =?utf-8?B?Wjdyck9sYzBYVFVVR3RlRVU2L3VLaTVBZHpwMk9HQWk0VG1aYWhnU0I5ZGJm?= =?utf-8?B?WkdtbHd0S1B4SGpiejJSbnptcUJCUHpzTWVwRFFweVBSci9WdUZkeE1nVWN0?= =?utf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oxH8FuoqXfyQa36EJk9/0jcWCVHi/KP/tZ0dymRkhR0vVEi2FM=;7:iSotjfH7RaxNyajw+j3hpgcnwm8OFTjmgQZ9GAG/H7aFxGjfuV4/9yhjczh+w2L+tOJBRyro/IIGECtznXtwye840SwRn1FGR4TKUe8zlfDgvYU1GHIQROBt0G1ucMbiuu9s337cbVoUHzG/Vrz87J82ep26p/DC7iPhPNXmQBx7TDdibsc4q1GGmx6me1s5BqXcj9H2pt04tAz7CgvkVKk+1rE8P/tzDw6+GuxiayuMLGiT7Toudjj28dfRoYr4 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;CY4PR12MB1301;20:S9CgTs5/jpt1vQ9urZAy6TZxM4TCgGlQqpaOBXrzG0G7T8ahArUq835yYj0qXeXFqMflbeV+vS1ZYAimRiWHT1sNlqR5mmPuPHov9zk0BDB7zl6QBIv5II8EDKewdh5+H5Zw2m7AIsfn1VdM4/gQtjW71MBERVOcNcvh1U2P8jt+nxrDqb7i2XXQgkeFwcvWhOQ8o38fXh0GuwnBDwDv9rZTGYLlJJTwGUPULYzCD6J5R0cd8GKzALErm2wVcwcC X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Dec 2017 09:29:23.2793 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d9e6c347-2df4-4f11-589d-08d54ab0d248 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1301 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 8718 Lines: 270 Am 20.12.2017 um 15:05 schrieb Boris Ostrovsky: > Commit f5775e0b6116 ("x86/xen: discard RAM regions above the maximum > reservation") left host memory not assigned to dom0 as available for > memory hotplug. > > Unfortunately this also meant that those regions could be used by > others. Specifically, commit fa564ad96366 ("x86/PCI: Enable a 64bit BAR > on AMD Family 15h (Models 00-1f, 30-3f, 60-7f)") may try to map those > addresses as MMIO. > > To prevent this mark unallocated host memory as E820_TYPE_UNUSABLE (thus > effectively reverting f5775e0b6116) and keep track of that region as > a hostmem resource that can be used for the hotplug. > > Signed-off-by: Boris Ostrovsky Acked-by: Christian König > --- > Changes in v3: > * Use PFN_PHYS > * Replace kzalloc with kmalloc > * Declare arch_xen_balloon_init prototype in balloon.h > * Rename resources (s/memory/RAM/) > * Clarify (I think) comment when populating hostmem_resource > * Print open-ended interval on insert_resource() error > * Constify declaration of struct e820_entry *entry > > arch/x86/xen/enlighten.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++ > arch/x86/xen/setup.c | 6 ++-- > drivers/xen/balloon.c | 65 ++++++++++++++++++++++++++++++++------ > include/xen/balloon.h | 5 +++ > 4 files changed, 144 insertions(+), 13 deletions(-) > > diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c > index d669e9d..c9081c6 100644 > --- a/arch/x86/xen/enlighten.c > +++ b/arch/x86/xen/enlighten.c > @@ -1,8 +1,12 @@ > +#ifdef CONFIG_XEN_BALLOON_MEMORY_HOTPLUG > +#include > +#endif > #include > #include > > #include > #include > +#include > > #include > #include > @@ -331,3 +335,80 @@ void xen_arch_unregister_cpu(int num) > } > EXPORT_SYMBOL(xen_arch_unregister_cpu); > #endif > + > +#ifdef CONFIG_XEN_BALLOON_MEMORY_HOTPLUG > +void __init arch_xen_balloon_init(struct resource *hostmem_resource) > +{ > + struct xen_memory_map memmap; > + int rc; > + unsigned int i, last_guest_ram; > + phys_addr_t max_addr = PFN_PHYS(max_pfn); > + struct e820_table *xen_e820_table; > + const struct e820_entry *entry; > + struct resource *res; > + > + if (!xen_initial_domain()) > + return; > + > + xen_e820_table = kmalloc(sizeof(*xen_e820_table), GFP_KERNEL); > + if (!xen_e820_table) > + return; > + > + memmap.nr_entries = ARRAY_SIZE(xen_e820_table->entries); > + set_xen_guest_handle(memmap.buffer, xen_e820_table->entries); > + rc = HYPERVISOR_memory_op(XENMEM_machine_memory_map, &memmap); > + if (rc) { > + pr_warn("%s: Can't read host e820 (%d)\n", __func__, rc); > + goto out; > + } > + > + last_guest_ram = 0; > + for (i = 0; i < memmap.nr_entries; i++) { > + if (xen_e820_table->entries[i].addr >= max_addr) > + break; > + if (xen_e820_table->entries[i].type == E820_TYPE_RAM) > + last_guest_ram = i; > + } > + > + entry = &xen_e820_table->entries[last_guest_ram]; > + if (max_addr >= entry->addr + entry->size) > + goto out; /* No unallocated host RAM. */ > + > + hostmem_resource->start = max_addr; > + hostmem_resource->end = entry->addr + entry->size; > + > + /* > + * Mark non-RAM regions between the end of dom0 RAM and end of host RAM > + * as unavailable. The rest of that region can be used for hotplug-based > + * ballooning. > + */ > + for (; i < memmap.nr_entries; i++) { > + entry = &xen_e820_table->entries[i]; > + > + if (entry->type == E820_TYPE_RAM) > + continue; > + > + if (entry->addr >= hostmem_resource->end) > + break; > + > + res = kzalloc(sizeof(*res), GFP_KERNEL); > + if (!res) > + goto out; > + > + res->name = "Unavailable host RAM"; > + res->start = entry->addr; > + res->end = (entry->addr + entry->size < hostmem_resource->end) ? > + entry->addr + entry->size : hostmem_resource->end; > + rc = insert_resource(hostmem_resource, res); > + if (rc) { > + pr_warn("%s: Can't insert [%llx - %llx) (%d)\n", > + __func__, res->start, res->end, rc); > + kfree(res); > + goto out; > + } > + } > + > + out: > + kfree(xen_e820_table); > +} > +#endif /* CONFIG_XEN_BALLOON_MEMORY_HOTPLUG */ > diff --git a/arch/x86/xen/setup.c b/arch/x86/xen/setup.c > index c114ca7..6e0d208 100644 > --- a/arch/x86/xen/setup.c > +++ b/arch/x86/xen/setup.c > @@ -808,7 +808,6 @@ char * __init xen_memory_setup(void) > addr = xen_e820_table.entries[0].addr; > size = xen_e820_table.entries[0].size; > while (i < xen_e820_table.nr_entries) { > - bool discard = false; > > chunk_size = size; > type = xen_e820_table.entries[i].type; > @@ -824,11 +823,10 @@ char * __init xen_memory_setup(void) > xen_add_extra_mem(pfn_s, n_pfns); > xen_max_p2m_pfn = pfn_s + n_pfns; > } else > - discard = true; > + type = E820_TYPE_UNUSABLE; > } > > - if (!discard) > - xen_align_and_add_e820_region(addr, chunk_size, type); > + xen_align_and_add_e820_region(addr, chunk_size, type); > > addr += chunk_size; > size -= chunk_size; > diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c > index f77e499..065f0b6 100644 > --- a/drivers/xen/balloon.c > +++ b/drivers/xen/balloon.c > @@ -257,10 +257,25 @@ static void release_memory_resource(struct resource *resource) > kfree(resource); > } > > +/* > + * Host memory not allocated to dom0. We can use this range for hotplug-based > + * ballooning. > + * > + * It's a type-less resource. Setting IORESOURCE_MEM will make resource > + * management algorithms (arch_remove_reservations()) look into guest e820, > + * which we don't want. > + */ > +static struct resource hostmem_resource = { > + .name = "Host RAM", > +}; > + > +void __attribute__((weak)) __init arch_xen_balloon_init(struct resource *res) > +{} > + > static struct resource *additional_memory_resource(phys_addr_t size) > { > - struct resource *res; > - int ret; > + struct resource *res, *res_hostmem; > + int ret = -ENOMEM; > > res = kzalloc(sizeof(*res), GFP_KERNEL); > if (!res) > @@ -269,13 +284,42 @@ static struct resource *additional_memory_resource(phys_addr_t size) > res->name = "System RAM"; > res->flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY; > > - ret = allocate_resource(&iomem_resource, res, > - size, 0, -1, > - PAGES_PER_SECTION * PAGE_SIZE, NULL, NULL); > - if (ret < 0) { > - pr_err("Cannot allocate new System RAM resource\n"); > - kfree(res); > - return NULL; > + res_hostmem = kzalloc(sizeof(*res), GFP_KERNEL); > + if (res_hostmem) { > + /* Try to grab a range from hostmem */ > + res_hostmem->name = "Host memory"; > + ret = allocate_resource(&hostmem_resource, res_hostmem, > + size, 0, -1, > + PAGES_PER_SECTION * PAGE_SIZE, NULL, NULL); > + } > + > + if (!ret) { > + /* > + * Insert this resource into iomem. Because hostmem_resource > + * tracks portion of guest e820 marked as UNUSABLE noone else > + * should try to use it. > + */ > + res->start = res_hostmem->start; > + res->end = res_hostmem->end; > + ret = insert_resource(&iomem_resource, res); > + if (ret < 0) { > + pr_err("Can't insert iomem_resource [%llx - %llx]\n", > + res->start, res->end); > + release_memory_resource(res_hostmem); > + res_hostmem = NULL; > + res->start = res->end = 0; > + } > + } > + > + if (ret) { > + ret = allocate_resource(&iomem_resource, res, > + size, 0, -1, > + PAGES_PER_SECTION * PAGE_SIZE, NULL, NULL); > + if (ret < 0) { > + pr_err("Cannot allocate new System RAM resource\n"); > + kfree(res); > + return NULL; > + } > } > > #ifdef CONFIG_SPARSEMEM > @@ -287,6 +331,7 @@ static struct resource *additional_memory_resource(phys_addr_t size) > pr_err("New System RAM resource outside addressable RAM (%lu > %lu)\n", > pfn, limit); > release_memory_resource(res); > + release_memory_resource(res_hostmem); > return NULL; > } > } > @@ -765,6 +810,8 @@ static int __init balloon_init(void) > set_online_page_callback(&xen_online_page); > register_memory_notifier(&xen_memory_nb); > register_sysctl_table(xen_root); > + > + arch_xen_balloon_init(&hostmem_resource); > #endif > > #ifdef CONFIG_XEN_PV > diff --git a/include/xen/balloon.h b/include/xen/balloon.h > index 4914b93..61f410f 100644 > --- a/include/xen/balloon.h > +++ b/include/xen/balloon.h > @@ -44,3 +44,8 @@ static inline void xen_balloon_init(void) > { > } > #endif > + > +#ifdef CONFIG_XEN_BALLOON_MEMORY_HOTPLUG > +struct resource; > +void arch_xen_balloon_init(struct resource *hostmem_resource); > +#endif