From patchwork Tue Jun 27 11:22:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13294363 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 94C6BEB64DC for ; Tue, 27 Jun 2023 11:22:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 142558D0002; Tue, 27 Jun 2023 07:22:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0A6AB8D0005; Tue, 27 Jun 2023 07:22:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E36228D0002; Tue, 27 Jun 2023 07:22:35 -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 CFCE08D0001 for ; Tue, 27 Jun 2023 07:22:35 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 9E98F4097F for ; Tue, 27 Jun 2023 11:22:35 +0000 (UTC) X-FDA: 80948289870.21.1ED0E39 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf12.hostedemail.com (Postfix) with ESMTP id A432840009 for ; Tue, 27 Jun 2023 11:22:33 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=INgvN7iw; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf12.hostedemail.com: domain of david@redhat.com designates 170.10.133.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=1687864953; 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=2tWgJbMty0vF+sRGgcNfqljzE54wPeczugMOQkaZlck=; b=aMUq0G6Fj71t5il4LKRPkg610NPgnBvSuVSNqZwMgLZ+V8seUwM7lY2Kgqa5Qmoc8MN4rN Hg2IHb4c637DaZtSOlPaj8UQU/TVp3qGMwHTc0iPySdbsah2Y5Xmegfq9lnlISKxNTJB0P MCG4/dGLYa+WAcRZTVYwkYSODRoqrfs= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=INgvN7iw; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf12.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687864953; a=rsa-sha256; cv=none; b=Xi7B+bC1RyMcPnbHTga8h66To83Kv4C3q50tYmKRMTO668rW6yOKdquC3vOZ00aY6OXeNX OPMrsUJ25KjHlfaSsBzdVGQE8Igdg/HssihUZN2vxTbfM/5UbpoJF6Hkw1vBSVpPjV+YeQ WUACopcYUD1ud+SJTtyOrQ90N2kd8Gw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687864952; 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=2tWgJbMty0vF+sRGgcNfqljzE54wPeczugMOQkaZlck=; b=INgvN7iwmHzx+7mw9lO1K3VTQ7BRQbiF4kf8wnJNs/dN/dRgTUVKhLw4jwrDE02xOEbzRB 7h7wpGORO97bp+1bXWUKIA/cEKK4rbkvH9XQQsmbCa0kYA80rE6mUPezccBi/o5/BA7m5t Es2UV9di4oUB42GgRFUwDHhsNbkhZhA= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [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-636-FJnFfwwzPY-Qr_PfD7F3LQ-1; Tue, 27 Jun 2023 07:22:30 -0400 X-MC-Unique: FJnFfwwzPY-Qr_PfD7F3LQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C720F381494D; Tue, 27 Jun 2023 11:22:29 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.192.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id A1185200A3AD; Tue, 27 Jun 2023 11:22:27 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, virtualization@lists.linux-foundation.org, David Hildenbrand , Andrew Morton , "Michael S. Tsirkin" , John Hubbard , Oscar Salvador , Michal Hocko , Jason Wang , Xuan Zhuo Subject: [PATCH v1 1/5] mm/memory_hotplug: check for fatal signals only in offline_pages() Date: Tue, 27 Jun 2023 13:22:16 +0200 Message-Id: <20230627112220.229240-2-david@redhat.com> In-Reply-To: <20230627112220.229240-1-david@redhat.com> References: <20230627112220.229240-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Rspamd-Queue-Id: A432840009 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: iogjzq18foxiebgncna4n19go9wwf5yc X-HE-Tag: 1687864953-967085 X-HE-Meta: U2FsdGVkX185KC/t+qEg7TX0e4f4Btj7507ubudJB8u7NShkJVJLhGDK32zUE+KtVGimBIZPU16VYELUrJ8fi+b4QDUs8c/M35EpDc7vRq90Iz83+DXCr2gH021DZYYQuBVVcDnFR0V0WMTtvKyLgrxIlgofrlnBNkjJ1cuIvF3HxLle9lFEACyMY0Y+y2n1YsyJlw8bdLqQFmxKkWGsU+D0RO+6KpnW87MDY7vUhPYP1sNaQc0lDYm09j/FodOYsUfrp209UKWpD3nI5BQX/bPhOWMLPe4oIAKc9OKWwRKMLFlDcEVdZ4ntFyVzLWgC4maUFatu5JsuTkAo+86JCwFRQuUZtVsn1mIm8iUt2ls1v852fngQgh/jG4oU45x0lm8zvozfu0Fap4rFU/xtruhpWA7ZuF3M/VklYXpCdnSCDR++KbL4whAfqUKZGiCKfe+qDFz6PQxYV1qaLmnmBsDtSTlOXu7QhYP5fXgq72ZBDHnqT/Hy36NPkPHsNtugQyZTu2vIRqVMZW16inDYBX3iQp79jFFCFtXueHhab0DuNq5Zcbh5DzBjZznRkY8/QgAkooeVqpzHNRyd39VbH0zDg+x08cV6en3lEoJyBV3LorGsyxpUNvUI9ZZ74uUyJjEj2GpOSzC2A3cdVsMpESkCK0sygMdisPgCF6njB82zen76ZlJFyntBMVxg4x2JtCehGvFfbBT+ZEcZgo3VwfjwRLBo2eNC6lrOg+dB2mOUgAHd9Q/HeprgEFXM1tWElOlYjS8GFXjOuwRqqhmmQFOD5IFOCKIkDmN9kvl3Bn+hTI/B3YZ0JKwmWCH+WMVSgdw21SSu9R2415UnSbGilua6suvCibK/i7LtqS0mQIbVfCv/xeO/6/R0Vh/3mQ8yGOHCbtZUHwK/slqC1o2hfpi5PQIY40EeWKqlwW00wVt1JSGNIgEd8J5wjvUP06Kiklt5xuix0RHNTpsewnl qrAK5Is0 /hvKYUW3yOkcBU9REoc+fTJYJl7KK+ejrPJ8PsO6Z4xWGPsbe5z2rPFsAlphzmUV46UD9RYfvbV71LArna5Panf4+9sotIOkjCGZFdCVFvWiHPFl5cKC3e2ZA3XkEilMCWhvFHS9PlX1emiXvGks0xRKVCJUPdR/uVH933ZEad3cJKa3S6QzqHhDSIsfHNxrhiocRMsyii0YlF6n0zQoea66k6Q== 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 check for fatal signals only. That looks cleaner and still keeps the documented use case for manual user-space triggered memory offlining working. From Documentation/admin-guide/mm/memory-hotplug.rst: % timeout $TIMEOUT offline_block | failure_handling In fact, we even document there: "the offlining context can be terminated by sending a fatal signal". Signed-off-by: David Hildenbrand --- mm/memory_hotplug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 8e0fa209d533..0d2151df4ee1 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1879,7 +1879,7 @@ int __ref offline_pages(unsigned long start_pfn, unsigned long nr_pages, do { pfn = start_pfn; do { - if (signal_pending(current)) { + if (fatal_signal_pending(current)) { ret = -EINTR; reason = "signal backoff"; goto failed_removal_isolated; From patchwork Tue Jun 27 11:22:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13294365 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 34A6DEB64DC for ; Tue, 27 Jun 2023 11:22:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3B1A18D0006; Tue, 27 Jun 2023 07:22:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 29FC08D0003; Tue, 27 Jun 2023 07:22:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EF8AC8D0006; Tue, 27 Jun 2023 07:22:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id DA76C8D0003 for ; Tue, 27 Jun 2023 07:22:40 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id A40C84097E for ; Tue, 27 Jun 2023 11:22:40 +0000 (UTC) X-FDA: 80948290080.08.235690B Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf18.hostedemail.com (Postfix) with ESMTP id 8DE1C1C0019 for ; Tue, 27 Jun 2023 11:22:38 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=X0aJpT8D; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf18.hostedemail.com: domain of david@redhat.com designates 170.10.133.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=1687864958; 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=4aSs18Pv+ZzmA9Rj2C8nVvP+WDMPcyKRh1O4HH29Hbc=; b=fQs85jFQOBEFIcG6RgIruLmC6epCCkkUIWCxnYt1xCZ2FEJfRDC7gvmkb1nSi0qIlI81H6 +MQWX6r7rVFsao+iZRl1W51hOumzTzOrdzjzeXOJv+N4vfrMfXCtAth0RtAEP7PTWM7UOg QHVmyHRyoj5RMUNPE4PPzXJZifpyuz0= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=X0aJpT8D; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf18.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687864958; a=rsa-sha256; cv=none; b=sc91VSoYHxC92Kt8nkB4J835ELYW2/NjqcIwNSTGbxpcJNEfIHheSFDSgzWhiAY48lLsoL 0l8IzgdOet+VrFStKVSC4VxeZxNbea4Ib6CR+nYAhS6gRVh4yciJvSxoFK/zQtDdn8pM4c KDRbN6cBcZmkKGd/3NRyGDz/KhIOVIU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687864957; 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=4aSs18Pv+ZzmA9Rj2C8nVvP+WDMPcyKRh1O4HH29Hbc=; b=X0aJpT8DcdBXbEIJH7x/ucE8oKFRerQwSotFEHYsUFu/wOgPp9YlhPOAWP91TprPjo7LZh VG7dhqZ8qyn6ZE9pHwOSgZwnc6uPwdXVSPV+vJdSey1D2GN39cl7mDeK+DyqUPiwUyS7a8 dNgezmrpoLPwOqsaU3yNmkzf1pc+/Pk= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [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-266-y_sQWVhBPMapPH_5wxp9qg-1; Tue, 27 Jun 2023 07:22:32 -0400 X-MC-Unique: y_sQWVhBPMapPH_5wxp9qg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CA5553814947; Tue, 27 Jun 2023 11:22:31 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.192.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id 30867200A3AD; Tue, 27 Jun 2023 11:22:30 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, virtualization@lists.linux-foundation.org, David Hildenbrand , Andrew Morton , "Michael S. Tsirkin" , John Hubbard , Oscar Salvador , Michal Hocko , Jason Wang , Xuan Zhuo Subject: [PATCH v1 2/5] virtio-mem: convert most offline_and_remove_memory() errors to -EBUSY Date: Tue, 27 Jun 2023 13:22:17 +0200 Message-Id: <20230627112220.229240-3-david@redhat.com> In-Reply-To: <20230627112220.229240-1-david@redhat.com> References: <20230627112220.229240-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 8DE1C1C0019 X-Stat-Signature: 51ongstw6ae758jsx9k3zood3mmn3r6n X-Rspam-User: X-HE-Tag: 1687864958-584169 X-HE-Meta: U2FsdGVkX1+t4RN3I1Tj/2VYvLDI7PpxMYuVsFSTAsgQDlA6a3JD/hSUBs3GCFJLWmLpn8dOx6Vl9/FfLH7BrCBGH7d8YZnS3Yqo389K+feNGdr3ABuVqBuzPqgJocnyO4CzU8rrwFZ6awA+EwjuNkCfXDdFIoKa3U0kcVkTU4yJPpO7cbNXsSwWkjLPdWf6nwfBoO1TFpvoXWp47AXNs4zJq5TVnbPyVYjB5RHJRK113kJ3o5DOCkzPuJNoPeOGRHuZY5lHCb6/m/BtI2lTqTopj1jXWsLVOVYWyC/+0pAnxyz6oN2evDcIAyJ44y1TWbFWvGP4b23/ditMLS8UqdBjvloKgDhp7+8ssyVW3RpeyYuExw8WXTKUuI/oJNXiVYLT7JLNBkrzfFxV+aCXmDHWj4D2InfxfWqzmWfvWBd88YgBO9BXs+xC/4hM6ONKNoysuesmzHKnQ5CarefnNwInrkjmawK0YCaFnRs8+mX18hCwL/9CEAywooHzaAqV7wzRS/Icg0gnfKFAfdE1nGb0Als+aV8k7guc4fRr4N65nAMHjdE6wRB3N9Rb5ZOZ60Q5/yUpcYdV58CwnVazlkJKkYtG8GKPmGG4NyQ5Ev5Nas5ru3m/0W2rrf1Z77EVbCs/NXcbxyS1eWzJIjDnNsgPHTYYPuzVs8+K/osYApcVVARmSsacc9RHfQutTKhM9lByXprESKxqFBQ+QHFkwhdSeDqOA+lEBa1mcf/U0jKF6wfoQTzhcSw5br4PC4PNPP5vOZ11DjrPV8Eq8Lh90rDn6Y29zNRYA5RVd0H65QN8EYtZzhexbtXCSTtPrCmCHIaDyGnmT7K4uMFcmSjq7EHrOLmnZXEPP1oUNS8vptyZVya5RcJZ8i/c/68dez6c/nGmDIsrtQTgFUQEB5wPqfh0JFUMULOZZ5PhFFn37IKPssTdE05/X4LTGMyDC9omsFGGy9btzzlZM9lTl7V 6Mu7uRqk 3oJTwCyGM/SVPttB9V0Qavj5WpmdlNEUgjG3Vh46UUuLYEPM4kOJaZJAr46YzEv5XQGf//h+mexUhwRw6mqhThRxv5fzW4/G0Apq8OkfciqJHZRhrP3xOI/Y5XEZMABPj7MH5No4zZIAvQf512elOawHb+yQv1JFS8syIQ08LZo7simJWtaksIEhRZLWeR4AzcRJCgpaR3ohlbHfT3blUWVIc/Q== 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 prepare for offline_and_remove_memory() to return other error codes that effectively translate to -EBUSY, such as -ETIMEDOUT. Signed-off-by: David Hildenbrand --- drivers/virtio/virtio_mem.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c index 835f6cc2fb66..cb8bc6f6aa90 100644 --- a/drivers/virtio/virtio_mem.c +++ b/drivers/virtio/virtio_mem.c @@ -750,7 +750,15 @@ static int virtio_mem_offline_and_remove_memory(struct virtio_mem *vm, dev_dbg(&vm->vdev->dev, "offlining and removing memory failed: %d\n", rc); } - return rc; + + switch (rc) { + case 0: + case -ENOMEM: + case -EINVAL: + return rc; + default: + return -EBUSY; + } } /* From patchwork Tue Jun 27 11:22:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13294364 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 CBA35C001B1 for ; Tue, 27 Jun 2023 11:22:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 621198D0005; Tue, 27 Jun 2023 07:22:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5A9CA8D0003; Tue, 27 Jun 2023 07:22:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 423578D0005; Tue, 27 Jun 2023 07:22:40 -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 2D49B8D0003 for ; Tue, 27 Jun 2023 07:22:40 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id D243E809F9 for ; Tue, 27 Jun 2023 11:22:39 +0000 (UTC) X-FDA: 80948290038.10.DE63435 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf20.hostedemail.com (Postfix) with ESMTP id 1809F1C002A for ; Tue, 27 Jun 2023 11:22:37 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=WeIiOZw7; spf=pass (imf20.hostedemail.com: domain of david@redhat.com designates 170.10.133.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=1687864958; 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=fr+vpotgatzONrB41R1RGYN75/TLbh/yXCu/qwGS3Ro=; b=oF89UEHCPV+9RK8I5AHXXf2JYvhBMQ1gCT4JCJ9BDX1TTF/qCJzVF6SwWZyHun/2I+PZnE wr/+cX/IBCy292JxhKPuuTRYsjvy5caOtmfOgveXuL9ls7+DeFV0dNK8MtDLqclmDNK+Xd OaIq3RNPr4dmNiDlgoXiIDVkGqyk3V0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687864958; a=rsa-sha256; cv=none; b=cWs3mY1e9OwEYeSlMIz67R8Wg6ScZHUbMb+gvO+t+ZbKjiifRoSTcCL/JLjFj3WuOv37ir mj016I0cld01vB0fMyGfN4nRybtcC9S6zJ/KihIH1sY/w20JfAZUm1C0ryx6lKJ5+BhoZn W2Rsy0LMU9BV9J1JQp8Nz3fffzU5l7Y= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=WeIiOZw7; spf=pass (imf20.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687864957; 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=fr+vpotgatzONrB41R1RGYN75/TLbh/yXCu/qwGS3Ro=; b=WeIiOZw7ojEoGWhmIzeU+2N+CrQBAqeOVcswkfqTGooz28ZwuWCHAHJ7vZaNOVGfhRWIDm Tcb6SAlDe5EqeBmHtwc/iHqiMiXubgfyAf6bZD4GzEc1V/ASgiOnNpgZItIIQV0Dx7T7gi Lb5nMsGRyEncAOYHVRcvzyBBT0QyKX4= 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-344-5tImlbEUOjm-C3jcDkwNPA-1; Tue, 27 Jun 2023 07:22:34 -0400 X-MC-Unique: 5tImlbEUOjm-C3jcDkwNPA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A9866800962; Tue, 27 Jun 2023 11:22:33 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.192.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id 10AC1200A3AD; Tue, 27 Jun 2023 11:22:31 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, virtualization@lists.linux-foundation.org, David Hildenbrand , Andrew Morton , "Michael S. Tsirkin" , John Hubbard , Oscar Salvador , Michal Hocko , Jason Wang , Xuan Zhuo Subject: [PATCH v1 3/5] mm/memory_hotplug: make offline_and_remove_memory() timeout instead of failing on fatal signals Date: Tue, 27 Jun 2023 13:22:18 +0200 Message-Id: <20230627112220.229240-4-david@redhat.com> In-Reply-To: <20230627112220.229240-1-david@redhat.com> References: <20230627112220.229240-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Rspamd-Queue-Id: 1809F1C002A X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: oucthrfrarhuqyuawjgygkturtr6qhcu X-HE-Tag: 1687864957-706792 X-HE-Meta: U2FsdGVkX1877FkAFbSSfiRttr3r7btOV9BhDMiCg0elSouhjMDoMTON698mNFmA5L7TSi5G9U+J2nNsTHESsrcNEtQ7+Ij8nejP0YscyDz4bR+WCpynDQ7Tt8CuZKBpqIzaMnjndd5CyWQd5MRdZbxikDK8EajBvC/bziWTUyyqU1g5xJZUWVd78JzAVbaeBfD/XZQJqN3Sbtdc+7ZjpF6MxKPuZsmUXAdbtpAsQ0AGtPhlu8WJ3TlZlfSIZTwGP0IqE6LB6PDmpU9Q8xn6IrjJsbR0ApbWZRejvRc/A4y95kZFoxeAvKVZs8MOdDvHoiPxfUqmipMjgCrHHkYH4Zhrn3QyOVCcVAt9Oy4C3o2ZW52maLiADiP7t6qjdBmAoiPpv7wWG7Ba4KiBcyKAeGabk+GccF0R6hxVCn0CWK6u7VR3mzxmeyMzAufXbwRNLvqLLjcWQUerewf99I2yieAIx9iWyBC0cte8usMNhm6S1khvUK22bR/8EGOUpU2M+/XVSc8L3NGSf8K58z/m1+u1JjPomu2a3u9BaQWMP6iDBcvS2i53nZiKxCbgdq283CDLrTf0quSdHznwxXWWa6CQOWgi9dDstVt5GpIsLh/YF8GslEHjHc3l/VOuHVWOWRltZAqRvK3AKn64l5v02lZ4tMMyVyCPvjwBIATM0wVXufsRCPwg8t/EdKiTa/jc9IdJTsKatatlHjPjkH7QNVBQEET1uQpY/0WC8TenpkE0M9DduBsUJPuZWA8N5/xQI1keu62scpEQQsq8ROifwHCxeYxuqvMLQTaOYs2RL6lEEhLZWiUY+80OiRa7hCmJJlfu0A6ls4k2NEMZyOI1pSCz6yl+9VE5tWtBAgwNNyLAQyTBDRD6tifurx0tMhTwhQFOxBbDAXSgJTvES860qV6NhOFw2hAW1z3RdeDsbqydzpdM/mxtaUg+a/QYU+zadcx/KuukNq5q+t6kp2H cLyo3E7k nfHfMu119zAOrt6U6rKrxc5rVEdjyBtRZts9H9OAVgBFqY9FA8G2pCNa7btcaiuLFuAoqxte7C2J85Pd65vr/3PtwkcJ26hf9l3/Ks3gsFrke7nv6cmWddYqHXPm+l3yQaFkoHvtMbRE2uEwPUfTTaN6ABZDYk+4BzQVfc6BAkvRNjvpmhi1pmWfpaFW92zzLyxN3/jVTgLD73/BpGx1CWEe1fQFuia7QN4N3AiJIzIBkh6sK2u0rS4CAZcB4fZt/GKQY9oOXJIN1ybRAkZ4o7SW+fVCW27u29Qnu9fag4UC8UNo= 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: John Hubbard writes [1]: Some device drivers add memory to the system via memory hotplug. When the driver is unloaded, that memory is hot-unplugged. However, memory hot unplug can fail. And these days, it fails a little too easily, with respect to the above case. Specifically, if a signal is pending on the process, hot unplug fails. [...] So in this case, other things (unmovable pages, un-splittable huge pages) can also cause the above problem. However, those are demonstrably less common than simply having a pending signal. I've got bug reports from users who can trivially reproduce this by killing their process with a "kill -9", for example. Especially with ZONE_MOVABLE, offlining is supposed to work in most cases when offlining actually hotplugged (not boot) memory, and only fail in rare corner cases (e.g., some driver holds a reference to a page in ZONE_MOVABLE, turning it unmovable). In these corner cases we really don't want to be stuck forever in offline_and_remove_memory(). But in the general cases, we really want to do our best to make memory offlining succeed -- in a reasonable timeframe. Reliably failing in the described case when there is a fatal signal pending is sub-optimal. The pending signal check is mostly only relevant when user space explicitly triggers offlining of memory using sysfs device attributes ("state" or "online" attribute), but not when coming via offline_and_remove_memory(). So let's use a timer instead and ignore fatal signals, because they are not really expressive for offline_and_remove_memory() users. Let's default to 30 seconds if no timeout was specified, and limit the timeout to 120 seconds. This change is also valuable for virtio-mem in BBM (Big Block Mode) with "bbm_safe_unplug=off", to avoid endless loops when stuck forever in offline_and_remove_memory(). While at it, drop the "extern" from offline_and_remove_memory() to make it fit into a single line. [1] https://lkml.kernel.org/r/20230620011719.155379-1-jhubbard@nvidia.com Signed-off-by: David Hildenbrand --- drivers/virtio/virtio_mem.c | 2 +- include/linux/memory_hotplug.h | 2 +- mm/memory_hotplug.c | 50 ++++++++++++++++++++++++++++++++-- 3 files changed, 50 insertions(+), 4 deletions(-) diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c index cb8bc6f6aa90..f8792223f1db 100644 --- a/drivers/virtio/virtio_mem.c +++ b/drivers/virtio/virtio_mem.c @@ -738,7 +738,7 @@ static int virtio_mem_offline_and_remove_memory(struct virtio_mem *vm, "offlining and removing memory: 0x%llx - 0x%llx\n", addr, addr + size - 1); - rc = offline_and_remove_memory(addr, size); + rc = offline_and_remove_memory(addr, size, 0); if (!rc) { atomic64_sub(size, &vm->offline_size); /* diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h index 9fcbf5706595..d5f9e8b5a4a4 100644 --- a/include/linux/memory_hotplug.h +++ b/include/linux/memory_hotplug.h @@ -307,7 +307,7 @@ extern int offline_pages(unsigned long start_pfn, unsigned long nr_pages, struct zone *zone, struct memory_group *group); extern int remove_memory(u64 start, u64 size); extern void __remove_memory(u64 start, u64 size); -extern int offline_and_remove_memory(u64 start, u64 size); +int offline_and_remove_memory(u64 start, u64 size, unsigned int timeout_ms); #else static inline void try_offline_node(int nid) {} diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 0d2151df4ee1..ca635121644a 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -152,6 +152,22 @@ void put_online_mems(void) bool movable_node_enabled = false; +/* + * Protected by the device hotplug lock: offline_and_remove_memory() + * will activate a timer such that offlining cannot be stuck forever. + * + * With an active timer, fatal signals will be ignored, because they can be + * counter-productive when dying user space triggers device unplug/driver + * unloading that ends up offlining+removing device memory. + */ +static bool mhp_offlining_timer_active; +static atomic_t mhp_offlining_timer_expired; + +static void mhp_offline_timer_fn(struct timer_list *unused) +{ + atomic_set(&mhp_offlining_timer_expired, 1); +} + #ifndef CONFIG_MEMORY_HOTPLUG_DEFAULT_ONLINE int mhp_default_online_type = MMOP_OFFLINE; #else @@ -1879,7 +1895,18 @@ int __ref offline_pages(unsigned long start_pfn, unsigned long nr_pages, do { pfn = start_pfn; do { - if (fatal_signal_pending(current)) { + /* + * If a timer is active, we're coming via + * offline_and_remove_memory() and want to ignore even + * fatal signals. + */ + if (mhp_offlining_timer_active) { + if (atomic_read(&mhp_offlining_timer_expired)) { + ret = -ETIMEDOUT; + reason = "timeout"; + goto failed_removal_isolated; + } + } else if (fatal_signal_pending(current)) { ret = -EINTR; reason = "signal backoff"; goto failed_removal_isolated; @@ -2232,11 +2259,17 @@ static int try_reonline_memory_block(struct memory_block *mem, void *arg) * memory is still in use. Primarily useful for memory devices that logically * unplugged all memory (so it's no longer in use) and want to offline + remove * that memory. + * + * offline_and_remove_memory() will not fail on fatal signals. Instead, it will + * fail once the timeout has been reached and offlining was not completed. If + * no timeout was specified, it will timeout after 30 seconds. The timeout is + * limited to 120 seconds. */ -int offline_and_remove_memory(u64 start, u64 size) +int offline_and_remove_memory(u64 start, u64 size, unsigned int timeout_ms) { const unsigned long mb_count = size / memory_block_size_bytes(); uint8_t *online_types, *tmp; + struct timer_list timer; int rc; if (!IS_ALIGNED(start, memory_block_size_bytes()) || @@ -2261,9 +2294,22 @@ int offline_and_remove_memory(u64 start, u64 size) lock_device_hotplug(); + if (!timeout_ms) + timeout_ms = 30 * MSEC_PER_SEC; + timeout_ms = min_t(unsigned int, timeout_ms, 120 * MSEC_PER_SEC); + + timer_setup_on_stack(&timer, mhp_offline_timer_fn, 0); + mod_timer(&timer, jiffies + msecs_to_jiffies(timeout_ms)); + mhp_offlining_timer_active = true; + tmp = online_types; rc = walk_memory_blocks(start, size, &tmp, try_offline_memory_block); + timer_delete_sync(&timer); + atomic_set(&mhp_offlining_timer_expired, 0); + mhp_offlining_timer_active = false; + destroy_timer_on_stack(&timer); + /* * In case we succeeded to offline all memory, remove it. * This cannot fail as it cannot get onlined in the meantime. From patchwork Tue Jun 27 11:22:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13294366 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 09A1BC001B1 for ; Tue, 27 Jun 2023 11:22:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 97E338D0007; Tue, 27 Jun 2023 07:22:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9079B8D0003; Tue, 27 Jun 2023 07:22:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 70CF28D0007; Tue, 27 Jun 2023 07:22:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 571898D0003 for ; Tue, 27 Jun 2023 07:22:42 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 2C311A092F for ; Tue, 27 Jun 2023 11:22:42 +0000 (UTC) X-FDA: 80948290164.22.D43987D Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf19.hostedemail.com (Postfix) with ESMTP id 654101A000C for ; Tue, 27 Jun 2023 11:22:40 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="b/a92jyL"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf19.hostedemail.com: domain of david@redhat.com designates 170.10.133.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=1687864960; 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=T3lZgYf4GUx7yLsElB4csYTB1LQXvieCj0NGb4r43Kk=; b=6U6UTZTvMrWzvaZw4h6M5sCl8LQDO7G7F+biGWMthi1kVYJQLX+plY71588Td0ebATkWu4 LfNmWkj/LEJG72D8urJ4zcme8efaDFATGM1Inb4srgliZpNW88pO6vPolHokXV6cLAOdwm lQYFMfMH1cV5ZdTDR4nxow6E2KD/JPM= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="b/a92jyL"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf19.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687864960; a=rsa-sha256; cv=none; b=jJC1bhmTo/iLfF92/FdL6R4Mi8O648octsemkgVKzZhe/RlxRxqfxMmQaFGlRdeGAJAV1n nzl96DZEHU+2FwbviOjlAA/jAMlk4zIwb7KyROYPUxgY2/+psIW1f+l7tL3BdglMqUPvjs iaaaQGVlXst2CUi0jb5Q6O9egR9eqEI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687864959; 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=T3lZgYf4GUx7yLsElB4csYTB1LQXvieCj0NGb4r43Kk=; b=b/a92jyLnP5/ODfL+PGt7EB4l/b1ULIakSdTlpvOwlCbKFkKeTLLJ723acem4M1V3VZOrO AMs7hkOf6FAnfn89uHZPGDju4aGDyrgX9x1EerSevl7xCgdbg72xZGYT9TvJ/PggaaNFQt F43OJiVtBT1jrUPoFopHzr4/T7llAVg= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [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-354-SGCc500YMA6d6vSpb4530Q-1; Tue, 27 Jun 2023 07:22:36 -0400 X-MC-Unique: SGCc500YMA6d6vSpb4530Q-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A4EBE1C07588; Tue, 27 Jun 2023 11:22:35 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.192.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id E5588200A3AD; Tue, 27 Jun 2023 11:22:33 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, virtualization@lists.linux-foundation.org, David Hildenbrand , Andrew Morton , "Michael S. Tsirkin" , John Hubbard , Oscar Salvador , Michal Hocko , Jason Wang , Xuan Zhuo Subject: [PATCH v1 4/5] virtio-mem: set the timeout for offline_and_remove_memory() to 10 seconds Date: Tue, 27 Jun 2023 13:22:19 +0200 Message-Id: <20230627112220.229240-5-david@redhat.com> In-Reply-To: <20230627112220.229240-1-david@redhat.com> References: <20230627112220.229240-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Rspamd-Queue-Id: 654101A000C X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: bgsuu4dix1ci4nj8izfcms66t755ut18 X-HE-Tag: 1687864960-128858 X-HE-Meta: U2FsdGVkX18OPbBCQaeGroMUENmcg22bMQ/4IovELVI260odazuw3w2viXqNRAdaXSyXuvvlAiLnV8FXyZWcAkMi0x+IbGSbr7LYg/JPjiZC85wgr5vIIfMTuXHUP/GJq2SmjEG1qPacsP4Ol9CvPByrrbAUISh4e3y6x85qfn+NeEdSv9efGuq1o03oaJ5oodeGMhAWqkCCuehRtI2GSDtvDKcks+qfzm1dTowg8jSsb0a+Tx5vFkVNKJAVPwHCp32FdJY/UyaY2JRljw8ARYdw+vpqePz+Y+pk25ixxx2kZIh9jEXc8vD2+Rr+3/q1wxiMZDfLGrkm8UQ0Y2/c1h47sfVPP16L6XNYd34i2iHAOdcDKFS8M+8tXM/a6YnN5Zxk1PbU/Gx7Z5XXS4obtgVy7N3hLjnBG0M87Qpg+xRn98vEye/qE7iB7fTYbJ/yQbdJBOwzb3eU5KCe8mYxTACWmdNnTStt3ZBB9SVT8nBBNzALq0PPV7dLw+2a93Wcpyhh0PiSQEJazUu3sc4AlcZb/2FzFvcQ1PibgJrGqQcoZskrfB68wp87bSk3BmBE8ufWygSTK4B7WsxTpfAMWmJD/4rqgEXGGA63xwALIM0+7EVf4t0Am82QrvcjA71JTGHmun7fSU2mIkv7LVCdut5QloysBoyFX2qUiHulGqtdIGz4MQxkuO3JFmmJdUqK14hFFAx+v0eCkCZ8RJeHPlXOmy+t6R+qro2GFZSFfvEhjcKay/tNEXMQX14YBLS3kJ65n4E84O0n+/C+upRmTYmDtQgXLsuceb3uN+4LF3KacKT2o/ova3FKg6F0+bV3Sn1w/wF7jPR4yT25FP+4l+1KMv2ecwvxxgcNSKbAOgbGLF8tki/AkllkG5nwXm0g4023vJThYuZalwUH7D33Ipr5IrMeixYvZYB2PhkXFh+c7C0q33lOmwokehfRbKY15Ni1RhHTyabdnM2qjvU lo84qFJc oAp5vodHjlORQhjerMbIpi/QYgDjSo1geRoY0ioHEImoZ4o5uYzDdqmM2coBojxDbo+dSvkxgeZU/qDzAqGPNUOqP4jqvNIxOhw4lHtEd7oiRzYXmrzJde8I3Pz26c7zvlwgcm4JwjQTw4yTRsG07mKGs9uFcdk9H5QznrnMJTP15ROY8fLYICb386YwozoCgN4n7TVZ3PqfwTo0s1z1KDhwhNw== 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: Currently we use the default (30 seconds), let's reduce it to 10 seconds. In BBM, we barely deal with blocks larger than 1/2 GiB, and after 10 seconds it's most probably best to give up on that memory block and try another one (or retry this one later). In the common fake-offline case where we effectively fake-offline memory using alloc_contig_range() first (SBM or BBM with bbm_safe_unplug=on), we expect offline_and_remove_memory() to be blazingly fast and never take anywhere close to 10seconds -- so this should only affect BBM with bbm_safe_unplug=off. While at it, update the parameter description and the relationship to unmovable pages. Signed-off-by: David Hildenbrand --- drivers/virtio/virtio_mem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c index f8792223f1db..7468b4a907e3 100644 --- a/drivers/virtio/virtio_mem.c +++ b/drivers/virtio/virtio_mem.c @@ -41,7 +41,7 @@ MODULE_PARM_DESC(bbm_block_size, 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"); + "Use a safe/fast unplug mechanism in BBM, failing faster on unmovable pages"); /* * virtio-mem currently supports the following modes of operation: @@ -738,7 +738,7 @@ static int virtio_mem_offline_and_remove_memory(struct virtio_mem *vm, "offlining and removing memory: 0x%llx - 0x%llx\n", addr, addr + size - 1); - rc = offline_and_remove_memory(addr, size, 0); + rc = offline_and_remove_memory(addr, size, 10 * MSEC_PER_SEC); if (!rc) { atomic64_sub(size, &vm->offline_size); /* From patchwork Tue Jun 27 11:22:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13294367 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 9672CEB64D9 for ; Tue, 27 Jun 2023 11:22:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 33BAF8D0008; Tue, 27 Jun 2023 07:22:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2C38B8D0003; Tue, 27 Jun 2023 07:22:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 13E458D0008; Tue, 27 Jun 2023 07:22:47 -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 00C098D0003 for ; Tue, 27 Jun 2023 07:22:46 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id D10C7C098E for ; Tue, 27 Jun 2023 11:22:46 +0000 (UTC) X-FDA: 80948290332.12.674606E Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf28.hostedemail.com (Postfix) with ESMTP id 1F388C0010 for ; Tue, 27 Jun 2023 11:22:44 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Y9SMURnY; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf28.hostedemail.com: domain of david@redhat.com designates 170.10.133.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=1687864965; 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=8+JMX7PmWMV8slSmifeWswXiVAWwIFJBeTLnY9EmnBs=; b=o68rtZeCFnF0TtJv9sZoCgPXUTLv46YQzsOhEofsn7/dHbSuzwW5GvQSHK8W6gKcMU2S7j FiPrX9Wiy7af23DEWc0Y+nOspOh+ukTiY4Jumof/4pr5PupQFx0YRUKAClm1e1PmKj3l7H x0EGKlcjgDe7rtBT36tHCtvPgTcX5a8= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Y9SMURnY; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf28.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687864965; a=rsa-sha256; cv=none; b=oNSkrWXsHdMaz11mYep8798YsL5Qmckmr2ULdt9HYDwDiWI8PKhl1NPc9Gm0oSmncwPvId 8G8b3e1VclOp++QQxZut7kSAjBz4bI6evbtzKwBlAGGC4eQ6sITPmz81KxUb2yfWRqRTl5 k8MRrOx0geCIFovH0zLnOFJXsaTJ7IA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687864964; 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=8+JMX7PmWMV8slSmifeWswXiVAWwIFJBeTLnY9EmnBs=; b=Y9SMURnYHcWu94Jvra+2/zutC6/iAuT1sYOleMDjw7hhChNWQzIbbMyr0XeSwPs/GmGQ+2 RyaaHXIDERGo3f79hwHgD5bPWp43zKFNZ7Gd4npQF9lehqlHehm802BcheTjJsBr5qtvZ9 dIDgSZRqWVs9uunYwwKL9s8czWrU3CI= 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-228-_3hHQO3VOiqe86__7AxxGg-1; Tue, 27 Jun 2023 07:22:38 -0400 X-MC-Unique: _3hHQO3VOiqe86__7AxxGg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CE10B858290; Tue, 27 Jun 2023 11:22:37 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.192.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id E37C0200A3AD; Tue, 27 Jun 2023 11:22:35 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, virtualization@lists.linux-foundation.org, David Hildenbrand , Andrew Morton , "Michael S. Tsirkin" , John Hubbard , Oscar Salvador , Michal Hocko , Jason Wang , Xuan Zhuo Subject: [PATCH v1 5/5] virtio-mem: check if the config changed before (fake) offlining memory Date: Tue, 27 Jun 2023 13:22:20 +0200 Message-Id: <20230627112220.229240-6-david@redhat.com> In-Reply-To: <20230627112220.229240-1-david@redhat.com> References: <20230627112220.229240-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Rspamd-Queue-Id: 1F388C0010 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: zgrtixhfnkexf3nyyhkecgxiatdqqpio X-HE-Tag: 1687864964-242526 X-HE-Meta: U2FsdGVkX18eCWTvch3jC9YT3VLQcC6fpP5oyCDQzmL71cA+NstWgWWk7c7mag8YIbvWSZQ9P6phHd21G8fJ9KsmpEwEuOZmry4hsawrkzzWX/2b3ggNnRXBoOV8yPfwmtmuZLZYR1dZcXhcEnZYQ3ypNm2B5cbFaBHew+9mw7o5MEAS20jlRSAnLZdCn7mXFUGQPQAvrYDpQC8DFcPIvYwBvnPVIlpvVTTnqDT01jMbfKv1EzeiAs66Jp5jyfKLO2Y9GJdTRR+o+AElDSQrQhiBi5rUHXqj1VNVorAIa5er3Dfss7yIzgH69juP3JSChxSX6ZBLezDe5Sb1R2Mcd+ia49jjkR6t1geBm3Fgqogi47YnOQYTNbr4QTRcXeg+jW4JN7wGTn4qqHNlZUGc1plaBewLXudfeeuMRgK4HvOykkzplQ4uJVF2xfCFBLH6EyErMa6CIaw7/gmaivmeU5RZb7d9XvYH4muqZVKG7wR5fUnyH7sC6HE7gWwu2Jf6kYeJ+rlZwzdsTp7MCo9ygyzYqH74bcNMhYccIxc3PXUWPYkk+z6a/rNysKjlfLtmCcvqgU+X5TJVfVuDca8K9FyP5/QyKGIqmUA2qtRe9VKLPahXTVkV6vqzdR6kC9lK9aXhL2lrDHE2ZAlbW1qHaK+bnUqWCSd2dEOnvwix1wRqtHooyi89AZa7NwgzGVYBmwg2/3ELPKu2zSTbu8PkjIWjC7hHVGv0wXUJAllrw/o8plPfch75a3MCUVePQpLUGLakSipjpiels06abO0TzR9N+EH7/4OFYr6N8nvNuwy2RpPwmnY2/DvlSpsX1Dpe1neqHJ8rTfZquHcb1fvua7j4hG37BgBT/ZcefeqXybnrIEGFBmp63N5sN7Ke5gLiPdB6xRcaK8BPlxLMFgV+HnManHOBBX8ZfBShOm3VuycrhkpnWIbfsOXfA+Bozus24vdHbeJoPZbeS8PJWV8 RtSmsa7j XzKU7T6OFWIB9Br1FCcL3wHZT01OrxeJA8lT97UYOZtFsSMQbKciZ04ppz1T+JYys7gk4g6xLDd9oSdgyMTWX9DPDofGmgjDNE7REanS0CF+IlYxWi/CkiLqgDnzbk5BtAzn5YIY+fp6/VKScchBNUa13N6IaX2A2RC1h0gV3glLbJRY= 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, 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. So we could end up trying for a long time to offline memory, even though the config changed already and we're not supposed to unplug memory anymore. Let's optimize for that case, identified while testing the offline_and_remove() memory timeout and simulating it repeatedly running into the timeout. Signed-off-by: David Hildenbrand --- drivers/virtio/virtio_mem.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c index 7468b4a907e3..247fb3e0ce61 100644 --- a/drivers/virtio/virtio_mem.c +++ b/drivers/virtio/virtio_mem.c @@ -1922,6 +1922,10 @@ static int virtio_mem_sbm_unplug_sb_online(struct virtio_mem *vm, unsigned long start_pfn; int rc; + /* Stop fake offlining attempts if the config changed. */ + if (atomic_read(&vm->config_changed)) + return -EAGAIN; + start_pfn = PFN_DOWN(virtio_mem_mb_id_to_phys(mb_id) + sb_id * vm->sbm.sb_size); @@ -2233,6 +2237,10 @@ static int virtio_mem_bbm_unplug_request(struct virtio_mem *vm, uint64_t diff) virtio_mem_bbm_for_each_bb_rev(vm, bb_id, VIRTIO_MEM_BBM_BB_ADDED) { cond_resched(); + /* Stop (fake) offlining attempts if the config changed. */ + if (atomic_read(&vm->config_changed)) + return -EAGAIN; + /* * As we're holding no locks, these checks are racy, * but we don't care.