Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3524107pxj; Mon, 7 Jun 2021 12:58:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwokNlbMGKfGs0h/1JTlo0L0LdBEROo71bgeYv0nX1MJpPlLafag4rnudUUfiN687XblFSY X-Received: by 2002:a17:906:3c56:: with SMTP id i22mr19958762ejg.369.1623095907492; Mon, 07 Jun 2021 12:58:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623095907; cv=none; d=google.com; s=arc-20160816; b=kpUCKL39SU/2S2cgOI8MbVlcQvSX3ZQZp2p1t0jfQYJNQlw7f7E14TNYJSLRiA43d0 scose9eV+9h6TS2pBIpfUD3GFKHVkGOWTNYpkEFRji+MldATkc4XdlWIjiYFolAFZH6e vhi5789T9bAqLs77fR0/1ypKPTNRy+MN5Igp/9WgY5jgNfqmuVIBg+nrl6gJjmA5Ub91 RKCYojoU+nuwOLnodmw1oS8DOT2ILsvOIXrhqR9pZM6/3v0DoTYSc2UtgxV74FHwgkai HKo4xck9tAdc58XQ7oVc7nehAViFbyANjNSaJxVYt0f65deBvsIF9IzLm9qpmU56Ej7G FvEQ== 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=we7KxiONd+RRHM3f3H50fIrTEzJMZrnOephVGh+JFPs=; b=e9zN9tDWqRnLVIiH1SlnahS05B2uq5MSxMFIdE9g7fKCT2rqwWtaiD9pQISaXBQEnk VG4831wcwMc1I0HkhVEeLT8Vr1Kow6KXjz/qM1q8um3zWyH8IlxxxD5sqD5wKTGMExLY mgFjCehd6ipSj1/OAyKXYzHHy4mNOxWdIup8DJ67D6YjrhWpv6qxyQDgdzqfGLL9b+yR VvH+E1wEjHQ9cLUV49qF6Br1qHag2UeLBHIogE5e9m+UESFgfzoDEQY2+7zbsBbGy/T3 ZvdPJlCmJxaaX8Pq4+TKHaAuFXqtSb6Ynp+87KRtO0UWyGSaNu1gL0k3An6NaaYHJITI VZ5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WdnFdViS; 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 eb13si14739003edb.95.2021.06.07.12.58.04; Mon, 07 Jun 2021 12:58:27 -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=WdnFdViS; 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 S231672AbhFGT5v (ORCPT + 99 others); Mon, 7 Jun 2021 15:57:51 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:55232 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231671AbhFGT5u (ORCPT ); Mon, 7 Jun 2021 15:57:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623095758; 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=we7KxiONd+RRHM3f3H50fIrTEzJMZrnOephVGh+JFPs=; b=WdnFdViSheFgKahjFxkS//1nYBEkwzbKMpRxQIGMbChxx57f6x8rBSJH/W3J8paBU57niI +lUeJj97MKO5OkD9xY+S9v0eD4r+QakJ+pIcDb2MfT3N5/Dgd8VuyQ4un9GoS9OArK5Q9p 2AOmpgrRJeJliH95Rc2++E5Gul28mEo= 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-551-xue4KIEMN8mt8Nf3IR86ZA-1; Mon, 07 Jun 2021 15:55:57 -0400 X-MC-Unique: xue4KIEMN8mt8Nf3IR86ZA-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 EF854100748D; Mon, 7 Jun 2021 19:55:54 +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 DE9101002D71; Mon, 7 Jun 2021 19:55:50 +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 10/12] virtio-mem: use a single dynamic memory group for a single virtio-mem device Date: Mon, 7 Jun 2021 21:54:28 +0200 Message-Id: <20210607195430.48228-11-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 use a single dynamic memory group. Signed-off-by: David Hildenbrand --- drivers/virtio/virtio_mem.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c index e327fb878143..6b9b8b7bf89d 100644 --- a/drivers/virtio/virtio_mem.c +++ b/drivers/virtio/virtio_mem.c @@ -139,6 +139,8 @@ struct virtio_mem { * add_memory_driver_managed(). */ const char *resource_name; + /* Memory group identification. */ + int mgid; /* * We don't want to add too much memory if it's not getting onlined, @@ -622,8 +624,8 @@ static int virtio_mem_add_memory(struct virtio_mem *vm, uint64_t addr, addr + size - 1); /* Memory might get onlined immediately. */ atomic64_add(size, &vm->offline_size); - rc = add_memory_driver_managed(vm->nid, addr, size, vm->resource_name, - MHP_MERGE_RESOURCE); + rc = add_memory_driver_managed(vm->mgid, addr, size, vm->resource_name, + MHP_MERGE_RESOURCE | MHP_NID_IS_MGID); if (rc) { atomic64_sub(size, &vm->offline_size); dev_warn(&vm->vdev->dev, "adding memory failed: %d\n", rc); @@ -2550,6 +2552,7 @@ static bool virtio_mem_has_memory_added(struct virtio_mem *vm) static int virtio_mem_probe(struct virtio_device *vdev) { struct virtio_mem *vm; + uint64_t unit_pages; int rc; BUILD_BUG_ON(sizeof(struct virtio_mem_req) != 24); @@ -2584,6 +2587,16 @@ static int virtio_mem_probe(struct virtio_device *vdev) if (rc) goto out_del_vq; + /* use a single dynamic memory group to cover the whole memory device */ + if (vm->in_sbm) + unit_pages = PHYS_PFN(memory_block_size_bytes()); + else + unit_pages = PHYS_PFN(vm->bbm.bb_size); + rc = register_dynamic_memory_group(vm->nid, unit_pages); + if (rc < 0) + goto out_del_resource; + vm->mgid = rc; + /* * If we still have memory plugged, we have to unplug all memory first. * Registering our parent resource makes sure that this memory isn't @@ -2598,7 +2611,7 @@ static int virtio_mem_probe(struct virtio_device *vdev) vm->memory_notifier.notifier_call = virtio_mem_memory_notifier_cb; rc = register_memory_notifier(&vm->memory_notifier); if (rc) - goto out_del_resource; + goto out_unreg_group; rc = register_virtio_mem_device(vm); if (rc) goto out_unreg_mem; @@ -2612,6 +2625,8 @@ static int virtio_mem_probe(struct virtio_device *vdev) return 0; out_unreg_mem: unregister_memory_notifier(&vm->memory_notifier); +out_unreg_group: + unregister_memory_group(vm->mgid); out_del_resource: virtio_mem_delete_resource(vm); out_del_vq: @@ -2676,6 +2691,7 @@ static void virtio_mem_remove(struct virtio_device *vdev) } else { virtio_mem_delete_resource(vm); kfree_const(vm->resource_name); + unregister_memory_group(vm->mgid); } /* remove all tracking data - no locking needed */ -- 2.31.1