Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2546981lqp; Mon, 25 Mar 2024 02:04:42 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXatkAlf3Pf8ZHJfQx4HNPFIo3wXHW3fikmPXhKWE62Z0BwnYjBVo3DROxQcOCnwB6durPnWevPjvV7sKwDX9VO5n0Qll1cDsPQXy3ACQ== X-Google-Smtp-Source: AGHT+IFbFF2JfagPBCHdcoy7zgOXj5wXEJNXcfZ0fG2BCpoEWX1JccHQjh2GwmsACRUbH6NthLmv X-Received: by 2002:a05:6402:34c1:b0:56c:189f:cf2f with SMTP id w1-20020a05640234c100b0056c189fcf2fmr574686edc.32.1711357482578; Mon, 25 Mar 2024 02:04:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711357482; cv=pass; d=google.com; s=arc-20160816; b=bNOG37XB+88NC9tHJTS4gxOGkpWKBz2IcVhPwo+uIdpLaDg1pm0aKg4J5PjRPfPhOk q81OCi9Xq74jkQrKile7RcXCNkJRGI2kop/w/8MAqYC+3M+ubRbO6LlSsUipUU+KioCp ZnMGscybKoOI/vR4T1cTopwOr4vyHIcyI0G65ZRHv1jJ/WqX6egxQI6dqa4SczLazCsD iIdJJshX5ywTEY8j+URgpyg4cgxJURITAMIG0j5OqzML53WRBlSO2X0muqfzUc2dSstE ISt1QfXWnr/dfN98Pz4xxLlzPNG21BIIFAllwACTKpu/FY65yuqbhyLeQDduTY+n0V7j jq8g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=tL4IEZ0gdZjNqeF8ix393S7np36ZPUMMX4IE0bG1bv4=; fh=gztaZlEV/IhaCTI9OXrOTx7G3T0xX7o1SJxZFm84PTI=; b=Y1/t8UC2bz8s62uvItF2QayQ23zkSX3b6SW7V8ErW21FKegEblQ7qziD5XjGsHZTho TGUZkdKJ2ghzmyBZoDk8O1LeKAqRStk3dPVyjHxv0IONrP/BHaFqWuB4/tFaR29JedXw Ly9UxP3p5Xvo40xVc/MD/dXt8NijAoAGwqGJH4PUa72QAmItF5EaRMJaOJKkUOr6AM92 +FsZqTnsX5NvTaPajt/k2pjA0E7GmfyIfw34dUXuIjRaWH9DXVse8X5dm30BFPDjAre+ Pc+8y/fiMrg/1zN04Yttlk2tfiRtO2ts8lBAeKZHG+9SJWZGH0ObOy7VTLmT+r/Vw47v zG+w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=W+pa6MKr; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-115680-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-115680-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id bl16-20020a056402211000b0056c1c5ff746si63320edb.11.2024.03.25.02.04.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 02:04:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-115680-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=W+pa6MKr; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-115680-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-115680-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 26BD11F35E37 for ; Mon, 25 Mar 2024 09:04:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1BD0535944E; Mon, 25 Mar 2024 02:53:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="W+pa6MKr" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AA90015251D; Sun, 24 Mar 2024 23:06:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711321613; cv=none; b=Kl7qUEOtzmu8Vx0l5wl2VTm91f8CHiAU5GJmYi+b7dtv/Y2tl0kT+6uiTH8dZk4ixskMC5jYUxSbh3LQl9e6ElCpMOWHtK04oo9Rko3Cpy0uhe4z6tNjUNhkccJf2hvLN3vxqIYTIPfBPDLviITbs8pteMuwaFXXPd1t5uJgOig= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711321613; c=relaxed/simple; bh=8u2lrOUR/FMLDlaneYHW1ouJaJJx5e8JluC0PlHvuOk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XBKu8Sz0sKljld2WKUym35Apa0rr7XGGx5VLp6k+4bRnSNqQJseqHB+c493RykNRGPJMgRC17rWmhCHWerF0iCj5ZC6isMpHogCjLbm6PuDCcUy8n70iJXxIXYgg+lLbyVZCOXQAQt32msLD6cWlZYfCTeZllq9GPVvMrNzucHE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=W+pa6MKr; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id EB5CEC433C7; Sun, 24 Mar 2024 23:06:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711321612; bh=8u2lrOUR/FMLDlaneYHW1ouJaJJx5e8JluC0PlHvuOk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W+pa6MKrsC6o8wSu/SWm+NAeZW1sV0mVTH0YTeQA4nzGsji77kLfRhwnzwwX6IhH7 A0EQWiHEYU58TL2DjOXKSvdCbFSA6kVSpEaPxdz+jrtOzUghCRqyHDqW1DsnjvS/zE 7GkdIf1NqvTOIurdIRuaEB05FVQEkGVa1iG4aktM13xkSDKaVzH6j7kfw8HB93BZ46 wDV9FjVh4C2/gMaKFNfpQMl0Bl62e5DXWY6ZPv/wGQ5FwdhEoGsGRYKxLPOvTQjWi3 ZoyGm0BaldqZbNq9+9A0qZO+SSJwAXyiOnibugrczhT0ygmeJNn+blrVPj1TmCM41B WIZMBFxoNgTlw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Mikulas Patocka , Mike Snitzer , Sasha Levin Subject: [PATCH 6.6 342/638] dm: call the resume method on internal suspend Date: Sun, 24 Mar 2024 18:56:19 -0400 Message-ID: <20240324230116.1348576-343-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324230116.1348576-1-sashal@kernel.org> References: <20240324230116.1348576-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Mikulas Patocka [ Upstream commit 65e8fbde64520001abf1c8d0e573561b4746ef38 ] There is this reported crash when experimenting with the lvm2 testsuite. The list corruption is caused by the fact that the postsuspend and resume methods were not paired correctly; there were two consecutive calls to the origin_postsuspend function. The second call attempts to remove the "hash_list" entry from a list, while it was already removed by the first call. Fix __dm_internal_resume so that it calls the preresume and resume methods of the table's targets. If a preresume method of some target fails, we are in a tricky situation. We can't return an error because dm_internal_resume isn't supposed to return errors. We can't return success, because then the "resume" and "postsuspend" methods would not be paired correctly. So, we set the DMF_SUSPENDED flag and we fake normal suspend - it may confuse userspace tools, but it won't cause a kernel crash. ------------[ cut here ]------------ kernel BUG at lib/list_debug.c:56! invalid opcode: 0000 [#1] PREEMPT SMP CPU: 1 PID: 8343 Comm: dmsetup Not tainted 6.8.0-rc6 #4 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.14.0-2 04/01/2014 RIP: 0010:__list_del_entry_valid_or_report+0x77/0xc0 RSP: 0018:ffff8881b831bcc0 EFLAGS: 00010282 RAX: 000000000000004e RBX: ffff888143b6eb80 RCX: 0000000000000000 RDX: 0000000000000001 RSI: ffffffff819053d0 RDI: 00000000ffffffff RBP: ffff8881b83a3400 R08: 00000000fffeffff R09: 0000000000000058 R10: 0000000000000000 R11: ffffffff81a24080 R12: 0000000000000001 R13: ffff88814538e000 R14: ffff888143bc6dc0 R15: ffffffffa02e4bb0 FS: 00000000f7c0f780(0000) GS:ffff8893f0a40000(0000) knlGS:0000000000000000 CS: 0010 DS: 002b ES: 002b CR0: 0000000080050033 CR2: 0000000057fb5000 CR3: 0000000143474000 CR4: 00000000000006b0 Call Trace: ? die+0x2d/0x80 ? do_trap+0xeb/0xf0 ? __list_del_entry_valid_or_report+0x77/0xc0 ? do_error_trap+0x60/0x80 ? __list_del_entry_valid_or_report+0x77/0xc0 ? exc_invalid_op+0x49/0x60 ? __list_del_entry_valid_or_report+0x77/0xc0 ? asm_exc_invalid_op+0x16/0x20 ? table_deps+0x1b0/0x1b0 [dm_mod] ? __list_del_entry_valid_or_report+0x77/0xc0 origin_postsuspend+0x1a/0x50 [dm_snapshot] dm_table_postsuspend_targets+0x34/0x50 [dm_mod] dm_suspend+0xd8/0xf0 [dm_mod] dev_suspend+0x1f2/0x2f0 [dm_mod] ? table_deps+0x1b0/0x1b0 [dm_mod] ctl_ioctl+0x300/0x5f0 [dm_mod] dm_compat_ctl_ioctl+0x7/0x10 [dm_mod] __x64_compat_sys_ioctl+0x104/0x170 do_syscall_64+0x184/0x1b0 entry_SYSCALL_64_after_hwframe+0x46/0x4e RIP: 0033:0xf7e6aead ---[ end trace 0000000000000000 ]--- Fixes: ffcc39364160 ("dm: enhance internal suspend and resume interface") Signed-off-by: Mikulas Patocka Signed-off-by: Mike Snitzer Signed-off-by: Sasha Levin --- drivers/md/dm.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/drivers/md/dm.c b/drivers/md/dm.c index 64a1f306c96c1..f945ee453457b 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -2918,6 +2918,9 @@ static void __dm_internal_suspend(struct mapped_device *md, unsigned int suspend static void __dm_internal_resume(struct mapped_device *md) { + int r; + struct dm_table *map; + BUG_ON(!md->internal_suspend_count); if (--md->internal_suspend_count) @@ -2926,12 +2929,23 @@ static void __dm_internal_resume(struct mapped_device *md) if (dm_suspended_md(md)) goto done; /* resume from nested suspend */ - /* - * NOTE: existing callers don't need to call dm_table_resume_targets - * (which may fail -- so best to avoid it for now by passing NULL map) - */ - (void) __dm_resume(md, NULL); - + map = rcu_dereference_protected(md->map, lockdep_is_held(&md->suspend_lock)); + r = __dm_resume(md, map); + if (r) { + /* + * If a preresume method of some target failed, we are in a + * tricky situation. We can't return an error to the caller. We + * can't fake success because then the "resume" and + * "postsuspend" methods would not be paired correctly, and it + * would break various targets, for example it would cause list + * corruption in the "origin" target. + * + * So, we fake normal suspend here, to make sure that the + * "resume" and "postsuspend" methods will be paired correctly. + */ + DMERR("Preresume method failed: %d", r); + set_bit(DMF_SUSPENDED, &md->flags); + } done: clear_bit(DMF_SUSPENDED_INTERNALLY, &md->flags); smp_mb__after_atomic(); -- 2.43.0