From nobody Fri Nov 29 18:37:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1632853539; cv=none; d=zohomail.com; s=zohoarc; b=PAOw6LNwb/ITdgTNaFZbvpIgQymQlkzZTJ3nxn1uMxeqkHDTSLVtgie9V0AutQ1+YLn/sWP+zIhAjSv5qmf1YSK8sRQayHA6HPTFI9qxG73JWdS5PBnkFZTX80KMTtvXByUARRNhxXkpGd4e6Hj9KWrQH1Z7+4yevGls4yjTQ+0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632853539; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=nJ4bVTfY2RBZ7dKHJReSBumHsyhYfakPMn9Oqd8JPC0=; b=M4eTS6dHGS0eWk7Pu6AAHo57H003PcvFIJfrxrvWGDmAwmiVVFBA+DfGHOEgaUwNqD6rowrxkaxm6sjTOU3uyaMh0U5v2uXPNWAz/3OtPRQlDr+1dBK2QhpCEnz06ju7rGFx0GeIkHPhfSc4beYKSgn24R+FPKDXOFGbOCBWwQY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 163285353901023.809021034976126; Tue, 28 Sep 2021 11:25:39 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.198345.351795 (Exim 4.92) (envelope-from ) id 1mVHnA-0002c9-2u; Tue, 28 Sep 2021 18:25:24 +0000 Received: by outflank-mailman (output) from mailman id 198345.351795; Tue, 28 Sep 2021 18:25:24 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mVHn9-0002c2-Um; Tue, 28 Sep 2021 18:25:23 +0000 Received: by outflank-mailman (input) for mailman id 198345; Tue, 28 Sep 2021 18:25:23 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mVHn8-0002MP-Va for xen-devel@lists.xenproject.org; Tue, 28 Sep 2021 18:25:23 +0000 Received: from us-smtp-delivery-124.mimecast.com (unknown [170.10.129.124]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 68e8b53e-2089-11ec-bcc4-12813bfff9fa; Tue, 28 Sep 2021 18:25:08 +0000 (UTC) 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-27-tfQVnEQpPz2XZ-E6EUT2ZA-1; Tue, 28 Sep 2021 14:25:06 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 57A0C824FA8; Tue, 28 Sep 2021 18:25:04 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.194.120]) by smtp.corp.redhat.com (Postfix) with ESMTP id D16BB60854; Tue, 28 Sep 2021 18:24:26 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 68e8b53e-2089-11ec-bcc4-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632853508; 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=nJ4bVTfY2RBZ7dKHJReSBumHsyhYfakPMn9Oqd8JPC0=; b=etqVQ8C2Y8Dqe5zlDHBVyetBME4Hm9bFB3v+8JFC7aq8+e2ViAtogD7w7qbNiaXRBHyM3s 96OBiBGVN9l9xmQ/qrq372XN0gv13Y10H5K7CW41ODSqj3wPj9pcQhvhoHQzrX57GIY9mK 2qa5462w6tJhf/+r/lcb1evdglxBmUE= X-MC-Unique: tfQVnEQpPz2XZ-E6EUT2ZA-1 From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: David Hildenbrand , Andrew Morton , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Boris Ostrovsky , Juergen Gross , Stefano Stabellini , "Michael S. Tsirkin" , Jason Wang , Dave Young , Baoquan He , Vivek Goyal , Michal Hocko , Oscar Salvador , Mike Rapoport , "Rafael J. Wysocki" , x86@kernel.org, xen-devel@lists.xenproject.org, virtualization@lists.linux-foundation.org, kexec@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v1 6/8] virtio-mem: factor out hotplug specifics from virtio_mem_probe() into virtio_mem_init_hotplug() Date: Tue, 28 Sep 2021 20:22:56 +0200 Message-Id: <20210928182258.12451-7-david@redhat.com> In-Reply-To: <20210928182258.12451-1-david@redhat.com> References: <20210928182258.12451-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1632853539855100001 Content-Type: text/plain; charset="utf-8" Let's prepare for a new virtio-mem kdump mode in which we don't actually hot(un)plug any memory but only observe the state of device blocks. Signed-off-by: David Hildenbrand --- drivers/virtio/virtio_mem.c | 87 +++++++++++++++++++------------------ 1 file changed, 45 insertions(+), 42 deletions(-) diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c index 2ba7e8d6ba8d..1be3ee7f684d 100644 --- a/drivers/virtio/virtio_mem.c +++ b/drivers/virtio/virtio_mem.c @@ -260,6 +260,8 @@ static void virtio_mem_fake_offline_going_offline(unsig= ned long pfn, static void virtio_mem_fake_offline_cancel_offline(unsigned long pfn, unsigned long nr_pages); static void virtio_mem_retry(struct virtio_mem *vm); +static int virtio_mem_create_resource(struct virtio_mem *vm); +static void virtio_mem_delete_resource(struct virtio_mem *vm); =20 /* * Register a virtio-mem device so it will be considered for the online_pa= ge @@ -2395,7 +2397,8 @@ static int virtio_mem_init_vq(struct virtio_mem *vm) static int virtio_mem_init_hotplug(struct virtio_mem *vm) { const struct range pluggable_range =3D mhp_get_pluggable_range(true); - uint64_t sb_size, addr; + uint64_t unit_pages, sb_size, addr; + int rc; =20 /* bad device setup - warn only */ if (!IS_ALIGNED(vm->addr, memory_block_size_bytes())) @@ -2474,7 +2477,48 @@ static int virtio_mem_init_hotplug(struct virtio_mem= *vm) dev_info(&vm->vdev->dev, "big block size: 0x%llx", (unsigned long long)vm->bbm.bb_size); =20 + /* create the parent resource for all memory */ + rc =3D virtio_mem_create_resource(vm); + if (rc) + return rc; + + /* 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 memory_group_register_dynamic(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 + * actually in use (e.g., trying to reload the driver). + */ + if (vm->plugged_size) { + vm->unplug_all_required =3D true; + dev_info(&vm->vdev->dev, "unplugging all memory is required\n"); + } + + /* register callbacks */ + vm->memory_notifier.notifier_call =3D virtio_mem_memory_notifier_cb; + rc =3D register_memory_notifier(&vm->memory_notifier); + if (rc) + goto out_unreg_group; + rc =3D register_virtio_mem_device(vm); + if (rc) + goto out_unreg_mem; + return 0; +out_unreg_mem: + unregister_memory_notifier(&vm->memory_notifier); +out_unreg_group: + memory_group_unregister(vm->mgid); +out_del_resource: + virtio_mem_delete_resource(vm); + return rc; } =20 static int virtio_mem_init(struct virtio_mem *vm) @@ -2578,7 +2622,6 @@ 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; =20 BUILD_BUG_ON(sizeof(struct virtio_mem_req) !=3D 24); @@ -2608,40 +2651,6 @@ static int virtio_mem_probe(struct virtio_device *vd= ev) if (rc) goto out_del_vq; =20 - /* create the parent resource for all memory */ - rc =3D virtio_mem_create_resource(vm); - if (rc) - goto out_del_vq; - - /* 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 memory_group_register_dynamic(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 - * actually in use (e.g., trying to reload the driver). - */ - if (vm->plugged_size) { - vm->unplug_all_required =3D true; - dev_info(&vm->vdev->dev, "unplugging all memory is required\n"); - } - - /* register callbacks */ - vm->memory_notifier.notifier_call =3D virtio_mem_memory_notifier_cb; - rc =3D register_memory_notifier(&vm->memory_notifier); - if (rc) - goto out_unreg_group; - rc =3D register_virtio_mem_device(vm); - if (rc) - goto out_unreg_mem; - virtio_device_ready(vdev); =20 /* trigger a config update to start processing the requested_size */ @@ -2649,12 +2658,6 @@ static int virtio_mem_probe(struct virtio_device *vd= ev) queue_work(system_freezable_wq, &vm->wq); =20 return 0; -out_unreg_mem: - unregister_memory_notifier(&vm->memory_notifier); -out_unreg_group: - memory_group_unregister(vm->mgid); -out_del_resource: - virtio_mem_delete_resource(vm); out_del_vq: vdev->config->del_vqs(vdev); out_free_vm: --=20 2.31.1