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=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 6B99CC47095 for ; Mon, 7 Jun 2021 19:56:19 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 21F2861108 for ; Mon, 7 Jun 2021 19:56:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 21F2861108 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B84736B006E; Mon, 7 Jun 2021 15:56:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B5A666B0070; Mon, 7 Jun 2021 15:56:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9FBBE6B007D; Mon, 7 Jun 2021 15:56:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0243.hostedemail.com [216.40.44.243]) by kanga.kvack.org (Postfix) with ESMTP id 6C64F6B006E for ; Mon, 7 Jun 2021 15:56:18 -0400 (EDT) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 09FB119464 for ; Mon, 7 Jun 2021 19:56:18 +0000 (UTC) X-FDA: 78227984436.21.4B582EA Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf05.hostedemail.com (Postfix) with ESMTP id B68BAE016159 for ; Mon, 7 Jun 2021 19:56:08 +0000 (UTC) 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= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623095765; 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=ei55jgQ3upplsiPw0vFrnHbKL15r02TeRVPS/DKFnNC5GBWSQeya3Sor8HmT1xJqLF5qaf QiW2V8hrUzhy/oQvLzDavzVqz8SK/8O/6Cu5yyLOgEa7C0rUEeR+kk92DUWpMcq2uF1HhY 914+wL6vSbZU+4b3bxr69CKyZljIE+4= 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 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=WdnFdViS; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ei55jgQ3; spf=none (imf05.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 216.205.24.124) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Stat-Signature: 4f9dczwa4pjshw3g65hsyhwpmmnhf1cu X-Rspamd-Queue-Id: B68BAE016159 X-Rspamd-Server: rspam01 X-HE-Tag: 1623095768-174881 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: 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; =20 /* * 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 *v= m, uint64_t addr, addr + size - 1); /* Memory might get onlined immediately. */ atomic64_add(size, &vm->offline_size); - rc =3D add_memory_driver_managed(vm->nid, addr, size, vm->resource_name= , - MHP_MERGE_RESOURCE); + rc =3D add_memory_driver_managed(vm->mgid, addr, size, vm->resource_nam= e, + 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 virt= io_mem *vm) static int virtio_mem_probe(struct virtio_device *vdev) { struct virtio_mem *vm; + uint64_t unit_pages; int rc; =20 BUILD_BUG_ON(sizeof(struct virtio_mem_req) !=3D 24); @@ -2584,6 +2587,16 @@ static int virtio_mem_probe(struct virtio_device *= vdev) if (rc) goto out_del_vq; =20 + /* use a single dynamic memory group to cover the whole memory device *= / + if (vm->in_sbm) + unit_pages =3D PHYS_PFN(memory_block_size_bytes()); + else + unit_pages =3D PHYS_PFN(vm->bbm.bb_size); + rc =3D register_dynamic_memory_group(vm->nid, unit_pages); + if (rc < 0) + goto out_del_resource; + vm->mgid =3D 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 *v= dev) vm->memory_notifier.notifier_call =3D virtio_mem_memory_notifier_cb; rc =3D register_memory_notifier(&vm->memory_notifier); if (rc) - goto out_del_resource; + goto out_unreg_group; rc =3D register_virtio_mem_device(vm); if (rc) goto out_unreg_mem; @@ -2612,6 +2625,8 @@ static int virtio_mem_probe(struct virtio_device *v= dev) 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); } =20 /* remove all tracking data - no locking needed */ --=20 2.31.1