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+NstWgWWk7c7mag8YIbvWSZQ9P6phHd21G8fJ9KsmpEwEuOZmry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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.