From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5CB2EC433E2 for ; Tue, 1 Sep 2020 14:46:16 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0FFD621D6C for ; Tue, 1 Sep 2020 14:46:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="SjGrvG0J" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0FFD621D6C Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 9AF0F6B0002; Tue, 1 Sep 2020 10:46:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 95E896B0037; Tue, 1 Sep 2020 10:46:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 84E396B0055; Tue, 1 Sep 2020 10:46:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0165.hostedemail.com [216.40.44.165]) by kanga.kvack.org (Postfix) with ESMTP id 6AA7E6B0002 for ; Tue, 1 Sep 2020 10:46:15 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 029E3180AD806 for ; Tue, 1 Sep 2020 14:46:15 +0000 (UTC) X-FDA: 77214767910.30.cars55_5e00c4127099 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin30.hostedemail.com (Postfix) with ESMTP id CA92C180B3C8E for ; Tue, 1 Sep 2020 14:45:59 +0000 (UTC) X-HE-Tag: cars55_5e00c4127099 X-Filterd-Recvd-Size: 5547 Received: from esa4.hc3370-68.iphmx.com (esa4.hc3370-68.iphmx.com [216.71.155.144]) by imf40.hostedemail.com (Postfix) with ESMTP for ; Tue, 1 Sep 2020 14:45:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1598971558; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=JdnTGG+FGAeYr/CaqX7nq47kV+5WzzeAxfnDtVerGyo=; b=SjGrvG0JQscbd/d8C4LLh0d3HkfqJXKuqb1Dgo2q/1ov4uuT/vcURoG9 gPWpgEhK7O5EMhVciGH9eD04MAuXi5am8pnmSTM/qb7p53veZ4ZTm6SnE rnY0kPU4l0Ghg5IqmnHoW5VubcyqDIFBvX/O+CumO9+ehjgrd9namMF8F w=; Authentication-Results: esa4.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: Fx1CBO5kj/E1oAMz1SNj/x+W2f0hG4uH49vCOwacHjqiEVjH7W+Z6ZuJZjjum/02jE8xubVska 3sIRr0yzCkV4UFYdAcAEcQc4GhV+gB8w1o75XW1D5ExaZvi5cN6ZLmCer9O+ksnWJQiP2Sgj10 qB4qwe6YKfcng8UZr3n0SOQ5PpIFcJuHhd74YlTayszxMAsS0OrjOzM8z+nks1IfNFppYINasU Ro6lhbOIuB5NwPtFeaSBPdzODMC3WqFYJrILMML41cyYE6RwfKjxRUW9A0yz27uqJzHVG1uKB9 Dt4= X-SBRS: 2.7 X-MesageID: 26701517 X-Ironport-Server: esa4.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.76,379,1592884800"; d="scan'208";a="26701517" Date: Tue, 1 Sep 2020 16:45:39 +0200 From: Roger Pau =?utf-8?B?TW9ubsOp?= To: CC: Oleksandr Andrushchenko , David Airlie , Daniel Vetter , Boris Ostrovsky , Juergen Gross , "Stefano Stabellini" , Dan Carpenter , Wei Liu , Yan Yankovskyi , , , , David Hildenbrand , Michal Hocko , Dan Williams Subject: Re: [PATCH v5 3/3] xen: add helpers to allocate unpopulated memory Message-ID: <20200901144539.GI753@Air-de-Roger> References: <20200901083326.21264-1-roger.pau@citrix.com> <20200901083326.21264-4-roger.pau@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Disposition: inline In-Reply-To: <20200901083326.21264-4-roger.pau@citrix.com> X-ClientProxiedBy: AMSPEX02CAS02.citrite.net (10.69.22.113) To FTLPEX02CL06.citrite.net (10.13.108.179) X-Rspamd-Queue-Id: CA92C180B3C8E X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Sep 01, 2020 at 10:33:26AM +0200, Roger Pau Monne wrote: > +static int fill_list(unsigned int nr_pages) > +{ > + struct dev_pagemap *pgmap; > + void *vaddr; > + unsigned int i, alloc_pages = round_up(nr_pages, PAGES_PER_SECTION); > + int nid, ret; > + > + pgmap = kzalloc(sizeof(*pgmap), GFP_KERNEL); > + if (!pgmap) > + return -ENOMEM; > + > + pgmap->type = MEMORY_DEVICE_GENERIC; > + pgmap->res.name = "Xen scratch"; > + pgmap->res.flags = IORESOURCE_MEM | IORESOURCE_BUSY; > + > + ret = allocate_resource(&iomem_resource, &pgmap->res, > + alloc_pages * PAGE_SIZE, 0, -1, > + PAGES_PER_SECTION * PAGE_SIZE, NULL, NULL); > + if (ret < 0) { > + pr_err("Cannot allocate new IOMEM resource\n"); > + kfree(pgmap); > + return ret; > + } > + > + nid = memory_add_physaddr_to_nid(pgmap->res.start); I think this is not needed ... > + > +#ifdef CONFIG_XEN_HAVE_PVMMU > + /* > + * memremap will build page tables for the new memory so > + * the p2m must contain invalid entries so the correct > + * non-present PTEs will be written. > + * > + * If a failure occurs, the original (identity) p2m entries > + * are not restored since this region is now known not to > + * conflict with any devices. > + */ > + if (!xen_feature(XENFEAT_auto_translated_physmap)) { > + xen_pfn_t pfn = PFN_DOWN(pgmap->res.start); > + > + for (i = 0; i < alloc_pages; i++) { > + if (!set_phys_to_machine(pfn + i, INVALID_P2M_ENTRY)) { > + pr_warn("set_phys_to_machine() failed, no memory added\n"); > + release_resource(&pgmap->res); > + kfree(pgmap); > + return -ENOMEM; > + } > + } > + } > +#endif > + > + vaddr = memremap_pages(pgmap, nid); ... and NUMA_NO_NODE should be used here instead, as this memory is just fictitious space to map foreign memory, and shouldn't be related to any NUMA node. The following chunk should be folded in, or I can resend. Thanks, Roger. ---8<--- diff --git a/drivers/xen/unpopulated-alloc.c b/drivers/xen/unpopulated-alloc.c index 1b5d157c6977..3b98dc921426 100644 --- a/drivers/xen/unpopulated-alloc.c +++ b/drivers/xen/unpopulated-alloc.c @@ -20,7 +20,7 @@ static int fill_list(unsigned int nr_pages) struct dev_pagemap *pgmap; void *vaddr; unsigned int i, alloc_pages = round_up(nr_pages, PAGES_PER_SECTION); - int nid, ret; + int ret; pgmap = kzalloc(sizeof(*pgmap), GFP_KERNEL); if (!pgmap) @@ -39,8 +39,6 @@ static int fill_list(unsigned int nr_pages) return ret; } - nid = memory_add_physaddr_to_nid(pgmap->res.start); - #ifdef CONFIG_XEN_HAVE_PVMMU /* * memremap will build page tables for the new memory so @@ -65,7 +63,7 @@ static int fill_list(unsigned int nr_pages) } #endif - vaddr = memremap_pages(pgmap, nid); + vaddr = memremap_pages(pgmap, NUMA_NO_NODE); if (IS_ERR(vaddr)) { pr_err("Cannot remap memory range\n"); release_resource(&pgmap->res);