Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3523984pxj; Mon, 7 Jun 2021 12:58:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzR94MHABdnymjFCpAyUEqIJMZxjh2URnN0MqRGW+12T3WIkGkLKK6CCqzCoR8+jvZbp1hp X-Received: by 2002:a17:906:b0c8:: with SMTP id bk8mr4899493ejb.412.1623095890955; Mon, 07 Jun 2021 12:58:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623095890; cv=none; d=google.com; s=arc-20160816; b=iv1dbSdzd1bi+46pcsyGIVyWWSWTB0dJF538MXHbbbEx6xRZJQ0Rk/qNazW5jtNW28 aohXM27X9xo4sKahQivX5HlMSgzS27h+oDtKteILcnpCFsUrR0WHvQIgN/8BMihaqzHP 25Fu3DQGaHDbdaffpn1C2FZrjN1pqSOd+jbps7VNnXWh86/MIjThkrcDkiYWoaerbydy L0t0Ja+4DYQHVbEvuL2SaffyDjAVbkxbpHOUfRwT6JAAx/RT0Iyg4gOdwPyMD/BE7UQK IQMb4THpsWMNY/3Vz5KlInfRJIsBbbJ1HddEfRYQLaewxwZ8oHX2QC3ViSxMiKafDTB+ yKPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=H0au02BQp+qDy0PcdQC1Y8QhvsrT7V9iUgei65ky9cE=; b=p69Oqog+zm+WS771W36EU/sVo0GEmPqHY/DEsLCJEyfqmLwaMaXBT6s8/fEXgJh9C/ 1gpVkQI2IFhPQHQKRAYIImHEM0AFSDE7hhIdDCHCcTT4Hia5CCZGB7i8YEKjWUs1qqm9 Q30NOYLtxuPbwC1lQ7MmdyefZP7MOnjNtkF0ufJM4shPkDbaKrP4lTva2C6B3YMdF4Hw txz6SkDgoAne16StfNmOVRCtgRJ/56OtJ2pcHZNYajsFxsEJXclQgllvWHoKeb3F9S+B HbzEi/Zh4nSmeCG0fggtM37ve6pXJlZqT4Ajdub31wz0v8YVSKzqzBU75kdrgyW/G7Y/ C2NA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WjuRtNSu; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f9si13199973edv.112.2021.06.07.12.57.47; Mon, 07 Jun 2021 12:58:10 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WjuRtNSu; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231663AbhFGT5r (ORCPT + 99 others); Mon, 7 Jun 2021 15:57:47 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:47294 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231630AbhFGT5q (ORCPT ); Mon, 7 Jun 2021 15:57:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623095754; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=H0au02BQp+qDy0PcdQC1Y8QhvsrT7V9iUgei65ky9cE=; b=WjuRtNSu3S30LDpr/JHSn8TlQrC/OboGB8XH/FE1f9Ln7WmQzfYbgbu2aaF6HXhmnjOAc5 eScBaYycvS44BCJ09TEy4HuOeN8rlTYav9LPCAOxZjyCc7LFTPrIZldxs/W1DjR9qLhKtF /AFodfzrQS/b5YCmrjCOjo6P74eind4= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-116-hSb3xzLFO0-XBsfTuSZMjQ-1; Mon, 07 Jun 2021 15:55:52 -0400 X-MC-Unique: hSb3xzLFO0-XBsfTuSZMjQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 93B51107ACC7; Mon, 7 Jun 2021 19:55:50 +0000 (UTC) Received: from t480s.redhat.com (ovpn-112-9.ams2.redhat.com [10.36.112.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 81A3510013C1; Mon, 7 Jun 2021 19:55:46 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: David Hildenbrand , 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-mm@kvack.org, linux-acpi@vger.kernel.org Subject: [PATCH v1 09/12] ACPI: memhotplug: use a single static memory group for a single memory device Date: Mon, 7 Jun 2021 21:54:27 +0200 Message-Id: <20210607195430.48228-10-david@redhat.com> In-Reply-To: <20210607195430.48228-1-david@redhat.com> References: <20210607195430.48228-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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