From patchwork Thu Jul 13 14:55:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13312325 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 282A4C0015E for ; Thu, 13 Jul 2023 14:56:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B6EA76B0074; Thu, 13 Jul 2023 10:56:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B1ECC900035; Thu, 13 Jul 2023 10:56:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9E5ED90001C; Thu, 13 Jul 2023 10:56:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 8D0CD6B0074 for ; Thu, 13 Jul 2023 10:56:04 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id DAF3F40306 for ; Thu, 13 Jul 2023 14:56:03 +0000 (UTC) X-FDA: 81006888606.29.9469C7C Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf25.hostedemail.com (Postfix) with ESMTP id 0FF4AA001A for ; Thu, 13 Jul 2023 14:56:01 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ckP2DaeZ; spf=pass (imf25.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689260162; a=rsa-sha256; cv=none; b=JxrOg7dlDiLYi/gPDVPpq01xYTxtCXBjoJMDDtWRG378MDGUPEFg/P4d8OLpz7iDn/pU4F gHQGqM6KGAth/7rs+lKcbueezSWKn9FIp0ro/K2BOxPjIo5CA4lQSCxL4IEBDmaxX9PXHD n5jGwzYq4REciGdvsGJeFXRojXtdyrc= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ckP2DaeZ; spf=pass (imf25.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689260162; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=rOmThcBQ38XDQnqrguekPpebm9LB32j86WbUbdRAymk=; b=YY6iOalf3fPWvZTpxT3F/P/gPYDTKCgL9nXDAWLcYz+PKqBjT8Lb+DOSJGAxy+J5IKghZ/ QynWhG1Z3eknbX2B0ArAi4aaBX8T9eQtmu+pt5iZKTeLG3XCvJS/aON6WBTf9zV7z0MlsE mzALcwY1HjHig2m4AjjmJiDD45AZZO0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689260161; 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=rOmThcBQ38XDQnqrguekPpebm9LB32j86WbUbdRAymk=; b=ckP2DaeZp6yd41hYpo24COXZYVXu5A8TiFzIc3yySFV+z4hViJvMtaQQxspdtgZGZ5beD/ hDRb1mpKhtqYEMk400uZbdfmXy91Zfvi3XLDRp8vA/f9T0tStXlbM/V24Vq/umO7eZr5nW tFoceyVhexTSPK7yJYV0eHQfGhUjsKc= Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-651-j4H8HIhJMpCZyM7rsWcs1g-1; Thu, 13 Jul 2023 10:55:57 -0400 X-MC-Unique: j4H8HIhJMpCZyM7rsWcs1g-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4FD7A29A9D36; Thu, 13 Jul 2023 14:55:57 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.39.192.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id A4780F66D1; Thu, 13 Jul 2023 14:55:55 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, virtualization@lists.linux-foundation.org, David Hildenbrand , "Michael S. Tsirkin" , Jason Wang , Xuan Zhuo Subject: [PATCH v1 1/4] virtio-mem: remove unsafe unplug in Big Block Mode (BBM) Date: Thu, 13 Jul 2023 16:55:48 +0200 Message-ID: <20230713145551.2824980-2-david@redhat.com> In-Reply-To: <20230713145551.2824980-1-david@redhat.com> References: <20230713145551.2824980-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 0FF4AA001A X-Stat-Signature: 3zf566thh4m75dywrt7gofidfwfhghz6 X-Rspam-User: X-HE-Tag: 1689260161-51212 X-HE-Meta: U2FsdGVkX18sGqQBU05FdpwYo74R0uUPqrWbyIkRYiT2FDvM7nsMF1H9RMhOgBWMcaSFYCg3POtP4uz9Idl0gtvtPZvEAzsjnTk8thgly9Qq0YTXty/yUX3zQTCXlsjJAWoE/VfmOKJfrqfcHAND/a0xv4ZMo0FO8WGR+08A2ER1GIAeDZ2AgNdOBInfUf8xhMM8F17Do+6I2lnKtRYdkCO1fElcbSb2zE0sP+sjC3h9+E3D5mxx7Sc9FChkNhkGVwHVIcrvBB33rgNxwwz3zjtswML1m5tyMle3p8zQR/o0wunwv0JwTo0iYf2d59HQEv2EivN2RQyr7G/BgPRU/q9/qc8cUcRCzMQ0/Z0tsglavVmk3lNIsIzIyQaSgjCAIxSkXg5JJ7dmTofkLh8u/ISLnahUPRqclwdK+WVwhvNVmIJANoTZyJzn2EbpTARu5Sv2kGWISQxKKtCgC5wZRzxOOq0JaTpg4L8e6j4LEzBBsMWIh8UYquc60OASZjJ8RtidC/LYdvXlWjnVz8aLPG8BhTsEsHTbtdBzD4+IIPCQGxhE0f0TzBSm8W+YdymXtz/A4GJUtQLymHA+ZxKUUdKpSkvCplb3p0RgGnyWO3YKxu2AN34XAlxHvGZcMIu/y05Wc+IRDMkKPNmfM/KaLhyBq1e61/02y9rWf2wZh1heGpXxOXYTQjFqF7T6TYCNQW7Kf5Ko+30LKnbI3cFOhIYNx/um/bc+kSilsae5DtVIpGURR4qMZk9uvSnvu+DKrOOo4qqd66OcoqadgsDBxnQ+NDrBMkP7tVK6DwJ2sJ9QYCS8gV9vTEC02ZuZbOtLK2Bd721UdJu2j3EGeDZjoUbTuxhQ29m6CWcTTvBQZF0X6OwBY8kdgewjpYHcgOncg7UUicoDG0cDZ6uZkhH/jf3prGziydfJJK7oGgdsELTAcYNRUuzahIp3ipWgvP5cJSaX+V7NhWKIAThDkVk WghmhKda sEmZy1CtY0iHJyK2myfuHcYm5z2veGpEiShrYIhxyzBwlIEdHSOe8mi6+QqBQ1D2XCeP8kH4HaD3igcPDf90F/6A1EFQY+IlFnQdg63UTqyKun93BwoFgAMb2I6pxYE0CtLjuoRY8DqaciiBP1zdaA7FzGhHABVSDz7wo9Yunk6hkMcw= 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: When "unsafe unplug" is enabled, we don't fake-offline all memory ahead of actual memory offlining using alloc_contig_range(). Instead, we rely on offline_pages() to also perform actual page migration, which might fail or take a very long time. In that case, it's possible to easily run into endless loops that cannot be aborted anymore (as offlining is triggered by a workqueue then): For example, a single (accidentally) permanently unmovable page in ZONE_MOVABLE results in an endless loop. For ZONE_NORMAL, races between isolating the pageblock (and checking for unmovable pages) and concurrent page allocation are possible and similarly result in endless loops. The idea of the unsafe unplug mode was to make it possible to more reliably unplug large memory blocks. However, (a) we really should be tackling that differently, by extending the alloc_contig_range()-based mechanism; and (b) this mode is not the default and as far as I know, it's unused either way. So let's simply get rid of it. Signed-off-by: David Hildenbrand --- drivers/virtio/virtio_mem.c | 51 +++++++++++++++---------------------- 1 file changed, 20 insertions(+), 31 deletions(-) diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c index 835f6cc2fb66..ed15d2a4bd96 100644 --- a/drivers/virtio/virtio_mem.c +++ b/drivers/virtio/virtio_mem.c @@ -38,11 +38,6 @@ module_param(bbm_block_size, ulong, 0444); MODULE_PARM_DESC(bbm_block_size, "Big Block size in bytes. Default is 0 (auto-detection)."); -static bool bbm_safe_unplug = true; -module_param(bbm_safe_unplug, bool, 0444); -MODULE_PARM_DESC(bbm_safe_unplug, - "Use a safe unplug mechanism in BBM, avoiding long/endless loops"); - /* * virtio-mem currently supports the following modes of operation: * @@ -2111,38 +2106,32 @@ static int virtio_mem_bbm_offline_remove_and_unplug_bb(struct virtio_mem *vm, VIRTIO_MEM_BBM_BB_ADDED)) return -EINVAL; - if (bbm_safe_unplug) { - /* - * Start by fake-offlining all memory. Once we marked the device - * block as fake-offline, all newly onlined memory will - * automatically be kept fake-offline. Protect from concurrent - * onlining/offlining until we have a consistent state. - */ - mutex_lock(&vm->hotplug_mutex); - virtio_mem_bbm_set_bb_state(vm, bb_id, - VIRTIO_MEM_BBM_BB_FAKE_OFFLINE); + /* + * Start by fake-offlining all memory. Once we marked the device + * block as fake-offline, all newly onlined memory will + * automatically be kept fake-offline. Protect from concurrent + * onlining/offlining until we have a consistent state. + */ + mutex_lock(&vm->hotplug_mutex); + virtio_mem_bbm_set_bb_state(vm, bb_id, VIRTIO_MEM_BBM_BB_FAKE_OFFLINE); - for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) { - page = pfn_to_online_page(pfn); - if (!page) - continue; + for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) { + page = pfn_to_online_page(pfn); + if (!page) + continue; - rc = virtio_mem_fake_offline(pfn, PAGES_PER_SECTION); - if (rc) { - end_pfn = pfn; - goto rollback_safe_unplug; - } + rc = virtio_mem_fake_offline(pfn, PAGES_PER_SECTION); + if (rc) { + end_pfn = pfn; + goto rollback; } - mutex_unlock(&vm->hotplug_mutex); } + mutex_unlock(&vm->hotplug_mutex); rc = virtio_mem_bbm_offline_and_remove_bb(vm, bb_id); if (rc) { - if (bbm_safe_unplug) { - mutex_lock(&vm->hotplug_mutex); - goto rollback_safe_unplug; - } - return rc; + mutex_lock(&vm->hotplug_mutex); + goto rollback; } rc = virtio_mem_bbm_unplug_bb(vm, bb_id); @@ -2154,7 +2143,7 @@ static int virtio_mem_bbm_offline_remove_and_unplug_bb(struct virtio_mem *vm, VIRTIO_MEM_BBM_BB_UNUSED); return rc; -rollback_safe_unplug: +rollback: for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) { page = pfn_to_online_page(pfn); if (!page) From patchwork Thu Jul 13 14:55:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13312326 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D35AFC001DD for ; Thu, 13 Jul 2023 14:56:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 776B06B0075; Thu, 13 Jul 2023 10:56:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 72758900035; Thu, 13 Jul 2023 10:56:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 615D790001C; Thu, 13 Jul 2023 10:56:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 552016B0075 for ; Thu, 13 Jul 2023 10:56:06 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id BC1C6C02F3 for ; Thu, 13 Jul 2023 14:56:04 +0000 (UTC) X-FDA: 81006888648.25.62FB7C7 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf08.hostedemail.com (Postfix) with ESMTP id 438A7160011 for ; Thu, 13 Jul 2023 14:56:01 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Sq8VJqeM; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf08.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689260162; a=rsa-sha256; cv=none; b=gBr34+raLEHdJzT2iOAzay888jWvCE+OVNYNfy6GDyY85eydP7s2aKQjzRgbxRefF545IA I8X/0RMXy9AINPYok0AwrIARl6FtiB++pEsINOvKfjWvvXpGc59yBgJrEu8vU+BlaAnmuo fTkSlJTkJC/UBacuLUQbVcrTqqRye2c= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Sq8VJqeM; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf08.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689260162; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=tvagZqP7r7JhOH2HSmKVW5dMeNgJcBr/tywkzsCuQEE=; b=yM5SGsbQd3wBjTxRjXDFyjWf8hXa3h5BjNaSUdEL1o1MKFAQL69QkbEwqRNMoWxNITeRVE kjlKTzknPvHTbmNB9UtTcYBS7Uvis/gx5I0KPo7Gn4Gu9xJ2EK7BLwcI/kqx0dVpmXtrvS WxVrWuuqYz1LzW/aNDysSwiu+xI38UU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689260161; 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=tvagZqP7r7JhOH2HSmKVW5dMeNgJcBr/tywkzsCuQEE=; b=Sq8VJqeMMVAW+HhHwmBoefB78zv3aqKFmtPLTQfZW+DSOI2fQaxueB5f/URpV48EWmHOdh 0TCOX/fr0GvyVOUGrvdu2WVHIedS02RJ++mOMa96JOnY6PtTwC+JBijtPVGHcW2JmSdl1a p/nxtP7O+TnkD+2s8PNxa5nkeyvXT+A= Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-13-nm4gKlnDNE-L9galCwEr3g-1; Thu, 13 Jul 2023 10:55:59 -0400 X-MC-Unique: nm4gKlnDNE-L9galCwEr3g-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 640A63815F7E; Thu, 13 Jul 2023 14:55:59 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.39.192.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id B0225F66D7; Thu, 13 Jul 2023 14:55:57 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, virtualization@lists.linux-foundation.org, David Hildenbrand , "Michael S. Tsirkin" , Jason Wang , Xuan Zhuo Subject: [PATCH v1 2/4] virtio-mem: convert most offline_and_remove_memory() errors to -EBUSY Date: Thu, 13 Jul 2023 16:55:49 +0200 Message-ID: <20230713145551.2824980-3-david@redhat.com> In-Reply-To: <20230713145551.2824980-1-david@redhat.com> References: <20230713145551.2824980-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 438A7160011 X-Stat-Signature: su1hu5njrxxkdfr4yws4qccuz71r3sje X-HE-Tag: 1689260161-590143 X-HE-Meta: U2FsdGVkX18MVlDJmLtqIu6/s6e53AzGQTGNq4XHresrF9m9Gg3zIk6D0I0yf3uDfLbhKkdKYb/p02qv4Zq7+HoNc+5WLJKMJWVfd4UUgJTWVbHOTluIPxb1rCkWjAolFtnKXR8n46Nwu978Hc8Z1qRaV1e9P4/2JU5r0vVEd5TeLbHeAWOoTz2ZX432G4m7pbdopI5/xonL0l3qX7AKRbzT2/e8Dj4h462+jFz7wH/Zw/8MngCHkwg4mk4cfyWXX/x3epLVDchWdQVv9umI8oFIGGoWWkGtke9G0HKe9nM1fotp4hMQ8KefP9Lnq45HlcnZW69zGVb/o1+VUTA7gW/q+4vayQ1JeNAmMhh9QFSI0FhmYO8ZEtAPdgTZx+3EkS6Ck64f9kXFXsrgrhqlboPB7gSEKhxR8YCP53pyaz15Fk7MaSpFQYAcIxulMhLrhRf/ZDX6oMGRal6QxfE8GAZt14hwt6D27xnHMfqAjGbOt+AVOY+1INFbKpRKUaACzZ4JZYObQOIN33jlAnp5Kr3HodxA+Oxp5AAsjx6EL9KClsG9j5PyCrGmfbnTYaLEG5v2FkD5NzsByvS3AMOlYjuuS2XKm1/fEGGqQynxyc2okC9tt4L7h46E9f3T254h8accu5H7DJ7sBhriCbQMxjk4vNMFtrWeVl99+sOedWOnMzSUVywmtBAzhhpBFbMXAPaOQqTYOBnBk+rSb2SVHogKhpXJU2kXSu2K4TJ3YfIclmb9vIQexO6Brv3ihFSCwfpUo8fXpYNZc9VFBO4zCJQ2ulqfn3NF+QBOfTZJqXYTPYdej8kKvadrWlbETeWjld5G3CZTo4QW/+pXQM1WGRDWU1l6SMFOJNhNZ60ywfFWYlpZnX1GZgjiWCaaY0HwQ9Y5t5vH3NNJH0Qev9uSpqmglJ6S1P15eFyK7sW3g4VbfPtehg6b+gEBarKRkg0d7ZzS5gL2Yr1Hfo5le8W KgJiNAVm B2CQNUzrcn69hiU9oNzTYL7Wa7eU0wAOnnDBewh9ey57Gh1SslKcqiEyhoxmoAUY8gWAoZITwT/xQnqdMQSbp1+7b4BZZJoO9xfVAn5OGMT4kYuCO858m635OcqbpieSxKZSXrCwRx4uFfc7fwgGUzv63mNbGBMcPirNvIQs3O3WYDmXYGpXum4YhcfOn3wjo8gQp3iNsteLZbcnNtod9obk0zA== 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: Just like we do with alloc_contig_range(), let's convert all unknown errors to -EBUSY, but WARN so we can look into the issue. For example, offline_pages() could fail with -EINTR, which would be unexpected in our case. Signed-off-by: David Hildenbrand --- drivers/virtio/virtio_mem.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c index ed15d2a4bd96..1a76ba2bc118 100644 --- a/drivers/virtio/virtio_mem.c +++ b/drivers/virtio/virtio_mem.c @@ -741,11 +741,15 @@ static int virtio_mem_offline_and_remove_memory(struct virtio_mem *vm, * immediately instead of waiting. */ virtio_mem_retry(vm); - } else { - dev_dbg(&vm->vdev->dev, - "offlining and removing memory failed: %d\n", rc); + return 0; } - return rc; + dev_dbg(&vm->vdev->dev, "offlining and removing memory failed: %d\n", rc); + /* + * We don't really expect this to fail, because we fake-offlined all + * memory already. But it could fail in corner cases. + */ + WARN_ON_ONCE(rc != -ENOMEM && rc != -EBUSY); + return rc == -ENOMEM ? -ENOMEM : -EBUSY; } /* From patchwork Thu Jul 13 14:55:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13312327 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3B455C001DE for ; Thu, 13 Jul 2023 14:56:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CA66390001C; Thu, 13 Jul 2023 10:56:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C57E56B007B; Thu, 13 Jul 2023 10:56:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A82BF90001C; Thu, 13 Jul 2023 10:56:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 9B6826B0078 for ; Thu, 13 Jul 2023 10:56:08 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 650F9B03B4 for ; Thu, 13 Jul 2023 14:56:08 +0000 (UTC) X-FDA: 81006888816.15.762E4DD Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf26.hostedemail.com (Postfix) with ESMTP id 52DD1140026 for ; Thu, 13 Jul 2023 14:56:06 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=cT3GAHcd; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf26.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689260166; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=/51NS5IdbGhAF1WTe4etoP/bWkQWV6fSApbrFXQZ0Fk=; b=U12wp1AYq5YyPqe90GRhrinJFDZxx83KkDvJ/rT86Pc8YDZAiavu7Ea86+8kZx1HRptmck HL65LC32/mGLitWz/3sGJbMd5hl0npAiY8kRikFEGPe38JllA4gAhaKzYaLLltX+UsvSir FxPJtk4jZrPkYqe8i0sL0sIi9T89a8I= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=cT3GAHcd; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf26.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689260166; a=rsa-sha256; cv=none; b=D5y3JA3gqa8pCCpz6pRHJ1Xvu2DqxmtFfISIeo7m/hkqxwO1AFeJ6KAerADhhp8nLvdddT OP7RhnUqrjiTxl4c77HRlWvNXkBaM1a5Jyo5/I/cMMiey/ljhWsymXG1QjukavNsl3YmTP dzS8V7KZtp6TpQEF0jssE7nou3cPrTo= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689260165; 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=/51NS5IdbGhAF1WTe4etoP/bWkQWV6fSApbrFXQZ0Fk=; b=cT3GAHcdCMQ6jimAJQcgCQMJtqPvjFJaqjSE3TpXOjRlzPh0XWuV0vyxYMSbFxKejRy42M PfBktahuYoCIi44iy5azBjA31yVOkbzmqZG3sirqrLVF1lVmzJp7qRcanmfY4NAXsV4nwH CuxHY6ApF13i2aMx1mbzXcomG4tDv84= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-669-Cnd2LY13MK-Zy4GC5ZFc9w-1; Thu, 13 Jul 2023 10:56:01 -0400 X-MC-Unique: Cnd2LY13MK-Zy4GC5ZFc9w-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C7FA283FC20; Thu, 13 Jul 2023 14:56:00 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.39.192.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9F036F66D1; Thu, 13 Jul 2023 14:55:59 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, virtualization@lists.linux-foundation.org, David Hildenbrand , "Michael S. Tsirkin" , Jason Wang , Xuan Zhuo Subject: [PATCH v1 3/4] virtio-mem: keep retrying on offline_and_remove_memory() errors in Sub Block Mode (SBM) Date: Thu, 13 Jul 2023 16:55:50 +0200 Message-ID: <20230713145551.2824980-4-david@redhat.com> In-Reply-To: <20230713145551.2824980-1-david@redhat.com> References: <20230713145551.2824980-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Rspam-User: X-Stat-Signature: 54wsfe8wyqhw6nuwitqhpnfzz41ij77s X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 52DD1140026 X-HE-Tag: 1689260166-669354 X-HE-Meta: U2FsdGVkX195f0TYu7W19VFvlTlUePxsSUholySTjvoYWWeNyG9bJmRJamLhXTN6WcC+/kQqduT7jMiCvyThBV6ZCtqnGy06zDAP2x6HdB0VzLIzWNgJenj9DUbraDm/979Cnz724jUl6d3/Q4XT90urUhoUcE+q4QrKEGREMikh/C28cHfXyZtsoDlRzV+SZfZ6s7umFl9U9jg0HuX6b3mmXCSWXF3+0B1hN7lcnxGHMJiNnpNv0TArhSjDjtDDkGRd2v308kpUyPBCxlgHQs1QU7WiOWBQIvoea/0O5RFuKiyMtOerVq/HKp+G9QM5OLg8j5/8coR1iiceskkth6MZC5MT6pX1qCBTYPnwxtHpzYJh6oWw3gpEfb2sYV+6ZJD1blTKOc2b8mCkAfYgFA0eIOK0oHL376SDqmpTgUXVwSSRwYYYL/riVv/bmxdC8+50pkJMcRvfEnBouSCoYaGEa/u5Ei85nmOXiKRh5Yy0BOjKLyXK3313r7udnfBh1fJ9+6RPv61uhM6U7rqDPRL9gsr5fiJB8xkVCTbDZqrIBC58MEAo3l1PEfsDkjPWhQCiIMaaRbcSCL2C15TOSYmV1RrD8zXCEjIVs8V0TjX7xPhYaDlMqvjVygddlhfLz9dnCl64/B/blfyVORmRl1M27z+QCerdxBMhEYcfYlo92za4ydvVNsXNnrhi8BU5b+NaK9WhcWoZmt5t/gflbCSGmnI3Qe8Js8OEg8c+x82HAb4QEmcK/IjpjBjIDjioBFqIz1BnzGU30fme+QnPRD0rsiIo2CibQT+pML8+1rQjF2R1t8DYLh9pMfOz6lzkUYkJI9b+VscSVLHYWfgV8psDpjXCygzB1mCO/P3CVGV6II01bAb263Pf+3ciSNfMaw4nz7zPRrg5kpgUWpmV41YjFURCBNDNZKZ9frIAgC5V0m1DJarHVKY3CL65F4E5FDAp8BwI8Zdw/TznYX9 SSNYtSfR bWfoRmSVtGhkn6Eg6+D7lvKOUOps8BRDC0Cjq6EfyPA0SWjKxyndLTR92H6zOtAYYjNGIXbUsd1PFG7wfyWHQD1NoHZJF/vweb2vT+GVE7xq9CqAFhTrHKA0Iry6B+y+SPgJVpVoGtua4vf5X5NwV8f1k/XHjxloUe84wAmiJGH2FkjweDQ+jKA8tnjWe7+4iazZiizMPKyxbGfFtCRl6+Pd2Aw== 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: In case offline_and_remove_memory() fails in SBM, we leave a completely unplugged Linux memory block stick around until we try plugging memory again. We won't try removing that memory block again. offline_and_remove_memory() may, for example, fail if we're racing with another alloc_contig_range() user, if allocating temporary memory fails, or if some memory notifier rejected the offlining request. Let's handle that case better, by simple retrying to offline and remove such memory. Tested using CONFIG_MEMORY_NOTIFIER_ERROR_INJECT. Signed-off-by: David Hildenbrand --- drivers/virtio/virtio_mem.c | 92 +++++++++++++++++++++++++++++-------- 1 file changed, 73 insertions(+), 19 deletions(-) diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c index 1a76ba2bc118..a5cf92e3e5af 100644 --- a/drivers/virtio/virtio_mem.c +++ b/drivers/virtio/virtio_mem.c @@ -168,6 +168,13 @@ struct virtio_mem { /* The number of subblocks per Linux memory block. */ uint32_t sbs_per_mb; + /* + * Some of the Linux memory blocks tracked as "partially + * plugged" are completely unplugged and can be offlined + * and removed -- which previously failed. + */ + bool have_unplugged_mb; + /* Summary of all memory block states. */ unsigned long mb_count[VIRTIO_MEM_SBM_MB_COUNT]; @@ -765,6 +772,34 @@ static int virtio_mem_sbm_offline_and_remove_mb(struct virtio_mem *vm, return virtio_mem_offline_and_remove_memory(vm, addr, size); } +/* + * Try (offlining and) removing memory from Linux in case all subblocks are + * unplugged. Can be called on online and offline memory blocks. + * + * May modify the state of memory blocks in virtio-mem. + */ +static int virtio_mem_sbm_try_remove_unplugged_mb(struct virtio_mem *vm, + unsigned long mb_id) +{ + int rc; + + /* + * Once all subblocks of a memory block were unplugged, offline and + * remove it. + */ + if (!virtio_mem_sbm_test_sb_unplugged(vm, mb_id, 0, vm->sbm.sbs_per_mb)) + return 0; + + /* offline_and_remove_memory() works for online and offline memory. */ + mutex_unlock(&vm->hotplug_mutex); + rc = virtio_mem_sbm_offline_and_remove_mb(vm, mb_id); + mutex_lock(&vm->hotplug_mutex); + if (!rc) + virtio_mem_sbm_set_mb_state(vm, mb_id, + VIRTIO_MEM_SBM_MB_UNUSED); + return rc; +} + /* * See virtio_mem_offline_and_remove_memory(): Try to offline and remove a * all Linux memory blocks covered by the big block. @@ -1988,20 +2023,10 @@ static int virtio_mem_sbm_unplug_any_sb_online(struct virtio_mem *vm, } unplugged: - /* - * Once all subblocks of a memory block were unplugged, offline and - * remove it. This will usually not fail, as no memory is in use - * anymore - however some other notifiers might NACK the request. - */ - if (virtio_mem_sbm_test_sb_unplugged(vm, mb_id, 0, vm->sbm.sbs_per_mb)) { - mutex_unlock(&vm->hotplug_mutex); - rc = virtio_mem_sbm_offline_and_remove_mb(vm, mb_id); - mutex_lock(&vm->hotplug_mutex); - if (!rc) - virtio_mem_sbm_set_mb_state(vm, mb_id, - VIRTIO_MEM_SBM_MB_UNUSED); - } - + rc = virtio_mem_sbm_try_remove_unplugged_mb(vm, mb_id); + if (rc) + vm->sbm.have_unplugged_mb = 1; + /* Ignore errors, this is not critical. We'll retry later. */ return 0; } @@ -2253,12 +2278,13 @@ static int virtio_mem_unplug_request(struct virtio_mem *vm, uint64_t diff) /* * Try to unplug all blocks that couldn't be unplugged before, for example, - * because the hypervisor was busy. + * because the hypervisor was busy. Further, offline and remove any memory + * blocks where we previously failed. */ -static int virtio_mem_unplug_pending_mb(struct virtio_mem *vm) +static int virtio_mem_cleanup_pending_mb(struct virtio_mem *vm) { unsigned long id; - int rc; + int rc = 0; if (!vm->in_sbm) { virtio_mem_bbm_for_each_bb(vm, id, @@ -2280,6 +2306,27 @@ static int virtio_mem_unplug_pending_mb(struct virtio_mem *vm) VIRTIO_MEM_SBM_MB_UNUSED); } + if (!vm->sbm.have_unplugged_mb) + return 0; + + /* + * Let's retry (offlining and) removing completely unplugged Linux + * memory blocks. + */ + vm->sbm.have_unplugged_mb = false; + + mutex_lock(&vm->hotplug_mutex); + virtio_mem_sbm_for_each_mb(vm, id, VIRTIO_MEM_SBM_MB_MOVABLE_PARTIAL) + rc |= virtio_mem_sbm_try_remove_unplugged_mb(vm, id); + virtio_mem_sbm_for_each_mb(vm, id, VIRTIO_MEM_SBM_MB_KERNEL_PARTIAL) + rc |= virtio_mem_sbm_try_remove_unplugged_mb(vm, id); + virtio_mem_sbm_for_each_mb(vm, id, VIRTIO_MEM_SBM_MB_OFFLINE_PARTIAL) + rc |= virtio_mem_sbm_try_remove_unplugged_mb(vm, id); + mutex_unlock(&vm->hotplug_mutex); + + if (rc) + vm->sbm.have_unplugged_mb = true; + /* Ignore errors, this is not critical. We'll retry later. */ return 0; } @@ -2361,9 +2408,9 @@ static void virtio_mem_run_wq(struct work_struct *work) virtio_mem_refresh_config(vm); } - /* Unplug any leftovers from previous runs */ + /* Cleanup any leftovers from previous runs */ if (!rc) - rc = virtio_mem_unplug_pending_mb(vm); + rc = virtio_mem_cleanup_pending_mb(vm); if (!rc && vm->requested_size != vm->plugged_size) { if (vm->requested_size > vm->plugged_size) { @@ -2375,6 +2422,13 @@ static void virtio_mem_run_wq(struct work_struct *work) } } + /* + * Keep retrying to offline and remove completely unplugged Linux + * memory blocks. + */ + if (!rc && vm->in_sbm && vm->sbm.have_unplugged_mb) + rc = -EBUSY; + switch (rc) { case 0: vm->retry_timer_ms = VIRTIO_MEM_RETRY_TIMER_MIN_MS; From patchwork Thu Jul 13 14:55:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13312328 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D904EC001DD for ; Thu, 13 Jul 2023 14:56:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8D742900035; Thu, 13 Jul 2023 10:56:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 85FFF6B007B; Thu, 13 Jul 2023 10:56:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 70141900035; Thu, 13 Jul 2023 10:56:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 62C3E6B0078 for ; Thu, 13 Jul 2023 10:56:09 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 429BFB015D for ; Thu, 13 Jul 2023 14:56:09 +0000 (UTC) X-FDA: 81006888858.05.C639893 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf17.hostedemail.com (Postfix) with ESMTP id 1B23C40002 for ; Thu, 13 Jul 2023 14:56:06 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gNSwROuc; spf=pass (imf17.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689260167; a=rsa-sha256; cv=none; b=ExoMkVfURw8JVZAsCa9Y2zYLDibLNPNFRHXtwbP11iuEdOEZaloPCbURzh3YbYqb9LntX8 pTBY/sKmOmtLWhEWoglYTDek4nCPU9BBiT3SRVU68x28O326pKVBPBtHY0MAo0Gqe4NNbL lByplhC3DiWlaINaUe2Tc1FxVd1xf1A= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gNSwROuc; spf=pass (imf17.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689260167; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Bk+toP/Ed4qPpAgMLWeptgvuADn7go/7Jo6jlttF96s=; b=doNMHz2E6IxQP4QOv+/gLPg7kxEbS0B4etIdnDW8XLVbDZUhSZ8ktc/RW0USzghE0d+gh8 uGdB0RdlYy8Jevt1EZUY+zf60a76ix0UXshNCS3L75RvFa2ktqgokKUOisslvI/vjvUpNX hq4LD+EwDTYpzcmB1iuPTWPjI41OAak= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689260166; 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=Bk+toP/Ed4qPpAgMLWeptgvuADn7go/7Jo6jlttF96s=; b=gNSwROucsZMlcoBwn+p2eERWuaXeVuw+ri+Gq2TpGXSI3q7kzYg33kF9tQXZx3K5T6J9dH NC/cKna0b6CNW7GLFa17Rt/WRrMgnBOuXgOfSbZTPPNWhXCER+4RI5KaUX8ddsaXfqsO0i IBJ94gFqHvglentirGpwYhLealUd3l4= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-351-pEnhlwaAPsitRYud8qL9ig-1; Thu, 13 Jul 2023 10:56:02 -0400 X-MC-Unique: pEnhlwaAPsitRYud8qL9ig-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 58A8086F122; Thu, 13 Jul 2023 14:56:02 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.39.192.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id 197A0F66CB; Thu, 13 Jul 2023 14:56:00 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, virtualization@lists.linux-foundation.org, David Hildenbrand , "Michael S. Tsirkin" , Jason Wang , Xuan Zhuo Subject: [PATCH v1 4/4] virtio-mem: check if the config changed before fake offlining memory Date: Thu, 13 Jul 2023 16:55:51 +0200 Message-ID: <20230713145551.2824980-5-david@redhat.com> In-Reply-To: <20230713145551.2824980-1-david@redhat.com> References: <20230713145551.2824980-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 1B23C40002 X-Stat-Signature: riru7fepas9ozfwmer91ggr9fgkg4jt5 X-Rspam-User: X-HE-Tag: 1689260166-616672 X-HE-Meta: U2FsdGVkX1+twlQ7psaXK8YpcLddM0U/phEelYkoRVPQJQVa3f1FpmwAwT5DIf6lDr9/+S4iGdZ/pBiO5hzZynxbnhZTd1HNPoQJ6PpGTB5XookSsy4TvfhLvly9ovT4Dok7sVHgCcqy0A4ck80+nggJZgr3qQiBY2NA2UmwExBc6L29A0B2/Qm9UC0rSzx/ouBMVDyNG+GCJ3QPN94rkXwcsydSn1p4H6qFIf27tEg6eNyvHR322UM0cmxOIpCGIeeSFG9Tsc88KZnfF7icvEUm3XazvFvAZznKx/BeiEkXPLfFPh399BKLMqZJjx33rRf9LrnR43Gmf3+8LTDC/W9anxRsJZUpxpB0LQ7NaOx7FVXYd0D62PuYb3H3JRKg7HssgYHolTKp5DnYv26qnexCqWYH+R2Bl82U/JLCxlsLDz8eW9QvUTsmi2i3WDRobtB4lD1qgSyPJVn4xgp4s9ANHE3w/Fuc8eWQbz7XrR0Z0oDnf4nrgEUpL/w+bVU65LlA2YgmrP+/zzNwXRIKlBrKWd88W2nvl9kNnuQTMkSIF4MP5aSBDKsCW5/pcAdCG5TbvU7jDqD6bPBHxaA+KpTc1PU/RXiM6H0DI4F+xy8v4rqOxHUda7XObtpnXhqKm9Zc9StKd8zQijzdfzvCpqvF1b3EmaWqO5/9GeP4FP2PialBNwL5AKJ0sc1w8s296EPS17Vx62emMl/4OHnmU7XBZadH3/Fpp/dAyRHTq3s3jqefBtvN0aYhI1XIlPFuutVjaZTEJejWgTD+2u3a6HLEorDx9BhAabwYwzOdH1Pix1Cyt9tr7BblE0nUqGNYT/WLAizW+njAwiwbcHDHEldCQrs26jGD68ddCpobi4o44Yeq6x850uiGybvoUXTmY+8pvfCigY589b44wkCx6UoFI5i1OGKIIBNre4RfHhPlOJWmEs3jElSwaDrncsjYDpmA0JhhtvYTzdLrEXJ xRmiR2y5 UUPmumoYw6qitDVGOi49Cr/QoijwdKsCNEYwj1ke037OZNphC937zRRnJhf1PZycquW/xPuSicrG71kenwxQG5wh9X6bLCFcRAT/0888Hckm9ggB5NgHyBNClFB2p+qC58bh4PumHzGSthqGR4V29p1FcVn8AMNi6aU3coipX1G17FOQeHRjJdUoSeTbyUER/KAGIZ2AnC6P4xmc= 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: If we repeatedly fail to fake offline memory to unplug it, we won't be sending any unplug requests to the device. However, we only check if the config changed when sending such (un)plug requests. We could end up trying for a long time to unplug memory, even though the config changed already and we're not supposed to unplug memory anymore. For example, the hypervisor might detect a low-memory situation while unplugging memory and decide to replug some memory. Continuing trying to unplug memory in that case can be problematic. So let's check on a more regular basis. Signed-off-by: David Hildenbrand --- drivers/virtio/virtio_mem.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c index a5cf92e3e5af..fa5226c198cc 100644 --- a/drivers/virtio/virtio_mem.c +++ b/drivers/virtio/virtio_mem.c @@ -1189,7 +1189,8 @@ static void virtio_mem_fake_online(unsigned long pfn, unsigned long nr_pages) * Try to allocate a range, marking pages fake-offline, effectively * fake-offlining them. */ -static int virtio_mem_fake_offline(unsigned long pfn, unsigned long nr_pages) +static int virtio_mem_fake_offline(struct virtio_mem *vm, unsigned long pfn, + unsigned long nr_pages) { const bool is_movable = is_zone_movable_page(pfn_to_page(pfn)); int rc, retry_count; @@ -1202,6 +1203,14 @@ static int virtio_mem_fake_offline(unsigned long pfn, unsigned long nr_pages) * some guarantees. */ for (retry_count = 0; retry_count < 5; retry_count++) { + /* + * If the config changed, stop immediately and go back to the + * main loop: avoid trying to keep unplugging if the device + * might have decided to not remove any more memory. + */ + if (atomic_read(&vm->config_changed)) + return -EAGAIN; + rc = alloc_contig_range(pfn, pfn + nr_pages, MIGRATE_MOVABLE, GFP_KERNEL); if (rc == -ENOMEM) @@ -1951,7 +1960,7 @@ static int virtio_mem_sbm_unplug_sb_online(struct virtio_mem *vm, start_pfn = PFN_DOWN(virtio_mem_mb_id_to_phys(mb_id) + sb_id * vm->sbm.sb_size); - rc = virtio_mem_fake_offline(start_pfn, nr_pages); + rc = virtio_mem_fake_offline(vm, start_pfn, nr_pages); if (rc) return rc; @@ -2149,7 +2158,7 @@ static int virtio_mem_bbm_offline_remove_and_unplug_bb(struct virtio_mem *vm, if (!page) continue; - rc = virtio_mem_fake_offline(pfn, PAGES_PER_SECTION); + rc = virtio_mem_fake_offline(vm, pfn, PAGES_PER_SECTION); if (rc) { end_pfn = pfn; goto rollback;