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.6 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 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 A4AF3C43461 for ; Tue, 1 Sep 2020 14:54:45 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 63AAF208CA for ; Tue, 1 Sep 2020 14:54:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 63AAF208CA Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 0E4E56B0088; Tue, 1 Sep 2020 10:54:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 095266B008A; Tue, 1 Sep 2020 10:54:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EC62A6B008C; Tue, 1 Sep 2020 10:54:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0205.hostedemail.com [216.40.44.205]) by kanga.kvack.org (Postfix) with ESMTP id D75E56B0088 for ; Tue, 1 Sep 2020 10:54:44 -0400 (EDT) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 7165C362B for ; Tue, 1 Sep 2020 14:54:44 +0000 (UTC) X-FDA: 77214789288.09.spot50_2703f1e27099 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin09.hostedemail.com (Postfix) with ESMTP id 08972180AD802 for ; Tue, 1 Sep 2020 14:54:43 +0000 (UTC) X-HE-Tag: spot50_2703f1e27099 X-Filterd-Recvd-Size: 3825 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf24.hostedemail.com (Postfix) with ESMTP for ; Tue, 1 Sep 2020 14:54:42 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id D50A6ACC3; Tue, 1 Sep 2020 14:54:41 +0000 (UTC) Subject: Re: [PATCH v5 3/3] xen: add helpers to allocate unpopulated memory To: =?UTF-8?Q?Roger_Pau_Monn=c3=a9?= , linux-kernel@vger.kernel.org Cc: Oleksandr Andrushchenko , David Airlie , Daniel Vetter , Boris Ostrovsky , Stefano Stabellini , Dan Carpenter , Wei Liu , Yan Yankovskyi , dri-devel@lists.freedesktop.org, xen-devel@lists.xenproject.org, linux-mm@kvack.org, David Hildenbrand , Michal Hocko , Dan Williams References: <20200901083326.21264-1-roger.pau@citrix.com> <20200901083326.21264-4-roger.pau@citrix.com> <20200901144539.GI753@Air-de-Roger> From: =?UTF-8?B?SsO8cmdlbiBHcm/Dnw==?= Message-ID: <4b24c8c3-fb0f-23ad-09c5-81fcfdb6a2b5@suse.com> Date: Tue, 1 Sep 2020 16:54:40 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 MIME-Version: 1.0 In-Reply-To: <20200901144539.GI753@Air-de-Roger> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US X-Rspamd-Queue-Id: 08972180AD802 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 Content-Transfer-Encoding: quoted-printable 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 01.09.20 16:45, Roger Pau Monn=C3=A9 wrote: > 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 =3D round_up(nr_pages, PAGES_PER_SECTION= ); >> + int nid, ret; >> + >> + pgmap =3D kzalloc(sizeof(*pgmap), GFP_KERNEL); >> + if (!pgmap) >> + return -ENOMEM; >> + >> + pgmap->type =3D MEMORY_DEVICE_GENERIC; >> + pgmap->res.name =3D "Xen scratch"; >> + pgmap->res.flags =3D IORESOURCE_MEM | IORESOURCE_BUSY; >> + >> + ret =3D 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 =3D memory_add_physaddr_to_nid(pgmap->res.start); >=20 > I think this is not needed ... >=20 >> + >> +#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 =3D PFN_DOWN(pgmap->res.start); >> + >> + for (i =3D 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 =3D memremap_pages(pgmap, nid); >=20 > ... and NUMA_NO_NODE should be used here instead, as this memory is jus= t > fictitious space to map foreign memory, and shouldn't be related to > any NUMA node. >=20 > The following chunk should be folded in, or I can resend. I can fold it in. Juergen