Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4048138pxj; Tue, 8 Jun 2021 05:22:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzAJCkvFuJpKMJyvNpaw2qE70J1IVV1TiPb0ogr4jdICbZYt6tGONfGiVxfDyaROwufsgJW X-Received: by 2002:a17:906:660c:: with SMTP id b12mr23601375ejp.86.1623154965409; Tue, 08 Jun 2021 05:22:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623154965; cv=none; d=google.com; s=arc-20160816; b=jOBiHBFSx53i+7lCkooYtD/K4uFGlz5hbWAhgK8KjMeaEBLslSZnmnpRu5MrSknpLE W1vGTBc06g+WMS5wZIxQff7TE5y8Errs3rozwKqor37wAkoYhZCXMp2RHlitTe5pRWCj S0j+y/rjhGqD/H1hz0frYJobWgj7VxcwjluZv28+7rvhfb4T+PkmVcwTlaLt3JhqYg8+ XdmxUQaJV8s0Wh6t1t9nJw+/CIqFwatVeL6MowL7H9HAtrTrhTp1aPT4ccl4MUcpw5mQ hZbghT/PK3QuE2S5ndfm+TLP+p3xwFH74ulIXlZgQ3TWxwaxJvmIlMsJVd4GjVOWxw9w +Zww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=aBvx0tMqvnsqasRMwdIjV828Q4KMfEaGuv9isdIMh6w=; b=xVWQnMRTj2j4rTu8ar1IA8m9erBwHkT35LLtM9i5bY5aiziogH0v5fL1Jgsz1mn9YK p7/WSEeRsr9xUPCqNbM/XGicKv1I8l0ctkpUkn6p4W4BlmnaCDnxdCpYp9LayRDjz/of e7KJXGPwr0utJiOKVBqqRU/KcRsdrjUgiB53MkTq9kGbEaA3LPaUfEciyuqb81RXYupm wbVjdlxMOtFeuu695/MiS9XsLwmAqZMr+McKen+ugaqSDwRd74Qx0oQe0np9z7Nr1LW0 tOj6A9OdADGvmMBwT+ooFjVZ4BRcQkuiql5fC+SYtURzvZFmTe+nc1NGoU0mh7C2j9xc lFSQ== ARC-Authentication-Results: i=1; mx.google.com; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j9si11779481edw.50.2021.06.08.05.22.21; Tue, 08 Jun 2021 05:22:45 -0700 (PDT) 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; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232204AbhFHMWp (ORCPT + 99 others); Tue, 8 Jun 2021 08:22:45 -0400 Received: from mail-ot1-f51.google.com ([209.85.210.51]:43755 "EHLO mail-ot1-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232246AbhFHMWo (ORCPT ); Tue, 8 Jun 2021 08:22:44 -0400 Received: by mail-ot1-f51.google.com with SMTP id i12-20020a05683033ecb02903346fa0f74dso20060003otu.10; Tue, 08 Jun 2021 05:20:51 -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=AfriIGXHJdqcAM38Gv6UrSnFkVhDOaztKwBGacdZwnam3vJ8mSUStbcLynOlF6rCYG Bt1Ck+vueKHFANZQ+NNh92WbOYKVC4zyd+U8m8X2xCgNc1XIq1oGlLvR5WTV3rvd1s9a rT5SRFYJi/9e1ntWO4Brn/sugqgzykiI4TRQjP+Ot5388mITcuoItUeKeQ/GhNiehcOF 1cId7F8t2qfVkPLq0kwi1mOzQgdwjv9iv7XjHGhYI+AVa/g7gNkegAIvct4bwIvWMw8P +KKmag6s0aK/laagl3SXQBIGjGdfqezwqnu82c6bjZVs0IxtN/ZsR0ci8TrUb4hzNAl1 OOag== X-Gm-Message-State: AOAM530r7JzBSDbX+lF7PFtF/eFilSI9VyCS2TSZdLuP91wCRKOgcMLQ hl9A0bgl0Oy1NHF86tNTyjyb5GRGEdVNUiPtGsg= 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" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 >