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=-14.0 required=3.0 tests=BAYES_00,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham 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 0002FC4743F for ; Tue, 8 Jun 2021 12:20:53 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9727C6135D for ; Tue, 8 Jun 2021 12:20:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9727C6135D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 363CA6B006E; Tue, 8 Jun 2021 08:20:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 33A666B0070; Tue, 8 Jun 2021 08:20:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2024B6B0071; Tue, 8 Jun 2021 08:20:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0202.hostedemail.com [216.40.44.202]) by kanga.kvack.org (Postfix) with ESMTP id E4E526B006E for ; Tue, 8 Jun 2021 08:20:52 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 867E9941F for ; Tue, 8 Jun 2021 12:20:52 +0000 (UTC) X-FDA: 78230465544.22.21278B1 Received: from mail-ot1-f46.google.com (mail-ot1-f46.google.com [209.85.210.46]) by imf07.hostedemail.com (Postfix) with ESMTP id CB003A0001CF for ; Tue, 8 Jun 2021 12:20:48 +0000 (UTC) Received: by mail-ot1-f46.google.com with SMTP id w23-20020a9d5a970000b02903d0ef989477so15682705oth.9 for ; Tue, 08 Jun 2021 05:20:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=aBvx0tMqvnsqasRMwdIjV828Q4KMfEaGuv9isdIMh6w=; b=OIps73g3lD0NIlz8q0qyk/3kABtBSOs7q3AuhyJUw8L+PcBPa4xEx1dRIvENB/MFmv uynxikd0rGLF3i+YoLDSsaKpP5qn/DKYF04DGoP16+fGegzlXA5jjvp4XRT4g7tmwWzy BEJxpDEfDBbga/XCdMWxl2BUTlrYLitjILn8ceZrXEenzYFDhL8L3eC/Xr4nRMdQMkNl SGpjxM2z7ttXjasua4xlkWaz8MtSzCtW1bkDXUvw2nFbvNUyvndNxIwYIKUiyhkLgFY+ oKdffjpeeTQRq/pW6PF2Ja9qJIlpTS6VgrhWOdbpqJ64bcaOhViehcyAgD94onpTDHwC iYHQ== X-Gm-Message-State: AOAM5308Eb/1sDfrUx9Wc/UWDb4MoRq16RzcoN54BKHSkvbI2p6nZvIM nOp0N509P9sYibl9ovlt2B2PrTvQMaOiM48Xwxs= X-Google-Smtp-Source: ABdhPJxH/dWUiK6LlZLSUta/Ys0v09YjScxWXuTxxpG59lqd7H1n1RYtnEYQbcCaesHEWVw7jYVneuift9/T5XVCqBA= X-Received: by 2002:a9d:63cd:: with SMTP id e13mr18583145otl.206.1623154851653; Tue, 08 Jun 2021 05:20:51 -0700 (PDT) MIME-Version: 1.0 References: <20210607195430.48228-1-david@redhat.com> <20210607195430.48228-10-david@redhat.com> In-Reply-To: <20210607195430.48228-10-david@redhat.com> From: "Rafael J. Wysocki" Date: Tue, 8 Jun 2021 14:20:40 +0200 Message-ID: Subject: Re: [PATCH v1 09/12] ACPI: memhotplug: use a single static memory group for a single memory device To: David Hildenbrand Cc: Linux Kernel Mailing List , Andrew Morton , Vitaly Kuznetsov , "Michael S. Tsirkin" , Jason Wang , Marek Kedzierski , Hui Zhu , Pankaj Gupta , Wei Yang , Oscar Salvador , Michal Hocko , Dan Williams , Anshuman Khandual , Dave Hansen , Vlastimil Babka , Mike Rapoport , "Rafael J. Wysocki" , Len Brown , Pavel Tatashin , virtualization@lists.linux-foundation.org, Linux Memory Management List , ACPI Devel Maling List Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: CB003A0001CF Authentication-Results: imf07.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=kernel.org (policy=none); spf=pass (imf07.hostedemail.com: domain of rjwysocki@gmail.com designates 209.85.210.46 as permitted sender) smtp.mailfrom=rjwysocki@gmail.com X-Stat-Signature: eixnpnndt3w1pu4j3hntr8r9su1yb5mx X-HE-Tag: 1623154848-398141 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 Mon, Jun 7, 2021 at 9:55 PM David Hildenbrand wrote: > > Let's group all memory we add for a single memory device - we want a > single node for that (which also seems to be the sane thing to do). > > We won't care for now about memory that was already added to the system > (e.g., via e820) -- usually *all* memory of a memory device was already > added and we'll fail acpi_memory_enable_device(). > > Signed-off-by: David Hildenbrand Acked-by: Rafael J. Wysocki > --- > drivers/acpi/acpi_memhotplug.c | 35 +++++++++++++++++++++++++++++----- > 1 file changed, 30 insertions(+), 5 deletions(-) > > diff --git a/drivers/acpi/acpi_memhotplug.c b/drivers/acpi/acpi_memhotplug.c > index eb4faf7c5cad..0c7b062c0e5d 100644 > --- a/drivers/acpi/acpi_memhotplug.c > +++ b/drivers/acpi/acpi_memhotplug.c > @@ -54,6 +54,7 @@ struct acpi_memory_info { > struct acpi_memory_device { > struct acpi_device *device; > struct list_head res_list; > + int mgid; > }; > > static acpi_status > @@ -171,10 +172,31 @@ static int acpi_memory_enable_device(struct acpi_memory_device *mem_device) > acpi_handle handle = mem_device->device->handle; > int result, num_enabled = 0; > struct acpi_memory_info *info; > - mhp_t mhp_flags = MHP_NONE; > - int node; > + mhp_t mhp_flags = MHP_NID_IS_MGID; > + u64 total_length = 0; > + int node, mgid; > > node = acpi_get_node(handle); > + > + list_for_each_entry(info, &mem_device->res_list, list) { > + if (!info->length) > + continue; > + /* We want a single node for the whole memory group */ > + if (node < 0) > + node = memory_add_physaddr_to_nid(info->start_addr); > + total_length += info->length; > + } > + > + if (!total_length) { > + dev_err(&mem_device->device->dev, "device is empty\n"); > + return -EINVAL; > + } > + > + mgid = register_static_memory_group(node, PFN_UP(total_length)); > + if (mgid < 0) > + return mgid; > + mem_device->mgid = mgid; > + > /* > * Tell the VM there is more memory here... > * Note: Assume that this function returns zero on success > @@ -188,12 +210,10 @@ static int acpi_memory_enable_device(struct acpi_memory_device *mem_device) > */ > if (!info->length) > continue; > - if (node < 0) > - node = memory_add_physaddr_to_nid(info->start_addr); > > if (mhp_supports_memmap_on_memory(info->length)) > mhp_flags |= MHP_MEMMAP_ON_MEMORY; > - result = __add_memory(node, info->start_addr, info->length, > + result = __add_memory(mgid, info->start_addr, info->length, > mhp_flags); > > /* > @@ -253,6 +273,10 @@ static void acpi_memory_device_free(struct acpi_memory_device *mem_device) > if (!mem_device) > return; > > + /* In case we succeeded adding *some* memory, unregistering fails. */ > + if (mem_device->mgid >= 0) > + unregister_memory_group(mem_device->mgid); > + > acpi_memory_free_device_resources(mem_device); > mem_device->device->driver_data = NULL; > kfree(mem_device); > @@ -273,6 +297,7 @@ static int acpi_memory_device_add(struct acpi_device *device, > > INIT_LIST_HEAD(&mem_device->res_list); > mem_device->device = device; > + mem_device->mgid = -1; > sprintf(acpi_device_name(device), "%s", ACPI_MEMORY_DEVICE_NAME); > sprintf(acpi_device_class(device), "%s", ACPI_MEMORY_DEVICE_CLASS); > device->driver_data = mem_device; > -- > 2.31.1 >