Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp597849pxj; Tue, 18 May 2021 09:58:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJypIb8X7Xeyj9AhKS2tNpjISswTzDSYhOzYm8rdDZbqtFz9cPmvqZxKM4gx1In9Swa3SaSc X-Received: by 2002:a17:907:105e:: with SMTP id oy30mr6996626ejb.258.1621357095698; Tue, 18 May 2021 09:58:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621357095; cv=none; d=google.com; s=arc-20160816; b=D3q9ESOCogT+ksbrPdB4PZ4fjobQVi/HIs+Gm6fIzbb31SS8zmqssKeNea6Y6RDSq8 V7lzrYsGkwQAjns4EX2U9Miu1U5VeDGWXivYle60M/B5FQlR3BGq0VDXEm54jGpUuR10 JYibTnwboRiOKTHf7vHcqELogbzHnE0jphlcOhTpnYZsFgXXEBqJbpOyQP0A01ttlR1n 9Mv//XENxkGd2kLoLtqAdOMfQe0EvVnmYlBlaqfVaQIkR/eJ6ZDu8yJnHqqQ85vl6foY 8sQPDeihamfPcAxH2d4T95fZdNMCWbgEIdtryMO9IL+DllQHabMDnPUsovxjBP1Xh2Zr 9g8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/IV4K+dexe75QKr1hn//WRou+fcFDyW8s1BRX1FSM3Y=; b=QUxuvTVQOu4csHaAd16+TukkR+Lf2mQ5KelAwsiiCpmb6Tn3njOXchaj6ROoS5uCA3 TWmrjWO4Dr6HxkSS1dB266eIGOVGVLFxJpOy7/wHiarKFGTvbMIY+kKExh/zwcNKW5t7 nMIFjabMugc5Da0MoTwVHq2pk7K4MrVdN4D+4PPYq1CP234eu4fTtTkbJC8VqZ1muQRa izya73zFykd5AOg1cOgqTDoVe+6pqUqyOUlg25ZcOrbdwxrkCbI2RGuhzcIGd+Efok9C SLNYmx8Obcx035j6duVY3teuRomSgzqg0diERD6liULQxL9WMYwcVj3axPYLEBIRCqn3 Migg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Z6dQeKkO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z27si13356279ejc.287.2021.05.18.09.57.20; Tue, 18 May 2021 09:58:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Z6dQeKkO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345654AbhEQQEh (ORCPT + 99 others); Mon, 17 May 2021 12:04:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:52066 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243745AbhEQPoB (ORCPT ); Mon, 17 May 2021 11:44:01 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A180B6194F; Mon, 17 May 2021 14:42:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621262580; bh=Y1Fi/8EmZWG4KsmdkBqPpUUPzppWQTtjsGwFkKKu/P0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z6dQeKkOyUHuS8eyAnCA/ch+DtUMliloNMkx05wOlvVjksZBwHnOPEZgkLO6oAuTA NL4q11+sTNqiZbYdBUoY4s6Lyq0vtye15U8bGwQ5gFHib4QC7IQ3OAHz7/xNiHoEoD sqeve6+eB4/hz4N/7jvtJ52cfXbf4I604UlChygA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sergio Lopez , Jan Kara , Dan Williams , Vivek Goyal , Sasha Levin Subject: [PATCH 5.10 218/289] dax: Wake up all waiters after invalidating dax entry Date: Mon, 17 May 2021 16:02:23 +0200 Message-Id: <20210517140312.481170746@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140305.140529752@linuxfoundation.org> References: <20210517140305.140529752@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vivek Goyal [ Upstream commit 237388320deffde7c2d65ed8fc9eef670dc979b3 ] I am seeing missed wakeups which ultimately lead to a deadlock when I am using virtiofs with DAX enabled and running "make -j". I had to mount virtiofs as rootfs and also reduce to dax window size to 256M to reproduce the problem consistently. So here is the problem. put_unlocked_entry() wakes up waiters only if entry is not null as well as !dax_is_conflict(entry). But if I call multiple instances of invalidate_inode_pages2() in parallel, then I can run into a situation where there are waiters on this index but nobody will wake these waiters. invalidate_inode_pages2() invalidate_inode_pages2_range() invalidate_exceptional_entry2() dax_invalidate_mapping_entry_sync() __dax_invalidate_entry() { xas_lock_irq(&xas); entry = get_unlocked_entry(&xas, 0); ... ... dax_disassociate_entry(entry, mapping, trunc); xas_store(&xas, NULL); ... ... put_unlocked_entry(&xas, entry); xas_unlock_irq(&xas); } Say a fault in in progress and it has locked entry at offset say "0x1c". Now say three instances of invalidate_inode_pages2() are in progress (A, B, C) and they all try to invalidate entry at offset "0x1c". Given dax entry is locked, all tree instances A, B, C will wait in wait queue. When dax fault finishes, say A is woken up. It will store NULL entry at index "0x1c" and wake up B. When B comes along it will find "entry=0" at page offset 0x1c and it will call put_unlocked_entry(&xas, 0). And this means put_unlocked_entry() will not wake up next waiter, given the current code. And that means C continues to wait and is not woken up. This patch fixes the issue by waking up all waiters when a dax entry has been invalidated. This seems to fix the deadlock I am facing and I can make forward progress. Reported-by: Sergio Lopez Fixes: ac401cc78242 ("dax: New fault locking") Reviewed-by: Jan Kara Suggested-by: Dan Williams Signed-off-by: Vivek Goyal Link: https://lore.kernel.org/r/20210428190314.1865312-4-vgoyal@redhat.com Signed-off-by: Dan Williams Signed-off-by: Sasha Levin --- fs/dax.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/dax.c b/fs/dax.c index 56eb1c759ca5..df5485b4bddf 100644 --- a/fs/dax.c +++ b/fs/dax.c @@ -675,7 +675,7 @@ static int __dax_invalidate_entry(struct address_space *mapping, mapping->nrexceptional--; ret = 1; out: - put_unlocked_entry(&xas, entry, WAKE_NEXT); + put_unlocked_entry(&xas, entry, WAKE_ALL); xas_unlock_irq(&xas); return ret; } -- 2.30.2