Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2511910lqp; Mon, 25 Mar 2024 00:28:32 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXyCNyeKZxBEdlV2VFvGcVPAheeQS10UHZLAoG0qkeruUrREeVSWhZvULx/a3Q8pDzLhVQ93bosNeAq3o6AMS5q3m6411iYMSVBEx8moA== X-Google-Smtp-Source: AGHT+IFohgnqFoIa0Qk+uX/3075Kmw1ntNxY0VvkUXLif4XjD1Ay+CHFLEC9k12x1QSkhYOVwSUA X-Received: by 2002:a17:902:bb8b:b0:1e0:3447:8dc5 with SMTP id m11-20020a170902bb8b00b001e034478dc5mr5718269pls.63.1711351711997; Mon, 25 Mar 2024 00:28:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711351711; cv=pass; d=google.com; s=arc-20160816; b=zzRHfau/0bBGK0pZ0nknYJBiRTa0blyQ4UVMd9ebKLtAVUln3SuVNhhDOx72CvRr7r UY6vAOKVc9xAlSiUHkXwMa0KhhgyWPhYozxpVFw+is4rDoFtYFNAlE1ZdBf84hi6Y/Kp cjZtBymZPOW06ZJK88N84JdCkPGcbFe7A6lXgYSMGpCovPNK866nLowiW4ezrqYogP/G gM+6GGBU95qKBeD4ccZipQ9pkuTZlV/xJVOSDXweWPwfIN9XidAkjBiKNeA6S+iNl13m NVATusa5OijYVKuA40+XU7C0rnyxYdFiFXvKcKGX1SWnPq4tOoT9k8+71qh2rOcFxQ9N jQdw== 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=6UaCubcHt7/iRzLBm+zHZJyRVZZ0GFTsVxDGmuuWtDs=; fh=gztaZlEV/IhaCTI9OXrOTx7G3T0xX7o1SJxZFm84PTI=; b=fW67TTfSrklS3N6sT84H6Fg3cuA6Y3+kXM4dsO0D/SWlCA2sUkWOdjPbnRS5D8OMpS AAaTDhfo83n8DPGzxzQe2NV3eA/uMeudiJBi07IdRLI1wB11L/GeG6JTc63fAdc6bqTi Vg86aHDHisHSHQlRmKRGJjpApV8MhlM4mxsoyEnr48+/DgPdeysMnScxXKMM2Rhqwm7O bKPwlIc5BZ03W+/1FYXjHO4fpnYyvHepxa1iVt/xyF+luWrFU36VDKsPeW6EA8PXv64+ P6z01e4yQkgj5w3wl98iFHVJ0wCMKzBeCYtIlGWGj2iZeXUOr5NYfM+GG+XYvsGm4yf3 Pgww==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="JJKm/Fw8"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-114994-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-114994-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id be5-20020a170902aa0500b001e06c1eee20si4418461plb.320.2024.03.25.00.28.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 00:28:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-114994-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="JJKm/Fw8"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-114994-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-114994-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id B6CFD2A1EFB for ; Mon, 25 Mar 2024 07:13:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2C04C17B505; Mon, 25 Mar 2024 00:58:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="JJKm/Fw8" 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 3919D282A74; Sun, 24 Mar 2024 23:42:18 +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=1711323739; cv=none; b=uE8cuBKHHo9Tr/rcgTNVu4gIRXtHZbVp3MxcIVSTXpn9xzDL09FY+uTpFLrG3ehXTekXMbGfVuBNeEE7wsVxyoOcHN8CcELaIdEAHAvkqAUhpb+GR4Jr4IcTAwyOZgb7xy/VqVJLKDFHeM8BCo6ZsInoy0jYDLO1iE+kXODb8O0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711323739; c=relaxed/simple; bh=+RqRYV2NYG1NoiMrMCsLjRQDW69XNgVdsN7s/z6YTYc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nrOSCBCVJduFFSGhJ0hHjC11nLiOoaU84eQf8H4Vv4vP2dft8pevzwO/j6IJCazLaIrk7dZ8nxV5rLIKoip8ZaeNymqHuuYzJmEkrOlrz6fQYdYq4lyJ7gmShRaLu+j+DVNFYoW5vqrk+LJ4Y2fNuDntyS8nTThDWKE9Q6KHa30= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JJKm/Fw8; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 78F65C433C7; Sun, 24 Mar 2024 23:42:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711323738; bh=+RqRYV2NYG1NoiMrMCsLjRQDW69XNgVdsN7s/z6YTYc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JJKm/Fw8IFzZgT8bhhc/oCxpIZugvNRDSe4OWi2+ResuUJfxRd6r/+O1vUtJkmZYQ KWw1J56XKEIC/zfxknqoXCxX4KAQnnSJWrJvWHMDzyU0yWCmzRn8/oc0t54qgAxDvU dvqTZUwK6kJLorGbZ7X3fhwdlv5d9AljCSajAZx6Tu1lOgf0KMy72I3MOqrBPUz498 VQzh6mDTrM1hhe8MwbVEMzJoCG96eGC7S1LrJXZK7efRJeVK3CtzqsJj1Vjky986SO 3pcf5H09Jj7XIBIBTWT/cuyvuvQl57Wi9M8O6yw98MoT2b+aj6KDUHgYlcG3tCDRhx tmAiUrmxRme6Q== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Mikulas Patocka , Mike Snitzer , Sasha Levin Subject: [PATCH 5.10 112/238] dm: call the resume method on internal suspend Date: Sun, 24 Mar 2024 19:38:20 -0400 Message-ID: <20240324234027.1354210-113-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324234027.1354210-1-sashal@kernel.org> References: <20240324234027.1354210-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 9029c1004b933..dc8498b4b5c13 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -2733,6 +2733,9 @@ static void __dm_internal_suspend(struct mapped_device *md, unsigned suspend_fla 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) @@ -2741,12 +2744,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